lwk_node 0.8.5

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 ADDED
@@ -0,0 +1,92 @@
1
+
2
+ # Liquid Wallet Kit for WASM
3
+
4
+ This is only a proof of concept at the moment but we want to show our commitment to have the
5
+ Liquid Wallet Kit working in the WASM environment.
6
+
7
+ [Available](https://www.npmjs.com/package/lwk_wasm) as npm package.
8
+
9
+ For an example usage see the [Liquid Web Wallet](https://liquidwebwallet.org/) ([source](https://github.com/RCasatta/liquid-web-wallet)). Works as CT descriptor watch-only wallet or connected to a Jade.
10
+
11
+
12
+ ## For LWK Library developers
13
+
14
+ To build the WASM library you need [rust](https://www.rust-lang.org/learn/get-started) and
15
+ [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) installed
16
+
17
+ ```shell
18
+ $ wasm-pack build --dev
19
+ ```
20
+
21
+ To enable web-serial:
22
+
23
+ ```shell
24
+ $ RUSTFLAGS="--cfg=web_sys_unstable_apis" wasm-pack build --dev --features serial
25
+ ```
26
+
27
+ ## For LWK library consumers (front-end developers)
28
+
29
+ Download the Liquid Web Wallet source
30
+
31
+ ```shell
32
+ $ git clone https://github.com/RCasatta/liquid-web-wallet
33
+ $ npm install
34
+ $ npm run start
35
+ ```
36
+
37
+ Open the browser at `http://localhost:8080`
38
+
39
+ ### Test
40
+
41
+ ```shell
42
+ $ cd lwk_wasm
43
+ $ wasm-pack test --firefox # or --chrome
44
+ ```
45
+
46
+ Then open the browser at http://127.0.0.1:8000, open also the dev tools to see console messages and
47
+ network requests.
48
+
49
+ To avoid requiring opening the browser the headless mode is possible.
50
+
51
+ Note the increased timeout specified via the env var, the 20s default one could be too low.
52
+
53
+ ```shell
54
+ $ cd lwk_wasm
55
+ $ WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --firefox --headless
56
+ ```
57
+
58
+ run specific test (note the double `--`)
59
+
60
+ ```shell
61
+ $ wasm-pack test --firefox --headless -- -- balance_test_testnet
62
+ ```
63
+
64
+ ### Build NPM Package for release
65
+
66
+ Build rust crates in release mode, optimizing for space.
67
+
68
+ ```shell
69
+ $ cd lwk_wasm/
70
+ $ RUSTFLAGS="--cfg=web_sys_unstable_apis" CARGO_PROFILE_RELEASE_OPT_LEVEL=z wasm-pack build --features serial
71
+ ```
72
+
73
+ ```shell
74
+ $ cd pkg
75
+ $ npm publish
76
+ ```
77
+
78
+ ### Build wasm lib for profiling
79
+
80
+ To analyze the generated wasm file to optimize for size, we want to follow the same optimization
81
+ as release but we want to keep debug info to analyze the produced lib with function names.
82
+
83
+ ```shell
84
+ $ cd lwk_wasm/
85
+ $ RUSTFLAGS="--cfg=web_sys_unstable_apis" CARGO_PROFILE_RELEASE_OPT_LEVEL=z CARGO_PROFILE_RELEASE_DEBUG=2 wasm-pack build --profiling --features serial
86
+ ```
87
+
88
+ With [twiggy](https://github.com/rustwasm/twiggy) is then possible to analyze the library:
89
+
90
+ ```shell
91
+ twiggy top -n 10 pkg/lwk_wasm_bg.wasm
92
+ ```
package/lwk_wasm.d.ts ADDED
@@ -0,0 +1,606 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export function search_ledger_device(): Promise<HIDDevice>;
4
+ /**
5
+ * Wallet chain
6
+ */
7
+ export enum Chain {
8
+ /**
9
+ * External address, shown when asked for a payment.
10
+ * Wallet having a single descriptor are considered External
11
+ */
12
+ External = 0,
13
+ /**
14
+ * Internal address, used for the change
15
+ */
16
+ Internal = 1,
17
+ }
18
+ /**
19
+ * Wrapper of [`elements::Address`]
20
+ */
21
+ export class Address {
22
+ free(): void;
23
+ /**
24
+ * Creates an `Address`
25
+ */
26
+ constructor(s: string);
27
+ scriptPubkey(): Script;
28
+ isBlinded(): boolean;
29
+ isMainnet(): boolean;
30
+ toUnconfidential(): Address;
31
+ toString(): string;
32
+ /**
33
+ * Returns a string encoding an image in a uri
34
+ *
35
+ * The string can be open in the browser or be used as `src` field in `img` in HTML
36
+ *
37
+ * For max efficiency we suggest to pass `None` to `pixel_per_module`, get a very small image
38
+ * and use styling to scale up the image in the browser. eg
39
+ * `style="image-rendering: pixelated; border: 20px solid white;"`
40
+ */
41
+ QRCodeUri(pixel_per_module?: number): string;
42
+ /**
43
+ * Returns a string of the QR code printable in a terminal environment
44
+ */
45
+ QRCodeText(): string;
46
+ }
47
+ /**
48
+ * Wrapper of [`lwk_wollet::AddressResult`]
49
+ */
50
+ export class AddressResult {
51
+ private constructor();
52
+ free(): void;
53
+ address(): Address;
54
+ index(): number;
55
+ }
56
+ /**
57
+ * Wrapper of [`lwk_wollet::amp2::Amp2`]
58
+ */
59
+ export class Amp2 {
60
+ private constructor();
61
+ free(): void;
62
+ static new_testnet(): Amp2;
63
+ descriptor_from_str(keyorigin_xpub: string): Amp2Descriptor;
64
+ register(desc: Amp2Descriptor): Promise<string>;
65
+ cosign(pset: Pset): Promise<Pset>;
66
+ }
67
+ /**
68
+ * Wrapper of [`lwk_wollet::amp2::Amp2Descriptor`]
69
+ */
70
+ export class Amp2Descriptor {
71
+ private constructor();
72
+ free(): void;
73
+ descriptor(): WolletDescriptor;
74
+ toString(): string;
75
+ }
76
+ /**
77
+ * A valid asset identifier. wrapper of [`elements::AssetId`]
78
+ *
79
+ * 32 bytes encoded as hex string.
80
+ */
81
+ export class AssetId {
82
+ free(): void;
83
+ /**
84
+ * Creates an `AssetId`
85
+ */
86
+ constructor(asset_id: string);
87
+ toString(): string;
88
+ }
89
+ /**
90
+ * wrapper over [`lwk_common::Bip`]
91
+ */
92
+ export class Bip {
93
+ private constructor();
94
+ free(): void;
95
+ /**
96
+ * Creates a bip49 variant
97
+ */
98
+ static bip49(): Bip;
99
+ /**
100
+ * Creates a bip84 variant
101
+ */
102
+ static bip84(): Bip;
103
+ /**
104
+ * Creates a bip87 variant
105
+ */
106
+ static bip87(): Bip;
107
+ toString(): string;
108
+ }
109
+ /**
110
+ * Wrapper of [`lwk_wollet::Contract`]
111
+ */
112
+ export class Contract {
113
+ free(): void;
114
+ /**
115
+ * Creates a `Contract`
116
+ */
117
+ constructor(domain: string, issuer_pubkey: string, name: string, precision: number, ticker: string, version: number);
118
+ toString(): string;
119
+ }
120
+ /**
121
+ * Wrapper of [`asyncr::EsploraClient`]
122
+ */
123
+ export class EsploraClient {
124
+ free(): void;
125
+ /**
126
+ * Creates a client, wrapper of [`asyncr::EsploraClient`]
127
+ */
128
+ constructor(network: Network, url: string, waterfalls: boolean);
129
+ fullScan(wollet: Wollet): Promise<Update | undefined>;
130
+ broadcast(pset: Pset): Promise<Txid>;
131
+ set_waterfalls_server_recipient(recipient: string): Promise<void>;
132
+ }
133
+ /**
134
+ * PSET details from a perspective of a wallet, wrapper of [`lwk_common::Issuance`]
135
+ */
136
+ export class Issuance {
137
+ private constructor();
138
+ free(): void;
139
+ asset(): AssetId | undefined;
140
+ token(): AssetId | undefined;
141
+ prevVout(): number | undefined;
142
+ prevTxid(): Txid | undefined;
143
+ isIssuance(): boolean;
144
+ isReissuance(): boolean;
145
+ }
146
+ /**
147
+ * Wrapper of [`asyncr::Jade`]
148
+ */
149
+ export class Jade {
150
+ free(): void;
151
+ /**
152
+ * Creates a Jade from Web Serial for the given network
153
+ *
154
+ * When filter is true, it will filter available serial with Blockstream released chips, use
155
+ * false if you don't see your DYI jade
156
+ */
157
+ constructor(network: Network, filter: boolean);
158
+ getVersion(): Promise<any>;
159
+ getMasterXpub(): Promise<Xpub>;
160
+ /**
161
+ * Return a single sig address with the given `variant` and `path` derivation
162
+ */
163
+ getReceiveAddressSingle(variant: Singlesig, path: Uint32Array): Promise<string>;
164
+ /**
165
+ * Return a multisig address of a registered `multisig_name` wallet
166
+ *
167
+ * This method accept `path` and `path_n` in place of a single `Vec<Vec<u32>>` because the
168
+ * latter is not supported by wasm_bindgen (and neither `(u32, Vec<u32>)`). `path` and `path_n`
169
+ * are converted internally to a `Vec<Vec<u32>>` with the caveat all the paths are the same,
170
+ * which is almost always the case.
171
+ */
172
+ getReceiveAddressMulti(multisig_name: string, path: Uint32Array): Promise<string>;
173
+ /**
174
+ * Sign and consume the given PSET, returning the signed one
175
+ */
176
+ sign(pset: Pset): Promise<Pset>;
177
+ wpkh(): Promise<WolletDescriptor>;
178
+ shWpkh(): Promise<WolletDescriptor>;
179
+ multi(name: string): Promise<WolletDescriptor>;
180
+ getRegisteredMultisigs(): Promise<any>;
181
+ keyoriginXpub(bip: Bip): Promise<string>;
182
+ registerDescriptor(name: string, desc: WolletDescriptor): Promise<boolean>;
183
+ }
184
+ export class LedgerWeb {
185
+ free(): void;
186
+ constructor(hid_device: HIDDevice);
187
+ get_version(): Promise<string>;
188
+ }
189
+ /**
190
+ * Wrapper of [`bip39::Mnemonic`]
191
+ */
192
+ export class Mnemonic {
193
+ free(): void;
194
+ /**
195
+ * Creates a Mnemonic
196
+ */
197
+ constructor(s: string);
198
+ toString(): string;
199
+ /**
200
+ * Creates a Mnemonic from entropy, at least 16 bytes are needed.
201
+ */
202
+ static fromEntropy(b: Uint8Array): Mnemonic;
203
+ /**
204
+ * Creates a random Mnemonic of given words (12,15,18,21,24)
205
+ */
206
+ static fromRandom(word_count: number): Mnemonic;
207
+ }
208
+ /**
209
+ * Wrapper of [`lwk_wollet::ElementsNetwork`]
210
+ */
211
+ export class Network {
212
+ private constructor();
213
+ free(): void;
214
+ /**
215
+ * Creates a mainnet `Network``
216
+ */
217
+ static mainnet(): Network;
218
+ /**
219
+ * Creates a testnet `Network``
220
+ */
221
+ static testnet(): Network;
222
+ /**
223
+ * Creates a regtest `Network``
224
+ */
225
+ static regtest(policy_asset: AssetId): Network;
226
+ /**
227
+ * Creates the default regtest `Network`
228
+ */
229
+ static regtestDefault(): Network;
230
+ defaultEsploraClient(): EsploraClient;
231
+ isMainnet(): boolean;
232
+ toString(): string;
233
+ policyAsset(): AssetId;
234
+ txBuilder(): TxBuilder;
235
+ defaultExplorerUrl(): string;
236
+ }
237
+ /**
238
+ * An optional wallet transaction output. Could be None when it's not possible to unblind.
239
+ * It seems required by wasm_bindgen because we can't return `Vec<Option<WalletTxOut>>`
240
+ */
241
+ export class OptionWalletTxOut {
242
+ private constructor();
243
+ free(): void;
244
+ get(): WalletTxOut | undefined;
245
+ }
246
+ /**
247
+ * Wrapper of [`elements::OutPoint`]
248
+ */
249
+ export class OutPoint {
250
+ free(): void;
251
+ /**
252
+ * Creates an `OutPoint`
253
+ */
254
+ constructor(s: string);
255
+ txid(): Txid;
256
+ vout(): number;
257
+ }
258
+ /**
259
+ * Wrapper of [`lwk_common::precision::Precision`]
260
+ */
261
+ export class Precision {
262
+ free(): void;
263
+ /**
264
+ * Creates a Precision
265
+ */
266
+ constructor(precision: number);
267
+ satsToString(sats: bigint): string;
268
+ stringToSats(sats: string): bigint;
269
+ }
270
+ /**
271
+ * Partially Signed Elements Transaction, wrapper of [`PartiallySignedTransaction`]
272
+ */
273
+ export class Pset {
274
+ free(): void;
275
+ /**
276
+ * Creates a `Pset`
277
+ */
278
+ constructor(base64: string);
279
+ toString(): string;
280
+ extractTx(): Transaction;
281
+ combine(other: Pset): void;
282
+ inputs(): (PsetInput)[];
283
+ }
284
+ /**
285
+ * PSET details from a perspective of a wallet, wrapper of [`lwk_common::PsetBalance`]
286
+ */
287
+ export class PsetBalance {
288
+ private constructor();
289
+ free(): void;
290
+ fee(): bigint;
291
+ /**
292
+ * The net balance for every asset with respect of the wallet asking the pset details
293
+ */
294
+ balances(): any;
295
+ recipients(): (Recipient)[];
296
+ }
297
+ /**
298
+ * PSET details from a perspective of a wallet, wrapper of [`lwk_common::PsetDetails`]
299
+ */
300
+ export class PsetDetails {
301
+ private constructor();
302
+ free(): void;
303
+ balance(): PsetBalance;
304
+ /**
305
+ * For each input existing or missing signatures
306
+ */
307
+ signatures(): (PsetSignatures)[];
308
+ fingerprintsMissing(): (string)[];
309
+ fingerprintsHas(): (string)[];
310
+ /**
311
+ * Return an element for every input that could possibly be a issuance or a reissuance
312
+ */
313
+ inputsIssuances(): (Issuance)[];
314
+ }
315
+ /**
316
+ * PSET input
317
+ */
318
+ export class PsetInput {
319
+ private constructor();
320
+ free(): void;
321
+ /**
322
+ * Prevout TXID of the input
323
+ */
324
+ previous_txid(): Txid;
325
+ /**
326
+ * Prevout vout of the input
327
+ */
328
+ previous_vout(): number;
329
+ /**
330
+ * If the input has an issuance, the asset id
331
+ */
332
+ issuanceAsset(): AssetId | undefined;
333
+ /**
334
+ * If the input has an issuance, the token id
335
+ */
336
+ issuanceToken(): AssetId | undefined;
337
+ }
338
+ /**
339
+ * PSET details from a perspective of a wallet, wrapper of [`lwk_common::PsetSignatures`]
340
+ */
341
+ export class PsetSignatures {
342
+ private constructor();
343
+ free(): void;
344
+ /**
345
+ * Returns `Vec<(PublicKey, KeySource)>`
346
+ */
347
+ hasSignature(): any;
348
+ missingSignature(): any;
349
+ }
350
+ /**
351
+ * Recipient of a PSET, in other words outputs that doesn't belong to the wallet
352
+ */
353
+ export class Recipient {
354
+ private constructor();
355
+ free(): void;
356
+ asset(): AssetId | undefined;
357
+ value(): bigint | undefined;
358
+ address(): Address | undefined;
359
+ vout(): number;
360
+ }
361
+ /**
362
+ * Wrapper of [`elements::Script`]
363
+ */
364
+ export class Script {
365
+ free(): void;
366
+ /**
367
+ * Creates a `Script`
368
+ */
369
+ constructor(s: string);
370
+ bytes(): Uint8Array;
371
+ asm(): string;
372
+ toString(): string;
373
+ }
374
+ /**
375
+ * A Software signer, wrapper of [`lwk_signer::SwSigner`]
376
+ */
377
+ export class Signer {
378
+ free(): void;
379
+ /**
380
+ * Creates a `Signer`
381
+ */
382
+ constructor(mnemonic: Mnemonic, network: Network);
383
+ /**
384
+ * Sign and consume the given PSET, returning the signed one
385
+ */
386
+ sign(pset: Pset): Pset;
387
+ wpkhSlip77Descriptor(): WolletDescriptor;
388
+ getMasterXpub(): Xpub;
389
+ keyoriginXpub(bip: Bip): string;
390
+ mnemonic(): Mnemonic;
391
+ }
392
+ export class Singlesig {
393
+ private constructor();
394
+ free(): void;
395
+ static from(variant: string): Singlesig;
396
+ }
397
+ /**
398
+ * Wrapper of [`lwk_wollet::Tip`]
399
+ */
400
+ export class Tip {
401
+ private constructor();
402
+ free(): void;
403
+ height(): number;
404
+ hash(): string;
405
+ timestamp(): number | undefined;
406
+ }
407
+ /**
408
+ * A Liquid transaction, wrapper of [`elements::Transaction`]
409
+ *
410
+ * See [`crate::WalletTx`] for the transaction as seen from the perspective of the wallet
411
+ * where you can actually see unblinded amounts and tx net-balance.
412
+ */
413
+ export class Transaction {
414
+ free(): void;
415
+ /**
416
+ * Creates a `Transaction`
417
+ */
418
+ constructor(tx_hex: string);
419
+ txid(): Txid;
420
+ bytes(): Uint8Array;
421
+ fee(policy_asset: AssetId): bigint;
422
+ toString(): string;
423
+ }
424
+ /**
425
+ * Wrapper of [`lwk_wollet::TxBuilder`]
426
+ */
427
+ export class TxBuilder {
428
+ free(): void;
429
+ /**
430
+ * Creates a transaction builder
431
+ */
432
+ constructor(network: Network);
433
+ /**
434
+ * Build the transaction
435
+ */
436
+ finish(wollet: Wollet): Pset;
437
+ /**
438
+ * Set the fee rate
439
+ */
440
+ feeRate(fee_rate?: number): TxBuilder;
441
+ /**
442
+ * Select all available L-BTC inputs
443
+ */
444
+ drainLbtcWallet(): TxBuilder;
445
+ /**
446
+ * Sets the address to drain excess L-BTC to
447
+ */
448
+ drainLbtcTo(address: Address): TxBuilder;
449
+ /**
450
+ * Add a recipient receiving L-BTC
451
+ *
452
+ * Errors if address's network is incompatible
453
+ */
454
+ addLbtcRecipient(address: Address, satoshi: bigint): TxBuilder;
455
+ /**
456
+ * Add a recipient receiving the given asset
457
+ *
458
+ * Errors if address's network is incompatible
459
+ */
460
+ addRecipient(address: Address, satoshi: bigint, asset: AssetId): TxBuilder;
461
+ /**
462
+ * Burn satoshi units of the given asset
463
+ */
464
+ addBurn(satoshi: bigint, asset: AssetId): TxBuilder;
465
+ /**
466
+ * Issue an asset, wrapper of [`lwk_wollet::TxBuilder::issue_asset()`]
467
+ */
468
+ issueAsset(asset_sats: bigint, asset_receiver: Address | undefined, token_sats: bigint, token_receiver?: Address, contract?: Contract): TxBuilder;
469
+ /**
470
+ * Reissue an asset, wrapper of [`lwk_wollet::TxBuilder::reissue_asset()`]
471
+ */
472
+ reissueAsset(asset_to_reissue: AssetId, satoshi_to_reissue: bigint, asset_receiver?: Address, issuance_tx?: Transaction): TxBuilder;
473
+ toString(): string;
474
+ }
475
+ /**
476
+ * Wrapper of [`elements::TxOutSecrets`]
477
+ */
478
+ export class TxOutSecrets {
479
+ private constructor();
480
+ free(): void;
481
+ asset(): AssetId;
482
+ assetBlindingFactor(): string;
483
+ value(): bigint;
484
+ valueBlindingFactor(): string;
485
+ }
486
+ /**
487
+ * A valid transaction identifier.
488
+ *
489
+ * 32 bytes encoded as hex string.
490
+ */
491
+ export class Txid {
492
+ free(): void;
493
+ /**
494
+ * Creates a `Txid`
495
+ */
496
+ constructor(tx_id: string);
497
+ toString(): string;
498
+ }
499
+ /**
500
+ * Wrapper of [`lwk_wollet::Update`]
501
+ */
502
+ export class Update {
503
+ free(): void;
504
+ /**
505
+ * Creates an `Update`
506
+ */
507
+ constructor(bytes: Uint8Array);
508
+ serialize(): Uint8Array;
509
+ serializeEncryptedBase64(desc: WolletDescriptor): string;
510
+ static deserializeDecryptedBase64(base64: string, desc: WolletDescriptor): Update;
511
+ onlyTip(): boolean;
512
+ prune(wollet: Wollet): void;
513
+ }
514
+ /**
515
+ * Wrapper of [`lwk_wollet::WalletTx`]
516
+ */
517
+ export class WalletTx {
518
+ private constructor();
519
+ free(): void;
520
+ tx(): Transaction;
521
+ height(): number | undefined;
522
+ balance(): any;
523
+ txid(): Txid;
524
+ fee(): bigint;
525
+ txType(): string;
526
+ timestamp(): number | undefined;
527
+ inputs(): (OptionWalletTxOut)[];
528
+ outputs(): (OptionWalletTxOut)[];
529
+ unblindedUrl(explorer_url: string): string;
530
+ }
531
+ /**
532
+ * Wrapper of [`lwk_wollet::WalletTxOut`]
533
+ */
534
+ export class WalletTxOut {
535
+ private constructor();
536
+ free(): void;
537
+ outpoint(): OutPoint;
538
+ scriptPubkey(): Script;
539
+ height(): number | undefined;
540
+ unblinded(): TxOutSecrets;
541
+ wildcardIndex(): number;
542
+ extInt(): Chain;
543
+ }
544
+ /**
545
+ * Wrapper of [`lwk_wollet::Wollet`]
546
+ */
547
+ export class Wollet {
548
+ free(): void;
549
+ /**
550
+ * Create a `Wollet`
551
+ */
552
+ constructor(network: Network, descriptor: WolletDescriptor);
553
+ /**
554
+ * Get a wallet address with the correspondong derivation index
555
+ *
556
+ * If Some return the address at the given index,
557
+ * otherwise the last unused address.
558
+ */
559
+ address(index?: number): AddressResult;
560
+ addressFullPath(index: number): Uint32Array;
561
+ applyUpdate(update: Update): void;
562
+ balance(): any;
563
+ transactions(): (WalletTx)[];
564
+ /**
565
+ * Finalize and consume the given PSET, returning the finalized one
566
+ */
567
+ finalize(pset: Pset): Pset;
568
+ psetDetails(pset: Pset): PsetDetails;
569
+ descriptor(): WolletDescriptor;
570
+ status(): bigint;
571
+ tip(): Tip;
572
+ /**
573
+ * wraps [lwk_wollet::Wollet::never_scanned()]
574
+ */
575
+ neverScanned(): boolean;
576
+ }
577
+ /**
578
+ * Wrapper of [`lwk_wollet::WolletDescriptor`]
579
+ */
580
+ export class WolletDescriptor {
581
+ free(): void;
582
+ /**
583
+ * Creates a `WolletDescriptor`
584
+ */
585
+ constructor(descriptor: string);
586
+ toString(): string;
587
+ static newMultiWshSlip77(threshold: number, participants: (string)[]): WolletDescriptor;
588
+ isMainnet(): boolean;
589
+ }
590
+ /**
591
+ * Wrapper of [`bip32::Xpub`]
592
+ */
593
+ export class Xpub {
594
+ free(): void;
595
+ /**
596
+ * Creates a Mnemonic
597
+ */
598
+ constructor(s: string);
599
+ toString(): string;
600
+ identifier(): string;
601
+ fingerprint(): string;
602
+ /**
603
+ * Returns true if the passed string is a valid xpub with a valid keyorigin if present
604
+ */
605
+ static isValidWithKeyOrigin(s: string): boolean;
606
+ }