@buildonspark/spark-sdk 0.0.9 → 0.0.10
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/dist/services/config.d.ts +20 -16
- package/dist/services/config.js +26 -18
- package/dist/services/config.js.map +1 -1
- package/dist/services/connection.js +1 -1
- package/dist/services/connection.js.map +1 -1
- package/dist/services/deposit.js +2 -2
- package/dist/services/deposit.js.map +1 -1
- package/dist/services/lightning.js +4 -4
- package/dist/services/lightning.js.map +1 -1
- package/dist/services/token-transactions.js +8 -7
- package/dist/services/token-transactions.js.map +1 -1
- package/dist/services/transfer.js +12 -10
- package/dist/services/transfer.js.map +1 -1
- package/dist/spark-sdk.d.ts +2 -3
- package/dist/spark-sdk.js +2 -7
- package/dist/spark-sdk.js.map +1 -1
- package/dist/tests/coop-exit.test.js +8 -5
- package/dist/tests/coop-exit.test.js.map +1 -1
- package/dist/tests/deposit.test.js +8 -10
- package/dist/tests/deposit.test.js.map +1 -1
- package/dist/tests/jest.setup.d.ts +1 -0
- package/dist/tests/jest.setup.js +8 -0
- package/dist/tests/jest.setup.js.map +1 -0
- package/dist/tests/keys.test.js +0 -1
- package/dist/tests/keys.test.js.map +1 -1
- package/dist/tests/lightning.test.js +10 -7
- package/dist/tests/lightning.test.js.map +1 -1
- package/dist/tests/swap.test.js +8 -5
- package/dist/tests/swap.test.js.map +1 -1
- package/dist/tests/test-util.d.ts +8 -44
- package/dist/tests/test-util.js +10 -7
- package/dist/tests/test-util.js.map +1 -1
- package/dist/tests/transfer.test.js +30 -19
- package/dist/tests/transfer.test.js.map +1 -1
- package/package.json +2 -2
- package/dist/LightningSendRequest-CNJFhLVc.d.cts +0 -374
- package/dist/LightningSendRequest-CNJFhLVc.d.ts +0 -374
- package/dist/auto-bind.d.ts +0 -7
- package/dist/auto-bind.js +0 -41
- package/dist/auto-bind.js.map +0 -1
- package/dist/chunk-5SAJ52IV.js +0 -10309
- package/dist/chunk-COXVABEU.js +0 -1524
- package/dist/chunk-F4JW24C4.js +0 -78
- package/dist/chunk-H4A2WXR3.js +0 -331
- package/dist/chunk-HTNOFUHX.js +0 -1547
- package/dist/chunk-JQFHUW4I.js +0 -21
- package/dist/chunk-K3Y7DVLD.js +0 -19
- package/dist/chunk-NDKNVHGP.js +0 -127
- package/dist/chunk-PMVJGQCP.js +0 -627
- package/dist/chunk-QX3ZJH2S.js +0 -527
- package/dist/chunk-SL2YOBVM.js +0 -127
- package/dist/chunk-SWCOMKD6.js +0 -333
- package/dist/chunk-SWFFNBSR.js +0 -1244
- package/dist/chunk-WLK5POBV.js +0 -527
- package/dist/chunk-WZ74TD7N.js +0 -660
- package/dist/chunk-WZYVI3M3.js +0 -1244
- package/dist/chunk-ZGU3XW7W.js +0 -78
- package/dist/connection-BgWj7Hnd.d.cts +0 -77
- package/dist/connection-BgbVJtzh.d.ts +0 -77
- package/dist/connection-DX-9yFl8.d.ts +0 -77
- package/dist/connection-hITj9Mgk.d.cts +0 -77
- package/dist/graphql/objects/index.cjs +0 -626
- package/dist/graphql/objects/index.d.cts +0 -140
- package/dist/index.cjs +0 -17202
- package/dist/index.d.cts +0 -413
- package/dist/index.d.ts +0 -413
- package/dist/index.js +0 -3390
- package/dist/proto/spark.cjs +0 -10451
- package/dist/proto/spark.d.cts +0 -3
- package/dist/services/index.cjs +0 -12503
- package/dist/services/index.d.cts +0 -23
- package/dist/services/index.d.ts +0 -23
- package/dist/services/index.js +0 -17
- package/dist/signer/signer.cjs +0 -894
- package/dist/signer/signer.d.cts +0 -5
- package/dist/signer-BaC_ZP1g.d.ts +0 -138
- package/dist/signer-C6h1OnSQ.d.cts +0 -138
- package/dist/signer-CO4owhHI.d.ts +0 -154
- package/dist/signer-DDkpXvNZ.d.cts +0 -154
- package/dist/spark-BUTdOtMz.d.cts +0 -1170
- package/dist/spark-BUTdOtMz.d.ts +0 -1170
- package/dist/tests/test-util.cjs +0 -12269
- package/dist/tests/test-util.d.cts +0 -90
- package/dist/utils/index.cjs +0 -1825
- package/dist/utils/index.d.cts +0 -280
package/dist/chunk-F4JW24C4.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getP2TRScriptFromPublicKey
|
|
3
|
-
} from "./chunk-NDKNVHGP.js";
|
|
4
|
-
import {
|
|
5
|
-
spark_bindings_default
|
|
6
|
-
} from "./chunk-COXVABEU.js";
|
|
7
|
-
|
|
8
|
-
// src/utils/transaction.ts
|
|
9
|
-
import { Transaction } from "@scure/btc-signer";
|
|
10
|
-
var TIME_LOCK_INTERVAL = 100;
|
|
11
|
-
function createRefundTx(sequence, nodeOutPoint, amountSats, receivingPubkey, network) {
|
|
12
|
-
const newRefundTx = new Transaction({ allowUnknownOutputs: true });
|
|
13
|
-
newRefundTx.addInput({
|
|
14
|
-
...nodeOutPoint,
|
|
15
|
-
sequence
|
|
16
|
-
});
|
|
17
|
-
const refundPkScript = getP2TRScriptFromPublicKey(receivingPubkey, network);
|
|
18
|
-
newRefundTx.addOutput({
|
|
19
|
-
script: refundPkScript,
|
|
20
|
-
amount: amountSats
|
|
21
|
-
});
|
|
22
|
-
newRefundTx.addOutput(getEphemeralAnchorOutput());
|
|
23
|
-
return newRefundTx;
|
|
24
|
-
}
|
|
25
|
-
function getNextTransactionSequence(currSequence) {
|
|
26
|
-
const currentTimelock = (currSequence || 0) & 65535;
|
|
27
|
-
if (currentTimelock - TIME_LOCK_INTERVAL <= 0) {
|
|
28
|
-
throw new Error("timelock interval is less or equal to 0");
|
|
29
|
-
}
|
|
30
|
-
return 1 << 30 | currentTimelock - TIME_LOCK_INTERVAL;
|
|
31
|
-
}
|
|
32
|
-
function getEphemeralAnchorOutput() {
|
|
33
|
-
return {
|
|
34
|
-
script: new Uint8Array([81]),
|
|
35
|
-
// OP_TRUE
|
|
36
|
-
amount: 0n
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/utils/wasm-wrapper.ts
|
|
41
|
-
async function initWasm() {
|
|
42
|
-
let wasmModule;
|
|
43
|
-
try {
|
|
44
|
-
if (typeof window === "undefined") {
|
|
45
|
-
const fs = await import("fs/promises");
|
|
46
|
-
const path = await import("path");
|
|
47
|
-
const { fileURLToPath } = await import("url");
|
|
48
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
49
|
-
const __dirname = path.dirname(__filename);
|
|
50
|
-
const wasmPath = path.resolve(
|
|
51
|
-
__dirname,
|
|
52
|
-
"../wasm/spark_bindings_bg.wasm"
|
|
53
|
-
);
|
|
54
|
-
const wasmBuffer = await fs.readFile(wasmPath);
|
|
55
|
-
wasmModule = await spark_bindings_default({ module_or_path: wasmBuffer }).catch((e) => {
|
|
56
|
-
console.error("WASM initialization error:", e);
|
|
57
|
-
throw e;
|
|
58
|
-
});
|
|
59
|
-
return wasmModule;
|
|
60
|
-
} else {
|
|
61
|
-
wasmModule = await spark_bindings_default();
|
|
62
|
-
}
|
|
63
|
-
} catch (e) {
|
|
64
|
-
console.error("WASM initialization error:", e);
|
|
65
|
-
throw e;
|
|
66
|
-
}
|
|
67
|
-
if (!wasmModule || typeof wasmModule !== "object") {
|
|
68
|
-
throw new Error("WASM module not properly initialized");
|
|
69
|
-
}
|
|
70
|
-
return wasmModule;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export {
|
|
74
|
-
createRefundTx,
|
|
75
|
-
getNextTransactionSequence,
|
|
76
|
-
getEphemeralAnchorOutput,
|
|
77
|
-
initWasm
|
|
78
|
-
};
|
package/dist/chunk-H4A2WXR3.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
KeyPackage,
|
|
3
|
-
aggregateFrost,
|
|
4
|
-
createWasmSigningCommitment,
|
|
5
|
-
createWasmSigningNonce,
|
|
6
|
-
generateAdaptorFromSignature,
|
|
7
|
-
getMasterHDKeyFromSeed,
|
|
8
|
-
getRandomSigningNonce,
|
|
9
|
-
getSigningCommitmentFromNonce,
|
|
10
|
-
signFrost,
|
|
11
|
-
splitSecretWithProofs,
|
|
12
|
-
subtractPrivateKeys
|
|
13
|
-
} from "./chunk-HTNOFUHX.js";
|
|
14
|
-
|
|
15
|
-
// src/signer/signer.ts
|
|
16
|
-
import {
|
|
17
|
-
bytesToHex,
|
|
18
|
-
bytesToNumberBE,
|
|
19
|
-
hexToBytes
|
|
20
|
-
} from "@noble/curves/abstract/utils";
|
|
21
|
-
import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
|
|
22
|
-
import * as bip39 from "@scure/bip39";
|
|
23
|
-
import { generateMnemonic } from "@scure/bip39";
|
|
24
|
-
import { wordlist } from "@scure/bip39/wordlists/english";
|
|
25
|
-
import { sha256 } from "@scure/btc-signer/utils";
|
|
26
|
-
import { Buffer } from "buffer";
|
|
27
|
-
import * as ecies from "eciesjs";
|
|
28
|
-
globalThis.Buffer = Buffer;
|
|
29
|
-
var DefaultSparkSigner = class {
|
|
30
|
-
identityPrivateKey = null;
|
|
31
|
-
// <hex, hex>
|
|
32
|
-
publicKeyToPrivateKeyMap = /* @__PURE__ */ new Map();
|
|
33
|
-
commitmentToNonceMap = /* @__PURE__ */ new Map();
|
|
34
|
-
deriveSigningKey(hash) {
|
|
35
|
-
if (!this.identityPrivateKey) {
|
|
36
|
-
throw new Error("Private key is not set");
|
|
37
|
-
}
|
|
38
|
-
let amount = 0;
|
|
39
|
-
for (let i = 0; i < 8; i++) {
|
|
40
|
-
const view = new DataView(hash.buffer, i * 4, 4);
|
|
41
|
-
amount += view.getUint32(0, false);
|
|
42
|
-
amount = amount % 2147483648;
|
|
43
|
-
}
|
|
44
|
-
const newPrivateKey = this.identityPrivateKey.deriveChild(
|
|
45
|
-
Number(amount) + 2147483648
|
|
46
|
-
).privateKey;
|
|
47
|
-
if (!newPrivateKey) {
|
|
48
|
-
throw new Error("Failed to recover signing key");
|
|
49
|
-
}
|
|
50
|
-
return newPrivateKey;
|
|
51
|
-
}
|
|
52
|
-
async restoreSigningKeysFromLeafs(leafs) {
|
|
53
|
-
if (!this.identityPrivateKey) {
|
|
54
|
-
throw new Error("Private key is not set");
|
|
55
|
-
}
|
|
56
|
-
for (const leaf of leafs) {
|
|
57
|
-
const hash = sha256(leaf.id);
|
|
58
|
-
const privateKey = this.deriveSigningKey(hash);
|
|
59
|
-
const publicKey = secp256k1.getPublicKey(privateKey);
|
|
60
|
-
this.publicKeyToPrivateKeyMap.set(
|
|
61
|
-
bytesToHex(publicKey),
|
|
62
|
-
bytesToHex(privateKey)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async getSchnorrPublicKey(publicKey) {
|
|
67
|
-
const privateKey = this.publicKeyToPrivateKeyMap.get(bytesToHex(publicKey));
|
|
68
|
-
if (!privateKey) {
|
|
69
|
-
throw new Error("Private key is not set");
|
|
70
|
-
}
|
|
71
|
-
return schnorr.getPublicKey(hexToBytes(privateKey));
|
|
72
|
-
}
|
|
73
|
-
async signSchnorr(message, publicKey) {
|
|
74
|
-
const privateKey = this.publicKeyToPrivateKeyMap.get(bytesToHex(publicKey));
|
|
75
|
-
if (!privateKey) {
|
|
76
|
-
throw new Error("Private key is not set");
|
|
77
|
-
}
|
|
78
|
-
return schnorr.sign(message, hexToBytes(privateKey));
|
|
79
|
-
}
|
|
80
|
-
async signSchnorrWithIdentityKey(message) {
|
|
81
|
-
if (!this.identityPrivateKey?.privateKey) {
|
|
82
|
-
throw new Error("Private key is not set");
|
|
83
|
-
}
|
|
84
|
-
const signature = schnorr.sign(message, this.identityPrivateKey.privateKey);
|
|
85
|
-
return signature;
|
|
86
|
-
}
|
|
87
|
-
async getIdentityPublicKey() {
|
|
88
|
-
if (!this.identityPrivateKey?.privateKey) {
|
|
89
|
-
throw new Error("Private key is not set");
|
|
90
|
-
}
|
|
91
|
-
return secp256k1.getPublicKey(this.identityPrivateKey.privateKey);
|
|
92
|
-
}
|
|
93
|
-
async generateMnemonic() {
|
|
94
|
-
return generateMnemonic(wordlist);
|
|
95
|
-
}
|
|
96
|
-
async createSparkWalletFromMnemonic(mnemonic, network) {
|
|
97
|
-
const seed = await bip39.mnemonicToSeed(mnemonic);
|
|
98
|
-
return this.createSparkWalletFromSeed(seed, network);
|
|
99
|
-
}
|
|
100
|
-
async getTrackedPublicKeys() {
|
|
101
|
-
return Array.from(this.publicKeyToPrivateKeyMap.keys()).map(hexToBytes);
|
|
102
|
-
}
|
|
103
|
-
async generatePublicKey(hash) {
|
|
104
|
-
if (!this.identityPrivateKey) {
|
|
105
|
-
throw new Error("Private key is not set");
|
|
106
|
-
}
|
|
107
|
-
let newPrivateKey = null;
|
|
108
|
-
if (hash) {
|
|
109
|
-
newPrivateKey = this.deriveSigningKey(hash);
|
|
110
|
-
} else {
|
|
111
|
-
newPrivateKey = secp256k1.utils.randomPrivateKey();
|
|
112
|
-
}
|
|
113
|
-
if (!newPrivateKey) {
|
|
114
|
-
throw new Error("Failed to generate new private key");
|
|
115
|
-
}
|
|
116
|
-
const publicKey = secp256k1.getPublicKey(newPrivateKey);
|
|
117
|
-
const pubKeyHex = bytesToHex(publicKey);
|
|
118
|
-
const privKeyHex = bytesToHex(newPrivateKey);
|
|
119
|
-
this.publicKeyToPrivateKeyMap.set(pubKeyHex, privKeyHex);
|
|
120
|
-
return publicKey;
|
|
121
|
-
}
|
|
122
|
-
async removePublicKey(publicKey) {
|
|
123
|
-
this.publicKeyToPrivateKeyMap.delete(bytesToHex(publicKey));
|
|
124
|
-
}
|
|
125
|
-
async subtractPrivateKeysGivenPublicKeys(first, second) {
|
|
126
|
-
const firstPubKeyHex = bytesToHex(first);
|
|
127
|
-
const secondPubKeyHex = bytesToHex(second);
|
|
128
|
-
const firstPrivateKeyHex = this.publicKeyToPrivateKeyMap.get(firstPubKeyHex);
|
|
129
|
-
const secondPrivateKeyHex = this.publicKeyToPrivateKeyMap.get(secondPubKeyHex);
|
|
130
|
-
if (!firstPrivateKeyHex || !secondPrivateKeyHex) {
|
|
131
|
-
throw new Error("Private key is not set");
|
|
132
|
-
}
|
|
133
|
-
const firstPrivateKey = hexToBytes(firstPrivateKeyHex);
|
|
134
|
-
const secondPrivateKey = hexToBytes(secondPrivateKeyHex);
|
|
135
|
-
const resultPrivKey = subtractPrivateKeys(
|
|
136
|
-
firstPrivateKey,
|
|
137
|
-
secondPrivateKey
|
|
138
|
-
);
|
|
139
|
-
const resultPubKey = secp256k1.getPublicKey(resultPrivKey);
|
|
140
|
-
const resultPrivKeyHex = bytesToHex(resultPrivKey);
|
|
141
|
-
const resultPubKeyHex = bytesToHex(resultPubKey);
|
|
142
|
-
this.publicKeyToPrivateKeyMap.set(resultPubKeyHex, resultPrivKeyHex);
|
|
143
|
-
return resultPubKey;
|
|
144
|
-
}
|
|
145
|
-
async splitSecretWithProofs({
|
|
146
|
-
secret,
|
|
147
|
-
curveOrder,
|
|
148
|
-
threshold,
|
|
149
|
-
numShares,
|
|
150
|
-
isSecretPubkey = false
|
|
151
|
-
}) {
|
|
152
|
-
if (isSecretPubkey) {
|
|
153
|
-
const pubKeyHex = bytesToHex(secret);
|
|
154
|
-
const privateKey = this.publicKeyToPrivateKeyMap.get(pubKeyHex);
|
|
155
|
-
if (!privateKey) {
|
|
156
|
-
throw new Error("Private key is not set");
|
|
157
|
-
}
|
|
158
|
-
secret = hexToBytes(privateKey);
|
|
159
|
-
}
|
|
160
|
-
const secretAsInt = bytesToNumberBE(secret);
|
|
161
|
-
return splitSecretWithProofs(secretAsInt, curveOrder, threshold, numShares);
|
|
162
|
-
}
|
|
163
|
-
async signFrost({
|
|
164
|
-
message,
|
|
165
|
-
privateAsPubKey,
|
|
166
|
-
publicKey,
|
|
167
|
-
verifyingKey,
|
|
168
|
-
selfCommitment,
|
|
169
|
-
statechainCommitments,
|
|
170
|
-
adaptorPubKey
|
|
171
|
-
}) {
|
|
172
|
-
const privateAsPubKeyHex = bytesToHex(privateAsPubKey);
|
|
173
|
-
const signingPrivateKey = this.publicKeyToPrivateKeyMap.get(privateAsPubKeyHex);
|
|
174
|
-
if (!signingPrivateKey) {
|
|
175
|
-
throw new Error("Private key is not set");
|
|
176
|
-
}
|
|
177
|
-
const nonce = this.commitmentToNonceMap.get(selfCommitment);
|
|
178
|
-
if (!nonce) {
|
|
179
|
-
throw new Error("Nonce is not set");
|
|
180
|
-
}
|
|
181
|
-
const keyPackage = new KeyPackage(
|
|
182
|
-
hexToBytes(signingPrivateKey),
|
|
183
|
-
publicKey,
|
|
184
|
-
verifyingKey
|
|
185
|
-
);
|
|
186
|
-
return signFrost({
|
|
187
|
-
msg: message,
|
|
188
|
-
keyPackage,
|
|
189
|
-
nonce: createWasmSigningNonce(nonce),
|
|
190
|
-
selfCommitment: createWasmSigningCommitment(selfCommitment),
|
|
191
|
-
statechainCommitments,
|
|
192
|
-
adaptorPubKey
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
async aggregateFrost({
|
|
196
|
-
message,
|
|
197
|
-
publicKey,
|
|
198
|
-
verifyingKey,
|
|
199
|
-
selfCommitment,
|
|
200
|
-
statechainCommitments,
|
|
201
|
-
adaptorPubKey,
|
|
202
|
-
selfSignature,
|
|
203
|
-
statechainSignatures,
|
|
204
|
-
statechainPublicKeys
|
|
205
|
-
}) {
|
|
206
|
-
return aggregateFrost({
|
|
207
|
-
msg: message,
|
|
208
|
-
statechainSignatures,
|
|
209
|
-
statechainPublicKeys,
|
|
210
|
-
verifyingKey,
|
|
211
|
-
statechainCommitments,
|
|
212
|
-
selfCommitment: createWasmSigningCommitment(selfCommitment),
|
|
213
|
-
selfPublicKey: publicKey,
|
|
214
|
-
selfSignature,
|
|
215
|
-
adaptorPubKey
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
async createSparkWalletFromSeed(seed, network) {
|
|
219
|
-
if (typeof seed === "string") {
|
|
220
|
-
seed = hexToBytes(seed);
|
|
221
|
-
}
|
|
222
|
-
const hdkey = getMasterHDKeyFromSeed(
|
|
223
|
-
seed,
|
|
224
|
-
network == 3 /* REGTEST */ ? 0 : 1
|
|
225
|
-
);
|
|
226
|
-
if (!hdkey.privateKey) {
|
|
227
|
-
throw new Error("Could not derive private key from seed");
|
|
228
|
-
}
|
|
229
|
-
this.identityPrivateKey = hdkey;
|
|
230
|
-
return bytesToHex(secp256k1.getPublicKey(hdkey.privateKey, true));
|
|
231
|
-
}
|
|
232
|
-
async signMessageWithPublicKey(message, publicKey, compact) {
|
|
233
|
-
const privateKey = this.publicKeyToPrivateKeyMap.get(bytesToHex(publicKey));
|
|
234
|
-
if (!privateKey) {
|
|
235
|
-
throw new Error(
|
|
236
|
-
`No private key found for public key: ${bytesToHex(publicKey)}`
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
const signature = secp256k1.sign(message, hexToBytes(privateKey));
|
|
240
|
-
if (compact) {
|
|
241
|
-
return signature.toCompactRawBytes();
|
|
242
|
-
}
|
|
243
|
-
return signature.toDERRawBytes();
|
|
244
|
-
}
|
|
245
|
-
async signMessageWithIdentityKey(message, compact) {
|
|
246
|
-
if (!this.identityPrivateKey?.privateKey) {
|
|
247
|
-
throw new Error("Private key is not set");
|
|
248
|
-
}
|
|
249
|
-
const signature = secp256k1.sign(
|
|
250
|
-
message,
|
|
251
|
-
this.identityPrivateKey.privateKey
|
|
252
|
-
);
|
|
253
|
-
if (compact) {
|
|
254
|
-
return signature.toCompactRawBytes();
|
|
255
|
-
}
|
|
256
|
-
return signature.toDERRawBytes();
|
|
257
|
-
}
|
|
258
|
-
async encryptLeafPrivateKeyEcies(receiverPublicKey, publicKey) {
|
|
259
|
-
const publicKeyHex = bytesToHex(publicKey);
|
|
260
|
-
const privateKey = this.publicKeyToPrivateKeyMap.get(publicKeyHex);
|
|
261
|
-
if (!privateKey) {
|
|
262
|
-
throw new Error("Private key is not set");
|
|
263
|
-
}
|
|
264
|
-
return ecies.encrypt(receiverPublicKey, hexToBytes(privateKey));
|
|
265
|
-
}
|
|
266
|
-
async decryptEcies(ciphertext) {
|
|
267
|
-
if (!this.identityPrivateKey?.privateKey) {
|
|
268
|
-
throw new Error("Private key is not set");
|
|
269
|
-
}
|
|
270
|
-
const receiverEciesPrivKey = ecies.PrivateKey.fromHex(
|
|
271
|
-
bytesToHex(this.identityPrivateKey.privateKey)
|
|
272
|
-
);
|
|
273
|
-
const privateKey = ecies.decrypt(receiverEciesPrivKey.toHex(), ciphertext);
|
|
274
|
-
const publicKey = secp256k1.getPublicKey(privateKey);
|
|
275
|
-
const publicKeyHex = bytesToHex(publicKey);
|
|
276
|
-
const privateKeyHex = bytesToHex(privateKey);
|
|
277
|
-
this.publicKeyToPrivateKeyMap.set(publicKeyHex, privateKeyHex);
|
|
278
|
-
return publicKey;
|
|
279
|
-
}
|
|
280
|
-
async getRandomSigningCommitment() {
|
|
281
|
-
const nonce = getRandomSigningNonce();
|
|
282
|
-
const commitment = getSigningCommitmentFromNonce(nonce);
|
|
283
|
-
this.commitmentToNonceMap.set(commitment, nonce);
|
|
284
|
-
return commitment;
|
|
285
|
-
}
|
|
286
|
-
// Hardcode this for default ssp
|
|
287
|
-
async getSspIdentityPublicKey(network) {
|
|
288
|
-
if (network === 0 /* MAINNET */) {
|
|
289
|
-
return hexToBytes(
|
|
290
|
-
"02e0b8d42c5d3b5fe4c5beb6ea796ab3bc8aaf28a3d3195407482c67e0b58228a5"
|
|
291
|
-
);
|
|
292
|
-
} else {
|
|
293
|
-
return hexToBytes(
|
|
294
|
-
"028c094a432d46a0ac95349d792c2e3730bd60c29188db716f56a99e39b95338b4"
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async hashRandomPrivateKey() {
|
|
299
|
-
return sha256(secp256k1.utils.randomPrivateKey());
|
|
300
|
-
}
|
|
301
|
-
async generateAdaptorFromSignature(signature) {
|
|
302
|
-
const adaptor = generateAdaptorFromSignature(signature);
|
|
303
|
-
const adaptorPublicKey = secp256k1.getPublicKey(adaptor.adaptorPrivateKey);
|
|
304
|
-
this.publicKeyToPrivateKeyMap.set(
|
|
305
|
-
bytesToHex(adaptorPublicKey),
|
|
306
|
-
bytesToHex(adaptor.adaptorPrivateKey)
|
|
307
|
-
);
|
|
308
|
-
return {
|
|
309
|
-
adaptorSignature: signature,
|
|
310
|
-
adaptorPublicKey
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
async getDepositSigningKey() {
|
|
314
|
-
if (!this.identityPrivateKey?.privateKey) {
|
|
315
|
-
throw new Error("Private key is not set");
|
|
316
|
-
}
|
|
317
|
-
const depositSigningKey = this.identityPrivateKey.derive("M/8797555'/0'/2'");
|
|
318
|
-
if (!depositSigningKey.privateKey) {
|
|
319
|
-
throw new Error("Could not derive deposit signing key");
|
|
320
|
-
}
|
|
321
|
-
this.publicKeyToPrivateKeyMap.set(
|
|
322
|
-
bytesToHex(secp256k1.getPublicKey(depositSigningKey.privateKey)),
|
|
323
|
-
bytesToHex(depositSigningKey.privateKey)
|
|
324
|
-
);
|
|
325
|
-
return secp256k1.getPublicKey(depositSigningKey.privateKey);
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
export {
|
|
330
|
-
DefaultSparkSigner
|
|
331
|
-
};
|