@buildonspark/spark-sdk 0.0.9 → 0.0.11

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 (82) hide show
  1. package/dist/services/config.d.ts +20 -16
  2. package/dist/services/config.js +26 -18
  3. package/dist/services/config.js.map +1 -1
  4. package/dist/services/connection.js +1 -1
  5. package/dist/services/connection.js.map +1 -1
  6. package/dist/services/deposit.js +2 -2
  7. package/dist/services/deposit.js.map +1 -1
  8. package/dist/services/lightning.js +4 -4
  9. package/dist/services/lightning.js.map +1 -1
  10. package/dist/services/token-transactions.js +8 -7
  11. package/dist/services/token-transactions.js.map +1 -1
  12. package/dist/services/transfer.js +12 -10
  13. package/dist/services/transfer.js.map +1 -1
  14. package/dist/spark-sdk.d.ts +2 -3
  15. package/dist/spark-sdk.js +2 -7
  16. package/dist/spark-sdk.js.map +1 -1
  17. package/dist/tests/coop-exit.test.js +8 -5
  18. package/dist/tests/coop-exit.test.js.map +1 -1
  19. package/dist/tests/deposit.test.js +8 -10
  20. package/dist/tests/deposit.test.js.map +1 -1
  21. package/dist/tests/keys.test.js +0 -1
  22. package/dist/tests/keys.test.js.map +1 -1
  23. package/dist/tests/lightning.test.js +10 -7
  24. package/dist/tests/lightning.test.js.map +1 -1
  25. package/dist/tests/swap.test.js +8 -5
  26. package/dist/tests/swap.test.js.map +1 -1
  27. package/dist/tests/test-util.d.ts +8 -44
  28. package/dist/tests/test-util.js +10 -7
  29. package/dist/tests/test-util.js.map +1 -1
  30. package/dist/tests/transfer.test.js +30 -19
  31. package/dist/tests/transfer.test.js.map +1 -1
  32. package/package.json +2 -2
  33. package/dist/LightningSendRequest-CNJFhLVc.d.cts +0 -374
  34. package/dist/LightningSendRequest-CNJFhLVc.d.ts +0 -374
  35. package/dist/auto-bind.d.ts +0 -7
  36. package/dist/auto-bind.js +0 -41
  37. package/dist/auto-bind.js.map +0 -1
  38. package/dist/chunk-5SAJ52IV.js +0 -10309
  39. package/dist/chunk-COXVABEU.js +0 -1524
  40. package/dist/chunk-F4JW24C4.js +0 -78
  41. package/dist/chunk-H4A2WXR3.js +0 -331
  42. package/dist/chunk-HTNOFUHX.js +0 -1547
  43. package/dist/chunk-JQFHUW4I.js +0 -21
  44. package/dist/chunk-K3Y7DVLD.js +0 -19
  45. package/dist/chunk-NDKNVHGP.js +0 -127
  46. package/dist/chunk-PMVJGQCP.js +0 -627
  47. package/dist/chunk-QX3ZJH2S.js +0 -527
  48. package/dist/chunk-SL2YOBVM.js +0 -127
  49. package/dist/chunk-SWCOMKD6.js +0 -333
  50. package/dist/chunk-SWFFNBSR.js +0 -1244
  51. package/dist/chunk-WLK5POBV.js +0 -527
  52. package/dist/chunk-WZ74TD7N.js +0 -660
  53. package/dist/chunk-WZYVI3M3.js +0 -1244
  54. package/dist/chunk-ZGU3XW7W.js +0 -78
  55. package/dist/connection-BgWj7Hnd.d.cts +0 -77
  56. package/dist/connection-BgbVJtzh.d.ts +0 -77
  57. package/dist/connection-DX-9yFl8.d.ts +0 -77
  58. package/dist/connection-hITj9Mgk.d.cts +0 -77
  59. package/dist/graphql/objects/index.cjs +0 -626
  60. package/dist/graphql/objects/index.d.cts +0 -140
  61. package/dist/index.cjs +0 -17202
  62. package/dist/index.d.cts +0 -413
  63. package/dist/index.d.ts +0 -413
  64. package/dist/index.js +0 -3390
  65. package/dist/proto/spark.cjs +0 -10451
  66. package/dist/proto/spark.d.cts +0 -3
  67. package/dist/services/index.cjs +0 -12503
  68. package/dist/services/index.d.cts +0 -23
  69. package/dist/services/index.d.ts +0 -23
  70. package/dist/services/index.js +0 -17
  71. package/dist/signer/signer.cjs +0 -894
  72. package/dist/signer/signer.d.cts +0 -5
  73. package/dist/signer-BaC_ZP1g.d.ts +0 -138
  74. package/dist/signer-C6h1OnSQ.d.cts +0 -138
  75. package/dist/signer-CO4owhHI.d.ts +0 -154
  76. package/dist/signer-DDkpXvNZ.d.cts +0 -154
  77. package/dist/spark-BUTdOtMz.d.cts +0 -1170
  78. package/dist/spark-BUTdOtMz.d.ts +0 -1170
  79. package/dist/tests/test-util.cjs +0 -12269
  80. package/dist/tests/test-util.d.cts +0 -90
  81. package/dist/utils/index.cjs +0 -1825
  82. package/dist/utils/index.d.cts +0 -280
