@bitgo-beta/unspents 0.13.2-beta.9 → 0.13.2-beta.900
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/.mocharc.js +1 -1
- package/CHANGELOG.md +541 -0
- package/bin/generate_tables.ts +94 -0
- package/dist/bin/generate_tables.d.ts +2 -0
- package/dist/bin/generate_tables.d.ts.map +1 -0
- package/dist/bin/generate_tables.js +107 -0
- package/dist/{codes.d.ts → src/codes.d.ts} +11 -10
- package/dist/src/codes.d.ts.map +1 -0
- package/dist/src/codes.js +182 -0
- package/dist/{dimensions.d.ts → src/dimensions.d.ts} +10 -11
- package/dist/src/dimensions.d.ts.map +1 -0
- package/dist/src/dimensions.js +500 -0
- package/dist/{index.d.ts → src/index.d.ts} +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +44 -0
- package/dist/{inputWeights.d.ts → src/inputWeights.d.ts} +4 -3
- package/dist/src/inputWeights.d.ts.map +1 -0
- package/dist/src/inputWeights.js +97 -0
- package/dist/{scriptSizes.d.ts → src/scriptSizes.d.ts} +1 -0
- package/dist/src/scriptSizes.d.ts.map +1 -0
- package/dist/src/scriptSizes.js +50 -0
- package/dist/{types.d.ts → src/types.d.ts} +1 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +39 -0
- package/dist/{virtualSizes.d.ts → src/virtualSizes.d.ts} +13 -12
- package/dist/src/virtualSizes.d.ts.map +1 -0
- package/dist/src/virtualSizes.js +114 -0
- package/dist/src/zcash.d.ts +9 -0
- package/dist/src/zcash.d.ts.map +1 -0
- package/dist/src/zcash.js +22 -0
- package/dist/test/chain.d.ts +2 -0
- package/dist/test/chain.d.ts.map +1 -0
- package/dist/test/chain.js +92 -0
- package/dist/test/dimensions.d.ts +2 -0
- package/dist/test/dimensions.d.ts.map +1 -0
- package/dist/test/dimensions.js +235 -0
- package/dist/test/signedTx/inputWeights.d.ts +2 -0
- package/dist/test/signedTx/inputWeights.d.ts.map +1 -0
- package/dist/test/signedTx/inputWeights.js +127 -0
- package/dist/test/signedTx/txCombinations.d.ts +3 -0
- package/dist/test/signedTx/txCombinations.d.ts.map +1 -0
- package/dist/test/signedTx/txCombinations.js +130 -0
- package/dist/test/signedTx/txGen.d.ts +74 -0
- package/dist/test/signedTx/txGen.d.ts.map +1 -0
- package/dist/test/signedTx/txGen.js +233 -0
- package/dist/test/testutils.d.ts +36 -0
- package/dist/test/testutils.d.ts.map +1 -0
- package/dist/test/testutils.js +190 -0
- package/dist/test/virtualSizes.d.ts +2 -0
- package/dist/test/virtualSizes.d.ts.map +1 -0
- package/dist/test/virtualSizes.js +18 -0
- package/dist/test/zcash.d.ts +2 -0
- package/dist/test/zcash.d.ts.map +1 -0
- package/dist/test/zcash.js +60 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/input-costs.md +14 -0
- package/package.json +7 -7
- package/dist/codes.js +0 -168
- package/dist/dimensions.js +0 -490
- package/dist/index.js +0 -30
- package/dist/inputWeights.js +0 -97
- package/dist/scriptSizes.js +0 -51
- package/dist/types.js +0 -25
- package/dist/virtualSizes.js +0 -114
package/dist/inputWeights.js
DELETED
|
@@ -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
|
package/dist/scriptSizes.js
DELETED
|
@@ -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
|
package/dist/types.js
DELETED
|
@@ -1,25 +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.PositiveInteger = void 0;
|
|
23
|
-
const t = __importStar(require("tcomb"));
|
|
24
|
-
exports.PositiveInteger = t.refinement(t.Integer, (n) => n >= 0, 'PositiveInteger');
|
|
25
|
-
//# sourceMappingURL=types.js.map
|
package/dist/virtualSizes.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
This is a reference implementation for calculating weights and vSizes from bitcoinjs-lib 3.3.2.
|
|
4
|
-
https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/src/transaction.js#L194-L219
|
|
5
|
-
|
|
6
|
-
```
|
|
7
|
-
function encodingLength (number) {
|
|
8
|
-
checkUInt53(number)
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
number < 0xfd ? 1
|
|
12
|
-
: number <= 0xffff ? 3
|
|
13
|
-
: number <= 0xffffffff ? 5
|
|
14
|
-
: 9
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function varSliceSize (someScript) {
|
|
19
|
-
var length = someScript.length
|
|
20
|
-
|
|
21
|
-
return encodingLength(length) + length
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function vectorSize (someVector) {
|
|
25
|
-
var length = someVector.length
|
|
26
|
-
|
|
27
|
-
return varuint.encodingLength(length) + someVector.reduce(function (sum, witness) {
|
|
28
|
-
return sum + varSliceSize(witness)
|
|
29
|
-
}, 0)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
Transaction.prototype.__byteLength = function (__allowWitness) {
|
|
33
|
-
var hasWitnesses = __allowWitness && this.hasWitnesses()
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
(hasWitnesses ? 10 : 8) +
|
|
37
|
-
varuint.encodingLength(this.ins.length) +
|
|
38
|
-
varuint.encodingLength(this.outs.length) +
|
|
39
|
-
this.ins.reduce(function (sum, input) { return sum + 40 + varSliceSize(input.script) }, 0) +
|
|
40
|
-
this.outs.reduce(function (sum, output) { return sum + 8 + varSliceSize(output.script) }, 0) +
|
|
41
|
-
(hasWitnesses ? this.ins.reduce(function (sum, input) { return sum + vectorSize(input.witness) }, 0) : 0)
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
Transaction.prototype.weight = function () {
|
|
46
|
-
var base = this.__byteLength(false)
|
|
47
|
-
var total = this.__byteLength(true)
|
|
48
|
-
return base * 3 + total
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
Transaction.prototype.virtualSize = function () {
|
|
52
|
-
return Math.ceil(this.weight() / 4)
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
*/
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.VirtualSizes = void 0;
|
|
58
|
-
const inputWeights_1 = require("./inputWeights");
|
|
59
|
-
function getVirtualInputSizeFromComponents(components) {
|
|
60
|
-
return Math.ceil(inputWeights_1.getInputComponentsWeight(components) / 4);
|
|
61
|
-
}
|
|
62
|
-
// Constants for signed TX input and output vsizes.
|
|
63
|
-
// See https://bitcoincore.org/en/segwit_wallet_dev/#transaction-serialization for full description
|
|
64
|
-
// FIXME(BG-9233): use weight units instead
|
|
65
|
-
exports.VirtualSizes = Object.freeze({
|
|
66
|
-
// FIXME(BG-7873): add support for signature grinding
|
|
67
|
-
// Size of a P2PKH input with (un)compressed key
|
|
68
|
-
/** @deprecated */
|
|
69
|
-
txP2pkhInputSizeCompressedKey: 148,
|
|
70
|
-
/** @deprecated */
|
|
71
|
-
txP2pkhInputSizeUncompressedKey: 180,
|
|
72
|
-
// Input sizes
|
|
73
|
-
txP2shInputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2sh),
|
|
74
|
-
txP2shP2wshInputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2shP2wsh),
|
|
75
|
-
txP2wshInputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2wsh),
|
|
76
|
-
txP2trKeypathInputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2trKeySpend),
|
|
77
|
-
txP2shP2pkInputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2shP2pk),
|
|
78
|
-
txP2trScriptPathLevel1InputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2trScriptSpendLevel1),
|
|
79
|
-
txP2trScriptPathLevel2InputSize: getVirtualInputSizeFromComponents(inputWeights_1.inputComponentsP2trScriptSpendLevel2),
|
|
80
|
-
//
|
|
81
|
-
// Output sizes
|
|
82
|
-
//
|
|
83
|
-
// The size is calculated as
|
|
84
|
-
//
|
|
85
|
-
// scriptLength + compactSize(scriptLength) + txOutputAmountSize
|
|
86
|
-
//
|
|
87
|
-
// Since compactSize(scriptLength) is 1 for all scripts considered here, we can simplify this to
|
|
88
|
-
//
|
|
89
|
-
// scriptLength + 9
|
|
90
|
-
//
|
|
91
|
-
// Size of single output amount
|
|
92
|
-
txOutputAmountSize: 8,
|
|
93
|
-
// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v4.0.2/src/templates/scripthash/output.js#L9
|
|
94
|
-
txP2shOutputSize: 32,
|
|
95
|
-
txP2shP2wshOutputSize: 32,
|
|
96
|
-
// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v4.0.2/src/templates/witnessscripthash/output.js#L9
|
|
97
|
-
txP2wshOutputSize: 43,
|
|
98
|
-
// OP_1 OP_PUSH32 <schnorr_public_key>
|
|
99
|
-
txP2trOutputSize: 43,
|
|
100
|
-
// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v4.0.2/src/templates/pubkeyhash/output.js#L9
|
|
101
|
-
txP2pkhOutputSize: 34,
|
|
102
|
-
// https://github.com/bitcoinjs/bitcoinjs-lib/blob/v4.0.2/src/templates/witnesspubkeyhash/output.js#L9
|
|
103
|
-
txP2wpkhOutputSize: 31,
|
|
104
|
-
/** @deprecated - use txP2pkhOutputSize instead */
|
|
105
|
-
txOutputSize: 34,
|
|
106
|
-
//
|
|
107
|
-
// General tx size constants
|
|
108
|
-
//
|
|
109
|
-
txOverheadSize: 10,
|
|
110
|
-
// Segwit adds one byte each for marker and flag to the witness section.
|
|
111
|
-
// Thus, the vsize is only increased by one.
|
|
112
|
-
txSegOverheadVSize: 11,
|
|
113
|
-
});
|
|
114
|
-
//# sourceMappingURL=virtualSizes.js.map
|