@buildonspark/spark-sdk 0.1.39 → 0.1.41
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/README.md +1 -1
- package/dist/{RequestLightningSendInput-39_zGri6.d.cts → RequestLightningSendInput-DXcLoiCe.d.cts} +10 -2
- package/dist/{RequestLightningSendInput-B4JdzclX.d.ts → RequestLightningSendInput-mXUWn_cp.d.ts} +10 -2
- package/dist/address/index.cjs +138 -6
- package/dist/address/index.d.cts +18 -6
- package/dist/address/index.d.ts +18 -6
- package/dist/address/index.js +5 -2
- package/dist/{chunk-FWQPAPXK.js → chunk-2ZXXLPG2.js} +1 -1
- package/dist/{chunk-S7KD6DDL.js → chunk-6YVPOQ2A.js} +41 -20
- package/dist/{chunk-ZUVYYR5T.js → chunk-7EFSUADA.js} +1 -0
- package/dist/{chunk-NS4UZRQ7.js → chunk-ABZA6R5S.js} +1 -1
- package/dist/{chunk-57XLH3ZR.js → chunk-ATEHMLKP.js} +23 -23
- package/dist/{chunk-VJTDG4BQ.js → chunk-HK6LPV6Z.js} +10 -1
- package/dist/{chunk-W3EC5XSA.js → chunk-J5W5Q2ZP.js} +337 -72
- package/dist/{chunk-TKYOYOYJ.js → chunk-KKSU7OZO.js} +653 -76
- package/dist/chunk-L3EHBOUX.js +0 -0
- package/dist/{chunk-C5LTJBI7.js → chunk-M6A4KFIG.js} +125 -226
- package/dist/{chunk-A74XSEW3.js → chunk-MIVX3GHD.js} +1 -1
- package/dist/{chunk-RGWBSZIO.js → chunk-ROKY5KS4.js} +23 -3
- package/dist/{chunk-LIP2K6KR.js → chunk-TM4TOEOX.js} +26 -8
- package/dist/{chunk-RAPBVYJY.js → chunk-UKT6OFLO.js} +125 -35
- package/dist/chunk-VA7MV4MZ.js +1073 -0
- package/dist/chunk-YEZDPUFY.js +840 -0
- package/dist/{chunk-DI7QXUQJ.js → chunk-ZXDE2XMU.js} +8 -5
- package/dist/graphql/objects/index.cjs +6 -3
- package/dist/graphql/objects/index.d.cts +6 -5
- package/dist/graphql/objects/index.d.ts +6 -5
- package/dist/graphql/objects/index.js +1 -1
- package/dist/{index-DEo_hdN3.d.cts → index-CFh4uWzi.d.cts} +60 -6
- package/dist/{index-BVY0yH_H.d.ts → index-OSDtPMmC.d.ts} +60 -6
- package/dist/index.cjs +3316 -954
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +48 -26
- package/dist/index.node.cjs +3316 -954
- package/dist/index.node.d.cts +9 -8
- package/dist/index.node.d.ts +9 -8
- package/dist/index.node.js +48 -26
- package/dist/native/index.cjs +3323 -961
- package/dist/native/index.d.cts +542 -260
- package/dist/native/index.d.ts +542 -260
- package/dist/native/index.js +3192 -838
- package/dist/{network-DobHpaV6.d.ts → network-BF2GYPye.d.ts} +9 -2
- package/dist/{network-GFGEHkS4.d.cts → network-BiwBmoOg.d.cts} +9 -2
- package/dist/proto/lrc20.d.cts +1 -1
- package/dist/proto/lrc20.d.ts +1 -1
- package/dist/proto/lrc20.js +2 -2
- package/dist/proto/spark.cjs +125 -226
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark.js +3 -5
- package/dist/proto/spark_token.cjs +1364 -0
- package/dist/proto/spark_token.d.cts +209 -0
- package/dist/proto/spark_token.d.ts +209 -0
- package/dist/proto/spark_token.js +32 -0
- package/dist/{sdk-types-BuVMn2rX.d.cts → sdk-types-CfhdFnsA.d.cts} +1 -1
- package/dist/{sdk-types-BeI6DM_M.d.ts → sdk-types-MnQrHolg.d.ts} +1 -1
- package/dist/services/config.cjs +64 -40
- package/dist/services/config.d.cts +6 -5
- package/dist/services/config.d.ts +6 -5
- package/dist/services/config.js +7 -7
- package/dist/services/connection.cjs +1108 -306
- package/dist/services/connection.d.cts +10 -5
- package/dist/services/connection.d.ts +10 -5
- package/dist/services/connection.js +3 -2
- package/dist/services/index.cjs +1702 -488
- package/dist/services/index.d.cts +6 -5
- package/dist/services/index.d.ts +6 -5
- package/dist/services/index.js +16 -14
- package/dist/services/lrc-connection.d.cts +5 -5
- package/dist/services/lrc-connection.d.ts +5 -5
- package/dist/services/lrc-connection.js +3 -3
- package/dist/services/token-transactions.cjs +637 -247
- package/dist/services/token-transactions.d.cts +19 -8
- package/dist/services/token-transactions.d.ts +19 -8
- package/dist/services/token-transactions.js +5 -4
- package/dist/services/wallet-config.cjs +1 -0
- package/dist/services/wallet-config.d.cts +6 -5
- package/dist/services/wallet-config.d.ts +6 -5
- package/dist/services/wallet-config.js +1 -1
- package/dist/signer/signer.cjs +122 -35
- package/dist/signer/signer.d.cts +4 -3
- package/dist/signer/signer.d.ts +4 -3
- package/dist/signer/signer.js +8 -4
- package/dist/{signer-C1t40Wus.d.cts → signer-BhLS7SYR.d.cts} +35 -14
- package/dist/{signer-DFGw9RRp.d.ts → signer-CylxIujU.d.ts} +35 -14
- package/dist/{spark-DXYE9gMM.d.ts → spark-DjR1b3TC.d.cts} +13 -21
- package/dist/{spark-DXYE9gMM.d.cts → spark-DjR1b3TC.d.ts} +13 -21
- package/dist/types/index.cjs +130 -227
- package/dist/types/index.d.cts +6 -5
- package/dist/types/index.d.ts +6 -5
- package/dist/types/index.js +3 -3
- package/dist/utils/index.cjs +1169 -3
- package/dist/utils/index.d.cts +66 -6
- package/dist/utils/index.d.ts +66 -6
- package/dist/utils/index.js +35 -14
- package/package.json +6 -2
- package/src/address/address.ts +41 -6
- package/src/graphql/client.ts +15 -0
- package/src/graphql/objects/Transfer.ts +7 -0
- package/src/graphql/queries/Transfer.ts +10 -0
- package/src/proto/spark.ts +215 -337
- package/src/proto/spark_token.ts +1407 -0
- package/src/services/config.ts +4 -0
- package/src/services/connection.ts +37 -1
- package/src/services/deposit.ts +23 -5
- package/src/services/token-transactions.ts +426 -75
- package/src/services/transfer.ts +182 -11
- package/src/services/tree-creation.ts +29 -14
- package/src/services/wallet-config.ts +2 -0
- package/src/signer/signer.ts +190 -48
- package/src/spark-wallet/spark-wallet.ts +510 -6
- package/src/tests/integration/transfer.test.ts +186 -214
- package/src/tests/integration/tree-creation.test.ts +5 -1
- package/src/tests/signer.test.ts +34 -0
- package/src/tests/transaction.test.ts +12 -0
- package/src/tests/xchain-address.test.ts +28 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/mempool.ts +26 -1
- package/src/utils/network.ts +15 -0
- package/src/utils/transaction.ts +51 -3
- package/src/utils/unilateral-exit.ts +729 -0
- package/src/utils/xchain-address.ts +36 -0
- package/dist/chunk-E5SL7XTO.js +0 -301
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
getSigningCommitmentFromNonce,
|
|
5
5
|
subtractPrivateKeys
|
|
6
6
|
} from "./chunk-7VMYMQLF.js";
|
|
7
|
-
import {
|
|
8
|
-
splitSecretWithProofs
|
|
9
|
-
} from "./chunk-MGPRLH6Q.js";
|
|
10
7
|
import {
|
|
11
8
|
isReactNative
|
|
12
9
|
} from "./chunk-HKAKEKCE.js";
|
|
10
|
+
import {
|
|
11
|
+
splitSecretWithProofs
|
|
12
|
+
} from "./chunk-MGPRLH6Q.js";
|
|
13
13
|
import {
|
|
14
14
|
ConfigurationError,
|
|
15
15
|
ValidationError
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
bytesToHex,
|
|
24
24
|
bytesToNumberBE,
|
|
25
|
+
equalBytes,
|
|
25
26
|
hexToBytes
|
|
26
27
|
} from "@noble/curves/abstract/utils";
|
|
27
28
|
import { schnorr, secp256k1 } from "@noble/curves/secp256k1";
|
|
@@ -29,11 +30,14 @@ import { HDKey } from "@scure/bip32";
|
|
|
29
30
|
import { generateMnemonic, mnemonicToSeed } from "@scure/bip39";
|
|
30
31
|
import { wordlist } from "@scure/bip39/wordlists/english";
|
|
31
32
|
import * as ecies from "eciesjs";
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
|
|
33
|
+
import { privateAdd, privateNegate } from "@bitcoinerlab/secp256k1";
|
|
34
|
+
import {
|
|
35
|
+
fromPrivateKey,
|
|
36
|
+
PARITY,
|
|
37
|
+
Receipt
|
|
38
|
+
} from "@buildonspark/lrc20-sdk";
|
|
35
39
|
import { sha256 } from "@noble/hashes/sha2";
|
|
36
|
-
import {
|
|
40
|
+
import { taprootTweakPrivKey } from "@scure/btc-signer/utils";
|
|
37
41
|
var sparkFrostModule = void 0;
|
|
38
42
|
var getSparkFrostModule = async () => {
|
|
39
43
|
if (isReactNative) {
|
|
@@ -45,8 +49,8 @@ var getSparkFrostModule = async () => {
|
|
|
45
49
|
return sparkFrostModule;
|
|
46
50
|
};
|
|
47
51
|
var HARDENED_OFFSET = 2147483648;
|
|
48
|
-
var
|
|
49
|
-
async
|
|
52
|
+
var DefaultSparkKeysGenerator = class {
|
|
53
|
+
async deriveKeysFromSeed(seed, accountNumber) {
|
|
50
54
|
const hdkey = HDKey.fromMasterSeed(seed);
|
|
51
55
|
if (!hdkey.privateKey || !hdkey.publicKey) {
|
|
52
56
|
throw new ValidationError("Failed to derive keys from seed", {
|
|
@@ -67,27 +71,79 @@ var DefaultHDKeyGenerator = class {
|
|
|
67
71
|
);
|
|
68
72
|
}
|
|
69
73
|
return {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
privateKey:
|
|
73
|
-
publicKey:
|
|
74
|
+
masterPublicKey: hdkey.publicKey,
|
|
75
|
+
identityKey: {
|
|
76
|
+
privateKey: identityKey.privateKey,
|
|
77
|
+
publicKey: identityKey.publicKey
|
|
78
|
+
},
|
|
79
|
+
signingHDKey: {
|
|
80
|
+
hdKey: signingKey,
|
|
81
|
+
privateKey: signingKey.privateKey,
|
|
82
|
+
publicKey: signingKey.publicKey
|
|
74
83
|
},
|
|
84
|
+
depositKey: {
|
|
85
|
+
privateKey: depositKey.privateKey,
|
|
86
|
+
publicKey: depositKey.publicKey
|
|
87
|
+
},
|
|
88
|
+
staticDepositHDKey: {
|
|
89
|
+
hdKey: staticDepositKey,
|
|
90
|
+
privateKey: staticDepositKey.privateKey,
|
|
91
|
+
publicKey: staticDepositKey.publicKey
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var TaprootOutputKeysGenerator = class {
|
|
97
|
+
constructor(useAddressIndex = false) {
|
|
98
|
+
this.useAddressIndex = useAddressIndex;
|
|
99
|
+
}
|
|
100
|
+
async deriveKeysFromSeed(seed, accountNumber) {
|
|
101
|
+
const hdkey = HDKey.fromMasterSeed(seed);
|
|
102
|
+
if (!hdkey.privateKey || !hdkey.publicKey) {
|
|
103
|
+
throw new ValidationError("Failed to derive keys from seed", {
|
|
104
|
+
field: "hdkey",
|
|
105
|
+
value: seed
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const derivationPath = this.useAddressIndex ? `m/86'/0'/0'/0/${accountNumber}` : `m/86'/0'/${accountNumber}'/0/0`;
|
|
109
|
+
const taprootInternalKey = hdkey.derive(derivationPath);
|
|
110
|
+
let tweakedPrivateKey = taprootTweakPrivKey(taprootInternalKey.privateKey);
|
|
111
|
+
let tweakedPublicKey = secp256k1.getPublicKey(tweakedPrivateKey);
|
|
112
|
+
if (tweakedPublicKey[0] === 3) {
|
|
113
|
+
tweakedPrivateKey = privateNegate(tweakedPrivateKey);
|
|
114
|
+
tweakedPublicKey = secp256k1.getPublicKey(tweakedPrivateKey);
|
|
115
|
+
}
|
|
116
|
+
const identityKey = {
|
|
117
|
+
publicKey: tweakedPublicKey,
|
|
118
|
+
privateKey: tweakedPrivateKey
|
|
119
|
+
};
|
|
120
|
+
const signingKey = hdkey.derive(`${derivationPath}/1'`);
|
|
121
|
+
const depositKey = hdkey.derive(`${derivationPath}/2'`);
|
|
122
|
+
const staticDepositKey = hdkey.derive(`${derivationPath}/3'`);
|
|
123
|
+
if (!signingKey.privateKey || !signingKey.publicKey || !depositKey.privateKey || !depositKey.publicKey || !staticDepositKey.privateKey || !staticDepositKey.publicKey) {
|
|
124
|
+
throw new ValidationError(
|
|
125
|
+
"Failed to derive all required keys from seed",
|
|
126
|
+
{
|
|
127
|
+
field: "derivedKeys"
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
masterPublicKey: hdkey.publicKey,
|
|
75
133
|
identityKey: {
|
|
76
|
-
hdKey: identityKey,
|
|
77
134
|
privateKey: identityKey.privateKey,
|
|
78
135
|
publicKey: identityKey.publicKey
|
|
79
136
|
},
|
|
80
|
-
|
|
137
|
+
signingHDKey: {
|
|
81
138
|
hdKey: signingKey,
|
|
82
139
|
privateKey: signingKey.privateKey,
|
|
83
140
|
publicKey: signingKey.publicKey
|
|
84
141
|
},
|
|
85
142
|
depositKey: {
|
|
86
|
-
hdKey: depositKey,
|
|
87
143
|
privateKey: depositKey.privateKey,
|
|
88
144
|
publicKey: depositKey.publicKey
|
|
89
145
|
},
|
|
90
|
-
|
|
146
|
+
staticDepositHDKey: {
|
|
91
147
|
hdKey: staticDepositKey,
|
|
92
148
|
privateKey: staticDepositKey.privateKey,
|
|
93
149
|
publicKey: staticDepositKey.publicKey
|
|
@@ -96,7 +152,7 @@ var DefaultHDKeyGenerator = class {
|
|
|
96
152
|
}
|
|
97
153
|
};
|
|
98
154
|
var DefaultSparkSigner = class {
|
|
99
|
-
|
|
155
|
+
masterPublicKey = null;
|
|
100
156
|
identityKey = null;
|
|
101
157
|
signingKey = null;
|
|
102
158
|
depositKey = null;
|
|
@@ -105,14 +161,16 @@ var DefaultSparkSigner = class {
|
|
|
105
161
|
// <hex, hex>
|
|
106
162
|
publicKeyToPrivateKeyMap = /* @__PURE__ */ new Map();
|
|
107
163
|
commitmentToNonceMap = /* @__PURE__ */ new Map();
|
|
108
|
-
|
|
109
|
-
constructor({
|
|
110
|
-
|
|
164
|
+
keysGenerator;
|
|
165
|
+
constructor({
|
|
166
|
+
sparkKeysGenerator
|
|
167
|
+
} = {}) {
|
|
168
|
+
this.keysGenerator = sparkKeysGenerator ?? new DefaultSparkKeysGenerator();
|
|
111
169
|
}
|
|
112
170
|
deriveSigningKey(hash) {
|
|
113
|
-
if (!this.
|
|
171
|
+
if (!this.signingKey) {
|
|
114
172
|
throw new ValidationError("Private key not initialized", {
|
|
115
|
-
field: "
|
|
173
|
+
field: "signingKey"
|
|
116
174
|
});
|
|
117
175
|
}
|
|
118
176
|
const view = new DataView(hash.buffer);
|
|
@@ -126,9 +184,9 @@ var DefaultSparkSigner = class {
|
|
|
126
184
|
return newPrivateKey;
|
|
127
185
|
}
|
|
128
186
|
async restoreSigningKeysFromLeafs(leafs) {
|
|
129
|
-
if (!this.
|
|
130
|
-
throw new ValidationError("
|
|
131
|
-
field: "
|
|
187
|
+
if (!this.signingKey) {
|
|
188
|
+
throw new ValidationError("Signing key is not set", {
|
|
189
|
+
field: "signingKey"
|
|
132
190
|
});
|
|
133
191
|
}
|
|
134
192
|
for (const leaf of leafs) {
|
|
@@ -248,9 +306,9 @@ var DefaultSparkSigner = class {
|
|
|
248
306
|
return Array.from(this.publicKeyToPrivateKeyMap.keys()).map(hexToBytes);
|
|
249
307
|
}
|
|
250
308
|
async generatePublicKey(hash) {
|
|
251
|
-
if (!this.
|
|
309
|
+
if (!this.signingKey) {
|
|
252
310
|
throw new ValidationError("Private key is not set", {
|
|
253
|
-
field: "
|
|
311
|
+
field: "signingKey"
|
|
254
312
|
});
|
|
255
313
|
}
|
|
256
314
|
let newPrivateKey = null;
|
|
@@ -386,10 +444,16 @@ var DefaultSparkSigner = class {
|
|
|
386
444
|
if (typeof seed === "string") {
|
|
387
445
|
seed = hexToBytes(seed);
|
|
388
446
|
}
|
|
389
|
-
const {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
447
|
+
const {
|
|
448
|
+
masterPublicKey,
|
|
449
|
+
identityKey,
|
|
450
|
+
signingHDKey: signingKey,
|
|
451
|
+
depositKey,
|
|
452
|
+
staticDepositHDKey: staticDepositKey
|
|
453
|
+
} = await this.keysGenerator.deriveKeysFromSeed(seed, accountNumber ?? 0);
|
|
454
|
+
this.masterPublicKey = masterPublicKey;
|
|
455
|
+
this.identityKey = identityKey;
|
|
456
|
+
this.depositKey = depositKey;
|
|
393
457
|
this.signingKey = signingKey.hdKey;
|
|
394
458
|
this.staticDepositKey = staticDepositKey.hdKey;
|
|
395
459
|
this.publicKeyToPrivateKeyMap.set(
|
|
@@ -478,10 +542,10 @@ var DefaultSparkSigner = class {
|
|
|
478
542
|
};
|
|
479
543
|
}
|
|
480
544
|
async getMasterPublicKey() {
|
|
481
|
-
if (!this.
|
|
545
|
+
if (!this.masterPublicKey) {
|
|
482
546
|
throw new Error("Private key is not set");
|
|
483
547
|
}
|
|
484
|
-
return this.
|
|
548
|
+
return this.masterPublicKey;
|
|
485
549
|
}
|
|
486
550
|
async validateMessageWithIdentityKey(message, signature) {
|
|
487
551
|
if (!this.identityKey?.publicKey) {
|
|
@@ -519,8 +583,34 @@ var DefaultSparkSigner = class {
|
|
|
519
583
|
const receiptProof = privateAdd(privateKey, pxhPubkey);
|
|
520
584
|
return Buffer.from(receiptProof);
|
|
521
585
|
}
|
|
586
|
+
signTransactionIndex(tx, index, publicKey) {
|
|
587
|
+
let privateKey;
|
|
588
|
+
if (equalBytes(publicKey, this.identityKey?.publicKey ?? new Uint8Array())) {
|
|
589
|
+
privateKey = this.identityKey?.privateKey;
|
|
590
|
+
} else if (equalBytes(publicKey, this.depositKey?.publicKey ?? new Uint8Array())) {
|
|
591
|
+
privateKey = this.depositKey?.privateKey;
|
|
592
|
+
} else {
|
|
593
|
+
privateKey = hexToBytes(
|
|
594
|
+
this.publicKeyToPrivateKeyMap.get(bytesToHex(publicKey)) ?? ""
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
if (!privateKey) {
|
|
598
|
+
throw new ValidationError("Private key not found for public key", {
|
|
599
|
+
field: "privateKey",
|
|
600
|
+
value: bytesToHex(publicKey)
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
tx.signIdx(privateKey, index);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
var TaprootSparkSigner = class extends DefaultSparkSigner {
|
|
607
|
+
constructor() {
|
|
608
|
+
super({ sparkKeysGenerator: new TaprootOutputKeysGenerator() });
|
|
609
|
+
}
|
|
522
610
|
};
|
|
523
611
|
|
|
524
612
|
export {
|
|
525
|
-
|
|
613
|
+
TaprootOutputKeysGenerator,
|
|
614
|
+
DefaultSparkSigner,
|
|
615
|
+
TaprootSparkSigner
|
|
526
616
|
};
|