mppx 0.18.0 → 0.19.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/CHANGELOG.md +39 -0
- package/dist/Currency.d.ts +59 -0
- package/dist/Currency.js +60 -0
- package/dist/Errors.d.ts +24 -4
- package/dist/Errors.js +28 -10
- package/dist/cli/cli.js +135 -135
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/plugins/tempo.js +13 -1
- package/dist/client/internal/Fetch.d.ts +5 -0
- package/dist/client/internal/Fetch.js +7 -0
- package/dist/cloudflare/ChannelStore.d.ts +1 -2
- package/dist/cloudflare/ChannelStore.js +14 -20
- package/dist/cloudflare/Channels.d.ts +20 -2
- package/dist/cloudflare/Channels.js +47 -4
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/discovery/Discovery.d.ts +116 -9
- package/dist/discovery/Discovery.js +169 -0
- package/dist/evm/server/Charge.js +2 -3
- package/dist/evm/server/Methods.d.ts +1 -1
- package/dist/evm/server/Methods.js +3 -2
- package/dist/extensions/identity/Types.d.ts +26 -0
- package/dist/extensions/identity/attestation/Token.d.ts +6 -4
- package/dist/extensions/identity/attestation/Token.js +11 -5
- package/dist/extensions/identity/email-otp/client/index.js +4 -4
- package/dist/extensions/identity/index.d.ts +6 -0
- package/dist/extensions/identity/index.js +6 -0
- package/dist/extensions/identity/internal/HttpMessageSignature.d.ts +2 -2
- package/dist/extensions/identity/internal/HttpMessageSignature.js +13 -10
- package/dist/extensions/identity/{web-bot-auth/internal → internal}/JwkThumbprint.js +1 -1
- package/dist/extensions/identity/internal/Signer.d.ts +20 -0
- package/dist/extensions/identity/internal/Signer.js +94 -0
- package/dist/extensions/identity/link/Constants.d.ts +102 -0
- package/dist/extensions/identity/link/Constants.js +16 -0
- package/dist/extensions/identity/link/client/index.d.ts +80 -0
- package/dist/extensions/identity/link/client/index.js +211 -0
- package/dist/extensions/identity/link/index.d.ts +12 -0
- package/dist/extensions/identity/link/index.js +12 -0
- package/dist/extensions/identity/link/server/index.d.ts +124 -0
- package/dist/extensions/identity/link/server/index.js +518 -0
- package/dist/extensions/identity/persona/Constants.d.ts +24 -0
- package/dist/extensions/identity/persona/Constants.js +24 -0
- package/dist/extensions/identity/persona/Did.d.ts +24 -0
- package/dist/extensions/identity/persona/Did.js +24 -0
- package/dist/extensions/identity/persona/Types.d.ts +21 -0
- package/dist/extensions/identity/persona/Types.js +2 -0
- package/dist/extensions/identity/persona/index.d.ts +10 -0
- package/dist/extensions/identity/persona/index.js +9 -0
- package/dist/extensions/identity/persona/server/index.d.ts +152 -0
- package/dist/extensions/identity/persona/server/index.js +263 -0
- package/dist/extensions/identity/tap/client/index.d.ts +6 -2
- package/dist/extensions/identity/tap/client/index.js +2 -0
- package/dist/extensions/identity/tempo/Constants.d.ts +14 -0
- package/dist/extensions/identity/tempo/Constants.js +14 -0
- package/dist/extensions/identity/tempo/Types.d.ts +31 -0
- package/dist/extensions/identity/tempo/Types.js +2 -0
- package/dist/extensions/identity/tempo/client/index.d.ts +34 -0
- package/dist/extensions/identity/tempo/client/index.js +60 -0
- package/dist/extensions/identity/tempo/index.d.ts +5 -0
- package/dist/extensions/identity/tempo/index.js +4 -0
- package/dist/extensions/identity/tempo/internal/Jwt.d.ts +36 -0
- package/dist/extensions/identity/tempo/internal/Jwt.js +114 -0
- package/dist/extensions/identity/tempo/server/index.d.ts +65 -0
- package/dist/extensions/identity/tempo/server/index.js +247 -0
- package/dist/extensions/identity/web-bot-auth/client/index.d.ts +6 -4
- package/dist/extensions/identity/web-bot-auth/client/index.js +7 -5
- package/dist/extensions/identity/web-bot-auth/server/index.js +1 -1
- package/dist/extensions/identity/world/Constants.d.ts +50 -0
- package/dist/extensions/identity/world/Constants.js +50 -0
- package/dist/extensions/identity/world/Types.d.ts +52 -0
- package/dist/extensions/identity/world/Types.js +2 -0
- package/dist/extensions/identity/world/client/index.d.ts +103 -0
- package/dist/extensions/identity/world/client/index.js +208 -0
- package/dist/extensions/identity/world/index.d.ts +6 -0
- package/dist/extensions/identity/world/index.js +5 -0
- package/dist/extensions/identity/world/internal/Idp.d.ts +50 -0
- package/dist/extensions/identity/world/internal/Idp.js +265 -0
- package/dist/extensions/identity/world/issuer/index.d.ts +120 -0
- package/dist/extensions/identity/world/issuer/index.js +520 -0
- package/dist/extensions/identity/world/server/index.d.ts +49 -0
- package/dist/extensions/identity/world/server/index.js +63 -0
- package/dist/identity/Headers.d.ts +6 -1
- package/dist/identity/Headers.js +11 -1
- package/dist/identity/Server.js +2 -0
- package/dist/identity/Types.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/proxy/internal/Headers.js +4 -4
- package/dist/server/Mppx.js +6 -2
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/client/Charge.d.ts +11 -8
- package/dist/tempo/client/Charge.js +85 -18
- package/dist/tempo/index.d.ts +4 -0
- package/dist/tempo/index.js +4 -0
- package/dist/tempo/internal/auto-swap.d.ts +6 -5
- package/dist/tempo/internal/auto-swap.js +17 -2
- package/dist/tempo/internal/currencies.d.ts +5 -4
- package/dist/tempo/internal/currencies.js +13 -9
- package/dist/tempo/internal/defaults.d.ts +7 -0
- package/dist/tempo/internal/defaults.js +7 -0
- package/dist/tempo/internal/fee-payer.js +8 -2
- package/dist/tempo/internal/machine-token-charge.d.ts +52 -0
- package/dist/tempo/internal/machine-token-charge.js +82 -1
- package/dist/tempo/internal/zone.d.ts +27 -0
- package/dist/tempo/internal/zone.js +54 -7
- package/dist/tempo/server/Charge.js +59 -2
- package/dist/tempo/server/Methods.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/transport.d.ts +1 -1
- package/dist/tempo/server/internal/transport.js +9 -16
- package/dist/tempo/session/client/CredentialState.js +31 -0
- package/dist/tempo/session/client/Session.d.ts +12 -6
- package/dist/tempo/session/client/Session.js +64 -18
- package/dist/tempo/session/server/ChannelStore.d.ts +22 -1
- package/dist/tempo/session/server/ChannelStore.js +58 -8
- package/dist/tempo/session/server/CloseSupervisor.d.ts +5 -1
- package/dist/tempo/session/server/CloseSupervisor.js +110 -12
- package/dist/tempo/session/server/CredentialVerification.d.ts +2 -0
- package/dist/tempo/session/server/CredentialVerification.js +6 -32
- package/dist/tempo/session/server/Session.js +6 -3
- package/dist/tempo/session/server/Settlement.d.ts +7 -0
- package/dist/tempo/session/server/Settlement.js +36 -6
- package/dist/tempo/session/server/Sse.d.ts +2 -0
- package/dist/tempo/session/server/Sse.js +12 -12
- package/dist/tempo/subscription/KeyAuthorization.d.ts +1 -1
- package/dist/tempo/subscription/KeyAuthorization.js +1 -1
- package/dist/x402/Assets.d.ts +14 -5
- package/dist/x402/Assets.js +11 -16
- package/package.json +23 -3
- /package/dist/extensions/identity/{web-bot-auth/internal → internal}/JwkThumbprint.d.ts +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type * as Challenge from '../../../../Challenge.js';
|
|
3
|
+
import type * as Credential from '../../../../Credential.js';
|
|
4
|
+
import type * as Identity from '../../../../identity/Types.js';
|
|
5
|
+
import type { MaybePromise } from '../../../../internal/types.js';
|
|
6
|
+
import type * as Store from '../../../../Store.js';
|
|
7
|
+
import type * as Types from '../Types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Persona client for one Persona organization and inquiry template.
|
|
10
|
+
*
|
|
11
|
+
* - `startInquiry` starts an inquiry for a reference ID and returns a one-time link to
|
|
12
|
+
* Persona's hosted flow.
|
|
13
|
+
* - `paymentCheck` requires an approved inquiry on a route's paid retry, keyed by the payer.
|
|
14
|
+
* - `verifier` requires one before any 402, keyed by your own session.
|
|
15
|
+
*
|
|
16
|
+
* Link a wallet to a person by proving they own it (`verifyWallet`) before you start an
|
|
17
|
+
* inquiry with its DID as the reference ID. Otherwise anyone can complete KYC as themselves
|
|
18
|
+
* for someone else's wallet.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const persona = Persona.Server.create({ apiKey: env.PERSONA_API_KEY, templateId: 'itmpl_…' })
|
|
23
|
+
*
|
|
24
|
+
* app.post('/kyc', async (request) => {
|
|
25
|
+
* const referenceId = await Persona.Server.verifyWallet({ ...(await request.json()), nonce })
|
|
26
|
+
* return Response.json(await persona.startInquiry({ referenceId }))
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* const kyc = persona.paymentCheck({
|
|
30
|
+
* referenceId: ({ request }) => session(request)?.wallet, // a DID from verifyWallet
|
|
31
|
+
* onboarding: 'https://api.example/kyc',
|
|
32
|
+
* cache: Store.memory(),
|
|
33
|
+
* })
|
|
34
|
+
* mppx.charge({ amount: '1', identity: { payment: kyc } })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function create(config: create.Config): Persona;
|
|
38
|
+
export declare namespace create {
|
|
39
|
+
type Config = {
|
|
40
|
+
/** Persona API key. Keep it on the server. */
|
|
41
|
+
readonly apiKey: string;
|
|
42
|
+
/** Inquiry template (`itmpl_…`) to start inquiries from and to accept them from. */
|
|
43
|
+
readonly templateId?: string | undefined;
|
|
44
|
+
/** Persona API origin. @default 'https://api.withpersona.com' */
|
|
45
|
+
readonly apiUrl?: string | undefined;
|
|
46
|
+
/** `Persona-Version` header. @default '2023-01-05' */
|
|
47
|
+
readonly apiVersion?: string | undefined;
|
|
48
|
+
/** Fetch used for the Persona API. */
|
|
49
|
+
readonly fetch?: typeof globalThis.fetch | undefined;
|
|
50
|
+
/** Milliseconds before a Persona API call is abandoned. @default 5000 */
|
|
51
|
+
readonly timeout?: number | undefined;
|
|
52
|
+
};
|
|
53
|
+
/** What a payment check's `referenceId` receives. */
|
|
54
|
+
type PaymentParameters = {
|
|
55
|
+
readonly request: Request;
|
|
56
|
+
readonly challenge: Challenge.Challenge;
|
|
57
|
+
readonly credential?: Credential.Credential | undefined;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** A Persona client from {@link create}. */
|
|
61
|
+
export type Persona = {
|
|
62
|
+
/** Starts an inquiry for a reference ID and returns a one-time link to Persona's hosted flow. */
|
|
63
|
+
readonly startInquiry: (parameters: {
|
|
64
|
+
/** Reference ID to match later, such as `Persona.did(…)` of a wallet the person proved they own. */
|
|
65
|
+
readonly referenceId: string;
|
|
66
|
+
/** Inquiry template, overriding the client's. */
|
|
67
|
+
readonly templateId?: string | undefined;
|
|
68
|
+
/** Where Persona sends the person after the flow. */
|
|
69
|
+
readonly redirectUri?: string | undefined;
|
|
70
|
+
}) => Promise<Types.StartedInquiry>;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a payment check that requires the payer to have passed Persona KYC.
|
|
73
|
+
*
|
|
74
|
+
* Every 402 of the route advertises `Identity-Required: kyc;issuer="https://api.withpersona.com"`.
|
|
75
|
+
* On the paid retry, before the Credential settles, it accepts the most recent inquiry whose
|
|
76
|
+
* reference ID `referenceId` returns. Derive it from something your server authenticated, such
|
|
77
|
+
* as your own session, or a payer address your payment method verified. A Credential's
|
|
78
|
+
* `source` is client-supplied and some payment flows do not check it against the payer, so
|
|
79
|
+
* returning it as is lets a payer present another wallet's KYC. On a route with `authorize`,
|
|
80
|
+
* the check runs without a Credential.
|
|
81
|
+
*
|
|
82
|
+
* No payer is `missing` (401), no accepted inquiry `forbidden` (403), both with `onboarding`
|
|
83
|
+
* in a `Link` header; a Persona API failure is `unavailable` (503).
|
|
84
|
+
*/
|
|
85
|
+
readonly paymentCheck: (options: LookupOptions & {
|
|
86
|
+
/** Returns the payer's authenticated reference ID, or `undefined` when there is none. */
|
|
87
|
+
readonly referenceId: (parameters: create.PaymentParameters) => MaybePromise<string | undefined>;
|
|
88
|
+
}) => Identity.PaymentCheck<Types.VerifiedInquiry>;
|
|
89
|
+
/**
|
|
90
|
+
* Returns a request-stage verifier that requires an approved inquiry before any 402, for a
|
|
91
|
+
* caller `referenceId` identifies from the request, such as by your own session.
|
|
92
|
+
*/
|
|
93
|
+
readonly verifier: (options: LookupOptions & {
|
|
94
|
+
/** Returns the caller's reference ID, or `undefined` when there is none. */
|
|
95
|
+
readonly referenceId: (request: Request) => MaybePromise<string | undefined>;
|
|
96
|
+
}) => Identity.Verifier<Types.VerifiedInquiry>;
|
|
97
|
+
};
|
|
98
|
+
/** Options shared by {@link Persona.paymentCheck} and {@link Persona.verifier}. */
|
|
99
|
+
export type LookupOptions = {
|
|
100
|
+
/** Accepted inquiry statuses. @default ['approved'] */
|
|
101
|
+
readonly statuses?: readonly Types.InquiryStatus[] | undefined;
|
|
102
|
+
/** Oldest accepted verification, in seconds since the inquiry was decisioned or completed. */
|
|
103
|
+
readonly maxAge?: number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Where a rejected payer starts KYC, sent as `Link: <url>; rel="kyc"` with 401 and 403
|
|
106
|
+
* responses, such as your endpoint that calls `startInquiry`.
|
|
107
|
+
*/
|
|
108
|
+
readonly onboarding?: string | ((parameters: {
|
|
109
|
+
readonly request: Request;
|
|
110
|
+
readonly referenceId: string | undefined;
|
|
111
|
+
}) => MaybePromise<string | undefined>) | undefined;
|
|
112
|
+
/** Caches approvals by reference ID, so a paid request skips the Persona API. */
|
|
113
|
+
readonly cache?: Store.Store | undefined;
|
|
114
|
+
/** Seconds an approval stays cached. @default 300 */
|
|
115
|
+
readonly cacheTtl?: number | undefined;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Verifies that the signer of `message` owns `address` and returns the wallet's reference ID
|
|
119
|
+
* (`Persona.did`), to start an inquiry with. `message` must contain `nonce`, a single-use
|
|
120
|
+
* value your server issued for this person, so a signature cannot be replayed, and the wallet's
|
|
121
|
+
* DID, so the signer commits to the chain.
|
|
122
|
+
*
|
|
123
|
+
* Without `verify`, it accepts EOA signatures only. Pass `verify` for smart accounts, such as
|
|
124
|
+
* viem's `publicClient.verifyMessage` on `chainId`, which supports ERC-1271 and ERC-6492.
|
|
125
|
+
*/
|
|
126
|
+
export declare function verifyWallet(parameters: verifyWallet.Parameters): Promise<string>;
|
|
127
|
+
export declare namespace verifyWallet {
|
|
128
|
+
type Parameters = {
|
|
129
|
+
/** Wallet address the person claims. */
|
|
130
|
+
readonly address: Address;
|
|
131
|
+
/** Chain ID of the wallet, such as `4217` for Tempo mainnet. */
|
|
132
|
+
readonly chainId: number;
|
|
133
|
+
/** Message the wallet signed, containing `nonce` and the wallet's DID (`Persona.did`). */
|
|
134
|
+
readonly message: string;
|
|
135
|
+
/** Signature over `message`. */
|
|
136
|
+
readonly signature: Hex;
|
|
137
|
+
/** Single-use value your server issued and the message must contain. */
|
|
138
|
+
readonly nonce: string;
|
|
139
|
+
/** Verifies the signature. Defaults to viem's `verifyMessage` (EOA only). */
|
|
140
|
+
readonly verify?: ((parameters: {
|
|
141
|
+
address: Address;
|
|
142
|
+
chainId: number;
|
|
143
|
+
message: string;
|
|
144
|
+
signature: Hex;
|
|
145
|
+
}) => Promise<boolean>) | undefined;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** A failed or malformed Persona API call. */
|
|
149
|
+
export declare class PersonaError extends Error {
|
|
150
|
+
readonly name = "PersonaError";
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { verifyMessage } from 'viem';
|
|
2
|
+
import { unwrapFetch } from '../../../../client/internal/Fetch.js';
|
|
3
|
+
import { Constants } from '../Constants.js';
|
|
4
|
+
import * as Did from '../Did.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Persona client for one Persona organization and inquiry template.
|
|
7
|
+
*
|
|
8
|
+
* - `startInquiry` starts an inquiry for a reference ID and returns a one-time link to
|
|
9
|
+
* Persona's hosted flow.
|
|
10
|
+
* - `paymentCheck` requires an approved inquiry on a route's paid retry, keyed by the payer.
|
|
11
|
+
* - `verifier` requires one before any 402, keyed by your own session.
|
|
12
|
+
*
|
|
13
|
+
* Link a wallet to a person by proving they own it (`verifyWallet`) before you start an
|
|
14
|
+
* inquiry with its DID as the reference ID. Otherwise anyone can complete KYC as themselves
|
|
15
|
+
* for someone else's wallet.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const persona = Persona.Server.create({ apiKey: env.PERSONA_API_KEY, templateId: 'itmpl_…' })
|
|
20
|
+
*
|
|
21
|
+
* app.post('/kyc', async (request) => {
|
|
22
|
+
* const referenceId = await Persona.Server.verifyWallet({ ...(await request.json()), nonce })
|
|
23
|
+
* return Response.json(await persona.startInquiry({ referenceId }))
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* const kyc = persona.paymentCheck({
|
|
27
|
+
* referenceId: ({ request }) => session(request)?.wallet, // a DID from verifyWallet
|
|
28
|
+
* onboarding: 'https://api.example/kyc',
|
|
29
|
+
* cache: Store.memory(),
|
|
30
|
+
* })
|
|
31
|
+
* mppx.charge({ amount: '1', identity: { payment: kyc } })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function create(config) {
|
|
35
|
+
const { apiKey, apiUrl = Constants.apiUrl, apiVersion = Constants.apiVersion, templateId, timeout = Constants.timeout, } = config;
|
|
36
|
+
if (!apiKey)
|
|
37
|
+
throw new TypeError('Persona.Server.create needs an apiKey.');
|
|
38
|
+
// AbortSignal.timeout throws on these at request time, and Node clamps delays above 2^31 - 1 ms
|
|
39
|
+
// to 1 ms: either would read as a Persona outage.
|
|
40
|
+
if (!Number.isSafeInteger(timeout) || timeout <= 0 || timeout > 2_147_483_647)
|
|
41
|
+
throw new TypeError('Persona.Server.create needs a positive integer timeout in milliseconds.');
|
|
42
|
+
// A digest of the API origin and key: identifies the Persona organization without storing the key.
|
|
43
|
+
const scope = digest(`${new URL(apiUrl).origin}\n${apiKey}`);
|
|
44
|
+
async function call(path, init = {}) {
|
|
45
|
+
// Unwrapped, and resolved per call: a Persona request must never pay a Payment Challenge,
|
|
46
|
+
// even when an mppx client polyfilled globalThis.fetch.
|
|
47
|
+
const fetch = unwrapFetch(config.fetch ?? globalThis.fetch);
|
|
48
|
+
const response = await fetch(new URL(path, apiUrl), {
|
|
49
|
+
...init,
|
|
50
|
+
// A redirect is a failure: never send the bearer key on, nor read another origin's body.
|
|
51
|
+
redirect: 'manual',
|
|
52
|
+
headers: {
|
|
53
|
+
Accept: 'application/json',
|
|
54
|
+
Authorization: `Bearer ${apiKey}`,
|
|
55
|
+
'Persona-Version': apiVersion,
|
|
56
|
+
...(init.body !== undefined && { 'Content-Type': 'application/json' }),
|
|
57
|
+
},
|
|
58
|
+
signal: AbortSignal.timeout(timeout),
|
|
59
|
+
});
|
|
60
|
+
// Never surface the upstream body: it may carry request details.
|
|
61
|
+
if (!response.ok)
|
|
62
|
+
throw new PersonaError(`The Persona API returned ${response.status}.`);
|
|
63
|
+
return response.json();
|
|
64
|
+
}
|
|
65
|
+
/** Returns the most recent accepted inquiry for a reference ID, or `undefined`. */
|
|
66
|
+
async function find(referenceId, options) {
|
|
67
|
+
const url = new URL(Constants.inquiriesPath, apiUrl);
|
|
68
|
+
url.searchParams.set('filter[reference-id]', referenceId);
|
|
69
|
+
url.searchParams.set('filter[status]', options.statuses.join(','));
|
|
70
|
+
if (templateId)
|
|
71
|
+
url.searchParams.set('filter[inquiry-template-id]', templateId);
|
|
72
|
+
url.searchParams.set('page[size]', '25');
|
|
73
|
+
let next = url.pathname + url.search;
|
|
74
|
+
const now = Date.now();
|
|
75
|
+
for (let page = 0; next && page < Constants.maxPages; page++) {
|
|
76
|
+
const body = (await call(next));
|
|
77
|
+
if (!Array.isArray(body?.data))
|
|
78
|
+
throw new PersonaError('The Persona API response is malformed.');
|
|
79
|
+
// Persona lists the most recent inquiries first.
|
|
80
|
+
for (const inquiry of body.data) {
|
|
81
|
+
const attributes = inquiry?.attributes;
|
|
82
|
+
if (typeof inquiry?.id !== 'string' || !attributes)
|
|
83
|
+
continue;
|
|
84
|
+
// Recheck what the filters asked for, so an API or proxy that ignores them cannot widen them.
|
|
85
|
+
if (attributes['reference-id'] !== referenceId)
|
|
86
|
+
continue;
|
|
87
|
+
const status = attributes.status;
|
|
88
|
+
if (!options.statuses.includes(status))
|
|
89
|
+
continue;
|
|
90
|
+
// Fails closed when the inquiry does not name its template.
|
|
91
|
+
if (templateId && inquiry.relationships?.['inquiry-template']?.data?.id !== templateId)
|
|
92
|
+
continue;
|
|
93
|
+
const verifiedAt = date(attributes['decisioned-at'] ?? attributes['completed-at']);
|
|
94
|
+
if (!fresh(verifiedAt, options.maxAge, now))
|
|
95
|
+
continue;
|
|
96
|
+
return Object.freeze({ inquiryId: inquiry.id, referenceId, status, verifiedAt });
|
|
97
|
+
}
|
|
98
|
+
next = sameOrigin(body.links?.next, apiUrl);
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/** Looks a reference ID up, through the cache when set, and maps the result to a verification. */
|
|
103
|
+
async function lookup(referenceId, options, request) {
|
|
104
|
+
const { cache, cacheTtl = Constants.cacheTtl, maxAge, statuses = Constants.statuses } = options;
|
|
105
|
+
if (statuses.length === 0)
|
|
106
|
+
throw new TypeError('Persona needs at least one accepted status.');
|
|
107
|
+
const headers = await onboardingHeaders(options.onboarding, request, referenceId);
|
|
108
|
+
if (!referenceId)
|
|
109
|
+
return { status: 'missing', headers, reason: 'Persona KYC requires a payer.' };
|
|
110
|
+
// Scoped to the Persona organization and environment, so clients sharing a Store never
|
|
111
|
+
// accept each other's approvals.
|
|
112
|
+
const key = `mppx:persona:${await scope}:${templateId ?? ''}:${referenceId}`;
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
const cached = cache ? (await cache.get(key)) : null;
|
|
115
|
+
if (cached &&
|
|
116
|
+
// Each check applies its own lifetime, so a longer-lived check sharing the Store never
|
|
117
|
+
// extends a stricter one's revalidation window.
|
|
118
|
+
cached.cachedAt + cacheTtl * 1_000 > now &&
|
|
119
|
+
statuses.includes(cached.status) &&
|
|
120
|
+
fresh(date(cached.verifiedAt), maxAge, now))
|
|
121
|
+
return {
|
|
122
|
+
status: 'valid',
|
|
123
|
+
value: Object.freeze({
|
|
124
|
+
inquiryId: cached.inquiryId,
|
|
125
|
+
referenceId,
|
|
126
|
+
status: cached.status,
|
|
127
|
+
verifiedAt: date(cached.verifiedAt),
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
let inquiry;
|
|
131
|
+
try {
|
|
132
|
+
inquiry = await find(referenceId, { statuses, maxAge });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return { status: 'unavailable', reason: 'Persona KYC verification is unavailable.' };
|
|
136
|
+
}
|
|
137
|
+
if (!inquiry)
|
|
138
|
+
return { status: 'forbidden', headers, reason: 'The payer has not passed Persona KYC.' };
|
|
139
|
+
// Only approvals are cached, so a person who just passed KYC is never kept waiting.
|
|
140
|
+
if (cache)
|
|
141
|
+
await cache.put(key, {
|
|
142
|
+
cachedAt: now,
|
|
143
|
+
inquiryId: inquiry.inquiryId,
|
|
144
|
+
status: inquiry.status,
|
|
145
|
+
verifiedAt: inquiry.verifiedAt?.toISOString(),
|
|
146
|
+
});
|
|
147
|
+
return { status: 'valid', value: inquiry };
|
|
148
|
+
}
|
|
149
|
+
return Object.freeze({
|
|
150
|
+
async startInquiry(parameters) {
|
|
151
|
+
const { redirectUri, referenceId } = parameters;
|
|
152
|
+
const inquiryTemplateId = parameters.templateId ?? templateId;
|
|
153
|
+
if (!referenceId)
|
|
154
|
+
throw new TypeError('startInquiry needs a referenceId.');
|
|
155
|
+
if (!inquiryTemplateId)
|
|
156
|
+
throw new TypeError('startInquiry needs a templateId.');
|
|
157
|
+
const created = (await call(Constants.inquiriesPath, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
body: JSON.stringify({
|
|
160
|
+
data: {
|
|
161
|
+
attributes: {
|
|
162
|
+
'inquiry-template-id': inquiryTemplateId,
|
|
163
|
+
'reference-id': referenceId,
|
|
164
|
+
...(redirectUri && { 'redirect-uri': redirectUri }),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
}));
|
|
169
|
+
const inquiryId = created?.data?.id;
|
|
170
|
+
if (typeof inquiryId !== 'string')
|
|
171
|
+
throw new PersonaError('The Persona API response is malformed.');
|
|
172
|
+
const link = (await call(`${Constants.inquiriesPath}/${encodeURIComponent(inquiryId)}/generate-one-time-link`, { method: 'POST', body: '{}' }));
|
|
173
|
+
const url = link?.meta?.['one-time-link'];
|
|
174
|
+
if (typeof url !== 'string')
|
|
175
|
+
throw new PersonaError('The Persona API response is malformed.');
|
|
176
|
+
return Object.freeze({ inquiryId, url });
|
|
177
|
+
},
|
|
178
|
+
paymentCheck(options) {
|
|
179
|
+
const { referenceId } = options;
|
|
180
|
+
return Object.freeze({
|
|
181
|
+
requires: Object.freeze([
|
|
182
|
+
Object.freeze({ type: Constants.type, issuer: Constants.issuer }),
|
|
183
|
+
]),
|
|
184
|
+
async verify(parameters) {
|
|
185
|
+
return lookup(await referenceId(parameters), options, parameters.request);
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
verifier(options) {
|
|
190
|
+
return Object.freeze({
|
|
191
|
+
async verify(request) {
|
|
192
|
+
return lookup(await options.referenceId(request), options, request);
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Verifies that the signer of `message` owns `address` and returns the wallet's reference ID
|
|
200
|
+
* (`Persona.did`), to start an inquiry with. `message` must contain `nonce`, a single-use
|
|
201
|
+
* value your server issued for this person, so a signature cannot be replayed, and the wallet's
|
|
202
|
+
* DID, so the signer commits to the chain.
|
|
203
|
+
*
|
|
204
|
+
* Without `verify`, it accepts EOA signatures only. Pass `verify` for smart accounts, such as
|
|
205
|
+
* viem's `publicClient.verifyMessage` on `chainId`, which supports ERC-1271 and ERC-6492.
|
|
206
|
+
*/
|
|
207
|
+
export async function verifyWallet(parameters) {
|
|
208
|
+
const { address, chainId, message, nonce, signature } = parameters;
|
|
209
|
+
if (!nonce || !message.includes(nonce))
|
|
210
|
+
throw new TypeError('The signed message must contain the nonce.');
|
|
211
|
+
const referenceId = Did.did({ address, chainId });
|
|
212
|
+
// The signer commits to the chain as well as the address: the same address can have different
|
|
213
|
+
// owners on different chains.
|
|
214
|
+
if (!message.toLowerCase().includes(referenceId.toLowerCase()))
|
|
215
|
+
throw new TypeError(`The signed message must contain the wallet's DID, ${referenceId}.`);
|
|
216
|
+
const verify = parameters.verify ?? verifyMessage;
|
|
217
|
+
const valid = await verify({ address, chainId, message, signature }).catch(() => false);
|
|
218
|
+
if (!valid)
|
|
219
|
+
throw new TypeError('The signature does not match the address.');
|
|
220
|
+
return referenceId;
|
|
221
|
+
}
|
|
222
|
+
/** A failed or malformed Persona API call. */
|
|
223
|
+
export class PersonaError extends Error {
|
|
224
|
+
name = 'PersonaError';
|
|
225
|
+
}
|
|
226
|
+
async function onboardingHeaders(onboarding, request, referenceId) {
|
|
227
|
+
const url = typeof onboarding === 'function' ? await onboarding({ request, referenceId }) : onboarding;
|
|
228
|
+
if (!url)
|
|
229
|
+
return undefined;
|
|
230
|
+
return { Link: `<${url}>; rel="${Constants.rel}"` };
|
|
231
|
+
}
|
|
232
|
+
function fresh(verifiedAt, maxAge, now) {
|
|
233
|
+
if (maxAge === undefined)
|
|
234
|
+
return true;
|
|
235
|
+
if (!(Number.isInteger(maxAge) && maxAge > 0))
|
|
236
|
+
throw new RangeError('Persona maxAge must be a positive integer.');
|
|
237
|
+
return verifiedAt !== undefined && now - verifiedAt.getTime() <= maxAge * 1_000;
|
|
238
|
+
}
|
|
239
|
+
function date(value) {
|
|
240
|
+
if (typeof value !== 'string')
|
|
241
|
+
return undefined;
|
|
242
|
+
const parsed = new Date(value);
|
|
243
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
244
|
+
}
|
|
245
|
+
async function digest(value) {
|
|
246
|
+
const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
|
|
247
|
+
return Array.from(new Uint8Array(hash).slice(0, 16), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Returns a pagination link as a path, or `undefined` unless it is on the Persona API origin, so
|
|
251
|
+
* the API key is never sent to an origin a response names.
|
|
252
|
+
*/
|
|
253
|
+
function sameOrigin(link, apiUrl) {
|
|
254
|
+
if (typeof link !== 'string')
|
|
255
|
+
return undefined;
|
|
256
|
+
const base = new URL(apiUrl);
|
|
257
|
+
const url = new URL(link, base);
|
|
258
|
+
if (url.origin !== base.origin)
|
|
259
|
+
return undefined;
|
|
260
|
+
// The absolute URL, not its path: a path such as '//host/x' would resolve to another origin.
|
|
261
|
+
return url.href;
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as Identity from '../../../../identity/Types.js';
|
|
2
|
+
import type { SigningKey } from '../../Types.js';
|
|
2
3
|
import { Constants } from '../Constants.js';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a TAP identity prover.
|
|
@@ -17,8 +18,11 @@ export declare namespace prover {
|
|
|
17
18
|
type Config = {
|
|
18
19
|
/** TAP signature type for the request. */
|
|
19
20
|
intent: (typeof Constants.intents)[keyof typeof Constants.intents];
|
|
20
|
-
/**
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Ed25519 or RSA-PSS SHA-512 key pair, or a {@link SigningKey | Signer} for a remote key,
|
|
23
|
+
* provisioned to the agent provider.
|
|
24
|
+
*/
|
|
25
|
+
key: SigningKey;
|
|
22
26
|
/** Identifier the merchant uses to resolve the signing public key. */
|
|
23
27
|
keyId: string;
|
|
24
28
|
/** Origins that receive TAP signatures, or `'*'` for any origin. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as HttpMessageSignature from '../../internal/HttpMessageSignature.js';
|
|
2
|
+
import * as Signer from '../../internal/Signer.js';
|
|
2
3
|
import { Constants } from '../Constants.js';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a TAP identity prover.
|
|
@@ -15,6 +16,7 @@ import { Constants } from '../Constants.js';
|
|
|
15
16
|
export function prover(config) {
|
|
16
17
|
const tag = config.intent === Constants.intents.payment ? Constants.tags.payment : Constants.tags.browse;
|
|
17
18
|
const expiresIn = config.expiresIn ?? Constants.defaultSignatureLifetime;
|
|
19
|
+
Signer.resolve(config.key);
|
|
18
20
|
if (!Number.isInteger(expiresIn) ||
|
|
19
21
|
expiresIn <= 0 ||
|
|
20
22
|
expiresIn > Constants.maximumSignatureLifetime)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Tempo ID values. */
|
|
2
|
+
export declare const Constants: {
|
|
3
|
+
/** Identity type advertised in the 402's `Identity-Required` header. */
|
|
4
|
+
readonly type: 'tempo-id';
|
|
5
|
+
/** Tempo ID in production: the issuer of every access token. */
|
|
6
|
+
readonly issuer: 'https://id.tempo.xyz';
|
|
7
|
+
/** Header that carries the user's ID token, for their email address. */
|
|
8
|
+
readonly idTokenHeader: 'Tempo-Id-Token';
|
|
9
|
+
/** Seconds a DPoP proof is accepted after its `iat`. */
|
|
10
|
+
readonly proofMaxAge: 300;
|
|
11
|
+
/** Seconds of clock skew allowed on token and proof times. */
|
|
12
|
+
readonly clockTolerance: 60;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=Constants.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Tempo ID values. */
|
|
2
|
+
export const Constants = {
|
|
3
|
+
/** Identity type advertised in the 402's `Identity-Required` header. */
|
|
4
|
+
type: 'tempo-id',
|
|
5
|
+
/** Tempo ID in production: the issuer of every access token. */
|
|
6
|
+
issuer: 'https://id.tempo.xyz',
|
|
7
|
+
/** Header that carries the user's ID token, for their email address. */
|
|
8
|
+
idTokenHeader: 'Tempo-Id-Token',
|
|
9
|
+
/** Seconds a DPoP proof is accepted after its `iat`. */
|
|
10
|
+
proofMaxAge: 300,
|
|
11
|
+
/** Seconds of clock skew allowed on token and proof times. */
|
|
12
|
+
clockTolerance: 60,
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=Constants.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Address } from 'ox';
|
|
2
|
+
/** The screening state of a Tempo Account: only `clear` may pay without limits. */
|
|
3
|
+
export type ComplianceState = 'clear' | 'exit_only' | 'blocked' | 'pending';
|
|
4
|
+
/** A Tempo ID user, as a verified access token (and, when sent, ID token) names them. */
|
|
5
|
+
export type Caller = {
|
|
6
|
+
/** The Tempo ID user ID: stable across every app on Tempo ID. */
|
|
7
|
+
readonly userId: string;
|
|
8
|
+
/** The app the user signed in to. */
|
|
9
|
+
readonly clientId: string;
|
|
10
|
+
/** The Tempo Accounts the token grants to the app on the configured chain, checksummed. */
|
|
11
|
+
readonly accounts: readonly Address.Address[];
|
|
12
|
+
/** The screening state of each account in the app's realms, by checksummed address. Empty for an unregistered app. */
|
|
13
|
+
readonly compliance: Readonly<Record<Address.Address, ComplianceState>>;
|
|
14
|
+
/** The user's email address, lowercased, from the ID token. Absent without one, or without the `email` scope. */
|
|
15
|
+
readonly email?: string | undefined;
|
|
16
|
+
/** Whether Tempo ID verified the email address. */
|
|
17
|
+
readonly emailVerified?: boolean | undefined;
|
|
18
|
+
};
|
|
19
|
+
/** A verified Tempo ID user and the Tempo Account that paid. */
|
|
20
|
+
export type Payer = Caller & {
|
|
21
|
+
/** The account that paid, checksummed. Absent when the check ran without a Credential. */
|
|
22
|
+
readonly account?: Address.Address | undefined;
|
|
23
|
+
};
|
|
24
|
+
/** An ES256 DPoP key (RFC 9449), such as the Tempo ID SDK's session key. */
|
|
25
|
+
export type DpopKey = {
|
|
26
|
+
/** The public key as a JWK. */
|
|
27
|
+
readonly jwk: JsonWebKey;
|
|
28
|
+
/** The private key that signs each proof. */
|
|
29
|
+
readonly privateKey: CryptoKey;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type * as Identity from '../../../../identity/Types.js';
|
|
2
|
+
import type { MaybePromise } from '../../../../internal/types.js';
|
|
3
|
+
import type * as Types from '../Types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a prover that sends a Tempo ID access token with each request: as `DPoP` with a new
|
|
6
|
+
* proof when `dpop` is set, else as `Bearer`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const mppx = Mppx.create({
|
|
11
|
+
* identity: [
|
|
12
|
+
* TempoId.Client.prover({
|
|
13
|
+
* accessToken: () => accounts.session.accessToken(),
|
|
14
|
+
* scope: ['https://api.example'],
|
|
15
|
+
* }),
|
|
16
|
+
* ],
|
|
17
|
+
* methods: [tempo({ account })],
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function prover(config: prover.Config): Identity.Prover;
|
|
22
|
+
export declare namespace prover {
|
|
23
|
+
type Config = {
|
|
24
|
+
/** Returns a live Tempo ID access token, such as `accounts.session.accessToken`. */
|
|
25
|
+
readonly accessToken: () => MaybePromise<string>;
|
|
26
|
+
/** The DPoP key that binds the token. Absent, the token is sent as a Bearer token. */
|
|
27
|
+
readonly dpop?: Types.DpopKey | undefined;
|
|
28
|
+
/** Returns the user's ID token, such as `accounts.session.get()?.idToken`, so the API reads their email. */
|
|
29
|
+
readonly idToken?: (() => MaybePromise<string | undefined>) | undefined;
|
|
30
|
+
/** Origins that receive the token. Send it only to the API it was issued for. */
|
|
31
|
+
readonly scope: Identity.Prover['scope'];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Base64 } from 'ox';
|
|
2
|
+
import * as Credential from '../../../../Credential.js';
|
|
3
|
+
import { Constants } from '../Constants.js';
|
|
4
|
+
import * as Jwt from '../internal/Jwt.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a prover that sends a Tempo ID access token with each request: as `DPoP` with a new
|
|
7
|
+
* proof when `dpop` is set, else as `Bearer`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const mppx = Mppx.create({
|
|
12
|
+
* identity: [
|
|
13
|
+
* TempoId.Client.prover({
|
|
14
|
+
* accessToken: () => accounts.session.accessToken(),
|
|
15
|
+
* scope: ['https://api.example'],
|
|
16
|
+
* }),
|
|
17
|
+
* ],
|
|
18
|
+
* methods: [tempo({ account })],
|
|
19
|
+
* })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function prover(config) {
|
|
23
|
+
const { dpop } = config;
|
|
24
|
+
return {
|
|
25
|
+
scope: config.scope,
|
|
26
|
+
headers: ['dpop', Constants.idTokenHeader.toLowerCase()],
|
|
27
|
+
async prove(request) {
|
|
28
|
+
const accessToken = await config.accessToken();
|
|
29
|
+
const headers = new Headers(request.headers);
|
|
30
|
+
// The access token would replace a Payment Credential in Authorization; a server created
|
|
31
|
+
// with `requiresAuth: true` takes the Credential in Payment-Authorization instead.
|
|
32
|
+
const authorization = headers.get('Authorization');
|
|
33
|
+
if (authorization && Credential.extractPaymentScheme(authorization) !== null)
|
|
34
|
+
throw new TypeError('The Tempo ID access token needs Authorization, which holds the Payment Credential: the server must set requiresAuth: true.');
|
|
35
|
+
headers.set('Authorization', `${dpop ? 'DPoP' : 'Bearer'} ${accessToken}`);
|
|
36
|
+
if (dpop)
|
|
37
|
+
headers.set('DPoP', await proof(dpop, accessToken, request));
|
|
38
|
+
const idToken = await config.idToken?.();
|
|
39
|
+
if (idToken)
|
|
40
|
+
headers.set(Constants.idTokenHeader, idToken);
|
|
41
|
+
return new Request(request, { headers });
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Signs a DPoP proof (RFC 9449) of `accessToken` for one request. */
|
|
46
|
+
async function proof(dpop, accessToken, request) {
|
|
47
|
+
const { crv, kty, x, y } = dpop.jwk;
|
|
48
|
+
const header = Jwt.encode({ alg: 'ES256', jwk: { crv, kty, x, y }, typ: 'dpop+jwt' });
|
|
49
|
+
const claims = Jwt.encode({
|
|
50
|
+
ath: await Jwt.sha256(accessToken),
|
|
51
|
+
htm: request.method,
|
|
52
|
+
htu: Jwt.htu(request.url),
|
|
53
|
+
iat: Math.floor(Date.now() / 1_000),
|
|
54
|
+
jti: crypto.randomUUID(),
|
|
55
|
+
});
|
|
56
|
+
const input = `${header}.${claims}`;
|
|
57
|
+
const signature = await crypto.subtle.sign(Jwt.es256.sign, dpop.privateKey, new TextEncoder().encode(input));
|
|
58
|
+
return `${input}.${Base64.fromBytes(new Uint8Array(signature), { pad: false, url: true })}`;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** A decoded, unverified compact JWS. */
|
|
2
|
+
export type Decoded = {
|
|
3
|
+
readonly header: Record<string, any>;
|
|
4
|
+
readonly claims: Record<string, any>;
|
|
5
|
+
readonly signingInput: Uint8Array<ArrayBuffer>;
|
|
6
|
+
readonly signature: Uint8Array<ArrayBuffer>;
|
|
7
|
+
};
|
|
8
|
+
/** ES256 in Web Crypto: the only DPoP algorithm the Tempo ID SDK signs with. */
|
|
9
|
+
export declare const es256: {
|
|
10
|
+
readonly key: {
|
|
11
|
+
readonly name: 'ECDSA';
|
|
12
|
+
readonly namedCurve: 'P-256';
|
|
13
|
+
};
|
|
14
|
+
readonly sign: {
|
|
15
|
+
readonly name: 'ECDSA';
|
|
16
|
+
readonly hash: 'SHA-256';
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** Decodes a compact JWS without verifying it, or returns `undefined` if it is malformed. */
|
|
20
|
+
export declare function decode(token: string): Decoded | undefined;
|
|
21
|
+
/** Encodes a JSON value as unpadded base64url. */
|
|
22
|
+
export declare function encode(value: unknown): string;
|
|
23
|
+
/** Unpadded base64url SHA-256 of a string, as DPoP's `ath` uses. */
|
|
24
|
+
export declare function sha256(value: string): Promise<string>;
|
|
25
|
+
/** RFC 7638 thumbprint of a P-256 public JWK. */
|
|
26
|
+
export declare function thumbprint(jwk: JsonWebKey): Promise<string>;
|
|
27
|
+
/** A request URL without its query and fragment, as DPoP's `htu` names it. */
|
|
28
|
+
export declare function htu(url: string | URL): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a lookup of an issuer's RS256 keys by key ID, from `<issuer>/oauth2/jwks`. The set is
|
|
31
|
+
* cached for five minutes, and an unknown key ID refetches it at most every 30 seconds. A failed
|
|
32
|
+
* fetch keeps the last set that loaded for up to one hour after it loaded, so a removed key stops
|
|
33
|
+
* verifying within an hour even while the issuer is unreachable.
|
|
34
|
+
*/
|
|
35
|
+
export declare function keys(issuer: string, fetch: typeof globalThis.fetch): (kid: string) => Promise<CryptoKey | undefined>;
|
|
36
|
+
//# sourceMappingURL=Jwt.d.ts.map
|