New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

secjs-hashcode

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secjs-hashcode

Encoding for Contract Application Binary Interface (ABI), including function name and input paras, based on the rule https://solidity.readthedocs.io/en/develop/abi-spec.html

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

secjs-hashcode

Encoding for Contract Application Binary Interface (ABI), including function name and input parameter values, based on the rule https://solidity.readthedocs.io/en/develop/abi-spec.html For further information in detail. Please refer to test cases and introduction in test/test.js.

JavaScript Style Guide

[JavaScript Style Guide]

  • HashCode
    • new HashCode(sFnName, aParaValue)
    • .getFnName()String
    • .getParaValue()Array.<Dict>
    • .setFnName(sFnName)
    • .setParaValue(aParaValue)
    • .runHashCode()
    • .getHashCode()String
    • .getHashCodeFragments()Array.<String>
    • .showHashCodeFragments()

new HashCode(sFnName, aParaValue)

new HashCode(sFnName, aParaValue) Constructs an Encoder.

ParamTypeDescription
sFnNameStringThe function name with the parenthesised list of parameter types. Parameter types are split by a single comma - no spaces are used. e.g. "sam(bytes,bool,uint[])"
aParaValueArray.<Dict>The array of input Parameter Values with its type. e.g. [{value: 'dave', type: 'bytes'}, {value: true, type: 'bool'}, {value: [1, 2, 3], type: 'uint[]'}]

Example

const HashCode = require('../src/index')

const sFnName = 'sam(bytes,bool,uint[])'
const aParaValue = [{value: 'dave', type: 'bytes'}, {value: true, type: 'bool'}, {value: [1, 2, 3], type: 'uint[]'}]
const oHashCode = new HashCode(sFnName, aParaValue)

HashCode.getFnName() ⇒ String

Returns the current Function Name information.

Example

const sFnName = oHashCode.getFnName()

HashCode.getParaValue() ⇒ Array.<Dict>

Returns the current input parameter values information.

Example

const aParaValue = oHashCode.getParaValue()

HashCode.setFnName(sFnName)

Set the Function Name.

Example

const sFnName = 'sam(bytes,bool,uint[])'
oHashCode.setFnName(sFnName)

HashCode.setParaValue(aParaValue)

Set the input parameter values.

Example

const aParaValue = [{value: 'dave', type: 'bytes'}, {value: true, type: 'bool'}, {value: [1, 2, 3], type: 'uint[]'}]
oHashCode.setParaValue(aParaValue)

HashCode.runHashCode()

Run the encoding based on current function name information and input parameter values

Example

oHashCode.runHashCode(aParaValue)

HashCode.getHashCode() ⇒ String

Returns the endcoded Bytecode String.

Example

const sByteCode = oHashCode1.getHashCode()
/*
An example for the format of result:
"8be6524600000000000000000000000000000000000000000000000000000000000001230000000000000000000000000000000000000000000000000000000000000080313233343536373839300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004560000000000000000000000000000000000000000000000000000000000000789000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000"
*/

HashCode.getHashCodeFragments() ⇒ Array.<String>

Returns the array of encoded result of each element to have a better look and check.

Example

const aHashCodeFragments = oHashCode1.getHashCodeFragments()
/*
An example for the format of result:
["8be65246",
"0000000000000000000000000000000000000000000000000000000000000123",
"0000000000000000000000000000000000000000000000000000000000000080",
"3132333435363738393000000000000000000000000000000000000000000000",
"00000000000000000000000000000000000000000000000000000000000000e0",
"0000000000000000000000000000000000000000000000000000000000000002",
"0000000000000000000000000000000000000000000000000000000000000456",
"0000000000000000000000000000000000000000000000000000000000000789",
"000000000000000000000000000000000000000000000000000000000000000d",
"48656c6c6f2c20776f726c642100000000000000000000000000000000000000"]
*/

HashCode.getHashCodeFragments() ⇒ Array.<String>

Show the encoded result of each element row by row in console to have a better look and check.

Example

oHashCode1.showHashCodeFragments()
/*
An example for the console output:
8be65246
0000000000000000000000000000000000000000000000000000000000000123
0000000000000000000000000000000000000000000000000000000000000080
3132333435363738393000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000e0
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000456
0000000000000000000000000000000000000000000000000000000000000789
000000000000000000000000000000000000000000000000000000000000000d
48656c6c6f2c20776f726c642100000000000000000000000000000000000000
*/

Keywords

secjs

FAQs

Package last updated on 22 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts