@tuwaio/payments-sdk 0.0.0 → 0.0.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 (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +75 -1
  3. package/dist/OwnConnection-ET76SUMX-4JFMOO7Z.cjs +1 -0
  4. package/dist/OwnConnection-ET76SUMX-G7ZHJN57.js +1 -0
  5. package/dist/checkout-C05-kSiE.d.cts +1616 -0
  6. package/dist/checkout-C05-kSiE.d.ts +1616 -0
  7. package/dist/checkout.cjs +1 -0
  8. package/dist/checkout.d.cts +2 -0
  9. package/dist/checkout.d.ts +2 -0
  10. package/dist/checkout.js +1 -0
  11. package/dist/chunk-LB2KDA4M.js +2 -0
  12. package/dist/chunk-MJOZIUWN.cjs +1 -0
  13. package/dist/chunk-NQ26UU24.cjs +1 -0
  14. package/dist/chunk-TN5VGRRA.cjs +2 -0
  15. package/dist/chunk-UJ2TJGKY.js +1 -0
  16. package/dist/chunk-VTOKR3DS.js +1 -0
  17. package/dist/de-53SSE6O2-GWJEBBVJ.js +1 -0
  18. package/dist/de-53SSE6O2-SX2QT2XZ.cjs +1 -0
  19. package/dist/es-LP3HJ4KB-7RFRVGPQ.cjs +1 -0
  20. package/dist/es-LP3HJ4KB-JN7LQABB.js +1 -0
  21. package/dist/evm.cjs +1 -0
  22. package/dist/evm.d.cts +34 -0
  23. package/dist/evm.d.ts +34 -0
  24. package/dist/evm.js +1 -0
  25. package/dist/i18n.cjs +1 -0
  26. package/dist/i18n.d.cts +10 -0
  27. package/dist/i18n.d.ts +10 -0
  28. package/dist/i18n.js +1 -0
  29. package/dist/index.cjs +2 -0
  30. package/dist/index.d.cts +2979 -0
  31. package/dist/index.d.ts +2979 -0
  32. package/dist/index.js +2 -0
  33. package/dist/it-JJ5Z5EUF-2BNC5I2D.cjs +1 -0
  34. package/dist/it-JJ5Z5EUF-HOA77BWJ.js +1 -0
  35. package/dist/locales-DzMinYsr.d-DzMinYsr.d.cts +1221 -0
  36. package/dist/locales-DzMinYsr.d-DzMinYsr.d.ts +1221 -0
  37. package/dist/solana.cjs +1 -0
  38. package/dist/solana.d.cts +42 -0
  39. package/dist/solana.d.ts +42 -0
  40. package/dist/solana.js +1 -0
  41. package/dist/styles.css +1324 -0
  42. package/dist/types-Bp6JUt56.d-ByIsb1F7.d.cts +350 -0
  43. package/dist/types-Bp6JUt56.d-C5vQkYhR.d.ts +350 -0
  44. package/dist/uk-EI4N5BMM-5PL2AYKV.js +1 -0
  45. package/dist/uk-EI4N5BMM-UN76BFNO.cjs +1 -0
  46. package/dist/zhCN-BZBMKUUA-E7M3WG4Q.js +1 -0
  47. package/dist/zhCN-BZBMKUUA-VSNNE3YC.cjs +1 -0
  48. package/package.json +129 -6
  49. package/socket.json +17 -0
@@ -0,0 +1,350 @@
1
+ import { Transaction } from '@tuwaio/sdk/pulsar';
2
+ import { P as PaymentInstructions, T as TransferAuthorizationTypedData, m as PermissionRequest, G as GrantPermissionParams, f as CheckoutMethod } from './checkout-C05-kSiE.cjs';
3
+
4
+ /**
5
+ * @file The connected wallet and the payment methods as the method step needs them: CAIP identifiers, the payer of a
6
+ * method, QR payments, discounts and markups.
7
+ */
8
+
9
+ /** The chain family of a payment method or wallet. */
10
+ type PaymentFamily = 'eip155' | 'solana';
11
+ /** The wallet connected through Satellite Connect, as the checkout uses it. */
12
+ interface CheckoutWallet {
13
+ /** The account address. */
14
+ address: string;
15
+ /** CAIP-2 chain the wallet is on (Solana clusters as their genesis-hash ID). */
16
+ chainId: string;
17
+ /** Its chain family. */
18
+ family: PaymentFamily;
19
+ /** Connector type of Satellite Connect (`evm:metamask`). */
20
+ connectorType: string;
21
+ /** The wallet id for `WalletIcon` of `@tuwaio/nova-core` (`metamask`). */
22
+ walletId: string;
23
+ /** The wallet name to show: the name the wallet gives itself (`Switch Wallet`), see {@link walletLabel}. */
24
+ name: string;
25
+ /**
26
+ * The icon the wallet gives itself, an image `data:` URI (EIP-6963, Wallet Standard) or an HTTPS URL: of the
27
+ * connection (the connector that connected), else of its wallet in the Satellite store; `undefined` when neither
28
+ * gives one the checkout can show, and the checkout shows the icon of `walletId`.
29
+ */
30
+ icon?: string;
31
+ /** The Satellite Connect connection itself, for the chain adapters (the Solana adapter signs with its account). */
32
+ connection: unknown;
33
+ }
34
+ /**
35
+ * The name of a wallet: the name it gives itself, as the wallet list of Nova Connect shows it (`Switch Wallet`);
36
+ * without one, the name Nova knows for its connector type (`evm:metamask` is `MetaMask`), else the connector type
37
+ * with a capital letter. The generic injected connector is always `Browser wallet`.
38
+ *
39
+ * @param connectorType - Connector type of Satellite Connect, for example `evm:metamask`.
40
+ * @param ownName - The name of the wallet's connector (`name` of the wagmi connector or the Wallet Standard wallet).
41
+ * @returns The name, for example `MetaMask`.
42
+ */
43
+ declare function walletLabel(connectorType: string, ownName?: string): string;
44
+ /**
45
+ * Whether the checkout shows an icon a wallet gives itself: an image `data:` URI (EIP-6963, Wallet Standard) or an
46
+ * HTTPS URL.
47
+ *
48
+ * @param icon - The icon.
49
+ * @returns `true` for an image `data:` URI or an HTTPS URL.
50
+ * @internal
51
+ */
52
+ declare const isWalletIconUrl: (icon: string) => boolean;
53
+ /**
54
+ * The family of a CAIP-2 chain.
55
+ *
56
+ * @param chainId - A CAIP-2 chain ID.
57
+ * @returns `eip155` or `solana`; `null` for another namespace.
58
+ */
59
+ declare const familyOf: (chainId: string) => PaymentFamily | null;
60
+ /**
61
+ * The connected wallet of Satellite Connect in CAIP identifiers, named and shown as the wallet calls itself.
62
+ *
63
+ * @param connection - The active connection of the Satellite store: `address`, `chainId` (an EVM number or a Solana
64
+ * cluster), `connectorType`, and the `icon` of the wallet when the adapter set it.
65
+ * @param connectors - The wallets of the Satellite store by adapter (`getConnectors()`): the one with the connector
66
+ * type of the connection gives the name (see {@link walletLabel}); of several such wallets, the one with the icon of
67
+ * the connection. When it is not listed, the name comes from the connector type. The icon is the connection's, else
68
+ * the listed wallet's, when it is an image `data:` URI or an HTTPS URL.
69
+ * @returns The wallet, or `null` without a connection or with a chain the checkout cannot read.
70
+ */
71
+ declare function connectedWallet(connection: {
72
+ address: string;
73
+ chainId: string | number;
74
+ connectorType: string;
75
+ icon?: string;
76
+ } | null | undefined, connectors?: Partial<Record<string, unknown[]>>): CheckoutWallet | null;
77
+ /**
78
+ * The chain family of a payment method.
79
+ *
80
+ * @param method - The method.
81
+ * @returns `eip155` or `solana`; `null` for another namespace.
82
+ */
83
+ declare function methodFamily(method: CheckoutMethod): PaymentFamily | null;
84
+ /**
85
+ * The payer of a method for the connected wallet: its address on the method's chain. A wallet of the other family
86
+ * cannot pay it; a wallet on another chain of the family pays after switching (the quote names the method's chain).
87
+ *
88
+ * @param wallet - The connected wallet.
89
+ * @param method - The method.
90
+ * @returns The CAIP-10 account, or `null`.
91
+ */
92
+ declare function payerFor(wallet: CheckoutWallet | null, method: CheckoutMethod): string | null;
93
+ /**
94
+ * Whether a method can be paid by scanning a QR code with a phone: Solana with Solana Pay, an EVM method only through
95
+ * the payment page opened on the phone.
96
+ *
97
+ * @param method - The method.
98
+ * @param payUrl - The payment page of the invoice (its `payUrl`), if the app has it.
99
+ * @returns Whether the QR option applies.
100
+ */
101
+ declare function canPayWithQr(method: CheckoutMethod, payUrl?: string | null): boolean;
102
+ /**
103
+ * The discount or markup of a method, as the token and network options show it.
104
+ *
105
+ * @param method - The method.
106
+ * @returns `discount` or `markup` with the percent (`'1.5'`), or `null` for neither.
107
+ */
108
+ declare function priceAdjustment(method: CheckoutMethod): {
109
+ kind: 'discount' | 'markup';
110
+ percent: string;
111
+ } | null;
112
+ /**
113
+ * The name of a method's network, from the chain names of `@tuwaio/nova-core`.
114
+ *
115
+ * @param chainId - CAIP-2 chain of the method (`eip155:8453`, `solana:EtWT…`).
116
+ * @returns The name (`Base`, `Solana Devnet`), `Unknown` for a chain nova-core does not list.
117
+ */
118
+ declare function networkName(chainId: string): string;
119
+ /**
120
+ * The token of a method as a chain reads its balance, from its CAIP-19 asset.
121
+ *
122
+ * @param method - The payment method.
123
+ * @returns The token contract or mint, or `native` for the coin of the chain (a `slip44` asset, or none).
124
+ */
125
+ declare function methodToken(method: CheckoutMethod): string;
126
+
127
+ /** A fee in the native coin of a chain, in its base units. */
128
+ interface NativeFee {
129
+ /** The amount, in base units. */
130
+ amount: bigint;
131
+ /** Decimals of the native coin. */
132
+ decimals: number;
133
+ /** Symbol of the native coin. */
134
+ symbol: string;
135
+ }
136
+ /** A payment the wallet sent, with the texts of its transaction, for {@link PaymentsAdapter.pulsarTransaction}. */
137
+ interface PulsarTransactionParams {
138
+ /** The transaction hash (EVM) or signature (Solana). */
139
+ txKey: string;
140
+ /** What the wallet sent. */
141
+ instructions: PaymentInstructions;
142
+ /** The sender. */
143
+ account: string;
144
+ /** The connector of the wallet (`evm:metamask`). */
145
+ connectorType: string;
146
+ /** Title of the transaction (at most 100 characters). */
147
+ title: string;
148
+ /** Description of the transaction (at most 300 characters). */
149
+ description: string;
150
+ /** What the transaction pays: `quasarInvoice` is the invoice ID. */
151
+ payload: Record<string, string>;
152
+ }
153
+ /**
154
+ * What the checkout needs from a chain family to pay from the connected wallet. `@tuwaio/nova-payments/evm` and
155
+ * `@tuwaio/nova-payments/solana` make them; the checkout itself imports no chain library. Chains are CAIP-2 IDs, and
156
+ * amounts base units. A method that fails because of the wallet throws `PaymentWalletError` (or the wallet library's
157
+ * error, which the checkout reads with `walletErrorKind`).
158
+ */
159
+ interface PaymentsAdapter {
160
+ /** The chain family it pays on. */
161
+ family: PaymentFamily;
162
+ /**
163
+ * Reads a balance from the network in the browser (no request to Quasar).
164
+ *
165
+ * @param params - The chain, the account and the token (`native` for the coin of the chain).
166
+ * @returns The balance, in base units.
167
+ */
168
+ getBalance: (params: {
169
+ chainId: string;
170
+ account: string;
171
+ token: string;
172
+ }) => Promise<bigint>;
173
+ /**
174
+ * Estimates the network fee of the transfer, paid in the native coin.
175
+ *
176
+ * @param params - What the wallet sends and the sender.
177
+ * @returns The fee, or `null` when it cannot be estimated.
178
+ */
179
+ estimateFee?: (params: {
180
+ instructions: PaymentInstructions;
181
+ account: string;
182
+ }) => Promise<NativeFee | null>;
183
+ /**
184
+ * Whether the wallet sends `wallet_sendCalls` with the `paymasterService` capability on the chain (EIP-5792,
185
+ * ERC-7677).
186
+ *
187
+ * @param params - The chain and the account.
188
+ * @returns `true` when sponsored calls are possible.
189
+ */
190
+ canSponsorCalls?: (params: {
191
+ chainId: string;
192
+ account: string;
193
+ }) => Promise<boolean>;
194
+ /**
195
+ * Asks the wallet to switch to the chain of the payment.
196
+ *
197
+ * @param chainId - The chain.
198
+ */
199
+ switchChain?: (chainId: string) => Promise<void>;
200
+ /**
201
+ * Sends the transfer the quote describes, with the wallet's prompt.
202
+ *
203
+ * @param params - The quote's instructions, the sender, and the Satellite Connect connection of the wallet (the
204
+ * Solana adapter signs with its Wallet Standard account).
205
+ * @returns The transaction hash (EVM) or signature (Solana).
206
+ */
207
+ sendTransfer: (params: {
208
+ instructions: PaymentInstructions;
209
+ account: string;
210
+ connection?: unknown;
211
+ }) => Promise<string>;
212
+ /**
213
+ * Signs the EIP-3009 authorization of a gasless quote (`eth_signTypedData_v4`), with the wallet's prompt.
214
+ *
215
+ * @param params - The typed data and the signer.
216
+ * @returns The 65-byte signature.
217
+ */
218
+ signTransferAuthorization?: (params: {
219
+ typedData: TransferAuthorizationTypedData;
220
+ account: string;
221
+ }) => Promise<string>;
222
+ /**
223
+ * Signs a message with `personal_sign` (EIP-191), with the wallet's prompt: the EIP-4361 message by which the paying
224
+ * wallet confirms the invoice before an EVM payment it sends itself (`confirmPayer` of the checkout store of
225
+ * `@tuwaio/quasar-sdk/checkout`). A free signature that moves no funds; a smart wallet signs it through its own flow
226
+ * (ERC-1271, ERC-6492), often with a passkey. Without it the checkout cannot pay methods that need the confirmation
227
+ * from this wallet.
228
+ *
229
+ * @param params - The message exactly as Quasar wrote it, the signer, and the CAIP-2 network the message names (the
230
+ * wallet is on it already: the checkout switches it first).
231
+ * @returns The signature, as hex.
232
+ */
233
+ signMessage?: (params: {
234
+ message: string;
235
+ account: string;
236
+ chainId: string;
237
+ }) => Promise<string>;
238
+ /**
239
+ * Sends the sponsored calls of a gasless quote with `wallet_sendCalls` and the paymaster, with the wallet's prompt,
240
+ * and waits for the transaction that carries them.
241
+ *
242
+ * @param params - The calls, the paymaster URL of the checkout, the chain, the sender, and `onSent`, called once the
243
+ * wallet accepted the calls (before they are included).
244
+ * @returns The hash of the transaction (not the batch ID), as Quasar expects it.
245
+ */
246
+ /**
247
+ * The link of a transaction on a block explorer of its chain.
248
+ *
249
+ * @param params - The chain and the transaction hash or signature.
250
+ * @returns The link, or `undefined` when the chain has no known explorer.
251
+ */
252
+ explorerUrl?: (params: {
253
+ chainId: string;
254
+ txKey: string;
255
+ }) => string | undefined;
256
+ /**
257
+ * The link of a wallet address on a block explorer of its chain.
258
+ *
259
+ * @param params - The chain and the address.
260
+ * @returns The link, or `undefined` when the chain has no known explorer.
261
+ */
262
+ explorerAddressUrl?: (params: {
263
+ chainId: string;
264
+ address: string;
265
+ }) => string | undefined;
266
+ /**
267
+ * What the account is for automatic payments, read before asking for the permission: `smart` has code on the network,
268
+ * `upgradable` is a plain account its wallet can switch to a smart account, `unknown` says nothing either way. Quasar
269
+ * decides in the end: it refuses a wallet that could never be charged.
270
+ *
271
+ * @param params - The network and the account.
272
+ * @returns The kind.
273
+ */
274
+ smartAccountStatus?: (params: {
275
+ chainId: string;
276
+ account: string;
277
+ }) => Promise<'smart' | 'upgradable' | 'unknown'>;
278
+ /**
279
+ * Has the wallet switch a plain account to its smart account (`upgradable` of {@link PaymentsAdapter.smartAccountStatus})
280
+ * and waits until the network includes it. The wallet asks the buyer and the buyer pays the network fee.
281
+ *
282
+ * @param params - The network and the account.
283
+ */
284
+ upgradeToSmartAccount?: (params: {
285
+ chainId: string;
286
+ account: string;
287
+ }) => Promise<void>;
288
+ /**
289
+ * Asks the wallet for the ERC-7715 permission of a subscription's automatic payments, with the wallet's prompt.
290
+ *
291
+ * @param params - The request of the checkout's auto-charge offer and the granting account.
292
+ * @returns What the wallet granted, for `grantPermission` of the checkout store (without the payer).
293
+ */
294
+ requestPermission?: (params: {
295
+ request: PermissionRequest;
296
+ account: string;
297
+ }) => Promise<Omit<GrantPermissionParams, 'payer'>>;
298
+ /**
299
+ * Sends the transaction that revokes the permission of a subscription's automatic payments, with the wallet's prompt,
300
+ * and waits until the network includes it. The wallet pays its network fee.
301
+ *
302
+ * @param params - The transaction of the checkout's auto-charge offer, its CAIP-2 chain, the account that granted the
303
+ * permission and what to call once the wallet has sent it: a failure while waiting must not send it again.
304
+ */
305
+ revokePermission?: (params: {
306
+ revocation: {
307
+ to: string;
308
+ data: string;
309
+ };
310
+ chainId: string;
311
+ account: string;
312
+ onSent?: () => void;
313
+ }) => Promise<void>;
314
+ /**
315
+ * Describes a sent payment as a pending transaction of `@tuwaio/pulsar-core`, so that the app's Pulsar store tracks
316
+ * it (and Nova Transactions shows its toast) once the checkout closes.
317
+ *
318
+ * @param params - The payment and the texts of its transaction.
319
+ * @returns The pending transaction, for `injectExternalPendingTxs` of the Pulsar store.
320
+ */
321
+ pulsarTransaction?: (params: PulsarTransactionParams) => Transaction;
322
+ /**
323
+ * Follows a batch the wallet took before the page was reloaded, until its transaction comes or `until` passes.
324
+ *
325
+ * @param params - The batch, until when to follow it (a timestamp) and what to call with its transaction.
326
+ */
327
+ followSponsoredCalls?: (params: {
328
+ batchId: string;
329
+ until: number;
330
+ onLate: (txKey: string) => void;
331
+ }) => void;
332
+ sendSponsoredCalls?: (params: {
333
+ calls: {
334
+ to: string;
335
+ value: string;
336
+ data: string;
337
+ }[];
338
+ paymasterUrl: string;
339
+ chainId: string;
340
+ account: string;
341
+ onSent?: () => void;
342
+ /** Called with the ID of the batch as soon as the wallet took it, before it has a transaction. */
343
+ onAccepted?: (batchId: string) => void;
344
+ /** Called with the transaction of a batch that landed after the adapter gave up waiting (`sentUnconfirmed`). */
345
+ onLate?: (txKey: string) => void;
346
+ }) => Promise<string>;
347
+ }
348
+
349
+ export { canPayWithQr as c, connectedWallet as d, methodToken as e, familyOf as f, priceAdjustment as g, isWalletIconUrl as i, methodFamily as m, networkName as n, payerFor as p, walletLabel as w };
350
+ export type { CheckoutWallet as C, NativeFee as N, PaymentsAdapter as P, PaymentFamily as a, PulsarTransactionParams as b };