@arkade-os/sdk 0.3.1-alpha.1 → 0.3.1-alpha.2

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.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.aggregateKeys = exports.sign = exports.PartialSig = exports.generateNonces = void 0;
3
+ exports.aggregateKeys = exports.sign = exports.PartialSig = exports.aggregateNonces = exports.generateNonces = void 0;
4
4
  var nonces_1 = require("./nonces");
5
5
  Object.defineProperty(exports, "generateNonces", { enumerable: true, get: function () { return nonces_1.generateNonces; } });
6
+ Object.defineProperty(exports, "aggregateNonces", { enumerable: true, get: function () { return nonces_1.aggregateNonces; } });
6
7
  var sign_1 = require("./sign");
7
8
  Object.defineProperty(exports, "PartialSig", { enumerable: true, get: function () { return sign_1.PartialSig; } });
8
9
  Object.defineProperty(exports, "sign", { enumerable: true, get: function () { return sign_1.sign; } });
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateNonces = generateNonces;
37
+ exports.aggregateNonces = aggregateNonces;
37
38
  const musig = __importStar(require("@scure/btc-signer/musig2.js"));
38
39
  /**
39
40
  * Generates a pair of public and secret nonces for MuSig2 signing
@@ -42,3 +43,6 @@ function generateNonces(publicKey) {
42
43
  const nonces = musig.nonceGen(publicKey);
43
44
  return { secNonce: nonces.secret, pubNonce: nonces.public };
44
45
  }
46
+ function aggregateNonces(pubNonces) {
47
+ return musig.nonceAggregate(pubNonces);
48
+ }
@@ -11,7 +11,7 @@ var SettlementEventType;
11
11
  SettlementEventType["BatchFinalized"] = "batch_finalized";
12
12
  SettlementEventType["BatchFailed"] = "batch_failed";
13
13
  SettlementEventType["TreeSigningStarted"] = "tree_signing_started";
14
- SettlementEventType["TreeNoncesAggregated"] = "tree_nonces_aggregated";
14
+ SettlementEventType["TreeNonces"] = "tree_nonces";
15
15
  SettlementEventType["TreeTx"] = "tree_tx";
16
16
  SettlementEventType["TreeSignature"] = "tree_signature";
17
17
  })(SettlementEventType || (exports.SettlementEventType = SettlementEventType = {}));
@@ -390,10 +390,16 @@ class RestArkProvider {
390
390
  }
391
391
  // Check for TreeNoncesAggregated event
392
392
  if (data.treeNoncesAggregated) {
393
+ // skip treeNoncesAggregated event, deprecated
394
+ return null;
395
+ }
396
+ if (data.treeNonces) {
393
397
  return {
394
- type: SettlementEventType.TreeNoncesAggregated,
395
- id: data.treeNoncesAggregated.id,
396
- treeNonces: decodeMusig2Nonces(data.treeNoncesAggregated.treeNonces),
398
+ type: SettlementEventType.TreeNonces,
399
+ id: data.treeNonces.id,
400
+ topic: data.treeNonces.topic,
401
+ txid: data.treeNonces.txid,
402
+ nonces: decodeMusig2Nonces(data.treeNonces.nonces), // pubkey -> public nonce
397
403
  };
398
404
  }
399
405
  // Check for TreeTx event
@@ -423,10 +429,6 @@ class RestArkProvider {
423
429
  signature: data.treeSignature.signature,
424
430
  };
425
431
  }
426
- // TODO: Handle TreeNoncesEvent when implemented server-side
427
- if (data.treeNonces) {
428
- return null;
429
- }
430
432
  // Skip heartbeat events
431
433
  if (data.heartbeat) {
432
434
  return null;
@@ -77,10 +77,44 @@ class TreeSignerSession {
77
77
  }
78
78
  return publicNonces;
79
79
  }
80
- async setAggregatedNonces(nonces) {
81
- if (this.aggregateNonces)
82
- throw new Error("nonces already set");
83
- this.aggregateNonces = nonces;
80
+ async aggregatedNonces(txid, noncesByPubkey) {
81
+ if (!this.graph)
82
+ throw exports.ErrMissingVtxoGraph;
83
+ if (!this.aggregateNonces) {
84
+ this.aggregateNonces = new Map();
85
+ }
86
+ if (!this.myNonces) {
87
+ await this.getNonces(); // generate nonces if not generated yet
88
+ }
89
+ if (this.aggregateNonces.has(txid)) {
90
+ return {
91
+ hasAllNonces: this.aggregateNonces.size === this.myNonces?.size,
92
+ };
93
+ }
94
+ const myNonce = this.myNonces.get(txid);
95
+ if (!myNonce)
96
+ throw new Error(`missing nonce for txid ${txid}`);
97
+ const myPublicKey = await this.getPublicKey();
98
+ // set my nonce to not rely on server
99
+ noncesByPubkey.set(base_1.hex.encode(myPublicKey.subarray(1)), myNonce);
100
+ const tx = this.graph.find(txid);
101
+ if (!tx)
102
+ throw new Error(`missing tx for txid ${txid}`);
103
+ const cosigners = (0, unknownFields_1.getArkPsbtFields)(tx.root, 0, unknownFields_1.CosignerPublicKey).map((c) => base_1.hex.encode(c.key.subarray(1)) // xonly pubkey
104
+ );
105
+ const pubNonces = [];
106
+ for (const cosigner of cosigners) {
107
+ const nonce = noncesByPubkey.get(cosigner);
108
+ if (!nonce) {
109
+ throw new Error(`missing nonce for cosigner ${cosigner}`);
110
+ }
111
+ pubNonces.push(nonce.pubNonce);
112
+ }
113
+ const aggregateNonce = musig2.aggregateNonces(pubNonces);
114
+ this.aggregateNonces.set(txid, { pubNonce: aggregateNonce });
115
+ return {
116
+ hasAllNonces: this.aggregateNonces.size === this.myNonces?.size,
117
+ };
84
118
  }
85
119
  async sign() {
86
120
  if (!this.graph)
@@ -51,9 +51,9 @@ var ArkPsbtFieldKey;
51
51
  })(ArkPsbtFieldKey || (exports.ArkPsbtFieldKey = ArkPsbtFieldKey = {}));
52
52
  /**
53
53
  * ArkPsbtFieldKeyType is the type of the ark psbt field key.
54
- * Every ark psbt field has key type 255.
54
+ * Every ark psbt field has key type 222.
55
55
  */
