mppx 0.17.6 → 0.18.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 +28 -0
- package/dist/cli/cli.js +139 -139
- package/dist/cli/plugins/index.js +6 -6
- package/dist/client/Mppx.js +13 -4
- package/dist/client/internal/Fetch.js +9 -5
- 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 +17 -5
- 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 +2 -0
- package/dist/extensions/identity/index.js +2 -0
- package/dist/extensions/identity/internal/Verification.js +9 -5
- 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 +16 -0
- package/dist/identity/Headers.js +19 -0
- package/dist/identity/Server.d.ts +159 -37
- package/dist/identity/Server.js +307 -138
- package/dist/identity/Status.d.ts +14 -0
- package/dist/identity/Status.js +19 -0
- package/dist/identity/Types.d.ts +161 -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/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 +7 -3
- package/dist/server/Mppx.d.ts +14 -6
- package/dist/server/Mppx.js +252 -148
- package/dist/server/internal/challengeMeta.d.ts +0 -6
- package/dist/server/internal/challengeMeta.js +3 -17
- package/dist/tempo/server/Charge.d.ts +14 -9
- package/dist/tempo/server/Charge.js +5 -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/session/server/Session.d.ts +5 -1
- package/package.json +5 -1
- 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
package/dist/client/Mppx.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Constants from '../Constants.js';
|
|
2
2
|
import * as Expires from '../Expires.js';
|
|
3
3
|
import * as IdentityClient from '../identity/Client.js';
|
|
4
|
+
import * as IdentityHeaders from '../identity/Headers.js';
|
|
4
5
|
import * as AcceptPayment from '../internal/AcceptPayment.js';
|
|
5
6
|
import * as Fetch from './internal/Fetch.js';
|
|
6
7
|
import * as MethodChallenge from './internal/MethodChallenge.js';
|
|
@@ -222,6 +223,7 @@ export function create(config) {
|
|
|
222
223
|
return rawFetch(paidRequest);
|
|
223
224
|
const { response } = await identityClient.send(rawFetch, paidRequest, {
|
|
224
225
|
challenge: payment.challenge,
|
|
226
|
+
headers: preparedHttp.identityHeaders,
|
|
225
227
|
});
|
|
226
228
|
return response;
|
|
227
229
|
},
|
|
@@ -277,12 +279,12 @@ const bodyHeaders = [
|
|
|
277
279
|
'content-type',
|
|
278
280
|
'transfer-encoding',
|
|
279
281
|
];
|
|
282
|
+
/** Credential headers never sent across origins; identity headers come from `Identity.Headers` and the provers. */
|
|
280
283
|
const crossOriginHeaders = [
|
|
281
284
|
'authorization',
|
|
282
285
|
'cookie',
|
|
283
286
|
'cookie2',
|
|
284
287
|
'host',
|
|
285
|
-
'identity-attestation',
|
|
286
288
|
'payment-authorization',
|
|
287
289
|
'payment-signature',
|
|
288
290
|
'proxy-authorization',
|
|
@@ -292,24 +294,30 @@ async function prepareHttpRequest(parameters) {
|
|
|
292
294
|
const { acceptPayment, acceptPaymentPolicy, fetch, identity, init, input, maxRedirects } = parameters;
|
|
293
295
|
if (!Number.isInteger(maxRedirects) || maxRedirects < 0)
|
|
294
296
|
throw new TypeError('maxRedirects must be a non-negative integer.');
|
|
297
|
+
const stripped = new Set([
|
|
298
|
+
...crossOriginHeaders,
|
|
299
|
+
...IdentityHeaders.request,
|
|
300
|
+
...(identity?.headers ?? []),
|
|
301
|
+
]);
|
|
295
302
|
let request = new Request(input, { ...init, redirect: 'manual' });
|
|
296
303
|
const explicitAcceptPayment = request.headers.has(Constants.Headers.acceptPayment);
|
|
297
304
|
let body = await replayBody(request, init?.body);
|
|
298
305
|
const redirects = [];
|
|
299
306
|
for (;;) {
|
|
300
307
|
request = withAcceptPayment(request, acceptPayment, explicitAcceptPayment, acceptPaymentPolicy);
|
|
301
|
-
const { request: sentRequest, response } = await (async () => {
|
|
308
|
+
const { request: sentRequest, response, headers: identityHeaders, } = await (async () => {
|
|
302
309
|
// `request` stays unread for replay; the reported request is the one actually sent.
|
|
303
310
|
if (identity)
|
|
304
311
|
return identity.send(fetch, request.clone());
|
|
305
312
|
const sent = request.clone();
|
|
306
|
-
return { request: sent, response: await fetch(sent) };
|
|
313
|
+
return { request: sent, response: await fetch(sent), headers: [] };
|
|
307
314
|
})();
|
|
308
315
|
if (response.type === 'opaqueredirect' || response.status === 0)
|
|
309
316
|
throw new Error('prepareRequest requires a runtime that exposes manual redirect responses.');
|
|
310
317
|
if (!redirectStatuses.has(response.status))
|
|
311
318
|
return {
|
|
312
319
|
body,
|
|
320
|
+
identityHeaders,
|
|
313
321
|
replayRequest: request,
|
|
314
322
|
request: sentRequest,
|
|
315
323
|
response,
|
|
@@ -319,6 +327,7 @@ async function prepareHttpRequest(parameters) {
|
|
|
319
327
|
if (!location)
|
|
320
328
|
return {
|
|
321
329
|
body,
|
|
330
|
+
identityHeaders,
|
|
322
331
|
replayRequest: request,
|
|
323
332
|
request: sentRequest,
|
|
324
333
|
response,
|
|
@@ -347,7 +356,7 @@ async function prepareHttpRequest(parameters) {
|
|
|
347
356
|
if (from.origin !== to.origin)
|
|
348
357
|
for (const header of [...headers.keys()]) {
|
|
349
358
|
const value = headers.get(header) ?? '';
|
|
350
|
-
if (
|
|
359
|
+
if (stripped.has(header) || value.startsWith('Payment '))
|
|
351
360
|
headers.delete(header);
|
|
352
361
|
}
|
|
353
362
|
redirects.push(Object.freeze({ from: from.href, status: response.status, to: to.href }));
|
|
@@ -118,15 +118,18 @@ export function from(config) {
|
|
|
118
118
|
// which can duplicate retries and make restore semantics fragile.
|
|
119
119
|
const baseFetch = unwrapFetch(fetch);
|
|
120
120
|
const send = async (input, init, context) => identity
|
|
121
|
-
?
|
|
122
|
-
: baseFetch(input, init);
|
|
121
|
+
? identity.send(baseFetch, new Request(input, init), context)
|
|
122
|
+
: { response: await baseFetch(input, init), headers: [] };
|
|
123
123
|
const request = async (input, init, canRefetch) => {
|
|
124
124
|
const callerHeaders = getCallerHeaders(input, init?.headers);
|
|
125
125
|
const hasExplicitAcceptPayment = callerHeaders.has(Constants.Headers.acceptPayment);
|
|
126
126
|
const paymentPreferences = resolvePaymentPreferences(callerHeaders, resolvedAcceptPayment);
|
|
127
127
|
const capturedBody = captureRequestBody(input, init, callerHeaders);
|
|
128
128
|
const initialRequest = prepareInitialRequest(input, init, callerHeaders, paymentPreferences.header, hasExplicitAcceptPayment, acceptPaymentPolicy);
|
|
129
|
-
|
|
129
|
+
const first = await send(cloneRequestInput(initialRequest.input), initialRequest.init);
|
|
130
|
+
let response = first.response;
|
|
131
|
+
// Retry headers from the unpaid attempt (such as an attestation) go on the paid attempt too.
|
|
132
|
+
const identityHeaders = first.headers;
|
|
130
133
|
const transportRequest = withCapturedBody(initialRequest.init, await capturedBody);
|
|
131
134
|
if (init?.[skipPayment])
|
|
132
135
|
return response;
|
|
@@ -261,14 +264,15 @@ export function from(config) {
|
|
|
261
264
|
transactionHash: MethodResponse.getTransactionHash(selected.method, credential),
|
|
262
265
|
});
|
|
263
266
|
try {
|
|
264
|
-
|
|
267
|
+
;
|
|
268
|
+
({ response } = await send(paymentInput, {
|
|
265
269
|
...transport.setCredential({
|
|
266
270
|
...fetchInit,
|
|
267
271
|
headers: initialRequest.headers,
|
|
268
272
|
}, credential, { challenge: selectedChallenge }),
|
|
269
273
|
// Runtimes do not strip custom payment headers on cross-origin redirects.
|
|
270
274
|
redirect: 'manual',
|
|
271
|
-
}, { challenge: selectedChallenge });
|
|
275
|
+
}, { challenge: selectedChallenge, headers: identityHeaders }));
|
|
272
276
|
}
|
|
273
277
|
catch (cause) {
|
|
274
278
|
outcomeUnknown = unknownOutcome(cause);
|
|
@@ -12,7 +12,10 @@ export declare const Constants: {
|
|
|
12
12
|
readonly jwksPath: '/.well-known/jwks.json';
|
|
13
13
|
/** Clock tolerance, in seconds, applied to `iat` and `exp`. */
|
|
14
14
|
readonly clockTolerance: 60;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Seconds before expiry at which a client stops sending an attestation on unpaid attempts and
|
|
17
|
+
* replaces it, capped at half the attestation's lifetime.
|
|
18
|
+
*/
|
|
16
19
|
readonly refreshMargin: 300;
|
|
17
20
|
/** Longest attestation accepted, in characters. */
|
|
18
21
|
readonly maxLength: 8192;
|
|
@@ -12,7 +12,10 @@ export const Constants = {
|
|
|
12
12
|
jwksPath: '/.well-known/jwks.json',
|
|
13
13
|
/** Clock tolerance, in seconds, applied to `iat` and `exp`. */
|
|
14
14
|
clockTolerance: 60,
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Seconds before expiry at which a client stops sending an attestation on unpaid attempts and
|
|
17
|
+
* replaces it, capped at half the attestation's lifetime.
|
|
18
|
+
*/
|
|
16
19
|
refreshMargin: 300,
|
|
17
20
|
/** Longest attestation accepted, in characters. */
|
|
18
21
|
maxLength: 8_192,
|
|
@@ -13,18 +13,18 @@ export declare function resolver(options?: resolver.Options): Types.KeyResolver;
|
|
|
13
13
|
export declare namespace resolver {
|
|
14
14
|
type Options = {
|
|
15
15
|
/** Fetch implementation. @default globalThis.fetch */
|
|
16
|
-
fetch?: typeof globalThis.fetch | undefined;
|
|
16
|
+
readonly fetch?: typeof globalThis.fetch | undefined;
|
|
17
17
|
/** Seconds a fetched key set is cached. @default 300 */
|
|
18
|
-
ttl?: number | undefined;
|
|
18
|
+
readonly ttl?: number | undefined;
|
|
19
19
|
/** Seconds before a key set fetch is abandoned. @default 5 */
|
|
20
|
-
timeout?: number | undefined;
|
|
20
|
+
readonly timeout?: number | undefined;
|
|
21
21
|
/** Minimum seconds between refetches for an unknown key ID, per issuer. @default 30 */
|
|
22
|
-
refreshInterval?: number | undefined;
|
|
22
|
+
readonly refreshInterval?: number | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* Seconds after its fetch that the last good key set keeps verifying while
|
|
25
25
|
* the issuer is unreachable, so a rotated-out key stops working. @default 3600
|
|
26
26
|
*/
|
|
27
|
-
maxStale?: number | undefined;
|
|
27
|
+
readonly maxStale?: number | undefined;
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=Jwks.d.ts.map
|
package/dist/extensions/identity/{email-otp/internal/Attestation.d.ts → attestation/Token.d.ts}
RENAMED
|
@@ -2,17 +2,28 @@ import type * as Types from './Types.js';
|
|
|
2
2
|
/** A decoded, unverified attestation. */
|
|
3
3
|
export type Decoded = {
|
|
4
4
|
/** JWS protected header. */
|
|
5
|
-
header: {
|
|
6
|
-
alg?: unknown;
|
|
7
|
-
kid?: unknown;
|
|
8
|
-
typ?: unknown;
|
|
5
|
+
readonly header: {
|
|
6
|
+
readonly alg?: unknown;
|
|
7
|
+
readonly kid?: unknown;
|
|
8
|
+
readonly typ?: unknown;
|
|
9
9
|
};
|
|
10
10
|
/** Unverified claims. */
|
|
11
|
-
claims: Partial<Types.Claims> & Record<string, unknown
|
|
11
|
+
readonly claims: Partial<Types.Claims> & Readonly<Record<string, unknown>>;
|
|
12
12
|
/** The signed bytes: `base64url(header) + '.' + base64url(claims)`. */
|
|
13
|
-
signingInput: Uint8Array;
|
|
13
|
+
readonly signingInput: Uint8Array;
|
|
14
14
|
/** Signature bytes. */
|
|
15
|
-
signature: Uint8Array;
|
|
15
|
+
readonly signature: Uint8Array;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The outcome of {@link verify}: `unavailable` when the issuer's keys could not be fetched,
|
|
19
|
+
* which says nothing about the token.
|
|
20
|
+
*/
|
|
21
|
+
export type VerifyResult = {
|
|
22
|
+
readonly status: 'valid';
|
|
23
|
+
readonly claims: Types.Claims;
|
|
24
|
+
} | {
|
|
25
|
+
readonly status: 'invalid' | 'unavailable';
|
|
26
|
+
readonly reason: string;
|
|
16
27
|
};
|
|
17
28
|
/**
|
|
18
29
|
* Signs attestation claims as a compact JWS (EdDSA over Ed25519).
|
|
@@ -21,8 +32,8 @@ export type Decoded = {
|
|
|
21
32
|
* published in the issuer's JSON Web Key Set.
|
|
22
33
|
*/
|
|
23
34
|
export declare function sign(claims: Types.Claims, options: {
|
|
24
|
-
key: CryptoKey;
|
|
25
|
-
keyId: string;
|
|
35
|
+
readonly key: CryptoKey;
|
|
36
|
+
readonly keyId: string;
|
|
26
37
|
}): Promise<string>;
|
|
27
38
|
/** Decodes an attestation without verifying it, or returns `undefined` if it is malformed. */
|
|
28
39
|
export declare function decode(token: string): Decoded | undefined;
|
|
@@ -33,34 +44,37 @@ export declare function decode(token: string): Decoded | undefined;
|
|
|
33
44
|
* `iat` and `exp` times (with `clockTolerance`), then the signature with the
|
|
34
45
|
* key `keyResolver` returns for the header's `kid`.
|
|
35
46
|
*/
|
|
36
|
-
export declare function verify(token: string, options: verify.Options): Promise<
|
|
37
|
-
status: 'valid';
|
|
38
|
-
claims: Types.Claims;
|
|
39
|
-
} | {
|
|
40
|
-
status: 'invalid';
|
|
41
|
-
reason: string;
|
|
42
|
-
unavailable?: true;
|
|
43
|
-
}>;
|
|
47
|
+
export declare function verify(token: string, options: verify.Options): Promise<VerifyResult>;
|
|
44
48
|
export declare namespace verify {
|
|
45
49
|
type Options = {
|
|
46
50
|
/** Accepted attestation type, such as `email`. */
|
|
47
|
-
type: string;
|
|
51
|
+
readonly type: string;
|
|
48
52
|
/** Trusted issuer URL. */
|
|
49
|
-
issuer: string;
|
|
53
|
+
readonly issuer: string;
|
|
50
54
|
/** Origin the attestation must be bound to. */
|
|
51
|
-
audience: string;
|
|
55
|
+
readonly audience: string;
|
|
52
56
|
/** Resolves the issuer's public key by key ID. */
|
|
53
|
-
keyResolver: Types.KeyResolver;
|
|
57
|
+
readonly keyResolver: Types.KeyResolver;
|
|
54
58
|
/** Oldest accepted `iat`, in seconds before now. Defaults to the attestation's own `exp`. */
|
|
55
|
-
maxAge?: number | undefined;
|
|
59
|
+
readonly maxAge?: number | undefined;
|
|
56
60
|
/** Clock tolerance in seconds. @default 60 */
|
|
57
|
-
clockTolerance?: number | undefined;
|
|
61
|
+
readonly clockTolerance?: number | undefined;
|
|
58
62
|
/** Current Unix time in seconds, for tests. */
|
|
59
|
-
now?: number | undefined;
|
|
63
|
+
readonly now?: number | undefined;
|
|
60
64
|
};
|
|
61
65
|
}
|
|
62
66
|
/** Splits an `Identity-Attestation` header value into its attestations. */
|
|
63
|
-
export declare function parseHeader(value: string | null): string[];
|
|
67
|
+
export declare function parseHeader(value: string | null): readonly string[];
|
|
68
|
+
/**
|
|
69
|
+
* Throws a `TypeError` unless `clockTolerance`, `maxAge` and `now` are each absent or a
|
|
70
|
+
* non-negative integer of seconds: `NaN` or `Infinity` would turn the time checks off.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export declare function assertTimes(options: {
|
|
74
|
+
readonly clockTolerance?: number | undefined;
|
|
75
|
+
readonly maxAge?: number | undefined;
|
|
76
|
+
readonly now?: number | undefined;
|
|
77
|
+
}): void;
|
|
64
78
|
/** Accepts https issuers, and http only on localhost for development. */
|
|
65
79
|
export declare function isIssuer(value: string): boolean;
|
|
66
|
-
//# sourceMappingURL=
|
|
80
|
+
//# sourceMappingURL=Token.d.ts.map
|
|
@@ -43,6 +43,7 @@ export function decode(token) {
|
|
|
43
43
|
* key `keyResolver` returns for the header's `kid`.
|
|
44
44
|
*/
|
|
45
45
|
export async function verify(token, options) {
|
|
46
|
+
assertTimes(options);
|
|
46
47
|
const decoded = decode(token);
|
|
47
48
|
if (!decoded)
|
|
48
49
|
return invalid('The attestation is malformed.');
|
|
@@ -79,7 +80,7 @@ export async function verify(token, options) {
|
|
|
79
80
|
}
|
|
80
81
|
catch {
|
|
81
82
|
// The issuer's keys are unreachable, which says nothing about the token.
|
|
82
|
-
return {
|
|
83
|
+
return { status: 'unavailable', reason: 'The attestation key could not be resolved.' };
|
|
83
84
|
}
|
|
84
85
|
if (!key)
|
|
85
86
|
return invalid('No public key is available for the attestation key ID.');
|
|
@@ -90,7 +91,7 @@ export async function verify(token, options) {
|
|
|
90
91
|
catch { }
|
|
91
92
|
if (!valid)
|
|
92
93
|
return invalid('The attestation signature is invalid.');
|
|
93
|
-
return { status: 'valid', claims: claims };
|
|
94
|
+
return { status: 'valid', claims: Object.freeze({ ...claims }) };
|
|
94
95
|
}
|
|
95
96
|
/** Splits an `Identity-Attestation` header value into its attestations. */
|
|
96
97
|
export function parseHeader(value) {
|
|
@@ -110,6 +111,20 @@ function invalid(reason) {
|
|
|
110
111
|
function isObject(value) {
|
|
111
112
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
112
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Throws a `TypeError` unless `clockTolerance`, `maxAge` and `now` are each absent or a
|
|
116
|
+
* non-negative integer of seconds: `NaN` or `Infinity` would turn the time checks off.
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
export function assertTimes(options) {
|
|
120
|
+
for (const [name, value] of [
|
|
121
|
+
['clockTolerance', options.clockTolerance],
|
|
122
|
+
['maxAge', options.maxAge],
|
|
123
|
+
['now', options.now],
|
|
124
|
+
])
|
|
125
|
+
if (value !== undefined && !isTime(value))
|
|
126
|
+
throw new TypeError(`Attestation ${name} must be a non-negative integer of seconds.`);
|
|
127
|
+
}
|
|
113
128
|
function isTime(value) {
|
|
114
129
|
// Bounded by the largest time a Date holds, so every accepted time converts to a valid Date.
|
|
115
130
|
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 && value <= maxTime;
|
|
@@ -125,4 +140,4 @@ export function isIssuer(value) {
|
|
|
125
140
|
return true;
|
|
126
141
|
return url.protocol === 'http:' && (url.hostname === 'localhost' || url.hostname === '127.0.0.1');
|
|
127
142
|
}
|
|
128
|
-
//# sourceMappingURL=
|
|
143
|
+
//# sourceMappingURL=Token.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MaybePromise } from '
|
|
1
|
+
import type { MaybePromise } from '../../../internal/types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Claims of an MPP identity attestation.
|
|
4
4
|
*
|
|
@@ -8,41 +8,41 @@ import type { MaybePromise } from '../../../../internal/types.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export type Claims = {
|
|
10
10
|
/** Issuer URL. */
|
|
11
|
-
iss: string;
|
|
11
|
+
readonly iss: string;
|
|
12
12
|
/** Origin of the server the attestation is for, such as `https://api.example`. */
|
|
13
|
-
aud: string;
|
|
13
|
+
readonly aud: string;
|
|
14
14
|
/** Attested subject, such as an email address. */
|
|
15
|
-
sub: string;
|
|
15
|
+
readonly sub: string;
|
|
16
16
|
/** Attestation type, such as `email`. */
|
|
17
|
-
type: string;
|
|
17
|
+
readonly type: string;
|
|
18
18
|
/** Issued-at time, in Unix seconds. */
|
|
19
|
-
iat: number;
|
|
19
|
+
readonly iat: number;
|
|
20
20
|
/** Expiry time, in Unix seconds. */
|
|
21
|
-
exp: number;
|
|
21
|
+
readonly exp: number;
|
|
22
22
|
/** Unique attestation identifier. */
|
|
23
|
-
jti?: string | undefined;
|
|
23
|
+
readonly jti?: string | undefined;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* Resolves the issuer's public key for an attestation's `kid`. Returns
|
|
27
27
|
* `undefined` for an unknown or malformed `kid`, and throws only when the keys
|
|
28
|
-
* cannot be fetched: a throw answers the request with 503.
|
|
28
|
+
* cannot be fetched: a throw answers the request with 503 (`unavailable`).
|
|
29
29
|
*/
|
|
30
30
|
export type KeyResolver = (parameters: {
|
|
31
31
|
/** Issuer URL the attestation claims. */
|
|
32
|
-
issuer: string;
|
|
32
|
+
readonly issuer: string;
|
|
33
33
|
/** Key identifier from the JWS header. */
|
|
34
|
-
keyId: string;
|
|
34
|
+
readonly keyId: string;
|
|
35
35
|
}) => MaybePromise<CryptoKey | undefined>;
|
|
36
36
|
/** An attestation a route requires, as listed in `Identity-Attestation-Required`. */
|
|
37
37
|
export type Requirement = {
|
|
38
38
|
/** Attestation type, such as `email`. */
|
|
39
|
-
type: string;
|
|
39
|
+
readonly type: string;
|
|
40
40
|
/** Issuer URL the route trusts, or where to obtain the identity. Absent for a server's own identity system without one. */
|
|
41
|
-
issuer?: string | undefined;
|
|
41
|
+
readonly issuer?: string | undefined;
|
|
42
42
|
};
|
|
43
43
|
/** A verified attestation. */
|
|
44
44
|
export type Verified = {
|
|
45
45
|
/** Verified claims. */
|
|
46
|
-
claims: Claims;
|
|
46
|
+
readonly claims: Claims;
|
|
47
47
|
};
|
|
48
48
|
//# sourceMappingURL=Types.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
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 presents identity attestations, and obtains them when a server asks.
|
|
6
|
+
*
|
|
7
|
+
* Each in-scope request carries, in `Identity-Attestation`, the cached attestations whose
|
|
8
|
+
* audience is the request's origin: on a paid attempt every one not expired beyond the clock
|
|
9
|
+
* tolerance, on an unpaid one only those outside the refresh margin, so one close to expiry is
|
|
10
|
+
* replaced before paying. When a server answers 401 or 403 with `Identity-Attestation-Required`,
|
|
11
|
+
* the prover meets each listed group (see {@link requirements}) with one attestation from a
|
|
12
|
+
* trusted issuer, and resends the request with them, keeping the attestations it already carried.
|
|
13
|
+
* Within a group of alternatives it prefers one it holds, and otherwise acquires them in listed
|
|
14
|
+
* order until one succeeds, so a route accepting any of several issuers costs one acquisition.
|
|
15
|
+
*
|
|
16
|
+
* Trust is set by two options together:
|
|
17
|
+
* - `scope`: the origins that may receive attestations and ask for new ones. The audience is
|
|
18
|
+
* always the request's own origin, never one a server names, so a server cannot obtain an
|
|
19
|
+
* attestation it could replay elsewhere.
|
|
20
|
+
* - `issuers`: the issuers `acquire` may be asked for. A server only names an issuer; an
|
|
21
|
+
* untrusted one could relay a code and obtain an attestation for another origin.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* Attestation.Client.prover({
|
|
26
|
+
* scope: ['https://api.example'],
|
|
27
|
+
* issuers: ['https://issuer.example'],
|
|
28
|
+
* types: ['phone'],
|
|
29
|
+
* acquire: ({ audience, issuer }) => obtainPhoneAttestation({ audience, issuer }),
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function prover(config: prover.Config): Identity.Prover;
|
|
34
|
+
export declare namespace prover {
|
|
35
|
+
type Config = {
|
|
36
|
+
/** Origins that receive attestations and may ask for new ones, or `'*'` for any origin. */
|
|
37
|
+
readonly scope: Identity.Prover['scope'];
|
|
38
|
+
/** Attestations obtained beforehand, such as from an issuer with curl. */
|
|
39
|
+
readonly attestations?: readonly string[] | undefined;
|
|
40
|
+
/** Obtains an attestation a server requires, or returns `undefined` to decline. */
|
|
41
|
+
readonly acquire?: ((requirement: {
|
|
42
|
+
/** Origin the attestation must be bound to. */
|
|
43
|
+
readonly audience: string;
|
|
44
|
+
/** Issuer to obtain it from. */
|
|
45
|
+
readonly issuer: string;
|
|
46
|
+
/** Attestation type. */
|
|
47
|
+
readonly type: string;
|
|
48
|
+
}) => MaybePromise<string | undefined>) | undefined;
|
|
49
|
+
/** Issuers `acquire` may be asked for. Required with `acquire`. */
|
|
50
|
+
readonly issuers?: readonly string[] | undefined;
|
|
51
|
+
/** Attestation types `acquire` may be asked for. Defaults to any. */
|
|
52
|
+
readonly types?: readonly string[] | undefined;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parses the attestation requirements of a rejected response as groups, every one of which a
|
|
57
|
+
* request must meet with any one of its requirements:
|
|
58
|
+
*
|
|
59
|
+
* - An item, such as `phone;issuer="https://a.example"`, is a group of one.
|
|
60
|
+
* - An inner list, such as `(email;issuer="https://a.example" email;issuer="https://b.example")`,
|
|
61
|
+
* is a group of alternatives, as `Identity.anyOf` sends them.
|
|
62
|
+
*
|
|
63
|
+
* Malformed members are skipped, and a group left with none is dropped.
|
|
64
|
+
*/
|
|
65
|
+
export declare function requirements(headers: Headers): readonly (readonly Types.Requirement[])[];
|
|
66
|
+
//# sourceMappingURL=index.d.ts.map
|