Page MenuHomePhabricator

[Cashtab] Implementing Bitgo utxolib
AbandonedPublic

Authored by bytesofman on Dec 23 2022, 17:44.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Implenting bitgo utxolib instead of ecashjs-lib

This diff replaces ecashjs-lib with the better tested and better maintained @bitgo/utxo-lib

Bundle size is about the same after implementation. Jest fails everything with this import, so need to find a way around that.

Still should evaluate and possibly migrate to the txbuilder replacement psbt

Still should schnorr sign

Test Plan

N/A, this is still a proof of concept

Diff Detail

Repository
rABC Bitcoin ABC
Branch
implementing-bitgo
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 21673
Build 42986: Build Diffcashtab-tests
Build 42985: arc lint + arc unit

Event Timeline

Tail of the build log:

FAIL src/components/Configure/__tests__/Configure.test.js
  ● Test suite failed to run

    ecc library invalid

      3 | import useInterval from './useInterval';
      4 | import BigNumber from 'bignumber.js';
    > 5 | import * as utxolib from '@bitgo/utxo-lib';
        | ^
      6 | import {
      7 |     loadStoredWallet,
      8 |     isValidStoredWallet,

      at assert (node_modules/ecpair/src/testecc.js:231:20)
      at testEcc (node_modules/ecpair/src/testecc.js:6:3)
      at Object.ECPairFactory (node_modules/ecpair/src/ecpair.js:19:25)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/noble_ecc.ts:98:27)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/bitgo/keyutil.ts:3:1)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/bitgo/index.ts:2:1)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/index.ts:3:1)
      at Object.<anonymous> (src/hooks/useWallet.js:5:1)
      at Object.<anonymous> (src/utils/context.js:3:1)
      at Object.<anonymous> (src/components/Configure/Configure.js:30:1)
      at Object.<anonymous> (src/components/Configure/__tests__/Configure.test.js:5:1)

FAIL src/components/Tokens/__tests__/CreateTokenForm.test.js
  ● Test suite failed to run

    ecc library invalid

      10 | import bs58 from 'bs58';
      11 | import * as slpMdm from 'slp-mdm';
    > 12 | import * as utxolib from '@bitgo/utxo-lib';
         | ^
      13 |
      14 | // function is based on BCH-JS' generateBurnOpReturn() however it's been trimmed down for Cashtab use
      15 | // Reference: https://github.com/Permissionless-Software-Foundation/bch-js/blob/62e56c832b35731880fe448269818b853c76dd80/src/slp/tokentype1.js#L217

      at assert (node_modules/ecpair/src/testecc.js:231:20)
      at testEcc (node_modules/ecpair/src/testecc.js:6:3)
      at Object.ECPairFactory (node_modules/ecpair/src/ecpair.js:19:25)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/noble_ecc.ts:98:27)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/bitgo/keyutil.ts:3:1)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/bitgo/index.ts:2:1)
      at Object.<anonymous> (node_modules/@bitgo/utxo-lib/src/index.ts:3:1)
      at Object.<anonymous> (src/utils/cashMethods.js:12:1)
      at Object.<anonymous> (src/utils/validation.js:3:1)
      at Object.<anonymous> (src/components/Common/ScanQRCode.js:9:1)
      at Object.<anonymous> (src/components/Common/EnhancedInputs.js:9:1)
      at Object.<anonymous> (src/components/Tokens/CreateTokenForm.js:4:1)
      at Object.<anonymous> (src/components/Tokens/__tests__/CreateTokenForm.test.js:5:1)


Test Suites: 16 failed, 5 passed, 21 total
Tests:       43 passed, 43 total
Snapshots:   2 passed, 2 total
Time:        10.056 s
Ran all test suites.
Build cashtab-tests failed with exit code 1
  • Need to resolve the "breaks every unit test" issue
  • Need to add tx builder support to the library
  • Need to evaluate the bitcoinjs-lib upgrade / replacement of tx builder

Next steps

  • New diff that implements the bitgo library, since completely mangled this branch in troubleshooting for this fix
  • The above fix does not resolve all unit testing, it patches the import error. There are some changes in mocks / expected values from using this new library that need to be addressed. IMO this is worth it as, with this library, we are actually using the proper ecash info, so we move away completely from BCH artifacts in TransactionBuilder.
  • Add native support for ecash transactions to the Bitgo module so that Cashtab does not need any shims, and other devs can also use the library without any shims