@ledgerhq/hw-app-btc
Advanced tools
Comparing version 10.2.4 to 10.3.0-next.0
# @ledgerhq/hw-app-btc | ||
## 10.3.0-next.0 | ||
### Minor Changes | ||
- [#6596](https://github.com/LedgerHQ/ledger-live/pull/6596) [`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11) Thanks [@KVNLS](https://github.com/KVNLS)! - Upgrade React Native to version 0.73.6 | ||
### Patch Changes | ||
- Updated dependencies [[`77fa530`](https://github.com/LedgerHQ/ledger-live/commit/77fa530c8626df94fa7f9c0a8b3a99f2efa7cb11), [`815ae3d`](https://github.com/LedgerHQ/ledger-live/commit/815ae3dae8027823854ada837df3dc983d09b10f)]: | ||
- @ledgerhq/hw-transport@6.31.0-next.0 | ||
## 10.2.4 | ||
@@ -4,0 +15,0 @@ |
@@ -69,4 +69,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
*/ | ||
getWalletXpub({ path, xpubVersion, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
getWalletXpub(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, xpubVersion, }) { | ||
const pathElements = pathStringToArray(path); | ||
@@ -89,4 +89,4 @@ const xpub = yield this.client.getExtendedPubkey(false, pathElements); | ||
getWalletPublicKey(path, opts) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
if (!isPathNormal(path)) { | ||
@@ -239,4 +239,4 @@ throw Error(`non-standard path: ${path}`); | ||
*/ | ||
signMessage({ path, messageHex }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
signMessage(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, messageHex }) { | ||
const pathElements = pathStringToArray(path); | ||
@@ -400,10 +400,10 @@ const message = Buffer.from(messageHex, "hex"); | ||
const VALID_COIN_TYPES = [ | ||
0, | ||
1, | ||
0, // Bitcoin | ||
1, // Bitcoin (Testnet) | ||
88, // Qtum | ||
]; | ||
const VALID_SINGLE_SIG_PURPOSES = [ | ||
44, | ||
49, | ||
84, | ||
44, // BIP44 - https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki | ||
49, // BIP49 - https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki | ||
84, // BIP84 - https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki | ||
86, // BIP86 - https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki | ||
@@ -410,0 +410,0 @@ ]; |
@@ -38,4 +38,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
getWalletXpub({ path, xpubVersion, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
getWalletXpub(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, xpubVersion, }) { | ||
const pathElements = pathStringToArray(path); | ||
@@ -120,4 +120,4 @@ const parentPath = pathElements.slice(0, -1); | ||
} | ||
signMessage({ path, messageHex }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
signMessage(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, messageHex }) { | ||
return signMessage(this.transport, { | ||
@@ -124,0 +124,0 @@ path, |
@@ -283,4 +283,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), | ||
Buffer.from([0x00, 0x00, 0x00, 0x00]), | ||
Buffer.from([0xff, 0xff, 0xff, 0xff]), | ||
Buffer.from([0x00, 0x00, 0x00, 0x00]), //Block height | ||
Buffer.from([0xff, 0xff, 0xff, 0xff]), //Block index | ||
Buffer.from([targetTransaction.inputs[inputIndex].script.length]), | ||
@@ -287,0 +287,0 @@ targetTransaction.inputs[inputIndex].script, |
@@ -16,4 +16,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
export function hashOutputFull(transport, outputScript, additionals = []) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
export function hashOutputFull(transport_1, outputScript_1) { | ||
return __awaiter(this, arguments, void 0, function* (transport, outputScript, additionals = []) { | ||
let offset = 0; | ||
@@ -20,0 +20,0 @@ const p1 = Number(0x80); |
@@ -31,4 +31,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
export function getTrustedInput(transport, indexLookup, transaction, additionals = []) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
export function getTrustedInput(transport_1, indexLookup_1, transaction_1) { | ||
return __awaiter(this, arguments, void 0, function* (transport, indexLookup, transaction, additionals = []) { | ||
const { version, inputs, outputs, locktime, nExpiryHeight, extraData } = transaction; | ||
@@ -95,3 +95,3 @@ if (!outputs || !locktime) { | ||
output.amount, | ||
isDecred ? Buffer.from([0x00, 0x00]) : Buffer.alloc(0), | ||
isDecred ? Buffer.from([0x00, 0x00]) : Buffer.alloc(0), //Version script | ||
createVarint(output.script.length), | ||
@@ -98,0 +98,0 @@ output.script, |
@@ -34,3 +34,3 @@ import { createVarint } from "./varint"; | ||
input.prevout, | ||
Buffer.from([0x00]), | ||
Buffer.from([0x00]), //tree | ||
input.sequence, | ||
@@ -61,3 +61,3 @@ ]) | ||
transaction.nVersionGroupId || Buffer.alloc(0), | ||
Buffer.from([0xb4, 0xd0, 0xd6, 0xc2]), | ||
Buffer.from([0xb4, 0xd0, 0xd6, 0xc2]), // Zcash Consensus Branch ID: 0xC2D6D0B4 refer to https://z.cash/upgrade/nu5/ | ||
transaction.locktime || Buffer.from([0x00, 0x00, 0x00, 0x00]), | ||
@@ -64,0 +64,0 @@ transaction.nExpiryHeight || Buffer.from([0x00, 0x00, 0x00, 0x00]), |
@@ -12,4 +12,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { MAX_SCRIPT_BLOCK } from "./constants"; | ||
export function signMessage(transport, { path, messageHex, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
export function signMessage(transport_1, _a) { | ||
return __awaiter(this, arguments, void 0, function* (transport, { path, messageHex, }) { | ||
const paths = bippath.fromString(path).toPathArray(); | ||
@@ -16,0 +16,0 @@ const message = Buffer.from(messageHex, "hex"); |
@@ -24,4 +24,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
export function startUntrustedHashTransactionInput(transport, newTransaction, transaction, inputs, bip143 = false, overwinter = false, additionals = [], useTrustedInputForSegwit = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
export function startUntrustedHashTransactionInput(transport_1, newTransaction_1, transaction_1, inputs_1) { | ||
return __awaiter(this, arguments, void 0, function* (transport, newTransaction, transaction, inputs, bip143 = false, overwinter = false, additionals = [], useTrustedInputForSegwit = false) { | ||
let data = Buffer.concat([ | ||
@@ -28,0 +28,0 @@ transaction.version, |
@@ -72,4 +72,4 @@ "use strict"; | ||
*/ | ||
getWalletXpub({ path, xpubVersion, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
getWalletXpub(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, xpubVersion, }) { | ||
const pathElements = (0, bip32_1.pathStringToArray)(path); | ||
@@ -92,4 +92,4 @@ const xpub = yield this.client.getExtendedPubkey(false, pathElements); | ||
getWalletPublicKey(path, opts) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
if (!isPathNormal(path)) { | ||
@@ -242,4 +242,4 @@ throw Error(`non-standard path: ${path}`); | ||
*/ | ||
signMessage({ path, messageHex }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
signMessage(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, messageHex }) { | ||
const pathElements = (0, bip32_1.pathStringToArray)(path); | ||
@@ -404,10 +404,10 @@ const message = Buffer.from(messageHex, "hex"); | ||
const VALID_COIN_TYPES = [ | ||
0, | ||
1, | ||
0, // Bitcoin | ||
1, // Bitcoin (Testnet) | ||
88, // Qtum | ||
]; | ||
const VALID_SINGLE_SIG_PURPOSES = [ | ||
44, | ||
49, | ||
84, | ||
44, // BIP44 - https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki | ||
49, // BIP49 - https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki | ||
84, // BIP84 - https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki | ||
86, // BIP86 - https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki | ||
@@ -414,0 +414,0 @@ ]; |
@@ -43,4 +43,4 @@ "use strict"; | ||
} | ||
getWalletXpub({ path, xpubVersion, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
getWalletXpub(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, xpubVersion, }) { | ||
const pathElements = (0, bip32_1.pathStringToArray)(path); | ||
@@ -125,4 +125,4 @@ const parentPath = pathElements.slice(0, -1); | ||
} | ||
signMessage({ path, messageHex }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
signMessage(_a) { | ||
return __awaiter(this, arguments, void 0, function* ({ path, messageHex }) { | ||
return (0, signMessage_1.signMessage)(this.transport, { | ||
@@ -129,0 +129,0 @@ path, |
@@ -286,4 +286,4 @@ "use strict"; | ||
Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), | ||
Buffer.from([0x00, 0x00, 0x00, 0x00]), | ||
Buffer.from([0xff, 0xff, 0xff, 0xff]), | ||
Buffer.from([0x00, 0x00, 0x00, 0x00]), //Block height | ||
Buffer.from([0xff, 0xff, 0xff, 0xff]), //Block index | ||
Buffer.from([targetTransaction.inputs[inputIndex].script.length]), | ||
@@ -290,0 +290,0 @@ targetTransaction.inputs[inputIndex].script, |
@@ -20,4 +20,4 @@ "use strict"; | ||
exports.provideOutputFullChangePath = provideOutputFullChangePath; | ||
function hashOutputFull(transport, outputScript, additionals = []) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
function hashOutputFull(transport_1, outputScript_1) { | ||
return __awaiter(this, arguments, void 0, function* (transport, outputScript, additionals = []) { | ||
let offset = 0; | ||
@@ -24,0 +24,0 @@ const p1 = Number(0x80); |
@@ -38,4 +38,4 @@ "use strict"; | ||
exports.getTrustedInputRaw = getTrustedInputRaw; | ||
function getTrustedInput(transport, indexLookup, transaction, additionals = []) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
function getTrustedInput(transport_1, indexLookup_1, transaction_1) { | ||
return __awaiter(this, arguments, void 0, function* (transport, indexLookup, transaction, additionals = []) { | ||
const { version, inputs, outputs, locktime, nExpiryHeight, extraData } = transaction; | ||
@@ -102,3 +102,3 @@ if (!outputs || !locktime) { | ||
output.amount, | ||
isDecred ? Buffer.from([0x00, 0x00]) : Buffer.alloc(0), | ||
isDecred ? Buffer.from([0x00, 0x00]) : Buffer.alloc(0), //Version script | ||
(0, varint_1.createVarint)(output.script.length), | ||
@@ -105,0 +105,0 @@ output.script, |
@@ -38,3 +38,3 @@ "use strict"; | ||
input.prevout, | ||
Buffer.from([0x00]), | ||
Buffer.from([0x00]), //tree | ||
input.sequence, | ||
@@ -65,3 +65,3 @@ ]) | ||
transaction.nVersionGroupId || Buffer.alloc(0), | ||
Buffer.from([0xb4, 0xd0, 0xd6, 0xc2]), | ||
Buffer.from([0xb4, 0xd0, 0xd6, 0xc2]), // Zcash Consensus Branch ID: 0xC2D6D0B4 refer to https://z.cash/upgrade/nu5/ | ||
transaction.locktime || Buffer.from([0x00, 0x00, 0x00, 0x00]), | ||
@@ -68,0 +68,0 @@ transaction.nExpiryHeight || Buffer.from([0x00, 0x00, 0x00, 0x00]), |
@@ -18,4 +18,4 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
function signMessage(transport, { path, messageHex, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
function signMessage(transport_1, _a) { | ||
return __awaiter(this, arguments, void 0, function* (transport, { path, messageHex, }) { | ||
const paths = bip32_path_1.default.fromString(path).toPathArray(); | ||
@@ -22,0 +22,0 @@ const message = Buffer.from(messageHex, "hex"); |
@@ -28,4 +28,4 @@ "use strict"; | ||
exports.startUntrustedHashTransactionInputRaw = startUntrustedHashTransactionInputRaw; | ||
function startUntrustedHashTransactionInput(transport, newTransaction, transaction, inputs, bip143 = false, overwinter = false, additionals = [], useTrustedInputForSegwit = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
function startUntrustedHashTransactionInput(transport_1, newTransaction_1, transaction_1, inputs_1) { | ||
return __awaiter(this, arguments, void 0, function* (transport, newTransaction, transaction, inputs, bip143 = false, overwinter = false, additionals = [], useTrustedInputForSegwit = false) { | ||
let data = Buffer.concat([ | ||
@@ -32,0 +32,0 @@ transaction.version, |
{ | ||
"name": "@ledgerhq/hw-app-btc", | ||
"version": "10.2.4", | ||
"version": "10.3.0-next.0", | ||
"description": "Ledger Hardware Wallet Bitcoin Application API", | ||
@@ -73,3 +73,3 @@ "keywords": [ | ||
"varuint-bitcoin": "1.1.2", | ||
"@ledgerhq/hw-transport": "^6.30.6", | ||
"@ledgerhq/hw-transport": "^6.31.0-next.0", | ||
"@ledgerhq/logs": "^6.12.0" | ||
@@ -87,4 +87,4 @@ }, | ||
"ts-node": "^10.4.0", | ||
"@ledgerhq/hw-transport-mocker": "^6.28.6", | ||
"@ledgerhq/hw-transport-node-speculos": "^6.28.6" | ||
"@ledgerhq/hw-transport-mocker": "^6.29.0-next.0", | ||
"@ledgerhq/hw-transport-node-speculos": "^6.29.0-next.0" | ||
}, | ||
@@ -91,0 +91,0 @@ "gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec", |
@@ -132,4 +132,4 @@ import { log } from "@ledgerhq/logs"; | ||
: isXST | ||
? defaultVersion.writeUInt32LE(2, 0) | ||
: defaultVersion.writeUInt32LE(1, 0); | ||
? defaultVersion.writeUInt32LE(2, 0) | ||
: defaultVersion.writeUInt32LE(1, 0); | ||
// Default version to 2 for XST not to have timestamp | ||
@@ -182,4 +182,4 @@ const trustedInputs: Array<any> = []; | ||
: sapling | ||
? [0x85, 0x20, 0x2f, 0x89] | ||
: [0x70, 0x82, 0xc4, 0x03], | ||
? [0x85, 0x20, 0x2f, 0x89] | ||
: [0x70, 0x82, 0xc4, 0x03], | ||
); | ||
@@ -272,8 +272,8 @@ targetTransaction.nExpiryHeight = expiryHeight; | ||
: !segwit | ||
? regularOutputs[i].script | ||
: Buffer.concat([ | ||
Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), | ||
hashPublicKey(publicKeys[i]), | ||
Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]), | ||
]); | ||
? regularOutputs[i].script | ||
: Buffer.concat([ | ||
Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), | ||
hashPublicKey(publicKeys[i]), | ||
Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]), | ||
]); | ||
const pseudoTX = Object.assign({}, targetTransaction); | ||
@@ -280,0 +280,0 @@ const pseudoTrustedInputs = useBip143 ? [trustedInputs[i]] : trustedInputs; |
@@ -104,4 +104,4 @@ import invariant from "invariant"; | ||
: isXSTV2 | ||
? processWholeScriptBlock(input.sequence) | ||
: processScriptBlocks(input.script, input.sequence)); | ||
? processWholeScriptBlock(input.sequence) | ||
: processScriptBlocks(input.script, input.sequence)); | ||
} | ||
@@ -108,0 +108,0 @@ |
@@ -17,8 +17,8 @@ import type Transport from "@ledgerhq/hw-transport"; | ||
: bip143 | ||
? additionals.includes("sapling") | ||
? 0x05 | ||
: overwinter | ||
? 0x04 | ||
: 0x02 | ||
: 0x00; | ||
? additionals.includes("sapling") | ||
? 0x05 | ||
: overwinter | ||
? 0x04 | ||
: 0x02 | ||
: 0x00; | ||
return transport.send( | ||
@@ -25,0 +25,0 @@ 0xe0, |
@@ -1,6 +0,6 @@ | ||
import { BufferReader, BufferWriter } from "../src/buffertools" | ||
import { BufferReader, BufferWriter } from "../src/buffertools"; | ||
function run(n: number, expectedHex: string) { | ||
const w = new BufferWriter(); | ||
w.writeUInt64(n) | ||
w.writeUInt64(n); | ||
expect(w.buffer()).toEqual(Buffer.from(expectedHex, "hex")); | ||
@@ -14,13 +14,13 @@ const r = new BufferReader(w.buffer()); | ||
run(1, "0100000000000000"); | ||
run(0xffffffff, "ffffffff00000000"); | ||
run(0xffffffff, "ffffffff00000000"); | ||
run(0x0100000000, "0000000001000000"); | ||
run(0x010203040506, "0605040302010000"); | ||
run(Number.MAX_SAFE_INTEGER, "FFFFFFFFFFFF1F00"); | ||
}) | ||
}); | ||
test("Too big 64 bit number", () => { | ||
const w = new BufferWriter(); | ||
expect(() => w.writeUInt64(Number.MAX_SAFE_INTEGER+1)).toThrow(); | ||
const r = new BufferReader(Buffer.from("FFFFFFFFFFFF2000", "hex")) | ||
expect(() => w.writeUInt64(Number.MAX_SAFE_INTEGER + 1)).toThrow(); | ||
const r = new BufferReader(Buffer.from("FFFFFFFFFFFF2000", "hex")); | ||
expect(() => r.readUInt64()).toThrow(); | ||
}) | ||
}); |
@@ -7,10 +7,22 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import BtcNew from "../../src/BtcNew"; | ||
import { | ||
DefaultDescriptorTemplate, | ||
WalletPolicy | ||
} from "../../src/newops/policy"; | ||
import { DefaultDescriptorTemplate, WalletPolicy } from "../../src/newops/policy"; | ||
import { PsbtV2 } from "../../src/newops/psbtv2"; | ||
import { splitTransaction } from "../../src/splitTransaction"; | ||
import { StandardPurpose, addressFormatFromDescriptorTemplate, creatDummyXpub, masterFingerprint, runSignTransaction, TestingClient } from "./integrationtools"; | ||
import { CoreInput, CoreTx, p2pkh, p2tr, p2wpkh, wrappedP2wpkh, wrappedP2wpkhTwoInputs } from "./testtx"; | ||
import { | ||
StandardPurpose, | ||
addressFormatFromDescriptorTemplate, | ||
creatDummyXpub, | ||
masterFingerprint, | ||
runSignTransaction, | ||
TestingClient, | ||
} from "./integrationtools"; | ||
import { | ||
CoreInput, | ||
CoreTx, | ||
p2pkh, | ||
p2tr, | ||
p2wpkh, | ||
wrappedP2wpkh, | ||
wrappedP2wpkhTwoInputs, | ||
} from "./testtx"; | ||
@@ -40,3 +52,3 @@ test("getWalletPublicKey p2pkh", async () => { | ||
function testPaths(type: StandardPurpose): { ins: string[], out?: string } { | ||
function testPaths(type: StandardPurpose): { ins: string[]; out?: string } { | ||
const basePath = `m/${type}/1'/0'/`; | ||
@@ -75,24 +87,28 @@ const ins = [ | ||
const testTx = JSON.parse(JSON.stringify(p2tr)); | ||
testTx.vin.forEach((input: CoreInput, index: number) => { | ||
testTx.vin.forEach((input: CoreInput) => { | ||
// Test SIGHASH_SINGLE | SIGHASH_ANYONECANPAY, 0x83 | ||
const sig = input.txinwitness![0] + "83"; | ||
input.txinwitness = [sig]; | ||
}) | ||
const tx = await runSignTransactionNoVerification(testTx, StandardPurpose.p2tr); | ||
}); | ||
await runSignTransactionNoVerification(testTx, StandardPurpose.p2tr); | ||
// The verification of the sighashtype is done in MockClient.signPsbt | ||
}) | ||
}); | ||
test("Sign p2tr sequence 0", async() => { | ||
test("Sign p2tr sequence 0", async () => { | ||
const testTx = JSON.parse(JSON.stringify(p2tr)); | ||
testTx.vin.forEach((input: CoreInput, index: number) => { | ||
testTx.vin.forEach((input: CoreInput) => { | ||
input.sequence = 0; | ||
}) | ||
}); | ||
const tx = await runSignTransactionNoVerification(testTx, StandardPurpose.p2tr); | ||
const txObj = splitTransaction(tx, true); | ||
txObj.inputs.forEach((input, index) => { | ||
txObj.inputs.forEach(input => { | ||
expect(input.sequence.toString("hex")).toEqual("00000000"); | ||
}) | ||
}) | ||
}); | ||
}); | ||
async function runSignTransactionTest(testTx: CoreTx, accountType: StandardPurpose, changePubkey?: string) { | ||
async function runSignTransactionTest( | ||
testTx: CoreTx, | ||
accountType: StandardPurpose, | ||
changePubkey?: string, | ||
) { | ||
const tx = await runSignTransactionNoVerification(testTx, accountType, changePubkey); | ||
@@ -102,5 +118,10 @@ expect(tx).toEqual(testTx.hex); | ||
async function runSignTransactionNoVerification(testTx: CoreTx, accountType: StandardPurpose, changePubkey?: string): Promise<string> { | ||
async function runSignTransactionNoVerification( | ||
testTx: CoreTx, | ||
accountType: StandardPurpose, | ||
changePubkey?: string, | ||
): Promise<string> { | ||
const [client, transport] = await createClient(); | ||
const accountXpub = "tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"; | ||
const accountXpub = | ||
"tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"; | ||
client.mockGetPubkeyResponse(`m/${accountType}/1'/0'`, accountXpub); | ||
@@ -119,3 +140,4 @@ const paths = testPaths(accountType); | ||
const [client] = await createClient(); | ||
const expectedXpub = "tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"; | ||
const expectedXpub = | ||
"tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT"; | ||
client.mockGetPubkeyResponse(path, expectedXpub); | ||
@@ -128,3 +150,3 @@ const btc = new BtcNew(client); | ||
accountPath: string, | ||
expectedDescriptorTemplate: DefaultDescriptorTemplate | ||
expectedDescriptorTemplate: DefaultDescriptorTemplate, | ||
) { | ||
@@ -139,5 +161,3 @@ const [client] = await createClient(); | ||
client.mockGetPubkeyResponse(path, keyXpub); | ||
const key = `[${masterFingerprint.toString("hex")}${accountPath.substring( | ||
1 | ||
)}]${accountXpub}/**`; | ||
const key = `[${masterFingerprint.toString("hex")}${accountPath.substring(1)}]${accountXpub}/**`; | ||
client.mockGetWalletAddressResponse( | ||
@@ -147,3 +167,3 @@ new WalletPolicy(expectedDescriptorTemplate, key), | ||
0, | ||
"testaddress" | ||
"testaddress", | ||
); | ||
@@ -163,13 +183,9 @@ | ||
expectedXpub: string, | ||
expectedAddress?: string | ||
expectedAddress?: string, | ||
) { | ||
expect(result.bitcoinAddress).toEqual(expectedAddress ?? ""); | ||
const expectedComponents = getXpubComponents(expectedXpub); | ||
const expectedPubKey = Buffer.from( | ||
ecc.pointCompress(expectedComponents.pubkey, false) | ||
); | ||
const expectedPubKey = Buffer.from(ecc.pointCompress(expectedComponents.pubkey, false)); | ||
expect(expectedPubKey.length).toEqual(65); | ||
expect(result.chainCode).toEqual( | ||
expectedComponents.chaincode.toString("hex") | ||
); | ||
expect(result.chainCode).toEqual(expectedComponents.chaincode.toString("hex")); | ||
expect(result.publicKey).toEqual(expectedPubKey.toString("hex")); | ||
@@ -194,3 +210,3 @@ } | ||
addressIndex: number, | ||
response: string | ||
response: string, | ||
) { | ||
@@ -218,3 +234,3 @@ const key = this.getWalletAddressKey(walletPolicy, change, addressIndex); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
display: boolean | ||
display: boolean, | ||
): Promise<string> { | ||
@@ -253,3 +269,3 @@ const key = this.getWalletAddressKey(walletPolicy, change, addressIndex); | ||
change: number, | ||
addressIndex: number | ||
addressIndex: number, | ||
): string { | ||
@@ -259,2 +275,1 @@ return walletPolicy.serialize().toString("hex") + change + addressIndex; | ||
} | ||
@@ -25,2 +25,2 @@ export const cla = "e1"; | ||
return resp + ascii(data) + ok; | ||
} | ||
} |
@@ -10,6 +10,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { AppClient } from "../../src/newops/appClient"; | ||
import { | ||
DefaultDescriptorTemplate, | ||
WalletPolicy, | ||
} from "../../src/newops/policy"; | ||
import { DefaultDescriptorTemplate, WalletPolicy } from "../../src/newops/policy"; | ||
import { Transaction } from "../../src/types"; | ||
@@ -22,3 +19,3 @@ import { CoreInput, CoreTx, spentTxs } from "./testtx"; | ||
client: TestingClient, | ||
transport: Transport | ||
transport: Transport, | ||
): Promise<string> { | ||
@@ -42,9 +39,3 @@ const btcNew = new BtcNew(client); | ||
const inputData = createInput(input, btc); | ||
const pubkey = getPubkey( | ||
index, | ||
accountType, | ||
testTx, | ||
inputData[0], | ||
inputData[1] | ||
); | ||
const pubkey = getPubkey(index, accountType, testTx, inputData[0], inputData[1]); | ||
const mockXpub = creatDummyXpub(pubkey); | ||
@@ -63,9 +54,8 @@ client.mockGetPubkeyResponse(path, mockXpub); | ||
outputWriter.writeVarInt(testTx.vout.length); | ||
testTx.vout.forEach((output) => { | ||
outputWriter.writeUInt64( | ||
Number.parseFloat((output.value * 100000000).toFixed(8)) | ||
); | ||
testTx.vout.forEach(output => { | ||
outputWriter.writeUInt64(Number.parseFloat((output.value * 100000000).toFixed(8))); | ||
outputWriter.writeVarSlice(Buffer.from(output.scriptPubKey.hex, "hex")); | ||
}); | ||
const outputScriptHex = outputWriter.buffer().toString("hex"); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
let callbacks = ""; | ||
@@ -85,5 +75,4 @@ function logCallback(message: string) { | ||
onDeviceSignatureGranted: () => logCallback("CALLBACK: signature granted"), | ||
onDeviceSignatureRequested: () => | ||
logCallback("CALLBACK: signature requested"), | ||
onDeviceStreaming: (arg) => logCallback("CALLBACK: " + JSON.stringify(arg)), | ||
onDeviceSignatureRequested: () => logCallback("CALLBACK: signature requested"), | ||
onDeviceStreaming: arg => logCallback("CALLBACK: " + JSON.stringify(arg)), | ||
}; | ||
@@ -98,3 +87,3 @@ logCallback("Start createPaymentTransaction"); | ||
export function addressFormatFromDescriptorTemplate( | ||
descTemp: DefaultDescriptorTemplate | ||
descTemp: DefaultDescriptorTemplate, | ||
): AddressFormat { | ||
@@ -120,3 +109,3 @@ if (descTemp == "tr(@0)") return "bech32m"; | ||
spentTx: Transaction, | ||
spentOutputIndex: number | ||
spentOutputIndex: number, | ||
): Buffer { | ||
@@ -130,6 +119,3 @@ const scriptSig = Buffer.from(testTx.vin[inputIndex].scriptSig.hex, "hex"); | ||
} | ||
if ( | ||
accountType == StandardPurpose.p2wpkh || | ||
accountType == StandardPurpose.p2wpkhInP2sh | ||
) { | ||
if (accountType == StandardPurpose.p2wpkh || accountType == StandardPurpose.p2wpkhInP2sh) { | ||
return Buffer.from(testTx.vin[inputIndex].txinwitness![1], "hex"); | ||
@@ -140,6 +126,3 @@ } | ||
function getSignature( | ||
testTxInput: CoreInput, | ||
accountType: StandardPurpose | ||
): Buffer { | ||
function getSignature(testTxInput: CoreInput, accountType: StandardPurpose): Buffer { | ||
const scriptSig = Buffer.from(testTxInput.scriptSig.hex, "hex"); | ||
@@ -152,6 +135,3 @@ if (accountType == StandardPurpose.p2pkh) { | ||
} | ||
if ( | ||
accountType == StandardPurpose.p2wpkh || | ||
accountType == StandardPurpose.p2wpkhInP2sh | ||
) { | ||
if (accountType == StandardPurpose.p2wpkh || accountType == StandardPurpose.p2wpkhInP2sh) { | ||
return Buffer.from(testTxInput.txinwitness![0], "hex"); | ||
@@ -184,6 +164,5 @@ } | ||
const xpubDecoded = bs58check.decode( | ||
"tpubDHcN44A4UHqdHJZwBxgTbu8Cy87ZrZkN8tQnmJGhcijHqe4rztuvGcD4wo36XSviLmiqL5fUbDnekYaQ7LzAnaqauBb9RsyahsTTFHdeJGd" | ||
"tpubDHcN44A4UHqdHJZwBxgTbu8Cy87ZrZkN8tQnmJGhcijHqe4rztuvGcD4wo36XSviLmiqL5fUbDnekYaQ7LzAnaqauBb9RsyahsTTFHdeJGd", | ||
); | ||
const pubkey33 = | ||
pubkey.length == 33 ? pubkey : Buffer.concat([Buffer.from([2]), pubkey]); | ||
const pubkey33 = pubkey.length == 33 ? pubkey : Buffer.concat([Buffer.from([2]), pubkey]); | ||
xpubDecoded.fill(pubkey33, xpubDecoded.length - 33); | ||
@@ -193,6 +172,3 @@ return bs58check.encode(xpubDecoded); | ||
function createInput( | ||
coreInput: CoreInput, | ||
btc: Btc | ||
): [Transaction, number, string | null, number] { | ||
function createInput(coreInput: CoreInput, btc: Btc): [Transaction, number, string | null, number] { | ||
const spentTx = spentTxs[coreInput.txid]; | ||
@@ -213,5 +189,5 @@ if (!spentTx) { | ||
_addressIndex: number, | ||
_response: string | ||
_response: string, | ||
): void {} | ||
mockSignPsbt(_yieldSigs: Map<number, Buffer>): void {} | ||
} |
@@ -17,4 +17,4 @@ import { Merkle } from "../../src/newops/merkle"; | ||
return new Merkle( | ||
leaves.map((v) => leaf(v)), | ||
testHasher | ||
leaves.map(v => leaf(v)), | ||
testHasher, | ||
).getRoot(); | ||
@@ -59,41 +59,13 @@ } | ||
test("Merkle proof of four", () => { | ||
expect(merkleOf(4).getProof(0)).toEqual([ | ||
rootOfLeaves(1), | ||
rootOfLeaves(2, 3), | ||
]); | ||
expect(merkleOf(4).getProof(1)).toEqual([ | ||
rootOfLeaves(0), | ||
rootOfLeaves(2, 3), | ||
]); | ||
expect(merkleOf(4).getProof(2)).toEqual([ | ||
rootOfLeaves(3), | ||
rootOfLeaves(0, 1), | ||
]); | ||
expect(merkleOf(4).getProof(3)).toEqual([ | ||
rootOfLeaves(2), | ||
rootOfLeaves(0, 1), | ||
]); | ||
expect(merkleOf(4).getProof(0)).toEqual([rootOfLeaves(1), rootOfLeaves(2, 3)]); | ||
expect(merkleOf(4).getProof(1)).toEqual([rootOfLeaves(0), rootOfLeaves(2, 3)]); | ||
expect(merkleOf(4).getProof(2)).toEqual([rootOfLeaves(3), rootOfLeaves(0, 1)]); | ||
expect(merkleOf(4).getProof(3)).toEqual([rootOfLeaves(2), rootOfLeaves(0, 1)]); | ||
}); | ||
test("Merkle proof of five", () => { | ||
expect(merkleOf(5).getProof(0)).toEqual([ | ||
rootOfLeaves(1), | ||
rootOfLeaves(2, 3), | ||
rootOfLeaves(4), | ||
]); | ||
expect(merkleOf(5).getProof(1)).toEqual([ | ||
rootOfLeaves(0), | ||
rootOfLeaves(2, 3), | ||
rootOfLeaves(4), | ||
]); | ||
expect(merkleOf(5).getProof(2)).toEqual([ | ||
rootOfLeaves(3), | ||
rootOfLeaves(0, 1), | ||
rootOfLeaves(4), | ||
]); | ||
expect(merkleOf(5).getProof(3)).toEqual([ | ||
rootOfLeaves(2), | ||
rootOfLeaves(0, 1), | ||
rootOfLeaves(4), | ||
]); | ||
expect(merkleOf(5).getProof(0)).toEqual([rootOfLeaves(1), rootOfLeaves(2, 3), rootOfLeaves(4)]); | ||
expect(merkleOf(5).getProof(1)).toEqual([rootOfLeaves(0), rootOfLeaves(2, 3), rootOfLeaves(4)]); | ||
expect(merkleOf(5).getProof(2)).toEqual([rootOfLeaves(3), rootOfLeaves(0, 1), rootOfLeaves(4)]); | ||
expect(merkleOf(5).getProof(3)).toEqual([rootOfLeaves(2), rootOfLeaves(0, 1), rootOfLeaves(4)]); | ||
expect(merkleOf(5).getProof(4)).toEqual([rootOfLeaves(0, 1, 2, 3)]); | ||
}); |
@@ -7,3 +7,3 @@ import { PsbtV2 } from "../../src/newops/psbtv2"; | ||
"cHNidP8BAAoBAAAAAAAAAAAAAQIEAgAAAAEDBAAAAAABBAECAQUBAgH7BAIAAAAAAQBxAgAAAAGTarLgEHL3k8/kyXdU3hth/gPn22U2yLLyHdC1dCxIRQEAAAAA/v///wLe4ccAAAAAABYAFOt418QL8QY7Dj/OKcNWW2ichVmrECcAAAAAAAAWABQjGNZvhP71xIdfkzsDjcY4MfjaE/mXHgABAR8QJwAAAAAAABYAFCMY1m+E/vXEh1+TOwONxjgx+NoTIgYDRV7nztyXsLpDW4AGb8ksljo0xgAxeYHRNTMMTuQ6x6MY9azC/VQAAIABAACAAAAAgAAAAAABAAAAAQ4gniz+J/Cth7eKI31ddAXUowZmyjYdWFpGew3+QiYrTbQBDwQBAAAAARAE/f///wESBAAAAAAAAQBxAQAAAAEORx706Sway1HvyGYPjT9pk26pybK/9y/5vIHFHvz0ZAEAAAAAAAAAAAJgrgoAAAAAABYAFDXG4N1tPISxa6iF3Kc6yGPQtZPsrwYyAAAAAAAWABTcKG4M0ua9N86+nsNJ+18IkFZy/AAAAAABAR9grgoAAAAAABYAFDXG4N1tPISxa6iF3Kc6yGPQtZPsIgYCcbW3ea2HCDhYd5e89vDHrsWr52pwnXJPSNLibPh08KAY9azC/VQAAIABAACAAAAAgAEAAAAAAAAAAQ4gr7+uBlkPdB/xr1m2rEYRJjNqTEqC21U99v76tzesM/MBDwQAAAAAARAE/f///wESBAAAAAAAIgICKexHcnEx7SWIogxG7amrt9qm9J/VC6/nC5xappYcTswY9azC/VQAAIABAACAAAAAgAEAAAAKAAAAAQMIqDoGAAAAAAABBBYAFOs4+puBKPgfJule2wxf+uqDaQ/kAAEDCOCTBAAAAAAAAQQiACA/qWbJ3c3C/ZbkpeG8dlufr2zos+tPEQSq1r33cyTlvgA=", | ||
"base64" | ||
"base64", | ||
); | ||
@@ -10,0 +10,0 @@ |
@@ -1,5 +0,2 @@ | ||
import { | ||
openTransportReplayer, | ||
RecordStore, | ||
} from "@ledgerhq/hw-transport-mocker"; | ||
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker"; | ||
import Btc from "../src/Btc"; | ||
@@ -36,3 +33,3 @@ | ||
<= 3045022100e4acf0eb3803a62399f53825d86aa30743fe999eefb01522d5f7ecd9eeec663d022063b90c512e207c2ac47d8759e1c73c6abeff58daec31c48905193470bc87f2d3019000 | ||
`) | ||
`), | ||
); | ||
@@ -45,5 +42,5 @@ const btc = new Btc({ transport, currency: "zcash" }); | ||
false, | ||
["zencash"] | ||
["zencash"], | ||
); | ||
expect(tx1.outputs?.length).toEqual(40); // 40 outputs in the above transaction. refer to https://explorer.zen-solutions.io/tx/1af7f8e4c77b35f558ee11defe7590c30e85723c0d846787729ecd4fbd45a533 | ||
}); |
@@ -6,6 +6,3 @@ import axios from "axios"; | ||
export async function approveTransaction(): Promise<void> { | ||
await axios.post( | ||
`${SPECULOS_REST_API_ENDPOINT}/automation`, | ||
approveTransactionScript | ||
); | ||
await axios.post(`${SPECULOS_REST_API_ENDPOINT}/automation`, approveTransactionScript); | ||
} | ||
@@ -15,35 +12,49 @@ | ||
const approveTransactionScript = { | ||
"version": 1, | ||
"rules": [ | ||
version: 1, | ||
rules: [ | ||
{ | ||
"text": "output #1", | ||
"actions": [ | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
["button", 1, true], ["button", 1, false], | ||
["button", 1, true], ["button", 2, true], | ||
["button", 1, false], ["button", 2, false], | ||
] | ||
text: "output #1", | ||
actions: [ | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 1, true], | ||
["button", 1, false], | ||
["button", 1, true], | ||
["button", 2, true], | ||
["button", 1, false], | ||
["button", 2, false], | ||
], | ||
}, | ||
{ | ||
"text": "transaction", | ||
"actions": [ | ||
["button", 2, true], ["button", 2, false], | ||
["button", 2, true], ["button", 2, false], | ||
] | ||
text: "transaction", | ||
actions: [ | ||
["button", 2, true], | ||
["button", 2, false], | ||
["button", 2, true], | ||
["button", 2, false], | ||
], | ||
}, | ||
{ | ||
"text": "and send", | ||
"actions": [ | ||
["button", 1, true], ["button", 2, true], | ||
["button", 1, false], ["button", 2, false], | ||
] | ||
} | ||
] | ||
} | ||
text: "and send", | ||
actions: [ | ||
["button", 1, true], | ||
["button", 2, true], | ||
["button", 1, false], | ||
["button", 2, false], | ||
], | ||
}, | ||
], | ||
}; | ||
/* eslint-enable */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1079860
15402
1