@buildonspark/spark-sdk 0.1.46 → 0.1.47

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 (146) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/{chunk-I54FARY2.js → chunk-EAP3U3CW.js} +14 -14
  3. package/dist/chunk-GWFQ7EBA.js +3773 -0
  4. package/dist/{chunk-JB64OQES.js → chunk-NNX4OK44.js} +3488 -935
  5. package/dist/{RequestLightningSendInput-CN6BNg_g.d.ts → client-CvpTRpcw.d.cts} +422 -212
  6. package/dist/{RequestLightningSendInput-2cSh_In4.d.cts → client-D7KgLN44.d.ts} +422 -212
  7. package/dist/graphql/objects/index.d.cts +5 -9
  8. package/dist/graphql/objects/index.d.ts +5 -9
  9. package/dist/graphql/objects/index.js +1 -1
  10. package/dist/index.cjs +20460 -23376
  11. package/dist/index.d.cts +15 -769
  12. package/dist/index.d.ts +15 -769
  13. package/dist/index.js +83 -73
  14. package/dist/index.node.cjs +21994 -25018
  15. package/dist/index.node.d.cts +312 -34
  16. package/dist/index.node.d.ts +312 -34
  17. package/dist/index.node.js +84 -178
  18. package/dist/native/index.cjs +17112 -20106
  19. package/dist/native/index.d.cts +974 -1138
  20. package/dist/native/index.d.ts +974 -1138
  21. package/dist/native/index.js +10604 -13592
  22. package/dist/proto/lrc20.d.cts +2 -2
  23. package/dist/proto/lrc20.d.ts +2 -2
  24. package/dist/proto/lrc20.js +3098 -46
  25. package/dist/proto/spark.d.cts +1 -1
  26. package/dist/proto/spark.d.ts +1 -1
  27. package/dist/proto/spark_token.d.cts +1 -1
  28. package/dist/proto/spark_token.d.ts +1 -1
  29. package/dist/{sdk-types-CKBsylfW.d.ts → sdk-types-BGCeea0G.d.ts} +1 -1
  30. package/dist/{sdk-types-Ct8xmN7l.d.cts → sdk-types-XUeQMLFP.d.cts} +1 -1
  31. package/dist/{spark-DbzGfse6.d.cts → spark-BbUrbvZz.d.cts} +1 -1
  32. package/dist/{spark-DbzGfse6.d.ts → spark-BbUrbvZz.d.ts} +1 -1
  33. package/dist/spark-wallet-BAFPpPtY.d.cts +923 -0
  34. package/dist/spark-wallet-CJkQW8pK.d.ts +923 -0
  35. package/dist/spark_bindings/native/index.d.cts +1 -1
  36. package/dist/spark_bindings/native/index.d.ts +1 -1
  37. package/dist/spark_bindings/wasm/index.d.cts +1 -1
  38. package/dist/spark_bindings/wasm/index.d.ts +1 -1
  39. package/dist/{services/index.cjs → tests/test-utils.cjs} +2511 -4379
  40. package/dist/tests/test-utils.d.cts +79 -0
  41. package/dist/tests/test-utils.d.ts +79 -0
  42. package/dist/tests/test-utils.js +85 -0
  43. package/dist/types/index.d.cts +5 -9
  44. package/dist/types/index.d.ts +5 -9
  45. package/dist/types/index.js +5 -5
  46. package/dist/{types-C-Rp0Oo7.d.cts → types-BADxR3bm.d.cts} +1 -1
  47. package/dist/{types-C-Rp0Oo7.d.ts → types-BADxR3bm.d.ts} +1 -1
  48. package/package.json +6 -34
  49. package/src/graphql/client.ts +59 -20
  50. package/src/index.node.ts +28 -2
  51. package/src/index.ts +31 -1
  52. package/src/native/index.ts +16 -2
  53. package/src/services/config.ts +4 -6
  54. package/src/services/connection.ts +131 -64
  55. package/src/services/lightning.ts +1 -2
  56. package/src/services/token-transactions.ts +7 -7
  57. package/src/services/transfer.ts +1 -1
  58. package/src/services/tree-creation.ts +1 -1
  59. package/src/services/wallet-config.ts +17 -9
  60. package/src/signer/signer.react-native.ts +2 -5
  61. package/src/signer/signer.ts +138 -64
  62. package/src/signer/types.ts +52 -0
  63. package/src/spark-wallet/spark-wallet.ts +79 -36
  64. package/src/spark-wallet/types.ts +4 -4
  65. package/src/tests/integration/coop-exit.test.ts +2 -1
  66. package/src/tests/integration/lightning.test.ts +2 -2
  67. package/src/tests/integration/swap.test.ts +1 -1
  68. package/src/tests/integration/transfer.test.ts +5 -5
  69. package/src/tests/integration/tree-creation.test.ts +1 -1
  70. package/src/tests/integration/wallet.test.ts +1 -0
  71. package/src/tests/isHermeticTest.ts +3 -24
  72. package/src/tests/{test-util.ts → test-utils.ts} +3 -7
  73. package/src/tests/wrapWithOtelSpan.test.ts +1 -1
  74. package/src/{address → utils}/address.ts +1 -1
  75. package/src/utils/crypto.ts +19 -9
  76. package/src/utils/index.ts +2 -0
  77. package/src/utils/network.ts +17 -0
  78. package/src/utils/secret-sharing.ts +1 -2
  79. package/src/utils/signing.ts +1 -1
  80. package/src/utils/token-transactions.ts +3 -3
  81. package/src/utils/unilateral-exit.ts +32 -0
  82. package/src/utils/xchain-address.ts +1 -1
  83. package/dist/BitcoinNetwork-TnABML0T.d.cts +0 -18
  84. package/dist/BitcoinNetwork-TnABML0T.d.ts +0 -18
  85. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +0 -10
  86. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +0 -10
  87. package/dist/address/index.cjs +0 -458
  88. package/dist/address/index.d.cts +0 -32
  89. package/dist/address/index.d.ts +0 -32
  90. package/dist/address/index.js +0 -17
  91. package/dist/chunk-4EMV7HHW.js +0 -277
  92. package/dist/chunk-C2S227QR.js +0 -2336
  93. package/dist/chunk-DXR2PXJU.js +0 -1122
  94. package/dist/chunk-GSI4OLXZ.js +0 -117
  95. package/dist/chunk-HHNQ3ZHC.js +0 -170
  96. package/dist/chunk-HSCLBJEL.js +0 -113
  97. package/dist/chunk-HWJWKEIU.js +0 -75
  98. package/dist/chunk-KMUMFYFX.js +0 -137
  99. package/dist/chunk-L3EHBOUX.js +0 -0
  100. package/dist/chunk-N5VZVCGJ.js +0 -622
  101. package/dist/chunk-NSJF5F5O.js +0 -325
  102. package/dist/chunk-NTFKFRQ2.js +0 -3146
  103. package/dist/chunk-OFCJFZ4I.js +0 -24
  104. package/dist/chunk-QNNSEJ4P.js +0 -232
  105. package/dist/chunk-UXDODSDT.js +0 -838
  106. package/dist/chunk-VTUGIIWI.js +0 -0
  107. package/dist/chunk-Z5HIAYFT.js +0 -84
  108. package/dist/index-CKL5DodV.d.cts +0 -214
  109. package/dist/index-COm59SPw.d.ts +0 -214
  110. package/dist/network-Css46DAz.d.cts +0 -46
  111. package/dist/network-hynb7iTZ.d.ts +0 -46
  112. package/dist/services/config.cjs +0 -2354
  113. package/dist/services/config.d.cts +0 -42
  114. package/dist/services/config.d.ts +0 -42
  115. package/dist/services/config.js +0 -17
  116. package/dist/services/connection.cjs +0 -17691
  117. package/dist/services/connection.d.cts +0 -95
  118. package/dist/services/connection.d.ts +0 -95
  119. package/dist/services/connection.js +0 -11
  120. package/dist/services/index.d.cts +0 -21
  121. package/dist/services/index.d.ts +0 -21
  122. package/dist/services/index.js +0 -58
  123. package/dist/services/lrc-connection.cjs +0 -4713
  124. package/dist/services/lrc-connection.d.cts +0 -34
  125. package/dist/services/lrc-connection.d.ts +0 -34
  126. package/dist/services/lrc-connection.js +0 -11
  127. package/dist/services/token-transactions.cjs +0 -2877
  128. package/dist/services/token-transactions.d.cts +0 -75
  129. package/dist/services/token-transactions.d.ts +0 -75
  130. package/dist/services/token-transactions.js +0 -15
  131. package/dist/services/wallet-config.cjs +0 -340
  132. package/dist/services/wallet-config.d.cts +0 -56
  133. package/dist/services/wallet-config.d.ts +0 -56
  134. package/dist/services/wallet-config.js +0 -33
  135. package/dist/signer/signer.cjs +0 -2004
  136. package/dist/signer/signer.d.cts +0 -10
  137. package/dist/signer/signer.d.ts +0 -10
  138. package/dist/signer/signer.js +0 -24
  139. package/dist/signer-BP6F__oR.d.cts +0 -187
  140. package/dist/signer-BVZJXcq7.d.ts +0 -187
  141. package/dist/utils/index.cjs +0 -2947
  142. package/dist/utils/index.d.cts +0 -18
  143. package/dist/utils/index.d.ts +0 -18
  144. package/dist/utils/index.js +0 -157
  145. package/src/address/index.ts +0 -1
  146. package/src/services/lrc-connection.ts +0 -215
