lwk_node 0.14.0 → 0.15.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 CHANGED
@@ -119,42 +119,4 @@ node network.js
119
119
 
120
120
  ## Javascript code conventions
121
121
 
122
- ### String
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
@@ -620,6 +620,17 @@ export class ExchangeRates {
620
620
  */
621
621
  serialize(): string;
622
622
  }
623
+ /**
624
+ * An external UTXO, owned by another wallet.
625
+ */
626
+ export class ExternalUtxo {
627
+ free(): void;
628
+ [Symbol.dispose](): void;
629
+ /**
630
+ * Construct an ExternalUtxo
631
+ */
632
+ constructor(vout: number, tx: Transaction, unblinded: TxOutSecrets, max_weight_to_satisfy: number, is_segwit: boolean);
633
+ }
623
634
  /**
624
635
  * Wrapper over [`lwk_boltz::InvoiceResponse`]
625
636
  */
@@ -758,6 +769,42 @@ export class JadeWebSocket {
758
769
  keyoriginXpub(bip: Bip): Promise<string>;
759
770
  registerDescriptor(name: string, desc: WolletDescriptor): Promise<boolean>;
760
771
  }
772
+ /**
773
+ * A bridge that connects a [`JsStorage`] to [`lwk_common::Store`].
774
+ */
775
+ export class JsStoreLink {
776
+ free(): void;
777
+ [Symbol.dispose](): void;
778
+ /**
779
+ * Create a new `JsStoreLink` from a JavaScript storage object.
780
+ *
781
+ * The JS object must have `get(key)`, `put(key, value)`, and `remove(key)` methods.
782
+ */
783
+ constructor(storage: any);
784
+ }
785
+ /**
786
+ * Test helper to verify Rust can read/write through a JS store.
787
+ */
788
+ export class JsTestStore {
789
+ free(): void;
790
+ [Symbol.dispose](): void;
791
+ /**
792
+ * Create a new test helper wrapping the given JS storage.
793
+ */
794
+ constructor(storage: any);
795
+ /**
796
+ * Write a key-value pair to the store.
797
+ */
798
+ write(key: string, value: Uint8Array): void;
799
+ /**
800
+ * Read a value from the store.
801
+ */
802
+ read(key: string): Uint8Array | undefined;
803
+ /**
804
+ * Remove a key from the store.
805
+ */
806
+ remove(key: string): void;
807
+ }
761
808
  /**
762
809
  * Response from the last_used_index endpoint
763
810
  *
@@ -920,6 +967,10 @@ export class Network {
920
967
  * Return the policy asset for this network
921
968
  */
922
969
  policyAsset(): AssetId;
970
+ /**
971
+ * Return the genesis block hash for this network as hex string.
972
+ */
973
+ genesisBlockHash(): string;
923
974
  /**
924
975
  * Return the transaction builder for this network
925
976
  */
