@phala/pay 0.12.1 → 0.13.0
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.
- package/README.md +13 -65
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/quote.d.ts +6 -1
- package/dist/quote.d.ts.map +1 -1
- package/dist/quote.js +8 -0
- package/dist/quote.js.map +1 -1
- package/dist/wallet.d.ts +0 -25
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +2 -21
- package/dist/wallet.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/quote.ts +14 -1
- package/src/wallet.ts +1 -45
package/README.md
CHANGED
|
@@ -48,7 +48,6 @@ connects a wallet with wagmi, RainbowKit, ConnectKit, or AppKit, pass it in inst
|
|
|
48
48
|
apiBase="https://pay.example.com"
|
|
49
49
|
onSuccess={props.onPaid}
|
|
50
50
|
onExpire={props.onRetry}
|
|
51
|
-
buttonText="Pay with crypto"
|
|
52
51
|
/>
|
|
53
52
|
);
|
|
54
53
|
}
|
|
@@ -176,7 +175,6 @@ import { PaymentElement } from "@phala/pay-react";
|
|
|
176
175
|
createQuote={(option, { idempotencyKey }) =>
|
|
177
176
|
api.createTopUp({ amount: 2500, chain_id: option.chain_id, asset: option.asset, idempotencyKey })
|
|
178
177
|
}
|
|
179
|
-
createDepositAddress={() => api.depositAddress()} // optional: "Use a deposit address"
|
|
180
178
|
apiBase="https://pay.example.com"
|
|
181
179
|
renderDetail={(option) => (option.asset === "usdc" ? "$1.00" : "Market rate")}
|
|
182
180
|
onSuccess={() => router.refresh()}
|
|
@@ -188,7 +186,7 @@ import { PaymentElement } from "@phala/pay-react";
|
|
|
188
186
|
`{ clientSecret, expectedAddress, apiBase? }`; `apiBase` falls back to the prop. A rejection
|
|
189
187
|
shows "Could not start the payment. Try again." and calls `onError(error)`. To show your own
|
|
190
188
|
reason in that alert instead, pass `errorMessage(cause)`: a non-empty string replaces the text,
|
|
191
|
-
and `null` or `undefined` keeps it.
|
|
189
|
+
and `null` or `undefined` keeps it.
|
|
192
190
|
- Create the quote with `idempotencyKey` as its `Idempotency-Key`, not an order id of yours: the
|
|
193
191
|
key is a new random UUID for each quote the payer asks for (another option or amount, or a new
|
|
194
192
|
quote after going back from one) and the same only when they retry after `createQuote` failed
|
|
@@ -197,49 +195,14 @@ import { PaymentElement } from "@phala/pay-react";
|
|
|
197
195
|
new quote with the expired one. If your quote varies by anything else between attempts (a field
|
|
198
196
|
of your own form, say), pass it as `amount` or give the element a new `key` when it changes, or
|
|
199
197
|
a retry would reuse a key with another body.
|
|
200
|
-
- After the quote: the checkout, and a way back to the options ("
|
|
201
|
-
|
|
202
|
-
new payment" once credited.
|
|
203
|
-
- `createDepositAddress(option)` adds one quiet line at the end of the form, "Paying from an
|
|
204
|
-
exchange? Use a deposit address", for payers sending from an exchange or any wallet: it resolves
|
|
205
|
-
with the deposit address's `address` and `networks` and, to follow its payments, `clientSecret`;
|
|
206
|
-
the element shows `<DepositAddress>` at the chosen option, which states the per-transfer limits.
|
|
207
|
-
- **Deposit-address mode.** Without `createQuote`, submit calls `createDepositAddress(option)` once
|
|
208
|
-
and shows that address as the way to pay, with no secondary line: the customer's one fixed address
|
|
209
|
-
instead of a new quote per payment. `depositAmountAtomic(option, token)` names the token amount to
|
|
210
|
-
ask for in the token's smallest unit (`undefined` for any amount); it is called once the address
|
|
211
|
-
is created, with its token for the chosen option, whose `decimals` give the unit. The address view
|
|
212
|
-
then states the amount and network once, pays it with `Pay with <wallet name>`
|
|
213
|
-
(`payDepositAddressWithWallet`: exactly that amount, then a transaction-hash hint), and keeps a QR
|
|
214
|
-
code that requests the amount (EIP-681 `uint256`) and the address to copy behind "Pay from an
|
|
215
|
-
exchange or another wallet". It follows the payment the wallet sent, by its hash, or else the
|
|
216
|
-
newest one that arrives after the address was first read, on one status line; `onChange` reports
|
|
217
|
-
it as `payment`, and `onDepositSuccess(payment)` is called once when it is credited. An address
|
|
218
|
-
that does not take the chosen token on the chosen network is a `createDepositAddress` failure. To
|
|
219
|
-
resume after a reload, keep `onDepositSent(txHash, chainId)`'s values and pass them back as
|
|
220
|
-
`depositTxHash`, with that option as `value` or `defaultValue`: the element calls
|
|
221
|
-
`createDepositAddress` at once and shows that payment's status (no way to pay again) until it is
|
|
222
|
-
credited.
|
|
223
|
-
|
|
224
|
-
```tsx
|
|
225
|
-
<PaymentElement
|
|
226
|
-
options={paymentOptions(config.assets)}
|
|
227
|
-
amount={2500}
|
|
228
|
-
// POST /v1/deposit_addresses on your backend: { address, networks, clientSecret }
|
|
229
|
-
createDepositAddress={() => api.depositAddress()}
|
|
230
|
-
// 25 of a $1 stablecoin: cents × 10^(decimals − 2)
|
|
231
|
-
depositAmountAtomic={(option, token) => (2500n * 10n ** BigInt(token.decimals)) / 100n}
|
|
232
|
-
apiBase="https://pay.example.com"
|
|
233
|
-
onDepositSuccess={() => router.refresh()}
|
|
234
|
-
/>
|
|
235
|
-
```
|
|
236
|
-
|
|
198
|
+
- After the quote: the checkout, and a way back to the options ("Back") until a payment is on its
|
|
199
|
+
way, then "Start a new payment" once it is credited or does not complete.
|
|
237
200
|
- Your own content: `children` go inside the form, under the token and network and above the
|
|
238
201
|
element's button, while the payer chooses. With `hideSubmit`, put your summary and your
|
|
239
202
|
`type="submit"` button there, and the deposit-address line follows your button:
|
|
240
203
|
|
|
241
204
|
```tsx
|
|
242
|
-
<PaymentElement hideSubmit options={options} createQuote={createQuote}
|
|
205
|
+
<PaymentElement hideSubmit options={options} createQuote={createQuote}>
|
|
243
206
|
<OrderSummary />
|
|
244
207
|
<Button type="submit">Continue to pay $25.00</Button>
|
|
245
208
|
</PaymentElement>
|
|
@@ -249,10 +212,9 @@ import { PaymentElement } from "@phala/pay-react";
|
|
|
249
212
|
button `type="submit" form={id}` (or call `requestSubmit()` on the form with that id). The
|
|
250
213
|
element is a `<form>`: do not nest it in another one.
|
|
251
214
|
- `value` and `onOptionChange` control the choice (`defaultValue` sets the first one otherwise);
|
|
252
|
-
`onChange({ step, checkout
|
|
253
|
-
|
|
254
|
-
`
|
|
255
|
-
`onWalletError`, `walletClient`, `pollInterval`, and `appearance` are `<Checkout>`'s.
|
|
215
|
+
`onChange({ step, checkout })` reports each step (`options`, `creating`, `checkout`) and each
|
|
216
|
+
checkout status change; `onSuccess`, `onExpire`, `onWalletError`, `walletClient`, `pollInterval`,
|
|
217
|
+
and `appearance` are `<Checkout>`'s.
|
|
256
218
|
|
|
257
219
|
### Payment options
|
|
258
220
|
|
|
@@ -314,11 +276,11 @@ import { DepositAddress } from "@phala/pay-react";
|
|
|
314
276
|
With `clientSecret` and `apiBase` it reads the address's public view about every three seconds and
|
|
315
277
|
lists its payments of the last 24 hours: "1.5 PHA received on Sepolia, 1 confirmation" once the
|
|
316
278
|
service sees the transfer (within about a block for a hinted payment, at the next discovery scan
|
|
317
|
-
otherwise), then "credited" (or rejected or reversed). Display only. It also states when
|
|
318
|
-
network
|
|
279
|
+
otherwise), then "credited" (or rejected or reversed). Display only. It also states when a payment on the
|
|
280
|
+
chosen network is usually credited: `<DepositAddress>` submits no transaction-hash hint (the
|
|
319
281
|
payer's wallet or exchange gives it no hash), so the service's 5-minute discovery scan plus the
|
|
320
|
-
view's `typical_credit_seconds` ("usually within about 6 minutes
|
|
321
|
-
|
|
282
|
+
view's `typical_credit_seconds` ("usually within about 6 minutes"); until the view is loaded it
|
|
283
|
+
names no time.
|
|
322
284
|
|
|
323
285
|
After ten minutes without a change in the public view, `<DepositAddress>` uses a base interval
|
|
324
286
|
of `max(pollInterval, 15000)` milliseconds, with the same jitter and failure backoff, so a longer
|
|
@@ -330,22 +292,8 @@ not report loading. Unchanged polls, callback replacements,
|
|
|
330
292
|
and reconnecting alone do not trigger it. Use it to update your page without additional polling;
|
|
331
293
|
fulfil from the `deposit.credited` webhook.
|
|
332
294
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
(`walletClient`, `buttonText`, and `onWalletError` as `<Checkout>`'s), and "Pay from an exchange or
|
|
336
|
-
another wallet" revealing a QR code that requests exactly the amount and the address to copy (shown
|
|
337
|
-
at once when the browser has no wallet). With `clientSecret` and `apiBase` it follows that payment
|
|
338
|
-
(the wallet's transaction by its hash, else the newest payment that arrives after the address was
|
|
339
|
-
first read) on one status line, calls `onPaymentChange(payment)` as it changes and `onSuccess(payment)`
|
|
340
|
-
once it is credited, and replaces the ways to pay with that status once it is on its way.
|
|
341
|
-
`onSent(txHash, chainId)` reports the wallet's transaction; pass it back as `txHash` after a
|
|
342
|
-
reload to follow that payment again.
|
|
343
|
-
|
|
344
|
-
`depositAddressTransfer(network, asset)` reads and checks one token's amount-less EIP-681
|
|
345
|
-
`payment_uri` without React; `payDepositAddressWithWallet(wallet, { network, asset, amountAtomic,
|
|
346
|
-
clientSecret?, apiBase? })` pays an amount of it from a wallet as `payWithWallet` pays a quote
|
|
347
|
-
(connect, switch chain, balance check, `transfer`), then, with `clientSecret` and `apiBase`, hints
|
|
348
|
-
the transaction with its `chain_id` without waiting on the hint, and resolves with the hash.
|
|
295
|
+
`depositAddressTransfer(network, asset)` reads and checks one token's amountless EIP-681
|
|
296
|
+
`payment_uri` without React. `<DepositAddress>` accepts any amount within its per-transfer limits.
|
|
349
297
|
|
|
350
298
|
## Appearance
|
|
351
299
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { depositAddressTransfer, parseTransferUri, quoteTransfer, type DepositAd
|
|
|
7
7
|
export { parseClientQuote, quoteIdFromClientSecret, type ClientQuote } from "./quote.js";
|
|
8
8
|
export { assetIconName, assetName, assetSymbol, iconMonogram, type IconName } from "./icon-names.js";
|
|
9
9
|
export { paymentOptionLabel, paymentOptions, samePaymentOption, type NetworkPaymentOption, type PaymentNetwork, type PaymentOption, } from "./options.js";
|
|
10
|
-
export { INJECTED_WALLET_UUID, WalletError,
|
|
10
|
+
export { INJECTED_WALLET_UUID, WalletError, payWithWallet, watchWallets, type EthereumProvider, type Wallet, type WalletErrorCode, type WalletInfo, } from "./wallet.js";
|
|
11
11
|
export { networkIcon, assetIcon } from "./icons.js";
|
|
12
12
|
export type { CheckoutParams } from "./shared/checkout-params.js";
|
|
13
13
|
export { submitTransaction, type SubmitTransactionOptions } from "./transactions.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,GACnC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/I,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,KAAK,W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,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrG,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { depositAddressTransfer, parseTransferUri, quoteTransfer, } from "./paym
|
|
|
7
7
|
export { parseClientQuote, quoteIdFromClientSecret } from "./quote.js";
|
|
8
8
|
export { assetIconName, assetName, assetSymbol, iconMonogram } from "./icon-names.js";
|
|
9
9
|
export { paymentOptionLabel, paymentOptions, samePaymentOption, } from "./options.js";
|
|
10
|
-
export { INJECTED_WALLET_UUID, WalletError,
|
|
10
|
+
export { INJECTED_WALLET_UUID, WalletError, payWithWallet, watchWallets, } from "./wallet.js";
|
|
11
11
|
export { networkIcon, assetIcon } from "./icons.js";
|
|
12
12
|
export { submitTransaction } from "./transactions.js";
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,GAQd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAwB,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,sBAAsB,GAKvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/I,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,GAMd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAoB,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AACrG,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,GAQd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAwB,MAAM,aAAa,CAAC;AAC7D,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,sBAAsB,GAKvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/I,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,GAMd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAoB,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AACrG,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,YAAY,GAKb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGpD,OAAO,EAAE,iBAAiB,EAAiC,MAAM,mBAAmB,CAAC"}
|
package/dist/quote.d.ts
CHANGED
|
@@ -17,8 +17,13 @@ export interface ClientQuote {
|
|
|
17
17
|
chain_id: number;
|
|
18
18
|
/** The exact token amount to send, in the token's smallest unit, as a decimal string. */
|
|
19
19
|
amount_atomic: string;
|
|
20
|
-
/** The
|
|
20
|
+
/** The customer's fixed deposit address on the chosen network. */
|
|
21
21
|
address: string;
|
|
22
|
+
deposit_address: string | null;
|
|
23
|
+
deposit_address_version: number | null;
|
|
24
|
+
replaced_by: string | null;
|
|
25
|
+
/** Exclusive start of the price window, Unix seconds. */
|
|
26
|
+
window_start: number;
|
|
22
27
|
/** The EIP-681 payment request: token transfer of `amount_atomic` to `address`. */
|
|
23
28
|
payment_uri: string;
|
|
24
29
|
/** Unix seconds; after this the address must no longer be shown. */
|
package/dist/quote.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote.d.ts","sourceRoot":"","sources":["../src/quote.ts"],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nF,WAAW,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC;;;;;OAKG;IACH,cAAc,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;IACtF,8EAA8E;IAC9E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;OAIG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;;OAIG;IACH,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAKD,oFAAoF;AACpF,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMpE;AAED,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CA4D5D"}
|
package/dist/quote.js
CHANGED
|
@@ -30,6 +30,10 @@ export function parseClientQuote(value) {
|
|
|
30
30
|
!/^\d+$/.test(v["amount_atomic"]) ||
|
|
31
31
|
typeof v["address"] !== "string" ||
|
|
32
32
|
!/^0x[0-9a-fA-F]{40}$/.test(v["address"]) ||
|
|
33
|
+
!(v["deposit_address"] === null || typeof v["deposit_address"] === "string") ||
|
|
34
|
+
!(v["deposit_address_version"] === null || isSafeInteger(v["deposit_address_version"])) ||
|
|
35
|
+
!(v["replaced_by"] === null || typeof v["replaced_by"] === "string") ||
|
|
36
|
+
!isSafeInteger(v["window_start"]) ||
|
|
33
37
|
typeof v["payment_uri"] !== "string" ||
|
|
34
38
|
!isSafeInteger(v["expires_at"]) ||
|
|
35
39
|
!(cancelRequestedAt === undefined || cancelRequestedAt === null || isSafeInteger(cancelRequestedAt)) ||
|
|
@@ -51,6 +55,10 @@ export function parseClientQuote(value) {
|
|
|
51
55
|
chain_id: v["chain_id"],
|
|
52
56
|
amount_atomic: v["amount_atomic"],
|
|
53
57
|
address: v["address"],
|
|
58
|
+
deposit_address: v["deposit_address"],
|
|
59
|
+
deposit_address_version: v["deposit_address_version"],
|
|
60
|
+
replaced_by: v["replaced_by"],
|
|
61
|
+
window_start: v["window_start"],
|
|
54
62
|
payment_uri: v["payment_uri"],
|
|
55
63
|
expires_at: v["expires_at"],
|
|
56
64
|
...(cancelRequestedAt === undefined ? {} : { cancel_requested_at: cancelRequestedAt }),
|
package/dist/quote.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../src/quote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quote.js","sourceRoot":"","sources":["../src/quote.ts"],"names":[],"mappings":"AAuDA,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AAC5E,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAErG,oFAAoF;AACpF,MAAM,UAAU,uBAAuB,CAAC,YAAoB;IAC1D,MAAM,KAAK,GAAG,mCAAmC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACrE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,MAAM,aAAa,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC;IACzC,MAA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,EAAE,CAAC,CAAC,YAAY,CAAC;QAC3B,GAAG,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,CAAC;QACtF,cAAc,EAAE,CAAC,CAAC,gBAAgB,CAAC;QACnC,aAAa;QACb,eAAe,EAAE,cAAc;QAC/B,sBAAsB,EAAE,CAAC,CAAC,wBAAwB,CAAC;KACpD,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAmB,KAAc,EAAE,OAAqB;IACpE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,OAA6B,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrF,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC"}
|
package/dist/wallet.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Hash, type WalletClient } from "viem";
|
|
2
|
-
import { type DepositAddressAsset, type DepositAddressNetwork } from "./payment.js";
|
|
3
2
|
import type { ClientQuote } from "./quote.js";
|
|
4
3
|
/** EIP-6963 provider info. */
|
|
5
4
|
export interface WalletInfo {
|
|
@@ -44,28 +43,4 @@ export declare class WalletError extends Error {
|
|
|
44
43
|
* it; the checkout's status follows the payment from there.
|
|
45
44
|
*/
|
|
46
45
|
export declare function payWithWallet(wallet: WalletClient | EthereumProvider, quote: ClientQuote): Promise<Hash>;
|
|
47
|
-
export interface PayDepositAddressOptions {
|
|
48
|
-
/** The network to pay on, from the deposit address's `networks`. */
|
|
49
|
-
network: DepositAddressNetwork;
|
|
50
|
-
/** The token to pay in, from that network's `assets`. */
|
|
51
|
-
asset: DepositAddressAsset;
|
|
52
|
-
/** The token amount to send, in the smallest unit; positive. */
|
|
53
|
-
amountAtomic: bigint;
|
|
54
|
-
/**
|
|
55
|
-
* The address's `client_secret`. With `apiBase`, the transaction hash is sent to the service as
|
|
56
|
-
* a best-effort hint once the wallet broadcasts it, so the payment is found within about a block.
|
|
57
|
-
*/
|
|
58
|
-
clientSecret?: string | undefined;
|
|
59
|
-
/** The service origin; needed with `clientSecret`. */
|
|
60
|
-
apiBase?: string | undefined;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Pays `amountAtomic` of a token to a customer's deposit address from a wallet, as `payWithWallet`
|
|
64
|
-
* pays a quote: connects, switches to (or adds) the network's chain, checks the token balance, and
|
|
65
|
-
* sends the ERC-20 `transfer` that the token's `payment_uri` states, for exactly that amount. Then,
|
|
66
|
-
* with `clientSecret` and `apiBase`, it hints the transaction to the service without waiting for
|
|
67
|
-
* or failing on it. Resolves with the transaction hash once the wallet has broadcast it; follow the
|
|
68
|
-
* payment in the address's `payments` by that hash.
|
|
69
|
-
*/
|
|
70
|
-
export declare function payDepositAddressWithWallet(wallet: WalletClient | EthereumProvider, { network, asset, amountAtomic, clientSecret, apiBase }: PayDepositAddressOptions): Promise<Hash>;
|
|
71
46
|
//# sourceMappingURL=wallet.d.ts.map
|
package/dist/wallet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,IAAI,EACT,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,IAAI,EACT,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAQd,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,8BAA8B;AAC9B,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,2FAA2F;AAC3F,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED,iGAAiG;AACjG,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAE/C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAa9E;AA8BD,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,YAAY,GACZ,aAAa,GACb,sBAAsB,GACtB,QAAQ,CAAC;AAEb,qBAAa,WAAY,SAAQ,KAAK;IAIlC,QAAQ,CAAC,IAAI,EAAE,eAAe;IAHhC,SAAkB,IAAI,iBAAiB;gBAG5B,IAAI,EAAE,eAAe,EAC9B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY;CAIzB;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,YAAY,GAAG,gBAAgB,EACvC,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
package/dist/wallet.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { submitWalletTransaction } from "./transactions.js";
|
|
2
2
|
import { createStore } from "mipd";
|
|
3
3
|
import { BaseError, createWalletClient, custom, erc20Abi, SwitchChainError, UserRejectedRequestError, } from "viem";
|
|
4
4
|
import { readContract } from "viem/actions";
|
|
5
5
|
import { knownChain, networkName } from "./chains.js";
|
|
6
6
|
import { formatUnitsGrouped } from "./format.js";
|
|
7
|
-
import {
|
|
7
|
+
import { quoteTransfer, } from "./payment.js";
|
|
8
8
|
/** The legacy `window.ethereum` provider, offered when no wallet announces itself (EIP-6963). */
|
|
9
9
|
export const INJECTED_WALLET_UUID = "injected";
|
|
10
10
|
/**
|
|
@@ -72,25 +72,6 @@ export async function payWithWallet(wallet, quote) {
|
|
|
72
72
|
submitWalletTransaction(quote, hash);
|
|
73
73
|
return hash;
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Pays `amountAtomic` of a token to a customer's deposit address from a wallet, as `payWithWallet`
|
|
77
|
-
* pays a quote: connects, switches to (or adds) the network's chain, checks the token balance, and
|
|
78
|
-
* sends the ERC-20 `transfer` that the token's `payment_uri` states, for exactly that amount. Then,
|
|
79
|
-
* with `clientSecret` and `apiBase`, it hints the transaction to the service without waiting for
|
|
80
|
-
* or failing on it. Resolves with the transaction hash once the wallet has broadcast it; follow the
|
|
81
|
-
* payment in the address's `payments` by that hash.
|
|
82
|
-
*/
|
|
83
|
-
export async function payDepositAddressWithWallet(wallet, { network, asset, amountAtomic, clientSecret, apiBase }) {
|
|
84
|
-
if (amountAtomic <= 0n) {
|
|
85
|
-
throw new TypeError("amountAtomic must be positive");
|
|
86
|
-
}
|
|
87
|
-
const transfer = { ...depositAddressTransfer(network, asset), amount: amountAtomic };
|
|
88
|
-
const hash = await sendTransfer(wallet, transfer, asset.asset, asset.decimals);
|
|
89
|
-
if (clientSecret !== undefined && apiBase !== undefined) {
|
|
90
|
-
void submitTransaction({ apiBase, clientSecret, transactionHash: hash, chainId: transfer.chainId }).catch(() => undefined);
|
|
91
|
-
}
|
|
92
|
-
return hash;
|
|
93
|
-
}
|
|
94
75
|
async function sendTransfer(wallet, transfer, asset, decimals) {
|
|
95
76
|
const client = isWalletClient(wallet) ? wallet : createWalletClient({ transport: custom(wallet) });
|
|
96
77
|
try {
|
package/dist/wallet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings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C,aAAa,EAAE,yBAAyB,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,wBAAwB,CAAC,KAAK,IAAI,CAAC;AACzG,CAAC;AAED;kFACkF;AAClF,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,CACL,KAAK,YAAY,SAAS;QAC1B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACf,MAAM,MAAM,GAAI,CAA8D,EAAE,IAAI,CAAC;YACrF,OAAO,CAAC,YAAY,gBAAgB,IAAI,MAAM,EAAE,aAAa,EAAE,IAAI,KAAK,gBAAgB,CAAC,IAAI,CAAC;QAChG,CAAC,CAAC,KAAK,IAAI,CACZ,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/quote.ts
CHANGED
|
@@ -17,8 +17,13 @@ export interface ClientQuote {
|
|
|
17
17
|
chain_id: number;
|
|
18
18
|
/** The exact token amount to send, in the token's smallest unit, as a decimal string. */
|
|
19
19
|
amount_atomic: string;
|
|
20
|
-
/** The
|
|
20
|
+
/** The customer's fixed deposit address on the chosen network. */
|
|
21
21
|
address: string;
|
|
22
|
+
deposit_address: string | null;
|
|
23
|
+
deposit_address_version: number | null;
|
|
24
|
+
replaced_by: string | null;
|
|
25
|
+
/** Exclusive start of the price window, Unix seconds. */
|
|
26
|
+
window_start: number;
|
|
22
27
|
/** The EIP-681 payment request: token transfer of `amount_atomic` to `address`. */
|
|
23
28
|
payment_uri: string;
|
|
24
29
|
/** Unix seconds; after this the address must no longer be shown. */
|
|
@@ -83,6 +88,10 @@ export function parseClientQuote(value: unknown): ClientQuote {
|
|
|
83
88
|
!/^\d+$/.test(v["amount_atomic"]) ||
|
|
84
89
|
typeof v["address"] !== "string" ||
|
|
85
90
|
!/^0x[0-9a-fA-F]{40}$/.test(v["address"]) ||
|
|
91
|
+
!(v["deposit_address"] === null || typeof v["deposit_address"] === "string") ||
|
|
92
|
+
!(v["deposit_address_version"] === null || isSafeInteger(v["deposit_address_version"])) ||
|
|
93
|
+
!(v["replaced_by"] === null || typeof v["replaced_by"] === "string") ||
|
|
94
|
+
!isSafeInteger(v["window_start"]) ||
|
|
86
95
|
typeof v["payment_uri"] !== "string" ||
|
|
87
96
|
!isSafeInteger(v["expires_at"]) ||
|
|
88
97
|
!(cancelRequestedAt === undefined || cancelRequestedAt === null || isSafeInteger(cancelRequestedAt)) ||
|
|
@@ -105,6 +114,10 @@ export function parseClientQuote(value: unknown): ClientQuote {
|
|
|
105
114
|
chain_id: v["chain_id"],
|
|
106
115
|
amount_atomic: v["amount_atomic"],
|
|
107
116
|
address: v["address"],
|
|
117
|
+
deposit_address: v["deposit_address"],
|
|
118
|
+
deposit_address_version: v["deposit_address_version"],
|
|
119
|
+
replaced_by: v["replaced_by"],
|
|
120
|
+
window_start: v["window_start"],
|
|
108
121
|
payment_uri: v["payment_uri"],
|
|
109
122
|
expires_at: v["expires_at"],
|
|
110
123
|
...(cancelRequestedAt === undefined ? {} : { cancel_requested_at: cancelRequestedAt }),
|
package/src/wallet.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { submitWalletTransaction } from "./transactions.js";
|
|
2
2
|
import { createStore } from "mipd";
|
|
3
3
|
import {
|
|
4
4
|
BaseError,
|
|
@@ -15,10 +15,7 @@ import { readContract } from "viem/actions";
|
|
|
15
15
|
import { knownChain, networkName } from "./chains.js";
|
|
16
16
|
import { formatUnitsGrouped } from "./format.js";
|
|
17
17
|
import {
|
|
18
|
-
depositAddressTransfer,
|
|
19
18
|
quoteTransfer,
|
|
20
|
-
type DepositAddressAsset,
|
|
21
|
-
type DepositAddressNetwork,
|
|
22
19
|
type TokenTransfer,
|
|
23
20
|
} from "./payment.js";
|
|
24
21
|
import type { ClientQuote } from "./quote.js";
|
|
@@ -130,47 +127,6 @@ export async function payWithWallet(
|
|
|
130
127
|
return hash;
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
export interface PayDepositAddressOptions {
|
|
134
|
-
/** The network to pay on, from the deposit address's `networks`. */
|
|
135
|
-
network: DepositAddressNetwork;
|
|
136
|
-
/** The token to pay in, from that network's `assets`. */
|
|
137
|
-
asset: DepositAddressAsset;
|
|
138
|
-
/** The token amount to send, in the smallest unit; positive. */
|
|
139
|
-
amountAtomic: bigint;
|
|
140
|
-
/**
|
|
141
|
-
* The address's `client_secret`. With `apiBase`, the transaction hash is sent to the service as
|
|
142
|
-
* a best-effort hint once the wallet broadcasts it, so the payment is found within about a block.
|
|
143
|
-
*/
|
|
144
|
-
clientSecret?: string | undefined;
|
|
145
|
-
/** The service origin; needed with `clientSecret`. */
|
|
146
|
-
apiBase?: string | undefined;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Pays `amountAtomic` of a token to a customer's deposit address from a wallet, as `payWithWallet`
|
|
151
|
-
* pays a quote: connects, switches to (or adds) the network's chain, checks the token balance, and
|
|
152
|
-
* sends the ERC-20 `transfer` that the token's `payment_uri` states, for exactly that amount. Then,
|
|
153
|
-
* with `clientSecret` and `apiBase`, it hints the transaction to the service without waiting for
|
|
154
|
-
* or failing on it. Resolves with the transaction hash once the wallet has broadcast it; follow the
|
|
155
|
-
* payment in the address's `payments` by that hash.
|
|
156
|
-
*/
|
|
157
|
-
export async function payDepositAddressWithWallet(
|
|
158
|
-
wallet: WalletClient | EthereumProvider,
|
|
159
|
-
{ network, asset, amountAtomic, clientSecret, apiBase }: PayDepositAddressOptions,
|
|
160
|
-
): Promise<Hash> {
|
|
161
|
-
if (amountAtomic <= 0n) {
|
|
162
|
-
throw new TypeError("amountAtomic must be positive");
|
|
163
|
-
}
|
|
164
|
-
const transfer = { ...depositAddressTransfer(network, asset), amount: amountAtomic };
|
|
165
|
-
const hash = await sendTransfer(wallet, transfer, asset.asset, asset.decimals);
|
|
166
|
-
if (clientSecret !== undefined && apiBase !== undefined) {
|
|
167
|
-
void submitTransaction({ apiBase, clientSecret, transactionHash: hash, chainId: transfer.chainId }).catch(
|
|
168
|
-
() => undefined,
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
return hash;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
130
|
async function sendTransfer(
|
|
175
131
|
wallet: WalletClient | EthereumProvider,
|
|
176
132
|
transfer: TokenTransfer,
|