Page MenuHomePhabricator

[b58-ts] Add `b58-ts` library for base58 en-/decoding in TS
AcceptedPublic

Authored by tobias_ruck on Sat, Nov 30, 01:57.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Summary

Adding our own base58 library has the advantage that we have this sensitive code in-house without extra dependencies, that we can model it closely after our existing C++ implementation, and that we can modify it's behavior as needed.

Alternatives were considered:

  • bs58: Just a special case of base-x, but we want somethins specialized without extra dependencies
  • base58-js: No TS support and also really obscure implementation with reduce(.map)
  • b58: Older version of bs58 is seems?
  • base58: Only for integers it seems
Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
bs58-lib-init
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 31428
Build 62354: Build Diff
Build 62353: arc lint + arc unit

Event Timeline

Tail of the build log:

Test does not depend on ecashaddrjs, skipping ecashaddrjs dependencies...
Test does not depend on mock-chronik-client, skipping mock-chronik-client dependencies...
Test does not depend on ecash-lib-wasm, skipping
Test does not depend on chronik-client
Test does not depend on ecash-lib
Test does not depend on ecash-agora
Test does not depend on ecash-script, skipping ecash-script dependencies...
Test does not depend on ecash-coinselect, skipping ecash-coinselect dependencies...
/work/modules/b58-ts /work/abc-ci-builds/b58-ts-tests
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated glob@7.2.0: Glob versions prior to v9 are no longer supported
npm warn deprecated glob@8.1.0: Glob versions prior to v9 are no longer supported
npm warn deprecated @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
npm warn deprecated @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
npm warn deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.

> b58-ts@0.1.0 prepublish
> npm run build


> b58-ts@0.1.0 build
> tsc

tests/test.ts(7,32): error TS2307: Cannot find module 'ecash-lib' or its corresponding type declarations.
npm error code 2
npm error path /work/modules/b58-ts
npm error command failed
npm error command sh -c npm run build
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-11-30T01_58_56_526Z-debug-0.log
Build b58-ts-tests failed with exit code 2

Tail of the build log:

   Compiling wasm-bindgen-shared v0.2.92
   Compiling shlex v1.3.0
   Compiling bumpalo v3.16.0
   Compiling log v0.4.22
   Compiling once_cell v1.20.2
   Compiling thiserror v1.0.69
   Compiling wasm-bindgen v0.2.92
   Compiling cfg-if v1.0.0
   Compiling abc-rust-lint v0.1.0 (/work/chronik/abc-rust-lint)
   Compiling cc v1.2.1
   Compiling generic-array v0.14.7
   Compiling quote v1.0.37
   Compiling syn v2.0.87
   Compiling ecash-secp256k1-sys v0.10.0 (/work/modules/ecash-secp256k1/ecash-secp256k1-sys)
   Compiling crypto-common v0.1.6
   Compiling block-buffer v0.10.4
   Compiling digest v0.10.7
   Compiling sha2 v0.10.8
   Compiling ripemd v0.1.3
   Compiling wasm-bindgen-backend v0.2.92
   Compiling ecash-secp256k1 v0.30.0 (/work/modules/ecash-secp256k1)
   Compiling thiserror-impl v1.0.69
   Compiling wasm-bindgen-macro-support v0.2.92
   Compiling wasm-bindgen-macro v0.2.92
   Compiling ecash-lib-wasm v0.1.0 (/work/modules/ecash-lib-wasm)
    Finished release-wasm [optimized] target(s) in 8.24s
Test does not depend on chronik-client
Test depends on ecash-lib. Building TypeScript...
/work/modules/ecash-lib /work/modules/ecash-lib-wasm /work/abc-ci-builds/b58-ts-tests

added 363 packages, and audited 366 packages in 2s

60 packages are looking for funding
  run `npm fund` for details

2 vulnerabilities (1 moderate, 1 high)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

> ecash-lib@1.1.0 build
> tsc && tsc -p ./tsconfig.build.json && cp -r ./src/ffi ./dist

