@buildonspark/spark-sdk 0.1.47 → 0.2.0
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 +12 -0
- package/dist/{chunk-BGGEVUJK.js → chunk-2ENZX6LT.js} +241 -7
- package/dist/{chunk-LHRD2WT6.js → chunk-4JD4HIAN.js} +23 -3
- package/dist/chunk-BYXBJQAS.js +0 -0
- package/dist/{chunk-EAP3U3CW.js → chunk-CDLETEDT.js} +25 -17
- package/dist/{chunk-OBFKIEMP.js → chunk-TM6CHQXC.js} +1 -1
- package/dist/{chunk-NNX4OK44.js → chunk-UDK3EBE5.js} +5544 -1678
- package/dist/chunk-XYTKKLCV.js +7 -0
- package/dist/{client-D7KgLN44.d.ts → client-DKbwpcnl.d.ts} +73 -61
- package/dist/{client-CvpTRpcw.d.cts → client-Drs5Lapg.d.cts} +73 -61
- package/dist/debug.cjs +32358 -0
- package/dist/debug.d.cts +126 -0
- package/dist/debug.d.ts +126 -0
- package/dist/debug.js +21 -0
- package/dist/graphql/objects/index.d.cts +2 -5
- package/dist/graphql/objects/index.d.ts +2 -5
- package/dist/graphql/objects/index.js +2 -4
- package/dist/index.cjs +791 -474
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +32 -36
- package/dist/index.node.cjs +791 -474
- package/dist/index.node.d.cts +12 -132
- package/dist/index.node.d.ts +12 -132
- package/dist/index.node.js +31 -31
- package/dist/native/index.cjs +885 -575
- package/dist/native/index.d.cts +419 -335
- package/dist/native/index.d.ts +419 -335
- package/dist/native/index.js +857 -550
- package/dist/proto/lrc20.d.cts +1 -1
- package/dist/proto/lrc20.d.ts +1 -1
- package/dist/proto/lrc20.js +1 -1
- package/dist/proto/spark.cjs +241 -7
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark.js +5 -1
- package/dist/proto/spark_token.cjs +22 -2
- package/dist/proto/spark_token.d.cts +8 -1
- package/dist/proto/spark_token.d.ts +8 -1
- package/dist/proto/spark_token.js +2 -2
- package/dist/{sdk-types-BGCeea0G.d.ts → sdk-types-DCIVdKUT.d.ts} +1 -1
- package/dist/{sdk-types-XUeQMLFP.d.cts → sdk-types-DJ2ve9YY.d.cts} +1 -1
- package/dist/{spark-BbUrbvZz.d.ts → spark-BUOx3U7Q.d.cts} +103 -5
- package/dist/{spark-BbUrbvZz.d.cts → spark-BUOx3U7Q.d.ts} +103 -5
- package/dist/{spark-wallet-CJkQW8pK.d.ts → spark-wallet-CF8Oxjqs.d.ts} +143 -131
- package/dist/{spark-wallet-BAFPpPtY.d.cts → spark-wallet-DOLSa3oF.d.cts} +143 -131
- package/dist/tests/test-utils.cjs +7137 -5744
- package/dist/tests/test-utils.d.cts +5 -5
- package/dist/tests/test-utils.d.ts +5 -5
- package/dist/tests/test-utils.js +16 -8
- package/dist/types/index.cjs +239 -7
- package/dist/types/index.d.cts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +6 -8
- package/dist/xchain-address-C2xMs9nz.d.cts +126 -0
- package/dist/xchain-address-Ckto9oEz.d.ts +126 -0
- package/package.json +5 -1
- package/src/debug.ts +13 -0
- package/src/proto/mock.ts +76 -0
- package/src/proto/spark.ts +354 -6
- package/src/proto/spark_token.ts +34 -2
- package/src/services/coop-exit.ts +6 -3
- package/src/services/deposit.ts +9 -8
- package/src/services/lightning.ts +3 -1
- package/src/services/signing.ts +10 -6
- package/src/services/token-transactions.ts +95 -80
- package/src/services/transfer.ts +88 -60
- package/src/services/tree-creation.ts +17 -9
- package/src/signer/signer.react-native.ts +3 -5
- package/src/signer/signer.ts +153 -297
- package/src/signer/types.ts +18 -7
- package/src/spark-wallet/spark-wallet.ts +170 -136
- package/src/spark-wallet/types.ts +18 -4
- package/src/tests/integration/adaptor-signature.test.ts +8 -9
- package/src/tests/integration/coop-exit.test.ts +212 -201
- package/src/tests/integration/lightning.test.ts +126 -101
- package/src/tests/integration/swap.test.ts +115 -83
- package/src/tests/integration/transfer.test.ts +287 -210
- package/src/tests/integration/tree-creation.test.ts +0 -5
- package/src/tests/test-utils.ts +10 -4
- package/src/tests/token-identifier.test.ts +6 -6
- package/src/utils/token-identifier.ts +27 -21
- package/src/utils/token-transaction-validation.ts +34 -0
- package/src/utils/token-transactions.ts +9 -5
- package/dist/chunk-GWFQ7EBA.js +0 -3773
- package/dist/chunk-HMLOC6TE.js +0 -14
- package/ios/spark_frost.kt +0 -1900
package/src/services/transfer.ts
CHANGED
|
@@ -36,7 +36,11 @@ import {
|
|
|
36
36
|
TransferType,
|
|
37
37
|
TreeNode,
|
|
38
38
|
} from "../proto/spark.js";
|
|
39
|
-
import
|
|
39
|
+
import {
|
|
40
|
+
KeyDerivation,
|
|
41
|
+
KeyDerivationType,
|
|
42
|
+
type SigningCommitment,
|
|
43
|
+
} from "../signer/types.js";
|
|
40
44
|
import {
|
|
41
45
|
getSigHashFromTx,
|
|
42
46
|
getTxFromRawTxBytes,
|
|
@@ -65,12 +69,12 @@ function initialSequence() {
|
|
|
65
69
|
|
|
66
70
|
export type LeafKeyTweak = {
|
|
67
71
|
leaf: TreeNode;
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
keyDerivation: KeyDerivation;
|
|
73
|
+
newKeyDerivation: KeyDerivation;
|
|
70
74
|
};
|
|
71
75
|
|
|
72
76
|
export type ClaimLeafData = {
|
|
73
|
-
|
|
77
|
+
keyDerivation: KeyDerivation;
|
|
74
78
|
tx?: Transaction;
|
|
75
79
|
refundTx?: Transaction;
|
|
76
80
|
signingNonceCommitment: SigningCommitment;
|
|
@@ -78,7 +82,7 @@ export type ClaimLeafData = {
|
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
export type LeafRefundSigningData = {
|
|
81
|
-
|
|
85
|
+
keyDerivation: KeyDerivation;
|
|
82
86
|
receivingPubkey: Uint8Array;
|
|
83
87
|
tx: Transaction;
|
|
84
88
|
refundTx?: Transaction;
|
|
@@ -399,10 +403,13 @@ export class BaseTransferService {
|
|
|
399
403
|
|
|
400
404
|
const refundTxSighash = getSigHashFromTx(leafData.refundTx, 0, txOutput);
|
|
401
405
|
|
|
406
|
+
const publicKey = await this.config.signer.getPublicKeyFromDerivation(
|
|
407
|
+
leafData.keyDerivation,
|
|
408
|
+
);
|
|
402
409
|
const userSignature = await this.config.signer.signFrost({
|
|
403
410
|
message: refundTxSighash,
|
|
404
|
-
publicKey
|
|
405
|
-
|
|
411
|
+
publicKey,
|
|
412
|
+
keyDerivation: leafData.keyDerivation,
|
|
406
413
|
selfCommitment: leafData.signingNonceCommitment,
|
|
407
414
|
statechainCommitments:
|
|
408
415
|
operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
|
|
@@ -420,7 +427,7 @@ export class BaseTransferService {
|
|
|
420
427
|
statechainCommitments:
|
|
421
428
|
operatorSigningResult.refundTxSigningResult?.signingNonceCommitments,
|
|
422
429
|
selfCommitment: leafData.signingNonceCommitment,
|
|
423
|
-
publicKey
|
|
430
|
+
publicKey,
|
|
424
431
|
selfSignature: userSignature,
|
|
425
432
|
adaptorPubKey: adaptorPubKey,
|
|
426
433
|
});
|
|
@@ -476,19 +483,16 @@ export class BaseTransferService {
|
|
|
476
483
|
refundSignature?: Uint8Array,
|
|
477
484
|
): Promise<Map<string, SendLeafKeyTweak>> {
|
|
478
485
|
const signingOperators = this.config.getSigningOperators();
|
|
479
|
-
const pubKeyTweak =
|
|
480
|
-
await this.config.signer.subtractPrivateKeysGivenPublicKeys(
|
|
481
|
-
leaf.signingPubKey,
|
|
482
|
-
leaf.newSigningPubKey,
|
|
483
|
-
);
|
|
484
486
|
|
|
485
|
-
const shares
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
487
|
+
const { shares, secretCipher } =
|
|
488
|
+
await this.config.signer.subtractSplitAndEncrypt({
|
|
489
|
+
first: leaf.keyDerivation,
|
|
490
|
+
second: leaf.newKeyDerivation,
|
|
491
|
+
receiverPublicKey: receiverEciesPubKey.toBytes(),
|
|
492
|
+
curveOrder: secp256k1.CURVE.n,
|
|
493
|
+
threshold: this.config.getThreshold(),
|
|
494
|
+
numShares: Object.keys(signingOperators).length,
|
|
495
|
+
});
|
|
492
496
|
|
|
493
497
|
const pubkeySharesTweak = new Map<string, Uint8Array>();
|
|
494
498
|
for (const [identifier, operator] of Object.entries(signingOperators)) {
|
|
@@ -504,11 +508,6 @@ export class BaseTransferService {
|
|
|
504
508
|
pubkeySharesTweak.set(identifier, pubkeyTweak);
|
|
505
509
|
}
|
|
506
510
|
|
|
507
|
-
const secretCipher = await this.config.signer.encryptLeafPrivateKeyEcies(
|
|
508
|
-
receiverEciesPubKey.toBytes(),
|
|
509
|
-
leaf.newSigningPubKey,
|
|
510
|
-
);
|
|
511
|
-
|
|
512
511
|
const encoder = new TextEncoder();
|
|
513
512
|
const payload = new Uint8Array([
|
|
514
513
|
...encoder.encode(leaf.leaf.id),
|
|
@@ -814,8 +813,9 @@ export class TransferService extends BaseTransferService {
|
|
|
814
813
|
|
|
815
814
|
const tx = getTxFromRawTxBytes(leaf.leaf.nodeTx);
|
|
816
815
|
const refundTx = getTxFromRawTxBytes(leaf.leaf.refundTx);
|
|
816
|
+
|
|
817
817
|
leafDataMap.set(leaf.leaf.id, {
|
|
818
|
-
|
|
818
|
+
keyDerivation: leaf.keyDerivation,
|
|
819
819
|
receivingPubkey: receiverIdentityPubkey,
|
|
820
820
|
signingNonceCommitment,
|
|
821
821
|
tx,
|
|
@@ -824,7 +824,10 @@ export class TransferService extends BaseTransferService {
|
|
|
824
824
|
});
|
|
825
825
|
}
|
|
826
826
|
|
|
827
|
-
const signingJobs = this.prepareRefundSoSigningJobs(
|
|
827
|
+
const signingJobs = await this.prepareRefundSoSigningJobs(
|
|
828
|
+
leaves,
|
|
829
|
+
leafDataMap,
|
|
830
|
+
);
|
|
828
831
|
|
|
829
832
|
const sparkClient = await this.connectionManager.createSparkClient(
|
|
830
833
|
this.config.getCoordinatorAddress(),
|
|
@@ -891,11 +894,11 @@ export class TransferService extends BaseTransferService {
|
|
|
891
894
|
};
|
|
892
895
|
}
|
|
893
896
|
|
|
894
|
-
private prepareRefundSoSigningJobs(
|
|
897
|
+
private async prepareRefundSoSigningJobs(
|
|
895
898
|
leaves: LeafKeyTweak[],
|
|
896
899
|
leafDataMap: Map<string, LeafRefundSigningData>,
|
|
897
900
|
isForClaim?: boolean,
|
|
898
|
-
): LeafRefundTxSigningJob[] {
|
|
901
|
+
): Promise<LeafRefundTxSigningJob[]> {
|
|
899
902
|
const signingJobs: LeafRefundTxSigningJob[] = [];
|
|
900
903
|
for (const leaf of leaves) {
|
|
901
904
|
const refundSigningData = leafDataMap.get(leaf.leaf.id);
|
|
@@ -936,7 +939,9 @@ export class TransferService extends BaseTransferService {
|
|
|
936
939
|
signingJobs.push({
|
|
937
940
|
leafId: leaf.leaf.id,
|
|
938
941
|
refundTxSigningJob: {
|
|
939
|
-
signingPublicKey:
|
|
942
|
+
signingPublicKey: await this.config.signer.getPublicKeyFromDerivation(
|
|
943
|
+
refundSigningData.keyDerivation,
|
|
944
|
+
),
|
|
940
945
|
rawTx: refundTx.toBytes(),
|
|
941
946
|
signingNonceCommitment: refundNonceCommitmentProto,
|
|
942
947
|
},
|
|
@@ -1042,20 +1047,17 @@ export class TransferService extends BaseTransferService {
|
|
|
1042
1047
|
}> {
|
|
1043
1048
|
const signingOperators = this.config.getSigningOperators();
|
|
1044
1049
|
|
|
1045
|
-
const
|
|
1046
|
-
await this.config.signer.
|
|
1047
|
-
|
|
1048
|
-
|
|
1050
|
+
const shares =
|
|
1051
|
+
await this.config.signer.subtractAndSplitSecretWithProofsGivenDerivations(
|
|
1052
|
+
{
|
|
1053
|
+
first: leaf.keyDerivation,
|
|
1054
|
+
second: leaf.newKeyDerivation,
|
|
1055
|
+
curveOrder: secp256k1.CURVE.n,
|
|
1056
|
+
threshold: this.config.getThreshold(),
|
|
1057
|
+
numShares: Object.keys(signingOperators).length,
|
|
1058
|
+
},
|
|
1049
1059
|
);
|
|
1050
1060
|
|
|
1051
|
-
const shares = await this.config.signer.splitSecretWithProofs({
|
|
1052
|
-
secret: pubKeyTweak,
|
|
1053
|
-
curveOrder: secp256k1.CURVE.n,
|
|
1054
|
-
threshold: this.config.getThreshold(),
|
|
1055
|
-
numShares: Object.keys(signingOperators).length,
|
|
1056
|
-
isSecretPubkey: true,
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
1061
|
const pubkeySharesTweak = new Map<string, Uint8Array>();
|
|
1060
1062
|
|
|
1061
1063
|
for (const [identifier, operator] of Object.entries(signingOperators)) {
|
|
@@ -1105,8 +1107,10 @@ export class TransferService extends BaseTransferService {
|
|
|
1105
1107
|
for (const leafKey of leafKeys) {
|
|
1106
1108
|
const tx = getTxFromRawTxBytes(leafKey.leaf.nodeTx);
|
|
1107
1109
|
leafDataMap.set(leafKey.leaf.id, {
|
|
1108
|
-
|
|
1109
|
-
receivingPubkey:
|
|
1110
|
+
keyDerivation: leafKey.newKeyDerivation,
|
|
1111
|
+
receivingPubkey: await this.config.signer.getPublicKeyFromDerivation(
|
|
1112
|
+
leafKey.newKeyDerivation,
|
|
1113
|
+
),
|
|
1110
1114
|
signingNonceCommitment:
|
|
1111
1115
|
await this.config.signer.getRandomSigningCommitment(),
|
|
1112
1116
|
tx,
|
|
@@ -1114,7 +1118,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1114
1118
|
});
|
|
1115
1119
|
}
|
|
1116
1120
|
|
|
1117
|
-
const signingJobs = this.prepareRefundSoSigningJobs(
|
|
1121
|
+
const signingJobs = await this.prepareRefundSoSigningJobs(
|
|
1118
1122
|
leafKeys,
|
|
1119
1123
|
leafDataMap,
|
|
1120
1124
|
true,
|
|
@@ -1203,11 +1207,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1203
1207
|
}
|
|
1204
1208
|
}
|
|
1205
1209
|
|
|
1206
|
-
async refreshTimelockNodes(
|
|
1207
|
-
nodes: TreeNode[],
|
|
1208
|
-
parentNode: TreeNode,
|
|
1209
|
-
signingPubKey: Uint8Array,
|
|
1210
|
-
) {
|
|
1210
|
+
async refreshTimelockNodes(nodes: TreeNode[], parentNode: TreeNode) {
|
|
1211
1211
|
if (nodes.length === 0) {
|
|
1212
1212
|
throw Error("no nodes to refresh");
|
|
1213
1213
|
}
|
|
@@ -1264,7 +1264,10 @@ export class TransferService extends BaseTransferService {
|
|
|
1264
1264
|
}
|
|
1265
1265
|
|
|
1266
1266
|
signingJobs.push({
|
|
1267
|
-
signingPublicKey:
|
|
1267
|
+
signingPublicKey: await this.config.signer.getPublicKeyFromDerivation({
|
|
1268
|
+
type: KeyDerivationType.LEAF,
|
|
1269
|
+
path: node.id,
|
|
1270
|
+
}),
|
|
1268
1271
|
rawTx: newTx.toBytes(),
|
|
1269
1272
|
signingNonceCommitment:
|
|
1270
1273
|
await this.config.signer.getRandomSigningCommitment(),
|
|
@@ -1316,7 +1319,10 @@ export class TransferService extends BaseTransferService {
|
|
|
1316
1319
|
});
|
|
1317
1320
|
|
|
1318
1321
|
const refundSigningJob = {
|
|
1319
|
-
signingPublicKey:
|
|
1322
|
+
signingPublicKey: await this.config.signer.getPublicKeyFromDerivation({
|
|
1323
|
+
type: KeyDerivationType.LEAF,
|
|
1324
|
+
path: leaf.id,
|
|
1325
|
+
}),
|
|
1320
1326
|
rawTx: newRefundTx.toBytes(),
|
|
1321
1327
|
signingNonceCommitment:
|
|
1322
1328
|
await this.config.signer.getRandomSigningCommitment(),
|
|
@@ -1384,8 +1390,11 @@ export class TransferService extends BaseTransferService {
|
|
|
1384
1390
|
|
|
1385
1391
|
const userSignature = await this.config.signer.signFrost({
|
|
1386
1392
|
message: rawTxSighash,
|
|
1387
|
-
|
|
1388
|
-
|
|
1393
|
+
keyDerivation: {
|
|
1394
|
+
type: KeyDerivationType.LEAF,
|
|
1395
|
+
path: nodeId,
|
|
1396
|
+
},
|
|
1397
|
+
publicKey: signingJob.signingPublicKey,
|
|
1389
1398
|
verifyingKey: signingResult.verifyingKey,
|
|
1390
1399
|
selfCommitment: signingJob.signingNonceCommitment,
|
|
1391
1400
|
statechainCommitments:
|
|
@@ -1401,7 +1410,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1401
1410
|
statechainCommitments:
|
|
1402
1411
|
signingResult.signingResult?.signingNonceCommitments,
|
|
1403
1412
|
selfCommitment: signingJob.signingNonceCommitment,
|
|
1404
|
-
publicKey:
|
|
1413
|
+
publicKey: signingJob.signingPublicKey,
|
|
1405
1414
|
selfSignature: userSignature,
|
|
1406
1415
|
adaptorPubKey: new Uint8Array(),
|
|
1407
1416
|
});
|
|
@@ -1446,7 +1455,7 @@ export class TransferService extends BaseTransferService {
|
|
|
1446
1455
|
return result;
|
|
1447
1456
|
}
|
|
1448
1457
|
|
|
1449
|
-
async extendTimelock(node: TreeNode
|
|
1458
|
+
async extendTimelock(node: TreeNode) {
|
|
1450
1459
|
const nodeTx = getTxFromRawTxBytes(node.nodeTx);
|
|
1451
1460
|
const refundTx = getTxFromRawTxBytes(node.refundTx);
|
|
1452
1461
|
|
|
@@ -1488,6 +1497,11 @@ export class TransferService extends BaseTransferService {
|
|
|
1488
1497
|
throw new Error("Amount not found in extendTimelock");
|
|
1489
1498
|
}
|
|
1490
1499
|
|
|
1500
|
+
const signingPubKey = await this.config.signer.getPublicKeyFromDerivation({
|
|
1501
|
+
type: KeyDerivationType.LEAF,
|
|
1502
|
+
path: node.id,
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1491
1505
|
// Apply fee to the refund transaction as well
|
|
1492
1506
|
// const feeReducedRefundAmount = maybeApplyFee(amountSats);
|
|
1493
1507
|
const newRefundTx = createRefundTx(
|
|
@@ -1536,7 +1550,10 @@ export class TransferService extends BaseTransferService {
|
|
|
1536
1550
|
|
|
1537
1551
|
const nodeUserSig = await this.config.signer.signFrost({
|
|
1538
1552
|
message: nodeSighash,
|
|
1539
|
-
|
|
1553
|
+
keyDerivation: {
|
|
1554
|
+
type: KeyDerivationType.LEAF,
|
|
1555
|
+
path: node.id,
|
|
1556
|
+
},
|
|
1540
1557
|
publicKey: signingPubKey,
|
|
1541
1558
|
verifyingKey: response.nodeTxSigningResult.verifyingKey,
|
|
1542
1559
|
selfCommitment: newNodeSigningJob.signingNonceCommitment,
|
|
@@ -1547,7 +1564,10 @@ export class TransferService extends BaseTransferService {
|
|
|
1547
1564
|
|
|
1548
1565
|
const refundUserSig = await this.config.signer.signFrost({
|
|
1549
1566
|
message: refundSighash,
|
|
1550
|
-
|
|
1567
|
+
keyDerivation: {
|
|
1568
|
+
type: KeyDerivationType.LEAF,
|
|
1569
|
+
path: node.id,
|
|
1570
|
+
},
|
|
1551
1571
|
publicKey: signingPubKey,
|
|
1552
1572
|
verifyingKey: response.refundTxSigningResult.verifyingKey,
|
|
1553
1573
|
selfCommitment: newRefundSigningJob.signingNonceCommitment,
|
|
@@ -1598,13 +1618,18 @@ export class TransferService extends BaseTransferService {
|
|
|
1598
1618
|
});
|
|
1599
1619
|
}
|
|
1600
1620
|
|
|
1601
|
-
async refreshTimelockRefundTx(node: TreeNode
|
|
1621
|
+
async refreshTimelockRefundTx(node: TreeNode) {
|
|
1602
1622
|
const nodeTx = getTxFromRawTxBytes(node.nodeTx);
|
|
1603
1623
|
const refundTx = getTxFromRawTxBytes(node.refundTx);
|
|
1604
1624
|
|
|
1605
1625
|
const currSequence = refundTx.getInput(0).sequence || 0;
|
|
1606
1626
|
const { nextSequence } = getNextTransactionSequence(currSequence);
|
|
1607
1627
|
|
|
1628
|
+
const signingPubKey = await this.config.signer.getPublicKeyFromDerivation({
|
|
1629
|
+
type: KeyDerivationType.LEAF,
|
|
1630
|
+
path: node.id,
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1608
1633
|
const newRefundTx = new Transaction({
|
|
1609
1634
|
version: 3,
|
|
1610
1635
|
allowUnknownOutputs: true,
|
|
@@ -1674,7 +1699,10 @@ export class TransferService extends BaseTransferService {
|
|
|
1674
1699
|
|
|
1675
1700
|
const userSignature = await this.config.signer.signFrost({
|
|
1676
1701
|
message: rawTxSighash,
|
|
1677
|
-
|
|
1702
|
+
keyDerivation: {
|
|
1703
|
+
type: KeyDerivationType.LEAF,
|
|
1704
|
+
path: node.id,
|
|
1705
|
+
},
|
|
1678
1706
|
publicKey: signingPubKey,
|
|
1679
1707
|
verifyingKey: signingResult.verifyingKey,
|
|
1680
1708
|
selfCommitment: refundSigningJob.signingNonceCommitment,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { hexToBytes } from "@noble/curves/abstract/utils";
|
|
2
|
-
import { sha256 } from "@noble/hashes/sha2";
|
|
3
2
|
import { Address, OutScript, Transaction } from "@scure/btc-signer";
|
|
4
3
|
import { NetworkError, ValidationError } from "../errors/index.js";
|
|
5
4
|
import {
|
|
@@ -16,7 +15,7 @@ import {
|
|
|
16
15
|
SigningJob,
|
|
17
16
|
TreeNode,
|
|
18
17
|
} from "../proto/spark.js";
|
|
19
|
-
import { SigningCommitment } from "../signer/types.js";
|
|
18
|
+
import { KeyDerivationType, SigningCommitment } from "../signer/types.js";
|
|
20
19
|
import {
|
|
21
20
|
getP2TRAddressFromPublicKey,
|
|
22
21
|
getSigHashFromTx,
|
|
@@ -245,16 +244,19 @@ export class TreeCreationService {
|
|
|
245
244
|
targetSigningPublicKey: Uint8Array,
|
|
246
245
|
nodeId: string,
|
|
247
246
|
): Promise<DepositAddressTree[]> {
|
|
248
|
-
|
|
247
|
+
// TODO: If we decide to reimplement tree-creation into the SDK
|
|
248
|
+
// this needs to be updated to use the new derivation path based signing
|
|
249
249
|
const leftNode: DepositAddressTree = {
|
|
250
|
-
signingPublicKey: leftKey,
|
|
250
|
+
// signingPublicKey: leftKey,
|
|
251
|
+
signingPublicKey: targetSigningPublicKey,
|
|
251
252
|
children: [],
|
|
252
253
|
};
|
|
253
254
|
|
|
254
255
|
const rightKey =
|
|
255
|
-
await this.config.signer.
|
|
256
|
-
targetSigningPublicKey,
|
|
257
|
-
|
|
256
|
+
await this.config.signer.subtractPrivateKeysGivenDerivationPaths(
|
|
257
|
+
// targetSigningPublicKey,
|
|
258
|
+
nodeId,
|
|
259
|
+
nodeId,
|
|
258
260
|
);
|
|
259
261
|
|
|
260
262
|
const rightNode: DepositAddressTree = {
|
|
@@ -528,7 +530,10 @@ export class TreeCreationService {
|
|
|
528
530
|
const userSignature = await this.config.signer.signFrost({
|
|
529
531
|
message: txSighash,
|
|
530
532
|
publicKey: creationNode.nodeTxSigningJob.signingPublicKey,
|
|
531
|
-
|
|
533
|
+
keyDerivation: {
|
|
534
|
+
type: KeyDerivationType.LEAF,
|
|
535
|
+
path: creationResponseNode.nodeId,
|
|
536
|
+
},
|
|
532
537
|
selfCommitment: creationNode.nodeTxSigningCommitment,
|
|
533
538
|
statechainCommitments:
|
|
534
539
|
creationResponseNode.nodeTxSigningResult?.signingNonceCommitments,
|
|
@@ -565,7 +570,10 @@ export class TreeCreationService {
|
|
|
565
570
|
const refundSigningResponse = await this.config.signer.signFrost({
|
|
566
571
|
message: refundTxSighash,
|
|
567
572
|
publicKey: creationNode.refundTxSigningJob.signingPublicKey,
|
|
568
|
-
|
|
573
|
+
keyDerivation: {
|
|
574
|
+
type: KeyDerivationType.LEAF,
|
|
575
|
+
path: creationResponseNode.nodeId,
|
|
576
|
+
},
|
|
569
577
|
selfCommitment: creationNode.refundTxSigningCommitment,
|
|
570
578
|
statechainCommitments:
|
|
571
579
|
creationResponseNode.refundTxSigningResult?.signingNonceCommitments,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
|
2
1
|
import { ValidationError } from "../errors/index.js";
|
|
3
2
|
import { NativeSparkFrost } from "../spark_bindings/native/index.js";
|
|
4
3
|
import { IKeyPackage } from "../spark_bindings/types.js";
|
|
@@ -8,16 +7,15 @@ import type { AggregateFrostParams, SignFrostParams } from "./types.js";
|
|
|
8
7
|
export class ReactNativeSparkSigner extends DefaultSparkSigner {
|
|
9
8
|
async signFrost({
|
|
10
9
|
message,
|
|
11
|
-
|
|
10
|
+
keyDerivation,
|
|
12
11
|
publicKey,
|
|
13
12
|
verifyingKey,
|
|
14
13
|
selfCommitment,
|
|
15
14
|
statechainCommitments,
|
|
16
15
|
adaptorPubKey,
|
|
17
16
|
}: SignFrostParams): Promise<Uint8Array> {
|
|
18
|
-
const privateAsPubKeyHex = bytesToHex(privateAsPubKey);
|
|
19
17
|
const signingPrivateKey =
|
|
20
|
-
this.
|
|
18
|
+
await this.getSigningPrivateKeyFromDerivation(keyDerivation);
|
|
21
19
|
|
|
22
20
|
if (!signingPrivateKey) {
|
|
23
21
|
throw new ValidationError("Private key not found for public key", {
|
|
@@ -33,7 +31,7 @@ export class ReactNativeSparkSigner extends DefaultSparkSigner {
|
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
const keyPackage: IKeyPackage = {
|
|
36
|
-
secretKey:
|
|
34
|
+
secretKey: signingPrivateKey,
|
|
37
35
|
publicKey: publicKey,
|
|
38
36
|
verifyingKey: verifyingKey,
|
|
39
37
|
};
|