lwk_node 0.14.1 → 0.16.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 +1 -39
- package/lwk_wasm.d.ts +232 -7
- package/lwk_wasm.js +747 -115
- package/lwk_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,42 +119,4 @@ node network.js
|
|
|
119
119
|
|
|
120
120
|
## Javascript code conventions
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
For object that have a string representation we implement `std::fmt::Display` and we expose them like that
|
|
125
|
-
|
|
126
|
-
```rust
|
|
127
|
-
#[wasm_bindgen(js_name = toString)]
|
|
128
|
-
pub fn to_string_js(&self) -> String {
|
|
129
|
-
self.to_string()
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### JSON
|
|
134
|
-
|
|
135
|
-
For objects that have a json representation, like the balance we provide a `toJSON()` method that must work when the caller use for example `JSON.stringify(object)`
|
|
136
|
-
Unfortunately `JSON.stringify` cannot serialize big integers by default, thus we use string representation for `BigInt`.
|
|
137
|
-
|
|
138
|
-
### Entries
|
|
139
|
-
|
|
140
|
-
Since JSON doesn't support `BigInt` some object expose also the js standard `entries()` method so that the following code is possible
|
|
141
|
-
|
|
142
|
-
```js
|
|
143
|
-
const balance = wallet.balance();
|
|
144
|
-
|
|
145
|
-
// 1. Create a Map
|
|
146
|
-
const balanceMap = new Map(balance.entries());
|
|
147
|
-
|
|
148
|
-
// 2. Iterate directly in a for...of loop
|
|
149
|
-
for (const [currency, amount] of balance.entries()) {
|
|
150
|
-
console.log(`${currency}: ${amount}`);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 3. Convert to a plain object
|
|
154
|
-
const balanceObject = Object.fromEntries(balance.entries());
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Documentation
|
|
158
|
-
|
|
159
|
-
Documentation of this crate should not use link to rust types such as [`Transaction`] because they are not usable in end-user javascript packages.
|
|
160
|
-
Many types are wrappers of types in lwk crates, in this cases we mostly duplicate the original documentation with context adjustment.
|
|
122
|
+
For new additions and improvements, follow our [guidelines](GUIDE.md).
|
package/lwk_wasm.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
export function searchLedgerDevice(): Promise<HIDDevice>;
|
|
3
4
|
/**
|
|
4
5
|
* Convert the given string to a QR code image uri
|
|
5
6
|
*
|
|
@@ -9,7 +10,6 @@
|
|
|
9
10
|
* for example in html: `style="image-rendering: pixelated; border: 20px solid white;"`
|
|
10
11
|
*/
|
|
11
12
|
export function stringToQr(str: string, pixel_per_module?: number | null): string;
|
|
12
|
-
export function searchLedgerDevice(): Promise<HIDDevice>;
|
|
13
13
|
/**
|
|
14
14
|
* Wallet chain
|
|
15
15
|
*/
|
|
@@ -290,6 +290,38 @@ export class AssetAmount {
|
|
|
290
290
|
amount(): bigint;
|
|
291
291
|
asset(): AssetId;
|
|
292
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* A blinding factor for asset commitments.
|
|
295
|
+
*/
|
|
296
|
+
export class AssetBlindingFactor {
|
|
297
|
+
private constructor();
|
|
298
|
+
free(): void;
|
|
299
|
+
[Symbol.dispose](): void;
|
|
300
|
+
/**
|
|
301
|
+
* Creates an `AssetBlindingFactor` from a string.
|
|
302
|
+
*/
|
|
303
|
+
static fromString(s: string): AssetBlindingFactor;
|
|
304
|
+
/**
|
|
305
|
+
* Creates an `AssetBlindingFactor` from a byte slice.
|
|
306
|
+
*/
|
|
307
|
+
static fromBytes(bytes: Uint8Array): AssetBlindingFactor;
|
|
308
|
+
/**
|
|
309
|
+
* Returns a zero asset blinding factor.
|
|
310
|
+
*/
|
|
311
|
+
static zero(): AssetBlindingFactor;
|
|
312
|
+
/**
|
|
313
|
+
* Returns the bytes (32 bytes) in little-endian byte order.
|
|
314
|
+
*
|
|
315
|
+
* This is the internal representation used by secp256k1. The byte order is
|
|
316
|
+
* reversed compared to the hex string representation (which uses big-endian,
|
|
317
|
+
* following Bitcoin display conventions).
|
|
318
|
+
*/
|
|
319
|
+
toBytes(): Uint8Array;
|
|
320
|
+
/**
|
|
321
|
+
* Returns string representation of the ABF
|
|
322
|
+
*/
|
|
323
|
+
toString(): string;
|
|
324
|
+
}
|
|
293
325
|
/**
|
|
294
326
|
* A valid asset identifier.
|
|
295
327
|
*
|
|
@@ -300,11 +332,25 @@ export class AssetId {
|
|
|
300
332
|
[Symbol.dispose](): void;
|
|
301
333
|
/**
|
|
302
334
|
* Creates an `AssetId`
|
|
335
|
+
*
|
|
336
|
+
* Deprecated: use `from_string()` instead
|
|
303
337
|
*/
|
|
304
338
|
constructor(asset_id: string);
|
|
339
|
+
/**
|
|
340
|
+
* Creates an `AssetId` from hex string
|
|
341
|
+
*/
|
|
342
|
+
static fromString(s: string): AssetId;
|
|
343
|
+
/**
|
|
344
|
+
* Creates an `AssetId` from a bytes.
|
|
345
|
+
*/
|
|
346
|
+
static fromBytes(bytes: Uint8Array): AssetId;
|
|
347
|
+
/**
|
|
348
|
+
* Returns the `AssetId` bytes in little-endian byte order.
|
|
349
|
+
*/
|
|
350
|
+
toBytes(): Uint8Array;
|
|
305
351
|
/**
|
|
306
352
|
* Return the string representation of the asset identifier (64 hex characters).
|
|
307
|
-
* This representation can be used to recreate the asset identifier via `
|
|
353
|
+
* This representation can be used to recreate the asset identifier via `fromString()`
|
|
308
354
|
*/
|
|
309
355
|
toString(): string;
|
|
310
356
|
}
|
|
@@ -620,6 +666,17 @@ export class ExchangeRates {
|
|
|
620
666
|
*/
|
|
621
667
|
serialize(): string;
|
|
622
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* An external UTXO, owned by another wallet.
|
|
671
|
+
*/
|
|
672
|
+
export class ExternalUtxo {
|
|
673
|
+
free(): void;
|
|
674
|
+
[Symbol.dispose](): void;
|
|
675
|
+
/**
|
|
676
|
+
* Construct an ExternalUtxo
|
|
677
|
+
*/
|
|
678
|
+
constructor(vout: number, tx: Transaction, unblinded: TxOutSecrets, max_weight_to_satisfy: number, is_segwit: boolean);
|
|
679
|
+
}
|
|
623
680
|
/**
|
|
624
681
|
* Wrapper over [`lwk_boltz::InvoiceResponse`]
|
|
625
682
|
*/
|
|
@@ -758,6 +815,42 @@ export class JadeWebSocket {
|
|
|
758
815
|
keyoriginXpub(bip: Bip): Promise<string>;
|
|
759
816
|
registerDescriptor(name: string, desc: WolletDescriptor): Promise<boolean>;
|
|
760
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* A bridge that connects a [`JsStorage`] to [`lwk_common::Store`].
|
|
820
|
+
*/
|
|
821
|
+
export class JsStoreLink {
|
|
822
|
+
free(): void;
|
|
823
|
+
[Symbol.dispose](): void;
|
|
824
|
+
/**
|
|
825
|
+
* Create a new `JsStoreLink` from a JavaScript storage object.
|
|
826
|
+
*
|
|
827
|
+
* The JS object must have `get(key)`, `put(key, value)`, and `remove(key)` methods.
|
|
828
|
+
*/
|
|
829
|
+
constructor(storage: any);
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Test helper to verify Rust can read/write through a JS store.
|
|
833
|
+
*/
|
|
834
|
+
export class JsTestStore {
|
|
835
|
+
free(): void;
|
|
836
|
+
[Symbol.dispose](): void;
|
|
837
|
+
/**
|
|
838
|
+
* Create a new test helper wrapping the given JS storage.
|
|
839
|
+
*/
|
|
840
|
+
constructor(storage: any);
|
|
841
|
+
/**
|
|
842
|
+
* Write a key-value pair to the store.
|
|
843
|
+
*/
|
|
844
|
+
write(key: string, value: Uint8Array): void;
|
|
845
|
+
/**
|
|
846
|
+
* Read a value from the store.
|
|
847
|
+
*/
|
|
848
|
+
read(key: string): Uint8Array | undefined;
|
|
849
|
+
/**
|
|
850
|
+
* Remove a key from the store.
|
|
851
|
+
*/
|
|
852
|
+
remove(key: string): void;
|
|
853
|
+
}
|
|
761
854
|
/**
|
|
762
855
|
* Response from the last_used_index endpoint
|
|
763
856
|
*
|
|
@@ -920,6 +1013,10 @@ export class Network {
|
|
|
920
1013
|
* Return the policy asset for this network
|
|
921
1014
|
*/
|
|
922
1015
|
policyAsset(): AssetId;
|
|
1016
|
+
/**
|
|
1017
|
+
* Return the genesis block hash for this network as hex string.
|
|
1018
|
+
*/
|
|
1019
|
+
genesisBlockHash(): string;
|
|
923
1020
|
/**
|
|
924
1021
|
* Return the transaction builder for this network
|
|
925
1022
|
*/
|
|
@@ -949,9 +1046,13 @@ export class OutPoint {
|
|
|
949
1046
|
free(): void;
|
|
950
1047
|
[Symbol.dispose](): void;
|
|
951
1048
|
/**
|
|
952
|
-
* Creates an `OutPoint`
|
|
1049
|
+
* Creates an `OutPoint` from a string representation.
|
|
953
1050
|
*/
|
|
954
1051
|
constructor(s: string);
|
|
1052
|
+
/**
|
|
1053
|
+
* Creates an `OutPoint` from a transaction ID and output index.
|
|
1054
|
+
*/
|
|
1055
|
+
static fromParts(txid: Txid, vout: number): OutPoint;
|
|
955
1056
|
/**
|
|
956
1057
|
* Return the transaction identifier.
|
|
957
1058
|
*/
|
|
@@ -1096,6 +1197,12 @@ export class Pset {
|
|
|
1096
1197
|
* the available signature information in place.
|
|
1097
1198
|
*/
|
|
1098
1199
|
extractTx(): Transaction;
|
|
1200
|
+
/**
|
|
1201
|
+
* Get the unique id of the PSET as defined by [BIP-370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#unique-identification)
|
|
1202
|
+
*
|
|
1203
|
+
* The unique id is the txid of the PSET with sequence numbers of inputs set to 0
|
|
1204
|
+
*/
|
|
1205
|
+
uniqueId(): Txid;
|
|
1099
1206
|
/**
|
|
1100
1207
|
* Attempt to merge with another `Pset`.
|
|
1101
1208
|
*/
|
|
@@ -1175,6 +1282,14 @@ export class PsetInput {
|
|
|
1175
1282
|
* Prevout vout of the input
|
|
1176
1283
|
*/
|
|
1177
1284
|
previousVout(): number;
|
|
1285
|
+
/**
|
|
1286
|
+
* Prevout scriptpubkey of the input
|
|
1287
|
+
*/
|
|
1288
|
+
previousScriptPubkey(): Script | undefined;
|
|
1289
|
+
/**
|
|
1290
|
+
* Redeem script of the input
|
|
1291
|
+
*/
|
|
1292
|
+
redeemScript(): Script | undefined;
|
|
1178
1293
|
/**
|
|
1179
1294
|
* If the input has an issuance, the asset id
|
|
1180
1295
|
*/
|
|
@@ -1183,6 +1298,19 @@ export class PsetInput {
|
|
|
1183
1298
|
* If the input has an issuance, the token id
|
|
1184
1299
|
*/
|
|
1185
1300
|
issuanceToken(): AssetId | undefined;
|
|
1301
|
+
/**
|
|
1302
|
+
* If the input has a (re)issuance, the issuance object
|
|
1303
|
+
*/
|
|
1304
|
+
issuance(): Issuance | undefined;
|
|
1305
|
+
/**
|
|
1306
|
+
* Input sighash
|
|
1307
|
+
*/
|
|
1308
|
+
sighash(): number;
|
|
1309
|
+
/**
|
|
1310
|
+
* If the input has an issuance, returns [asset_id, token_id].
|
|
1311
|
+
* Returns undefined if the input has no issuance.
|
|
1312
|
+
*/
|
|
1313
|
+
issuanceIds(): AssetId[] | undefined;
|
|
1186
1314
|
}
|
|
1187
1315
|
/**
|
|
1188
1316
|
* PSET output
|
|
@@ -1191,7 +1319,22 @@ export class PsetOutput {
|
|
|
1191
1319
|
private constructor();
|
|
1192
1320
|
free(): void;
|
|
1193
1321
|
[Symbol.dispose](): void;
|
|
1322
|
+
/**
|
|
1323
|
+
* Get the script pubkey
|
|
1324
|
+
*/
|
|
1194
1325
|
scriptPubkey(): Script;
|
|
1326
|
+
/**
|
|
1327
|
+
* Get the explicit amount, if set
|
|
1328
|
+
*/
|
|
1329
|
+
amount(): bigint | undefined;
|
|
1330
|
+
/**
|
|
1331
|
+
* Get the explicit asset ID, if set
|
|
1332
|
+
*/
|
|
1333
|
+
asset(): AssetId | undefined;
|
|
1334
|
+
/**
|
|
1335
|
+
* Get the blinder index, if set
|
|
1336
|
+
*/
|
|
1337
|
+
blinderIndex(): number | undefined;
|
|
1195
1338
|
}
|
|
1196
1339
|
/**
|
|
1197
1340
|
* The details of the signatures in a PSET, divided in available and missing signatures.
|
|
@@ -1302,16 +1445,44 @@ export class Script {
|
|
|
1302
1445
|
* Creates a `Script` from its hex string representation.
|
|
1303
1446
|
*/
|
|
1304
1447
|
constructor(s: string);
|
|
1448
|
+
/**
|
|
1449
|
+
* Creates an empty `Script`.
|
|
1450
|
+
*/
|
|
1451
|
+
static empty(): Script;
|
|
1305
1452
|
/**
|
|
1306
1453
|
* Return the consensus encoded bytes of the script.
|
|
1307
1454
|
*/
|
|
1308
1455
|
bytes(): Uint8Array;
|
|
1456
|
+
/**
|
|
1457
|
+
* Returns SHA256 of the script's consensus bytes.
|
|
1458
|
+
*
|
|
1459
|
+
* Returns an equivalent value to the `jet::input_script_hash(index)`/`jet::output_script_hash(index)`.
|
|
1460
|
+
*/
|
|
1461
|
+
jet_sha256_hex(): string;
|
|
1309
1462
|
/**
|
|
1310
1463
|
* Return the string of the script showing op codes and their arguments.
|
|
1311
1464
|
*
|
|
1312
1465
|
* For example: "OP_DUP OP_HASH160 OP_PUSHBYTES_20 088ac47276d105b91cf9aa27a00112421dd5f23c OP_EQUALVERIFY OP_CHECKSIG"
|
|
1313
1466
|
*/
|
|
1314
1467
|
asm(): string;
|
|
1468
|
+
/**
|
|
1469
|
+
* Creates an OP_RETURN script with the given data.
|
|
1470
|
+
*/
|
|
1471
|
+
static newOpReturn(data: Uint8Array): Script;
|
|
1472
|
+
/**
|
|
1473
|
+
* Returns true if the script is provably unspendable.
|
|
1474
|
+
*
|
|
1475
|
+
* A script is provably unspendable if it starts with OP_RETURN or is larger
|
|
1476
|
+
* than the maximum script size.
|
|
1477
|
+
*/
|
|
1478
|
+
isProvablyUnspendable(): boolean;
|
|
1479
|
+
/**
|
|
1480
|
+
* Returns true if this script_pubkey is provably SegWit.
|
|
1481
|
+
*
|
|
1482
|
+
* This checks if the script_pubkey is provably SegWit based on the
|
|
1483
|
+
* script_pubkey itself and an optional redeem_script.
|
|
1484
|
+
*/
|
|
1485
|
+
isProvablySegwit(redeem_script?: Script | null): boolean;
|
|
1315
1486
|
/**
|
|
1316
1487
|
* Return the string representation of the script (hex encoding of its consensus encoded bytes).
|
|
1317
1488
|
* This representation can be used to recreate the script via `new()`
|
|
@@ -1401,8 +1572,18 @@ export class Transaction {
|
|
|
1401
1572
|
[Symbol.dispose](): void;
|
|
1402
1573
|
/**
|
|
1403
1574
|
* Creates a `Transaction`
|
|
1575
|
+
*
|
|
1576
|
+
* Deprecated: use `fromString()` instead.
|
|
1404
1577
|
*/
|
|
1405
1578
|
constructor(tx_hex: string);
|
|
1579
|
+
/**
|
|
1580
|
+
* Creates a `Transaction` from hex-encoded consensus bytes.
|
|
1581
|
+
*/
|
|
1582
|
+
static fromString(s: string): Transaction;
|
|
1583
|
+
/**
|
|
1584
|
+
* Creates a `Transaction` from consensus-encoded bytes.
|
|
1585
|
+
*/
|
|
1586
|
+
static fromBytes(bytes: Uint8Array): Transaction;
|
|
1406
1587
|
/**
|
|
1407
1588
|
* Return the transaction identifier.
|
|
1408
1589
|
*/
|
|
@@ -1410,6 +1591,12 @@ export class Transaction {
|
|
|
1410
1591
|
/**
|
|
1411
1592
|
* Return the consensus encoded bytes of the transaction.
|
|
1412
1593
|
*/
|
|
1594
|
+
toBytes(): Uint8Array;
|
|
1595
|
+
/**
|
|
1596
|
+
* Return the consensus encoded bytes of the transaction.
|
|
1597
|
+
*
|
|
1598
|
+
* Deprecated: use `toBytes()` instead.
|
|
1599
|
+
*/
|
|
1413
1600
|
bytes(): Uint8Array;
|
|
1414
1601
|
/**
|
|
1415
1602
|
* Return the fee of the transaction in the given asset.
|
|
@@ -1539,22 +1726,28 @@ export class TxOutSecrets {
|
|
|
1539
1726
|
private constructor();
|
|
1540
1727
|
free(): void;
|
|
1541
1728
|
[Symbol.dispose](): void;
|
|
1729
|
+
/**
|
|
1730
|
+
* Creates a new `TxOutSecrets` for an explicit (unblinded) output.
|
|
1731
|
+
*
|
|
1732
|
+
* The blinding factors are set to zero.
|
|
1733
|
+
*/
|
|
1734
|
+
static fromExplicit(asset_id: AssetId, value: bigint): TxOutSecrets;
|
|
1542
1735
|
/**
|
|
1543
1736
|
* Return the asset of the output.
|
|
1544
1737
|
*/
|
|
1545
1738
|
asset(): AssetId;
|
|
1546
1739
|
/**
|
|
1547
|
-
* Return the asset blinding factor as a
|
|
1740
|
+
* Return the asset blinding factor as a typed object.
|
|
1548
1741
|
*/
|
|
1549
|
-
assetBlindingFactor():
|
|
1742
|
+
assetBlindingFactor(): AssetBlindingFactor;
|
|
1550
1743
|
/**
|
|
1551
1744
|
* Return the value of the output.
|
|
1552
1745
|
*/
|
|
1553
1746
|
value(): bigint;
|
|
1554
1747
|
/**
|
|
1555
|
-
* Return the value blinding factor as a
|
|
1748
|
+
* Return the value blinding factor as a typed object.
|
|
1556
1749
|
*/
|
|
1557
|
-
valueBlindingFactor():
|
|
1750
|
+
valueBlindingFactor(): ValueBlindingFactor;
|
|
1558
1751
|
/**
|
|
1559
1752
|
* Return true if the output is explicit (no blinding factors).
|
|
1560
1753
|
*/
|
|
@@ -1659,6 +1852,38 @@ export class ValidatedLiquidexProposal {
|
|
|
1659
1852
|
output(): AssetAmount;
|
|
1660
1853
|
toString(): string;
|
|
1661
1854
|
}
|
|
1855
|
+
/**
|
|
1856
|
+
* A blinding factor for value commitments.
|
|
1857
|
+
*/
|
|
1858
|
+
export class ValueBlindingFactor {
|
|
1859
|
+
private constructor();
|
|
1860
|
+
free(): void;
|
|
1861
|
+
[Symbol.dispose](): void;
|
|
1862
|
+
/**
|
|
1863
|
+
* Creates a `ValueBlindingFactor` from a string.
|
|
1864
|
+
*/
|
|
1865
|
+
static fromString(s: string): ValueBlindingFactor;
|
|
1866
|
+
/**
|
|
1867
|
+
* Creates a `ValueBlindingFactor` from a byte slice.
|
|
1868
|
+
*/
|
|
1869
|
+
static fromBytes(bytes: Uint8Array): ValueBlindingFactor;
|
|
1870
|
+
/**
|
|
1871
|
+
* Returns a zero value blinding factor.
|
|
1872
|
+
*/
|
|
1873
|
+
static zero(): ValueBlindingFactor;
|
|
1874
|
+
/**
|
|
1875
|
+
* Returns the bytes (32 bytes) in little-endian byte order.
|
|
1876
|
+
*
|
|
1877
|
+
* This is the internal representation used by secp256k1. The byte order is
|
|
1878
|
+
* reversed compared to the hex string representation (which uses big-endian,
|
|
1879
|
+
* following Bitcoin display conventions).
|
|
1880
|
+
*/
|
|
1881
|
+
toBytes(): Uint8Array;
|
|
1882
|
+
/**
|
|
1883
|
+
* Returns string representation of the VBF
|
|
1884
|
+
*/
|
|
1885
|
+
toString(): string;
|
|
1886
|
+
}
|
|
1662
1887
|
/**
|
|
1663
1888
|
* Value returned by asking transactions to the wallet. Contains details about a transaction
|
|
1664
1889
|
* from the perspective of the wallet, for example the net-balance of the transaction for the
|