@breeztech/breez-sdk-spark 0.14.0 → 0.15.1

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.
Files changed (37) hide show
  1. package/breez-sdk-spark.tgz +0 -0
  2. package/bundler/breez_sdk_spark_wasm.d.ts +114 -40
  3. package/bundler/breez_sdk_spark_wasm.js +1 -1
  4. package/bundler/breez_sdk_spark_wasm_bg.js +118 -104
  5. package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
  6. package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
  7. package/deno/breez_sdk_spark_wasm.d.ts +114 -40
  8. package/deno/breez_sdk_spark_wasm.js +118 -104
  9. package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
  10. package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
  11. package/nodejs/breez_sdk_spark_wasm.d.ts +114 -40
  12. package/nodejs/breez_sdk_spark_wasm.js +121 -106
  13. package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
  14. package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
  15. package/nodejs/index.mjs +3 -2
  16. package/nodejs/mysql-session-manager/index.cjs +26 -8
  17. package/nodejs/mysql-session-manager/migrations.cjs +40 -3
  18. package/nodejs/mysql-storage/index.cjs +67 -48
  19. package/nodejs/mysql-storage/migrations.cjs +220 -85
  20. package/nodejs/mysql-token-store/index.cjs +133 -68
  21. package/nodejs/mysql-token-store/migrations.cjs +309 -80
  22. package/nodejs/mysql-tree-store/index.cjs +76 -41
  23. package/nodejs/mysql-tree-store/migrations.cjs +254 -71
  24. package/nodejs/postgres-session-manager/index.cjs +27 -9
  25. package/nodejs/postgres-session-manager/migrations.cjs +45 -6
  26. package/nodejs/postgres-storage/index.cjs +81 -62
  27. package/nodejs/postgres-storage/migrations.cjs +207 -79
  28. package/nodejs/postgres-token-store/index.cjs +111 -67
  29. package/nodejs/postgres-token-store/migrations.cjs +153 -61
  30. package/nodejs/postgres-tree-store/index.cjs +60 -42
  31. package/nodejs/postgres-tree-store/migrations.cjs +130 -46
  32. package/package.json +1 -1
  33. package/ssr/index.js +14 -9
  34. package/web/breez_sdk_spark_wasm.d.ts +126 -51
  35. package/web/breez_sdk_spark_wasm.js +118 -104
  36. package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
  37. package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +12 -11
