@bitgo-beta/unspents 0.13.2-beta.9 → 0.13.2-beta.91

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/bin/generate_tables.ts +94 -0
  3. package/dist/bin/generate_tables.d.ts +2 -0
  4. package/dist/bin/generate_tables.d.ts.map +1 -0
  5. package/dist/bin/generate_tables.js +94 -0
  6. package/dist/{codes.d.ts → src/codes.d.ts} +1 -0
  7. package/dist/src/codes.d.ts.map +1 -0
  8. package/dist/src/codes.js +168 -0
  9. package/dist/{dimensions.d.ts → src/dimensions.d.ts} +6 -7
  10. package/dist/src/dimensions.d.ts.map +1 -0
  11. package/dist/src/dimensions.js +485 -0
  12. package/dist/{index.d.ts → src/index.d.ts} +1 -0
  13. package/dist/src/index.d.ts.map +1 -0
  14. package/dist/{index.js → src/index.js} +1 -1
  15. package/dist/{inputWeights.d.ts → src/inputWeights.d.ts} +1 -0
  16. package/dist/src/inputWeights.d.ts.map +1 -0
  17. package/dist/src/inputWeights.js +97 -0
  18. package/dist/{scriptSizes.d.ts → src/scriptSizes.d.ts} +1 -0
  19. package/dist/src/scriptSizes.d.ts.map +1 -0
  20. package/dist/src/scriptSizes.js +51 -0
  21. package/dist/{types.d.ts → src/types.d.ts} +1 -0
  22. package/dist/src/types.d.ts.map +1 -0
  23. package/dist/{types.js → src/types.js} +1 -1
  24. package/dist/{virtualSizes.d.ts → src/virtualSizes.d.ts} +1 -0
  25. package/dist/src/virtualSizes.d.ts.map +1 -0
  26. package/dist/src/virtualSizes.js +114 -0
  27. package/dist/test/chain.d.ts +2 -0
  28. package/dist/test/chain.d.ts.map +1 -0
  29. package/dist/test/chain.js +92 -0
  30. package/dist/test/dimensions.d.ts +2 -0
  31. package/dist/test/dimensions.d.ts.map +1 -0
  32. package/dist/test/dimensions.js +211 -0
  33. package/dist/test/signedTx/inputWeights.d.ts +2 -0
  34. package/dist/test/signedTx/inputWeights.d.ts.map +1 -0
  35. package/dist/test/signedTx/inputWeights.js +113 -0
  36. package/dist/test/signedTx/txCombinations.d.ts +3 -0
  37. package/dist/test/signedTx/txCombinations.d.ts.map +1 -0
  38. package/dist/test/signedTx/txCombinations.js +116 -0
  39. package/dist/test/signedTx/txGen.d.ts +75 -0
  40. package/dist/test/signedTx/txGen.d.ts.map +1 -0
  41. package/dist/test/signedTx/txGen.js +219 -0
  42. package/dist/test/testutils.d.ts +36 -0
  43. package/dist/test/testutils.d.ts.map +1 -0
  44. package/dist/test/testutils.js +176 -0
  45. package/dist/test/virtualSizes.d.ts +2 -0
  46. package/dist/test/virtualSizes.d.ts.map +1 -0
  47. package/dist/test/virtualSizes.js +18 -0
  48. package/dist/tsconfig.build.tsbuildinfo +1 -0
  49. package/dist/tsconfig.tsbuildinfo +1 -0
  50. package/docs/input-costs.md +13 -0
  51. package/package.json +5 -5
  52. package/dist/codes.js +0 -168
  53. package/dist/dimensions.js +0 -490
  54. package/dist/inputWeights.js +0 -97
  55. package/dist/scriptSizes.js +0 -51
  56. package/dist/virtualSizes.js +0 -114
