@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.
- package/README.md +156 -174
- package/dist/cjs/arknote/index.js +61 -58
- package/dist/cjs/bip322/errors.js +13 -0
- package/dist/cjs/bip322/index.js +178 -0
- package/dist/cjs/forfeit.js +14 -25
- package/dist/cjs/identity/singleKey.js +68 -0
- package/dist/cjs/index.js +41 -17
- package/dist/cjs/providers/ark.js +253 -317
- package/dist/cjs/providers/indexer.js +525 -0
- package/dist/cjs/providers/onchain.js +193 -15
- package/dist/cjs/script/address.js +48 -17
- package/dist/cjs/script/base.js +120 -3
- package/dist/cjs/script/default.js +18 -4
- package/dist/cjs/script/tapscript.js +46 -14
- package/dist/cjs/script/vhtlc.js +27 -7
- package/dist/cjs/tree/signingSession.js +63 -106
- package/dist/cjs/tree/txTree.js +193 -0
- package/dist/cjs/tree/validation.js +79 -155
- package/dist/cjs/utils/anchor.js +35 -0
- package/dist/cjs/utils/arkTransaction.js +108 -0
- package/dist/cjs/utils/transactionHistory.js +84 -72
- package/dist/cjs/utils/txSizeEstimator.js +12 -0
- package/dist/cjs/utils/unknownFields.js +211 -0
- package/dist/cjs/wallet/index.js +12 -0
- package/dist/cjs/wallet/onchain.js +201 -0
- package/dist/cjs/wallet/ramps.js +95 -0
- package/dist/cjs/wallet/serviceWorker/db/vtxo/idb.js +32 -0
- package/dist/cjs/wallet/serviceWorker/request.js +15 -12
- package/dist/cjs/wallet/serviceWorker/response.js +22 -27
- package/dist/cjs/wallet/serviceWorker/utils.js +8 -0
- package/dist/cjs/wallet/serviceWorker/wallet.js +58 -34
- package/dist/cjs/wallet/serviceWorker/worker.js +117 -108
- package/dist/cjs/wallet/unroll.js +270 -0
- package/dist/cjs/wallet/wallet.js +701 -459
- package/dist/esm/arknote/index.js +61 -57
- package/dist/esm/bip322/errors.js +9 -0
- package/dist/esm/bip322/index.js +174 -0
- package/dist/esm/forfeit.js +15 -26
- package/dist/esm/identity/singleKey.js +64 -0
- package/dist/esm/index.js +30 -12
- package/dist/esm/providers/ark.js +252 -317
- package/dist/esm/providers/indexer.js +521 -0
- package/dist/esm/providers/onchain.js +193 -15
- package/dist/esm/script/address.js +48 -17
- package/dist/esm/script/base.js +120 -3
- package/dist/esm/script/default.js +18 -4
- package/dist/esm/script/tapscript.js +46 -14
- package/dist/esm/script/vhtlc.js +27 -7
- package/dist/esm/tree/signingSession.js +65 -108
- package/dist/esm/tree/txTree.js +189 -0
- package/dist/esm/tree/validation.js +75 -152
- package/dist/esm/utils/anchor.js +31 -0
- package/dist/esm/utils/arkTransaction.js +105 -0
- package/dist/esm/utils/transactionHistory.js +84 -72
- package/dist/esm/utils/txSizeEstimator.js +12 -0
- package/dist/esm/utils/unknownFields.js +173 -0
- package/dist/esm/wallet/index.js +9 -0
- package/dist/esm/wallet/onchain.js +196 -0
- package/dist/esm/wallet/ramps.js +91 -0
- package/dist/esm/wallet/serviceWorker/db/vtxo/idb.js +32 -0
- package/dist/esm/wallet/serviceWorker/request.js +15 -12
- package/dist/esm/wallet/serviceWorker/response.js +22 -27
- package/dist/esm/wallet/serviceWorker/utils.js +8 -0
- package/dist/esm/wallet/serviceWorker/wallet.js +59 -35
- package/dist/esm/wallet/serviceWorker/worker.js +117 -108
- package/dist/esm/wallet/unroll.js +267 -0
- package/dist/esm/wallet/wallet.js +674 -466
- package/dist/types/arknote/index.d.ts +40 -13
- package/dist/types/bip322/errors.d.ts +6 -0
- package/dist/types/bip322/index.d.ts +57 -0
- package/dist/types/forfeit.d.ts +2 -14
- package/dist/types/identity/singleKey.d.ts +27 -0
- package/dist/types/index.d.ts +23 -12
- package/dist/types/providers/ark.d.ts +114 -95
- package/dist/types/providers/indexer.d.ts +186 -0
- package/dist/types/providers/onchain.d.ts +41 -11
- package/dist/types/script/address.d.ts +26 -2
- package/dist/types/script/base.d.ts +13 -3
- package/dist/types/script/default.d.ts +22 -0
- package/dist/types/script/tapscript.d.ts +61 -5
- package/dist/types/script/vhtlc.d.ts +27 -0
- package/dist/types/tree/signingSession.d.ts +5 -5
- package/dist/types/tree/txTree.d.ts +28 -0
- package/dist/types/tree/validation.d.ts +15 -22
- package/dist/types/utils/anchor.d.ts +19 -0
- package/dist/types/utils/arkTransaction.d.ts +27 -0
- package/dist/types/utils/transactionHistory.d.ts +7 -1
- package/dist/types/utils/txSizeEstimator.d.ts +3 -0
- package/dist/types/utils/unknownFields.d.ts +83 -0
- package/dist/types/wallet/index.d.ts +51 -50
- package/dist/types/wallet/onchain.d.ts +49 -0
- package/dist/types/wallet/ramps.d.ts +32 -0
- package/dist/types/wallet/serviceWorker/db/vtxo/idb.d.ts +2 -0
- package/dist/types/wallet/serviceWorker/db/vtxo/index.d.ts +2 -0
- package/dist/types/wallet/serviceWorker/request.d.ts +14 -16
- package/dist/types/wallet/serviceWorker/response.d.ts +17 -19
- package/dist/types/wallet/serviceWorker/utils.d.ts +8 -0
- package/dist/types/wallet/serviceWorker/wallet.d.ts +36 -8
- package/dist/types/wallet/serviceWorker/worker.d.ts +7 -3
- package/dist/types/wallet/unroll.d.ts +102 -0
- package/dist/types/wallet/wallet.d.ts +71 -26
- package/package.json +14 -15
- package/dist/cjs/identity/inMemoryKey.js +0 -40
- package/dist/cjs/tree/vtxoTree.js +0 -231
- package/dist/cjs/utils/coinselect.js +0 -73
- package/dist/cjs/utils/psbt.js +0 -137
- package/dist/esm/identity/inMemoryKey.js +0 -36
- package/dist/esm/tree/vtxoTree.js +0 -191
- package/dist/esm/utils/coinselect.js +0 -69
- package/dist/esm/utils/psbt.js +0 -131
- package/dist/types/identity/inMemoryKey.d.ts +0 -12
- package/dist/types/tree/vtxoTree.d.ts +0 -33
- package/dist/types/utils/coinselect.d.ts +0 -21
- package/dist/types/utils/psbt.d.ts +0 -11
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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):
|
|
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,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;
|
package/dist/types/forfeit.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
1
|
import { Transaction } from "@scure/btc-signer";
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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 {
|
|
18
|
-
import {
|
|
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
|
-
|
|
23
|
-
|
|
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 {
|
|
2
|
-
import { Outpoint, VirtualCoin } from "../wallet";
|
|
1
|
+
import { TxTreeNode } from "../tree/txTree";
|
|
3
2
|
import { TreeNonces, TreePartialSigs } from "../tree/signingSession";
|
|
4
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
32
|
-
type: SettlementEventType.
|
|
18
|
+
export type BatchFinalizationEvent = {
|
|
19
|
+
type: SettlementEventType.BatchFinalization;
|
|
33
20
|
id: string;
|
|
34
|
-
|
|
35
|
-
vtxoTree: TxTree;
|
|
36
|
-
connectors: TxTree;
|
|
37
|
-
minRelayFeeRate: bigint;
|
|
38
|
-
connectorsIndex: Map<string, Outpoint>;
|
|
21
|
+
commitmentTx: string;
|
|
39
22
|
};
|
|
40
|
-
export type
|
|
41
|
-
type: SettlementEventType.
|
|
23
|
+
export type BatchFinalizedEvent = {
|
|
24
|
+
type: SettlementEventType.BatchFinalized;
|
|
42
25
|
id: string;
|
|
43
|
-
|
|
26
|
+
commitmentTxid: string;
|
|
44
27
|
};
|
|
45
|
-
export type
|
|
46
|
-
type: SettlementEventType.
|
|
28
|
+
export type BatchFailedEvent = {
|
|
29
|
+
type: SettlementEventType.BatchFailed;
|
|
47
30
|
id: string;
|
|
48
31
|
reason: string;
|
|
49
32
|
};
|
|
50
|
-
export type
|
|
51
|
-
type: SettlementEventType.
|
|
33
|
+
export type TreeSigningStartedEvent = {
|
|
34
|
+
type: SettlementEventType.TreeSigningStarted;
|
|
52
35
|
id: string;
|
|
53
36
|
cosignersPublicKeys: string[];
|
|
54
|
-
|
|
55
|
-
unsignedSettlementTx: string;
|
|
37
|
+
unsignedCommitmentTx: string;
|
|
56
38
|
};
|
|
57
|
-
export type
|
|
58
|
-
type: SettlementEventType.
|
|
39
|
+
export type TreeNoncesAggregatedEvent = {
|
|
40
|
+
type: SettlementEventType.TreeNoncesAggregated;
|
|
59
41
|
id: string;
|
|
60
42
|
treeNonces: TreeNonces;
|
|
61
43
|
};
|
|
62
|
-
export type
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
75
|
-
|
|
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
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
submitTx(signedArkTx: string, checkpointTxs: string[]): Promise<{
|
|
105
|
+
arkTxid: string;
|
|
106
|
+
finalArkTx: string;
|
|
107
|
+
signedCheckpointTxs: string[];
|
|
92
108
|
}>;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
}
|