@buildonspark/spark-sdk 0.1.45 → 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 +22 -0
- package/dist/{chunk-I54FARY2.js → chunk-EAP3U3CW.js} +14 -14
- package/dist/chunk-GWFQ7EBA.js +3773 -0
- package/dist/{chunk-J2IE4Z7Y.js → chunk-NNX4OK44.js} +3487 -934
- package/dist/{RequestLightningSendInput-Du0z7Om7.d.cts → client-CvpTRpcw.d.cts} +422 -212
- package/dist/{RequestLightningSendInput-DEPd_fPO.d.ts → 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 +20461 -23377
- package/dist/index.d.cts +15 -769
- package/dist/index.d.ts +15 -769
- package/dist/index.js +81 -71
- 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 +82 -176
- package/dist/native/index.cjs +22847 -25841
- 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-Cc4l4kb1.d.ts → sdk-types-BGCeea0G.d.ts} +1 -1
- package/dist/{sdk-types-B0SwjolI.d.cts → sdk-types-XUeQMLFP.d.cts} +1 -1
- package/dist/{spark-dM7EYXYQ.d.cts → spark-BbUrbvZz.d.cts} +1 -1
- package/dist/{spark-dM7EYXYQ.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} +2512 -4380
- 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 +7 -35
- 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 +18 -10
- 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-5FUB65LX.js +0 -838
- package/dist/chunk-6264CGDM.js +0 -113
- package/dist/chunk-7V6N75CC.js +0 -24
- package/dist/chunk-C2S227QR.js +0 -2336
- package/dist/chunk-GSI4OLXZ.js +0 -117
- package/dist/chunk-GZ5IPPJ2.js +0 -170
- package/dist/chunk-HWJWKEIU.js +0 -75
- package/dist/chunk-KMUMFYFX.js +0 -137
- package/dist/chunk-L3EHBOUX.js +0 -0
- package/dist/chunk-NSJF5F5O.js +0 -325
- package/dist/chunk-NTFKFRQ2.js +0 -3146
- package/dist/chunk-PQN3C2MF.js +0 -1122
- package/dist/chunk-QNNSEJ4P.js +0 -232
- package/dist/chunk-R5PXJZQS.js +0 -277
- package/dist/chunk-VTUGIIWI.js +0 -0
- package/dist/chunk-YUPMXTCJ.js +0 -622
- package/dist/chunk-Z5HIAYFT.js +0 -84
- package/dist/index-B2AwKW5J.d.cts +0 -214
- package/dist/index-CJDi1HWc.d.ts +0 -214
- package/dist/network-BTJl-Sul.d.ts +0 -46
- package/dist/network-CqgsdUF2.d.cts +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-BocS_J6B.d.ts +0 -187
- package/dist/signer-DKS0AJkw.d.cts +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-NSJF5F5O.js
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ValidationError
|
|
3
|
-
} from "./chunk-GSI4OLXZ.js";
|
|
4
|
-
|
|
5
|
-
// src/utils/adaptor-signature.ts
|
|
6
|
-
import { mod } from "@noble/curves/abstract/modular";
|
|
7
|
-
import { bytesToNumberBE, numberToBytesBE } from "@noble/curves/abstract/utils";
|
|
8
|
-
import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
|
|
9
|
-
function generateSignatureFromExistingAdaptor(signature, adaptorPrivateKeyBytes) {
|
|
10
|
-
const { r, s } = parseSignature(signature);
|
|
11
|
-
const sBigInt = bytesToNumberBE(s);
|
|
12
|
-
const tBigInt = bytesToNumberBE(adaptorPrivateKeyBytes);
|
|
13
|
-
const newS = mod(sBigInt - tBigInt, secp256k1.CURVE.n);
|
|
14
|
-
const newSignature = new Uint8Array([...r, ...numberToBytesBE(newS, 32)]);
|
|
15
|
-
return newSignature;
|
|
16
|
-
}
|
|
17
|
-
function generateAdaptorFromSignature(signature) {
|
|
18
|
-
const adaptorPrivateKey = secp256k1.utils.randomPrivateKey();
|
|
19
|
-
const { r, s } = parseSignature(signature);
|
|
20
|
-
const sBigInt = bytesToNumberBE(s);
|
|
21
|
-
const tBigInt = bytesToNumberBE(adaptorPrivateKey);
|
|
22
|
-
const newS = mod(sBigInt - tBigInt, secp256k1.CURVE.n);
|
|
23
|
-
const newSignature = new Uint8Array([...r, ...numberToBytesBE(newS, 32)]);
|
|
24
|
-
return {
|
|
25
|
-
adaptorSignature: newSignature,
|
|
26
|
-
adaptorPrivateKey
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function validateOutboundAdaptorSignature(pubkey, hash, signature, adaptorPubkey) {
|
|
30
|
-
return schnorrVerifyWithAdaptor(
|
|
31
|
-
signature,
|
|
32
|
-
hash,
|
|
33
|
-
pubkey,
|
|
34
|
-
adaptorPubkey,
|
|
35
|
-
false
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
function applyAdaptorToSignature(pubkey, hash, signature, adaptorPrivateKeyBytes) {
|
|
39
|
-
const { r, s } = parseSignature(signature);
|
|
40
|
-
const sBigInt = bytesToNumberBE(s);
|
|
41
|
-
const adaptorPrivateKey = bytesToNumberBE(adaptorPrivateKeyBytes);
|
|
42
|
-
const newS = mod(sBigInt + adaptorPrivateKey, secp256k1.CURVE.n);
|
|
43
|
-
const newSig = new Uint8Array([...r, ...numberToBytesBE(newS, 32)]);
|
|
44
|
-
if (schnorr.verify(newSig, hash, pubkey)) {
|
|
45
|
-
return newSig;
|
|
46
|
-
}
|
|
47
|
-
const altS = mod(sBigInt - adaptorPrivateKey, secp256k1.CURVE.n);
|
|
48
|
-
const altSig = new Uint8Array([...r, ...numberToBytesBE(altS, 32)]);
|
|
49
|
-
if (schnorr.verify(altSig, hash, pubkey)) {
|
|
50
|
-
return altSig;
|
|
51
|
-
}
|
|
52
|
-
throw new Error("Cannot apply adaptor to signature");
|
|
53
|
-
}
|
|
54
|
-
function schnorrVerifyWithAdaptor(signature, hash, pubKeyBytes, adaptorPubkey, inbound) {
|
|
55
|
-
if (hash.length !== 32) {
|
|
56
|
-
throw new Error(`wrong size for message (got ${hash.length}, want 32)`);
|
|
57
|
-
}
|
|
58
|
-
const pubKey = schnorr.utils.lift_x(bytesToNumberBE(pubKeyBytes));
|
|
59
|
-
pubKey.assertValidity();
|
|
60
|
-
const { r, s } = parseSignature(signature);
|
|
61
|
-
const commitmenet = schnorr.utils.taggedHash(
|
|
62
|
-
"BIP0340/challenge",
|
|
63
|
-
r,
|
|
64
|
-
pubKey.toRawBytes().slice(1),
|
|
65
|
-
hash
|
|
66
|
-
);
|
|
67
|
-
if (commitmenet.length > 32) {
|
|
68
|
-
throw new Error("hash of (r || P || m) too big");
|
|
69
|
-
}
|
|
70
|
-
const e = mod(bytesToNumberBE(commitmenet), secp256k1.CURVE.n);
|
|
71
|
-
const negE = mod(-e, secp256k1.CURVE.n);
|
|
72
|
-
const R = secp256k1.ProjectivePoint.BASE.multiplyAndAddUnsafe(
|
|
73
|
-
pubKey,
|
|
74
|
-
bytesToNumberBE(s),
|
|
75
|
-
negE
|
|
76
|
-
);
|
|
77
|
-
if (!R) {
|
|
78
|
-
throw new Error("R is undefined");
|
|
79
|
-
}
|
|
80
|
-
R.assertValidity();
|
|
81
|
-
const adaptorPoint = secp256k1.ProjectivePoint.fromHex(adaptorPubkey);
|
|
82
|
-
const newR = R.add(adaptorPoint);
|
|
83
|
-
if (!inbound && newR.equals(secp256k1.ProjectivePoint.ZERO)) {
|
|
84
|
-
throw new Error("calculated R point is the point at infinity");
|
|
85
|
-
}
|
|
86
|
-
newR.assertValidity();
|
|
87
|
-
if (!newR.hasEvenY()) {
|
|
88
|
-
throw new Error("calculated R y-value is odd");
|
|
89
|
-
}
|
|
90
|
-
const rNum = bytesToNumberBE(r);
|
|
91
|
-
if (newR.toAffine().x !== rNum) {
|
|
92
|
-
throw new Error("calculated R point was not given R");
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
function parseSignature(signature) {
|
|
97
|
-
if (signature.length < 64) {
|
|
98
|
-
throw new ValidationError("Signature too short", {
|
|
99
|
-
expectedLength: 64,
|
|
100
|
-
actualLength: signature.length
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
if (signature.length > 64) {
|
|
104
|
-
throw new ValidationError("Signature too long", {
|
|
105
|
-
expectedLength: 64,
|
|
106
|
-
actualLength: signature.length
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const r = signature.slice(0, 32);
|
|
110
|
-
const s = signature.slice(32, 64);
|
|
111
|
-
if (bytesToNumberBE(r) >= secp256k1.CURVE.Fp.ORDER) {
|
|
112
|
-
throw new ValidationError("Invalid signature: r >= field prime", {
|
|
113
|
-
rValue: bytesToNumberBE(r),
|
|
114
|
-
fieldPrime: secp256k1.CURVE.Fp.ORDER
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (bytesToNumberBE(s) >= secp256k1.CURVE.n) {
|
|
118
|
-
throw new ValidationError("Invalid signature: s >= group order", {
|
|
119
|
-
sValue: bytesToNumberBE(s),
|
|
120
|
-
groupOrder: secp256k1.CURVE.n
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return { r, s };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/utils/keys.ts
|
|
127
|
-
import { numberToBytesBE as numberToBytesBE2 } from "@noble/curves/abstract/utils";
|
|
128
|
-
import { secp256k1 as secp256k12 } from "@noble/curves/secp256k1";
|
|
129
|
-
function addPublicKeys(a, b) {
|
|
130
|
-
if (a.length !== 33 || b.length !== 33) {
|
|
131
|
-
throw new ValidationError("Public keys must be 33 bytes", {
|
|
132
|
-
field: "publicKeys",
|
|
133
|
-
value: `a: ${a.length}, b: ${b.length}`,
|
|
134
|
-
expected: 33
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
const pubkeyA = secp256k12.ProjectivePoint.fromHex(a);
|
|
138
|
-
const pubkeyB = secp256k12.ProjectivePoint.fromHex(b);
|
|
139
|
-
return pubkeyA.add(pubkeyB).toRawBytes(true);
|
|
140
|
-
}
|
|
141
|
-
function applyAdditiveTweakToPublicKey(pubkey, tweak) {
|
|
142
|
-
if (pubkey.length !== 33) {
|
|
143
|
-
throw new ValidationError("Public key must be 33 bytes", {
|
|
144
|
-
field: "pubkey",
|
|
145
|
-
value: pubkey.length,
|
|
146
|
-
expected: 33
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (tweak.length !== 32) {
|
|
150
|
-
throw new ValidationError("Tweak must be 32 bytes", {
|
|
151
|
-
field: "tweak",
|
|
152
|
-
value: tweak.length,
|
|
153
|
-
expected: 32
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
const pubkeyPoint = secp256k12.ProjectivePoint.fromHex(pubkey);
|
|
157
|
-
const privTweek = secp256k12.utils.normPrivateKeyToScalar(tweak);
|
|
158
|
-
const pubTweek = secp256k12.getPublicKey(privTweek, true);
|
|
159
|
-
const tweekPoint = secp256k12.ProjectivePoint.fromHex(pubTweek);
|
|
160
|
-
return pubkeyPoint.add(tweekPoint).toRawBytes(true);
|
|
161
|
-
}
|
|
162
|
-
function subtractPublicKeys(a, b) {
|
|
163
|
-
if (a.length !== 33 || b.length !== 33) {
|
|
164
|
-
throw new ValidationError("Public keys must be 33 bytes", {
|
|
165
|
-
field: "publicKeys",
|
|
166
|
-
value: `a: ${a.length}, b: ${b.length}`,
|
|
167
|
-
expected: 33
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
const pubkeyA = secp256k12.ProjectivePoint.fromHex(a);
|
|
171
|
-
const pubkeyB = secp256k12.ProjectivePoint.fromHex(b);
|
|
172
|
-
return pubkeyA.subtract(pubkeyB).toRawBytes(true);
|
|
173
|
-
}
|
|
174
|
-
function addPrivateKeys(a, b) {
|
|
175
|
-
if (a.length !== 32 || b.length !== 32) {
|
|
176
|
-
throw new ValidationError("Private keys must be 32 bytes", {
|
|
177
|
-
field: "privateKeys",
|
|
178
|
-
value: `a: ${a.length}, b: ${b.length}`,
|
|
179
|
-
expected: 32
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
const privA = secp256k12.utils.normPrivateKeyToScalar(a);
|
|
183
|
-
const privB = secp256k12.utils.normPrivateKeyToScalar(b);
|
|
184
|
-
const sum = (privA + privB) % secp256k12.CURVE.n;
|
|
185
|
-
return numberToBytesBE2(sum, 32);
|
|
186
|
-
}
|
|
187
|
-
function subtractPrivateKeys(a, b) {
|
|
188
|
-
if (a.length !== 32 || b.length !== 32) {
|
|
189
|
-
throw new ValidationError("Private keys must be 32 bytes", {
|
|
190
|
-
field: "privateKeys",
|
|
191
|
-
value: `a: ${a.length}, b: ${b.length}`,
|
|
192
|
-
expected: 32
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
const privA = secp256k12.utils.normPrivateKeyToScalar(a);
|
|
196
|
-
const privB = secp256k12.utils.normPrivateKeyToScalar(b);
|
|
197
|
-
const sum = (secp256k12.CURVE.n - privB + privA) % secp256k12.CURVE.n;
|
|
198
|
-
return numberToBytesBE2(sum, 32);
|
|
199
|
-
}
|
|
200
|
-
function sumOfPrivateKeys(keys) {
|
|
201
|
-
return keys.reduce((sum, key) => {
|
|
202
|
-
if (key.length !== 32) {
|
|
203
|
-
throw new ValidationError("Private keys must be 32 bytes", {
|
|
204
|
-
field: "privateKey",
|
|
205
|
-
value: key.length,
|
|
206
|
-
expected: 32
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return addPrivateKeys(sum, key);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function lastKeyWithTarget(target, keys) {
|
|
213
|
-
if (target.length !== 32) {
|
|
214
|
-
throw new ValidationError("Target must be 32 bytes", {
|
|
215
|
-
field: "target",
|
|
216
|
-
value: target.length,
|
|
217
|
-
expected: 32
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
const sum = sumOfPrivateKeys(keys);
|
|
221
|
-
return subtractPrivateKeys(target, sum);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/utils/signing.ts
|
|
225
|
-
import { secp256k1 as secp256k13 } from "@noble/curves/secp256k1";
|
|
226
|
-
function getRandomSigningNonce() {
|
|
227
|
-
const binding = secp256k13.utils.randomPrivateKey();
|
|
228
|
-
const hiding = secp256k13.utils.randomPrivateKey();
|
|
229
|
-
return createSigningNonce(binding, hiding);
|
|
230
|
-
}
|
|
231
|
-
function createSigningNonce(binding, hiding) {
|
|
232
|
-
if (binding.length !== 32 || hiding.length !== 32) {
|
|
233
|
-
throw new ValidationError("Invalid nonce length", {
|
|
234
|
-
field: "nonce",
|
|
235
|
-
value: `binding: ${binding.length}, hiding: ${hiding.length}`,
|
|
236
|
-
expected: "Both binding and hiding should be 32 bytes"
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
binding,
|
|
241
|
-
hiding
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
function getSigningCommitmentFromNonce(nonce) {
|
|
245
|
-
const bindingPubKey = secp256k13.getPublicKey(nonce.binding, true);
|
|
246
|
-
const hidingPubKey = secp256k13.getPublicKey(nonce.hiding, true);
|
|
247
|
-
return {
|
|
248
|
-
binding: bindingPubKey,
|
|
249
|
-
hiding: hidingPubKey
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function encodeSigningNonceToBytes(nonce) {
|
|
253
|
-
return new Uint8Array([...nonce.binding, ...nonce.hiding]);
|
|
254
|
-
}
|
|
255
|
-
function decodeBytesToSigningNonce(bytes) {
|
|
256
|
-
if (bytes.length !== 64) {
|
|
257
|
-
throw new ValidationError("Invalid nonce length", {
|
|
258
|
-
field: "bytes",
|
|
259
|
-
value: bytes.length,
|
|
260
|
-
expected: "64 bytes (32 bytes for binding + 32 bytes for hiding)"
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
return {
|
|
264
|
-
binding: bytes.slice(32, 64),
|
|
265
|
-
hiding: bytes.slice(0, 32)
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
function createSigningCommitment(binding, hiding) {
|
|
269
|
-
if (binding.length !== 33 || hiding.length !== 33) {
|
|
270
|
-
throw new ValidationError("Invalid nonce commitment length", {
|
|
271
|
-
field: "commitment",
|
|
272
|
-
value: `binding: ${binding.length}, hiding: ${hiding.length}`,
|
|
273
|
-
expected: "Both binding and hiding should be 33 bytes (compressed public keys)"
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
binding,
|
|
278
|
-
hiding
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function encodeSigningCommitmentToBytes(commitment) {
|
|
282
|
-
if (commitment.binding.length !== 33 || commitment.hiding.length !== 33) {
|
|
283
|
-
throw new ValidationError("Invalid nonce commitment length", {
|
|
284
|
-
field: "commitment",
|
|
285
|
-
value: `binding: ${commitment.binding.length}, hiding: ${commitment.hiding.length}`,
|
|
286
|
-
expected: "Both binding and hiding should be 33 bytes (compressed public keys)"
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
return new Uint8Array([...commitment.binding, ...commitment.hiding]);
|
|
290
|
-
}
|
|
291
|
-
function decodeBytesToSigningCommitment(bytes) {
|
|
292
|
-
if (bytes.length !== 66) {
|
|
293
|
-
throw new ValidationError("Invalid nonce commitment length", {
|
|
294
|
-
field: "bytes",
|
|
295
|
-
value: bytes.length,
|
|
296
|
-
expected: "66 bytes (33 bytes for binding + 33 bytes for hiding)"
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
return {
|
|
300
|
-
binding: bytes.slice(33, 66),
|
|
301
|
-
hiding: bytes.slice(0, 33)
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export {
|
|
306
|
-
generateSignatureFromExistingAdaptor,
|
|
307
|
-
generateAdaptorFromSignature,
|
|
308
|
-
validateOutboundAdaptorSignature,
|
|
309
|
-
applyAdaptorToSignature,
|
|
310
|
-
addPublicKeys,
|
|
311
|
-
applyAdditiveTweakToPublicKey,
|
|
312
|
-
subtractPublicKeys,
|
|
313
|
-
addPrivateKeys,
|
|
314
|
-
subtractPrivateKeys,
|
|
315
|
-
sumOfPrivateKeys,
|
|
316
|
-
lastKeyWithTarget,
|
|
317
|
-
getRandomSigningNonce,
|
|
318
|
-
createSigningNonce,
|
|
319
|
-
getSigningCommitmentFromNonce,
|
|
320
|
-
encodeSigningNonceToBytes,
|
|
321
|
-
decodeBytesToSigningNonce,
|
|
322
|
-
createSigningCommitment,
|
|
323
|
-
encodeSigningCommitmentToBytes,
|
|
324
|
-
decodeBytesToSigningCommitment
|
|
325
|
-
};
|