@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.
- package/CHANGELOG.md +14 -0
- package/dist/{chunk-I54FARY2.js → chunk-EAP3U3CW.js} +14 -14
- package/dist/chunk-GWFQ7EBA.js +3773 -0
- package/dist/{chunk-JB64OQES.js → chunk-NNX4OK44.js} +3488 -935
- package/dist/{RequestLightningSendInput-CN6BNg_g.d.ts → client-CvpTRpcw.d.cts} +422 -212
- package/dist/{RequestLightningSendInput-2cSh_In4.d.cts → client-D7KgLN44.d.ts} +422 -212
- package/dist/graphql/objects/index.d.cts +5 -9
- package/dist/graphql/objects/index.d.ts +5 -9
- package/dist/graphql/objects/index.js +1 -1
- package/dist/index.cjs +20460 -23376
- package/dist/index.d.cts +15 -769
- package/dist/index.d.ts +15 -769
- package/dist/index.js +83 -73
- package/dist/index.node.cjs +21994 -25018
- package/dist/index.node.d.cts +312 -34
- package/dist/index.node.d.ts +312 -34
- package/dist/index.node.js +84 -178
- package/dist/native/index.cjs +17112 -20106
- package/dist/native/index.d.cts +974 -1138
- package/dist/native/index.d.ts +974 -1138
- package/dist/native/index.js +10604 -13592
- package/dist/proto/lrc20.d.cts +2 -2
- package/dist/proto/lrc20.d.ts +2 -2
- package/dist/proto/lrc20.js +3098 -46
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark_token.d.cts +1 -1
- package/dist/proto/spark_token.d.ts +1 -1
- package/dist/{sdk-types-CKBsylfW.d.ts → sdk-types-BGCeea0G.d.ts} +1 -1
- package/dist/{sdk-types-Ct8xmN7l.d.cts → sdk-types-XUeQMLFP.d.cts} +1 -1
- package/dist/{spark-DbzGfse6.d.cts → spark-BbUrbvZz.d.cts} +1 -1
- package/dist/{spark-DbzGfse6.d.ts → spark-BbUrbvZz.d.ts} +1 -1
- package/dist/spark-wallet-BAFPpPtY.d.cts +923 -0
- package/dist/spark-wallet-CJkQW8pK.d.ts +923 -0
- package/dist/spark_bindings/native/index.d.cts +1 -1
- package/dist/spark_bindings/native/index.d.ts +1 -1
- package/dist/spark_bindings/wasm/index.d.cts +1 -1
- package/dist/spark_bindings/wasm/index.d.ts +1 -1
- package/dist/{services/index.cjs → tests/test-utils.cjs} +2511 -4379
- package/dist/tests/test-utils.d.cts +79 -0
- package/dist/tests/test-utils.d.ts +79 -0
- package/dist/tests/test-utils.js +85 -0
- package/dist/types/index.d.cts +5 -9
- package/dist/types/index.d.ts +5 -9
- package/dist/types/index.js +5 -5
- package/dist/{types-C-Rp0Oo7.d.cts → types-BADxR3bm.d.cts} +1 -1
- package/dist/{types-C-Rp0Oo7.d.ts → types-BADxR3bm.d.ts} +1 -1
- package/package.json +6 -34
- package/src/graphql/client.ts +59 -20
- package/src/index.node.ts +28 -2
- package/src/index.ts +31 -1
- package/src/native/index.ts +16 -2
- package/src/services/config.ts +4 -6
- package/src/services/connection.ts +131 -64
- package/src/services/lightning.ts +1 -2
- package/src/services/token-transactions.ts +7 -7
- package/src/services/transfer.ts +1 -1
- package/src/services/tree-creation.ts +1 -1
- package/src/services/wallet-config.ts +17 -9
- package/src/signer/signer.react-native.ts +2 -5
- package/src/signer/signer.ts +138 -64
- package/src/signer/types.ts +52 -0
- package/src/spark-wallet/spark-wallet.ts +79 -36
- package/src/spark-wallet/types.ts +4 -4
- package/src/tests/integration/coop-exit.test.ts +2 -1
- package/src/tests/integration/lightning.test.ts +2 -2
- package/src/tests/integration/swap.test.ts +1 -1
- package/src/tests/integration/transfer.test.ts +5 -5
- package/src/tests/integration/tree-creation.test.ts +1 -1
- package/src/tests/integration/wallet.test.ts +1 -0
- package/src/tests/isHermeticTest.ts +3 -24
- package/src/tests/{test-util.ts → test-utils.ts} +3 -7
- package/src/tests/wrapWithOtelSpan.test.ts +1 -1
- package/src/{address → utils}/address.ts +1 -1
- package/src/utils/crypto.ts +19 -9
- package/src/utils/index.ts +2 -0
- package/src/utils/network.ts +17 -0
- package/src/utils/secret-sharing.ts +1 -2
- package/src/utils/signing.ts +1 -1
- package/src/utils/token-transactions.ts +3 -3
- package/src/utils/unilateral-exit.ts +32 -0
- package/src/utils/xchain-address.ts +1 -1
- package/dist/BitcoinNetwork-TnABML0T.d.cts +0 -18
- package/dist/BitcoinNetwork-TnABML0T.d.ts +0 -18
- package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +0 -10
- package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +0 -10
- package/dist/address/index.cjs +0 -458
- package/dist/address/index.d.cts +0 -32
- package/dist/address/index.d.ts +0 -32
- package/dist/address/index.js +0 -17
- package/dist/chunk-4EMV7HHW.js +0 -277
- package/dist/chunk-C2S227QR.js +0 -2336
- package/dist/chunk-DXR2PXJU.js +0 -1122
- package/dist/chunk-GSI4OLXZ.js +0 -117
- package/dist/chunk-HHNQ3ZHC.js +0 -170
- package/dist/chunk-HSCLBJEL.js +0 -113
- package/dist/chunk-HWJWKEIU.js +0 -75
- package/dist/chunk-KMUMFYFX.js +0 -137
- package/dist/chunk-L3EHBOUX.js +0 -0
- package/dist/chunk-N5VZVCGJ.js +0 -622
- package/dist/chunk-NSJF5F5O.js +0 -325
- package/dist/chunk-NTFKFRQ2.js +0 -3146
- package/dist/chunk-OFCJFZ4I.js +0 -24
- package/dist/chunk-QNNSEJ4P.js +0 -232
- package/dist/chunk-UXDODSDT.js +0 -838
- package/dist/chunk-VTUGIIWI.js +0 -0
- package/dist/chunk-Z5HIAYFT.js +0 -84
- package/dist/index-CKL5DodV.d.cts +0 -214
- package/dist/index-COm59SPw.d.ts +0 -214
- package/dist/network-Css46DAz.d.cts +0 -46
- package/dist/network-hynb7iTZ.d.ts +0 -46
- package/dist/services/config.cjs +0 -2354
- package/dist/services/config.d.cts +0 -42
- package/dist/services/config.d.ts +0 -42
- package/dist/services/config.js +0 -17
- package/dist/services/connection.cjs +0 -17691
- package/dist/services/connection.d.cts +0 -95
- package/dist/services/connection.d.ts +0 -95
- package/dist/services/connection.js +0 -11
- package/dist/services/index.d.cts +0 -21
- package/dist/services/index.d.ts +0 -21
- package/dist/services/index.js +0 -58
- package/dist/services/lrc-connection.cjs +0 -4713
- package/dist/services/lrc-connection.d.cts +0 -34
- package/dist/services/lrc-connection.d.ts +0 -34
- package/dist/services/lrc-connection.js +0 -11
- package/dist/services/token-transactions.cjs +0 -2877
- package/dist/services/token-transactions.d.cts +0 -75
- package/dist/services/token-transactions.d.ts +0 -75
- package/dist/services/token-transactions.js +0 -15
- package/dist/services/wallet-config.cjs +0 -340
- package/dist/services/wallet-config.d.cts +0 -56
- package/dist/services/wallet-config.d.ts +0 -56
- package/dist/services/wallet-config.js +0 -33
- package/dist/signer/signer.cjs +0 -2004
- package/dist/signer/signer.d.cts +0 -10
- package/dist/signer/signer.d.ts +0 -10
- package/dist/signer/signer.js +0 -24
- package/dist/signer-BP6F__oR.d.cts +0 -187
- package/dist/signer-BVZJXcq7.d.ts +0 -187
- package/dist/utils/index.cjs +0 -2947
- package/dist/utils/index.d.cts +0 -18
- package/dist/utils/index.d.ts +0 -18
- package/dist/utils/index.js +0 -157
- package/src/address/index.ts +0 -1
- package/src/services/lrc-connection.ts +0 -215
package/dist/chunk-OFCJFZ4I.js
DELETED
|
@@ -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
|
-
};
|
package/dist/chunk-QNNSEJ4P.js
DELETED
|
@@ -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
|
-
};
|