Page MenuHomePhabricator

[ecashaddrjs] Add function to support conversion to legacy format
ClosedPublic

Authored by bytesofman on Apr 10 2023, 17:45.

Details

Summary

T3096

Going forward, we will use utxo-lib and bitcoinjs-message for javascript applications that create transactions and sign / verify msgs.

These libraries are robust and well maintained. However, they require address input format to be legacy.

Include a toLegacy function in ecashaddrjs to support future implementation of above libraries.

Test Plan

npm test

Diff Detail

Repository
rABC Bitcoin ABC
Branch
add-tolegacy
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 23176
Build 45971: Build Diff
Build 45970: arc lint + arc unit

Event Timeline

Move new unit tests after existing unit tests

add a unit test case for failure to convert

Fabien requested changes to this revision.Apr 10 2023, 19:18
Fabien added a subscriber: Fabien.
Fabien added inline comments.
modules/ecashaddrjs/src/cashaddr.js
526

It would be more robust to check isTestnet as !isMainnet. E.g. ecregtest prefix are testnet wrt cash address format.
Also we tend to add test nets over time but not main nets.

This revision now requires changes to proceed.Apr 10 2023, 19:18

Improve check for mainnet or testnet

modules/ecashaddrjs/src/cashaddr.js
526
var VALID_PREFIXES = [
    'ecash',
    'bitcoincash',
    'simpleledger',
    'etoken',
    'ectest',
    'bchtest',
    'bchreg',
];

E.g. ecregtest prefix are testnet wrt cash address format.

Is this a prefix that should be added to VALID_PREFIXES ?

is bchreg a testnet address?

Fabien added inline comments.
modules/ecashaddrjs/src/cashaddr.js
526

ecregtest and bchreg are both used for regression testing, so not a live chain. Supporting them depends on how you plan to use the lib, but I think you should have none or both. Both are testnet addresses as per address encoding.

This revision is now accepted and ready to land.Apr 11 2023, 04:56