Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@multiversx/sdk-transaction-decoder

Package Overview
Dependencies
Maintainers
10
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@multiversx/sdk-transaction-decoder - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

69

lib/src/transaction.decoder.js

@@ -27,35 +27,42 @@ "use strict";

metadata.value = BigInt(transaction.value);
if (transaction.data) {
const decodedData = this.base64Decode(transaction.data);
const dataComponents = decodedData.split('@');
const args = dataComponents.slice(1);
if (args.every((x) => this.isSmartContractArgument(x))) {
metadata.functionName = dataComponents[0];
metadata.functionArgs = args;
if (!transaction.data) {
metadata.functionName = 'transfer';
metadata.functionArgs = undefined;
return metadata;
}
const decodedData = this.base64Decode(transaction.data);
const dataComponents = decodedData.split('@');
const args = dataComponents.slice(1);
if (args.every((x) => this.isSmartContractArgument(x))) {
metadata.functionName = dataComponents[0];
metadata.functionArgs = args;
}
if (args.length === 0) {
metadata.functionName = 'transfer';
metadata.functionArgs = undefined;
}
if (metadata.functionName === 'relayedTx' && metadata.functionArgs && metadata.functionArgs.length === 1) {
try {
const relayedTransaction = JSON.parse(this.hexToString(metadata.functionArgs[0]));
relayedTransaction.value = relayedTransaction.value.toString();
relayedTransaction.sender = this.bech32Encode(this.base64ToHex(relayedTransaction.sender));
relayedTransaction.receiver = this.bech32Encode(this.base64ToHex(relayedTransaction.receiver));
return this.getNormalTransactionMetadata(relayedTransaction);
}
if (metadata.functionName === 'relayedTx' && metadata.functionArgs && metadata.functionArgs.length === 1) {
try {
const relayedTransaction = JSON.parse(this.hexToString(metadata.functionArgs[0]));
relayedTransaction.value = relayedTransaction.value.toString();
relayedTransaction.sender = this.bech32Encode(this.base64ToHex(relayedTransaction.sender));
relayedTransaction.receiver = this.bech32Encode(this.base64ToHex(relayedTransaction.receiver));
return this.getNormalTransactionMetadata(relayedTransaction);
}
catch (error) {
// nothing special
}
catch (error) {
// nothing special
}
if (metadata.functionName === 'relayedTxV2' && metadata.functionArgs && metadata.functionArgs.length === 4) {
try {
const relayedTransaction = new TransactionToDecode();
relayedTransaction.sender = transaction.receiver;
relayedTransaction.receiver = this.bech32Encode(metadata.functionArgs[0]);
relayedTransaction.data = this.base64Encode(this.hexToString(metadata.functionArgs[2]));
relayedTransaction.value = '0';
return this.getNormalTransactionMetadata(relayedTransaction);
}
catch (error) {
// nothing special
}
}
if (metadata.functionName === 'relayedTxV2' && metadata.functionArgs && metadata.functionArgs.length === 4) {
try {
const relayedTransaction = new TransactionToDecode();
relayedTransaction.sender = transaction.receiver;
relayedTransaction.receiver = this.bech32Encode(metadata.functionArgs[0]);
relayedTransaction.data = this.base64Encode(this.hexToString(metadata.functionArgs[2]));
relayedTransaction.value = '0';
return this.getNormalTransactionMetadata(relayedTransaction);
}
catch (error) {
// nothing special
}
}

@@ -92,3 +99,3 @@ return metadata;

const value = this.hexToBigInt(args[index++]);
if (nonce) {
if (nonce && this.hexToNumber(nonce) > 0) {
result.transfers.push({

@@ -95,0 +102,0 @@ value,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const transaction_decoder_1 = require("./../src/transaction.decoder");
test('Simple wallet to wallet transfer with dummy data text', () => {
const decoder = new transaction_decoder_1.TransactionDecoder();
const metadata = decoder.getTransactionMetadata({
sender: 'erd18w6yj09l9jwlpj5cjqq9eccfgulkympv7d4rj6vq4u49j8fpwzwsvx7e85',
receiver: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
data: 'ZHVtbXlUZXh0',
value: '10000000000000000',
});
expect(metadata).toEqual({
sender: 'erd18w6yj09l9jwlpj5cjqq9eccfgulkympv7d4rj6vq4u49j8fpwzwsvx7e85',
receiver: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
value: BigInt('10000000000000000'),
functionName: 'transfer'
});
});
test('NFT Smart contract call', () => {

@@ -89,1 +104,63 @@ const decoder = new transaction_decoder_1.TransactionDecoder();

});
test('MultiESDTNFTTransfer fungible (with 00 nonce) + meta', () => {
const decoder = new transaction_decoder_1.TransactionDecoder();
const metadata = decoder.getTransactionMetadata({
sender: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
receiver: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
data: 'TXVsdGlFU0RUTkZUVHJhbnNmZXJAMDAwMDAwMDAwMDAwMDAwMDA1MDBkZjNiZWJlMWFmYTEwYzQwOTI1ZTgzM2MxNGE0NjBlMTBhODQ5ZjUwYTQ2OEAwMkA0YzRiNGQ0NTU4MmQ2MTYxNjIzOTMxMzBAMmZlM2IwQDA5Yjk5YTZkYjMwMDI3ZTRmM2VjQDU1NTM0NDQzMmQzMzM1MzA2MzM0NjVAMDBAMDEyNjMwZTlhMjlmMmY5MzgxNDQ5MUA3MDYxNzk1ZjZkNjU3NDYxNWY2MTZlNjQ1ZjY2NzU2ZTY3Njk2MjZjNjVAMGVkZTY0MzExYjhkMDFiNUA=',
value: '0',
});
expect(metadata).toEqual({
sender: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
receiver: 'erd1qqqqqqqqqqqqqpgqmua7hcd05yxypyj7sv7pffrquy9gf86s535qxct34s',
value: BigInt('0'),
functionName: 'pay_meta_and_fungible',
functionArgs: [
'0ede64311b8d01b5',
'',
],
transfers: [
{
value: BigInt('45925073746530627023852'),
properties: {
collection: 'LKMEX-aab910',
identifier: 'LKMEX-aab910-2fe3b0',
},
},
{
value: BigInt('1389278024872597502641297'),
properties: {
token: 'USDC-350c4e',
},
},
],
});
});
test('MultiESDTNFTTransfer fungibles (00 and missing nonce)', () => {
const decoder = new transaction_decoder_1.TransactionDecoder();
const metadata = decoder.getTransactionMetadata({
sender: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
receiver: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
data: 'TXVsdGlFU0RUTkZUVHJhbnNmZXJAMDAwMDAwMDAwMDAwMDAwMDA1MDBkZjNiZWJlMWFmYTEwYzQwOTI1ZTgzM2MxNGE0NjBlMTBhODQ5ZjUwYTQ2OEAwMkA1MjQ5NDQ0NTJkMzAzNTYyMzE2MjYyQDAwQDA5Yjk5YTZkYjMwMDI3ZTRmM2VjQDU1NTM0NDQzMmQzMzM1MzA2MzM0NjVAQDAxMjYzMGU5YTI5ZjJmOTM4MTQ0OTE=',
value: '0',
});
expect(metadata).toEqual({
sender: 'erd1lkrrrn3ws9sp854kdpzer9f77eglqpeet3e3k3uxvqxw9p3eq6xqxj43r9',
receiver: 'erd1qqqqqqqqqqqqqpgqmua7hcd05yxypyj7sv7pffrquy9gf86s535qxct34s',
value: BigInt('0'),
transfers: [
{
value: BigInt('45925073746530627023852'),
properties: {
token: 'RIDE-05b1bb',
},
},
{
value: BigInt('1389278024872597502641297'),
properties: {
token: 'USDC-350c4e',
},
},
],
});
});
{
"name": "@multiversx/sdk-transaction-decoder",
"version": "1.0.2",
"version": "1.0.3",
"description": "Transaction metadata decoder",

@@ -5,0 +5,0 @@ "main": "lib/transaction.decoder.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc