@arkade-os/sdk 0.1.3 → 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.
Files changed (114) hide show
  1. package/README.md +156 -174
  2. package/dist/cjs/arknote/index.js +61 -58
  3. package/dist/cjs/bip322/errors.js +13 -0
  4. package/dist/cjs/bip322/index.js +178 -0
  5. package/dist/cjs/forfeit.js +14 -25
  6. package/dist/cjs/identity/singleKey.js +68 -0
  7. package/dist/cjs/index.js +41 -17
  8. package/dist/cjs/providers/ark.js +253 -317
  9. package/dist/cjs/providers/indexer.js +525 -0
  10. package/dist/cjs/providers/onchain.js +193 -15
  11. package/dist/cjs/script/address.js +48 -17
  12. package/dist/cjs/script/base.js +120 -3
  13. package/dist/cjs/script/default.js +18 -4
  14. package/dist/cjs/script/tapscript.js +46 -14
  15. package/dist/cjs/script/vhtlc.js +27 -7
  16. package/dist/cjs/tree/signingSession.js +63 -106
  17. package/dist/cjs/tree/txTree.js +193 -0
  18. package/dist/cjs/tree/validation.js +79 -155
  19. package/dist/cjs/utils/anchor.js +35 -0
  20. package/dist/cjs/utils/arkTransaction.js +108 -0
  21. package/dist/cjs/utils/transactionHistory.js +84 -72
  22. package/dist/cjs/utils/txSizeEstimator.js +12 -0
  23. package/dist/cjs/utils/unknownFields.js +211 -0
  24. package/dist/cjs/wallet/index.js +12 -0
  25. package/dist/cjs/wallet/onchain.js +201 -0
  26. package/dist/cjs/wallet/ramps.js +95 -0
  27. package/dist/cjs/wallet/serviceWorker/db/vtxo/idb.js +32 -0
  28. package/dist/cjs/wallet/serviceWorker/request.js +15 -12
  29. package/dist/cjs/wallet/serviceWorker/response.js +22 -27
  30. package/dist/cjs/wallet/serviceWorker/utils.js +8 -0
  31. package/dist/cjs/wallet/serviceWorker/wallet.js +58 -34
  32. package/dist/cjs/wallet/serviceWorker/worker.js +117 -108
  33. package/dist/cjs/wallet/unroll.js +270 -0
  34. package/dist/cjs/wallet/wallet.js +701 -459
  35. package/dist/esm/arknote/index.js +61 -57
  36. package/dist/esm/bip322/errors.js +9 -0
  37. package/dist/esm/bip322/index.js +174 -0
  38. package/dist/esm/forfeit.js +15 -26
  39. package/dist/esm/identity/singleKey.js +64 -0
  40. package/dist/esm/index.js +30 -12
  41. package/dist/esm/providers/ark.js +252 -317
  42. package/dist/esm/providers/indexer.js +521 -0
  43. package/dist/esm/providers/onchain.js +193 -15
  44. package/dist/esm/script/address.js +48 -17
  45. package/dist/esm/script/base.js +120 -3
  46. package/dist/esm/script/default.js +18 -4
  47. package/dist/esm/script/tapscript.js +46 -14
  48. package/dist/esm/script/vhtlc.js +27 -7
  49. package/dist/esm/tree/signingSession.js +65 -108
  50. package/dist/esm/tree/txTree.js +189 -0
  51. package/dist/esm/tree/validation.js +75 -152
  52. package/dist/esm/utils/anchor.js +31 -0
  53. package/dist/esm/utils/arkTransaction.js +105 -0
  54. package/dist/esm/utils/transactionHistory.js +84 -72
  55. package/dist/esm/utils/txSizeEstimator.js +12 -0
  56. package/dist/esm/utils/unknownFields.js +173 -0
  57. package/dist/esm/wallet/index.js +9 -0
  58. package/dist/esm/wallet/onchain.js +196 -0
  59. package/dist/esm/wallet/ramps.js +91 -0
  60. package/dist/esm/wallet/serviceWorker/db/vtxo/idb.js +32 -0
  61. package/dist/esm/wallet/serviceWorker/request.js +15 -12
  62. package/dist/esm/wallet/serviceWorker/response.js +22 -27
  63. package/dist/esm/wallet/serviceWorker/utils.js +8 -0
  64. package/dist/esm/wallet/serviceWorker/wallet.js +59 -35
  65. package/dist/esm/wallet/serviceWorker/worker.js +117 -108
  66. package/dist/esm/wallet/unroll.js +267 -0
  67. package/dist/esm/wallet/wallet.js +674 -466
  68. package/dist/types/arknote/index.d.ts +40 -13
  69. package/dist/types/bip322/errors.d.ts +6 -0
  70. package/dist/types/bip322/index.d.ts +57 -0
  71. package/dist/types/forfeit.d.ts +2 -14
  72. package/dist/types/identity/singleKey.d.ts +27 -0
  73. package/dist/types/index.d.ts +23 -12
  74. package/dist/types/providers/ark.d.ts +114 -95
  75. package/dist/types/providers/indexer.d.ts +186 -0
  76. package/dist/types/providers/onchain.d.ts +41 -11
  77. package/dist/types/script/address.d.ts +26 -2
  78. package/dist/types/script/base.d.ts +13 -3
  79. package/dist/types/script/default.d.ts +22 -0
  80. package/dist/types/script/tapscript.d.ts +61 -5
  81. package/dist/types/script/vhtlc.d.ts +27 -0
  82. package/dist/types/tree/signingSession.d.ts +5 -5
  83. package/dist/types/tree/txTree.d.ts +28 -0
  84. package/dist/types/tree/validation.d.ts +15 -22
  85. package/dist/types/utils/anchor.d.ts +19 -0
  86. package/dist/types/utils/arkTransaction.d.ts +27 -0
  87. package/dist/types/utils/transactionHistory.d.ts +7 -1
  88. package/dist/types/utils/txSizeEstimator.d.ts +3 -0
  89. package/dist/types/utils/unknownFields.d.ts +83 -0
  90. package/dist/types/wallet/index.d.ts +51 -50
  91. package/dist/types/wallet/onchain.d.ts +49 -0
  92. package/dist/types/wallet/ramps.d.ts +32 -0
  93. package/dist/types/wallet/serviceWorker/db/vtxo/idb.d.ts +2 -0
  94. package/dist/types/wallet/serviceWorker/db/vtxo/index.d.ts +2 -0
  95. package/dist/types/wallet/serviceWorker/request.d.ts +14 -16
  96. package/dist/types/wallet/serviceWorker/response.d.ts +17 -19
  97. package/dist/types/wallet/serviceWorker/utils.d.ts +8 -0
  98. package/dist/types/wallet/serviceWorker/wallet.d.ts +36 -8
  99. package/dist/types/wallet/serviceWorker/worker.d.ts +7 -3
  100. package/dist/types/wallet/unroll.d.ts +102 -0
  101. package/dist/types/wallet/wallet.d.ts +71 -26
  102. package/package.json +14 -15
  103. package/dist/cjs/identity/inMemoryKey.js +0 -40
  104. package/dist/cjs/tree/vtxoTree.js +0 -231
  105. package/dist/cjs/utils/coinselect.js +0 -73
  106. package/dist/cjs/utils/psbt.js +0 -137
  107. package/dist/esm/identity/inMemoryKey.js +0 -36
  108. package/dist/esm/tree/vtxoTree.js +0 -191
  109. package/dist/esm/utils/coinselect.js +0 -69
  110. package/dist/esm/utils/psbt.js +0 -131
  111. package/dist/types/identity/inMemoryKey.d.ts +0 -12
  112. package/dist/types/tree/vtxoTree.d.ts +0 -33
  113. package/dist/types/utils/coinselect.d.ts +0 -21
  114. package/dist/types/utils/psbt.d.ts +0 -11
