@ledgerhq/hw-app-btc 10.5.0 → 10.6.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/README.md +3 -2
- package/lib/Btc.d.ts +1 -0
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +35 -41
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +191 -216
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.js +23 -37
- package/lib/BtcOld.js.map +1 -1
- package/lib/bip32.d.ts +1 -0
- package/lib/bip32.d.ts.map +1 -1
- package/lib/buffertools.d.ts +1 -0
- package/lib/buffertools.d.ts.map +1 -1
- package/lib/buffertools.js +3 -3
- package/lib/buffertools.js.map +1 -1
- package/lib/compressPublicKey.d.ts +1 -0
- package/lib/compressPublicKey.d.ts.map +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +3 -1
- package/lib/constants.js.map +1 -1
- package/lib/createTransaction.d.ts +19 -1
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/createTransaction.js +273 -245
- package/lib/createTransaction.js.map +1 -1
- package/lib/finalizeInput.d.ts +1 -0
- package/lib/finalizeInput.d.ts.map +1 -1
- package/lib/finalizeInput.js +18 -29
- package/lib/finalizeInput.js.map +1 -1
- package/lib/getAppAndVersion.d.ts +1 -0
- package/lib/getAppAndVersion.d.ts.map +1 -1
- package/lib/getAppAndVersion.js +6 -15
- package/lib/getAppAndVersion.js.map +1 -1
- package/lib/getTrustedInput.d.ts +1 -0
- package/lib/getTrustedInput.d.ts.map +1 -1
- package/lib/getTrustedInput.js +83 -96
- package/lib/getTrustedInput.js.map +1 -1
- package/lib/getWalletPublicKey.js +27 -34
- package/lib/getWalletPublicKey.js.map +1 -1
- package/lib/hashPublicKey.d.ts +1 -0
- package/lib/hashPublicKey.d.ts.map +1 -1
- package/lib/newops/accounttype.d.ts +1 -0
- package/lib/newops/accounttype.d.ts.map +1 -1
- package/lib/newops/accounttype.js +2 -0
- package/lib/newops/accounttype.js.map +1 -1
- package/lib/newops/appClient.d.ts +1 -0
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/appClient.js +90 -110
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts +1 -0
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +18 -10
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.d.ts +1 -0
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib/newops/merkelizedPsbt.js +5 -2
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.d.ts +1 -0
- package/lib/newops/merkle.d.ts.map +1 -1
- package/lib/newops/merkle.js +8 -0
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.d.ts +1 -0
- package/lib/newops/merkleMap.d.ts.map +1 -1
- package/lib/newops/merkleMap.js +4 -0
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts +1 -0
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +2 -0
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.d.ts +1 -0
- package/lib/newops/psbtExtractor.d.ts.map +1 -1
- package/lib/newops/psbtExtractor.js +2 -3
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtv2.d.ts +1 -0
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +10 -10
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib/serializeTransaction.d.ts +1 -0
- package/lib/serializeTransaction.d.ts.map +1 -1
- package/lib/signMessage.js +38 -49
- package/lib/signMessage.js.map +1 -1
- package/lib/signP2SHTransaction.js +72 -83
- package/lib/signP2SHTransaction.js.map +1 -1
- package/lib/signTransaction.d.ts +1 -0
- package/lib/signTransaction.d.ts.map +1 -1
- package/lib/startUntrustedHashTransactionInput.d.ts +1 -0
- package/lib/startUntrustedHashTransactionInput.d.ts.map +1 -1
- package/lib/startUntrustedHashTransactionInput.js +52 -63
- package/lib/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/varint.d.ts +1 -0
- package/lib/varint.d.ts.map +1 -1
- package/lib-es/Btc.d.ts +1 -0
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +35 -41
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +191 -216
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.js +23 -37
- package/lib-es/BtcOld.js.map +1 -1
- package/lib-es/bip32.d.ts +1 -0
- package/lib-es/bip32.d.ts.map +1 -1
- package/lib-es/buffertools.d.ts +1 -0
- package/lib-es/buffertools.d.ts.map +1 -1
- package/lib-es/buffertools.js +3 -3
- package/lib-es/buffertools.js.map +1 -1
- package/lib-es/compressPublicKey.d.ts +1 -0
- package/lib-es/compressPublicKey.d.ts.map +1 -1
- package/lib-es/constants.d.ts +1 -0
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +2 -0
- package/lib-es/constants.js.map +1 -1
- package/lib-es/createTransaction.d.ts +19 -1
- package/lib-es/createTransaction.d.ts.map +1 -1
- package/lib-es/createTransaction.js +272 -245
- package/lib-es/createTransaction.js.map +1 -1
- package/lib-es/finalizeInput.d.ts +1 -0
- package/lib-es/finalizeInput.d.ts.map +1 -1
- package/lib-es/finalizeInput.js +18 -29
- package/lib-es/finalizeInput.js.map +1 -1
- package/lib-es/getAppAndVersion.d.ts +1 -0
- package/lib-es/getAppAndVersion.d.ts.map +1 -1
- package/lib-es/getAppAndVersion.js +6 -15
- package/lib-es/getAppAndVersion.js.map +1 -1
- package/lib-es/getTrustedInput.d.ts +1 -0
- package/lib-es/getTrustedInput.d.ts.map +1 -1
- package/lib-es/getTrustedInput.js +83 -96
- package/lib-es/getTrustedInput.js.map +1 -1
- package/lib-es/getWalletPublicKey.js +27 -34
- package/lib-es/getWalletPublicKey.js.map +1 -1
- package/lib-es/hashPublicKey.d.ts +1 -0
- package/lib-es/hashPublicKey.d.ts.map +1 -1
- package/lib-es/newops/accounttype.d.ts +1 -0
- package/lib-es/newops/accounttype.d.ts.map +1 -1
- package/lib-es/newops/accounttype.js +2 -0
- package/lib-es/newops/accounttype.js.map +1 -1
- package/lib-es/newops/appClient.d.ts +1 -0
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/appClient.js +90 -110
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts +1 -0
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +18 -10
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts +1 -0
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +5 -2
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.d.ts +1 -0
- package/lib-es/newops/merkle.d.ts.map +1 -1
- package/lib-es/newops/merkle.js +8 -0
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.d.ts +1 -0
- package/lib-es/newops/merkleMap.d.ts.map +1 -1
- package/lib-es/newops/merkleMap.js +4 -0
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts +1 -0
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +2 -0
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.d.ts +1 -0
- package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
- package/lib-es/newops/psbtExtractor.js +2 -3
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts +1 -0
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +10 -10
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/lib-es/serializeTransaction.d.ts +1 -0
- package/lib-es/serializeTransaction.d.ts.map +1 -1
- package/lib-es/signMessage.js +38 -49
- package/lib-es/signMessage.js.map +1 -1
- package/lib-es/signP2SHTransaction.js +72 -83
- package/lib-es/signP2SHTransaction.js.map +1 -1
- package/lib-es/signTransaction.d.ts +1 -0
- package/lib-es/signTransaction.d.ts.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.d.ts +1 -0
- package/lib-es/startUntrustedHashTransactionInput.d.ts.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.js +52 -63
- 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/lib-es/varint.d.ts +1 -0
- package/lib-es/varint.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/BtcNew.ts +7 -1
- package/src/constants.ts +3 -0
- package/src/createTransaction.ts +68 -5
- package/tests/createTransaction.test.ts +225 -0
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { createVarint } from "./varint";
|
|
11
2
|
import { MAX_SCRIPT_BLOCK } from "./constants";
|
|
12
3
|
export function startUntrustedHashTransactionInputRaw(transport, newTransaction, firstRound, transactionData, bip143 = false, overwinter = false, additionals = []) {
|
|
@@ -21,67 +12,65 @@ export function startUntrustedHashTransactionInputRaw(transport, newTransaction,
|
|
|
21
12
|
: 0x00;
|
|
22
13
|
return transport.send(0xe0, 0x44, firstRound ? 0x00 : 0x80, newTransaction ? p2 : 0x80, transactionData);
|
|
23
14
|
}
|
|
24
|
-
export function startUntrustedHashTransactionInput(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
prefix = Buffer.from([0x01, inputValue.length]);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
prefix = Buffer.from([0x02]);
|
|
44
|
-
}
|
|
15
|
+
export async function startUntrustedHashTransactionInput(transport, newTransaction, transaction, inputs, bip143 = false, overwinter = false, additionals = [], useTrustedInputForSegwit = false) {
|
|
16
|
+
let data = Buffer.concat([
|
|
17
|
+
transaction.version,
|
|
18
|
+
transaction.timestamp || Buffer.alloc(0),
|
|
19
|
+
transaction.nVersionGroupId || Buffer.alloc(0),
|
|
20
|
+
createVarint(transaction.inputs.length),
|
|
21
|
+
]);
|
|
22
|
+
await startUntrustedHashTransactionInputRaw(transport, newTransaction, true, data, bip143, overwinter, additionals);
|
|
23
|
+
let i = 0;
|
|
24
|
+
const isDecred = additionals.includes("decred");
|
|
25
|
+
for (const input of transaction.inputs) {
|
|
26
|
+
let prefix;
|
|
27
|
+
const inputValue = inputs[i].value;
|
|
28
|
+
if (bip143) {
|
|
29
|
+
if (useTrustedInputForSegwit && inputs[i].trustedInput) {
|
|
30
|
+
prefix = Buffer.from([0x01, inputValue.length]);
|
|
45
31
|
}
|
|
46
32
|
else {
|
|
47
|
-
|
|
48
|
-
prefix = Buffer.from([0x01, inputs[i].value.length]);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
prefix = Buffer.from([0x00]);
|
|
52
|
-
}
|
|
33
|
+
prefix = Buffer.from([0x02]);
|
|
53
34
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
createVarint(input.script.length),
|
|
59
|
-
]);
|
|
60
|
-
yield startUntrustedHashTransactionInputRaw(transport, newTransaction, false, data, bip143, overwinter, additionals);
|
|
61
|
-
const scriptBlocks = [];
|
|
62
|
-
let offset = 0;
|
|
63
|
-
if (input.script.length === 0) {
|
|
64
|
-
scriptBlocks.push(input.sequence);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (inputs[i].trustedInput) {
|
|
38
|
+
prefix = Buffer.from([0x01, inputs[i].value.length]);
|
|
65
39
|
}
|
|
66
40
|
else {
|
|
67
|
-
|
|
68
|
-
const blockSize = input.script.length - offset > MAX_SCRIPT_BLOCK
|
|
69
|
-
? MAX_SCRIPT_BLOCK
|
|
70
|
-
: input.script.length - offset;
|
|
71
|
-
if (offset + blockSize !== input.script.length) {
|
|
72
|
-
scriptBlocks.push(input.script.slice(offset, offset + blockSize));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
scriptBlocks.push(Buffer.concat([input.script.slice(offset, offset + blockSize), input.sequence]));
|
|
76
|
-
}
|
|
77
|
-
offset += blockSize;
|
|
78
|
-
}
|
|
41
|
+
prefix = Buffer.from([0x00]);
|
|
79
42
|
}
|
|
80
|
-
|
|
81
|
-
|
|
43
|
+
}
|
|
44
|
+
data = Buffer.concat([
|
|
45
|
+
prefix,
|
|
46
|
+
inputValue,
|
|
47
|
+
isDecred ? Buffer.from([0x00]) : Buffer.alloc(0),
|
|
48
|
+
createVarint(input.script.length),
|
|
49
|
+
]);
|
|
50
|
+
await startUntrustedHashTransactionInputRaw(transport, newTransaction, false, data, bip143, overwinter, additionals);
|
|
51
|
+
const scriptBlocks = [];
|
|
52
|
+
let offset = 0;
|
|
53
|
+
if (input.script.length === 0) {
|
|
54
|
+
scriptBlocks.push(input.sequence);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
while (offset !== input.script.length) {
|
|
58
|
+
const blockSize = input.script.length - offset > MAX_SCRIPT_BLOCK
|
|
59
|
+
? MAX_SCRIPT_BLOCK
|
|
60
|
+
: input.script.length - offset;
|
|
61
|
+
if (offset + blockSize !== input.script.length) {
|
|
62
|
+
scriptBlocks.push(input.script.slice(offset, offset + blockSize));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
scriptBlocks.push(Buffer.concat([input.script.slice(offset, offset + blockSize), input.sequence]));
|
|
66
|
+
}
|
|
67
|
+
offset += blockSize;
|
|
82
68
|
}
|
|
83
|
-
i++;
|
|
84
69
|
}
|
|
85
|
-
|
|
70
|
+
for (const scriptBlock of scriptBlocks) {
|
|
71
|
+
await startUntrustedHashTransactionInputRaw(transport, newTransaction, false, scriptBlock, bip143, overwinter, additionals);
|
|
72
|
+
}
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
86
75
|
}
|
|
87
76
|
//# sourceMappingURL=startUntrustedHashTransactionInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startUntrustedHashTransactionInput.js","sourceRoot":"","sources":["../src/startUntrustedHashTransactionInput.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"startUntrustedHashTransactionInput.js","sourceRoot":"","sources":["../src/startUntrustedHashTransactionInput.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,MAAM,UAAU,qCAAqC,CACnD,SAAoB,EACpB,cAAuB,EACvB,UAAmB,EACnB,eAAuB,EACvB,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,KAAK,EAClB,cAA6B,EAAE;IAE/B,MAAM,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC;QACzC,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,MAAM;YACN,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAC/B,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,UAAU;oBACV,CAAC,CAAC,IAAI;oBACN,CAAC,CAAC,IAAI;YACV,CAAC,CAAC,IAAI,CAAC;IACX,OAAO,SAAS,CAAC,IAAI,CACnB,IAAI,EACJ,IAAI,EACJ,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EACxB,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAC1B,eAAe,CAChB,CAAC;AACJ,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,SAAoB,EACpB,cAAuB,EACvB,WAAwB,EACxB,MAGE,EACF,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,KAAK,EAClB,cAA6B,EAAE,EAC/B,wBAAwB,GAAG,KAAK;IAEhC,IAAI,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;QACvB,WAAW,CAAC,OAAO;QACnB,WAAW,CAAC,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,WAAW,CAAC,eAAe,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9C,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;KACxC,CAAC,CAAC;IACH,MAAM,qCAAqC,CACzC,SAAS,EACT,cAAc,EACd,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,WAAW,CACZ,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAEhD,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,MAAM,CAAC;QACX,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAEnC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,wBAAwB,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;gBACvD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;YAClD,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;gBAC3B,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;YACvD,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;YACnB,MAAM;YACN,UAAU;YACV,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAChD,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;SAClC,CAAC,CAAC;QACH,MAAM,qCAAqC,CACzC,SAAS,EACT,cAAc,EACd,KAAK,EACL,IAAI,EACJ,MAAM,EACN,UAAU,EACV,WAAW,CACZ,CAAC;QACF,MAAM,YAAY,GAAa,EAAE,CAAC;QAClC,IAAI,MAAM,GAAG,CAAC,CAAC;QAEf,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9B,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;gBACtC,MAAM,SAAS,GACb,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,gBAAgB;oBAC7C,CAAC,CAAC,gBAAgB;oBAClB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;gBAEnC,IAAI,MAAM,GAAG,SAAS,KAAK,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;oBAC/C,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;gBACpE,CAAC;qBAAM,CAAC;oBACN,YAAY,CAAC,IAAI,CACf,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAChF,CAAC;gBACJ,CAAC;gBAED,MAAM,IAAI,SAAS,CAAC;YACtB,CAAC;QACH,CAAC;QAED,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,MAAM,qCAAqC,CACzC,SAAS,EACT,cAAc,EACd,KAAK,EACL,WAAW,EACX,MAAM,EACN,UAAU,EACV,WAAW,CACZ,CAAC;QACJ,CAAC;QAED,CAAC,EAAE,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/lib-es/types.d.ts
CHANGED
package/lib-es/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AAAA;GACG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;GACG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;GACG;AACH,MAAM,WAAW,WAAW;IAG1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAG9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,eAAe,CAAC,EAAE,MAAM,CAAC;IAKzB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
package/lib-es/varint.d.ts
CHANGED
package/lib-es/varint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"varint.d.ts","sourceRoot":"","sources":["../src/varint.ts"],"names":[],"mappings":";;AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBxE;AACD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAsBlD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/hw-app-btc",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.6.0-next.0",
|
|
4
4
|
"description": "Ledger Hardware Wallet Bitcoin Application API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@types/jest": "^29.5.10",
|
|
78
|
-
"@types/node": "^
|
|
78
|
+
"@types/node": "^22.10.10",
|
|
79
79
|
"axios": "1.7.7",
|
|
80
80
|
"documentation": "14.0.2",
|
|
81
81
|
"jest": "^29.7.0",
|
|
@@ -89,10 +89,11 @@
|
|
|
89
89
|
"gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec",
|
|
90
90
|
"scripts": {
|
|
91
91
|
"clean": "rimraf lib lib-es",
|
|
92
|
-
"
|
|
92
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/.test.ts.disabled|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-hw-app-btc.json",
|
|
93
|
+
"build": "tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es",
|
|
93
94
|
"prewatch": "pnpm build",
|
|
94
95
|
"watch": "tsc --watch",
|
|
95
|
-
"watch:es": "tsc --watch -m
|
|
96
|
+
"watch:es": "tsc --watch -m esnext --moduleResolution bundler --outDir lib-es",
|
|
96
97
|
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
97
98
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
98
99
|
"lint:fix": "pnpm lint --fix",
|
package/src/BtcNew.ts
CHANGED
|
@@ -349,7 +349,13 @@ export default class BtcNew {
|
|
|
349
349
|
private async setInput(
|
|
350
350
|
psbt: PsbtV2,
|
|
351
351
|
i: number,
|
|
352
|
-
input: [
|
|
352
|
+
input: [
|
|
353
|
+
Transaction,
|
|
354
|
+
number,
|
|
355
|
+
string | null | undefined,
|
|
356
|
+
number | null | undefined,
|
|
357
|
+
(number | null | undefined)?,
|
|
358
|
+
],
|
|
353
359
|
pathElements: number[],
|
|
354
360
|
accountType: AccountType,
|
|
355
361
|
masterFP: Buffer,
|
package/src/constants.ts
CHANGED
package/src/createTransaction.ts
CHANGED
|
@@ -21,9 +21,11 @@ import {
|
|
|
21
21
|
HASH_SIZE,
|
|
22
22
|
OP_EQUALVERIFY,
|
|
23
23
|
OP_CHECKSIG,
|
|
24
|
+
ZCASH_NU6_ACTIVATION_HEIGHT,
|
|
24
25
|
} from "./constants";
|
|
25
26
|
import { shouldUseTrustedInputForSegwit } from "./shouldUseTrustedInputForSegwit";
|
|
26
27
|
export type { AddressFormat };
|
|
28
|
+
|
|
27
29
|
const defaultsSignTransaction = {
|
|
28
30
|
lockTime: DEFAULT_LOCKTIME,
|
|
29
31
|
sigHashType: SIGHASH_ALL,
|
|
@@ -34,15 +36,67 @@ const defaultsSignTransaction = {
|
|
|
34
36
|
onDeviceSignatureRequested: () => {},
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
const getZcashTransactionVersion = (blockHeight: number | null | undefined): Buffer => {
|
|
40
|
+
const version = Buffer.alloc(4);
|
|
41
|
+
if (blockHeight && blockHeight < ZCASH_NU6_ACTIVATION_HEIGHT) {
|
|
42
|
+
version.writeUInt32LE(0x80000005, 0);
|
|
43
|
+
} else {
|
|
44
|
+
// NOTE: null and undefined should default to latest version
|
|
45
|
+
version.writeUInt32LE(0x80000006, 0);
|
|
46
|
+
}
|
|
47
|
+
return version;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const getDefaultVersions = ({
|
|
51
|
+
isZcash,
|
|
52
|
+
sapling,
|
|
53
|
+
isDecred,
|
|
54
|
+
expiryHeight,
|
|
55
|
+
blockHeight,
|
|
56
|
+
}: {
|
|
57
|
+
isZcash: boolean;
|
|
58
|
+
sapling: boolean;
|
|
59
|
+
isDecred: boolean;
|
|
60
|
+
expiryHeight: Buffer | undefined;
|
|
61
|
+
blockHeight: number | undefined;
|
|
62
|
+
}): { defaultVersion: Buffer; defaultVersionNu5Only: Buffer } => {
|
|
63
|
+
let defaultVersion = Buffer.alloc(4);
|
|
64
|
+
const defaultVersionNu5Only = Buffer.alloc(4);
|
|
65
|
+
|
|
66
|
+
if (!!expiryHeight && !isDecred) {
|
|
67
|
+
if (isZcash) {
|
|
68
|
+
defaultVersion = getZcashTransactionVersion(blockHeight);
|
|
69
|
+
defaultVersionNu5Only.writeUInt32LE(0x80000005, 0);
|
|
70
|
+
} else {
|
|
71
|
+
const version = sapling ? 0x80000004 : 0x80000003;
|
|
72
|
+
defaultVersion.writeUInt32LE(version, 0);
|
|
73
|
+
defaultVersionNu5Only.writeUInt32LE(version, 0);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
defaultVersion.writeUInt32LE(1, 0);
|
|
77
|
+
defaultVersionNu5Only.writeUInt32LE(1, 0);
|
|
78
|
+
}
|
|
79
|
+
return { defaultVersion, defaultVersionNu5Only };
|
|
80
|
+
};
|
|
81
|
+
|
|
37
82
|
/**
|
|
38
83
|
*
|
|
39
84
|
*/
|
|
40
85
|
export type CreateTransactionArg = {
|
|
41
|
-
inputs: Array<
|
|
86
|
+
inputs: Array<
|
|
87
|
+
[
|
|
88
|
+
Transaction,
|
|
89
|
+
number,
|
|
90
|
+
string | null | undefined,
|
|
91
|
+
number | null | undefined,
|
|
92
|
+
(number | null | undefined)?,
|
|
93
|
+
]
|
|
94
|
+
>;
|
|
42
95
|
associatedKeysets: string[];
|
|
43
96
|
changePath?: string;
|
|
44
97
|
outputScriptHex: string;
|
|
45
98
|
lockTime?: number;
|
|
99
|
+
blockHeight?: number;
|
|
46
100
|
sigHashType?: number;
|
|
47
101
|
segwit?: boolean;
|
|
48
102
|
additionals: Array<string>;
|
|
@@ -60,6 +114,7 @@ export async function createTransaction(
|
|
|
60
114
|
const {
|
|
61
115
|
inputs,
|
|
62
116
|
associatedKeysets,
|
|
117
|
+
blockHeight,
|
|
63
118
|
changePath,
|
|
64
119
|
outputScriptHex,
|
|
65
120
|
lockTime,
|
|
@@ -121,10 +176,14 @@ export async function createTransaction(
|
|
|
121
176
|
lockTimeBuffer.writeUInt32LE(lockTime, 0);
|
|
122
177
|
const nullScript = Buffer.alloc(0);
|
|
123
178
|
const nullPrevout = Buffer.alloc(0);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
179
|
+
|
|
180
|
+
const { defaultVersion, defaultVersionNu5Only } = getDefaultVersions({
|
|
181
|
+
isZcash,
|
|
182
|
+
sapling,
|
|
183
|
+
isDecred,
|
|
184
|
+
expiryHeight,
|
|
185
|
+
blockHeight,
|
|
186
|
+
});
|
|
128
187
|
// Default version to 2 for XST not to have timestamp
|
|
129
188
|
const trustedInputs: Array<any> = [];
|
|
130
189
|
const regularOutputs: Array<TransactionOutput> = [];
|
|
@@ -144,6 +203,9 @@ export async function createTransaction(
|
|
|
144
203
|
// first pass on inputs to get trusted inputs
|
|
145
204
|
for (const input of inputs) {
|
|
146
205
|
if (!resuming) {
|
|
206
|
+
if (isZcash) {
|
|
207
|
+
input[0].version = getZcashTransactionVersion(input[4]);
|
|
208
|
+
}
|
|
147
209
|
const trustedInput = await getTrustedInputCall(transport, input[1], input[0], additionals);
|
|
148
210
|
log("hw", "got trustedInput=" + trustedInput);
|
|
149
211
|
const sequence = Buffer.alloc(4);
|
|
@@ -309,6 +371,7 @@ export async function createTransaction(
|
|
|
309
371
|
}
|
|
310
372
|
}
|
|
311
373
|
|
|
374
|
+
targetTransaction.version = defaultVersionNu5Only;
|
|
312
375
|
// Populate the final input scripts
|
|
313
376
|
for (let i = 0; i < inputs.length; i++) {
|
|
314
377
|
if (segwit) {
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { ZCASH_NU6_ACTIVATION_HEIGHT } from "../src/constants";
|
|
2
|
+
import { getDefaultVersions } from "../src/createTransaction";
|
|
3
|
+
import { openTransportReplayer, RecordStore } from "@ledgerhq/hw-transport-mocker";
|
|
4
|
+
import Btc from "../src/Btc";
|
|
5
|
+
|
|
6
|
+
describe("createTransaction", () => {
|
|
7
|
+
describe("createTransaction", () => {
|
|
8
|
+
test("zcash", async () => {
|
|
9
|
+
const transport = await openTransportReplayer(
|
|
10
|
+
RecordStore.fromString(`
|
|
11
|
+
=> b001000000
|
|
12
|
+
<= 01055a6361736805322e332e3101029000
|
|
13
|
+
=> e04200000d00000000050000800a27a72601
|
|
14
|
+
<= 9000
|
|
15
|
+
=> e0428000251d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f4010000006a
|
|
16
|
+
<= 9000
|
|
17
|
+
=> e0428000324730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879
|
|
18
|
+
<= 9000
|
|
19
|
+
=> e042800032cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff
|
|
20
|
+
<= 9000
|
|
21
|
+
=> e04280000a75673c50650c00000000
|
|
22
|
+
<= 9000
|
|
23
|
+
=> e04280000102
|
|
24
|
+
<= 9000
|
|
25
|
+
=> e04280002250c30000000000001976a914de3542c396924ada3c5850225770f6dd3e2249b988ac
|
|
26
|
+
<= 9000
|
|
27
|
+
=> e0428000223df2c202000000001976a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac
|
|
28
|
+
<= 9000
|
|
29
|
+
=> e042800009000000000400000000
|
|
30
|
+
<= 3200ed40989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb0000000050c3000000000000d53c396d2f5c98619000
|
|
31
|
+
=> e04200000d00000000060000800a27a72601
|
|
32
|
+
<= 9000
|
|
33
|
+
=> e0428000258c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d11000000006b
|
|
34
|
+
<= 9000
|
|
35
|
+
=> e04280003248304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb
|
|
36
|
+
<= 9000
|
|
37
|
+
=> e042800032146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903
|
|
38
|
+
<= 9000
|
|
39
|
+
=> e04280000ba42b5aea50327900000000
|
|
40
|
+
<= 00009000
|
|
41
|
+
=> e04280000102
|
|
42
|
+
<= 9000
|
|
43
|
+
=> e042800022404b4c00000000001976a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac
|
|
44
|
+
<= 9000
|
|
45
|
+
=> e0428000220e532a00000000001976a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac
|
|
46
|
+
<= 9000
|
|
47
|
+
=> e042800009000000000400000000
|
|
48
|
+
<= 320071857203407d7ff3f5832db7c37973ac01569a832cd78a6dbd3627e4f9ee7458532200000000404b4c0000000000aa2ea74bcab3a20a9000
|
|
49
|
+
|
|
50
|
+
=> e04000000d03800000000000000000000000
|
|
51
|
+
<= 9000
|
|
52
|
+
=> e04000000100
|
|
53
|
+
<= 9000
|
|
54
|
+
=> e0440000050100000002
|
|
55
|
+
<= 9000
|
|
56
|
+
|
|
57
|
+
=> e04480003b01383200ed40989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb0000000050c3000000000000d53c396d2f5c986119
|
|
58
|
+
<= 9000
|
|
59
|
+
=> e04480001d76a914de3542c396924ada3c5850225770f6dd3e2249b988ac00000000
|
|
60
|
+
<= 009000
|
|
61
|
+
=> e04480003b0138320071857203407d7ff3f5832db7c37973ac01569a832cd78a6dbd3627e4f9ee7458532200000000404b4c0000000000aa2ea74bcab3a20a19
|
|
62
|
+
<= 00009000
|
|
63
|
+
|
|
64
|
+
=> e04480001d76a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac00000000
|
|
65
|
+
<= 00009000
|
|
66
|
+
|
|
67
|
+
=> e04a0000320210270000000000001976a9140fef7d9e0afcc8e198ac049945b6499b6fe7aef288ac1a314700000000001976a914d83e71
|
|
68
|
+
<= 00009000
|
|
69
|
+
|
|
70
|
+
=> e04a800013f7a39b28a617c7bcedbd925c2a621952b288ac
|
|
71
|
+
<= 00009000
|
|
72
|
+
|
|
73
|
+
=> e04800001303800000000000000000000000000000000001
|
|
74
|
+
<= 00009000
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
=> e0440080050100000002
|
|
78
|
+
<= 9000
|
|
79
|
+
|
|
80
|
+
=> e04480803b01383200ed40989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb0000000050c3000000000000d53c396d2f5c986100
|
|
81
|
+
<= 9000
|
|
82
|
+
=> e04480800400000000
|
|
83
|
+
<= 9000
|
|
84
|
+
|
|
85
|
+
=> e04480803b0138320071857203407d7ff3f5832db7c37973ac01569a832cd78a6dbd3627e4f9ee7458532200000000404b4c0000000000aa2ea74bcab3a20a19
|
|
86
|
+
<= 9000
|
|
87
|
+
|
|
88
|
+
=> e04480801d76a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac00000000
|
|
89
|
+
<= 314402200e4952c0763be7e81f342e80042ea0858911aa3c460b90698195f014ddc8bf120220723b14f186ad7a66829982f00210e8ae6289284a146ed90b706d9e0e3313ae12019000
|
|
90
|
+
|
|
91
|
+
=> e04a0000320210270000000000001976a9140fef7d9e0afcc8e198ac049945b6499b6fe7aef288ac1a314700000000001976a914d83e71
|
|
92
|
+
<= 9000
|
|
93
|
+
=> e04a800013f7a39b28a617c7bcedbd925c2a621952b288ac
|
|
94
|
+
<= 9000
|
|
95
|
+
|
|
96
|
+
=> e04800000700000000000001
|
|
97
|
+
<= 9000
|
|
98
|
+
|
|
99
|
+
=> e04800001f058000002c8000008580000001000000000000000a00000000000100000000
|
|
100
|
+
<= 3045022100fd7bcbec98aaa7768774db3a289e07d951a727cb65b6fbfb48e23c745c3a7d16022046f2246519789af567d970b396c9c8c5c462e5a13709ea93481b512479bdf2b3019000
|
|
101
|
+
`),
|
|
102
|
+
);
|
|
103
|
+
/*
|
|
104
|
+
|
|
105
|
+
splitTransaction 050000800a27a726b4d0d6c20000000000000000011d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f4010000006a4730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff75673c50650c000000000250c30000000000001976a914de3542c396924ada3c5850225770f6dd3e2249b988ac3df2c202000000001976a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac000000:
|
|
106
|
+
TX version 05000080 locktime 00000000 timestamp nVersionGroupId 0a27a726 nExpiryHeight 00000000 extraData
|
|
107
|
+
input 0: prevout 1d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f401000000 script 4730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff75673c50650c sequence 00000000
|
|
108
|
+
output 0: amount 50c3000000000000 script 76a914de3542c396924ada3c5850225770f6dd3e2249b988ac
|
|
109
|
+
output 1: amount 3df2c20200000000 script 76a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac
|
|
110
|
+
*/
|
|
111
|
+
// This test covers the old bitcoin Nano app 1.6 API, before the breaking changes that occurred in v2.1.0 of the app
|
|
112
|
+
const btc = new Btc({ transport, currency: "zcash" });
|
|
113
|
+
const tx1 = btc.splitTransaction(
|
|
114
|
+
"050000800a27a726b4d0d6c20000000000000000011d73f1a467297aab205ee7a4ed506f28ea558056401b4f6d308016c1b58d27f4010000006a4730440220337050efe67689fdbdccd2058f6f7b7fe3b13070d91cd0d7ecb1f84e622a220b02201356d33259d64db1095879cfce666b016771cf4e239376497b7f82efedd9c54a01210396fcfd94e1bfb2949e0acbab934583c11ad29d14105d25528aff75673c50650c000000000250c30000000000001976a914de3542c396924ada3c5850225770f6dd3e2249b988ac3df2c202000000001976a914fc0da061ca85923e01d97ac276aa8dc890a28efa88ac000000",
|
|
115
|
+
true,
|
|
116
|
+
true,
|
|
117
|
+
["zcash", "sapling"],
|
|
118
|
+
);
|
|
119
|
+
/*
|
|
120
|
+
splitTransaction 050000800a27a7265510e7c80000000000000000018c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d11000000006b48304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903a42b5aea5032790000000002404b4c00000000001976a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac0e532a00000000001976a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac000000:
|
|
121
|
+
TX version 05000080 locktime 00000000 timestamp nVersionGroupId 0a27a726 nExpiryHeight 00000000 extraData
|
|
122
|
+
input 0: prevout 8c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d1100000000 script 48304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903a42b5aea503279 sequence 00000000
|
|
123
|
+
output 0: amount 404b4c0000000000 script 76a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac
|
|
124
|
+
output 1: amount 0e532a0000000000 script 76a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac
|
|
125
|
+
*/
|
|
126
|
+
const tx2 = btc.splitTransaction(
|
|
127
|
+
"050000800a27a7265510e7c80000000000000000018c63f70704d9987dafffc5481b171dee900e9b6d71261fee880543bc96c41d11000000006b48304502210098a92ce696ff51d46233885e5ea7d0bc0bcd04621c6d79e4230e579f9b13f1480220772d04b65133859ef7fb146a41080b1187335fed9daf62a237b6bd54657f555d0121039402a22682e936ab3c1e2f649859ba13b39a59bd74212ac903a42b5aea5032790000000002404b4c00000000001976a914c59ace9b52af703379f3f89ebbc8ec1813ca50ec88ac0e532a00000000001976a9144cd6509f71020b6a9e890bef43c4d5e61f9c0dad88ac000000",
|
|
128
|
+
true,
|
|
129
|
+
true,
|
|
130
|
+
["zcash", "sapling"],
|
|
131
|
+
);
|
|
132
|
+
const result = await btc.createPaymentTransaction({
|
|
133
|
+
inputs: [
|
|
134
|
+
[tx1, 0, null, 0, 1806010],
|
|
135
|
+
[tx2, 0, null, 0, 2733284],
|
|
136
|
+
],
|
|
137
|
+
associatedKeysets: ["0'/0/0"],
|
|
138
|
+
changePath: undefined,
|
|
139
|
+
blockHeight: 2812009,
|
|
140
|
+
sigHashType: 1,
|
|
141
|
+
outputScriptHex:
|
|
142
|
+
"0210270000000000001976a9140fef7d9e0afcc8e198ac049945b6499b6fe7aef288ac1a314700000000001976a914d83e71f7a39b28a617c7bcedbd925c2a621952b288ac",
|
|
143
|
+
additionals: ["zcash", "sapling"],
|
|
144
|
+
});
|
|
145
|
+
expect(result).toEqual(
|
|
146
|
+
"010000005510e7c8000000000000000002989caa0731d6526fe4e03d49c54720be148f911924129e15d7ecf6e190829edb00000000050230000102000000007203407d7ff3f5832db7c37973ac01569a832cd78a6dbd3627e4f9ee745853220000000003000102000000000210270000000000001976a9140fef7d9e0afcc8e198ac049945b6499b6fe7aef288ac1a314700000000001976a914d83e71f7a39b28a617c7bcedbd925c2a621952b288ac000000",
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe("getDefaultVersions", () => {
|
|
151
|
+
it("should return default versions for non-Zcash and non-Decred with no expiryHeight", () => {
|
|
152
|
+
const result = getDefaultVersions({
|
|
153
|
+
isZcash: false,
|
|
154
|
+
sapling: false,
|
|
155
|
+
isDecred: false,
|
|
156
|
+
expiryHeight: undefined,
|
|
157
|
+
blockHeight: undefined,
|
|
158
|
+
});
|
|
159
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(1);
|
|
160
|
+
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(1);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("should return Zcash versions with expiryHeight and blockHeight below activation height", () => {
|
|
164
|
+
const result = getDefaultVersions({
|
|
165
|
+
isZcash: true,
|
|
166
|
+
sapling: false,
|
|
167
|
+
isDecred: false,
|
|
168
|
+
expiryHeight: Buffer.alloc(4),
|
|
169
|
+
blockHeight: 1000,
|
|
170
|
+
});
|
|
171
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000005);
|
|
172
|
+
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000005);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("should return Zcash versions with expiryHeight and blockHeight above activation height", () => {
|
|
176
|
+
const blockHeight = 3_000_000;
|
|
177
|
+
expect(blockHeight > ZCASH_NU6_ACTIVATION_HEIGHT).toBe(true);
|
|
178
|
+
const result = getDefaultVersions({
|
|
179
|
+
isZcash: true,
|
|
180
|
+
sapling: false,
|
|
181
|
+
isDecred: false,
|
|
182
|
+
expiryHeight: Buffer.alloc(4),
|
|
183
|
+
blockHeight: blockHeight,
|
|
184
|
+
});
|
|
185
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000006);
|
|
186
|
+
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000005);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should return Sapling versions with expiryHeight", () => {
|
|
190
|
+
const result = getDefaultVersions({
|
|
191
|
+
isZcash: false,
|
|
192
|
+
sapling: true,
|
|
193
|
+
isDecred: false,
|
|
194
|
+
expiryHeight: Buffer.alloc(4),
|
|
195
|
+
blockHeight: undefined,
|
|
196
|
+
});
|
|
197
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000004);
|
|
198
|
+
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000004);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("should return non-Sapling versions with expiryHeight", () => {
|
|
202
|
+
const result = getDefaultVersions({
|
|
203
|
+
isZcash: false,
|
|
204
|
+
sapling: false,
|
|
205
|
+
isDecred: false,
|
|
206
|
+
expiryHeight: Buffer.alloc(4),
|
|
207
|
+
blockHeight: undefined,
|
|
208
|
+
});
|
|
209
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(0x80000003);
|
|
210
|
+
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(0x80000003);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("should return default versions for Decred with expiryHeight", () => {
|
|
214
|
+
const result = getDefaultVersions({
|
|
215
|
+
isZcash: false,
|
|
216
|
+
sapling: false,
|
|
217
|
+
isDecred: true,
|
|
218
|
+
expiryHeight: Buffer.alloc(4),
|
|
219
|
+
blockHeight: undefined,
|
|
220
|
+
});
|
|
221
|
+
expect(result.defaultVersion.readUInt32LE(0)).toBe(1);
|
|
222
|
+
expect(result.defaultVersionNu5Only.readUInt32LE(0)).toBe(1);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
});
|