@breeztech/breez-sdk-spark 0.2.5-dev2 → 0.2.6

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.
Binary file
@@ -31,12 +31,23 @@ export interface Storage {
31
31
  insertPayment: (payment: Payment) => Promise<void>;
32
32
  setPaymentMetadata: (paymentId: string, metadata: PaymentMetadata) => Promise<void>;
33
33
  getPaymentById: (id: string) => Promise<Payment>;
34
+ getPaymentByInvoice: (invoice: string) => Promise<Payment>;
34
35
  addDeposit: (txid: string, vout: number, amount_sats: number) => Promise<void>;
35
36
  deleteDeposit: (txid: string, vout: number) => Promise<void>;
36
37
  listDeposits: () => Promise<DepositInfo[]>;
37
38
  updateDeposit: (txid: string, vout: number, payload: UpdateDepositPayload) => Promise<void>;
38
39
  }
39
40
 
41
+ export interface WaitForPaymentResponse {
42
+ payment: Payment;
43
+ }
44
+
45
+ export type WaitForPaymentIdentifier = ({ type: "paymentId" } & string) | ({ type: "paymentRequest" } & string);
46
+
47
+ export interface WaitForPaymentRequest {
48
+ identifier: WaitForPaymentIdentifier;
49
+ }
50
+
40
51
  export interface Symbol {
41
52
  grapheme?: string;
42
53
  template?: string;
@@ -137,7 +148,7 @@ export interface SendPaymentRequest {
137
148
  options?: SendPaymentOptions;
138
149
  }
139
150
 
140
- export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean };
151
+ export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean; completionTimeoutSecs?: number };
141
152
 
142
153
  export type OnchainConfirmationSpeed = "fast" | "medium" | "slow";
143
154
 
@@ -513,7 +524,7 @@ export class BreezSdk {
513
524
  free(): void;
514
525
  addEventListener(listener: EventListener): Promise<string>;
515
526
  removeEventListener(id: string): Promise<boolean>;
516
- disconnect(): void;
527
+ disconnect(): Promise<void>;
517
528
  getInfo(request: GetInfoRequest): Promise<GetInfoResponse>;
518
529
  receivePayment(request: ReceivePaymentRequest): Promise<ReceivePaymentResponse>;
519
530
  prepareSendPayment(request: PrepareSendPaymentRequest): Promise<PrepareSendPaymentResponse>;
@@ -532,6 +543,7 @@ export class BreezSdk {
532
543
  deleteLightningAddress(): Promise<void>;
533
544
  listFiatCurrencies(): Promise<ListFiatCurrenciesResponse>;
534
545
  listFiatRates(): Promise<ListFiatRatesResponse>;
546
+ waitForPayment(request: WaitForPaymentRequest): Promise<WaitForPaymentResponse>;
535
547
  }
536
548
  export class IntoUnderlyingByteSource {
537
549
  private constructor();
@@ -279,14 +279,14 @@ export function task_worker_entry_point(ptr) {
279
279
  }
280
280
 
281
281
  function __wbg_adapter_52(arg0, arg1) {
282
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4(arg0, arg1);
282
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf(arg0, arg1);
283
283
  }
284
284
 
285
285
  function __wbg_adapter_55(arg0, arg1, arg2) {
286
- wasm.closure781_externref_shim(arg0, arg1, arg2);
286
+ wasm.closure780_externref_shim(arg0, arg1, arg2);
287
287
  }
288
288
 
289
- function __wbg_adapter_180(arg0, arg1, arg2, arg3) {
289
+ function __wbg_adapter_183(arg0, arg1, arg2, arg3) {
290
290
  wasm.closure434_externref_shim(arg0, arg1, arg2, arg3);
291
291
  }
292
292
 
@@ -345,11 +345,12 @@ export class BreezSdk {
345
345
  const ret = wasm.breezsdk_removeEventListener(this.__wbg_ptr, ptr0, len0);
346
346
  return ret;
347
347
  }
348
+ /**
349
+ * @returns {Promise<void>}
350
+ */
348
351
  disconnect() {
349
352
  const ret = wasm.breezsdk_disconnect(this.__wbg_ptr);
350
- if (ret[1]) {
351
- throw takeFromExternrefTable0(ret[0]);
352
- }
353
+ return ret;
353
354
  }
354
355
  /**
355
356
  * @param {GetInfoRequest} request
@@ -491,6 +492,14 @@ export class BreezSdk {
491
492
  const ret = wasm.breezsdk_listFiatRates(this.__wbg_ptr);
492
493
  return ret;
493
494
  }
495
+ /**
496
+ * @param {WaitForPaymentRequest} request
497
+ * @returns {Promise<WaitForPaymentResponse>}
498
+ */
499
+ waitForPayment(request) {
500
+ const ret = wasm.breezsdk_waitForPayment(this.__wbg_ptr, request);
501
+ return ret;
502
+ }
494
503
  }
495
504
 
496
505
  const IntoUnderlyingByteSourceFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -896,6 +905,19 @@ export function __wbg_getPaymentById_c23144bfc404b2fc() { return handleError(fun
896
905
  }
897
906
  }, arguments) };
898
907
 
908
+ export function __wbg_getPaymentByInvoice_afddfcbefa5508b0() { return handleError(function (arg0, arg1, arg2) {
909
+ let deferred0_0;
910
+ let deferred0_1;
911
+ try {
912
+ deferred0_0 = arg1;
913
+ deferred0_1 = arg2;
914
+ const ret = arg0.getPaymentByInvoice(getStringFromWasm0(arg1, arg2));
915
+ return ret;
916
+ } finally {
917
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
918
+ }
919
+ }, arguments) };
920
+
899
921
  export function __wbg_getRandomValues_b8f5dbd5f3995a9e() { return handleError(function (arg0, arg1) {
900
922
  arg0.getRandomValues(arg1);
901
923
  }, arguments) };
