@zondax/izari-filecoin-tools v0.1.0-rc1
Izari Filecoin Tools
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
| Feature | Supported? | 
|---|---|
| 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
| Feature | ID (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
| Feature | Supported? | 
|---|---|
| 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
| Feature | Supported? | 
|---|---|
| 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 installThen, if you want to build the package, just need to run the following command. It will build both CJS and ESM flavours.
yarn buildTesting
The repo has established a set of rules to run ESLint in order to catch typos and possible bugs as soon as possible.
yarn lintBesides the linter, a formatter is set in place to assure the same code style through our developers.
yarn formatTest 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:generateFinally, in order to run tests, just do it by simply running the next command.
yarn testNotes
- 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
| Environments | Tested? | 
|---|---|
| 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 browsers | Tested? | 
|---|---|
| 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-cboris 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.jsonfile.
- 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-resolveris 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
3 years ago