utxo-lib 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/README.md +16 -19
  2. package/dist/src/bitgo/PsbtUtil.d.ts +0 -5
  3. package/dist/src/bitgo/PsbtUtil.d.ts.map +1 -1
  4. package/dist/src/bitgo/PsbtUtil.js +2 -15
  5. package/dist/src/bitgo/UtxoPsbt.d.ts +0 -9
  6. package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -1
  7. package/dist/src/bitgo/UtxoPsbt.js +12 -42
  8. package/dist/src/bitgo/index.d.ts +0 -1
  9. package/dist/src/bitgo/index.d.ts.map +1 -1
  10. package/dist/src/bitgo/index.js +2 -3
  11. package/dist/src/bitgo/parseInput.js +2 -2
  12. package/dist/src/bitgo/wallet/Psbt.d.ts +0 -14
  13. package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -1
  14. package/dist/src/bitgo/wallet/Psbt.js +3 -71
  15. package/dist/src/bitgo/wallet/WalletOutput.d.ts +1 -17
  16. package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -1
  17. package/dist/src/bitgo/wallet/WalletOutput.js +23 -64
  18. package/dist/src/bitgo/wallet/chains.d.ts +1 -1
  19. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +1 -0
  20. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -1
  21. package/dist/src/bitgo/zcash/ZcashPsbt.js +12 -3
  22. package/dist/src/testutil/keys.d.ts +0 -3
  23. package/dist/src/testutil/keys.d.ts.map +1 -1
  24. package/dist/src/testutil/keys.js +2 -17
  25. package/dist/src/testutil/psbt.d.ts +5 -23
  26. package/dist/src/testutil/psbt.d.ts.map +1 -1
  27. package/dist/src/testutil/psbt.js +13 -16
  28. package/dist/src/testutil/transaction.d.ts +5 -14
  29. package/dist/src/testutil/transaction.d.ts.map +1 -1
  30. package/dist/src/testutil/transaction.js +9 -9
  31. package/package.json +5 -5
  32. package/dist/src/base_crypto.d.ts +0 -14
  33. package/dist/src/base_crypto.d.ts.map +0 -1
  34. package/dist/src/base_crypto.js +0 -215
  35. package/dist/src/bitgo/legacysafe/index.d.ts +0 -15
  36. package/dist/src/bitgo/legacysafe/index.d.ts.map +0 -1
  37. package/dist/src/bitgo/legacysafe/index.js +0 -61
  38. package/dist/src/musig.d.ts +0 -390
  39. package/dist/src/musig.d.ts.map +0 -1
  40. package/dist/src/musig.js +0 -447