@@ -1049,7 +1071,7 @@ export function __wbg_new_23a2665fac83c611(arg0, arg1) {
1049
1071
  const a = state0.a;
1050
1072
  state0.a = 0;
1051
1073
  try {
1052
- return __wbg_adapter_180(a, state0.b, arg0, arg1);
1074
+ return __wbg_adapter_183(a, state0.b, arg0, arg1);
1053
1075
  } finally {
1054
1076
  state0.a = a;
1055
1077
  }
@@ -1412,13 +1434,13 @@ export function __wbindgen_cb_drop(arg0) {
1412
1434
  return ret;
1413
1435
  };
1414
1436
 
1415
- export function __wbindgen_closure_wrapper8071(arg0, arg1, arg2) {
1416
- const ret = makeMutClosure(arg0, arg1, 611, __wbg_adapter_52);
1437
+ export function __wbindgen_closure_wrapper8079(arg0, arg1, arg2) {
1438
+ const ret = makeMutClosure(arg0, arg1, 612, __wbg_adapter_52);
1417
1439
  return ret;
1418
1440
  };
1419
1441
 
1420
- export function __wbindgen_closure_wrapper9713(arg0, arg1, arg2) {
1421
- const ret = makeMutClosure(arg0, arg1, 782, __wbg_adapter_55);
1442
+ export function __wbindgen_closure_wrapper9672(arg0, arg1, arg2) {
1443
+ const ret = makeMutClosure(arg0, arg1, 781, __wbg_adapter_55);
1422
1444
  return ret;
1423
1445
  };
1424
1446
 
@@ -9,7 +9,7 @@ export const defaultStorage: (a: number, b: number) => any;
9
9
  export const parse: (a: number, b: number) => any;
10
10
  export const breezsdk_addEventListener: (a: number, b: any) => any;
11
11
  export const breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
12
- export const breezsdk_disconnect: (a: number) => [number, number];
12
+ export const breezsdk_disconnect: (a: number) => any;
13
13
  export const breezsdk_getInfo: (a: number, b: any) => any;
14
14
  export const breezsdk_receivePayment: (a: number, b: any) => any;
15
15
  export const breezsdk_prepareSendPayment: (a: number, b: any) => any;
@@ -28,6 +28,7 @@ export const breezsdk_registerLightningAddress: (a: number, b: any) => any;
28
28
  export const breezsdk_deleteLightningAddress: (a: number) => any;
29
29
  export const breezsdk_listFiatCurrencies: (a: number) => any;
30
30
  export const breezsdk_listFiatRates: (a: number) => any;
31
+ export const breezsdk_waitForPayment: (a: number, b: any) => any;
31
32
  export const __wbg_sdkbuilder_free: (a: number, b: number) => void;
32
33
  export const sdkbuilder_new: (a: any, b: any, c: any) => [number, number, number];
33
34
  export const sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: number) => number;
@@ -59,7 +60,7 @@ export const __externref_table_alloc: () => number;
59
60
  export const __wbindgen_export_5: WebAssembly.Table;
60
61
  export const __wbindgen_export_6: WebAssembly.Table;
61
62
  export const __externref_table_dealloc: (a: number) => void;
62
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4: (a: number, b: number) => void;
63
- export const closure781_externref_shim: (a: number, b: number, c: any) => void;
63
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf: (a: number, b: number) => void;
64
+ export const closure780_externref_shim: (a: number, b: number, c: any) => void;
64
65
  export const closure434_externref_shim: (a: number, b: number, c: any, d: any) => void;
65
66
  export const __wbindgen_start: () => void;
@@ -100,6 +100,17 @@ class MigrationManager {
100
100
  }
101
101
  },
102
102
  },
103
+ {
104
+ name: "Create invoice index",
105
+ upgrade: (db, transaction) => {
106
+ const paymentStore = transaction.objectStore("payments");
107
+ if (!paymentStore.indexNames.contains("invoice")) {
108
+ paymentStore.createIndex("invoice", "details.invoice", {
109
+ unique: false,
110
+ });
111
+ }
112
+ }
113
+ }
103
114
  ];
104
115
  }
105
116
  }
@@ -436,6 +447,58 @@ class IndexedDBStorage {
436
447
  });
437
448
  }
438
449
 
450
+ async getPaymentByInvoice(invoice) {
451
+ if (!this.db) {
452
+ throw new StorageError("Database not initialized");
453
+ }
454
+
455
+ return new Promise((resolve, reject) => {
456
+ const transaction = this.db.transaction(
457
+ ["payments", "payment_metadata"],
458
+ "readonly"
459
+ );
460
+ const paymentStore = transaction.objectStore("payments");
461
+ const invoiceIndex = paymentStore.index("invoice");
462
+ const metadataStore = transaction.objectStore("payment_metadata");
463
+
464
+ const paymentRequest = invoiceIndex.get(invoice);
465
+
466
+ paymentRequest.onsuccess = () => {
467
+ const payment = paymentRequest.result;
468
+ if (!payment) {
469
+ resolve(null);
470
+ return;
471
+ }
472
+
473
+ // Get metadata for this payment
474
+ const metadataRequest = metadataStore.get(invoice);
475
+ metadataRequest.onsuccess = () => {
476
+ const metadata = metadataRequest.result;
477
+ const paymentWithMetadata = this._mergePaymentMetadata(
478
+ payment,
479
+ metadata
480
+ );
481
+ resolve(paymentWithMetadata);
482
+ };
483
+ metadataRequest.onerror = () => {
484
+ // Return payment without metadata if metadata fetch fails
485
+ resolve(payment);
486
+ };
487
+ };
488
+
489
+ paymentRequest.onerror = () => {
490
+ reject(
491
+ new StorageError(
492
+ `Failed to get payment by invoice '${invoice}': ${
493
+ paymentRequest.error?.message || "Unknown error"
494
+ }`,
495
+ paymentRequest.error
496
+ )
497
+ );
498
+ };
499
+ });
500
+ }
501
+
439
502
  async setPaymentMetadata(paymentId, metadata) {
440
503
  if (!this.db) {
441
504
  throw new StorageError("Database not initialized");
@@ -31,12 +31,23 @@ export interface Storage {
31
31
  insertPayment: (payment: Payment) => Promise<void>;
32
32
  setPaymentMetadata: (paymentId: string, metadata: PaymentMetadata) => Promise<void>;
33
33
  getPaymentById: (id: string) => Promise<Payment>;
34
+ getPaymentByInvoice: (invoice: string) => Promise<Payment>;
34
35
  addDeposit: (txid: string, vout: number, amount_sats: number) => Promise<void>;
35
36
  deleteDeposit: (txid: string, vout: number) => Promise<void>;
36
37
  listDeposits: () => Promise<DepositInfo[]>;
37
38
  updateDeposit: (txid: string, vout: number, payload: UpdateDepositPayload) => Promise<void>;
38
39
  }
39
40
 
41
+ export interface WaitForPaymentResponse {
42
+ payment: Payment;
43
+ }
44
+
45
+ export type WaitForPaymentIdentifier = ({ type: "paymentId" } & string) | ({ type: "paymentRequest" } & string);
46
+
47
+ export interface WaitForPaymentRequest {
48
+ identifier: WaitForPaymentIdentifier;
49
+ }
50
+
40
51
  export interface Symbol {
41
52
  grapheme?: string;
42
53
  template?: string;
@@ -137,7 +148,7 @@ export interface SendPaymentRequest {
137
148
  options?: SendPaymentOptions;
138
149
  }
139
150
 
140
- export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean };
151
+ export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean; completionTimeoutSecs?: number };
141
152
 
142
153
  export type OnchainConfirmationSpeed = "fast" | "medium" | "slow";
143
154
 
@@ -513,7 +524,7 @@ export class BreezSdk {
513
524
  free(): void;
514
525
  addEventListener(listener: EventListener): Promise<string>;
515
526
  removeEventListener(id: string): Promise<boolean>;
516
- disconnect(): void;
527
+ disconnect(): Promise<void>;
517
528
  getInfo(request: GetInfoRequest): Promise<GetInfoResponse>;
518
529
  receivePayment(request: ReceivePaymentRequest): Promise<ReceivePaymentResponse>;
519
530
  prepareSendPayment(request: PrepareSendPaymentRequest): Promise<PrepareSendPaymentResponse>;
@@ -532,6 +543,7 @@ export class BreezSdk {
532
543
  deleteLightningAddress(): Promise<void>;
533
544
  listFiatCurrencies(): Promise<ListFiatCurrenciesResponse>;
534
545
  listFiatRates(): Promise<ListFiatRatesResponse>;
546
+ waitForPayment(request: WaitForPaymentRequest): Promise<WaitForPaymentResponse>;
535
547
  }
536
548
  export class IntoUnderlyingByteSource {
537
549
  private constructor();
@@ -262,14 +262,14 @@ export function task_worker_entry_point(ptr) {
262
262
  }
263
263
 
264
264
  function __wbg_adapter_52(arg0, arg1) {
265
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4(arg0, arg1);
265
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf(arg0, arg1);
266
266
  }
267
267
 
268
268
  function __wbg_adapter_55(arg0, arg1, arg2) {
269
- wasm.closure781_externref_shim(arg0, arg1, arg2);
269
+ wasm.closure780_externref_shim(arg0, arg1, arg2);
270
270
  }
271
271
 
272
- function __wbg_adapter_180(arg0, arg1, arg2, arg3) {
272
+ function __wbg_adapter_183(arg0, arg1, arg2, arg3) {
273
273
  wasm.closure434_externref_shim(arg0, arg1, arg2, arg3);
274
274
  }
275
275
 
@@ -328,11 +328,12 @@ export class BreezSdk {
328
328
  const ret = wasm.breezsdk_removeEventListener(this.__wbg_ptr, ptr0, len0);
329
329
  return ret;
330
330
  }
331
+ /**
332
+ * @returns {Promise<void>}
333
+ */
331
334
  disconnect() {
332
335
  const ret = wasm.breezsdk_disconnect(this.__wbg_ptr);
333
- if (ret[1]) {
334
- throw takeFromExternrefTable0(ret[0]);
335
- }
336
+ return ret;
336
337
  }
337
338
  /**
338
339
  * @param {GetInfoRequest} request
@@ -474,6 +475,14 @@ export class BreezSdk {
474
475
  const ret = wasm.breezsdk_listFiatRates(this.__wbg_ptr);
475
476
  return ret;
476
477
  }
478
+ /**
479
+ * @param {WaitForPaymentRequest} request
480
+ * @returns {Promise<WaitForPaymentResponse>}
481
+ */
482
+ waitForPayment(request) {
483
+ const ret = wasm.breezsdk_waitForPayment(this.__wbg_ptr, request);
484
+ return ret;
485
+ }
477
486
  }
478
487
 
479
488
  const IntoUnderlyingByteSourceFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -847,6 +856,18 @@ const imports = {
847
856
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
848
857
  }
849
858
  }, arguments) },