@@ -1,17 +1,44 @@
1
- export declare class ArkNoteData {
2
- id: bigint;
1
+ import { TapLeafScript, VtxoScript } from "../script/base";
2
+ import { Bytes } from "@scure/btc-signer/utils";
3
+ import { ExtendedCoin, Status } from "../wallet";
4
+ /**
5
+ * ArkNotes are special virtual coins in the Ark protocol that can be created
6
+ * and spent without requiring any transactions. The server mints them, and they
7
+ * are encoded as base58 strings with a human-readable prefix. It contains a
8
+ * preimage and value.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Create an ArkNote
13
+ * const note = new ArkNote(preimage, 50000);
14
+ *
15
+ * // Encode to string
16
+ * const noteString = note.toString();
17
+ *
18
+ * // Decode from string
19
+ * const decodedNote = ArkNote.fromString(noteString);
20
+ * ```
21
+ */
22
+ export declare class ArkNote implements ExtendedCoin {
23
+ preimage: Uint8Array;
3
24
  value: number;
4
- constructor(id: bigint, value: number);
25
+ HRP: string;
26
+ static readonly DefaultHRP = "arknote";
27
+ static readonly PreimageLength = 32;
28
+ static readonly ValueLength = 4;
29
+ static readonly Length: number;
30
+ static readonly FakeOutpointIndex = 0;
31
+ readonly vtxoScript: VtxoScript;
32
+ readonly txid: string;
33
+ readonly vout = 0;
34
+ readonly forfeitTapLeafScript: TapLeafScript;
35
+ readonly intentTapLeafScript: TapLeafScript;
36
+ readonly tapTree: Bytes;
37
+ readonly status: Status;
38
+ readonly extraWitness?: Bytes[] | undefined;
39
+ constructor(preimage: Uint8Array, value: number, HRP?: string);
5
40
  encode(): Uint8Array;
6
- static decode(data: Uint8Array): ArkNoteData;
7
- }
8
- export declare class ArkNote {
9
- data: ArkNoteData;
10
- signature: Uint8Array;
11
- static readonly HRP = "arknote";
12
- constructor(data: ArkNoteData, signature: Uint8Array);
13
- encode(): Uint8Array;
14
- static decode(data: Uint8Array): ArkNote;
15
- static fromString(noteStr: string): ArkNote;
41
+ static decode(data: Uint8Array, hrp?: string): ArkNote;
42
+ static fromString(noteStr: string, hrp?: string): ArkNote;
16
43
  toString(): string;
17
44
  }
@@ -0,0 +1,6 @@
1
+ export declare class BIP322Error extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare const ErrMissingInputs: BIP322Error;
5
+ export declare const ErrMissingData: BIP322Error;
6
+ export declare const ErrMissingWitnessUtxo: BIP322Error;
@@ -0,0 +1,57 @@
1
+ import { Transaction } from "@scure/btc-signer";
2
+ import { TransactionInput, TransactionOutput } from "@scure/btc-signer/psbt";
3
+ /**
4
+ * BIP-322 signature implementation for Bitcoin message signing.
5
+ *
6
+ * BIP-322 defines a standard for signing Bitcoin messages as well as proving
7
+ * ownership of coins. This namespace provides utilities for creating and
8
+ * validating BIP-322.
9
+ *
10
+ * @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // Create a BIP-322 proof
15
+ * const proof = BIP322.create(
16
+ * "Hello Bitcoin!",
17
+ * [input],
18
+ * [output]
19
+ * );
20
+ *
21
+ * // Sign the proof
22
+ * const signedProof = await identity.sign(proof);
23
+ *
24
+ * // Extract the signature
25
+ * const signature = BIP322.signature(signedProof);
26
+ * ```
27
+ */
28
+ export declare namespace BIP322 {
29
+ type FullProof = Transaction;
30
+ type Signature = string;
31
+ /**
32
+ * Creates a new BIP-322 "full" proof of funds unsigned transaction.
33
+ *
34
+ * This function constructs a special transaction that can be signed to prove
35
+ * ownership of VTXOs and UTXOs. The proof includes the message to be
36
+ * signed and the inputs/outputs that demonstrate ownership.
37
+ *
38
+ * @param message - The BIP-322 message to be signed
39
+ * @param inputs - Array of transaction inputs to prove ownership of
40
+ * @param outputs - Optional array of transaction outputs
41
+ * @returns An unsigned BIP-322 proof transaction
42
+ */
43
+ function create(message: string, inputs: TransactionInput[], outputs?: TransactionOutput[]): FullProof;
44
+ /**
45
+ * Finalizes and extracts the FullProof transaction into a BIP-322 signature.
46
+ *
47
+ * This function takes a signed proof transaction and converts it into a
48
+ * base64-encoded signature string. If the proof's inputs have special
49
+ * spending conditions, a custom finalizer can be provided.
50
+ *
51
+ * @param signedProof - The signed BIP-322 proof transaction
52
+ * @param finalizer - Optional custom finalizer function
53
+ * @returns Base64-encoded BIP-322 signature
54
+ */
55
+ function signature(signedProof: FullProof, finalizer?: (tx: FullProof) => void): Signature;
56
+ }
57
+ export declare function craftToSpendTx(message: string, pkScript: Uint8Array): Transaction;
@@ -1,15 +1,3 @@
1
1
  import { Transaction } from "@scure/btc-signer";
2
- import { Outpoint } from "./wallet";
3
- interface ForfeitTxParams {
4
- connectorInput: Outpoint;
5
- vtxoInput: Outpoint;
6
- vtxoAmount: bigint;
7
- connectorAmount: bigint;
8
- feeAmount: bigint;
9
- vtxoPkScript: Uint8Array;
10
- connectorPkScript: Uint8Array;
11
- serverPkScript: Uint8Array;
12
- txLocktime?: number;
13
- }
14
- export declare function buildForfeitTx({ connectorInput, vtxoInput, vtxoAmount, connectorAmount, feeAmount, vtxoPkScript, connectorPkScript, serverPkScript, txLocktime, }: ForfeitTxParams): Transaction;
15
- export {};
2
+ import { TransactionInputUpdate } from "@scure/btc-signer/psbt";
3
+ export declare function buildForfeitTx(inputs: TransactionInputUpdate[], forfeitPkScript: Uint8Array, txLocktime?: number): Transaction;
@@ -0,0 +1,27 @@
1
+ import { Transaction } from "@scure/btc-signer";
2
+ import { Identity } from ".";
3
+ import { SignerSession } from "../tree/signingSession";
4
+ /**
5
+ * In-memory single key implementation for Bitcoin transaction signing.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Create from hex string
10
+ * const key = SingleKey.fromHex('your_private_key_hex');
11
+ *
12
+ * // Create from raw bytes
13
+ * const key = SingleKey.fromPrivateKey(privateKeyBytes);
14
+ *
15
+ * // Sign a transaction
16
+ * const signedTx = await key.sign(transaction);
17
+ * ```
18
+ */
19
+ export declare class SingleKey implements Identity {
20
+ private key;
21
+ private constructor();
22
+ static fromPrivateKey(privateKey: Uint8Array): SingleKey;
23
+ static fromHex(privateKeyHex: string): SingleKey;
24
+ sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
25
+ xOnlyPublicKey(): Uint8Array;
26
+ signerSession(): SignerSession;
27
+ }
@@ -1,23 +1,34 @@
1
- import { InMemoryKey } from "./identity/inMemoryKey";
1
+ import { SingleKey } from "./identity/singleKey";
2
2
  import { Identity } from "./identity";
3
3
  import { ArkAddress } from "./script/address";
4
4
  import { VHTLC } from "./script/vhtlc";
5
5
  import { DefaultVtxo } from "./script/default";
6
- import { VtxoScript } from "./script/base";
7
- import { TxType, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, VtxoTaprootAddress, AddressInfo, TapscriptInfo, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, Addresses } from "./wallet/index";
8
- import { Wallet } from "./wallet/wallet";
6
+ import { VtxoScript, EncodedVtxoScript, TapLeafScript } from "./script/base";
7
+ import { TxType, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, GetVtxosFilter, TapLeaves } from "./wallet";
8
+ import { Wallet, waitForIncomingFunds, IncomingFunds } from "./wallet/wallet";
9
+ import { TxTree, TxTreeNode } from "./tree/txTree";
10
+ import { SignerSession, TreeNonces, TreePartialSigs } from "./tree/signingSession";
11
+ import { Ramps } from "./wallet/ramps";
9
12
  import { ServiceWorkerWallet } from "./wallet/serviceWorker/wallet";
13
+ import { OnchainWallet } from "./wallet/onchain";
10
14
  import { setupServiceWorker } from "./wallet/serviceWorker/utils";
11
15
  import { Worker } from "./wallet/serviceWorker/worker";
12
16
  import { Request } from "./wallet/serviceWorker/request";
13
17
  import { Response } from "./wallet/serviceWorker/response";
14
- import { ESPLORA_URL, EsploraProvider } from "./providers/onchain";
15
- import { RestArkProvider } from "./providers/ark";
16
- import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, decodeTapscript, MultisigTapscript, TapscriptType } from "./script/tapscript";
17
- import { addConditionWitness, CONDITION_WITNESS_KEY_PREFIX, createVirtualTx } from "./utils/psbt";
18
- import { ArkNote, ArkNoteData } from "./arknote";
18
+ import { ESPLORA_URL, EsploraProvider, OnchainProvider, ExplorerTransaction } from "./providers/onchain";
19
+ import { RestArkProvider, ArkProvider, SettlementEvent, SettlementEventType, ArkInfo, Intent, Output, TxNotification, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesAggregatedEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, MarketHour } from "./providers/ark";
20
+ import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, decodeTapscript, MultisigTapscript, TapscriptType, ArkTapscript, RelativeTimelock } from "./script/tapscript";
21
+ import { buildOffchainTx, ArkTxInput, OffchainTx } from "./utils/arkTransaction";
22
+ import { VtxoTaprootTree, ConditionWitness, getArkPsbtFields, setArkPsbtField, ArkPsbtFieldCoder, ArkPsbtFieldKey, ArkPsbtFieldKeyType, CosignerPublicKey, VtxoTreeExpiry } from "./utils/unknownFields";
23
+ import { BIP322 } from "./bip322";
24
+ import { ArkNote } from "./arknote";
19
25
  import { IndexedDBVtxoRepository } from "./wallet/serviceWorker/db/vtxo/idb";