56
- exports.ArkPsbtFieldKeyType = 255;
56
+ exports.ArkPsbtFieldKeyType = 222;
57
57
  /**
58
58
  * setArkPsbtField appends a new unknown field to the input at inputIndex
59
59
  *
@@ -546,13 +546,13 @@ class Wallet {
546
546
  if (!hasOffchainOutputs) {
547
547
  // if there are no offchain outputs, we don't have to handle musig2 tree signatures
548
548
  // we can directly advance to the finalization step
549
- step = ark_1.SettlementEventType.TreeNoncesAggregated;
549
+ step = ark_1.SettlementEventType.TreeNonces;
550
550
  }
551
551
  }
552
552
  break;
553
553
  case ark_1.SettlementEventType.TreeTx:
554
554
  if (step !== ark_1.SettlementEventType.BatchStarted &&
555
- step !== ark_1.SettlementEventType.TreeNoncesAggregated) {
555
+ step !== ark_1.SettlementEventType.TreeNonces) {
556
556
  continue;
557
557
  }
558
558
  // index 0 = vtxo tree
@@ -568,7 +568,7 @@ class Wallet {
568
568
  }
569
569
  break;
570
570
  case ark_1.SettlementEventType.TreeSignature:
571
- if (step !== ark_1.SettlementEventType.TreeNoncesAggregated) {
571
+ if (step !== ark_1.SettlementEventType.TreeNonces) {
572
572
  continue;
573
573
  }
574
574
  if (!hasOffchainOutputs) {
@@ -610,7 +610,7 @@ class Wallet {
610
610
  break;
611
611
  // the musig2 nonces of the vtxo tree transactions are generated
612
612
  // the server expects now the partial musig2 signatures
613
- case ark_1.SettlementEventType.TreeNoncesAggregated:
613
+ case ark_1.SettlementEventType.TreeNonces:
614
614
  if (step !== ark_1.SettlementEventType.TreeSigningStarted) {
615
615
  continue;
616
616
  }
@@ -618,14 +618,18 @@ class Wallet {
618
618
  if (!session) {
619
619
  throw new Error("Signing session not set");
620
620
  }
621
- await this.handleSettlementSigningNoncesGeneratedEvent(event, session);
621
+ const signed = await this.handleSettlementTreeNoncesEvent(event, session);
622
+ if (signed) {
623
+ step = event.type;
624
+ }
625
+ break;
622
626
  }
623
627
  step = event.type;
624
628
  break;
625
629
  // the vtxo tree is signed, craft, sign and submit forfeit transactions
626
630
  // if any boarding utxos are involved, the settlement tx is also signed
627
631
  case ark_1.SettlementEventType.BatchFinalization:
628
- if (step !== ark_1.SettlementEventType.TreeNoncesAggregated) {
632
+ if (step !== ark_1.SettlementEventType.TreeNonces) {
629
633
  continue;
630
634
  }
631
635
  if (!this.forfeitOutputScript) {
@@ -771,11 +775,15 @@ class Wallet {
771
775
  const nonces = await session.getNonces();
772
776
  await this.arkProvider.submitTreeNonces(event.id, pubkey, nonces);
773
777
  }
774
- async handleSettlementSigningNoncesGeneratedEvent(event, session) {
775
- session.setAggregatedNonces(event.treeNonces);
778
+ async handleSettlementTreeNoncesEvent(event, session) {
779
+ const { hasAllNonces } = await session.aggregatedNonces(event.txid, event.nonces);
780
+ // wait to receive and aggregate all nonces before sending signatures
781
+ if (!hasAllNonces)
782
+ return false;
776
783
  const signatures = await session.sign();
777
784
  const pubkey = base_1.hex.encode(await session.getPublicKey());
778
785
  await this.arkProvider.submitTreeSignatures(event.id, pubkey, signatures);
786
+ return true;
779
787
  }
780
788
  async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, connectorsGraph) {
781
789
  // the signed forfeits transactions to submit
@@ -1,3 +1,3 @@
1
- export { generateNonces } from './nonces.js';
1
+ export { generateNonces, aggregateNonces } from './nonces.js';
2
2
  export { PartialSig, sign } from './sign.js';
3
3
  export { aggregateKeys } from './keys.js';
@@ -6,3 +6,6 @@ export function generateNonces(publicKey) {
6
6
  const nonces = musig.nonceGen(publicKey);
7
7
  return { secNonce: nonces.secret, pubNonce: nonces.public };
8
8
  }
9
+ export function aggregateNonces(pubNonces) {
10
+ return musig.nonceAggregate(pubNonces);
11
+ }
@@ -7,7 +7,7 @@ export var SettlementEventType;
7
7
  SettlementEventType["BatchFinalized"] = "batch_finalized";
8
8
  SettlementEventType["BatchFailed"] = "batch_failed";
9
9
  SettlementEventType["TreeSigningStarted"] = "tree_signing_started";
10
- SettlementEventType["TreeNoncesAggregated"] = "tree_nonces_aggregated";
10
+ SettlementEventType["TreeNonces"] = "tree_nonces";
11
11
  SettlementEventType["TreeTx"] = "tree_tx";
12
12
  SettlementEventType["TreeSignature"] = "tree_signature";
13
13
  })(SettlementEventType || (SettlementEventType = {}));
@@ -386,10 +386,16 @@ export class RestArkProvider {
386
386
  }
387
387
  // Check for TreeNoncesAggregated event
388
388
  if (data.treeNoncesAggregated) {
389
+ // skip treeNoncesAggregated event, deprecated
390
+ return null;
391
+ }
392
+ if (data.treeNonces) {
389
393
  return {
390
- type: SettlementEventType.TreeNoncesAggregated,
391
- id: data.treeNoncesAggregated.id,
392
- treeNonces: decodeMusig2Nonces(data.treeNoncesAggregated.treeNonces),
394
+ type: SettlementEventType.TreeNonces,
395
+ id: data.treeNonces.id,
396
+ topic: data.treeNonces.topic,
397
+ txid: data.treeNonces.txid,
398
+ nonces: decodeMusig2Nonces(data.treeNonces.nonces), // pubkey -> public nonce
393
399
  };
394
400
  }
395
401
  // Check for TreeTx event
@@ -419,10 +425,6 @@ export class RestArkProvider {
419
425
  signature: data.treeSignature.signature,
420
426
  };
421
427
  }
422
- // TODO: Handle TreeNoncesEvent when implemented server-side
423
- if (data.treeNonces) {
424
- return null;
425
- }
426
428
  // Skip heartbeat events
427
429
  if (data.heartbeat) {
428
430
  return null;
@@ -40,10 +40,44 @@ export class TreeSignerSession {
40
40
  }
41
41
  return publicNonces;
42
42
  }
43
- async setAggregatedNonces(nonces) {
44
- if (this.aggregateNonces)
45
- throw new Error("nonces already set");
46
- this.aggregateNonces = nonces;
43
+ async aggregatedNonces(txid, noncesByPubkey) {
44
+ if (!this.graph)
45
+ throw ErrMissingVtxoGraph;
46
+ if (!this.aggregateNonces) {
47
+ this.aggregateNonces = new Map();
48
+ }
49
+ if (!this.myNonces) {
50
+ await this.getNonces(); // generate nonces if not generated yet
51
+ }
52
+ if (this.aggregateNonces.has(txid)) {
53
+ return {
54
+ hasAllNonces: this.aggregateNonces.size === this.myNonces?.size,
55
+ };
56
+ }
57
+ const myNonce = this.myNonces.get(txid);
58
+ if (!myNonce)
59
+ throw new Error(`missing nonce for txid ${txid}`);
60
+ const myPublicKey = await this.getPublicKey();
61
+ // set my nonce to not rely on server
62
+ noncesByPubkey.set(hex.encode(myPublicKey.subarray(1)), myNonce);
63
+ const tx = this.graph.find(txid);
64
+ if (!tx)
65
+ throw new Error(`missing tx for txid ${txid}`);
66
+ const cosigners = getArkPsbtFields(tx.root, 0, CosignerPublicKey).map((c) => hex.encode(c.key.subarray(1)) // xonly pubkey
67
+ );
68
+ const pubNonces = [];
69
+ for (const cosigner of cosigners) {
70
+ const nonce = noncesByPubkey.get(cosigner);
71
+ if (!nonce) {
72
+ throw new Error(`missing nonce for cosigner ${cosigner}`);
73
+ }
74
+ pubNonces.push(nonce.pubNonce);
75
+ }
76
+ const aggregateNonce = musig2.aggregateNonces(pubNonces);
77
+ this.aggregateNonces.set(txid, { pubNonce: aggregateNonce });
78
+ return {
79
+ hasAllNonces: this.aggregateNonces.size === this.myNonces?.size,
80
+ };
47
81
  }
48
82
  async sign() {
49
83
  if (!this.graph)
@@ -13,9 +13,9 @@ export var ArkPsbtFieldKey;
13
13
  })(ArkPsbtFieldKey || (ArkPsbtFieldKey = {}));
14
14
  /**
15
15
  * ArkPsbtFieldKeyType is the type of the ark psbt field key.
16
- * Every ark psbt field has key type 255.
16
+ * Every ark psbt field has key type 222.
17
17
  */
