@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,27 @@
|
|
|
1
|
+
export type VSize = {
|
|
2
|
+
value: bigint;
|
|
3
|
+
fee(feeRate: bigint): bigint;
|
|
4
|
+
};
|
|
5
|
+
export declare class TxWeightEstimator {
|
|
6
|
+
static readonly P2PKH_SCRIPT_SIG_SIZE: number;
|
|
7
|
+
static readonly INPUT_SIZE: number;
|
|
8
|
+
static readonly BASE_CONTROL_BLOCK_SIZE: number;
|
|
9
|
+
static readonly OUTPUT_SIZE: number;
|
|
10
|
+
static readonly P2WKH_OUTPUT_SIZE: number;
|
|
11
|
+
static readonly BASE_TX_SIZE: number;
|
|
12
|
+
static readonly WITNESS_HEADER_SIZE = 2;
|
|
13
|
+
static readonly WITNESS_SCALE_FACTOR = 4;
|
|
14
|
+
hasWitness: boolean;
|
|
15
|
+
inputCount: number;
|
|
16
|
+
outputCount: number;
|
|
17
|
+
inputSize: number;
|
|
18
|
+
inputWitnessSize: number;
|
|
19
|
+
outputSize: number;
|
|
20
|
+
private constructor();
|
|
21
|
+
static create(): TxWeightEstimator;
|
|
22
|
+
addKeySpendInput(isDefault?: boolean): TxWeightEstimator;
|
|
23
|
+
addP2PKHInput(): TxWeightEstimator;
|
|
24
|
+
addTapscriptInput(leafWitnessSize: number, leafScriptSize: number, leafControlBlockSize: number): TxWeightEstimator;
|
|
25
|
+
addP2WKHOutput(): TxWeightEstimator;
|
|
26
|
+
vsize(): VSize;
|
|
27
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Output, SettlementEvent } from "../providers/ark";
|
|
2
|
+
import { Identity } from "../identity";
|
|
3
|
+
import { NetworkName } from "../networks";
|
|
4
|
+
import { RelativeTimelock } from "../script/tapscript";
|
|
5
|
+
import { EncodedVtxoScript, TapLeafScript } from "../script/base";
|
|
6
|
+
export interface WalletConfig {
|
|
7
|
+
network: NetworkName;
|
|
8
|
+
identity: Identity;
|
|
9
|
+
esploraUrl?: string;
|
|
10
|
+
arkServerUrl?: string;
|
|
11
|
+
arkServerPublicKey?: string;
|
|
12
|
+
boardingTimelock?: RelativeTimelock;
|
|
13
|
+
exitTimelock?: RelativeTimelock;
|
|
14
|
+
}
|
|
15
|
+
export interface WalletBalance {
|
|
16
|
+
onchain: {
|
|
17
|
+
confirmed: number;
|
|
18
|
+
unconfirmed: number;
|
|
19
|
+
total: number;
|
|
20
|
+
};
|
|
21
|
+
offchain: {
|
|
22
|
+
swept: number;
|
|
23
|
+
settled: number;
|
|
24
|
+
pending: number;
|
|
25
|
+
total: number;
|
|
26
|
+
};
|
|
27
|
+
total: number;
|
|
28
|
+
}
|
|
29
|
+
export interface SendBitcoinParams {
|
|
30
|
+
address: string;
|
|
31
|
+
amount: number;
|
|
32
|
+
feeRate?: number;
|
|
33
|
+
memo?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface Recipient {
|
|
36
|
+
address: string;
|
|
37
|
+
amount: number;
|
|
38
|
+
}
|
|
39
|
+
export interface SettleParams {
|
|
40
|
+
inputs: (string | ({
|
|
41
|
+
tapLeafScript: TapLeafScript;
|
|
42
|
+
} & Outpoint & EncodedVtxoScript))[];
|
|
43
|
+
outputs: Output[];
|
|
44
|
+
}
|
|
45
|
+
export interface VtxoTaprootAddress {
|
|
46
|
+
address: string;
|
|
47
|
+
scripts: {
|
|
48
|
+
exit: string[];
|
|
49
|
+
forfeit: string[];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface AddressInfo {
|
|
53
|
+
offchain: VtxoTaprootAddress;
|
|
54
|
+
boarding: VtxoTaprootAddress;
|
|
55
|
+
}
|
|
56
|
+
export interface Addresses {
|
|
57
|
+
onchain: string;
|
|
58
|
+
offchain?: string;
|
|
59
|
+
boarding?: string;
|
|
60
|
+
bip21: string;
|
|
61
|
+
}
|
|
62
|
+
export interface TapscriptInfo {
|
|
63
|
+
offchain?: string[];
|
|
64
|
+
boarding?: string[];
|
|
65
|
+
}
|
|
66
|
+
export interface Status {
|
|
67
|
+
confirmed: boolean;
|
|
68
|
+
block_height?: number;
|
|
69
|
+
block_hash?: string;
|
|
70
|
+
block_time?: number;
|
|
71
|
+
}
|
|
72
|
+
export interface VirtualStatus {
|
|
73
|
+
state: "pending" | "settled" | "swept" | "spent";
|
|
74
|
+
batchTxID?: string;
|
|
75
|
+
batchExpiry?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface Outpoint {
|
|
78
|
+
txid: string;
|
|
79
|
+
vout: number;
|
|
80
|
+
}
|
|
81
|
+
export interface Coin extends Outpoint {
|
|
82
|
+
value: number;
|
|
83
|
+
status: Status;
|
|
84
|
+
}
|
|
85
|
+
export interface VirtualCoin extends Coin {
|
|
86
|
+
virtualStatus: VirtualStatus;
|
|
87
|
+
spentBy?: string;
|
|
88
|
+
createdAt: Date;
|
|
89
|
+
}
|
|
90
|
+
export declare enum TxType {
|
|
91
|
+
TxSent = "SENT",
|
|
92
|
+
TxReceived = "RECEIVED"
|
|
93
|
+
}
|
|
94
|
+
export interface TxKey {
|
|
95
|
+
boardingTxid: string;
|
|
96
|
+
roundTxid: string;
|
|
97
|
+
redeemTxid: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ArkTransaction {
|
|
100
|
+
key: TxKey;
|
|
101
|
+
type: TxType;
|
|
102
|
+
amount: number;
|
|
103
|
+
settled: boolean;
|
|
104
|
+
createdAt: number;
|
|
105
|
+
}
|
|
106
|
+
export type ExtendedCoin = {
|
|
107
|
+
tapLeafScript: TapLeafScript;
|
|
108
|
+
} & EncodedVtxoScript & Coin;
|
|
109
|
+
export type ExtendedVirtualCoin = {
|
|
110
|
+
tapLeafScript: TapLeafScript;
|
|
111
|
+
} & EncodedVtxoScript & VirtualCoin;
|
|
112
|
+
export interface IWallet {
|
|
113
|
+
getAddress(): Promise<Addresses>;
|
|
114
|
+
getAddressInfo(): Promise<AddressInfo>;
|
|
115
|
+
getBalance(): Promise<WalletBalance>;
|
|
116
|
+
getCoins(): Promise<Coin[]>;
|
|
117
|
+
getVtxos(): Promise<ExtendedVirtualCoin[]>;
|
|
118
|
+
getBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
119
|
+
getTransactionHistory(): Promise<ArkTransaction[]>;
|
|
120
|
+
sendBitcoin(params: SendBitcoinParams, zeroFee?: boolean): Promise<string>;
|
|
121
|
+
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
122
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { VtxoRepository } from ".";
|
|
2
|
+
import { ExtendedVirtualCoin } from "../../..";
|
|
3
|
+
export declare class IndexedDBVtxoRepository implements VtxoRepository {
|
|
4
|
+
static readonly DB_NAME = "wallet-db";
|
|
5
|
+
static readonly STORE_NAME = "vtxos";
|
|
6
|
+
static readonly DB_VERSION = 1;
|
|
7
|
+
static delete(): Promise<void>;
|
|
8
|
+
private db;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
open(): Promise<void>;
|
|
11
|
+
addOrUpdate(vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
12
|
+
deleteAll(): Promise<void>;
|
|
13
|
+
getSpendableVtxos(): Promise<ExtendedVirtualCoin[]>;
|
|
14
|
+
getAllVtxos(): Promise<{
|
|
15
|
+
spendable: ExtendedVirtualCoin[];
|
|
16
|
+
spent: ExtendedVirtualCoin[];
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExtendedVirtualCoin } from "../../../..";
|
|
2
|
+
export interface VtxoRepository {
|
|
3
|
+
addOrUpdate(vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
4
|
+
deleteAll(): Promise<void>;
|
|
5
|
+
getSpendableVtxos(): Promise<ExtendedVirtualCoin[]>;
|
|
6
|
+
getAllVtxos(): Promise<{
|
|
7
|
+
spendable: ExtendedVirtualCoin[];
|
|
8
|
+
spent: ExtendedVirtualCoin[];
|
|
9
|
+
}>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
open(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { NetworkName } from "../../networks";
|
|
2
|
+
import { SettleParams, SendBitcoinParams } from "..";
|
|
3
|
+
export declare namespace Request {
|
|
4
|
+
type Type = "INIT_WALLET" | "SETTLE" | "GET_ADDRESS" | "GET_ADDRESS_INFO" | "GET_BALANCE" | "GET_COINS" | "GET_VTXOS" | "GET_VIRTUAL_COINS" | "GET_BOARDING_UTXOS" | "SEND_BITCOIN" | "GET_TRANSACTION_HISTORY" | "GET_STATUS" | "CLEAR";
|
|
5
|
+
interface Base {
|
|
6
|
+
type: Type;
|
|
7
|
+
id: string;
|
|
8
|
+
}
|
|
9
|
+
function isBase(message: unknown): message is Base;
|
|
10
|
+
interface InitWallet extends Base {
|
|
11
|
+
type: "INIT_WALLET";
|
|
12
|
+
privateKey: string;
|
|
13
|
+
arkServerUrl: string;
|
|
14
|
+
network: NetworkName;
|
|
15
|
+
arkServerPublicKey?: string;
|
|
16
|
+
}
|
|
17
|
+
function isInitWallet(message: Base): message is InitWallet;
|
|
18
|
+
interface Settle extends Base {
|
|
19
|
+
type: "SETTLE";
|
|
20
|
+
params?: SettleParams;
|
|
21
|
+
}
|
|
22
|
+
function isSettle(message: Base): message is Settle;
|
|
23
|
+
interface GetAddress extends Base {
|
|
24
|
+
type: "GET_ADDRESS";
|
|
25
|
+
}
|
|
26
|
+
function isGetAddress(message: Base): message is GetAddress;
|
|
27
|
+
interface GetAddressInfo extends Base {
|
|
28
|
+
type: "GET_ADDRESS_INFO";
|
|
29
|
+
}
|
|
30
|
+
function isGetAddressInfo(message: Base): message is GetAddressInfo;
|
|
31
|
+
interface GetBalance extends Base {
|
|
32
|
+
type: "GET_BALANCE";
|
|
33
|
+
}
|
|
34
|
+
function isGetBalance(message: Base): message is GetBalance;
|
|
35
|
+
interface GetCoins extends Base {
|
|
36
|
+
type: "GET_COINS";
|
|
37
|
+
}
|
|
38
|
+
function isGetCoins(message: Base): message is GetCoins;
|
|
39
|
+
interface GetVtxos extends Base {
|
|
40
|
+
type: "GET_VTXOS";
|
|
41
|
+
}
|
|
42
|
+
function isGetVtxos(message: Base): message is GetVtxos;
|
|
43
|
+
interface GetVirtualCoins extends Base {
|
|
44
|
+
type: "GET_VIRTUAL_COINS";
|
|
45
|
+
}
|
|
46
|
+
function isGetVirtualCoins(message: Base): message is GetVirtualCoins;
|
|
47
|
+
interface GetBoardingUtxos extends Base {
|
|
48
|
+
type: "GET_BOARDING_UTXOS";
|
|
49
|
+
}
|
|
50
|
+
function isGetBoardingUtxos(message: Base): message is GetBoardingUtxos;
|
|
51
|
+
interface SendBitcoin extends Base {
|
|
52
|
+
type: "SEND_BITCOIN";
|
|
53
|
+
params: SendBitcoinParams;
|
|
54
|
+
zeroFee?: boolean;
|
|
55
|
+
}
|
|
56
|
+
function isSendBitcoin(message: Base): message is SendBitcoin;
|
|
57
|
+
interface GetTransactionHistory extends Base {
|
|
58
|
+
type: "GET_TRANSACTION_HISTORY";
|
|
59
|
+
}
|
|
60
|
+
function isGetTransactionHistory(message: Base): message is GetTransactionHistory;
|
|
61
|
+
interface GetStatus extends Base {
|
|
62
|
+
type: "GET_STATUS";
|
|
63
|
+
}
|
|
64
|
+
function isGetStatus(message: Base): message is GetStatus;
|
|
65
|
+
interface Clear extends Base {
|
|
66
|
+
type: "CLEAR";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { WalletBalance, Coin, VirtualCoin, ArkTransaction, AddressInfo as WalletAddressInfo, IWallet, Addresses } from "..";
|
|
2
|
+
import { SettlementEvent } from "../../providers/ark";
|
|
3
|
+
export declare namespace Response {
|
|
4
|
+
type Type = "WALLET_INITIALIZED" | "SETTLE_EVENT" | "SETTLE_SUCCESS" | "ADDRESS" | "ADDRESS_INFO" | "BALANCE" | "COINS" | "VTXOS" | "VIRTUAL_COINS" | "BOARDING_UTXOS" | "SEND_BITCOIN_SUCCESS" | "TRANSACTION_HISTORY" | "WALLET_STATUS" | "ERROR" | "CLEAR_RESPONSE";
|
|
5
|
+
interface Base {
|
|
6
|
+
type: Type;
|
|
7
|
+
success: boolean;
|
|
8
|
+
id: string;
|
|
9
|
+
}
|
|
10
|
+
const walletInitialized: (id: string) => Base;
|
|
11
|
+
interface Error extends Base {
|
|
12
|
+
type: "ERROR";
|
|
13
|
+
success: false;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
function error(id: string, message: string): Error;
|
|
17
|
+
interface SettleEvent extends Base {
|
|
18
|
+
type: "SETTLE_EVENT";
|
|
19
|
+
success: true;
|
|
20
|
+
event: SettlementEvent;
|
|
21
|
+
}
|
|
22
|
+
function settleEvent(id: string, event: SettlementEvent): SettleEvent;
|
|
23
|
+
interface SettleSuccess extends Base {
|
|
24
|
+
type: "SETTLE_SUCCESS";
|
|
25
|
+
success: true;
|
|
26
|
+
txid: string;
|
|
27
|
+
}
|
|
28
|
+
function settleSuccess(id: string, txid: string): SettleSuccess;
|
|
29
|
+
function isSettleSuccess(response: Base): response is SettleSuccess;
|
|
30
|
+
interface Address extends Base {
|
|
31
|
+
type: "ADDRESS";
|
|
32
|
+
success: true;
|
|
33
|
+
addresses: Addresses;
|
|
34
|
+
}
|
|
35
|
+
function isAddress(response: Base): response is Address;
|
|
36
|
+
function addresses(id: string, addresses: Addresses): Address;
|
|
37
|
+
interface AddressInfo extends Base {
|
|
38
|
+
type: "ADDRESS_INFO";
|
|
39
|
+
success: true;
|
|
40
|
+
addressInfo: WalletAddressInfo;
|
|
41
|
+
}
|
|
42
|
+
function isAddressInfo(response: Base): response is AddressInfo;
|
|
43
|
+
function addressInfo(id: string, addressInfo: WalletAddressInfo): AddressInfo;
|
|
44
|
+
interface Balance extends Base {
|
|
45
|
+
type: "BALANCE";
|
|
46
|
+
success: true;
|
|
47
|
+
balance: WalletBalance;
|
|
48
|
+
}
|
|
49
|
+
function isBalance(response: Base): response is Balance;
|
|
50
|
+
function balance(id: string, balance: WalletBalance): Balance;
|
|
51
|
+
interface Coins extends Base {
|
|
52
|
+
type: "COINS";
|
|
53
|
+
success: true;
|
|
54
|
+
coins: Coin[];
|
|
55
|
+
}
|
|
56
|
+
function isCoins(response: Base): response is Coins;
|
|
57
|
+
function coins(id: string, coins: Coin[]): Coins;
|
|
58
|
+
interface Vtxos extends Base {
|
|
59
|
+
type: "VTXOS";
|
|
60
|
+
success: true;
|
|
61
|
+
vtxos: Awaited<ReturnType<IWallet["getVtxos"]>>;
|
|
62
|
+
}
|
|
63
|
+
function isVtxos(response: Base): response is Vtxos;
|
|
64
|
+
function vtxos(id: string, vtxos: Awaited<ReturnType<IWallet["getVtxos"]>>): Vtxos;
|
|
65
|
+
interface VirtualCoins extends Base {
|
|
66
|
+
type: "VIRTUAL_COINS";
|
|
67
|
+
success: true;
|
|
68
|
+
virtualCoins: VirtualCoin[];
|
|
69
|
+
}
|
|
70
|
+
function isVirtualCoins(response: Base): response is VirtualCoins;
|
|
71
|
+
function virtualCoins(id: string, virtualCoins: VirtualCoin[]): VirtualCoins;
|
|
72
|
+
interface BoardingUtxos extends Base {
|
|
73
|
+
type: "BOARDING_UTXOS";
|
|
74
|
+
success: true;
|
|
75
|
+
boardingUtxos: Awaited<ReturnType<IWallet["getBoardingUtxos"]>>;
|
|
76
|
+
}
|
|
77
|
+
function isBoardingUtxos(response: Base): response is BoardingUtxos;
|
|
78
|
+
function boardingUtxos(id: string, boardingUtxos: Awaited<ReturnType<IWallet["getBoardingUtxos"]>>): BoardingUtxos;
|
|
79
|
+
interface SendBitcoinSuccess extends Base {
|
|
80
|
+
type: "SEND_BITCOIN_SUCCESS";
|
|
81
|
+
success: true;
|
|
82
|
+
txid: string;
|
|
83
|
+
}
|
|
84
|
+
function isSendBitcoinSuccess(response: Base): response is SendBitcoinSuccess;
|
|
85
|
+
function sendBitcoinSuccess(id: string, txid: string): SendBitcoinSuccess;
|
|
86
|
+
interface TransactionHistory extends Base {
|
|
87
|
+
type: "TRANSACTION_HISTORY";
|
|
88
|
+
success: true;
|
|
89
|
+
transactions: ArkTransaction[];
|
|
90
|
+
}
|
|
91
|
+
function isTransactionHistory(response: Base): response is TransactionHistory;
|
|
92
|
+
function transactionHistory(id: string, transactions: ArkTransaction[]): TransactionHistory;
|
|
93
|
+
interface WalletStatus extends Base {
|
|
94
|
+
type: "WALLET_STATUS";
|
|
95
|
+
success: true;
|
|
96
|
+
status: {
|
|
97
|
+
walletInitialized: boolean;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function isWalletStatus(response: Base): response is WalletStatus;
|
|
101
|
+
function walletStatus(id: string, walletInitialized: boolean): WalletStatus;
|
|
102
|
+
interface ClearResponse extends Base {
|
|
103
|
+
type: "CLEAR_RESPONSE";
|
|
104
|
+
}
|
|
105
|
+
function isClearResponse(response: Base): response is ClearResponse;
|
|
106
|
+
function clearResponse(id: string, success: boolean): ClearResponse;
|
|
107
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IWallet, WalletBalance, SendBitcoinParams, SettleParams, AddressInfo, Coin, ArkTransaction, WalletConfig, ExtendedCoin, ExtendedVirtualCoin, Addresses } from "..";
|
|
2
|
+
import { Response } from "./response";
|
|
3
|
+
import { SettlementEvent } from "../../providers/ark";
|
|
4
|
+
export declare class ServiceWorkerWallet implements IWallet {
|
|
5
|
+
private serviceWorker?;
|
|
6
|
+
static create(svcWorkerPath: string): Promise<ServiceWorkerWallet>;
|
|
7
|
+
getStatus(): Promise<Response.WalletStatus["status"]>;
|
|
8
|
+
init(config: Omit<WalletConfig, "identity"> & {
|
|
9
|
+
privateKey: string;
|
|
10
|
+
}, failIfInitialized?: boolean): Promise<void>;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
private setupServiceWorker;
|
|
13
|
+
private sendMessage;
|
|
14
|
+
getAddress(): Promise<Addresses>;
|
|
15
|
+
getAddressInfo(): Promise<AddressInfo>;
|
|
16
|
+
getBalance(): Promise<WalletBalance>;
|
|
17
|
+
getCoins(): Promise<Coin[]>;
|
|
18
|
+
getVtxos(): Promise<ExtendedVirtualCoin[]>;
|
|
19
|
+
getBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
20
|
+
sendBitcoin(params: SendBitcoinParams, zeroFee?: boolean): Promise<string>;
|
|
21
|
+
settle(params?: SettleParams, callback?: (event: SettlementEvent) => void): Promise<string>;
|
|
22
|
+
getTransactionHistory(): Promise<ArkTransaction[]>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { VtxoRepository } from "./db/vtxo";
|
|
2
|
+
export declare class Worker {
|
|
3
|
+
private readonly vtxoRepository;
|
|
4
|
+
private readonly messageCallback;
|
|
5
|
+
private wallet;
|
|
6
|
+
private arkProvider;
|
|
7
|
+
private vtxoSubscription;
|
|
8
|
+
constructor(vtxoRepository?: VtxoRepository, messageCallback?: (message: ExtendableMessageEvent) => void);
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
clear(): Promise<void>;
|
|
11
|
+
private onWalletInitialized;
|
|
12
|
+
private processVtxoSubscription;
|
|
13
|
+
private handleClear;
|
|
14
|
+
private handleInitWallet;
|
|
15
|
+
private handleSettle;
|
|
16
|
+
private handleSendBitcoin;
|
|
17
|
+
private handleGetAddress;
|
|
18
|
+
private handleGetAddressInfo;
|
|
19
|
+
private handleGetBalance;
|
|
20
|
+
private handleGetCoins;
|
|
21
|
+
private handleGetVtxos;
|
|
22
|
+
private handleGetBoardingUtxos;
|
|
23
|
+
private handleGetTransactionHistory;
|
|
24
|
+
private handleGetStatus;
|
|
25
|
+
private handleMessage;
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ArkAddress } from "../script/address";
|
|
2
|
+
import { DefaultVtxo } from "../script/default";
|
|
3
|
+
import { SettlementEvent } from "../providers/ark";
|
|
4
|
+
import { Addresses, AddressInfo, ArkTransaction, Coin, ExtendedCoin, ExtendedVirtualCoin, IWallet, SendBitcoinParams, SettleParams, WalletBalance, WalletConfig } from ".";
|
|
5
|
+
export declare class Wallet implements IWallet {
|
|
6
|
+
private identity;
|
|
7
|
+
private network;
|
|
8
|
+
private onchainProvider;
|
|
9
|
+
private onchainP2TR;
|
|
10
|
+
private arkProvider?;
|
|
11
|
+
private arkServerPublicKey?;
|
|
12
|
+
readonly offchainTapscript?: DefaultVtxo.Script | undefined;
|
|
13
|
+
readonly boardingTapscript?: DefaultVtxo.Script | undefined;
|
|
14
|
+
static DUST_AMOUNT: bigint;
|
|
15
|
+
static FEE_RATE: number;
|
|
16
|
+
private constructor();
|
|
17
|
+
static create(config: WalletConfig): Promise<Wallet>;
|
|
18
|
+
get onchainAddress(): string;
|
|
19
|
+
get boardingAddress(): ArkAddress;
|
|
20
|
+
get boardingOnchainAddress(): string;
|
|
21
|
+
get offchainAddress(): ArkAddress;
|
|
22
|
+
getAddress(): Promise<Addresses>;
|
|
23
|
+
getAddressInfo(): Promise<AddressInfo>;
|
|
24
|
+
getBalance(): Promise<WalletBalance>;
|
|
25
|
+
getCoins(): Promise<Coin[]>;
|
|
26
|
+
getVtxos(): Promise<ExtendedVirtualCoin[]>;
|
|
27
|
+
private getVirtualCoins;
|
|
28
|
+
getTransactionHistory(): Promise<ArkTransaction[]>;
|
|
29
|
+
getBoardingTxs(): Promise<{
|
|
30
|
+
boardingTxs: ArkTransaction[];
|
|
31
|
+
roundsToIgnore: Set<string>;
|
|
32
|
+
}>;
|
|
33
|
+
getBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
34
|
+
sendBitcoin(params: SendBitcoinParams, zeroFee?: boolean): Promise<string>;
|
|
35
|
+
private isOffchainSuitable;
|
|
36
|
+
private sendOnchain;
|
|
37
|
+
private sendOffchain;
|
|
38
|
+
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
39
|
+
private handleSettlementSigningEvent;
|
|
40
|
+
private handleSettlementSigningNoncesGeneratedEvent;
|
|
41
|
+
private handleSettlementFinalizationEvent;
|
|
42
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arkade-os/sdk",
|
|
3
|
+
"version": "0.0.16",
|
|
4
|
+
"description": "Bitcoin wallet SDK with Taproot and Ark integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js",
|
|
15
|
+
"default": "./dist/esm/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@noble/curves": "1.7.0",
|
|
27
|
+
"@noble/hashes": "1.6.1",
|
|
28
|
+
"@noble/secp256k1": "2.2.3",
|
|
29
|
+
"@scure/base": "1.2.1",
|
|
30
|
+
"@scure/btc-signer": "1.7.0",
|
|
31
|
+
"bip68": "1.0.4"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"rimraf": "^5.0.0",
|
|
35
|
+
"@eslint/js": "^9.17.0",
|
|
36
|
+
"@types/node": "22.10.2",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "8.18.2",
|
|
38
|
+
"@typescript-eslint/parser": "8.18.2",
|
|
39
|
+
"@vitest/coverage-v8": "2.1.8",
|
|
40
|
+
"esbuild": "^0.20.1",
|
|
41
|
+
"eslint": "^9.17.0",
|
|
42
|
+
"glob": "11.0.1",
|
|
43
|
+
"husky": "9.1.7",
|
|
44
|
+
"lint-staged": "15.3.0",
|
|
45
|
+
"prettier": "3.4.2",
|
|
46
|
+
"typescript": "5.7.2",
|
|
47
|
+
"vitest": "2.1.8"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"bitcoin",
|
|
51
|
+
"wallet",
|
|
52
|
+
"taproot",
|
|
53
|
+
"ark",
|
|
54
|
+
"sdk"
|
|
55
|
+
],
|
|
56
|
+
"author": "Ark Labs",
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "rimraf dist && pnpm run build:esm && node scripts/add-extensions.js && pnpm run build:cjs && pnpm run build:types && node scripts/generate-package-files.js",
|
|
63
|
+
"build:esm": "tsc -p tsconfig.esm.json --outDir dist/esm",
|
|
64
|
+
"build:cjs": "tsc -p tsconfig.cjs.json --outDir dist/cjs",
|
|
65
|
+
"build:types": "tsc -p tsconfig.json --outDir dist/types --emitDeclarationOnly",
|
|
66
|
+
"build:browser": "node scripts/build-browser.js",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"test:master": "ARK_ENV=master vitest run",
|
|
69
|
+
"test:unit": "vitest run --exclude test/integration.test.ts",
|
|
70
|
+
"test:setup": "node test/setup.js",
|
|
71
|
+
"test:setup-master": "node test/setup.js master",
|
|
72
|
+
"test:up-master": "docker compose -f docker-compose.yml up -d --build",
|
|
73
|
+
"test:down-master": "docker compose -f docker-compose.yml down",
|
|
74
|
+
"test:integration": "vitest run test/integration.test.ts",
|
|
75
|
+
"test:integration-master": "ARK_ENV=master vitest run test/integration.test.ts",
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"test:coverage": "vitest run --coverage",
|
|
78
|
+
"test:sw": "pnpm run build:browser && node test/serviceWorker/serve.js",
|
|
79
|
+
"format": "prettier --write src test examples",
|
|
80
|
+
"lint": "prettier --check src test examples",
|
|
81
|
+
"audit": "pnpm audit",
|
|
82
|
+
"preinstall": "npx only-allow pnpm",
|
|
83
|
+
"release": "bash scripts/release.sh",
|
|
84
|
+
"release:dry-run": "bash scripts/release.sh --dry-run",
|
|
85
|
+
"release:cleanup": "bash scripts/release.sh --cleanup",
|
|
86
|
+
"precommit": "lint-staged"
|
|
87
|
+
}
|
|
88
|
+
}
|