@arkade-os/sdk 0.1.4 → 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 -454
- 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 -461
- 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 -25
- 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,11 +1,14 @@
|
|
|
1
1
|
import type { NetworkName } from "../networks";
|
|
2
2
|
import { Coin } from "../wallet";
|
|
3
|
+
/**
|
|
4
|
+
* The default base URLs for esplora API providers.
|
|
5
|
+
*/
|
|
3
6
|
export declare const ESPLORA_URL: Record<NetworkName, string>;
|
|
4
7
|
export type ExplorerTransaction = {
|
|
5
8
|
txid: string;
|
|
6
9
|
vout: {
|
|
7
10
|
scriptpubkey_address: string;
|
|
8
|
-
value:
|
|
11
|
+
value: string;
|
|
9
12
|
}[];
|
|
10
13
|
status: {
|
|
11
14
|
confirmed: boolean;
|
|
@@ -14,33 +17,60 @@ export type ExplorerTransaction = {
|
|
|
14
17
|
};
|
|
15
18
|
export interface OnchainProvider {
|
|
16
19
|
getCoins(address: string): Promise<Coin[]>;
|
|
17
|
-
getFeeRate(): Promise<number>;
|
|
18
|
-
broadcastTransaction(
|
|
20
|
+
getFeeRate(): Promise<number | undefined>;
|
|
21
|
+
broadcastTransaction(...txs: string[]): Promise<string>;
|
|
19
22
|
getTxOutspends(txid: string): Promise<{
|
|
20
23
|
spent: boolean;
|
|
21
24
|
txid: string;
|
|
22
25
|
}[]>;
|
|
23
26
|
getTransactions(address: string): Promise<ExplorerTransaction[]>;
|
|
24
27
|
getTxStatus(txid: string): Promise<{
|
|
25
|
-
confirmed:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
confirmed: false;
|
|
29
|
+
} | {
|
|
30
|
+
confirmed: true;
|
|
31
|
+
blockTime: number;
|
|
32
|
+
blockHeight: number;
|
|
33
|
+
}>;
|
|
34
|
+
getChainTip(): Promise<{
|
|
35
|
+
height: number;
|
|
36
|
+
time: number;
|
|
37
|
+
hash: string;
|
|
28
38
|
}>;
|
|
39
|
+
watchAddresses(addresses: string[], eventCallback: (txs: ExplorerTransaction[]) => void): Promise<() => void>;
|
|
29
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Implementation of the onchain provider interface for esplora REST API.
|
|
43
|
+
* @see https://mempool.space/docs/api/rest
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const provider = new EsploraProvider("https://mempool.space/api");
|
|
47
|
+
* const utxos = await provider.getCoins("bcrt1q679zsd45msawvr7782r0twvmukns3drlstjt77");
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
30
50
|
export declare class EsploraProvider implements OnchainProvider {
|
|
31
51
|
private baseUrl;
|
|
32
52
|
constructor(baseUrl: string);
|
|
33
53
|
getCoins(address: string): Promise<Coin[]>;
|
|
34
|
-
getFeeRate(): Promise<number>;
|
|
35
|
-
broadcastTransaction(
|
|
54
|
+
getFeeRate(): Promise<number | undefined>;
|
|
55
|
+
broadcastTransaction(...txs: string[]): Promise<string>;
|
|
36
56
|
getTxOutspends(txid: string): Promise<{
|
|
37
57
|
spent: boolean;
|
|
38
58
|
txid: string;
|
|
39
59
|
}[]>;
|
|
40
60
|
getTransactions(address: string): Promise<ExplorerTransaction[]>;
|
|
41
61
|
getTxStatus(txid: string): Promise<{
|
|
42
|
-
confirmed:
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
confirmed: false;
|
|
63
|
+
} | {
|
|
64
|
+
confirmed: true;
|
|
65
|
+
blockTime: number;
|
|
66
|
+
blockHeight: number;
|
|
67
|
+
}>;
|
|
68
|
+
watchAddresses(addresses: string[], callback: (txs: ExplorerTransaction[]) => void): Promise<() => void>;
|
|
69
|
+
getChainTip(): Promise<{
|
|
70
|
+
height: number;
|
|
71
|
+
time: number;
|
|
72
|
+
hash: string;
|
|
45
73
|
}>;
|
|
74
|
+
private broadcastPackage;
|
|
75
|
+
private broadcastTx;
|
|
46
76
|
}
|
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
/**
|
|
3
|
+
* ArkAddress allows to create and decode bech32m encoded ark address.
|
|
4
|
+
* An ark address is composed of:
|
|
5
|
+
* - a human readable prefix (hrp)
|
|
6
|
+
* - a version byte (1 byte)
|
|
7
|
+
* - a server public key (32 bytes)
|
|
8
|
+
* - a vtxo taproot public key (32 bytes)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const address = new ArkAddress(
|
|
13
|
+
* new Uint8Array(32), // server public key
|
|
14
|
+
* new Uint8Array(32), // vtxo taproot public key
|
|
15
|
+
* "ark"
|
|
16
|
+
* );
|
|
17
|
+
*
|
|
18
|
+
* const encoded = address.encode();
|
|
19
|
+
* console.log("address: ", encoded);
|
|
20
|
+
*
|
|
21
|
+
* const decoded = ArkAddress.decode(encoded);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
2
24
|
export declare class ArkAddress {
|
|
3
25
|
readonly serverPubKey: Bytes;
|
|
4
|
-
readonly
|
|
26
|
+
readonly vtxoTaprootKey: Bytes;
|
|
5
27
|
readonly hrp: string;
|
|
6
|
-
|
|
28
|
+
readonly version: number;
|
|
29
|
+
constructor(serverPubKey: Bytes, vtxoTaprootKey: Bytes, hrp: string, version?: number);
|
|
7
30
|
static decode(address: string): ArkAddress;
|
|
8
31
|
encode(): string;
|
|
9
32
|
get pkScript(): Bytes;
|
|
33
|
+
get subdustPkScript(): Bytes;
|
|
10
34
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BTC_NETWORK, Bytes } from "@scure/btc-signer/utils";
|
|
2
2
|
import { ArkAddress } from "./address";
|
|
3
|
+
import { ConditionCSVMultisigTapscript, CSVMultisigTapscript } from "./tapscript";
|
|
3
4
|
export type TapLeafScript = [
|
|
4
5
|
{
|
|
5
6
|
version: number;
|
|
@@ -9,18 +10,27 @@ export type TapLeafScript = [
|
|
|
9
10
|
Bytes
|
|
10
11
|
];
|
|
11
12
|
export declare function scriptFromTapLeafScript(leaf: TapLeafScript): Bytes;
|
|
13
|
+
/**
|
|
14
|
+
* VtxoScript is a script that contains a list of tapleaf scripts.
|
|
15
|
+
* It is used to create vtxo scripts.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const vtxoScript = new VtxoScript([new Uint8Array(32), new Uint8Array(32)]);
|
|
20
|
+
*/
|
|
12
21
|
export declare class VtxoScript {
|
|
13
22
|
readonly scripts: Bytes[];
|
|
14
23
|
readonly leaves: TapLeafScript[];
|
|
15
24
|
readonly tweakedPublicKey: Bytes;
|
|
16
|
-
static decode(
|
|
25
|
+
static decode(tapTree: Bytes): VtxoScript;
|
|
17
26
|
constructor(scripts: Bytes[]);
|
|
18
|
-
encode():
|
|
27
|
+
encode(): Bytes;
|
|
19
28
|
address(prefix: string, serverPubKey: Bytes): ArkAddress;
|
|
20
29
|
get pkScript(): Bytes;
|
|
21
30
|
onchainAddress(network: BTC_NETWORK): string;
|
|
22
31
|
findLeaf(scriptHex: string): TapLeafScript;
|
|
32
|
+
exitPaths(): Array<CSVMultisigTapscript.Type | ConditionCSVMultisigTapscript.Type>;
|
|
23
33
|
}
|
|
24
34
|
export type EncodedVtxoScript = {
|
|
25
|
-
|
|
35
|
+
tapTree: Bytes;
|
|
26
36
|
};
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
2
|
import { TapLeafScript, VtxoScript } from "./base";
|
|
3
3
|
import { RelativeTimelock } from "./tapscript";
|
|
4
|
+
/**
|
|
5
|
+
* DefaultVtxo is the default implementation of a VtxoScript.
|
|
6
|
+
* It contains 1 forfeit path and 1 exit path.
|
|
7
|
+
* - forfeit = (Alice + Server)
|
|
8
|
+
* - exit = (Alice) after csvTimelock
|
|
9
|
+
*/
|
|
4
10
|
export declare namespace DefaultVtxo {
|
|
11
|
+
/**
|
|
12
|
+
* Options is the options for the DefaultVtxo.Script class.
|
|
13
|
+
* csvTimelock is the exit path timelock, default is 144 blocks (1 day).
|
|
14
|
+
*/
|
|
5
15
|
interface Options {
|
|
6
16
|
pubKey: Bytes;
|
|
7
17
|
serverPubKey: Bytes;
|
|
8
18
|
csvTimelock?: RelativeTimelock;
|
|
9
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* DefaultVtxo.Script is the class letting to create the vtxo script.
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const vtxoScript = new DefaultVtxo.Script({
|
|
25
|
+
* pubKey: new Uint8Array(32),
|
|
26
|
+
* serverPubKey: new Uint8Array(32),
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* console.log("script pub key:", vtxoScript.pkScript)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
10
32
|
class Script extends VtxoScript {
|
|
11
33
|
readonly options: Options;
|
|
12
34
|
static readonly DEFAULT_TIMELOCK: RelativeTimelock;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
|
+
/**
|
|
3
|
+
* RelativeTimelock lets to create timelocked with CHECKSEQUENCEVERIFY script.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const timelock = { value: 144n, type: "blocks" }; // 1 day in blocks
|
|
8
|
+
* const timelock = { value: 512n, type: "seconds" }; // 8 minutes in seconds
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
2
11
|
export type RelativeTimelock = {
|
|
3
12
|
value: bigint;
|
|
4
13
|
type: "seconds" | "blocks";
|
|
@@ -10,16 +19,35 @@ export declare enum TapscriptType {
|
|
|
10
19
|
ConditionMultisig = "condition-multisig",
|
|
11
20
|
CLTVMultisig = "cltv-multisig"
|
|
12
21
|
}
|
|
13
|
-
|
|
22
|
+
/**
|
|
23
|
+
* ArkTapscript is the base element of vtxo scripts.
|
|
24
|
+
* It is used to encode and decode the different types of vtxo scripts.
|
|
25
|
+
*/
|
|
26
|
+
export interface ArkTapscript<T extends TapscriptType, Params> {
|
|
14
27
|
type: T;
|
|
15
28
|
params: Params;
|
|
16
29
|
script: Uint8Array;
|
|
17
|
-
witnessSize(args: SizeArgs): number;
|
|
18
30
|
}
|
|
19
|
-
export declare function decodeTapscript(script: Uint8Array): ArkTapscript<TapscriptType, any, any | undefined>;
|
|
20
31
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
32
|
+
* decodeTapscript is a function that decodes an ark tapsript from a raw script.
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} if the script is not a valid ark tapscript
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const arkTapscript = decodeTapscript(new Uint8Array(32));
|
|
38
|
+
* console.log("type:", arkTapscript.type);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function decodeTapscript(script: Uint8Array): ArkTapscript<TapscriptType, any>;
|
|
42
|
+
/**
|
|
43
|
+
* Implements a multi-signature tapscript.
|
|
44
|
+
*
|
|
45
|
+
* <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const multisigTapscript = MultisigTapscript.encode({ pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
50
|
+
* ```
|
|
23
51
|
*/
|
|
24
52
|
export declare namespace MultisigTapscript {
|
|
25
53
|
type Type = ArkTapscript<TapscriptType.Multisig, Params>;
|
|
@@ -40,6 +68,13 @@ export declare namespace MultisigTapscript {
|
|
|
40
68
|
* after the relative timelock has expired. The timelock can be specified in blocks or seconds.
|
|
41
69
|
*
|
|
42
70
|
* This is the standard exit closure and it is also used for the sweep closure in vtxo trees.
|
|
71
|
+
*
|
|
72
|
+
* <sequence> CHECKSEQUENCEVERIFY DROP <pubkey> CHECKSIG
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const csvMultisigTapscript = CSVMultisigTapscript.encode({ timelock: { type: "blocks", value: 144 }, pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
77
|
+
* ```
|
|
43
78
|
*/
|
|
44
79
|
export declare namespace CSVMultisigTapscript {
|
|
45
80
|
type Type = ArkTapscript<TapscriptType.CSVMultisig, Params>;
|
|
@@ -54,6 +89,13 @@ export declare namespace CSVMultisigTapscript {
|
|
|
54
89
|
* Combines a condition script with an exit closure. The resulting script requires
|
|
55
90
|
* the condition to be met, followed by the standard exit closure requirements
|
|
56
91
|
* (timelock and signatures).
|
|
92
|
+
*
|
|
93
|
+
* <conditionScript> VERIFY <sequence> CHECKSEQUENCEVERIFY DROP <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const conditionCSVMultisigTapscript = ConditionCSVMultisigTapscript.encode({ conditionScript: new Uint8Array(32), pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
98
|
+
* ```
|
|
57
99
|
*/
|
|
58
100
|
export declare namespace ConditionCSVMultisigTapscript {
|
|
59
101
|
type Type = ArkTapscript<TapscriptType.ConditionCSVMultisig, Params>;
|
|
@@ -68,6 +110,13 @@ export declare namespace ConditionCSVMultisigTapscript {
|
|
|
68
110
|
* Combines a condition script with a forfeit closure. The resulting script requires
|
|
69
111
|
* the condition to be met, followed by the standard forfeit closure requirements
|
|
70
112
|
* (multi-signature).
|
|
113
|
+
*
|
|
114
|
+
* <conditionScript> VERIFY <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const conditionMultisigTapscript = ConditionMultisigTapscript.encode({ conditionScript: new Uint8Array(32), pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
119
|
+
* ```
|
|
71
120
|
*/
|
|
72
121
|
export declare namespace ConditionMultisigTapscript {
|
|
73
122
|
type Type = ArkTapscript<TapscriptType.ConditionMultisig, Params>;
|
|
@@ -82,6 +131,13 @@ export declare namespace ConditionMultisigTapscript {
|
|
|
82
131
|
* Implements an absolute timelock (CLTV) script combined with a forfeit closure.
|
|
83
132
|
* The script requires waiting until a specific block height/timestamp before the
|
|
84
133
|
* forfeit closure conditions can be met.
|
|
134
|
+
*
|
|
135
|
+
* <locktime> CHECKLOCKTIMEVERIFY DROP <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const cltvMultisigTapscript = CLTVMultisigTapscript.encode({ absoluteTimelock: 144, pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
140
|
+
* ```
|
|
85
141
|
*/
|
|
86
142
|
export declare namespace CLTVMultisigTapscript {
|
|
87
143
|
type Type = ArkTapscript<TapscriptType.CLTVMultisig, Params>;
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import { Bytes } from "@scure/btc-signer/utils";
|
|
2
2
|
import { RelativeTimelock } from "./tapscript";
|
|
3
3
|
import { TapLeafScript, VtxoScript } from "./base";
|
|
4
|
+
/**
|
|
5
|
+
* Virtual Hash Time Lock Contract (VHTLC) implementation.
|
|
6
|
+
*
|
|
7
|
+
* VHTLC is a contract that enables atomic swaps and conditional payments
|
|
8
|
+
* in the Ark protocol. It provides multiple spending paths:
|
|
9
|
+
*
|
|
10
|
+
* - **claim**: Receiver can claim funds by revealing the preimage
|
|
11
|
+
* - **refund**: Sender and receiver can collaboratively refund
|
|
12
|
+
* - **refundWithoutReceiver**: Sender can refund after locktime expires
|
|
13
|
+
* - **unilateralClaim**: Receiver can claim unilaterally after delay
|
|
14
|
+
* - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
|
|
15
|
+
* - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const vhtlc = new VHTLC.Script({
|
|
20
|
+
* sender: alicePubKey,
|
|
21
|
+
* receiver: bobPubKey,
|
|
22
|
+
* server: serverPubKey,
|
|
23
|
+
* preimageHash: hash160(secret),
|
|
24
|
+
* refundLocktime: BigInt(chainTip + 10),
|
|
25
|
+
* unilateralClaimDelay: { type: 'blocks', value: 100n },
|
|
26
|
+
* unilateralRefundDelay: { type: 'blocks', value: 102n },
|
|
27
|
+
* unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
4
31
|
export declare namespace VHTLC {
|
|
5
32
|
interface Options {
|
|
6
33
|
sender: Bytes;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as musig2 from "../musig2";
|
|
2
|
-
import { TxTree } from "./
|
|
3
|
-
export declare const
|
|
2
|
+
import { TxTree } from "./txTree";
|
|
3
|
+
export declare const ErrMissingVtxoGraph: Error;
|
|
4
4
|
export declare const ErrMissingAggregateKey: Error;
|
|
5
|
-
export type TreeNonces =
|
|
6
|
-
export type TreePartialSigs =
|
|
5
|
+
export type TreeNonces = Map<string, Pick<musig2.Nonces, "pubNonce">>;
|
|
6
|
+
export type TreePartialSigs = Map<string, musig2.PartialSig>;
|
|
7
7
|
export interface SignerSession {
|
|
8
8
|
getPublicKey(): Uint8Array;
|
|
9
9
|
init(tree: TxTree, scriptRoot: Uint8Array, rootInputAmount: bigint): void;
|
|
@@ -16,7 +16,7 @@ export declare class TreeSignerSession implements SignerSession {
|
|
|
16
16
|
static NOT_INITIALIZED: Error;
|
|
17
17
|
private myNonces;
|
|
18
18
|
private aggregateNonces;
|
|
19
|
-
private
|
|
19
|
+
private graph;
|
|
20
20
|
private scriptRoot;
|
|
21
21
|
private rootSharedOutputAmount;
|
|
22
22
|
constructor(secretKey: Uint8Array);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
/**
|
|
3
|
+
* TxTreeNode is a node of the tree.
|
|
4
|
+
* It contains the transaction id, the transaction and the children.
|
|
5
|
+
* any TxTree can be serialized as a list of TxTreeNode.
|
|
6
|
+
*/
|
|
7
|
+
export type TxTreeNode = {
|
|
8
|
+
txid: string;
|
|
9
|
+
tx: string;
|
|
10
|
+
children: Record<number, string>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* TxTree is a graph of bitcoin transactions.
|
|
14
|
+
* It is used to represent batch tree created during settlement session
|
|
15
|
+
*/
|
|
16
|
+
export declare class TxTree implements Iterable<TxTree> {
|
|
17
|
+
readonly root: Transaction;
|
|
18
|
+
readonly children: Map<number, TxTree>;
|
|
19
|
+
constructor(root: Transaction, children?: Map<number, TxTree>);
|
|
20
|
+
static create(chunks: TxTreeNode[]): TxTree;
|
|
21
|
+
nbOfNodes(): number;
|
|
22
|
+
validate(): void;
|
|
23
|
+
leaves(): Transaction[];
|
|
24
|
+
get txid(): string;
|
|
25
|
+
find(txid: string): TxTree | null;
|
|
26
|
+
update(txid: string, fn: (tx: Transaction) => void): void;
|
|
27
|
+
[Symbol.iterator](): IterableIterator<TxTree>;
|
|
28
|
+
}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const ErrNumberOfInputs:
|
|
7
|
-
export declare const ErrWrongSettlementTxid:
|
|
8
|
-
export declare const ErrInvalidAmount:
|
|
9
|
-
export declare const ErrNoLeaves:
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare
|
|
15
|
-
export declare
|
|
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;
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { TxTree } from "./txTree";
|
|
3
|
+
export declare const ErrInvalidSettlementTx: (tx: string) => Error;
|
|
4
|
+
export declare const ErrInvalidSettlementTxOutputs: Error;
|
|
5
|
+
export declare const ErrEmptyTree: Error;
|
|
6
|
+
export declare const ErrNumberOfInputs: Error;
|
|
7
|
+
export declare const ErrWrongSettlementTxid: Error;
|
|
8
|
+
export declare const ErrInvalidAmount: Error;
|
|
9
|
+
export declare const ErrNoLeaves: Error;
|
|
10
|
+
export declare const ErrInvalidTaprootScript: Error;
|
|
11
|
+
export declare const ErrInvalidRoundTxOutputs: Error;
|
|
12
|
+
export declare const ErrWrongCommitmentTxid: Error;
|
|
13
|
+
export declare const ErrMissingCosignersPublicKeys: Error;
|
|
14
|
+
export declare function validateConnectorsTxGraph(settlementTxB64: string, connectorsGraph: TxTree): void;
|
|
15
|
+
export declare function validateVtxoTxGraph(graph: TxTree, roundTransaction: Transaction, sweepTapTreeRoot: Uint8Array): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { TransactionInputUpdate } from "@scure/btc-signer/psbt";
|
|
3
|
+
export declare const ANCHOR_VALUE = 0n;
|
|
4
|
+
export declare const ANCHOR_PKSCRIPT: Uint8Array<ArrayBuffer>;
|
|
5
|
+
/**
|
|
6
|
+
* A zero-value anchor output.
|
|
7
|
+
*/
|
|
8
|
+
export declare const P2A: {
|
|
9
|
+
script: Uint8Array<ArrayBuffer>;
|
|
10
|
+
amount: bigint;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* search for anchor in the given transaction.
|
|
14
|
+
* @throws {Error} if the anchor is not found or has the wrong amount
|
|
15
|
+
*/
|
|
16
|
+
export declare function findP2AOutput(tx: Transaction): TransactionInputUpdate;
|
|
17
|
+
export interface AnchorBumper {
|
|
18
|
+
bumpP2A(parent: Transaction): Promise<[string, string]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { VirtualCoin } from "../wallet";
|
|
3
|
+
import { EncodedVtxoScript, TapLeafScript } from "../script/base";
|
|
4
|
+
import { CSVMultisigTapscript } from "../script/tapscript";
|
|
5
|
+
import { TransactionOutput } from "@scure/btc-signer/psbt";
|
|
6
|
+
import { Bytes } from "@scure/btc-signer/utils";
|
|
7
|
+
export type ArkTxInput = {
|
|
8
|
+
tapLeafScript: TapLeafScript;
|
|
9
|
+
checkpointTapLeafScript?: Bytes;
|
|
10
|
+
} & EncodedVtxoScript & Pick<VirtualCoin, "txid" | "vout" | "value">;
|
|
11
|
+
export type OffchainTx = {
|
|
12
|
+
arkTx: Transaction;
|
|
13
|
+
checkpoints: Transaction[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Builds an offchain transaction with checkpoint transactions.
|
|
17
|
+
*
|
|
18
|
+
* Creates one checkpoint transaction per input and a virtual transaction that
|
|
19
|
+
* combines all the checkpoints, sending to the specified outputs. This is the
|
|
20
|
+
* core function for creating Ark transactions.
|
|
21
|
+
*
|
|
22
|
+
* @param inputs - Array of virtual transaction inputs
|
|
23
|
+
* @param outputs - Array of transaction outputs
|
|
24
|
+
* @param serverUnrollScript - Server unroll script for checkpoint transactions
|
|
25
|
+
* @returns Object containing the virtual transaction and checkpoint transactions
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildOffchainTx(inputs: ArkTxInput[], outputs: TransactionOutput[], serverUnrollScript: CSVMultisigTapscript.Type): OffchainTx;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { ArkTransaction, VirtualCoin } from "../wallet";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @param spendable - Vtxos that are spendable
|
|
4
|
+
* @param spent - Vtxos that are spent
|
|
5
|
+
* @param boardingBatchTxids - Set of boarding batch txids
|
|
6
|
+
* @returns Ark transactions
|
|
7
|
+
*/
|
|
8
|
+
export declare function vtxosToTxs(spendable: VirtualCoin[], spent: VirtualCoin[], boardingBatchTxids: Set<string>): ArkTransaction[];
|
|
@@ -11,6 +11,7 @@ export declare class TxWeightEstimator {
|
|
|
11
11
|
static readonly BASE_TX_SIZE: number;
|
|
12
12
|
static readonly WITNESS_HEADER_SIZE = 2;
|
|
13
13
|
static readonly WITNESS_SCALE_FACTOR = 4;
|
|
14
|
+
static readonly P2TR_OUTPUT_SIZE: number;
|
|
14
15
|
hasWitness: boolean;
|
|
15
16
|
inputCount: number;
|
|
16
17
|
outputCount: number;
|
|
@@ -19,9 +20,11 @@ export declare class TxWeightEstimator {
|
|
|
19
20
|
outputSize: number;
|
|
20
21
|
private constructor();
|
|
21
22
|
static create(): TxWeightEstimator;
|
|
23
|
+
addP2AInput(): TxWeightEstimator;
|
|
22
24
|
addKeySpendInput(isDefault?: boolean): TxWeightEstimator;
|
|
23
25
|
addP2PKHInput(): TxWeightEstimator;
|
|
24
26
|
addTapscriptInput(leafWitnessSize: number, leafScriptSize: number, leafControlBlockSize: number): TxWeightEstimator;
|
|
25
27
|
addP2WKHOutput(): TxWeightEstimator;
|
|
28
|
+
addP2TROutput(): TxWeightEstimator;
|
|
26
29
|
vsize(): VSize;
|
|
27
30
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Transaction } from "@scure/btc-signer";
|
|
2
|
+
import { TransactionInputUpdate } from "@scure/btc-signer/psbt";
|
|
3
|
+
/**
|
|
4
|
+
* ArkPsbtFieldKey is the key values for ark psbt fields.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ArkPsbtFieldKey {
|
|
7
|
+
VtxoTaprootTree = "taptree",
|
|
8
|
+
VtxoTreeExpiry = "expiry",
|
|
9
|
+
Cosigner = "cosigner",
|
|
10
|
+
ConditionWitness = "condition"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* ArkPsbtFieldKeyType is the type of the ark psbt field key.
|
|
14
|
+
* Every ark psbt field has key type 255.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ArkPsbtFieldKeyType = 255;
|
|
17
|
+
/**
|
|
18
|
+
* ArkPsbtFieldCoder is the coder for the ark psbt fields.
|
|
19
|
+
* each type has its own coder.
|
|
20
|
+
*/
|
|
21
|
+
export interface ArkPsbtFieldCoder<T> {
|
|
22
|
+
key: ArkPsbtFieldKey;
|
|
23
|
+
encode: (value: T) => NonNullable<TransactionInputUpdate["unknown"]>[number];
|
|
24
|
+
decode: (value: NonNullable<TransactionInputUpdate["unknown"]>[number]) => T | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* setArkPsbtField appends a new unknown field to the input at inputIndex
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* setArkPsbtField(tx, 0, VtxoTaprootTree, myTaprootTree);
|
|
32
|
+
* setArkPsbtField(tx, 0, VtxoTreeExpiry, myVtxoTreeExpiry);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function setArkPsbtField<T>(tx: Transaction, inputIndex: number, coder: ArkPsbtFieldCoder<T>, value: T): void;
|
|
36
|
+
/**
|
|
37
|
+
* getArkPsbtFields returns all the values of the given coder for the input at inputIndex
|
|
38
|
+
* Multiple fields of the same type can exist in a single input.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const vtxoTaprootTreeFields = getArkPsbtFields(tx, 0, VtxoTaprootTree);
|
|
43
|
+
* console.log(`input has ${vtxoTaprootTreeFields.length} vtxoTaprootTree fields`);
|
|
44
|
+
*/
|
|
45
|
+
export declare function getArkPsbtFields<T>(tx: Transaction, inputIndex: number, coder: ArkPsbtFieldCoder<T>): T[];
|
|
46
|
+
/**
|
|
47
|
+
* VtxoTaprootTree is set to pass all spending leaves of the vtxo input
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const vtxoTaprootTree = VtxoTaprootTree.encode(myTaprootTree);
|
|
52
|
+
*/
|
|
53
|
+
export declare const VtxoTaprootTree: ArkPsbtFieldCoder<Uint8Array>;
|
|
54
|
+
/**
|
|
55
|
+
* ConditionWitness is set to pass the witness data used to finalize the conditionMultisigClosure
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const conditionWitness = ConditionWitness.encode(myConditionWitness);
|
|
60
|
+
*/
|
|
61
|
+
export declare const ConditionWitness: ArkPsbtFieldCoder<Uint8Array[]>;
|
|
62
|
+
/**
|
|
63
|
+
* CosignerPublicKey is set on every TxGraph transactions to identify the musig2 public keys
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const cosignerPublicKey = CosignerPublicKey.encode(myCosignerPublicKey);
|
|
68
|
+
*/
|
|
69
|
+
export declare const CosignerPublicKey: ArkPsbtFieldCoder<{
|
|
70
|
+
index: number;
|
|
71
|
+
key: Uint8Array;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* VtxoTreeExpiry is set to pass the expiry time of the input
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const vtxoTreeExpiry = VtxoTreeExpiry.encode(myVtxoTreeExpiry);
|
|
79
|
+
*/
|
|
80
|
+
export declare const VtxoTreeExpiry: ArkPsbtFieldCoder<{
|
|
81
|
+
type: "blocks" | "seconds";
|
|
82
|
+
value: bigint;
|
|
83
|
+
}>;
|