Skip to content

Commit

Permalink
Algorand/hot fix for KMS (#265)
Browse files Browse the repository at this point in the history
* fix for algorand kms

* version up

Co-authored-by: jay_sun <[email protected]>
  • Loading branch information
JeyDev310 and jay_sun authored Dec 7, 2021
1 parent 33fb472 commit a28cfa6
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "1.29.27",
"version": "1.29.28",
"description": "Tatum API client allows browsers and Node.js clients to interact with Tatum API.",
"main": "dist/src/index.js",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
58 changes: 45 additions & 13 deletions src/transaction/algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ export const prepareAlgoSignedTransaction = async (testnet: boolean, tx: AlgoTra
const enc = new TextEncoder();
const note = enc.encode(tx.note ? tx.note : '');
const txn = algosdk.makePaymentTxnWithSuggestedParams(
tx.from,
tx.to,
Number(tx.amount) * 1000000,
undefined,
note,
tx.from,
tx.to,
Number(tx.amount) * 1000000,
undefined,
note,
{
...params,
fee: Number(tx.fee) * 1000000,
...params,
fee: Number(tx.fee) * 1000000,
flatFee: true
}
);
Expand Down Expand Up @@ -106,9 +106,41 @@ export const signAlgoKMSTransaction = async (tx: TransactionKMS, fromPrivateKey:
throw Error('Unsupported chain.')
}
const decoder = new base32.Decoder({ type: 'rfc4648' })
const txn = JSON.parse(tx.serializedTransaction);
const secretKey = new Uint8Array(decoder.write(fromPrivateKey).buf);
const signedTxn = txn.signTxn(secretKey);
let txn = JSON.parse(tx.serializedTransaction);
txn.from = algosdk.encodeAddress(new Uint8Array(Object.values(txn.from.publicKey)));
txn.to = algosdk.encodeAddress(new Uint8Array(Object.values(txn.to.publicKey)));
txn.note = new Uint8Array(Object.values(txn.note));
txn.lease = undefined;
if (txn.tag) {
if (txn.tag.data) {
txn.tag = Buffer.from(txn.tag.data);
}
}
txn.genesisHash = Buffer.from(txn.genesisHash.data);
if (txn.assetManager) {
txn.assetManager = algosdk.encodeAddress(new Uint8Array(Object.values(txn.assetManager.publicKey)));
}
if (txn.assetReserve) {
txn.assetReserve = undefined;
}
if (txn.assetFreeze) {
txn.assetFreeze = undefined;
}
if (txn.assetClawback) {
txn.assetClawback = undefined;
}
if (txn.assetRevocationTarget) {
txn.assetRevocationTarget = undefined;
}
if (txn.reKeyTo) {
txn.reKeyTo = undefined;
}
if (txn.assetMetadataHash) {
txn.assetMetadataHash = new Uint8Array(Object.values(txn.assetMetadataHash));
}
const _txn = new (algosdk.Transaction)(txn);
const secretKey = new Uint8Array(decoder.write(fromPrivateKey).buf);
const signedTxn = _txn.signTxn(secretKey);
return signedTxn;
}

Expand Down Expand Up @@ -248,7 +280,7 @@ export const prepareAlgoCreateFractionalNFTSignedTransaction = async (testnet: b
const txn = algosdk.makeAssetCreateTxnWithSuggestedParams(
tx.fromPrivateKey ? generateAlgodAddressFromPrivatetKey(tx.fromPrivateKey) : tx.from,
undefined,
10 ** Math.floor(Math.log10(Number(tx.amount))),
10 ** Math.floor(Math.log10(Number(tx.amount))),
Math.floor(Math.log10(Number(tx.amount))),
false,
tx.fromPrivateKey ? generateAlgodAddressFromPrivatetKey(tx.fromPrivateKey) : tx.from,
Expand Down Expand Up @@ -290,7 +322,7 @@ export const sendAlgoCreateFractionalNFTSignedTransaction = async (testnet: bool
export const prepareAlgoTransferFractionalNFTSignedTransaction = async (testnet: boolean, tx: TransferMultiToken, provider?: string) => {
const algodClient = getAlgoClient(testnet, provider);
const params = await algodClient.getTransactionParams().do();
const decoder = new base32.Decoder({ type: 'rfc4648' })
const decoder = new base32.Decoder({ type: 'rfc4648' })
const txn = algosdk.makeAssetTransferTxnWithSuggestedParams(
tx.fromPrivateKey ? generateAlgodAddressFromPrivatetKey(tx.fromPrivateKey) : tx.from,
tx.to,
Expand Down Expand Up @@ -368,7 +400,7 @@ export const sendAlgoBurnFractionalNFTSignedTransaction = async (testnet: boolea
export const prepareAlgoCreateFTSignedTransaction = async (testnet: boolean, tx: DeployErc20, provider?: string) => {
const algodClient = getAlgoClient(testnet, provider);
const params = await algodClient.getTransactionParams().do();
const decoder = new base32.Decoder({ type: 'rfc4648' })
const decoder = new base32.Decoder({ type: 'rfc4648' })
const txn = algosdk.makeAssetCreateTxnWithSuggestedParams(
tx.fromPrivateKey ? generateAlgodAddressFromPrivatetKey(tx.fromPrivateKey) : tx.from,
undefined,
Expand Down
Loading

0 comments on commit a28cfa6

Please sign in to comment.