@ledgerhq/hw-app-btc 6.12.0 → 6.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/BtcNew.d.ts +1 -0
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +47 -17
- package/lib/BtcNew.js.map +1 -1
- package/lib/buffertools.d.ts +4 -2
- package/lib/buffertools.d.ts.map +1 -1
- package/lib/buffertools.js +37 -5
- package/lib/buffertools.js.map +1 -1
- package/lib/newops/accounttype.d.ts.map +1 -1
- package/lib/newops/accounttype.js +9 -6
- package/lib/newops/accounttype.js.map +1 -1
- package/lib/newops/appClient.d.ts +2 -1
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/appClient.js +4 -4
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts +3 -41
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +7 -12
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkle.js +2 -2
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/psbtExtractor.js +3 -3
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +7 -8
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib-es/BtcNew.d.ts +1 -0
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +47 -17
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/buffertools.d.ts +4 -2
- package/lib-es/buffertools.d.ts.map +1 -1
- package/lib-es/buffertools.js +34 -4
- package/lib-es/buffertools.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts.map +1 -1
- package/lib-es/newops/accounttype.js +9 -6
- package/lib-es/newops/accounttype.js.map +1 -1
- package/lib-es/newops/appClient.d.ts +2 -1
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/appClient.js +4 -4
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts +3 -41
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +6 -11
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkle.js +2 -2
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/psbtExtractor.js +3 -3
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +8 -9
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/package.json +2 -2
- package/src/BtcNew.ts +55 -18
- package/src/buffertools.ts +38 -6
- package/src/newops/accounttype.ts +9 -6
- package/src/newops/appClient.ts +6 -6
- package/src/newops/clientCommands.ts +15 -11
- package/src/newops/merkle.ts +2 -2
- package/src/newops/psbtExtractor.ts +3 -3
- package/src/newops/psbtv2.ts +13 -11
- package/tests/Btc.test.ts +68 -45
- package/tests/buffertools.test.ts +25 -0
- package/tests/newops/BtcNew.test.ts +13 -0
- package/tests/newops/integrationtools.ts +58 -28
- package/tests/newops/merkle.test.ts +1 -1
package/tests/Btc.test.ts
CHANGED
|
@@ -106,14 +106,24 @@ ascii(1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb)
|
|
|
106
106
|
8bd937d416de7020952cc8e2c99ce9ac7e01265e31ceb8e47bf9c37f46f8abbd
|
|
107
107
|
*/
|
|
108
108
|
/*eslint-disable */
|
|
109
|
-
const pubkeyParent =
|
|
110
|
-
|
|
111
|
-
const
|
|
109
|
+
const pubkeyParent =
|
|
110
|
+
"045d4a72237572a91e13818fa38cedabe6174569cc9a319012f75150d5c0a0639d54eafd13a68d079b7a67764800c6a981825ef52384f08c3925109188ab21bc09";
|
|
111
|
+
const addrParent = Buffer.from(
|
|
112
|
+
"1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb",
|
|
113
|
+
"ascii"
|
|
114
|
+
).toString("hex");
|
|
115
|
+
const ccParent =
|
|
116
|
+
"8bd937d416de7020952cc8e2c99ce9ac7e01265e31ceb8e47bf9c37f46f8abbd";
|
|
112
117
|
const responseParent = `41${pubkeyParent}22${addrParent}${ccParent}`;
|
|
113
118
|
|
|
114
|
-
const pubkeyAcc =
|
|
115
|
-
|
|
116
|
-
const
|
|
119
|
+
const pubkeyAcc =
|
|
120
|
+
"04250dfdfb84c1efd160ed0e10ebac845d0e4b04277174630ba56de96bbd3afb21fc6c04ce0d5a0cbd784fdabc99d16269c27cf3842fe8440f1f21b8af900f0eaa";
|
|
121
|
+
const addrAcc = Buffer.from(
|
|
122
|
+
"16Y97ByhyboePhTYMMmFj1tq5Cy1bDq8jT",
|
|
123
|
+
"ascii"
|
|
124
|
+
).toString("hex");
|
|
125
|
+
const ccAcc =
|
|
126
|
+
"c071c6f2d05cbc9ea9a04951b238086ce1608cf00020c3cab85b36aac5fdd591";
|
|
117
127
|
/*eslint-enable */
|
|
118
128
|
const responseAcc = `41${pubkeyAcc}22${addrAcc}${ccAcc}`;
|
|
119
129
|
const transport = await openTransportReplayer(
|
|
@@ -123,7 +133,7 @@ ascii(1NjiCsVBuKDT62LmaUd7WZZZBK2gPAkisb)
|
|
|
123
133
|
=> e040000009028000002c80000000
|
|
124
134
|
<= ${responseParent}9000
|
|
125
135
|
=> e04000000d038000002c8000000080000011
|
|
126
|
-
<= ${responseAcc}9000
|
|
136
|
+
<= ${responseAcc}9000
|
|
127
137
|
`)
|
|
128
138
|
);
|
|
129
139
|
const btc = new Btc(transport);
|
|
@@ -430,7 +440,7 @@ test("signMessage", async () => {
|
|
|
430
440
|
function testBackend(s: string): any {
|
|
431
441
|
return async () => {
|
|
432
442
|
return { publicKey: s, bitcoinAddress: "", chainCode: "" };
|
|
433
|
-
}
|
|
443
|
+
};
|
|
434
444
|
}
|
|
435
445
|
|
|
436
446
|
class TestBtc extends Btc {
|
|
@@ -461,43 +471,51 @@ class TestBtc extends Btc {
|
|
|
461
471
|
// });
|
|
462
472
|
|
|
463
473
|
test.each`
|
|
464
|
-
app | ver
|
|
465
|
-
${"Bitcoin"} | ${"1.99.99"}
|
|
466
|
-
${"Bitcoin"} | ${"1.99.99"}
|
|
467
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'"}
|
|
468
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'"}
|
|
469
|
-
${"Bitcoin"} | ${"2.0.0-beta"}
|
|
470
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'"}
|
|
471
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'"}
|
|
472
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'"}
|
|
473
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/0/0"} | ${"bech32"}
|
|
474
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/1/0"} | ${"bech32"}
|
|
475
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/1/0"} | ${"legacy"}
|
|
476
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/1/0"} | ${"p2sh"}
|
|
477
|
-
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/2/0"} | ${"bech32"}
|
|
478
|
-
`(
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
474
|
+
app | ver | path | format | display | exp
|
|
475
|
+
${"Bitcoin"} | ${"1.99.99"} | ${"m/44'/0'/1'"} | ${"bech32m"} | ${false} | ${""}
|
|
476
|
+
${"Bitcoin"} | ${"1.99.99"} | ${"m/44'/0'"} | ${"bech32m"} | ${false} | ${""}
|
|
477
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'"} | ${"bech32m"} | ${false} | ${"new"}
|
|
478
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'"} | ${"bech32m"} | ${false} | ${"new"}
|
|
479
|
+
${"Bitcoin"} | ${"2.0.0-beta"} | ${"m/84'/1'/0'"} | ${"bech32"} | ${false} | ${"new"}
|
|
480
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'"} | ${"bech32"} | ${false} | ${"new"}
|
|
481
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'"} | ${"bech32"} | ${undefined} | ${"old"}
|
|
482
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'"} | ${"bech32"} | ${true} | ${"new"}
|
|
483
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/0/0"} | ${"bech32"} | ${false} | ${"new"}
|
|
484
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/1/0"} | ${"bech32"} | ${false} | ${"new"}
|
|
485
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/1/0"} | ${"legacy"} | ${false} | ${"new"}
|
|
486
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/1/0"} | ${"p2sh"} | ${false} | ${"new"}
|
|
487
|
+
${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/2/0"} | ${"bech32"} | ${false} | ${"old"}
|
|
488
|
+
`(
|
|
489
|
+
"dispatch $app $ver $path $format $display to $exp",
|
|
490
|
+
async ({ app, ver, path, format, display, exp }) => {
|
|
491
|
+
const appName = Buffer.from([app.length])
|
|
492
|
+
.toString("hex")
|
|
493
|
+
.concat(Buffer.from(app, "ascii").toString("hex"));
|
|
494
|
+
const appVersion = Buffer.from([ver.length])
|
|
495
|
+
.toString("hex")
|
|
496
|
+
.concat(Buffer.from(ver, "ascii").toString("hex"));
|
|
497
|
+
const resp = `01${appName}${appVersion}01029000`;
|
|
498
|
+
const tr = await openTransportReplayer(
|
|
499
|
+
RecordStore.fromString(`=> b001000000\n <= ${resp}`)
|
|
500
|
+
);
|
|
501
|
+
const btc = new TestBtc(tr);
|
|
502
|
+
try {
|
|
503
|
+
const key = await btc.getWalletPublicKey(path, {
|
|
504
|
+
format: format,
|
|
505
|
+
verify: display,
|
|
506
|
+
});
|
|
507
|
+
if (exp === "") {
|
|
508
|
+
expect(1).toEqual(0); // Allways fail. Don't know how to do that properly
|
|
509
|
+
}
|
|
510
|
+
expect(key.publicKey).toEqual(exp);
|
|
511
|
+
} catch (e: any) {
|
|
512
|
+
if (exp != "") {
|
|
513
|
+
throw e;
|
|
514
|
+
}
|
|
515
|
+
expect(exp).toEqual("");
|
|
497
516
|
}
|
|
498
|
-
expect(exp).toEqual("");
|
|
499
517
|
}
|
|
500
|
-
|
|
518
|
+
);
|
|
501
519
|
|
|
502
520
|
// test("getWalletPublicKey compatibility for internal hardened keys", async () => {
|
|
503
521
|
// await testDispatch("Bitcoin", "1.99.99", "m/44'/0'/1'", "bech32m", "");
|
|
@@ -508,5 +526,10 @@ ${"Bitcoin"} | ${"2.0.0-alpha1"} | ${"m/44'/0'/1'/2/0"} | ${"bech32"} | ${false}
|
|
|
508
526
|
// await testDispatch("Bitcoin", "2.0.0-alpha1", "m/44'/0'", "bech32", "old");
|
|
509
527
|
// });
|
|
510
528
|
|
|
511
|
-
async function testDispatch(
|
|
512
|
-
|
|
529
|
+
async function testDispatch(
|
|
530
|
+
name: string,
|
|
531
|
+
version: string,
|
|
532
|
+
path: string,
|
|
533
|
+
addressFormat: AddressFormat | undefined,
|
|
534
|
+
exp: string
|
|
535
|
+
): Promise<void> {}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BufferReader, BufferWriter } from "../src/buffertools"
|
|
2
|
+
|
|
3
|
+
function run(n: number, expectedHex: string) {
|
|
4
|
+
const w = new BufferWriter();
|
|
5
|
+
w.writeUInt64(n)
|
|
6
|
+
expect(w.buffer()).toEqual(Buffer.from(expectedHex, "hex"));
|
|
7
|
+
const r = new BufferReader(w.buffer());
|
|
8
|
+
expect(r.readUInt64()).toEqual(n);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
test("Test 64 bit numbers", () => {
|
|
12
|
+
run(0, "0000000000000000");
|
|
13
|
+
run(1, "0100000000000000");
|
|
14
|
+
run(0xffffffff, "ffffffff00000000");
|
|
15
|
+
run(0x0100000000, "0000000001000000");
|
|
16
|
+
run(0x010203040506, "0605040302010000");
|
|
17
|
+
run(Number.MAX_SAFE_INTEGER, "FFFFFFFFFFFF1F00");
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test("Too big 64 bit number", () => {
|
|
21
|
+
const w = new BufferWriter();
|
|
22
|
+
expect(() => w.writeUInt64(Number.MAX_SAFE_INTEGER+1)).toThrow();
|
|
23
|
+
const r = new BufferReader(Buffer.from("FFFFFFFFFFFF2000", "hex"))
|
|
24
|
+
expect(() => r.readUInt64()).toThrow();
|
|
25
|
+
})
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
WalletPolicy
|
|
10
10
|
} from "../../src/newops/policy";
|
|
11
11
|
import { PsbtV2 } from "../../src/newops/psbtv2";
|
|
12
|
+
import { splitTransaction } from "../../src/splitTransaction";
|
|
12
13
|
import { StandardPurpose, addressFormatFromDescriptorTemplate, creatDummyXpub, masterFingerprint, runSignTransaction, TestingClient } from "./integrationtools";
|
|
13
14
|
import { CoreInput, CoreTx, p2pkh, p2tr, p2wpkh, wrappedP2wpkh, wrappedP2wpkhTwoInputs } from "./testtx";
|
|
14
15
|
|
|
@@ -83,6 +84,18 @@ test("Sign p2tr with sigHashType", async () => {
|
|
|
83
84
|
// The verification of the sighashtype is done in MockClient.signPsbt
|
|
84
85
|
})
|
|
85
86
|
|
|
87
|
+
test("Sign p2tr sequence 0", async() => {
|
|
88
|
+
const testTx = JSON.parse(JSON.stringify(p2tr));
|
|
89
|
+
testTx.vin.forEach((input: CoreInput, index: number) => {
|
|
90
|
+
input.sequence = 0;
|
|
91
|
+
})
|
|
92
|
+
const tx = await runSignTransactionNoVerification(testTx, StandardPurpose.p2tr);
|
|
93
|
+
const txObj = splitTransaction(tx, true);
|
|
94
|
+
txObj.inputs.forEach((input, index) => {
|
|
95
|
+
expect(input.sequence.toString("hex")).toEqual("00000000");
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
86
99
|
async function runSignTransactionTest(testTx: CoreTx, accountType: StandardPurpose, changePubkey?: string) {
|
|
87
100
|
const tx = await runSignTransactionNoVerification(testTx, accountType, changePubkey);
|
|
88
101
|
expect(tx).toEqual(testTx.hex);
|
|
@@ -9,17 +9,17 @@ import { AddressFormat } from "../../src/getWalletPublicKey";
|
|
|
9
9
|
import { AppClient } from "../../src/newops/appClient";
|
|
10
10
|
import {
|
|
11
11
|
DefaultDescriptorTemplate,
|
|
12
|
-
WalletPolicy
|
|
12
|
+
WalletPolicy,
|
|
13
13
|
} from "../../src/newops/policy";
|
|
14
14
|
import { Transaction } from "../../src/types";
|
|
15
15
|
import { CoreInput, CoreTx, spentTxs } from "./testtx";
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
export async function runSignTransaction(
|
|
19
18
|
testTx: CoreTx,
|
|
20
|
-
testPaths: { ins: string[]
|
|
19
|
+
testPaths: { ins: string[]; out?: string },
|
|
21
20
|
client: TestingClient,
|
|
22
|
-
transport: Transport
|
|
21
|
+
transport: Transport
|
|
22
|
+
): Promise<string> {
|
|
23
23
|
const btcNew = new BtcNew(client);
|
|
24
24
|
// btc is needed to perform some functions like splitTransaction.
|
|
25
25
|
const btc = new Btc(transport);
|
|
@@ -37,30 +37,38 @@ export async function runSignTransaction(
|
|
|
37
37
|
const path = testPaths.ins[index];
|
|
38
38
|
associatedKeysets.push(path);
|
|
39
39
|
const inputData = createInput(input, btc);
|
|
40
|
-
const pubkey = getPubkey(
|
|
40
|
+
const pubkey = getPubkey(
|
|
41
|
+
index,
|
|
42
|
+
accountType,
|
|
43
|
+
testTx,
|
|
44
|
+
inputData[0],
|
|
45
|
+
inputData[1]
|
|
46
|
+
);
|
|
41
47
|
const mockXpub = creatDummyXpub(pubkey);
|
|
42
48
|
client.mockGetPubkeyResponse(path, mockXpub);
|
|
43
49
|
yieldSigs.set(index, getSignature(input, accountType));
|
|
44
50
|
return inputData;
|
|
45
51
|
});
|
|
46
52
|
const sig0 = yieldSigs.get(0)!;
|
|
47
|
-
let sigHashType: number | undefined = sig0.readUInt8(sig0.length - 1)
|
|
53
|
+
let sigHashType: number | undefined = sig0.readUInt8(sig0.length - 1);
|
|
48
54
|
if (sigHashType == 0x01) {
|
|
49
55
|
sigHashType = undefined;
|
|
50
56
|
}
|
|
51
57
|
client.mockSignPsbt(yieldSigs);
|
|
52
58
|
const outputWriter = new BufferWriter();
|
|
53
59
|
outputWriter.writeVarInt(testTx.vout.length);
|
|
54
|
-
testTx.vout.forEach(output => {
|
|
55
|
-
outputWriter.writeUInt64(
|
|
60
|
+
testTx.vout.forEach((output) => {
|
|
61
|
+
outputWriter.writeUInt64(
|
|
62
|
+
Number.parseFloat((output.value * 100000000).toFixed(8))
|
|
63
|
+
);
|
|
56
64
|
outputWriter.writeVarSlice(Buffer.from(output.scriptPubKey.hex, "hex"));
|
|
57
65
|
});
|
|
58
|
-
const outputScriptHex = outputWriter.buffer().toString("hex");
|
|
66
|
+
const outputScriptHex = outputWriter.buffer().toString("hex");
|
|
59
67
|
let callbacks = "";
|
|
60
68
|
function logCallback(message: string) {
|
|
61
69
|
callbacks += new Date().toISOString() + " " + message + "\n";
|
|
62
70
|
}
|
|
63
|
-
const arg: CreateTransactionArg = {
|
|
71
|
+
const arg: CreateTransactionArg = {
|
|
64
72
|
inputs,
|
|
65
73
|
additionals,
|
|
66
74
|
associatedKeysets,
|
|
@@ -70,19 +78,20 @@ export async function runSignTransaction(
|
|
|
70
78
|
sigHashType,
|
|
71
79
|
segwit: accountType != StandardPurpose.p2pkh,
|
|
72
80
|
onDeviceSignatureGranted: () => logCallback("CALLBACK: signature granted"),
|
|
73
|
-
onDeviceSignatureRequested: () =>
|
|
74
|
-
|
|
81
|
+
onDeviceSignatureRequested: () =>
|
|
82
|
+
logCallback("CALLBACK: signature requested"),
|
|
83
|
+
onDeviceStreaming: (arg) => logCallback("CALLBACK: " + JSON.stringify(arg)),
|
|
75
84
|
};
|
|
76
85
|
logCallback("Start createPaymentTransactionNew");
|
|
77
86
|
const tx = await btcNew.createPaymentTransactionNew(arg);
|
|
78
87
|
logCallback("Done createPaymentTransactionNew");
|
|
79
88
|
// console.log(callbacks);
|
|
80
89
|
return tx;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
}
|
|
84
91
|
|
|
85
|
-
export function addressFormatFromDescriptorTemplate(
|
|
92
|
+
export function addressFormatFromDescriptorTemplate(
|
|
93
|
+
descTemp: DefaultDescriptorTemplate
|
|
94
|
+
): AddressFormat {
|
|
86
95
|
if (descTemp == "tr(@0)") return "bech32m";
|
|
87
96
|
if (descTemp == "pkh(@0)") return "legacy";
|
|
88
97
|
if (descTemp == "wpkh(@0)") return "bech32";
|
|
@@ -94,10 +103,16 @@ export enum StandardPurpose {
|
|
|
94
103
|
p2tr = "86'",
|
|
95
104
|
p2wpkh = "84'",
|
|
96
105
|
p2wpkhInP2sh = "49'",
|
|
97
|
-
p2pkh = "44'"
|
|
106
|
+
p2pkh = "44'",
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
function getPubkey(
|
|
109
|
+
function getPubkey(
|
|
110
|
+
inputIndex: number,
|
|
111
|
+
accountType: StandardPurpose,
|
|
112
|
+
testTx: CoreTx,
|
|
113
|
+
spentTx: Transaction,
|
|
114
|
+
spentOutputIndex: number
|
|
115
|
+
): Buffer {
|
|
101
116
|
const scriptSig = Buffer.from(testTx.vin[inputIndex].scriptSig.hex, "hex");
|
|
102
117
|
if (accountType == StandardPurpose.p2pkh) {
|
|
103
118
|
return scriptSig.slice(scriptSig.length - 33);
|
|
@@ -105,13 +120,19 @@ function getPubkey(inputIndex: number, accountType: StandardPurpose, testTx: Cor
|
|
|
105
120
|
if (accountType == StandardPurpose.p2tr) {
|
|
106
121
|
return spentTx.outputs![spentOutputIndex].script.slice(2, 34); // 32 bytes x-only pubkey
|
|
107
122
|
}
|
|
108
|
-
if (
|
|
123
|
+
if (
|
|
124
|
+
accountType == StandardPurpose.p2wpkh ||
|
|
125
|
+
accountType == StandardPurpose.p2wpkhInP2sh
|
|
126
|
+
) {
|
|
109
127
|
return Buffer.from(testTx.vin[inputIndex].txinwitness![1], "hex");
|
|
110
128
|
}
|
|
111
129
|
throw new Error();
|
|
112
130
|
}
|
|
113
131
|
|
|
114
|
-
function getSignature(
|
|
132
|
+
function getSignature(
|
|
133
|
+
testTxInput: CoreInput,
|
|
134
|
+
accountType: StandardPurpose
|
|
135
|
+
): Buffer {
|
|
115
136
|
const scriptSig = Buffer.from(testTxInput.scriptSig.hex, "hex");
|
|
116
137
|
if (accountType == StandardPurpose.p2pkh) {
|
|
117
138
|
return scriptSig.slice(1, scriptSig.length - 34);
|
|
@@ -119,7 +140,10 @@ function getSignature(testTxInput: CoreInput, accountType: StandardPurpose): Buf
|
|
|
119
140
|
if (accountType == StandardPurpose.p2tr) {
|
|
120
141
|
return Buffer.from(testTxInput.txinwitness![0], "hex");
|
|
121
142
|
}
|
|
122
|
-
if (
|
|
143
|
+
if (
|
|
144
|
+
accountType == StandardPurpose.p2wpkh ||
|
|
145
|
+
accountType == StandardPurpose.p2wpkhInP2sh
|
|
146
|
+
) {
|
|
123
147
|
return Buffer.from(testTxInput.txinwitness![0], "hex");
|
|
124
148
|
}
|
|
125
149
|
throw new Error();
|
|
@@ -146,13 +170,19 @@ function getAccountType(coreInput: CoreInput, btc: Btc): StandardPurpose {
|
|
|
146
170
|
}
|
|
147
171
|
|
|
148
172
|
export function creatDummyXpub(pubkey: Buffer): string {
|
|
149
|
-
const xpubDecoded = bs58check.decode(
|
|
150
|
-
|
|
173
|
+
const xpubDecoded = bs58check.decode(
|
|
174
|
+
"tpubDHcN44A4UHqdHJZwBxgTbu8Cy87ZrZkN8tQnmJGhcijHqe4rztuvGcD4wo36XSviLmiqL5fUbDnekYaQ7LzAnaqauBb9RsyahsTTFHdeJGd"
|
|
175
|
+
);
|
|
176
|
+
const pubkey33 =
|
|
177
|
+
pubkey.length == 33 ? pubkey : Buffer.concat([Buffer.from([2]), pubkey]);
|
|
151
178
|
xpubDecoded.fill(pubkey33, xpubDecoded.length - 33);
|
|
152
179
|
return bs58check.encode(xpubDecoded);
|
|
153
180
|
}
|
|
154
181
|
|
|
155
|
-
function createInput(
|
|
182
|
+
function createInput(
|
|
183
|
+
coreInput: CoreInput,
|
|
184
|
+
btc: Btc
|
|
185
|
+
): [Transaction, number, string | null, number] {
|
|
156
186
|
const spentTx = spentTxs[coreInput.txid];
|
|
157
187
|
if (!spentTx) {
|
|
158
188
|
throw new Error("Spent tx " + coreInput.txid + " unavailable.");
|
|
@@ -161,14 +191,14 @@ function createInput(coreInput: CoreInput, btc: Btc): [Transaction, number, stri
|
|
|
161
191
|
return [splitSpentTx, coreInput.vout, null, coreInput.sequence];
|
|
162
192
|
}
|
|
163
193
|
|
|
164
|
-
export const masterFingerprint = Buffer.
|
|
194
|
+
export const masterFingerprint = Buffer.from([1, 2, 3, 4]);
|
|
165
195
|
export class TestingClient extends AppClient {
|
|
166
|
-
mockGetPubkeyResponse(_pathElements: string, _response: string): void {
|
|
196
|
+
mockGetPubkeyResponse(_pathElements: string, _response: string): void {}
|
|
167
197
|
mockGetWalletAddressResponse(
|
|
168
198
|
_walletPolicy: WalletPolicy,
|
|
169
199
|
_change: number,
|
|
170
200
|
_addressIndex: number,
|
|
171
201
|
_response: string
|
|
172
|
-
): void {
|
|
173
|
-
mockSignPsbt(_yieldSigs: Map<number, Buffer>): void {
|
|
202
|
+
): void {}
|
|
203
|
+
mockSignPsbt(_yieldSigs: Map<number, Buffer>): void {}
|
|
174
204
|
}
|