@@ -1 +0,0 @@
1
- {"version":3,"file":"base_crypto.d.ts","sourceRoot":"","sources":["../../src/base_crypto.ts"],"names":[],"mappings":"AA4CA,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD;AAkCD,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAqB9C;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAOnD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAKlE;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU,CAKvE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAItD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAInD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAO/C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAO/C;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAcrD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAIhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAW/C"}
@@ -1,215 +0,0 @@
1
- "use strict";
2
- // BigInt / Uint8Array versions of Crypto functions that do not require point
3
- // math. If your JS interpreter has BigInt, you can use all of these. If not,
4
- // you'll need to either shim it in or override more of these functions.
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.hasEvenY = exports.pointX = exports.pointNegate = exports.isSecret = exports.isScalar = exports.scalarMod = exports.scalarNegate = exports.scalarMultiply = exports.scalarAdd = exports.isXOnlyPoint = exports.isPoint = exports.readSecret = exports.readScalar = void 0;
7
- // Idea from noble-secp256k1, be nice to bad JS parsers
8
- const _0n = BigInt(0);
9
- const _1n = BigInt(1);
10
- const _2n = BigInt(2);
11
- const _3n = BigInt(3);
12
- const _5n = BigInt(5);
13
- const _7n = BigInt(7);
14
- const _64n = BigInt(64);
15
- const _64mask = BigInt('0xFFFFFFFFFFFFFFFF');
16
- const MAX_INT = BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
17
- const CURVE = {
18
- b: BigInt(7),
19
- P: BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F'),
20
- n: BigInt('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'),
21
- };
22
- // Big Endian
23
- function read32b(bytes) {
24
- if (bytes.length !== 32)
25
- throw new Error(`Expected 32-bytes, not ${bytes.length}`);
26
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
27
- let b = view.getBigUint64(0);
28
- for (let offs = 8; offs < bytes.length; offs += 8) {
29
- b <<= _64n;
30
- b += view.getBigUint64(offs);
31
- }
32
- return b;
33
- }
34
- function write32b(num, dest = new Uint8Array(32)) {
35
- // All input values are modulo P or n, so no bounds checking needed
36
- const view = new DataView(dest.buffer, dest.byteOffset, dest.length);
37
- for (let offs = 24; offs >= 0; offs -= 8) {
38
- view.setBigUint64(offs, num & _64mask);
39
- num >>= _64n;
40
- }
41
- return dest;
42
- }
43
- function readScalar(bytes) {
44
- const a = read32b(bytes);
45
- if (a >= CURVE.n)
46
- throw new Error('Expected value mod n');
47
- return a;
48
- }
49
- exports.readScalar = readScalar;
50
- function readSecret(bytes) {
51
- const a = readScalar(bytes);
52
- if (a === 0n)
53
- throw new Error('Expected non-zero');
54
- return a;
55
- }
56
- exports.readSecret = readSecret;
57
- // The short Weierstrass form curve equation simplifes to y^2 = x^3 + 7.
58
- function secp256k1Right(x) {
59
- const x2 = (x * x) % CURVE.P;
60
- const x3 = (x2 * x) % CURVE.P;
61
- return (x3 + CURVE.b) % CURVE.P;
62
- }
63
- // For prime P, the Jacobi Symbol of 'a' is 1 if and only if 'a' is a quadratic
64
- // residue mod P, ie. there exists a value 'x' for whom x^2 = a.
65
- function jacobiSymbol(a) {
66
- if (a === _0n)
67
- return 0; // Vanishingly improbable
68
- let p = CURVE.P;
69
- let sign = 1;
70
- // This algorithm is fairly heavily optimized, so don't simplify it w/o benchmarking
71
- for (;;) {
72
- let and3;
73
- // Handle runs of zeros efficiently w/o flipping sign each time
74
- for (and3 = a & _3n; and3 === _0n; a >>= _2n, and3 = a & _3n)
75
- ;
76
- // If there's one more zero, shift it off and flip the sign
77
- if (and3 === _2n) {
78
- a >>= _1n;
79
- const pand7 = p & _7n;
80
- if (pand7 === _3n || pand7 === _5n)
81
- sign = -sign;
82
- }
83
- if (a === _1n)
84
- break;
85
- if ((_3n & a) === _3n && (_3n & p) === _3n)
86
- sign = -sign;
87
- [a, p] = [p % a, a];
88
- }
89
- return sign > 0 ? 1 : -1;
90
- }
91
- function isPoint(p) {
92
- if (p.length < 33)
93
- return false;
94
- const t = p[0];
95
- if (p.length === 33) {
96
- return (t === 0x02 || t === 0x03) && isXOnlyPoint(p.subarray(1));
97
- }
98
- if (t !== 0x04 || p.length !== 65)
99
- return false;
100
- const x = read32b(p.subarray(1, 33));
101
- if (x === _0n)
102
- return false;
103
- if (x >= CURVE.P)
104
- return false;
105
- const y = read32b(p.subarray(33));
106
- if (y === _0n)
107
- return false;
108
- if (y >= CURVE.P)
109
- return false;
110
- const left = (y * y) % CURVE.P;
111
- const right = secp256k1Right(x);
112
- return left === right;
113
- }
114
- exports.isPoint = isPoint;
115
- function isXOnlyPoint(p) {
116
- if (p.length !== 32)
117
- return false;
118
- const x = read32b(p);
119
- if (x === _0n)
120
- return false;
121
- if (x >= CURVE.P)
122
- return false;
123
- const y2 = secp256k1Right(x);
124
- return jacobiSymbol(y2) === 1; // If sqrt(y^2) exists, x is on the curve.
125
- }
126
- exports.isXOnlyPoint = isXOnlyPoint;
127
- function scalarAdd(a, b) {
128
- const aN = readScalar(a);
129
- const bN = readScalar(b);
130
- const sum = (aN + bN) % CURVE.n;
131
- return write32b(sum);
132
- }
133
- exports.scalarAdd = scalarAdd;
134
- function scalarMultiply(a, b) {
135
- const aN = readScalar(a);
136
- const bN = readScalar(b);
137
- const product = (aN * bN) % CURVE.n;
138
- return write32b(product);
139
- }
140
- exports.scalarMultiply = scalarMultiply;
141
- function scalarNegate(a) {
142
- const aN = readScalar(a);
143
- const negated = aN === _0n ? _0n : CURVE.n - aN;
144
- return write32b(negated);
145
- }
146
- exports.scalarNegate = scalarNegate;
147
- function scalarMod(a) {
148
- const aN = read32b(a);
149
- const remainder = aN % CURVE.n;
150
- return write32b(remainder);
151
- }
152
- exports.scalarMod = scalarMod;
153
- function isScalar(t) {
154
- try {
155
- readScalar(t);
156
- return true;
157
- }
158
- catch {
159
- return false;
160
- }
161
- }
162
- exports.isScalar = isScalar;
163
- function isSecret(s) {
164
- try {
165
- readSecret(s);
166
- return true;
167
- }
168
- catch {
169
- return false;
170
- }
171
- }
172
- exports.isSecret = isSecret;
173
- function pointNegate(p) {
174
- // hasEvenY does basic structure check, so start there
175
- const even = hasEvenY(p);
176
- // `from` because node.Buffer.slice doesn't copy but looks like a Uint8Array
177
- const negated = Uint8Array.from(p);
178
- if (p.length === 33) {
179
- negated[0] = even ? 3 : 2;
180
- }
181
- else if (p.length === 65) {
182
- const y = read32b(p.subarray(33));
183
- if (y >= CURVE.P)
184
- throw new Error('Expected Y coordinate mod P');
185
- const minusY = y === _0n ? _0n : CURVE.P - y;
186
- write32b(minusY, negated.subarray(33));
187
- }
188
- return negated;
189
- }
190
- exports.pointNegate = pointNegate;
191
- function pointX(p) {
192
- if (p.length === 32)
193
- return p;
194
- hasEvenY(p); // hasEvenY throws if not well structured
195
- return p.slice(1, 33);
196
- }
197
- exports.pointX = pointX;
198
- function hasEvenY(p) {
199
- if (p.length === 33) {
200
- if (p[0] === 2)
201
- return true;
202
- else if (p[0] === 3)
203
- return false;
204
- else
205
- throw new Error('Wrong first byte to be a point');
206
- }
207
- if (p.length === 65) {
208
- if (p[0] !== 4)
209
- throw new Error('Wrong first byte to be point');
210
- return p[64] % 2 === 0;
211
- }
212
- throw new Error('Wrong length to be a point');
213
- }
214
- exports.hasEvenY = hasEvenY;
215
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZV9jcnlwdG8uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYmFzZV9jcnlwdG8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDZFQUE2RTtBQUM3RSw2RUFBNkU7QUFDN0Usd0VBQXdFOzs7QUFFeEUsdURBQXVEO0FBQ3ZELE1BQU0sR0FBRyxHQUFHLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUN0QixNQUFNLEdBQUcsR0FBRyxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7QUFDdEIsTUFBTSxHQUFHLEdBQUcsTUFBTSxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3RCLE1BQU0sR0FBRyxHQUFHLE1BQU0sQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUN0QixNQUFNLEdBQUcsR0FBRyxNQUFNLENBQUMsQ0FBQyxDQUFDLENBQUM7Q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QgUCcpO1xuICAgIGNvbnN0IG1pbnVzWSA9IHkgPT09IF8wbiA/IF8wbiA6IENVUlZFLlAgLSB5O1xuICAgIHdyaXRlMzJiKG1pbnVzWSwgbmVnYXRlZC5zdWJhcnJheSgzMykpO1xuICB9XG4gIHJldHVybiBuZWdhdGVkO1xufVxuXG5leHBvcnQgZnVuY3Rpb24gcG9pbnRYKHA6IFVpbnQ4QXJyYXkpOiBVaW50OEFycmF5IHtcbiAgaWYgKHAubGVuZ3RoID09PSAzMikgcmV0dXJuIHA7XG4gIGhhc0V2ZW5ZKHApOyAvLyBoYXNFdmVuWSB0aHJvd3MgaWYgbm90IHdlbGwgc3RydWN0dXJlZFxuICByZXR1cm4gcC5zbGljZSgxLCAzMyk7XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBoYXNFdmVuWShwOiBVaW50OEFycmF5KTogYm9vbGVhbiB7XG4gIGlmIChwLmxlbmd0aCA9PT0gMzMpIHtcbiAgICBpZiAocFswXSA9PT0gMikgcmV0dXJuIHRydWU7XG4gICAgZWxzZSBpZiAocFswXSA9PT0gMykgcmV0dXJuIGZhbHNlO1xuICAgIGVsc2UgdGhyb3cgbmV3IEVycm9yKCdXcm9uZyBmaXJzdCBieXRlIHRvIGJlIGEgcG9pbnQnKTtcbiAgfVxuICBpZiAocC5sZW5ndGggPT09IDY1KSB7XG4gICAgaWYgKHBbMF0gIT09IDQpIHRocm93IG5ldyBFcnJvcignV3JvbmcgZmlyc3QgYnl0ZSB0byBiZSBwb2ludCcpO1xuICAgIHJldHVybiBwWzY0XSAlIDIgPT09IDA7XG4gIH1cbiAgdGhyb3cgbmV3IEVycm9yKCdXcm9uZyBsZW5ndGggdG8gYmUgYSBwb2ludCcpO1xufVxuIl19
@@ -1,15 +0,0 @@
1
- /**
2
- * V1 Safe Wallets are the oldest type of wallets that BitGo supports. They were
3
- * created back in 2013-14 and don't use HD chains. Instead, they have only one
4
- * P2SH address per wallet whose redeem script uses uncompressed public keys.
5
- * */
6
- /// <reference types="node" />
7
- import { Network } from '../../networks';
8
- export declare function toUncompressedPub(pubkey: Buffer): Buffer;
9
- export declare function toCompressedPub(pubkey: Buffer): Buffer;
10
- /** create p2sh scripts with uncompressed pubkeys */
11
- export declare function createLegacySafeOutputScript2of3(pubkeys: Buffer[], network?: Network): {
12
- scriptPubKey: Buffer;
13
- redeemScript: Buffer;
14
- };
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/legacysafe/index.ts"],"names":[],"mappings":"AAAA;;;;KAIK;;AAIL,OAAO,EAAa,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAepD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,oDAAoD;AACpD,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB,CAgCA"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- /**
3
- * V1 Safe Wallets are the oldest type of wallets that BitGo supports. They were
4
- * created back in 2013-14 and don't use HD chains. Instead, they have only one
5
- * P2SH address per wallet whose redeem script uses uncompressed public keys.
6
- * */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.createLegacySafeOutputScript2of3 = exports.toCompressedPub = exports.toUncompressedPub = void 0;
9
- const assert = require("assert");
10
- const noble_ecc_1 = require("../../noble_ecc");
11
- const networks_1 = require("../../networks");
12
- const types_1 = require("../types");
13
- const bitcoinjs = require("bitcoinjs-lib");
14
- function getPublicKeyBuffer(publicKey, { compressed = true } = {}) {
15
- const res = noble_ecc_1.ecc.pointCompress(publicKey, compressed);
16
- if (res === null) {
17
- throw new Error('invalid public key');
18
- }
19
- const buffer = Buffer.from(res);
20
- assert.strictEqual(buffer.length, compressed ? 33 : 65);
21
- return buffer;
22
- }
23
- function toUncompressedPub(pubkey) {
24
- return getPublicKeyBuffer(pubkey, { compressed: false });
25
- }
26
- exports.toUncompressedPub = toUncompressedPub;
27
- function toCompressedPub(pubkey) {
28
- return getPublicKeyBuffer(pubkey, { compressed: true });
29
- }
30
- exports.toCompressedPub = toCompressedPub;
31
- /** create p2sh scripts with uncompressed pubkeys */
32
- function createLegacySafeOutputScript2of3(pubkeys, network) {
33
- if (network) {
34
- if (!networks_1.isBitcoin(network)) {
35
- throw new Error(`unsupported network for legacy safe output script: ${network.coin}`);
36
- }
37
- }
38
- if (!types_1.isTriple(pubkeys)) {
39
- throw new Error(`must provide pubkey triple`);
40
- }
41
- pubkeys.forEach((key) => {
42
- if (key.length !== pubkeys[0].length) {
43
- throw new Error(`all pubkeys must have the same length`);
44
- }
45
- if (key.length !== 65 && key.length !== 33) {
46
- // V1 Safe BTC wallets could contain either uncompressed or compressed pubkeys
47
- throw new Error(`Unexpected key length ${key.length}, neither compressed nor uncompressed.`);
48
- }
49
- });
50
- const script2of3 = bitcoinjs.payments.p2ms({ m: 2, pubkeys });
51
- assert(script2of3.output);
52
- const scriptPubKey = bitcoinjs.payments.p2sh({ redeem: script2of3 });
53
- assert(scriptPubKey);
54
- assert(scriptPubKey.output);
55
- return {
56
- scriptPubKey: scriptPubKey.output,
57
- redeemScript: script2of3.output,
58
- };
59
- }
60
- exports.createLegacySafeOutputScript2of3 = createLegacySafeOutputScript2of3;
61
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYml0Z28vbGVnYWN5c2FmZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7S0FJSzs7O0FBRUwsaUNBQWlDO0FBQ2pDLCt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