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

ethereum-input-data-decoder

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereum-input-data-decoder - npm Package Compare versions

Comparing version 0.1.6 to 0.2.0

test/cli_test.js

12

cli.js

@@ -7,4 +7,3 @@ const path = require('path')

const cli = meow(`
Usage
const cli = meow(` Usage
$ ethereum_input_data_decoder [flags] [input]

@@ -64,3 +63,3 @@

if (result.name === null && result.types.length === 0) {
if (result.method === null && result.types.length === 0) {
console.log('No matches')

@@ -70,3 +69,6 @@ return

const output = [`${'name'.padEnd(10)}${result.name}`]
const padType = result.types.reduce((a, x) => Math.max(a, x.length), 0)+2
const padName = result.names.reduce((a, x) => Math.max(a, x.length), 0)+2
const output = [`${'method'.padEnd(padType)}${result.method}\n`]
for (let i = 0; i < result.types.length; i++) {

@@ -82,3 +84,3 @@ let value = result.inputs[i]

output.push(`${result.types[i].padEnd(10)}${value}`)
output.push(`${result.types[i].padEnd(padType)}${result.names[i].padEnd(padName)}${value}`)
}

@@ -85,0 +87,0 @@

@@ -48,6 +48,9 @@ 'use strict';

var name = obj.name || null;
var method = obj.name || null;
var types = obj.inputs ? obj.inputs.map(function (x) {
return x.type;
}) : [];
var names = obj.inputs ? obj.inputs.map(function (x) {
return x.name;
}) : [];

@@ -68,5 +71,6 @@ // take last 32 bytes

return {
name: name,
method: method,
types: types,
inputs: inputs
inputs: inputs,
names: names
};

@@ -97,3 +101,3 @@ }

if (obj.type === 'event') return acc;
var name = obj.name || null;
var method = obj.name || null;
var types = obj.inputs ? obj.inputs.map(function (x) {

@@ -107,4 +111,12 @@ if (x.type === 'tuple[]') {

var hash = genMethodId(name, types);
var names = obj.inputs ? obj.inputs.map(function (x) {
if (x.type === 'tuple[]') {
return '';
} else {
return x.name;
}
}) : [];
var hash = genMethodId(method, types);
if (hash === methodId) {

@@ -124,5 +136,6 @@ var inputs = [];

return {
name: name,
method: method,
types: types,
inputs: inputs
inputs: inputs,
names: names
};

@@ -132,5 +145,5 @@ }

return acc;
}, { name: null, types: [], inputs: [] });
}, { method: null, types: [], inputs: [], names: [] });
if (!result.name) {
if (!result.method) {
try {

@@ -137,0 +150,0 @@ var decoded = this.decodeConstructor(data);

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

const name = obj.name || null
const method = obj.name || null
const types = obj.inputs ? obj.inputs.map(x => x.type) : []
const names = obj.inputs ? obj.inputs.map(x => x.name) : []

@@ -56,5 +57,6 @@ // take last 32 bytes

return {
name,
method,
types,
inputs
inputs,
names
}

@@ -84,3 +86,3 @@ }

if (obj.type === 'event') return acc
const name = obj.name || null
const method = obj.name || null
let types = obj.inputs ? obj.inputs.map(x => {

@@ -94,4 +96,12 @@ if (x.type === 'tuple[]') {

const hash = genMethodId(name, types)
let names = obj.inputs ? obj.inputs.map(x => {
if (x.type === 'tuple[]') {
return ''
} else {
return x.name
}
}) : []
const hash = genMethodId(method, types)
if (hash === methodId) {

@@ -111,5 +121,6 @@ let inputs = []

return {
name,
method,
types,
inputs
inputs,
names
}

@@ -119,5 +130,5 @@ }

return acc
}, { name: null, types: [], inputs: [] })
}, { method: null, types: [], inputs: [], names: [] })
if (!result.name) {
if (!result.method) {
try {

@@ -124,0 +135,0 @@ const decoded = this.decodeConstructor(data)

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

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -55,3 +55,3 @@ <h3 align="center">

{
"name": "registerOffChainDonation",
"method": "registerOffChainDonation",
"types": [

@@ -70,2 +70,9 @@ "address",

<Buffer f3 df ... 71 c8>
],
"names": [
"addr",
"timestamp",
"chfCents",
"currency",
"memo"
]

@@ -137,8 +144,9 @@ }

name registerOffChainDonation
address 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 1487012400
uint256 4204852
string BTC
bytes32 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
method registerOffChainDonation
address addr 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 timestamp 1487012400
uint256 chfCents 4204852
string currency BTC
bytes32 memo 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
```

@@ -151,8 +159,9 @@

name registerOffChainDonation
address 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 1487012400
uint256 4204852
string BTC
bytes32 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
method registerOffChainDonation
address addr 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 timestamp 1487012400
uint256 chfCents 4204852
string currency BTC
bytes32 memo 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
```

@@ -165,8 +174,9 @@

name registerOffChainDonation
address 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 1487012400
uint256 4204852
string BTC
bytes32 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
method registerOffChainDonation
address addr 0x5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02
uint256 timestamp 1487012400
uint256 chfCents 4204852
string currency BTC
bytes32 memo 0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8
```

@@ -224,4 +234,8 @@

- Q: Does this library support ABIEncoderV2?
- A: Yes, but it's buggy. Please submit a [bug report](https://github.com/miguelmota/ethereum-input-data-decoder/issues/new) if you encounter issues.
## License
[MIT](LICENSE)

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

const result = decoder.decodeData(data)
t.equal(result.name, 'registerOffChainDonation')
t.equal(result.method, 'registerOffChainDonation')
t.deepEqual(result.types, [

@@ -31,3 +31,3 @@ 'address',

t.test('abi array object', t => {
t.plan(6)
t.plan(7)
const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/abi1.json`))

@@ -37,10 +37,4 @@ const decoder = new InputDataDecoder(abi)

const result = decoder.decodeData(data)
t.equal(result.name, 'registerOffChainDonation')
t.deepEqual(result.types, [
'address',
'uint256',
'uint256',
'string',
'bytes32'
])
t.equal(result.method, 'registerOffChainDonation')
t.deepEqual(result.types, ['address', 'uint256', 'uint256', 'string', 'bytes32'])
t.equal(result.inputs[0].toString(16), '5a9dac9315fdd1c3d13ef8af7fdfeb522db08f02')

@@ -50,2 +44,3 @@ t.equal(result.inputs[1].toString(16), '58a20230')

t.equal(result.inputs[3], 'BTC')
t.deepEqual(result.names, ['addr', 'timestamp', 'chfCents', 'currency', 'memo'])
t.end()

@@ -55,4 +50,4 @@ })

// https://etherscan.io/tx/0xc7add41f6ae5e4fe268f654709f450983510ab7da67812be608faf2133a90b5a
t.test('contract creation data', t => {
t.plan(2)
t.test('contract creation data (constructor)', t => {
t.plan(4)

@@ -67,2 +62,5 @@ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/abi1.json`))

t.equal(result.inputs[1].toString(16), 'STIFTUNG Dfinity FDC')
t.equal(result.names[0].toString(), '_masterAuth')
t.equal(result.names[1].toString(), '_name')
})

@@ -72,3 +70,3 @@

t.test('erc721 transferFrom', t => {
t.plan(3)
t.plan(6)

@@ -84,2 +82,6 @@ const abi = JSON.parse(fs.readFileSync(`${__dirname}/data/erc721_abi.json`))

t.equal(result.inputs[2].toString(16), '5dc5')
t.equal(result.names[0], '_from')
t.equal(result.names[1], '_to')
t.equal(result.names[2], '_tokenId')
})

@@ -86,0 +88,0 @@

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

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