@arkade-os/sdk 0.0.16
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 +312 -0
- package/dist/cjs/arknote/index.js +86 -0
- package/dist/cjs/forfeit.js +38 -0
- package/dist/cjs/identity/inMemoryKey.js +40 -0
- package/dist/cjs/identity/index.js +2 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/musig2/index.js +10 -0
- package/dist/cjs/musig2/keys.js +57 -0
- package/dist/cjs/musig2/nonces.js +44 -0
- package/dist/cjs/musig2/sign.js +102 -0
- package/dist/cjs/networks.js +26 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/providers/ark.js +530 -0
- package/dist/cjs/providers/onchain.js +61 -0
- package/dist/cjs/script/address.js +45 -0
- package/dist/cjs/script/base.js +51 -0
- package/dist/cjs/script/default.js +40 -0
- package/dist/cjs/script/tapscript.js +528 -0
- package/dist/cjs/script/vhtlc.js +84 -0
- package/dist/cjs/tree/signingSession.js +238 -0
- package/dist/cjs/tree/validation.js +184 -0
- package/dist/cjs/tree/vtxoTree.js +197 -0
- package/dist/cjs/utils/bip21.js +114 -0
- package/dist/cjs/utils/coinselect.js +73 -0
- package/dist/cjs/utils/psbt.js +124 -0
- package/dist/cjs/utils/transactionHistory.js +148 -0
- package/dist/cjs/utils/txSizeEstimator.js +95 -0
- package/dist/cjs/wallet/index.js +8 -0
- package/dist/cjs/wallet/serviceWorker/db/vtxo/idb.js +153 -0
- package/dist/cjs/wallet/serviceWorker/db/vtxo/index.js +2 -0
- package/dist/cjs/wallet/serviceWorker/request.js +75 -0
- package/dist/cjs/wallet/serviceWorker/response.js +187 -0
- package/dist/cjs/wallet/serviceWorker/wallet.js +332 -0
- package/dist/cjs/wallet/serviceWorker/worker.js +452 -0
- package/dist/cjs/wallet/wallet.js +720 -0
- package/dist/esm/arknote/index.js +81 -0
- package/dist/esm/forfeit.js +35 -0
- package/dist/esm/identity/inMemoryKey.js +36 -0
- package/dist/esm/identity/index.js +1 -0
- package/dist/esm/index.js +39 -0
- package/dist/esm/musig2/index.js +3 -0
- package/dist/esm/musig2/keys.js +21 -0
- package/dist/esm/musig2/nonces.js +8 -0
- package/dist/esm/musig2/sign.js +63 -0
- package/dist/esm/networks.js +22 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/providers/ark.js +526 -0
- package/dist/esm/providers/onchain.js +57 -0
- package/dist/esm/script/address.js +41 -0
- package/dist/esm/script/base.js +46 -0
- package/dist/esm/script/default.js +37 -0
- package/dist/esm/script/tapscript.js +491 -0
- package/dist/esm/script/vhtlc.js +81 -0
- package/dist/esm/tree/signingSession.js +200 -0
- package/dist/esm/tree/validation.js +179 -0
- package/dist/esm/tree/vtxoTree.js +157 -0
- package/dist/esm/utils/bip21.js +110 -0
- package/dist/esm/utils/coinselect.js +69 -0
- package/dist/esm/utils/psbt.js +118 -0
- package/dist/esm/utils/transactionHistory.js +145 -0
- package/dist/esm/utils/txSizeEstimator.js +91 -0
- package/dist/esm/wallet/index.js +5 -0
- package/dist/esm/wallet/serviceWorker/db/vtxo/idb.js +149 -0
- package/dist/esm/wallet/serviceWorker/db/vtxo/index.js +1 -0
- package/dist/esm/wallet/serviceWorker/request.js +72 -0
- package/dist/esm/wallet/serviceWorker/response.js +184 -0
- package/dist/esm/wallet/serviceWorker/wallet.js +328 -0
- package/dist/esm/wallet/serviceWorker/worker.js +448 -0
- package/dist/esm/wallet/wallet.js +716 -0
- package/dist/types/arknote/index.d.ts +17 -0
- package/dist/types/forfeit.d.ts +15 -0
- package/dist/types/identity/inMemoryKey.d.ts +12 -0
- package/dist/types/identity/index.d.ts +7 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/musig2/index.d.ts +4 -0
- package/dist/types/musig2/keys.d.ts +9 -0
- package/dist/types/musig2/nonces.d.ts +13 -0
- package/dist/types/musig2/sign.d.ts +27 -0
- package/dist/types/networks.d.ts +16 -0
- package/dist/types/providers/ark.d.ts +126 -0
- package/dist/types/providers/onchain.d.ts +36 -0
- package/dist/types/script/address.d.ts +10 -0
- package/dist/types/script/base.d.ts +26 -0
- package/dist/types/script/default.d.ts +19 -0
- package/dist/types/script/tapscript.d.ts +94 -0
- package/dist/types/script/vhtlc.d.ts +31 -0
- package/dist/types/tree/signingSession.d.ts +32 -0
- package/dist/types/tree/validation.d.ts +22 -0
- package/dist/types/tree/vtxoTree.d.ts +32 -0
- package/dist/types/utils/bip21.d.ts +21 -0
- package/dist/types/utils/coinselect.d.ts +21 -0
- package/dist/types/utils/psbt.d.ts +11 -0
- package/dist/types/utils/transactionHistory.d.ts +2 -0
- package/dist/types/utils/txSizeEstimator.d.ts +27 -0
- package/dist/types/wallet/index.d.ts +122 -0
- package/dist/types/wallet/serviceWorker/db/vtxo/idb.d.ts +18 -0
- package/dist/types/wallet/serviceWorker/db/vtxo/index.d.ts +12 -0
- package/dist/types/wallet/serviceWorker/request.d.ts +68 -0
- package/dist/types/wallet/serviceWorker/response.d.ts +107 -0
- package/dist/types/wallet/serviceWorker/wallet.d.ts +23 -0
- package/dist/types/wallet/serviceWorker/worker.d.ts +26 -0
- package/dist/types/wallet/wallet.d.ts +42 -0
- package/package.json +88 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class ArkNoteData {
|
|
2
|
+
id: bigint;
|
|
3
|
+
value: number;
|
|
4
|
+
constructor(id: bigint, value: number);
|
|
5
|
+
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;
|
|
16
|
+
toString(): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { Identity } from ".";
|
|
3
|
+
import { SignerSession } from "../tree/signingSession";
|
|
4
|
+
export declare class InMemoryKey implements Identity {
|
|
5
|
+
private key;
|
|
6
|
+
private constructor();
|
|
7
|
+
static fromPrivateKey(privateKey: Uint8Array): InMemoryKey;
|
|
8
|
+
static fromHex(privateKeyHex: string): InMemoryKey;
|
|
9
|
+
sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
|
|
10
|
+
xOnlyPublicKey(): Uint8Array;
|
|
11
|
+
signerSession(): SignerSession;
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { SignerSession } from "../tree/signingSession";
|
|
3
|
+
export interface Identity {
|
|
4
|
+
sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
|
|
5
|
+
xOnlyPublicKey(): Uint8Array;
|
|
6
|
+
signerSession(): SignerSession;
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InMemoryKey } from "./identity/inMemoryKey";
|
|
2
|
+
import { Identity } from "./identity";
|
|
3
|
+
import { ArkAddress } from "./script/address";
|
|
4
|
+
import { VHTLC } from "./script/vhtlc";
|
|
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";
|
|
9
|
+
import { ServiceWorkerWallet } from "./wallet/serviceWorker/wallet";
|
|
10
|
+
import { Worker } from "./wallet/serviceWorker/worker";
|
|
11
|
+
import { Request } from "./wallet/serviceWorker/request";
|
|
12
|
+
import { Response } from "./wallet/serviceWorker/response";
|
|
13
|
+
import { ESPLORA_URL, EsploraProvider } from "./providers/onchain";
|
|
14
|
+
import { RestArkProvider } from "./providers/ark";
|
|
15
|
+
import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, decodeTapscript, MultisigTapscript, TapscriptType } from "./script/tapscript";
|
|
16
|
+
import { addConditionWitness, CONDITION_WITNESS_KEY_PREFIX, createVirtualTx } from "./utils/psbt";
|
|
17
|
+
import { ArkNote, ArkNoteData } from "./arknote";
|
|
18
|
+
import { IndexedDBVtxoRepository } from "./wallet/serviceWorker/db/vtxo/idb";
|
|
19
|
+
import { VtxoRepository } from "./wallet/serviceWorker/db/vtxo";
|
|
20
|
+
import { networks } from "./networks";
|
|
21
|
+
export { Wallet, ServiceWorkerWallet, InMemoryKey, ESPLORA_URL, EsploraProvider, RestArkProvider, ArkAddress, DefaultVtxo, VtxoScript, VHTLC, TxType, Worker, Request, Response, decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, addConditionWitness, CONDITION_WITNESS_KEY_PREFIX, createVirtualTx, ArkNote, ArkNoteData, networks, IndexedDBVtxoRepository, };
|
|
22
|
+
export type { Identity, IWallet, WalletConfig, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, WalletBalance, SendBitcoinParams, Recipient, SettleParams, VtxoTaprootAddress, AddressInfo, Addresses, TapscriptInfo, Status, VirtualStatus, Outpoint, VirtualCoin, TxKey, TapscriptType, VtxoRepository, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface KeyAggOptions {
|
|
2
|
+
taprootTweak?: Uint8Array;
|
|
3
|
+
}
|
|
4
|
+
export interface AggregateKey {
|
|
5
|
+
preTweakedKey: Uint8Array;
|
|
6
|
+
finalKey: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export declare function aggregateKeys(publicKeys: Uint8Array[], sort: boolean, options?: Partial<KeyAggOptions>): AggregateKey;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MuSig2 nonce pair containing public and secret values.
|
|
3
|
+
* Public nonces are two compressed points (33 bytes each).
|
|
4
|
+
* Secret nonces are the corresponding private scalars plus pubkey.
|
|
5
|
+
*/
|
|
6
|
+
export type Nonces = {
|
|
7
|
+
pubNonce: Uint8Array;
|
|
8
|
+
secNonce: Uint8Array;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Generates a pair of public and secret nonces for MuSig2 signing
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateNonces(publicKey: Uint8Array): Nonces;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class PartialSignatureError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
interface SignOptions {
|
|
5
|
+
sortKeys?: boolean;
|
|
6
|
+
taprootTweak?: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export declare class PartialSig {
|
|
9
|
+
s: Uint8Array;
|
|
10
|
+
R: Uint8Array;
|
|
11
|
+
constructor(s: Uint8Array, R: Uint8Array);
|
|
12
|
+
/**
|
|
13
|
+
* Encodes the partial signature into bytes
|
|
14
|
+
* Returns a 32-byte array containing just the s value
|
|
15
|
+
*/
|
|
16
|
+
encode(): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Decodes a partial signature from bytes
|
|
19
|
+
* @param bytes - 32-byte array containing s value
|
|
20
|
+
*/
|
|
21
|
+
static decode(bytes: Uint8Array): PartialSig;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generates a MuSig2 partial signature
|
|
25
|
+
*/
|
|
26
|
+
export declare function sign(secNonce: Uint8Array, privateKey: Uint8Array, combinedNonce: Uint8Array, publicKeys: Uint8Array[], message: Uint8Array, options?: SignOptions): PartialSig;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type NetworkName = "bitcoin" | "testnet" | "signet" | "mutinynet" | "regtest";
|
|
2
|
+
export interface Network {
|
|
3
|
+
hrp: string;
|
|
4
|
+
bech32: string;
|
|
5
|
+
pubKeyHash: number;
|
|
6
|
+
scriptHash: number;
|
|
7
|
+
wif: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const getNetwork: (network: NetworkName) => Network;
|
|
10
|
+
export declare const networks: {
|
|
11
|
+
bitcoin: Network;
|
|
12
|
+
testnet: Network;
|
|
13
|
+
signet: Network;
|
|
14
|
+
mutinynet: Network;
|
|
15
|
+
regtest: Network;
|
|
16
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { TxTree } from "../tree/vtxoTree";
|
|
2
|
+
import { Outpoint, VirtualCoin } from "../wallet";
|
|
3
|
+
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;
|
|
20
|
+
export type Output = {
|
|
21
|
+
address: string;
|
|
22
|
+
amount: bigint;
|
|
23
|
+
};
|
|
24
|
+
export declare enum SettlementEventType {
|
|
25
|
+
Finalization = "finalization",
|
|
26
|
+
Finalized = "finalized",
|
|
27
|
+
Failed = "failed",
|
|
28
|
+
SigningStart = "signing_start",
|
|
29
|
+
SigningNoncesGenerated = "signing_nonces_generated"
|
|
30
|
+
}
|
|
31
|
+
export type FinalizationEvent = {
|
|
32
|
+
type: SettlementEventType.Finalization;
|
|
33
|
+
id: string;
|
|
34
|
+
roundTx: string;
|
|
35
|
+
vtxoTree: TxTree;
|
|
36
|
+
connectors: TxTree;
|
|
37
|
+
minRelayFeeRate: bigint;
|
|
38
|
+
connectorsIndex: Map<string, Outpoint>;
|
|
39
|
+
};
|
|
40
|
+
export type FinalizedEvent = {
|
|
41
|
+
type: SettlementEventType.Finalized;
|
|
42
|
+
id: string;
|
|
43
|
+
roundTxid: string;
|
|
44
|
+
};
|
|
45
|
+
export type FailedEvent = {
|
|
46
|
+
type: SettlementEventType.Failed;
|
|
47
|
+
id: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
export type SigningStartEvent = {
|
|
51
|
+
type: SettlementEventType.SigningStart;
|
|
52
|
+
id: string;
|
|
53
|
+
cosignersPublicKeys: string[];
|
|
54
|
+
unsignedVtxoTree: TxTree;
|
|
55
|
+
unsignedSettlementTx: string;
|
|
56
|
+
};
|
|
57
|
+
export type SigningNoncesGeneratedEvent = {
|
|
58
|
+
type: SettlementEventType.SigningNoncesGenerated;
|
|
59
|
+
id: string;
|
|
60
|
+
treeNonces: TreeNonces;
|
|
61
|
+
};
|
|
62
|
+
export type SettlementEvent = FinalizationEvent | FinalizedEvent | FailedEvent | SigningStartEvent | SigningNoncesGeneratedEvent;
|
|
63
|
+
export interface ArkInfo {
|
|
64
|
+
pubkey: string;
|
|
65
|
+
batchExpiry: bigint;
|
|
66
|
+
unilateralExitDelay: bigint;
|
|
67
|
+
roundInterval: bigint;
|
|
68
|
+
network: string;
|
|
69
|
+
dust: bigint;
|
|
70
|
+
boardingDescriptorTemplate: string;
|
|
71
|
+
vtxoDescriptorTemplates: string[];
|
|
72
|
+
forfeitAddress: string;
|
|
73
|
+
marketHour?: {
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export interface ArkProvider {
|
|
79
|
+
getInfo(): Promise<ArkInfo>;
|
|
80
|
+
getVirtualCoins(address: string): Promise<{
|
|
81
|
+
spendableVtxos: VirtualCoin[];
|
|
82
|
+
spentVtxos: VirtualCoin[];
|
|
83
|
+
}>;
|
|
84
|
+
submitVirtualTx(psbtBase64: string): Promise<string>;
|
|
85
|
+
subscribeToEvents(callback: (event: ArkEvent) => void): Promise<() => void>;
|
|
86
|
+
registerInputsForNextRound(inputs: Input[]): Promise<{
|
|
87
|
+
requestId: string;
|
|
88
|
+
}>;
|
|
89
|
+
registerOutputsForNextRound(requestId: string, outputs: Output[], vtxoTreeSigningPublicKeys: string[], signAll?: boolean): Promise<void>;
|
|
90
|
+
submitTreeNonces(settlementID: string, pubkey: string, nonces: TreeNonces): Promise<void>;
|
|
91
|
+
submitTreeSignatures(settlementID: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
|
|
92
|
+
submitSignedForfeitTxs(signedForfeitTxs: string[], signedRoundTx?: string): Promise<void>;
|
|
93
|
+
ping(paymentID: string): Promise<void>;
|
|
94
|
+
getEventStream(signal: AbortSignal): AsyncIterableIterator<SettlementEvent>;
|
|
95
|
+
subscribeForAddress(address: string, abortSignal: AbortSignal): AsyncIterableIterator<{
|
|
96
|
+
newVtxos: VirtualCoin[];
|
|
97
|
+
spentVtxos: VirtualCoin[];
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
100
|
+
export declare class RestArkProvider implements ArkProvider {
|
|
101
|
+
serverUrl: string;
|
|
102
|
+
constructor(serverUrl: string);
|
|
103
|
+
getInfo(): Promise<ArkInfo>;
|
|
104
|
+
getVirtualCoins(address: string): Promise<{
|
|
105
|
+
spendableVtxos: VirtualCoin[];
|
|
106
|
+
spentVtxos: VirtualCoin[];
|
|
107
|
+
}>;
|
|
108
|
+
submitVirtualTx(psbtBase64: string): Promise<string>;
|
|
109
|
+
subscribeToEvents(callback: (event: ArkEvent) => void): Promise<() => void>;
|
|
110
|
+
registerInputsForNextRound(inputs: Input[]): Promise<{
|
|
111
|
+
requestId: string;
|
|
112
|
+
}>;
|
|
113
|
+
registerOutputsForNextRound(requestId: string, outputs: Output[], cosignersPublicKeys: string[], signingAll?: boolean): Promise<void>;
|
|
114
|
+
submitTreeNonces(settlementID: string, pubkey: string, nonces: TreeNonces): Promise<void>;
|
|
115
|
+
submitTreeSignatures(settlementID: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
|
|
116
|
+
submitSignedForfeitTxs(signedForfeitTxs: string[], signedRoundTx?: string): Promise<void>;
|
|
117
|
+
ping(requestId: string): Promise<void>;
|
|
118
|
+
getEventStream(signal: AbortSignal): AsyncIterableIterator<SettlementEvent>;
|
|
119
|
+
subscribeForAddress(address: string, abortSignal: AbortSignal): AsyncIterableIterator<{
|
|
120
|
+
newVtxos: VirtualCoin[];
|
|
121
|
+
spentVtxos: VirtualCoin[];
|
|
122
|
+
}>;
|
|
123
|
+
private toConnectorsIndex;
|
|
124
|
+
private toTxTree;
|
|
125
|
+
private parseSettlementEvent;
|
|
126
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { NetworkName } from "../networks";
|
|
2
|
+
import { Coin } from "../wallet";
|
|
3
|
+
export declare const ESPLORA_URL: Record<NetworkName, string>;
|
|
4
|
+
export type ExplorerTransaction = {
|
|
5
|
+
txid: string;
|
|
6
|
+
vout: {
|
|
7
|
+
scriptpubkey_address: string;
|
|
8
|
+
value: bigint;
|
|
9
|
+
}[];
|
|
10
|
+
status: {
|
|
11
|
+
confirmed: boolean;
|
|
12
|
+
block_time: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export interface OnchainProvider {
|
|
16
|
+
getCoins(address: string): Promise<Coin[]>;
|
|
17
|
+
getFeeRate(): Promise<number>;
|
|
18
|
+
broadcastTransaction(txHex: string): Promise<string>;
|
|
19
|
+
getTxOutspends(txid: string): Promise<{
|
|
20
|
+
spent: boolean;
|
|
21
|
+
txid: string;
|
|
22
|
+
}[]>;
|
|
23
|
+
getTransactions(address: string): Promise<ExplorerTransaction[]>;
|
|
24
|
+
}
|
|
25
|
+
export declare class EsploraProvider implements OnchainProvider {
|
|
26
|
+
private baseUrl;
|
|
27
|
+
constructor(baseUrl: string);
|
|
28
|
+
getCoins(address: string): Promise<Coin[]>;
|
|
29
|
+
getFeeRate(): Promise<number>;
|
|
30
|
+
broadcastTransaction(txHex: string): Promise<string>;
|
|
31
|
+
getTxOutspends(txid: string): Promise<{
|
|
32
|
+
spent: boolean;
|
|
33
|
+
txid: string;
|
|
34
|
+
}[]>;
|
|
35
|
+
getTransactions(address: string): Promise<ExplorerTransaction[]>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
export declare class ArkAddress {
|
|
3
|
+
readonly serverPubKey: Bytes;
|
|
4
|
+
readonly tweakedPubKey: Bytes;
|
|
5
|
+
readonly hrp: string;
|
|
6
|
+
constructor(serverPubKey: Bytes, tweakedPubKey: Bytes, hrp: string);
|
|
7
|
+
static decode(address: string): ArkAddress;
|
|
8
|
+
encode(): string;
|
|
9
|
+
get pkScript(): Bytes;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BTC_NETWORK, Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
import { ArkAddress } from "./address";
|
|
3
|
+
export type TapLeafScript = [
|
|
4
|
+
{
|
|
5
|
+
version: number;
|
|
6
|
+
internalKey: Bytes;
|
|
7
|
+
merklePath: Bytes[];
|
|
8
|
+
},
|
|
9
|
+
Bytes
|
|
10
|
+
];
|
|
11
|
+
export declare function scriptFromTapLeafScript(leaf: TapLeafScript): Bytes;
|
|
12
|
+
export declare class VtxoScript {
|
|
13
|
+
readonly scripts: Bytes[];
|
|
14
|
+
readonly leaves: TapLeafScript[];
|
|
15
|
+
readonly tweakedPublicKey: Bytes;
|
|
16
|
+
static decode(scripts: string[]): VtxoScript;
|
|
17
|
+
constructor(scripts: Bytes[]);
|
|
18
|
+
encode(): string[];
|
|
19
|
+
address(prefix: string, serverPubKey: Bytes): ArkAddress;
|
|
20
|
+
get pkScript(): Bytes;
|
|
21
|
+
onchainAddress(network: BTC_NETWORK): string;
|
|
22
|
+
findLeaf(scriptHex: string): TapLeafScript;
|
|
23
|
+
}
|
|
24
|
+
export type EncodedVtxoScript = {
|
|
25
|
+
scripts: ReturnType<VtxoScript["encode"]>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
import { TapLeafScript, VtxoScript } from "./base";
|
|
3
|
+
import { RelativeTimelock } from "./tapscript";
|
|
4
|
+
export declare namespace DefaultVtxo {
|
|
5
|
+
interface Options {
|
|
6
|
+
pubKey: Bytes;
|
|
7
|
+
serverPubKey: Bytes;
|
|
8
|
+
csvTimelock?: RelativeTimelock;
|
|
9
|
+
}
|
|
10
|
+
class Script extends VtxoScript {
|
|
11
|
+
readonly options: Options;
|
|
12
|
+
static readonly DEFAULT_TIMELOCK: RelativeTimelock;
|
|
13
|
+
readonly forfeitScript: string;
|
|
14
|
+
readonly exitScript: string;
|
|
15
|
+
constructor(options: Options);
|
|
16
|
+
forfeit(): TapLeafScript;
|
|
17
|
+
exit(): TapLeafScript;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
export type RelativeTimelock = {
|
|
3
|
+
value: bigint;
|
|
4
|
+
type: "seconds" | "blocks";
|
|
5
|
+
};
|
|
6
|
+
export declare enum TapscriptType {
|
|
7
|
+
Multisig = "multisig",
|
|
8
|
+
CSVMultisig = "csv-multisig",
|
|
9
|
+
ConditionCSVMultisig = "condition-csv-multisig",
|
|
10
|
+
ConditionMultisig = "condition-multisig",
|
|
11
|
+
CLTVMultisig = "cltv-multisig"
|
|
12
|
+
}
|
|
13
|
+
export interface ArkTapscript<T extends TapscriptType, Params, SizeArgs = never> {
|
|
14
|
+
type: T;
|
|
15
|
+
params: Params;
|
|
16
|
+
script: Uint8Array;
|
|
17
|
+
witnessSize(args: SizeArgs): number;
|
|
18
|
+
}
|
|
19
|
+
export declare function decodeTapscript(script: Uint8Array): ArkTapscript<TapscriptType, any, any | undefined>;
|
|
20
|
+
/**
|
|
21
|
+
* Implements a multi-signature script that requires a threshold of signatures
|
|
22
|
+
* from the specified pubkeys.
|
|
23
|
+
*/
|
|
24
|
+
export declare namespace MultisigTapscript {
|
|
25
|
+
type Type = ArkTapscript<TapscriptType.Multisig, Params>;
|
|
26
|
+
enum MultisigType {
|
|
27
|
+
CHECKSIG = 0,
|
|
28
|
+
CHECKSIGADD = 1
|
|
29
|
+
}
|
|
30
|
+
type Params = {
|
|
31
|
+
pubkeys: Bytes[];
|
|
32
|
+
type?: MultisigType;
|
|
33
|
+
};
|
|
34
|
+
function encode(params: Params): Type;
|
|
35
|
+
function decode(script: Uint8Array): Type;
|
|
36
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Implements a relative timelock script that requires all specified pubkeys to sign
|
|
40
|
+
* after the relative timelock has expired. The timelock can be specified in blocks or seconds.
|
|
41
|
+
*
|
|
42
|
+
* This is the standard exit closure and it is also used for the sweep closure in vtxo trees.
|
|
43
|
+
*/
|
|
44
|
+
export declare namespace CSVMultisigTapscript {
|
|
45
|
+
type Type = ArkTapscript<TapscriptType.CSVMultisig, Params>;
|
|
46
|
+
type Params = {
|
|
47
|
+
timelock: RelativeTimelock;
|
|
48
|
+
} & MultisigTapscript.Params;
|
|
49
|
+
function encode(params: Params): Type;
|
|
50
|
+
function decode(script: Uint8Array): Type;
|
|
51
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Combines a condition script with an exit closure. The resulting script requires
|
|
55
|
+
* the condition to be met, followed by the standard exit closure requirements
|
|
56
|
+
* (timelock and signatures).
|
|
57
|
+
*/
|
|
58
|
+
export declare namespace ConditionCSVMultisigTapscript {
|
|
59
|
+
type Type = ArkTapscript<TapscriptType.ConditionCSVMultisig, Params>;
|
|
60
|
+
type Params = {
|
|
61
|
+
conditionScript: Bytes;
|
|
62
|
+
} & CSVMultisigTapscript.Params;
|
|
63
|
+
function encode(params: Params): Type;
|
|
64
|
+
function decode(script: Uint8Array): Type;
|
|
65
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Combines a condition script with a forfeit closure. The resulting script requires
|
|
69
|
+
* the condition to be met, followed by the standard forfeit closure requirements
|
|
70
|
+
* (multi-signature).
|
|
71
|
+
*/
|
|
72
|
+
export declare namespace ConditionMultisigTapscript {
|
|
73
|
+
type Type = ArkTapscript<TapscriptType.ConditionMultisig, Params>;
|
|
74
|
+
type Params = {
|
|
75
|
+
conditionScript: Bytes;
|
|
76
|
+
} & MultisigTapscript.Params;
|
|
77
|
+
function encode(params: Params): Type;
|
|
78
|
+
function decode(script: Uint8Array): Type;
|
|
79
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Implements an absolute timelock (CLTV) script combined with a forfeit closure.
|
|
83
|
+
* The script requires waiting until a specific block height/timestamp before the
|
|
84
|
+
* forfeit closure conditions can be met.
|
|
85
|
+
*/
|
|
86
|
+
export declare namespace CLTVMultisigTapscript {
|
|
87
|
+
type Type = ArkTapscript<TapscriptType.CLTVMultisig, Params>;
|
|
88
|
+
type Params = {
|
|
89
|
+
absoluteTimelock: bigint;
|
|
90
|
+
} & MultisigTapscript.Params;
|
|
91
|
+
function encode(params: Params): Type;
|
|
92
|
+
function decode(script: Uint8Array): Type;
|
|
93
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
94
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
import { RelativeTimelock } from "./tapscript";
|
|
3
|
+
import { TapLeafScript, VtxoScript } from "./base";
|
|
4
|
+
export declare namespace VHTLC {
|
|
5
|
+
interface Options {
|
|
6
|
+
sender: Bytes;
|
|
7
|
+
receiver: Bytes;
|
|
8
|
+
server: Bytes;
|
|
9
|
+
preimageHash: Bytes;
|
|
10
|
+
refundLocktime: bigint;
|
|
11
|
+
unilateralClaimDelay: RelativeTimelock;
|
|
12
|
+
unilateralRefundDelay: RelativeTimelock;
|
|
13
|
+
unilateralRefundWithoutReceiverDelay: RelativeTimelock;
|
|
14
|
+
}
|
|
15
|
+
class Script extends VtxoScript {
|
|
16
|
+
readonly options: Options;
|
|
17
|
+
readonly claimScript: string;
|
|
18
|
+
readonly refundScript: string;
|
|
19
|
+
readonly refundWithoutReceiverScript: string;
|
|
20
|
+
readonly unilateralClaimScript: string;
|
|
21
|
+
readonly unilateralRefundScript: string;
|
|
22
|
+
readonly unilateralRefundWithoutReceiverScript: string;
|
|
23
|
+
constructor(options: Options);
|
|
24
|
+
claim(): TapLeafScript;
|
|
25
|
+
refund(): TapLeafScript;
|
|
26
|
+
refundWithoutReceiver(): TapLeafScript;
|
|
27
|
+
unilateralClaim(): TapLeafScript;
|
|
28
|
+
unilateralRefund(): TapLeafScript;
|
|
29
|
+
unilateralRefundWithoutReceiver(): TapLeafScript;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as musig2 from "../musig2";
|
|
2
|
+
import { TxTree } from "./vtxoTree";
|
|
3
|
+
export declare const ErrMissingVtxoTree: Error;
|
|
4
|
+
export declare const ErrMissingAggregateKey: Error;
|
|
5
|
+
export type TreeNonces = (Pick<musig2.Nonces, "pubNonce"> | null)[][];
|
|
6
|
+
export type TreePartialSigs = (musig2.PartialSig | null)[][];
|
|
7
|
+
export interface SignerSession {
|
|
8
|
+
getPublicKey(): Uint8Array;
|
|
9
|
+
init(tree: TxTree, scriptRoot: Uint8Array, rootInputAmount: bigint): void;
|
|
10
|
+
getNonces(): TreeNonces;
|
|
11
|
+
setAggregatedNonces(nonces: TreeNonces): void;
|
|
12
|
+
sign(): TreePartialSigs;
|
|
13
|
+
}
|
|
14
|
+
export declare class TreeSignerSession implements SignerSession {
|
|
15
|
+
private secretKey;
|
|
16
|
+
static NOT_INITIALIZED: Error;
|
|
17
|
+
private myNonces;
|
|
18
|
+
private aggregateNonces;
|
|
19
|
+
private tree;
|
|
20
|
+
private scriptRoot;
|
|
21
|
+
private rootSharedOutputAmount;
|
|
22
|
+
constructor(secretKey: Uint8Array);
|
|
23
|
+
static random(): TreeSignerSession;
|
|
24
|
+
init(tree: TxTree, scriptRoot: Uint8Array, rootInputAmount: bigint): void;
|
|
25
|
+
getPublicKey(): Uint8Array;
|
|
26
|
+
getNonces(): TreeNonces;
|
|
27
|
+
setAggregatedNonces(nonces: TreeNonces): void;
|
|
28
|
+
sign(): TreePartialSigs;
|
|
29
|
+
private generateNonces;
|
|
30
|
+
private signPartial;
|
|
31
|
+
}
|
|
32
|
+
export declare function validateTreeSigs(finalAggregatedKey: Uint8Array, sharedOutputAmount: bigint, vtxoTree: TxTree): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TxTree, TxTreeError } from "./vtxoTree";
|
|
2
|
+
export declare const ErrInvalidSettlementTx: TxTreeError;
|
|
3
|
+
export declare const ErrInvalidSettlementTxOutputs: TxTreeError;
|
|
4
|
+
export declare const ErrEmptyTree: TxTreeError;
|
|
5
|
+
export declare const ErrInvalidRootLevel: TxTreeError;
|
|
6
|
+
export declare const ErrNumberOfInputs: TxTreeError;
|
|
7
|
+
export declare const ErrWrongSettlementTxid: TxTreeError;
|
|
8
|
+
export declare const ErrInvalidAmount: TxTreeError;
|
|
9
|
+
export declare const ErrNoLeaves: TxTreeError;
|
|
10
|
+
export declare const ErrNodeTxEmpty: TxTreeError;
|
|
11
|
+
export declare const ErrNodeTxidEmpty: TxTreeError;
|
|
12
|
+
export declare const ErrNodeParentTxidEmpty: TxTreeError;
|
|
13
|
+
export declare const ErrNodeTxidDifferent: TxTreeError;
|
|
14
|
+
export declare const ErrParentTxidInput: TxTreeError;
|
|
15
|
+
export declare const ErrLeafChildren: TxTreeError;
|
|
16
|
+
export declare const ErrInvalidTaprootScript: TxTreeError;
|
|
17
|
+
export declare const ErrInternalKey: TxTreeError;
|
|
18
|
+
export declare const ErrInvalidControlBlock: TxTreeError;
|
|
19
|
+
export declare const ErrInvalidRootTransaction: TxTreeError;
|
|
20
|
+
export declare const ErrInvalidNodeTransaction: TxTreeError;
|
|
21
|
+
export declare function validateConnectorsTree(settlementTxB64: string, connectorsTree: TxTree): void;
|
|
22
|
+
export declare function validateVtxoTree(settlementTx: string, vtxoTree: TxTree, sweepTapTreeRoot: Uint8Array): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { RelativeTimelock } from "../script/tapscript";
|
|
3
|
+
export interface TreeNode {
|
|
4
|
+
txid: string;
|
|
5
|
+
tx: string;
|
|
6
|
+
parentTxid: string;
|
|
7
|
+
leaf: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class TxTreeError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export declare const ErrLeafNotFound: TxTreeError;
|
|
13
|
+
export declare const ErrParentNotFound: TxTreeError;
|
|
14
|
+
export declare class TxTree {
|
|
15
|
+
private tree;
|
|
16
|
+
constructor(tree: TreeNode[][]);
|
|
17
|
+
get levels(): TreeNode[][];
|
|
18
|
+
root(): TreeNode;
|
|
19
|
+
leaves(): TreeNode[];
|
|
20
|
+
children(nodeTxid: string): TreeNode[];
|
|
21
|
+
numberOfNodes(): number;
|
|
22
|
+
branch(vtxoTxid: string): TreeNode[];
|
|
23
|
+
private findParent;
|
|
24
|
+
validate(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function getVtxoTreeExpiry(input: {
|
|
27
|
+
unknown?: {
|
|
28
|
+
key: Uint8Array;
|
|
29
|
+
value: Uint8Array;
|
|
30
|
+
}[];
|
|
31
|
+
}): RelativeTimelock | null;
|
|
32
|
+
export declare function getCosignerKeys(tx: Transaction): Uint8Array[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface BIP21Params {
|
|
2
|
+
address?: string;
|
|
3
|
+
amount?: number;
|
|
4
|
+
label?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
ark?: string;
|
|
7
|
+
sp?: string;
|
|
8
|
+
[key: string]: string | number | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface BIP21ParseResult {
|
|
11
|
+
originalString: string;
|
|
12
|
+
params: BIP21Params;
|
|
13
|
+
}
|
|
14
|
+
export declare enum BIP21Error {
|
|
15
|
+
INVALID_URI = "Invalid BIP21 URI",
|
|
16
|
+
INVALID_ADDRESS = "Invalid address"
|
|
17
|
+
}
|
|
18
|
+
export declare class BIP21 {
|
|
19
|
+
static create(params: BIP21Params): string;
|
|
20
|
+
static parse(uri: string): BIP21ParseResult;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Coin, VirtualCoin } from "../wallet";
|
|
2
|
+
/**
|
|
3
|
+
* Select coins to reach a target amount, prioritizing those closer to expiry
|
|
4
|
+
* @param coins List of coins to select from
|
|
5
|
+
* @param targetAmount Target amount to reach in satoshis
|
|
6
|
+
* @returns Selected coins and change amount, or null if insufficient funds
|
|
7
|
+
*/
|
|
8
|
+
export declare function selectCoins(coins: Coin[], targetAmount: number): {
|
|
9
|
+
inputs: Coin[] | null;
|
|
10
|
+
changeAmount: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Select virtual coins to reach a target amount, prioritizing those closer to expiry
|
|
14
|
+
* @param coins List of virtual coins to select from
|
|
15
|
+
* @param targetAmount Target amount to reach in satoshis
|
|
16
|
+
* @returns Selected coins and change amount, or null if insufficient funds
|
|
17
|
+
*/
|
|
18
|
+
export declare function selectVirtualCoins(coins: VirtualCoin[], targetAmount: number): {
|
|
19
|
+
inputs: VirtualCoin[] | null;
|
|
20
|
+
changeAmount: number;
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { VirtualCoin } from "../wallet";
|
|
3
|
+
import { Output } from "../providers/ark";
|
|
4
|
+
import { EncodedVtxoScript, TapLeafScript } from "../script/base";
|
|
5
|
+
export declare const CONDITION_WITNESS_KEY_PREFIX: Uint8Array<ArrayBufferLike>;
|
|
6
|
+
export declare const VTXO_TAPROOT_TREE_KEY_PREFIX: Uint8Array<ArrayBufferLike>;
|
|
7
|
+
export declare function addVtxoTaprootTree(inIndex: number, tx: Transaction, scripts: Uint8Array[]): void;
|
|
8
|
+
export declare function addConditionWitness(inIndex: number, tx: Transaction, witness: Uint8Array[]): void;
|
|
9
|
+
export declare function createVirtualTx(inputs: ({
|
|
10
|
+
tapLeafScript: TapLeafScript;
|
|
11
|
+
} & EncodedVtxoScript & Pick<VirtualCoin, "txid" | "vout" | "value">)[], outputs: Output[]): Transaction;
|