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