@nervosnetwork/fiber-js 0.5.1

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/src/index.ts ADDED
@@ -0,0 +1,193 @@
1
+
2
+ import DbWorker from "./db.worker.ts";
3
+ import FiberWorker from "./fiber.worker.ts";
4
+ import { Mutex } from "async-mutex";
5
+ import { DbWorkerInitializationOptions, FiberInvokeRequest, FiberInvokeResponse, FiberWorkerInitializationOptions } from "./types/general.ts";
6
+ import { AbandonChannelParams, AcceptChannelParams, AcceptChannelResult, ListChannelsParams, ListChannelsResult, OpenChannelParams, OpenChannelResult, ShutdownChannelParams, UpdateChannelParams } from "./types/channel.ts";
7
+ import { GraphChannelsParams, GraphChannelsResult, GraphNodesParams, GraphNodesResult } from "./types/graph.ts";
8
+ import { NodeInfoResult } from "./types/info.ts";
9
+ import { GetInvoiceResult, InvoiceParams, InvoiceResult, NewInvoiceParams, ParseInvoiceParams, ParseInvoiceResult } from "./types/invoice.ts";
10
+ import { BuildPaymentRouterResult, BuildRouterParams, GetPaymentCommandParams, GetPaymentCommandResult, SendPaymentCommandParams, SendPaymentWithRouterParams } from "./types/payment.ts";
11
+ import { ConnectPeerParams, DisconnectPeerParams, ListPeerResult } from "./types/peer.ts";
12
+
13
+ const DEFAULT_BUFFER_SIZE = 50 * (1 << 20);
14
+ /**
15
+ * A Fiber Wasm instance
16
+ */
17
+ class Fiber {
18
+ private dbWorker: Worker | null
19
+ private fiberWorker: Worker | null
20
+ private inputBuffer: SharedArrayBuffer
21
+ private outputBuffer: SharedArrayBuffer
22
+ private commandInvokeLock: Mutex;
23
+ /**
24
+ * Construct a Fiber Wasm instance.
25
+ * inputBuffer and outputBuffer are buffers used for transporting data between database and fiber wasm. Set them to appropriate sizes.
26
+ * @param inputBufferSize Size of inputBuffer
27
+ * @param outputBufferSize Size of outputBuffer
28
+ */
29
+ constructor(inputBufferSize = DEFAULT_BUFFER_SIZE, outputBufferSize = DEFAULT_BUFFER_SIZE) {
30
+ this.dbWorker = new DbWorker();
31
+ this.fiberWorker = new FiberWorker();
32
+ this.inputBuffer = new SharedArrayBuffer(inputBufferSize);
33
+ this.outputBuffer = new SharedArrayBuffer(outputBufferSize);
34
+ this.commandInvokeLock = new Mutex();
35
+ }
36
+
37
+ /**
38
+ * Start the Fiber Wasm instance.
39
+ * @param config Config file for fiber
40
+ * @param fiberKeyPair keypair used for fiber
41
+ * @param ckbSecretKey secret key for CKB
42
+ * @param chainSpec Chain spec if chain is neither testnet nor mainnet
43
+ * @param logLevel log level, such as `trace`, `debug`, `info`, `error`
44
+ * @param databasePrefix Name prefix of IndexedDB store. Defaults to `/wasm`
45
+ *
46
+ */
47
+ async start(
48
+ config: string,
49
+ fiberKeyPair: Uint8Array,
50
+ ckbSecretKey: Uint8Array,
51
+ chainSpec?: string,
52
+ logLevel: "trace" | "debug" | "info" | "error" = "info",
53
+ databasePrefix?: string) {
54
+ this.dbWorker.postMessage({
55
+ inputBuffer: this.inputBuffer,
56
+ outputBuffer: this.outputBuffer,
57
+ logLevel: logLevel
58
+ } as DbWorkerInitializationOptions);
59
+ this.fiberWorker.postMessage({
60
+ inputBuffer: this.inputBuffer,
61
+ outputBuffer: this.outputBuffer,
62
+ ckbSecretKey,
63
+ config,
64
+ fiberKeyPair,
65
+ logLevel,
66
+ chainSpec,
67
+ databasePrefix
68
+ } as FiberWorkerInitializationOptions);
69
+ await new Promise<void>((res, rej) => {
70
+ this.dbWorker.onmessage = () => res();
71
+ this.dbWorker.onerror = (evt) => rej(evt);
72
+ });
73
+ await new Promise<void>((res, rej) => {
74
+ this.fiberWorker.onmessage = () => res();
75
+ this.fiberWorker.onerror = (evt) => rej(evt);
76
+ });
77
+
78
+ }
79
+ invokeCommand(name: string, args?: any[]): Promise<any> {
80
+ // Why use lock here?
81
+ // fiber-wasm provided async APIs. Use lock here to avoid mixture of different calls
82
+ return this.commandInvokeLock.runExclusive(async () => {
83
+ this.fiberWorker.postMessage({
84
+ name,
85
+ args: args || []
86
+ } as FiberInvokeRequest);
87
+ return await new Promise((resolve, reject) => {
88
+ const clean = () => {
89
+ this.fiberWorker.removeEventListener("message", resolveFn);
90
+ this.fiberWorker.removeEventListener("error", errorFn);
91
+ }
92
+ const resolveFn = (evt: MessageEvent<FiberInvokeResponse>) => {
93
+ if (evt.data.ok === true) {
94
+ resolve(evt.data.data);
95
+ } else {
96
+ reject(evt.data.error);
97
+ }
98
+ clean();
99
+
100
+ };
101
+ const errorFn = (evt: ErrorEvent) => {
102
+ reject(evt);
103
+ clean();
104
+
105
+ };
106
+ this.fiberWorker.addEventListener("message", resolveFn);
107
+ this.fiberWorker.addEventListener("error", errorFn);
108
+ })
109
+ })
110
+
111
+ }
112
+ /**
113
+ * Stop the fiber instance.
114
+ */
115
+ async stop() {
116
+ this.dbWorker.terminate();
117
+ this.fiberWorker.terminate();
118
+ }
119
+ async openChannel(params: OpenChannelParams): Promise<OpenChannelResult> {
120
+ return await this.invokeCommand("open_channel", [params]);
121
+ }
122
+ async acceptChannel(params: AcceptChannelParams): Promise<AcceptChannelResult> {
123
+ return await this.invokeCommand("accept_channel", [params]);
124
+ }
125
+ async abandonChannel(params: AbandonChannelParams): Promise<void> {
126
+ await this.invokeCommand("abandon_channel", [params]);
127
+ }
128
+ async listChannels(params: ListChannelsParams): Promise<ListChannelsResult> {
129
+ return await this.invokeCommand("list_channels", [params]);
130
+ }
131
+ async shutdownChannel(params: ShutdownChannelParams): Promise<void> {
132
+ await this.invokeCommand("shutdown_channel", [params]);
133
+ }
134
+ async updateChannel(params: UpdateChannelParams): Promise<void> {
135
+ await this.invokeCommand("update_channel", [params]);
136
+ }
137
+ async graphNodes(params: GraphNodesParams): Promise<GraphNodesResult> {
138
+ return await this.invokeCommand("graph_nodes", [params]);
139
+ }
140
+ async graphChannels(params: GraphChannelsParams): Promise<GraphChannelsResult> {
141
+ return await this.invokeCommand("graph_channels", [params]);
142
+ }
143
+ async nodeInfo(): Promise<NodeInfoResult> {
144
+ return await this.invokeCommand("node_info");
145
+ }
146
+ async newInvoice(params: NewInvoiceParams): Promise<InvoiceResult> {
147
+ return await this.invokeCommand("new_invoice", [params]);
148
+ }
149
+ async parseInvoice(params: ParseInvoiceParams): Promise<ParseInvoiceResult> {
150
+ return await this.invokeCommand("parse_invoice", [params]);
151
+ }
152
+ async getInvoice(params: InvoiceParams): Promise<GetInvoiceResult> {
153
+ return await this.invokeCommand("get_invoice", [params]);
154
+ }
155
+ async cancelInvoice(params: InvoiceParams): Promise<GetInvoiceResult> {
156
+ return await this.invokeCommand("cancel_invoice", [params]);
157
+ }
158
+ async sendPayment(params: SendPaymentCommandParams): Promise<GetPaymentCommandResult> {
159
+ return await this.invokeCommand("send_payment", [params]);
160
+ }
161
+ async getPayment(params: GetPaymentCommandParams): Promise<GetPaymentCommandResult> {
162
+ return await this.invokeCommand("get_payment", [params]);
163
+ }
164
+ async buildRouter(params: BuildRouterParams): Promise<BuildPaymentRouterResult> {
165
+ return await this.invokeCommand("build_router", [params]);
166
+ }
167
+ async sendPaymentWithRouter(params: SendPaymentWithRouterParams): Promise<GetPaymentCommandResult> {
168
+ return await this.invokeCommand("send_payment_with_router", [params]);
169
+ }
170
+ async connectPeer(params: ConnectPeerParams): Promise<void> {
171
+ await this.invokeCommand("connect_peer", [params]);
172
+ }
173
+ async disconnectPeer(params: DisconnectPeerParams): Promise<void> {
174
+ await this.invokeCommand("disconnect_peer", [params]);
175
+ }
176
+ async listPeers(): Promise<ListPeerResult> {
177
+ return await this.invokeCommand("list_peers");
178
+ }
179
+ }
180
+
181
+ export { Fiber };
182
+
183
+ /**
184
+ * Generate a random 32-byte secret key.
185
+ * @returns The secret key.
186
+ */
187
+ export function randomSecretKey(): Uint8Array {
188
+ const arr = new Uint8Array(32);
189
+ crypto.getRandomValues(arr);
190
+ return arr;
191
+ }
192
+
193
+ export * from "./types/general.ts";
@@ -0,0 +1,100 @@
1
+ import { HexString } from "./general";
2
+
3
+ interface Script {
4
+ code_hash: HexString;
5
+ hash_type: "data" | "type" | "data1" | "data2";
6
+ args: string;
7
+ }
8
+
9
+ interface OpenChannelParams {
10
+ peer_id: string;
11
+ funding_amount: HexString;
12
+ public?: boolean;
13
+ funding_udt_type_script?: Script;
14
+ shutdown_script?: Script;
15
+ commitment_delay_epoch?: HexString;
16
+ commitment_fee_rate?: HexString;
17
+ funding_fee_rate?: HexString;
18
+ tlc_expiry_delta?: HexString;
19
+ tlc_min_value?: HexString;
20
+ tlc_fee_proportional_millionths?: HexString;
21
+ max_tlc_value_in_flight?: HexString;
22
+ max_tlc_number_in_flight?: HexString;
23
+ }
24
+ interface OpenChannelResult {
25
+ temporary_channel_id: HexString;
26
+ }
27
+ interface AbandonChannelParams {
28
+ channel_id: HexString;
29
+ }
30
+ interface AcceptChannelParams {
31
+ temporary_channel_id: HexString;
32
+ funding_amount: HexString;
33
+ shutdown_script?: Script;
34
+ max_tlc_value_in_flight?: HexString;
35
+ max_tlc_number_in_flight?: HexString;
36
+ tlc_min_value?: HexString;
37
+ tlc_fee_proportional_millionths?: HexString;
38
+ tlc_expiry_delta?: HexString;
39
+ }
40
+ interface AcceptChannelResult {
41
+ channel_id: HexString;
42
+ }
43
+ interface ListChannelsParams {
44
+ peer_id?: string;
45
+ include_closed?: boolean;
46
+ }
47
+
48
+ interface ChannelState {
49
+ state_name: string;
50
+ state_flags: string;
51
+ }
52
+ interface Channel {
53
+ channel_id: HexString;
54
+ is_public: boolean;
55
+ channel_outpoint: HexString;
56
+ peer_id: HexString;
57
+ funding_udt_type_script?: Script;
58
+ state: ChannelState;
59
+ local_balance: HexString;
60
+ offered_tlc_balance: HexString;
61
+ remote_balance: HexString;
62
+ received_tlc_balance: HexString;
63
+ latest_commitment_transaction_hash?: HexString;
64
+ created_at: HexString;
65
+ enabled: boolean;
66
+ tlc_expiry_delta: HexString;
67
+ tlc_fee_proportional_millionths: HexString;
68
+ }
69
+
70
+ interface ShutdownChannelParams {
71
+ channel_id: HexString;
72
+ close_script?: Script;
73
+ fee_rate?: HexString;
74
+ force?: boolean;
75
+ }
76
+
77
+ interface UpdateChannelParams {
78
+ channel_id: HexString;
79
+ enabled?: boolean;
80
+ tlc_expiry_delta?: HexString;
81
+ tlc_minimum_value?: HexString;
82
+ tlc_fee_proportional_millionths?: HexString;
83
+ }
84
+ interface ListChannelsResult {
85
+ channels: Channel[];
86
+ }
87
+ export type {
88
+ OpenChannelParams,
89
+ Script,
90
+ OpenChannelResult,
91
+ AbandonChannelParams,
92
+ AcceptChannelParams,
93
+ AcceptChannelResult,
94
+ ListChannelsParams,
95
+ Channel,
96
+ ChannelState,
97
+ ShutdownChannelParams,
98
+ UpdateChannelParams,
99
+ ListChannelsResult
100
+ }
@@ -0,0 +1,34 @@
1
+ interface DbWorkerInitializationOptions {
2
+ inputBuffer: SharedArrayBuffer;
3
+ outputBuffer: SharedArrayBuffer;
4
+ logLevel: string;
5
+ }
6
+ interface FiberWorkerInitializationOptions {
7
+ inputBuffer: SharedArrayBuffer;
8
+ outputBuffer: SharedArrayBuffer;
9
+ logLevel: string;
10
+ fiberKeyPair: Uint8Array;
11
+ ckbSecretKey: Uint8Array;
12
+ config: string;
13
+ chainSpec?: string;
14
+ databasePrefix?: string;
15
+ }
16
+
17
+ interface FiberInvokeRequest {
18
+ name: string;
19
+ args: any[];
20
+ };
21
+ type FiberInvokeResponse = { ok: true; data: any; } | { ok: false; error: string };
22
+
23
+ type HexString = `0x${string}`;
24
+
25
+ type HashAlgorithm = "ckb_hash" | "sha_256";
26
+
27
+ export type {
28
+ DbWorkerInitializationOptions,
29
+ FiberWorkerInitializationOptions,
30
+ FiberInvokeRequest,
31
+ FiberInvokeResponse,
32
+ HexString,
33
+ HashAlgorithm
34
+ }
@@ -0,0 +1,101 @@
1
+ import { Script } from "./channel";
2
+ import { HexString } from "./general"
3
+
4
+ interface GraphNodesParams {
5
+ limit?: HexString;
6
+ after?: HexString;
7
+ }
8
+ type UdtScript = Script;
9
+ type DepType = "code" | "dep_group";
10
+
11
+ interface UdtCellDep {
12
+ out_point: OutPoint;
13
+ dep_type: DepType;
14
+ }
15
+
16
+ interface OutPoint {
17
+ tx_hash: HexString;
18
+ index: HexString;
19
+ }
20
+
21
+ interface UdtDep {
22
+ cell_dep?: UdtCellDep;
23
+ type_id?: Script;
24
+ }
25
+
26
+ interface UdtCellDep {
27
+ out_point: OutPoint;
28
+ dep_type: DepType;
29
+ }
30
+
31
+ interface UdtArgInfo {
32
+ name: string;
33
+ script: UdtScript;
34
+ auto_accept_amount?: HexString;
35
+ cell_deps: UdtDep[];
36
+ }
37
+ type UdtCfgInfos = UdtArgInfo[];
38
+
39
+ interface NodeInfo {
40
+ node_name: string;
41
+ addresses: string[];
42
+ node_id: HexString;
43
+ timestamp: HexString;
44
+ chain_hash: HexString;
45
+ auto_accept_min_ckb_funding_amount: HexString;
46
+ udt_cfg_infos: UdtCfgInfos;
47
+ }
48
+
49
+ interface GraphNodesResult {
50
+ nodes: NodeInfo[];
51
+ last_cursor: HexString;
52
+ }
53
+ interface GraphChannelsParams {
54
+ limit?: HexString;
55
+ after?: HexString;
56
+ }
57
+
58
+ interface ChannelUpdateInfo {
59
+ timestamp: HexString;
60
+ enabled: boolean;
61
+ outbound_liquidity?: HexString;
62
+ tlc_expiry_delta: HexString;
63
+ tlc_minimum_value: HexString;
64
+ fee_rate: HexString;
65
+ }
66
+
67
+ interface ChannelInfo {
68
+ channel_outpoint: HexString;
69
+ node1: HexString;
70
+ node2: HexString;
71
+ created_timestamp: HexString;
72
+ update_info_of_node1?: ChannelUpdateInfo;
73
+ update_info_of_node2?: ChannelUpdateInfo;
74
+ capacity: HexString;
75
+ chain_hash: HexString;
76
+ udt_type_script?: Script;
77
+
78
+ }
79
+ interface GraphChannelsResult {
80
+ channels: ChannelInfo[];
81
+ last_cursor: HexString;
82
+ }
83
+ export type {
84
+ GraphNodesParams,
85
+ GraphNodesResult,
86
+ GraphChannelsParams,
87
+ GraphChannelsResult,
88
+ ChannelInfo,
89
+ ChannelUpdateInfo,
90
+ DepType,
91
+ HexString,
92
+ NodeInfo,
93
+ OutPoint,
94
+ Script,
95
+ UdtCellDep,
96
+ UdtArgInfo,
97
+ UdtCfgInfos,
98
+ UdtDep,
99
+ UdtScript,
100
+
101
+ }
@@ -0,0 +1,25 @@
1
+ import { Script } from "./channel";
2
+ import { HexString } from "./general";
3
+ import { UdtCfgInfos } from "./graph";
4
+
5
+ interface NodeInfoResult {
6
+ version: string;
7
+ commit_hash: string;
8
+ node_id: string;
9
+ node_name?: string;
10
+ addresses: string[];
11
+ chain_hash: HexString;
12
+ open_channel_auto_accept_min_ckb_funding_amount: HexString;
13
+ auto_accept_channel_ckb_funding_amount: HexString;
14
+ default_funding_lock_script: Script;
15
+ tlc_expiry_delta: HexString;
16
+ tlc_min_value: HexString;
17
+ tlc_fee_proportional_millionths: HexString;
18
+ channel_count: HexString;
19
+ pending_channel_count: HexString;
20
+ peers_count: HexString;
21
+ udt_cfg_infos: UdtCfgInfos;
22
+ }
23
+
24
+
25
+ export type { NodeInfoResult }
@@ -0,0 +1,75 @@
1
+ import { Script } from "./channel";
2
+ import { HashAlgorithm, HexString } from "./general"
3
+
4
+ type Currency = "Fibb" | "Fibt" | "Fibd";
5
+ type CkbInvoiceStatus = "Open" | "Cancelled" | "Expired" | "Received" | "Paid";
6
+ interface NewInvoiceParams {
7
+ amount: HexString;
8
+ description?: string;
9
+ currency: Currency;
10
+ payment_preimage: HexString;
11
+ expiry?: HexString;
12
+ fallback_address?: string;
13
+ final_expiry_delta?: HexString;
14
+ udt_type_script?: Script;
15
+ hash_algorithm?: HashAlgorithm;
16
+ }
17
+ type CkbScript = HexString;
18
+ type Attribute = { FinalHtlcTimeout: HexString } |
19
+ { FinalHtlcMinimumExpiryDelta: HexString } |
20
+ { ExpiryTime: HexString } |
21
+ { Description: string } |
22
+ { FallbackAddr: string } |
23
+ { UdtScript: CkbScript } |
24
+ { PayeePublicKey: string } |
25
+ { HashAlgorithm: number } |
26
+ { Feature: HexString };
27
+
28
+
29
+ interface InvoiceData {
30
+ timestamp: HexString;
31
+ payment_hash: HexString;
32
+ attrs: Attribute[];
33
+ }
34
+ interface CkbInvoice {
35
+ currency: Currency;
36
+ amount?: HexString;
37
+ signature?: string;
38
+ data: InvoiceData;
39
+ }
40
+
41
+ interface InvoiceResult {
42
+ invoice_address: string;
43
+ invoice: CkbInvoice;
44
+ }
45
+
46
+ interface ParseInvoiceParams {
47
+ invoice: string;
48
+ }
49
+ interface ParseInvoiceResult {
50
+ invoice: CkbInvoice;
51
+ }
52
+ interface InvoiceParams {
53
+ payment_hash: HexString;
54
+ }
55
+
56
+ interface GetInvoiceResult {
57
+ invoice_address: string;
58
+ invoice: CkbInvoice;
59
+ status: CkbInvoiceStatus;
60
+ }
61
+
62
+ export type {
63
+ NewInvoiceParams,
64
+ InvoiceResult,
65
+ Attribute,
66
+ CkbInvoice,
67
+ CkbInvoiceStatus,
68
+ CkbScript,
69
+ Currency,
70
+ GetInvoiceResult,
71
+ InvoiceData,
72
+ InvoiceParams,
73
+ ParseInvoiceParams,
74
+ ParseInvoiceResult
75
+ }
@@ -0,0 +1,91 @@
1
+ import { Script } from "./channel";
2
+ import { HexString } from "./general"
3
+ type PaymentSessionStatus = "Created" | "Inflight" | "Success" | "Failed";
4
+
5
+ interface PaymentCustomRecords {
6
+ [k: HexString]: HexString;
7
+ }
8
+ interface SessionRouteNode {
9
+ pubkey: string;
10
+ amount: HexString;
11
+ channel_outpoint: HexString;
12
+ }
13
+ interface GetPaymentCommandResult {
14
+ payment_hash: HexString;
15
+ status: PaymentSessionStatus;
16
+ created_at: HexString;
17
+ last_updated_at: HexString;
18
+ failed_error?: string;
19
+ fee: HexString;
20
+ custom_records?: PaymentCustomRecords;
21
+ /// Only available in debug mode
22
+ router?: SessionRouteNode[];
23
+ }
24
+ interface HopHint {
25
+ pubkey: string;
26
+ channel_outpoint: HexString;
27
+ fee_rate: HexString;
28
+ tlc_expiry_delta: HexString;
29
+ }
30
+ interface HopRequire {
31
+ pubkey: string;
32
+ channel_outpoint: HexString;
33
+ }
34
+ interface RouterHop {
35
+ target: HexString;
36
+ channel_outpoint: HexString;
37
+ amount_received: HexString;
38
+ incoming_tlc_expiry: HexString;
39
+ }
40
+ interface GetPaymentCommandParams {
41
+ payment_hash: HexString;
42
+ }
43
+ interface SendPaymentCommandParams {
44
+ target_pubkey?: string;
45
+ amount?: HexString;
46
+ payment_hash?: HexString;
47
+ final_tlc_expiry_delta?: HexString;
48
+ tlc_expiry_limit?: HexString;
49
+ invoice?: string;
50
+ timeout?: HexString;
51
+ max_fee_amount?: HexString;
52
+ max_parts?: HexString;
53
+ keysend?: boolean;
54
+ udt_type_script?: Script;
55
+ allow_self_payment?: boolean;
56
+ custom_records?: PaymentCustomRecords;
57
+ hop_hints?: HopHint[];
58
+ dry_run?: boolean;
59
+ }
60
+ interface BuildRouterParams {
61
+ amount?: HexString;
62
+ udt_type_script?: Script;
63
+ hops_info: HopRequire[];
64
+ final_tlc_expiry_delta?: HexString;
65
+ }
66
+ interface BuildPaymentRouterResult {
67
+ router_hops: RouterHop[];
68
+ }
69
+ interface SendPaymentWithRouterParams {
70
+ payment_hash?: HexString;
71
+ router: RouterHop[];
72
+ invoice?: string;
73
+ custom_records?: PaymentCustomRecords;
74
+ keysend?: boolean;
75
+ udt_type_script?: Script;
76
+ dry_run?: boolean;
77
+ }
78
+ export type {
79
+ GetPaymentCommandResult,
80
+ BuildPaymentRouterResult,
81
+ BuildRouterParams,
82
+ HopHint,
83
+ HopRequire,
84
+ PaymentCustomRecords,
85
+ PaymentSessionStatus,
86
+ RouterHop,
87
+ SendPaymentCommandParams,
88
+ SendPaymentWithRouterParams,
89
+ SessionRouteNode,
90
+ GetPaymentCommandParams
91
+ }
@@ -0,0 +1,29 @@
1
+ import { HexString } from "./general"
2
+
3
+ interface ConnectPeerParams {
4
+ address: string;
5
+ save?: boolean;
6
+
7
+ }
8
+
9
+ interface DisconnectPeerParams {
10
+ peer_id: string;
11
+ }
12
+
13
+ interface PeerInfo {
14
+ pubkey: string;
15
+ peer_id: string;
16
+ addresses: string[];
17
+ }
18
+
19
+ interface ListPeerResult {
20
+ peers: PeerInfo[];
21
+ }
22
+
23
+
24
+ export type {
25
+ ConnectPeerParams,
26
+ DisconnectPeerParams,
27
+ ListPeerResult,
28
+ PeerInfo
29
+ }
@@ -0,0 +1,13 @@
1
+ declare module "*.worker.ts" {
2
+ class WebpackWorker extends Worker {
3
+ constructor();
4
+ }
5
+ export default WebpackWorker;
6
+ }
7
+
8
+ declare module "*.worker" {
9
+ class WebpackWorker extends Worker {
10
+ constructor();
11
+ }
12
+ export default WebpackWorker;
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist/",
4
+ "noImplicitAny": true,
5
+ "module": "ESNext",
6
+ "target": "es2020",
7
+ "allowJs": true,
8
+ "mapRoot": "dist",
9
+ "sourceMap": true,
10
+ "declaration": true,
11
+ "declarationDir": "dist",
12
+ "rootDir": "src",
13
+ "declarationMap": true,
14
+ "typeRoots": [
15
+ "/src"
16
+ ],
17
+ "allowSyntheticDefaultImports": true,
18
+ "lib": [
19
+ "ES2024",
20
+ "WebWorker",
21
+ "ESNext"
22
+ ],
23
+ "moduleResolution": "bundler",
24
+ "allowImportingTsExtensions": true,
25
+ "emitDeclarationOnly": true
26
+ },
27
+ "exclude": [
28
+ "webpack.config.js",
29
+ "dist/**",
30
+ "node_modules/**",
31
+ "jest.config.js",
32
+ "esbuild.config.*"
33
+ ]
34
+ }