@ledgerhq/hw-app-btc 10.0.1 → 10.0.2-next.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/CHANGELOG.md +7 -0
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +72 -97
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.js +217 -313
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.js +46 -106
- package/lib/BtcOld.js.map +1 -1
- package/lib/bip32.js +12 -12
- package/lib/bip32.js.map +1 -1
- package/lib/buffertools.js +66 -69
- package/lib/buffertools.js.map +1 -1
- package/lib/compressPublicKey.js +3 -3
- package/lib/compressPublicKey.js.map +1 -1
- package/lib/constants.js +1 -1
- package/lib/createTransaction.d.ts +1 -1
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/createTransaction.js +285 -398
- package/lib/createTransaction.js.map +1 -1
- package/lib/debug.js +11 -13
- package/lib/debug.js.map +1 -1
- package/lib/finalizeInput.js +23 -62
- package/lib/finalizeInput.js.map +1 -1
- package/lib/getAppAndVersion.d.ts +1 -1
- package/lib/getAppAndVersion.d.ts.map +1 -1
- package/lib/getAppAndVersion.js +29 -72
- package/lib/getAppAndVersion.js.map +1 -1
- package/lib/getTrustedInput.js +108 -251
- package/lib/getTrustedInput.js.map +1 -1
- package/lib/getTrustedInputBIP143.js +9 -10
- package/lib/getTrustedInputBIP143.js.map +1 -1
- package/lib/getWalletPublicKey.d.ts +1 -1
- package/lib/getWalletPublicKey.d.ts.map +1 -1
- package/lib/getWalletPublicKey.js +27 -73
- package/lib/getWalletPublicKey.js.map +1 -1
- package/lib/hashPublicKey.js +4 -4
- package/lib/hashPublicKey.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/newops/accounttype.d.ts +2 -2
- package/lib/newops/accounttype.d.ts.map +1 -1
- package/lib/newops/accounttype.js +85 -125
- package/lib/newops/accounttype.js.map +1 -1
- package/lib/newops/appClient.js +98 -205
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.js +122 -213
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.js +28 -75
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.js +38 -67
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.js +11 -12
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts +1 -1
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +17 -18
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.js +9 -9
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtFinalizer.js +22 -22
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/newops/psbtv2.d.ts +1 -1
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +227 -286
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib/serializeTransaction.js +13 -15
- package/lib/serializeTransaction.js.map +1 -1
- package/lib/shouldUseTrustedInputForSegwit.js +4 -5
- package/lib/shouldUseTrustedInputForSegwit.js.map +1 -1
- package/lib/signMessage.js +47 -99
- package/lib/signMessage.js.map +1 -1
- package/lib/signP2SHTransaction.d.ts +1 -1
- package/lib/signP2SHTransaction.d.ts.map +1 -1
- package/lib/signP2SHTransaction.js +91 -187
- package/lib/signP2SHTransaction.js.map +1 -1
- package/lib/signTransaction.js +8 -9
- package/lib/signTransaction.js.map +1 -1
- package/lib/splitTransaction.js +50 -54
- package/lib/splitTransaction.js.map +1 -1
- package/lib/startUntrustedHashTransactionInput.js +65 -167
- package/lib/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib/types.js +1 -1
- package/lib/varint.js +10 -10
- package/lib/varint.js.map +1 -1
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +58 -84
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.js +205 -302
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.js +35 -96
- package/lib-es/BtcOld.js.map +1 -1
- package/lib-es/bip32.js +7 -7
- package/lib-es/bip32.js.map +1 -1
- package/lib-es/buffertools.js +62 -67
- package/lib-es/buffertools.js.map +1 -1
- package/lib-es/compressPublicKey.js +2 -2
- package/lib-es/compressPublicKey.js.map +1 -1
- package/lib-es/constants.js +12 -12
- package/lib-es/constants.js.map +1 -1
- package/lib-es/createTransaction.d.ts +1 -1
- package/lib-es/createTransaction.d.ts.map +1 -1
- package/lib-es/createTransaction.js +271 -384
- package/lib-es/createTransaction.js.map +1 -1
- package/lib-es/debug.js +10 -12
- package/lib-es/debug.js.map +1 -1
- package/lib-es/finalizeInput.js +20 -59
- package/lib-es/finalizeInput.js.map +1 -1
- package/lib-es/getAppAndVersion.d.ts +1 -1
- package/lib-es/getAppAndVersion.d.ts.map +1 -1
- package/lib-es/getAppAndVersion.js +27 -70
- package/lib-es/getAppAndVersion.js.map +1 -1
- package/lib-es/getTrustedInput.js +104 -247
- package/lib-es/getTrustedInput.js.map +1 -1
- package/lib-es/getTrustedInputBIP143.js +5 -6
- package/lib-es/getTrustedInputBIP143.js.map +1 -1
- package/lib-es/getWalletPublicKey.d.ts +1 -1
- package/lib-es/getWalletPublicKey.d.ts.map +1 -1
- package/lib-es/getWalletPublicKey.js +25 -71
- package/lib-es/getWalletPublicKey.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts +2 -2
- package/lib-es/newops/accounttype.d.ts.map +1 -1
- package/lib-es/newops/accounttype.js +79 -123
- package/lib-es/newops/accounttype.js.map +1 -1
- package/lib-es/newops/appClient.js +92 -200
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.js +117 -214
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +25 -73
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.js +36 -66
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.js +8 -10
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts +1 -1
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +12 -14
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.js +7 -7
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.js +19 -19
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts +1 -1
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +225 -286
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/lib-es/serializeTransaction.js +11 -13
- package/lib-es/serializeTransaction.js.map +1 -1
- package/lib-es/shouldUseTrustedInputForSegwit.js +1 -2
- package/lib-es/shouldUseTrustedInputForSegwit.js.map +1 -1
- package/lib-es/signMessage.js +44 -96
- package/lib-es/signMessage.js.map +1 -1
- package/lib-es/signP2SHTransaction.d.ts +1 -1
- package/lib-es/signP2SHTransaction.d.ts.map +1 -1
- package/lib-es/signP2SHTransaction.js +84 -180
- package/lib-es/signP2SHTransaction.js.map +1 -1
- package/lib-es/signTransaction.js +6 -7
- package/lib-es/signTransaction.js.map +1 -1
- package/lib-es/splitTransaction.js +46 -50
- package/lib-es/splitTransaction.js.map +1 -1
- package/lib-es/startUntrustedHashTransactionInput.js +62 -164
- package/lib-es/startUntrustedHashTransactionInput.js.map +1 -1
- package/lib-es/varint.js +9 -9
- package/lib-es/varint.js.map +1 -1
- package/package.json +5 -6
- package/src/Btc.ts +28 -5
|
@@ -1,47 +1,27 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
import { crypto } from "bitcoinjs-lib";
|
|
17
2
|
import { pointAddScalar } from "tiny-secp256k1";
|
|
18
3
|
import { BufferWriter } from "../buffertools";
|
|
19
4
|
import { HASH_SIZE, OP_CHECKSIG, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH160, } from "../constants";
|
|
20
5
|
import { hashPublicKey } from "../hashPublicKey";
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
class BaseAccount {
|
|
7
|
+
constructor(psbt, masterFp) {
|
|
23
8
|
this.psbt = psbt;
|
|
24
9
|
this.masterFp = masterFp;
|
|
25
10
|
}
|
|
26
|
-
|
|
27
|
-
}());
|
|
11
|
+
}
|
|
28
12
|
/**
|
|
29
13
|
* Superclass for single signature accounts. This will make sure that the pubkey
|
|
30
14
|
* arrays and path arrays in the method arguments contains exactly one element
|
|
31
15
|
* and calls an abstract method to do the actual work.
|
|
32
16
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function SingleKeyAccount() {
|
|
36
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
37
|
-
}
|
|
38
|
-
SingleKeyAccount.prototype.spendingCondition = function (pubkeys) {
|
|
17
|
+
class SingleKeyAccount extends BaseAccount {
|
|
18
|
+
spendingCondition(pubkeys) {
|
|
39
19
|
if (pubkeys.length != 1) {
|
|
40
20
|
throw new Error("Expected single key, got " + pubkeys.length);
|
|
41
21
|
}
|
|
42
22
|
return this.singleKeyCondition(pubkeys[0]);
|
|
43
|
-
}
|
|
44
|
-
|
|
23
|
+
}
|
|
24
|
+
setInput(i, inputTx, spentOutput, pubkeys, pathElems) {
|
|
45
25
|
if (pubkeys.length != 1) {
|
|
46
26
|
throw new Error("Expected single key, got " + pubkeys.length);
|
|
47
27
|
}
|
|
@@ -49,8 +29,8 @@ var SingleKeyAccount = /** @class */ (function (_super) {
|
|
|
49
29
|
throw new Error("Expected single path, got " + pathElems.length);
|
|
50
30
|
}
|
|
51
31
|
this.setSingleKeyInput(i, inputTx, spentOutput, pubkeys[0], pathElems[0]);
|
|
52
|
-
}
|
|
53
|
-
|
|
32
|
+
}
|
|
33
|
+
setOwnOutput(i, cond, pubkeys, paths) {
|
|
54
34
|
if (pubkeys.length != 1) {
|
|
55
35
|
throw new Error("Expected single key, got " + pubkeys.length);
|
|
56
36
|
}
|
|
@@ -58,73 +38,62 @@ var SingleKeyAccount = /** @class */ (function (_super) {
|
|
|
58
38
|
throw new Error("Expected single path, got " + paths.length);
|
|
59
39
|
}
|
|
60
40
|
this.setSingleKeyOutput(i, cond, pubkeys[0], paths[0]);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
68
|
-
}
|
|
69
|
-
p2pkh.prototype.singleKeyCondition = function (pubkey) {
|
|
70
|
-
var buf = new BufferWriter();
|
|
71
|
-
var pubkeyHash = hashPublicKey(pubkey);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class p2pkh extends SingleKeyAccount {
|
|
44
|
+
singleKeyCondition(pubkey) {
|
|
45
|
+
const buf = new BufferWriter();
|
|
46
|
+
const pubkeyHash = hashPublicKey(pubkey);
|
|
72
47
|
buf.writeSlice(Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]));
|
|
73
48
|
buf.writeSlice(pubkeyHash);
|
|
74
49
|
buf.writeSlice(Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]));
|
|
75
50
|
return { scriptPubKey: buf.buffer() };
|
|
76
|
-
}
|
|
77
|
-
|
|
51
|
+
}
|
|
52
|
+
setSingleKeyInput(i, inputTx, _spentOutput, pubkey, path) {
|
|
78
53
|
if (!inputTx) {
|
|
79
54
|
throw new Error("Full input base transaction required");
|
|
80
55
|
}
|
|
81
56
|
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
82
57
|
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
83
|
-
}
|
|
84
|
-
|
|
58
|
+
}
|
|
59
|
+
setSingleKeyOutput(i, cond, pubkey, path) {
|
|
85
60
|
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
86
|
-
}
|
|
87
|
-
|
|
61
|
+
}
|
|
62
|
+
getDescriptorTemplate() {
|
|
88
63
|
return "pkh(@0)";
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
97
|
-
}
|
|
98
|
-
p2tr.prototype.singleKeyCondition = function (pubkey) {
|
|
99
|
-
var xonlyPubkey = pubkey.slice(1); // x-only pubkey
|
|
100
|
-
var buf = new BufferWriter();
|
|
101
|
-
var outputKey = this.getTaprootOutputKey(xonlyPubkey);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class p2tr extends SingleKeyAccount {
|
|
67
|
+
singleKeyCondition(pubkey) {
|
|
68
|
+
const xonlyPubkey = pubkey.slice(1); // x-only pubkey
|
|
69
|
+
const buf = new BufferWriter();
|
|
70
|
+
const outputKey = this.getTaprootOutputKey(xonlyPubkey);
|
|
102
71
|
buf.writeSlice(Buffer.from([0x51, 32])); // push1, pubkeylen
|
|
103
72
|
buf.writeSlice(outputKey);
|
|
104
73
|
return { scriptPubKey: buf.buffer() };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
74
|
+
}
|
|
75
|
+
setSingleKeyInput(i, _inputTx, spentOutput, pubkey, path) {
|
|
76
|
+
const xonly = pubkey.slice(1);
|
|
108
77
|
this.psbt.setInputTapBip32Derivation(i, xonly, [], this.masterFp, path);
|
|
109
78
|
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
79
|
+
}
|
|
80
|
+
setSingleKeyOutput(i, cond, pubkey, path) {
|
|
81
|
+
const xonly = pubkey.slice(1);
|
|
113
82
|
this.psbt.setOutputTapBip32Derivation(i, xonly, [], this.masterFp, path);
|
|
114
|
-
}
|
|
115
|
-
|
|
83
|
+
}
|
|
84
|
+
getDescriptorTemplate() {
|
|
116
85
|
return "tr(@0)";
|
|
117
|
-
}
|
|
86
|
+
}
|
|
118
87
|
/*
|
|
119
88
|
The following two functions are copied from wallet-btc and adapted.
|
|
120
89
|
They should be moved to a library to avoid code reuse.
|
|
121
90
|
*/
|
|
122
|
-
|
|
91
|
+
hashTapTweak(x) {
|
|
123
92
|
// hash_tag(x) = SHA256(SHA256(tag) || SHA256(tag) || x), see BIP340
|
|
124
93
|
// See https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification
|
|
125
|
-
|
|
94
|
+
const h = crypto.sha256(Buffer.from("TapTweak", "utf-8"));
|
|
126
95
|
return crypto.sha256(Buffer.concat([h, h, x]));
|
|
127
|
-
}
|
|
96
|
+
}
|
|
128
97
|
/**
|
|
129
98
|
* Calculates a taproot output key from an internal key. This output key will be
|
|
130
99
|
* used as witness program in a taproot output. The internal key is tweaked
|
|
@@ -134,7 +103,7 @@ var p2tr = /** @class */ (function (_super) {
|
|
|
134
103
|
* @param internalPubkey A 32 byte x-only taproot internal key
|
|
135
104
|
* @returns The output key
|
|
136
105
|
*/
|
|
137
|
-
|
|
106
|
+
getTaprootOutputKey(internalPubkey) {
|
|
138
107
|
if (internalPubkey.length != 32) {
|
|
139
108
|
throw new Error("Expected 32 byte pubkey. Got " + internalPubkey.length);
|
|
140
109
|
}
|
|
@@ -142,92 +111,79 @@ var p2tr = /** @class */ (function (_super) {
|
|
|
142
111
|
// the first byte, which represent the oddness/evenness. In schnorr all
|
|
143
112
|
// pubkeys are even.
|
|
144
113
|
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-conversion
|
|
145
|
-
|
|
114
|
+
const evenEcdsaPubkey = Buffer.concat([
|
|
146
115
|
Buffer.from([0x02]),
|
|
147
116
|
internalPubkey,
|
|
148
117
|
]);
|
|
149
|
-
|
|
118
|
+
const tweak = this.hashTapTweak(internalPubkey);
|
|
150
119
|
// Q = P + int(hash_TapTweak(bytes(P)))G
|
|
151
|
-
|
|
120
|
+
const outputEcdsaKey = Buffer.from(pointAddScalar(evenEcdsaPubkey, tweak));
|
|
152
121
|
// Convert to schnorr.
|
|
153
|
-
|
|
122
|
+
const outputSchnorrKey = outputEcdsaKey.slice(1);
|
|
154
123
|
// Create address
|
|
155
124
|
return outputSchnorrKey;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
164
|
-
}
|
|
165
|
-
p2wpkhWrapped.prototype.singleKeyCondition = function (pubkey) {
|
|
166
|
-
var buf = new BufferWriter();
|
|
167
|
-
var redeemScript = this.createRedeemScript(pubkey);
|
|
168
|
-
var scriptHash = hashPublicKey(redeemScript);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export class p2wpkhWrapped extends SingleKeyAccount {
|
|
128
|
+
singleKeyCondition(pubkey) {
|
|
129
|
+
const buf = new BufferWriter();
|
|
130
|
+
const redeemScript = this.createRedeemScript(pubkey);
|
|
131
|
+
const scriptHash = hashPublicKey(redeemScript);
|
|
169
132
|
buf.writeSlice(Buffer.from([OP_HASH160, HASH_SIZE]));
|
|
170
133
|
buf.writeSlice(scriptHash);
|
|
171
134
|
buf.writeUInt8(OP_EQUAL);
|
|
172
135
|
return { scriptPubKey: buf.buffer(), redeemScript: redeemScript };
|
|
173
|
-
}
|
|
174
|
-
|
|
136
|
+
}
|
|
137
|
+
setSingleKeyInput(i, inputTx, spentOutput, pubkey, path) {
|
|
175
138
|
if (!inputTx) {
|
|
176
139
|
throw new Error("Full input base transaction required");
|
|
177
140
|
}
|
|
178
141
|
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
179
142
|
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
180
|
-
|
|
181
|
-
|
|
143
|
+
const userSuppliedRedeemScript = spentOutput.cond.redeemScript;
|
|
144
|
+
const expectedRedeemScript = this.createRedeemScript(pubkey);
|
|
182
145
|
if (userSuppliedRedeemScript &&
|
|
183
146
|
!expectedRedeemScript.equals(userSuppliedRedeemScript)) {
|
|
184
147
|
// At what point might a user set the redeemScript on its own?
|
|
185
|
-
throw new Error(
|
|
148
|
+
throw new Error(`User-supplied redeemScript ${userSuppliedRedeemScript.toString("hex")} doesn't
|
|
149
|
+
match expected ${expectedRedeemScript.toString("hex")} for input ${i}`);
|
|
186
150
|
}
|
|
187
151
|
this.psbt.setInputRedeemScript(i, expectedRedeemScript);
|
|
188
152
|
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
189
|
-
}
|
|
190
|
-
|
|
153
|
+
}
|
|
154
|
+
setSingleKeyOutput(i, cond, pubkey, path) {
|
|
191
155
|
this.psbt.setOutputRedeemScript(i, cond.redeemScript);
|
|
192
156
|
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
193
|
-
}
|
|
194
|
-
|
|
157
|
+
}
|
|
158
|
+
getDescriptorTemplate() {
|
|
195
159
|
return "sh(wpkh(@0))";
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
160
|
+
}
|
|
161
|
+
createRedeemScript(pubkey) {
|
|
162
|
+
const pubkeyHash = hashPublicKey(pubkey);
|
|
199
163
|
return Buffer.concat([Buffer.from("0014", "hex"), pubkeyHash]);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
function p2wpkh() {
|
|
207
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
208
|
-
}
|
|
209
|
-
p2wpkh.prototype.singleKeyCondition = function (pubkey) {
|
|
210
|
-
var buf = new BufferWriter();
|
|
211
|
-
var pubkeyHash = hashPublicKey(pubkey);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export class p2wpkh extends SingleKeyAccount {
|
|
167
|
+
singleKeyCondition(pubkey) {
|
|
168
|
+
const buf = new BufferWriter();
|
|
169
|
+
const pubkeyHash = hashPublicKey(pubkey);
|
|
212
170
|
buf.writeSlice(Buffer.from([0, HASH_SIZE]));
|
|
213
171
|
buf.writeSlice(pubkeyHash);
|
|
214
172
|
return { scriptPubKey: buf.buffer() };
|
|
215
|
-
}
|
|
216
|
-
|
|
173
|
+
}
|
|
174
|
+
setSingleKeyInput(i, inputTx, spentOutput, pubkey, path) {
|
|
217
175
|
if (!inputTx) {
|
|
218
176
|
throw new Error("Full input base transaction required");
|
|
219
177
|
}
|
|
220
178
|
this.psbt.setInputNonWitnessUtxo(i, inputTx);
|
|
221
179
|
this.psbt.setInputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
222
180
|
this.psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.cond.scriptPubKey);
|
|
223
|
-
}
|
|
224
|
-
|
|
181
|
+
}
|
|
182
|
+
setSingleKeyOutput(i, cond, pubkey, path) {
|
|
225
183
|
this.psbt.setOutputBip32Derivation(i, pubkey, this.masterFp, path);
|
|
226
|
-
}
|
|
227
|
-
|
|
184
|
+
}
|
|
185
|
+
getDescriptorTemplate() {
|
|
228
186
|
return "wpkh(@0)";
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
}(SingleKeyAccount));
|
|
232
|
-
export { p2wpkh };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
233
189
|
//# sourceMappingURL=accounttype.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounttype.js","sourceRoot":"","sources":["../../src/newops/accounttype.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"accounttype.js","sourceRoot":"","sources":["../../src/newops/accounttype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,SAAS,EACT,WAAW,EACX,MAAM,EACN,QAAQ,EACR,cAAc,EACd,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAyEjD,MAAe,WAAW;IACxB,YAAsB,IAAY,EAAY,QAAgB;QAAxC,SAAI,GAAJ,IAAI,CAAQ;QAAY,aAAQ,GAAR,QAAQ,CAAQ;IAAG,CAAC;CACnE;AAED;;;;GAIG;AACH,MAAe,gBAAiB,SAAQ,WAAW;IACjD,iBAAiB,CAAC,OAAiB;QACjC,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC/D;QACD,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IAGD,QAAQ,CACN,CAAS,EACT,OAA2B,EAC3B,WAAwB,EACxB,OAAiB,EACjB,SAAqB;QAErB,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,OAAO,CAAC,MAAM,CAAC,CA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