@breeztech/breez-sdk-spark 0.18.0 → 0.19.2

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.
@@ -39,16 +39,24 @@ type ReserveResult =
39
39
  | { type: 'insufficientFunds' }
40
40
  | { type: 'waitForPending'; needed: number; available: number; pending: number };
41
41
 
42
+ type LeafSelection =
43
+ | { type: 'exact'; leaves: TreeNode[] }
44
+ | { type: 'swapNeeded'; leaves: TreeNode[] }
45
+ | { type: 'insufficientFunds' };
46
+
42
47
  export interface TreeStore {
43
48
  addLeaves: (leaves: TreeNode[]) => Promise<void>;
44
49
  getLeaves: () => Promise<Leaves>;
45
50
  getAvailableBalance: () => Promise<bigint>;
51
+ getVerifiedLeafKeys: () => Promise<[string, string, string][]>;
46
52
  setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
47
53
  cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
48
54
  finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
49
55
  tryReserveLeaves: (targetAmounts: TargetAmounts | null, exactOnly: boolean, purpose: string) => Promise<ReserveResult>;
50
56
  now: () => Promise<number>;
51
57
  updateReservation: (reservationId: string, reservedLeaves: TreeNode[], changeLeaves: TreeNode[]) => Promise<LeavesReservation>;
58
+ tryReserveLeavesByIds: (leafIds: string[], purpose: string) => Promise<LeavesReservation>;
59
+ trySelectLeaves: (targetAmounts: TargetAmounts | null) => Promise<LeafSelection>;
52
60
  }
53
61
 
54
62
 
@@ -123,6 +131,17 @@ export interface TokenStore {
123
131
  preferredOutputs: WasmTokenOutputWithPrevOut[] | null,
124
132
  selectionStrategy: string | null
125
133
  ) => Promise<WasmTokenOutputsReservation>;
134
+ selectTokenOutputs: (
135
+ tokenIdentifier: string,
136
+ target: WasmReservationTarget,
137
+ preferredOutputs: WasmTokenOutputWithPrevOut[] | null,
138
+ selectionStrategy: string | null
139
+ ) => Promise<WasmTokenOutputs>;
140
+ reserveTokenOutputsByOutpoints: (
141
+ tokenIdentifier: string,
142
+ outpoints: { prevTxHash: string; prevTxVout: number }[],
143
+ purpose: string
144
+ ) => Promise<WasmTokenOutputsReservation>;
126
145
  cancelReservation: (id: string) => Promise<void>;
127
146
  finalizeReservation: (id: string) => Promise<void>;
128
147
  now: () => Promise<number>;
@@ -288,6 +307,14 @@ export interface PrfProvider {
288
307
  * device. Hosts gate UX on the result.
289
308
  */
290
309
  isSupported(): Promise<boolean>;
310
+
311
+ /**
312
+ * Optional. Whether the silent single-CTA flow works here (a
313
+ * no-credential sign-in fast-fails with no UI). Omit to be treated as
314
+ * unsupported (`false`); the built-in browser provider returns the
315
+ * WebAuthn immediate-mediation capability.
316
+ */
317
+ supportsImmediateMediation?(): Promise<boolean>;
291
318
  }
292
319
 
293
320
  /**
@@ -303,7 +330,9 @@ export interface DeriveSeedOptions {
303
330
  allowCredentials?: Uint8Array[];
304
331
  /**
305
332
  * Fast-fail when no local credential is available. On the web this maps
306
- * to WebAuthn `mediation: 'immediate'`: `true` opts in where the browser
333
+ * to WebAuthn `uiMode: 'immediate'`, used only on the unpinned probe (a
334
+ * non-empty allowCredentials keeps the standard picker, since a pin means
335
+ * a credential is already known): `true` opts in where the browser
307
336
  * advertises support, `false` uses the standard picker. Unset uses the
308
337
  * provider default.
309
338
  */
@@ -353,6 +382,15 @@ export interface PasskeyProviderOptions {
353
382
  userDisplayName?: string;
354
383
  }
355
384
 
385
+ /**
386
+ * Request shape for `PasskeyClient.connectWithPasskey`.
387
+ */
388
+ export interface ConnectWithPasskeyRequest {
389
+ label?: string;
390
+ allowCredentials?: Uint8Array[];
391
+ excludeCredentials?: Uint8Array[];
392
+ }
393
+
356
394
  /**
357
395
  * Request shape for `PasskeyClient.register`.
358
396
  */
@@ -370,6 +408,15 @@ export interface SignInRequest {
370
408
  preferImmediatelyAvailableCredentials?: boolean;
371
409
  }
372
410
 
