@breeztech/breez-sdk-spark 0.5.1 → 0.6.0-rc1

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.
@@ -226,20 +226,20 @@ export function initLogging(logger, filter) {
226
226
  }
227
227
 
228
228
  /**
229
- * @param {ConnectRequest} request
230
- * @returns {Promise<BreezSdk>}
229
+ * @param {Network} network
230
+ * @returns {Config}
231
231
  */
232
- export function connect(request) {
233
- const ret = wasm.connect(request);
232
+ export function defaultConfig(network) {
233
+ const ret = wasm.defaultConfig(network);
234
234
  return ret;
235
235
  }
236
236
 
237
237
  /**
238
- * @param {Network} network
239
- * @returns {Config}
238
+ * @param {ConnectRequest} request
239
+ * @returns {Promise<BreezSdk>}
240
240
  */
241
- export function defaultConfig(network) {
242
- const ret = wasm.defaultConfig(network);
241
+ export function connect(request) {
242
+ const ret = wasm.connect(request);
243
243
  return ret;
244
244
  }
245
245
 
@@ -260,15 +260,15 @@ export function task_worker_entry_point(ptr) {
260
260
  }
261
261
 
262
262
  function __wbg_adapter_58(arg0, arg1) {
263
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbac93e35ba6a14f4(arg0, arg1);
263
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd4a74686750ed5d4(arg0, arg1);
264
264
  }
265
265
 
266
266
  function __wbg_adapter_61(arg0, arg1, arg2) {
267
- wasm.closure937_externref_shim(arg0, arg1, arg2);
267
+ wasm.closure979_externref_shim(arg0, arg1, arg2);
268
268
  }
269
269
 
270
- function __wbg_adapter_225(arg0, arg1, arg2, arg3) {
271
- wasm.closure538_externref_shim(arg0, arg1, arg2, arg3);
270
+ function __wbg_adapter_227(arg0, arg1, arg2, arg3) {
271
+ wasm.closure561_externref_shim(arg0, arg1, arg2, arg3);
272
272
  }
273
273
 
274
274
  const __wbindgen_enum_ReadableStreamType = ["bytes"];
@@ -1378,7 +1378,7 @@ function __wbg_get_imports() {
1378
1378
  const a = state0.a;
1379
1379
  state0.a = 0;
1380
1380
  try {
1381
- return __wbg_adapter_225(a, state0.b, arg0, arg1);
1381
+ return __wbg_adapter_227(a, state0.b, arg0, arg1);
1382
1382
  } finally {
1383
1383
  state0.a = a;
1384
1384
  }
@@ -1537,6 +1537,12 @@ function __wbg_get_imports() {
1537
1537
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1538
1538
  }
1539
1539
  }, arguments) };
1540
+ imports.wbg.__wbg_setLnurlMetadata_0bf15cc7efb6cc11 = function() { return handleError(function (arg0, arg1, arg2) {
1541
+ var v0 = getArrayJsValueFromWasm0(arg1, arg2).slice();
1542
+ wasm.__wbindgen_free(arg1, arg2 * 4, 4);
1543
+ const ret = arg0.setLnurlMetadata(v0);
1544
+ return ret;
1545
+ }, arguments) };
1540
1546
  imports.wbg.__wbg_setPaymentMetadata_0bbf82aa72b85deb = function() { return handleError(function (arg0, arg1, arg2, arg3) {
1541
1547
  let deferred0_0;
1542
1548
  let deferred0_1;
@@ -1763,12 +1769,12 @@ function __wbg_get_imports() {
1763
1769
  const ret = false;
1764
1770
  return ret;
1765
1771
  };
1766
- imports.wbg.__wbindgen_closure_wrapper11446 = function(arg0, arg1, arg2) {
1767
- const ret = makeMutClosure(arg0, arg1, 938, __wbg_adapter_61);
1772
+ imports.wbg.__wbindgen_closure_wrapper11748 = function(arg0, arg1, arg2) {
1773
+ const ret = makeMutClosure(arg0, arg1, 980, __wbg_adapter_61);
1768
1774
  return ret;
1769
1775
  };
1770
- imports.wbg.__wbindgen_closure_wrapper9553 = function(arg0, arg1, arg2) {
1771
- const ret = makeMutClosure(arg0, arg1, 710, __wbg_adapter_58);
1776
+ imports.wbg.__wbindgen_closure_wrapper9873 = function(arg0, arg1, arg2) {
1777
+ const ret = makeMutClosure(arg0, arg1, 752, __wbg_adapter_58);
1772
1778
  return ret;
1773
1779
  };
1774
1780
  imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
Binary file
@@ -82,7 +82,7 @@ export const __wbindgen_export_5: WebAssembly.Table;
82
82
  export const __externref_drop_slice: (a: number, b: number) => void;
83
83
  export const __wbindgen_export_7: WebAssembly.Table;
84
84
  export const __externref_table_dealloc: (a: number) => void;
85
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbac93e35ba6a14f4: (a: number, b: number) => void;
86
- export const closure937_externref_shim: (a: number, b: number, c: any) => void;
87
- export const closure538_externref_shim: (a: number, b: number, c: any, d: any) => void;
85
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd4a74686750ed5d4: (a: number, b: number) => void;
86
+ export const closure979_externref_shim: (a: number, b: number, c: any) => void;
87
+ export const closure561_externref_shim: (a: number, b: number, c: any, d: any) => void;
88
88
  export const __wbindgen_start: () => void;
@@ -178,8 +178,27 @@ class MigrationManager {
178
178
  if (!db.objectStoreNames.contains("sync_state")) {
179
179
  db.createObjectStore("sync_state", { keyPath: ["type", "dataId"] });
180
180
  }
181
- },
181
+ }
182
+ },
183
+ {
184
+ name: "Create lnurl_receive_metadata store",
185
+ upgrade: (db) => {
186
+ if (!db.objectStoreNames.contains("lnurl_receive_metadata")) {
187
+ db.createObjectStore("lnurl_receive_metadata", { keyPath: "paymentHash" });
188
+ }
189
+ }
182
190
  },
191
+ {
192
+ // Delete all unclaimed deposits to clear old claim_error JSON format.
193
+ // Deposits will be recovered on next sync.
194
+ name: "Clear unclaimed deposits for claim_error format change",
195
+ upgrade: (db, transaction) => {
196
+ if (db.objectStoreNames.contains("unclaimed_deposits")) {
197
+ const store = transaction.objectStore("unclaimed_deposits");
198
+ store.clear();
199
+ }
200
+ }
201
+ }
183
202
  ];
184
203
  }
185
204
  }
@@ -203,7 +222,7 @@ class IndexedDBStorage {
203
222
  this.db = null;
204
223
  this.migrationManager = null;
205
224
  this.logger = logger;
206
- this.dbVersion = 4; // Current schema version
225
+ this.dbVersion = 6; // Current schema version
207
226
  }
208
227
 
209
228
  /**
@@ -372,11 +391,12 @@ class IndexedDBStorage {
372
391
 
373
392
  return new Promise((resolve, reject) => {
374
393
  const transaction = this.db.transaction(
375
- ["payments", "payment_metadata"],
394
+ ["payments", "payment_metadata", "lnurl_receive_metadata"],
376
395
  "readonly"
377
396
  );
378
397
  const paymentStore = transaction.objectStore("payments");
379
398
  const metadataStore = transaction.objectStore("payment_metadata");
399
+ const lnurlReceiveMetadataStore = transaction.objectStore("lnurl_receive_metadata");
380
400
 
381
401
  const payments = [];
382
402
  let count = 0;
@@ -420,9 +440,20 @@ class IndexedDBStorage {
420
440
  payment,
421
441
  metadata
422
442
  );
423
- payments.push(paymentWithMetadata);
424
- count++;
425
- cursor.continue();
443
+
444
+ // Fetch lnurl receive metadata if it's a lightning payment
445
+ this._fetchLnurlReceiveMetadata(paymentWithMetadata, lnurlReceiveMetadataStore)
446
+ .then((mergedPayment) => {
447
+ payments.push(mergedPayment);
448
+ count++;
449
+ cursor.continue();
450
+ })
451
+ .catch(() => {
452
+ // Continue without lnurl receive metadata if fetch fails
453
+ payments.push(paymentWithMetadata);
454
+ count++;
455
+ cursor.continue();
456
+ });
426
457
  };
427
458
  metadataRequest.onerror = () => {
428
459
  // Continue without metadata if it fails
@@ -483,11 +514,12 @@ class IndexedDBStorage {
483
514
 
484
515
  return new Promise((resolve, reject) => {
485
516
  const transaction = this.db.transaction(
486
- ["payments", "payment_metadata"],
517
+ ["payments", "payment_metadata", "lnurl_receive_metadata"],
487
518
  "readonly"
488
519
  );
489
520
  const paymentStore = transaction.objectStore("payments");
490
521
  const metadataStore = transaction.objectStore("payment_metadata");
522
+ const lnurlReceiveMetadataStore = transaction.objectStore("lnurl_receive_metadata");
491
523
 
492
524
  const paymentRequest = paymentStore.get(id);
493
525
 
@@ -506,7 +538,14 @@ class IndexedDBStorage {
506
538
  payment,
507
539
  metadata
508
540
  );
509
- resolve(paymentWithMetadata);
541
+
542
+ // Fetch lnurl receive metadata if it's a lightning payment
543
+ this._fetchLnurlReceiveMetadata(paymentWithMetadata, lnurlReceiveMetadataStore)
544
+ .then(resolve)
545
+ .catch(() => {
546
+ // Continue without lnurl receive metadata if fetch fails
547
+ resolve(paymentWithMetadata);
548
+ });
510
549
  };
511
550
  metadataRequest.onerror = () => {
512
551
  // Return payment without metadata if metadata fetch fails
@@ -534,12 +573,13 @@ class IndexedDBStorage {
534
573
 
535
574
  return new Promise((resolve, reject) => {
536
575
  const transaction = this.db.transaction(
537
- ["payments", "payment_metadata"],
576
+ ["payments", "payment_metadata", "lnurl_receive_metadata"],
538
577
  "readonly"
539
578
  );
540
579
  const paymentStore = transaction.objectStore("payments");
541
580
  const invoiceIndex = paymentStore.index("invoice");
542
581
  const metadataStore = transaction.objectStore("payment_metadata");
582
+ const lnurlReceiveMetadataStore = transaction.objectStore("lnurl_receive_metadata");
543
583
 
544
584
  const paymentRequest = invoiceIndex.get(invoice);
545
585
 
@@ -551,14 +591,21 @@ class IndexedDBStorage {
551
591
  }
552
592
 
553
593
  // Get metadata for this payment
554
- const metadataRequest = metadataStore.get(invoice);
594
+ const metadataRequest = metadataStore.get(payment.id);
555
595
  metadataRequest.onsuccess = () => {
556
596
  const metadata = metadataRequest.result;
557
597
  const paymentWithMetadata = this._mergePaymentMetadata(
558
598
  payment,
559
599
  metadata
560
600
  );
561
- resolve(paymentWithMetadata);
601
+
602
+ // Fetch lnurl receive metadata if it's a lightning payment
603
+ this._fetchLnurlReceiveMetadata(paymentWithMetadata, lnurlReceiveMetadataStore)
604
+ .then(resolve)
605
+ .catch(() => {
606
+ // Continue without lnurl receive metadata if fetch fails
607
+ resolve(paymentWithMetadata);
608
+ });
562
609
  };
563
610
  metadataRequest.onerror = () => {
564
611
  // Return payment without metadata if metadata fetch fails
@@ -779,6 +826,55 @@ class IndexedDBStorage {
779
826
  });
780
827
  }
781
828
 
829
+ async setLnurlMetadata(metadata) {
830
+ if (!this.db) {
831
+ throw new StorageError("Database not initialized");
832
+ }
833
+
834
+ return new Promise((resolve, reject) => {
835
+ const transaction = this.db.transaction(
836
+ "lnurl_receive_metadata",
837
+ "readwrite"
838
+ );
839
+ const store = transaction.objectStore("lnurl_receive_metadata");
840
+
841
+ let completed = 0;
842
+ const total = metadata.length;
843
+
844
+ if (total === 0) {
845
+ resolve();
846
+ return;
847
+ }
848
+
849
+ for (const item of metadata) {
850
+ const request = store.put({
851
+ paymentHash: item.paymentHash,
852
+ nostrZapRequest: item.nostrZapRequest || null,
853
+ nostrZapReceipt: item.nostrZapReceipt || null,
854
+ senderComment: item.senderComment || null,
855
+ });
856
+
857
+ request.onsuccess = () => {
858
+ completed++;
859
+ if (completed === total) {
860
+ resolve();
861
+ }
862
+ };
863
+
864
+ request.onerror = () => {
865
+ reject(
866
+ new StorageError(
867
+ `Failed to add lnurl metadata for payment hash '${item.paymentHash}': ${
868
+ request.error?.message || "Unknown error"
869
+ }`,
870
+ request.error
871
+ )
872
+ );
873
+ };
874
+ }
875
+ });
876
+ }
877
+
782
878
  async syncAddOutgoingChange(record) {
783
879
  if (!this.db) {
784
880
  throw new StorageError("Database not initialized");
@@ -1499,6 +1595,38 @@ class IndexedDBStorage {
1499
1595
  details,
1500
1596
  };
1501
1597
  }
1598
+
1599
+ _fetchLnurlReceiveMetadata(payment, lnurlReceiveMetadataStore) {
1600
+ // Only fetch for lightning payments with a payment hash
1601
+ if (!payment.details || payment.details.type !== "lightning" || !payment.details.paymentHash) {
1602
+ return Promise.resolve(payment);
1603
+ }
1604
+
1605
+ if (!lnurlReceiveMetadataStore) {
1606
+ return Promise.resolve(payment);
1607
+ }
1608
+
1609
+ return new Promise((resolve, reject) => {
1610
+ const lnurlReceiveRequest = lnurlReceiveMetadataStore.get(payment.details.paymentHash);
1611
+
1612
+ lnurlReceiveRequest.onsuccess = () => {
1613
+ const lnurlReceiveMetadata = lnurlReceiveRequest.result;
1614
+ if (lnurlReceiveMetadata && (lnurlReceiveMetadata.nostrZapRequest || lnurlReceiveMetadata.senderComment)) {
1615
+ payment.details.lnurlReceiveMetadata = {
1616
+ nostrZapRequest: lnurlReceiveMetadata.nostrZapRequest || null,
1617
+ nostrZapReceipt: lnurlReceiveMetadata.nostrZapReceipt || null,
1618
+ senderComment: lnurlReceiveMetadata.senderComment || null,
1619
+ };
1620
+ }
1621
+ resolve(payment);
1622
+ };
1623
+
1624
+ lnurlReceiveRequest.onerror = () => {
1625
+ // Continue without lnurlReceiveMetadata if fetch fails
1626
+ reject(new Error("Failed to fetch lnurl receive metadata"));
1627
+ };
1628
+ });
1629
+ }
1502
1630
  }
1503
1631
 
1504
1632
  export async function createDefaultStorage(