@ledgerhq/hw-app-btc 10.0.1 → 10.0.2-nightly.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 +7 -0
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +72 -97
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.js +217 -313
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.js +46 -106
- package/lib/BtcOld.js.map +1 -1
- package/lib/bip32.js +12 -12
- package/lib/bip32.js.map +1 -1
- package/lib/buffertools.js +66 -69
- package/lib/buffertools.js.map +1 -1
- package/lib/compressPublicKey.js +3 -3
- package/lib/compressPublicKey.js.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/createTransaction.d.ts +1 -1
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/createTransaction.js +285 -398
- package/lib/createTransaction.js.map +1 -1
- package/lib/debug.js +11 -13
- package/lib/debug.js.map +1 -1
- package/lib/finalizeInput.js +23 -62
- package/lib/finalizeInput.js.map +1 -1
- package/lib/getAppAndVersion.d.ts +1 -1
- package/lib/getAppAndVersion.d.ts.map +1 -1
- package/lib/getAppAndVersion.js +29 -72
- package/lib/getAppAndVersion.js.map +1 -1
- package/lib/getTrustedInput.js +108 -251
- package/lib/getTrustedInput.js.map +1 -1
- package/lib/getTrustedInputBIP143.js +9 -10
- package/lib/getTrustedInputBIP143.js.map +1 -1
- package/lib/getWalletPublicKey.d.ts +1 -1
- package/lib/getWalletPublicKey.d.ts.map +1 -1
- package/lib/getWalletPublicKey.js +27 -73
- package/lib/getWalletPublicKey.js.map +1 -1
- package/lib/hashPublicKey.js +4 -4
- package/lib/hashPublicKey.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/newops/accounttype.d.ts +2 -2
- package/lib/newops/accounttype.d.ts.map +1 -1
- package/lib/newops/accounttype.js +85 -125
- package/lib/newops/accounttype.js.map +1 -1
- package/lib/newops/appClient.js +98 -205
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.js +122 -213
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.js +28 -75
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.js +38 -67
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.js +11 -12
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts +1 -1
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +17 -18
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.js +9 -9
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtFinalizer.js +22 -22
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/newops/psbtv2.d.ts +1 -1
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +227 -286
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib/serializeTransaction.js +13 -15
- package/lib/serializeTransaction.js.map +1 -1
- package/lib/shouldUseTrustedInputForSegwit.js +4 -5
- package/lib/shouldUseTrustedInputForSegwit.js.map +1 -1
- package/lib/signMessage.js +47 -99
- package/lib/signMessage.js.map +1 -1
- package/lib/signP2SHTransaction.d.ts +1 -1
- package/lib/signP2SHTransaction.d.ts.map +1 -1
- package/lib/signP2SHTransaction.js +91 -187
- package/lib/signP2SHTransaction.js.map +1 -1
- package/lib/signTransaction.js +8 -9
- package/lib/signTransaction.js.map +1 -1
- package/lib/splitTransaction.js +50 -54
- package/lib/splitTransaction.js.map +1 -1
- package/lib/startUntrustedHashTransactionInput.js +65 -167
- package/lib/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib/types.js +1 -1
- package/lib/varint.js +10 -10
- package/lib/varint.js.map +1 -1
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +58 -84
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.js +205 -302
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.js +35 -96
- package/lib-es/BtcOld.js.map +1 -1
- package/lib-es/bip32.js +7 -7
- package/lib-es/bip32.js.map +1 -1
- package/lib-es/buffertools.js +62 -67
- package/lib-es/buffertools.js.map +1 -1
- package/lib-es/compressPublicKey.js +2 -2
- package/lib-es/compressPublicKey.js.map +1 -1
- package/lib-es/constants.js +12 -12
- package/lib-es/constants.js.map +1 -1
- package/lib-es/createTransaction.d.ts +1 -1
- package/lib-es/createTransaction.d.ts.map +1 -1
- package/lib-es/createTransaction.js +271 -384
- package/lib-es/createTransaction.js.map +1 -1
- package/lib-es/debug.js +10 -12
- package/lib-es/debug.js.map +1 -1
- package/lib-es/finalizeInput.js +20 -59
- package/lib-es/finalizeInput.js.map +1 -1
- package/lib-es/getAppAndVersion.d.ts +1 -1
- package/lib-es/getAppAndVersion.d.ts.map +1 -1
- package/lib-es/getAppAndVersion.js +27 -70
- package/lib-es/getAppAndVersion.js.map +1 -1
- package/lib-es/getTrustedInput.js +104 -247
- package/lib-es/getTrustedInput.js.map +1 -1
- package/lib-es/getTrustedInputBIP143.js +5 -6
- package/lib-es/getTrustedInputBIP143.js.map +1 -1
- package/lib-es/getWalletPublicKey.d.ts +1 -1
- package/lib-es/getWalletPublicKey.d.ts.map +1 -1
- package/lib-es/getWalletPublicKey.js +25 -71
- package/lib-es/getWalletPublicKey.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts +2 -2
- package/lib-es/newops/accounttype.d.ts.map +1 -1
- package/lib-es/newops/accounttype.js +79 -123
- package/lib-es/newops/accounttype.js.map +1 -1
- package/lib-es/newops/appClient.js +92 -200
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.js +117 -214
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +25 -73
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.js +36 -66
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.js +8 -10
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts +1 -1
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +12 -14
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.js +7 -7
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.js +19 -19
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts +1 -1
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +225 -286
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/lib-es/serializeTransaction.js +11 -13
- package/lib-es/serializeTransaction.js.map +1 -1
- package/lib-es/shouldUseTrustedInputForSegwit.js +1 -2
- package/lib-es/shouldUseTrustedInputForSegwit.js.map +1 -1
- package/lib-es/signMessage.js +44 -96
- package/lib-es/signMessage.js.map +1 -1
- package/lib-es/signP2SHTransaction.d.ts +1 -1
- package/lib-es/signP2SHTransaction.d.ts.map +1 -1
- package/lib-es/signP2SHTransaction.js +84 -180
- package/lib-es/signP2SHTransaction.js.map +1 -1
- package/lib-es/signTransaction.js +6 -7
- package/lib-es/signTransaction.js.map +1 -1
- package/lib-es/splitTransaction.js +46 -50
- package/lib-es/splitTransaction.js.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.js +62 -164
- package/lib-es/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib-es/varint.js +9 -9
- package/lib-es/varint.js.map +1 -1
- package/package.json +5 -6
- package/src/Btc.ts +28 -5
|
@@ -1,61 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
var __values = (this && this.__values) || function(o) {
|
|
43
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
-
if (m) return m.call(o);
|
|
45
|
-
if (o && typeof o.length === "number") return {
|
|
46
|
-
next: function () {
|
|
47
|
-
if (o && i >= o.length) o = void 0;
|
|
48
|
-
return { value: o && o[i++], done: !o };
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
-
};
|
|
53
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
3
|
exports.ClientCommandInterpreter = exports.GetMoreElementsCommand = exports.GetMerkleLeafIndexCommand = exports.GetMerkleLeafProofCommand = exports.GetPreimageCommand = exports.YieldCommand = void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
4
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
5
|
+
const buffertools_1 = require("../buffertools");
|
|
6
|
+
const varint_1 = require("../varint");
|
|
7
|
+
const merkle_1 = require("./merkle");
|
|
59
8
|
var ClientCommandCode;
|
|
60
9
|
(function (ClientCommandCode) {
|
|
61
10
|
ClientCommandCode[ClientCommandCode["YIELD"] = 16] = "YIELD";
|
|
@@ -64,39 +13,31 @@ var ClientCommandCode;
|
|
|
64
13
|
ClientCommandCode[ClientCommandCode["GET_MERKLE_LEAF_INDEX"] = 66] = "GET_MERKLE_LEAF_INDEX";
|
|
65
14
|
ClientCommandCode[ClientCommandCode["GET_MORE_ELEMENTS"] = 160] = "GET_MORE_ELEMENTS";
|
|
66
15
|
})(ClientCommandCode || (ClientCommandCode = {}));
|
|
67
|
-
|
|
68
|
-
|
|
16
|
+
class ClientCommand {
|
|
17
|
+
}
|
|
18
|
+
class YieldCommand extends ClientCommand {
|
|
19
|
+
constructor(results, progressCallback) {
|
|
20
|
+
super();
|
|
21
|
+
this.progressCallback = progressCallback;
|
|
22
|
+
this.code = ClientCommandCode.YIELD;
|
|
23
|
+
this.results = results;
|
|
69
24
|
}
|
|
70
|
-
|
|
71
|
-
}());
|
|
72
|
-
var YieldCommand = /** @class */ (function (_super) {
|
|
73
|
-
__extends(YieldCommand, _super);
|
|
74
|
-
function YieldCommand(results, progressCallback) {
|
|
75
|
-
var _this = _super.call(this) || this;
|
|
76
|
-
_this.progressCallback = progressCallback;
|
|
77
|
-
_this.code = ClientCommandCode.YIELD;
|
|
78
|
-
_this.results = results;
|
|
79
|
-
return _this;
|
|
80
|
-
}
|
|
81
|
-
YieldCommand.prototype.execute = function (request) {
|
|
25
|
+
execute(request) {
|
|
82
26
|
this.results.push(Buffer.from(request.subarray(1)));
|
|
83
27
|
this.progressCallback();
|
|
84
28
|
return Buffer.from("");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}(ClientCommand));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
88
31
|
exports.YieldCommand = YieldCommand;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_this.queue = queue;
|
|
96
|
-
return _this;
|
|
32
|
+
class GetPreimageCommand extends ClientCommand {
|
|
33
|
+
constructor(known_preimages, queue) {
|
|
34
|
+
super();
|
|
35
|
+
this.code = ClientCommandCode.GET_PREIMAGE;
|
|
36
|
+
this.known_preimages = known_preimages;
|
|
37
|
+
this.queue = queue;
|
|
97
38
|
}
|
|
98
|
-
|
|
99
|
-
|
|
39
|
+
execute(request) {
|
|
40
|
+
const req = Buffer.from(request.subarray(1));
|
|
100
41
|
// we expect no more data to read
|
|
101
42
|
if (req.length != 1 + 32) {
|
|
102
43
|
throw new Error("Invalid request, unexpected trailing data");
|
|
@@ -105,20 +46,20 @@ var GetPreimageCommand = /** @class */ (function (_super) {
|
|
|
105
46
|
throw new Error("Unsupported request, the first byte should be 0");
|
|
106
47
|
}
|
|
107
48
|
// read the hash
|
|
108
|
-
|
|
109
|
-
for (
|
|
49
|
+
const hash = Buffer.alloc(32);
|
|
50
|
+
for (let i = 0; i < 32; i++) {
|
|
110
51
|
hash[i] = req[1 + i];
|
|
111
52
|
}
|
|
112
|
-
|
|
113
|
-
|
|
53
|
+
const req_hash_hex = hash.toString("hex");
|
|
54
|
+
const known_preimage = this.known_preimages.get(req_hash_hex);
|
|
114
55
|
if (known_preimage != undefined) {
|
|
115
|
-
|
|
56
|
+
const preimage_len_varint = (0, varint_1.createVarint)(known_preimage.length);
|
|
116
57
|
// We can send at most 255 - len(preimage_len_out) - 1 bytes in a single message;
|
|
117
58
|
// the rest will be stored in the queue for GET_MORE_ELEMENTS
|
|
118
|
-
|
|
119
|
-
|
|
59
|
+
const max_payload_size = 255 - preimage_len_varint.length - 1;
|
|
60
|
+
const payload_size = Math.min(max_payload_size, known_preimage.length);
|
|
120
61
|
if (payload_size < known_preimage.length) {
|
|
121
|
-
for (
|
|
62
|
+
for (let i = payload_size; i < known_preimage.length; i++) {
|
|
122
63
|
this.queue.push(Buffer.from([known_preimage[i]]));
|
|
123
64
|
}
|
|
124
65
|
}
|
|
@@ -128,31 +69,27 @@ var GetPreimageCommand = /** @class */ (function (_super) {
|
|
|
128
69
|
Buffer.from(known_preimage.subarray(0, payload_size)),
|
|
129
70
|
]);
|
|
130
71
|
}
|
|
131
|
-
throw Error(
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}(ClientCommand));
|
|
72
|
+
throw Error(`Requested unknown preimage for: ${req_hash_hex}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
135
75
|
exports.GetPreimageCommand = GetPreimageCommand;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
_this.queue = queue;
|
|
143
|
-
return _this;
|
|
76
|
+
class GetMerkleLeafProofCommand extends ClientCommand {
|
|
77
|
+
constructor(known_trees, queue) {
|
|
78
|
+
super();
|
|
79
|
+
this.code = ClientCommandCode.GET_MERKLE_LEAF_PROOF;
|
|
80
|
+
this.known_trees = known_trees;
|
|
81
|
+
this.queue = queue;
|
|
144
82
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
var req = Buffer.from(request.subarray(1));
|
|
83
|
+
execute(request) {
|
|
84
|
+
const req = Buffer.from(request.subarray(1));
|
|
148
85
|
if (req.length < 32 + 1 + 1) {
|
|
149
86
|
throw new Error("Invalid request, expected at least 34 bytes");
|
|
150
87
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
88
|
+
const reqBuf = new buffertools_1.BufferReader(req);
|
|
89
|
+
const hash = reqBuf.readSlice(32);
|
|
90
|
+
const hash_hex = hash.toString("hex");
|
|
91
|
+
let tree_size;
|
|
92
|
+
let leaf_index;
|
|
156
93
|
try {
|
|
157
94
|
tree_size = reqBuf.readVarInt();
|
|
158
95
|
leaf_index = reqBuf.readVarInt();
|
|
@@ -160,9 +97,9 @@ var GetMerkleLeafProofCommand = /** @class */ (function (_super) {
|
|
|
160
97
|
catch (e) {
|
|
161
98
|
throw new Error("Invalid request, couldn't parse tree_size or leaf_index");
|
|
162
99
|
}
|
|
163
|
-
|
|
100
|
+
const mt = this.known_trees.get(hash_hex);
|
|
164
101
|
if (!mt) {
|
|
165
|
-
throw Error(
|
|
102
|
+
throw Error(`Requested Merkle leaf proof for unknown tree: ${hash_hex}`);
|
|
166
103
|
}
|
|
167
104
|
if (leaf_index >= tree_size || mt.size() != tree_size) {
|
|
168
105
|
throw Error("Invalid index or tree size.");
|
|
@@ -170,54 +107,52 @@ var GetMerkleLeafProofCommand = /** @class */ (function (_super) {
|
|
|
170
107
|
if (this.queue.length != 0) {
|
|
171
108
|
throw Error("This command should not execute when the queue is not empty.");
|
|
172
109
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
110
|
+
const proof = mt.getProof(leaf_index);
|
|
111
|
+
const n_response_elements = Math.min(Math.floor((255 - 32 - 1 - 1) / 32), proof.length);
|
|
112
|
+
const n_leftover_elements = proof.length - n_response_elements;
|
|
176
113
|
// Add to the queue any proof elements that do not fit the response
|
|
177
114
|
if (n_leftover_elements > 0) {
|
|
178
|
-
|
|
115
|
+
this.queue.push(...proof.slice(-n_leftover_elements));
|
|
179
116
|
}
|
|
180
|
-
return Buffer.concat(
|
|
117
|
+
return Buffer.concat([
|
|
181
118
|
mt.getLeafHash(leaf_index),
|
|
182
119
|
Buffer.from([proof.length]),
|
|
183
|
-
Buffer.from([n_response_elements])
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
120
|
+
Buffer.from([n_response_elements]),
|
|
121
|
+
...proof.slice(0, n_response_elements),
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
188
125
|
exports.GetMerkleLeafProofCommand = GetMerkleLeafProofCommand;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
_this.known_trees = known_trees;
|
|
195
|
-
return _this;
|
|
126
|
+
class GetMerkleLeafIndexCommand extends ClientCommand {
|
|
127
|
+
constructor(known_trees) {
|
|
128
|
+
super();
|
|
129
|
+
this.code = ClientCommandCode.GET_MERKLE_LEAF_INDEX;
|
|
130
|
+
this.known_trees = known_trees;
|
|
196
131
|
}
|
|
197
|
-
|
|
198
|
-
|
|
132
|
+
execute(request) {
|
|
133
|
+
const req = Buffer.from(request.subarray(1));
|
|
199
134
|
if (req.length != 32 + 32) {
|
|
200
135
|
throw new Error("Invalid request, unexpected trailing data");
|
|
201
136
|
}
|
|
202
137
|
// read the root hash
|
|
203
|
-
|
|
204
|
-
for (
|
|
138
|
+
const root_hash = Buffer.alloc(32);
|
|
139
|
+
for (let i = 0; i < 32; i++) {
|
|
205
140
|
root_hash[i] = req.readUInt8(i);
|
|
206
141
|
}
|
|
207
|
-
|
|
142
|
+
const root_hash_hex = root_hash.toString("hex");
|
|
208
143
|
// read the leaf hash
|
|
209
|
-
|
|
210
|
-
for (
|
|
144
|
+
const leef_hash = Buffer.alloc(32);
|
|
145
|
+
for (let i = 0; i < 32; i++) {
|
|
211
146
|
leef_hash[i] = req.readUInt8(32 + i);
|
|
212
147
|
}
|
|
213
|
-
|
|
214
|
-
|
|
148
|
+
const leef_hash_hex = leef_hash.toString("hex");
|
|
149
|
+
const mt = this.known_trees.get(root_hash_hex);
|
|
215
150
|
if (!mt) {
|
|
216
|
-
throw Error(
|
|
151
|
+
throw Error(`Requested Merkle leaf index for unknown root: ${root_hash_hex}`);
|
|
217
152
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
for (
|
|
153
|
+
let leaf_index = 0;
|
|
154
|
+
let found = 0;
|
|
155
|
+
for (let i = 0; i < mt.size(); i++) {
|
|
221
156
|
if (mt.getLeafHash(i).toString("hex") == leef_hash_hex) {
|
|
222
157
|
found = 1;
|
|
223
158
|
leaf_index = i;
|
|
@@ -225,19 +160,16 @@ var GetMerkleLeafIndexCommand = /** @class */ (function (_super) {
|
|
|
225
160
|
}
|
|
226
161
|
}
|
|
227
162
|
return Buffer.concat([Buffer.from([found]), (0, varint_1.createVarint)(leaf_index)]);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
}(ClientCommand));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
231
165
|
exports.GetMerkleLeafIndexCommand = GetMerkleLeafIndexCommand;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
_this.queue = queue;
|
|
238
|
-
return _this;
|
|
166
|
+
class GetMoreElementsCommand extends ClientCommand {
|
|
167
|
+
constructor(queue) {
|
|
168
|
+
super();
|
|
169
|
+
this.code = ClientCommandCode.GET_MORE_ELEMENTS;
|
|
170
|
+
this.queue = queue;
|
|
239
171
|
}
|
|
240
|
-
|
|
172
|
+
execute(request) {
|
|
241
173
|
if (request.length != 1) {
|
|
242
174
|
throw new Error("Invalid request, unexpected trailing data");
|
|
243
175
|
}
|
|
@@ -245,20 +177,20 @@ var GetMoreElementsCommand = /** @class */ (function (_super) {
|
|
|
245
177
|
throw new Error("No elements to get");
|
|
246
178
|
}
|
|
247
179
|
// all elements should have the same length
|
|
248
|
-
|
|
249
|
-
if (this.queue.some(
|
|
180
|
+
const element_len = this.queue[0].length;
|
|
181
|
+
if (this.queue.some((el) => el.length != element_len)) {
|
|
250
182
|
throw new Error("The queue contains elements with different byte length, which is not expected");
|
|
251
183
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return Buffer.concat(
|
|
184
|
+
const max_elements = Math.floor(253 / element_len);
|
|
185
|
+
const n_returned_elements = Math.min(max_elements, this.queue.length);
|
|
186
|
+
const returned_elements = this.queue.splice(0, n_returned_elements);
|
|
187
|
+
return Buffer.concat([
|
|
256
188
|
Buffer.from([n_returned_elements]),
|
|
257
|
-
Buffer.from([element_len])
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
189
|
+
Buffer.from([element_len]),
|
|
190
|
+
...returned_elements,
|
|
191
|
+
]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
262
194
|
exports.GetMoreElementsCommand = GetMoreElementsCommand;
|
|
263
195
|
/**
|
|
264
196
|
* This class will dispatch a client command coming from the hardware device to
|
|
@@ -275,79 +207,56 @@ exports.GetMoreElementsCommand = GetMoreElementsCommand;
|
|
|
275
207
|
* data will be accessible after the command completed by calling getYielded(),
|
|
276
208
|
* which will return the yields in the same order as they came in.
|
|
277
209
|
*/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
var e_1, _a;
|
|
210
|
+
class ClientCommandInterpreter {
|
|
211
|
+
constructor(progressCallback) {
|
|
281
212
|
this.roots = new Map();
|
|
282
213
|
this.preimages = new Map();
|
|
283
214
|
this.yielded = [];
|
|
284
215
|
this.queue = [];
|
|
285
216
|
this.commands = new Map();
|
|
286
|
-
|
|
217
|
+
const commands = [
|
|
287
218
|
new YieldCommand(this.yielded, progressCallback),
|
|
288
219
|
new GetPreimageCommand(this.preimages, this.queue),
|
|
289
220
|
new GetMerkleLeafIndexCommand(this.roots),
|
|
290
221
|
new GetMerkleLeafProofCommand(this.roots, this.queue),
|
|
291
222
|
new GetMoreElementsCommand(this.queue),
|
|
292
223
|
];
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (this.commands.has(cmd.code)) {
|
|
297
|
-
throw new Error("Multiple commands with code ".concat(cmd.code));
|
|
298
|
-
}
|
|
299
|
-
this.commands.set(cmd.code, cmd);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
303
|
-
finally {
|
|
304
|
-
try {
|
|
305
|
-
if (commands_1_1 && !commands_1_1.done && (_a = commands_1["return"])) _a.call(commands_1);
|
|
224
|
+
for (const cmd of commands) {
|
|
225
|
+
if (this.commands.has(cmd.code)) {
|
|
226
|
+
throw new Error(`Multiple commands with code ${cmd.code}`);
|
|
306
227
|
}
|
|
307
|
-
|
|
228
|
+
this.commands.set(cmd.code, cmd);
|
|
308
229
|
}
|
|
309
230
|
}
|
|
310
|
-
|
|
231
|
+
getYielded() {
|
|
311
232
|
return this.yielded;
|
|
312
|
-
}
|
|
313
|
-
|
|
233
|
+
}
|
|
234
|
+
addKnownPreimage(preimage) {
|
|
314
235
|
this.preimages.set(bitcoinjs_lib_1.crypto.sha256(preimage).toString("hex"), preimage);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
var el = elements_1_1.value;
|
|
321
|
-
var preimage = Buffer.concat([Buffer.from([0]), el]);
|
|
322
|
-
this.addKnownPreimage(preimage);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
326
|
-
finally {
|
|
327
|
-
try {
|
|
328
|
-
if (elements_1_1 && !elements_1_1.done && (_a = elements_1["return"])) _a.call(elements_1);
|
|
329
|
-
}
|
|
330
|
-
finally { if (e_2) throw e_2.error; }
|
|
236
|
+
}
|
|
237
|
+
addKnownList(elements) {
|
|
238
|
+
for (const el of elements) {
|
|
239
|
+
const preimage = Buffer.concat([Buffer.from([0]), el]);
|
|
240
|
+
this.addKnownPreimage(preimage);
|
|
331
241
|
}
|
|
332
|
-
|
|
242
|
+
const mt = new merkle_1.Merkle(elements.map((el) => (0, merkle_1.hashLeaf)(el)));
|
|
333
243
|
this.roots.set(mt.getRoot().toString("hex"), mt);
|
|
334
|
-
}
|
|
335
|
-
|
|
244
|
+
}
|
|
245
|
+
addKnownMapping(mm) {
|
|
336
246
|
this.addKnownList(mm.keys);
|
|
337
247
|
this.addKnownList(mm.values);
|
|
338
|
-
}
|
|
339
|
-
|
|
248
|
+
}
|
|
249
|
+
execute(request) {
|
|
340
250
|
if (request.length == 0) {
|
|
341
251
|
throw new Error("Unexpected empty command");
|
|
342
252
|
}
|
|
343
|
-
|
|
344
|
-
|
|
253
|
+
const cmdCode = request[0];
|
|
254
|
+
const cmd = this.commands.get(cmdCode);
|
|
345
255
|
if (!cmd) {
|
|
346
|
-
throw new Error(
|
|
256
|
+
throw new Error(`Unexpected command code ${cmdCode}`);
|
|
347
257
|
}
|
|
348
258
|
return cmd.execute(request);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
}());
|
|
259
|
+
}
|
|
260
|
+
}
|
|
352
261
|
exports.ClientCommandInterpreter = ClientCommandInterpreter;
|
|
353
262
|
//# sourceMappingURL=clientCommands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientCommands.js","sourceRoot":"","sources":["../../src/newops/clientCommands.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clientCommands.js","sourceRoot":"","sources":["../../src/newops/clientCommands.ts"],"names":[],"mappings":";;;AAAA,iDAAuC;AACvC,gDAA8C;AAC9C,sCAAyC;AACzC,qCAA4C;AAG5C,IAAK,iBAMJ;AAND,WAAK,iBAAiB;IACpB,4DAAY,CAAA;IACZ,0EAAmB,CAAA;IACnB,4FAA4B,CAAA;IAC5B,4FAA4B,CAAA;IAC5B,qFAAwB,CAAA;AAC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@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
3
|
exports.MerkelizedPsbt = void 0;
|
|
44
|
-
|
|
45
|
-
|
|
4
|
+
const merkleMap_1 = require("./merkleMap");
|
|
5
|
+
const psbtv2_1 = require("./psbtv2");
|
|
46
6
|
/**
|
|
47
7
|
* This class merkelizes a PSBTv2, by merkelizing the different
|
|
48
8
|
* maps of the psbt. This is used during the transaction signing process,
|
|
@@ -54,49 +14,42 @@ var psbtv2_1 = require("./psbtv2");
|
|
|
54
14
|
* The signing process is documented at
|
|
55
15
|
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#sign_psbt
|
|
56
16
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_this.inputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(_this.inputMaps[i]));
|
|
17
|
+
class MerkelizedPsbt extends psbtv2_1.PsbtV2 {
|
|
18
|
+
constructor(psbt) {
|
|
19
|
+
super();
|
|
20
|
+
this.inputMerkleMaps = [];
|
|
21
|
+
this.outputMerkleMaps = [];
|
|
22
|
+
psbt.copy(this);
|
|
23
|
+
this.globalMerkleMap = MerkelizedPsbt.createMerkleMap(this.globalMap);
|
|
24
|
+
for (let i = 0; i < this.getGlobalInputCount(); i++) {
|
|
25
|
+
this.inputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(this.inputMaps[i]));
|
|
67
26
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for (var i = 0; i < _this.getGlobalOutputCount(); i++) {
|
|
72
|
-
_this.outputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(_this.outputMaps[i]));
|
|
27
|
+
this.inputMapCommitments = [...this.inputMerkleMaps.values()].map((v) => v.commitment());
|
|
28
|
+
for (let i = 0; i < this.getGlobalOutputCount(); i++) {
|
|
29
|
+
this.outputMerkleMaps.push(MerkelizedPsbt.createMerkleMap(this.outputMaps[i]));
|
|
73
30
|
}
|
|
74
|
-
|
|
75
|
-
return v.commitment();
|
|
76
|
-
});
|
|
77
|
-
return _this;
|
|
31
|
+
this.outputMapCommitments = [...this.outputMerkleMaps.values()].map((v) => v.commitment());
|
|
78
32
|
}
|
|
79
33
|
// These public functions are for MerkelizedPsbt.
|
|
80
|
-
|
|
34
|
+
getGlobalSize() {
|
|
81
35
|
return this.globalMap.size;
|
|
82
|
-
}
|
|
83
|
-
|
|
36
|
+
}
|
|
37
|
+
getGlobalKeysValuesRoot() {
|
|
84
38
|
return this.globalMerkleMap.commitment();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
39
|
+
}
|
|
40
|
+
static createMerkleMap(map) {
|
|
41
|
+
const sortedKeysStrings = [...map.keys()].sort();
|
|
42
|
+
const values = sortedKeysStrings.map((k) => {
|
|
43
|
+
const v = map.get(k);
|
|
90
44
|
if (!v) {
|
|
91
45
|
throw new Error("No value for key " + k);
|
|
92
46
|
}
|
|
93
47
|
return v;
|
|
94
48
|
});
|
|
95
|
-
|
|
96
|
-
|
|
49
|
+
const sortedKeys = sortedKeysStrings.map((k) => Buffer.from(k, "hex"));
|
|
50
|
+
const merkleMap = new merkleMap_1.MerkleMap(sortedKeys, values);
|
|
97
51
|
return merkleMap;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}(psbtv2_1.PsbtV2));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
101
54
|
exports.MerkelizedPsbt = MerkelizedPsbt;
|
|
102
55
|
//# sourceMappingURL=merkelizedPsbt.js.map
|