20
26
  import { VtxoRepository } from "./wallet/serviceWorker/db/vtxo";
21
- import { networks } from "./networks";
22
- export { Wallet, InMemoryKey, ESPLORA_URL, EsploraProvider, RestArkProvider, ArkAddress, DefaultVtxo, VtxoScript, VHTLC, TxType, setupServiceWorker, Worker, ServiceWorkerWallet, Request, Response, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, addConditionWitness, CONDITION_WITNESS_KEY_PREFIX, createVirtualTx, ArkNote, ArkNoteData, networks, IndexedDBVtxoRepository, };
23
- export type { Identity, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, VtxoTaprootAddress, AddressInfo, Addresses, TapscriptInfo, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, VtxoRepository, };
27
+ import { networks, Network, NetworkName } from "./networks";
28
+ import { RestIndexerProvider, IndexerProvider, IndexerTxType, ChainTxType, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, VtxoChain, Tx, Vtxo, PaginationOptions, SubscriptionResponse } from "./providers/indexer";
29
+ import { Nonces } from "./musig2/nonces";
30
+ import { PartialSig } from "./musig2/sign";
31
+ import { AnchorBumper, P2A } from "./utils/anchor";
32
+ import { Unroll } from "./wallet/unroll";
33
+ export { Wallet, SingleKey, OnchainWallet, Ramps, 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, waitForIncomingFunds, ArkNote, networks, IndexedDBVtxoRepository, BIP322, TxTree, P2A, Unroll, };
34
+ export type { Identity, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, VtxoRepository, ArkTxInput, OffchainTx, TapLeaves, IncomingFunds, IndexerProvider, PageResponse, Batch, ChainTx, CommitmentTx, TxHistoryRecord, Vtxo, VtxoChain, Tx, OnchainProvider, ArkProvider, SettlementEvent, ArkInfo, Intent, Output, TxNotification, ExplorerTransaction, BatchFinalizationEvent, BatchFinalizedEvent, BatchFailedEvent, TreeSigningStartedEvent, TreeNoncesAggregatedEvent, BatchStartedEvent, TreeTxEvent, TreeSignatureEvent, MarketHour, PaginationOptions, SubscriptionResponse, Network, NetworkName, ArkTapscript, RelativeTimelock, EncodedVtxoScript, TapLeafScript, SignerSession, TreeNonces, TreePartialSigs, GetVtxosFilter, Nonces, PartialSig, ArkPsbtFieldCoder, TxTreeNode, AnchorBumper, };
@@ -1,136 +1,155 @@
1
- import { TxTree } from "../tree/vtxoTree";
2
- import { Outpoint, VirtualCoin } from "../wallet";
1
+ import { TxTreeNode } from "../tree/txTree";
3
2
  import { TreeNonces, TreePartialSigs } from "../tree/signingSession";
