@kaleidorg/rgb-lib-wasm 0.0.0-stage → 1.0.0-ks.2
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 +456 -2
- package/package.json +18 -3
- package/rgb_lib_wasm_bindings.d.ts +474 -0
- package/rgb_lib_wasm_bindings.js +2353 -0
- package/rgb_lib_wasm_bindings_bg.wasm +0 -0
- package/snippets/rgb-lib-wasm-4b05876ce9def59a/inline0.js +19 -0
package/README.md
CHANGED
|
@@ -1,3 +1,457 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rgb-lib-wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A WebAssembly port of [rgb-lib](https://github.com/UTEXO-Protocol/rgb-lib) for managing RGB protocol wallets in the browser.
|
|
4
|
+
|
|
5
|
+
> **Beta Software** — This library is under active development and has not been audited.
|
|
6
|
+
> APIs may change without notice between versions. Use at your own risk.
|
|
7
|
+
|
|
8
|
+
## What it does
|
|
9
|
+
|
|
10
|
+
rgb-lib-wasm lets you issue, send, and receive RGB assets from a web browser. It replaces the native Rust dependencies (filesystem, SQLite, TCP sockets) with browser-compatible alternatives:
|
|
11
|
+
|
|
12
|
+
- **In-memory database** with IndexedDB persistence
|
|
13
|
+
- **Esplora indexer** over HTTP
|
|
14
|
+
- **Encrypted backup** to a local file or a remote VSS server
|
|
15
|
+
|
|
16
|
+
Supported asset types:
|
|
17
|
+
- **NIA** (Non-Inflatable Asset)
|
|
18
|
+
- **IFA** (Inflatable Fungible Asset)
|
|
19
|
+
- **BFA** (Bridged Fungible Asset): issue, send, receive, burn and mint.
|
|
20
|
+
|
|
21
|
+
## Prerequisites
|
|
22
|
+
|
|
23
|
+
- Rust 1.88.0+ with the `wasm32-unknown-unknown` target
|
|
24
|
+
- [wasm-pack](https://rustwasm.github.io/wasm-pack/) 0.14+
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
rustup target add wasm32-unknown-unknown
|
|
28
|
+
cargo install wasm-pack@0.14.0
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Building
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
cd bindings/wasm
|
|
35
|
+
./build.sh
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This produces the `pkg/` directory containing an npm-ready package (`rgb_lib_wasm.js`, `.d.ts` types, and the `.wasm` binary).
|
|
39
|
+
|
|
40
|
+
### Trying the examples
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cd bindings/wasm
|
|
44
|
+
python3 -m http.server 8000
|
|
45
|
+
# Open http://localhost:8000/examples/index.html
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `examples/` folder contains interactive pages that cover the full API, split by topic:
|
|
49
|
+
|
|
50
|
+
| Page | Description |
|
|
51
|
+
|------|-------------|
|
|
52
|
+
| [`index.html`](bindings/wasm/examples/index.html) | Quick start guide + automated "Run All" flow |
|
|
53
|
+
| [`wallet.html`](bindings/wasm/examples/wallet.html) | Key management, wallet creation, go online, fund, create UTXOs, wallet state queries, fee estimation |
|
|
54
|
+
| [`bitcoin.html`](bindings/wasm/examples/bitcoin.html) | Send BTC, drain wallet, PSBT sign/finalize utilities |
|
|
55
|
+
| [`rgb.html`](bindings/wasm/examples/rgb.html) | Issue NIA/IFA, blind/witness receive, send RGB, inflate IFA, refresh/fail/delete transfers |
|
|
56
|
+
| [`backup.html`](bindings/wasm/examples/backup.html) | Local encrypted backup, VSS cloud backup, check proxy URL, error handling tests |
|
|
57
|
+
|
|
58
|
+
All pages share `examples/lib/shared.js` (WASM init, helpers, regtest utilities). Each page is self-contained with its own wallet setup section. Online operations (funding, sending, etc.) require the regtest Docker services — see [DEV-ENVIRONMENT.md](DEV-ENVIRONMENT.md) for setup.
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import init, {
|
|
64
|
+
generateKeys, restoreKeys, checkProxyUrl,
|
|
65
|
+
validateConsignmentOffchain,
|
|
66
|
+
WasmWallet, WasmInvoice,
|
|
67
|
+
} from './pkg/rgb_lib_wasm.js';
|
|
68
|
+
|
|
69
|
+
await init();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Key generation
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
const keys = generateKeys('Regtest');
|
|
76
|
+
// keys: { mnemonic, accountXpubVanilla, accountXpubColored, masterFingerprint }
|
|
77
|
+
|
|
78
|
+
const restored = restoreKeys('Regtest', keys.mnemonic);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Creating a wallet
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
const walletData = {
|
|
85
|
+
dataDir: ':memory:',
|
|
86
|
+
bitcoinNetwork: 'Regtest',
|
|
87
|
+
databaseType: 'Sqlite',
|
|
88
|
+
maxAllocationsPerUtxo: 5,
|
|
89
|
+
accountXpubVanilla: keys.accountXpubVanilla,
|
|
90
|
+
accountXpubColored: keys.accountXpubColored,
|
|
91
|
+
mnemonic: keys.mnemonic,
|
|
92
|
+
masterFingerprint: keys.masterFingerprint,
|
|
93
|
+
vanillaKeychain: null,
|
|
94
|
+
supportedSchemas: ['Nia', 'Ifa'],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// create() restores state from IndexedDB if available
|
|
98
|
+
const wallet = await WasmWallet.create(JSON.stringify(walletData));
|
|
99
|
+
|
|
100
|
+
// Await durable IndexedDB commit before persisting dependent application state.
|
|
101
|
+
await wallet.flush();
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Persistence ordering
|
|
105
|
+
|
|
106
|
+
`WasmWallet.create()` and Rust `Wallet::restore()` finish IndexedDB restoration
|
|
107
|
+
before returning. They return an error instead of silently starting from fresh
|
|
108
|
+
state when a stored snapshot cannot be read or decoded.
|
|
109
|
+
|
|
110
|
+
Rust `Wallet::flush()` and JavaScript `wallet.flush()` resolve only after the
|
|
111
|
+
IndexedDB read-write transaction commits. Persist dependent application state,
|
|
112
|
+
acknowledge accepted RGB funding, or broadcast a transaction that depends on an
|
|
113
|
+
RGB mutation only after the flush succeeds. A failed flush leaves the current
|
|
114
|
+
in-memory wallet state intact and can be retried. A flush that writes nothing
|
|
115
|
+
fails. A wallet saves over a stored snapshot only if it loaded that snapshot
|
|
116
|
+
through `create()` or `Wallet::restore()`, or wrote it itself. A wallet built with
|
|
117
|
+
`new` on a data directory that holds a snapshot cannot save: its saves fail and
|
|
118
|
+
its calls return a persistence error.
|
|
119
|
+
|
|
120
|
+
Every call that changes the wallet saves it. Saves are written in order, and
|
|
121
|
+
none is dropped. An async call returns after its save commits, and returns a
|
|
122
|
+
persistence error if the save fails. `sync`, `full_scan`, `refresh`,
|
|
123
|
+
`fail_transfers` and the begins that sync first also save when they keep a
|
|
124
|
+
change and then fail. `backup` and `vss_backup` save the backup time. A sync call
|
|
125
|
+
(`issue_asset_*`, `get_address`, `rotate_address`, `delete_transfers`,
|
|
126
|
+
`abort_pending_vanilla_tx`, `restore_backup`) queues its save
|
|
127
|
+
and returns before the write. It returns a persistence error when an earlier save
|
|
128
|
+
failed and no save since has committed. Its change stays in memory and its save
|
|
129
|
+
is queued again. Await `flush()` to know that the state is stored.
|
|
130
|
+
`backup` returns its bytes also when a save failed. `lastSaveError()` returns
|
|
131
|
+
the error of the last failed save, until a save commits.
|
|
132
|
+
|
|
133
|
+
Lightning-specific `consume_fascia` and `color_psbt_and_consume` operations
|
|
134
|
+
await this durable commit before returning success.
|
|
135
|
+
|
|
136
|
+
### Going online
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
const online = await wallet.goOnline({ indexerConfig: { Esplora: { url: 'http://localhost:8094/regtest/api' } }, skipConsistencyCheck: true, proxyAuthKeys: {} });
|
|
140
|
+
await wallet.sync(online);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Creating UTXOs
|
|
144
|
+
|
|
145
|
+
RGB allocations live on UTXOs. Before issuing or receiving assets you need colored UTXOs:
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
const unsignedPsbt = await wallet.createUtxosBegin(online, true, 5, 1000, 1n, false);
|
|
149
|
+
const signedPsbt = wallet.signPsbt(unsignedPsbt);
|
|
150
|
+
const count = await wallet.createUtxosEnd(online, signedPsbt, false);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Issuing assets
|
|
154
|
+
|
|
155
|
+
```javascript
|
|
156
|
+
// NIA (fixed supply)
|
|
157
|
+
const nia = wallet.issueAssetNia('TICK', 'My Token', 0, [1000]);
|
|
158
|
+
|
|
159
|
+
// IFA (inflatable supply)
|
|
160
|
+
const ifa = wallet.issueAssetIfa('IFAT', 'Inflatable', 0, [1000], [500], undefined, false, null);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Sending RGB assets
|
|
164
|
+
|
|
165
|
+
All send operations follow a three-step PSBT workflow: **begin** (build unsigned PSBT) → **sign** → **end** (broadcast).
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
const recipientMap = {
|
|
169
|
+
[assetId]: [{
|
|
170
|
+
recipientId: invoiceString,
|
|
171
|
+
witnessData: { amountSat: 1000, blinding: null },
|
|
172
|
+
amount: 100,
|
|
173
|
+
transportEndpoints: ['rpc://localhost:3000/json-rpc'],
|
|
174
|
+
// from the invoice: its `pk` and `enc` fields and its expiration
|
|
175
|
+
publicKey: invoiceData.publicKey,
|
|
176
|
+
encryption: invoiceData.encryption,
|
|
177
|
+
expirationTimestamp: invoiceData.expirationTimestamp,
|
|
178
|
+
}]
|
|
179
|
+
};
|
|
180
|
+
// the sender's own proxy, where the recipients post their ACK and get the signed TX from
|
|
181
|
+
const senderEndpoint = 'rpc://localhost:3000/json-rpc';
|
|
182
|
+
const begin = await wallet.sendBegin(online, recipientMap, false, 1n, 1, Math.floor(Date.now() / 1000) + 3600, senderEndpoint, null, false);
|
|
183
|
+
// begin: { psbt, batchTransferIdx, details }; dryRun = true saves nothing and gives batchTransferIdx null
|
|
184
|
+
const signed = wallet.signPsbt(begin.psbt);
|
|
185
|
+
const result = await wallet.sendEnd(online, signed, false);
|
|
186
|
+
// result: { txid, batchTransferIdx }
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Sending BTC
|
|
190
|
+
|
|
191
|
+
```javascript
|
|
192
|
+
const psbt = await wallet.sendBtcBegin(online, address, 50000n, 1n, false);
|
|
193
|
+
const signed = wallet.signPsbt(psbt);
|
|
194
|
+
const txid = await wallet.sendBtcEnd(online, signed, false);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Receiving assets
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
// Blind receive (UTXO-based)
|
|
201
|
+
// The wallet reserves the invoice on its proxies, so it takes the Online object. The last argument
|
|
202
|
+
// is the encryption preference ('Required' by default, 'Unsupported' or 'Optional').
|
|
203
|
+
const blind = await wallet.blindReceive(online, null, 'Any', Math.floor(Date.now() / 1000) + 86400, ['rpc://localhost:3000/json-rpc'], 1, null);
|
|
204
|
+
// blind: { invoice, recipientId, expirationTimestamp, batchTransferIdx, publicKey }
|
|
205
|
+
|
|
206
|
+
// Witness receive (address-based)
|
|
207
|
+
const witness = await wallet.witnessReceive(online, null, { Fungible: 100 }, Math.floor(Date.now() / 1000) + 86400, ['rpc://localhost:3000/json-rpc'], 1, null);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Parsing invoices
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
const invoice = new WasmInvoice(invoiceString);
|
|
214
|
+
const data = invoice.invoiceData();
|
|
215
|
+
// data: { recipientId, assetSchema, assetId, assignment, assignmentName, network, expirationTimestamp, transportEndpoints, publicKey, encryption, unknownQueryParams }
|
|
216
|
+
// expirationTimestamp is a BigInt and unknownQueryParams is a plain object
|
|
217
|
+
const str = invoice.invoiceString(); // original string
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Querying wallet state
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
const btcBalance = wallet.getBtcBalance();
|
|
224
|
+
const assetBalance = wallet.getAssetBalance(assetId);
|
|
225
|
+
const metadata = wallet.getAssetMetadata(assetId);
|
|
226
|
+
// metadata: { assetSchema, name, ticker, precision, initialSupply, maxSupply, knownCirculatingSupply, timestamp, ... }
|
|
227
|
+
const assets = wallet.listAssets([]); // all schemas
|
|
228
|
+
const transfers = wallet.listTransfers(null); // all assets
|
|
229
|
+
const unspents = wallet.listUnspents(false);
|
|
230
|
+
const transactions = wallet.listTransactions();
|
|
231
|
+
const address = wallet.getAddress();
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Fee estimation
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
const feeRate = await wallet.getFeeEstimation(online, 6); // target 6 blocks
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Draining the wallet
|
|
241
|
+
|
|
242
|
+
```javascript
|
|
243
|
+
const psbt = await wallet.drainToBegin(online, destinationAddress, true, 1n);
|
|
244
|
+
const signed = wallet.signPsbt(psbt);
|
|
245
|
+
const txid = await wallet.drainToEnd(online, signed);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Inflating an IFA asset
|
|
249
|
+
|
|
250
|
+
```javascript
|
|
251
|
+
const psbt = await wallet.inflateBegin(online, assetId, [200], 1n, 1);
|
|
252
|
+
const signed = wallet.signPsbt(psbt);
|
|
253
|
+
const result = await wallet.inflateEnd(online, signed);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Burning IFA or BFA units
|
|
257
|
+
|
|
258
|
+
```javascript
|
|
259
|
+
// the reason is optional: a hex-encoded 32-byte value, shown on the transfer as `burnReason`
|
|
260
|
+
const result = await wallet.burn(online, assetId, 50n, reason, 1n, 1);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
`sendEnd`, `inflateEnd`, `burn`, `burnEnd` and `mintEnd` return `{ txid, batchTransferIdx, entropy }`,
|
|
264
|
+
where `entropy` is the MPC entropy of the commitment.
|
|
265
|
+
|
|
266
|
+
### Local encrypted backup
|
|
267
|
+
|
|
268
|
+
Wallet state is encrypted with Scrypt + XChaCha20Poly1305 and returned as bytes:
|
|
269
|
+
|
|
270
|
+
```javascript
|
|
271
|
+
// Backup
|
|
272
|
+
const bytes = wallet.backup('my-password');
|
|
273
|
+
// bytes is a Uint8Array — save it as a file download
|
|
274
|
+
|
|
275
|
+
// Check if backup is needed
|
|
276
|
+
const needed = wallet.backupInfo(); // true if wallet changed since last backup
|
|
277
|
+
|
|
278
|
+
// Restore (create the wallet with create() and the same mnemonic)
|
|
279
|
+
wallet.restoreBackup(backupBytes, 'my-password');
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### VSS cloud backup
|
|
283
|
+
|
|
284
|
+
[VSS](https://github.com/lightningdevkit/vss-server) (Versioned Storage Service) provides cloud backup with optimistic locking.
|
|
285
|
+
VSS backups are manual: nothing uploads on its own. The app checks `backupInfo()` and calls `vssBackup()`.
|
|
286
|
+
|
|
287
|
+
```javascript
|
|
288
|
+
// Configure (signing key is a 32-byte hex-encoded secp256k1 secret key)
|
|
289
|
+
wallet.configureVssBackup('http://vss-server:8082/vss', 'my-store-id', signingKeyHex);
|
|
290
|
+
|
|
291
|
+
// Upload the first backup, if the wallet has changes (returns null when none)
|
|
292
|
+
await wallet.ensureInitialBackup();
|
|
293
|
+
|
|
294
|
+
// Upload
|
|
295
|
+
if (wallet.backupInfo()) {
|
|
296
|
+
const version = await wallet.vssBackup();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Check status
|
|
300
|
+
const info = await wallet.vssBackupInfo();
|
|
301
|
+
// info: { backupExists, serverVersion, backupRequired }
|
|
302
|
+
|
|
303
|
+
// Restore
|
|
304
|
+
await wallet.vssRestoreBackup();
|
|
305
|
+
|
|
306
|
+
// Disable
|
|
307
|
+
wallet.disableVssBackup();
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Transfer management
|
|
311
|
+
|
|
312
|
+
```javascript
|
|
313
|
+
const refreshResult = await wallet.refresh(online, null, [], false);
|
|
314
|
+
const failed = await wallet.failTransfers(online, null, false, false);
|
|
315
|
+
const deleted = wallet.deleteTransfers(null, false);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Utilities
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
// Validate an RGB proxy server
|
|
322
|
+
await checkProxyUrl('http://localhost:3000/json-rpc');
|
|
323
|
+
|
|
324
|
+
// Validate an RGB consignment offchain (before TX is broadcast)
|
|
325
|
+
// consignmentBytes is a Uint8Array of the strict-encoded consignment
|
|
326
|
+
const result = validateConsignmentOffchain(consignmentBytes, txid, 'Regtest');
|
|
327
|
+
// result: { valid: true, warnings: [...] }
|
|
328
|
+
// result: { valid: false, error: "invalid", details: "..." }
|
|
329
|
+
|
|
330
|
+
// PSBT signing and finalization (standalone)
|
|
331
|
+
const signed = wallet.signPsbt(unsignedPsbtBase64);
|
|
332
|
+
const finalized = wallet.finalizePsbt(signedPsbtBase64);
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Security
|
|
336
|
+
|
|
337
|
+
The wallet trusts every script on its page. A script in the same page can call every wallet method, read the wasm memory, which holds the mnemonic while the wallet exists, and read the IndexedDB snapshot, which holds the wallet database without the mnemonic. `getWalletData` and `Debug` output do not show the mnemonic. This stops accidental leaks, not a hostile script.
|
|
338
|
+
|
|
339
|
+
To protect a wallet:
|
|
340
|
+
|
|
341
|
+
- Load no third-party scripts on the wallet's origin. Set a strict Content Security Policy and use Subresource Integrity on the scripts you load.
|
|
342
|
+
- Run the wallet on its own origin, for example in an iframe on a dedicated subdomain, and talk to it with `postMessage`. Scripts on the main page then cannot reach its memory or its storage.
|
|
343
|
+
- To keep the mnemonic out of the page, create the wallet with `mnemonic: null` (watch-only). Sign the PSBT of each `*Begin` call elsewhere, for example on a hardware wallet, and pass the signed PSBT to the matching `*End` call.
|
|
344
|
+
|
|
345
|
+
## API reference
|
|
346
|
+
|
|
347
|
+
### Standalone functions
|
|
348
|
+
|
|
349
|
+
| Function | Description |
|
|
350
|
+
|----------|-------------|
|
|
351
|
+
| `generateKeys(network)` | Generate a new BIP39 mnemonic and derive xpubs |
|
|
352
|
+
| `restoreKeys(network, mnemonic)` | Restore xpubs from a mnemonic |
|
|
353
|
+
| `checkProxyUrl(url)` | Validate an RGB proxy server URL |
|
|
354
|
+
| `validateConsignmentOffchain(bytes, txid, network)` | Validate an RGB consignment using bundled witness data |
|
|
355
|
+
|
|
356
|
+
### `WasmInvoice`
|
|
357
|
+
|
|
358
|
+
| Method | Description |
|
|
359
|
+
|--------|-------------|
|
|
360
|
+
| `new(invoiceString)` | Parse and validate an RGB invoice string |
|
|
361
|
+
| `invoiceData()` | Return parsed `InvoiceData` as a JS object |
|
|
362
|
+
| `invoiceString()` | Return the original invoice string |
|
|
363
|
+
|
|
364
|
+
### `WasmWallet` methods
|
|
365
|
+
|
|
366
|
+
| Method | Async | Description |
|
|
367
|
+
|--------|-------|-------------|
|
|
368
|
+
| `new(walletDataJson)` | no | Create wallet (no IndexedDB restore) |
|
|
369
|
+
| `create(walletDataJson)` | yes | Create wallet with IndexedDB restore; fails if restore fails |
|
|
370
|
+
| `flush()` | yes | Durably commit current wallet state to IndexedDB |
|
|
371
|
+
| `getWalletData()` | no | Return WalletData as JS object; the mnemonic is not returned (`mnemonic` is null) |
|
|
372
|
+
| `getAddress()` | no | Get a new Bitcoin address |
|
|
373
|
+
| `getBtcBalance()` | no | Get BTC balance |
|
|
374
|
+
| `getAssetBalance(assetId)` | no | Get balance for an RGB asset |
|
|
375
|
+
| `getAssetMetadata(assetId)` | no | Get metadata for an RGB asset (name, ticker, precision, supply, etc.) |
|
|
376
|
+
| `listAssets(schemas)` | no | List known RGB assets |
|
|
377
|
+
| `listTransfers(assetId?)` | no | List RGB transfers |
|
|
378
|
+
| `listUnspents(settledOnly)` | no | List unspent outputs with RGB allocations |
|
|
379
|
+
| `listTransactions()` | no | List Bitcoin transactions, and begun vanilla operations with `pending: true` |
|
|
380
|
+
| `listPendingVanillaTxs()` | no | List begun vanilla operations that are not ended or aborted |
|
|
381
|
+
| `abortPendingVanillaTx(txid)` | no | Fail a begun vanilla operation and release its inputs |
|
|
382
|
+
| `goOnline(onlineOptions)` | yes | Connect to an Esplora indexer. The optional `evmChains` option maps an EVM chain ID to `{rpcUrl, minMintLockBlocks, maxMintLockBlocks}`, for BFA. Unless `skipConsistencyCheck` is true, it checks the wallet's data against the RGB stock and a full scan, and fails on a mismatch. |
|
|
383
|
+
| `sync(online)` | yes | Sync wallet with indexer |
|
|
384
|
+
| `createUtxosBegin(...)` | yes | Prepare PSBT to create colored UTXOs |
|
|
385
|
+
| `createUtxosEnd(online, psbt, skipSync)` | yes | Broadcast UTXO creation PSBT |
|
|
386
|
+
| `issueAssetNia(ticker, name, precision, amounts)` | no | Issue a Non-Inflatable Asset |
|
|
387
|
+
| `issueAssetIfa(ticker, name, precision, amounts, inflationAmounts, rejectListUrl?, linkRight, linkedFromContract?)` | no | Issue an Inflatable Fungible Asset, with its link right if `linkRight` |
|
|
388
|
+
| `issueAssetBfa(ticker, name, precision, mintRights, chainId, contractAddress, rejectListAddress?, linkRight, linkedFromContract?)` | no | Issue a Bridged Fungible Asset with mint rights and no units, with its link right if `linkRight` |
|
|
389
|
+
| `blindReceive(...)` | yes | Create a blind receive invoice and reserve it on the proxies |
|
|
390
|
+
| `witnessReceive(...)` | yes | Create a witness receive invoice and reserve it on the proxies |
|
|
391
|
+
| `sendBegin(...)` | yes | Prepare RGB send PSBT, save it as Initiated unless dryRun |
|
|
392
|
+
| `sendEnd(online, psbt, skipSync)` | yes | Broadcast RGB send PSBT |
|
|
393
|
+
| `sendBtcBegin(...)` | yes | Prepare BTC send PSBT |
|
|
394
|
+
| `sendBtcEnd(online, psbt, skipSync)` | yes | Broadcast BTC send PSBT |
|
|
395
|
+
| `getFeeEstimation(online, blocks)` | yes | Estimate fee rate for target blocks |
|
|
396
|
+
| `drainToBegin(online, addr, destroyAssets, feeRate)` | yes | Prepare drain PSBT |
|
|
397
|
+
| `drainToEnd(online, psbt)` | yes | Broadcast drain PSBT |
|
|
398
|
+
| `inflateBegin(...)` | yes | Prepare IFA inflation PSBT |
|
|
399
|
+
| `inflateEnd(online, psbt)` | yes | Broadcast IFA inflation PSBT |
|
|
400
|
+
| `burn(online, assetId, amount, burnReason?, feeRate, minConf)` | yes | Burn IFA or BFA units, signing with the wallet keys |
|
|
401
|
+
| `burnBegin(online, assetId, amount, burnReason?, feeRate, minConf, dryRun)` | yes | Prepare burn PSBT. `burnReason` is an optional hex-encoded 32-byte value |
|
|
402
|
+
| `burnEnd(online, psbt)` | yes | Broadcast burn PSBT |
|
|
403
|
+
| `link(online, assetId, linkedToContract, feeRate, minConf)` | yes | Link an IFA or BFA asset to another contract, spending its link right, signing with the wallet keys |
|
|
404
|
+
| `linkBegin(online, assetId, linkedToContract, feeRate, minConf, dryRun)` | yes | Prepare link PSBT |
|
|
405
|
+
| `linkEnd(online, psbt)` | yes | Broadcast link PSBT |
|
|
406
|
+
| `mintBegin(online, assetId, recipient, beforeBlock, feeRate, minConf, senderEndpoint)` | yes | Prepare BFA mint PSBT and post the consignment to the recipient. The lock has to be included before `beforeBlock` |
|
|
407
|
+
| `mintEnd(online, psbt)` | yes | Broadcast mint PSBT once the lock on the EVM chain is finalized |
|
|
408
|
+
| `getReceivedMint(recipientId)` | no | Return what the lock of a received mint has to match (`lockId`, `amount`, `beforeBlock`), or null |
|
|
409
|
+
| `listUnspentsVanilla(online, minConf, skipSync)` | yes | List non-colored UTXOs |
|
|
410
|
+
| `refresh(online, assetId?, filter, skipSync)` | yes | Refresh pending transfers and settle ended vanilla operations |
|
|
411
|
+
| `failTransfers(online, batchIdx?, noAssetOnly, skipSync)` | yes | Fail pending transfers |
|
|
412
|
+
| `deleteTransfers(batchIdx?, noAssetOnly)` | no | Delete failed transfers |
|
|
413
|
+
| `signPsbt(psbt)` | no | Sign a PSBT |
|
|
414
|
+
| `finalizePsbt(psbt)` | no | Finalize a signed PSBT |
|
|
415
|
+
| `backup(password)` | no | Create encrypted backup (returns bytes) |
|
|
416
|
+
| `restoreBackup(bytes, password)` | no | Restore from encrypted backup |
|
|
417
|
+
| `backupInfo()` | no | Check if backup is needed |
|
|
418
|
+
| `configureVssBackup(url, storeId, keyHex)` | no | Configure VSS cloud backup |
|
|
419
|
+
| `disableVssBackup()` | no | Disable VSS cloud backup |
|
|
420
|
+
| `vssBackup()` | yes | Upload backup to VSS server |
|
|
421
|
+
| `ensureInitialBackup()` | yes | Upload a VSS backup if the wallet has changes |
|
|
422
|
+
| `vssRestoreBackup()` | yes | Restore from VSS server |
|
|
423
|
+
| `vssBackupInfo()` | yes | Query VSS backup status |
|
|
424
|
+
|
|
425
|
+
## Cargo features
|
|
426
|
+
|
|
427
|
+
| Feature | Default | Description |
|
|
428
|
+
|---------|---------|-------------|
|
|
429
|
+
| `esplora` | yes | Online operations via Esplora HTTP indexer |
|
|
430
|
+
| `camel_case` | yes | camelCase JSON serialization for all types |
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
## Running tests
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Native unit tests (94 tests)
|
|
437
|
+
cargo test --lib
|
|
438
|
+
|
|
439
|
+
# WASM unit tests (headless Firefox)
|
|
440
|
+
wasm-pack test --headless --firefox --release -- --test keys_wasm
|
|
441
|
+
WASM_BINDGEN_TEST_TIMEOUT=300 wasm-pack test --headless --firefox --release -- --test pow_wasm
|
|
442
|
+
|
|
443
|
+
# Integration tests (requires regtest Docker services)
|
|
444
|
+
cd tests && bash regtest.sh start
|
|
445
|
+
cd .. && wasm-pack test --headless --firefox --release -- --test wallet_wasm
|
|
446
|
+
wasm-pack test --headless --firefox --release bindings/wasm --test bindings_wasm
|
|
447
|
+
wasm-pack test --headless --firefox --release -- --test integration_wasm
|
|
448
|
+
wasm-pack test --headless --firefox --release -- --test receive_wasm
|
|
449
|
+
wasm-pack test --headless --firefox --release -- --test send_wasm
|
|
450
|
+
cd tests && bash regtest.sh stop
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
See [DEV-ENVIRONMENT.md](DEV-ENVIRONMENT.md) for the full regtest infrastructure setup, CI configuration, Docker Compose details, and troubleshooting.
|
|
454
|
+
|
|
455
|
+
## License
|
|
456
|
+
|
|
457
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaleidorg/rgb-lib-wasm",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "RGB wallet library WASM bindings for browsers",
|
|
5
|
+
"version": "1.0.0-ks.2",
|
|
6
|
+
"files": [
|
|
7
|
+
"rgb_lib_wasm_bindings_bg.wasm",
|
|
8
|
+
"rgb_lib_wasm_bindings.js",
|
|
9
|
+
"rgb_lib_wasm_bindings.d.ts",
|
|
10
|
+
"snippets"
|
|
11
|
+
],
|
|
12
|
+
"main": "rgb_lib_wasm_bindings.js",
|
|
13
|
+
"types": "rgb_lib_wasm_bindings.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./snippets/*"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/kaleidoswap/rgb-lib-wasm.git"
|
|
20
|
+
}
|
|
6
21
|
}
|