@lendasat/lendaswap-sdk 0.1.2 → 0.1.4

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/dist/wallet.d.ts DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * High-level Wallet class wrapping the WASM SDK.
3
- *
4
- * This is the main entry point for using the Lendaswap Client SDK.
5
- */
6
- import type { WalletStorageProvider } from "./api.js";
7
- import type { Network, SwapParams } from "./types.js";
8
- /**
9
- * Initialize the WASM module.
10
- *
11
- * This is called automatically when creating a Wallet, but can be called
12
- * explicitly for eager initialization.
13
- *
14
- * @param wasmPath - Optional path to the WASM file (for Node.js environments)
15
- */
16
- export declare function initWasm(wasmPath?: string): Promise<void>;
17
- /**
18
- * High-level Wallet class for the Lendaswap Client SDK.
19
- *
20
- * @example
21
- * ```typescript
22
- * import { Wallet, type WalletStorageProvider } from '@lendaswap/sdk';
23
- *
24
- * // Create a wallet storage provider using localStorage
25
- * const walletStorage: WalletStorageProvider = {
26
- * getMnemonic: async () => localStorage.getItem('mnemonic'),
27
- * setMnemonic: async (mnemonic) => localStorage.setItem('mnemonic', mnemonic),
28
- * getKeyIndex: async () => parseInt(localStorage.getItem('key_index') ?? '0'),
29
- * setKeyIndex: async (index) => localStorage.setItem('key_index', index.toString()),
30
- * };
31
- * const wallet = await Wallet.create(walletStorage, 'bitcoin');
32
- *
33
- * // Generate or get existing mnemonic
34
- * const mnemonic = await wallet.generateOrGetMnemonic();
35
- *
36
- * // Derive swap parameters
37
- * const params = await wallet.deriveSwapParams();
38
- * console.log(params.preimageHash);
39
- * ```
40
- */
41
- export declare class Wallet {
42
- private wasmWallet;
43
- private storage;
44
- private network;
45
- private constructor();
46
- /**
47
- * Create a new Wallet instance.
48
- *
49
- * @param storage - Wallet storage provider for persisting mnemonic and key index
50
- * @param network - Bitcoin network ('bitcoin', 'testnet', 'regtest', 'mutinynet')
51
- * @param wasmPath - Optional path to the WASM file (for Node.js environments)
52
- * @returns A new Wallet instance
53
- */
54
- static create(storage: WalletStorageProvider, network: Network, wasmPath?: string): Promise<Wallet>;
55
- /**
56
- * Get the network this wallet is configured for.
57
- */
58
- getNetwork(): Network;
59
- /**
60
- * Get the underlying storage provider.
61
- */
62
- getStorage(): WalletStorageProvider;
63
- /**
64
- * Generate a new mnemonic or return existing one.
65
- *
66
- * If a mnemonic already exists in storage, it is returned.
67
- * Otherwise, a new 12-word mnemonic is generated and stored.
68
- *
69
- * @returns The mnemonic phrase
70
- */
71
- generateOrGetMnemonic(): Promise<string>;
72
- /**
73
- * Get the stored mnemonic (for backup display).
74
- *
75
- * @returns The mnemonic phrase, or null if not generated
76
- */
77
- getMnemonic(): Promise<string | null>;
78
- /**
79
- * Import a mnemonic phrase (replaces existing).
80
- *
81
- * @param phrase - The mnemonic phrase to import
82
- */
83
- importMnemonic(phrase: string): Promise<void>;
84
- /**
85
- * Derive swap parameters for a new swap.
86
- *
87
- * This automatically increments the key derivation index.
88
- *
89
- * @returns The derived swap parameters
90
- */
91
- deriveSwapParams(): Promise<SwapParams>;
92
- /**
93
- * Derive swap parameters at a specific index (for recovery).
94
- *
95
- * This does not modify the stored key index.
96
- *
97
- * @param index - The derivation index to use
98
- * @returns The derived swap parameters
99
- */
100
- deriveSwapParamsAtIndex(index: number): Promise<SwapParams>;
101
- /**
102
- * Get the user ID Xpub for wallet recovery.
103
- *
104
- * @returns The extended public key, or null if no mnemonic
105
- */
106
- getUserIdXpub(): Promise<string | null>;
107
- }
108
- //# sourceMappingURL=wallet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAKtD;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4C/D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,OAAO,CAAU;IAEzB,OAAO;IAUP;;;;;;;OAOG;WACU,MAAM,CACjB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC;IAelB;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,UAAU,IAAI,qBAAqB;IAInC;;;;;;;OAOG;IACG,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAK3C;;;;OAIG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD;;;;;;OAMG;IACG,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC;IAY7C;;;;;;;OAOG;IACG,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAYjE;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAI9C"}
package/dist/wallet.js DELETED
@@ -1,188 +0,0 @@
1
- /**
2
- * High-level Wallet class wrapping the WASM SDK.
3
- *
4
- * This is the main entry point for using the Lendaswap Client SDK.
5
- */
6
- // Import WASM module
7
- import init, { JsWalletStorageProvider, Wallet as WasmWalletClass, } from "../wasm/lendaswap_wasm_sdk.js";
8
- // Cached initialization promise
9
- let initPromise = null;
10
- /**
11
- * Initialize the WASM module.
12
- *
13
- * This is called automatically when creating a Wallet, but can be called
14
- * explicitly for eager initialization.
15
- *
16
- * @param wasmPath - Optional path to the WASM file (for Node.js environments)
17
- */
18
- export async function initWasm(wasmPath) {
19
- if (initPromise) {
20
- return initPromise;
21
- }
22
- initPromise = (async () => {
23
- // Check if we're in Node.js
24
- const isNode = typeof process !== "undefined" &&
25
- process.versions != null &&
26
- process.versions.node != null;
27
- if (isNode && !wasmPath) {
28
- // In Node.js, try to load the WASM file directly
29
- const { readFile } = await import("fs/promises");
30
- const { fileURLToPath } = await import("url");
31
- const { dirname, join } = await import("path");
32
- // Get the directory of the current module
33
- const __filename = fileURLToPath(import.meta.url);
34
- const __dirname = dirname(__filename);
35
- // The WASM file is in the wasm directory relative to src
36
- const wasmFilePath = join(__dirname, "..", "wasm", "lendaswap_sdk_bg.wasm");
37
- const wasmBuffer = await readFile(wasmFilePath);
38
- await init(wasmBuffer);
39
- }
40
- else if (wasmPath) {
41
- // Custom path provided
42
- const { readFile } = await import("fs/promises");
43
- const wasmBuffer = await readFile(wasmPath);
44
- await init(wasmBuffer);
45
- }
46
- else {
47
- // Browser environment - let init handle fetching
48
- await init();
49
- }
50
- })();
51
- return initPromise;
52
- }
53
- /**
54
- * High-level Wallet class for the Lendaswap Client SDK.
55
- *
56
- * @example
57
- * ```typescript
58
- * import { Wallet, type WalletStorageProvider } from '@lendaswap/sdk';
59
- *
60
- * // Create a wallet storage provider using localStorage
61
- * const walletStorage: WalletStorageProvider = {
62
- * getMnemonic: async () => localStorage.getItem('mnemonic'),
63
- * setMnemonic: async (mnemonic) => localStorage.setItem('mnemonic', mnemonic),
64
- * getKeyIndex: async () => parseInt(localStorage.getItem('key_index') ?? '0'),
65
- * setKeyIndex: async (index) => localStorage.setItem('key_index', index.toString()),
66
- * };
67
- * const wallet = await Wallet.create(walletStorage, 'bitcoin');
68
- *
69
- * // Generate or get existing mnemonic
70
- * const mnemonic = await wallet.generateOrGetMnemonic();
71
- *
72
- * // Derive swap parameters
73
- * const params = await wallet.deriveSwapParams();
74
- * console.log(params.preimageHash);
75
- * ```
76
- */
77
- export class Wallet {
78
- wasmWallet;
79
- storage;
80
- network;
81
- constructor(wasmWallet, storage, network) {
82
- this.wasmWallet = wasmWallet;
83
- this.storage = storage;
84
- this.network = network;
85
- }
86
- /**
87
- * Create a new Wallet instance.
88
- *
89
- * @param storage - Wallet storage provider for persisting mnemonic and key index
90
- * @param network - Bitcoin network ('bitcoin', 'testnet', 'regtest', 'mutinynet')
91
- * @param wasmPath - Optional path to the WASM file (for Node.js environments)
92
- * @returns A new Wallet instance
93
- */
94
- static async create(storage, network, wasmPath) {
95
- await initWasm(wasmPath);
96
- // Create the JS storage provider that bridges to our WalletStorageProvider interface
97
- const jsProvider = new JsWalletStorageProvider(storage.getMnemonic.bind(storage), storage.setMnemonic.bind(storage), storage.getKeyIndex.bind(storage), storage.setKeyIndex.bind(storage));
98
- const wasmWallet = new WasmWalletClass(jsProvider, network);
99
- return new Wallet(wasmWallet, storage, network);
100
- }
101
- /**
102
- * Get the network this wallet is configured for.
103
- */
104
- getNetwork() {
105
- return this.network;
106
- }
107
- /**
108
- * Get the underlying storage provider.
109
- */
110
- getStorage() {
111
- return this.storage;
112
- }
113
- /**
114
- * Generate a new mnemonic or return existing one.
115
- *
116
- * If a mnemonic already exists in storage, it is returned.
117
- * Otherwise, a new 12-word mnemonic is generated and stored.
118
- *
119
- * @returns The mnemonic phrase
120
- */
121
- async generateOrGetMnemonic() {
122
- return await this.wasmWallet.generate_or_get_mnemonic();
123
- }
124
- /**
125
- * Get the stored mnemonic (for backup display).
126
- *
127
- * @returns The mnemonic phrase, or null if not generated
128
- */
129
- async getMnemonic() {
130
- const result = await this.wasmWallet.get_mnemonic();
131
- return result;
132
- }
133
- /**
134
- * Import a mnemonic phrase (replaces existing).
135
- *
136
- * @param phrase - The mnemonic phrase to import
137
- */
138
- async importMnemonic(phrase) {
139
- await this.wasmWallet.import_mnemonic(phrase);
140
- }
141
- /**
142
- * Derive swap parameters for a new swap.
143
- *
144
- * This automatically increments the key derivation index.
145
- *
146
- * @returns The derived swap parameters
147
- */
148
- async deriveSwapParams() {
149
- const result = await this.wasmWallet.derive_swap_params();
150
- return {
151
- ownSk: result.own_sk,
152
- ownPk: result.own_pk,
153
- preimage: result.preimage,
154
- preimageHash: result.preimage_hash,
155
- userId: result.user_id,
156
- keyIndex: result.key_index,
157
- };
158
- }
159
- /**
160
- * Derive swap parameters at a specific index (for recovery).
161
- *
162
- * This does not modify the stored key index.
163
- *
164
- * @param index - The derivation index to use
165
- * @returns The derived swap parameters
166
- */
167
- async deriveSwapParamsAtIndex(index) {
168
- const result = await this.wasmWallet.derive_swap_params_at_index(index);
169
- return {
170
- ownSk: result.own_sk,
171
- ownPk: result.own_pk,
172
- preimage: result.preimage,
173
- preimageHash: result.preimage_hash,
174
- userId: result.user_id,
175
- keyIndex: result.key_index,
176
- };
177
- }
178
- /**
179
- * Get the user ID Xpub for wallet recovery.
180
- *
181
- * @returns The extended public key, or null if no mnemonic
182
- */
183
- async getUserIdXpub() {
184
- const result = await this.wasmWallet.get_user_id_xpub();
185
- return result;
186
- }
187
- }
188
- //# sourceMappingURL=wallet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,qBAAqB;AACrB,OAAO,IAAI,EAAE,EACX,uBAAuB,EACvB,MAAM,IAAI,eAAe,GAC1B,MAAM,+BAA+B,CAAC;AAIvC,gCAAgC;AAChC,IAAI,WAAW,GAAyB,IAAI,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,QAAiB;IAC9C,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;QACxB,4BAA4B;QAC5B,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW;YAC9B,OAAO,CAAC,QAAQ,IAAI,IAAI;YACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC;QAEh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