859
+ __wbg_getPaymentByInvoice_afddfcbefa5508b0: function() { return handleError(function (arg0, arg1, arg2) {
860
+ let deferred0_0;
861
+ let deferred0_1;
862
+ try {
863
+ deferred0_0 = arg1;
864
+ deferred0_1 = arg2;
865
+ const ret = arg0.getPaymentByInvoice(getStringFromWasm0(arg1, arg2));
866
+ return ret;
867
+ } finally {
868
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
869
+ }
870
+ }, arguments) },
850
871
  __wbg_getRandomValues_b8f5dbd5f3995a9e: function() { return handleError(function (arg0, arg1) {
851
872
  arg0.getRandomValues(arg1);
852
873
  }, arguments) },
@@ -975,7 +996,7 @@ const imports = {
975
996
  const a = state0.a;
976
997
  state0.a = 0;
977
998
  try {
978
- return __wbg_adapter_180(a, state0.b, arg0, arg1);
999
+ return __wbg_adapter_183(a, state0.b, arg0, arg1);
979
1000
  } finally {
980
1001
  state0.a = a;
981
1002
  }
@@ -1271,12 +1292,12 @@ const imports = {
1271
1292
  const ret = false;
1272
1293
  return ret;
1273
1294
  },
1274
- __wbindgen_closure_wrapper8071: function(arg0, arg1, arg2) {
1275
- const ret = makeMutClosure(arg0, arg1, 611, __wbg_adapter_52);
1295
+ __wbindgen_closure_wrapper8079: function(arg0, arg1, arg2) {
1296
+ const ret = makeMutClosure(arg0, arg1, 612, __wbg_adapter_52);
1276
1297
  return ret;
1277
1298
  },
1278
- __wbindgen_closure_wrapper9713: function(arg0, arg1, arg2) {
1279
- const ret = makeMutClosure(arg0, arg1, 782, __wbg_adapter_55);
1299
+ __wbindgen_closure_wrapper9672: function(arg0, arg1, arg2) {
1300
+ const ret = makeMutClosure(arg0, arg1, 781, __wbg_adapter_55);
1280
1301
  return ret;
1281
1302
  },
1282
1303
  __wbindgen_debug_string: function(arg0, arg1) {
Binary file
@@ -9,7 +9,7 @@ export const defaultStorage: (a: number, b: number) => any;
9
9
  export const parse: (a: number, b: number) => any;
10
10
  export const breezsdk_addEventListener: (a: number, b: any) => any;
11
11
  export const breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
12
- export const breezsdk_disconnect: (a: number) => [number, number];
12
+ export const breezsdk_disconnect: (a: number) => any;
13
13
  export const breezsdk_getInfo: (a: number, b: any) => any;
14
14
  export const breezsdk_receivePayment: (a: number, b: any) => any;
15
15
  export const breezsdk_prepareSendPayment: (a: number, b: any) => any;
@@ -28,6 +28,7 @@ export const breezsdk_registerLightningAddress: (a: number, b: any) => any;
28
28
  export const breezsdk_deleteLightningAddress: (a: number) => any;
29
29
  export const breezsdk_listFiatCurrencies: (a: number) => any;
30
30
  export const breezsdk_listFiatRates: (a: number) => any;
31
+ export const breezsdk_waitForPayment: (a: number, b: any) => any;
31
32
  export const __wbg_sdkbuilder_free: (a: number, b: number) => void;
32
33
  export const sdkbuilder_new: (a: any, b: any, c: any) => [number, number, number];
33
34
  export const sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: number) => number;
@@ -59,7 +60,7 @@ export const __externref_table_alloc: () => number;
59
60
  export const __wbindgen_export_5: WebAssembly.Table;
60
61
  export const __wbindgen_export_6: WebAssembly.Table;
61
62
  export const __externref_table_dealloc: (a: number) => void;
62
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4: (a: number, b: number) => void;
63
- export const closure781_externref_shim: (a: number, b: number, c: any) => void;
63
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf: (a: number, b: number) => void;
64
+ export const closure780_externref_shim: (a: number, b: number, c: any) => void;
64
65
  export const closure434_externref_shim: (a: number, b: number, c: any, d: any) => void;
65
66
  export const __wbindgen_start: () => void;
@@ -31,12 +31,23 @@ export interface Storage {
31
31
  insertPayment: (payment: Payment) => Promise<void>;
32
32
  setPaymentMetadata: (paymentId: string, metadata: PaymentMetadata) => Promise<void>;
33
33
  getPaymentById: (id: string) => Promise<Payment>;
34
+ getPaymentByInvoice: (invoice: string) => Promise<Payment>;
34
35
  addDeposit: (txid: string, vout: number, amount_sats: number) => Promise<void>;
35
36
  deleteDeposit: (txid: string, vout: number) => Promise<void>;
36
37
  listDeposits: () => Promise<DepositInfo[]>;
37
38
  updateDeposit: (txid: string, vout: number, payload: UpdateDepositPayload) => Promise<void>;
38
39
  }
39
40
 
41
+ export interface WaitForPaymentResponse {
42
+ payment: Payment;
43
+ }
44
+
45
+ export type WaitForPaymentIdentifier = ({ type: "paymentId" } & string) | ({ type: "paymentRequest" } & string);
46
+
47
+ export interface WaitForPaymentRequest {
48
+ identifier: WaitForPaymentIdentifier;
49
+ }
50
+
40
51
  export interface Symbol {
41
52
  grapheme?: string;
42
53
  template?: string;
@@ -137,7 +148,7 @@ export interface SendPaymentRequest {
137
148
  options?: SendPaymentOptions;
138
149
  }
139
150
 
140
- export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean };
151
+ export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean; completionTimeoutSecs?: number };
141
152
 
142
153
  export type OnchainConfirmationSpeed = "fast" | "medium" | "slow";
143
154
 
@@ -513,7 +524,7 @@ export class BreezSdk {
513
524
  free(): void;
514
525
  addEventListener(listener: EventListener): Promise<string>;
515
526
  removeEventListener(id: string): Promise<boolean>;
516
- disconnect(): void;
527
+ disconnect(): Promise<void>;
517
528
  getInfo(request: GetInfoRequest): Promise<GetInfoResponse>;
518
529
  receivePayment(request: ReceivePaymentRequest): Promise<ReceivePaymentResponse>;
519
530
  prepareSendPayment(request: PrepareSendPaymentRequest): Promise<PrepareSendPaymentResponse>;
@@ -532,6 +543,7 @@ export class BreezSdk {
532
543
  deleteLightningAddress(): Promise<void>;
533
544
  listFiatCurrencies(): Promise<ListFiatCurrenciesResponse>;
534
545
  listFiatRates(): Promise<ListFiatRatesResponse>;
546
+ waitForPayment(request: WaitForPaymentRequest): Promise<WaitForPaymentResponse>;
535
547
  }
536
548
  export class IntoUnderlyingByteSource {
537
549
  private constructor();
@@ -275,14 +275,14 @@ module.exports.task_worker_entry_point = function(ptr) {
275
275
  };
276
276
 
277
277
  function __wbg_adapter_52(arg0, arg1) {
278
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4(arg0, arg1);
278
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf(arg0, arg1);
279
279
  }
280
280
 
281
281
  function __wbg_adapter_55(arg0, arg1, arg2) {
282
- wasm.closure781_externref_shim(arg0, arg1, arg2);
282
+ wasm.closure780_externref_shim(arg0, arg1, arg2);
283
283
  }
284
284
 
285
- function __wbg_adapter_180(arg0, arg1, arg2, arg3) {
285
+ function __wbg_adapter_183(arg0, arg1, arg2, arg3) {
286
286
  wasm.closure434_externref_shim(arg0, arg1, arg2, arg3);
287
287
  }
288
288
 
@@ -341,11 +341,12 @@ class BreezSdk {
341
341
  const ret = wasm.breezsdk_removeEventListener(this.__wbg_ptr, ptr0, len0);
342
342
  return ret;
343
343
  }
344
+ /**
345
+ * @returns {Promise<void>}
346
+ */
344
347
  disconnect() {
345
348
  const ret = wasm.breezsdk_disconnect(this.__wbg_ptr);
346
- if (ret[1]) {
347
- throw takeFromExternrefTable0(ret[0]);
348
- }
349
+ return ret;
349
350
  }
350
351
  /**
351
352
  * @param {GetInfoRequest} request
@@ -487,6 +488,14 @@ class BreezSdk {
487
488
  const ret = wasm.breezsdk_listFiatRates(this.__wbg_ptr);
488
489
  return ret;
489
490
  }
491
+ /**
492
+ * @param {WaitForPaymentRequest} request
493
+ * @returns {Promise<WaitForPaymentResponse>}
494
+ */
495
+ waitForPayment(request) {
496
+ const ret = wasm.breezsdk_waitForPayment(this.__wbg_ptr, request);
497
+ return ret;
498
+ }
490
499
  }
491
500
  module.exports.BreezSdk = BreezSdk;
492
501
 
@@ -897,6 +906,19 @@ module.exports.__wbg_getPaymentById_c23144bfc404b2fc = function() { return handl
897
906
  }
898
907
  }, arguments) };
899
908
 
909
+ module.exports.__wbg_getPaymentByInvoice_afddfcbefa5508b0 = function() { return handleError(function (arg0, arg1, arg2) {
910
+ let deferred0_0;
911
+ let deferred0_1;
912
+ try {
913
+ deferred0_0 = arg1;
914
+ deferred0_1 = arg2;
915
+ const ret = arg0.getPaymentByInvoice(getStringFromWasm0(arg1, arg2));
916
+ return ret;
917
+ } finally {
918
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
919
+ }
920
+ }, arguments) };
921
+
900
922
  module.exports.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
901
923
  arg0.getRandomValues(arg1);
902
924
  }, arguments) };
