@scure/btc-signer 1.8.1 → 2.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/README.md +8 -5
- package/index.js +17 -61
- package/index.js.map +1 -1
- package/musig2.d.ts +2 -2
- package/musig2.d.ts.map +1 -1
- package/musig2.js +93 -90
- package/musig2.js.map +1 -1
- package/p2p.d.ts +7 -8
- package/p2p.d.ts.map +1 -1
- package/p2p.js +32 -38
- package/p2p.js.map +1 -1
- package/package.json +33 -103
- package/payment.js +73 -96
- package/payment.js.map +1 -1
- package/psbt.d.ts +224 -224
- package/psbt.d.ts.map +1 -1
- package/psbt.js +58 -63
- package/psbt.js.map +1 -1
- package/script.d.ts +125 -120
- package/script.d.ts.map +1 -1
- package/script.js +46 -146
- package/script.js.map +1 -1
- package/src/musig2.ts +43 -50
- package/src/p2p.ts +28 -40
- package/src/psbt.ts +7 -7
- package/src/script.ts +29 -26
- package/src/transaction.ts +21 -21
- package/src/utils.ts +41 -22
- package/transaction.d.ts +22 -28
- package/transaction.d.ts.map +1 -1
- package/transaction.js +134 -151
- package/transaction.js.map +1 -1
- package/utils.d.ts +11 -5
- package/utils.d.ts.map +1 -1
- package/utils.js +60 -62
- package/utils.js.map +1 -1
- package/utxo.d.ts +45 -45
- package/utxo.d.ts.map +1 -1
- package/utxo.js +62 -58
- package/utxo.js.map +1 -1
- package/_type_test.d.ts +0 -2
- package/_type_test.d.ts.map +0 -1
- package/_type_test.js +0 -59
- package/_type_test.js.map +0 -1
- package/esm/_type_test.d.ts +0 -2
- package/esm/_type_test.d.ts.map +0 -1
- package/esm/_type_test.js +0 -57
- package/esm/_type_test.js.map +0 -1
- package/esm/index.d.ts +0 -22
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -22
- package/esm/index.js.map +0 -1
- package/esm/musig2.d.ts +0 -148
- package/esm/musig2.d.ts.map +0 -1
- package/esm/musig2.js +0 -404
- package/esm/musig2.js.map +0 -1
- package/esm/p2p.d.ts +0 -38
- package/esm/p2p.d.ts.map +0 -1
- package/esm/p2p.js +0 -156
- package/esm/p2p.js.map +0 -1
- package/esm/package.json +0 -1
- package/esm/payment.d.ts +0 -200
- package/esm/payment.d.ts.map +0 -1
- package/esm/payment.js +0 -697
- package/esm/payment.js.map +0 -1
- package/esm/psbt.d.ts +0 -820
- package/esm/psbt.d.ts.map +0 -1
- package/esm/psbt.js +0 -409
- package/esm/psbt.js.map +0 -1
- package/esm/script.d.ts +0 -170
- package/esm/script.d.ts.map +0 -1
- package/esm/script.js +0 -356
- package/esm/script.js.map +0 -1
- package/esm/transaction.d.ts +0 -172
- package/esm/transaction.d.ts.map +0 -1
- package/esm/transaction.js +0 -1185
- package/esm/transaction.js.map +0 -1
- package/esm/utils.d.ts +0 -35
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -118
- package/esm/utils.js.map +0 -1
- package/esm/utxo.d.ts +0 -198
- package/esm/utxo.d.ts.map +0 -1
- package/esm/utxo.js +0 -461
- package/esm/utxo.js.map +0 -1
- package/src/_type_test.ts +0 -69
- package/src/package.json +0 -3
package/esm/utxo.js
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
import { hex } from '@scure/base';
|
|
2
|
-
import * as P from 'micro-packed';
|
|
3
|
-
import { Address, OutScript, checkScript, tapLeafHash } from "./payment.js";
|
|
4
|
-
import * as psbt from "./psbt.js";
|
|
5
|
-
import { CompactSizeLen, RawWitness, Script, VarBytes } from "./script.js";
|
|
6
|
-
import { SignatureHash, Transaction, getInputType, getPrevOut, inputBeforeSign, normalizeInput, toVsize, } from "./transaction.js";
|
|
7
|
-
import { NETWORK, PubT, TAPROOT_UNSPENDABLE_KEY, compareBytes, equalBytes, isBytes, sha256, validatePubkey, } from "./utils.js";
|
|
8
|
-
const encodeTapBlock = (item) => psbt.TaprootControlBlock.encode(item);
|
|
9
|
-
function iterLeafs(tapLeafScript, sigSize, customScripts) {
|
|
10
|
-
if (!tapLeafScript || !tapLeafScript.length)
|
|
11
|
-
throw new Error('no leafs');
|
|
12
|
-
const empty = () => new Uint8Array(sigSize);
|
|
13
|
-
// If user want to select specific leaf, which can signed,
|
|
14
|
-
// it is possible to remove all other leafs manually.
|
|
15
|
-
// Sort leafs by control block length.
|
|
16
|
-
const leafs = tapLeafScript.sort((a, b) => encodeTapBlock(a[0]).length - encodeTapBlock(b[0]).length);
|
|
17
|
-
for (const [cb, _script] of leafs) {
|
|
18
|
-
// Last byte is version
|
|
19
|
-
const script = _script.slice(0, -1);
|
|
20
|
-
const ver = _script[_script.length - 1];
|
|
21
|
-
const outs = OutScript.decode(script);
|
|
22
|
-
let signatures = [];
|
|
23
|
-
if (outs.type === 'tr_ms') {
|
|
24
|
-
const m = outs.m;
|
|
25
|
-
const n = outs.pubkeys.length - m;
|
|
26
|
-
for (let i = 0; i < m; i++)
|
|
27
|
-
signatures.push(empty());
|
|
28
|
-
for (let i = 0; i < n; i++)
|
|
29
|
-
signatures.push(P.EMPTY);
|
|
30
|
-
}
|
|
31
|
-
else if (outs.type === 'tr_ns') {
|
|
32
|
-
for (const _pub of outs.pubkeys)
|
|
33
|
-
signatures.push(empty());
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
if (!customScripts)
|
|
37
|
-
throw new Error('Finalize: Unknown tapLeafScript');
|
|
38
|
-
const leafHash = tapLeafHash(script, ver);
|
|
39
|
-
for (const c of customScripts) {
|
|
40
|
-
if (!c.finalizeTaproot)
|
|
41
|
-
continue;
|
|
42
|
-
const scriptDecoded = Script.decode(script);
|
|
43
|
-
const csEncoded = c.encode(scriptDecoded);
|
|
44
|
-
if (csEncoded === undefined)
|
|
45
|
-
continue;
|
|
46
|
-
const pubKeys = scriptDecoded.filter((i) => {
|
|
47
|
-
if (!isBytes(i))
|
|
48
|
-
return false;
|
|
49
|
-
try {
|
|
50
|
-
validatePubkey(i, PubT.schnorr);
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
const finalized = c.finalizeTaproot(script, csEncoded, pubKeys.map((pubKey) => [{ pubKey, leafHash }, empty()]));
|
|
58
|
-
if (!finalized)
|
|
59
|
-
continue;
|
|
60
|
-
return finalized.concat(encodeTapBlock(cb));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Witness is stack, so last element will be used first
|
|
64
|
-
return signatures.reverse().concat([script, encodeTapBlock(cb)]);
|
|
65
|
-
}
|
|
66
|
-
throw new Error('there was no witness');
|
|
67
|
-
}
|
|
68
|
-
function estimateInput(inputType, input, opts) {
|
|
69
|
-
let script = P.EMPTY;
|
|
70
|
-
let witness;
|
|
71
|
-
// schnorr sig is always 64 bytes. except for cases when sighash is not default!
|
|
72
|
-
if (inputType.txType === 'taproot') {
|
|
73
|
-
const SCHNORR_SIG_SIZE = inputType.sighash !== SignatureHash.DEFAULT ? 65 : 64;
|
|
74
|
-
if (input.tapInternalKey && !equalBytes(input.tapInternalKey, TAPROOT_UNSPENDABLE_KEY)) {
|
|
75
|
-
witness = [new Uint8Array(SCHNORR_SIG_SIZE)];
|
|
76
|
-
}
|
|
77
|
-
else if (input.tapLeafScript) {
|
|
78
|
-
witness = iterLeafs(input.tapLeafScript, SCHNORR_SIG_SIZE, opts.customScripts);
|
|
79
|
-
}
|
|
80
|
-
else
|
|
81
|
-
throw new Error('estimateInput/taproot: unknown input');
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// It is possible to grind signatures until it has minimal size (but changing fee value +N satoshi),
|
|
85
|
-
// which will make estimations exact. But will be very hard for multi sig (need to make sure all signatures has small size).
|
|
86
|
-
const empty = () => new Uint8Array(72); // max size of sigs
|
|
87
|
-
const emptyPub = () => new Uint8Array(33); // size of pubkey
|
|
88
|
-
let inputScript = P.EMPTY;
|
|
89
|
-
let inputWitness = [];
|
|
90
|
-
const ltype = inputType.last.type;
|
|
91
|
-
if (ltype === 'ms') {
|
|
92
|
-
const m = inputType.last.m;
|
|
93
|
-
const sig = [0];
|
|
94
|
-
for (let i = 0; i < m; i++)
|
|
95
|
-
sig.push(empty());
|
|
96
|
-
inputScript = Script.encode(sig);
|
|
97
|
-
}
|
|
98
|
-
else if (ltype === 'pk') {
|
|
99
|
-
// 71 sig + 1 sighash
|
|
100
|
-
inputScript = Script.encode([empty()]);
|
|
101
|
-
}
|
|
102
|
-
else if (ltype === 'pkh') {
|
|
103
|
-
inputScript = Script.encode([empty(), emptyPub()]);
|
|
104
|
-
}
|
|
105
|
-
else if (ltype === 'wpkh') {
|
|
106
|
-
inputScript = P.EMPTY;
|
|
107
|
-
inputWitness = [empty(), emptyPub()];
|
|
108
|
-
}
|
|
109
|
-
else if (ltype === 'unknown' && !opts.allowUnknownInputs)
|
|
110
|
-
throw new Error('Unknown inputs are not allowed');
|
|
111
|
-
if (inputType.type.includes('wsh-')) {
|
|
112
|
-
// P2WSH
|
|
113
|
-
if (inputScript.length && inputType.lastScript.length) {
|
|
114
|
-
inputWitness = Script.decode(inputScript).map((i) => {
|
|
115
|
-
if (i === 0)
|
|
116
|
-
return P.EMPTY;
|
|
117
|
-
if (isBytes(i))
|
|
118
|
-
return i;
|
|
119
|
-
throw new Error(`Wrong witness op=${i}`);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
inputWitness = inputWitness.concat(inputType.lastScript);
|
|
123
|
-
}
|
|
124
|
-
if (inputType.txType === 'segwit')
|
|
125
|
-
witness = inputWitness;
|
|
126
|
-
if (inputType.type.startsWith('sh-wsh-')) {
|
|
127
|
-
script = Script.encode([Script.encode([0, new Uint8Array(sha256.outputLen)])]);
|
|
128
|
-
}
|
|
129
|
-
else if (inputType.type.startsWith('sh-')) {
|
|
130
|
-
script = Script.encode([...Script.decode(inputScript), inputType.lastScript]);
|
|
131
|
-
}
|
|
132
|
-
else if (inputType.type.startsWith('wsh-')) {
|
|
133
|
-
}
|
|
134
|
-
else if (inputType.txType !== 'segwit')
|
|
135
|
-
script = inputScript;
|
|
136
|
-
}
|
|
137
|
-
let weight = 160 + 4 * VarBytes.encode(script).length;
|
|
138
|
-
let hasWitnesses = false;
|
|
139
|
-
if (witness) {
|
|
140
|
-
weight += RawWitness.encode(witness).length;
|
|
141
|
-
hasWitnesses = true;
|
|
142
|
-
}
|
|
143
|
-
return { weight, hasWitnesses };
|
|
144
|
-
}
|
|
145
|
-
// Exported for tests, internal method
|
|
146
|
-
export const _cmpBig = (a, b) => {
|
|
147
|
-
const n = a - b;
|
|
148
|
-
if (n < 0n)
|
|
149
|
-
return -1;
|
|
150
|
-
else if (n > 0n)
|
|
151
|
-
return 1;
|
|
152
|
-
return 0;
|
|
153
|
-
};
|
|
154
|
-
function getScript(o, opts = {}, network = NETWORK) {
|
|
155
|
-
let script;
|
|
156
|
-
if ('script' in o && isBytes(o.script)) {
|
|
157
|
-
script = o.script;
|
|
158
|
-
}
|
|
159
|
-
if ('address' in o) {
|
|
160
|
-
if (typeof o.address !== 'string')
|
|
161
|
-
throw new Error(`Estimator: wrong output address=${o.address}`);
|
|
162
|
-
script = OutScript.encode(Address(network).decode(o.address));
|
|
163
|
-
}
|
|
164
|
-
if (!script)
|
|
165
|
-
throw new Error('Estimator: wrong output script');
|
|
166
|
-
if (typeof o.amount !== 'bigint')
|
|
167
|
-
throw new Error(`Estimator: wrong output amount=${o.amount}, should be of type bigint but got ${typeof o.amount}.`);
|
|
168
|
-
if (script && !opts.allowUnknownOutputs && OutScript.decode(script).type === 'unknown') {
|
|
169
|
-
throw new Error('Estimator: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure');
|
|
170
|
-
}
|
|
171
|
-
if (!opts.disableScriptCheck)
|
|
172
|
-
checkScript(script);
|
|
173
|
-
return script;
|
|
174
|
-
}
|
|
175
|
-
// class, because we need to re-use normalized inputs, instead of parsing each time
|
|
176
|
-
// internal stuff, exported for tests only
|
|
177
|
-
export class _Estimator {
|
|
178
|
-
constructor(inputs, outputs, opts) {
|
|
179
|
-
this.requiredIndices = [];
|
|
180
|
-
this.outputs = outputs;
|
|
181
|
-
this.opts = opts;
|
|
182
|
-
if (typeof opts.feePerByte !== 'bigint')
|
|
183
|
-
throw new Error(`Estimator: wrong feePerByte=${opts.feePerByte}, should be of type bigint but got ${typeof opts.feePerByte}.`);
|
|
184
|
-
// Dust stuff
|
|
185
|
-
// TODO: think about this more:
|
|
186
|
-
// - current dust filters tx which cannot be relayed by core
|
|
187
|
-
// - but actual dust meaning is 'can be this amount spent?'
|
|
188
|
-
// - dust contains full tx size. but we can use other inputs to pay for outputDust (and parially inputsDust)?
|
|
189
|
-
// - not sure if we can spent anything with feePerByte: 3. It will be relayed, but will it be mined?
|
|
190
|
-
// - for now it works exactly as bitcoin-core. But will create change/outputs which cannot be spent (reasonable).
|
|
191
|
-
// Number of bytes needed to create and spend a UTXO.
|
|
192
|
-
// https://github.com/bitcoin/bitcoin/blob/27a770b34b8f1dbb84760f442edb3e23a0c2420b/src/policy/policy.cpp#L28-L41
|
|
193
|
-
const inputsDust = 32 + 4 + 1 + 107 + 4; // NOTE: can be smaller for segwit tx?
|
|
194
|
-
const outputDust = 34; // NOTE: 'nSize = GetSerializeSize(txout)'
|
|
195
|
-
const dustBytes = opts.dust === undefined ? BigInt(inputsDust + outputDust) : opts.dust;
|
|
196
|
-
if (typeof dustBytes !== 'bigint') {
|
|
197
|
-
throw new Error(`Estimator: wrong dust=${opts.dust}, should be of type bigint but got ${typeof opts.dust}.`);
|
|
198
|
-
}
|
|
199
|
-
// 3 sat/vb is the default minimum fee rate used to calculate dust thresholds by bitcoin core.
|
|
200
|
-
// 3000 sat/kvb -> 3 sat/vb.
|
|
201
|
-
// https://github.com/bitcoin/bitcoin/blob/27a770b34b8f1dbb84760f442edb3e23a0c2420b/src/policy/policy.h#L55
|
|
202
|
-
const dustFee = opts.dustRelayFeeRate === undefined ? 3n : opts.dustRelayFeeRate;
|
|
203
|
-
if (typeof dustFee !== 'bigint') {
|
|
204
|
-
throw new Error(`Estimator: wrong dustRelayFeeRate=${opts.dustRelayFeeRate}, should be of type bigint but got ${typeof opts.dustRelayFeeRate}.`);
|
|
205
|
-
}
|
|
206
|
-
// Dust uses feePerbyte by default, but we allow separate dust fee if needed
|
|
207
|
-
this.dust = dustBytes * dustFee;
|
|
208
|
-
if (opts.requiredInputs !== undefined && !Array.isArray(opts.requiredInputs))
|
|
209
|
-
throw new Error(`Estimator: wrong required inputs=${opts.requiredInputs}`);
|
|
210
|
-
const network = opts.network || NETWORK;
|
|
211
|
-
let amount = 0n;
|
|
212
|
-
// Base weight: tx with outputs, no inputs
|
|
213
|
-
let baseWeight = 32;
|
|
214
|
-
for (const o of outputs) {
|
|
215
|
-
const script = getScript(o, opts, opts.network);
|
|
216
|
-
baseWeight += 32 + 4 * VarBytes.encode(script).length;
|
|
217
|
-
amount += o.amount;
|
|
218
|
-
}
|
|
219
|
-
if (typeof opts.changeAddress !== 'string')
|
|
220
|
-
throw new Error(`Estimator: wrong change address=${opts.changeAddress}`);
|
|
221
|
-
let changeWeight = baseWeight +
|
|
222
|
-
32 +
|
|
223
|
-
4 * VarBytes.encode(OutScript.encode(Address(network).decode(opts.changeAddress))).length;
|
|
224
|
-
baseWeight += 4 * CompactSizeLen.encode(outputs.length).length;
|
|
225
|
-
// If there a lot of outputs change can change fee
|
|
226
|
-
changeWeight += 4 * CompactSizeLen.encode(outputs.length + 1).length;
|
|
227
|
-
this.baseWeight = baseWeight;
|
|
228
|
-
this.changeWeight = changeWeight;
|
|
229
|
-
this.amount = amount;
|
|
230
|
-
const allInputs = Array.from(inputs);
|
|
231
|
-
if (opts.requiredInputs) {
|
|
232
|
-
for (let i = 0; i < opts.requiredInputs.length; i++)
|
|
233
|
-
this.requiredIndices.push(allInputs.push(opts.requiredInputs[i]) - 1);
|
|
234
|
-
}
|
|
235
|
-
const inputKeys = new Set();
|
|
236
|
-
this.normalizedInputs = allInputs.map((i) => {
|
|
237
|
-
const normalized = normalizeInput(i, undefined, undefined, opts.disableScriptCheck, opts.allowUnknown);
|
|
238
|
-
inputBeforeSign(normalized); // check fields
|
|
239
|
-
const key = `${hex.encode(normalized.txid)}:${normalized.index}`;
|
|
240
|
-
if (!opts.allowSameUtxo && inputKeys.has(key))
|
|
241
|
-
throw new Error(`Estimator: same input passed multiple times: ${key}`);
|
|
242
|
-
inputKeys.add(key);
|
|
243
|
-
const inputType = getInputType(normalized, opts.allowLegacyWitnessUtxo);
|
|
244
|
-
const prev = getPrevOut(normalized);
|
|
245
|
-
const estimate = estimateInput(inputType, normalized, this.opts);
|
|
246
|
-
const value = prev.amount - opts.feePerByte * BigInt(toVsize(estimate.weight)); // value = amount-fee
|
|
247
|
-
return { inputType, normalized, amount: prev.amount, value, estimate };
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
checkInputIdx(idx) {
|
|
251
|
-
if (!Number.isSafeInteger(idx) || 0 > idx || idx >= this.normalizedInputs.length)
|
|
252
|
-
throw new Error(`Wrong input index=${idx}`);
|
|
253
|
-
return idx;
|
|
254
|
-
}
|
|
255
|
-
sortIndices(indices) {
|
|
256
|
-
return indices.slice().sort((a, b) => {
|
|
257
|
-
const ai = this.normalizedInputs[this.checkInputIdx(a)];
|
|
258
|
-
const bi = this.normalizedInputs[this.checkInputIdx(b)];
|
|
259
|
-
const out = compareBytes(ai.normalized.txid, bi.normalized.txid);
|
|
260
|
-
if (out !== 0)
|
|
261
|
-
return out;
|
|
262
|
-
return ai.normalized.index - bi.normalized.index;
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
sortOutputs(outputs) {
|
|
266
|
-
const scripts = outputs.map((o) => getScript(o, this.opts, this.opts.network));
|
|
267
|
-
const indices = outputs.map((_, j) => j);
|
|
268
|
-
return indices.sort((a, b) => {
|
|
269
|
-
const aa = outputs[a].amount;
|
|
270
|
-
const ba = outputs[b].amount;
|
|
271
|
-
const out = _cmpBig(aa, ba);
|
|
272
|
-
if (out !== 0)
|
|
273
|
-
return out;
|
|
274
|
-
return compareBytes(scripts[a], scripts[b]);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
getSatoshi(weigth) {
|
|
278
|
-
return this.opts.feePerByte * BigInt(toVsize(weigth));
|
|
279
|
-
}
|
|
280
|
-
// Sort by value instead of amount
|
|
281
|
-
get biggest() {
|
|
282
|
-
return this.normalizedInputs
|
|
283
|
-
.map((_i, j) => j)
|
|
284
|
-
.sort((a, b) => _cmpBig(this.normalizedInputs[b].value, this.normalizedInputs[a].value));
|
|
285
|
-
}
|
|
286
|
-
get smallest() {
|
|
287
|
-
return this.biggest.reverse();
|
|
288
|
-
}
|
|
289
|
-
// These assume that UTXO array has historical order.
|
|
290
|
-
// Otherwise, we have no way to know which tx is oldest
|
|
291
|
-
// Explorers usually give UTXO in this order.
|
|
292
|
-
get oldest() {
|
|
293
|
-
return this.normalizedInputs.map((_i, j) => j);
|
|
294
|
-
}
|
|
295
|
-
get newest() {
|
|
296
|
-
return this.oldest.reverse();
|
|
297
|
-
}
|
|
298
|
-
// exact - like blackjack from coinselect.
|
|
299
|
-
// exact(biggest) will select one big utxo which is closer to targetValue+dust, if possible.
|
|
300
|
-
// If not, it will accumulate largest utxo until value is close to targetValue+dust.
|
|
301
|
-
accumulate(indices, exact = false, skipNegative = true, all = false) {
|
|
302
|
-
// TODO: how to handle change addresses?
|
|
303
|
-
// - cost of input
|
|
304
|
-
// - cost of change output (if input requires change)
|
|
305
|
-
// - cost of output spending
|
|
306
|
-
// Dust threshold should be significantly bigger, no point in
|
|
307
|
-
// creating an output, which cannot be spent.
|
|
308
|
-
// coinselect doesn't consider cost of output address for dust.
|
|
309
|
-
// Changing that can actually reduce privacy
|
|
310
|
-
let weight = this.opts.alwaysChange ? this.changeWeight : this.baseWeight;
|
|
311
|
-
let hasWitnesses = false;
|
|
312
|
-
let num = 0;
|
|
313
|
-
let inputsAmount = 0n;
|
|
314
|
-
const targetAmount = this.amount;
|
|
315
|
-
const res = new Set();
|
|
316
|
-
let fee;
|
|
317
|
-
for (const idx of this.requiredIndices) {
|
|
318
|
-
this.checkInputIdx(idx);
|
|
319
|
-
if (res.has(idx))
|
|
320
|
-
throw new Error('required input encountered multiple times'); // should not happen
|
|
321
|
-
const { estimate, amount } = this.normalizedInputs[idx];
|
|
322
|
-
let newWeight = weight + estimate.weight;
|
|
323
|
-
if (!hasWitnesses && estimate.hasWitnesses)
|
|
324
|
-
newWeight += 2; // enable witness if needed
|
|
325
|
-
const totalWeight = newWeight + 4 * CompactSizeLen.encode(num).length; // number of outputs can change weight
|
|
326
|
-
fee = this.getSatoshi(totalWeight);
|
|
327
|
-
weight = newWeight;
|
|
328
|
-
if (estimate.hasWitnesses)
|
|
329
|
-
hasWitnesses = true;
|
|
330
|
-
num++;
|
|
331
|
-
inputsAmount += amount;
|
|
332
|
-
res.add(idx);
|
|
333
|
-
// inputsAmount is enough to cover cost of tx
|
|
334
|
-
if (!all && targetAmount + fee <= inputsAmount && num >= this.requiredIndices.length)
|
|
335
|
-
return { indices: Array.from(res), fee, weight: totalWeight, total: inputsAmount };
|
|
336
|
-
}
|
|
337
|
-
for (const idx of indices) {
|
|
338
|
-
this.checkInputIdx(idx);
|
|
339
|
-
if (res.has(idx))
|
|
340
|
-
continue; // skip required inputs
|
|
341
|
-
const { estimate, amount, value } = this.normalizedInputs[idx];
|
|
342
|
-
let newWeight = weight + estimate.weight;
|
|
343
|
-
if (!hasWitnesses && estimate.hasWitnesses)
|
|
344
|
-
newWeight += 2; // enable witness if needed
|
|
345
|
-
const totalWeight = newWeight + 4 * CompactSizeLen.encode(num).length; // number of outputs can change weight
|
|
346
|
-
fee = this.getSatoshi(totalWeight);
|
|
347
|
-
// Best case scenario exact(biggest) -> we find biggest output, less than target+threshold
|
|
348
|
-
if (exact && amount + inputsAmount > targetAmount + fee + this.dust)
|
|
349
|
-
continue; // skip if added value is bigger than dust
|
|
350
|
-
// Negative: cost of using input is more than value provided (negative)
|
|
351
|
-
// By default 'blackjack' mode in coinselect doesn't use that, which means
|
|
352
|
-
// it will use negative output if sorted by 'smallest'
|
|
353
|
-
if (skipNegative && value <= 0n)
|
|
354
|
-
continue;
|
|
355
|
-
weight = newWeight;
|
|
356
|
-
if (estimate.hasWitnesses)
|
|
357
|
-
hasWitnesses = true;
|
|
358
|
-
num++;
|
|
359
|
-
inputsAmount += amount;
|
|
360
|
-
res.add(idx);
|
|
361
|
-
// inputsAmount is enough to cover cost of tx
|
|
362
|
-
if (!all && targetAmount + fee <= inputsAmount)
|
|
363
|
-
return { indices: Array.from(res), fee, weight: totalWeight, total: inputsAmount };
|
|
364
|
-
}
|
|
365
|
-
if (all) {
|
|
366
|
-
const newWeight = weight + 4 * CompactSizeLen.encode(num).length;
|
|
367
|
-
return { indices: Array.from(res), fee, weight: newWeight, total: inputsAmount };
|
|
368
|
-
}
|
|
369
|
-
return undefined;
|
|
370
|
-
}
|
|
371
|
-
// Works like coinselect default method
|
|
372
|
-
default() {
|
|
373
|
-
const { biggest } = this;
|
|
374
|
-
const exact = this.accumulate(biggest, true, false);
|
|
375
|
-
if (exact)
|
|
376
|
-
return exact;
|
|
377
|
-
return this.accumulate(biggest);
|
|
378
|
-
}
|
|
379
|
-
select(strategy) {
|
|
380
|
-
if (strategy === 'all') {
|
|
381
|
-
return this.accumulate(this.normalizedInputs.map((_, j) => j), false, true, true);
|
|
382
|
-
}
|
|
383
|
-
if (strategy === 'default')
|
|
384
|
-
return this.default();
|
|
385
|
-
const data = {
|
|
386
|
-
Oldest: () => this.oldest,
|
|
387
|
-
Newest: () => this.newest,
|
|
388
|
-
Smallest: () => this.smallest,
|
|
389
|
-
Biggest: () => this.biggest,
|
|
390
|
-
};
|
|
391
|
-
if (strategy.startsWith('exact')) {
|
|
392
|
-
const [exactData, left] = strategy.slice(5).split('/');
|
|
393
|
-
if (!data[exactData])
|
|
394
|
-
throw new Error(`Estimator.select: wrong strategy=${strategy}`);
|
|
395
|
-
strategy = left;
|
|
396
|
-
const exact = this.accumulate(data[exactData](), true, true);
|
|
397
|
-
if (exact)
|
|
398
|
-
return exact;
|
|
399
|
-
}
|
|
400
|
-
if (strategy.startsWith('accum')) {
|
|
401
|
-
const accumData = strategy.slice(5);
|
|
402
|
-
if (!data[accumData])
|
|
403
|
-
throw new Error(`Estimator.select: wrong strategy=${strategy}`);
|
|
404
|
-
return this.accumulate(data[accumData]());
|
|
405
|
-
}
|
|
406
|
-
throw new Error(`Estimator.select: wrong strategy=${strategy}`);
|
|
407
|
-
}
|
|
408
|
-
result(strategy) {
|
|
409
|
-
const s = this.select(strategy);
|
|
410
|
-
if (!s)
|
|
411
|
-
return;
|
|
412
|
-
const { indices, weight, total } = s;
|
|
413
|
-
let needChange = this.opts.alwaysChange;
|
|
414
|
-
const changeWeight = this.opts.alwaysChange
|
|
415
|
-
? weight
|
|
416
|
-
: weight + (this.changeWeight - this.baseWeight);
|
|
417
|
-
const changeFee = this.getSatoshi(changeWeight);
|
|
418
|
-
let fee = s.fee;
|
|
419
|
-
const change = total - this.amount - changeFee;
|
|
420
|
-
if (change > this.dust)
|
|
421
|
-
needChange = true;
|
|
422
|
-
let inputs = indices;
|
|
423
|
-
let outputs = Array.from(this.outputs);
|
|
424
|
-
if (needChange) {
|
|
425
|
-
fee = changeFee;
|
|
426
|
-
// this shouldn't happen!
|
|
427
|
-
if (change < 0n)
|
|
428
|
-
throw new Error(`Estimator.result: negative change=${change}`);
|
|
429
|
-
outputs.push({ address: this.opts.changeAddress, amount: change });
|
|
430
|
-
}
|
|
431
|
-
if (this.opts.bip69) {
|
|
432
|
-
inputs = this.sortIndices(inputs);
|
|
433
|
-
outputs = this.sortOutputs(outputs).map((i) => outputs[i]);
|
|
434
|
-
}
|
|
435
|
-
const res = {
|
|
436
|
-
inputs: inputs.map((i) => this.normalizedInputs[i].normalized),
|
|
437
|
-
outputs,
|
|
438
|
-
fee,
|
|
439
|
-
weight: this.opts.alwaysChange ? s.weight : changeWeight,
|
|
440
|
-
change: !!needChange,
|
|
441
|
-
};
|
|
442
|
-
let tx;
|
|
443
|
-
if (this.opts.createTx) {
|
|
444
|
-
const { inputs, outputs } = res;
|
|
445
|
-
tx = new Transaction(this.opts);
|
|
446
|
-
for (const i of inputs)
|
|
447
|
-
tx.addInput(i);
|
|
448
|
-
for (const o of outputs)
|
|
449
|
-
tx.addOutput({ ...o, script: getScript(o, this.opts, this.opts.network) });
|
|
450
|
-
}
|
|
451
|
-
return Object.assign(res, { tx });
|
|
452
|
-
// return { ...res, tx: tx };
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
export function selectUTXO(inputs, outputs, strategy, opts) {
|
|
456
|
-
// Defaults: do we want bip69 by default?
|
|
457
|
-
const _opts = { createTx: true, bip69: true, ...opts };
|
|
458
|
-
const est = new _Estimator(inputs, outputs, _opts);
|
|
459
|
-
return est.result(strategy);
|
|
460
|
-
}
|
|
461
|
-
//# sourceMappingURL=utxo.js.map
|
package/esm/utxo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utxo.js","sourceRoot":"","sources":["../src/utxo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,OAAO,EAAqB,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/F,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EACL,aAAa,EACb,WAAW,EAEX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,cAAc,EACd,OAAO,GACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,OAAO,EACP,IAAI,EACJ,uBAAuB,EACvB,YAAY,EACZ,UAAU,EACV,OAAO,EACP,MAAM,EACN,cAAc,GACf,MAAM,YAAY,CAAC;AAcpB,MAAM,cAAc,GAAG,CAAC,IAAQ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AAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC"}
|
package/src/_type_test.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { secp256k1 as secp } from '@noble/curves/secp256k1';
|
|
2
|
-
import { hex } from '@scure/base';
|
|
3
|
-
import * as btc from './index.ts';
|
|
4
|
-
|
|
5
|
-
const privKey1 = hex.decode('0101010101010101010101010101010101010101010101010101010101010101');
|
|
6
|
-
const P1 = secp.getPublicKey(privKey1, true);
|
|
7
|
-
|
|
8
|
-
const wpkh = btc.p2wpkh(P1);
|
|
9
|
-
|
|
10
|
-
const tx = new btc.Transaction();
|
|
11
|
-
|
|
12
|
-
// Basic input test
|
|
13
|
-
tx.addInput({
|
|
14
|
-
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
15
|
-
index: 0,
|
|
16
|
-
...wpkh,
|
|
17
|
-
finalScriptSig: Uint8Array.of(),
|
|
18
|
-
sequence: 1,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Doesn't force any fields on input addition (only on sign)
|
|
22
|
-
tx.addInput({
|
|
23
|
-
sequence: 1,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
tx.updateInput(0, {
|
|
27
|
-
sequence: 1,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const nonWitnessUtxo =
|
|
31
|
-
'0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000';
|
|
32
|
-
const nonWitnessUtxoB = hex.decode(nonWitnessUtxo);
|
|
33
|
-
|
|
34
|
-
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxo });
|
|
35
|
-
tx.updateInput(0, { nonWitnessUtxo: nonWitnessUtxoB });
|
|
36
|
-
tx.addInput({
|
|
37
|
-
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
38
|
-
index: 0,
|
|
39
|
-
nonWitnessUtxo: nonWitnessUtxo,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
tx.addInput({
|
|
43
|
-
txid: hex.decode('0af50a00a22f74ece24c12cd667c290d3a35d48124a69f4082700589172a3aa2'),
|
|
44
|
-
index: 0,
|
|
45
|
-
nonWitnessUtxo: nonWitnessUtxoB,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Should fail!
|
|
49
|
-
// tx.updateInput(0, {
|
|
50
|
-
// nonWitnessUtxo: 1,
|
|
51
|
-
// });
|
|
52
|
-
// Outputs
|
|
53
|
-
tx.addOutput({ amount: 123n });
|
|
54
|
-
// should fail
|
|
55
|
-
// tx.updateOutput(0, { amount: '1' });
|
|
56
|
-
// tx.updateOutput(0, { amount: 1 });
|
|
57
|
-
// should fail
|
|
58
|
-
// tx.addOutput({ amount: '123' });
|
|
59
|
-
// tx.addOutput({ amount: 123 });
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < tx.inputsLength; i++) {
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
console.log('I', tx.getInput(i));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
for (let i = 0; i < tx.outputsLength; i++) {
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
console.log('O', tx.getOutput(i));
|
|
69
|
-
}
|
package/src/package.json
DELETED