@@ -949,9 +1000,13 @@ export class OutPoint {
949
1000
  free(): void;
950
1001
  [Symbol.dispose](): void;
951
1002
  /**
952
- * Creates an `OutPoint`
1003
+ * Creates an `OutPoint` from a string representation.
953
1004
  */
954
1005
  constructor(s: string);
1006
+ /**
1007
+ * Creates an `OutPoint` from a transaction ID and output index.
1008
+ */
1009
+ static fromParts(txid: Txid, vout: number): OutPoint;
955
1010
  /**
956
1011
  * Return the transaction identifier.
957
1012
  */
@@ -1096,6 +1151,12 @@ export class Pset {
1096
1151
  * the available signature information in place.
1097
1152
  */
1098
1153
  extractTx(): Transaction;
1154
+ /**
1155
+ * Get the unique id of the PSET as defined by [BIP-370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#unique-identification)
1156
+ *
1157
+ * The unique id is the txid of the PSET with sequence numbers of inputs set to 0
1158
+ */
1159
+ uniqueId(): Txid;
1099
1160
  /**
1100
1161
  * Attempt to merge with another `Pset`.
1101
1162
  */
@@ -1175,6 +1236,14 @@ export class PsetInput {
1175
1236
  * Prevout vout of the input
1176
1237
  */
1177
1238
  previousVout(): number;
1239
+ /**
1240
+ * Prevout scriptpubkey of the input
1241
+ */
1242
+ previousScriptPubkey(): Script | undefined;
1243
+ /**
1244
+ * Redeem script of the input
1245
+ */
1246
+ redeemScript(): Script | undefined;
1178
1247
  /**
1179
1248
  * If the input has an issuance, the asset id
1180
1249
  */
@@ -1183,6 +1252,19 @@ export class PsetInput {
1183
1252
  * If the input has an issuance, the token id
1184
1253
  */
1185
1254
  issuanceToken(): AssetId | undefined;
1255
+ /**
1256
+ * If the input has a (re)issuance, the issuance object
1257
+ */
1258
+ issuance(): Issuance | undefined;
1259
+ /**
1260
+ * Input sighash
1261
+ */
1262
+ sighash(): number;
1263
+ /**
1264
+ * If the input has an issuance, returns [asset_id, token_id].
1265
+ * Returns undefined if the input has no issuance.
1266
+ */
1267
+ issuanceIds(): AssetId[] | undefined;
1186
1268
  }
1187
1269
  /**
1188
1270
  * PSET output
@@ -1191,7 +1273,22 @@ export class PsetOutput {
1191
1273
  private constructor();
1192
1274
  free(): void;
1193
1275
  [Symbol.dispose](): void;
1276
+ /**
1277
+ * Get the script pubkey
1278
+ */
1194
1279
  scriptPubkey(): Script;
1280
+ /**
1281
+ * Get the explicit amount, if set
1282
+ */
1283
+ amount(): bigint | undefined;
1284
+ /**
1285
+ * Get the explicit asset ID, if set
1286
+ */
1287
+ asset(): AssetId | undefined;
1288
+ /**
1289
+ * Get the blinder index, if set
1290
+ */
1291
+ blinderIndex(): number | undefined;
1195
1292
  }
1196
1293
  /**
1197
1294
  * The details of the signatures in a PSET, divided in available and missing signatures.
@@ -1302,16 +1399,44 @@ export class Script {
1302
1399
  * Creates a `Script` from its hex string representation.
1303
1400
  */
1304
1401
  constructor(s: string);
1402
+ /**
1403
+ * Creates an empty `Script`.
1404
+ */
1405
+ static empty(): Script;
1305
1406
  /**
1306
1407
  * Return the consensus encoded bytes of the script.
1307
1408
  */
1308
1409
  bytes(): Uint8Array;
1410
+ /**
1411
+ * Returns SHA256 of the script's consensus bytes.
1412
+ *
1413
+ * Returns an equivalent value to the `jet::input_script_hash(index)`/`jet::output_script_hash(index)`.
1414
+ */
1415
+ jet_sha256_hex(): string;
1309
1416
  /**
1310
1417
  * Return the string of the script showing op codes and their arguments.
1311
1418
  *
1312
1419
  * For example: "OP_DUP OP_HASH160 OP_PUSHBYTES_20 088ac47276d105b91cf9aa27a00112421dd5f23c OP_EQUALVERIFY OP_CHECKSIG"
1313
1420
  */
1314
1421
  asm(): string;
1422
+ /**
1423
+ * Creates an OP_RETURN script with the given data.
1424
+ */
1425
+ static newOpReturn(data: Uint8Array): Script;
1426
+ /**
1427
+ * Returns true if the script is provably unspendable.
1428
+ *
1429
+ * A script is provably unspendable if it starts with OP_RETURN or is larger
1430
+ * than the maximum script size.
1431
+ */
1432
+ isProvablyUnspendable(): boolean;
1433
+ /**
1434
+ * Returns true if this script_pubkey is provably SegWit.
1435
+ *
1436
+ * This checks if the script_pubkey is provably SegWit based on the
1437
+ * script_pubkey itself and an optional redeem_script.
1438
+ */
1439
+ isProvablySegwit(redeem_script?: Script | null): boolean;
1315
1440
  /**
1316
1441
  * Return the string representation of the script (hex encoding of its consensus encoded bytes).
1317
1442
  * This representation can be used to recreate the script via `new()`
@@ -1539,6 +1664,12 @@ export class TxOutSecrets {
1539
1664
  private constructor();
1540
1665
  free(): void;
1541
1666
  [Symbol.dispose](): void;
1667
+ /**
1668
+ * Creates a new `TxOutSecrets` for an explicit (unblinded) output.
1669
+ *
1670
+ * The blinding factors are set to zero.
1671
+ */
1672
+ static fromExplicit(asset_id: AssetId, value: bigint): TxOutSecrets;
1542
1673
  /**
1543
1674
  * Return the asset of the output.
1544
1675
  */