@breeztech/breez-sdk-spark 0.10.0 → 0.11.0-dev2

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.
@@ -221,6 +221,43 @@ function debugString(val) {
221
221
  // TODO we could test for more things here, like `Set`s and `Map`s.
222
222
  return className;
223
223
  }
224
+ /**
225
+ * Creates a default PostgreSQL storage configuration with sensible defaults.
226
+ *
227
+ * Default values (from pg.Pool):
228
+ * - `maxPoolSize`: 10
229
+ * - `createTimeoutSecs`: 0 (no timeout)
230
+ * - `recycleTimeoutSecs`: 10 (10 seconds idle before disconnect)
231
+ * @param {string} connection_string
232
+ * @returns {PostgresStorageConfig}
233
+ */
234
+ export function defaultPostgresStorageConfig(connection_string) {
235
+ const ptr0 = passStringToWasm0(connection_string, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
236
+ const len0 = WASM_VECTOR_LEN;
237
+ const ret = wasm.defaultPostgresStorageConfig(ptr0, len0);
238
+ return ret;
239
+ }
240
+
241
+ /**
242
+ * Creates a default external signer from a mnemonic phrase.
243
+ *
244
+ * This creates a signer that can be used with `connectWithSigner` or `SdkBuilder.newWithSigner`.
245
+ * @returns {Promise<SparkStatus>}
246
+ */
247
+ export function getSparkStatus() {
248
+ const ret = wasm.getSparkStatus();
249
+ return ret;
250
+ }
251
+
252
+ /**
253
+ * @param {Network} network
254
+ * @returns {Config}
255
+ */
256
+ export function defaultConfig(network) {
257
+ const ret = wasm.defaultConfig(network);
258
+ return ret;
259
+ }
260
+
224
261
  /**
225
262
  * @param {Logger} logger
226
263
  * @param {string | null} [filter]
@@ -257,15 +294,6 @@ export function defaultExternalSigner(mnemonic, passphrase, network, key_set_con
257
294
  return DefaultSigner.__wrap(ret[0]);
258
295
  }
259
296
 
260
- /**
261
- * @param {Network} network
262
- * @returns {Config}
263
- */
264
- export function defaultConfig(network) {
265
- const ret = wasm.defaultConfig(network);
266
- return ret;
267
- }
268
-
269
297
  /**
270
298
  * @param {ConnectRequest} request
271
299
  * @returns {Promise<BreezSdk>}
@@ -288,17 +316,6 @@ export function connectWithSigner(config, signer, storage_dir) {
288
316
  return ret;
289
317
  }
290
318
 
291
- /**
292
- * Creates a default external signer from a mnemonic phrase.
293
- *
294
- * This creates a signer that can be used with `connectWithSigner` or `SdkBuilder.newWithSigner`.
295
- * @returns {Promise<SparkStatus>}
296
- */
297
- export function getSparkStatus() {
298
- const ret = wasm.getSparkStatus();
299
- return ret;
300
- }
301
-
302
319
  function passArray8ToWasm0(arg, malloc) {
303
320
  const ptr = malloc(arg.length * 1, 1) >>> 0;
304
321
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -317,15 +334,15 @@ export function task_worker_entry_point(ptr) {
317
334
  }
318
335
 
319
336
  function __wbg_adapter_64(arg0, arg1) {
320
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hce61e5994b0c00ad(arg0, arg1);
337
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2ac8515d28de5817(arg0, arg1);
321
338
  }
322
339
 
323
340
  function __wbg_adapter_67(arg0, arg1, arg2) {
324
- wasm.closure1048_externref_shim(arg0, arg1, arg2);
341
+ wasm.closure1068_externref_shim(arg0, arg1, arg2);
325
342
  }
326
343
 
327
- function __wbg_adapter_285(arg0, arg1, arg2, arg3) {
328
- wasm.closure642_externref_shim(arg0, arg1, arg2, arg3);
344
+ function __wbg_adapter_301(arg0, arg1, arg2, arg3) {
345
+ wasm.closure651_externref_shim(arg0, arg1, arg2, arg3);
329
346
  }
330
347
 
331
348
  const __wbindgen_enum_ReadableStreamType = ["bytes"];
@@ -380,6 +397,14 @@ export class BreezSdk {
380
397
  const ret = wasm.breezsdk_lnurlAuth(this.__wbg_ptr, request_data);
381
398
  return ret;
382
399
  }
400
+ /**
401
+ * @param {AddContactRequest} request
402
+ * @returns {Promise<Contact>}
403
+ */
404
+ addContact(request) {
405
+ const ret = wasm.breezsdk_addContact(this.__wbg_ptr, request);
406
+ return ret;
407
+ }
383
408
  /**
384
409
  * @param {BuyBitcoinRequest} request
385
410
  * @returns {Promise<BuyBitcoinResponse>}
@@ -436,6 +461,14 @@ export class BreezSdk {
436
461
  const ret = wasm.breezsdk_claimDeposit(this.__wbg_ptr, request);
437
462
  return ret;
438
463
  }
464
+ /**
465
+ * @param {ListContactsRequest} request
466
+ * @returns {Promise<Contact[]>}
467
+ */
468
+ listContacts(request) {
469
+ const ret = wasm.breezsdk_listContacts(this.__wbg_ptr, request);
470
+ return ret;
471
+ }
439
472
  /**
440
473
  * @param {ListPaymentsRequest} request
441
474
  * @returns {Promise<ListPaymentsResponse>}
@@ -444,6 +477,16 @@ export class BreezSdk {
444
477
  const ret = wasm.breezsdk_listPayments(this.__wbg_ptr, request);
445
478
  return ret;
446
479
  }
480
+ /**
481
+ * @param {string} id
482
+ * @returns {Promise<void>}
483
+ */
484
+ deleteContact(id) {
485
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
486
+ const len0 = WASM_VECTOR_LEN;
487
+ const ret = wasm.breezsdk_deleteContact(this.__wbg_ptr, ptr0, len0);
488
+ return ret;
489
+ }
447
490
  /**
448
491
  * @param {LnurlWithdrawRequest} request
449
492
  * @returns {Promise<LnurlWithdrawResponse>}
@@ -460,6 +503,14 @@ export class BreezSdk {
460
503
  const ret = wasm.breezsdk_refundDeposit(this.__wbg_ptr, request);
461
504
  return ret;
462
505
  }
506
+ /**
507
+ * @param {UpdateContactRequest} request
508
+ * @returns {Promise<Contact>}
509
+ */
510
+ updateContact(request) {
511
+ const ret = wasm.breezsdk_updateContact(this.__wbg_ptr, request);
512
+ return ret;
513
+ }
463
514
  /**
464
515
  * @returns {Promise<ListFiatRatesResponse>}
465
516
  */
@@ -1099,6 +1150,15 @@ export class SdkBuilder {
1099
1150
  const ret = wasm.sdkbuilder_withPaymentObserver(ptr, payment_observer);
1100
1151
  return SdkBuilder.__wrap(ret);
1101
1152
  }
1153
+ /**
1154
+ * @param {PostgresStorageConfig} config
1155
+ * @returns {SdkBuilder}
1156
+ */
1157
+ withPostgresStorage(config) {
1158
+ const ptr = this.__destroy_into_raw();
1159
+ const ret = wasm.sdkbuilder_withPostgresStorage(ptr, config);
1160
+ return SdkBuilder.__wrap(ret);
1161
+ }
1102
1162
  /**
1103
1163
  * @param {string} url
1104
1164
  * @param {ChainApiType} api_type
@@ -1353,6 +1413,11 @@ export function __wbg_createDefaultStorage_458aa01b5eaead27() { return handleErr
1353
1413
  return ret;
1354
1414
  }, arguments) };
1355
1415
 
1416
+ export function __wbg_createPostgresStorage_46770cbf8e947f9e() { return handleError(function (arg0, arg1) {
1417
+ const ret = createPostgresStorage(arg0, arg1);
1418
+ return ret;
1419
+ }, arguments) };
1420
+
1356
1421
  export function __wbg_crypto_574e78ad8b13b65f(arg0) {
1357
1422
  const ret = arg0.crypto;
1358
1423
  return ret;
@@ -1371,6 +1436,19 @@ export function __wbg_deleteCachedItem_ff3c84380e94360b() { return handleError(f
1371
1436
  }
1372
1437
  }, arguments) };
1373
1438
 
1439
+ export function __wbg_deleteContact_04d635b32c469d83() { return handleError(function (arg0, arg1, arg2) {
1440
+ let deferred0_0;
1441
+ let deferred0_1;
1442
+ try {
1443
+ deferred0_0 = arg1;
1444
+ deferred0_1 = arg2;
1445
+ const ret = arg0.deleteContact(getStringFromWasm0(arg1, arg2));
1446
+ return ret;
1447
+ } finally {
1448
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1449
+ }
1450
+ }, arguments) };
1451
+
1374
1452
  export function __wbg_deleteDeposit_72ec826e7c3c3ccf() { return handleError(function (arg0, arg1, arg2, arg3) {
1375
1453
  let deferred0_0;
1376
1454
  let deferred0_1;
@@ -1534,6 +1612,19 @@ export function __wbg_getCachedItem_de40d6348815c7b9() { return handleError(func
1534
1612
  }
1535
1613
  }, arguments) };
1536
1614
 
1615
+ export function __wbg_getContact_b7300737e5dee01b() { return handleError(function (arg0, arg1, arg2) {
1616
+ let deferred0_0;
1617
+ let deferred0_1;
1618
+ try {
1619
+ deferred0_0 = arg1;
1620
+ deferred0_1 = arg2;
1621
+ const ret = arg0.getContact(getStringFromWasm0(arg1, arg2));
1622
+ return ret;
1623
+ } finally {
1624
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1625
+ }
1626
+ }, arguments) };
1627
+
1537
1628
  export function __wbg_getPaymentById_c23144bfc404b2fc() { return handleError(function (arg0, arg1, arg2) {
1538
1629
  let deferred0_0;
1539
1630
  let deferred0_1;
@@ -1699,6 +1790,11 @@ export function __wbg_identityPublicKey_c8b35005055a3df0() { return handleError(
1699
1790
  return ret;
1700
1791
  }, arguments) };
1701
1792
 
1793
+ export function __wbg_insertContact_33c214012213409d() { return handleError(function (arg0, arg1) {
1794
+ const ret = arg0.insertContact(arg1);
1795
+ return ret;
1796
+ }, arguments) };
1797
+
1702
1798
  export function __wbg_insertPaymentMetadata_0c4ebdcde694d29b() { return handleError(function (arg0, arg1, arg2, arg3) {
1703
1799
  let deferred0_0;
1704
1800
  let deferred0_1;
@@ -1819,6 +1915,11 @@ export function __wbg_length_e2d2a49132c1b256(arg0) {
1819
1915
  return ret;
1820
1916
  };
1821
1917
 
1918
+ export function __wbg_listContacts_5b4d38a57743b713() { return handleError(function (arg0, arg1) {
1919
+ const ret = arg0.listContacts(arg1);
1920
+ return ret;
1921
+ }, arguments) };
1922
+
1822
1923
  export function __wbg_listDeposits_7ca6e22afc06d560() { return handleError(function (arg0) {
1823
1924
  const ret = arg0.listDeposits();
1824
1925
  return ret;
@@ -1876,7 +1977,7 @@ export function __wbg_new_23a2665fac83c611(arg0, arg1) {
1876
1977
  const a = state0.a;
1877
1978
  state0.a = 0;
1878
1979
  try {
1879
- return __wbg_adapter_285(a, state0.b, arg0, arg1);
1980
+ return __wbg_adapter_301(a, state0.b, arg0, arg1);
1880
1981
  } finally {
1881
1982
  state0.a = a;
1882
1983
  }
@@ -2401,13 +2502,13 @@ export function __wbindgen_cb_drop(arg0) {
2401
2502
  return ret;
2402
2503
  };
2403
2504
 
2404
- export function __wbindgen_closure_wrapper11704(arg0, arg1, arg2) {
2405
- const ret = makeMutClosure(arg0, arg1, 817, __wbg_adapter_64);
2505
+ export function __wbindgen_closure_wrapper11838(arg0, arg1, arg2) {
2506
+ const ret = makeMutClosure(arg0, arg1, 828, __wbg_adapter_64);
2406
2507
  return ret;
2407
2508
  };
2408
2509
 
2409
- export function __wbindgen_closure_wrapper13627(arg0, arg1, arg2) {
2410
- const ret = makeMutClosure(arg0, arg1, 1049, __wbg_adapter_67);
2510
+ export function __wbindgen_closure_wrapper13801(arg0, arg1, arg2) {
2511
+ const ret = makeMutClosure(arg0, arg1, 1069, __wbg_adapter_67);
2411
2512
  return ret;
2412
2513
  };
2413
2514
 
@@ -5,6 +5,7 @@ export const __wbg_breezsdk_free: (a: number, b: number) => void;
5
5
  export const __wbg_defaultsigner_free: (a: number, b: number) => void;
6
6
  export const __wbg_sdkbuilder_free: (a: number, b: number) => void;
7
7
  export const __wbg_tokenissuer_free: (a: number, b: number) => void;
8
+ export const breezsdk_addContact: (a: number, b: any) => any;
8
9
  export const breezsdk_addEventListener: (a: number, b: any) => any;
9
10
  export const breezsdk_buyBitcoin: (a: number, b: any) => any;
10
11
  export const breezsdk_cancelLeafOptimization: (a: number) => any;
@@ -12,6 +13,7 @@ export const breezsdk_checkLightningAddressAvailable: (a: number, b: any) => any
12
13
  export const breezsdk_checkMessage: (a: number, b: any) => any;
13
14
  export const breezsdk_claimDeposit: (a: number, b: any) => any;
14
15
  export const breezsdk_claimHtlcPayment: (a: number, b: any) => any;
16
+ export const breezsdk_deleteContact: (a: number, b: number, c: number) => any;
15
17
  export const breezsdk_deleteLightningAddress: (a: number) => any;
16
18
  export const breezsdk_disconnect: (a: number) => any;
17
19
  export const breezsdk_fetchConversionLimits: (a: number, b: any) => any;
@@ -22,6 +24,7 @@ export const breezsdk_getPayment: (a: number, b: any) => any;
22
24
  export const breezsdk_getTokenIssuer: (a: number) => number;
23
25
  export const breezsdk_getTokensMetadata: (a: number, b: any) => any;
24
26
  export const breezsdk_getUserSettings: (a: number) => any;
27
+ export const breezsdk_listContacts: (a: number, b: any) => any;
25
28
  export const breezsdk_listFiatCurrencies: (a: number) => any;
26
29
  export const breezsdk_listFiatRates: (a: number) => any;
27
30
  export const breezsdk_listPayments: (a: number, b: any) => any;
@@ -41,11 +44,13 @@ export const breezsdk_sendPayment: (a: number, b: any) => any;
41
44
  export const breezsdk_signMessage: (a: number, b: any) => any;
42
45
  export const breezsdk_startLeafOptimization: (a: number) => void;
43
46
  export const breezsdk_syncWallet: (a: number, b: any) => any;
47
+ export const breezsdk_updateContact: (a: number, b: any) => any;
44
48
  export const breezsdk_updateUserSettings: (a: number, b: any) => any;
45
49
  export const connect: (a: any) => any;
46
50
  export const connectWithSigner: (a: any, b: any, c: number, d: number) => any;
47
51
  export const defaultConfig: (a: any) => any;
48
52
  export const defaultExternalSigner: (a: number, b: number, c: number, d: number, e: any, f: number) => [number, number, number];
53
+ export const defaultPostgresStorageConfig: (a: number, b: number) => any;
49
54
  export const defaultsigner_aggregateFrost: (a: number, b: any) => any;
50
55
  export const defaultsigner_decryptEcies: (a: number, b: number, c: number, d: number, e: number) => any;
51
56
  export const defaultsigner_derivePublicKey: (a: number, b: number, c: number) => any;
@@ -77,6 +82,7 @@ export const sdkbuilder_withFiatService: (a: number, b: any) => number;
77
82
  export const sdkbuilder_withKeySet: (a: number, b: any) => number;
78
83
  export const sdkbuilder_withLnurlClient: (a: number, b: any) => number;
79
84
  export const sdkbuilder_withPaymentObserver: (a: number, b: any) => number;
85
+ export const sdkbuilder_withPostgresStorage: (a: number, b: any) => number;
80
86
  export const sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: any, e: number) => number;
81
87
  export const sdkbuilder_withStorage: (a: number, b: any) => number;
82
88
  export const tokenissuer_burnIssuerToken: (a: number, b: any) => any;
@@ -113,7 +119,7 @@ export const __wbindgen_export_5: WebAssembly.Table;
113
119
  export const __externref_drop_slice: (a: number, b: number) => void;
114
120
  export const __wbindgen_export_7: WebAssembly.Table;
115
121
  export const __externref_table_dealloc: (a: number) => void;
116
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hce61e5994b0c00ad: (a: number, b: number) => void;
117
- export const closure1048_externref_shim: (a: number, b: number, c: any) => void;
118
- export const closure642_externref_shim: (a: number, b: number, c: any, d: any) => void;
122
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2ac8515d28de5817: (a: number, b: number) => void;
123
+ export const closure1068_externref_shim: (a: number, b: number, c: any) => void;
124
+ export const closure651_externref_shim: (a: number, b: number, c: any, d: any) => void;
119
125
  export const __wbindgen_start: () => void;
@@ -409,6 +409,16 @@ class MigrationManager {
409
409
  }
410
410
  },
411
411
  },
412
+ {
413
+ name: "Create contacts store",
414
+ upgrade: (db) => {
415
+ if (!db.objectStoreNames.contains("contacts")) {
416
+ const contactsStore = db.createObjectStore("contacts", { keyPath: "id" });
417
+ contactsStore.createIndex("name_identifier", ["name", "paymentIdentifier"], { unique: false });
418
+ contactsStore.createIndex("name", "name", { unique: false });
419
+ }
420
+ }
421
+ },
412
422
  {
413
423
  name: "Clear cached lightning address for LnurlInfo schema change",
414
424
  upgrade: (db, transaction) => {
@@ -441,7 +451,7 @@ class IndexedDBStorage {
441
451
  this.db = null;
442
452
  this.migrationManager = null;
443
453
  this.logger = logger;
444
- this.dbVersion = 13; // Current schema version
454
+ this.dbVersion = 14; // Current schema version
445
455
  }
446
456
 
447
457
  /**
@@ -461,8 +471,7 @@ class IndexedDBStorage {
461
471
 
462
472
  request.onerror = () => {
463
473
  const error = new StorageError(
464
- `Failed to open IndexedDB: ${
465
- request.error?.message || "Unknown error"
474
+ `Failed to open IndexedDB: ${request.error?.message || "Unknown error"
466
475
  }`,
467
476
  request.error
468
477
  );
@@ -537,8 +546,7 @@ class IndexedDBStorage {
537
546
  request.onerror = () => {
538
547
  reject(
539
548
  new StorageError(
540
- `Failed to get cached item '${key}': ${
541
- request.error?.message || "Unknown error"
549
+ `Failed to get cached item '${key}': ${request.error?.message || "Unknown error"
542
550
  }`,
543
551
  request.error
544
552
  )
@@ -562,8 +570,7 @@ class IndexedDBStorage {
562
570
  request.onerror = () => {
563
571
  reject(
564
572
  new StorageError(
565
- `Failed to set cached item '${key}': ${
566
- request.error?.message || "Unknown error"
573
+ `Failed to set cached item '${key}': ${request.error?.message || "Unknown error"
567
574
  }`,
568
575
  request.error
569
576
  )
@@ -587,8 +594,7 @@ class IndexedDBStorage {
587
594
  request.onerror = () => {
588
595
  reject(
589
596
  new StorageError(
590
- `Failed to delete cached item '${key}': ${
591
- request.error?.message || "Unknown error"
597
+ `Failed to delete cached item '${key}': ${request.error?.message || "Unknown error"
592
598
  }`,
593
599
  request.error
594
600
  )
@@ -758,8 +764,7 @@ class IndexedDBStorage {
758
764
  cursorRequest.onerror = () => {
759
765
  reject(
760
766
  new StorageError(
761
- `Failed to list payments (request: ${JSON.stringify(request)}: ${
762
- cursorRequest.error?.message || "Unknown error"
767
+ `Failed to list payments (request: ${JSON.stringify(request)}: ${cursorRequest.error?.message || "Unknown error"
763
768
  }`,
764
769
  cursorRequest.error
765
770
  )
@@ -789,8 +794,7 @@ class IndexedDBStorage {
789
794
  request.onerror = () => {
790
795
  reject(
791
796
  new StorageError(
792
- `Failed to insert payment '${payment.id}': ${
793
- request.error?.message || "Unknown error"
797
+ `Failed to insert payment '${payment.id}': ${request.error?.message || "Unknown error"
794
798
  }`,
795
799
  request.error
796
800
  )
@@ -853,8 +857,7 @@ class IndexedDBStorage {
853
857
  paymentRequest.onerror = () => {
854
858
  reject(
855
859
  new StorageError(
856
- `Failed to get payment by id '${id}': ${
857
- paymentRequest.error?.message || "Unknown error"
860
+ `Failed to get payment by id '${id}': ${paymentRequest.error?.message || "Unknown error"
858
861
  }`,
859
862
  paymentRequest.error
860
863
  )
@@ -918,8 +921,7 @@ class IndexedDBStorage {
918
921
  paymentRequest.onerror = () => {
919
922
  reject(
920
923
  new StorageError(
921
- `Failed to get payment by invoice '${invoice}': ${
922
- paymentRequest.error?.message || "Unknown error"
924
+ `Failed to get payment by invoice '${invoice}': ${paymentRequest.error?.message || "Unknown error"
923
925
  }`,
924
926
  paymentRequest.error
925
927
  )
@@ -1084,8 +1086,7 @@ class IndexedDBStorage {
1084
1086
  cursorRequest.onerror = () => {
1085
1087
  reject(
1086
1088
  new StorageError(
1087
- `Failed to get payments by parent ids: ${
1088
- cursorRequest.error?.message || "Unknown error"
1089
+ `Failed to get payments by parent ids: ${cursorRequest.error?.message || "Unknown error"
1089
1090
  }`,
1090
1091
  cursorRequest.error
1091
1092
  )
@@ -1129,8 +1130,7 @@ class IndexedDBStorage {
1129
1130
  putRequest.onerror = () => {
1130
1131
  reject(
1131
1132
  new StorageError(
1132
- `Failed to set payment metadata for '${paymentId}': ${
1133
- putRequest.error?.message || "Unknown error"
1133
+ `Failed to set payment metadata for '${paymentId}': ${putRequest.error?.message || "Unknown error"
1134
1134
  }`,
1135
1135
  putRequest.error
1136
1136
  )
@@ -1140,8 +1140,7 @@ class IndexedDBStorage {
1140
1140
  getRequest.onerror = () => {
1141
1141
  reject(
1142
1142
  new StorageError(
1143
- `Failed to get existing payment metadata for '${paymentId}': ${
1144
- getRequest.error?.message || "Unknown error"
1143
+ `Failed to get existing payment metadata for '${paymentId}': ${getRequest.error?.message || "Unknown error"
1145
1144
  }`,
1146
1145
  getRequest.error
1147
1146
  )
@@ -1178,8 +1177,7 @@ class IndexedDBStorage {
1178
1177
  request.onerror = () => {
1179
1178
  reject(
1180
1179
  new StorageError(
1181
- `Failed to add deposit '${txid}:${vout}': ${
1182
- request.error?.message || "Unknown error"
1180
+ `Failed to add deposit '${txid}:${vout}': ${request.error?.message || "Unknown error"
1183
1181
  }`,
1184
1182
  request.error
1185
1183
  )
@@ -1205,8 +1203,7 @@ class IndexedDBStorage {
1205
1203
  request.onerror = () => {
1206
1204
  reject(
1207
1205
  new StorageError(
1208
- `Failed to delete deposit '${txid}:${vout}': ${
1209
- request.error?.message || "Unknown error"
1206
+ `Failed to delete deposit '${txid}:${vout}': ${request.error?.message || "Unknown error"
1210
1207
  }`,
1211
1208
  request.error
1212
1209
  )
@@ -1240,8 +1237,7 @@ class IndexedDBStorage {
1240
1237
  request.onerror = () => {
1241
1238
  reject(
1242
1239
  new StorageError(
1243
- `Failed to list deposits: ${
1244
- request.error?.message || "Unknown error"
1240
+ `Failed to list deposits: ${request.error?.message || "Unknown error"
1245
1241
  }`,
1246
1242
  request.error
1247
1243
  )
@@ -1293,8 +1289,7 @@ class IndexedDBStorage {
1293
1289
  putRequest.onerror = () => {
1294
1290
  reject(
1295
1291
  new StorageError(
1296
- `Failed to update deposit '${txid}:${vout}': ${
1297
- putRequest.error?.message || "Unknown error"
1292
+ `Failed to update deposit '${txid}:${vout}': ${putRequest.error?.message || "Unknown error"
1298
1293
  }`,
1299
1294
  putRequest.error
1300
1295
  )
@@ -1305,8 +1300,7 @@ class IndexedDBStorage {
1305
1300
  getRequest.onerror = () => {
1306
1301
  reject(
1307
1302
  new StorageError(
1308
- `Failed to get deposit '${txid}:${vout}' for update: ${
1309
- getRequest.error?.message || "Unknown error"
1303
+ `Failed to get deposit '${txid}:${vout}' for update: ${getRequest.error?.message || "Unknown error"
1310
1304
  }`,
1311
1305
  getRequest.error
1312
1306
  )
@@ -1354,8 +1348,7 @@ class IndexedDBStorage {
1354
1348
  request.onerror = () => {
1355
1349
  reject(
1356
1350
  new StorageError(
1357
- `Failed to add lnurl metadata for payment hash '${
1358
- item.paymentHash
1351
+ `Failed to add lnurl metadata for payment hash '${item.paymentHash
1359
1352
  }': ${request.error?.message || "Unknown error"}`,
1360
1353
  request.error
1361
1354
  )
@@ -1841,6 +1834,144 @@ class IndexedDBStorage {
1841
1834
  });
1842
1835
  }
1843
1836
 
1837
+ // ===== Contact Operations =====
1838
+
1839
+ async listContacts(request) {
1840
+ if (!this.db) {
1841
+ throw new StorageError("Database not initialized");
1842
+ }
1843
+
1844
+ const actualOffset = request.offset !== null && request.offset !== undefined ? request.offset : 0;
1845
+ const actualLimit = request.limit !== null && request.limit !== undefined ? request.limit : 4294967295;
1846
+
1847
+ return new Promise((resolve, reject) => {
1848
+ const transaction = this.db.transaction("contacts", "readonly");
1849
+ const store = transaction.objectStore("contacts");
1850
+ const nameIndex = store.index("name");
1851
+
1852
+ const contacts = [];
1853
+ let count = 0;
1854
+ let skipped = 0;
1855
+
1856
+ const cursorRequest = nameIndex.openCursor();
1857
+
1858
+ cursorRequest.onsuccess = (event) => {
1859
+ const cursor = event.target.result;
1860
+
1861
+ if (!cursor || count >= actualLimit) {
1862
+ resolve(contacts);
1863
+ return;
1864
+ }
1865
+
1866
+ if (skipped < actualOffset) {
1867
+ skipped++;
1868
+ cursor.continue();
1869
+ return;
1870
+ }
1871
+
1872
+ contacts.push(cursor.value);
1873
+ count++;
1874
+ cursor.continue();
1875
+ };
1876
+
1877
+ cursorRequest.onerror = () => {
1878
+ reject(
1879
+ new StorageError(
1880
+ `Failed to list contacts: ${cursorRequest.error?.message || "Unknown error"}`,
1881
+ cursorRequest.error
1882
+ )
1883
+ );
1884
+ };
1885
+ });
1886
+ }
1887
+
1888
+ async getContact(id) {
1889
+ if (!this.db) {
1890
+ throw new StorageError("Database not initialized");
1891
+ }
1892
+
1893
+ return new Promise((resolve, reject) => {
1894
+ const transaction = this.db.transaction("contacts", "readonly");
1895
+ const store = transaction.objectStore("contacts");
1896
+ const request = store.get(id);
1897
+
1898
+ request.onsuccess = () => {
1899
+ resolve(request.result || null);
1900
+ };
1901
+
1902
+ request.onerror = () => {
1903
+ reject(
1904
+ new StorageError(
1905
+ `Failed to get contact '${id}': ${request.error?.message || "Unknown error"}`,
1906
+ request.error
1907
+ )
1908
+ );
1909
+ };
1910
+ });
1911
+ }
1912
+
1913
+ async insertContact(contact) {
1914
+ if (!this.db) {
1915
+ throw new StorageError("Database not initialized");
1916
+ }
1917
+
1918
+ return new Promise((resolve, reject) => {
1919
+ const transaction = this.db.transaction("contacts", "readwrite");
1920
+ const store = transaction.objectStore("contacts");
1921
+
1922
+ // Preserve created_at from existing record on update
1923
+ const getRequest = store.get(contact.id);
1924
+ getRequest.onsuccess = () => {
1925
+ const existingById = getRequest.result;
1926
+ const toStore = existingById
1927
+ ? { ...contact, createdAt: existingById.createdAt }
1928
+ : contact;
1929
+
1930
+ const putRequest = store.put(toStore);
1931
+ putRequest.onsuccess = () => resolve();
1932
+ putRequest.onerror = () => {
1933
+ reject(
1934
+ new StorageError(
1935
+ `Inserting contact failed: ${putRequest.error?.name || "Unknown error"} - ${putRequest.error?.message || ""}`,
1936
+ putRequest.error
1937
+ )
1938
+ );
1939
+ };
1940
+ };
1941
+ getRequest.onerror = () => {
1942
+ reject(
1943
+ new StorageError(
1944
+ `Failed to check existing contact: ${getRequest.error?.message || "Unknown error"}`,
1945
+ getRequest.error
1946
+ )
1947
+ );
1948
+ };
1949
+ });
1950
+ }
1951
+
1952
+ async deleteContact(id) {
1953
+ if (!this.db) {
1954
+ throw new StorageError("Database not initialized");
1955
+ }
1956
+
1957
+ return new Promise((resolve, reject) => {
1958
+ const transaction = this.db.transaction("contacts", "readwrite");
1959
+ const store = transaction.objectStore("contacts");
1960
+ const request = store.delete(id);
1961
+
1962
+ request.onsuccess = () => resolve();
1963
+
1964
+ request.onerror = () => {
1965
+ reject(
1966
+ new StorageError(
1967
+ `Failed to delete contact '${id}': ${request.error?.message || "Unknown error"}`,
1968
+ request.error
1969
+ )
1970
+ );
1971
+ };
1972
+ });
1973
+ }
1974
+
1844
1975
  // ===== Private Helper Methods =====
1845
1976
 
1846
1977
  _matchesFilters(payment, request) {