4
- export interface ArkEvent {
5
- type: "vtxo_created" | "vtxo_spent" | "vtxo_swept" | "vtxo_expired";
6
- data: {
7
- txid?: string;
8
- address?: string;
9
- amount?: number;
10
- roundTxid?: string;
11
- expireAt?: number;
12
- };
13
- }
14
- export type NoteInput = string;
15
- export type VtxoInput = {
16
- outpoint: Outpoint;
17
- tapscripts: string[];
18
- };
19
- export type Input = NoteInput | VtxoInput;
3
+ import { Vtxo } from "./indexer";
20
4
  export type Output = {
21
5
  address: string;
22
6
  amount: bigint;
23
7
  };
24
8
  export declare enum SettlementEventType {
25
- Finalization = "finalization",
26
- Finalized = "finalized",
27
- Failed = "failed",
28
- SigningStart = "signing_start",
29
- SigningNoncesGenerated = "signing_nonces_generated"
9
+ BatchStarted = "batch_started",
10
+ BatchFinalization = "batch_finalization",
11
+ BatchFinalized = "batch_finalized",
12
+ BatchFailed = "batch_failed",
13
+ TreeSigningStarted = "tree_signing_started",
14
+ TreeNoncesAggregated = "tree_nonces_aggregated",
15
+ TreeTx = "tree_tx",
16
+ TreeSignature = "tree_signature"
30
17
  }
