@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
package/lib/newops/appClient.js
CHANGED
|
@@ -8,53 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __values = (this && this.__values) || function(o) {
|
|
39
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
-
if (m) return m.call(o);
|
|
41
|
-
if (o && typeof o.length === "number") return {
|
|
42
|
-
next: function () {
|
|
43
|
-
if (o && i >= o.length) o = void 0;
|
|
44
|
-
return { value: o && o[i++], done: !o };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
-
};
|
|
49
|
-
exports.__esModule = true;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
12
|
exports.AppClient = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
13
|
+
const bip32_1 = require("../bip32");
|
|
14
|
+
const merkelizedPsbt_1 = require("./merkelizedPsbt");
|
|
15
|
+
const clientCommands_1 = require("./clientCommands");
|
|
16
|
+
const varint_1 = require("../varint");
|
|
17
|
+
const merkle_1 = require("./merkle");
|
|
18
|
+
const CLA_BTC = 0xe1;
|
|
19
|
+
const CLA_FRAMEWORK = 0xf8;
|
|
58
20
|
var BitcoinIns;
|
|
59
21
|
(function (BitcoinIns) {
|
|
60
22
|
BitcoinIns[BitcoinIns["GET_PUBKEY"] = 0] = "GET_PUBKEY";
|
|
@@ -72,172 +34,103 @@ var FrameworkIns;
|
|
|
72
34
|
* This class encapsulates the APDU protocol documented at
|
|
73
35
|
* https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
|
|
74
36
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
37
|
+
class AppClient {
|
|
38
|
+
constructor(transport) {
|
|
77
39
|
this.transport = transport;
|
|
78
40
|
}
|
|
79
|
-
|
|
80
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
case 1:
|
|
86
|
-
response = _a.sent();
|
|
87
|
-
_a.label = 2;
|
|
88
|
-
case 2:
|
|
89
|
-
if (!(response.readUInt16BE(response.length - 2) === 0xe000)) return [3 /*break*/, 4];
|
|
90
|
-
if (!cci) {
|
|
91
|
-
throw new Error("Unexpected SW_INTERRUPTED_EXECUTION");
|
|
92
|
-
}
|
|
93
|
-
hwRequest = response.slice(0, -2);
|
|
94
|
-
commandResponse = cci.execute(hwRequest);
|
|
95
|
-
return [4 /*yield*/, this.transport.send(CLA_FRAMEWORK, FrameworkIns.CONTINUE_INTERRUPTED, 0, 0, commandResponse, [0x9000, 0xe000])];
|
|
96
|
-
case 3:
|
|
97
|
-
response = _a.sent();
|
|
98
|
-
return [3 /*break*/, 2];
|
|
99
|
-
case 4: return [2 /*return*/, response.slice(0, -2)]; // drop the status word (can only be 0x9000 at this point)
|
|
41
|
+
makeRequest(ins, data, cci) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
let response = yield this.transport.send(CLA_BTC, ins, 0, 0, data, [0x9000, 0xe000]);
|
|
44
|
+
while (response.readUInt16BE(response.length - 2) === 0xe000) {
|
|
45
|
+
if (!cci) {
|
|
46
|
+
throw new Error("Unexpected SW_INTERRUPTED_EXECUTION");
|
|
100
47
|
}
|
|
101
|
-
|
|
48
|
+
const hwRequest = response.slice(0, -2);
|
|
49
|
+
const commandResponse = cci.execute(hwRequest);
|
|
50
|
+
response = yield this.transport.send(CLA_FRAMEWORK, FrameworkIns.CONTINUE_INTERRUPTED, 0, 0, commandResponse, [0x9000, 0xe000]);
|
|
51
|
+
}
|
|
52
|
+
return response.slice(0, -2); // drop the status word (can only be 0x9000 at this point)
|
|
102
53
|
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Buffer.from(display ? [1] : [0]),
|
|
115
|
-
(0, bip32_1.pathElementsToBuffer)(pathElements),
|
|
116
|
-
]))];
|
|
117
|
-
case 1:
|
|
118
|
-
response = _a.sent();
|
|
119
|
-
return [2 /*return*/, response.toString("ascii")];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
54
|
+
}
|
|
55
|
+
getExtendedPubkey(display, pathElements) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (pathElements.length > 6) {
|
|
58
|
+
throw new Error("Path too long. At most 6 levels allowed.");
|
|
59
|
+
}
|
|
60
|
+
const response = yield this.makeRequest(BitcoinIns.GET_PUBKEY, Buffer.concat([
|
|
61
|
+
Buffer.from(display ? [1] : [0]),
|
|
62
|
+
(0, bip32_1.pathElementsToBuffer)(pathElements),
|
|
63
|
+
]));
|
|
64
|
+
return response.toString("ascii");
|
|
122
65
|
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
Buffer.from([change]),
|
|
147
|
-
addressIndexBuffer,
|
|
148
|
-
]), clientInterpreter)];
|
|
149
|
-
case 1:
|
|
150
|
-
response = _a.sent();
|
|
151
|
-
return [2 /*return*/, response.toString("ascii")];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
66
|
+
}
|
|
67
|
+
getWalletAddress(walletPolicy, walletHMAC, change, addressIndex, display) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (change !== 0 && change !== 1)
|
|
70
|
+
throw new Error("Change can only be 0 or 1");
|
|
71
|
+
if (addressIndex < 0 || !Number.isInteger(addressIndex))
|
|
72
|
+
throw new Error("Invalid address index");
|
|
73
|
+
if (walletHMAC != null && walletHMAC.length != 32) {
|
|
74
|
+
throw new Error("Invalid HMAC length");
|
|
75
|
+
}
|
|
76
|
+
const clientInterpreter = new clientCommands_1.ClientCommandInterpreter(() => { });
|
|
77
|
+
clientInterpreter.addKnownList(walletPolicy.keys.map((k) => Buffer.from(k, "ascii")));
|
|
78
|
+
clientInterpreter.addKnownPreimage(walletPolicy.serialize());
|
|
79
|
+
const addressIndexBuffer = Buffer.alloc(4);
|
|
80
|
+
addressIndexBuffer.writeUInt32BE(addressIndex, 0);
|
|
81
|
+
const response = yield this.makeRequest(BitcoinIns.GET_WALLET_ADDRESS, Buffer.concat([
|
|
82
|
+
Buffer.from(display ? [1] : [0]),
|
|
83
|
+
walletPolicy.getWalletId(),
|
|
84
|
+
walletHMAC || Buffer.alloc(32, 0),
|
|
85
|
+
Buffer.from([change]),
|
|
86
|
+
addressIndexBuffer,
|
|
87
|
+
]), clientInterpreter);
|
|
88
|
+
return response.toString("ascii");
|
|
154
89
|
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
finally {
|
|
193
|
-
try {
|
|
194
|
-
if (_d && !_d.done && (_f = _c["return"])) _f.call(_c);
|
|
195
|
-
}
|
|
196
|
-
finally { if (e_2) throw e_2.error; }
|
|
197
|
-
}
|
|
198
|
-
clientInterpreter.addKnownList(merkelizedPsbt.inputMapCommitments);
|
|
199
|
-
inputMapsRoot = new merkle_1.Merkle(merkelizedPsbt.inputMapCommitments.map(function (m) { return (0, merkle_1.hashLeaf)(m); })).getRoot();
|
|
200
|
-
clientInterpreter.addKnownList(merkelizedPsbt.outputMapCommitments);
|
|
201
|
-
outputMapsRoot = new merkle_1.Merkle(merkelizedPsbt.outputMapCommitments.map(function (m) { return (0, merkle_1.hashLeaf)(m); })).getRoot();
|
|
202
|
-
return [4 /*yield*/, this.makeRequest(BitcoinIns.SIGN_PSBT, Buffer.concat([
|
|
203
|
-
merkelizedPsbt.getGlobalKeysValuesRoot(),
|
|
204
|
-
(0, varint_1.createVarint)(merkelizedPsbt.getGlobalInputCount()),
|
|
205
|
-
inputMapsRoot,
|
|
206
|
-
(0, varint_1.createVarint)(merkelizedPsbt.getGlobalOutputCount()),
|
|
207
|
-
outputMapsRoot,
|
|
208
|
-
walletPolicy.getWalletId(),
|
|
209
|
-
walletHMAC || Buffer.alloc(32, 0),
|
|
210
|
-
]), clientInterpreter)];
|
|
211
|
-
case 1:
|
|
212
|
-
_h.sent();
|
|
213
|
-
yielded = clientInterpreter.getYielded();
|
|
214
|
-
ret = new Map();
|
|
215
|
-
try {
|
|
216
|
-
for (yielded_1 = __values(yielded), yielded_1_1 = yielded_1.next(); !yielded_1_1.done; yielded_1_1 = yielded_1.next()) {
|
|
217
|
-
inputAndSig = yielded_1_1.value;
|
|
218
|
-
ret.set(inputAndSig[0], inputAndSig.slice(1));
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
222
|
-
finally {
|
|
223
|
-
try {
|
|
224
|
-
if (yielded_1_1 && !yielded_1_1.done && (_g = yielded_1["return"])) _g.call(yielded_1);
|
|
225
|
-
}
|
|
226
|
-
finally { if (e_3) throw e_3.error; }
|
|
227
|
-
}
|
|
228
|
-
return [2 /*return*/, ret];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
90
|
+
}
|
|
91
|
+
signPsbt(psbt, walletPolicy, walletHMAC, progressCallback) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const merkelizedPsbt = new merkelizedPsbt_1.MerkelizedPsbt(psbt);
|
|
94
|
+
if (walletHMAC != null && walletHMAC.length != 32) {
|
|
95
|
+
throw new Error("Invalid HMAC length");
|
|
96
|
+
}
|
|
97
|
+
const clientInterpreter = new clientCommands_1.ClientCommandInterpreter(progressCallback);
|
|
98
|
+
// prepare ClientCommandInterpreter
|
|
99
|
+
clientInterpreter.addKnownList(walletPolicy.keys.map((k) => Buffer.from(k, "ascii")));
|
|
100
|
+
clientInterpreter.addKnownPreimage(walletPolicy.serialize());
|
|
101
|
+
clientInterpreter.addKnownMapping(merkelizedPsbt.globalMerkleMap);
|
|
102
|
+
for (const map of merkelizedPsbt.inputMerkleMaps) {
|
|
103
|
+
clientInterpreter.addKnownMapping(map);
|
|
104
|
+
}
|
|
105
|
+
for (const map of merkelizedPsbt.outputMerkleMaps) {
|
|
106
|
+
clientInterpreter.addKnownMapping(map);
|
|
107
|
+
}
|
|
108
|
+
clientInterpreter.addKnownList(merkelizedPsbt.inputMapCommitments);
|
|
109
|
+
const inputMapsRoot = new merkle_1.Merkle(merkelizedPsbt.inputMapCommitments.map((m) => (0, merkle_1.hashLeaf)(m))).getRoot();
|
|
110
|
+
clientInterpreter.addKnownList(merkelizedPsbt.outputMapCommitments);
|
|
111
|
+
const outputMapsRoot = new merkle_1.Merkle(merkelizedPsbt.outputMapCommitments.map((m) => (0, merkle_1.hashLeaf)(m))).getRoot();
|
|
112
|
+
yield this.makeRequest(BitcoinIns.SIGN_PSBT, Buffer.concat([
|
|
113
|
+
merkelizedPsbt.getGlobalKeysValuesRoot(),
|
|
114
|
+
(0, varint_1.createVarint)(merkelizedPsbt.getGlobalInputCount()),
|
|
115
|
+
inputMapsRoot,
|
|
116
|
+
(0, varint_1.createVarint)(merkelizedPsbt.getGlobalOutputCount()),
|
|
117
|
+
outputMapsRoot,
|
|
118
|
+
walletPolicy.getWalletId(),
|
|
119
|
+
walletHMAC || Buffer.alloc(32, 0),
|
|
120
|
+
]), clientInterpreter);
|
|
121
|
+
const yielded = clientInterpreter.getYielded();
|
|
122
|
+
const ret = new Map();
|
|
123
|
+
for (const inputAndSig of yielded) {
|
|
124
|
+
ret.set(inputAndSig[0], inputAndSig.slice(1));
|
|
125
|
+
}
|
|
126
|
+
return ret;
|
|
231
127
|
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
235
|
-
return
|
|
236
|
-
return [2 /*return*/, this.makeRequest(BitcoinIns.GET_MASTER_FINGERPRINT, Buffer.from([]))];
|
|
237
|
-
});
|
|
128
|
+
}
|
|
129
|
+
getMasterFingerprint() {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
return this.makeRequest(BitcoinIns.GET_MASTER_FINGERPRINT, Buffer.from([]));
|
|
238
132
|
});
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
}());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
242
135
|
exports.AppClient = AppClient;
|
|
243
136
|
//# sourceMappingURL=appClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appClient.js","sourceRoot":"","sources":["../../src/newops/appClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"appClient.js","sourceRoot":"","sources":["../../src/newops/appClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAgD;AAEhD,qDAAkD;AAClD,qDAA4D;AAE5D,sCAAyC;AACzC,qCAA4C;AAE5C,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,IAAK,UAOJ;AAPD,WAAK,UAAU;IACb,uDAAiB,CAAA;IACjB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