@tempoxyz/id 0.0.0-pr-212.sha-dca8bcf → 0.0.0-pr-210.sha-dfd6fc2
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/dist/app/client/assets/{ccip-vaNdT_Ga.js → ccip-D3sAVeIt.js} +1 -1
- package/dist/app/client/assets/{index-Dd17MDXK.css → index-BGqXyEgd.css} +1 -1
- package/dist/app/client/assets/{index-CRiD2b4b.js → index-s_euKzrq.js} +42 -42
- package/dist/app/server/.vite/manifest.json +3 -3
- package/dist/app/server/assets/{_tanstack-start-manifest_v-DWbS5CJ8.js → _tanstack-start-manifest_v-OOGXxG7v.js} +1 -1
- package/dist/app/server/assets/router-Bp9HWhG2.css +1 -0
- package/dist/app/server/assets/router-DX0i0cOR.js +7 -0
- package/dist/app/server/assets/router-DX0i0cOR.js.map +1 -0
- package/dist/app/server/index.js +20 -20
- package/dist/app/server/index.js.map +1 -1
- package/dist/internal/ErrorResponse.d.ts +11 -0
- package/dist/internal/ErrorResponse.d.ts.map +1 -1
- package/dist/internal/ErrorResponse.js +22 -3
- package/dist/internal/ErrorResponse.js.map +1 -1
- package/dist/internal/KeyAuthorization.d.ts +2 -7
- package/dist/internal/KeyAuthorization.d.ts.map +1 -1
- package/dist/internal/KeyAuthorization.js +2 -26
- package/dist/internal/KeyAuthorization.js.map +1 -1
- package/dist/internal/RateLimit.d.ts +4 -4
- package/dist/internal/RateLimit.d.ts.map +1 -1
- package/dist/internal/RateLimit.js +6 -5
- package/dist/internal/RateLimit.js.map +1 -1
- package/package.json +1 -1
- package/src/app/components/Grant.tsx +5 -16
- package/src/app/routes/[_].flows.tsx +6 -127
- package/src/app/routes/login.tsx +12 -1
- package/src/app/screens/SignIn.tsx +2 -2
- package/src/internal/ErrorResponse.ts +28 -3
- package/src/internal/KeyAuthorization.ts +2 -28
- package/src/internal/RateLimit.ts +6 -5
- package/dist/app/server/assets/router-DHNhpddA.js +0 -7
- package/dist/app/server/assets/router-DHNhpddA.js.map +0 -1
- package/dist/app/server/assets/router-aoNinkjH.css +0 -1
|
@@ -322,10 +322,9 @@ const email = 'user@example.com'
|
|
|
322
322
|
/** The sample refusal of an upstream service, which the failure flows show. */
|
|
323
323
|
const unavailable = 'An upstream service is unavailable. Retry later.'
|
|
324
324
|
|
|
325
|
-
/** The key that the samples request: 100 USD a day for a week, in pathUSD
|
|
325
|
+
/** The key that the samples request: 100 USD a day for a week, in pathUSD. */
|
|
326
326
|
function key(): Approval.Key {
|
|
327
327
|
return {
|
|
328
|
-
chain: { id: 4217, name: 'Tempo Mainnet', testnet: false },
|
|
329
328
|
expiry: Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60,
|
|
330
329
|
limits: [
|
|
331
330
|
{
|
|
@@ -338,14 +337,6 @@ function key(): Approval.Key {
|
|
|
338
337
|
}
|
|
339
338
|
}
|
|
340
339
|
|
|
341
|
-
/** The sample key on Tempo testnet, whose card names the chain. */
|
|
342
|
-
function testnetKey(): Approval.Key {
|
|
343
|
-
return {
|
|
344
|
-
...key(),
|
|
345
|
-
chain: { id: 42431, name: 'Tempo Testnet (Moderato)', testnet: true },
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
340
|
/** The props that `Approval` takes for a key, before a decision. */
|
|
350
341
|
function approval(): Approval.Props {
|
|
351
342
|
return {
|
|
@@ -826,7 +817,7 @@ function sections(): readonly Section[] {
|
|
|
826
817
|
name: 'Deposit (rate limited)',
|
|
827
818
|
screen: (
|
|
828
819
|
<Deposit
|
|
829
|
-
error="Too many requests.
|
|
820
|
+
error="Too many requests. Try again in 1 minute."
|
|
830
821
|
heading="h4"
|
|
831
822
|
/>
|
|
832
823
|
),
|
|
@@ -910,46 +901,6 @@ function sections(): readonly Section[] {
|
|
|
910
901
|
],
|
|
911
902
|
title: 'Sign-in that grants a key',
|
|
912
903
|
},
|
|
913
|
-
{
|
|
914
|
-
description:
|
|
915
|
-
'A key on a chain other than Tempo mainnet names its chain on the sign-in page, since its tokens hold no real value. The flow is otherwise the same as for a mainnet key.',
|
|
916
|
-
nodes: [
|
|
917
|
-
{
|
|
918
|
-
...keyedEntry,
|
|
919
|
-
detail: 'GET /authorize?…&key_authorization, chainId 0xa5bf',
|
|
920
|
-
},
|
|
921
|
-
{
|
|
922
|
-
edge: '302 /oauth2/authorize, 302 /login?…&sig, GET /login: request',
|
|
923
|
-
name: 'Sign in (testnet key)',
|
|
924
|
-
screen: (
|
|
925
|
-
<SignIn
|
|
926
|
-
{...signIn()}
|
|
927
|
-
request={{ ...signInRequest(), key: testnetKey() }}
|
|
928
|
-
/>
|
|
929
|
-
),
|
|
930
|
-
},
|
|
931
|
-
{
|
|
932
|
-
edge: 'POST /v1/auth/code',
|
|
933
|
-
name: 'Check your email',
|
|
934
|
-
screen: <SignIn {...signIn()} email={email} />,
|
|
935
|
-
},
|
|
936
|
-
{
|
|
937
|
-
edge: 'POST /v1/auth/code/verify with oauth_query: 200, grants the key',
|
|
938
|
-
name: 'Check your email (accepted)',
|
|
939
|
-
screen: <SignIn {...signIn()} email={email} verified />,
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
detail: 'GET redirect_uri?code&state',
|
|
943
|
-
edge: 'after 500 ms, redirect',
|
|
944
|
-
name: 'Web app callback',
|
|
945
|
-
},
|
|
946
|
-
{
|
|
947
|
-
...tokenExit,
|
|
948
|
-
detail: 'Tokens, account, and key_authorization',
|
|
949
|
-
},
|
|
950
|
-
],
|
|
951
|
-
title: 'Sign-in that grants a testnet key',
|
|
952
|
-
},
|
|
953
904
|
{
|
|
954
905
|
description:
|
|
955
906
|
'On the sign-in page, the passkey’s challenge is the digest of the request’s key. One tap signs the user in and signs the key, for an account that this passkey owns, or that Privy or secp256k1 owns.',
|
|
@@ -1391,33 +1342,6 @@ function sections(): readonly Section[] {
|
|
|
1391
1342
|
],
|
|
1392
1343
|
title: 'Approval of a key',
|
|
1393
1344
|
},
|
|
1394
|
-
{
|
|
1395
|
-
description:
|
|
1396
|
-
'A key on a chain other than Tempo mainnet names its chain on the approval page, since its tokens hold no real value.',
|
|
1397
|
-
nodes: [
|
|
1398
|
-
{
|
|
1399
|
-
...redirectEntry,
|
|
1400
|
-
detail: 'GET /authorize?…&key_authorization, chainId 0xa5bf',
|
|
1401
|
-
},
|
|
1402
|
-
{
|
|
1403
|
-
edge: '302 /oauth2/authorize, 302 /authorize?…&sig',
|
|
1404
|
-
name: 'Authorize this app (testnet key)',
|
|
1405
|
-
screen: (
|
|
1406
|
-
<Approval {...approval()} keyAuthorization={testnetKey()} />
|
|
1407
|
-
),
|
|
1408
|
-
},
|
|
1409
|
-
{
|
|
1410
|
-
detail: 'GET redirect_uri?code&state',
|
|
1411
|
-
edge: 'Approve, POST /v1/authorize/consent',
|
|
1412
|
-
name: 'Web app callback',
|
|
1413
|
-
},
|
|
1414
|
-
{
|
|
1415
|
-
...tokenExit,
|
|
1416
|
-
detail: 'Tokens, account, and key_authorization',
|
|
1417
|
-
},
|
|
1418
|
-
],
|
|
1419
|
-
title: 'Approval of a testnet key',
|
|
1420
|
-
},
|
|
1421
1345
|
{
|
|
1422
1346
|
description:
|
|
1423
1347
|
'A passkey owns the account, so the approval returns the passkey step. The passkey signs the key’s digest, and the page approves again.',
|
|
@@ -1970,51 +1894,6 @@ function sections(): readonly Section[] {
|
|
|
1970
1894
|
],
|
|
1971
1895
|
title: 'Device code, signed out',
|
|
1972
1896
|
},
|
|
1973
|
-
{
|
|
1974
|
-
description:
|
|
1975
|
-
'A key on a chain other than Tempo mainnet names its chain on the device page, since its tokens hold no real value.',
|
|
1976
|
-
nodes: [
|
|
1977
|
-
{
|
|
1978
|
-
...loginEntry,
|
|
1979
|
-
detail:
|
|
1980
|
-
'POST /v1/device/authorize with key_authorization, chainId 0xa5bf',
|
|
1981
|
-
},
|
|
1982
|
-
{
|
|
1983
|
-
detail: 'GET /device?code',
|
|
1984
|
-
edge: 'Shows verification_uri_complete',
|
|
1985
|
-
name: 'Browser',
|
|
1986
|
-
},
|
|
1987
|
-
{
|
|
1988
|
-
edge: '200 device page, signed in',
|
|
1989
|
-
name: 'Authorize a device (testnet key)',
|
|
1990
|
-
screen: (
|
|
1991
|
-
<DeviceApproval
|
|
1992
|
-
{...deviceApproval()}
|
|
1993
|
-
request={{
|
|
1994
|
-
...deviceRequest(),
|
|
1995
|
-
key_authorization: testnetKey(),
|
|
1996
|
-
}}
|
|
1997
|
-
/>
|
|
1998
|
-
),
|
|
1999
|
-
},
|
|
2000
|
-
{
|
|
2001
|
-
edge: 'POST /v1/device/approve',
|
|
2002
|
-
name: 'Authorization successful',
|
|
2003
|
-
screen: (
|
|
2004
|
-
<DeviceApproval
|
|
2005
|
-
{...deviceApproval()}
|
|
2006
|
-
request={{
|
|
2007
|
-
...deviceRequest(),
|
|
2008
|
-
key_authorization: testnetKey(),
|
|
2009
|
-
}}
|
|
2010
|
-
status="approved"
|
|
2011
|
-
/>
|
|
2012
|
-
),
|
|
2013
|
-
},
|
|
2014
|
-
loginExit,
|
|
2015
|
-
],
|
|
2016
|
-
title: 'Device code, testnet key',
|
|
2017
|
-
},
|
|
2018
1897
|
{
|
|
2019
1898
|
description:
|
|
2020
1899
|
'A user who opens the bare `verification_uri` types the code that the terminal shows.',
|
|
@@ -2441,7 +2320,7 @@ function sections(): readonly Section[] {
|
|
|
2441
2320
|
<DeviceApproval
|
|
2442
2321
|
{...deviceApproval()}
|
|
2443
2322
|
code="BDWP-HQPK"
|
|
2444
|
-
error="Too many requests.
|
|
2323
|
+
error="Too many requests. Try again in 1 minute."
|
|
2445
2324
|
invalid
|
|
2446
2325
|
/>
|
|
2447
2326
|
),
|
|
@@ -2626,7 +2505,7 @@ function sections(): readonly Section[] {
|
|
|
2626
2505
|
},
|
|
2627
2506
|
{
|
|
2628
2507
|
description:
|
|
2629
|
-
'A resent code shows Code sent on the button,
|
|
2508
|
+
'A resent code shows Code sent on the disabled button for 5 seconds, then Resend code again. A hidden status announces the send. The code field keeps its value.',
|
|
2630
2509
|
nodes: [
|
|
2631
2510
|
{ detail: 'GET /login', name: 'Browser opens sign-in' },
|
|
2632
2511
|
{
|
|
@@ -2649,7 +2528,7 @@ function sections(): readonly Section[] {
|
|
|
2649
2528
|
<SignIn
|
|
2650
2529
|
{...signIn()}
|
|
2651
2530
|
email={email}
|
|
2652
|
-
error="Too many requests.
|
|
2531
|
+
error="Too many requests. Try again in 1 minute."
|
|
2653
2532
|
/>
|
|
2654
2533
|
),
|
|
2655
2534
|
},
|
|
@@ -2712,7 +2591,7 @@ function sections(): readonly Section[] {
|
|
|
2712
2591
|
screen: (
|
|
2713
2592
|
<Approval
|
|
2714
2593
|
{...approval()}
|
|
2715
|
-
error="Too many requests.
|
|
2594
|
+
error="Too many requests. Try again in 1 minute."
|
|
2716
2595
|
/>
|
|
2717
2596
|
),
|
|
2718
2597
|
},
|
package/src/app/routes/login.tsx
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { useMutation } from '@tanstack/react-query'
|
|
8
8
|
import { createFileRoute, useRouter } from '@tanstack/react-router'
|
|
9
9
|
import { type InferResponseType, parseResponse } from 'hono/client'
|
|
10
|
-
import { type FormEvent, useState } from 'react'
|
|
10
|
+
import { type FormEvent, useEffect, useState } from 'react'
|
|
11
11
|
import { Authentication } from 'webauthx/client'
|
|
12
12
|
import * as Client from '../lib/Client.js'
|
|
13
13
|
import * as Loader from '../lib/Loader.js'
|
|
@@ -104,6 +104,14 @@ function Page(props: Page.Props) {
|
|
|
104
104
|
})
|
|
105
105
|
const resend = useMutation({ mutationFn: sendCode })
|
|
106
106
|
const send = useMutation({ mutationFn: sendCode })
|
|
107
|
+
|
|
108
|
+
// The confirmation of a resent code clears after a short time, so the button offers a resend again.
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!resend.isSuccess) return
|
|
111
|
+
const timer = window.setTimeout(() => resend.reset(), sentDelay)
|
|
112
|
+
return () => window.clearTimeout(timer)
|
|
113
|
+
}, [resend.isSuccess, resend.reset])
|
|
114
|
+
|
|
107
115
|
const verify = useMutation({
|
|
108
116
|
async mutationFn(variables: { code: string; email: string }) {
|
|
109
117
|
// The link's passkey signs again, so a page left at the email step links nothing for the next
|
|
@@ -323,6 +331,9 @@ declare namespace Page {
|
|
|
323
331
|
}
|
|
324
332
|
}
|
|
325
333
|
|
|
334
|
+
/** How long the button shows "Code sent" after a resent code, in milliseconds. */
|
|
335
|
+
const sentDelay = 5000
|
|
336
|
+
|
|
326
337
|
/** How long an accepted code shows green before the sign-in continues, in milliseconds. */
|
|
327
338
|
const verifiedDelay = 500
|
|
328
339
|
|
|
@@ -107,7 +107,7 @@ export function SignIn(props: SignIn.Props): ReactNode {
|
|
|
107
107
|
<div {...styles.links()}>
|
|
108
108
|
<Button
|
|
109
109
|
disabled={
|
|
110
|
-
props.resend
|
|
110
|
+
props.resend !== 'idle' || props.verifying || props.verified
|
|
111
111
|
}
|
|
112
112
|
onClick={props.onResend}
|
|
113
113
|
variant="text"
|
|
@@ -260,7 +260,7 @@ export declare namespace SignIn {
|
|
|
260
260
|
key: Approval.Key
|
|
261
261
|
}
|
|
262
262
|
| undefined
|
|
263
|
-
/** The progress of a resent code. */
|
|
263
|
+
/** The progress of a resent code. The resend button is disabled unless it is `idle`. */
|
|
264
264
|
resend: 'idle' | 'pending' | 'sent'
|
|
265
265
|
/** Whether the first code is being sent. */
|
|
266
266
|
sending: boolean
|
|
@@ -13,7 +13,7 @@ import * as z from 'zod'
|
|
|
13
13
|
import * as Log from './Log.js'
|
|
14
14
|
|
|
15
15
|
/** The page that explains each `reason`, for `error_uri`. */
|
|
16
|
-
const docs = 'https://github.com/tempoxyz/
|
|
16
|
+
const docs = 'https://github.com/tempoxyz/id/blob/main/docs/errors.md'
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Every refusal Tempo ID returns, by `reason`: its OAuth `error` code, its HTTP status, and what it
|
|
@@ -393,7 +393,7 @@ export class RateLimitedError extends define('rate_limited') {
|
|
|
393
393
|
constructor(options: RateLimitedError.Options = {}) {
|
|
394
394
|
const { retryAfter } = options
|
|
395
395
|
super({
|
|
396
|
-
error_description: `Rate limited by an upstream service.
|
|
396
|
+
error_description: `Rate limited by an upstream service. Try again ${retryAfter ? `in ${wait({ seconds: retryAfter })}` : 'later'}.`,
|
|
397
397
|
...(retryAfter ? { meta: { retryAfter } } : {}),
|
|
398
398
|
})
|
|
399
399
|
this.retryAfter = retryAfter
|
|
@@ -631,7 +631,7 @@ export namespace schema {
|
|
|
631
631
|
field: 'post_logout_redirect_uri',
|
|
632
632
|
},
|
|
633
633
|
rate_limited: {
|
|
634
|
-
error_description: 'Too many requests.
|
|
634
|
+
error_description: 'Too many requests. Try again in 30 seconds.',
|
|
635
635
|
},
|
|
636
636
|
rejected: {
|
|
637
637
|
error_description:
|
|
@@ -852,3 +852,28 @@ export function json<const reason extends Reason>(
|
|
|
852
852
|
c.header('retry-after', String(error.retryAfter))
|
|
853
853
|
return c.json(response, reasons[response.reason].status) as Json<reason>
|
|
854
854
|
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Returns a wait of `seconds` in the largest whole unit, rounded up, for an `error_description`:
|
|
858
|
+
* "45 seconds", "5 minutes", or "1 hour".
|
|
859
|
+
*/
|
|
860
|
+
export function wait(options: wait.Options) {
|
|
861
|
+
const { seconds } = options
|
|
862
|
+
const [value, unit] = (() => {
|
|
863
|
+
if (seconds < 60) return [seconds, 'second'] as const
|
|
864
|
+
if (seconds < 60 * 60) return [Math.ceil(seconds / 60), 'minute'] as const
|
|
865
|
+
return [Math.ceil(seconds / (60 * 60)), 'hour'] as const
|
|
866
|
+
})()
|
|
867
|
+
return new Intl.NumberFormat('en', {
|
|
868
|
+
style: 'unit',
|
|
869
|
+
unit,
|
|
870
|
+
unitDisplay: 'long',
|
|
871
|
+
}).format(value)
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
export declare namespace wait {
|
|
875
|
+
type Options = {
|
|
876
|
+
/** The wait, in whole seconds. */
|
|
877
|
+
seconds: number
|
|
878
|
+
}
|
|
879
|
+
}
|
|
@@ -349,23 +349,6 @@ export namespace schema {
|
|
|
349
349
|
'The Tempo Account the request names. Absent when the request names none.',
|
|
350
350
|
examples: ['0x9a073914db0d149375ac2b7fbb72c68c0780fb5f'],
|
|
351
351
|
}),
|
|
352
|
-
chain: z
|
|
353
|
-
.object({
|
|
354
|
-
id: z.number().meta({
|
|
355
|
-
description: "The chain's ID.",
|
|
356
|
-
examples: [4217, 42431],
|
|
357
|
-
}),
|
|
358
|
-
name: z.string().meta({
|
|
359
|
-
description: "The chain's name, from Viem's chain definitions.",
|
|
360
|
-
examples: ['Tempo Mainnet', 'Tempo Testnet (Moderato)'],
|
|
361
|
-
}),
|
|
362
|
-
testnet: z.boolean().meta({
|
|
363
|
-
description:
|
|
364
|
-
'True on every chain but Tempo mainnet, whose tokens hold no real value.',
|
|
365
|
-
examples: [false, true],
|
|
366
|
-
}),
|
|
367
|
-
})
|
|
368
|
-
.meta({ description: 'The chain the key acts on.' }),
|
|
369
352
|
expiry: z.number().meta({
|
|
370
353
|
description: 'Unix seconds.',
|
|
371
354
|
examples: [1893456000],
|
|
@@ -1092,13 +1075,10 @@ export namespace checkHeadless {
|
|
|
1092
1075
|
}
|
|
1093
1076
|
|
|
1094
1077
|
/**
|
|
1095
|
-
* What a `key` that passes `check` grants, as the approval screens show it: its
|
|
1096
|
-
*
|
|
1078
|
+
* What a `key` that passes `check` grants, as the approval screens show it: its limits totaled per
|
|
1079
|
+
* currency and period, and its expiry.
|
|
1097
1080
|
*/
|
|
1098
1081
|
export function describe(key: Key): Description {
|
|
1099
|
-
// `check` accepts only tokens listed on a Tempo chain, so the key's chain is one of them.
|
|
1100
|
-
const chain = chains.find((entry) => entry.id === Number(key.chainId))!
|
|
1101
|
-
|
|
1102
1082
|
// The screens state spending per currency, so limits on tokens of one currency and period add up.
|
|
1103
1083
|
const totals = new Map<
|
|
1104
1084
|
string,
|
|
@@ -1145,12 +1125,6 @@ export function describe(key: Key): Description {
|
|
|
1145
1125
|
|
|
1146
1126
|
return {
|
|
1147
1127
|
account: key.account,
|
|
1148
|
-
chain: {
|
|
1149
|
-
id: chain.id,
|
|
1150
|
-
// Viem names the local chain `Tempo`, the same as mainnet.
|
|
1151
|
-
name: chain.id === tempoLocalnet.id ? 'Tempo Localnet' : chain.name,
|
|
1152
|
-
testnet: chain.id !== tempo.id,
|
|
1153
|
-
},
|
|
1154
1128
|
expiry: key.expiry,
|
|
1155
1129
|
limits: [...totals.values()].map((total) => ({
|
|
1156
1130
|
amount: Value.format(total.amount, total.decimals),
|
|
@@ -22,7 +22,8 @@ export class LimitedError extends ErrorResponse.define('rate_limited') {
|
|
|
22
22
|
|
|
23
23
|
constructor(options: LimitedError.Options) {
|
|
24
24
|
super({
|
|
25
|
-
error_description: `Too many requests.
|
|
25
|
+
error_description: `Too many requests. Try again in ${ErrorResponse.wait({ seconds: options.retryAfter })}.`,
|
|
26
|
+
meta: { retryAfter: options.retryAfter },
|
|
26
27
|
})
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -294,10 +295,10 @@ export declare namespace policy {
|
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
/**
|
|
297
|
-
* Returns a 429 response with `Retry-After
|
|
298
|
-
* quota left (`r=0`) for `retryAfter` seconds (`t`). The body names no key
|
|
299
|
-
* nothing about the key, such as whether an account exists. It reads no
|
|
300
|
-
* loader's context can call it too.
|
|
298
|
+
* Returns a 429 response with `Retry-After` and `meta: { retryAfter }`, and `RateLimit` naming the
|
|
299
|
+
* spent `policy` with no quota left (`r=0`) for `retryAfter` seconds (`t`). The body names no key
|
|
300
|
+
* or limit, so it reveals nothing about the key, such as whether an account exists. It reads no
|
|
301
|
+
* binding, so a page loader's context can call it too.
|
|
301
302
|
*/
|
|
302
303
|
export function refuse(c: Context, options: refuse.Options) {
|
|
303
304
|
const { policy, retryAfter } = options
|