@ledgerhq/hw-app-btc 6.10.0 → 6.12.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 +384 -60
- package/lib/Btc.d.ts +9 -6
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +73 -8
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +79 -32
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +168 -207
- package/lib/BtcNew.js.map +1 -1
- package/lib/newops/accounttype.d.ts +110 -0
- package/lib/newops/accounttype.d.ts.map +1 -0
- package/lib/newops/accounttype.js +233 -0
- package/lib/newops/accounttype.js.map +1 -0
- package/lib/newops/appClient.d.ts +6 -2
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/appClient.js +8 -4
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts +18 -2
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +34 -12
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.d.ts +11 -0
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib/newops/merkelizedPsbt.js +11 -0
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.d.ts +5 -0
- package/lib/newops/merkle.d.ts.map +1 -1
- package/lib/newops/merkle.js +5 -0
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.d.ts +10 -0
- package/lib/newops/merkleMap.d.ts.map +1 -1
- package/lib/newops/merkleMap.js +10 -0
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts +8 -0
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +9 -1
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.d.ts +6 -0
- package/lib/newops/psbtExtractor.d.ts.map +1 -1
- package/lib/newops/psbtExtractor.js +6 -0
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtFinalizer.d.ts +11 -1
- package/lib/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib/newops/psbtFinalizer.js +26 -1
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/newops/psbtv2.d.ts +22 -2
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +33 -8
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib-es/Btc.d.ts +9 -6
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +73 -8
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +79 -32
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +170 -209
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts +110 -0
- package/lib-es/newops/accounttype.d.ts.map +1 -0
- package/lib-es/newops/accounttype.js +230 -0
- package/lib-es/newops/accounttype.js.map +1 -0
- package/lib-es/newops/appClient.d.ts +6 -2
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/appClient.js +8 -4
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts +18 -2
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +34 -12
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts +11 -0
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +11 -0
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.d.ts +5 -0
- package/lib-es/newops/merkle.d.ts.map +1 -1
- package/lib-es/newops/merkle.js +5 -0
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.d.ts +10 -0
- package/lib-es/newops/merkleMap.d.ts.map +1 -1
- package/lib-es/newops/merkleMap.js +10 -0
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts +8 -0
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +10 -2
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.d.ts +6 -0
- package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
- package/lib-es/newops/psbtExtractor.js +6 -0
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.d.ts +11 -1
- package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib-es/newops/psbtFinalizer.js +26 -1
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts +22 -2
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +33 -8
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/package.json +3 -3
- package/src/Btc.ts +111 -9
- package/src/BtcNew.ts +204 -209
- package/src/newops/accounttype.ts +370 -0
- package/src/newops/appClient.ts +12 -4
- package/src/newops/clientCommands.ts +34 -12
- package/src/newops/merkelizedPsbt.ts +11 -0
- package/src/newops/merkle.ts +5 -0
- package/src/newops/merkleMap.ts +10 -0
- package/src/newops/policy.ts +10 -2
- package/src/newops/psbtExtractor.ts +6 -0
- package/src/newops/psbtFinalizer.ts +26 -1
- package/src/newops/psbtv2.ts +34 -14
- package/tests/Btc.test.ts +89 -0
- package/tests/newops/BtcNew.test.ts +48 -21
- package/tests/newops/integrationtools.ts +47 -36
- package/tests/newops/testtx.ts +0 -55
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DefaultDescriptorTemplate } from "./policy";
|
|
3
|
+
import { PsbtV2 } from "./psbtv2";
|
|
4
|
+
export declare type SpendingCondition = {
|
|
5
|
+
scriptPubKey: Buffer;
|
|
6
|
+
redeemScript?: Buffer;
|
|
7
|
+
};
|
|
8
|
+
export declare type SpentOutput = {
|
|
9
|
+
cond: SpendingCondition;
|
|
10
|
+
amount: Buffer;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Encapsulates differences between account types, for example p2wpkh,
|
|
14
|
+
* p2wpkhWrapped, p2tr.
|
|
15
|
+
*/
|
|
16
|
+
export interface AccountType {
|
|
17
|
+
/**
|
|
18
|
+
* Generates a scriptPubKey (output script) from a list of public keys. If a
|
|
19
|
+
* p2sh redeemScript or a p2wsh witnessScript is needed it will also be set on
|
|
20
|
+
* the returned SpendingCondition.
|
|
21
|
+
*
|
|
22
|
+
* The pubkeys are expected to be 33 byte ecdsa compressed pubkeys.
|
|
23
|
+
*/
|
|
24
|
+
spendingCondition(pubkeys: Buffer[]): SpendingCondition;
|
|
25
|
+
/**
|
|
26
|
+
* Populates the psbt with account type-specific data for an input.
|
|
27
|
+
* @param i The index of the input map to populate
|
|
28
|
+
* @param inputTx The full transaction containing the spent output. This may
|
|
29
|
+
* be omitted for taproot.
|
|
30
|
+
* @param spentOutput The amount and spending condition of the spent output
|
|
31
|
+
* @param pubkeys The 33 byte ecdsa compressed public keys involved in the input
|
|
32
|
+
* @param pathElems The paths corresponding to the pubkeys, in same order.
|
|
33
|
+
*/
|
|
34
|
+
setInput(i: number, inputTx: Buffer | undefined, spentOutput: SpentOutput, pubkeys: Buffer[], pathElems: number[][]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Populates the psbt with account type-specific data for an output. This is typically
|
|
37
|
+
* done for change outputs and other outputs that goes to the same account as
|
|
38
|
+
* being spent from.
|
|
39
|
+
* @param i The index of the output map to populate
|
|
40
|
+
* @param cond The spending condition for this output
|
|
41
|
+
* @param pubkeys The 33 byte ecdsa compressed public keys involved in this output
|
|
42
|
+
* @param paths The paths corresponding to the pubkeys, in same order.
|
|
43
|
+
*/
|
|
44
|
+
setOwnOutput(i: number, cond: SpendingCondition, pubkeys: Buffer[], paths: number[][]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the descriptor template for this account type. Currently only
|
|
47
|
+
* DefaultDescriptorTemplates are allowed, but that might be changed in the
|
|
48
|
+
* future. See class WalletPolicy for more information on descriptor
|
|
49
|
+
* templates.
|
|
50
|
+
*/
|
|
51
|
+
getDescriptorTemplate(): DefaultDescriptorTemplate;
|
|
52
|
+
}
|
|
53
|
+
interface BaseAccount extends AccountType {
|
|
54
|
+
}
|
|
55
|
+
declare abstract class BaseAccount implements AccountType {
|
|
56
|
+
protected psbt: PsbtV2;
|
|
57
|
+
protected masterFp: Buffer;
|
|
58
|
+
constructor(psbt: PsbtV2, masterFp: Buffer);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Superclass for single signature accounts. This will make sure that the pubkey
|
|
62
|
+
* arrays and path arrays in the method arguments contains exactly one element
|
|
63
|
+
* and calls an abstract method to do the actual work.
|
|
64
|
+
*/
|
|
65
|
+
declare abstract class SingleKeyAccount extends BaseAccount {
|
|
66
|
+
spendingCondition(pubkeys: Buffer[]): SpendingCondition;
|
|
67
|
+
protected abstract singleKeyCondition(pubkey: Buffer): SpendingCondition;
|
|
68
|
+
setInput(i: number, inputTx: Buffer | undefined, spentOutput: SpentOutput, pubkeys: Buffer[], pathElems: number[][]): void;
|
|
69
|
+
protected abstract setSingleKeyInput(i: number, inputTx: Buffer | undefined, spentOutput: SpentOutput, pubkey: Buffer, path: number[]): any;
|
|
70
|
+
setOwnOutput(i: number, cond: SpendingCondition, pubkeys: Buffer[], paths: number[][]): void;
|
|
71
|
+
protected abstract setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]): any;
|
|
72
|
+
}
|
|
73
|
+
export declare class p2pkh extends SingleKeyAccount {
|
|
74
|
+
singleKeyCondition(pubkey: Buffer): SpendingCondition;
|
|
75
|
+
setSingleKeyInput(i: number, inputTx: Buffer | undefined, _spentOutput: SpentOutput, pubkey: Buffer, path: number[]): void;
|
|
76
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]): void;
|
|
77
|
+
getDescriptorTemplate(): DefaultDescriptorTemplate;
|
|
78
|
+
}
|
|
79
|
+
export declare class p2tr extends SingleKeyAccount {
|
|
80
|
+
singleKeyCondition(pubkey: Buffer): SpendingCondition;
|
|
81
|
+
setSingleKeyInput(i: number, _inputTx: Buffer | undefined, spentOutput: SpentOutput, pubkey: Buffer, path: number[]): void;
|
|
82
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]): void;
|
|
83
|
+
getDescriptorTemplate(): DefaultDescriptorTemplate;
|
|
84
|
+
private hashTapTweak;
|
|
85
|
+
/**
|
|
86
|
+
* Calculates a taproot output key from an internal key. This output key will be
|
|
87
|
+
* used as witness program in a taproot output. The internal key is tweaked
|
|
88
|
+
* according to recommendation in BIP341:
|
|
89
|
+
* https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0
|
|
90
|
+
*
|
|
91
|
+
* @param internalPubkey A 32 byte x-only taproot internal key
|
|
92
|
+
* @returns The output key
|
|
93
|
+
*/
|
|
94
|
+
getTaprootOutputKey(internalPubkey: Buffer): Buffer;
|
|
95
|
+
}
|
|
96
|
+
export declare class p2wpkhWrapped extends SingleKeyAccount {
|
|
97
|
+
singleKeyCondition(pubkey: Buffer): SpendingCondition;
|
|
98
|
+
setSingleKeyInput(i: number, inputTx: Buffer | undefined, spentOutput: SpentOutput, pubkey: Buffer, path: number[]): void;
|
|
99
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]): void;
|
|
100
|
+
getDescriptorTemplate(): DefaultDescriptorTemplate;
|
|
101
|
+
private createRedeemScript;
|
|
102
|
+
}
|
|
103
|
+
export declare class p2wpkh extends SingleKeyAccount {
|
|
104
|
+
singleKeyCondition(pubkey: Buffer): SpendingCondition;
|
|
105
|
+
setSingleKeyInput(i: number, inputTx: Buffer | undefined, spentOutput: SpentOutput, pubkey: Buffer, path: number[]): void;
|
|
106
|
+
setSingleKeyOutput(i: number, cond: SpendingCondition, pubkey: Buffer, path: number[]): void;
|
|
107
|
+
getDescriptorTemplate(): DefaultDescriptorTemplate;
|
|
108
|
+
}
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=accounttype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounttype.d.ts","sourceRoot":"","sources":["../../src/newops/accounttype.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,oBAAY,iBAAiB,GAAG;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CAIvB,CAAC;AAEF,oBAAY,WAAW,GAAG;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;IAExD;;;;;;;;OAQG;IACH,QAAQ,CACN,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,MAAM,EAAE,EAAE,GACpB,IAAI,CAAC;IAER;;;;;;;;OAQG;IACH,YAAY,CACV,CAAC,EAAE,MAAM,EACT,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,MAAM,EAAE,EAAE,GAChB,IAAI,CAAC;IAER;;;;;OAKG;IACH,qBAAqB,IAAI,yBAAyB,CAAC;CACpD;AAGD,UAAU,WAAY,SAAQ,WAAW;CAAG;AAE5C,uBAAe,WAAY,YAAW,WAAW;IACnC,SAAS,CAAC,IAAI,EAAE,MAAM;IAAE,SAAS,CAAC,QAAQ,EAAE,MAA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,iBAAiB,EACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAAE;IAKhB,qBAAqB,IAAI,yBAAyB;CAGnD"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
exports.__esModule = true;
|
|
18
|
+
exports.p2wpkh = exports.p2wpkhWrapped = exports.p2tr = exports.p2pkh = void 0;
|
|
19
|
+
var bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
20
|
+
var tiny_secp256k1_1 = require("tiny-secp256k1");
|
|
21
|
+
var buffertools_1 = require("../buffertools");
|
|
22
|
+
var constants_1 = require("../constants");
|
|
23
|
+
var hashPublicKey_1 = require("../hashPublicKey");
|
|
24
|
+
var BaseAccount = /** @class */ (function () {
|
|
25
|
+
function BaseAccount(psbt, masterFp) {
|
|
26
|
+
this.psbt = psbt;
|
|
27
|
+
this.masterFp = masterFp;
|
|
28
|
+
}
|
|
29
|
+
return BaseAccount;
|
|
30
|
+
}());
|
|
31
|
+
/**
|
|
32
|
+
* Superclass for single signature accounts. This will make sure that the pubkey
|
|
33
|
+
* arrays and path arrays in the method arguments contains exactly one element
|
|
34
|
+
* and calls an abstract method to do the actual work.
|
|
35
|
+
*/
|
|
36
|
+
var SingleKeyAccount = /** @class */ (function (_super) {
|
|
37
|
+
__extends(SingleKeyAccount, _super);
|
|
38
|
+
function SingleKeyAccount() {
|
|
39
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
40
|
+
}
|
|
41
|
+
SingleKeyAccount.prototype.spendingCondition = function (pubkeys) {
|
|
42
|
+
if (pubkeys.length != 1) {
|
|
43
|
+
throw new Error("Expected single key, got " + pubkeys.length);
|
|
44
|
+
}
|
|
45
|
+
return this.singleKeyCondition(pubkeys[0]);
|
|
46
|
+
};
|
|
47
|
+
SingleKeyAccount.prototype.setInput = function (i, inputTx, spentOutput, pubkeys, pathElems) {
|
|
48
|
+
if (pubkeys.length != 1) {
|
|
49
|
+
throw new Error("Expected single key, got " + pubkeys.length);
|
|
50
|
+
}
|
|
51
|
+
if (pathElems.length != 1) {
|
|
52
|
+
throw new Error("Expected single path, got " + pathElems.length);
|
|
53
|
+
}
|
|
54
|
+
this.setSingleKeyInput(i, inputTx, spentOutput, pubkeys[0], pathElems[0]);
|
|
55
|
+
};
|
|
56
|
+
SingleKeyAccount.prototype.setOwnOutput = function (i, cond, pubkeys, paths) {
|
|
57
|
+
if (pubkeys.length != 1) {
|
|
58
|
+
throw new Error("Expected single key, got " + pubkeys.length);
|
|
59
|
+
}
|
|
60
|
+
if (paths.length != 1) {
|
|
61
|
+
throw new Error("Expected single path, got " + paths.length);
|
|
62
|
+
}
|
|
63
|
+
this.setSingleKeyOutput(i, cond, pubkeys[0], paths[0]);
|
|
64
|
+
};
|
|
65
|
+
return SingleKeyAccount;
|
|
66
|
+
}(BaseAccount));
|
|
67
|
+
var p2pkh = /** @class */ (function (_super) {
|
|
68
|
+
__extends(p2pkh, _super);
|
|
69
|
+
function p2pkh() {
|
|
70
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
71
|
+
}
|
|
72
|
+
p2pkh.prototype.singleKeyCondition = function (pubkey) {
|
|
73
|
+
var buf = new buffertools_1.BufferWriter();
|
|
74
|
+
var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
|
|
75
|
+
buf.writeSlice(Buffer.of(constants_1.OP_DUP, constants_1.OP_HASH160, constants_1.HASH_SIZE));
|
|
76
|
+
buf.writeSlice(pubkeyHash);
|
|
77
|
+
buf.writeSlice(Buffer.of(constants_1.OP_EQUALVERIFY, constants_1.OP_CHECKSIG));
|
|
78
|
+
return { scriptPubKey: buf.buffer() };
|
|
79
|
+
};
|
|
80
|
+
p2pkh.prototype.setSingleKeyInput = function (i, inputTx, _spentOutput, pubkey, path) {
|
|
81
|
+
if (!inputTx) {
|
|
82
|
+
throw new Error("Full input base transaction required");
|
|
83
|
+
}
|
|
84
|
+
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
85
|
+
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
86
|
+
};
|
|
87
|
+
p2pkh.prototype.setSingleKeyOutput = function (i, cond, pubkey, path) {
|
|
88
|
+
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
89
|
+
};
|
|
90
|
+
p2pkh.prototype.getDescriptorTemplate = function () {
|
|
91
|
+
return "pkh(@0)";
|
|
92
|
+
};
|
|
93
|
+
return p2pkh;
|
|
94
|
+
}(SingleKeyAccount));
|
|
95
|
+
exports.p2pkh = p2pkh;
|
|
96
|
+
var p2tr = /** @class */ (function (_super) {
|
|
97
|
+
__extends(p2tr, _super);
|
|
98
|
+
function p2tr() {
|
|
99
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
100
|
+
}
|
|
101
|
+
p2tr.prototype.singleKeyCondition = function (pubkey) {
|
|
102
|
+
var xonlyPubkey = pubkey.slice(1); // x-only pubkey
|
|
103
|
+
var buf = new buffertools_1.BufferWriter();
|
|
104
|
+
var outputKey = this.getTaprootOutputKey(xonlyPubkey);
|
|
105
|
+
buf.writeSlice(Buffer.of(0x51, 32)); // push1, pubkeylen
|
|
106
|
+
buf.writeSlice(outputKey);
|
|
107
|
+
return { scriptPubKey: buf.buffer() };
|
|
108
|
+
};
|
|
109
|
+
p2tr.prototype.setSingleKeyInput = function (i, _inputTx, spentOutput, pubkey, path) {
|
|
110
|
+
var xonly = pubkey.slice(1);
|
|
111
|
+
this.psbt.setInputTapBip32Derivation(i, xonly, [], this.masterFp, path);
|
|
112
|
+
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
113
|
+
};
|
|
114
|
+
p2tr.prototype.setSingleKeyOutput = function (i, cond, pubkey, path) {
|
|
115
|
+
var xonly = pubkey.slice(1);
|
|
116
|
+
this.psbt.setOutputTapBip32Derivation(i, xonly, [], this.masterFp, path);
|
|
117
|
+
};
|
|
118
|
+
p2tr.prototype.getDescriptorTemplate = function () {
|
|
119
|
+
return "tr(@0)";
|
|
120
|
+
};
|
|
121
|
+
/*
|
|
122
|
+
The following two functions are copied from wallet-btc and adapted.
|
|
123
|
+
They should be moved to a library to avoid code reuse.
|
|
124
|
+
*/
|
|
125
|
+
p2tr.prototype.hashTapTweak = function (x) {
|
|
126
|
+
// hash_tag(x) = SHA256(SHA256(tag) || SHA256(tag) || x), see BIP340
|
|
127
|
+
// See https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification
|
|
128
|
+
var h = bitcoinjs_lib_1.crypto.sha256(Buffer.from("TapTweak", "utf-8"));
|
|
129
|
+
return bitcoinjs_lib_1.crypto.sha256(Buffer.concat([h, h, x]));
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Calculates a taproot output key from an internal key. This output key will be
|
|
133
|
+
* used as witness program in a taproot output. The internal key is tweaked
|
|
134
|
+
* according to recommendation in BIP341:
|
|
135
|
+
* https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0
|
|
136
|
+
*
|
|
137
|
+
* @param internalPubkey A 32 byte x-only taproot internal key
|
|
138
|
+
* @returns The output key
|
|
139
|
+
*/
|
|
140
|
+
p2tr.prototype.getTaprootOutputKey = function (internalPubkey) {
|
|
141
|
+
if (internalPubkey.length != 32) {
|
|
142
|
+
throw new Error("Expected 32 byte pubkey. Got " + internalPubkey.length);
|
|
143
|
+
}
|
|
144
|
+
// A BIP32 derived key can be converted to a schnorr pubkey by dropping
|
|
145
|
+
// the first byte, which represent the oddness/evenness. In schnorr all
|
|
146
|
+
// pubkeys are even.
|
|
147
|
+
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-conversion
|
|
148
|
+
var evenEcdsaPubkey = Buffer.concat([Buffer.of(0x02), internalPubkey]);
|
|
149
|
+
var tweak = this.hashTapTweak(internalPubkey);
|
|
150
|
+
// Q = P + int(hash_TapTweak(bytes(P)))G
|
|
151
|
+
var outputEcdsaKey = Buffer.from((0, tiny_secp256k1_1.pointAddScalar)(evenEcdsaPubkey, tweak));
|
|
152
|
+
// Convert to schnorr.
|
|
153
|
+
var outputSchnorrKey = outputEcdsaKey.slice(1);
|
|
154
|
+
// Create address
|
|
155
|
+
return outputSchnorrKey;
|
|
156
|
+
};
|
|
157
|
+
return p2tr;
|
|
158
|
+
}(SingleKeyAccount));
|
|
159
|
+
exports.p2tr = p2tr;
|
|
160
|
+
var p2wpkhWrapped = /** @class */ (function (_super) {
|
|
161
|
+
__extends(p2wpkhWrapped, _super);
|
|
162
|
+
function p2wpkhWrapped() {
|
|
163
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
164
|
+
}
|
|
165
|
+
p2wpkhWrapped.prototype.singleKeyCondition = function (pubkey) {
|
|
166
|
+
var buf = new buffertools_1.BufferWriter();
|
|
167
|
+
var redeemScript = this.createRedeemScript(pubkey);
|
|
168
|
+
var scriptHash = (0, hashPublicKey_1.hashPublicKey)(redeemScript);
|
|
169
|
+
buf.writeSlice(Buffer.of(constants_1.OP_HASH160, constants_1.HASH_SIZE));
|
|
170
|
+
buf.writeSlice(scriptHash);
|
|
171
|
+
buf.writeUInt8(constants_1.OP_EQUAL);
|
|
172
|
+
return { scriptPubKey: buf.buffer(), redeemScript: redeemScript };
|
|
173
|
+
};
|
|
174
|
+
p2wpkhWrapped.prototype.setSingleKeyInput = function (i, inputTx, spentOutput, pubkey, path) {
|
|
175
|
+
if (!inputTx) {
|
|
176
|
+
throw new Error("Full input base transaction required");
|
|
177
|
+
}
|
|
178
|
+
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
179
|
+
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
180
|
+
var userSuppliedRedeemScript = spentOutput.cond.redeemScript;
|
|
181
|
+
var expectedRedeemScript = this.createRedeemScript(pubkey);
|
|
182
|
+
if (userSuppliedRedeemScript &&
|
|
183
|
+
!expectedRedeemScript.equals(userSuppliedRedeemScript)) {
|
|
184
|
+
// At what point might a user set the redeemScript on its own?
|
|
185
|
+
throw new Error("User-supplied redeemScript " + userSuppliedRedeemScript.toString("hex") + " doesn't\n match expected " + expectedRedeemScript.toString("hex") + " for input " + i);
|
|
186
|
+
}
|
|
187
|
+
this.psbt.setInputRedeemScript(i, expectedRedeemScript);
|
|
188
|
+
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
189
|
+
};
|
|
190
|
+
p2wpkhWrapped.prototype.setSingleKeyOutput = function (i, cond, pubkey, path) {
|
|
191
|
+
this.psbt.setOutputRedeemScript(i, cond.redeemScript);
|
|
192
|
+
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
193
|
+
};
|
|
194
|
+
p2wpkhWrapped.prototype.getDescriptorTemplate = function () {
|
|
195
|
+
return "sh(wpkh(@0))";
|
|
196
|
+
};
|
|
197
|
+
p2wpkhWrapped.prototype.createRedeemScript = function (pubkey) {
|
|
198
|
+
var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
|
|
199
|
+
return Buffer.concat([Buffer.from("0014", "hex"), pubkeyHash]);
|
|
200
|
+
};
|
|
201
|
+
return p2wpkhWrapped;
|
|
202
|
+
}(SingleKeyAccount));
|
|
203
|
+
exports.p2wpkhWrapped = p2wpkhWrapped;
|
|
204
|
+
var p2wpkh = /** @class */ (function (_super) {
|
|
205
|
+
__extends(p2wpkh, _super);
|
|
206
|
+
function p2wpkh() {
|
|
207
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
208
|
+
}
|
|
209
|
+
p2wpkh.prototype.singleKeyCondition = function (pubkey) {
|
|
210
|
+
var buf = new buffertools_1.BufferWriter();
|
|
211
|
+
var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
|
|
212
|
+
buf.writeSlice(Buffer.of(0, constants_1.HASH_SIZE));
|
|
213
|
+
buf.writeSlice(pubkeyHash);
|
|
214
|
+
return { scriptPubKey: buf.buffer() };
|
|
215
|
+
};
|
|
216
|
+
p2wpkh.prototype.setSingleKeyInput = function (i, inputTx, spentOutput, pubkey, path) {
|
|
217
|
+
if (!inputTx) {
|
|
218
|
+
throw new Error("Full input base transaction required");
|
|
219
|
+
}
|
|
220
|
+
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
221
|
+
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
222
|
+
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
223
|
+
};
|
|
224
|
+
p2wpkh.prototype.setSingleKeyOutput = function (i, cond, pubkey, path) {
|
|
225
|
+
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
226
|
+
};
|
|
227
|
+
p2wpkh.prototype.getDescriptorTemplate = function () {
|
|
228
|
+
return "wpkh(@0)";
|
|
229
|
+
};
|
|
230
|
+
return p2wpkh;
|
|
231
|
+
}(SingleKeyAccount));
|
|
232
|
+
exports.p2wpkh = p2wpkh;
|
|
233
|
+
//# sourceMappingURL=accounttype.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounttype.js","sourceRoot":"","sources":["../../src/newops/accounttype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AG,IAAA,6BAAa,EAAC,MAAM,CAAC,CAAC;QACzC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAS,CAAC,CAAC,CAAC;QACxC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC3B,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IACxC,CAAC;IAED,kCAAiB,GAAjB,UACE,CAAS,EACT,OAA2B,EAC3B,WAAwB,EACxB,MAAc,EACd,IAAc;QAEd,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SACzD;QACD,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAC3B,CAAC,EACD,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,CAAC,YAAY,CAC9B,CAAC;IACJ,CAAC;IAED,mCAAkB,GAAlB,UACE,CAAS,EACT,IAAuB,EACvB,MAAc,EACd,IAAc;QAEd,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC;IAED,sCAAqB,GAArB;QACE,OAAO,UAAU,CAAC;IACpB,CAAC;IACH,aAAC;AAAD,CAAC,AAxCD,CAA4B,gBAAgB,GAwC3C;AAxCY,wBAAM"}
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
import Transport from "@ledgerhq/hw-transport";
|
|
3
3
|
import { PsbtV2 } from "./psbtv2";
|
|
4
4
|
import { WalletPolicy } from "./policy";
|
|
5
|
+
/**
|
|
6
|
+
* This class encapsulates the APDU protocol documented at
|
|
7
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
|
|
8
|
+
*/
|
|
5
9
|
export declare class AppClient {
|
|
6
10
|
transport: Transport;
|
|
7
11
|
constructor(transport: Transport);
|
|
8
12
|
private makeRequest;
|
|
9
|
-
|
|
13
|
+
getExtendedPubkey(display: boolean, pathElements: number[]): Promise<string>;
|
|
10
14
|
getWalletAddress(walletPolicy: WalletPolicy, walletHMAC: Buffer | null, change: number, addressIndex: number, display: boolean): Promise<string>;
|
|
11
|
-
signPsbt(psbt: PsbtV2, walletPolicy: WalletPolicy, walletHMAC: Buffer | null): Promise<Map<number, Buffer>>;
|
|
15
|
+
signPsbt(psbt: PsbtV2, walletPolicy: WalletPolicy, walletHMAC: Buffer | null, progressCallback: () => void): Promise<Map<number, Buffer>>;
|
|
12
16
|
getMasterFingerprint(): Promise<Buffer>;
|
|
13
17
|
}
|
|
14
18
|
//# sourceMappingURL=appClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appClient.d.ts","sourceRoot":"","sources":["../../src/newops/appClient.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAoBxC,qBAAa,SAAS;IACpB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS;YAIlB,WAAW;IA6BnB,
|
|
1
|
+
{"version":3,"file":"appClient.d.ts","sourceRoot":"","sources":["../../src/newops/appClient.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAoBxC;;;GAGG;AACH,qBAAa,SAAS;IACpB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS;YAIlB,WAAW;IA6BnB,iBAAiB,CACrB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,MAAM,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC;IAcZ,gBAAgB,CACpB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC;IAkCZ,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,gBAAgB,EAAE,MAAM,IAAI,GAC3B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAuDzB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC;CAG9C"}
|
package/lib/newops/appClient.js
CHANGED
|
@@ -68,6 +68,10 @@ var FrameworkIns;
|
|
|
68
68
|
(function (FrameworkIns) {
|
|
69
69
|
FrameworkIns[FrameworkIns["CONTINUE_INTERRUPTED"] = 1] = "CONTINUE_INTERRUPTED";
|
|
70
70
|
})(FrameworkIns || (FrameworkIns = {}));
|
|
71
|
+
/**
|
|
72
|
+
* This class encapsulates the APDU protocol documented at
|
|
73
|
+
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
|
|
74
|
+
*/
|
|
71
75
|
var AppClient = /** @class */ (function () {
|
|
72
76
|
function AppClient(transport) {
|
|
73
77
|
this.transport = transport;
|
|
@@ -100,7 +104,7 @@ var AppClient = /** @class */ (function () {
|
|
|
100
104
|
});
|
|
101
105
|
});
|
|
102
106
|
};
|
|
103
|
-
AppClient.prototype.
|
|
107
|
+
AppClient.prototype.getExtendedPubkey = function (display, pathElements) {
|
|
104
108
|
return __awaiter(this, void 0, void 0, function () {
|
|
105
109
|
var response;
|
|
106
110
|
return __generator(this, function (_a) {
|
|
@@ -133,7 +137,7 @@ var AppClient = /** @class */ (function () {
|
|
|
133
137
|
if (walletHMAC != null && walletHMAC.length != 32) {
|
|
134
138
|
throw new Error("Invalid HMAC length");
|
|
135
139
|
}
|
|
136
|
-
clientInterpreter = new clientCommands_1.ClientCommandInterpreter();
|
|
140
|
+
clientInterpreter = new clientCommands_1.ClientCommandInterpreter(function () { });
|
|
137
141
|
clientInterpreter.addKnownList(walletPolicy.keys.map(function (k) { return Buffer.from(k, "ascii"); }));
|
|
138
142
|
clientInterpreter.addKnownPreimage(walletPolicy.serialize());
|
|
139
143
|
addressIndexBuffer = Buffer.alloc(4);
|
|
@@ -152,7 +156,7 @@ var AppClient = /** @class */ (function () {
|
|
|
152
156
|
});
|
|
153
157
|
});
|
|
154
158
|
};
|
|
155
|
-
AppClient.prototype.signPsbt = function (psbt, walletPolicy, walletHMAC) {
|
|
159
|
+
AppClient.prototype.signPsbt = function (psbt, walletPolicy, walletHMAC, progressCallback) {
|
|
156
160
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
161
|
var merkelizedPsbt, clientInterpreter, _a, _b, map, _c, _d, map, inputMapsRoot, outputMapsRoot, yielded, ret, yielded_1, yielded_1_1, inputAndSig;
|
|
158
162
|
var e_1, _e, e_2, _f, e_3, _g;
|
|
@@ -163,7 +167,7 @@ var AppClient = /** @class */ (function () {
|
|
|
163
167
|
if (walletHMAC != null && walletHMAC.length != 32) {
|
|
164
168
|
throw new Error("Invalid HMAC length");
|
|
165
169
|
}
|
|
166
|
-
clientInterpreter = new clientCommands_1.ClientCommandInterpreter();
|
|
170
|
+
clientInterpreter = new clientCommands_1.ClientCommandInterpreter(progressCallback);
|
|
167
171
|
// prepare ClientCommandInterpreter
|
|
168
172
|
clientInterpreter.addKnownList(walletPolicy.keys.map(function (k) { return Buffer.from(k, "ascii"); }));
|
|
169
173
|
clientInterpreter.addKnownPreimage(walletPolicy.serialize());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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|
abstract execute(request: Buffer): Buffer;
|
|
14
14
|
}
|
|
15
15
|
export declare class YieldCommand extends ClientCommand {
|
|
16
|
+
private progressCallback;
|
|
16
17
|
private results;
|
|
17
18
|
code: ClientCommandCode;
|
|
18
|
-
constructor(results: Buffer[]);
|
|
19
|
+
constructor(results: Buffer[], progressCallback: () => void);
|
|
19
20
|
execute(request: Buffer): Buffer;
|
|
20
21
|
}
|
|
21
22
|
export declare class GetPreimageCommand extends ClientCommand {
|
|
@@ -44,13 +45,28 @@ export declare class GetMoreElementsCommand extends ClientCommand {
|
|
|
44
45
|
constructor(queue: Buffer[]);
|
|
45
46
|
execute(request: Buffer): Buffer;
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* This class will dispatch a client command coming from the hardware device to
|
|
50
|
+
* the appropriate client command implementation. Those client commands
|
|
51
|
+
* typically requests data from a merkle tree or merkelized maps.
|
|
52
|
+
*
|
|
53
|
+
* A ClientCommandInterpreter is prepared by adding the merkle trees and
|
|
54
|
+
* merkelized maps it should be able to serve to the hardware device. This class
|
|
55
|
+
* doesn't know anything about the semantics of the data it holds, it just
|
|
56
|
+
* serves merkle data. It doesn't even know in what context it is being
|
|
57
|
+
* executed, ie SignPsbt, getWalletAddress, etc.
|
|
58
|
+
*
|
|
59
|
+
* If the command yelds results to the client, as signPsbt does, the yielded
|
|
60
|
+
* data will be accessible after the command completed by calling getYielded(),
|
|
61
|
+
* which will return the yields in the same order as they came in.
|
|
62
|
+
*/
|
|
47
63
|
export declare class ClientCommandInterpreter {
|
|
48
64
|
private roots;
|
|
49
65
|
private preimages;
|
|
50
66
|
private yielded;
|
|
51
67
|
private queue;
|
|
52
68
|
private commands;
|
|
53
|
-
constructor();
|
|
69
|
+
constructor(progressCallback: () => void);
|
|
54
70
|
getYielded(): Buffer[];
|
|
55
71
|
addKnownPreimage(preimage: Buffer): void;
|
|
56
72
|
addKnownList(elements: Buffer[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCommands.d.ts","sourceRoot":"","sources":["../../src/newops/clientCommands.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"clientCommands.d.ts","sourceRoot":"","sources":["../../src/newops/clientCommands.ts"],"names":[],"mappings":";AAGA,OAAO,EAAY,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,aAAK,iBAAiB;IACpB,KAAK,KAAO;IACZ,YAAY,KAAO;IACnB,qBAAqB,KAAO;IAC5B,qBAAqB,KAAO;IAC5B,iBAAiB,MAAO;CACzB;AAED,uBAAe,aAAa;IAC1B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAC1C;AAED,qBAAa,YAAa,SAAQ,aAAa;IAKd,OAAO,CAAC,gBAAgB;IAJvD,OAAO,CAAC,OAAO,CAAW;IAE1B,IAAI,oBAA2B;gBAEnB,OAAO,EAAE,MAAM,EAAE,EAAU,gBAAgB,EAAE,MAAM,IAAI;IAKnE,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAKjC;AAED,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,KAAK,CAAW;IAExB,IAAI,oBAAkC;gBAE1B,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE;IAMjE,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CA4CjC;AAED,qBAAa,yBAA0B,SAAQ,aAAa;IAC1D,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,KAAK,CAAW;IAExB,IAAI,oBAA2C;gBAEnC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE;IAM7D,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAyDjC;AAED,qBAAa,yBAA0B,SAAQ,aAAa;IAC1D,OAAO,CAAC,WAAW,CAAsB;IAEzC,IAAI,oBAA2C;gBAEnC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAK5C,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAuCjC;AAED,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB,IAAI,oBAAuC;gBAE/B,KAAK,EAAE,MAAM,EAAE;IAK3B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CA4BjC;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,SAAS,CAAkC;IAEnD,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,KAAK,CAAgB;IAE7B,OAAO,CAAC,QAAQ,CAAoD;gBAExD,gBAAgB,EAAE,MAAM,IAAI;IAiBxC,UAAU,IAAI,MAAM,EAAE;IAItB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIxC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAStC,eAAe,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAKpC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAajC"}
|
|
@@ -53,6 +53,7 @@ var __values = (this && this.__values) || function(o) {
|
|
|
53
53
|
exports.__esModule = true;
|
|
54
54
|
exports.ClientCommandInterpreter = exports.GetMoreElementsCommand = exports.GetMerkleLeafIndexCommand = exports.GetMerkleLeafProofCommand = exports.GetPreimageCommand = exports.YieldCommand = void 0;
|
|
55
55
|
var bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
56
|
+
var buffertools_1 = require("../buffertools");
|
|
56
57
|
var varint_1 = require("../varint");
|
|
57
58
|
var merkle_1 = require("./merkle");
|
|
58
59
|
var ClientCommandCode;
|
|
@@ -70,14 +71,16 @@ var ClientCommand = /** @class */ (function () {
|
|
|
70
71
|
}());
|
|
71
72
|
var YieldCommand = /** @class */ (function (_super) {
|
|
72
73
|
__extends(YieldCommand, _super);
|
|
73
|
-
function YieldCommand(results) {
|
|
74
|
+
function YieldCommand(results, progressCallback) {
|
|
74
75
|
var _this = _super.call(this) || this;
|
|
76
|
+
_this.progressCallback = progressCallback;
|
|
75
77
|
_this.code = ClientCommandCode.YIELD;
|
|
76
78
|
_this.results = results;
|
|
77
79
|
return _this;
|
|
78
80
|
}
|
|
79
81
|
YieldCommand.prototype.execute = function (request) {
|
|
80
82
|
this.results.push(Buffer.from(request.subarray(1)));
|
|
83
|
+
this.progressCallback();
|
|
81
84
|
return Buffer.from("");
|
|
82
85
|
};
|
|
83
86
|
return YieldCommand;
|
|
@@ -142,17 +145,21 @@ var GetMerkleLeafProofCommand = /** @class */ (function (_super) {
|
|
|
142
145
|
GetMerkleLeafProofCommand.prototype.execute = function (request) {
|
|
143
146
|
var _a;
|
|
144
147
|
var req = request.subarray(1);
|
|
145
|
-
if (req.length
|
|
146
|
-
throw new Error("Invalid request,
|
|
147
|
-
}
|
|
148
|
-
// read the hash
|
|
149
|
-
var hash = Buffer.alloc(32);
|
|
150
|
-
for (var i = 0; i < 32; i++) {
|
|
151
|
-
hash[i] = req.readUInt8(i);
|
|
148
|
+
if (req.length < 32 + 1 + 1) {
|
|
149
|
+
throw new Error("Invalid request, expected at least 34 bytes");
|
|
152
150
|
}
|
|
151
|
+
var reqBuf = new buffertools_1.BufferReader(req);
|
|
152
|
+
var hash = reqBuf.readSlice(32);
|
|
153
153
|
var hash_hex = hash.toString("hex");
|
|
154
|
-
var tree_size
|
|
155
|
-
var leaf_index
|
|
154
|
+
var tree_size;
|
|
155
|
+
var leaf_index;
|
|
156
|
+
try {
|
|
157
|
+
tree_size = reqBuf.readVarInt();
|
|
158
|
+
leaf_index = reqBuf.readVarInt();
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
throw new Error("Invalid request, couldn't parse tree_size or leaf_index");
|
|
162
|
+
}
|
|
156
163
|
var mt = this.known_trees.get(hash_hex);
|
|
157
164
|
if (!mt) {
|
|
158
165
|
throw Error("Requested Merkle leaf proof for unknown tree: " + hash_hex);
|
|
@@ -253,8 +260,23 @@ var GetMoreElementsCommand = /** @class */ (function (_super) {
|
|
|
253
260
|
return GetMoreElementsCommand;
|
|
254
261
|
}(ClientCommand));
|
|
255
262
|
exports.GetMoreElementsCommand = GetMoreElementsCommand;
|
|
263
|
+
/**
|
|
264
|
+
* This class will dispatch a client command coming from the hardware device to
|
|
265
|
+
* the appropriate client command implementation. Those client commands
|
|
266
|
+
* typically requests data from a merkle tree or merkelized maps.
|
|
267
|
+
*
|
|
268
|
+
* A ClientCommandInterpreter is prepared by adding the merkle trees and
|
|
269
|
+
* merkelized maps it should be able to serve to the hardware device. This class
|
|
270
|
+
* doesn't know anything about the semantics of the data it holds, it just
|
|
271
|
+
* serves merkle data. It doesn't even know in what context it is being
|
|
272
|
+
* executed, ie SignPsbt, getWalletAddress, etc.
|
|
273
|
+
*
|
|
274
|
+
* If the command yelds results to the client, as signPsbt does, the yielded
|
|
275
|
+
* data will be accessible after the command completed by calling getYielded(),
|
|
276
|
+
* which will return the yields in the same order as they came in.
|
|
277
|
+
*/
|
|
256
278
|
var ClientCommandInterpreter = /** @class */ (function () {
|
|
257
|
-
function ClientCommandInterpreter() {
|
|
279
|
+
function ClientCommandInterpreter(progressCallback) {
|
|
258
280
|
var e_1, _a;
|
|
259
281
|
this.roots = new Map();
|
|
260
282
|
this.preimages = new Map();
|
|
@@ -262,7 +284,7 @@ var ClientCommandInterpreter = /** @class */ (function () {
|
|
|
262
284
|
this.queue = [];
|
|
263
285
|
this.commands = new Map();
|
|
264
286
|
var commands = [
|
|
265
|
-
new YieldCommand(this.yielded),
|
|
287
|
+
new YieldCommand(this.yielded, progressCallback),
|
|
266
288
|
new GetPreimageCommand(this.preimages, this.queue),
|
|
267
289
|
new GetMerkleLeafIndexCommand(this.roots),
|
|
268
290
|
new GetMerkleLeafProofCommand(this.roots, this.queue),
|