@@ -1,894 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
26
- mod2
27
- ));
28
- var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
29
-
30
- // src/signer/signer.ts
31
- var signer_exports = {};
32
- __export(signer_exports, {
33
- DefaultSparkSigner: () => DefaultSparkSigner
34
- });
35
- module.exports = __toCommonJS(signer_exports);
36
- var import_utils4 = require("@noble/curves/abstract/utils");
37
- var import_secp256k15 = require("@noble/curves/secp256k1");
38
- var import_bip32 = require("@scure/bip32");
39
- var bip39 = __toESM(require("@scure/bip39"), 1);
40
- var import_bip39 = require("@scure/bip39");
41
- var import_english = require("@scure/bip39/wordlists/english");
42
- var import_utils5 = require("@scure/btc-signer/utils");
43
- var import_buffer = require("buffer");
44
- var ecies = __toESM(require("eciesjs"), 1);
45
-
46
- // src/utils/adaptor-signature.ts
47
- var import_modular = require("@noble/curves/abstract/modular");
48
- var import_utils = require("@noble/curves/abstract/utils");
49
- var import_secp256k1 = require("@noble/curves/secp256k1");
50
- function generateAdaptorFromSignature(signature) {
51
- const adaptorPrivateKey = import_secp256k1.secp256k1.utils.randomPrivateKey();
52
- const { r, s } = parseSignature(signature);
53
- const sBigInt = (0, import_utils.bytesToNumberBE)(s);
54
- const tBigInt = (0, import_utils.bytesToNumberBE)(adaptorPrivateKey);
55
- const newS = (0, import_modular.mod)(sBigInt - tBigInt, import_secp256k1.secp256k1.CURVE.n);
56
- const newSignature = new Uint8Array([...r, ...(0, import_utils.numberToBytesBE)(newS, 32)]);
57
- return {
58
- adaptorSignature: newSignature,
59
- adaptorPrivateKey
60
- };
61
- }
62
- function parseSignature(signature) {
63
- if (signature.length < 64) {
64
- throw new Error(`malformed signature: too short: ${signature.length} < 64`);
65
- }
66
- if (signature.length > 64) {
67
- throw new Error(`malformed signature: too long: ${signature.length} > 64`);
68
- }
69
- const r = signature.slice(0, 32);
70
- const s = signature.slice(32, 64);
71
- if ((0, import_utils.bytesToNumberBE)(r) >= import_secp256k1.secp256k1.CURVE.Fp.ORDER) {
72
- throw new Error(`invalid signature: r >= field prime`);
73
- }
74
- if ((0, import_utils.bytesToNumberBE)(s) >= import_secp256k1.secp256k1.CURVE.n) {
75
- throw new Error(`invalid signature: s >= group order`);
76
- }
77
- return { r, s };
78
- }
79
-
80
- // src/utils/keys.ts
81
- var import_secp256k12 = require("@noble/curves/secp256k1");
82
- var import_utils2 = require("@noble/curves/abstract/utils");
83
- function subtractPrivateKeys(a, b) {
84
- if (a.length !== 32 || b.length !== 32) {
85
- throw new Error("Private keys must be 32 bytes");
86
- }
87
- const privA = import_secp256k12.secp256k1.utils.normPrivateKeyToScalar(a);
88
- const privB = import_secp256k12.secp256k1.utils.normPrivateKeyToScalar(b);
89
- const sum = (import_secp256k12.secp256k1.CURVE.n - privB + privA) % import_secp256k12.secp256k1.CURVE.n;
90
- return (0, import_utils2.numberToBytesBE)(sum, 32);
91
- }
92
-
93
- // src/utils/network.ts
94
- var btc = __toESM(require("@scure/btc-signer"), 1);
95
- var NetworkToProto = {
96
- [0 /* MAINNET */]: 0 /* MAINNET */,
97
- [1 /* TESTNET */]: 2 /* TESTNET */,
98
- [2 /* SIGNET */]: 3 /* SIGNET */,
99
- [3 /* REGTEST */]: 1 /* REGTEST */,
100
- [4 /* LOCAL */]: 1 /* REGTEST */
101
- };
102
- var NetworkConfig = {
103
- [0 /* MAINNET */]: btc.NETWORK,
104
- [1 /* TESTNET */]: btc.TEST_NETWORK,
105
- [2 /* SIGNET */]: btc.TEST_NETWORK,
106
- [3 /* REGTEST */]: { ...btc.TEST_NETWORK, bech32: "bcrt" },
107
- [4 /* LOCAL */]: { ...btc.TEST_NETWORK, bech32: "bcrt" }
108
- };
109
-
110
- // src/utils/secret-sharing.ts
111
- var import_utils3 = require("@noble/curves/abstract/utils");
112
- var import_secp256k13 = require("@noble/curves/secp256k1");
113
-
114
- // src/utils/crypto.ts
115
- var import_crypto = __toESM(require("crypto"), 1);
116
- var getCrypto = () => {
117
- if (typeof window !== "undefined" && window.crypto) {
118
- return window.crypto;
119
- }
120
- if (typeof global !== "undefined" && global.crypto) {
121
- return global.crypto;
122
- }
123
- return import_crypto.default;
124
- };
125
-
126
- // src/utils/secret-sharing.ts
127
- var crypto2 = getCrypto();
128
- function getRandomBigInt(max) {
129
- const byteLength = max.toString(2).length + 7 >> 3;
130
- const maxBigInt = max;
131
- const mask = (1n << BigInt(max.toString(2).length)) - 1n;
132
- while (true) {
133
- const randBytes = crypto2.getRandomValues(new Uint8Array(byteLength + 1));
134
- const randValue = BigInt("0x" + (0, import_utils3.bytesToHex)(randBytes)) & mask;
135
- if (randValue < maxBigInt) {
136
- return randValue;
137
- }
138
- }
139
- }
140
- function evaluatePolynomial(polynomial, x) {
141
- let result = 0n;
142
- for (let i = 0; i < polynomial.coefficients.length; i++) {
143
- const coeff = polynomial.coefficients[i];
144
- if (!coeff) {
145
- throw new Error("Coefficient is undefined");
146
- }
147
- const xPow = x ** BigInt(i) % polynomial.fieldModulus;
148
- result = (result + xPow * coeff) % polynomial.fieldModulus;
149
- }
150
- return result;
151
- }
152
- function generatePolynomialForSecretSharing(fieldModulus, secret, degree) {
153
- const coefficients = new Array(degree);
154
- const proofs = new Array(degree);
155
- coefficients[0] = secret;
156
- proofs[0] = import_secp256k13.secp256k1.ProjectivePoint.fromPrivateKey(secret).toRawBytes(true);
157
- for (let i = 1; i < degree; i++) {
158
- const coefficient = getRandomBigInt(fieldModulus);
159
- coefficients[i] = coefficient;
160
- proofs[i] = import_secp256k13.secp256k1.ProjectivePoint.fromPrivateKey(coefficient).toRawBytes(true);
161
- }
162
- return {
163
- fieldModulus,
164
- coefficients,
165
- proofs
166
- };
167
- }
168
- function splitSecretWithProofs(secret, fieldModulus, threshold, numberOfShares) {
169
- const polynomial = generatePolynomialForSecretSharing(
170
- fieldModulus,
171
- secret,
172
- threshold - 1
173
- );
174
- const shares = [];
175
- for (let i = 1; i <= numberOfShares; i++) {
176
- const share = evaluatePolynomial(polynomial, BigInt(i));
177
- shares.push({
178
- fieldModulus,
179
- threshold,
180
- index: BigInt(i),
181
- share,
182
- proofs: polynomial.proofs
183
- });
184
- }
185
- return shares;
186
- }
187
-
188
- // src/utils/signing.ts
189
- var import_secp256k14 = require("@noble/curves/secp256k1");
190
-
191
- // src/wasm/spark_bindings.js
192
- var wasm;
193
- var WASM_VECTOR_LEN = 0;
194
- var cachedUint8ArrayMemory0 = null;
195
- function getUint8ArrayMemory0() {
196
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
197
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
198
- }
199
- return cachedUint8ArrayMemory0;
200
- }
201
- var cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => {
202
- throw Error("TextEncoder not available");
203
- } };
204
- var encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
205
- return cachedTextEncoder.encodeInto(arg, view);
206
- } : function(arg, view) {
207
- const buf = cachedTextEncoder.encode(arg);
208
- view.set(buf);
209
- return {
210
- read: arg.length,
211
- written: buf.length
212
- };
213
- };
214
- var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => {
215
- throw Error("TextDecoder not available");
216
- } };
217
- if (typeof TextDecoder !== "undefined") {
218
- cachedTextDecoder.decode();
219
- }
220
- function isLikeNone(x) {
221
- return x === void 0 || x === null;
222
- }
223
- function getArrayU8FromWasm0(ptr, len) {
224
- ptr = ptr >>> 0;
225
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
226
- }
227
- function passArray8ToWasm0(arg, malloc) {
228
- const ptr = malloc(arg.length * 1, 1) >>> 0;
229
- getUint8ArrayMemory0().set(arg, ptr / 1);
230
- WASM_VECTOR_LEN = arg.length;
231
- return ptr;
232
- }
233
- function _assertClass(instance, klass) {
234
- if (!(instance instanceof klass)) {
235
- throw new Error(`expected instance of ${klass.name}`);
236
- }
237
- }
238
- function takeFromExternrefTable0(idx) {
239
- const value = wasm.__wbindgen_export_4.get(idx);
240
- wasm.__externref_table_dealloc(idx);
241
- return value;
242
- }
243
- function wasm_sign_frost(msg, key_package, nonce, self_commitment, statechain_commitments, adaptor_public_key) {
244
- const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
245
- const len0 = WASM_VECTOR_LEN;
246
- _assertClass(key_package, KeyPackage);
247
- var ptr1 = key_package.__destroy_into_raw();
248
- _assertClass(nonce, SigningNonce);
249
- var ptr2 = nonce.__destroy_into_raw();
250
- _assertClass(self_commitment, SigningCommitment2);
251
- var ptr3 = self_commitment.__destroy_into_raw();
252
- var ptr4 = isLikeNone(adaptor_public_key) ? 0 : passArray8ToWasm0(adaptor_public_key, wasm.__wbindgen_malloc);
253
- var len4 = WASM_VECTOR_LEN;
254
- const ret = wasm.wasm_sign_frost(ptr0, len0, ptr1, ptr2, ptr3, statechain_commitments, ptr4, len4);
255
- if (ret[3]) {
256
- throw takeFromExternrefTable0(ret[2]);
257
- }
258
- var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
259
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
260
- return v6;
261
- }
262
- function wasm_aggregate_frost(msg, statechain_commitments, self_commitment, statechain_signatures, self_signature, statechain_public_keys, self_public_key, verifying_key, adaptor_public_key) {
263
- const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
264
- const len0 = WASM_VECTOR_LEN;
265
- _assertClass(self_commitment, SigningCommitment2);
266
- var ptr1 = self_commitment.__destroy_into_raw();
267
- const ptr2 = passArray8ToWasm0(self_signature, wasm.__wbindgen_malloc);
268
- const len2 = WASM_VECTOR_LEN;
269
- const ptr3 = passArray8ToWasm0(self_public_key, wasm.__wbindgen_malloc);
270
- const len3 = WASM_VECTOR_LEN;
271
- const ptr4 = passArray8ToWasm0(verifying_key, wasm.__wbindgen_malloc);
272
- const len4 = WASM_VECTOR_LEN;
273
- var ptr5 = isLikeNone(adaptor_public_key) ? 0 : passArray8ToWasm0(adaptor_public_key, wasm.__wbindgen_malloc);
274
- var len5 = WASM_VECTOR_LEN;
275
- const ret = wasm.wasm_aggregate_frost(ptr0, len0, statechain_commitments, ptr1, statechain_signatures, ptr2, len2, statechain_public_keys, ptr3, len3, ptr4, len4, ptr5, len5);
276
- if (ret[3]) {
277
- throw takeFromExternrefTable0(ret[2]);
278
- }
279
- var v7 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
280
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
281
- return v7;
282
- }
283
- var DummyTxFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
284
- }, unregister: () => {
285
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_dummytx_free(ptr >>> 0, 1));
286
- var KeyPackageFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
287
- }, unregister: () => {
288
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_keypackage_free(ptr >>> 0, 1));
289
- var KeyPackage = class {
290
- __destroy_into_raw() {
291
- const ptr = this.__wbg_ptr;
292
- this.__wbg_ptr = 0;
293
- KeyPackageFinalization.unregister(this);
294
- return ptr;
295
- }
296
- free() {
297
- const ptr = this.__destroy_into_raw();
298
- wasm.__wbg_keypackage_free(ptr, 0);
299
- }
300
- /**
301
- * @returns {Uint8Array}
302
- */
303
- get secret_key() {
304
- const ret = wasm.__wbg_get_keypackage_secret_key(this.__wbg_ptr);
305
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
306
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
307
- return v1;
308
- }
309
- /**
310
- * @param {Uint8Array} arg0
311
- */
312
- set secret_key(arg0) {
313
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
314
- const len0 = WASM_VECTOR_LEN;
315
- wasm.__wbg_set_dummytx_tx(this.__wbg_ptr, ptr0, len0);
316
- }
317
- /**
318
- * @returns {Uint8Array}
319
- */
320
- get public_key() {
321
- const ret = wasm.__wbg_get_keypackage_public_key(this.__wbg_ptr);
322
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
323
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
324
- return v1;
325
- }
326
- /**
327
- * @param {Uint8Array} arg0
328
- */
329
- set public_key(arg0) {
330
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
331
- const len0 = WASM_VECTOR_LEN;
332
- wasm.__wbg_set_dummytx_txid(this.__wbg_ptr, ptr0, len0);
333
- }
334
- /**
335
- * @returns {Uint8Array}
336
- */
337
- get verifying_key() {
338
- const ret = wasm.__wbg_get_keypackage_verifying_key(this.__wbg_ptr);
339
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
340
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
341
- return v1;
342
- }
343
- /**
344
- * @param {Uint8Array} arg0
345
- */
346
- set verifying_key(arg0) {
347
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
348
- const len0 = WASM_VECTOR_LEN;
349
- wasm.__wbg_set_keypackage_verifying_key(this.__wbg_ptr, ptr0, len0);
350
- }
351
- /**
352
- * @param {Uint8Array} secret_key
353
- * @param {Uint8Array} public_key
354
- * @param {Uint8Array} verifying_key
355
- */
356
- constructor(secret_key, public_key, verifying_key) {
357
- const ptr0 = passArray8ToWasm0(secret_key, wasm.__wbindgen_malloc);
358
- const len0 = WASM_VECTOR_LEN;
359
- const ptr1 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
360
- const len1 = WASM_VECTOR_LEN;
361
- const ptr2 = passArray8ToWasm0(verifying_key, wasm.__wbindgen_malloc);
362
- const len2 = WASM_VECTOR_LEN;
363
- const ret = wasm.keypackage_new(ptr0, len0, ptr1, len1, ptr2, len2);
364
- this.__wbg_ptr = ret >>> 0;
365
- KeyPackageFinalization.register(this, this.__wbg_ptr, this);
366
- return this;
367
- }
368
- };
369
- var NonceResultFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
370
- }, unregister: () => {
371
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_nonceresult_free(ptr >>> 0, 1));
372
- var SigningCommitmentFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
373
- }, unregister: () => {
374
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_signingcommitment_free(ptr >>> 0, 1));
375
- var SigningCommitment2 = class _SigningCommitment {
376
- static __wrap(ptr) {
377
- ptr = ptr >>> 0;
378
- const obj = Object.create(_SigningCommitment.prototype);
379
- obj.__wbg_ptr = ptr;
380
- SigningCommitmentFinalization.register(obj, obj.__wbg_ptr, obj);
381
- return obj;
382
- }
383
- __destroy_into_raw() {
384
- const ptr = this.__wbg_ptr;
385
- this.__wbg_ptr = 0;
386
- SigningCommitmentFinalization.unregister(this);
387
- return ptr;
388
- }
389
- free() {
390
- const ptr = this.__destroy_into_raw();
391
- wasm.__wbg_signingcommitment_free(ptr, 0);
392
- }
393
- /**
394
- * @returns {Uint8Array}
395
- */
396
- get hiding() {
397
- const ret = wasm.__wbg_get_signingcommitment_hiding(this.__wbg_ptr);
398
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
399
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
400
- return v1;
401
- }
402
- /**
403
- * @param {Uint8Array} arg0
404
- */
405
- set hiding(arg0) {
406
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
407
- const len0 = WASM_VECTOR_LEN;
408
- wasm.__wbg_set_dummytx_tx(this.__wbg_ptr, ptr0, len0);
409
- }
410
- /**
411
- * @returns {Uint8Array}
412
- */
413
- get binding() {
414
- const ret = wasm.__wbg_get_signingcommitment_binding(this.__wbg_ptr);
415
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
416
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
417
- return v1;
418
- }
419
- /**
420
- * @param {Uint8Array} arg0
421
- */
422
- set binding(arg0) {
423
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
424
- const len0 = WASM_VECTOR_LEN;
425
- wasm.__wbg_set_dummytx_txid(this.__wbg_ptr, ptr0, len0);
426
- }
427
- /**
428
- * @param {Uint8Array} hiding
429
- * @param {Uint8Array} binding
430
- */
431
- constructor(hiding, binding) {
432
- const ptr0 = passArray8ToWasm0(hiding, wasm.__wbindgen_malloc);
433
- const len0 = WASM_VECTOR_LEN;
434
- const ptr1 = passArray8ToWasm0(binding, wasm.__wbindgen_malloc);
435
- const len1 = WASM_VECTOR_LEN;
436
- const ret = wasm.signingcommitment_new(ptr0, len0, ptr1, len1);
437
- this.__wbg_ptr = ret >>> 0;
438
- SigningCommitmentFinalization.register(this, this.__wbg_ptr, this);
439
- return this;
440
- }
441
- };
442
- var SigningNonceFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
443
- }, unregister: () => {
444
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_signingnonce_free(ptr >>> 0, 1));
445
- var SigningNonce = class _SigningNonce {
446
- static __wrap(ptr) {
447
- ptr = ptr >>> 0;
448
- const obj = Object.create(_SigningNonce.prototype);
449
- obj.__wbg_ptr = ptr;
450
- SigningNonceFinalization.register(obj, obj.__wbg_ptr, obj);
451
- return obj;
452
- }
453
- __destroy_into_raw() {
454
- const ptr = this.__wbg_ptr;
455
- this.__wbg_ptr = 0;
456
- SigningNonceFinalization.unregister(this);
457
- return ptr;
458
- }
459
- free() {
460
- const ptr = this.__destroy_into_raw();
461
- wasm.__wbg_signingnonce_free(ptr, 0);
462
- }
463
- /**
464
- * @returns {Uint8Array}
465
- */
466
- get hiding() {
467
- const ret = wasm.__wbg_get_signingnonce_hiding(this.__wbg_ptr);
468
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
469
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
470
- return v1;
471
- }
472
- /**
473
- * @param {Uint8Array} arg0
474
- */
475
- set hiding(arg0) {
476
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
477
- const len0 = WASM_VECTOR_LEN;
478
- wasm.__wbg_set_dummytx_tx(this.__wbg_ptr, ptr0, len0);
479
- }
480
- /**
481
- * @returns {Uint8Array}
482
- */
483
- get binding() {
484
- const ret = wasm.__wbg_get_signingnonce_binding(this.__wbg_ptr);
485
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
486
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
487
- return v1;
488
- }
489
- /**
490
- * @param {Uint8Array} arg0
491
- */
492
- set binding(arg0) {
493
- const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
494
- const len0 = WASM_VECTOR_LEN;
495
- wasm.__wbg_set_dummytx_txid(this.__wbg_ptr, ptr0, len0);
496
- }
497
- /**
498
- * @param {Uint8Array} hiding
499
- * @param {Uint8Array} binding
500
- */
501
- constructor(hiding, binding) {
502
- const ptr0 = passArray8ToWasm0(hiding, wasm.__wbindgen_malloc);
503
- const len0 = WASM_VECTOR_LEN;
504
- const ptr1 = passArray8ToWasm0(binding, wasm.__wbindgen_malloc);
505
- const len1 = WASM_VECTOR_LEN;
506
- const ret = wasm.signingcommitment_new(ptr0, len0, ptr1, len1);
507
- this.__wbg_ptr = ret >>> 0;
508
- SigningNonceFinalization.register(this, this.__wbg_ptr, this);
509
- return this;
510
- }
511
- };
512
- var TransactionResultFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
513
- }, unregister: () => {
514
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_transactionresult_free(ptr >>> 0, 1));
515
-
516
- // src/utils/signing.ts
517
- function getRandomSigningNonce() {
518
- const binding = import_secp256k14.secp256k1.utils.randomPrivateKey();
519
- const hiding = import_secp256k14.secp256k1.utils.randomPrivateKey();
520
- return createSigningNonce(binding, hiding);
521
- }
522
- function createSigningNonce(binding, hiding) {
523
- if (binding.length !== 32 || hiding.length !== 32) {
524
- throw new Error("Invalid nonce length");
525
- }
526
- return {
527
- binding,
528
- hiding
529
- };
530
- }
531
- function getSigningCommitmentFromNonce(nonce) {
532
- const bindingPubKey = import_secp256k14.secp256k1.getPublicKey(nonce.binding, true);
533
- const hidingPubKey = import_secp256k14.secp256k1.getPublicKey(nonce.hiding, true);
534
- return {
535
- binding: bindingPubKey,
536
- hiding: hidingPubKey
537
- };
538
- }
539
- function createWasmSigningNonce(nonce) {
540
- return new SigningNonce(nonce.hiding, nonce.binding);
541
- }
542
- function createWasmSigningCommitment(commitment) {
543
- return new SigningCommitment2(commitment.hiding, commitment.binding);
544
- }
545
-
546
- // src/utils/wasm.ts
547
- function signFrost({
548
- msg,
549
- keyPackage,
550
- nonce,
551
- selfCommitment,
552
- statechainCommitments,
553
- adaptorPubKey
554
- }) {
555
- return wasm_sign_frost(
556
- msg,
557
- keyPackage,
558
- nonce,
559
- selfCommitment,
560
- statechainCommitments,
561
- adaptorPubKey
562
- );
563
- }
564
- function aggregateFrost({
565
- msg,
566
- statechainCommitments,
567
- selfCommitment,
568
- statechainSignatures,
569
- selfSignature,
570
- statechainPublicKeys,
571
- selfPublicKey,
572
- verifyingKey,
573
- adaptorPubKey
574
- }) {
575
- return wasm_aggregate_frost(
576
- msg,
577
- statechainCommitments,
578
- selfCommitment,
579
- statechainSignatures,
580
- selfSignature,
581
- statechainPublicKeys,
582
- selfPublicKey,
583
- verifyingKey,
584
- adaptorPubKey
585
- );
586
- }
587
-
588
- // src/signer/signer.ts
589
- globalThis.Buffer = import_buffer.Buffer;
590
- var DefaultSparkSigner = class {
591
- identityPrivateKey = null;
592
- // <hex, hex>
593
- publicKeyToPrivateKeyMap = /* @__PURE__ */ new Map();
594
- commitmentToNonceMap = /* @__PURE__ */ new Map();
595
- deriveSigningKey(hash) {
596
- if (!this.identityPrivateKey) {
597
- throw new Error("Private key is not set");
598
- }
599
- let amount = 0;
600
- for (let i = 0; i < 8; i++) {
601
- const view = new DataView(hash.buffer, i * 4, 4);
602
- amount += view.getUint32(0, false);
603
- amount = amount % 2147483648;
604
- }
605
- const newPrivateKey = this.identityPrivateKey.deriveChild(
606
- Number(amount) + 2147483648
607
- ).privateKey;
608
- if (!newPrivateKey) {
609
- throw new Error("Failed to recover signing key");
610
- }
611
- return newPrivateKey;
612
- }
613
- async restoreSigningKeysFromLeafs(leafs) {
614
- if (!this.identityPrivateKey) {
615
- throw new Error("Private key is not set");
616
- }
617
- for (const leaf of leafs) {
618
- const hash = (0, import_utils5.sha256)(leaf.id);
619
- const privateKey = this.deriveSigningKey(hash);
620
- const publicKey = import_secp256k15.secp256k1.getPublicKey(privateKey);
621
- this.publicKeyToPrivateKeyMap.set(
622
- (0, import_utils4.bytesToHex)(publicKey),
623
- (0, import_utils4.bytesToHex)(privateKey)
624
- );
625
- }
626
- }
627
- async getSchnorrPublicKey(publicKey) {
628
- const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey));
629
- if (!privateKey) {
630
- throw new Error("Private key is not set");
631
- }
632
- return import_secp256k15.schnorr.getPublicKey((0, import_utils4.hexToBytes)(privateKey));
633
- }
634
- async signSchnorr(message, publicKey) {
635
- const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey));
636
- if (!privateKey) {
637
- throw new Error("Private key is not set");
638
- }
639
- return import_secp256k15.schnorr.sign(message, (0, import_utils4.hexToBytes)(privateKey));
640
- }
641
- async signSchnorrWithIdentityKey(message) {
642
- if (!this.identityPrivateKey?.privateKey) {
643
- throw new Error("Private key is not set");
644
- }
645
- const signature = import_secp256k15.schnorr.sign(
646
- message,
647
- this.identityPrivateKey.privateKey
648
- );
649
- return signature;
650
- }
651
- async getIdentityPublicKey() {
652
- if (!this.identityPrivateKey?.privateKey) {
653
- throw new Error("Private key is not set");
654
- }
655
- return import_secp256k15.secp256k1.getPublicKey(this.identityPrivateKey.privateKey);
656
- }
657
- async generateMnemonic() {
658
- return (0, import_bip39.generateMnemonic)(import_english.wordlist);
659
- }
660
- async createSparkWalletFromMnemonic(mnemonic, network) {
661
- const seed = await bip39.mnemonicToSeed(mnemonic);
662
- return this.createSparkWalletFromSeed(seed, network);
663
- }
664
- async getTrackedPublicKeys() {
665
- return Array.from(this.publicKeyToPrivateKeyMap.keys()).map(import_utils4.hexToBytes);
666
- }
667
- async generatePublicKey(hash) {
668
- if (!this.identityPrivateKey) {
669
- throw new Error("Private key is not set");
670
- }
671
- let newPrivateKey = null;
672
- if (hash) {
673
- newPrivateKey = this.deriveSigningKey(hash);
674
- } else {
675
- newPrivateKey = import_secp256k15.secp256k1.utils.randomPrivateKey();
676
- }
677
- if (!newPrivateKey) {
678
- throw new Error("Failed to generate new private key");
679
- }
680
- const publicKey = import_secp256k15.secp256k1.getPublicKey(newPrivateKey);
681
- const pubKeyHex = (0, import_utils4.bytesToHex)(publicKey);
682
- const privKeyHex = (0, import_utils4.bytesToHex)(newPrivateKey);
683
- this.publicKeyToPrivateKeyMap.set(pubKeyHex, privKeyHex);
684
- return publicKey;
685
- }
686
- async removePublicKey(publicKey) {
687
- this.publicKeyToPrivateKeyMap.delete((0, import_utils4.bytesToHex)(publicKey));
688
- }
689
- async subtractPrivateKeysGivenPublicKeys(first, second) {
690
- const firstPubKeyHex = (0, import_utils4.bytesToHex)(first);
691
- const secondPubKeyHex = (0, import_utils4.bytesToHex)(second);
692
- const firstPrivateKeyHex = this.publicKeyToPrivateKeyMap.get(firstPubKeyHex);
693
- const secondPrivateKeyHex = this.publicKeyToPrivateKeyMap.get(secondPubKeyHex);
694
- if (!firstPrivateKeyHex || !secondPrivateKeyHex) {
695
- throw new Error("Private key is not set");
696
- }
697
- const firstPrivateKey = (0, import_utils4.hexToBytes)(firstPrivateKeyHex);
698
- const secondPrivateKey = (0, import_utils4.hexToBytes)(secondPrivateKeyHex);
699
- const resultPrivKey = subtractPrivateKeys(
700
- firstPrivateKey,
701
- secondPrivateKey
702
- );
703
- const resultPubKey = import_secp256k15.secp256k1.getPublicKey(resultPrivKey);
704
- const resultPrivKeyHex = (0, import_utils4.bytesToHex)(resultPrivKey);
705
- const resultPubKeyHex = (0, import_utils4.bytesToHex)(resultPubKey);
706
- this.publicKeyToPrivateKeyMap.set(resultPubKeyHex, resultPrivKeyHex);
707
- return resultPubKey;
708
- }
709
- async splitSecretWithProofs({
710
- secret,
711
- curveOrder,
712
- threshold,
713
- numShares,
714
- isSecretPubkey = false
715
- }) {
716
- if (isSecretPubkey) {
717
- const pubKeyHex = (0, import_utils4.bytesToHex)(secret);
718
- const privateKey = this.publicKeyToPrivateKeyMap.get(pubKeyHex);
719
- if (!privateKey) {
720
- throw new Error("Private key is not set");
721
- }
722
- secret = (0, import_utils4.hexToBytes)(privateKey);
723
- }
724
- const secretAsInt = (0, import_utils4.bytesToNumberBE)(secret);
725
- return splitSecretWithProofs(secretAsInt, curveOrder, threshold, numShares);
726
- }
727
- async signFrost({
728
- message,
729
- privateAsPubKey,
730
- publicKey,
731
- verifyingKey,
732
- selfCommitment,
733
- statechainCommitments,
734
- adaptorPubKey
735
- }) {
736
- const privateAsPubKeyHex = (0, import_utils4.bytesToHex)(privateAsPubKey);
737
- const signingPrivateKey = this.publicKeyToPrivateKeyMap.get(privateAsPubKeyHex);
738
- if (!signingPrivateKey) {
739
- throw new Error("Private key is not set");
740
- }
741
- const nonce = this.commitmentToNonceMap.get(selfCommitment);
742
- if (!nonce) {
743
- throw new Error("Nonce is not set");
744
- }
745
- const keyPackage = new KeyPackage(
746
- (0, import_utils4.hexToBytes)(signingPrivateKey),
747
- publicKey,
748
- verifyingKey
749
- );
750
- return signFrost({
751
- msg: message,
752
- keyPackage,
753
- nonce: createWasmSigningNonce(nonce),
754
- selfCommitment: createWasmSigningCommitment(selfCommitment),
755
- statechainCommitments,
756
- adaptorPubKey
757
- });
758
- }
759
- async aggregateFrost({
760
- message,
761
- publicKey,
762
- verifyingKey,
763
- selfCommitment,
764
- statechainCommitments,
765
- adaptorPubKey,
766
- selfSignature,
767
- statechainSignatures,
768
- statechainPublicKeys
769
- }) {
770
- return aggregateFrost({
771
- msg: message,
772
- statechainSignatures,
773
- statechainPublicKeys,
774
- verifyingKey,
775
- statechainCommitments,
776
- selfCommitment: createWasmSigningCommitment(selfCommitment),
777
- selfPublicKey: publicKey,
778
- selfSignature,
779
- adaptorPubKey
780
- });
781
- }
782
- async createSparkWalletFromSeed(seed, network) {
783
- if (typeof seed === "string") {
784
- seed = (0, import_utils4.hexToBytes)(seed);
785
- }
786
- const hdkey = import_bip32.HDKey.fromMasterSeed(seed).derive(
787
- `m/${network === 3 /* REGTEST */ ? "0" : "1"}`
788
- );
789
- if (!hdkey.privateKey) {
790
- throw new Error("Could not derive private key from seed");
791
- }
792
- this.identityPrivateKey = hdkey;
793
- return (0, import_utils4.bytesToHex)(import_secp256k15.secp256k1.getPublicKey(hdkey.privateKey, true));
794
- }
795
- async signMessageWithPublicKey(message, publicKey, compact) {
796
- const privateKey = this.publicKeyToPrivateKeyMap.get((0, import_utils4.bytesToHex)(publicKey));
797
- if (!privateKey) {
798
- throw new Error(
799
- `No private key found for public key: ${(0, import_utils4.bytesToHex)(publicKey)}`
800
- );
801
- }
802
- const signature = import_secp256k15.secp256k1.sign(message, (0, import_utils4.hexToBytes)(privateKey));
803
- if (compact) {
804
- return signature.toCompactRawBytes();
805
- }
806
- return signature.toDERRawBytes();
807
- }
808
- async signMessageWithIdentityKey(message, compact) {
809
- if (!this.identityPrivateKey?.privateKey) {
810
- throw new Error("Private key is not set");
811
- }
812
- const signature = import_secp256k15.secp256k1.sign(
813
- message,
814
- this.identityPrivateKey.privateKey
815
- );
816
- if (compact) {
817
- return signature.toCompactRawBytes();
818
- }
819
- return signature.toDERRawBytes();
820
- }
821
- async encryptLeafPrivateKeyEcies(receiverPublicKey, publicKey) {
822
- const publicKeyHex = (0, import_utils4.bytesToHex)(publicKey);
823
- const privateKey = this.publicKeyToPrivateKeyMap.get(publicKeyHex);
824
- if (!privateKey) {
825
- throw new Error("Private key is not set");
826
- }
827
- return ecies.encrypt(receiverPublicKey, (0, import_utils4.hexToBytes)(privateKey));
828
- }
829
- async decryptEcies(ciphertext) {
830
- if (!this.identityPrivateKey?.privateKey) {
831
- throw new Error("Private key is not set");
832
- }
833
- const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
834
- (0, import_utils4.bytesToHex)(this.identityPrivateKey.privateKey)
835
- );
836
- const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
837
- const publicKey = import_secp256k15.secp256k1.getPublicKey(privateKey);
838
- const publicKeyHex = (0, import_utils4.bytesToHex)(publicKey);
839
- const privateKeyHex = (0, import_utils4.bytesToHex)(privateKey);
840
- this.publicKeyToPrivateKeyMap.set(publicKeyHex, privateKeyHex);
841
- return publicKey;
842
- }
843
- async getRandomSigningCommitment() {
844
- const nonce = getRandomSigningNonce();
845
- const commitment = getSigningCommitmentFromNonce(nonce);
846
- this.commitmentToNonceMap.set(commitment, nonce);
847
- return commitment;
848
- }
849
- // Hardcode this for default ssp
850
- async getSspIdentityPublicKey(network) {
851
- if (network === 0 /* MAINNET */) {
852
- return (0, import_utils4.hexToBytes)(
853
- "02e0b8d42c5d3b5fe4c5beb6ea796ab3bc8aaf28a3d3195407482c67e0b58228a5"
854
- );
855
- } else {
856
- return (0, import_utils4.hexToBytes)(
857
- "028c094a432d46a0ac95349d792c2e3730bd60c29188db716f56a99e39b95338b4"
858
- );
859
- }
860
- }
861
- async hashRandomPrivateKey() {
862
- return (0, import_utils5.sha256)(import_secp256k15.secp256k1.utils.randomPrivateKey());
863
- }
864
- async generateAdaptorFromSignature(signature) {
865
- const adaptor = generateAdaptorFromSignature(signature);
866
- const adaptorPublicKey = import_secp256k15.secp256k1.getPublicKey(adaptor.adaptorPrivateKey);
867
- this.publicKeyToPrivateKeyMap.set(
868
- (0, import_utils4.bytesToHex)(adaptorPublicKey),
869
- (0, import_utils4.bytesToHex)(adaptor.adaptorPrivateKey)
870
- );
871
- return {
872
- adaptorSignature: signature,
873
- adaptorPublicKey
874
- };
875
- }
876
- async getDepositSigningKey() {
877
- if (!this.identityPrivateKey?.privateKey) {
878
- throw new Error("Private key is not set");
879
- }
880
- const depositSigningKey = this.identityPrivateKey.derive("M/8797555'/0'/2'");
881
- if (!depositSigningKey.privateKey) {
882
- throw new Error("Could not derive deposit signing key");
883
- }
884
- this.publicKeyToPrivateKeyMap.set(
885
- (0, import_utils4.bytesToHex)(import_secp256k15.secp256k1.getPublicKey(depositSigningKey.privateKey)),
886
- (0, import_utils4.bytesToHex)(depositSigningKey.privateKey)
887
- );
888
- return import_secp256k15.secp256k1.getPublicKey(depositSigningKey.privateKey);
889
- }
890
- };
891
- // Annotate the CommonJS export names for ESM import in node:
892
- 0 && (module.exports = {
893
- DefaultSparkSigner
894
- });