@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.
@@ -234,20 +234,20 @@ export function initLogging(logger, filter) {
234
234
  }
235
235
 
236
236
  /**
237
- * @param {ConnectRequest} request
238
- * @returns {Promise<BreezSdk>}
237
+ * @param {Network} network
238
+ * @returns {Config}
239
239
  */
240
- export function connect(request) {
241
- const ret = wasm.connect(request);
240
+ export function defaultConfig(network) {
241
+ const ret = wasm.defaultConfig(network);
242
242
  return ret;
243
243
  }
244
244
 
245
245
  /**
246
- * @param {Network} network
247
- * @returns {Config}
246
+ * @param {ConnectRequest} request
247
+ * @returns {Promise<BreezSdk>}
248
248
  */
249
- export function defaultConfig(network) {
250
- const ret = wasm.defaultConfig(network);
249
+ export function connect(request) {
250
+ const ret = wasm.connect(request);
251
251
  return ret;
252
252
  }
253
253
 
@@ -268,15 +268,15 @@ export function task_worker_entry_point(ptr) {
268
268
  }
269
269
 
270
270
  function __wbg_adapter_58(arg0, arg1) {
271
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbac93e35ba6a14f4(arg0, arg1);
271
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hd4a74686750ed5d4(arg0, arg1);
272
272
  }
273
273
 
274
274
  function __wbg_adapter_61(arg0, arg1, arg2) {
275
- wasm.closure937_externref_shim(arg0, arg1, arg2);
275
+ wasm.closure979_externref_shim(arg0, arg1, arg2);
276
276
  }
277
277
 
278
- function __wbg_adapter_225(arg0, arg1, arg2, arg3) {
279
- wasm.closure538_externref_shim(arg0, arg1, arg2, arg3);
278
+ function __wbg_adapter_227(arg0, arg1, arg2, arg3) {
279
+ wasm.closure561_externref_shim(arg0, arg1, arg2, arg3);
280
280
  }
281
281
 
282
282
  const __wbindgen_enum_ReadableStreamType = ["bytes"];
@@ -1429,7 +1429,7 @@ export function __wbg_new_23a2665fac83c611(arg0, arg1) {
1429
1429
  const a = state0.a;
1430
1430
  state0.a = 0;
1431
1431
  try {
1432
- return __wbg_adapter_225(a, state0.b, arg0, arg1);
1432
+ return __wbg_adapter_227(a, state0.b, arg0, arg1);
1433
1433
  } finally {
1434
1434
  state0.a = a;
1435
1435
  }
@@ -1621,6 +1621,13 @@ export function __wbg_setCachedItem_91b03741dfb0b4c2() { return handleError(func
1621
1621
  }
1622
1622
  }, arguments) };
1623
1623
 
1624
+ export function __wbg_setLnurlMetadata_0bf15cc7efb6cc11() { return handleError(function (arg0, arg1, arg2) {
1625
+ var v0 = getArrayJsValueFromWasm0(arg1, arg2).slice();
1626
+ wasm.__wbindgen_free(arg1, arg2 * 4, 4);
1627
+ const ret = arg0.setLnurlMetadata(v0);
1628
+ return ret;
1629
+ }, arguments) };
1630
+
1624
1631
  export function __wbg_setPaymentMetadata_0bbf82aa72b85deb() { return handleError(function (arg0, arg1, arg2, arg3) {
1625
1632
  let deferred0_0;
1626
1633
  let deferred0_1;
@@ -1900,13 +1907,13 @@ export function __wbindgen_cb_drop(arg0) {
1900
1907
  return ret;
1901
1908
  };
1902
1909
 
1903
- export function __wbindgen_closure_wrapper11446(arg0, arg1, arg2) {
1904
- const ret = makeMutClosure(arg0, arg1, 938, __wbg_adapter_61);
1910
+ export function __wbindgen_closure_wrapper11748(arg0, arg1, arg2) {
1911
+ const ret = makeMutClosure(arg0, arg1, 980, __wbg_adapter_61);
1905
1912
  return ret;
1906
1913
  };
1907
1914
 
1908
- export function __wbindgen_closure_wrapper9553(arg0, arg1, arg2) {
1909
- const ret = makeMutClosure(arg0, arg1, 710, __wbg_adapter_58);
1915
+ export function __wbindgen_closure_wrapper9873(arg0, arg1, arg2) {
1916
+ const ret = makeMutClosure(arg0, arg1, 752, __wbg_adapter_58);
1910
1917
  return ret;
1911
1918
  };
1912
1919
 
@@ -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(