mppx 0.17.6 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/dist/Currency.d.ts +59 -0
- package/dist/Currency.js +60 -0
- package/dist/Errors.d.ts +13 -0
- package/dist/Errors.js +15 -6
- package/dist/cli/cli.js +138 -138
- package/dist/cli/plugins/index.js +12 -12
- package/dist/cli/plugins/tempo.js +13 -1
- package/dist/client/Mppx.js +13 -4
- package/dist/client/internal/Fetch.d.ts +5 -0
- package/dist/client/internal/Fetch.js +16 -5
- 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/{email-otp/internal → attestation}/Constants.d.ts +4 -1
- package/dist/extensions/identity/{email-otp/internal → attestation}/Constants.js +4 -1
- package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.d.ts +5 -5
- package/dist/extensions/identity/{email-otp/internal → attestation}/Jwks.js +1 -1
- package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts} +40 -26
- package/dist/extensions/identity/{email-otp/internal/Attestation.js → attestation/Token.js} +18 -3
- package/dist/extensions/identity/{email-otp/internal → attestation}/Types.d.ts +14 -14
- package/dist/extensions/identity/attestation/client/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/client/index.js +273 -0
- package/dist/extensions/identity/attestation/index.d.ts +20 -0
- package/dist/extensions/identity/attestation/index.js +18 -0
- package/dist/extensions/identity/attestation/internal/Cache.d.ts +120 -0
- package/dist/extensions/identity/attestation/internal/Cache.js +90 -0
- package/dist/extensions/identity/attestation/server/index.d.ts +66 -0
- package/dist/extensions/identity/attestation/server/index.js +119 -0
- package/dist/extensions/identity/email-otp/Constants.d.ts +5 -5
- package/dist/extensions/identity/email-otp/Constants.js +6 -5
- package/dist/extensions/identity/email-otp/Types.d.ts +4 -4
- package/dist/extensions/identity/email-otp/client/index.d.ts +22 -15
- package/dist/extensions/identity/email-otp/client/index.js +21 -9
- package/dist/extensions/identity/email-otp/index.d.ts +3 -8
- package/dist/extensions/identity/email-otp/index.js +3 -8
- package/dist/extensions/identity/email-otp/server/index.d.ts +16 -16
- package/dist/extensions/identity/email-otp/server/index.js +17 -14
- package/dist/extensions/identity/index.d.ts +6 -0
- package/dist/extensions/identity/index.js +6 -0
- package/dist/extensions/identity/internal/Verification.js +9 -5
- 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/identity/Callback.d.ts +24 -5
- package/dist/identity/Callback.js +35 -11
- package/dist/identity/Client.d.ts +78 -5
- package/dist/identity/Client.js +165 -48
- package/dist/identity/Headers.d.ts +21 -0
- package/dist/identity/Headers.js +24 -0
- package/dist/identity/Server.d.ts +159 -37
- package/dist/identity/Server.js +309 -138
- package/dist/identity/Status.d.ts +14 -0
- package/dist/identity/Status.js +19 -0
- package/dist/identity/Types.d.ts +166 -65
- package/dist/identity/index.d.ts +2 -0
- package/dist/identity/index.js +2 -0
- package/dist/identity/internal/Requirements.d.ts +28 -0
- package/dist/identity/internal/Requirements.js +78 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/integrations/x402/Evm.d.ts +1 -0
- package/dist/internal/env.d.ts +14 -0
- package/dist/internal/env.js +38 -0
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/proxy/internal/Headers.d.ts +1 -1
- package/dist/proxy/internal/Headers.js +11 -7
- package/dist/server/Mppx.d.ts +14 -6
- package/dist/server/Mppx.js +256 -149
- package/dist/server/internal/challengeMeta.d.ts +0 -6
- package/dist/server/internal/challengeMeta.js +3 -17
- 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 +53 -6
- 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/server/Charge.d.ts +14 -9
- package/dist/tempo/server/Charge.js +64 -3
- package/dist/tempo/server/Methods.d.ts +1 -1
- package/dist/tempo/server/Methods.js +4 -1
- package/dist/tempo/server/Subscription.d.ts +8 -0
- package/dist/tempo/server/internal/fallback-store.d.ts +7 -2
- package/dist/tempo/server/internal/fallback-store.js +12 -3
- 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.d.ts +5 -1
- 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 +19 -3
- package/dist/extensions/identity/email-otp/internal/Prover.d.ts +0 -46
- package/dist/extensions/identity/email-otp/internal/Prover.js +0 -168
- package/dist/extensions/identity/email-otp/internal/Verifier.d.ts +0 -56
- package/dist/extensions/identity/email-otp/internal/Verifier.js +0 -116
- /package/dist/extensions/identity/{email-otp/internal → attestation}/Types.js +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
|
|
@@ -6,7 +6,7 @@ import type * as Types from './Types.js';
|
|
|
6
6
|
*
|
|
7
7
|
* `verify` returns the caller's identity, which the route handler reads with
|
|
8
8
|
* `result.identity.get(verifier)`; `undefined` or `null` when the request carries none
|
|
9
|
-
* (401, with `challenge` headers if set); or throws a {@link Rejection} to
|
|
9
|
+
* (`missing`, 401, with `challenge` headers if set); or throws a {@link Rejection} to
|
|
10
10
|
* reject the identity it carries.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
@@ -16,7 +16,7 @@ import type * as Types from './Types.js';
|
|
|
16
16
|
* const key = request.headers.get('X-Api-Key')
|
|
17
17
|
* if (!key) return undefined
|
|
18
18
|
* const row = await db.customerByKey(key)
|
|
19
|
-
* if (!row) throw new Identity.Rejection('Unknown API key.', {
|
|
19
|
+
* if (!row) throw new Identity.Rejection('Unknown API key.', { status: 'forbidden' })
|
|
20
20
|
* return row
|
|
21
21
|
* },
|
|
22
22
|
* })
|
|
@@ -38,10 +38,29 @@ export declare namespace from {
|
|
|
38
38
|
/** Rejects an identity a {@link from} verifier was given. */
|
|
39
39
|
export declare class Rejection extends Error {
|
|
40
40
|
readonly name = "Rejection";
|
|
41
|
-
/**
|
|
41
|
+
/** Fixed status of the rejection. @default 'invalid' */
|
|
42
|
+
readonly status: Rejection.Status;
|
|
43
|
+
/**
|
|
44
|
+
* HTTP status of the rejection.
|
|
45
|
+
*
|
|
46
|
+
* @deprecated Read `status`. Defaults to the status's fixed code (`Identity.Status.codes`).
|
|
47
|
+
*/
|
|
42
48
|
readonly code: number;
|
|
43
|
-
constructor(message: string, options?:
|
|
49
|
+
constructor(message: string, options?: Rejection.Options);
|
|
50
|
+
}
|
|
51
|
+
export declare namespace Rejection {
|
|
52
|
+
/** Fixed statuses a {@link Rejection} can carry. */
|
|
53
|
+
type Status = Exclude<Types.RejectionStatus, 'missing'>;
|
|
54
|
+
type Options = {
|
|
55
|
+
/** Fixed status of the rejection. @default 'invalid' */
|
|
56
|
+
status?: Status | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* HTTP status of the rejection.
|
|
59
|
+
*
|
|
60
|
+
* @deprecated Use `status`. 403 maps to `forbidden`, 503 to `unavailable`, and any other
|
|
61
|
+
* code to `invalid`, sent with that code.
|
|
62
|
+
*/
|
|
44
63
|
code?: number | undefined;
|
|
45
|
-
}
|
|
64
|
+
};
|
|
46
65
|
}
|
|
47
66
|
//# sourceMappingURL=Callback.d.ts.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import * as Status from './Status.js';
|
|
1
2
|
/**
|
|
2
3
|
* Creates a request-stage verifier from a function, such as a lookup in your
|
|
3
4
|
* own database, session store or KYC provider.
|
|
4
5
|
*
|
|
5
6
|
* `verify` returns the caller's identity, which the route handler reads with
|
|
6
7
|
* `result.identity.get(verifier)`; `undefined` or `null` when the request carries none
|
|
7
|
-
* (401, with `challenge` headers if set); or throws a {@link Rejection} to
|
|
8
|
+
* (`missing`, 401, with `challenge` headers if set); or throws a {@link Rejection} to
|
|
8
9
|
* reject the identity it carries.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
* const key = request.headers.get('X-Api-Key')
|
|
15
16
|
* if (!key) return undefined
|
|
16
17
|
* const row = await db.customerByKey(key)
|
|
17
|
-
* if (!row) throw new Identity.Rejection('Unknown API key.', {
|
|
18
|
+
* if (!row) throw new Identity.Rejection('Unknown API key.', { status: 'forbidden' })
|
|
18
19
|
* return row
|
|
19
20
|
* },
|
|
20
21
|
* })
|
|
@@ -22,8 +23,7 @@
|
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
export function from(config) {
|
|
25
|
-
return {
|
|
26
|
-
stage: 'request',
|
|
26
|
+
return Object.freeze({
|
|
27
27
|
async verify(request) {
|
|
28
28
|
let value;
|
|
29
29
|
try {
|
|
@@ -32,33 +32,57 @@ export function from(config) {
|
|
|
32
32
|
catch (error) {
|
|
33
33
|
if (!(error instanceof Rejection))
|
|
34
34
|
throw error;
|
|
35
|
+
const { code, message: reason } = error;
|
|
36
|
+
// Fails closed: a status set at runtime outside the fixed rejections is `invalid`.
|
|
37
|
+
const status = isRejectionStatus(error.status) ? error.status : 'invalid';
|
|
38
|
+
if (status !== 'invalid')
|
|
39
|
+
return { status, headers: config.challenge, reason };
|
|
35
40
|
return {
|
|
36
|
-
status
|
|
37
|
-
code
|
|
41
|
+
status,
|
|
42
|
+
// A deprecated non-standard code is still sent as is.
|
|
43
|
+
...(code !== Status.codes.invalid && { code }),
|
|
38
44
|
headers: config.challenge,
|
|
39
|
-
reason
|
|
45
|
+
reason,
|
|
40
46
|
};
|
|
41
47
|
}
|
|
42
48
|
// A lookup that found nothing often returns null: treat it as no identity.
|
|
43
49
|
if (value === undefined || value === null)
|
|
44
50
|
return {
|
|
45
51
|
status: 'missing',
|
|
46
|
-
code: 401,
|
|
47
52
|
headers: config.challenge,
|
|
48
53
|
reason: 'Identity verification is required.',
|
|
49
54
|
};
|
|
50
55
|
return { status: 'valid', value };
|
|
51
56
|
},
|
|
52
|
-
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const rejectionStatuses = ['invalid', 'forbidden', 'unavailable'];
|
|
60
|
+
function isRejectionStatus(status) {
|
|
61
|
+
return rejectionStatuses.includes(status);
|
|
53
62
|
}
|
|
54
63
|
/** Rejects an identity a {@link from} verifier was given. */
|
|
55
64
|
export class Rejection extends Error {
|
|
56
65
|
name = 'Rejection';
|
|
57
|
-
/**
|
|
66
|
+
/** Fixed status of the rejection. @default 'invalid' */
|
|
67
|
+
status;
|
|
68
|
+
/**
|
|
69
|
+
* HTTP status of the rejection.
|
|
70
|
+
*
|
|
71
|
+
* @deprecated Read `status`. Defaults to the status's fixed code (`Identity.Status.codes`).
|
|
72
|
+
*/
|
|
58
73
|
code;
|
|
59
74
|
constructor(message, options = {}) {
|
|
60
75
|
super(message);
|
|
61
|
-
|
|
76
|
+
if (options.status !== undefined && !isRejectionStatus(options.status))
|
|
77
|
+
throw new TypeError(`Identity rejection status must be one of ${rejectionStatuses.join(', ')}.`);
|
|
78
|
+
this.status =
|
|
79
|
+
options.status ??
|
|
80
|
+
(options.code === Status.codes.forbidden
|
|
81
|
+
? 'forbidden'
|
|
82
|
+
: options.code === Status.codes.unavailable
|
|
83
|
+
? 'unavailable'
|
|
84
|
+
: 'invalid');
|
|
85
|
+
this.code = options.code ?? Status.codes[this.status];
|
|
62
86
|
}
|
|
63
87
|
}
|
|
64
88
|
//# sourceMappingURL=Callback.js.map
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
import * as Challenge from '../Challenge.js';
|
|
1
2
|
import type * as Types from './Types.js';
|
|
3
|
+
/** Headers a prover's `retry` returned, as name and value pairs. */
|
|
4
|
+
export type ResendHeaders = readonly (readonly [name: string, value: string])[];
|
|
5
|
+
/** Payment state of one send. */
|
|
6
|
+
export type SendContext = {
|
|
7
|
+
/** The Challenge a paid attempt answers. Its presence makes the attempt paid. */
|
|
8
|
+
readonly challenge?: Challenge.Challenge | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Headers a `retry` returned earlier in the same logical request, such as on the unpaid
|
|
11
|
+
* attempt before a 402. They are set before the provers run, so the paid attempt carries them.
|
|
12
|
+
*/
|
|
13
|
+
readonly headers?: ResendHeaders | undefined;
|
|
14
|
+
};
|
|
2
15
|
/** Sends HTTP attempts with every in-scope prover applied. */
|
|
3
16
|
export type Client = {
|
|
4
17
|
/**
|
|
@@ -10,13 +23,73 @@ export type Client = {
|
|
|
10
23
|
* (non-402) response, the request is proved again and resent once, except for
|
|
11
24
|
* paid attempts, which are never resent.
|
|
12
25
|
*/
|
|
13
|
-
send: (fetch: typeof globalThis.fetch, request: Request, context?:
|
|
26
|
+
readonly send: (fetch: typeof globalThis.fetch, request: Request, context?: SendContext) => Promise<{
|
|
14
27
|
request: Request;
|
|
15
28
|
response: Response;
|
|
29
|
+
/** The retry headers the last attempt carried, to pass on to the paid attempt. */
|
|
30
|
+
headers: ResendHeaders;
|
|
16
31
|
}>;
|
|
17
|
-
/**
|
|
18
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Lets in-scope provers prepare proofs for a 402 from `url` before the payment retry,
|
|
34
|
+
* with the selected Challenge and the requirements of the 402's `Identity-Required` header.
|
|
35
|
+
*/
|
|
36
|
+
readonly challenge: (response: Response, context: {
|
|
37
|
+
readonly challenge: Challenge.Challenge;
|
|
38
|
+
}, url: string) => Promise<void>;
|
|
39
|
+
/** Extra sensitive request headers the provers declare (`Prover.headers`), lowercased. */
|
|
40
|
+
readonly headers: readonly string[];
|
|
19
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* The state of one `send`, as a state machine:
|
|
44
|
+
*
|
|
45
|
+
* - `unproved`: nothing sent yet.
|
|
46
|
+
* - `sent`: an unpaid attempt was sent; it may be resent once.
|
|
47
|
+
* - `paid`: a paid attempt was sent; it is never resent, since its payment may have settled.
|
|
48
|
+
* - `resent`: the request is proved again and resent once, with `headers` set.
|
|
49
|
+
* - `done`: the last response is final.
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export type Attempt = {
|
|
54
|
+
readonly phase: 'unproved';
|
|
55
|
+
} | {
|
|
56
|
+
readonly phase: 'sent';
|
|
57
|
+
} | {
|
|
58
|
+
readonly phase: 'paid';
|
|
59
|
+
} | {
|
|
60
|
+
readonly phase: 'resent';
|
|
61
|
+
readonly headers: ResendHeaders;
|
|
62
|
+
} | {
|
|
63
|
+
readonly phase: 'done';
|
|
64
|
+
};
|
|
65
|
+
/** An input to {@link transition}. @internal */
|
|
66
|
+
export type AttemptEvent =
|
|
67
|
+
/** The first attempt is sent, paid (a Challenge or payment credential) or not. */
|
|
68
|
+
{
|
|
69
|
+
readonly type: 'send';
|
|
70
|
+
readonly payment: 'paid' | 'unpaid';
|
|
71
|
+
}
|
|
72
|
+
/** A response arrived; `resend` holds the headers provers asked to resend with, if any. */
|
|
73
|
+
| {
|
|
74
|
+
readonly type: 'response';
|
|
75
|
+
readonly resend: ResendHeaders | undefined;
|
|
76
|
+
};
|
|
77
|
+
/** The state of a `send` before anything is sent. @internal */
|
|
78
|
+
export declare const initial: Attempt;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the next attempt state. Pure; throws a `TypeError` for an event the current phase
|
|
81
|
+
* does not accept, such as resending a paid attempt or resending twice.
|
|
82
|
+
*
|
|
83
|
+
* | Phase | Event | Next |
|
|
84
|
+
* | ------------------ | ---------------------- | ---------- |
|
|
85
|
+
* | `unproved` | `send` (paid) | `paid` |
|
|
86
|
+
* | `unproved` | `send` (unpaid) | `sent` |
|
|
87
|
+
* | `sent` | `response` with resend | `resent` |
|
|
88
|
+
* | `sent`, `paid`, `resent` | `response` without | `done` |
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export declare function transition(attempt: Attempt, event: AttemptEvent): Attempt;
|
|
20
93
|
/**
|
|
21
94
|
* Creates the client runner for a list of provers.
|
|
22
95
|
*
|
|
@@ -28,7 +101,7 @@ export declare function from(provers: readonly Types.Prover[]): Client;
|
|
|
28
101
|
/**
|
|
29
102
|
* Wraps a fetch implementation so every request is proved.
|
|
30
103
|
*
|
|
31
|
-
* Prefer `Mppx.create({ identity })`, which also passes the payment
|
|
104
|
+
* Prefer `Mppx.create({ identity })`, which also passes the payment Challenge to provers.
|
|
32
105
|
*/
|
|
33
|
-
export declare function wrapFetch(fetch: typeof globalThis.fetch, client: Client, context?:
|
|
106
|
+
export declare function wrapFetch(fetch: typeof globalThis.fetch, client: Client, context?: SendContext): typeof globalThis.fetch;
|
|
34
107
|
//# sourceMappingURL=Client.d.ts.map
|