@ledgerhq/hw-app-btc 10.8.0 → 10.9.0-next.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/CHANGELOG.md +6 -0
- package/lib/constants.d.ts +8 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +17 -3
- package/lib/constants.js.map +1 -1
- package/lib/createTransaction.d.ts +2 -3
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/createTransaction.js +37 -22
- package/lib/createTransaction.js.map +1 -1
- package/lib/getTrustedInput.d.ts.map +1 -1
- package/lib/getTrustedInput.js +5 -0
- package/lib/getTrustedInput.js.map +1 -1
- package/lib/serializeTransaction.js +1 -1
- package/lib/serializeTransaction.js.map +1 -1
- package/lib/splitTransaction.d.ts.map +1 -1
- package/lib/splitTransaction.js.map +1 -1
- package/lib/startUntrustedHashTransactionInput.d.ts.map +1 -1
- package/lib/startUntrustedHashTransactionInput.js +3 -0
- package/lib/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.d.ts.map +1 -1
- package/lib-es/constants.d.ts +8 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +16 -2
- package/lib-es/constants.js.map +1 -1
- package/lib-es/createTransaction.d.ts +2 -3
- package/lib-es/createTransaction.d.ts.map +1 -1
- package/lib-es/createTransaction.js +36 -22
- package/lib-es/createTransaction.js.map +1 -1
- package/lib-es/getTrustedInput.d.ts.map +1 -1
- package/lib-es/getTrustedInput.js +5 -0
- package/lib-es/getTrustedInput.js.map +1 -1
- package/lib-es/serializeTransaction.js +1 -1
- package/lib-es/serializeTransaction.js.map +1 -1
- package/lib-es/splitTransaction.d.ts.map +1 -1
- package/lib-es/splitTransaction.js.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.d.ts.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.js +3 -0
- package/lib-es/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib-es/types.d.ts +1 -0
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +16 -2
- package/src/createTransaction.ts +30 -25
- package/src/getTrustedInput.ts +5 -0
- package/src/serializeTransaction.ts +1 -1
- package/src/splitTransaction.ts +1 -0
- package/src/startUntrustedHashTransactionInput.ts +3 -0
- package/src/types.ts +2 -0
- package/tests/createTransaction.test.ts +7 -19
- package/tests/splitTransaction.test.ts +85 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZCASH_ACTIVATION_HEIGHTS } from "../src/constants";
|
|
2
2
|
import { getDefaultVersions } from "../src/createTransaction";
|
|
3
3
|
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
4
4
|
import Btc from "../src/Btc";
|
|
@@ -10,7 +10,7 @@ describe("createTransaction", () => {
|
|
|
10
10
|
RecordStore.fromString(`
|
|
11
11
|
=> b001000000
|
|
12
12
|
<= 01055a6361736805322e332e3101029000
|
|
13
|
-
=>
|
|
13
|
+
=> e04200001100000000050000800a27a726b4d0d6c201
|
|
14
14
|
<= 9000
|
|
15
15
|
=> e0428000251d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f4010000006a
|
|
16
16
|
<= 9000
|
|
@@ -28,7 +28,7 @@ describe("createTransaction", () => {
|
|
|
28
28
|
<= 9000
|
|
29
29
|
=> e042800009000000000400000000
|
|
30
30
|
<= 3200ed40989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb0000000050c3000000000000d53c396d2f5c98619000
|
|
31
|
-
=>
|
|
31
|
+
=> e04200001100000000050000800a27a7265510e7c801
|
|
32
32
|
<= 9000
|
|
33
33
|
=> e0428000258c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d11000000006b
|
|
34
34
|
<= 9000
|
|
@@ -51,7 +51,7 @@ describe("createTransaction", () => {
|
|
|
51
51
|
<= 9000
|
|
52
52
|
=> e04000000100
|
|
53
53
|
<= 9000
|
|
54
|
-
=>
|
|
54
|
+
=> e044000009010000005510e7c802
|
|
55
55
|
<= 9000
|
|
56
56
|
|
|
57
57
|
=> e04480003b01383200ed40989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb0000000050c3000000000000d53c396d2f5c986119
|
|
@@ -74,7 +74,7 @@ describe("createTransaction", () => {
|
|
|
74
74
|
<= 00009000
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
=>
|
|
77
|
+
=> e044008009010000005510e7c802
|
|
78
78
|
<= 9000
|
|
79
79
|
|
|
80
80
|
=> e04480803b01383200ed40989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb0000000050c3000000000000d53c396d2f5c986100
|
|
@@ -154,10 +154,8 @@ output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61
|
|
|
154
154
|
sapling: false,
|
|
155
155
|
isDecred: false,
|
|
156
156
|
expiryHeight: undefined,
|
|
157
|
-
blockHeight: undefined,
|
|
158
157
|
});
|
|
159
158
|
expect(result.defaultVersion.readUInt32LE(0)).toBe(1);
|
|
160
|
-
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(1);
|
|
161
159
|
});
|
|
162
160
|
|
|
163
161
|
it("should return Zcash versions with expiryHeight and blockHeight below activation height", () => {
|
|
@@ -166,24 +164,20 @@ output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61
|
|
|
166
164
|
sapling: false,
|
|
167
165
|
isDecred: false,
|
|
168
166
|
expiryHeight: Buffer.alloc(4),
|
|
169
|
-
blockHeight: 1000,
|
|
170
167
|
});
|
|
171
168
|
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000005);
|
|
172
|
-
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000005);
|
|
173
169
|
});
|
|
174
170
|
|
|
175
171
|
it("should return Zcash versions with expiryHeight and blockHeight above activation height", () => {
|
|
176
172
|
const blockHeight = 3_000_000;
|
|
177
|
-
expect(blockHeight >
|
|
173
|
+
expect(blockHeight > ZCASH_ACTIVATION_HEIGHTS.NU6).toBe(true);
|
|
178
174
|
const result = getDefaultVersions({
|
|
179
175
|
isZcash: true,
|
|
180
176
|
sapling: false,
|
|
181
177
|
isDecred: false,
|
|
182
178
|
expiryHeight: Buffer.alloc(4),
|
|
183
|
-
blockHeight: blockHeight,
|
|
184
179
|
});
|
|
185
|
-
expect(result.defaultVersion.readUInt32LE(0)).toBe(
|
|
186
|
-
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000005);
|
|
180
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000005);
|
|
187
181
|
});
|
|
188
182
|
|
|
189
183
|
it("should return Sapling versions with expiryHeight", () => {
|
|
@@ -192,10 +186,8 @@ output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61
|
|
|
192
186
|
sapling: true,
|
|
193
187
|
isDecred: false,
|
|
194
188
|
expiryHeight: Buffer.alloc(4),
|
|
195
|
-
blockHeight: undefined,
|
|
196
189
|
});
|
|
197
190
|
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000004);
|
|
198
|
-
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000004);
|
|
199
191
|
});
|
|
200
192
|
|
|
201
193
|
it("should return non-Sapling versions with expiryHeight", () => {
|
|
@@ -204,10 +196,8 @@ output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61
|
|
|
204
196
|
sapling: false,
|
|
205
197
|
isDecred: false,
|
|
206
198
|
expiryHeight: Buffer.alloc(4),
|
|
207
|
-
blockHeight: undefined,
|
|
208
199
|
});
|
|
209
200
|
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000003);
|
|
210
|
-
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000003);
|
|
211
201
|
});
|
|
212
202
|
|
|
213
203
|
it("should return default versions for Decred with expiryHeight", () => {
|
|
@@ -216,10 +206,8 @@ output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61
|
|
|
216
206
|
sapling: false,
|
|
217
207
|
isDecred: true,
|
|
218
208
|
expiryHeight: Buffer.alloc(4),
|
|
219
|
-
blockHeight: undefined,
|
|
220
209
|
});
|
|
221
210
|
expect(result.defaultVersion.readUInt32LE(0)).toBe(1);
|
|
222
|
-
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(1);
|
|
223
211
|
});
|
|
224
212
|
});
|
|
225
213
|
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
2
|
+
import Btc from "../src/Btc";
|
|
3
|
+
|
|
4
|
+
describe("splitTransaction", () => {
|
|
5
|
+
test("zcash", async () => {
|
|
6
|
+
const transport = await openTransportReplayer(RecordStore.fromString(""));
|
|
7
|
+
const btc = new Btc({ transport, currency: "zcash" });
|
|
8
|
+
/*
|
|
9
|
+
|
|
10
|
+
splitTransaction 050000800a27a726b4d0d6c20000000000000000011d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f4010000006a4730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff75673c50650c000000000250c30000000000001976a914de3542c396924ada3c5850225770f6dd3e2249b988ac3df2c202000000001976a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac000000:
|
|
11
|
+
TX version 05000080 locktime 00000000 timestamp nVersionGroupId 0a27a726 nExpiryHeight 00000000 extraData
|
|
12
|
+
input 0: prevout 1d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f401000000 script 4730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff75673c50650c sequence 00000000
|
|
13
|
+
output 0: amount 50c3000000000000 script 76a914de3542c396924ada3c5850225770f6dd3e2249b988ac
|
|
14
|
+
output 1: amount 3df2c20200000000 script 76a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac
|
|
15
|
+
*/
|
|
16
|
+
const tx1 = btc.splitTransaction(
|
|
17
|
+
"050000800a27a726b4d0d6c20000000000000000011d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f4010000006a4730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff75673c50650c000000000250c30000000000001976a914de3542c396924ada3c5850225770f6dd3e2249b988ac3df2c202000000001976a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac000000",
|
|
18
|
+
true,
|
|
19
|
+
true,
|
|
20
|
+
["zcash", "sapling"],
|
|
21
|
+
);
|
|
22
|
+
/*
|
|
23
|
+
splitTransaction 050000800a27a7265510e7c80000000000000000018c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d11000000006b48304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903a42b5aea5032790000000002404b4c00000000001976a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac0e532a00000000001976a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac000000:
|
|
24
|
+
TX version 05000080 locktime 00000000 timestamp nVersionGroupId 0a27a726 nExpiryHeight 00000000 extraData
|
|
25
|
+
input 0: prevout 8c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d1100000000 script 48304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903a42b5aea503279 sequence 00000000
|
|
26
|
+
output 0: amount 404b4c0000000000 script 76a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac
|
|
27
|
+
output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac
|
|
28
|
+
*/
|
|
29
|
+
const tx2 = btc.splitTransaction(
|
|
30
|
+
"050000800a27a7265510e7c80000000000000000018c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d11000000006b48304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903a42b5aea5032790000000002404b4c00000000001976a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac0e532a00000000001976a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac000000",
|
|
31
|
+
true,
|
|
32
|
+
true,
|
|
33
|
+
["zcash", "sapling"],
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
test("Zcash Sapling transaction (v4)", async () => {
|
|
37
|
+
const transport = await openTransportReplayer(RecordStore.fromString(""));
|
|
38
|
+
const btc = new Btc({ transport, currency: "zcash" });
|
|
39
|
+
|
|
40
|
+
const hex =
|
|
41
|
+
"0400008085202f890177507ef339c27d8d453723c568361fb93671f521f1ba2c42a0f136650939aaa5010000006b48304502210099a9fa0817083a1ce6f96404ed7366d9200f5533a9ccfcd4eddb50be4646c8a102205a6cccc8965f1ea45d6f32d96dda89a3cbb0422fad2a0e05b40fa51c0e51322a0121029f7331870af5630f14fe86e10b6ef696ee152bffb34e71396a4ce82ef64aa23effffffff0240781501000000001976a9144cf48844c49a77ba86e48b070f06151b712c862988ace39e0f02000000001976a91445110888402e6fd0c86329d9eda36c7a3fa354a588ac00000000000000000000000000000000000000";
|
|
42
|
+
|
|
43
|
+
const tx = btc.splitTransaction(hex, true, true, ["zcash", "sapling"]);
|
|
44
|
+
|
|
45
|
+
expect(tx?.version.toString("hex")).toBe("04000080");
|
|
46
|
+
// expect(tx.nVersionGroupId).toBeDefined();
|
|
47
|
+
expect(tx.nVersionGroupId?.toString("hex")).toBe("85202f89");
|
|
48
|
+
expect(tx.locktime?.toString("hex")).toBe("00000000");
|
|
49
|
+
expect(tx.nExpiryHeight?.toString("hex")).toBe("00000000");
|
|
50
|
+
|
|
51
|
+
expect(tx.inputs.length).toBe(1);
|
|
52
|
+
expect(tx.outputs?.length).toBe(2);
|
|
53
|
+
|
|
54
|
+
expect(tx.outputs![0].amount.toString("hex")).toBe("4078150100000000")
|
|
55
|
+
expect(tx.outputs![0].script.toString("hex")).toBe("76a9144cf48844c49a77ba86e48b070f06151b712c862988ac");
|
|
56
|
+
|
|
57
|
+
expect(tx.extraData).toBeDefined();
|
|
58
|
+
expect(tx.extraData?.length).toBe(11); // valueBalance (8) + shieldedSpend (1) + shieldedOutput (1) + joinSplit (1)
|
|
59
|
+
expect(tx.extraData!.toString("hex")).toBe("0000000000000000" + "00" + "00" + "00"); // empty shielded stuff
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test.only("Zcash NU5 transaction (v5)", async () => {
|
|
63
|
+
const transport = await openTransportReplayer(RecordStore.fromString(""));
|
|
64
|
+
const btc = new Btc({ transport, currency: "zcash" });
|
|
65
|
+
|
|
66
|
+
const hex =
|
|
67
|
+
"050000800a27a7265510e7c8000000000000000001b5c51aa7f90bd40671eb4887f0022613f5c773f8a30e0c38ff9fc933b754a218000000006b483045022100b4b7b664f7ac6e78026f81f04f9c6fbd7ccbee532ba53e4150ccb6a7c0bd21510220277b4cfdf44683e77a4211e88a3052be00d1c678c36f357db935450c13f2f33701210223b8ffaccab6cc90d2164bfc4361bb058b030217e7cccf677347f075beeef3bb0000000001c0a79500000000001976a914168bb00f59a2d1a059d7e60fcc709cd5a979992988ac000000";
|
|
68
|
+
|
|
69
|
+
const tx = btc.splitTransaction(hex, true, true, ["zcash", "sapling"]);
|
|
70
|
+
|
|
71
|
+
expect(tx.version.toString("hex")).toBe("05000080");
|
|
72
|
+
expect(tx.nVersionGroupId?.toString("hex")).toBe("0a27a726");
|
|
73
|
+
expect(tx.locktime?.toString("hex")).toBe("00000000");
|
|
74
|
+
expect(tx.nExpiryHeight?.toString("hex")).toBe("00000000");
|
|
75
|
+
|
|
76
|
+
expect(tx.inputs.length).toBe(1);
|
|
77
|
+
expect(tx.outputs?.length).toBe(1);
|
|
78
|
+
|
|
79
|
+
expect(tx.outputs![0].amount.toString("hex")).toBe("c0a7950000000000");
|
|
80
|
+
expect(tx.outputs![0].script.toString("hex")).toBe("76a914168bb00f59a2d1a059d7e60fcc709cd5a979992988ac");
|
|
81
|
+
expect(tx.extraData).toBeDefined();
|
|
82
|
+
// Overwinter : use nJoinSplit (1)
|
|
83
|
+
expect(tx.extraData!.length).toBe(0); // no extraData for pure NU5 transparent tx
|
|
84
|
+
});
|
|
85
|
+
});
|