@@ -1,490 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.Dimensions = exports.OutputDimensions = exports.VirtualSizes = void 0;
23
- const utxolib = __importStar(require("@bitgo-beta/utxo-lib"));
24
- const utxo_lib_1 = require("@bitgo-beta/utxo-lib");
25
- const { isChainCode, scriptTypeForChain } = utxo_lib_1.bitgo;
26
- const scriptSizes_1 = require("./scriptSizes");
27
- const types_1 = require("./types");
28
- const virtualSizes_1 = require("./virtualSizes");
29
- Object.defineProperty(exports, "VirtualSizes", { enumerable: true, get: function () { return virtualSizes_1.VirtualSizes; } });
30
- /**
31
- * Apply `f` to all properties of `d`
32
- */
33
- function mapDimensions(d, f) {
34
- return new Dimensions(Object.fromEntries(Object.entries(d).map(([key, value]) => [key, f(key, value)])));
35
- }
36
- /**
37
- * Aggregate count and size of transaction outputs
38
- */
39
- class OutputDimensions {
40
- constructor({ count = 0, size = 0 } = { count: 0, size: 0 }) {
41
- if (count === 0 || size === 0) {
42
- if (count !== 0 || size !== 0) {
43
- throw new Error(`count and size must both be zero if one is zero`);
44
- }
45
- }
46
- this.count = count;
47
- this.size = size;
48
- Object.freeze(this);
49
- }
50
- }
51
- exports.OutputDimensions = OutputDimensions;
52
- const defaultUnspentParams = {
53
- p2tr: {
54
- scriptPathLevel: 1,
55
- },
56
- p2trMusig2: {
57
- // Default to script path spend, to make it easier for recovery case callers (WRW etc).
58
- // WP can explicitly pass undefined to use key path.
59
- scriptPathLevel: 1,
60
- },
61
- };
62
- /**
63
- * Dimensions of a BitGo wallet transactions.
64
- */
65
- class Dimensions {
66
- constructor(d = {}) {
67
- /** Input counts for BitGo wallet multi-signature inputs */
68
- this.nP2shInputs = 0;
69
- this.nP2shP2wshInputs = 0;
70
- this.nP2wshInputs = 0;
71
- this.nP2trKeypathInputs = 0;
72
- this.nP2trScriptPathLevel1Inputs = 0;
73
- this.nP2trScriptPathLevel2Inputs = 0;
74
- /* Input count for single-signature inputs (Replay Protection inputs) */
75
- this.nP2shP2pkInputs = 0;
76
- this.outputs = new OutputDimensions();
77
- Object.entries(d).forEach(([key, value]) => this.setProperty(key, value));
78
- Object.freeze(this);
79
- }
80
- setProperty(k, v) {
81
- switch (k) {
82
- case 'nP2shInputs':
83
- case 'nP2shP2wshInputs':
84
- case 'nP2wshInputs':
85
- case 'nP2trKeypathInputs':
86
- case 'nP2trScriptPathLevel1Inputs':
87
- case 'nP2trScriptPathLevel2Inputs':
88
- case 'nP2shP2pkInputs':
89
- if (typeof v !== 'number') {
90
- throw new Error(`property ${k} must be number`);
91
- }
92
- if (!Number.isSafeInteger(v) || v < 0) {
93
- throw new Error(`property ${k} must be zero or positive integer`);
94
- }
95
- break;
96
- case 'outputs':
97
- if (!(v instanceof OutputDimensions)) {
98
- v = new OutputDimensions(v);
99
- }
100
- break;
101
- default:
102
- throw new Error(`unknown property ${k}`);
103
- }
104
- this[k] = v;
105
- }
106
- /**
107
- * @deprecated use ZERO
108
- * @return Dimensions for an empty transaction
109
- */
110
- static zero() {
111
- return this.ZERO;
112
- }
113
- /**
114
- * @param size
115
- * @return Dimensions for a single output with given size
116
- */
117
- static singleOutput(size) {
118
- return Dimensions.sum({ outputs: { count: 1, size } });
119
- }
120
- /**
121
- * @return Number of total inputs (p2sh + p2shP2wsh + p2wsh + p2tr)
122
- */
123
- get nInputs() {
124
- return (this.nP2shInputs +
125
- this.nP2shP2wshInputs +
126
- this.nP2wshInputs +
127
- this.nP2trKeypathInputs +
128
- this.nP2trScriptPathLevel1Inputs +
129
- this.nP2trScriptPathLevel2Inputs +
130
- this.nP2shP2pkInputs);
131
- }
132
- set nInputs(_) {
133
- throw new Error('read-only property nInputs');
134
- }
135
- /**
136
- * @return Number of total outputs
137
- */
138
- get nOutputs() {
139
- return this.outputs.count;
140
- }
141
- set nOutputs(_) {
142
- throw new Error(`read-only property nOutputs`);
143
- }
144
- /**
145
- * @param args - Dimensions (can be partially defined)
146
- * @return {Dimensions} sum of arguments
147
- */
148
- static sum(...args) {
149
- return args.reduce((a, b) => a.plus(b), new Dimensions());
150
- }
151
- /**
152
- * @param chain
153
- * @return {Number}
154
- */
155
- static getOutputScriptLengthForChain(chain) {
156
- switch (scriptTypeForChain(chain)) {
157
- case 'p2wsh':
158
- case 'p2tr':
159
- case 'p2trMusig2':
160
- return 34;
161
- default:
162
- return 23;
163
- }
164
- }
165
- /**
166
- * @param scriptLength
167
- * @return {Number} vSize of an output with script length
168
- */
169
- static getVSizeForOutputWithScriptLength(scriptLength) {
170
- if (!types_1.PositiveInteger.is(scriptLength)) {
171
- throw new TypeError(`expected positive integer for scriptLength, got ${scriptLength}`);
172
- }
173
- return scriptLength + scriptSizes_1.compactSize(scriptLength) + virtualSizes_1.VirtualSizes.txOutputAmountSize;
174
- }
175
- /**
176
- * @return
177
- */
178
- static fromScriptType(scriptType, params = {}) {
179
- switch (scriptType) {
180
- case 'p2sh':
181
- case 'p2shP2wsh':
182
- case 'p2wsh':
183
- case 'p2shP2pk':
184
- return Dimensions.SingleInput[scriptType];
185
- case 'p2tr':
186
- case 'taprootScriptPathSpend':
187
- switch (params.scriptPathLevel) {
188
- case 1:
189
- return Dimensions.SingleInput.p2trScriptPathLevel1;
190
- case 2:
191
- return Dimensions.SingleInput.p2trScriptPathLevel2;
192
- default:
193
- throw new Error(`unexpected script path level`);
194
- }
195
- case 'p2trMusig2':
196
- switch (params.scriptPathLevel) {
197
- case undefined:
198
- return Dimensions.SingleInput.p2trKeypath;
199
- case 1:
200
- return Dimensions.SingleInput.p2trScriptPathLevel1;
201
- default:
202
- throw new Error(`unexpected script path level`);
203
- }
204
- case 'taprootKeyPathSpend':
205
- return Dimensions.SingleInput.p2trKeypath;
206
- default:
207
- throw new Error(`unexpected scriptType ${scriptType}`);
208
- }
209
- }
210
- static getAssumedDimension(params = {}, index) {
211
- const { assumeUnsigned } = params;
212
- if (!assumeUnsigned) {
213
- throw new Error(`illegal input ${index}: empty script and assumeUnsigned not set`);
214
- }
215
- return assumeUnsigned;
216
- }
217
- /**
218
- * @param input - the transaction input to count
219
- * @param params
220
- * [param.assumeUnsigned] - default type for unsigned input
221
- */
222
- static fromInput(input, params = {}) {
223
- var _a, _b;
224
- if (((_a = input.script) === null || _a === void 0 ? void 0 : _a.length) || ((_b = input.witness) === null || _b === void 0 ? void 0 : _b.length)) {
225
- const parsed = utxolib.bitgo.parseSignatureScript(input);
226
- return Dimensions.fromScriptType(parsed.scriptType, parsed);
227
- }
228
- return Dimensions.getAssumedDimension(params, input.index);
229
- }
230
- /**
231
- * Create Dimensions from psbt input
232
- * @param psbt - psbt
233
- * @param inputIndex - psbt input index
234
- */
235
- static fromPsbtInput(psbt, inputIndex) {
236
- const parsed = utxolib.bitgo.parsePsbtInput(psbt, inputIndex);
237
- if (parsed && parsed.scriptType) {
238
- return Dimensions.fromScriptType(parsed.scriptType, parsed);
239
- }
240
- throw new Error(`illegal input ${inputIndex}: empty script`);
241
- }
242
- /**
243
- * @param inputs - Array of inputs
244
- * @param params - @see Dimensions.fromInput()
245
- * @return {Dimensions} sum of the dimensions for each input (@see Dimensions.fromInput())
246
- */
247
- static fromInputs(inputs, params) {
248
- if (!Array.isArray(inputs)) {
249
- throw new TypeError(`inputs must be array`);
250
- }
251
- return Dimensions.sum(...inputs.map((i) => Dimensions.fromInput(i, params)));
252
- }
253
- /**
254
- * Create Dimensions from multiple psbt inputs
255
- * @param psbt
256
- * @param params - @see Dimensions.fromInput()
257
- * @return {Dimensions} sum of the dimensions for each input (@see Dimensions.fromInput())
258
- */
259
- static fromPsbtInputs(psbt) {
260
- if (!Array.isArray(psbt.txInputs)) {
261
- throw new TypeError(`psbt must have inputs`);
262
- }
263
- return Dimensions.sum(...psbt.txInputs.map((input, inputIndex) => Dimensions.fromPsbtInput(psbt, inputIndex)));
264
- }
265
- /**
266
- * @param scriptLength {number} - size of the output script in bytes
267
- * @return {Dimensions} - Dimensions of the output
268
- */
269
- static fromOutputScriptLength(scriptLength) {
270
- return Dimensions.sum({
271
- outputs: {
272
- count: 1,
273
- size: Dimensions.getVSizeForOutputWithScriptLength(scriptLength),
274
- },
275
- });
276
- }
277
- /**
278
- * @param output - a tx output
279
- * @return Dimensions - the dimensions of the given output
280
- */
281
- static fromOutput({ script }) {
282
- if (!script) {
283
- throw new Error('expected output script to be defined');
284
- }
285
- if (!Buffer.isBuffer(script)) {
286
- throw new TypeError('expected script to be buffer, got ' + typeof script);
287
- }
288
- return Dimensions.fromOutputScriptLength(script.length);
289
- }
290
- /**
291
- * @param outputs - Array of outputs
292
- * @return {Dimensions} sum of the dimensions for each output (@see Dimensions.fromOutput())
293
- */
294
- static fromOutputs(outputs) {
295
- if (!Array.isArray(outputs)) {
296
- throw new TypeError(`outputs must be array`);
297
- }
298
- return Dimensions.sum(...outputs.map(Dimensions.fromOutput));
299
- }
300
- /**
301
- * Returns the dimensions of an output that will be created on a specific chain.
302
- * Currently, this simply adds a default output.
303
- *
304
- * @param chain - Chain code as defined by utxolib.bitgo
305
- * @return {Dimensions} - Dimensions for a single output on the given chain.
306
- */
307
- static fromOutputOnChain(chain) {
308
- return Dimensions.fromOutputScriptLength(Dimensions.getOutputScriptLengthForChain(chain));
309
- }
310
- /**
311
- * Return dimensions of an unspent according to `chain` parameter
312
- * @param chain - Chain code as defined by utxo.chain
313
- * @param params - Hint for unspents with variable input sizes (p2tr).
314
- * @return {Dimensions} of the unspent
315
- * @throws if the chain code is invalid or unsupported
316
- */
317
- static fromUnspent({ chain }, params = defaultUnspentParams) {
318
- if (!isChainCode(chain)) {
319
- throw new TypeError('invalid chain code');
320
- }
321
- const scriptType = scriptTypeForChain(chain);
322
- return Dimensions.fromScriptType(scriptType, scriptType === 'p2tr' ? params.p2tr : scriptType === 'p2trMusig2' ? params.p2trMusig2 : {});
323
- }
324
- /**
325
- * @param unspents
326
- * @return {Dimensions} sum of the dimensions for each unspent (@see Dimensions.fromUnspent())
327
- */
328
- static fromUnspents(unspents) {
329
- if (!Array.isArray(unspents)) {
330
- throw new TypeError(`unspents must be array`);
331
- }
332
- // Convert the individual unspents into dimensions and sum them up
333
- return Dimensions.sum(...unspents.map((u) => Dimensions.fromUnspent(u)));
334
- }
335
- /**
336
- * @param transaction - bitcoin-like transaction
337
- * @param [param.assumeUnsigned] - default type for unsigned inputs
338
- * @return {Dimensions}
339
- */
340
- static fromTransaction({ ins, outs, }, params) {
341
- return Dimensions.fromInputs(ins, params).plus(Dimensions.fromOutputs(outs));
342
- }
343
- /**
344
- * Create Dimensions from psbt inputs and outputs
345
- * @param psbt
346
- * @return {Dimensions}
347
- */
348
- static fromPsbt(psbt) {
349
- return Dimensions.fromPsbtInputs(psbt).plus(Dimensions.fromOutputs(psbt.getUnsignedTx().outs));
350
- }
351
- /**
352
- * @param dimensions (can be partially defined)
353
- * @return new dimensions with argument added
354
- */
355
- plus(dimensions) {
356
- if (typeof dimensions !== 'object') {
357
- throw new TypeError(`expected argument to be object`);
358
- }
359
- if (!(dimensions instanceof Dimensions)) {
360
- dimensions = new Dimensions(dimensions);
361
- }
362
- // Catch instances where we try to initialize Dimensions from partial data using deprecated parameters
363
- // using only "nOutputs".
364
- if ('nOutputs' in dimensions) {
365
- if (!('outputs' in dimensions)) {
366
- throw new Error('deprecated partial addition: argument has key "nOutputs" but no "outputs"');
367
- }
368
- const { outputs, nOutputs } = dimensions;
369
- if (outputs.count !== nOutputs) {
370
- throw new Error('deprecated partial addition: inconsistent values for "nOutputs" and "outputs.count"');
371
- }
372
- }
373
- return mapDimensions(this, (key, v) => {
374
- var _a;
375
- const w = (_a = dimensions[key]) !== null && _a !== void 0 ? _a : Dimensions.ZERO[key];
376
- if (key === 'outputs') {
377
- const vOutputs = v;
378
- const wOutputs = w;
379
- return new OutputDimensions({
380
- count: vOutputs.count + wOutputs.count,
381
- size: vOutputs.size + wOutputs.size,
382
- });
383
- }
384
- return v + w;
385
- });
386
- }
387
- /**
388
- * Multiply dimensions by a given factor
389
- * @param factor - Positive integer
390
- * @return {Dimensions}
391
- */
392
- times(factor) {
393
- if (!types_1.PositiveInteger.is(factor)) {
394
- throw new TypeError(`expected factor to be positive integer`);
395
- }
396
- return mapDimensions(this, (key, value) => {
397
- if (key === 'outputs') {
398
- const vOutputs = value;
399
- return {
400
- count: vOutputs.count * factor,
401
- size: vOutputs.size * factor,
402
- };
403
- }
404
- return value * factor;
405
- });
406
- }
407
- /**
408
- * @return Number of total inputs (p2sh, p2shP2wsh and p2wsh)
409
- * @deprecated use `dimension.nInputs` instead
410
- */
411
- getNInputs() {
412
- return this.nInputs;
413
- }
414
- /**
415
- * @returns {boolean} true iff dimensions have one or more (p2sh)p2wsh inputs
416
- */
417
- isSegwit() {
418
- return (this.nP2wshInputs +
419
- this.nP2shP2wshInputs +
420
- this.nP2trKeypathInputs +
421
- this.nP2trScriptPathLevel1Inputs +
422
- this.nP2trScriptPathLevel2Inputs >
423
- 0);
424
- }
425
- /**
426
- * @return {Number} overhead vsize, based on result isSegwit().
427
- */
428
- getOverheadVSize() {
429
- return this.isSegwit() ? virtualSizes_1.VirtualSizes.txSegOverheadVSize : virtualSizes_1.VirtualSizes.txOverheadSize;
430
- }
431
- /**
432
- * @returns {number} vsize of inputs, without transaction overhead
433
- */
434
- getInputsVSize() {
435
- const { txP2shInputSize, txP2shP2wshInputSize, txP2wshInputSize, txP2trKeypathInputSize, txP2trScriptPathLevel1InputSize, txP2trScriptPathLevel2InputSize, txP2shP2pkInputSize, } = virtualSizes_1.VirtualSizes;
436
- const { nP2shInputs, nP2shP2wshInputs, nP2wshInputs, nP2trKeypathInputs, nP2trScriptPathLevel1Inputs, nP2trScriptPathLevel2Inputs, nP2shP2pkInputs, } = this;
437
- const size = nP2shInputs * txP2shInputSize +
438
- nP2shP2wshInputs * txP2shP2wshInputSize +
439
- nP2wshInputs * txP2wshInputSize +
440
- nP2trKeypathInputs * txP2trKeypathInputSize +
441
- nP2shP2pkInputs * txP2shP2pkInputSize +
442
- nP2trScriptPathLevel1Inputs * txP2trScriptPathLevel1InputSize +
443
- nP2trScriptPathLevel2Inputs * txP2trScriptPathLevel2InputSize;
444
- if (Number.isNaN(size)) {
445
- throw new Error(`invalid size`);
446
- }
447
- return size;
448
- }
449
- /**
450
- * @returns {number} return vsize of outputs, without overhead
451
- */
452
- getOutputsVSize() {
453
- return this.outputs.size;
454
- }
455
- /**
456
- * Estimates the virtual size (1/4 weight) of a signed transaction as sum of
457
- * overhead vsize, input vsize and output vsize.
458
- * @returns {Number} The estimated vsize of the transaction dimensions.
459
- */
460
- getVSize() {
461
- return this.getOverheadVSize() + this.getInputsVSize() + this.getOutputsVSize();
462
- }
463
- }
464
- exports.Dimensions = Dimensions;
465
- Dimensions.ZERO = Object.freeze(new Dimensions());
466
- Dimensions.SingleOutput = Object.freeze({
467
- p2sh: Dimensions.singleOutput(virtualSizes_1.VirtualSizes.txP2shOutputSize),
468
- p2shP2wsh: Dimensions.singleOutput(virtualSizes_1.VirtualSizes.txP2shP2wshOutputSize),
469
- p2wsh: Dimensions.singleOutput(virtualSizes_1.VirtualSizes.txP2wshOutputSize),
470
- p2tr: Dimensions.singleOutput(virtualSizes_1.VirtualSizes.txP2trOutputSize),
471
- p2pkh: Dimensions.singleOutput(virtualSizes_1.VirtualSizes.txP2pkhOutputSize),
472
- p2wpkh: Dimensions.singleOutput(virtualSizes_1.VirtualSizes.txP2wpkhOutputSize),
473
- });
474
- Dimensions.SingleInput = Object.freeze({
475
- p2sh: Dimensions.sum({ nP2shInputs: 1 }),
476
- p2shP2wsh: Dimensions.sum({ nP2shP2wshInputs: 1 }),
477
- p2wsh: Dimensions.sum({ nP2wshInputs: 1 }),
478
- p2trKeypath: Dimensions.sum({ nP2trKeypathInputs: 1 }),
479
- p2trScriptPathLevel1: Dimensions.sum({ nP2trScriptPathLevel1Inputs: 1 }),
480
- p2trScriptPathLevel2: Dimensions.sum({ nP2trScriptPathLevel2Inputs: 1 }),
481
- p2shP2pk: Dimensions.sum({ nP2shP2pkInputs: 1 }),
482
- });
483
- Dimensions.ASSUME_P2SH = Dimensions.SingleInput.p2sh;
484
- Dimensions.ASSUME_P2SH_P2WSH = Dimensions.SingleInput.p2shP2wsh;
485
- Dimensions.ASSUME_P2WSH = Dimensions.SingleInput.p2wsh;
486
- Dimensions.ASSUME_P2TR_KEYPATH = Dimensions.SingleInput.p2trKeypath;
487
- Dimensions.ASSUME_P2TR_SCRIPTPATH_LEVEL1 = Dimensions.SingleInput.p2trScriptPathLevel1;
488
- Dimensions.ASSUME_P2TR_SCRIPTPATH_LEVEL2 = Dimensions.SingleInput.p2trScriptPathLevel2;
489
- Dimensions.ASSUME_P2SH_P2PK_INPUT = Dimensions.SingleInput.p2shP2pk;
490
- //# sourceMappingURL=dimensions.js.map
@@ -1,97 +0,0 @@
1
- "use strict";
2
- /**
3
- * Defines input sizes for BitGo signature scripts.
4
- */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.inputComponentsP2shP2pk = exports.inputComponentsP2trScriptSpendLevel2 = exports.inputComponentsP2trScriptSpendLevel1 = exports.inputComponentsP2trKeySpend = exports.inputComponentsP2wsh = exports.inputComponentsP2shP2wsh = exports.inputComponentsP2sh = exports.getInputComponentsWeight = exports.getInputWeight = exports.getInputByteLength = exports.varSliceSize = void 0;
10
- const varuint_bitcoin_1 = __importDefault(require("varuint-bitcoin"));
11
- function varSliceSize(someScript) {
12
- const length = someScript.length;
13
- return varuint_bitcoin_1.default.encodingLength(length) + length;
14
- }
15
- exports.varSliceSize = varSliceSize;
16
- function vectorSize(someVector) {
17
- const length = someVector.length;
18
- return (varuint_bitcoin_1.default.encodingLength(length) +
19
- someVector.reduce((sum, witness) => {
20
- return sum + varSliceSize(witness);
21
- }, 0));
22
- }
23
- function getInputByteLength(input, allowWitness) {
24
- return (40 /* inputId(32), index(4), nSequence(4) */ +
25
- varSliceSize(input.script) +
26
- (allowWitness ? vectorSize(input.witness) : 0));
27
- }
28
- exports.getInputByteLength = getInputByteLength;
29
- function getInputWeight(input) {
30
- return 3 * getInputByteLength(input, false) + getInputByteLength(input, true);
31
- }
32
- exports.getInputWeight = getInputWeight;
33
- function getInputComponentsWeight(c) {
34
- const scriptSize = c.script.reduce((a, b) => a + b, 0);
35
- return getInputWeight({
36
- script: { length: scriptSize },
37
- witness: c.witness.map((v) => ({ length: v })),
38
- });
39
- }
40
- exports.getInputComponentsWeight = getInputComponentsWeight;
41
- const opSize = 1;
42
- const op0Size = opSize;
43
- const opPushSize = opSize;
44
- const opCheckSigVerifySize = opSize;
45
- const opCheckSigSize = opSize;
46
- const ecdsaSignatureSize = 72;
47
- const schnorrPubkeySize = 32;
48
- const schnorrSignatureNoSighashSize = 64;
49
- const p2msPubScriptSize = 105;
50
- const p2wshPubScriptSize = 34;
51
- const p2pkPubScriptSize = 35;
52
- function p2trScriptSpend(level) {
53
- return [
54
- schnorrSignatureNoSighashSize,
55
- schnorrSignatureNoSighashSize,
56
- opPushSize + schnorrPubkeySize + opCheckSigSize + opPushSize + schnorrPubkeySize + opCheckSigVerifySize,
57
- /* header byte */ 1 + /* inner key */ 32 + /* inner leaf */ 32 * level,
58
- ];
59
- }
60
- function p2msSigScriptSize(witness) {
61
- return [
62
- witness ? 0 : op0Size,
63
- (witness ? 0 : opPushSize) + ecdsaSignatureSize,
64
- (witness ? 0 : opPushSize) + ecdsaSignatureSize,
65
- (witness ? 0 : /* OP_PUSHDATA2 */ opPushSize + 1) + p2msPubScriptSize,
66
- ];
67
- }
68
- exports.inputComponentsP2sh = {
69
- script: p2msSigScriptSize(false),
70
- witness: [],
71
- };
72
- exports.inputComponentsP2shP2wsh = {
73
- script: [opSize + p2wshPubScriptSize],
74
- witness: p2msSigScriptSize(true),
75
- };
76
- exports.inputComponentsP2wsh = {
77
- script: [],
78
- witness: p2msSigScriptSize(true),
79
- };
80
- // See: https://murchandamus.medium.com/2-of-3-multisig-inputs-using-pay-to-taproot-d5faf2312ba3
81
- exports.inputComponentsP2trKeySpend = {
82
- script: [],
83
- witness: [schnorrSignatureNoSighashSize],
84
- };
85
- exports.inputComponentsP2trScriptSpendLevel1 = {
86
- script: [],
87
- witness: p2trScriptSpend(1),
88
- };
89
- exports.inputComponentsP2trScriptSpendLevel2 = {
90
- script: [],
91
- witness: p2trScriptSpend(2),
92
- };
93
- exports.inputComponentsP2shP2pk = {
94
- script: [opPushSize + ecdsaSignatureSize, opPushSize + p2pkPubScriptSize],
95
- witness: [],
96
- };
97
- //# sourceMappingURL=inputWeights.js.map
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compactSize = exports.pushdataEncodingLength = void 0;
4
- const types_1 = require("./types");
5
- /**
6
- * Overhead size for a pushdata element in a script
7
- * @param i
8
- */
9
- function pushdataEncodingLength(i) {
10
- /*
11
- * https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#push-operators
12
- * Pushing any other byte sequence up to 75 bytes must use the normal data push (opcode byte n, with n the number of bytes, followed n bytes of data being pushed).
13
- * Pushing 76 to 255 bytes must use OP_PUSHDATA1.
14
- * Pushing 256 to 520 bytes must use OP_PUSHDATA2.
15
- * OP_PUSHDATA4 can never be used, as pushes over 520 bytes are not allowed, and those below can be done using other operators.
16
- */
17
- if (i < 76) {
18
- return 1;
19
- }
20
- if (i < 255) {
21
- return 2;
22
- }
23
- if (i < 520) {
24
- return 3;
25
- }
26
- throw new Error(`invalid pushdata size`);
27
- }
28
- exports.pushdataEncodingLength = pushdataEncodingLength;
29
- /**
30
- * https://developer.bitcoin.org/reference/transactions.html#compactsize-unsigned-integers
31
- * https://github.com/bitcoinjs/varuint-bitcoin/blob/1d5b253/index.js#L79
32
- * @param integer
33
- * @return {number} - The compact size the integer requires when serialized in a transaction
34
- */
35
- function compactSize(integer) {
36
- if (!types_1.PositiveInteger.is(integer)) {
37
- throw new TypeError(`expected positive integer`);
38
- }
39
- if (integer <= 252) {
40
- return 1;
41
- }
42
- if (integer <= 0xffff) {
43
- return 3;
44
- }
45
- if (integer <= 0xffffffff) {
46
- return 5;
47
- }
48
- return 9;
49
- }
50
- exports.compactSize = compactSize;
51
- //# sourceMappingURL=scriptSizes.js.map