@@ -1050,7 +1072,7 @@ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
1050
1072
  const a = state0.a;
1051
1073
  state0.a = 0;
1052
1074
  try {
1053
- return __wbg_adapter_180(a, state0.b, arg0, arg1);
1075
+ return __wbg_adapter_183(a, state0.b, arg0, arg1);
1054
1076
  } finally {
1055
1077
  state0.a = a;
1056
1078
  }
@@ -1413,13 +1435,13 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
1413
1435
  return ret;
1414
1436
  };
1415
1437
 
1416
- module.exports.__wbindgen_closure_wrapper8071 = function(arg0, arg1, arg2) {
1417
- const ret = makeMutClosure(arg0, arg1, 611, __wbg_adapter_52);
1438
+ module.exports.__wbindgen_closure_wrapper8079 = function(arg0, arg1, arg2) {
1439
+ const ret = makeMutClosure(arg0, arg1, 612, __wbg_adapter_52);
1418
1440
  return ret;
1419
1441
  };
1420
1442
 
1421
- module.exports.__wbindgen_closure_wrapper9713 = function(arg0, arg1, arg2) {
1422
- const ret = makeMutClosure(arg0, arg1, 782, __wbg_adapter_55);
1443
+ module.exports.__wbindgen_closure_wrapper9672 = function(arg0, arg1, arg2) {
1444
+ const ret = makeMutClosure(arg0, arg1, 781, __wbg_adapter_55);
1423
1445
  return ret;
1424
1446
  };
1425
1447
 
Binary file
@@ -9,7 +9,7 @@ export const defaultStorage: (a: number, b: number) => any;
9
9
  export const parse: (a: number, b: number) => any;
10
10
  export const breezsdk_addEventListener: (a: number, b: any) => any;
11
11
  export const breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
12
- export const breezsdk_disconnect: (a: number) => [number, number];
12
+ export const breezsdk_disconnect: (a: number) => any;
13
13
  export const breezsdk_getInfo: (a: number, b: any) => any;
14
14
  export const breezsdk_receivePayment: (a: number, b: any) => any;
15
15
  export const breezsdk_prepareSendPayment: (a: number, b: any) => any;
@@ -28,6 +28,7 @@ export const breezsdk_registerLightningAddress: (a: number, b: any) => any;
28
28
  export const breezsdk_deleteLightningAddress: (a: number) => any;
29
29
  export const breezsdk_listFiatCurrencies: (a: number) => any;
30
30
  export const breezsdk_listFiatRates: (a: number) => any;
31
+ export const breezsdk_waitForPayment: (a: number, b: any) => any;
31
32
  export const __wbg_sdkbuilder_free: (a: number, b: number) => void;
32
33
  export const sdkbuilder_new: (a: any, b: any, c: any) => [number, number, number];
33
34
  export const sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: number) => number;
@@ -59,7 +60,7 @@ export const __externref_table_alloc: () => number;
59
60
  export const __wbindgen_export_5: WebAssembly.Table;
60
61
  export const __wbindgen_export_6: WebAssembly.Table;
61
62
  export const __externref_table_dealloc: (a: number) => void;
62
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4: (a: number, b: number) => void;
63
- export const closure781_externref_shim: (a: number, b: number, c: any) => void;
63
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf: (a: number, b: number) => void;
64
+ export const closure780_externref_shim: (a: number, b: number, c: any) => void;
64
65
  export const closure434_externref_shim: (a: number, b: number, c: any, d: any) => void;
65
66
  export const __wbindgen_start: () => void;
@@ -126,11 +126,27 @@ class SqliteStorage {
126
126
  const actualLimit = limit !== null ? limit : 4294967295; // u32::MAX
127
127
 
128
128
  const stmt = this.db.prepare(`
129
- SELECT p.id, p.payment_type, p.status, p.amount, p.fees, p.timestamp, p.details, p.method, pm.lnurl_pay_info, pm.lnurl_description
130
- FROM payments p
131
- LEFT JOIN payment_metadata pm ON p.id = pm.payment_id
132
- ORDER BY p.timestamp DESC
133
- LIMIT ? OFFSET ?
129
+ SELECT p.id
130
+ , p.payment_type
131
+ , p.status
132
+ , p.amount
133
+ , p.fees
134
+ , p.timestamp
135
+ , p.method
136
+ , p.withdraw_tx_id
137
+ , p.deposit_tx_id
138
+ , p.spark
139
+ , l.invoice AS lightning_invoice
140
+ , l.payment_hash AS lightning_payment_hash
141
+ , l.destination_pubkey AS lightning_destination_pubkey
142
+ , COALESCE(l.description, pm.lnurl_description) AS lightning_description
143
+ , l.preimage AS lightning_preimage
144
+ , pm.lnurl_pay_info
145
+ FROM payments p
146
+ LEFT JOIN payment_details_lightning l ON p.id = l.payment_id
147
+ LEFT JOIN payment_metadata pm ON p.id = pm.payment_id
148
+ ORDER BY p.timestamp DESC
149
+ LIMIT ? OFFSET ?
134
150
  `);
135
151
 
136
152
  const rows = stmt.all(actualLimit, actualOffset);
@@ -153,21 +169,42 @@ class SqliteStorage {
153
169
  );
154
170
  }
155
171
 
156
- const stmt = this.db.prepare(`
157
- INSERT OR REPLACE INTO payments (id, payment_type, status, amount, fees, timestamp, details, method)
158
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
159
- `);
160
-
161
- stmt.run(
162
- payment.id,
163
- payment.paymentType,
164
- payment.status,
165
- payment.amount,
166
- payment.fees,
167
- payment.timestamp,
168
- payment.details ? JSON.stringify(payment.details) : null,
169
- payment.method ? JSON.stringify(payment.method) : null
172
+ const paymentInsert = this.db.prepare(
173
+ `INSERT OR REPLACE INTO payments (id, payment_type, status, amount, fees, timestamp, method, withdraw_tx_id, deposit_tx_id, spark)
174
+ VALUES (@id, @paymentType, @status, @amount, @fees, @timestamp, @method, @withdrawTxId, @depositTxId, @spark)`
175
+ );
176
+ const lightningInsert = this.db.prepare(
177
+ `INSERT OR REPLACE INTO payment_details_lightning
178
+ (payment_id, invoice, payment_hash, destination_pubkey, description, preimage)
179
+ VALUES (@id, @invoice, @paymentHash, @destinationPubkey, @description, @preimage)`
170
180
  );
181
+ const transaction = this.db.transaction(() => {
182
+ paymentInsert.run({
183
+ id: payment.id,
184
+ paymentType: payment.paymentType,
185
+ status: payment.status,
186
+ amount: payment.amount,
187
+ fees: payment.fees,
188
+ timestamp: payment.timestamp,
189
+ method: payment.method ? JSON.stringify(payment.method) : null,
190
+ withdrawTxId: payment.details?.type === 'withdraw' ? payment.details.txId : null,
191
+ depositTxId: payment.details?.type === 'deposit' ? payment.details.txId : null,
192
+ spark: payment.details?.type === 'spark' ? 1 : null,
193
+ });
194
+
195
+ if (payment.details?.type === 'lightning') {
196
+ lightningInsert.run({
197
+ id: payment.id,
198
+ invoice: payment.details.invoice,
199
+ paymentHash: payment.details.paymentHash,
200
+ destinationPubkey: payment.details.destinationPubkey,
201
+ description: payment.details.description,
202
+ preimage: payment.details.preimage,
203
+ });
204
+ }
205
+ });
206
+
207
+ transaction();
171
208
  return Promise.resolve();
172
209
  } catch (error) {
173
210
  return Promise.reject(
@@ -188,10 +225,26 @@ class SqliteStorage {
188
225
  }
189
226
 
190
227
  const stmt = this.db.prepare(`
191
- SELECT p.id, p.payment_type, p.status, p.amount, p.fees, p.timestamp, p.details, p.method, pm.lnurl_pay_info, pm.lnurl_description
192
- FROM payments p
193
- LEFT JOIN payment_metadata pm ON p.id = pm.payment_id
194
- WHERE p.id = ?
228
+ SELECT p.id
229
+ , p.payment_type
230
+ , p.status
231
+ , p.amount
232
+ , p.fees
233
+ , p.timestamp
234
+ , p.method
235
+ , p.withdraw_tx_id
236
+ , p.deposit_tx_id
237
+ , p.spark
238
+ , l.invoice AS lightning_invoice
239
+ , l.payment_hash AS lightning_payment_hash
240
+ , l.destination_pubkey AS lightning_destination_pubkey
241
+ , COALESCE(l.description, pm.lnurl_description) AS lightning_description
242
+ , l.preimage AS lightning_preimage
243
+ , pm.lnurl_pay_info
244
+ FROM payments p
245
+ LEFT JOIN payment_details_lightning l ON p.id = l.payment_id
246
+ LEFT JOIN payment_metadata pm ON p.id = pm.payment_id
247
+ WHERE p.id = ?
195
248
  `);
196
249
 
197
250
  const row = stmt.get(id);
@@ -214,6 +267,55 @@ class SqliteStorage {
214
267
  }
215
268
  }
216
269
 
270
+ getPaymentByInvoice(invoice) {
271
+ try {
272
+ if (!invoice) {
273
+ return Promise.reject(
274
+ new StorageError("Invoice cannot be null or undefined")
275
+ );
276
+ }
277
+
278
+ const stmt = this.db.prepare(`
279
+ SELECT p.id
280
+ , p.payment_type
281
+ , p.status
282
+ , p.amount
283
+ , p.fees
284
+ , p.timestamp
285
+ , p.method
286
+ , p.withdraw_tx_id
287
+ , p.deposit_tx_id
288
+ , p.spark
289
+ , l.invoice AS lightning_invoice
290
+ , l.payment_hash AS lightning_payment_hash
291
+ , l.destination_pubkey AS lightning_destination_pubkey
292
+ , COALESCE(l.description, pm.lnurl_description) AS lightning_description
293
+ , l.preimage AS lightning_preimage
294
+ , pm.lnurl_pay_info
295
+ FROM payments p
296
+ LEFT JOIN payment_details_lightning l ON p.id = l.payment_id
297
+ LEFT JOIN payment_metadata pm ON p.id = pm.payment_id
298
+ WHERE l.invoice = ?
299
+ `);
300
+
301
+ const row = stmt.get(invoice);
302
+ if (!row) {
303
+ return Promise.resolve(null);
304
+ }
305
+
306
+ return Promise.resolve(this._rowToPayment(row));
307
+ } catch (error) {
308
+ if (error instanceof StorageError) return Promise.reject(error);
309
+ const paymentId = id || "unknown";
310
+ return Promise.reject(
311
+ new StorageError(
312
+ `Failed to get payment by invoice '${invoice}': ${error.message}`,
313
+ error
314
+ )
315
+ );
316
+ }
317
+ }
318
+
217
319
  setPaymentMetadata(paymentId, metadata) {
218
320
  try {
219
321
  const stmt = this.db.prepare(`
@@ -340,15 +442,41 @@ class SqliteStorage {
340
442
 
341
443
  _rowToPayment(row) {
342
444
  let details = null;
343
- if (row.details) {
344
- try {
345
- details = JSON.parse(row.details);
346
- } catch (e) {
347
- throw new StorageError(
348
- `Failed to parse payment details JSON for payment ${row.id}: ${e.message}`,
349
- e
350
- );
445
+ if (row.lightning_invoice) {
446
+ details = {
447
+ type: 'lightning',
448
+ invoice: row.lightning_invoice,
449
+ paymentHash: row.lightning_payment_hash,
450
+ destinationPubkey: row.lightning_destination_pubkey,
451
+ description: row.lightning_description,
452
+ preimage: row.lightning_preimage,
453
+ };
454
+
455
+ if (row.lnurl_pay_info) {
456
+ try {
457
+ details.lnurlPayInfo = JSON.parse(row.lnurl_pay_info);
458
+ } catch (e) {
459
+ throw new StorageError(
460
+ `Failed to parse lnurl_pay_info JSON for payment ${row.id}: ${e.message}`,
461
+ e
462
+ );
463
+ }
351
464
  }
465
+ } else if (row.withdraw_tx_id) {
466
+ details = {
467
+ type: 'withdraw',
468
+ txId: row.withdraw_tx_id,
469
+ };
470
+ } else if (row.deposit_tx_id) {
471
+ details = {
472
+ type: 'deposit',
473
+ txId: row.deposit_tx_id,
474
+ };
475
+ } else if (row.spark) {
476
+ details = {
477
+ type: 'spark',
478
+ amount: row.spark,
479
+ };
352
480
  }
353
481
 
354
482
  let method = null;
@@ -363,21 +491,6 @@ class SqliteStorage {
363
491
  }
364
492
  }
365
493
 
366
- // If this is a Lightning payment and we have lnurl_pay_info, add it to details
367
- if (row.lnurl_pay_info && details && details.type == 'lightning') {
368
- try {
369
- details.lnurlPayInfo = JSON.parse(row.lnurl_pay_info);
370
- if (row.lnurl_description && !details.description) {
371
- details.description = row.lnurl_description;
372
- }
373
- } catch (e) {
374
- throw new StorageError(
375
- `Failed to parse lnurl_pay_info JSON for payment ${row.id}: ${e.message}`,
376
- e
377
- );
378
- }
379
- }
380
-
381
494
  return {
382
495
  id: row.id,
383
496
  paymentType: row.payment_type,
@@ -148,6 +148,34 @@ class MigrationManager {
148
148
  {
149
149
  name: "Add lnurl_description column to payment_metadata",
150
150
  sql: `ALTER TABLE payment_metadata ADD COLUMN lnurl_description TEXT`,
151
+ },
152
+ {
153
+ name: "Flatten payment details",
154
+ sql: [
155
+ `ALTER TABLE payments ADD COLUMN withdraw_tx_id TEXT`,
156
+ `ALTER TABLE payments ADD COLUMN deposit_tx_id TEXT`,
157
+ `ALTER TABLE payments ADD COLUMN spark INTEGER`,
158
+ `CREATE TABLE payment_details_lightning (
159
+ payment_id TEXT PRIMARY KEY,
160
+ invoice TEXT NOT NULL,
161
+ payment_hash TEXT NOT NULL,
162
+ destination_pubkey TEXT NOT NULL,
163
+ description TEXT,
164
+ preimage TEXT,
165
+ FOREIGN KEY (payment_id) REFERENCES payments(id) ON DELETE CASCADE
166
+ )`,
167
+ `INSERT INTO payment_details_lightning (payment_id, invoice, payment_hash, destination_pubkey, description, preimage)
168
+ SELECT id, json_extract(details, '$.Lightning.invoice'), json_extract(details, '$.Lightning.payment_hash'),
169
+ json_extract(details, '$.Lightning.destination_pubkey'), json_extract(details, '$.Lightning.description'),
170
+ json_extract(details, '$.Lightning.preimage')
171
+ FROM payments WHERE json_extract(details, '$.Lightning.invoice') IS NOT NULL`,
172
+ `UPDATE payments SET withdraw_tx_id = json_extract(details, '$.Withdraw.tx_id')
173
+ WHERE json_extract(details, '$.Withdraw.tx_id') IS NOT NULL`,
174
+ `UPDATE payments SET deposit_tx_id = json_extract(details, '$.Deposit.tx_id')
175
+ WHERE json_extract(details, '$.Deposit.tx_id') IS NOT NULL`,
176
+ `ALTER TABLE payments DROP COLUMN details`,
177
+ `CREATE INDEX idx_payment_details_lightning_invoice ON payment_details_lightning(invoice)`,
178
+ ]
151
179
  }
152
180
  ];
153
181
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breeztech/breez-sdk-spark",
3
- "version": "0.2.5-dev2",
3
+ "version": "0.2.6",
4
4
  "description": "Breez Spark SDK",
5
5
  "repository": "https://github.com/breez/spark-sdk",
6
6
  "author": "Breez <contact@breez.technology> (https://github.com/breez)",
@@ -31,12 +31,23 @@ export interface Storage {
31
31
  insertPayment: (payment: Payment) => Promise<void>;
32
32
  setPaymentMetadata: (paymentId: string, metadata: PaymentMetadata) => Promise<void>;
33
33
  getPaymentById: (id: string) => Promise<Payment>;
34
+ getPaymentByInvoice: (invoice: string) => Promise<Payment>;
34
35
  addDeposit: (txid: string, vout: number, amount_sats: number) => Promise<void>;
35
36
  deleteDeposit: (txid: string, vout: number) => Promise<void>;
36
37
  listDeposits: () => Promise<DepositInfo[]>;
37
38
  updateDeposit: (txid: string, vout: number, payload: UpdateDepositPayload) => Promise<void>;
38
39
  }
39
40
 
41
+ export interface WaitForPaymentResponse {
42
+ payment: Payment;
43
+ }
44
+
45
+ export type WaitForPaymentIdentifier = ({ type: "paymentId" } & string) | ({ type: "paymentRequest" } & string);
46
+
47
+ export interface WaitForPaymentRequest {
48
+ identifier: WaitForPaymentIdentifier;
49
+ }
50
+
40
51
  export interface Symbol {
41
52
  grapheme?: string;
42
53
  template?: string;
@@ -137,7 +148,7 @@ export interface SendPaymentRequest {
137
148
  options?: SendPaymentOptions;
138
149
  }
139
150
 
140
- export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean };
151
+ export type SendPaymentOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean; completionTimeoutSecs?: number };
141
152
 
142
153
  export type OnchainConfirmationSpeed = "fast" | "medium" | "slow";
143
154
 
@@ -513,7 +524,7 @@ export class BreezSdk {
513
524
  free(): void;
514
525
  addEventListener(listener: EventListener): Promise<string>;
515
526
  removeEventListener(id: string): Promise<boolean>;
516
- disconnect(): void;
527
+ disconnect(): Promise<void>;
517
528
  getInfo(request: GetInfoRequest): Promise<GetInfoResponse>;
518
529
  receivePayment(request: ReceivePaymentRequest): Promise<ReceivePaymentResponse>;
519
530
  prepareSendPayment(request: PrepareSendPaymentRequest): Promise<PrepareSendPaymentResponse>;
@@ -532,6 +543,7 @@ export class BreezSdk {
532
543
  deleteLightningAddress(): Promise<void>;
533
544
  listFiatCurrencies(): Promise<ListFiatCurrenciesResponse>;
534
545
  listFiatRates(): Promise<ListFiatRatesResponse>;
546
+ waitForPayment(request: WaitForPaymentRequest): Promise<WaitForPaymentResponse>;
535
547
  }
536
548
  export class IntoUnderlyingByteSource {
537
549
  private constructor();
@@ -576,7 +588,7 @@ export interface InitOutput {
576
588
  readonly parse: (a: number, b: number) => any;
577
589
  readonly breezsdk_addEventListener: (a: number, b: any) => any;
578
590
  readonly breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
579
- readonly breezsdk_disconnect: (a: number) => [number, number];
591
+ readonly breezsdk_disconnect: (a: number) => any;
580
592
  readonly breezsdk_getInfo: (a: number, b: any) => any;
581
593
  readonly breezsdk_receivePayment: (a: number, b: any) => any;
582
594
  readonly breezsdk_prepareSendPayment: (a: number, b: any) => any;
@@ -595,6 +607,7 @@ export interface InitOutput {
595
607
  readonly breezsdk_deleteLightningAddress: (a: number) => any;
596
608
  readonly breezsdk_listFiatCurrencies: (a: number) => any;
597
609
  readonly breezsdk_listFiatRates: (a: number) => any;
610
+ readonly breezsdk_waitForPayment: (a: number, b: any) => any;
598
611
  readonly __wbg_sdkbuilder_free: (a: number, b: number) => void;
599
612
  readonly sdkbuilder_new: (a: any, b: any, c: any) => [number, number, number];
600
613
  readonly sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: number) => number;
@@ -626,8 +639,8 @@ export interface InitOutput {
626
639
  readonly __wbindgen_export_5: WebAssembly.Table;
627
640
  readonly __wbindgen_export_6: WebAssembly.Table;
628
641
  readonly __externref_table_dealloc: (a: number) => void;
629
- readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4: (a: number, b: number) => void;
630
- readonly closure781_externref_shim: (a: number, b: number, c: any) => void;
642
+ readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf: (a: number, b: number) => void;
643
+ readonly closure780_externref_shim: (a: number, b: number, c: any) => void;
631
644
  readonly closure434_externref_shim: (a: number, b: number, c: any, d: any) => void;
632
645
  readonly __wbindgen_start: () => void;
633
646
  }
@@ -271,14 +271,14 @@ export function task_worker_entry_point(ptr) {
271
271
  }
272
272
 
273
273
  function __wbg_adapter_52(arg0, arg1) {
274
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4(arg0, arg1);
274
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf(arg0, arg1);
275
275
  }
276
276
 
277
277
  function __wbg_adapter_55(arg0, arg1, arg2) {
278
- wasm.closure781_externref_shim(arg0, arg1, arg2);
278
+ wasm.closure780_externref_shim(arg0, arg1, arg2);
279
279
  }
280
280
 
281
- function __wbg_adapter_180(arg0, arg1, arg2, arg3) {
281
+ function __wbg_adapter_183(arg0, arg1, arg2, arg3) {
282
282
  wasm.closure434_externref_shim(arg0, arg1, arg2, arg3);
283
283
  }
284
284
 
@@ -337,11 +337,12 @@ export class BreezSdk {
337
337
  const ret = wasm.breezsdk_removeEventListener(this.__wbg_ptr, ptr0, len0);
338
338
  return ret;
339
339
  }
340
+ /**
341
+ * @returns {Promise<void>}
342
+ */
340
343
  disconnect() {
341
344
  const ret = wasm.breezsdk_disconnect(this.__wbg_ptr);
342
- if (ret[1]) {
343
- throw takeFromExternrefTable0(ret[0]);
344
- }
345
+ return ret;
345
346
  }
346
347
  /**
347
348
  * @param {GetInfoRequest} request
@@ -483,6 +484,14 @@ export class BreezSdk {
483
484
  const ret = wasm.breezsdk_listFiatRates(this.__wbg_ptr);
484
485
  return ret;
485
486
  }
487
+ /**
488
+ * @param {WaitForPaymentRequest} request
489
+ * @returns {Promise<WaitForPaymentResponse>}
490
+ */
491
+ waitForPayment(request) {
492
+ const ret = wasm.breezsdk_waitForPayment(this.__wbg_ptr, request);
493
+ return ret;
494
+ }
486
495
  }
487
496
 
488
497
  const IntoUnderlyingByteSourceFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -888,6 +897,18 @@ function __wbg_get_imports() {
888
897
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
889
898
  }
890
899
  }, arguments) };
900
+ imports.wbg.__wbg_getPaymentByInvoice_afddfcbefa5508b0 = function() { return handleError(function (arg0, arg1, arg2) {
901
+ let deferred0_0;
902
+ let deferred0_1;
903
+ try {
904
+ deferred0_0 = arg1;
905
+ deferred0_1 = arg2;
906
+ const ret = arg0.getPaymentByInvoice(getStringFromWasm0(arg1, arg2));
907
+ return ret;
908
+ } finally {
909
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
910
+ }
911
+ }, arguments) };
891
912
  imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
892
913
  arg0.getRandomValues(arg1);
893
914
  }, arguments) };
@@ -1016,7 +1037,7 @@ function __wbg_get_imports() {
1016
1037
  const a = state0.a;
1017
1038
  state0.a = 0;
1018
1039
  try {
1019
- return __wbg_adapter_180(a, state0.b, arg0, arg1);
1040
+ return __wbg_adapter_183(a, state0.b, arg0, arg1);
1020
1041
  } finally {
1021
1042
  state0.a = a;
1022
1043
  }
@@ -1312,12 +1333,12 @@ function __wbg_get_imports() {
1312
1333
  const ret = false;
1313
1334
  return ret;
1314
1335
  };
1315
- imports.wbg.__wbindgen_closure_wrapper8071 = function(arg0, arg1, arg2) {
1316
- const ret = makeMutClosure(arg0, arg1, 611, __wbg_adapter_52);
1336
+ imports.wbg.__wbindgen_closure_wrapper8079 = function(arg0, arg1, arg2) {
1337
+ const ret = makeMutClosure(arg0, arg1, 612, __wbg_adapter_52);
1317
1338
  return ret;
1318
1339
  };
1319
- imports.wbg.__wbindgen_closure_wrapper9713 = function(arg0, arg1, arg2) {
1320
- const ret = makeMutClosure(arg0, arg1, 782, __wbg_adapter_55);
1340
+ imports.wbg.__wbindgen_closure_wrapper9672 = function(arg0, arg1, arg2) {
1341
+ const ret = makeMutClosure(arg0, arg1, 781, __wbg_adapter_55);
1321
1342
  return ret;
1322
1343
  };
1323
1344
  imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
Binary file
@@ -9,7 +9,7 @@ export const defaultStorage: (a: number, b: number) => any;
9
9
  export const parse: (a: number, b: number) => any;
10
10
  export const breezsdk_addEventListener: (a: number, b: any) => any;
11
11
  export const breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
12
- export const breezsdk_disconnect: (a: number) => [number, number];
12
+ export const breezsdk_disconnect: (a: number) => any;
13
13
  export const breezsdk_getInfo: (a: number, b: any) => any;
14
14
  export const breezsdk_receivePayment: (a: number, b: any) => any;
15
15
  export const breezsdk_prepareSendPayment: (a: number, b: any) => any;
@@ -28,6 +28,7 @@ export const breezsdk_registerLightningAddress: (a: number, b: any) => any;
28
28
  export const breezsdk_deleteLightningAddress: (a: number) => any;
29
29
  export const breezsdk_listFiatCurrencies: (a: number) => any;
30
30
  export const breezsdk_listFiatRates: (a: number) => any;
31
+ export const breezsdk_waitForPayment: (a: number, b: any) => any;
31
32
  export const __wbg_sdkbuilder_free: (a: number, b: number) => void;
32
33
  export const sdkbuilder_new: (a: any, b: any, c: any) => [number, number, number];
33
34
  export const sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: number) => number;
@@ -59,7 +60,7 @@ export const __externref_table_alloc: () => number;
59
60
  export const __wbindgen_export_5: WebAssembly.Table;
60
61
  export const __wbindgen_export_6: WebAssembly.Table;
61
62
  export const __externref_table_dealloc: (a: number) => void;
62
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf7c49586be6831c4: (a: number, b: number) => void;
63
- export const closure781_externref_shim: (a: number, b: number, c: any) => void;
63
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__he5eedad33b9ff4bf: (a: number, b: number) => void;
64
+ export const closure780_externref_shim: (a: number, b: number, c: any) => void;
64
65
  export const closure434_externref_shim: (a: number, b: number, c: any, d: any) => void;
65
66
  export const __wbindgen_start: () => void;
@@ -100,6 +100,17 @@ class MigrationManager {
100
100
  }
101
101
  },
102
102
  },
103
+ {
104
+ name: "Create invoice index",
105
+ upgrade: (db, transaction) => {
106
+ const paymentStore = transaction.objectStore("payments");
107
+ if (!paymentStore.indexNames.contains("invoice")) {
108
+ paymentStore.createIndex("invoice", "details.invoice", {
109
+ unique: false,
110
+ });
111
+ }
112
+ }
113
+ }
103
114
  ];
104
115
  }
105
116
  }
@@ -436,6 +447,58 @@ class IndexedDBStorage {
436
447
  });
437
448
  }
438
449
 
450
+ async getPaymentByInvoice(invoice) {
451
+ if (!this.db) {
452
+ throw new StorageError("Database not initialized");
453
+ }
454
+
455
+ return new Promise((resolve, reject) => {
456
+ const transaction = this.db.transaction(
457
+ ["payments", "payment_metadata"],
458
+ "readonly"
459
+ );
460
+ const paymentStore = transaction.objectStore("payments");
461
+ const invoiceIndex = paymentStore.index("invoice");
462
+ const metadataStore = transaction.objectStore("payment_metadata");
463
+
464
+ const paymentRequest = invoiceIndex.get(invoice);
465
+
466
+ paymentRequest.onsuccess = () => {
467
+ const payment = paymentRequest.result;
468
+ if (!payment) {
469
+ resolve(null);
470
+ return;
471
+ }
472
+
473
+ // Get metadata for this payment
474
+ const metadataRequest = metadataStore.get(invoice);
475
+ metadataRequest.onsuccess = () => {
476
+ const metadata = metadataRequest.result;
477
+ const paymentWithMetadata = this._mergePaymentMetadata(
478
+ payment,
479
+ metadata
480
+ );
481
+ resolve(paymentWithMetadata);
482
+ };
483
+ metadataRequest.onerror = () => {
484
+ // Return payment without metadata if metadata fetch fails
485
+ resolve(payment);
486
+ };
487
+ };
488
+
489
+ paymentRequest.onerror = () => {
490
+ reject(
491
+ new StorageError(
492
+ `Failed to get payment by invoice '${invoice}': ${
493
+ paymentRequest.error?.message || "Unknown error"
494
+ }`,
495
+ paymentRequest.error
496
+ )
497
+ );
498
+ };
499
+ });
500
+ }
501
+
439
502
  async setPaymentMetadata(paymentId, metadata) {
440
503
  if (!this.db) {
441
504
  throw new StorageError("Database not initialized");