../chronik-client/proto/chronik.ts(2,18): error TS2307: Cannot find module 'long' or its corresponding type declarations.
../chronik-client/proto/chronik.ts(3,17): error TS2307: Cannot find module 'protobufjs/minimal' or its corresponding type declarations.
../chronik-client/src/ChronikClient.ts(5,22): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
../chronik-client/src/ChronikClient.ts(6,23): error TS2307: Cannot find module 'isomorphic-ws' or its corresponding type declarations.
../chronik-client/src/ChronikClient.ts(7,21): error TS2307: Cannot find module 'ws' or its corresponding type declarations.
../chronik-client/src/failoverProxy.ts(5,38): error TS2307: Cannot find module 'axios' or its corresponding type declarations.
../chronik-client/src/failoverProxy.ts(6,23): error TS2307: Cannot find module 'isomorphic-ws' or its corresponding type declarations.
../chronik-client/src/failoverProxy.ts(7,21): error TS2307: Cannot find module 'ws' or its corresponding type declarations.
../chronik-client/src/failoverProxy.ts(186,35): error TS7006: Parameter 'x' implicitly has an 'any' type.
../chronik-client/src/failoverProxy.ts(270,32): error TS7006: Parameter 'e' implicitly has an 'any' type.
../chronik-client/src/failoverProxy.ts(276,30): error TS7006: Parameter 'e' implicitly has an 'any' type.
../chronik-client/src/failoverProxy.ts(294,33): error TS7006: Parameter 'msg' implicitly has an 'any' type.
src/script.ts(20,27): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
tests/txBuilder.test.ts(37,27): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
Build b58-ts-tests failed with exit code 2

Tail of the build log:

  Downloaded wasm-bindgen v0.2.92
  Downloaded wasm-bindgen-backend v0.2.92
  Downloaded unicode-ident v1.0.14
  Downloaded typenum v1.17.0
  Downloaded thiserror v1.0.69
  Downloaded cc v1.2.1
  Downloaded sha2 v0.10.8
  Downloaded thiserror-impl v1.0.69
  Downloaded crypto-common v0.1.6
  Downloaded cpufeatures v0.2.15
   Compiling proc-macro2 v1.0.89
   Compiling unicode-ident v1.0.14
   Compiling version_check v0.9.5
   Compiling typenum v1.17.0
   Compiling wasm-bindgen-shared v0.2.92
   Compiling shlex v1.3.0
   Compiling once_cell v1.20.2
   Compiling bumpalo v3.16.0
   Compiling log v0.4.22
   Compiling cfg-if v1.0.0
   Compiling wasm-bindgen v0.2.92
   Compiling thiserror v1.0.69
   Compiling abc-rust-lint v0.1.0 (/work/chronik/abc-rust-lint)
   Compiling cc v1.2.1
   Compiling generic-array v0.14.7
   Compiling quote v1.0.37
   Compiling syn v2.0.87
   Compiling ecash-secp256k1-sys v0.10.0 (/work/modules/ecash-secp256k1/ecash-secp256k1-sys)
   Compiling crypto-common v0.1.6
   Compiling block-buffer v0.10.4
   Compiling digest v0.10.7
   Compiling ripemd v0.1.3
   Compiling sha2 v0.10.8
   Compiling wasm-bindgen-backend v0.2.92
   Compiling ecash-secp256k1 v0.30.0 (/work/modules/ecash-secp256k1)
   Compiling thiserror-impl v1.0.69
   Compiling wasm-bindgen-macro-support v0.2.92
   Compiling wasm-bindgen-macro v0.2.92
   Compiling ecash-lib-wasm v0.1.0 (/work/modules/ecash-lib-wasm)
    Finished release-wasm [optimized] target(s) in 5.72s
Test depends on chronik-client. Building TypeScript...
/work/modules/chronik-client /work/modules/ecash-lib-wasm /work/abc-ci-builds/b58-ts-tests

> chronik-client@2.0.0 prepublish
> npm run build


> chronik-client@2.0.0 build
> tsc

src/ChronikClient.ts(5,22): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
test/integration/mempool_conflicts.ts(7,22): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
test/integration/script_endpoints.ts(7,22): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
test/integration/websocket.ts(7,22): error TS2307: Cannot find module 'ecashaddrjs' or its corresponding type declarations.
npm error code 2
npm error path /work/modules/chronik-client
npm error command failed
npm error command sh -c npm run build
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-11-30T02_04_23_753Z-debug-0.log
Build b58-ts-tests failed with exit code 2

would be nice to drop this into ecashaddrjs as a replacement for bs58check, to show that it works the way we expect to use it (in our own modules to replace 3rd-party deps).

modules/b58-ts/package.json
38 โ†—(On Diff #51267)

๐Ÿ”ฅ

modules/b58-ts/tests/base58_encode_decode.json
1 โ†—(On Diff #51267)

header

modules/b58-ts/tsconfig.json
1 โ†—(On Diff #51267)

should include a tsconfig.build.json as done in ecash-agora and ecash-lib so that we do not build ts for tests.

This revision now requires changes to proceed.Sat, Nov 30, 02:19

lib looks good. ok approving it now but we should replace base58check in ecashaddrjs with this in another diff soon.

This revision is now accepted and ready to land.Sat, Nov 30, 05:36