18
- export const ArkPsbtFieldKeyType = 255;
18
+ export const ArkPsbtFieldKeyType = 222;
19
19
  /**
20
20
  * setArkPsbtField appends a new unknown field to the input at inputIndex
21
21
  *
@@ -509,13 +509,13 @@ export class Wallet {
509
509
  if (!hasOffchainOutputs) {
510
510
  // if there are no offchain outputs, we don't have to handle musig2 tree signatures
511
511
  // we can directly advance to the finalization step
512
- step = SettlementEventType.TreeNoncesAggregated;
512
+ step = SettlementEventType.TreeNonces;
513
513
  }
514
514
  }
515
515
  break;
516
516
  case SettlementEventType.TreeTx:
517
517
  if (step !== SettlementEventType.BatchStarted &&
518
- step !== SettlementEventType.TreeNoncesAggregated) {
518
+ step !== SettlementEventType.TreeNonces) {
519
519
  continue;
520
520
  }
521
521
  // index 0 = vtxo tree
@@ -531,7 +531,7 @@ export class Wallet {
531
531
  }
532
532
  break;
533
533
  case SettlementEventType.TreeSignature:
534
- if (step !== SettlementEventType.TreeNoncesAggregated) {
534
+ if (step !== SettlementEventType.TreeNonces) {
535
535
  continue;
536
536
  }
537
537
  if (!hasOffchainOutputs) {
@@ -573,7 +573,7 @@ export class Wallet {
573
573
  break;
574
574
  // the musig2 nonces of the vtxo tree transactions are generated
575
575
  // the server expects now the partial musig2 signatures
576
- case SettlementEventType.TreeNoncesAggregated:
576
+ case SettlementEventType.TreeNonces:
577
577
  if (step !== SettlementEventType.TreeSigningStarted) {
578
578
  continue;
579
579
  }
@@ -581,14 +581,18 @@ export class Wallet {
581
581
  if (!session) {
582
582
  throw new Error("Signing session not set");
583
583
  }
584
- await this.handleSettlementSigningNoncesGeneratedEvent(event, session);
584
+ const signed = await this.handleSettlementTreeNoncesEvent(event, session);
585
+ if (signed) {
586
+ step = event.type;
587
+ }
588
+ break;
585
589
  }
586
590
  step = event.type;
587
591
  break;
588
592
  // the vtxo tree is signed, craft, sign and submit forfeit transactions
589
593
  // if any boarding utxos are involved, the settlement tx is also signed
590
594
  case SettlementEventType.BatchFinalization:
591
- if (step !== SettlementEventType.TreeNoncesAggregated) {
595
+ if (step !== SettlementEventType.TreeNonces) {
592
596
  continue;
593
597
  }
594
598
  if (!this.forfeitOutputScript) {
@@ -734,11 +738,15 @@ export class Wallet {
734
738
  const nonces = await session.getNonces();
735
739
  await this.arkProvider.submitTreeNonces(event.id, pubkey, nonces);
736
740
  }
737
- async handleSettlementSigningNoncesGeneratedEvent(event, session) {
738
- session.setAggregatedNonces(event.treeNonces);
741
+ async handleSettlementTreeNoncesEvent(event, session) {
742
+ const { hasAllNonces } = await session.aggregatedNonces(event.txid, event.nonces);
743
+ // wait to receive and aggregate all nonces before sending signatures
744
+ if (!hasAllNonces)
745
+ return false;
739
746
  const signatures = await session.sign();
740
747
  const pubkey = hex.encode(await session.getPublicKey());
741
748
  await this.arkProvider.submitTreeSignatures(event.id, pubkey, signatures);
749
+ return true;
742
750
  }
743
751
  async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, connectorsGraph) {
744
752
  // the signed forfeits transactions to submit
@@ -18,7 +18,7 @@ import { Worker } from "./wallet/serviceWorker/worker";
18
18
  import { Request } from "./wallet/serviceWorker/request";
19
19
  import { Response } from "./wallet/serviceWorker/response";
20
20
  import { ESPLORA_URL, EsploraProvider, OnchainProvider, ExplorerTransaction } from "./providers/onchain";
21
- import { RestArkProvider, ArkProvider, SettlementEvent, SettlementEventType, ArkInfo, SignedIntent, Output, TxNotification, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesAggregatedEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession } from "./providers/ark";
21
+ import { RestArkProvider, ArkProvider, SettlementEvent, SettlementEventType, ArkInfo, SignedIntent, Output, TxNotification, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession } from "./providers/ark";
22
22
  import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, decodeTapscript, MultisigTapscript, TapscriptType, ArkTapscript, RelativeTimelock } from "./script/tapscript";
23
23
  import { hasBoardingTxExpired, buildOffchainTx, verifyTapscriptSignatures, ArkTxInput, OffchainTx } from "./utils/arkTransaction";
24
24
  import { VtxoTaprootTree, ConditionWitness, getArkPsbtFields, setArkPsbtField, ArkPsbtFieldCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, CosignerPublicKey, VtxoTreeExpiry } from "./utils/unknownFields";
@@ -33,4 +33,4 @@ import { Unroll } from "./wallet/unroll";
33
33
  import { WalletRepositoryImpl } from "./repositories/walletRepository";
34
34
  import { ContractRepositoryImpl } from "./repositories/contractRepository";
35
35
  export { Wallet, SingleKey, OnchainWallet, Ramps, VtxoManager, ESPLORA_URL, EsploraProvider, RestArkProvider, RestIndexerProvider, ArkAddress, DefaultVtxo, VtxoScript, VHTLC, TxType, IndexerTxType, ChainTxType, SettlementEventType, setupServiceWorker, Worker, ServiceWorkerWallet, Request, Response, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness, buildOffchainTx, verifyTapscriptSignatures, waitForIncomingFunds, hasBoardingTxExpired, ArkNote, networks, WalletRepositoryImpl, ContractRepositoryImpl, Intent, TxTree, P2A, Unroll, Transaction, };
36
- export type { Identity, IWallet, WalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, IndexerProvider, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, ArkInfo, SignedIntent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesAggregatedEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, PaginationOptions, SubscriptionResponse, SubscriptionHeartbeat, SubscriptionEvent, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, };
36
+ export type { Identity, IWallet, WalletConfig, ProviderClass, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, IndexerProvider, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, ArkInfo, SignedIntent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, ScheduledSession, PaginationOptions, SubscriptionResponse, SubscriptionHeartbeat, SubscriptionEvent, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, };
@@ -1,4 +1,4 @@
1
1
  export type { Nonces } from "./nonces";
2
- export { generateNonces } from "./nonces";
2
+ export { generateNonces, aggregateNonces } from "./nonces";
3
3
  export { PartialSig, sign } from "./sign";
4
4
  export { aggregateKeys } from "./keys";
@@ -11,3 +11,4 @@ export type Nonces = {
11
11
  * Generates a pair of public and secret nonces for MuSig2 signing
12
12
  */
