Giter Site home page Giter Site logo

js-abi's Introduction

@parity/abi

A port of https://github.com/paritytech/ethabi to JavaScript

Build Status Coverage Status Dependency Status devDependency Status

contributing

Clone the repo and install dependencies via npm install. Tests can be executed via npm run test

installation

Install the package with npm install --save @parity/abi from @parity/abi

implementation

approach

  • this version tries to stay as close to the original Rust version in intent, function names & purpose
  • it is a basic port of the Rust version, relying on effectively the same test-suite (expanded where deemed appropriate)
  • it is meant as a library to be used in other projects, i.e. @parity/api

differences to original Rust version

  • internally the library operates on string binary representations as opposed to Vector bytes, lengths are therefore 64 bytes as opposed to 32 bytes
  • function names are adapted from the Rust standard snake_case to the JavaScript standard camelCase
  • due to the initial library focus, the cli component (as implemented by the original) is not supported nor implemented

js-abi's People

Contributors

jacogr avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

pirapira

js-abi's Issues

Wrong encoded input with nested arrays

// -- Encoded input using js lib (incorrect)

secureApi.util.abiEncode('update',['uint256[][]', 'uint256[][]'],[ [[]], [[]] ])

"0000000000000000000000000000000000000000000000000000000000000040" +
"0000000000000000000000000000000000000000000000000000000000000080" +
"0000000000000000000000000000000000000000000000000000000000000001" +
"0000000000000000000000000000000000000000000000000000000000000080" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000001" +
"00000000000000000000000000000000000000000000000000000000000000c0" +
"0000000000000000000000000000000000000000000000000000000000000000"
// -- Encoded input using rust lib (correct)

encode(&vec![
    Token::Array(vec![Token::Array(vec![])]),
    Token::Array(vec![Token::Array(vec![])]),
]);

// offset of the 1st array
"0000000000000000000000000000000000000000000000000000000000000040" +
// offset of the 2nd array
"00000000000000000000000000000000000000000000000000000000000000a0" +
// 40 - 1st array (len)
"0000000000000000000000000000000000000000000000000000000000000001" +
// offset of array inside 1st array
"0000000000000000000000000000000000000000000000000000000000000080" +
// 80 - array inside 1st array (len)
"0000000000000000000000000000000000000000000000000000000000000000" +
// a0 - 2nd array (len)
"0000000000000000000000000000000000000000000000000000000000000001" +
// offset of array inside 2nd array
"00000000000000000000000000000000000000000000000000000000000000e0" +
// e0 - array inside 2nd array (len)
"0000000000000000000000000000000000000000000000000000000000000000"

cc thanks @debris for verifying

ABI tries to encode float values

Given input such as 1cdef.5cb34 the ABI will try to encode the float hex value - incorrectly. Options are -

  1. Alert/throw when invalid floats are received
  2. Truncate the value before encoding (possibly still warning?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.