411
+ /**
412
+ * Response shape for `PasskeyClient.connectWithPasskey`.
413
+ */
414
+ export interface ConnectWithPasskeyResponse {
415
+ wallet: Wallet;
416
+ credential?: PasskeyCredential;
417
+ labels: string[];
418
+ }
419
+
373
420
  /**
374
421
  * Response shape for `PasskeyClient.register`.
375
422
  */
@@ -536,6 +583,15 @@ export interface Bolt12OfferDetails {
536
583
  signingPubkey?: string;
537
584
  }
538
585
 
586
+ export interface BuildUnsignedLnurlPayPackageRequest {
587
+ prepareResponse: PrepareLnurlPayResponse;
588
+ }
589
+
590
+ export interface BuildUnsignedTransferPackageRequest {
591
+ prepareResponse: PrepareSendPaymentResponse;
592
+ options?: BuildTransferPackageOptions;
593
+ }
594
+
539
595
  export interface BurnIssuerTokenRequest {
540
596
  amount: bigint;
541
597
  }
@@ -1078,6 +1134,12 @@ export interface LnurlInfo {
1078
1134
  bech32: string;
1079
1135
  }
1080
1136
 
1137
+ export interface LnurlPayContext {
1138
+ payRequest: LnurlPayRequestDetails;
1139
+ comment?: string;
1140
+ successAction?: SuccessAction;
1141
+ }
1142
+
1081
1143
  export interface LnurlPayInfo {
1082
1144
  lnAddress?: string;
1083
1145
  comment?: string;
@@ -1267,6 +1329,14 @@ export interface PublicKeyBytes {
1267
1329
  bytes: number[];
1268
1330
  }
1269
1331
 
1332
+ export interface PublishSignedLnurlPayPackageRequest {
1333
+ signedPackage: SignedTransferPackage;
1334
+ }
1335
+
1336
+ export interface PublishSignedTransferPackageRequest {
1337
+ signedPackage: SignedTransferPackage;
1338
+ }
1339
+
1270
1340
  export interface Rate {
1271
1341
  coin: string;
1272
1342
  value: number;
@@ -1408,6 +1478,11 @@ export interface SignMessageResponse {
1408
1478
  signature: string;
1409
1479
  }
1410
1480
 
1481
+ export interface SignedTransferPackage {
1482
+ unsigned: UnsignedTransferPackage;
1483
+ signature: TransferSignature;
1484
+ }
1485
+
1411
1486
  export interface SilentPaymentAddressDetails {
1412
1487
  address: string;
1413
1488
  network: BitcoinNetwork;
@@ -1428,6 +1503,7 @@ export interface SparkConfig {
1428
1503
  sspConfig: SparkSspConfig;
1429
1504
  expectedWithdrawBondSats: number;
1430
1505
  expectedWithdrawRelativeBlockLocktime: number;
1506
+ maxTokenTransactionInputs?: number;
1431
1507
  }
1432
1508
 
1433
1509
  export interface SparkHtlcDetails {
@@ -1597,7 +1673,9 @@ export interface TurnkeyConfig {
1597
1673
  walletId: string;
1598
1674
  network: Network;
1599
1675
  accountNumber?: number;
1676
+ identityPublicKey?: string;
1600
1677
  retry?: TurnkeyRetryConfig;
1678
+ maxRps?: number;
1601
1679
  }
1602
1680
 
1603
1681
  export interface TurnkeyRetryConfig {
@@ -1680,6 +1758,8 @@ export type AutoOptimizationEvent = { type: "started"; totalRounds: number } | {
1680
1758
 
1681
1759
  export type BitcoinNetwork = "bitcoin" | "testnet3" | "testnet4" | "signet" | "regtest";
1682
1760
 
1761
+ export type BuildTransferPackageOptions = { type: "bitcoinAddress"; confirmationSpeed: OnchainConfirmationSpeed } | { type: "bolt11Invoice"; preferSpark: boolean; completionTimeoutSecs?: number };
1762
+
1683
1763
  export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats: number };
1684
1764
 
1685
1765
  export type ChainApiType = "esplora" | "mempoolSpace";
@@ -1748,6 +1828,10 @@ export type PaymentType = "send" | "receive";
1748
1828
 
1749
1829
  export type ProvisionalPaymentDetails = { type: "bitcoin"; withdrawalAddress: string } | { type: "lightning"; invoice: string } | { type: "spark"; payRequest: string } | { type: "token"; tokenId: string; payRequest: string };
1750
1830
 
1831
+ export type PublishSignedLnurlPayResponse = { type: "swapCompleted" } | { type: "paymentSent"; response: LnurlPayResponse };
1832
+
1833
+ export type PublishSignedTransferPackageResponse = { type: "swapCompleted" } | { type: "paymentSent"; payment: Payment };
1834
+
1751
1835
  export type ReceivePaymentMethod = { type: "sparkAddress" } | { type: "sparkInvoice"; amount?: string; tokenIdentifier?: string; expiryTime?: number; description?: string; senderPublicKey?: string } | { type: "bitcoinAddress"; newAddress?: boolean } | { type: "bolt11Invoice"; description: string; amountSats?: number; expirySecs?: number; paymentHash?: string };
1752
1836
 
1753
1837
  export type SdkEvent = { type: "synced" } | { type: "unclaimedDeposits"; unclaimedDeposits: DepositInfo[] } | { type: "claimedDeposits"; claimedDeposits: DepositInfo[] } | { type: "paymentSucceeded"; payment: Payment } | { type: "paymentPending"; payment: Payment } | { type: "paymentFailed"; payment: Payment } | { type: "autoOptimization"; optimizationEvent: AutoOptimizationEvent } | { type: "lightningAddressChanged"; lightningAddress?: LightningAddressInfo } | { type: "newDeposits"; newDeposits: DepositInfo[] };
@@ -1776,6 +1860,12 @@ export type SuccessActionProcessed = { type: "aes"; result: AesSuccessActionData
1776
1860
 
1777
1861
  export type TokenTransactionType = "transfer" | "mint" | "burn";
1778
1862
 
1863
+ export type TransferSignature = { type: "transfer"; signed: ExternalPreparedTransfer } | { type: "token"; signed: ExternalPreparedTokenTransaction };
1864
+
1865
+ export type TransferTarget = { type: "spark"; address: string; sparkInvoice?: string } | { type: "lightning"; bolt11: string; lnurlPay?: LnurlPayContext; feePolicy: FeePolicy; completionTimeoutSecs?: number } | { type: "coopExit"; address: string; feeQuote: SendOnchainFeeQuote; confirmationSpeed: OnchainConfirmationSpeed };
1866
+
1867
+ export type UnsignedTransferPackage = { type: "swap"; prepareTransfer: ExternalPrepareTransferRequest; targetAmounts: number[]; amountSat: number; feeSat: number } | { type: "transfer"; prepareTransfer: ExternalPrepareTransferRequest; amountSat: number; feeSat: number; target: TransferTarget } | { type: "token"; prepareTokenTransaction: ExternalPrepareTokenTransactionRequest; tokenContext: number[]; tokenIdentifier: string; amount: string; fee: string; isSwap: boolean };
1868
+
1779
1869
  export type UpdateDepositPayload = { type: "claimError"; error: DepositClaimError } | { type: "refund"; refundTxid: string; refundTx: string };
1780
1870
 
1781
1871
  export type WebhookEventType = { type: "lightningReceiveFinished" } | { type: "lightningSendFinished" } | { type: "coopExitFinished" } | { type: "staticDepositFinished" } | ({ type: "unknown" } & string);
@@ -1807,6 +1897,8 @@ export class BreezSdk {
1807
1897
  addContact(request: AddContactRequest): Promise<Contact>;
1808
1898
  addEventListener(listener: EventListener): Promise<string>;
1809
1899
  authorizeLightningAddressTransfer(request: AuthorizeTransferRequest): Promise<TransferAuthorization>;
1900
+ buildUnsignedLnurlPayPackage(request: BuildUnsignedLnurlPayPackageRequest): Promise<UnsignedTransferPackage>;
1901
+ buildUnsignedTransferPackage(request: BuildUnsignedTransferPackageRequest): Promise<UnsignedTransferPackage>;
1810
1902
  buyBitcoin(request: BuyBitcoinRequest): Promise<BuyBitcoinResponse>;
1811
1903
  checkLightningAddressAvailable(request: CheckLightningAddressRequest): Promise<boolean>;
1812
1904
  checkMessage(request: CheckMessageRequest): Promise<CheckMessageResponse>;
@@ -1837,6 +1929,8 @@ export class BreezSdk {
1837
1929
  parse(input: string): Promise<InputType>;
1838
1930
  prepareLnurlPay(request: PrepareLnurlPayRequest): Promise<PrepareLnurlPayResponse>;
1839
1931
  prepareSendPayment(request: PrepareSendPaymentRequest): Promise<PrepareSendPaymentResponse>;
1932
+ publishSignedLnurlPayPackage(request: PublishSignedLnurlPayPackageRequest): Promise<PublishSignedLnurlPayResponse>;
1933
+ publishSignedTransferPackage(request: PublishSignedTransferPackageRequest): Promise<PublishSignedTransferPackageResponse>;
1840
1934
  receivePayment(request: ReceivePaymentRequest): Promise<ReceivePaymentResponse>;
1841
1935
  recommendedFees(): Promise<RecommendedFees>;
1842
1936
  refundDeposit(request: RefundDepositRequest): Promise<RefundDepositResponse>;
@@ -1852,6 +1946,21 @@ export class BreezSdk {
1852
1946
  updateUserSettings(request: UpdateUserSettingsRequest): Promise<void>;
1853
1947
  }
1854
1948
 
1949
+ /**
1950
+ * A JS handle to a backend's own session store (from `defaultSessionStore`),
1951
+ * exposing the same `getSession` / `setSession` interface. Wrap it in a JS
1952
+ * `SessionStore` decorator and pass that to `SdkBuilder.withSessionStore` to
1953
+ * transform tokens while keeping the backend's persistence: for example
1954
+ * at-rest encryption, which the SDK does not apply itself.
1955
+ */
1956
+ export class DefaultSessionStore {
1957
+ private constructor();
1958
+ free(): void;
1959
+ [Symbol.dispose](): void;
1960
+ getSession(service_identity_key: string): Promise<Session>;
1961
+ setSession(service_identity_key: string, session: Session): Promise<void>;
1962
+ }
1963
+
1855
1964
  /**
1856
1965
  * A Rust-backed [`ExternalBreezSigner`] surfaced to JS as a signer object that
1857
1966
  * can be passed to `connectWithSigner` or `SdkBuilder.newWithSigner`. Produced
@@ -1979,6 +2088,18 @@ export class PasskeyClient {
1979
2088
  * hosts can gate UX on.
1980
2089
  */
1981
2090
  checkAvailability(): Promise<PasskeyAvailability>;
2091
+ /**
2092
+ * Single-CTA onboarding: silent sign-in that falls through to
2093
+ * registration when no credential exists on the device. Pins
2094
+ * immediate mediation, so on web only use it where the browser
2095
+ * advertises it (`supportsImmediateMediation`); otherwise the silent
2096
+ * probe degrades to the standard picker and a dismiss does not fall
2097
+ * through to register, so
2098
+ * present an explicit create / sign-in choice instead. Called without
2099
+ * a `label`, the response `labels` lists a returning user's wallets
2100
+ * for a picker.
2101
+ */
2102
+ connectWithPasskey(request: ConnectWithPasskeyRequest): Promise<ConnectWithPasskeyResponse>;
1982
2103
  /**
1983
2104
  * Label sub-object. List / publish labels for this passkey's identity.
1984
2105
  */
@@ -2003,6 +2124,14 @@ export class PasskeyClient {
2003
2124
  * label set in the same ceremony.
2004
2125
  */
2005
2126
  signIn(request: SignInRequest): Promise<SignInResponse>;
2127
+ /**
2128
+ * Whether this browser advertises WebAuthn immediate mediation: the
2129
+ * silent single-CTA probe (a no-credential sign-in fast-fails with no
2130
+ * UI) works here, so a web host can pick single- vs two-button
2131
+ * onboarding. Web-only and WASM-only: native does the silent probe
2132
+ * inherently, so there is nothing to query off-web.
2133
+ */
2134
+ supportsImmediateMediation(): Promise<boolean>;
2006
2135
  }
2007
2136
 
2008
2137
  /**
@@ -2051,6 +2180,13 @@ export class SdkBuilder {
2051
2180
  */
2052
2181
  withPostgresBackend(config: PostgresStorageConfig): SdkBuilder;
2053
2182
  withRestChainService(url: string, api_type: ChainApiType, credentials?: Credentials | null): SdkBuilder;
2183
+ /**
2184
+ * Overrides the session store used to cache auth tokens, replacing the one
2185
+ * the backend provides. Pass any `SessionStore`: for example one that wraps
2186
+ * the backend's own store from `defaultSessionStore` to add at-rest
2187
+ * encryption, which the SDK does not apply itself.
2188
+ */
2189
+ withSessionStore(session_store: SessionStore): SdkBuilder;
2054
2190
  /**
2055
2191
  * Threads a shared [`WasmSdkContext`] into the builder.
2056
2192
  *
@@ -2185,6 +2321,14 @@ export function defaultPostgresStorageConfig(connection_string: string): Postgre
2185
2321
 
2186
2322
  export function defaultServerConfig(network: Network): Config;
2187
2323
 
2324
+ /**
2325
+ * The session store the `config`'s backend provides for `identity` (the wallet
2326
+ * identity public key, hex), as a handle to wrap in a `SessionStore` decorator
2327
+ * and pass to `SdkBuilder.withSessionStore`, keeping the backend's persistence.
2328
+ * A typical use is at-rest encryption, which the SDK does not apply itself.
2329
+ */
2330
+ export function defaultSessionStore(config: WasmStorageConfig, network: Network, identity: string): Promise<DefaultSessionStore>;
2331
+
2188
2332
  /**
2189
2333
  * File-based storage rooted at `storageDir` — IndexedDB in the browser,
2190
2334
  * SQLite under Node.js.