@@ -115,7 +115,7 @@ export interface TokenStore {
115
115
  listTokensOutputs: () => Promise<WasmTokenOutputsPerStatus[]>;
116
116
  getTokenBalances: () => Promise<WasmTokenBalance[]>;
117
117
  getTokenOutputs: (filter: WasmGetTokenOutputsFilter) => Promise<WasmTokenOutputsPerStatus>;
118
- insertTokenOutputs: (tokenOutputs: WasmTokenOutputs) => Promise<void>;
118
+ updateTokenOutputs: (outputsToRemove: [string, number][], outputsToAdd: WasmTokenOutputs | null) => Promise<void>;
119
119
  reserveTokenOutputs: (
120
120
  tokenIdentifier: string,
121
121
  target: WasmReservationTarget,
@@ -162,6 +162,20 @@ export interface MysqlStorageConfig {
162
162
  * Timeout in seconds before recycling an idle connection.
163
163
  */
164
164
  recycleTimeoutSecs: number;
165
+ /**
166
+ * Whether the SDK should run schema migrations on startup. Set to
167
+ * `false` when the embedding service owns and migrates the database
168
+ * schema. Defaults to `true`.
169
+ */
170
+ runMigration?: boolean;
171
+ /**
172
+ * Whether migrations should create database-enforced foreign keys.
173
+ *
174
+ * Use `Disabled` for environments that manage relationships in
175
+ * application code and require schema changes without foreign-key
176
+ * constraints.
177
+ */
178
+ foreignKeyMode?: MysqlForeignKeyMode;
165
179
  }
166
180
 
167
181
  /**
@@ -184,8 +198,19 @@ export interface PostgresStorageConfig {
184
198
  * Timeout in seconds before recycling an idle connection.
185
199
  */
186
200
  recycleTimeoutSecs: number;
201
+ /**
202
+ * Whether the SDK should run schema migrations on startup. Set to
203
+ * `false` when the embedding service owns and migrates the database
204
+ * schema. Defaults to `true`.
205
+ */
206
+ runMigration?: boolean;
187
207
  }
188
208
 
209
+ /**
210
+ * Controls whether MySQL migrations create database-enforced foreign keys.
211
+ */
212
+ export type MysqlForeignKeyMode = "Enforced" | "Disabled";
213
+
189
214
  /**
190
215
  * Interface for passkey PRF (Pseudo-Random Function) operations.
191
216
  *
@@ -255,6 +280,40 @@ export interface NostrRelayConfig {
255
280
  timeoutSecs?: number;
256
281
  }
257
282
 
283
+ /**
284
+ * Settings for `newSharedSdkContext`. `network` is required; all other
285
+ * fields are optional.
286
+ */
287
+ export interface WasmSdkContextConfig {
288
+ /**
289
+ * Network the shared resources target. Used to gate the partner JWT
290
+ * header provider — only constructed on Mainnet.
291
+ */
292
+ network: Network;
293
+ /**
294
+ * Breez API key. When set together with `network == Mainnet`, the
295
+ * context constructs a shared partner JWT header provider that all
296
+ * SDKs built from this context will attach to their SO requests.
297
+ */
298
+ apiKey?: string;
299
+ /**
300
+ * Number of gRPC connections per Spark operator. `None` (or `Some(1)`)
301
+ * keeps a single connection per operator (right for most deployments);
302
+ * `Some(n)` opens `n` channels per operator and balances requests.
303
+ */
304
+ connectionsPerOperator?: number;
305
+ /**
306
+ * PostgreSQL backend configuration. When set, SDKs constructed with
307
+ * this context store their data in PostgreSQL via the shared pool.
308
+ */
309
+ postgresConfig?: PostgresStorageConfig;
310
+ /**
311
+ * MySQL backend configuration. When set, SDKs constructed with this
312
+ * context store their data in MySQL via the shared pool.
313
+ */
314
+ mysqlConfig?: MysqlStorageConfig;
315
+ }
316
+
258
317
  export interface AddContactRequest {
259
318
  name: string;
260
319
  paymentIdentifier: string;
@@ -417,7 +476,8 @@ export interface Config {
417
476
  useDefaultExternalInputParsers: boolean;
418
477
  realTimeSyncServerUrl?: string;
419
478
  privateEnabledDefault: boolean;
420
- optimizationConfig: OptimizationConfig;
479
+ leafOptimizationConfig: LeafOptimizationConfig;
480
+ tokenOptimizationConfig: TokenOptimizationConfig;
421
481
  stableBalanceConfig?: StableBalanceConfig;
422
482
  /**
423
483
  * Maximum number of concurrent transfer claims.
@@ -428,6 +488,7 @@ export interface Config {
428
488
  */
429
489
  maxConcurrentClaims: number;
430
490
  sparkConfig?: SparkConfig;
491
+ backgroundTasksEnabled: boolean;
431
492
  }
432
493
 
433
494
  export interface ConnectRequest {
@@ -705,6 +766,11 @@ export interface KeySetConfig {
705
766
  accountNumber?: number;
706
767
  }
707
768
 
769
+ export interface LeafOptimizationConfig {
770
+ autoEnabled: boolean;
771
+ multiplicity: number;
772
+ }
773
+
708
774
  export interface LightningAddressDetails {
709
775
  address: string;
710
776
  payRequest: LnurlPayRequestDetails;
@@ -861,11 +927,6 @@ export interface MintIssuerTokenRequest {
861
927
  amount: bigint;
862
928
  }
863
929
 
864
- export interface OptimizationConfig {
865
- autoEnabled: boolean;
866
- multiplicity: number;
867
- }
868
-
869
930
  export interface OptimizationProgress {
870
931
  isRunning: boolean;
871
932
  currentRound: number;
@@ -1243,6 +1304,12 @@ export interface TokenMetadata {
1243
1304
  isFreezable: boolean;
1244
1305
  }
1245
1306
 
1307
+ export interface TokenOptimizationConfig {
1308
+ autoEnabled: boolean;
1309
+ targetOutputCount: number;
1310
+ minOutputsThreshold: number;
1311
+ }
1312
+
1246
1313
  export interface TxStatus {
1247
1314
  confirmed: boolean;
1248
1315
  blockHeight?: number;
@@ -1447,6 +1514,7 @@ export class BreezSdk {
1447
1514
  receivePayment(request: ReceivePaymentRequest): Promise<ReceivePaymentResponse>;
1448
1515
  recommendedFees(): Promise<RecommendedFees>;
1449
1516
  refundDeposit(request: RefundDepositRequest): Promise<RefundDepositResponse>;
1517
+ refundPendingConversions(): Promise<void>;
1450
1518
  registerLightningAddress(request: RegisterLightningAddressRequest): Promise<LightningAddressInfo>;
1451
1519
  registerWebhook(request: RegisterWebhookRequest): Promise<RegisterWebhookResponse>;
1452
1520
  removeEventListener(id: string): Promise<boolean>;
@@ -1518,7 +1586,8 @@ export class IntoUnderlyingSource {
1518
1586
  }
1519
1587
 
1520
1588
  /**
1521
- * A shareable MySQL connection pool. See [`PostgresConnectionPool`](super::postgres_pool::PostgresConnectionPool)
1589
+ * A shareable `MySQL` connection pool. See
1590
+ * [`PostgresConnectionPool`](super::postgres_pool::PostgresConnectionPool)
1522
1591
  * for sharing semantics and lifecycle.
1523
1592
  */
1524
1593
  export class MysqlConnectionPool {
@@ -1599,56 +1668,42 @@ export class SdkBuilder {
1599
1668
  withKeySet(config: KeySetConfig): SdkBuilder;
1600
1669
  withLnurlClient(lnurl_client: RestClient): SdkBuilder;
1601
1670
  /**
1602
- * **Deprecated.** Call `withMysqlConnectionPool(config)` and `withMysqlConnectionPool(pool)` instead.
1671
+ * **Deprecated.** Call `createMysqlConnectionPool(config)` and
1672
+ * `withMysqlConnectionPool(pool)` instead.
1603
1673
  */
1604
1674
  withMysqlBackend(config: MysqlStorageConfig): SdkBuilder;
1605
1675
  /**
1606
1676
  * Sets a shared `MySQL` connection pool as the backend for all stores.
1607
- * Construct via `createMysqlConnectionPool` and pass the same handle to multiple
1608
- * `SdkBuilder`s to share connections across SDKs.
1677
+ *
1678
+ * If the same builder also receives a `WasmSdkContext` carrying a MySQL
1679
+ * pool, `build()` returns an error — pick one source.
1609
1680
  */
1610
1681
  withMysqlConnectionPool(pool: MysqlConnectionPool): SdkBuilder;
1611
1682
  withPaymentObserver(payment_observer: PaymentObserver): SdkBuilder;
1612
1683
  /**
1613
- * **Deprecated.** Call `withPostgresConnectionPool(config)` and `withPostgresConnectionPool(pool)` instead.
1684
+ * **Deprecated.** Call `createPostgresConnectionPool(config)` and
1685
+ * `withPostgresConnectionPool(pool)` instead.
1614
1686
  */
1615
1687
  withPostgresBackend(config: PostgresStorageConfig): SdkBuilder;
1616
1688
  /**
1617
- * Sets a shared `PostgreSQL` connection pool as the backend for all
1618
- * stores. Construct via `createPostgresConnectionPool` and pass the same handle
1619
- * to multiple `SdkBuilder`s to share connections across SDKs.
1689
+ * Sets a shared Postgres connection pool as the backend for all stores.
1690
+ *
1691
+ * If the same builder also receives a `WasmSdkContext` carrying a
1692
+ * Postgres pool, `build()` returns an error — pick one source.
1620
1693
  */
1621
1694
  withPostgresConnectionPool(pool: PostgresConnectionPool): SdkBuilder;
1622
1695
  withRestChainService(url: string, api_type: ChainApiType, credentials?: Credentials | null): SdkBuilder;
1623
1696
  /**
1624
- * Sets a custom session manager used to persist authentication sessions.
1697
+ * Threads a shared [`WasmSdkContext`] into the builder.
1625
1698
  *
1626
- * Provide a shared, persistent implementation (e.g. backed by `PostgreSQL`
1627
- * or Redis) to let multiple SDK instances share authentication state and
1628
- * bootstrap quickly. If not set, an in-memory session manager is used.
1629
- */
1630
- withSessionManager(session_manager: SessionManager): SdkBuilder;
1631
- /**
1632
- * Reuses a shared SSP connection across SDK instances. Pass the same
1633
- * manager to every `SdkBuilder` whose SSP traffic should share an
1634
- * underlying HTTP client.
1699
+ * Construct the context once via `newSharedSdkContext` and pass the same
1700
+ * handle to every `SdkBuilder` whose SDKs should share its resources
1701
+ * (operator gRPC channels, SSP HTTP client, database pool).
1635
1702
  */
1636
- withSspConnectionManager(manager: SspConnectionManager): SdkBuilder;
1703
+ withSharedContext(context: WasmSdkContext): SdkBuilder;
1637
1704
  withStorage(storage: Storage): SdkBuilder;
1638
1705
  }
1639
1706
 
1640
- /**
1641
- * Shared transport for SSP GraphQL traffic across SDK instances.
1642
- *
1643
- * All SDK instances built with the same `SspConnectionManager` share a single
1644
- * underlying HTTP client (and its h2 connection pool) for SSP requests.
1645
- */
1646
- export class SspConnectionManager {
1647
- private constructor();
1648
- free(): void;
1649
- [Symbol.dispose](): void;
1650
- }
1651
-
1652
1707
  export class TokenIssuer {
1653
1708
  private constructor();
1654
1709
  free(): void;
@@ -1662,12 +1717,25 @@ export class TokenIssuer {
1662
1717
  unfreezeIssuerToken(request: UnfreezeIssuerTokenRequest): Promise<UnfreezeIssuerTokenResponse>;
1663
1718
  }
1664
1719
 
1720
+ /**
1721
+ * Process-shared resources backing one or more `BreezSdk` instances on WASM.
1722
+ *
1723
+ * Construct once via `newSharedSdkContext` and pass the handle to every
1724
+ * `SdkBuilder` whose SDKs should share its operator gRPC channels, SSP HTTP
1725
+ * client, and (optionally) database connection pool.
1726
+ */
1727
+ export class WasmSdkContext {
1728
+ private constructor();
1729
+ free(): void;
1730
+ [Symbol.dispose](): void;
1731
+ }
1732
+
1665
1733
  export function connect(request: ConnectRequest): Promise<BreezSdk>;
1666
1734
 
1667
1735
  export function connectWithSigner(config: Config, signer: ExternalSigner, storage_dir: string): Promise<BreezSdk>;
1668
1736
 
1669
1737
  /**
1670
- * Creates a shareable MySQL connection pool from the given config.
1738
+ * Creates a shareable `MySQL` connection pool from the given config.
1671
1739
  */
1672
1740
  export function createMysqlConnectionPool(config: MysqlStorageConfig): MysqlConnectionPool;
1673
1741
 
@@ -1687,6 +1755,7 @@ export function defaultExternalSigner(mnemonic: string, passphrase: string | nul
1687
1755
  * - `maxPoolSize`: 10
1688
1756
  * - `createTimeoutSecs`: 0 (no timeout)
1689
1757
  * - `recycleTimeoutSecs`: 10
1758
+ * - `foreignKeyMode`: `Enforced`
1690
1759
  */
1691
1760
  export function defaultMysqlStorageConfig(connection_string: string): MysqlStorageConfig;
1692
1761
 
@@ -1700,6 +1769,8 @@ export function defaultMysqlStorageConfig(connection_string: string): MysqlStora
1700
1769
  */
1701
1770
  export function defaultPostgresStorageConfig(connection_string: string): PostgresStorageConfig;
1702
1771
 
1772
+ export function defaultServerConfig(network: Network): Config;
1773
+
1703
1774
  /**
1704
1775
  * Creates a default external signer from a mnemonic phrase.
1705
1776
  *
@@ -1720,7 +1791,10 @@ export function initLogging(logger: Logger, filter?: string | null): Promise<voi
1720
1791
  */
1721
1792
  export function newRestChainService(url: string, network: Network, api_type: ChainApiType, credentials?: Credentials | null): Promise<BitcoinChainService>;
1722
1793
 
1723
- export function newSspConnectionManager(user_agent?: string | null): SspConnectionManager;
1794
+ /**
1795
+ * Constructs a [`WasmSdkContext`] from a `WasmSdkContextConfig`.
1796
+ */
1797
+ export function newSharedSdkContext(config: WasmSdkContextConfig): Promise<WasmSdkContext>;
1724
1798
 
1725
1799
  /**
1726
1800
  * Entry point invoked by JavaScript in a worker.
@@ -1736,9 +1810,10 @@ export interface InitOutput {
1736
1810
  readonly __wbg_defaultsigner_free: (a: number, b: number) => void;
1737
1811
  readonly __wbg_mysqlconnectionpool_free: (a: number, b: number) => void;
1738
1812
  readonly __wbg_passkey_free: (a: number, b: number) => void;
1813
+ readonly __wbg_postgresconnectionpool_free: (a: number, b: number) => void;
1739
1814
  readonly __wbg_sdkbuilder_free: (a: number, b: number) => void;
1740
- readonly __wbg_sspconnectionmanager_free: (a: number, b: number) => void;
1741
1815
  readonly __wbg_tokenissuer_free: (a: number, b: number) => void;
1816
+ readonly __wbg_wasmsdkcontext_free: (a: number, b: number) => void;
1742
1817
  readonly bitcoinchainservicehandle_broadcastTransaction: (a: number, b: number, c: number) => any;
1743
1818
  readonly bitcoinchainservicehandle_getAddressUtxos: (a: number, b: number, c: number) => any;
1744
1819
  readonly bitcoinchainservicehandle_getTransactionHex: (a: number, b: number, c: number) => any;
@@ -1778,6 +1853,7 @@ export interface InitOutput {
1778
1853
  readonly breezsdk_receivePayment: (a: number, b: any) => any;
1779
1854
  readonly breezsdk_recommendedFees: (a: number) => any;
1780
1855
  readonly breezsdk_refundDeposit: (a: number, b: any) => any;
1856
+ readonly breezsdk_refundPendingConversions: (a: number) => any;
1781
1857
  readonly breezsdk_registerLightningAddress: (a: number, b: any) => any;
1782
1858
  readonly breezsdk_registerWebhook: (a: number, b: any) => any;
1783
1859
  readonly breezsdk_removeEventListener: (a: number, b: number, c: number) => any;
@@ -1795,6 +1871,8 @@ export interface InitOutput {
1795
1871
  readonly defaultConfig: (a: any) => any;
1796
1872
  readonly defaultExternalSigner: (a: number, b: number, c: number, d: number, e: any, f: number) => [number, number, number];
1797
1873
  readonly defaultMysqlStorageConfig: (a: number, b: number) => any;
1874
+ readonly defaultPostgresStorageConfig: (a: number, b: number) => any;
1875
+ readonly defaultServerConfig: (a: any) => any;
1798
1876
  readonly defaultsigner_aggregateFrost: (a: number, b: any) => any;
1799
1877
  readonly defaultsigner_decryptEcies: (a: number, b: number, c: number, d: number, e: number) => any;
1800
1878
  readonly defaultsigner_derivePublicKey: (a: number, b: number, c: number) => any;
@@ -1818,7 +1896,7 @@ export interface InitOutput {
1818
1896
  readonly getSparkStatus: () => any;
1819
1897
  readonly initLogging: (a: any, b: number, c: number) => any;
1820
1898
  readonly newRestChainService: (a: number, b: number, c: any, d: any, e: number) => any;
1821
- readonly newSspConnectionManager: (a: number, b: number) => number;
1899
+ readonly newSharedSdkContext: (a: any) => any;
1822
1900
  readonly passkey_getWallet: (a: number, b: number, c: number) => any;
1823
1901
  readonly passkey_isAvailable: (a: number) => any;
1824
1902
  readonly passkey_listLabels: (a: number) => any;
@@ -1838,8 +1916,7 @@ export interface InitOutput {
1838
1916
  readonly sdkbuilder_withPostgresBackend: (a: number, b: any) => [number, number, number];
1839
1917
  readonly sdkbuilder_withPostgresConnectionPool: (a: number, b: number) => number;
1840
1918
  readonly sdkbuilder_withRestChainService: (a: number, b: number, c: number, d: any, e: number) => number;
1841
- readonly sdkbuilder_withSessionManager: (a: number, b: any) => number;
1842
- readonly sdkbuilder_withSspConnectionManager: (a: number, b: number) => number;
1919
+ readonly sdkbuilder_withSharedContext: (a: number, b: number) => number;
1843
1920
  readonly sdkbuilder_withStorage: (a: number, b: any) => number;
1844
1921
  readonly tokenissuer_burnIssuerToken: (a: number, b: any) => any;
1845
1922
  readonly tokenissuer_createIssuerToken: (a: number, b: any) => any;
@@ -1866,13 +1943,11 @@ export interface InitOutput {
1866
1943
  readonly intounderlyingsink_write: (a: number, b: any) => any;
1867
1944
  readonly intounderlyingsource_cancel: (a: number) => void;
1868
1945
  readonly intounderlyingsource_pull: (a: number, b: any) => any;
1869
- readonly __wbg_postgresconnectionpool_free: (a: number, b: number) => void;
1870
- readonly defaultPostgresStorageConfig: (a: number, b: number) => any;
1871
- readonly wasm_bindgen__convert__closures_____invoke__h459c42c6ffe5f52c: (a: number, b: number, c: any) => [number, number];
1872
- readonly wasm_bindgen__convert__closures_____invoke__h459c42c6ffe5f52c_4: (a: number, b: number, c: any) => [number, number];
1873
- readonly wasm_bindgen__convert__closures_____invoke__h459c42c6ffe5f52c_5: (a: number, b: number, c: any) => [number, number];
1874
- readonly wasm_bindgen__convert__closures_____invoke__h459c42c6ffe5f52c_6: (a: number, b: number, c: any) => [number, number];
1875
- readonly wasm_bindgen__convert__closures_____invoke__h459c42c6ffe5f52c_7: (a: number, b: number, c: any) => [number, number];
1946
+ readonly wasm_bindgen__convert__closures_____invoke__h013a98c02f3b4b21: (a: number, b: number, c: any) => [number, number];
1947
+ readonly wasm_bindgen__convert__closures_____invoke__h013a98c02f3b4b21_4: (a: number, b: number, c: any) => [number, number];
1948
+ readonly wasm_bindgen__convert__closures_____invoke__h013a98c02f3b4b21_5: (a: number, b: number, c: any) => [number, number];
1949
+ readonly wasm_bindgen__convert__closures_____invoke__h013a98c02f3b4b21_6: (a: number, b: number, c: any) => [number, number];
1950
+ readonly wasm_bindgen__convert__closures_____invoke__h013a98c02f3b4b21_7: (a: number, b: number, c: any) => [number, number];
1876
1951
  readonly wasm_bindgen__convert__closures_____invoke__h41057d61edf43a32: (a: number, b: number, c: any, d: any) => void;
1877
1952
  readonly wasm_bindgen__convert__closures_____invoke__h4819aba3eed2db57: (a: number, b: number, c: any) => void;
1878
1953
  readonly wasm_bindgen__convert__closures_____invoke__h4819aba3eed2db57_2: (a: number, b: number, c: any) => void;