diff --git a/.github/main.yaml b/.github/workflows/main.yaml similarity index 100% rename from .github/main.yaml rename to .github/workflows/main.yaml diff --git a/.github/publish.yaml b/.github/workflows/publish.yaml similarity index 100% rename from .github/publish.yaml rename to .github/workflows/publish.yaml diff --git a/README.md b/README.md index 217a0a2..c991b21 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ For a smooth and quick integration: #### Table of Contents * [bippath](#bippath) -* [Btc](#btc) +* [Acre](#acre) * [Parameters](#parameters) * [Examples](#examples) * [getWalletXpub](#getwalletxpub) @@ -55,7 +55,7 @@ For a smooth and quick integration: * [Parameters](#parameters-8) * [getTrustedInputBIP143](#gettrustedinputbip143) * [Parameters](#parameters-9) -* [BtcNew](#btcnew) +* [AcreBtcNew](#acrebtcnew) * [getWalletXpub](#getwalletxpub-1) * [Parameters](#parameters-10) * [getWalletPublicKey](#getwalletpublickey-1) @@ -68,7 +68,7 @@ For a smooth and quick integration: * [Parameters](#parameters-14) * [descrTemplFrom](#descrtemplfrom) * [Parameters](#parameters-15) -* [BtcOld](#btcold) +* [AcreBtcOld](#acrebtcold) * [getWalletPublicKey](#getwalletpublickey-2) * [Parameters](#parameters-16) * [Examples](#examples-7) @@ -130,9 +130,9 @@ which are commonly used in hierarchical deterministic (HD) wallets. It includes functions to convert BIP32 paths to and from different formats, extract components from extended public keys (xpubs), and manipulate path elements. -### Btc +### Acre -Bitcoin API. +Acre app API. #### Parameters @@ -143,8 +143,8 @@ Bitcoin API. #### Examples ```javascript -import Btc from "@blooo/hw-app-acre:"; -const btc = new Btc({ transport, currency: "bitcoin" }); +import Acre from "@blooo/hw-app-acre:"; +const acre = new Acre({ transport, currency: "bitcoin" }); ``` #### getWalletXpub @@ -181,8 +181,8 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/ ##### Examples ```javascript -btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) -btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) +acre.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) +acre.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), bitcoinAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), chainCode: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** @@ -199,7 +199,7 @@ You can sign a message according to the Bitcoin Signature format and retrieve v, ##### Examples ```javascript -btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) { +acre.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) { var v = result['v'] + 27 + 4; var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64'); console.log("Signature : " + signature); @@ -239,7 +239,7 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction ##### Examples ```javascript -btc.createTransaction({ +acre.createTransaction({ inputs: [ [tx1, 1] ], associatedKeysets: ["0'/0/0"], outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" @@ -267,7 +267,7 @@ To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransactio ##### Examples ```javascript -btc.signP2SHTransaction({ +acre.signP2SHTransaction({ inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ], associatedKeysets: ["0'/0/0"], outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" @@ -290,7 +290,7 @@ For each UTXO included in your transaction, create a transaction object from the ##### Examples ```javascript -const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); +const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); ``` Returns **[Transaction](#transaction)** the transaction object deserialized from the raw hexadecimal transaction @@ -306,8 +306,8 @@ Serialize a transaction's outputs to hexadecimal ##### Examples ```javascript -const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); -const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); +const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); +const outputScript = acre.serializeTransactionOutputs(tx1).toString('hex'); ``` Returns **[Buffer](https://nodejs.org/api/buffer.html)** @@ -338,19 +338,17 @@ Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** -### BtcNew +### AcreBtcNew -This class implements the same interface as BtcOld (formerly -named Btc), but interacts with Bitcoin hardware app version 2.1.0+ -which uses a totally new APDU protocol. This new -protocol is documented at - +This class implements the same interface as AcreBtcOld (formerly +named Btc), but interacts with Acre hardware app from version 1.0.0 +which uses the same APDU protocol as the Bitcoin app version 2.1.0+. +This protocol is documented at + -Since the interface must remain compatible with BtcOld, the methods +Since the interface must remain compatible with AcreBtcOld, the methods of this class are quite clunky, because it needs to adapt legacy -input data into the PSBT process. In the future, a new interface should -be developed that exposes PSBT to the outer world, which would render -a much cleaner implementation. +input data into the PSBT process. #### getWalletXpub @@ -409,7 +407,7 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/ #### createPaymentTransaction -Build and sign a transaction. See Btc.createPaymentTransaction for +Build and sign a transaction. See Acre.createPaymentTransaction for details on how to use this method. This method will convert the legacy arguments, CreateTransactionArg, into @@ -464,7 +462,7 @@ the bitcoin descriptor template. Returns **DefaultDescriptorTemplate** -### BtcOld +### AcreBtcOld This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 @@ -489,8 +487,8 @@ This Bitcoin old API is compatible with versions of the Bitcoin nano app that ar ##### Examples ```javascript -btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) -btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) +acre.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) +acre.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) ``` Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), bitcoinAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), chainCode: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** @@ -525,7 +523,7 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction ##### Examples ```javascript -btc.createTransaction({ +acre.createTransaction({ inputs: [ [tx1, 1] ], associatedKeysets: ["0'/0/0"], outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" @@ -829,8 +827,8 @@ complemantary fields as needed in the future. #### Examples ```javascript -const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); -const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); +const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); +const outputScript = acre.serializeTransactionOutputs(tx1).toString('hex'); ``` Returns **[Buffer](https://nodejs.org/api/buffer.html)** diff --git a/jest.config.ts b/jest.config.ts index 52d8fc7..2ab8eb0 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -5,7 +5,7 @@ export default { collectCoverage: true, testPathIgnorePatterns: ["packages/*/lib-es", "packages/*/lib"], coveragePathIgnorePatterns: ["packages/create-dapp"], - testMatch: ["**/tests/newops/BtcNew.test.ts"], + testMatch: ["**/tests/newops/AcreBtcNew.test.ts"], passWithNoTests: true, // collectCoverageFrom: ["packages/**/src/*.ts"], rootDir: __dirname, diff --git a/package.json b/package.json index c0006e9..b1675c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@blooo/hw-app-acre", - "version": "1.0.0", + "version": "1.0.1", "description": "Ledger Hardware Wallet Acre Application API", "keywords": [ "Ledger", @@ -23,9 +23,9 @@ "publishConfig": { "access": "public" }, - "main": "lib/Btc.js", - "module": "lib-es/Btc.js", - "types": "lib/Btc.d.ts", + "main": "lib/Acre.js", + "module": "lib-es/Acre.js", + "types": "lib/Acre.d.ts", "typesVersions": { "*": { "lib/*": [ @@ -36,7 +36,7 @@ ], "*": [ "lib/*", - "lib/Btc.d.ts" + "lib/Acre.d.ts" ] } }, @@ -54,15 +54,15 @@ "default": "./lib-es/*.js" }, ".": { - "require": "./lib/Btc.js", - "default": "./lib-es/Btc.js" + "require": "./lib/Acre.js", + "default": "./lib-es/Acre.js" }, "./package.json": "./package.json" }, "license": "Apache-2.0", "dependencies": { - "@ledgerhq/hw-transport": "workspace:^", - "@ledgerhq/logs": "workspace:^", + "@ledgerhq/hw-transport": "6.31.3", + "@ledgerhq/logs": "6.12.0", "bip32-path": "^0.4.2", "bitcoinjs-lib": "^5.2.0", "bs58": "^4.0.1", @@ -76,8 +76,8 @@ "varuint-bitcoin": "1.1.2" }, "devDependencies": { - "@ledgerhq/hw-transport-mocker": "workspace:^", - "@ledgerhq/hw-transport-node-speculos": "workspace:^", + "@ledgerhq/hw-transport-mocker": "6.29.3", + "@ledgerhq/hw-transport-node-speculos": "6.29.3", "@types/jest": "^29.5.10", "@types/node": "^20.8.10", "axios": "^0.25.0", diff --git a/src/Btc.ts b/src/Acre.ts similarity index 85% rename from src/Btc.ts rename to src/Acre.ts index 77117ed..140b049 100644 --- a/src/Btc.ts +++ b/src/Acre.ts @@ -1,7 +1,7 @@ import semver from "semver"; import type Transport from "@ledgerhq/hw-transport"; -import BtcNew from "./BtcNew"; -import BtcOld from "./BtcOld"; +import AcreBtcNew from "./AcreBtcNew"; +import AcreBtcOld from "./AcreBtcOld"; import type { CreateTransactionArg } from "./createTransaction"; import { getTrustedInput } from "./getTrustedInput"; import { getTrustedInputBIP143 } from "./getTrustedInputBIP143"; @@ -16,22 +16,22 @@ import { signP2SHTransaction } from "./signP2SHTransaction"; import { checkIsBtcLegacy, getAppAndVersion } from "./getAppAndVersion"; /** - * @class Btc + * @class Acre * @description Bitcoin API. * @param transport The transport layer used for communication. * @param scrambleKey This parameter is deprecated and no longer needed. * @param currency The currency to use, defaults to "bitcoin". * @example - * import Btc from "@blooo/hw-app-acre:"; - * const btc = new Btc({ transport, currency: "bitcoin" }); + * import Acre from "@blooo/hw-app-acre:"; + * const acre = new Acre({ transport, currency: "bitcoin" }); */ -export default class Btc { +export default class Acre { // Transport instance private _transport: Transport; // The specific implementation used, determined by the nano app and its version. - // It chooses between BtcNew (new interface) and BtcOld (old interface). - private _impl: BtcOld | BtcNew; + // It chooses between AcreBtcNew (current acre interface) and AcreBtcOld (old bitcoin interface). + private _impl: AcreBtcOld | AcreBtcNew; constructor({ transport, scrambleKey = "BTC", @@ -62,10 +62,10 @@ export default class Btc { case "bitcoin_testnet": case "qtum": // new APDU (nano app API) for currencies using app-bitcoin-new implementation - return new BtcNew(new AppClient(this._transport)); + return new AcreBtcNew(new AppClient(this._transport)); default: // old APDU (legacy API) for currencies using legacy bitcoin app implementation - return new BtcOld(this._transport); + return new AcreBtcOld(this._transport); } })(); } @@ -106,8 +106,8 @@ export default class Btc { * - cashaddr in case of Bitcoin Cash * * @example - * btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) - * btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) + * acre.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) + * acre.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) */ getWalletPublicKey( path: string, @@ -123,7 +123,7 @@ export default class Btc { let options; if (arguments.length > 2 || typeof opts === "boolean") { console.warn( - "btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })", + "acre.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })", ); options = { verify: !!opts, @@ -141,7 +141,7 @@ export default class Btc { /** * You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign. * @example - btc.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) { + acre.signMessage("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) { var v = result['v'] + 27 + 4; var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64'); console.log("Signature : " + signature); @@ -179,7 +179,7 @@ export default class Btc { nonce: "0xC", }; const path = "m/44'/0'/0'/0/0"; - const result = await btc.signWithdrawal({path: path, withdrawalData: withdrawalData}); + const result = await acre.signWithdrawal({path: path, withdrawalData: withdrawalData}); */ signWithdrawal( path: string, @@ -225,7 +225,7 @@ export default class Btc { * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true. * @return the signed transaction ready to be broadcast * @example - btc.createTransaction({ + acre.createTransaction({ inputs: [ [tx1, 1] ], associatedKeysets: ["0'/0/0"], outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" @@ -255,7 +255,7 @@ export default class Btc { * @param sigHashType is the hash type of the transaction to sign, or default (all) * @return the signed transaction ready to be broadcast * @example - btc.signP2SHTransaction({ + acre.signP2SHTransaction({ inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ], associatedKeysets: ["0'/0/0"], outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" @@ -273,7 +273,7 @@ export default class Btc { * @param additionals list of additionnal options * @return the transaction object deserialized from the raw hexadecimal transaction * @example - const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); + const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); */ splitTransaction( transactionHex: string, @@ -287,8 +287,8 @@ export default class Btc { /** * Serialize a transaction's outputs to hexadecimal * @example - const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); - const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); + const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); + const outputScript = acre.serializeTransactionOutputs(tx1).toString('hex'); */ serializeTransactionOutputs(t: Transaction): Buffer { return serializeTransactionOutputs(t); @@ -318,9 +318,8 @@ export default class Btc { return getTrustedInputBIP143(this._transport, indexLookup, transaction, additionals); } - async changeImplIfNecessary(): Promise { - // if BtcOld was instantiated, stick with it - if (this._impl instanceof BtcOld) return this._impl; + async changeImplIfNecessary(): Promise { + if (this._impl instanceof AcreBtcOld) return this._impl; const { name, version } = await getAppAndVersion(this._transport); @@ -353,7 +352,7 @@ export default class Btc { })(); if (isBtcLegacy) { - this._impl = new BtcOld(this._transport); + this._impl = new AcreBtcOld(this._transport); } return this._impl; } diff --git a/src/BtcNew.ts b/src/AcreBtcNew.ts similarity index 98% rename from src/BtcNew.ts rename to src/AcreBtcNew.ts index 6a754b2..d5765b6 100644 --- a/src/BtcNew.ts +++ b/src/AcreBtcNew.ts @@ -28,21 +28,21 @@ import type { Transaction, AcreWithdrawalData, AcreWithdrawalDataBuffer } from " import { log } from "@ledgerhq/logs"; /** - * @class BtcNew - * @description This class implements the same interface as BtcOld (formerly + * @class AcreBtcNew + * @description This class implements the same interface as AcreBtcOld (formerly * named Btc), but interacts with Bitcoin hardware app version 2.1.0+ * which uses a totally new APDU protocol. This new * protocol is documented at * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md * - * Since the interface must remain compatible with BtcOld, the methods + * Since the interface must remain compatible with AcreBtcOld, the methods * of this class are quite clunky, because it needs to adapt legacy * input data into the PSBT process. In the future, a new interface should * be developed that exposes PSBT to the outer world, which would render * a much cleaner implementation. * */ -export default class BtcNew { +export default class AcreBtcNew { constructor(private client: Client) {} /** @@ -174,7 +174,7 @@ export default class BtcNew { } /** - * Build and sign a transaction. See Btc.createPaymentTransaction for + * Build and sign a transaction. See Acre.createPaymentTransaction for * details on how to use this method. * * This method will convert the legacy arguments, CreateTransactionArg, into @@ -559,7 +559,7 @@ function accountTypeFromArg( Useful resource on derivation paths: https://learnmeabitcoin.com/technical/derivation-paths */ -//path is not deepest hardened node of a standard path or deeper, use BtcOld +//path is not deepest hardened node of a standard path or deeper, use AcreBtcOld const H = 0x80000000; //HARDENED from bip32 const VALID_COIN_TYPES = [ diff --git a/src/BtcOld.ts b/src/AcreBtcOld.ts similarity index 93% rename from src/BtcOld.ts rename to src/AcreBtcOld.ts index 0c2f59f..46169ad 100644 --- a/src/BtcOld.ts +++ b/src/AcreBtcOld.ts @@ -12,12 +12,12 @@ import { AcreWithdrawalData } from "./types"; export type { AddressFormat }; /** - * @class BtcOld + * @class AcreBtcOld * @description This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 * */ -export default class BtcOld { +export default class AcreBtcOld { constructor(private transport: Transport) {} private derivationsCache = {}; @@ -76,8 +76,8 @@ export default class BtcOld { * - cashaddr in case of Bitcoin Cash * * @example - * btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) - * btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) + * acre.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) + * acre.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) */ getWalletPublicKey( path: string, @@ -123,7 +123,7 @@ export default class BtcOld { * @param useTrustedInputForSegwit trust inputs for segwit transactions * @return the signed transaction ready to be broadcast * @example - btc.createTransaction({ + acre.createTransaction({ inputs: [ [tx1, 1] ], associatedKeysets: ["0'/0/0"], outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" @@ -150,7 +150,7 @@ export default class BtcOld { } /** - * This function will never be called from a BtcOld context, it is only delcared here for compatibility with + * This function will never be called from a AcreBtcOld context, it is only delcared here for compatibility with * the current framework, throwing an error in case it is ever reached. */ async signWithdrawal({ path, withdrawalData }: { path: string; withdrawalData: AcreWithdrawalData }): Promise<{ @@ -159,7 +159,7 @@ export default class BtcOld { s: string; }> { throw new Error( - "@blooo/hw-app-acre: Acre Withdrawal transaction is not compatible with the legacy BtcOld client. Please use the BtcNew client", + "@blooo/hw-app-acre: Acre Withdrawal transaction is not compatible with the legacy AcreBtcOld client. Please use the AcreBtcNew client", ); } } diff --git a/src/getAppAndVersion.ts b/src/getAppAndVersion.ts index 7795b9b..20e81e5 100644 --- a/src/getAppAndVersion.ts +++ b/src/getAppAndVersion.ts @@ -27,7 +27,7 @@ export const getAppAndVersion = async (transport: Transport): Promise => { try { - // Call old btc API, it will throw an exception with new btc app. It is a workaround to differentiate new/old btc nano app + // Call old btc API, it will throw an exception with acre app (based on the new btc app). await transport.send(0xe0, 0xc4, 0, 0); } catch (e: unknown) { return false; diff --git a/src/getWalletPublicKey.ts b/src/getWalletPublicKey.ts index 7117e26..3043089 100644 --- a/src/getWalletPublicKey.ts +++ b/src/getWalletPublicKey.ts @@ -30,7 +30,7 @@ export async function getWalletPublicKey( }; if (!(format in addressFormatMap)) { - throw new Error("btc.getWalletPublicKey invalid format=" + format); + throw new Error("acre.getWalletPublicKey invalid format=" + format); } const buffer = bip32asBuffer(path); diff --git a/src/index.ts b/src/index.ts index c6243fb..57cd37b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -import Btc from "./Btc"; -export default Btc; +import Acre from "./Acre"; +export default Acre; diff --git a/src/serializeTransaction.ts b/src/serializeTransaction.ts index bb2142c..fb68b62 100644 --- a/src/serializeTransaction.ts +++ b/src/serializeTransaction.ts @@ -3,8 +3,8 @@ import { createVarint } from "./varint"; /** @example -const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); -const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); +const tx1 = acre.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); +const outputScript = acre.serializeTransactionOutputs(tx1).toString('hex'); */ export function serializeTransactionOutputs({ outputs }: Transaction): Buffer { let outputBuffer = Buffer.alloc(0); diff --git a/src/splitTransaction.ts b/src/splitTransaction.ts index 7bf211e..8b7ef8e 100644 --- a/src/splitTransaction.ts +++ b/src/splitTransaction.ts @@ -154,6 +154,6 @@ export function splitTransaction( nExpiryHeight, extraData, }; - log("btc", `splitTransaction ${transactionHex}:\n${formatTransactionDebug(t)}`); + log("acre", `splitTransaction ${transactionHex}:\n${formatTransactionDebug(t)}`); return t; } diff --git a/tests/Btc.integration.test.ts.disabled b/tests/Acre.integration.test.ts.disabled similarity index 91% rename from tests/Btc.integration.test.ts.disabled rename to tests/Acre.integration.test.ts.disabled index 27cbb53..e87705c 100644 --- a/tests/Btc.integration.test.ts.disabled +++ b/tests/Acre.integration.test.ts.disabled @@ -2,8 +2,8 @@ import Transport from "@ledgerhq/hw-transport"; import SpeculosTransport from "@ledgerhq/hw-transport-node-speculos"; import { getXpubComponents } from "../src/bip32"; -import Btc from "../src/Btc"; -import BtcNew from "../src/BtcNew"; +import Acre from "../src/Acre"; +import AcreBtcNew from "../src/AcreBtcNew"; import { compressPublicKey } from "../src/compressPublicKey"; import { AppClient } from "../src/newops/appClient"; import { runSignTransaction, TestingClient } from "./newops/integrationtools"; @@ -38,10 +38,10 @@ const xpubs = { // async function listAddresses(paths: string[], addressFormat: AddressFormat) { // const tr = await transport(); // const client = new AppClient(tr); -// const btc = new BtcNew(client); +// const acre = new AcreBtcNew(client); // let result = ""; // for (let i = 0; i < paths.length; i++) { -// const addr = await btc.getWalletPublicKey(paths[i], { +// const addr = await acre.getWalletPublicKey(paths[i], { // format: addressFormat, // }); // result += paths[i] + ": " + addr.bitcoinAddress + "\n"; @@ -140,11 +140,7 @@ function checkIgnoreWitness(testTx: CoreTx, actualTx: string) { expect(actBaseTx).toEqual(expBaseTx); } -test("getWalletPublicKey BtcOld", async () => { - await runGetWalletPublicKey("old"); -}); - -test("getWalletPublicKey BtcNew", async () => { +test("getWalletPublicKey AcreBtcNew", async () => { await runGetWalletPublicKey("new"); }); @@ -155,13 +151,13 @@ async function transport(): Promise { async function impl( variant: "old" | "new", transport: Transport -): Promise { +): Promise { if (variant === "old") { - return new Btc(transport); + return new Acre(transport); } const client = new AppClient(transport); - const btc = new BtcNew(client); - return btc; + const acre = new AcreBtcNew(client); + return acre; } async function runGetWalletPublicKey(variant: "old" | "new") { @@ -173,9 +169,9 @@ async function runGetWalletPublicKey(variant: "old" | "new") { return; } try { - const btc = await impl(variant, tr); + const acre = await impl(variant, tr); - const account = await btc.getWalletPublicKey("m/44'/1'/0'"); + const account = await acre.getWalletPublicKey("m/44'/1'/0'"); const expectedAccount = getXpubComponents(xpubs["m/44'/1'/0'"]); const uncompressesPubkey = @@ -189,7 +185,7 @@ async function runGetWalletPublicKey(variant: "old" | "new") { ); expect(account.publicKey).toEqual(uncompressesPubkey); - const keydata = await btc.getWalletPublicKey("m/44'/1'/0'/0/0"); + const keydata = await acre.getWalletPublicKey("m/44'/1'/0'/0/0"); expect(keydata.bitcoinAddress).toEqual( "mz5vLWdM1wHVGSmXUkhKVvZbJ2g4epMXSm" ); diff --git a/tests/Acre.test.ts.disabled b/tests/Acre.test.ts.disabled new file mode 100644 index 0000000..386c961 --- /dev/null +++ b/tests/Acre.test.ts.disabled @@ -0,0 +1,153 @@ +import { + openTransportReplayer, + RecordStore, +} from "@ledgerhq/hw-transport-mocker"; +import Acre from "../src/Acre"; + +test("btc 3", async () => { + const transport = await openTransportReplayer( + RecordStore.fromString(` + => e042000009000000010100000001 + <= 9000 + => e0428000254ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a + <= 9000 + => e04280003247304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f + <= 9000 + => e04280003257c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7 + <= 9000 + => e04280002a325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff + <= 9000 + => e04280000102 + <= 9000 + => e04280002281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac + <= 9000 + => e042800022a0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac + <= 9000 + => e04280000400000000 + <= 3200e4eac773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f1001000000a086010000000000c79483cc9a6e96fe9000 + => e0440000050100000001 + <= 9000 + => e04480002600c773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f100100000069 + <= 9000 + => e04480003252210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04b + <= 9000 + => e044800032d40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc5 + <= 9000 + => e04480000900639853aeffffffff + <= 9000 + => e04a80002301905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac + <= 00009000 + => e04800001303800000000000000000000000000000000001 + <= 3045022100b5b1813992282b9a1fdd957b9751d79dc21018abc6586336e272212cc89cfe84022053765a1da0bdb5a0631a9866f1fd4c583589d5188b11cfa302fc20cd2611a71e019000 + `) + ); + const acre = new Acre({ transport }); + const tx1 = acre.splitTransaction( + "01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000" + ); + const result = await acre.signP2SHTransaction({ + inputs: [ + [ + tx1, + 1, + "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae", + undefined, + ], + ], + associatedKeysets: ["0'/0/0"], + outputScriptHex: + "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac", + }); + expect(result).toEqual([ + "3045022100b5b1813992282b9a1fdd957b9751d79dc21018abc6586336e272212cc89cfe84022053765a1da0bdb5a0631a9866f1fd4c583589d5188b11cfa302fc20cd2611a71e", + ]); +}); + +test("btc 4", async () => { + const transport = await openTransportReplayer( + RecordStore.fromString(` + => e04e000117048000002c800000008000000000000000000474657374 + <= 00009000 + => e04e80000100 + <= 3045022100e32b32b8a6b4228155ba4d1a536d8fed9900606663fbbf4ea420ed8e944f9c18022053c97c74d2f6d8620d060584dc7886f5f3003684bb249508eb7066215172281a9000 + `) + ); + const acre = new Acre({ transport }); + const result = await acre.signMessage( + "44'/0'/0'/0", + Buffer.from("test").toString("hex") + ); + expect(result).toEqual({ + r: "e32b32b8a6b4228155ba4d1a536d8fed9900606663fbbf4ea420ed8e944f9c18", + s: "53c97c74d2f6d8620d060584dc7886f5f3003684bb249508eb7066215172281a", + v: 0, + }); +}); + +test("acre sign p2sh seg", async () => { + const transport = await openTransportReplayer( + RecordStore.fromString(` + => e0440002050100000001 + <= 9000 + => e04480022e021ba3852a59cded8d2760434fa75af58a617b21e4fbe1cf9c826ea2f14f80927d00000000102700000000000000 + <= 9000 + => e044800204ffffffff + <= 9000 + => e04a8000230188130000000000001976a9140ae1441568d0d293764a347b191025c51556cecd88ac + <= 00009000 + => e0440080050100000001 + <= 9000 + => e04480802e021ba3852a59cded8d2760434fa75af58a617b21e4fbe1cf9c826ea2f14f80927d00000000102700000000000047 + <= 9000 + => e0448080325121026666422d00f1b308fc7527198749f06fedb028b979c09f60d0348ef79c985e41210384257cf895f1ca492bbee5d748 + <= 9000 + => e0448080195ae0ef479036fdf59e15b92e37970a98d6fe7552aeffffffff + <= 9000 + => e04800001303800000000000000000000000000000000001 + <= 3045022100932934ee326c19c81b72fb03cec0fb79ff980a8076639f77c7edec35bd59da1e02205e4030e8e0fd2405f6db2fe044c49d3f191adbdc0e05ec7ed4dcc4c6fe7310e5019000 + `) + ); + const acre = new Acre({ transport }); + const tx1 = acre.splitTransaction( + "0100000001d3a05cd6e15582f40e68bb8b1559dc9e5b3e4f9f34d92c1217dc8c3355bc844e010000008a47304402207ab1a4768cbb036d4bce3c4a294c13cc5ae6076fc7bedce88c62aa80ae366da702204f8fea6923f8df36315c0c26cb42d8d7ab52ca4736776816e10d6ce51906d0600141044289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34cec320a0565fb7caf11b1ca2f445f9b7b012dda5718b3cface369ee3a034ded6ffffffff02102700000000000017a9141188cc3c265fbc01a025fc8adec9823effd0cef187185f9265170100001976a9140ae1441568d0d293764a347b191025c51556cecd88ac00000000", + true + ); + const result = await acre.signP2SHTransaction({ + inputs: [ + [ + tx1, + 0, + "5121026666422d00f1b308fc7527198749f06fedb028b979c09f60d0348ef79c985e41210384257cf895f1ca492bbee5d7485ae0ef479036fdf59e15b92e37970a98d6fe7552ae", + undefined, + ], + ], + associatedKeysets: ["0'/0/0"], + outputScriptHex: + "0188130000000000001976a9140ae1441568d0d293764a347b191025c51556cecd88ac", + segwit: true, + }); + expect(result).toEqual([ + "3045022100932934ee326c19c81b72fb03cec0fb79ff980a8076639f77c7edec35bd59da1e02205e4030e8e0fd2405f6db2fe044c49d3f191adbdc0e05ec7ed4dcc4c6fe7310e501", + ]); +}); + +test("signMessage", async () => { + const transport = await openTransportReplayer( + RecordStore.fromString(` + => e04e00011d058000002c800000008000000000000000000000000006666f6f626172 + <= 00009000 + => e04e80000100 + <= 314402205eac720be544d3959a760d9bfd6a0e7c86d128fd1030038f06d85822608804e20220385d83273c9d03c469596292fb354b07d193034f83c2633a4c1f057838e12a5b9000 + `) + ); + const acre = new Acre({ transport }); + const res = await acre.signMessage( + "44'/0'/0'/0/0", + Buffer.from("foobar").toString("hex") + ); + expect(res).toEqual({ + v: 1, + r: "5eac720be544d3959a760d9bfd6a0e7c86d128fd1030038f06d85822608804e2", + s: "385d83273c9d03c469596292fb354b07d193034f83c2633a4c1f057838e12a5b", + }); +}); diff --git a/tests/Btc.test.ts.disabled b/tests/Btc.test.ts.disabled deleted file mode 100644 index ec0f19c..0000000 --- a/tests/Btc.test.ts.disabled +++ /dev/null @@ -1,419 +0,0 @@ -import { - openTransportReplayer, - RecordStore, -} from "@ledgerhq/hw-transport-mocker"; -import Btc from "../src/Btc"; - -test("btc.getWalletXpub", async () => { - /* -This is how I generate the xpub -Mainnet: -prv: 0x0488ade4 = 76066276 -pub: 0x0488b21e = 76067358 -Testnet: -prv: 0x04358394 = 70615956 -pub: 0x043587cf = 70617039 -versionpriv=70615956 -versionpub=70617039 -seed=be388c569b4a6846c847e882e09f000000000000000000000000e255bcd17cb8 -m=`bx hd-new -v $versionpriv $seed` -m_44h=`bx hd-private -d --index 44 $m` -m_44h_0h=`bx hd-private -d --index 0 $m_44h` -M_44h_0h=`bx hd-to-public -v $versionpub $m_44h_0h` -m_44h_0h_17h=`bx hd-private -d --index 17 $m_44h_0h` -M_44h_0h_17h=`bx hd-to-public -v $versionpub $m_44h_0h_17h` -echo "M_44h_0h_17h xpub: $M_44h_0h_17h" -echo "M_44h_0h: `bx base58check-decode $M_44h_0h`" -echo "M_44h_0h_17h: `bx base58check-decode $M_44h_0h_17h`" -Output (note that version (4) should be prepended to payload): -M_44h_0h_17h xpub: tpubDDn3XrB65rhCzRh4fsD8gogX9gFvGcEmP3jZtGbdxK7Mn25gipFB68vLFyqZ43i4e5Z7p6rki7THyb2PeH1D3NkLm5EUFzbUzyafp872GKa -M_44h_0h: wrapper -{ - checksum 2142374336 - payload 3587cf026d874e2b800000008bd937d416de7020952cc8e2c99ce9ac7e01265e31ceb8e47bf9c3 -7f46f8abbd035d4a72237572a91e13818fa38cedabe6174569cc9a319012f75150d5c0a0639d - version 4 -} -M_44h_0h_17h: wrapper -{ - checksum 4186623970 - payload 3587cf03ee6e81fd80000011c071c6f2d05cbc9ea9a04951b238086ce1608cf00020c3cab85b36 -aac5fdd59102250dfdfb84c1efd160ed0e10ebac845d0e4b04277174630ba56de96bbd3afb21 - version 4 -} -The xpub bytes (from bip32) are -4 byte: version bytes (mainnet: 0x0488B21E public, 0x0488ADE4 private; testnet: 0x043587CF public, 0x04358394 private) -1 byte: depth: 0x00 for master nodes, 0x01 for level-1 derived keys, .... -4 bytes: the fingerprint of the parent's key (0x00000000 if master key) -4 bytes: child number. This is ser32(i) for i in xi = xpar/i, with xi the key being serialized. (0x00000000 if master key) -32 bytes: the chain code -33 bytes: the public key or private key data (serP(K) for public keys, 0x00 || ser256(k) for private keys) -M_44h_0h_17h: -043587cf -03 -ee6e81fd -80000011 -c071c6f2d05cbc9ea9a04951b238086ce1608cf00020c3cab85b36aac5fdd591 -02250dfdfb84c1efd160ed0e10ebac845d0e4b04277174630ba56de96bbd3afb21 -M_44h_0h: -043587cf -02 -6d874e2b -80000000 -8bd937d416de7020952cc8e2c99ce9ac7e01265e31ceb8e47bf9c37f46f8abbd -035d4a72237572a91e13818fa38cedabe6174569cc9a319012f75150d5c0a0639d -Uncompress (a bit covoluted, but works): -prv=`bx hd-to-ec -p $versionpriv $m_44h_0h_17h` -bx ec-to-public -u ${prv:2} -04250dfdfb84c1efd160ed0e10ebac845d0e4b04277174630ba56de96bbd3afb21fc6c04ce0d5a0cbd784fdabc99d16269c27cf3842fe8440f1f21b8af900f0eaa -pubCompr=`bx ec-to-public ${prv:2}` -bx ec-to-address $pubCompr -16Y97ByhyboePhTYMMmFj1tq5Cy1bDq8jT -prv=`bx hd-to-ec -p $versionpriv $m_44h_0h` -bx ec-to-public -u ${prv:2} -045d4a72237572a91e13818fa38cedabe6174569cc9a319012f75150d5c0a0639d54eafd13a68d079b7a67764800c6a981825ef52384f08c3925109188ab21bc09 -pubCompr=`bx ec-to-public ${prv:2}` -bx ec-to-address $pubCompr -1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb -These translates to - pubkeylen(1) || pubkeyuncompressed(65) || addrLen(1) || address || chaincode(32) -Expected response for m/44'/0'/17': -41 -04250dfdfb84c1efd160ed0e10ebac845d0e4b04277174630ba56de96bbd3afb21fc6c04ce0d5a0cbd784fdabc99d16269c27cf3842fe8440f1f21b8af900f0eaa -22 -ascii(16Y97ByhyboePhTYMMmFj1tq5Cy1bDq8jT) -c071c6f2d05cbc9ea9a04951b238086ce1608cf00020c3cab85b36aac5fdd591 -Expected response for m/44'/0': -41 -045d4a72237572a91e13818fa38cedabe6174569cc9a319012f75150d5c0a0639d54eafd13a68d079b7a67764800c6a981825ef52384f08c3925109188ab21bc09 -22 -ascii(1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb) -8bd937d416de7020952cc8e2c99ce9ac7e01265e31ceb8e47bf9c37f46f8abbd -*/ - /*eslint-disable */ - const pubkeyParent = - "045d4a72237572a91e13818fa38cedabe6174569cc9a319012f75150d5c0a0639d54eafd13a68d079b7a67764800c6a981825ef52384f08c3925109188ab21bc09"; - const addrParent = Buffer.from( - "1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb", - "ascii" - ).toString("hex"); - const ccParent = - "8bd937d416de7020952cc8e2c99ce9ac7e01265e31ceb8e47bf9c37f46f8abbd"; - const responseParent = `41${pubkeyParent}22${addrParent}${ccParent}`; - - const pubkeyAcc = - "04250dfdfb84c1efd160ed0e10ebac845d0e4b04277174630ba56de96bbd3afb21fc6c04ce0d5a0cbd784fdabc99d16269c27cf3842fe8440f1f21b8af900f0eaa"; - const addrAcc = Buffer.from( - "16Y97ByhyboePhTYMMmFj1tq5Cy1bDq8jT", - "ascii" - ).toString("hex"); - const ccAcc = - "c071c6f2d05cbc9ea9a04951b238086ce1608cf00020c3cab85b36aac5fdd591"; - /*eslint-enable */ - const responseAcc = `41${pubkeyAcc}22${addrAcc}${ccAcc}`; - const transport = await openTransportReplayer( - RecordStore.fromString(` - => e040000009028000002c80000000 - <= ${responseParent}9000 - => e04000000d038000002c8000000080000011 - <= ${responseAcc}9000 - `) - ); - // This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app - const btc = new Btc({ transport, currency: "oldbitcoin" }); - const result = await btc.getWalletXpub({ - path: "44'/0'/17'", - xpubVersion: 0x043587cf, // mainnet - }); - const expectedXpub = - "tpubDDn3XrB65rhCzRh4fsD8gogX9gFvGcEmP3jZtGbdxK7Mn25gipFB68vLFyqZ43i4e5Z7p6rki7THyb2PeH1D3NkLm5EUFzbUzyafp872GKa"; - expect(result).toEqual(expectedXpub); -}); - -test("btc.getWalletPublicKey", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => e040000011048000002c800000008000000000000000 - <= 410486b865b52b753d0a84d09bc20063fab5d8453ec33c215d4019a5801c9c6438b917770b2782e29a9ecc6edb67cd1f0fbf05ec4c1236884b6d686d6be3b1588abb2231334b453654666641724c683466564d36756f517a7673597135767765744a63564dbce80dd580792cd18af542790e56aa813178dc28644bb5f03dbd44c85f2d2e7a9000 - `) - ); - // This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app - const btc = new Btc({ transport, currency: "oldbitcoin" }); - const result = await btc.getWalletPublicKey("44'/0'/0'/0"); - expect(result).toEqual({ - bitcoinAddress: "13KE6TffArLh4fVM6uoQzvsYq5vwetJcVM", - chainCode: - "bce80dd580792cd18af542790e56aa813178dc28644bb5f03dbd44c85f2d2e7a", - publicKey: - "0486b865b52b753d0a84d09bc20063fab5d8453ec33c215d4019a5801c9c6438b917770b2782e29a9ecc6edb67cd1f0fbf05ec4c1236884b6d686d6be3b1588abb", - }); -}); - -test("btc 2", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => b001000000 - <= 0107426974636f696e06312e332e323301029000 - => e042000009000000010100000001 - <= 9000 - => e0428000254ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a - <= 9000 - => e04280003247304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f - <= 9000 - => e04280003257c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7 - <= 9000 - => e04280002a325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff - <= 9000 - => e04280000102 - <= 9000 - => e04280002281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac - <= 9000 - => e042800022a0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac - <= 9000 - => e04280000400000000 - <= 32005df4c773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f1001000000a086010000000000b890da969aa6f3109000 - => e04000000d03800000000000000000000000 - <= 41046666422d00f1b308fc7527198749f06fedb028b979c09f60d0348ef79c985e4138b86996b354774c434488d61c7fb20a83293ef3195d422fde9354e6cf2a74ce223137383731457244716465764c544c57424836577a6a556331454b4744517a434d41612d17bc55b7aa153ae07fba348692c2976e6889b769783d475ba7488fb547709000 - => e0440000050100000001 - <= 9000 - => e04480003b013832005df4c773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f1001000000a086010000000000b890da969aa6f31019 - <= 9000 - => e04480001d76a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88acffffffff - <= 9000 - => e04a80002301905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac - <= 00009000 - => e04800001303800000000000000000000000000000000001 - <= 3145022100ff492ad0b3a634aa7751761f7e063bf6ef4148cd44ef8930164580d5ba93a17802206fac94b32e296549e2e478ce806b58d61cfacbfed35ac4ceca26ac531f92b20a019000 - `) - ); - // This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app - const btc = new Btc({ transport, currency: "oldbitcoin" }); - const tx1 = btc.splitTransaction( - "01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000" - ); - const result = await btc.createPaymentTransaction({ - inputs: [[tx1, 1, undefined, undefined]], - associatedKeysets: ["0'/0/0"], - changePath: undefined, - outputScriptHex: - "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac", - additionals: [], - }); - expect(result).toEqual( - "0100000001c773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f10010000006b483045022100ff492ad0b3a634aa7751761f7e063bf6ef4148cd44ef8930164580d5ba93a17802206fac94b32e296549e2e478ce806b58d61cfacbfed35ac4ceca26ac531f92b20a0121026666422d00f1b308fc7527198749f06fedb028b979c09f60d0348ef79c985e41ffffffff01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac00000000" - ); -}); - -test("btc 3", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => e042000009000000010100000001 - <= 9000 - => e0428000254ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a - <= 9000 - => e04280003247304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f - <= 9000 - => e04280003257c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7 - <= 9000 - => e04280002a325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff - <= 9000 - => e04280000102 - <= 9000 - => e04280002281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac - <= 9000 - => e042800022a0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac - <= 9000 - => e04280000400000000 - <= 3200e4eac773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f1001000000a086010000000000c79483cc9a6e96fe9000 - => e0440000050100000001 - <= 9000 - => e04480002600c773da236484dae8f0fdba3d7e0ba1d05070d1a34fc44943e638441262a04f100100000069 - <= 9000 - => e04480003252210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04b - <= 9000 - => e044800032d40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc5 - <= 9000 - => e04480000900639853aeffffffff - <= 9000 - => e04a80002301905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac - <= 00009000 - => e04800001303800000000000000000000000000000000001 - <= 3045022100b5b1813992282b9a1fdd957b9751d79dc21018abc6586336e272212cc89cfe84022053765a1da0bdb5a0631a9866f1fd4c583589d5188b11cfa302fc20cd2611a71e019000 - `) - ); - const btc = new Btc({ transport }); - const tx1 = btc.splitTransaction( - "01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000" - ); - const result = await btc.signP2SHTransaction({ - inputs: [ - [ - tx1, - 1, - "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae", - undefined, - ], - ], - associatedKeysets: ["0'/0/0"], - outputScriptHex: - "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac", - }); - expect(result).toEqual([ - "3045022100b5b1813992282b9a1fdd957b9751d79dc21018abc6586336e272212cc89cfe84022053765a1da0bdb5a0631a9866f1fd4c583589d5188b11cfa302fc20cd2611a71e", - ]); -}); - -test("btc 4", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => e04e000117048000002c800000008000000000000000000474657374 - <= 00009000 - => e04e80000100 - <= 3045022100e32b32b8a6b4228155ba4d1a536d8fed9900606663fbbf4ea420ed8e944f9c18022053c97c74d2f6d8620d060584dc7886f5f3003684bb249508eb7066215172281a9000 - `) - ); - const btc = new Btc({ transport }); - const result = await btc.signMessage( - "44'/0'/0'/0", - Buffer.from("test").toString("hex") - ); - expect(result).toEqual({ - r: "e32b32b8a6b4228155ba4d1a536d8fed9900606663fbbf4ea420ed8e944f9c18", - s: "53c97c74d2f6d8620d060584dc7886f5f3003684bb249508eb7066215172281a", - v: 0, - }); -}); - -test("btc seg multi", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => b001000000 - <= 0107426974636f696e06312e332e323201029000 - => e040000015058000003180000001800000050000000000000000 - <= 4104f004370a593b3cde1511801a1151c86dd09a2f246a3f9ac3ef0b0240c0aeb506feddb0a785f5039c3e3e829db9692364e333256284d0fe312177cb12b88551162131764a4336523431416334685a61704a7863334c5a6e69334e7169445837514562141c248b44b74cbe35a3a92801cfebaf895df8d65f5830264097260c863fc1e59000 - => e040000015058000003180000001800000050000000000000000 - <= 4104f004370a593b3cde1511801a1151c86dd09a2f246a3f9ac3ef0b0240c0aeb506feddb0a785f5039c3e3e829db9692364e333256284d0fe312177cb12b88551162131764a4336523431416334685a61704a7863334c5a6e69334e7169445837514562141c248b44b74cbe35a3a92801cfebaf895df8d65f5830264097260c863fc1e59000 - => e0440002050100000002 - <= 9000 - => e04480022e02f5f6920fea15dda9c093b565cecbe8ba50160071d9bc8bc3474e09ab25a3367d00000000c03b47030000000000 - <= 9000 - => e044800204ffffffff - <= 9000 - => e04480022e023b9b487a91eee1293090cc9aba5acdde99e562e55b135609a766ffec4dd1100a0000000080778e060000000000 - <= 9000 - => e044800204ffffffff - <= 9000 - => e04a80002101ecd3e7020000000017a9142397c9bb7a3b8a08368a72b3e58c7bb85055579287 - <= 00009000 - => e0440080050100000001 - <= 9000 - => e04480802e02f5f6920fea15dda9c093b565cecbe8ba50160071d9bc8bc3474e09ab25a3367d00000000c03b47030000000019 - <= 9000 - => e04480801d76a9140a146582553b2f5537e13cef6659e82ed8f69b8f88acffffffff - <= 9000 - => e04800001b058000003180000001800000050000000000000000000000000001 - <= 30440220081d5f82ec23759eaf93519819faa1037faabdc27277c8594f5e8e2ba04cb24502206dfff160629ef1fbae78c74d59bfa8c7d59f873c905b196cf2e3efa2273db988019000 - => e0440080050100000001 - <= 9000 - => e04480802e023b9b487a91eee1293090cc9aba5acdde99e562e55b135609a766ffec4dd1100a0000000080778e060000000019 - <= 9000 - => e04480801d76a9140a146582553b2f5537e13cef6659e82ed8f69b8f88acffffffff - <= 9000 - => e04800001b058000003180000001800000050000000000000000000000000001 - <= 3145022100c820c90ce84c6567617733cd6409c4b8f7469b863d811a3cdc73bf3fa43912bc0220320b7fd259939a6821d371f2b49a755d1ca588bffb1476fbb2da68907427b54b019000 - `) - ); - // This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app - const btc = new Btc({ transport, currency: "oldbitcoin" }); - const tx1 = btc.splitTransaction( - "0100000000010130992c1559a43de1457f23380fefada09124d22594bbeb46ab6e9356e8407d39010000001716001417507f91a6594df7367a0561e4d3df376a829e1fffffffff02c03b47030000000017a9142397c9bb7a3b8a08368a72b3e58c7bb850555792875f810acf0900000017a914813a2e6c7538f0d0afbdeb5db38608804f5d76ab8702483045022100e09ca8a5357623438daee5b7804e73c9209de7c645efd405f13f83420157c48402207d3e4a30f362e062e361967c7afdd45e7f21878a067b661a6635669e620f99910121035606550fd51f6b063b69dc92bd182934a34463f773222743f300d3c7fd3ae47300000000", - true - ); - const tx2 = btc.splitTransaction( - "0100000000010176ef6abce7feecefbe1322da6cd21245f2d475a1836f13e99f56847bf7127f7c0100000017160014a4e29e297768fccd19cabc21cced93a6afc803eeffffffff0280778e060000000017a9142397c9bb7a3b8a08368a72b3e58c7bb8505557928795061b51b100000017a914c5cfa33e119f60c7cb40bd6b9cfe9e78b026eb6a8702473044022031f0c72683374275328ef0341ed1f233c55a37e21335f9c111c25645b50d0d4e0220670b833be0f688c237bf4466d2b94c99631ada3557c95a7d13bfbb9177125c340121020879f8616da54f8ac5476b97fbe0329c5a0e4cbd32e22e7348262bdfad99a44200000000", - true - ); - const result = await btc.createPaymentTransaction({ - inputs: [ - [tx1, 0, undefined, undefined], - [tx2, 0, undefined, undefined], - ], - associatedKeysets: ["49'/1'/5'/0/0", "49'/1'/5'/0/0"], - changePath: undefined, - outputScriptHex: - "01ecd3e7020000000017a9142397c9bb7a3b8a08368a72b3e58c7bb85055579287", - segwit: true, - additionals: [], - }); - expect(result).toEqual( - "01000000000102f5f6920fea15dda9c093b565cecbe8ba50160071d9bc8bc3474e09ab25a3367d00000000171600140a146582553b2f5537e13cef6659e82ed8f69b8fffffffff3b9b487a91eee1293090cc9aba5acdde99e562e55b135609a766ffec4dd1100a00000000171600140a146582553b2f5537e13cef6659e82ed8f69b8fffffffff01ecd3e7020000000017a9142397c9bb7a3b8a08368a72b3e58c7bb85055579287024730440220081d5f82ec23759eaf93519819faa1037faabdc27277c8594f5e8e2ba04cb24502206dfff160629ef1fbae78c74d59bfa8c7d59f873c905b196cf2e3efa2273db988012102f004370a593b3cde1511801a1151c86dd09a2f246a3f9ac3ef0b0240c0aeb50602483045022100c820c90ce84c6567617733cd6409c4b8f7469b863d811a3cdc73bf3fa43912bc0220320b7fd259939a6821d371f2b49a755d1ca588bffb1476fbb2da68907427b54b012102f004370a593b3cde1511801a1151c86dd09a2f246a3f9ac3ef0b0240c0aeb50600000000" - ); -}); - -test("btc sign p2sh seg", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => e0440002050100000001 - <= 9000 - => e04480022e021ba3852a59cded8d2760434fa75af58a617b21e4fbe1cf9c826ea2f14f80927d00000000102700000000000000 - <= 9000 - => e044800204ffffffff - <= 9000 - => e04a8000230188130000000000001976a9140ae1441568d0d293764a347b191025c51556cecd88ac - <= 00009000 - => e0440080050100000001 - <= 9000 - => e04480802e021ba3852a59cded8d2760434fa75af58a617b21e4fbe1cf9c826ea2f14f80927d00000000102700000000000047 - <= 9000 - => e0448080325121026666422d00f1b308fc7527198749f06fedb028b979c09f60d0348ef79c985e41210384257cf895f1ca492bbee5d748 - <= 9000 - => e0448080195ae0ef479036fdf59e15b92e37970a98d6fe7552aeffffffff - <= 9000 - => e04800001303800000000000000000000000000000000001 - <= 3045022100932934ee326c19c81b72fb03cec0fb79ff980a8076639f77c7edec35bd59da1e02205e4030e8e0fd2405f6db2fe044c49d3f191adbdc0e05ec7ed4dcc4c6fe7310e5019000 - `) - ); - const btc = new Btc({ transport }); - const tx1 = btc.splitTransaction( - "0100000001d3a05cd6e15582f40e68bb8b1559dc9e5b3e4f9f34d92c1217dc8c3355bc844e010000008a47304402207ab1a4768cbb036d4bce3c4a294c13cc5ae6076fc7bedce88c62aa80ae366da702204f8fea6923f8df36315c0c26cb42d8d7ab52ca4736776816e10d6ce51906d0600141044289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34cec320a0565fb7caf11b1ca2f445f9b7b012dda5718b3cface369ee3a034ded6ffffffff02102700000000000017a9141188cc3c265fbc01a025fc8adec9823effd0cef187185f9265170100001976a9140ae1441568d0d293764a347b191025c51556cecd88ac00000000", - true - ); - const result = await btc.signP2SHTransaction({ - inputs: [ - [ - tx1, - 0, - "5121026666422d00f1b308fc7527198749f06fedb028b979c09f60d0348ef79c985e41210384257cf895f1ca492bbee5d7485ae0ef479036fdf59e15b92e37970a98d6fe7552ae", - undefined, - ], - ], - associatedKeysets: ["0'/0/0"], - outputScriptHex: - "0188130000000000001976a9140ae1441568d0d293764a347b191025c51556cecd88ac", - segwit: true, - }); - expect(result).toEqual([ - "3045022100932934ee326c19c81b72fb03cec0fb79ff980a8076639f77c7edec35bd59da1e02205e4030e8e0fd2405f6db2fe044c49d3f191adbdc0e05ec7ed4dcc4c6fe7310e501", - ]); -}); - -test("signMessage", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => e04e00011d058000002c800000008000000000000000000000000006666f6f626172 - <= 00009000 - => e04e80000100 - <= 314402205eac720be544d3959a760d9bfd6a0e7c86d128fd1030038f06d85822608804e20220385d83273c9d03c469596292fb354b07d193034f83c2633a4c1f057838e12a5b9000 - `) - ); - const btc = new Btc({ transport }); - const res = await btc.signMessage( - "44'/0'/0'/0/0", - Buffer.from("foobar").toString("hex") - ); - expect(res).toEqual({ - v: 1, - r: "5eac720be544d3959a760d9bfd6a0e7c86d128fd1030038f06d85822608804e2", - s: "385d83273c9d03c469596292fb354b07d193034f83c2633a4c1f057838e12a5b", - }); -}); diff --git a/tests/newops/BtcNew.test.ts b/tests/newops/AcreBtcNew.test.ts similarity index 94% rename from tests/newops/BtcNew.test.ts rename to tests/newops/AcreBtcNew.test.ts index a683dd5..a948094 100644 --- a/tests/newops/BtcNew.test.ts +++ b/tests/newops/AcreBtcNew.test.ts @@ -3,7 +3,7 @@ import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocke import { TransportReplayer } from "@ledgerhq/hw-transport-mocker/lib/openTransportReplayer"; import ecc from "tiny-secp256k1"; import { getXpubComponents, pathArrayToString } from "../../src/bip32"; -import BtcNew from "../../src/BtcNew"; +import AcreBtcNew from "../../src/AcreBtcNew"; import { DefaultDescriptorTemplate, WalletPolicy } from "../../src/newops/policy"; import { PsbtV2 } from "../../src/newops/psbtv2"; import { splitTransaction } from "../../src/splitTransaction"; @@ -149,8 +149,8 @@ async function testGetWalletXpub(path: string, version = 0x043587cf) { const expectedXpub = "tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"; client.mockGetPubkeyResponse(path, expectedXpub); - const btc = new BtcNew(client); - const result = await btc.getWalletXpub({ path: path, xpubVersion: version }); + const acre = new AcreBtcNew(client); + const result = await acre.getWalletXpub({ path: path, xpubVersion: version }); expect(result).toEqual(expectedXpub); } async function testGetWalletPublicKey( @@ -173,13 +173,13 @@ async function testGetWalletPublicKey( "testaddress", ); - const btcNew = new BtcNew(client); + const acreBtcNew = new AcreBtcNew(client); const addressFormat = addressFormatFromDescriptorTemplate(expectedDescriptorTemplate); - const result = await btcNew.getWalletPublicKey(path, { format: addressFormat }); + const result = await acreBtcNew.getWalletPublicKey(path, { format: addressFormat }); log('address', result.bitcoinAddress) verifyGetWalletPublicKeyResult(result, keyXpub, "testaddress"); console.log('notworkingforsure') - const resultAccount = await btcNew.getWalletPublicKey(accountPath); + const resultAccount = await acreBtcNew.getWalletPublicKey(accountPath); verifyGetWalletPublicKeyResult(resultAccount, accountXpub); } @@ -190,8 +190,8 @@ async function testSignMessageReplayer( const client = new AppClient(transport); const path = accountPath + "/0/0"; - const btcNew = new BtcNew(client); - const result = await btcNew.signMessage({ path: path, messageHex: Buffer.from("test").toString("hex") }); + const acreBtcNew = new AcreBtcNew(client); + const result = await acreBtcNew.signMessage({ path: path, messageHex: Buffer.from("test").toString("hex") }); expect(result).toEqual({ v: 0, r: 'df44ce2f8f6f62fec9b0d01bd66bc91aa73984e0cf02ad8ff7bf12f8013ba779', @@ -219,8 +219,8 @@ async function testSignWithdrawalReplayer() { }; const path = "m/44'/0'/0'/0/0"; - const btcNew = new BtcNew(client); - const result = await btcNew.signWithdrawal({path: path, withdrawalData: withdrawalData}); + const acreBtcNew = new AcreBtcNew(client); + const result = await acreBtcNew.signWithdrawal({path: path, withdrawalData: withdrawalData}); expect(result).toEqual({ v: 0, r: '88c6c773f8d3101e30bbcc7811f8b553d222265023b981ad2f12dfa0da8ae8c2', diff --git a/tests/newops/integrationtools.ts b/tests/newops/integrationtools.ts index f8b1d06..1270a9d 100644 --- a/tests/newops/integrationtools.ts +++ b/tests/newops/integrationtools.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import Transport from "@ledgerhq/hw-transport"; import bs58check from "bs58check"; -import Btc from "../../src/Btc"; -import BtcNew from "../../src/BtcNew"; +import Acre from "../../src/Acre"; +import AcreBtcNew from "../../src/AcreBtcNew"; import { BufferWriter } from "../../src/buffertools"; import { CreateTransactionArg } from "../../src/createTransaction"; import { AddressFormat } from "../../src/getWalletPublicKey"; @@ -17,10 +17,10 @@ export async function runSignTransaction( client: TestingClient, transport: Transport, ): Promise { - const btcNew = new BtcNew(client); - // btc is needed to perform some functions like splitTransaction. - const btc = new Btc({ transport }); - const accountType = getAccountType(testTx.vin[0], btc); + const acreBtcNew = new AcreBtcNew(client); + // acre is needed to perform some functions like splitTransaction. + const acre = new Acre({ transport }); + const accountType = getAccountType(testTx.vin[0], acre); const additionals: string[] = []; if (accountType == StandardPurpose.p2wpkh) { additionals.push("bech32"); @@ -33,7 +33,7 @@ export async function runSignTransaction( const inputs = testTx.vin.map((input, index) => { const path = testPaths.ins[index]; associatedKeysets.push(path); - const inputData = createInput(input, btc); + const inputData = createInput(input, acre); const pubkey = getPubkey(index, accountType, testTx, inputData[0], inputData[1]); const mockXpub = creatDummyXpub(pubkey); client.mockGetPubkeyResponse(path, mockXpub); @@ -72,7 +72,7 @@ export async function runSignTransaction( onDeviceStreaming: arg => logCallback("CALLBACK: " + JSON.stringify(arg)), }; logCallback("Start createPaymentTransaction"); - const tx = await btcNew.createPaymentTransaction(arg); + const tx = await acreBtcNew.createPaymentTransaction(arg); logCallback("Done createPaymentTransaction"); // console.log(callbacks); return tx; @@ -129,12 +129,12 @@ function getSignature(testTxInput: CoreInput, accountType: StandardPurpose): Buf throw new Error(); } -function getAccountType(coreInput: CoreInput, btc: Btc): StandardPurpose { +function getAccountType(coreInput: CoreInput, acre: Acre): StandardPurpose { const spentTx = spentTxs[coreInput.txid]; if (!spentTx) { throw new Error("Spent tx " + coreInput.txid + " unavailable."); } - const splitSpentTx = btc.splitTransaction(spentTx, true); + const splitSpentTx = acre.splitTransaction(spentTx, true); const spentOutput = splitSpentTx.outputs![coreInput.vout]; const script = spentOutput.script; if (script.length == 34 && script[0] == 0x51) { @@ -158,12 +158,12 @@ export function creatDummyXpub(pubkey: Buffer): string { return bs58check.encode(xpubDecoded); } -function createInput(coreInput: CoreInput, btc: Btc): [Transaction, number, string | null, number] { +function createInput(coreInput: CoreInput, acre: Acre): [Transaction, number, string | null, number] { const spentTx = spentTxs[coreInput.txid]; if (!spentTx) { throw new Error("Spent tx " + coreInput.txid + " unavailable."); } - const splitSpentTx = btc.splitTransaction(spentTx, true); + const splitSpentTx = acre.splitTransaction(spentTx, true); return [splitSpentTx, coreInput.vout, null, coreInput.sequence]; } diff --git a/tests/newops/isPathNormal.test.ts b/tests/newops/isPathNormal.test.ts index 5987f2d..aecc27c 100644 --- a/tests/newops/isPathNormal.test.ts +++ b/tests/newops/isPathNormal.test.ts @@ -1,4 +1,4 @@ -import { isPathNormal } from "../../src/BtcNew"; +import { isPathNormal } from "../../src/AcreBtcNew"; describe("isPathNormal", () => { describe("should return true for normal and supported paths", () => { diff --git a/tests/parseTx.test.ts b/tests/parseTx.test.ts deleted file mode 100644 index 44162e9..0000000 --- a/tests/parseTx.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker"; -import Btc from "../src/Btc"; - -test("transaction on btc – nano s 1.3.1 – native segwit", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => b001000000 - <= 0107426974636f696e06312e332e323301029000 - => b001000000 - <= 6d00 - => e04000001505800000548000000080000000000000010000001b - <= 41042e00ef5ab04c270bf697e817c5fd433aa4509b063745d6f82c2157a59d59c1b7146956cee1b5ce1c7739a87fb59de3ad918872b14301af3f00b538934837b1382231354a707a787578426b6358384576465a6e6d4d736a74664771314d676e6d465356b9b92151a60d39e94e5be7a91003d0f43f03cafd69db00ebc60a65434d83e66d9000 - => e0440002050100000001 - <= 9000 - => e04480022e02fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b01000000000000 - <= 9000 - => e044800204ffffffff - <= 9000 - => e04aff001505800000548000000080000000000000010000001c - <= 9000 - => e04a00003202a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f7154106 - <= 009000 - => e04a80000d6369afcfc98b829886b6c76bf5 - <= 00009000 - => e0440080050100000001 - <= 9000 - => e04480802e02fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b01000000000019 - <= 9000 - => e04480801d76a9142f3fa4710983519e4ae45dd80e72e70b79f25c5e88acffffffff - <= 9000 - => e04800001b05800000548000000080000000000000010000001b000000000001 - <= 3045022100e4acf0eb3803a62399f53825d86aa30743fe999eefb01522d5f7ecd9eeec663d022063b90c512e207c2ac47d8759e1c73c6abeff58daec31c48905193470bc87f2d3019000 - `), - ); - const btc = new Btc({ transport, currency: "zcash" }); - const tx1 = btc.splitTransaction( - "fdffffff00289840f900000000003f76a91491842e1e3773b404b7acbde07bf6a8782f86320288ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4dd109c00000000003f76a914a16d376a7036816aea0dbac7d0a288b38690bc2288ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b40a2aa100000000003f76a914126e122dcc80505b9b4f00fd47606a5c2168f87488ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4aa6da901000000003f76a914ac3b0b75d17de9b66f6ce0b04c7b6df68d8c627f88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4911a6110000000003f76a91412d85a4a2a000b5f0af5eb5c233c045bcb32237088ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b49640f900000000003f76a914f1555affa9e47423a5f07c55a22b6da90ea79c2c88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4cb3ea800000000003f76a91438a904ca713c285a20959108c6087c9b97fc06bb88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4c11ca700000000003f76a91476cd5b686b6c2e3535d488c376ffc4fa7e74490a88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b46bedab00000000003f76a91431ec601f10fda75caf164edf18aa7a97b531b78c88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b487ee9a00000000003f76a9144903ff43d006695400f033e399025daf8947d1c588ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b40b9caf00000000003f76a91443aa6dad34cff8f3e4db84f94b9c65e6fba79c8188ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4efc39d00000000003f76a91460b4b104b7e9bbc701abd3917949456c68f8522488ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4637b9d00000000003f76a91458c7adfd4b8f301dc9d65f3ff6a49d863cddec4b88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4f21cd800000000003f76a9144e05aafd31d66a762bf7d937f613256a48d7574688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b40d2aa100000000003f76a914defe35ddd78bc8918c1a54e540861c9c05b3e38788ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b46496f300000000003f76a91485bf80ae408b88bff15f7b708c421b9dd32fc47688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b43fd4a600000000003f76a914558fd5741c64f869592cab94ae86a1bc63c1888988ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4b65c7605000000003f76a91449d8ced84fa86a98e552d9a2a118c0c7ac57d58688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4752e9f00000000003f76a914525d5f215ccf943d028c862881dfba681db58f9d88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4102db000000000003f76a91436902a202fd435b2fe115887d3c33882fa15bf1288ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b49175b000000000003f76a9149a7ca1397dac859774bd10759a80f2e36c84e74388ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b448f6a700000000003f76a914bbfd902d072ad91c6b32a7e2bff6fd340dffaa8688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b465ceb900000000003f76a914696a361dbc20a39810133e33575a4fc7d3e8bdb688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4a681ec00000000003f76a914e0b80dd3e6a7224ecf9e9acdcea4b6694d5255f588ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b413c03201000000003f76a914784fdee5cfc5c53c47df55f023f1ccc9dd612b1588ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b465080201000000003f76a9142dd6dc1e4f219dca7f69d973a2230779e6a582c888ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b49b25a300000000003f76a914fbe62338b092fd2c0973c27dd3d0482b89a6412388ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b456379b00000000003f76a9144d0c38f0a68f2240126f34a366251c9a8a931d1c88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4e6b04f02000000003f76a9147df5a291502a857a7085263f92a66b5aa198302388ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b456379b00000000003f76a914f0e9b6e8973a5670e9be75c036455b45e6f3eeb288ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b41a4fb100000000003f76a914b34da261b708d61d354833f4e7f2b655af29e05588ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b49403a200000000003f76a9141b61c76511eda352b2d93638065ed61dffc1fa5788ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4ca3ea800000000003f76a914a3b72f15846e1377c54de250b96baf6f11858fc488ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b46bdbea01000000003f76a9148a74fe473eed123214029bc79270423e59b8708588ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b45a02e400000000003f76a9143bc0b5d39ceb0b9906e6b1a2c19236b0f245f04188ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b47e87d900000000003f76a9148369c5504ec06cb99a6ef34a64c32b3bbce323b888ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b41bdda200000000003f76a9146465e2df3a5f313bdb2e8f213e67362aafafa66688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b4a33b9900000000003f76a914da189d3e1fee6ec5f7e71b8dd0f0cb2cc63e706b88ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b411bba100000000003f76a91463dcb85ae2572d68177ea0664214a9b96c8a4a8388ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b49bbaa701000000003f76a914e254982595b3a9f27cef5e2dfffc190f682c29b688ac20856d3881bce79d50886e1da8ddfedd0bc5b1002f31c8eebaf69e770400000000031da710b400000000010000000000000000c6361b360000000009f8b468a5f89f6a651e5e0f4722634dfafeb9c06b5813991f1aeb593c691d8df11684326768947b1bca6276e3a81447fd1967a0361cba8421b95404b2ce6d5727139522e837d20bd94cc1c4d3179e35e2f662cbd8bbcb5e55ac5721a819a193c980c353cd4aa3ca6b73b2c970bfc662221cece4121ace898b92583dfdba8db5aa7942adc7e0c6669450a5f69c0a81ae92fd7f650dd25025c82107ce1611bcf3cabd2ee4bf6fcd2a4d510654383de08b434cfc58c2d6558c92a1d3a5ed64271f1d037a2fc07ae745e6cca7eb0803089b56d1edbd8b4913fd12d4e3cac095c70ca78a325f2f9a2fa409c43bdb02364bc53d2d1e351435a4c8af578cc3891ee8434f7f1a653e469b9213fecdb37548f78395f759578e2c735009090c21eef86398a2301bbfc7c87a3508eb0865119468a5f751eafa087260edaa7f0f7c2ba3e4bdc11bcb96e877b696798159606ac92768b860e15363edd98927f1466c6108c55fdfe123a88d42efa39288e8f8878da947813fa450d45c02458b33fc21a57141d109e145adaffce8c69da92b29bc3d9cee7a0fe44d26870323c37c74ae7a4711dd46fc23ffbdeff5df650c5076adb0103994f82ed876c3dcbc95499a5cdd89a8a3699196331f55db547d5d5311fae5c7b73a8396f6e68443aa4a623543fb1f8863ed9bb0def0f307be1c0f2114a3c95e452cc8627d0e8f7c9d0d75df49e92e5e2bccce8d76e96885163facc66728fddff2556e6547207c1ae8fd098d81486e7ad18f8b4b4cadb9cb801f14168bc9d63fb10c614b8011d59efe29bf316bbc2a7f96b06a583d658c82855a8d0bf7e40dc137c334c44fbfaedf3352c1a78b989e116e86ba0fc53e7ac8c215761c5bb36ae447d3a2f4357828a7882811ea61588f0afb1390b2c2148a6508430ba86e90457c42f531ea73d6f056756547d09d63282bab6b1d71cd055d60406e284a9e46a14625da76d1264161f9f561e7588a31ba86c9259309e816fa71c01c159cc84b28d59b7c446355c87fd9c7d0c983ebfa2849387a263f3a6a073e3d649c7829dab262aae5e5320e49609be50d4462acbcb3f7e6723bbcdb309c0f8fe76ea72f044678be352264677c4ad33796cbc52947fe8f1231e7a10f17f32cb9c91e0389a64da2c5a0dfbf04f9bbcb3d14b0c2c54f68547f63bc9bad03b4c2e32ea0fa70f6830dce279be920e90ebdaae44a0aeb8909640a1cd77970f47ccb6ae5aba42342a86d46b9177c4e461703eee28e9bad6720ab1a8033c454042f7d94441af413fd8a43a7651ea2c728d5666087bb28a1f74a071e345639f9947085bab77bab8272ac8228f8cacc397de4e1fb82e69dccb1a87cf28fbbd1febf3750053ab46a213a16cb4a178b621a0348ac522ddcc1ee876d8973c818617ed87db4f62ee68b3ff07f647d3ca5b368d428582126a5c94cff4d18261c8afd00917f738a8d5f87de8eff909ae038607402a947e156c048c0c8f0b2c23dbccd03aa49655fb458bb053b8751cc3abd1733a2df65a3220db75a73f68d5226ba133e58347e125abdde6111ec67a8add5a58dfd86d81218d9fbb33fb76811ab4bff7f98c4ab83bb14d9a93e4f66d976540797474ab0804228cbc0d2b06f4c252373d16d9b3e7b2aa2626f6caf04ed44cde1ca909e9e1133e724f043fcc793102d4952f4b66a900be292e19b8f24f4c17ac6a216f6d896a1e8610472a4b981b88517ca75653e49a0ebb1bf86e8f48f3e7872d33d312fe7333b12c76c3534440319daae7c4bff3ed8382a5c150f57d29a22269e931cfa03d3102135d0b64f38c4c6aabd89e85f310291e173854a0d5a8ec421aaaf0613870cdfa709bd6073a0f1616f32101b7838218e55a159873ba038647cd6172da138750b3c43b7eed2d32d1c02580fae152a407beb284404bd723c9f169b30d416f4898abb4e7a3e4b55f8b1ecae889a0c10ea1ab493f1d7ed15fd5eec475423be700d90b3bdc96ff8bbe3a51b6f1d97f3a5a11804baf2140afab032712712ea4e03000bb1fca1728a4e4ba3db64c614c2f0a432c9d2b23cd28ec4afa273412578c1248a945098380b48bdd8d4da265ae7834672d18428663da204f9d59fcb6cc57c3fb05131624a6f9bf022ea40269a38eff2085995fd43cb36d5105a8b13458aa131ff32978b7c474258e40659db516d01f79f3730a34c53a6acb5739d3da78f82eb8d45cc0beb1c77e104e7f4b3e255df37e6a522e79c3d377438a8025a29fc753a6900f3f5e65e50ed178a2abed7d5fe73cd1ef327f9bafc6872ab8e8b9aca4ad80d152062eb2cd3371d09a5c90ff20bb3c6b53ed68a2b9822891740c3b9bc92c2dbf4467ded45e325035bbde84cd50a99d9729a221ea9c0577ee818c05231a27637508221b9d711f883cef7743ac5cbb1cf0d36cda39b59625d784c38edb62ad663eece335178c4a8e79ddbe5dfea48f978d4990d1773648d7ddf4c938b31eebea90758ff5a251b0402c0d1b4c299508d459fabfe0ee7626e01", - true, - false, - ["zencash"], - ); - expect(tx1.outputs?.length).toEqual(40); // 40 outputs in the above transaction. refer to https://explorer.zen-solutions.io/tx/1af7f8e4c77b35f558ee11defe7590c30e85723c0d846787729ecd4fbd45a533 -}); diff --git a/tests/trustedInputs.test.ts.disabled b/tests/trustedInputs.test.ts.disabled deleted file mode 100644 index 82bbd96..0000000 --- a/tests/trustedInputs.test.ts.disabled +++ /dev/null @@ -1,123 +0,0 @@ -import { - openTransportReplayer, - RecordStore, -} from "@ledgerhq/hw-transport-mocker"; -import Btc from "../src/Btc"; - -test("transaction on btc – nano s 1.3.1 – native segwit", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => b001000000 - <= 6d00 - => e04000001505800000548000000080000000000000010000001b - <= 41042e00ef5ab04c270bf697e817c5fd433aa4509b063745d6f82c2157a59d59c1b7146956cee1b5ce1c7739a87fb59de3ad918872b14301af3f00b538934837b1382231354a707a787578426b6358384576465a6e6d4d736a74664771314d676e6d465356b9b92151a60d39e94e5be7a91003d0f43f03cafd69db00ebc60a65434d83e66d9000 - => e0440002050100000001 - <= 9000 - => e04480022e02fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b01000000000000 - <= 9000 - => e044800204ffffffff - <= 9000 - => e04aff001505800000548000000080000000000000010000001c - <= 9000 - => e04a00003202a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f7154106 - <= 009000 - => e04a80000d6369afcfc98b829886b6c76bf5 - <= 00009000 - => e0440080050100000001 - <= 9000 - => e04480802e02fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b01000000000019 - <= 9000 - => e04480801d76a9142f3fa4710983519e4ae45dd80e72e70b79f25c5e88acffffffff - <= 9000 - => e04800001b05800000548000000080000000000000010000001b000000000001 - <= 3045022100e4acf0eb3803a62399f53825d86aa30743fe999eefb01522d5f7ecd9eeec663d022063b90c512e207c2ac47d8759e1c73c6abeff58daec31c48905193470bc87f2d3019000 - `) - ); - // This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app - const btc = new Btc({ transport, currency: "oldbitcoin" }); - const tx1 = btc.splitTransaction( - "01000000000102b91a5eb409e1243dcc02440ad5709d57047946309a515902ffdba8b98ad9e9970000000000ffffff00b91a5eb409e1243dcc02440ad5709d57047946309a515902ffdba8b98ad9e9970100000000ffffff000250c300000000000016001449df9e8ba7e25dd4830579cb42fbea938497168bef8b0100000000001600142f3fa4710983519e4ae45dd80e72e70b79f25c5e0248304502210080ed332c269ae7d86fac26a143afcec0a634e1098fd1ee5ca43cbe0c66de861802204c804eceb4cc9ca397156fa683f46274d22bb5d95f8c8293dc595934899f7927012103cc39edf09d462b4de30cc9bf96b163f18dcee742e0a1ea6fad0274ae0b9d60330247304402203e277d48d19a01c33b45b8f102479eb10811d20991bbf060cab4ba79f0972e61022041e13ed7da2b266d20c36b01694f2d16cf144c1ff66863f26d7c332dc220bc1301210369f216ec068fb7ef17a46ad3ad4d7f0e04e8a3a16ae2da852d6e4b57c3bb972f00000000", - true - ); - const result = await btc.createPaymentTransaction({ - inputs: [[tx1, 1, undefined, 0xffffffff]], - associatedKeysets: ["84'/0'/0'/1/27"], - changePath: "84'/0'/0'/1/28", - outputScriptHex: - "02a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f71541066369afcfc98b829886b6c76bf5", - sigHashType: 1, - segwit: true, - additionals: ["bitcoin", "bech32"], - }); - expect(result).toEqual( - "01000000000101fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee0100000000ffffffff02a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f71541066369afcfc98b829886b6c76bf502483045022100e4acf0eb3803a62399f53825d86aa30743fe999eefb01522d5f7ecd9eeec663d022063b90c512e207c2ac47d8759e1c73c6abeff58daec31c48905193470bc87f2d30121022e00ef5ab04c270bf697e817c5fd433aa4509b063745d6f82c2157a59d59c1b700000000" - ); -}); - -test("transaction on btc – nano s 1.6.0 – native segwit", async () => { - const transport = await openTransportReplayer( - RecordStore.fromString(` - => b001000000 - <= 0107426974636f696e05312e342e3201029000 - => e042000009000000010100000002 - <= 9000 - => e042800025b91a5eb409e1243dcc02440ad5709d57047946309a515902ffdba8b98ad9e9970000000000 - <= 9000 - => e042800004ffffff00 - <= 9000 - => e042800025b91a5eb409e1243dcc02440ad5709d57047946309a515902ffdba8b98ad9e9970100000000 - <= 9000 - => e042800004ffffff00 - <= 9000 - => e04280000102 - <= 9000 - => e04280001f50c300000000000016001449df9e8ba7e25dd4830579cb42fbea938497168b - <= 9000 - => e04280001fef8b0100000000001600142f3fa4710983519e4ae45dd80e72e70b79f25c5e - <= 9000 - => e04280000400000000 - <= 3200bb29fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b0100000000004daa5993f8b02cde9000 - => e04000001505800000548000000080000000000000010000001b - <= 41042e00ef5ab04c270bf697e817c5fd433aa4509b063745d6f82c2157a59d59c1b7146956cee1b5ce1c7739a87fb59de3ad918872b14301af3f00b538934837b1382231354a707a787578426b6358384576465a6e6d4d736a74664771314d676e6d465356b9b92151a60d39e94e5be7a91003d0f43f03cafd69db00ebc60a65434d83e66d9000 - => e0440002050100000001 - <= 9000 - => e04480023b01383200bb29fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b0100000000004daa5993f8b02cde00 - <= 9000 - => e044800204ffffffff - <= 9000 - => e04aff001505800000548000000080000000000000010000001c - <= 9000 - => e04a00003202a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f7154106 - <= 009000 - => e04a80000d6369afcfc98b829886b6c76bf5 - <= 00009000 - => e0440080050100000001 - <= 9000 - => e04480803b01383200bb29fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee01000000ef8b0100000000004daa5993f8b02cde19 - <= 9000 - => e04480801d76a9142f3fa4710983519e4ae45dd80e72e70b79f25c5e88acffffffff - <= 9000 - => e04800001b05800000548000000080000000000000010000001b000000000001 - <= 3045022100e4acf0eb3803a62399f53825d86aa30743fe999eefb01522d5f7ecd9eeec663d022063b90c512e207c2ac47d8759e1c73c6abeff58daec31c48905193470bc87f2d3019000 - `) - ); - // This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app - const btc = new Btc({ transport, currency: "oldbitcoin" }); - const tx1 = btc.splitTransaction( - "01000000000102b91a5eb409e1243dcc02440ad5709d57047946309a515902ffdba8b98ad9e9970000000000ffffff00b91a5eb409e1243dcc02440ad5709d57047946309a515902ffdba8b98ad9e9970100000000ffffff000250c300000000000016001449df9e8ba7e25dd4830579cb42fbea938497168bef8b0100000000001600142f3fa4710983519e4ae45dd80e72e70b79f25c5e0248304502210080ed332c269ae7d86fac26a143afcec0a634e1098fd1ee5ca43cbe0c66de861802204c804eceb4cc9ca397156fa683f46274d22bb5d95f8c8293dc595934899f7927012103cc39edf09d462b4de30cc9bf96b163f18dcee742e0a1ea6fad0274ae0b9d60330247304402203e277d48d19a01c33b45b8f102479eb10811d20991bbf060cab4ba79f0972e61022041e13ed7da2b266d20c36b01694f2d16cf144c1ff66863f26d7c332dc220bc1301210369f216ec068fb7ef17a46ad3ad4d7f0e04e8a3a16ae2da852d6e4b57c3bb972f00000000", - true - ); - const result = await btc.createPaymentTransaction({ - inputs: [[tx1, 1, undefined, 0xffffffff]], - associatedKeysets: ["84'/0'/0'/1/27"], - changePath: "84'/0'/0'/1/28", - outputScriptHex: - "02a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f71541066369afcfc98b829886b6c76bf5", - sigHashType: 1, - segwit: true, - additionals: ["bitcoin", "bech32"], - }); - expect(result).toEqual( - "01000000000101fc4fd606567a2146ec33fd3904d978167d8309b510071b276734768397aa4eee0100000000ffffffff02a086010000000000160014562b254f8890788f45c7cf7bd4c81bce789ffcd0bd0400000000000016001483efa2f71541066369afcfc98b829886b6c76bf502483045022100e4acf0eb3803a62399f53825d86aa30743fe999eefb01522d5f7ecd9eeec663d022063b90c512e207c2ac47d8759e1c73c6abeff58daec31c48905193470bc87f2d30121022e00ef5ab04c270bf697e817c5fd433aa4509b063745d6f82c2157a59d59c1b700000000" - ); -});