@scure/btc-signer 1.2.2 → 1.3.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 +19 -3
- package/lib/_type_test.d.ts +2 -0
- package/lib/_type_test.d.ts.map +1 -0
- package/lib/_type_test.js +59 -0
- package/lib/_type_test.js.map +1 -0
- package/lib/esm/_type_test.js +57 -0
- package/lib/esm/_type_test.js.map +1 -0
- package/lib/esm/index.js +13 -3007
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/payment.js +681 -0
- package/lib/esm/payment.js.map +1 -0
- package/lib/esm/psbt.js +441 -0
- package/lib/esm/psbt.js.map +1 -0
- package/lib/esm/script.js +347 -0
- package/lib/esm/script.js.map +1 -0
- package/lib/esm/transaction.js +1013 -0
- package/lib/esm/transaction.js.map +1 -0
- package/lib/esm/utils.js +115 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/esm/utxo.js +491 -0
- package/lib/esm/utxo.js.map +1 -0
- package/lib/index.d.ts +18 -1439
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +53 -3042
- package/lib/index.js.map +1 -0
- package/lib/payment.d.ts +167 -0
- package/lib/payment.d.ts.map +1 -0
- package/lib/payment.js +704 -0
- package/lib/payment.js.map +1 -0
- package/lib/psbt.d.ts +834 -0
- package/lib/psbt.d.ts.map +1 -0
- package/lib/psbt.js +446 -0
- package/lib/psbt.js.map +1 -0
- package/lib/script.d.ts +154 -0
- package/lib/script.d.ts.map +1 -0
- package/lib/script.js +353 -0
- package/lib/script.js.map +1 -0
- package/lib/transaction.d.ts +223 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +1022 -0
- package/lib/transaction.js.map +1 -0
- package/lib/utils.d.ts +30 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +128 -0
- package/lib/utils.js.map +1 -0
- package/lib/utxo.d.ts +251 -0
- package/lib/utxo.d.ts.map +1 -0
- package/lib/utxo.js +501 -0
- package/lib/utxo.js.map +1 -0
- package/package.json +40 -10
- package/src/_type_test.ts +69 -0
- package/src/index.ts +28 -0
- package/src/package.json +3 -0
- package/src/payment.ts +749 -0
- package/src/psbt.ts +512 -0
- package/src/script.ts +236 -0
- package/src/transaction.ts +1065 -0
- package/src/utils.ts +118 -0
- package/src/utxo.ts +517 -0
- package/index.ts +0 -3067
package/lib/esm/utxo.js
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { hex } from '@scure/base';
|
|
2
|
+
import * as P from 'micro-packed';
|
|
3
|
+
import { Address, OutScript, checkScript } from './payment.js';
|
|
4
|
+
import * as psbt from './psbt.js';
|
|
5
|
+
import { CompactSizeLen, RawTx, RawWitness, Script, VarBytes } from './script.js';
|
|
6
|
+
import { DEFAULT_SEQUENCE, inputBeforeSign, SignatureHash, Transaction, } from './transaction.js'; // circular
|
|
7
|
+
import { NETWORK, compareBytes, isBytes, TAPROOT_UNSPENDABLE_KEY, sha256 } from './utils.js';
|
|
8
|
+
// Normalizes input
|
|
9
|
+
export function getPrevOut(input) {
|
|
10
|
+
if (input.nonWitnessUtxo) {
|
|
11
|
+
if (input.index === undefined)
|
|
12
|
+
throw new Error('Unknown input index');
|
|
13
|
+
return input.nonWitnessUtxo.outputs[input.index];
|
|
14
|
+
}
|
|
15
|
+
else if (input.witnessUtxo)
|
|
16
|
+
return input.witnessUtxo;
|
|
17
|
+
else
|
|
18
|
+
throw new Error('Cannot find previous output info');
|
|
19
|
+
}
|
|
20
|
+
export function normalizeInput(i, cur, allowedFields, disableScriptCheck = false) {
|
|
21
|
+
let { nonWitnessUtxo, txid } = i;
|
|
22
|
+
// String support for common fields. We usually prefer Uint8Array to avoid errors
|
|
23
|
+
// like hex looking string accidentally passed, however, in case of nonWitnessUtxo
|
|
24
|
+
// it is better to expect string, since constructing this complex object will be
|
|
25
|
+
// difficult for user
|
|
26
|
+
if (typeof nonWitnessUtxo === 'string')
|
|
27
|
+
nonWitnessUtxo = hex.decode(nonWitnessUtxo);
|
|
28
|
+
if (isBytes(nonWitnessUtxo))
|
|
29
|
+
nonWitnessUtxo = RawTx.decode(nonWitnessUtxo);
|
|
30
|
+
if (!('nonWitnessUtxo' in i) && nonWitnessUtxo === undefined)
|
|
31
|
+
nonWitnessUtxo = cur?.nonWitnessUtxo;
|
|
32
|
+
if (typeof txid === 'string')
|
|
33
|
+
txid = hex.decode(txid);
|
|
34
|
+
// TODO: if we have nonWitnessUtxo, we can extract txId from here
|
|
35
|
+
if (txid === undefined)
|
|
36
|
+
txid = cur?.txid;
|
|
37
|
+
let res = { ...cur, ...i, nonWitnessUtxo, txid };
|
|
38
|
+
if (!('nonWitnessUtxo' in i) && res.nonWitnessUtxo === undefined)
|
|
39
|
+
delete res.nonWitnessUtxo;
|
|
40
|
+
if (res.sequence === undefined)
|
|
41
|
+
res.sequence = DEFAULT_SEQUENCE;
|
|
42
|
+
if (res.tapMerkleRoot === null)
|
|
43
|
+
delete res.tapMerkleRoot;
|
|
44
|
+
res = psbt.mergeKeyMap(psbt.PSBTInput, res, cur, allowedFields);
|
|
45
|
+
psbt.PSBTInputCoder.encode(res); // Validates that everything is correct at this point
|
|
46
|
+
let prevOut;
|
|
47
|
+
if (res.nonWitnessUtxo && res.index !== undefined)
|
|
48
|
+
prevOut = res.nonWitnessUtxo.outputs[res.index];
|
|
49
|
+
else if (res.witnessUtxo)
|
|
50
|
+
prevOut = res.witnessUtxo;
|
|
51
|
+
if (prevOut && !disableScriptCheck)
|
|
52
|
+
checkScript(prevOut && prevOut.script, res.redeemScript, res.witnessScript);
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
export function getInputType(input, allowLegacyWitnessUtxo = false) {
|
|
56
|
+
let txType = 'legacy';
|
|
57
|
+
let defaultSighash = SignatureHash.ALL;
|
|
58
|
+
const prevOut = getPrevOut(input);
|
|
59
|
+
const first = OutScript.decode(prevOut.script);
|
|
60
|
+
let type = first.type;
|
|
61
|
+
let cur = first;
|
|
62
|
+
const stack = [first];
|
|
63
|
+
if (first.type === 'tr') {
|
|
64
|
+
defaultSighash = SignatureHash.DEFAULT;
|
|
65
|
+
return {
|
|
66
|
+
txType: 'taproot',
|
|
67
|
+
type: 'tr',
|
|
68
|
+
last: first,
|
|
69
|
+
lastScript: prevOut.script,
|
|
70
|
+
defaultSighash,
|
|
71
|
+
sighash: input.sighashType || defaultSighash,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (first.type === 'wpkh' || first.type === 'wsh')
|
|
76
|
+
txType = 'segwit';
|
|
77
|
+
if (first.type === 'sh') {
|
|
78
|
+
if (!input.redeemScript)
|
|
79
|
+
throw new Error('inputType: sh without redeemScript');
|
|
80
|
+
let child = OutScript.decode(input.redeemScript);
|
|
81
|
+
if (child.type === 'wpkh' || child.type === 'wsh')
|
|
82
|
+
txType = 'segwit';
|
|
83
|
+
stack.push(child);
|
|
84
|
+
cur = child;
|
|
85
|
+
type += `-${child.type}`;
|
|
86
|
+
}
|
|
87
|
+
// wsh can be inside sh
|
|
88
|
+
if (cur.type === 'wsh') {
|
|
89
|
+
if (!input.witnessScript)
|
|
90
|
+
throw new Error('inputType: wsh without witnessScript');
|
|
91
|
+
let child = OutScript.decode(input.witnessScript);
|
|
92
|
+
if (child.type === 'wsh')
|
|
93
|
+
txType = 'segwit';
|
|
94
|
+
stack.push(child);
|
|
95
|
+
cur = child;
|
|
96
|
+
type += `-${child.type}`;
|
|
97
|
+
}
|
|
98
|
+
const last = stack[stack.length - 1];
|
|
99
|
+
if (last.type === 'sh' || last.type === 'wsh')
|
|
100
|
+
throw new Error('inputType: sh/wsh cannot be terminal type');
|
|
101
|
+
const lastScript = OutScript.encode(last);
|
|
102
|
+
const res = {
|
|
103
|
+
type,
|
|
104
|
+
txType,
|
|
105
|
+
last,
|
|
106
|
+
lastScript,
|
|
107
|
+
defaultSighash,
|
|
108
|
+
sighash: input.sighashType || defaultSighash,
|
|
109
|
+
};
|
|
110
|
+
if (txType === 'legacy' && !allowLegacyWitnessUtxo && !input.nonWitnessUtxo) {
|
|
111
|
+
throw new Error(`Transaction/sign: legacy input without nonWitnessUtxo, can result in attack that forces paying higher fees. Pass allowLegacyWitnessUtxo=true, if you sure`);
|
|
112
|
+
}
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export const toVsize = (weight) => Math.ceil(weight / 4);
|
|
117
|
+
function estimateInput(inputType, input, opts) {
|
|
118
|
+
let script = P.EMPTY, witness;
|
|
119
|
+
// schnorr sig is always 64 bytes. except for cases when sighash is not default!
|
|
120
|
+
if (inputType.txType === 'taproot') {
|
|
121
|
+
const SCHNORR_SIG_SIZE = inputType.sighash !== SignatureHash.DEFAULT ? 65 : 64;
|
|
122
|
+
if (input.tapInternalKey && !P.equalBytes(input.tapInternalKey, TAPROOT_UNSPENDABLE_KEY)) {
|
|
123
|
+
witness = [new Uint8Array(SCHNORR_SIG_SIZE)];
|
|
124
|
+
}
|
|
125
|
+
else if (input.tapLeafScript) {
|
|
126
|
+
// If user want to select specific leaf (which can signed, it is possible to remove all other leafs manually);
|
|
127
|
+
// Sort leafs by control block length.
|
|
128
|
+
const leafs = input.tapLeafScript.sort((a, b) => psbt.TaprootControlBlock.encode(a[0]).length -
|
|
129
|
+
psbt.TaprootControlBlock.encode(b[0]).length);
|
|
130
|
+
for (const [cb, _script] of leafs) {
|
|
131
|
+
// Last byte is version
|
|
132
|
+
const script = _script.slice(0, -1);
|
|
133
|
+
const outScript = OutScript.decode(script);
|
|
134
|
+
let signatures = [];
|
|
135
|
+
if (outScript.type === 'tr_ms') {
|
|
136
|
+
const m = outScript.m;
|
|
137
|
+
for (let i = 0; i < m; i++)
|
|
138
|
+
signatures.push(new Uint8Array(SCHNORR_SIG_SIZE));
|
|
139
|
+
const n = outScript.pubkeys.length - m;
|
|
140
|
+
for (let i = 0; i < n; i++)
|
|
141
|
+
signatures.push(P.EMPTY);
|
|
142
|
+
}
|
|
143
|
+
else if (outScript.type === 'tr_ns') {
|
|
144
|
+
for (const _pub of outScript.pubkeys)
|
|
145
|
+
signatures.push(new Uint8Array(SCHNORR_SIG_SIZE));
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
throw new Error('Finalize: Unknown tapLeafScript');
|
|
149
|
+
// Witness is stack, so last element will be used first
|
|
150
|
+
witness = signatures.reverse().concat([script, psbt.TaprootControlBlock.encode(cb)]);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
throw new Error('estimateInput/taproot: unknown input');
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// It is possible to grind signatures until it has minimal size (but changing fee value +N satoshi),
|
|
159
|
+
// which will make estimations exact. But will be very hard for multi sig (need to make sure all signatures has small size).
|
|
160
|
+
const SIG_SIZE = 72; // Maximum size of signatures
|
|
161
|
+
const PUB_KEY_SIZE = 33;
|
|
162
|
+
let inputScript = P.EMPTY;
|
|
163
|
+
let inputWitness = [];
|
|
164
|
+
if (inputType.last.type === 'ms') {
|
|
165
|
+
const m = inputType.last.m;
|
|
166
|
+
const sig = [0];
|
|
167
|
+
for (let i = 0; i < m; i++)
|
|
168
|
+
sig.push(new Uint8Array(SIG_SIZE));
|
|
169
|
+
inputScript = Script.encode(sig);
|
|
170
|
+
}
|
|
171
|
+
else if (inputType.last.type === 'pk') {
|
|
172
|
+
// 71 sig + 1 sighash
|
|
173
|
+
inputScript = Script.encode([new Uint8Array(SIG_SIZE)]);
|
|
174
|
+
}
|
|
175
|
+
else if (inputType.last.type === 'pkh') {
|
|
176
|
+
inputScript = Script.encode([new Uint8Array(SIG_SIZE), new Uint8Array(PUB_KEY_SIZE)]);
|
|
177
|
+
}
|
|
178
|
+
else if (inputType.last.type === 'wpkh') {
|
|
179
|
+
inputScript = P.EMPTY;
|
|
180
|
+
inputWitness = [new Uint8Array(SIG_SIZE), new Uint8Array(PUB_KEY_SIZE)];
|
|
181
|
+
}
|
|
182
|
+
else if (inputType.last.type === 'unknown' && !opts.allowUnknownInputs)
|
|
183
|
+
throw new Error('Unknown inputs not allowed');
|
|
184
|
+
if (inputType.type.includes('wsh-')) {
|
|
185
|
+
// P2WSH
|
|
186
|
+
if (inputScript.length && inputType.lastScript.length) {
|
|
187
|
+
inputWitness = Script.decode(inputScript).map((i) => {
|
|
188
|
+
if (i === 0)
|
|
189
|
+
return P.EMPTY;
|
|
190
|
+
if (isBytes(i))
|
|
191
|
+
return i;
|
|
192
|
+
throw new Error(`Wrong witness op=${i}`);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
inputWitness = inputWitness.concat(inputType.lastScript);
|
|
196
|
+
}
|
|
197
|
+
if (inputType.txType === 'segwit')
|
|
198
|
+
witness = inputWitness;
|
|
199
|
+
if (inputType.type.startsWith('sh-wsh-')) {
|
|
200
|
+
script = Script.encode([Script.encode([0, new Uint8Array(sha256.outputLen)])]);
|
|
201
|
+
}
|
|
202
|
+
else if (inputType.type.startsWith('sh-')) {
|
|
203
|
+
script = Script.encode([...Script.decode(inputScript), inputType.lastScript]);
|
|
204
|
+
}
|
|
205
|
+
else if (inputType.type.startsWith('wsh-')) {
|
|
206
|
+
}
|
|
207
|
+
else if (inputType.txType !== 'segwit')
|
|
208
|
+
script = inputScript;
|
|
209
|
+
}
|
|
210
|
+
let weight = 160 + 4 * VarBytes.encode(script).length;
|
|
211
|
+
let hasWitnesses = false;
|
|
212
|
+
if (witness) {
|
|
213
|
+
weight += RawWitness.encode(witness).length;
|
|
214
|
+
hasWitnesses = true;
|
|
215
|
+
}
|
|
216
|
+
return { weight, hasWitnesses };
|
|
217
|
+
}
|
|
218
|
+
// Exported for tests, internal method
|
|
219
|
+
export const _cmpBig = (a, b) => {
|
|
220
|
+
const n = a - b;
|
|
221
|
+
if (n < 0n)
|
|
222
|
+
return -1;
|
|
223
|
+
else if (n > 0n)
|
|
224
|
+
return 1;
|
|
225
|
+
return 0;
|
|
226
|
+
};
|
|
227
|
+
function getScript(o, opts = {}, network = NETWORK) {
|
|
228
|
+
let script;
|
|
229
|
+
if ('script' in o && o.script instanceof Uint8Array) {
|
|
230
|
+
script = o.script;
|
|
231
|
+
}
|
|
232
|
+
if ('address' in o) {
|
|
233
|
+
if (typeof o.address !== 'string')
|
|
234
|
+
throw new Error(`Estimator: wrong output address=${o.address}`);
|
|
235
|
+
script = OutScript.encode(Address(network).decode(o.address));
|
|
236
|
+
}
|
|
237
|
+
if (!script)
|
|
238
|
+
throw new Error('Estimator: wrong output script');
|
|
239
|
+
if (typeof o.amount !== 'bigint')
|
|
240
|
+
throw new Error(`Estimator: wrong output amount=${o.amount}`);
|
|
241
|
+
if (script && !opts.allowUnknownOutputs && OutScript.decode(script).type === 'unknown') {
|
|
242
|
+
throw new Error('Estimator: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure');
|
|
243
|
+
}
|
|
244
|
+
if (!opts.disableScriptCheck)
|
|
245
|
+
checkScript(script);
|
|
246
|
+
return script;
|
|
247
|
+
}
|
|
248
|
+
// class, because we need to re-use normalized inputs, instead of parsing each time
|
|
249
|
+
// internal stuff, exported for tests only
|
|
250
|
+
export class _Estimator {
|
|
251
|
+
constructor(inputs, outputs, opts) {
|
|
252
|
+
this.inputs = inputs;
|
|
253
|
+
this.outputs = outputs;
|
|
254
|
+
this.opts = opts;
|
|
255
|
+
// https://github.com/bitcoin/bitcoin/blob/f90603ac6d24f5263649675d51233f1fce8b2ecd/src/policy/policy.cpp#L44
|
|
256
|
+
// 32 + 4 + 1 + 107 + 4
|
|
257
|
+
// Dust used in accumExact + change address algo
|
|
258
|
+
// - change address: can be smaller for segwit
|
|
259
|
+
// - accumExact: ???
|
|
260
|
+
this.dust = 148n; // compat with coinselect
|
|
261
|
+
if (typeof opts.feePerByte !== 'bigint')
|
|
262
|
+
throw new Error(`Estimator: wrong feePerByte=${opts.feePerByte}`);
|
|
263
|
+
if (opts.dust) {
|
|
264
|
+
if (typeof opts.dust !== 'bigint')
|
|
265
|
+
throw new Error(`Estimator: wrong dust=${opts.dust}`);
|
|
266
|
+
this.dust = opts.dust;
|
|
267
|
+
}
|
|
268
|
+
const network = opts.network || NETWORK;
|
|
269
|
+
let amount = 0n;
|
|
270
|
+
// Base weight: tx with outputs, no inputs
|
|
271
|
+
let baseWeight = 32;
|
|
272
|
+
for (const o of outputs) {
|
|
273
|
+
const script = getScript(o, opts, opts.network);
|
|
274
|
+
baseWeight += 32 + 4 * VarBytes.encode(script).length;
|
|
275
|
+
amount += o.amount;
|
|
276
|
+
}
|
|
277
|
+
if (typeof opts.changeAddress !== 'string')
|
|
278
|
+
throw new Error(`Estimator: wrong change address=${opts.changeAddress}`);
|
|
279
|
+
let changeWeight = baseWeight +
|
|
280
|
+
32 +
|
|
281
|
+
4 * VarBytes.encode(OutScript.encode(Address(network).decode(opts.changeAddress))).length;
|
|
282
|
+
baseWeight += 4 * CompactSizeLen.encode(outputs.length).length;
|
|
283
|
+
// If there a lot of outputs change can change fee
|
|
284
|
+
changeWeight += 4 * CompactSizeLen.encode(outputs.length + 1).length;
|
|
285
|
+
this.baseWeight = baseWeight;
|
|
286
|
+
this.changeWeight = changeWeight;
|
|
287
|
+
this.amount = amount;
|
|
288
|
+
this.normalizedInputs = this.inputs.map((i) => {
|
|
289
|
+
const normalized = normalizeInput(i, undefined, undefined, opts.disableScriptCheck);
|
|
290
|
+
inputBeforeSign(normalized); // check fields
|
|
291
|
+
const inputType = getInputType(normalized, opts.allowLegacyWitnessUtxo);
|
|
292
|
+
const prev = getPrevOut(normalized);
|
|
293
|
+
const estimate = estimateInput(inputType, normalized, this.opts);
|
|
294
|
+
const value = prev.amount - opts.feePerByte * BigInt(toVsize(estimate.weight)); // value = amount-fee
|
|
295
|
+
return { inputType, normalized, amount: prev.amount, value, estimate };
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
checkInputIdx(idx) {
|
|
299
|
+
if (!Number.isSafeInteger(idx) || 0 > idx || idx >= this.inputs.length)
|
|
300
|
+
throw new Error(`Wrong input index=${idx}`);
|
|
301
|
+
return idx;
|
|
302
|
+
}
|
|
303
|
+
sortIndices(indices) {
|
|
304
|
+
return indices.slice().sort((a, b) => {
|
|
305
|
+
const ai = this.normalizedInputs[this.checkInputIdx(a)];
|
|
306
|
+
const bi = this.normalizedInputs[this.checkInputIdx(b)];
|
|
307
|
+
const out = compareBytes(ai.normalized.txid, bi.normalized.txid);
|
|
308
|
+
if (out !== 0)
|
|
309
|
+
return out;
|
|
310
|
+
return ai.normalized.index - bi.normalized.index;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
sortOutputs(outputs) {
|
|
314
|
+
const scripts = outputs.map((o) => getScript(o, this.opts, this.opts.network));
|
|
315
|
+
const indices = outputs.map((_, j) => j);
|
|
316
|
+
return indices.sort((a, b) => {
|
|
317
|
+
const aa = outputs[a].amount;
|
|
318
|
+
const ba = outputs[b].amount;
|
|
319
|
+
const out = _cmpBig(aa, ba);
|
|
320
|
+
if (out !== 0)
|
|
321
|
+
return out;
|
|
322
|
+
return compareBytes(scripts[a], scripts[b]);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
getSatoshi(weigth) {
|
|
326
|
+
return this.opts.feePerByte * BigInt(toVsize(weigth));
|
|
327
|
+
}
|
|
328
|
+
// Sort by value instead of amount
|
|
329
|
+
get biggest() {
|
|
330
|
+
return this.inputs
|
|
331
|
+
.map((_i, j) => j)
|
|
332
|
+
.sort((a, b) => _cmpBig(this.normalizedInputs[b].value, this.normalizedInputs[a].value));
|
|
333
|
+
}
|
|
334
|
+
get smallest() {
|
|
335
|
+
return this.biggest.reverse();
|
|
336
|
+
}
|
|
337
|
+
// These assume that UTXO array has historical order.
|
|
338
|
+
// Otherwise, we have no way to know which tx is oldest
|
|
339
|
+
// Explorers usually give UTXO in this order.
|
|
340
|
+
get oldest() {
|
|
341
|
+
return this.inputs.map((_i, j) => j);
|
|
342
|
+
}
|
|
343
|
+
get newest() {
|
|
344
|
+
return this.oldest.reverse();
|
|
345
|
+
}
|
|
346
|
+
// exact - like blackjack from coinselect.
|
|
347
|
+
// exact(biggest) will select one big utxo which is closer to targetValue+dust, if possible.
|
|
348
|
+
// If not, it will accumulate largest utxo until value is close to targetValue+dust.
|
|
349
|
+
accumulate(indices, exact = false, skipNegative = true, all = false) {
|
|
350
|
+
const { feePerByte } = this.opts;
|
|
351
|
+
// TODO: how to handle change addresses?
|
|
352
|
+
// - cost of input
|
|
353
|
+
// - cost of change output (if input requires change)
|
|
354
|
+
// - cost of output spending
|
|
355
|
+
// Dust threshold should be significantly bigger, no point in
|
|
356
|
+
// creating an output, which cannot be spent.
|
|
357
|
+
// coinselect doesn't consider cost of output address for dust.
|
|
358
|
+
// Changing that can actually reduce privacy
|
|
359
|
+
let weight = this.opts.alwaysChange ? this.changeWeight : this.baseWeight;
|
|
360
|
+
let hasWitnesses = false;
|
|
361
|
+
let num = 0;
|
|
362
|
+
let inputsAmount = 0n;
|
|
363
|
+
const targetAmount = this.amount;
|
|
364
|
+
const res = [];
|
|
365
|
+
let fee;
|
|
366
|
+
for (const idx of indices) {
|
|
367
|
+
this.checkInputIdx(idx);
|
|
368
|
+
const { estimate, amount, value } = this.normalizedInputs[idx];
|
|
369
|
+
let newWeight = weight + estimate.weight;
|
|
370
|
+
if (!hasWitnesses && estimate.hasWitnesses)
|
|
371
|
+
newWeight += 2; // enable witness if needed
|
|
372
|
+
const totalWeight = newWeight + 4 * CompactSizeLen.encode(num).length; // number of outputs can change weight
|
|
373
|
+
fee = this.getSatoshi(totalWeight);
|
|
374
|
+
// Best case scenario exact(biggest) -> we find biggest output, less than target+threshold
|
|
375
|
+
if (exact) {
|
|
376
|
+
const dust = this.dust * feePerByte;
|
|
377
|
+
// skip if added value is bigger than dust
|
|
378
|
+
if (amount + inputsAmount > targetAmount + fee + dust)
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
// Negative: cost of using input is more than value provided (negative)
|
|
382
|
+
// By default 'blackjack' mode in coinselect doesn't use that, which means
|
|
383
|
+
// it will use negative output if sorted by 'smallest'
|
|
384
|
+
if (skipNegative && value <= 0n)
|
|
385
|
+
continue;
|
|
386
|
+
weight = newWeight;
|
|
387
|
+
if (estimate.hasWitnesses)
|
|
388
|
+
hasWitnesses = true;
|
|
389
|
+
num++;
|
|
390
|
+
inputsAmount += amount;
|
|
391
|
+
res.push(idx);
|
|
392
|
+
// inputsAmount is enough to cover cost of tx
|
|
393
|
+
if (!all && targetAmount + fee < inputsAmount)
|
|
394
|
+
return { indices: res, fee, weight: totalWeight, total: inputsAmount };
|
|
395
|
+
}
|
|
396
|
+
if (all) {
|
|
397
|
+
const newWeight = weight + 4 * CompactSizeLen.encode(num).length;
|
|
398
|
+
return { indices: res, fee, weight: newWeight, total: inputsAmount };
|
|
399
|
+
}
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
// Works like coinselect default method
|
|
403
|
+
default() {
|
|
404
|
+
const { biggest } = this;
|
|
405
|
+
const exact = this.accumulate(biggest, true, false);
|
|
406
|
+
if (exact)
|
|
407
|
+
return exact;
|
|
408
|
+
return this.accumulate(biggest);
|
|
409
|
+
}
|
|
410
|
+
select(strategy) {
|
|
411
|
+
if (strategy === 'all') {
|
|
412
|
+
return this.accumulate(this.inputs.map((_, j) => j), false, true, true);
|
|
413
|
+
}
|
|
414
|
+
if (strategy === 'default')
|
|
415
|
+
return this.default();
|
|
416
|
+
const data = {
|
|
417
|
+
Oldest: () => this.oldest,
|
|
418
|
+
Newest: () => this.newest,
|
|
419
|
+
Smallest: () => this.smallest,
|
|
420
|
+
Biggest: () => this.biggest,
|
|
421
|
+
};
|
|
422
|
+
if (strategy.startsWith('exact')) {
|
|
423
|
+
const [exactData, left] = strategy.slice(5).split('/');
|
|
424
|
+
if (!data[exactData])
|
|
425
|
+
throw new Error(`Estimator.select: wrong strategy=${strategy}`);
|
|
426
|
+
strategy = left;
|
|
427
|
+
const exact = this.accumulate(data[exactData](), true, true);
|
|
428
|
+
if (exact)
|
|
429
|
+
return exact;
|
|
430
|
+
}
|
|
431
|
+
if (strategy.startsWith('accum')) {
|
|
432
|
+
const accumData = strategy.slice(5);
|
|
433
|
+
if (!data[accumData])
|
|
434
|
+
throw new Error(`Estimator.select: wrong strategy=${strategy}`);
|
|
435
|
+
return this.accumulate(data[accumData]());
|
|
436
|
+
}
|
|
437
|
+
throw new Error(`Estimator.select: wrong strategy=${strategy}`);
|
|
438
|
+
}
|
|
439
|
+
result(strategy) {
|
|
440
|
+
const s = this.select(strategy);
|
|
441
|
+
if (!s)
|
|
442
|
+
return;
|
|
443
|
+
const { indices, weight, total } = s;
|
|
444
|
+
let needChange = this.opts.alwaysChange;
|
|
445
|
+
const changeWeight = this.opts.alwaysChange
|
|
446
|
+
? weight
|
|
447
|
+
: weight + (this.changeWeight - this.baseWeight);
|
|
448
|
+
const changeFee = this.getSatoshi(changeWeight);
|
|
449
|
+
let fee = s.fee;
|
|
450
|
+
const change = total - this.amount - changeFee;
|
|
451
|
+
if (change > this.dust)
|
|
452
|
+
needChange = true;
|
|
453
|
+
let inputs = indices;
|
|
454
|
+
let outputs = Array.from(this.outputs);
|
|
455
|
+
if (needChange) {
|
|
456
|
+
fee = changeFee;
|
|
457
|
+
// this shouldn't happen!
|
|
458
|
+
if (change < 0n)
|
|
459
|
+
throw new Error(`Estimator.result: negative change=${change}`);
|
|
460
|
+
outputs.push({ address: this.opts.changeAddress, amount: change });
|
|
461
|
+
}
|
|
462
|
+
if (this.opts.bip69) {
|
|
463
|
+
inputs = this.sortIndices(inputs);
|
|
464
|
+
outputs = this.sortOutputs(outputs).map((i) => outputs[i]);
|
|
465
|
+
}
|
|
466
|
+
const res = {
|
|
467
|
+
inputs: inputs.map((i) => this.inputs[i]),
|
|
468
|
+
outputs,
|
|
469
|
+
fee,
|
|
470
|
+
weight: this.opts.alwaysChange ? s.weight : changeWeight,
|
|
471
|
+
change: !!needChange,
|
|
472
|
+
};
|
|
473
|
+
let tx;
|
|
474
|
+
if (this.opts.createTx) {
|
|
475
|
+
const { inputs, outputs } = res;
|
|
476
|
+
tx = new Transaction(this.opts);
|
|
477
|
+
for (const i of inputs)
|
|
478
|
+
tx.addInput(i);
|
|
479
|
+
for (const o of outputs)
|
|
480
|
+
tx.addOutput({ ...o, script: getScript(o, this.opts, this.opts.network) });
|
|
481
|
+
}
|
|
482
|
+
return { ...res, tx };
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
export function selectUTXO(inputs, outputs, strategy, opts) {
|
|
486
|
+
// Defaults: do we want bip69 by default?
|
|
487
|
+
const _opts = { createTx: true, bip69: true, ...opts };
|
|
488
|
+
const est = new _Estimator(inputs, outputs, _opts);
|
|
489
|
+
return est.result(strategy);
|
|
490
|
+
}
|
|
491
|
+
//# sourceMappingURL=utxo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAa,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EACL,gBAAgB,EAEhB,eAAe,EACf,aAAa,EACb,WAAW,GACZ,MAAM,kBAAkB,CAAC,CAAC,WAAW;AACtC,OAAO,EAAE,OAAO,EAAS,YAAY,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpG,mBAAmB;AACnB,MAAM,UAAU,UAAU,CAAC,KAA4B;IACrD,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;YAAE,MAAM,IAAI,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