13
13
  export declare function generateNonces(publicKey: Uint8Array): Nonces;
14
+ export declare function aggregateNonces(pubNonces: Uint8Array[]): Uint8Array;
@@ -11,7 +11,7 @@ export declare enum SettlementEventType {
11
11
  BatchFinalized = "batch_finalized",
12
12
  BatchFailed = "batch_failed",
13
13
  TreeSigningStarted = "tree_signing_started",
14
- TreeNoncesAggregated = "tree_nonces_aggregated",
14
+ TreeNonces = "tree_nonces",
15
15
  TreeTx = "tree_tx",
16
16
  TreeSignature = "tree_signature"
17
17
  }
@@ -36,10 +36,12 @@ export type TreeSigningStartedEvent = {
36
36
  cosignersPublicKeys: string[];
37
37
  unsignedCommitmentTx: string;
38
38
  };
39
- export type TreeNoncesAggregatedEvent = {
40
- type: SettlementEventType.TreeNoncesAggregated;
39
+ export type TreeNoncesEvent = {
40
+ type: SettlementEventType.TreeNonces;
41
41
  id: string;
42
- treeNonces: TreeNonces;
42
+ topic: string[];
43
+ txid: string;
44
+ nonces: TreeNonces;
43
45
  };
44
46
  export type BatchStartedEvent = {
45
47
  type: SettlementEventType.BatchStarted;
@@ -62,7 +64,7 @@ export type TreeSignatureEvent = {
62
64
  txid: string;
63
65
  signature: string;
64
66
  };
65
- export type SettlementEvent = BatchFinalizationEvent | BatchFinalizedEvent | BatchFailedEvent | TreeSigningStartedEvent | TreeNoncesAggregatedEvent | BatchStartedEvent | TreeTxEvent | TreeSignatureEvent;
67
+ export type SettlementEvent = BatchFinalizationEvent | BatchFinalizedEvent | BatchFailedEvent | TreeSigningStartedEvent | TreeNoncesEvent | BatchStartedEvent | TreeTxEvent | TreeSignatureEvent;
66
68
  export interface ScheduledSession {
67
69
  duration: bigint;
68
70
  fees: FeeInfo;
@@ -2,13 +2,16 @@ import * as musig2 from "../musig2";
2
2
  import { TxTree } from "./txTree";
3
3
  export declare const ErrMissingVtxoGraph: Error;
4
4
  export declare const ErrMissingAggregateKey: Error;
5
- export type TreeNonces = Map<string, Pick<musig2.Nonces, "pubNonce">>;
5
+ export type Musig2PublicNonce = Pick<musig2.Nonces, "pubNonce">;
6
+ export type TreeNonces = Map<string, Musig2PublicNonce>;
6
7
  export type TreePartialSigs = Map<string, musig2.PartialSig>;
7
8
  export interface SignerSession {
8
9
  getPublicKey(): Promise<Uint8Array>;
9
10
  init(tree: TxTree, scriptRoot: Uint8Array, rootInputAmount: bigint): Promise<void>;
10
11
  getNonces(): Promise<TreeNonces>;
11
- setAggregatedNonces(nonces: TreeNonces): Promise<void>;
12
+ aggregatedNonces(txid: string, noncesByPubkey: TreeNonces): Promise<{
13
+ hasAllNonces: boolean;
14
+ }>;
12
15
  sign(): Promise<TreePartialSigs>;
13
16
  }
14
17
  export declare class TreeSignerSession implements SignerSession {
@@ -24,7 +27,9 @@ export declare class TreeSignerSession implements SignerSession {
24
27
  init(tree: TxTree, scriptRoot: Uint8Array, rootInputAmount: bigint): Promise<void>;
25
28
  getPublicKey(): Promise<Uint8Array>;
26
29
  getNonces(): Promise<TreeNonces>;
27
- setAggregatedNonces(nonces: TreeNonces): Promise<void>;
30
+ aggregatedNonces(txid: string, noncesByPubkey: TreeNonces): Promise<{
31
+ hasAllNonces: boolean;
32
+ }>;
28
33
  sign(): Promise<TreePartialSigs>;
29
34
  private generateNonces;
30
35
  private signPartial;
@@ -11,9 +11,9 @@ export declare enum ArkPsbtFieldKey {
11
11
  }
12
12
  /**
13
13
  * ArkPsbtFieldKeyType is the type of the ark psbt field key.
14
- * Every ark psbt field has key type 255.
14
+ * Every ark psbt field has key type 222.
15
15
  */
16
- export declare const ArkPsbtFieldKeyType = 255;
16
+ export declare const ArkPsbtFieldKeyType = 222;
17
17
  /**
18
18
  * ArkPsbtFieldCoder is the coder for the ark psbt fields.
19
19
  * each type has its own coder.
@@ -91,7 +91,7 @@ export declare class Wallet implements IWallet {
91
91
  notifyIncomingFunds(eventCallback: (coins: IncomingFunds) => void): Promise<() => void>;
92
92
  private handleBatchStartedEvent;
93
93
  private handleSettlementSigningEvent;
94
- private handleSettlementSigningNoncesGeneratedEvent;
94
+ private handleSettlementTreeNoncesEvent;
95
95
  private handleSettlementFinalizationEvent;
96
96
  private makeRegisterIntentSignature;
97
97
  private makeDeleteIntentSignature;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.3.1-alpha.1",
3
+ "version": "0.3.1-alpha.2",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",