@@ -1,24 +0,0 @@
1
- // src/constants.ts
2
- import { isNode } from "@lightsparkdev/core";
3
- var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
4
- var isBun = globalThis.Bun !== void 0;
5
- var packageVersion = true ? "0.1.46" : "unknown";
6
- var baseEnvStr = "unknown";
7
- if (isBun) {
8
- const bunVersion = "version" in globalThis.Bun ? globalThis.Bun.version : "unknown-version";
9
- baseEnvStr = `bun/${bunVersion}`;
10
- } else if (isNode) {
11
- baseEnvStr = `node/${process.version}`;
12
- } else if (isReactNative) {
13
- baseEnvStr = "react-native";
14
- } else {
15
- const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "unknown-user-agent";
16
- baseEnvStr = `browser/${userAgent}`;
17
- }
18
- var clientEnv = `js-spark-sdk/${packageVersion} ${baseEnvStr}`;
19
-
20
- export {
21
- isReactNative,
22
- isBun,
23
- clientEnv
24
- };
@@ -1,232 +0,0 @@
1
- import {
2
- ValidationError
3
- } from "./chunk-GSI4OLXZ.js";
4
-
5
- // src/utils/secret-sharing.ts
6
- import { bytesToHex, equalBytes } from "@noble/curves/abstract/utils";
7
- import { secp256k1 } from "@noble/curves/secp256k1";
8
-
9
- // src/utils/crypto.ts
10
- import nodeCrypto from "crypto";
11
- var getCrypto = () => {
12
- let cryptoImpl = typeof window !== "undefined" ? window.crypto : typeof global !== "undefined" && global.crypto ? global.crypto : nodeCrypto;
13
- return cryptoImpl;
14
- };
15
-
16
- // src/utils/secret-sharing.ts
17
- var crypto = getCrypto();
18
- function getRandomBigInt(max) {
19
- const byteLength = max.toString(2).length + 7 >> 3;
20
- const maxBigInt = max;
21
- const mask = (1n << BigInt(max.toString(2).length)) - 1n;
22
- while (true) {
23
- const randBytes = crypto.getRandomValues(new Uint8Array(byteLength + 1));
24
- const randValue = BigInt("0x" + bytesToHex(randBytes)) & mask;
25
- if (randValue < maxBigInt) {
26
- return randValue;
27
- }
28
- }
29
- }
30
- function modInverse(a, m) {
31
- a = (a % m + m) % m;
32
- let [old_r, r] = [a, m];
33
- let [old_s, s] = [1n, 0n];
34
- let [old_t, t] = [0n, 1n];
35
- while (r !== 0n) {
36
- const quotient = old_r / r;
37
- [old_r, r] = [r, old_r - quotient * r];
38
- [old_s, s] = [s, old_s - quotient * s];
39
- [old_t, t] = [t, old_t - quotient * t];
40
- }
41
- if (old_r !== 1n) {
42
- throw new ValidationError("Modular inverse does not exist", {
43
- field: "modInverse",
44
- value: `a: ${a}, m: ${m}`,
45
- expected: "a and m must be coprime"
46
- });
47
- }
48
- return (old_s % m + m) % m;
49
- }
50
- function evaluatePolynomial(polynomial, x) {
51
- let result = 0n;
52
- for (let i = 0; i < polynomial.coefficients.length; i++) {
53
- const coeff = polynomial.coefficients[i];
54
- if (!coeff) {
55
- throw new ValidationError("Coefficient is undefined", {
56
- field: "coefficient",
57
- value: "undefined",
58
- expected: "A valid bigint coefficient"
59
- });
60
- }
61
- const xPow = x ** BigInt(i) % polynomial.fieldModulus;
62
- result = (result + xPow * coeff) % polynomial.fieldModulus;
63
- }
64
- return result;
65
- }
66
- function fieldDiv(numerator, denominator, fieldModulus) {
67
- if (denominator === 0n) {
68
- throw new ValidationError("Division by zero", {
69
- field: "denominator",
70
- value: "0",
71
- expected: "Non-zero value"
72
- });
73
- }
74
- const inverse = modInverse(denominator, fieldModulus);
75
- return numerator * inverse % fieldModulus;
76
- }
77
- function computerLagrangeCoefficients(index, points) {
78
- let numerator = 1n;
79
- let denominator = 1n;
80
- let fieldModulus = points[0]?.fieldModulus;
81
- if (!fieldModulus) {
82
- throw new ValidationError("Field modulus is undefined", {
83
- field: "fieldModulus",
84
- value: "undefined",
85
- expected: "A valid field modulus"
86
- });
87
- }
88
- for (const point of points) {
89
- if (point.index === index) {
90
- continue;
91
- }
92
- numerator = numerator * point.index;
93
- const value = point.index - index;
94
- denominator = denominator * value;
95
- }
96
- return fieldDiv(numerator, denominator, fieldModulus);
97
- }
98
- function generatePolynomialForSecretSharing(fieldModulus, secret, degree) {
99
- const coefficients = new Array(degree);
100
- const proofs = new Array(degree);
101
- coefficients[0] = secret;
102
- proofs[0] = secp256k1.ProjectivePoint.fromPrivateKey(secret).toRawBytes(true);
103
- for (let i = 1; i < degree; i++) {
104
- const coefficient = getRandomBigInt(fieldModulus);
105
- coefficients[i] = coefficient;
106
- proofs[i] = secp256k1.ProjectivePoint.fromPrivateKey(coefficient).toRawBytes(true);
107
- }
108
- return {
109
- fieldModulus,
110
- coefficients,
111
- proofs
112
- };
113
- }
114
- function splitSecret(fieldModulus, secret, threshold, numberOfShares) {
115
- const polynomial = generatePolynomialForSecretSharing(
116
- fieldModulus,
117
- secret,
118
- threshold
119
- );
120
- const shares = [];
121
- for (let i = 1; i <= numberOfShares; i++) {
122
- const share = evaluatePolynomial(polynomial, BigInt(i));
123
- shares.push({
124
- fieldModulus,
125
- threshold,
126
- index: BigInt(i),
127
- share
128
- });
129
- }
130
- return shares;
131
- }
132
- function splitSecretWithProofs(secret, fieldModulus, threshold, numberOfShares) {
133
- const polynomial = generatePolynomialForSecretSharing(
134
- fieldModulus,
135
- secret,
136
- threshold
137
- );
138
- const shares = [];
139
- for (let i = 1; i <= numberOfShares; i++) {
140
- const share = evaluatePolynomial(polynomial, BigInt(i));
141
- shares.push({
142
- fieldModulus,
143
- threshold,
144
- index: BigInt(i),
145
- share,
146
- proofs: polynomial.proofs
147
- });
148
- }
149
- return shares;
150
- }
151
- function recoverSecret(shares) {
152
- if (shares.length === 0) return 0n;
153
- const threshold = shares[0]?.threshold;
154
- const fieldModulus = shares[0]?.fieldModulus;
155
- if (!threshold || !fieldModulus) {
156
- throw new ValidationError("Shares are not valid", {
157
- field: "shares",
158
- value: "Missing threshold or fieldModulus",
159
- expected: "Valid shares with threshold and fieldModulus"
160
- });
161
- }
162
- if (shares.length < threshold) {
163
- throw new ValidationError("Not enough shares to recover secret", {
164
- field: "shares",
165
- value: shares.length,
166
- expected: `At least ${threshold} shares`
167
- });
168
- }
169
- let result = 0n;
170
- for (const share of shares) {
171
- const coeff = computerLagrangeCoefficients(share.index, shares);
172
- const item = share.share * coeff % fieldModulus;
173
- result = (result + item) % fieldModulus;
174
- }
175
- return result;
176
- }
177
- function validateShare(share) {
178
- const targetPubkey = secp256k1.ProjectivePoint.fromPrivateKey(
179
- share.share
180
- ).toRawBytes(true);
181
- let resultPubkey = share.proofs[0];
182
- if (!resultPubkey) {
183
- throw new ValidationError("Result pubkey is not valid", {
184
- field: "resultPubkey",
185
- value: "null",
186
- expected: "Valid public key bytes"
187
- });
188
- }
189
- for (let i = 1; i < share.proofs.length; i++) {
190
- const pubkey = share.proofs[i];
191
- if (!pubkey) {
192
- throw new ValidationError("Pubkey is not valid", {
193
- field: "pubkey",
194
- value: "null",
195
- expected: "Valid public key bytes"
196
- });
197
- }
198
- const value = share.index ** BigInt(i) % share.fieldModulus;
199
- const scaledPoint = secp256k1.ProjectivePoint.fromHex(pubkey).multiply(value);
200
- resultPubkey = secp256k1.ProjectivePoint.fromHex(resultPubkey).add(scaledPoint).toRawBytes(true);
201
- }
202
- if (!equalBytes(resultPubkey, targetPubkey)) {
203
- throw new ValidationError("Share is not valid", {
204
- field: "share",
205
- value: "Invalid proof",
206
- expected: "Valid share with matching proofs"
207
- });
208
- }
209
- }
210
- function bigIntToPrivateKey(value) {
211
- const hex = value.toString(16).padStart(64, "0");
212
- const bytes = new Uint8Array(32);
213
- for (let i = 0; i < 32; i++) {
214
- bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
215
- }
216
- return bytes;
217
- }
218
-
219
- export {
220
- getCrypto,
221
- getRandomBigInt,
222
- modInverse,
223
- evaluatePolynomial,
224
- fieldDiv,
225
- computerLagrangeCoefficients,
226
- generatePolynomialForSecretSharing,
227
- splitSecret,
228
- splitSecretWithProofs,
229
- recoverSecret,
230
- validateShare,
231
- bigIntToPrivateKey
232
- };