Socket
Socket
Sign inDemoInstall

ethereum-input-data-decoder

Package Overview
Dependencies
115
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.2 to 0.3.4

test/data/1inch_exchange_v2_abi_no_eth.txt

9

dist/index.js

@@ -196,3 +196,5 @@ 'use strict';

return input.map(function (item, i) {
var type = tupleTypes[i].type;
// We find tupleTypes to not be an array where internalType is present in the ABI indicating item is a structure
var type = tupleTypes[i] ? tupleTypes[i].type : null;
if (type === 'address' && typeof item === 'string') {

@@ -206,2 +208,7 @@ return item.split('0x')[1];

}
if (Array.isArray(item)) {
return deepStripTupleAddresses(item, tupleTypes);
}
return item;

@@ -208,0 +215,0 @@ });

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

return input.map((item, i) => {
const type = tupleTypes[i].type
// We find tupleTypes to not be an array where internalType is present in the ABI indicating item is a structure
const type = tupleTypes[i] ? tupleTypes[i].type : null
if (type === 'address' && typeof item === 'string') {

@@ -176,2 +178,7 @@ return item.split('0x')[1]

}
if (Array.isArray(item)) {
return deepStripTupleAddresses(item, tupleTypes)
}
return item

@@ -178,0 +185,0 @@ })

4

package.json
{
"name": "ethereum-input-data-decoder",
"version": "0.3.2",
"version": "0.3.4",
"description": "Ethereum smart contract transaction input data decoder",

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

"is-buffer": "^2.0.3",
"meow": "^5.0.0"
"meow": "^10.1.1"
},

