@ledgerhq/hw-app-btc 6.7.0 → 6.9.1-6.9.1-taproot.0.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/lib/Btc.d.ts +7 -3
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +95 -26
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +70 -0
- package/lib/BtcNew.d.ts.map +1 -0
- package/lib/BtcNew.js +372 -0
- package/lib/BtcNew.js.map +1 -0
- package/lib/BtcOld.d.ts +114 -0
- package/lib/BtcOld.d.ts.map +1 -0
- package/lib/BtcOld.js +138 -0
- package/lib/BtcOld.js.map +1 -0
- package/lib/bip32.d.ts +8 -0
- package/lib/bip32.d.ts.map +1 -1
- package/lib/bip32.js +32 -3
- package/lib/bip32.js.map +1 -1
- package/lib/buffertools.d.ts +28 -0
- package/lib/buffertools.d.ts.map +1 -0
- package/lib/buffertools.js +100 -0
- package/lib/buffertools.js.map +1 -0
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/getWalletPublicKey.d.ts +1 -1
- package/lib/getWalletPublicKey.d.ts.map +1 -1
- package/lib/getWalletPublicKey.js.map +1 -1
- package/lib/hashPublicKey.d.ts +1 -1
- package/lib/hashPublicKey.d.ts.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/newops/appClient.d.ts +14 -0
- package/lib/newops/appClient.d.ts.map +1 -0
- package/lib/newops/appClient.js +242 -0
- package/lib/newops/appClient.js.map +1 -0
- package/lib/newops/clientCommands.d.ts +61 -0
- package/lib/newops/clientCommands.d.ts.map +1 -0
- package/lib/newops/clientCommands.js +331 -0
- package/lib/newops/clientCommands.js.map +1 -0
- package/lib/newops/merkelizedPsbt.d.ts +15 -0
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -0
- package/lib/newops/merkelizedPsbt.js +91 -0
- package/lib/newops/merkelizedPsbt.js.map +1 -0
- package/lib/newops/merkle.d.ts +29 -0
- package/lib/newops/merkle.d.ts.map +1 -0
- package/lib/newops/merkle.js +133 -0
- package/lib/newops/merkle.js.map +1 -0
- package/lib/newops/merkleMap.d.ts +15 -0
- package/lib/newops/merkleMap.d.ts.map +1 -0
- package/lib/newops/merkleMap.js +37 -0
- package/lib/newops/merkleMap.js.map +1 -0
- package/lib/newops/policy.d.ts +14 -0
- package/lib/newops/policy.d.ts.map +1 -0
- package/lib/newops/policy.js +40 -0
- package/lib/newops/policy.js.map +1 -0
- package/lib/newops/psbtExtractor.d.ts +4 -0
- package/lib/newops/psbtExtractor.d.ts.map +1 -0
- package/lib/newops/psbtExtractor.js +36 -0
- package/lib/newops/psbtExtractor.js.map +1 -0
- package/lib/newops/psbtFinalizer.d.ts +7 -0
- package/lib/newops/psbtFinalizer.d.ts.map +1 -0
- package/lib/newops/psbtFinalizer.js +111 -0
- package/lib/newops/psbtFinalizer.js.map +1 -0
- package/lib/newops/psbtv2.d.ts +129 -0
- package/lib/newops/psbtv2.d.ts.map +1 -0
- package/lib/newops/psbtv2.js +478 -0
- package/lib/newops/psbtv2.js.map +1 -0
- package/lib/varint.d.ts.map +1 -1
- package/lib/varint.js +1 -0
- package/lib/varint.js.map +1 -1
- package/lib-es/Btc.d.ts +7 -3
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +92 -26
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +70 -0
- package/lib-es/BtcNew.d.ts.map +1 -0
- package/lib-es/BtcNew.js +370 -0
- package/lib-es/BtcNew.js.map +1 -0
- package/lib-es/BtcOld.d.ts +114 -0
- package/lib-es/BtcOld.d.ts.map +1 -0
- package/lib-es/BtcOld.js +136 -0
- package/lib-es/BtcOld.js.map +1 -0
- package/lib-es/bip32.d.ts +8 -0
- package/lib-es/bip32.d.ts.map +1 -1
- package/lib-es/bip32.js +26 -2
- package/lib-es/bip32.js.map +1 -1
- package/lib-es/buffertools.d.ts +28 -0
- package/lib-es/buffertools.d.ts.map +1 -0
- package/lib-es/buffertools.js +94 -0
- package/lib-es/buffertools.js.map +1 -0
- package/lib-es/createTransaction.d.ts.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.map +1 -1
- package/lib-es/hashPublicKey.d.ts +1 -1
- package/lib-es/hashPublicKey.d.ts.map +1 -1
- package/lib-es/index.d.ts +3 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/newops/appClient.d.ts +14 -0
- package/lib-es/newops/appClient.d.ts.map +1 -0
- package/lib-es/newops/appClient.js +239 -0
- package/lib-es/newops/appClient.js.map +1 -0
- package/lib-es/newops/clientCommands.d.ts +61 -0
- package/lib-es/newops/clientCommands.d.ts.map +1 -0
- package/lib-es/newops/clientCommands.js +328 -0
- package/lib-es/newops/clientCommands.js.map +1 -0
- package/lib-es/newops/merkelizedPsbt.d.ts +15 -0
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -0
- package/lib-es/newops/merkelizedPsbt.js +88 -0
- package/lib-es/newops/merkelizedPsbt.js.map +1 -0
- package/lib-es/newops/merkle.d.ts +29 -0
- package/lib-es/newops/merkle.d.ts.map +1 -0
- package/lib-es/newops/merkle.js +129 -0
- package/lib-es/newops/merkle.js.map +1 -0
- package/lib-es/newops/merkleMap.d.ts +15 -0
- package/lib-es/newops/merkleMap.d.ts.map +1 -0
- package/lib-es/newops/merkleMap.js +34 -0
- package/lib-es/newops/merkleMap.js.map +1 -0
- package/lib-es/newops/policy.d.ts +14 -0
- package/lib-es/newops/policy.d.ts.map +1 -0
- package/lib-es/newops/policy.js +36 -0
- package/lib-es/newops/policy.js.map +1 -0
- package/lib-es/newops/psbtExtractor.d.ts +4 -0
- package/lib-es/newops/psbtExtractor.d.ts.map +1 -0
- package/lib-es/newops/psbtExtractor.js +32 -0
- package/lib-es/newops/psbtExtractor.js.map +1 -0
- package/lib-es/newops/psbtFinalizer.d.ts +7 -0
- package/lib-es/newops/psbtFinalizer.d.ts.map +1 -0
- package/lib-es/newops/psbtFinalizer.js +107 -0
- package/lib-es/newops/psbtFinalizer.js.map +1 -0
- package/lib-es/newops/psbtv2.d.ts +129 -0
- package/lib-es/newops/psbtv2.d.ts.map +1 -0
- package/lib-es/newops/psbtv2.js +475 -0
- package/lib-es/newops/psbtv2.js.map +1 -0
- package/lib-es/varint.d.ts.map +1 -1
- package/lib-es/varint.js +1 -0
- package/lib-es/varint.js.map +1 -1
- package/package.json +6 -3
- package/src/Btc.ts +42 -25
- package/src/BtcNew.ts +326 -0
- package/src/BtcOld.ts +156 -0
- package/src/bip32.ts +34 -2
- package/src/buffertools.ts +102 -0
- package/src/createTransaction.ts +1 -1
- package/src/getWalletPublicKey.ts +6 -1
- package/src/hashPublicKey.ts +1 -1
- package/src/index.ts +2 -0
- package/src/newops/appClient.ts +178 -0
- package/src/newops/clientCommands.ts +312 -0
- package/src/newops/merkelizedPsbt.ts +55 -0
- package/src/newops/merkle.ts +123 -0
- package/src/newops/merkleMap.ts +39 -0
- package/src/newops/policy.ts +52 -0
- package/src/newops/psbtExtractor.ts +33 -0
- package/src/newops/psbtFinalizer.ts +110 -0
- package/src/newops/psbtv2.ts +548 -0
- package/src/varint.ts +2 -0
- package/tests/Btc.integration.test.ts +89 -0
- package/tests/Btc.test.ts +6 -0
- package/tests/newops/BtcNew.test.ts +646 -0
- package/tests/newops/common.ts +25 -0
- package/tests/newops/merkle.test.ts +97 -0
- package/tests/trustedInputs.test.ts +4 -0
package/lib/BtcNew.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
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
|
+
exports.__esModule = true;
|
|
39
|
+
var bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
40
|
+
var bip32_1 = require("./bip32");
|
|
41
|
+
var buffertools_1 = require("./buffertools");
|
|
42
|
+
var hashPublicKey_1 = require("./hashPublicKey");
|
|
43
|
+
var policy_1 = require("./newops/policy");
|
|
44
|
+
var psbtExtractor_1 = require("./newops/psbtExtractor");
|
|
45
|
+
var psbtFinalizer_1 = require("./newops/psbtFinalizer");
|
|
46
|
+
var psbtv2_1 = require("./newops/psbtv2");
|
|
47
|
+
var serializeTransaction_1 = require("./serializeTransaction");
|
|
48
|
+
var tiny_secp256k1_1 = require("tiny-secp256k1");
|
|
49
|
+
var BtcNew = /** @class */ (function () {
|
|
50
|
+
function BtcNew(client) {
|
|
51
|
+
this.client = client;
|
|
52
|
+
}
|
|
53
|
+
BtcNew.prototype.getWalletPublicKey = function (path, opts) {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var pathElements, xpub, display, address, components, uncompressedPubkey;
|
|
57
|
+
return __generator(this, function (_c) {
|
|
58
|
+
switch (_c.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
pathElements = (0, bip32_1.pathStringToArray)(path);
|
|
61
|
+
return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
|
|
62
|
+
case 1:
|
|
63
|
+
xpub = _c.sent();
|
|
64
|
+
display = (_a = opts === null || opts === void 0 ? void 0 : opts.verify) !== null && _a !== void 0 ? _a : false;
|
|
65
|
+
return [4 /*yield*/, this.getWalletAddress(pathElements, accountTypeFrom((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : "legacy"), display)];
|
|
66
|
+
case 2:
|
|
67
|
+
address = _c.sent();
|
|
68
|
+
components = (0, bip32_1.getXpubComponents)(xpub);
|
|
69
|
+
uncompressedPubkey = Buffer.from((0, tiny_secp256k1_1.pointCompress)(components.pubkey, false));
|
|
70
|
+
return [2 /*return*/, {
|
|
71
|
+
publicKey: uncompressedPubkey.toString("hex"),
|
|
72
|
+
bitcoinAddress: address,
|
|
73
|
+
chainCode: components.chaincode.toString("hex")
|
|
74
|
+
}];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Get an address for the specified path.
|
|
81
|
+
*
|
|
82
|
+
* If display is true, we must get the address from the device, which would require
|
|
83
|
+
* us to determine WalletPolicy. This requires two *extra* queries to the device, one
|
|
84
|
+
* for the account xpub and one for master key fingerprint.
|
|
85
|
+
*
|
|
86
|
+
* If display is false we *could* generate the address ourselves, but chose to
|
|
87
|
+
* get it from the device to save development time. However, it shouldn't take
|
|
88
|
+
* more than a few hours to implement local address generation.
|
|
89
|
+
*
|
|
90
|
+
* Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
|
|
91
|
+
* way to get the address from the device. In this case we have to create it
|
|
92
|
+
* ourselves, but we don't at this time, and instead return an empty ("") address.
|
|
93
|
+
*/
|
|
94
|
+
BtcNew.prototype.getWalletAddress = function (pathElements, accountType, display) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
var accountPathLength, accountPath, accountXpub, masterFingerprint, policy, changeAndIndex;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0:
|
|
100
|
+
accountPathLength = this.accountPathLength(pathElements);
|
|
101
|
+
if (accountPathLength + 2 != pathElements.length) {
|
|
102
|
+
return [2 /*return*/, ""];
|
|
103
|
+
}
|
|
104
|
+
accountPath = pathElements.slice(0, accountPathLength);
|
|
105
|
+
return [4 /*yield*/, this.client.getPubkey(false, accountPath)];
|
|
106
|
+
case 1:
|
|
107
|
+
accountXpub = _a.sent();
|
|
108
|
+
return [4 /*yield*/, this.client.getMasterFingerprint()];
|
|
109
|
+
case 2:
|
|
110
|
+
masterFingerprint = _a.sent();
|
|
111
|
+
policy = new policy_1.WalletPolicy(accountType, (0, policy_1.createKey)(masterFingerprint, accountPath, accountXpub));
|
|
112
|
+
changeAndIndex = pathElements.slice(-2, pathElements.length);
|
|
113
|
+
return [2 /*return*/, this.client.getWalletAddress(policy, Buffer.alloc(32, 0), changeAndIndex[0], changeAndIndex[1], display)];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
BtcNew.prototype.accountPathLength = function (pathElements) {
|
|
119
|
+
for (var i = pathElements.length - 1; i >= 0; i--) {
|
|
120
|
+
if (pathElements[i] >= 0x80000000) {
|
|
121
|
+
return i + 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return 0;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
128
|
+
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
129
|
+
*
|
|
130
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
131
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
132
|
+
* * redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
133
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
134
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
135
|
+
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
136
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
|
|
137
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
138
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
139
|
+
* @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
|
|
140
|
+
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
141
|
+
* @param additionals list of additionnal options
|
|
142
|
+
*
|
|
143
|
+
* - "bech32" for spending native segwit outputs
|
|
144
|
+
* - "bech32m" for spending segwit v1+ outptus
|
|
145
|
+
* - "abc" for bch
|
|
146
|
+
* - "gold" for btg
|
|
147
|
+
* - "bipxxx" for using BIPxxx
|
|
148
|
+
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
149
|
+
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
150
|
+
* @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
|
|
151
|
+
* @return the signed transaction ready to be broadcast
|
|
152
|
+
* @example
|
|
153
|
+
btc.createTransaction({
|
|
154
|
+
inputs: [ [tx1, 1] ],
|
|
155
|
+
associatedKeysets: ["0'/0/0"],
|
|
156
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
157
|
+
}).then(res => ...);
|
|
158
|
+
*/
|
|
159
|
+
BtcNew.prototype.createPaymentTransactionNew = function (arg) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
+
var psbt, accountType, masterFp, accountXpub, accountPath, i, pathElems, outputsConcat, outputsBufferReader, outputCount, i, amount, outputScript, isChange, changePath, xpubBase58, pubkey, redeemScript, key, p;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
if (arg.inputs.length == 0) {
|
|
166
|
+
throw Error("No inputs");
|
|
167
|
+
}
|
|
168
|
+
psbt = new psbtv2_1.PsbtV2();
|
|
169
|
+
accountType = accountTypeFromArg(arg);
|
|
170
|
+
psbt.setGlobalTxVersion(2);
|
|
171
|
+
if (arg.lockTime) {
|
|
172
|
+
psbt.setGlobalFallbackLocktime(arg.lockTime);
|
|
173
|
+
}
|
|
174
|
+
psbt.setGlobalInputCount(arg.inputs.length);
|
|
175
|
+
psbt.setGlobalPsbtVersion(2);
|
|
176
|
+
psbt.setGlobalTxVersion(2);
|
|
177
|
+
return [4 /*yield*/, this.client.getMasterFingerprint()];
|
|
178
|
+
case 1:
|
|
179
|
+
masterFp = _a.sent();
|
|
180
|
+
accountXpub = "";
|
|
181
|
+
accountPath = [];
|
|
182
|
+
i = 0;
|
|
183
|
+
_a.label = 2;
|
|
184
|
+
case 2:
|
|
185
|
+
if (!(i < arg.inputs.length)) return [3 /*break*/, 7];
|
|
186
|
+
pathElems = (0, bip32_1.pathStringToArray)(arg.associatedKeysets[i]);
|
|
187
|
+
if (!(accountXpub == "")) return [3 /*break*/, 4];
|
|
188
|
+
// We assume all inputs belong to the same account so we set
|
|
189
|
+
// the account xpub and path based on the first input.
|
|
190
|
+
accountPath = pathElems.slice(0, -2);
|
|
191
|
+
return [4 /*yield*/, this.client.getPubkey(false, accountPath)];
|
|
192
|
+
case 3:
|
|
193
|
+
accountXpub = _a.sent();
|
|
194
|
+
_a.label = 4;
|
|
195
|
+
case 4: return [4 /*yield*/, this.setInput(psbt, i, arg.inputs[i], pathElems, accountType, masterFp)];
|
|
196
|
+
case 5:
|
|
197
|
+
_a.sent();
|
|
198
|
+
_a.label = 6;
|
|
199
|
+
case 6:
|
|
200
|
+
i++;
|
|
201
|
+
return [3 /*break*/, 2];
|
|
202
|
+
case 7:
|
|
203
|
+
outputsConcat = Buffer.from(arg.outputScriptHex, "hex");
|
|
204
|
+
outputsBufferReader = new buffertools_1.BufferReader(outputsConcat);
|
|
205
|
+
outputCount = outputsBufferReader.readVarInt();
|
|
206
|
+
psbt.setGlobalOutputCount(outputCount);
|
|
207
|
+
i = 0;
|
|
208
|
+
_a.label = 8;
|
|
209
|
+
case 8:
|
|
210
|
+
if (!(i < outputCount)) return [3 /*break*/, 12];
|
|
211
|
+
amount = Number(outputsBufferReader.readUInt64());
|
|
212
|
+
outputScript = outputsBufferReader.readVarSlice();
|
|
213
|
+
isChange = arg.changePath && i == outputCount - 1;
|
|
214
|
+
if (!isChange) return [3 /*break*/, 10];
|
|
215
|
+
changePath = (0, bip32_1.pathStringToArray)(arg.changePath);
|
|
216
|
+
return [4 /*yield*/, this.client.getPubkey(false, changePath)];
|
|
217
|
+
case 9:
|
|
218
|
+
xpubBase58 = _a.sent();
|
|
219
|
+
pubkey = (0, bip32_1.pubkeyFromXpub)(xpubBase58);
|
|
220
|
+
if (accountType == AccountType.p2pkh) {
|
|
221
|
+
psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
|
|
222
|
+
}
|
|
223
|
+
else if (accountType == AccountType.p2wpkh) {
|
|
224
|
+
psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
|
|
225
|
+
}
|
|
226
|
+
else if (accountType == AccountType.p2wpkhWrapped) {
|
|
227
|
+
redeemScript = this.createRedeemScript(pubkey);
|
|
228
|
+
psbt.setOutputRedeemScript(i, redeemScript);
|
|
229
|
+
psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
|
|
230
|
+
}
|
|
231
|
+
else if (accountType == AccountType.p2tr) {
|
|
232
|
+
psbt.setOutputTapBip32Derivation(i, pubkey, [], masterFp, changePath);
|
|
233
|
+
}
|
|
234
|
+
_a.label = 10;
|
|
235
|
+
case 10:
|
|
236
|
+
psbt.setOutputAmount(i, amount);
|
|
237
|
+
psbt.setOutputScript(i, outputScript);
|
|
238
|
+
_a.label = 11;
|
|
239
|
+
case 11:
|
|
240
|
+
i++;
|
|
241
|
+
return [3 /*break*/, 8];
|
|
242
|
+
case 12:
|
|
243
|
+
key = (0, policy_1.createKey)(masterFp, accountPath, accountXpub);
|
|
244
|
+
p = new policy_1.WalletPolicy(accountType, key);
|
|
245
|
+
return [4 /*yield*/, this.signPsbt(psbt, p)];
|
|
246
|
+
case 13: return [2 /*return*/, _a.sent()];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
BtcNew.prototype.setInput = function (psbt, i, input, pathElements, accountType, masterFP) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var inputTx, spentOutputIndex, redeemScript, sequence, inputTxBuffer, inputTxid, xpubBase58, pubkey, spentOutput, expectedRedeemScript;
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
256
|
+
case 0:
|
|
257
|
+
inputTx = input[0];
|
|
258
|
+
spentOutputIndex = input[1];
|
|
259
|
+
redeemScript = input[2];
|
|
260
|
+
sequence = input[3];
|
|
261
|
+
if (sequence) {
|
|
262
|
+
psbt.setInputSequence(i, sequence);
|
|
263
|
+
}
|
|
264
|
+
inputTxBuffer = (0, serializeTransaction_1.serializeTransaction)(inputTx, true);
|
|
265
|
+
inputTxid = bitcoinjs_lib_1.crypto.hash256(inputTxBuffer);
|
|
266
|
+
return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
|
|
267
|
+
case 1:
|
|
268
|
+
xpubBase58 = _a.sent();
|
|
269
|
+
pubkey = (0, bip32_1.pubkeyFromXpub)(xpubBase58);
|
|
270
|
+
if (!inputTx.outputs)
|
|
271
|
+
throw Error("Missing outputs array in transaction to sign");
|
|
272
|
+
spentOutput = inputTx.outputs[spentOutputIndex];
|
|
273
|
+
if (accountType == AccountType.p2pkh) {
|
|
274
|
+
psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
|
|
275
|
+
psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
|
|
276
|
+
}
|
|
277
|
+
else if (accountType == AccountType.p2wpkh) {
|
|
278
|
+
psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
|
|
279
|
+
psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
|
|
280
|
+
psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
|
|
281
|
+
}
|
|
282
|
+
else if (accountType == AccountType.p2wpkhWrapped) {
|
|
283
|
+
psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
|
|
284
|
+
psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
|
|
285
|
+
if (!redeemScript) {
|
|
286
|
+
throw new Error("Missing redeemScript for p2wpkhWrapped input");
|
|
287
|
+
}
|
|
288
|
+
expectedRedeemScript = this.createRedeemScript(pubkey);
|
|
289
|
+
if (redeemScript != expectedRedeemScript.toString("hex")) {
|
|
290
|
+
throw new Error("Unexpected redeemScript");
|
|
291
|
+
}
|
|
292
|
+
psbt.setInputRedeemScript(i, expectedRedeemScript);
|
|
293
|
+
psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
|
|
294
|
+
}
|
|
295
|
+
else if (accountType == AccountType.p2tr) {
|
|
296
|
+
psbt.setInputTapBip32Derivation(i, pubkey, [], masterFP, pathElements);
|
|
297
|
+
psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
|
|
298
|
+
}
|
|
299
|
+
psbt.setInputPreviousTxId(i, inputTxid);
|
|
300
|
+
psbt.setInputOutputIndex(i, spentOutputIndex);
|
|
301
|
+
return [2 /*return*/];
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
BtcNew.prototype.signPsbt = function (psbt, walletPolicy) {
|
|
307
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
308
|
+
var sigs, serializedTx;
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
switch (_a.label) {
|
|
311
|
+
case 0: return [4 /*yield*/, this.client.signPsbt(psbt, walletPolicy, Buffer.alloc(32, 0))];
|
|
312
|
+
case 1:
|
|
313
|
+
sigs = _a.sent();
|
|
314
|
+
sigs.forEach(function (v, k) {
|
|
315
|
+
// Note: Looking at BIP32 derivation does not work in the generic case.
|
|
316
|
+
// some inputs might not have a BIP32-derived pubkey.
|
|
317
|
+
var pubkeys = psbt.getInputKeyDatas(k, psbtv2_1.psbtIn.BIP32_DERIVATION);
|
|
318
|
+
var pubkey;
|
|
319
|
+
if (pubkeys.length != 1) {
|
|
320
|
+
pubkey = psbt.getInputKeyDatas(k, psbtv2_1.psbtIn.TAP_BIP32_DERIVATION);
|
|
321
|
+
if (pubkey.length == 0) {
|
|
322
|
+
throw Error("Missing pubkey derivation for input " + k);
|
|
323
|
+
}
|
|
324
|
+
psbt.setInputTapKeySig(k, v);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
pubkey = pubkeys[0];
|
|
328
|
+
psbt.setInputPartialSig(k, pubkey, v);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
(0, psbtFinalizer_1.finalize)(psbt);
|
|
332
|
+
serializedTx = (0, psbtExtractor_1.extract)(psbt);
|
|
333
|
+
return [2 /*return*/, serializedTx.toString("hex")];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
BtcNew.prototype.createRedeemScript = function (pubkey) {
|
|
339
|
+
var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
|
|
340
|
+
return Buffer.concat([Buffer.from("0014", "hex"), pubkeyHash]);
|
|
341
|
+
};
|
|
342
|
+
return BtcNew;
|
|
343
|
+
}());
|
|
344
|
+
exports["default"] = BtcNew;
|
|
345
|
+
var AccountType;
|
|
346
|
+
(function (AccountType) {
|
|
347
|
+
AccountType["p2pkh"] = "pkh(@0)";
|
|
348
|
+
AccountType["p2wpkh"] = "wpkh(@0)";
|
|
349
|
+
AccountType["p2wpkhWrapped"] = "sh(wpkh(@0))";
|
|
350
|
+
AccountType["p2tr"] = "tr(@0)";
|
|
351
|
+
})(AccountType || (AccountType = {}));
|
|
352
|
+
function accountTypeFrom(addressFormat) {
|
|
353
|
+
if (addressFormat == "legacy")
|
|
354
|
+
return AccountType.p2pkh;
|
|
355
|
+
if (addressFormat == "p2sh")
|
|
356
|
+
return AccountType.p2wpkhWrapped;
|
|
357
|
+
if (addressFormat == "bech32")
|
|
358
|
+
return AccountType.p2wpkh;
|
|
359
|
+
if (addressFormat == "bech32m")
|
|
360
|
+
return AccountType.p2tr;
|
|
361
|
+
throw new Error("Unsupported address format " + addressFormat);
|
|
362
|
+
}
|
|
363
|
+
function accountTypeFromArg(arg) {
|
|
364
|
+
if (arg.additionals.includes("bech32m"))
|
|
365
|
+
return AccountType.p2tr;
|
|
366
|
+
if (arg.additionals.includes("bech32"))
|
|
367
|
+
return AccountType.p2wpkh;
|
|
368
|
+
if (arg.segwit)
|
|
369
|
+
return AccountType.p2wpkhWrapped;
|
|
370
|
+
return AccountType.p2pkh;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=BtcNew.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BtcNew.js","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuC;AACvC,iCAA+E;AAC/E,6CAA6C;AAG7C,iDAAgD;AAEhD,0CAA0D;AAC1D,wDAAiD;AACjD,wDAAkD;AAClD,0CAAiD;AACjD,+DAA8D;AAE9D,iDAA+C;AAE/C;IACE,gBAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEhC,mCAAkB,GAAxB,UACE,IAAY,EACZ,IAGC;;;;;;;wBAMK,YAAY,GAAa,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAC;wBAC1C,qBAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,EAAA;;wBAAvD,IAAI,GAAG,SAAgD;wBAEvD,OAAO,GAAG,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,mCAAI,KAAK,CAAC;wBAEtB,qBAAM,IAAI,C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"@ledgerhq/hw-transport";
|
|
2
|
+
import type { CreateTransactionArg } from "./createTransaction";
|
|
3
|
+
import type { AddressFormat } from "./getWalletPublicKey";
|
|
4
|
+
import type { SignP2SHTransactionArg } from "./signP2SHTransaction";
|
|
5
|
+
export type { AddressFormat };
|
|
6
|
+
/**
|
|
7
|
+
* Bitcoin API.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* import Btc from "@ledgerhq/hw-app-btc";
|
|
11
|
+
* const btc = new Btc(transport)
|
|
12
|
+
*/
|
|
13
|
+
export default class BtcOld {
|
|
14
|
+
transport: Transport;
|
|
15
|
+
constructor(transport: Transport);
|
|
16
|
+
/**
|
|
17
|
+
* @param path a BIP 32 path
|
|
18
|
+
* @param options an object with optional these fields:
|
|
19
|
+
*
|
|
20
|
+
* - verify (boolean) will ask user to confirm the address on the device
|
|
21
|
+
*
|
|
22
|
+
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.
|
|
23
|
+
*
|
|
24
|
+
* NB The normal usage is to use:
|
|
25
|
+
*
|
|
26
|
+
* - legacy format with 44' paths
|
|
27
|
+
*
|
|
28
|
+
* - p2sh format with 49' paths
|
|
29
|
+
*
|
|
30
|
+
* - bech32 format with 173' paths
|
|
31
|
+
*
|
|
32
|
+
* - cashaddr in case of Bitcoin Cash
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
|
|
36
|
+
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
37
|
+
*/
|
|
38
|
+
getWalletPublicKey(path: string, opts?: {
|
|
39
|
+
verify?: boolean;
|
|
40
|
+
format?: AddressFormat;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
publicKey: string;
|
|
43
|
+
bitcoinAddress: string;
|
|
44
|
+
chainCode: string;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
|
48
|
+
* @example
|
|
49
|
+
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
50
|
+
var v = result['v'] + 27 + 4;
|
|
51
|
+
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
52
|
+
console.log("Signature : " + signature);
|
|
53
|
+
}).catch(function(ex) {console.log(ex);});
|
|
54
|
+
*/
|
|
55
|
+
signMessageNew(path: string, messageHex: string): Promise<{
|
|
56
|
+
v: number;
|
|
57
|
+
r: string;
|
|
58
|
+
s: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
62
|
+
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
63
|
+
*
|
|
64
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
65
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
66
|
+
* * redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
67
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
68
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
69
|
+
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
70
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
71
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
72
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
73
|
+
* @param segwit is an optional boolean indicating wether to use segwit or not
|
|
74
|
+
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
75
|
+
* @param additionals list of additionnal options
|
|
76
|
+
*
|
|
77
|
+
* - "bech32" for spending native segwit outputs
|
|
78
|
+
* - "abc" for bch
|
|
79
|
+
* - "gold" for btg
|
|
80
|
+
* - "bipxxx" for using BIPxxx
|
|
81
|
+
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
82
|
+
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
83
|
+
* @param useTrustedInputForSegwit trust inputs for segwit transactions
|
|
84
|
+
* @return the signed transaction ready to be broadcast
|
|
85
|
+
* @example
|
|
86
|
+
btc.createTransaction({
|
|
87
|
+
inputs: [ [tx1, 1] ],
|
|
88
|
+
associatedKeysets: ["0'/0/0"],
|
|
89
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
90
|
+
}).then(res => ...);
|
|
91
|
+
*/
|
|
92
|
+
createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
|
|
93
|
+
/**
|
|
94
|
+
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
95
|
+
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
96
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
97
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
98
|
+
* * redeem script is the mandatory redeem script associated to the current P2SH input
|
|
99
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
100
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
101
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
102
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
103
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
104
|
+
* @return the signed transaction ready to be broadcast
|
|
105
|
+
* @example
|
|
106
|
+
btc.signP2SHTransaction({
|
|
107
|
+
inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
|
|
108
|
+
associatedKeysets: ["0'/0/0"],
|
|
109
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
110
|
+
}).then(result => ...);
|
|
111
|
+
*/
|
|
112
|
+
signP2SHTransaction(arg: SignP2SHTransactionArg): Promise<string[]>;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=BtcOld.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BtcOld.d.ts","sourceRoot":"","sources":["../src/BtcOld.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS;IAIhC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,kBAAkB,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,aAAa,CAAC;KACxB,GACA,OAAO,CAAC;QACT,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAOF;;;;;;;;OAQG;IACH,cAAc,CACZ,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QACT,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IAOF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,2BAA2B,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC;IASvE;;;;;;;;;;;;;;;;;;OAkBG;IACH,mBAAmB,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CASpE"}
|
package/lib/BtcOld.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
exports.__esModule = true;
|
|
14
|
+
var createTransaction_1 = require("./createTransaction");
|
|
15
|
+
var getWalletPublicKey_1 = require("./getWalletPublicKey");
|
|
16
|
+
var signMessage_1 = require("./signMessage");
|
|
17
|
+
var signP2SHTransaction_1 = require("./signP2SHTransaction");
|
|
18
|
+
/**
|
|
19
|
+
* Bitcoin API.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* import Btc from "@ledgerhq/hw-app-btc";
|
|
23
|
+
* const btc = new Btc(transport)
|
|
24
|
+
*/
|
|
25
|
+
var BtcOld = /** @class */ (function () {
|
|
26
|
+
function BtcOld(transport) {
|
|
27
|
+
this.transport = transport;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param path a BIP 32 path
|
|
31
|
+
* @param options an object with optional these fields:
|
|
32
|
+
*
|
|
33
|
+
* - verify (boolean) will ask user to confirm the address on the device
|
|
34
|
+
*
|
|
35
|
+
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.
|
|
36
|
+
*
|
|
37
|
+
* NB The normal usage is to use:
|
|
38
|
+
*
|
|
39
|
+
* - legacy format with 44' paths
|
|
40
|
+
*
|
|
41
|
+
* - p2sh format with 49' paths
|
|
42
|
+
*
|
|
43
|
+
* - bech32 format with 173' paths
|
|
44
|
+
*
|
|
45
|
+
* - cashaddr in case of Bitcoin Cash
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
|
|
49
|
+
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
50
|
+
*/
|
|
51
|
+
BtcOld.prototype.getWalletPublicKey = function (path, opts) {
|
|
52
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.format) === "bech32m") {
|
|
53
|
+
throw new Error("Unsupported address format bech32m");
|
|
54
|
+
}
|
|
55
|
+
return (0, getWalletPublicKey_1.getWalletPublicKey)(this.transport, __assign(__assign({}, opts), { path: path }));
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
|
59
|
+
* @example
|
|
60
|
+
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
61
|
+
var v = result['v'] + 27 + 4;
|
|
62
|
+
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
63
|
+
console.log("Signature : " + signature);
|
|
64
|
+
}).catch(function(ex) {console.log(ex);});
|
|
65
|
+
*/
|
|
66
|
+
BtcOld.prototype.signMessageNew = function (path, messageHex) {
|
|
67
|
+
return (0, signMessage_1.signMessage)(this.transport, {
|
|
68
|
+
path: path,
|
|
69
|
+
messageHex: messageHex
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
74
|
+
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
|
|
75
|
+
*
|
|
76
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
77
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
78
|
+
* * redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
79
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
80
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
81
|
+
* @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
82
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
83
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
84
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
85
|
+
* @param segwit is an optional boolean indicating wether to use segwit or not
|
|
86
|
+
* @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
|
|
87
|
+
* @param additionals list of additionnal options
|
|
88
|
+
*
|
|
89
|
+
* - "bech32" for spending native segwit outputs
|
|
90
|
+
* - "abc" for bch
|
|
91
|
+
* - "gold" for btg
|
|
92
|
+
* - "bipxxx" for using BIPxxx
|
|
93
|
+
* - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
94
|
+
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
|
|
95
|
+
* @param useTrustedInputForSegwit trust inputs for segwit transactions
|
|
96
|
+
* @return the signed transaction ready to be broadcast
|
|
97
|
+
* @example
|
|
98
|
+
btc.createTransaction({
|
|
99
|
+
inputs: [ [tx1, 1] ],
|
|
100
|
+
associatedKeysets: ["0'/0/0"],
|
|
101
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
102
|
+
}).then(res => ...);
|
|
103
|
+
*/
|
|
104
|
+
BtcOld.prototype.createPaymentTransactionNew = function (arg) {
|
|
105
|
+
if (arguments.length > 1) {
|
|
106
|
+
console.warn("@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.");
|
|
107
|
+
}
|
|
108
|
+
return (0, createTransaction_1.createTransaction)(this.transport, arg);
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
112
|
+
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
113
|
+
* * transaction is the previously computed transaction object for this UTXO
|
|
114
|
+
* * output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
115
|
+
* * redeem script is the mandatory redeem script associated to the current P2SH input
|
|
116
|
+
* * sequence is the sequence number to use for this input (when using RBF), or non present
|
|
117
|
+
* @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
118
|
+
* @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
|
|
119
|
+
* @param lockTime is the optional lockTime of the transaction to sign, or default (0)
|
|
120
|
+
* @param sigHashType is the hash type of the transaction to sign, or default (all)
|
|
121
|
+
* @return the signed transaction ready to be broadcast
|
|
122
|
+
* @example
|
|
123
|
+
btc.signP2SHTransaction({
|
|
124
|
+
inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
|
|
125
|
+
associatedKeysets: ["0'/0/0"],
|
|
126
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
127
|
+
}).then(result => ...);
|
|
128
|
+
*/
|
|
129
|
+
BtcOld.prototype.signP2SHTransaction = function (arg) {
|
|
130
|
+
if (arguments.length > 1) {
|
|
131
|
+
console.warn("@ledgerhq/hw-app-btc: signP2SHTransaction multi argument signature is deprecated. please switch to named parameters.");
|
|
132
|
+
}
|
|
133
|
+
return (0, signP2SHTransaction_1.signP2SHTransaction)(this.transport, arg);
|
|
134
|
+
};
|
|
135
|
+
return BtcOld;
|
|
136
|
+
}());
|
|
137
|
+
exports["default"] = BtcOld;
|
|
138
|
+
//# sourceMappingURL=BtcOld.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BtcOld.js","sourceRoot":"","sources":["../src/BtcOld.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAEA,yDAAwD;AAExD,2DAA0D;AAC1D,6CAA4C;AAE5C,6DAA4D;AAE5D;;;;;;GAMG;AAEH;IAGE,gBAAY,SAAoB;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,mCAAkB,GAAlB,UACE,IAAY,EACZ,IAGC;QAMD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,MAAK,SAAS,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QACD,OAAO,IAAA,uCAAkB,EAAC,IAAI,CAAC,SAAS,wBAAO,IAAI,KAAE,IAAI,MAAA,IAAG,CAAC;IAC/D,CAAC;IAED;;;;;;;;OAQG;IACH,+BAAc,GAAd,UACE,IAAY,EACZ,UAAkB;QAMlB,OAAO,IAAA,yBAAW,EAAC,IAAI,CAAC,SAAS,EAAE;YACjC,IAAI,MAAA;YACJ,UAAU,YAAA;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,4CAA2B,GAA3B,UAA4B,GAAyB;QACnD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,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