0.1.0-rc1 • Published 1 year ago

@zondax/izari-filecoin-tools v0.1.0-rc1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

Izari Filecoin Tools

License node-current Package GithubActions

Short description

  • It is written in Typescript
  • It is composed by pure JS
  • It is transpiled to two different flavours:
    • CommonJS (es2015)
    • ESM (esnext)

Requisites

  • NodeJS >= 16.0.0

React

  • In order to use this package in browsers (like react, react-native, etc), some modules need to be polyfill (like Buffer, stream, etc). Most projects use webpack to bundle JS code. If your project uses it, please refer to this doc in order to configure it correctly. Besides, you could check this blog post too.

Features

Filecoin Node Comms

FeatureSupported?
Get next nonce:white_check_mark:
Estimate fees for new tx:white_check_mark:
Broadcast a new tx:white_check_mark:
Read tx state:white_check_mark:

Addresses

FeatureID (f0)SECP256K1 (f1)Actor (f2)BLS (f3)Delegated (f4)
Parse from string:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Parse from bytes:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Encode to bytes:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Encode to string:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Get payload:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Get protocol:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Get network type:white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
Get namespace:heavy_minus_sign::heavy_minus_sign::heavy_minus_sign::heavy_minus_sign::white_check_mark:
Get sub address:heavy_minus_sign::heavy_minus_sign::heavy_minus_sign::heavy_minus_sign::white_check_mark:

Transactions

FeatureSupported?
Create new instance:white_check_mark:
Parse from raw json:white_check_mark:
Parse from serialized:white_check_mark:
Export to json:white_check_mark:
Serialize (to cbor):white_check_mark:
Prepare to send (get nonce and fees):white_check_mark:

Wallet

FeatureSupported?
Generate new mnemonic:white_check_mark:
Derive key from seed:white_check_mark:
Derive key from mnemonic:white_check_mark:
Sign transactions (f1/secp256k1):white_check_mark:

Development

Build

In order to install all required dependencies, just need to run the following command

yarn install

Then, if you want to build the package, just need to run the following command. It will build both CJS and ESM flavours.

yarn build

Testing

The repo has established a set of rules to run ESLint in order to catch typos and possible bugs as soon as possible.

yarn lint

Besides the linter, a formatter is set in place to assure the same code style through our developers.

yarn format

Test cases generated automatically and are written in json files. Those files are consumed by jest to create on case for each scenario. In order to create those files from a raw input file, just run the following command.

yarn test:generate

Finally, in order to run tests, just do it by simply running the next command.

yarn test

Notes

  • Please, there are some env vars you need to set first in order to run the tests. Check it first.

Tests

So far, the package has been tested in different environments. We are trying to assure it works in as many platforms as we can.

Environments

EnvironmentsTested?
NodeJS (CommonJS):white_check_mark:
NodeJS (ESM):white_check_mark:
Integration tests (Jest):white_check_mark:
React app:white_check_mark:
NextJS:x:

Web Browsers

Web browsersTested?
Chromium:white_check_mark:
Firefox:x:
Safari:x:

Notes

Jest

  • It was necessary to load ESM support on jest in order to be able to load some modules that has no support to CJS anymore. In particular, @ipld/dag-cbor is the one that forced us to do it. It was done following the jest documentation site.
  • According to the ts-jest documentation site, we are using a custom tsconfig.json file.
  • TypeScript allows importing other TypeScript files with a .js extension, for compatibility with the ES6 modules loader specification. Unfortunately, Jest gets confused by this and complains that it's not able to find the JavaScript file. jest-ts-webcompat-resolver is the actual resolver we use in order to be able to handle imports with extensions. More info here.
  • In order to generate test cases for addresses features, we are using a glif package called @glif/filecoin-address. Besides, generating transaction test cases is done by using zondax package called @zondax/filecoin-signing-tools

React

  • React app is based on create-react-app utility. It has been ejected in order to configure webpack to polyfill some NodeJS native modules. In particular, you can find the custom configs added here and here.

https://jestjs.io/docs/ecmascript-modules