@@ -44,0 +44,0 @@ "keywords": [

@@ -8,3 +8,2 @@ const fs = require('fs')

const data = fs.readFileSync(`${__dirname}/data/abi1_input_data.txt`)
t.test('abi filepath', t => {

@@ -98,6 +97,6 @@ t.plan(6)

[
'0x6f02E6d47147B4448Fe2f2eb25B4f534cf110c23',
'0x0000000000000000000000000000000000000000',
'0xA258b39954ceF5cB142fd567A46cDdB31a670124',
'0x0000000000000000000000000000000000000000',
'6f02E6d47147B4448Fe2f2eb25B4f534cf110c23',
'0000000000000000000000000000000000000000',
'A258b39954ceF5cB142fd567A46cDdB31a670124',
'0000000000000000000000000000000000000000',
{ '_hex': '0x410d586a20a4bffff5' },

@@ -114,3 +113,3 @@ { '_hex': '0x5e05647aedbbd450' },

{ '_hex': '0x2386f26fc10000' },
[ '0x1b82e97aa18170e6b81ce3a829d77b7067cf3644c8706e97e7c96d5a92de61eb0c5c5aeb4fbfadca6b9fbc5adff91bfb32964aa9e1bf8309dad7e1bd3e45f0b44c03' ]
['0x1b82e97aa18170e6b81ce3a829d77b7067cf3644c8706e97e7c96d5a92de61eb0c5c5aeb4fbfadca6b9fbc5adff91bfb32964aa9e1bf8309dad7e1bd3e45f0b44c03']
]

@@ -171,4 +170,4 @@

{ '_hex': '0x3bf6ab7ba24000' },
[ 1 ],
[ 'C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' ],
[1],
['C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'],
[{ '_hex': '0x1a04a045412d3457' }],

@@ -231,2 +230,203 @@ [

})
// https://github.com/miguelmota/ethereum-input-data-decoder/issues/23
t.test('all inputs for operate(), (complex tuple hierarchies)', t => {
t.plan(3)
const decoder = new InputDataDecoder(`${__dirname}/data/PayableProxyForSoloMargin_abi.json`)
const data = fs.readFileSync(`${__dirname}/data/PayableProxyForSoloMargin_tx_data.txt`)
const result = decoder.decodeData(data)
const expectedInputs = [
[
[
'b929044aF6a7B7AE12EF0e653ACC59f73cf9577B', // accounts.owner
{ '_hex': '0x00' } // accounts.number
]
],
[
[
0,
{ '_hex': '0x00' },
[true, 0, 0, { '_hex': '0x06c46038fa803f00' }],
{ '_hex': '0x00' }, { '_hex': '0x00' },
'a8b39829cE2246f89B31C013b8Cde15506Fb9A76', // actions.otherAddress
{ '_hex': '0x00' },
'0x'
]
],
'b929044aF6a7B7AE12EF0e653ACC59f73cf9577B' // sendEthTo
]
const expectedNames = [
[
'accounts',
['owner', 'number']
],
[
'actions',
[
'actionType',
'accountId',
'amount',
'primaryMarketId',
'secondaryMarketId',
'otherAddress',
'otherAccountId',
'data'
]
],
'sendEthTo'
]
const expectedTypes = [
'(address,uint256)[]',
'(uint8,uint256,tuple,uint256,uint256,address,uint256,bytes)[]',
'address'
]
t.deepEqual(result.inputs, expectedInputs)
t.deepEqual(result.names, expectedNames)
t.deepEqual(result.types, expectedTypes)
})
// We found different behaviour for when WETH is used internally, so make sure to test for both cases
// - Alexander @ Blocknative
t.test('1inch swap tests, (common tuple[] usage with internalType)', t => {
t.plan(6)
const decoder = new InputDataDecoder(`${__dirname}/data/1inch_exchange_v2_abi.json`)
// https://etherscan.io/tx/0x4a62d52b5d084476e2cfd6eb4c5dfd8378147aa0186e117ed2710a7e54985ecf
const dataWithWeth = fs.readFileSync(`${__dirname}/data/1inch_exchange_v2_abi_with_eth.txt`)
// https://etherscan.io/tx/0x8ac7a9f4f9c8e788b2a4cb29e95f369ba09f0ef4c1bd064e6aa1517ce9247d38
const dataNoWeth = fs.readFileSync(`${__dirname}/data/1inch_exchange_v2_abi_no_eth.txt`)
const resultWithWeth = decoder.decodeData(dataWithWeth)
const resultNoWeth = decoder.decodeData(dataNoWeth)
const expectedTypes = ['address', '(address,address,address,address,uint256,uint256,uint256,uint256,address,bytes)', '(uint256,uint256,uint256,bytes)[]']
const expectedNames = [
'caller', [
'desc', [
'srcToken',
'dstToken',
'srcReceiver',
'dstReceiver',
'amount',
'minReturnAmount',
'guaranteedAmount',
'flags',
'referrer',
'permit'
]], [
'calls', [
'targetWithMandatory',
'gasLimit',
'value',
'data'
]
]
]
const expectedInputsNoWeth = [
'e069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
[
'dAC17F958D2ee523a2206206994597C13D831ec7',
'F970b8E36e23F7fC3FD752EeA86f8Be8D83375A6',
'e069CB01D06bA617bCDf789bf2ff0D5E5ca20C71',
'2C38b7622241958DC0A097D405c468a9176418A3',
{ '_hex': '0x0129c8e900' },
{ '_hex': '0x0b8cfc3e036ef2502538' },
{ '_hex': '0x0be8703fee6d197a3635' },
{ '_hex': '0x04' },
'6884249C226F1443f2b7040A3d6143C170Df34F6',
'0x'
], [
[
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xeb5625d9000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000129c8e900'
], [
{ '_hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xc98fefed00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000129c8e9000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c710000000000000000000000000000000000000000000000000000000000000003000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000005365b5bc56493f08a38e5eb08e36cbbe6fcc83060000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0x83f1291f000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000000000500000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064eb5625d90000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000008000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000104c98fefed000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c7100000000000000000000000000000000000000000000000000000000000000030000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000f7b9fa01098f22527db205ff9bb6fdf7c7d9f1c5000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000448000000000000000000000000000000000000000000000000000000000000024'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0x7f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000e069cb01d06ba617bcdf789bf2ff0d5e5ca20c7100000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000006884249c226f1443f2b7040a3d6143c170df34f600000000000000000000000000000000000000000000000000000000000000010000000000000000042b4998f6b3b8f500000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000004df804219786f1d7f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a6000000000000000000000000000000000000000000000be8703fee6d197a363500000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xb3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000024000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000000000000100000000000000000000000000000001000000000000000000000000f970b8e36e23f7fc3fd752eea86f8be8d83375a60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002c38b7622241958dc0a097d405c468a9176418a3000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
]
]
]
const expectedInputsWithWeth = [
'b3C9669A5706477a2B237D98eDb9B57678926f04',
[
'A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
'111111111117dC0aa78b770fA6A738034120C302',
'b3C9669A5706477a2B237D98eDb9B57678926f04',
'83B97790c7dA251FAFB24d6CbfC481cFa4AFc4F6',
{ '_hex': '0x010642ac00' },
{ '_hex': '0x34e551bf0ab692275a' },
{ '_hex': '0x35f9ac3b1a9af32d62' },
{ '_hex': '0x04' },
'382fFCe2287252F930E1C8DC9328dac5BF282bA1',
'0x'
], [
[
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xeb5625d9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0000000000000000000000000000000000000000000000000000000010642ac00'
], [
{ '_hex': '0x8000000000000000000000002f9ec37d6ccfff1cab21733bdadede11c823ccb0' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xc98fefed0000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000010642ac000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f040000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000874d8de5b26c9d9f6aa8d7bab283f9a9c6f777f40000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xb3af37c0000000000000000000000000000000000000000000000000000000000000008080000000000000000000000000000000000000000000000000000000000000240000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c00000000000000000000000000000014000000000000000000000000000000140000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000003fd4cf9303c4bc9e13772618828712c8eac7dd2f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xc9f12e9d0000000000000000000000003fd4cf9303c4bc9e13772618828712c8eac7dd2f0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000326aad2da94c59524ac0d93f6d6cbf9071d7086f20000000000000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x8000000000000000000000000000000000000000000000000000000000000000' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xc9f12e9d00000000000000000000000026aad2da94c59524ac0d93f6d6cbf9071d7086f2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000003b3c9669a5706477a2b237d98edb9b57678926f040000000000000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0x7f8fe7a000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000b3c9669a5706477a2b237d98edb9b57678926f0400000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000382ffce2287252f930e1c8dc9328dac5bf282ba10000000000000000000000000000000000000000000000000000000000000001000000000000000002b79a9b4d8a5c9300000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000fbc539a31bdf05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000000000000000000000000035f9ac3b1a9af32d6200000000000000000000000000000000000000000000000000000000'
], [
{ '_hex': '0x00' },
{ '_hex': '0x00' },
{ '_hex': '0x00' },
'0xb3af37c000000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000111111111117dc0aa78b770fa6a738034120c302000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000111111111117dc0aa78b770fa6a738034120c30200000000000000000000000083b97790c7da251fafb24d6cbfc481cfa4afc4f6000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000'
]
]
]
t.deepEquals(resultNoWeth.types, expectedTypes)
t.deepEquals(resultWithWeth.types, expectedTypes)
t.deepEquals(resultNoWeth.names, expectedNames)
t.deepEquals(resultWithWeth.names, expectedNames)
t.deepEquals(resultNoWeth.inputs, expectedInputsNoWeth)
t.deepEquals(resultWithWeth.inputs, expectedInputsWithWeth)
})
})

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

Sorry, the diff of this file is not supported yet

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