31
- export type FinalizationEvent = {
32
- type: SettlementEventType.Finalization;
18
+ export type BatchFinalizationEvent = {
19
+ type: SettlementEventType.BatchFinalization;
33
20
  id: string;
34
- roundTx: string;
35
- vtxoTree: TxTree;
36
- connectors: TxTree;
37
- minRelayFeeRate: bigint;
38
- connectorsIndex: Map<string, Outpoint>;
21
+ commitmentTx: string;
39
22
  };
40
- export type FinalizedEvent = {
41
- type: SettlementEventType.Finalized;
23
+ export type BatchFinalizedEvent = {
24
+ type: SettlementEventType.BatchFinalized;
42
25
  id: string;
43
- roundTxid: string;
26
+ commitmentTxid: string;
44
27
  };
45
- export type FailedEvent = {
46
- type: SettlementEventType.Failed;
28
+ export type BatchFailedEvent = {
29
+ type: SettlementEventType.BatchFailed;
47
30
  id: string;
48
31
  reason: string;
49
32
  };
50
- export type SigningStartEvent = {
51
- type: SettlementEventType.SigningStart;
33
+ export type TreeSigningStartedEvent = {
34
+ type: SettlementEventType.TreeSigningStarted;
52
35
  id: string;
53
36
  cosignersPublicKeys: string[];
54
- unsignedVtxoTree: TxTree;
55
- unsignedSettlementTx: string;
37
+ unsignedCommitmentTx: string;
56
38
  };
57
- export type SigningNoncesGeneratedEvent = {
58
- type: SettlementEventType.SigningNoncesGenerated;
39
+ export type TreeNoncesAggregatedEvent = {
40
+ type: SettlementEventType.TreeNoncesAggregated;
59
41
  id: string;
60
42
  treeNonces: TreeNonces;
61
43
  };
62
- export type SettlementEvent = FinalizationEvent | FinalizedEvent | FailedEvent | SigningStartEvent | SigningNoncesGeneratedEvent;
63
- export interface ArkInfo {
64
- pubkey: string;
44
+ export type BatchStartedEvent = {
45
+ type: SettlementEventType.BatchStarted;
46
+ id: string;
47
+ intentIdHashes: string[];
65
48
  batchExpiry: bigint;
49
+ };
50
+ export type TreeTxEvent = {
51
+ type: SettlementEventType.TreeTx;
52
+ id: string;
53
+ topic: string[];
54
+ batchIndex: number;
55
+ chunk: TxTreeNode;
56
+ };
57
+ export type TreeSignatureEvent = {
58
+ type: SettlementEventType.TreeSignature;
59
+ id: string;
60
+ topic: string[];
61
+ batchIndex: number;
62
+ txid: string;
63
+ signature: string;
64
+ };
65
+ export type SettlementEvent = BatchFinalizationEvent | BatchFinalizedEvent | BatchFailedEvent | TreeSigningStartedEvent | TreeNoncesAggregatedEvent | BatchStartedEvent | TreeTxEvent | TreeSignatureEvent;
66
+ export interface MarketHour {
67
+ nextStartTime: bigint;
68
+ nextEndTime: bigint;
69
+ period: bigint;
70
+ roundInterval: bigint;
71
+ }
72
+ export interface ArkInfo {
73
+ signerPubkey: string;
74
+ vtxoTreeExpiry: bigint;
66
75
  unilateralExitDelay: bigint;
67
76
  roundInterval: bigint;
68
77
  network: string;
69
78
  dust: bigint;
70
- boardingDescriptorTemplate: string;
71
- vtxoDescriptorTemplates: string[];
72
79
  forfeitAddress: string;
73
- marketHour?: {
74
- start: number;
75
- end: number;
76
- };
80
+ marketHour?: MarketHour;
81
+ version: string;
82
+ utxoMinAmount: bigint;
83
+ utxoMaxAmount: bigint;
84
+ vtxoMinAmount: bigint;
85
+ vtxoMaxAmount: bigint;
86
+ boardingExitDelay: bigint;
77
87
  }
78
- export interface Round {
79
- id: string;
80
- start: Date;
81
- end: Date;
82
- vtxoTree: TxTree;
83
- forfeitTxs: string[];
84
- connectors: TxTree;
88
+ export interface Intent {
89
+ signature: string;
90
+ message: string;
91
+ }
92
+ export interface TxNotification {
93
+ txid: string;
94
+ tx: string;
95
+ spentVtxos: Vtxo[];
96
+ spendableVtxos: Vtxo[];
97
+ checkpointTxs?: Record<string, {
98
+ txid: string;
99
+ tx: string;
100
+ }>;
85
101
  }
86
102
  export interface ArkProvider {
87
103
  getInfo(): Promise<ArkInfo>;
88
- getRound(txid: string): Promise<Round>;
89
- getVirtualCoins(address: string): Promise<{
90
- spendableVtxos: VirtualCoin[];
91
- spentVtxos: VirtualCoin[];
104
+ submitTx(signedArkTx: string, checkpointTxs: string[]): Promise<{
105
+ arkTxid: string;
106
+ finalArkTx: string;
107
+ signedCheckpointTxs: string[];
92
108
  }>;
93
- submitVirtualTx(psbtBase64: string): Promise<string>;
94
- subscribeToEvents(callback: (event: ArkEvent) => void): Promise<() => void>;
95
- registerInputsForNextRound(inputs: Input[]): Promise<{
96
- requestId: string;
97
- }>;
98
- registerOutputsForNextRound(requestId: string, outputs: Output[], vtxoTreeSigningPublicKeys: string[], signAll?: boolean): Promise<void>;
99
- submitTreeNonces(settlementID: string, pubkey: string, nonces: TreeNonces): Promise<void>;
100
- submitTreeSignatures(settlementID: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
101
- submitSignedForfeitTxs(signedForfeitTxs: string[], signedRoundTx?: string): Promise<void>;
102
- ping(paymentID: string): Promise<void>;
103
- getEventStream(signal: AbortSignal): AsyncIterableIterator<SettlementEvent>;
104
- subscribeForAddress(address: string, abortSignal: AbortSignal): AsyncIterableIterator<{
105
- newVtxos: VirtualCoin[];
106
- spentVtxos: VirtualCoin[];
109
+ finalizeTx(arkTxid: string, finalCheckpointTxs: string[]): Promise<void>;
110
+ registerIntent(intent: Intent): Promise<string>;
111
+ deleteIntent(intent: Intent): Promise<void>;
112
+ confirmRegistration(intentId: string): Promise<void>;
113
+ submitTreeNonces(batchId: string, pubkey: string, nonces: TreeNonces): Promise<void>;
114
+ submitTreeSignatures(batchId: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
115
+ submitSignedForfeitTxs(signedForfeitTxs: string[], signedCommitmentTx?: string): Promise<void>;
116
+ getEventStream(signal: AbortSignal, topics: string[]): AsyncIterableIterator<SettlementEvent>;
117
+ getTransactionsStream(signal: AbortSignal): AsyncIterableIterator<{
118
+ commitmentTx?: TxNotification;
119
+ arkTx?: TxNotification;
107
120
  }>;
108
121
  }
122
+ /**
123
+ * REST-based Ark provider implementation.
124
+ * @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.ArkService
125
+ * @example
126
+ * ```typescript
127
+ * const provider = new RestArkProvider('https://ark.example.com');
128
+ * const info = await provider.getInfo();
129
+ * ```
130
+ */
109
131
  export declare class RestArkProvider implements ArkProvider {
110
132
  serverUrl: string;
111
133
  constructor(serverUrl: string);
112
134
  getInfo(): Promise<ArkInfo>;
113
- getVirtualCoins(address: string): Promise<{
114
- spendableVtxos: VirtualCoin[];
115
- spentVtxos: VirtualCoin[];
116
- }>;
117
- getRound(txid: string): Promise<Round>;
118
- submitVirtualTx(psbtBase64: string): Promise<string>;
119
- subscribeToEvents(callback: (event: ArkEvent) => void): Promise<() => void>;
120
- registerInputsForNextRound(inputs: Input[]): Promise<{
121
- requestId: string;
135
+ submitTx(signedArkTx: string, checkpointTxs: string[]): Promise<{
136
+ arkTxid: string;
137
+ finalArkTx: string;
138
+ signedCheckpointTxs: string[];
122
139
  }>;
123
- registerOutputsForNextRound(requestId: string, outputs: Output[], cosignersPublicKeys: string[], signingAll?: boolean): Promise<void>;
124
- submitTreeNonces(settlementID: string, pubkey: string, nonces: TreeNonces): Promise<void>;
125
- submitTreeSignatures(settlementID: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
126
- submitSignedForfeitTxs(signedForfeitTxs: string[], signedRoundTx?: string): Promise<void>;
127
- ping(requestId: string): Promise<void>;
128
- getEventStream(signal: AbortSignal): AsyncIterableIterator<SettlementEvent>;
129
- subscribeForAddress(address: string, abortSignal: AbortSignal): AsyncIterableIterator<{
130
- newVtxos: VirtualCoin[];
131
- spentVtxos: VirtualCoin[];
140
+ finalizeTx(arkTxid: string, finalCheckpointTxs: string[]): Promise<void>;
141
+ registerIntent(intent: Intent): Promise<string>;
142
+ deleteIntent(intent: Intent): Promise<void>;
143
+ confirmRegistration(intentId: string): Promise<void>;
144
+ submitTreeNonces(batchId: string, pubkey: string, nonces: TreeNonces): Promise<void>;
145
+ submitTreeSignatures(batchId: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
146
+ submitSignedForfeitTxs(signedForfeitTxs: string[], signedCommitmentTx?: string): Promise<void>;
147
+ getEventStream(signal: AbortSignal, topics: string[]): AsyncIterableIterator<SettlementEvent>;
148
+ getTransactionsStream(signal: AbortSignal): AsyncIterableIterator<{
149
+ commitmentTx?: TxNotification;
150
+ arkTx?: TxNotification;
132
151
  }>;
133
- private toConnectorsIndex;
134
- private toTxTree;
135
152
  private parseSettlementEvent;
153
+ private parseTransactionNotification;
136
154
  }
155
+ export declare function isFetchTimeoutError(err: any): boolean;
@@ -0,0 +1,186 @@
1
+ import { Outpoint, VirtualCoin } from "../wallet";
2
+ export type PaginationOptions = {
3
+ pageIndex?: number;
4
+ pageSize?: number;
5
+ };
6
+ export declare enum IndexerTxType {
7
+ INDEXER_TX_TYPE_UNSPECIFIED = 0,
8
+ INDEXER_TX_TYPE_RECEIVED = 1,
9
+ INDEXER_TX_TYPE_SENT = 2
10
+ }
11
+ export declare enum ChainTxType {
12
+ UNSPECIFIED = "INDEXER_CHAINED_TX_TYPE_UNSPECIFIED",
13
+ COMMITMENT = "INDEXER_CHAINED_TX_TYPE_COMMITMENT",
14
+ ARK = "INDEXER_CHAINED_TX_TYPE_ARK",
15
+ TREE = "INDEXER_CHAINED_TX_TYPE_TREE",
16
+ CHECKPOINT = "INDEXER_CHAINED_TX_TYPE_CHECKPOINT"
17
+ }
18
+ export interface PageResponse {
19
+ current: number;
20
+ next: number;
21
+ total: number;
22
+ }
23
+ export interface Batch {
24
+ totalOutputAmount: string;
25
+ totalOutputVtxos: number;
26
+ expiresAt: string;
27
+ swept: boolean;
28
+ }
29
+ export interface ChainTx {
30
+ txid: string;
31
+ expiresAt: string;
32
+ type: ChainTxType;
33
+ spends: string[];
34
+ }
35
+ export interface CommitmentTx {
36
+ startedAt: string;
37
+ endedAt: string;
38
+ batches: {
39
+ [key: string]: Batch;
40
+ };
41
+ totalInputAmount: string;
42
+ totalInputVtxos: number;
43
+ totalOutputAmount: string;
44
+ totalOutputVtxos: number;
45
+ }
46
+ export interface Tx {
47
+ txid: string;
48
+ children: Record<number, string>;
49
+ }
50
+ export interface TxHistoryRecord {
51
+ commitmentTxid?: string;
52
+ virtualTxid?: string;
53
+ type: IndexerTxType;
54
+ amount: string;
55
+ createdAt: string;
56
+ isSettled: boolean;
57
+ settledBy: string;
58
+ }
59
+ export interface Vtxo {
60
+ outpoint: Outpoint;
61
+ createdAt: string;
62
+ expiresAt: string | null;
63
+ amount: string;
64
+ script: string;
65
+ isPreconfirmed: boolean;
66
+ isSwept: boolean;
67
+ isUnrolled: boolean;
68
+ isSpent: boolean;
69
+ spentBy: string | null;
70
+ commitmentTxids: string[];
71
+ settledBy?: string;
72
+ arkTxid?: string;
73
+ }
74
+ export interface VtxoChain {
75
+ chain: ChainTx[];
76
+ page?: PageResponse;
77
+ }
78
+ export interface SubscriptionResponse {
79
+ txid?: string;
80
+ scripts: string[];
81
+ newVtxos: VirtualCoin[];
82
+ spentVtxos: VirtualCoin[];
83
+ tx?: string;
84
+ checkpointTxs?: Record<string, {
85
+ txid: string;
86
+ tx: string;
87
+ }>;
88
+ }
89
+ export interface IndexerProvider {
90
+ getVtxoTree(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
91
+ vtxoTree: Tx[];
92
+ page?: PageResponse;
93
+ }>;
94
+ getVtxoTreeLeaves(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
95
+ leaves: Outpoint[];
96
+ page?: PageResponse;
97
+ }>;
98
+ getBatchSweepTransactions(batchOutpoint: Outpoint): Promise<{
99
+ sweptBy: string[];
100
+ }>;
101
+ getCommitmentTx(txid: string): Promise<CommitmentTx>;
102
+ getCommitmentTxConnectors(txid: string, opts?: PaginationOptions): Promise<{
103
+ connectors: Tx[];
104
+ page?: PageResponse;
105
+ }>;
106
+ getCommitmentTxForfeitTxs(txid: string, opts?: PaginationOptions): Promise<{
107
+ txids: string[];
108
+ page?: PageResponse;
109
+ }>;
110
+ getSubscription(subscriptionId: string, abortSignal: AbortSignal): AsyncIterableIterator<SubscriptionResponse>;
111
+ getVirtualTxs(txids: string[], opts?: PaginationOptions): Promise<{
112
+ txs: string[];
113
+ page?: PageResponse;
114
+ }>;
115
+ getVtxoChain(vtxoOutpoint: Outpoint, opts?: PaginationOptions): Promise<VtxoChain>;
116
+ getVtxos(opts?: PaginationOptions & {
117
+ scripts?: string[];
118
+ outpoints?: Outpoint[];
119
+ spendableOnly?: boolean;
120
+ spentOnly?: boolean;
121
+ recoverableOnly?: boolean;
122
+ }): Promise<{
123
+ vtxos: VirtualCoin[];
124
+ page?: PageResponse;
125
+ }>;
126
+ subscribeForScripts(scripts: string[], subscriptionId?: string): Promise<string>;
127
+ unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
128
+ }
129
+ /**
130
+ * REST-based Indexer provider implementation.
131
+ * @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.IndexerService
132
+ * @example
133
+ * ```typescript
134
+ * const provider = new RestIndexerProvider('https://ark.indexer.example.com');
135
+ * const commitmentTx = await provider.getCommitmentTx("6686af8f3be3517880821f62e6c3d749b9d6713736a1d8e229a55daa659446b2");
136
+ * ```
137
+ */
138
+ export declare class RestIndexerProvider implements IndexerProvider {
139
+ serverUrl: string;
140
+ constructor(serverUrl: string);
141
+ getVtxoTree(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
142
+ vtxoTree: Tx[];
143
+ page?: PageResponse;
144
+ }>;
145
+ getVtxoTreeLeaves(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
146
+ leaves: Outpoint[];
147
+ page?: PageResponse;
148
+ }>;
149
+ getBatchSweepTransactions(batchOutpoint: Outpoint): Promise<{
150
+ sweptBy: string[];
151
+ }>;
152
+ getCommitmentTx(txid: string): Promise<CommitmentTx>;
153
+ getCommitmentTxConnectors(txid: string, opts?: PaginationOptions): Promise<{
154
+ connectors: Tx[];
155
+ page?: PageResponse;
156
+ }>;
157
+ getCommitmentTxForfeitTxs(txid: string, opts?: PaginationOptions): Promise<{
158
+ txids: string[];
159
+ page?: PageResponse;
160
+ }>;
161
+ getSubscription(subscriptionId: string, abortSignal: AbortSignal): AsyncGenerator<{
162
+ txid: any;
163
+ scripts: any;
164
+ newVtxos: any;
165
+ spentVtxos: any;
166
+ tx: any;
167
+ checkpointTxs: any;
168
+ }, void, unknown>;
169
+ getVirtualTxs(txids: string[], opts?: PaginationOptions): Promise<{
170
+ txs: string[];
171
+ page?: PageResponse;
172
+ }>;
173
+ getVtxoChain(vtxoOutpoint: Outpoint, opts?: PaginationOptions): Promise<VtxoChain>;
174
+ getVtxos(opts?: PaginationOptions & {
175
+ scripts?: string[];
176
+ outpoints?: Outpoint[];
177
+ spendableOnly?: boolean;
178
+ spentOnly?: boolean;
179
+ recoverableOnly?: boolean;
180
+ }): Promise<{
181
+ vtxos: VirtualCoin[];
182
+ page?: PageResponse;
183
+ }>;
184
+ subscribeForScripts(scripts: string[], subscriptionId?: string): Promise<string>;
185
+ unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
186
+ }