Socket
Socket
Sign inDemoInstall

ethereum-input-data-decoder

Package Overview
Dependencies
111
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.5 to 0.4.0

test/data/abi3_data.txt

163

dist/index.js

@@ -9,4 +9,2 @@ 'use strict';

var fs = require('fs');
var ethabi = require('ethereumjs-abi');
var ethers = require('ethers');

@@ -16,2 +14,5 @@ var Buffer = require('buffer/').Buffer;

// TODO: dry up and clean up
// NOTE: this library may be deprecated in future, in favor of ethers v5 AbiCoder.
var InputDataDecoder = function () {

@@ -24,2 +25,3 @@ function InputDataDecoder(prop) {

if (typeof prop === 'string') {
var fs = require('fs');
this.abi = JSON.parse(fs.readFileSync(prop));

@@ -73,2 +75,3 @@ } else if (prop instanceof Object) {

var inputs = ethers.utils.defaultAbiCoder.decode(types, data);
inputs = deepRemoveUnwantedArrayProperties(inputs);

@@ -103,35 +106,42 @@ return {

var result = this.abi.reduce(function (acc, obj) {
if (obj.type === 'constructor') return acc;
if (obj.type === 'event') return acc;
var method = obj.name || null;
var types = obj.inputs ? obj.inputs.map(function (x) {
if (x.type.includes('tuple')) {
return x;
} else {
return x.type;
try {
if (obj.type === 'constructor') {
return acc;
}
}) : [];
var names = obj.inputs ? obj.inputs.map(function (x) {
if (x.type.includes('tuple')) {
return [x.name, x.components.map(function (a) {
return a.name;
})];
} else {
return x.name;
if (obj.type === 'event') {
return acc;
}
}) : [];
var method = obj.name || null;
var types = obj.inputs ? obj.inputs.map(function (x) {
if (x.type.includes('tuple')) {
return x;
} else {
return x.type;
}
}) : [];
var hash = genMethodId(method, types);
var names = obj.inputs ? obj.inputs.map(function (x) {
if (x.type.includes('tuple')) {
return [x.name, x.components.map(function (a) {
return a.name;
})];
} else {
return x.name;
}
}) : [];
if (hash === methodId) {
var inputs = [];
var hash = genMethodId(method, types);
try {
if (hash === methodId) {
var inputs = [];
inputsBuf = normalizeAddresses(types, inputsBuf);
inputs = ethabi.rawDecode(types, inputsBuf);
} catch (err) {
inputs = ethers.utils.defaultAbiCoder.decode(types, inputsBuf);
// defaultAbiCoder attaches some unwanted properties to the list object
inputs = deepRemoveUnwantedArrayProperties(inputs);
try {
inputs = ethers.utils.defaultAbiCoder.decode(types, inputsBuf);
} catch (err) {
try {
var ifc = new ethers.utils.Interface([]);
inputs = ifc.decodeFunctionData(ethers.utils.FunctionFragment.fromObject(obj), data);
} catch (err) {}
}

@@ -154,29 +164,82 @@ // TODO: do this normalization into normalizeAddresses

});
// Map any tuple types into arrays
var typesToReturn = types.map(function (t) {
if (t.components) {
var arr = t.components.reduce(function (acc, cur) {
return [].concat(_toConsumableArray(acc), [cur.type]);
}, []);
var tupleStr = '(' + arr.join(',') + ')';
if (t.type === 'tuple[]') return tupleStr + '[]';
return tupleStr;
}
return t;
});
// defaultAbiCoder attaches some unwanted properties to the list object
inputs = deepRemoveUnwantedArrayProperties(inputs);
return {
method: method,
types: typesToReturn,
inputs: inputs,
names: names
};
}
// Map any tuple types into arrays
var typesToReturn = types.map(function (t) {
if (t.components) {
var arr = t.components.reduce(function (acc, cur) {
return [].concat(_toConsumableArray(acc), [cur.type]);
}, []);
var tupleStr = '(' + arr.join(',') + ')';
if (t.type === 'tuple[]') return tupleStr + '[]';
return tupleStr;
}
return t;
});
return {
method: method,
types: typesToReturn,
inputs: inputs,
names: names
};
return acc;
} catch (err) {
return acc;
}
return acc;
}, { method: null, types: [], inputs: [], names: [] });
if (!result.method) {
this.abi.reduce(function (acc, obj) {
if (obj.type === 'constructor') {
return acc;
}
if (obj.type === 'event') {
return acc;
}
var method = obj.name || null;
try {
var ifc = new ethers.utils.Interface([]);
var _result = ifc.decodeFunctionData(ethers.utils.FunctionFragment.fromObject(obj), data);
var inputs = deepRemoveUnwantedArrayProperties(_result);
result.method = method;
result.inputs = inputs;
result.names = obj.inputs ? obj.inputs.map(function (x) {
if (x.type.includes('tuple')) {
return [x.name, x.components.map(function (a) {
return a.name;
})];
} else {
return x.name;
}
}) : [];
var types = obj.inputs ? obj.inputs.map(function (x) {
if (x.type.includes('tuple')) {
return x;
} else {
return x.type;
}
}) : [];
result.types = types.map(function (t) {
if (t.components) {
var arr = t.components.reduce(function (acc, cur) {
return [].concat(_toConsumableArray(acc), [cur.type]);
}, []);
var tupleStr = '(' + arr.join(',') + ')';
if (t.type === 'tuple[]') return tupleStr + '[]';
return tupleStr;
}
return t;
});
} catch (err) {}
});
}
if (!result.method) {
try {

@@ -183,0 +246,0 @@ var decoded = this.decodeConstructor(data);

@@ -1,3 +0,1 @@

const fs = require('fs')
const ethabi = require('ethereumjs-abi')
const ethers = require('ethers')

@@ -7,2 +5,5 @@ const Buffer = require('buffer/').Buffer

// TODO: dry up and clean up
// NOTE: this library may be deprecated in future, in favor of ethers v5 AbiCoder.
class InputDataDecoder {

@@ -13,2 +14,3 @@ constructor (prop) {

if (typeof prop === `string`) {
const fs = require('fs')
this.abi = JSON.parse(fs.readFileSync(prop))

@@ -33,3 +35,3 @@ } else if (prop instanceof Object) {

for (var i = 0; i < this.abi.length; i++) {
for (let i = 0; i < this.abi.length; i++) {
const obj = this.abi[i]

@@ -56,3 +58,4 @@

const inputs = ethers.utils.defaultAbiCoder.decode(types, data)
let inputs = ethers.utils.defaultAbiCoder.decode(types, data)
inputs = deepRemoveUnwantedArrayProperties(inputs)

@@ -83,36 +86,43 @@ return {

const methodId = toHexString(dataBuf.subarray(0, 4))
var inputsBuf = dataBuf.subarray(4)
let inputsBuf = dataBuf.subarray(4)
const result = this.abi.reduce((acc, obj) => {
if (obj.type === 'constructor') return acc
if (obj.type === 'event') return acc
const method = obj.name || null
let types = obj.inputs ? obj.inputs.map(x => {
if (x.type.includes('tuple')) {
return x
} else {
return x.type
try {
if (obj.type === 'constructor') {
return acc
}
}) : []
let names = obj.inputs ? obj.inputs.map(x => {
if (x.type.includes('tuple')) {
return [x.name, x.components.map(a => a.name)]
} else {
return x.name
if (obj.type === 'event') {
return acc
}
}) : []
const method = obj.name || null
let types = obj.inputs ? obj.inputs.map(x => {
if (x.type.includes('tuple')) {
return x
} else {
return x.type
}
}) : []
const hash = genMethodId(method, types)
let names = obj.inputs ? obj.inputs.map(x => {
if (x.type.includes('tuple')) {
return [x.name, x.components.map(a => a.name)]
} else {
return x.name
}
}) : []
if (hash === methodId) {
let inputs = []
const hash = genMethodId(method, types)
try {
if (hash === methodId) {
let inputs = []
inputsBuf = normalizeAddresses(types, inputsBuf)
inputs = ethabi.rawDecode(types, inputsBuf)
} catch (err) {
inputs = ethers.utils.defaultAbiCoder.decode(types, inputsBuf)
// defaultAbiCoder attaches some unwanted properties to the list object
inputs = deepRemoveUnwantedArrayProperties(inputs)
try {
inputs = ethers.utils.defaultAbiCoder.decode(types, inputsBuf)
} catch (err) {
try {
const ifc = new ethers.utils.Interface([])
inputs = ifc.decodeFunctionData(ethers.utils.FunctionFragment.fromObject(obj), data)
} catch (err) {}
}

@@ -133,27 +143,76 @@ // TODO: do this normalization into normalizeAddresses

})
}
// Map any tuple types into arrays
const typesToReturn = types.map(t => {
if (t.components) {
const arr = t.components.reduce((acc, cur) => [...acc, cur.type], [])
const tupleStr = `(${arr.join(',')})`
if (t.type === 'tuple[]') return tupleStr + '[]'
return tupleStr
// Map any tuple types into arrays
const typesToReturn = types.map(t => {
if (t.components) {
const arr = t.components.reduce((acc, cur) => [...acc, cur.type], [])
const tupleStr = `(${arr.join(',')})`
if (t.type === 'tuple[]') return tupleStr + '[]'
return tupleStr
}
return t
})
// defaultAbiCoder attaches some unwanted properties to the list object
inputs = deepRemoveUnwantedArrayProperties(inputs)
return {
method,
types: typesToReturn,
inputs,
names
}
return t
})
}
return {
method,
types: typesToReturn,
inputs,
names
}
return acc
} catch (err) {
return acc
}
return acc
}, { method: null, types: [], inputs: [], names: [] })
if (!result.method) {
this.abi.reduce((acc, obj) => {
if (obj.type === 'constructor') {
return acc
}
if (obj.type === 'event') {
return acc
}
const method = obj.name || null
try {
const ifc = new ethers.utils.Interface([])
const _result = ifc.decodeFunctionData(ethers.utils.FunctionFragment.fromObject(obj), data)
let inputs = deepRemoveUnwantedArrayProperties(_result)
result.method = method
result.inputs = inputs
result.names = obj.inputs ? obj.inputs.map(x => {
if (x.type.includes('tuple')) {
return [x.name, x.components.map(a => a.name)]
} else {
return x.name
}
}) : []
const types = obj.inputs ? obj.inputs.map(x => {
if (x.type.includes('tuple')) {
return x
} else {
return x.type
}
}) : []
result.types = types.map(t => {
if (t.components) {
const arr = t.components.reduce((acc, cur) => [...acc, cur.type], [])
const tupleStr = `(${arr.join(',')})`
if (t.type === 'tuple[]') return tupleStr + '[]'
return tupleStr
}
return t
})
} catch (err) {}
})
}
if (!result.method) {
try {

@@ -160,0 +219,0 @@ const decoded = this.decodeConstructor(data)

{
"name": "ethereum-input-data-decoder",
"version": "0.3.5",
"version": "0.4.0",
"description": "Ethereum smart contract transaction input data decoder",

@@ -39,4 +39,3 @@ "main": "dist/index.js",

"buffer": "^5.2.1",
"ethereumjs-abi": "^0.6.7",
"ethers": "^4.0.27",
"ethers": "^5.5.4",
"is-buffer": "^2.0.3",

@@ -43,0 +42,0 @@ "meow": "^10.1.1"

@@ -249,2 +249,8 @@ <h3 align="center">

5. Build:
```bash
npm run build
```
## Contributing

@@ -251,0 +257,0 @@

@@ -1,2 +0,1 @@

[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"name","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_allowance","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"totalSupply","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"decimals","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"_decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"amountBurned","outputs":[{"name":"amountBurned","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowed","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_address","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"currentSupply","outputs":[{"name":"currentSupply","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"symbol","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"_currentSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"_symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"_initialSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"_name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"burn","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"payable":false,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"currentSupply","type":"uint256"},{"indexed":false,"name":"data","type":"bytes"}],"name":"Burn","type":"event"}]

@@ -21,5 +21,5 @@ const fs = require('fs')

])
t.equal(result.inputs[0].toString(16), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')
t.equal(result.inputs[1].toString(16), '58a20230')
t.equal(result.inputs[2].toString(16), '402934')
t.equal(result.inputs[0].toString(16).toLowerCase(), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')
t.equal(result.inputs[1].toHexString(), '0x58a20230')
t.equal(result.inputs[2].toHexString(), '0x402934')
t.equal(result.inputs[3], 'BTC')

@@ -37,5 +37,5 @@ t.end()

t.deepEqual(result.types, ['address', 'uint256', 'uint256', 'string', 'bytes32'])
t.equal(result.inputs[0].toString(16), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')
t.equal(result.inputs[1].toString(16), '58a20230')
t.equal(result.inputs[2].toString(16), '402934')
t.equal(result.inputs[0].toString().toLowerCase(), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')
t.equal(result.inputs[1].toHexString(), '0x58a20230')
t.equal(result.inputs[2].toHexString(), '0x402934')
t.equal(result.inputs[3], 'BTC')

@@ -73,5 +73,5 @@ t.deepEqual(result.names, ['addr', 'timestamp', 'chfCents', 'currency', 'memo'])

t.equal(result.inputs[0].toString(16), '10017ca37b1257ac0771e24652aa28c758e378eb')
t.equal(result.inputs[1].toString(16), 'e7a632d89104385bdd3992eeb82cffeb48e4e539')
t.equal(result.inputs[2].toString(16), '5dc5')
t.equal(result.inputs[0].toString().toLowerCase(), '10017ca37b1257ac0771e24652aa28c758e378eb')
t.equal(result.inputs[1].toString().toLowerCase(), 'e7a632d89104385bdd3992eeb82cffeb48e4e539')
t.equal(result.inputs[2].toHexString(), '0x5dc5')

@@ -99,12 +99,12 @@ t.equal(result.names[0], '_from')

[
'6f02E6d47147B4448Fe2f2eb25B4f534cf110c23',
'0000000000000000000000000000000000000000',
'A258b39954ceF5cB142fd567A46cDdB31a670124',
'0000000000000000000000000000000000000000',
{ '_hex': '0x410d586a20a4bffff5' },
{ '_hex': '0x5e05647aedbbd450' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x5d787202' },
{ '_hex': '0x016d1e79ae50' },
'0x6f02E6d47147B4448Fe2f2eb25B4f534cf110c23',
'0x0000000000000000000000000000000000000000',
'0xA258b39954ceF5cB142fd567A46cDdB31a670124',
'0x0000000000000000000000000000000000000000',
{ 'type': 'BigNumber', 'hex': '0x410d586a20a4bffff5' },
{ 'type': 'BigNumber', 'hex': '0x5e05647aedbbd450' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x5d787202' },
{ 'type': 'BigNumber', 'hex': '0x016d1e79ae50' },
'0xf47261b000000000000000000000000089d24a6b4ccb1b6faa2625fe562bdd9a23260359',

@@ -114,7 +114,7 @@ '0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'

],
{ '_hex': '0x2386f26fc10000' },
{ 'type': 'BigNumber', 'hex': '0x2386f26fc10000' },
['0x1b82e97aa18170e6b81ce3a829d77b7067cf3644c8706e97e7c96d5a92de61eb0c5c5aeb4fbfadca6b9fbc5adff91bfb32964aa9e1bf8309dad7e1bd3e45f0b44c03']
]
t.deepEqual(result.inputs, expectedInputs)
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))

@@ -167,17 +167,17 @@ const expectedTypes = [

const expectedInputs = [
'81c55017F7Ce6E72451cEd49FF7bAB1e3DF64d0C',
{ '_hex': '0x27019ab6af611240' },
'0x81c55017F7Ce6E72451cEd49FF7bAB1e3DF64d0C',
{ 'type': 'BigNumber', 'hex': '0x27019ab6af611240' },
[
'A37dE6790861B5541b0dAa7d0C0e651F44c6f4D9',
{ '_hex': '0x3bf6ab7ba24000' },
'0xA37dE6790861B5541b0dAa7d0C0e651F44c6f4D9',
{ 'type': 'BigNumber', 'hex': '0x3bf6ab7ba24000' },
[1],
['C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'],
[{ '_hex': '0x1a04a045412d3457' }],
['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'],
[{ 'type': 'BigNumber', 'hex': '0x1a04a045412d3457' }],
[
'89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
'2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'
'0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
'0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'
],
[
{ '_hex': '0x06989640c83ea4a200' },
{ '_hex': '0x19c110' }
{ 'type': 'BigNumber', 'hex': '0x06989640c83ea4a200' },
{ 'type': 'BigNumber', 'hex': '0x19c110' }
]

@@ -189,3 +189,3 @@ ],

t.deepEqual(result.inputs, expectedInputs)
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))

@@ -230,3 +230,3 @@ const expectedNames = [

const result = decoder.decodeData(data)
t.equal(result.inputs[0].toString(16), 'e9dc1532d9d9cf914926406a02370cea80cf32f6')
t.equal(result.inputs[0].toString(16).toLowerCase(), 'e9dc1532d9d9cf914926406a02370cea80cf32f6')
t.equal(result.inputs[1].toString(10), '54378763')

@@ -245,4 +245,4 @@ })

[
'b929044aF6a7B7AE12EF0e653ACC59f73cf9577B', // accounts.owner
{ '_hex': '0x00' } // accounts.number
'0xb929044aF6a7B7AE12EF0e653ACC59f73cf9577B', // accounts.owner
{ 'type': 'BigNumber', 'hex': '0x00' } // accounts.number
]

@@ -253,11 +253,11 @@ ],

0,
{ '_hex': '0x00' },
[true, 0, 0, { '_hex': '0x06c46038fa803f00' }],
{ '_hex': '0x00' }, { '_hex': '0x00' },
'a8b39829cE2246f89B31C013b8Cde15506Fb9A76', // actions.otherAddress
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
[true, 0, 0, { 'type': 'BigNumber', 'hex': '0x06c46038fa803f00' }],
{ 'type': 'BigNumber', 'hex': '0x00' }, { 'type': 'BigNumber', 'hex': '0x00' },
'0xa8b39829cE2246f89B31C013b8Cde15506Fb9A76', // actions.otherAddress
{ 'type': 'BigNumber', 'hex': '0x00' },
'0x'
]
],
'b929044aF6a7B7AE12EF0e653ACC59f73cf9577B' // sendEthTo
'0xb929044aF6a7B7AE12EF0e653ACC59f73cf9577B' // sendEthTo
]

@@ -290,3 +290,3 @@ const expectedNames = [

t.deepEqual(result.inputs, expectedInputs)
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
t.deepEqual(result.names, expectedNames)

@@ -336,39 +336,39 @@ t.deepEqual(result.types, expectedTypes)

const expectedInputsNoWeth = [
'e069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
'0xe069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
[
'dAC17F958D2ee523a2206206994597C13D831ec7',
'F970b8E36e23F7fC3FD752EeA86f8Be8D83375A6',
'e069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
'2C38b7622241958DC0A097D405c468a9176418A3',
{ '_hex': '0x0129c8e900' },
{ '_hex': '0x0b8cfc3e036ef2502538' },
{ '_hex': '0x0be8703fee6d197a3635' },
{ '_hex': '0x04' },
'6884249C226F1443f2b7040A3d6143C170Df34F6',
'0xdAC17F958D2ee523a2206206994597C13D831ec7',
'0xF970b8E36e23F7fC3FD752EeA86f8Be8D83375A6',
'0xe069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
'0x2C38b7622241958DC0A097D405c468a9176418A3',
{ 'type': 'BigNumber', 'hex': '0x0129c8e900' },
{ 'type': 'BigNumber', 'hex': '0x0b8cfc3e036ef2502538' },
{ 'type': 'BigNumber', 'hex': '0x0be8703fee6d197a3635' },
{ 'type': 'BigNumber', 'hex': '0x04' },
'0x6884249C226F1443f2b7040A3d6143C170Df34F6',
'0x'
], [
[
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xeb5625d9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000129c8e900'
], [
{ '_hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xc98fefed00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000129c8e9000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c710000000000000000000000000000000000000000000000000000000000000003000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000005365b5bc56493f08a38e5eb08e36cbbe6fcc83060000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0x83f1291f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000000000500000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064eb5625d90000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000008000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000104c98fefed000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c7100000000000000000000000000000000000000000000000000000000000000030000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000f7b9fa01098f22527db205ff9bb6fdf7c7d9f1c5000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000448000000000000000000000000000000000000000000000000000000000000024'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0x7f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c7100000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000006884249c226f1443f2b7040a3d6143c170df34f600000000000000000000000000000000000000000000000000000000000000010000000000000000042b4998f6b3b8f500000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000004df804219786f1d7f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a6000000000000000000000000000000000000000000000be8703fee6d197a363500000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xb3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000024000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000000000000100000000000000000000000000000001000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002c38b7622241958dc0a097d405c468a9176418a3000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'

@@ -380,49 +380,49 @@ ]

const expectedInputsWithWeth = [
'b3C9669A5706477a2B237D98eDb9B57678926f04',
'0xb3C9669A5706477a2B237D98eDb9B57678926f04',
[
'A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'111111111117dC0aa78b770fA6A738034120C302',
'b3C9669A5706477a2B237D98eDb9B57678926f04',
'83B97790c7dA251FAFB24d6CbfC481cFa4AFc4F6',
{ '_hex': '0x010642ac00' },
{ '_hex': '0x34e551bf0ab692275a' },
{ '_hex': '0x35f9ac3b1a9af32d62' },
{ '_hex': '0x04' },
'382fFCe2287252F930E1C8DC9328dac5BF282bA1',
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'0x111111111117dC0aa78b770fA6A738034120C302',
'0xb3C9669A5706477a2B237D98eDb9B57678926f04',
'0x83B97790c7dA251FAFB24d6CbfC481cFa4AFc4F6',
{ 'type': 'BigNumber', 'hex': '0x010642ac00' },
{ 'type': 'BigNumber', 'hex': '0x34e551bf0ab692275a' },
{ 'type': 'BigNumber', 'hex': '0x35f9ac3b1a9af32d62' },
{ 'type': 'BigNumber', 'hex': '0x04' },
'0x382fFCe2287252F930E1C8DC9328dac5BF282bA1',
'0x'
], [
[
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xeb5625d9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000000000000000000000000000000000010642ac00'
], [
{ '_hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xc98fefed0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000010642ac000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f040000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000874d8de5b26c9d9f6aa8d7bab283f9a9c6f777f40000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xb3af37c0000000000000000000000000000000000000000000000000000000000000008080000000000000000000000000000000000000000000000000000000000000240000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c00000000000000000000000000000014000000000000000000000000000000140000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000003fd4cf9303c4bc9e13772618828712c8eac7dd2f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xc9f12e9d0000000000000000000000003fd4cf9303c4bc9e13772618828712c8eac7dd2f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000326aad2da94c59524ac0d93f6d6cbf9071d7086f20000000000000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xc9f12e9d00000000000000000000000026aad2da94c59524ac0d93f6d6cbf9071d7086f2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000003b3c9669a5706477a2b237d98edb9b57678926f040000000000000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0x7f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f0400000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000382ffce2287252f930e1c8dc9328dac5bf282ba10000000000000000000000000000000000000000000000000000000000000001000000000000000002b79a9b4d8a5c9300000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000fbc539a31bdf05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000000000000000000000000035f9ac3b1a9af32d6200000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
{ 'type': 'BigNumber', 'hex': '0x00' },
'0xb3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000111111111117dc0aa78b770fa6a738034120c30200000000000000000000000083b97790c7da251fafb24d6cbfc481cfa4afc4f6000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'

@@ -437,5 +437,188 @@ ]

t.deepEquals(resultWithWeth.names, expectedNames)
t.deepEquals(resultNoWeth.inputs, expectedInputsNoWeth)
t.deepEquals(resultWithWeth.inputs, expectedInputsWithWeth)
t.deepEquals(JSON.stringify(resultNoWeth.inputs), JSON.stringify(expectedInputsNoWeth))
t.deepEquals(JSON.stringify(resultWithWeth.inputs), JSON.stringify(expectedInputsWithWeth))
})
t.test('test abi3.json', t => {
t.plan(4)
const decoder = new InputDataDecoder(`${__dirname}/data/abi3.json`)
const data = fs.readFileSync(`${__dirname}/data/abi3_data.txt`)
const result = decoder.decodeData(data)
const expectedInputs = [
'0x482bc619eE7662759CDc0685B4E78f464Da39C73',
'0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
{
'type': 'BigNumber',
'hex': '0x66299080'
},
{
'type': 'BigNumber',
'hex': '0xe7413e'
},
{
'type': 'BigNumber',
'hex': '0x61f81da8'
},
'0xb0CC32190a06f4bA13027E7D6C516217b49E8eb0',
[
27,
'0xe35fd8994857126c80d25bd1994ba96849fa77556d1360a9e605f04cc8f9d7c1',
'0x1f2244a355a9ab6ea4864381e5d38d4d9b09a25291d0bf6e61c6f975a4d5b9f7'
],
'0x436c697070657200000000000000000000000000000000000000000000000000'
]
const expectedNames = [
'inputToken',
'outputToken',
'inputAmount',
'outputAmount',
'goodUntil',
'destinationAddress',
['theSignature', ['v', 'r', 's']],
'auxiliaryData'
]
const expectedTypes = [ 'address', 'address', 'uint256', 'uint256', 'uint256', 'address', '(uint8,bytes32,bytes32)', 'bytes' ]
t.deepEqual(result.method, 'transmitAndSwap')
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
t.deepEqual(result.names, expectedNames)
t.deepEqual(result.types, expectedTypes)
})
t.test('test abi4.json', t => {
t.plan(4)
const decoder = new InputDataDecoder(`${__dirname}/data/abi4.json`)
const data = fs.readFileSync(`${__dirname}/data/abi4_data.txt`)
const result = decoder.decodeData(data)
const expectedInputs = [
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
{
'type': 'BigNumber',
'hex': '0x77359400'
},
[
[
'0xe2A1b03Cd5D639377B6D6e48d81A50FbC6C955a8',
'0x4fcfecd10000000000000000000000000000000000000000000000000000000077359400000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
]
],
{
'type': 'BigNumber',
'hex': '0x06d14b423b3af5fc'
},
'0xcd43AaD533e663b726DAe4a08185E9db8eBC9f6F'
]
const expectedNames = [
'fromToken',
'toToken',
'fromAmount',
[
'trades',
[
'moduleAddress',
'encodedCalldata'
]
],
'finalAmountMin',
'recipient'
]
const expectedTypes = ['address', 'address', 'uint256', '(address,bytes)[]', 'uint256', 'address']
t.deepEqual(result.method, 'executeTrades')
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
t.deepEqual(result.names, expectedNames)
t.deepEqual(result.types, expectedTypes)
})
// https://github.com/miguelmota/ethereum-input-data-decoder/issues/28
t.test('test abi5.json', t => {
t.plan(4)
const decoder = new InputDataDecoder(`${__dirname}/data/abi5.json`)
const data = fs.readFileSync(`${__dirname}/data/abi5_data.txt`)
const result = decoder.decodeData(data)
const expectedInputs = [
[
[
[
'0x7842792a8471D0f5aE645f513Cc5999b1bB6B182',
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
'0x6b785a0322126826d8226d77e173d75DAfb84d11',
{
'type': 'BigNumber',
'hex': '0x2386f26fc10000'
},
{
'type': 'BigNumber',
'hex': '0x00'
},
{
'type': 'BigNumber',
'hex': '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}
],
[
'0x5D87Eb9Ac9C107424734F2a95F11649206cCFeA8',
'0x6b785a0322126826d8226d77e173d75DAfb84d11',
'0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
{
'type': 'BigNumber',
'hex': '0x01ee30107c0827ea7d'
},
{
'type': 'BigNumber',
'hex': '0x00'
},
{
'type': 'BigNumber',
'hex': '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
}
]
]
],
'0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
'0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
{
'type': 'BigNumber',
'hex': '0x2386f26fc10000'
},
{
'type': 'BigNumber',
'hex': '0x1b1bd5bfc01a3688'
}
]
const expectedNames = [ [ 'swapSequences', [ 'pool', 'tokenIn', 'tokenOut', 'swapAmount', 'limitReturnAmount', 'maxPrice' ] ], 'tokenIn', 'tokenOut', 'totalAmountIn', 'minTotalAmountOut' ]
const expectedTypes = [
'(address,address,address,uint256,uint256,uint256)', 'address', 'address', 'uint256', 'uint256'
]
t.deepEqual(result.method, 'multihopBatchSwapExactIn')
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
t.deepEqual(result.names, expectedNames)
t.deepEqual(result.types, expectedTypes)
})
// https://github.com/miguelmota/ethereum-input-data-decoder/issues/37
t.test('test abi6.json', t => {
t.plan(4)
const decoder = new InputDataDecoder(`${__dirname}/data/abi6.json`)
const data = fs.readFileSync(`${__dirname}/data/abi6_data.txt`)
const result = decoder.decodeData(data)
// not possible to decode:
// https://github.com/ethers-io/ethers.js/discussions/2656#discussioncomment-2115587
const expectedInputs = []
const expectedNames = [ 'amountOutMin', 'path', 'to', 'deadline' ]
const expectedTypes = [ 'uint256', 'address[]', 'address', 'uint256' ]
t.deepEqual(result.method, 'swapExactETHForTokens')
t.deepEqual(JSON.stringify(result.inputs), JSON.stringify(expectedInputs))
t.deepEqual(result.names, expectedNames)
t.deepEqual(result.types, expectedTypes)
})
})

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc