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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getAddress, recoverTypedDataAddress } from 'viem';
|
|
2
|
+
import * as Currency from '../../Currency.js';
|
|
2
3
|
import { VerificationFailedError } from '../../Errors.js';
|
|
3
4
|
import * as Method from '../../Method.js';
|
|
4
5
|
import * as Receipt from '../../Receipt.js';
|
|
@@ -116,9 +117,7 @@ function resolveConfig(config) {
|
|
|
116
117
|
let authorization = config.authorization;
|
|
117
118
|
let chainId = config.chainId;
|
|
118
119
|
let decimals = config.decimals;
|
|
119
|
-
|
|
120
|
-
chainId ??= Assets.toChainId(currency.network);
|
|
121
|
-
}
|
|
120
|
+
chainId ??= Currency.chainIdOf(currency);
|
|
122
121
|
if (chainId !== undefined) {
|
|
123
122
|
const resolved = Assets.resolve(currency, Types.networkOf(chainId));
|
|
124
123
|
if (!resolved)
|
|
@@ -219,7 +219,7 @@ export declare function evm<const parameters extends evm.Parameters>(parameters:
|
|
|
219
219
|
};
|
|
220
220
|
}, charge_.Defaults, import("../../server/Transport.js").Http, {}, string | undefined>];
|
|
221
221
|
export declare namespace evm {
|
|
222
|
-
/**
|
|
222
|
+
/** An accepted EVM currency: an address, a `viem/tokens` token (chain-indexed or resolved), or a known asset. */
|
|
223
223
|
type Currency = Assets.Currency;
|
|
224
224
|
/** Shared EVM settlement parameters and ordered accepted currencies. */
|
|
225
225
|
type Parameters = Omit<charge_.Parameters, 'currency'> & ({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Currency from '../../Currency.js';
|
|
1
2
|
import * as Assets from '../Assets.js';
|
|
2
3
|
import * as Chains from '../Chains.js';
|
|
3
4
|
import { charge as charge_ } from './Charge.js';
|
|
@@ -34,14 +35,14 @@ export function evm(parameters) {
|
|
|
34
35
|
const seen = new Set();
|
|
35
36
|
const methods = [];
|
|
36
37
|
for (const currency of currencies) {
|
|
37
|
-
const chainId = shared.chainId ??
|
|
38
|
+
const chainId = shared.chainId ?? Currency.chainIdOf(currency);
|
|
38
39
|
if (chainId === undefined)
|
|
39
40
|
throw new Error('EVM currencies require `chainId` or known asset metadata.');
|
|
40
41
|
const resolved = Assets.resolve(currency, Assets.toNetwork(chainId));
|
|
41
42
|
if (!resolved)
|
|
42
43
|
continue;
|
|
43
44
|
// One shared price cannot price non-USD or unknown-denomination token definitions.
|
|
44
|
-
if (Assets.
|
|
45
|
+
if (typeof currency !== 'string' && !Assets.isAsset(currency) && currency.currency !== 'USD')
|
|
45
46
|
continue;
|
|
46
47
|
const key = `${chainId}:${resolved.address.toLowerCase()}`;
|
|
47
48
|
if (seen.has(key))
|
|
@@ -2,6 +2,32 @@ import type { MaybePromise } from '../../internal/types.js';
|
|
|
2
2
|
import type { Algorithms } from './Constants.js';
|
|
3
3
|
/** RFC 9421 algorithms implemented by the HTTP message signature signer and verifier. */
|
|
4
4
|
export type SignatureAlgorithm = (typeof Algorithms)[keyof typeof Algorithms];
|
|
5
|
+
/**
|
|
6
|
+
* A key pair whose private key stays outside this process, such as in a cloud KMS, an HSM or a
|
|
7
|
+
* wallet service like Turnkey.
|
|
8
|
+
*
|
|
9
|
+
* mppx checks every signature `sign` returns against `publicKey` before it uses it, so a wrong
|
|
10
|
+
* key, a DER- or base64-encoded signature or a wrong RSA-PSS salt fails on the client instead of
|
|
11
|
+
* at the server.
|
|
12
|
+
*/
|
|
13
|
+
export type Signer = {
|
|
14
|
+
/**
|
|
15
|
+
* The public key of the remote private key: Ed25519 or RSA-PSS SHA-512, with the `verify`
|
|
16
|
+
* usage. Its algorithm is the signature algorithm, and identifiers that derive from the key
|
|
17
|
+
* (such as a Web Bot Auth `keyid`) are computed from it.
|
|
18
|
+
*/
|
|
19
|
+
readonly publicKey: CryptoKey;
|
|
20
|
+
/**
|
|
21
|
+
* Signs `payload` (the complete message, not a digest: the RFC 9421 signature base or the JWS
|
|
22
|
+
* signing input) and resolves with the raw signature bytes: 64 bytes for Ed25519, or the RSA
|
|
23
|
+
* modulus length for RSA-PSS SHA-512 (SHA-512, MGF1 with SHA-512, 64-byte salt).
|
|
24
|
+
*/
|
|
25
|
+
readonly sign: (parameters: {
|
|
26
|
+
readonly payload: Uint8Array;
|
|
27
|
+
}) => Promise<Uint8Array>;
|
|
28
|
+
};
|
|
29
|
+
/** A local `CryptoKeyPair`, or a {@link Signer} whose private key stays elsewhere. */
|
|
30
|
+
export type SigningKey = CryptoKeyPair | Signer;
|
|
5
31
|
/** Resolves a trusted public key for a parsed request signature. */
|
|
6
32
|
export type KeyResolver = (parameters: {
|
|
7
33
|
/** RFC 9421 algorithm declared by the signature. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SigningKey } from '../Types.js';
|
|
1
2
|
import type * as Types from './Types.js';
|
|
2
3
|
/** A decoded, unverified attestation. */
|
|
3
4
|
export type Decoded = {
|
|
@@ -28,12 +29,13 @@ export type VerifyResult = {
|
|
|
28
29
|
/**
|
|
29
30
|
* Signs attestation claims as a compact JWS (EdDSA over Ed25519).
|
|
30
31
|
*
|
|
31
|
-
* For issuers. `
|
|
32
|
-
*
|
|
32
|
+
* For issuers. `key` is an Ed25519 key pair, or a {@link SigningKey | Signer} whose private key
|
|
33
|
+
* stays in a KMS, HSM or wallet service. `keyId` defaults to the RFC 7638 thumbprint of its public
|
|
34
|
+
* key, the `kid` an issuer's JSON Web Key Set publishes for it.
|
|
33
35
|
*/
|
|
34
36
|
export declare function sign(claims: Types.Claims, options: {
|
|
35
|
-
readonly key:
|
|
36
|
-
readonly keyId
|
|
37
|
+
readonly key: SigningKey;
|
|
38
|
+
readonly keyId?: string | undefined;
|
|
37
39
|
}): Promise<string>;
|
|
38
40
|
/** Decodes an attestation without verifying it, or returns `undefined` if it is malformed. */
|
|
39
41
|
export declare function decode(token: string): Decoded | undefined;
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { Base64 } from 'ox';
|
|
2
|
+
import { Algorithms } from '../Constants.js';
|
|
3
|
+
import * as JwkThumbprint from '../internal/JwkThumbprint.js';
|
|
4
|
+
import * as Signer from '../internal/Signer.js';
|
|
2
5
|
import { Constants } from './Constants.js';
|
|
3
6
|
/**
|
|
4
7
|
* Signs attestation claims as a compact JWS (EdDSA over Ed25519).
|
|
5
8
|
*
|
|
6
|
-
* For issuers. `
|
|
7
|
-
*
|
|
9
|
+
* For issuers. `key` is an Ed25519 key pair, or a {@link SigningKey | Signer} whose private key
|
|
10
|
+
* stays in a KMS, HSM or wallet service. `keyId` defaults to the RFC 7638 thumbprint of its public
|
|
11
|
+
* key, the `kid` an issuer's JSON Web Key Set publishes for it.
|
|
8
12
|
*/
|
|
9
13
|
export async function sign(claims, options) {
|
|
10
|
-
const
|
|
14
|
+
const signer = Signer.resolve(options.key, [Algorithms.ed25519]);
|
|
15
|
+
const keyId = options.keyId ?? (await JwkThumbprint.fromKey(signer.publicKey));
|
|
16
|
+
const header = { alg: Constants.algorithm, kid: keyId, typ: Constants.tokenType };
|
|
11
17
|
const input = `${encode(header)}.${encode(claims)}`;
|
|
12
|
-
const signature = await
|
|
13
|
-
return `${input}.${Base64.fromBytes(
|
|
18
|
+
const signature = await signer.sign(new TextEncoder().encode(input));
|
|
19
|
+
return `${input}.${Base64.fromBytes(signature, { pad: false, url: true })}`;
|
|
14
20
|
}
|
|
15
21
|
/** Decodes an attestation without verifying it, or returns `undefined` if it is malformed. */
|
|
16
22
|
export function decode(token) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { unwrapFetch } from '../../../../client/internal/Fetch.js';
|
|
1
|
+
import { unwrapFetch, withoutPayment } from '../../../../client/internal/Fetch.js';
|
|
2
2
|
import * as Attestation from '../../attestation/client/index.js';
|
|
3
3
|
import { isIssuer } from '../../attestation/Token.js';
|
|
4
4
|
import { Constants } from '../Constants.js';
|
|
@@ -115,14 +115,14 @@ async function post(issuer, path, fetch, body) {
|
|
|
115
115
|
// The address and code never go over plaintext HTTP, except to localhost.
|
|
116
116
|
if (!isIssuer(issuer))
|
|
117
117
|
throw new EmailOtpError('The issuer must be an https URL (http only on localhost).');
|
|
118
|
-
//
|
|
119
|
-
const response = await unwrapFetch(fetch ?? globalThis.fetch)(`${issuer.replace(/\/+$/, '')}${path}`, {
|
|
118
|
+
// Untagged forwarding wrappers survive unwrapping, so also opt out explicitly.
|
|
119
|
+
const response = await unwrapFetch(fetch ?? globalThis.fetch)(`${issuer.replace(/\/+$/, '')}${path}`, withoutPayment({
|
|
120
120
|
body: JSON.stringify(body),
|
|
121
121
|
headers: { 'content-type': 'application/json' },
|
|
122
122
|
method: 'POST',
|
|
123
123
|
// Workers reject 'error'; a redirect is not ok, so it fails below.
|
|
124
124
|
redirect: 'manual',
|
|
125
|
-
});
|
|
125
|
+
}));
|
|
126
126
|
const json = (await response.json().catch(() => ({})));
|
|
127
127
|
if (!response.ok)
|
|
128
128
|
throw new EmailOtpError(typeof json.error === 'string' ? json.error : `The issuer answered ${response.status}.`, { status: response.status });
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
export * as Attestation from './attestation/index.js';
|
|
3
3
|
/** Email address verification with a one-time code. */
|
|
4
4
|
export * as EmailOtp from './email-otp/index.js';
|
|
5
|
+
/** Link agent identity: attestation tokens and Link-signed claims. */
|
|
6
|
+
export * as Link from './link/index.js';
|
|
7
|
+
/** Persona KYC: a payment check that requires an approved Persona inquiry. */
|
|
8
|
+
export * as Persona from './persona/index.js';
|
|
5
9
|
/** Client and server adapters for the TAP agent-recognition signature profile. */
|
|
6
10
|
export * as Tap from './tap/index.js';
|
|
7
11
|
/** Client and server adapters for the Web Bot Auth HTTPS-directory profile. */
|
|
8
12
|
export * as WebBotAuth from './web-bot-auth/index.js';
|
|
13
|
+
/** World ID: agents approved by a World ID-verified human, through World IdP (OpenID Connect). */
|
|
14
|
+
export * as World from './world/index.js';
|
|
9
15
|
export * from './Constants.js';
|
|
10
16
|
export type * from './Types.js';
|
|
11
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
export * as Attestation from './attestation/index.js';
|
|
3
3
|
/** Email address verification with a one-time code. */
|
|
4
4
|
export * as EmailOtp from './email-otp/index.js';
|
|
5
|
+
/** Link agent identity: attestation tokens and Link-signed claims. */
|
|
6
|
+
export * as Link from './link/index.js';
|
|
7
|
+
/** Persona KYC: a payment check that requires an approved Persona inquiry. */
|
|
8
|
+
export * as Persona from './persona/index.js';
|
|
5
9
|
/** Client and server adapters for the TAP agent-recognition signature profile. */
|
|
6
10
|
export * as Tap from './tap/index.js';
|
|
7
11
|
/** Client and server adapters for the Web Bot Auth HTTPS-directory profile. */
|
|
8
12
|
export * as WebBotAuth from './web-bot-auth/index.js';
|
|
13
|
+
/** World ID: agents approved by a World ID-verified human, through World IdP (OpenID Connect). */
|
|
14
|
+
export * as World from './world/index.js';
|
|
9
15
|
export * from './Constants.js';
|
|
10
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BareItem } from 'structured-headers';
|
|
2
2
|
import type { MaybePromise } from '../../../internal/types.js';
|
|
3
3
|
import * as Store from '../../../Store.js';
|
|
4
|
-
import type { KeyResolver, SignatureAlgorithm, SigningContext } from '../Types.js';
|
|
4
|
+
import type { KeyResolver, SignatureAlgorithm, SigningContext, SigningKey } from '../Types.js';
|
|
5
5
|
/** RFC 9421 constants used by identity signature profiles. */
|
|
6
6
|
export declare const Constants: {
|
|
7
7
|
/** Derived request components supported by this narrow request profile. */
|
|
@@ -54,7 +54,7 @@ export declare function sign(request: Request, options: {
|
|
|
54
54
|
components: readonly ComponentInput[];
|
|
55
55
|
expiresIn?: number | undefined;
|
|
56
56
|
keyId: string;
|
|
57
|
-
key:
|
|
57
|
+
key: SigningKey;
|
|
58
58
|
label: string;
|
|
59
59
|
context?: SigningContext | undefined;
|
|
60
60
|
tag: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isInnerList, parseDictionary, serializeItem, serializeDictionary, serializeInnerList, serializeParameters, } from 'structured-headers';
|
|
2
2
|
import * as Store from '../../../Store.js';
|
|
3
3
|
import { Algorithms, Headers as SignatureHeaders } from '../Constants.js';
|
|
4
|
+
import * as Signer from './Signer.js';
|
|
4
5
|
import * as SigningContextInternal from './SigningContext.js';
|
|
5
6
|
/** RFC 9421 constants used by identity signature profiles. */
|
|
6
7
|
export const Constants = {
|
|
@@ -33,7 +34,8 @@ export async function sign(request, options) {
|
|
|
33
34
|
const context = options.context ?? SigningContextInternal.create();
|
|
34
35
|
const created = context.created;
|
|
35
36
|
const expires = created + (options.expiresIn ?? 60);
|
|
36
|
-
const
|
|
37
|
+
const signer = Signer.resolve(options.key);
|
|
38
|
+
const algorithm = signer.algorithm;
|
|
37
39
|
const parameters = new Map([
|
|
38
40
|
['created', created],
|
|
39
41
|
['expires', expires],
|
|
@@ -53,7 +55,7 @@ export async function sign(request, options) {
|
|
|
53
55
|
parameters,
|
|
54
56
|
tag: options.tag,
|
|
55
57
|
};
|
|
56
|
-
|
|
58
|
+
// Check the existing signatures first, so a request this refuses never reaches a remote signer.
|
|
57
59
|
const headers = new Headers(request.headers);
|
|
58
60
|
const inputs = parseHeaderDictionary(headers, SignatureHeaders.signatureInput);
|
|
59
61
|
const signatures = parseHeaderDictionary(headers, SignatureHeaders.signature);
|
|
@@ -61,9 +63,16 @@ export async function sign(request, options) {
|
|
|
61
63
|
throw new Error('Signature-Input and Signature must contain the same labels.');
|
|
62
64
|
if (inputs.has(input.label) || signatures.has(input.label))
|
|
63
65
|
throw new Error(`HTTP message signature label "${input.label}" already exists.`);
|
|
66
|
+
// `new Request(request)` below throws on a read or locked body: refuse it before signing.
|
|
67
|
+
if (request.bodyUsed || request.body?.locked)
|
|
68
|
+
throw new TypeError('Cannot sign a request whose body has already been read or is locked.');
|
|
64
69
|
inputs.set(input.label, toInnerList(input));
|
|
70
|
+
// Serializing validates the label and parameters before the signer is called.
|
|
71
|
+
const signatureInput = serializeDictionary(inputs);
|
|
72
|
+
const bytes = encode(signatureBase(request, input));
|
|
73
|
+
const signature = (await signer.sign(bytes)).buffer;
|
|
65
74
|
signatures.set(input.label, [signature, new Map()]);
|
|
66
|
-
headers.set(SignatureHeaders.signatureInput,
|
|
75
|
+
headers.set(SignatureHeaders.signatureInput, signatureInput);
|
|
67
76
|
headers.set(SignatureHeaders.signature, serializeDictionary(signatures));
|
|
68
77
|
return new Request(request, { headers });
|
|
69
78
|
}
|
|
@@ -215,12 +224,6 @@ function toSignatureInput(label, entry) {
|
|
|
215
224
|
tag,
|
|
216
225
|
};
|
|
217
226
|
}
|
|
218
|
-
function algorithmFromKey(key) {
|
|
219
|
-
for (const algorithm of Object.values(Algorithms))
|
|
220
|
-
if (keySupportsAlgorithm(key, algorithm))
|
|
221
|
-
return algorithm;
|
|
222
|
-
throw new TypeError('HTTP message signatures require an Ed25519 or RSA-PSS SHA-512 signing key.');
|
|
223
|
-
}
|
|
224
227
|
function isInteger(value) {
|
|
225
228
|
return typeof value === 'number' && Number.isInteger(value);
|
|
226
229
|
}
|
|
@@ -317,6 +320,6 @@ function encode(value) {
|
|
|
317
320
|
return new TextEncoder().encode(value);
|
|
318
321
|
}
|
|
319
322
|
function toArrayBuffer(value) {
|
|
320
|
-
return
|
|
323
|
+
return Uint8Array.from(value).buffer;
|
|
321
324
|
}
|
|
322
325
|
//# sourceMappingURL=HttpMessageSignature.js.map
|
|
@@ -13,7 +13,7 @@ export async function fromKey(key) {
|
|
|
13
13
|
else if (jwk.kty === 'RSA' && jwk.e && jwk.n)
|
|
14
14
|
canonical = JSON.stringify({ e: jwk.e, kty: jwk.kty, n: jwk.n });
|
|
15
15
|
else
|
|
16
|
-
throw new TypeError('
|
|
16
|
+
throw new TypeError('RFC 7638 thumbprints need an Ed25519 or RSA public key.');
|
|
17
17
|
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonical));
|
|
18
18
|
return Base64.fromBytes(new Uint8Array(digest), { pad: false, url: true });
|
|
19
19
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SignatureAlgorithm, SigningKey } from '../Types.js';
|
|
2
|
+
/** A {@link SigningKey} checked and ready to sign. */
|
|
3
|
+
export type Resolved = {
|
|
4
|
+
/** Signature algorithm, from the public key. */
|
|
5
|
+
readonly algorithm: SignatureAlgorithm;
|
|
6
|
+
/** Public key that verifies every signature. */
|
|
7
|
+
readonly publicKey: CryptoKey;
|
|
8
|
+
/** Signs the complete message and resolves with the raw signature. */
|
|
9
|
+
readonly sign: (payload: Uint8Array) => Promise<Uint8Array<ArrayBuffer>>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Checks a {@link SigningKey} and returns how to sign with it.
|
|
13
|
+
*
|
|
14
|
+
* Throws a `TypeError` unless the key is a `CryptoKeyPair` or a {@link Signer} whose public key
|
|
15
|
+
* is one of `algorithms`. A `Signer`'s signatures are verified against its public key before
|
|
16
|
+
* they are returned.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolve(key: SigningKey, algorithms?: readonly SignatureAlgorithm[]): Resolved;
|
|
20
|
+
//# sourceMappingURL=Signer.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Algorithms } from '../Constants.js';
|
|
2
|
+
const webCrypto = {
|
|
3
|
+
[Algorithms.ed25519]: { name: 'Ed25519' },
|
|
4
|
+
[Algorithms.rsaPssSha512]: { name: 'RSA-PSS', saltLength: 64 },
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Checks a {@link SigningKey} and returns how to sign with it.
|
|
8
|
+
*
|
|
9
|
+
* Throws a `TypeError` unless the key is a `CryptoKeyPair` or a {@link Signer} whose public key
|
|
10
|
+
* is one of `algorithms`. A `Signer`'s signatures are verified against its public key before
|
|
11
|
+
* they are returned.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export function resolve(key, algorithms = Object.values(Algorithms)) {
|
|
15
|
+
if (!isObject(key))
|
|
16
|
+
throw invalidKey();
|
|
17
|
+
const { publicKey } = key;
|
|
18
|
+
if (isCryptoKey(key))
|
|
19
|
+
throw new TypeError('Signing keys are key pairs: pass { privateKey, publicKey } or a Signer, not a private key alone.');
|
|
20
|
+
if (!isCryptoKey(publicKey) || publicKey.type !== 'public')
|
|
21
|
+
throw invalidKey();
|
|
22
|
+
const algorithm = algorithmOf(publicKey);
|
|
23
|
+
if (!algorithm || !algorithms.includes(algorithm))
|
|
24
|
+
throw new TypeError(`Signing keys must be ${describe(algorithms)}.`);
|
|
25
|
+
const parameters = webCrypto[algorithm];
|
|
26
|
+
if (typeof key.sign === 'function') {
|
|
27
|
+
const signer = key;
|
|
28
|
+
if (!publicKey.usages.includes('verify'))
|
|
29
|
+
throw new TypeError('A Signer publicKey must have the verify usage.');
|
|
30
|
+
return {
|
|
31
|
+
algorithm,
|
|
32
|
+
publicKey,
|
|
33
|
+
async sign(payload) {
|
|
34
|
+
const signature = await signer.sign({ payload: Uint8Array.from(payload) });
|
|
35
|
+
if (!isUint8Array(signature))
|
|
36
|
+
throw new TypeError('A Signer must resolve with the raw signature as a Uint8Array.');
|
|
37
|
+
// A copy, so the signer can't change the signature after it is checked.
|
|
38
|
+
const bytes = Uint8Array.from(signature);
|
|
39
|
+
let valid = false;
|
|
40
|
+
try {
|
|
41
|
+
valid = await crypto.subtle.verify(parameters, publicKey, bytes, Uint8Array.from(payload));
|
|
42
|
+
}
|
|
43
|
+
catch { }
|
|
44
|
+
if (!valid)
|
|
45
|
+
throw new Error('The Signer returned a signature that does not verify with its publicKey. Check that it signs the payload itself (not a digest) with that key, and returns raw signature bytes.');
|
|
46
|
+
return bytes;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const { privateKey } = key;
|
|
51
|
+
if (!isCryptoKey(privateKey) || privateKey.type !== 'private')
|
|
52
|
+
throw invalidKey();
|
|
53
|
+
if (algorithmOf(privateKey) !== algorithm)
|
|
54
|
+
throw new TypeError('The privateKey and publicKey of a signing key pair use different algorithms.');
|
|
55
|
+
return {
|
|
56
|
+
algorithm,
|
|
57
|
+
publicKey,
|
|
58
|
+
async sign(payload) {
|
|
59
|
+
return new Uint8Array(await crypto.subtle.sign(parameters, privateKey, Uint8Array.from(payload)));
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** The signature algorithm a key is for, or `undefined` when it is not supported. */
|
|
64
|
+
function algorithmOf(key) {
|
|
65
|
+
if (key.algorithm.name === 'Ed25519')
|
|
66
|
+
return Algorithms.ed25519;
|
|
67
|
+
if (key.algorithm.name === 'RSA-PSS' &&
|
|
68
|
+
key.algorithm.hash?.name === 'SHA-512')
|
|
69
|
+
return Algorithms.rsaPssSha512;
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
function describe(algorithms) {
|
|
73
|
+
return algorithms
|
|
74
|
+
.map((algorithm) => (algorithm === Algorithms.ed25519 ? 'Ed25519' : 'RSA-PSS SHA-512'))
|
|
75
|
+
.join(' or ');
|
|
76
|
+
}
|
|
77
|
+
function invalidKey() {
|
|
78
|
+
return new TypeError('A signing key must be a CryptoKeyPair or a Signer with publicKey and sign.');
|
|
79
|
+
}
|
|
80
|
+
/** Whether `value` is a `Uint8Array` (or `Buffer`), including one from another realm. */
|
|
81
|
+
function isUint8Array(value) {
|
|
82
|
+
return (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === '[object Uint8Array]');
|
|
83
|
+
}
|
|
84
|
+
function isObject(value) {
|
|
85
|
+
return typeof value === 'object' && value !== null;
|
|
86
|
+
}
|
|
87
|
+
function isCryptoKey(value) {
|
|
88
|
+
// Duck-typed so keys from another realm or a WebCrypto polyfill keep working.
|
|
89
|
+
return (isObject(value) &&
|
|
90
|
+
typeof value.type === 'string' &&
|
|
91
|
+
isObject(value.algorithm) &&
|
|
92
|
+
Array.isArray(value.usages));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=Signer.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { MaybePromise } from '../../../internal/types.js';
|
|
2
|
+
/** Link agent identity values, as Link's Agent Identity SDK and Link CLI use them. */
|
|
3
|
+
export declare const Constants: {
|
|
4
|
+
/** Link's issuer, the only one the Agent Identity SDK trusts. */
|
|
5
|
+
readonly issuer: 'https://api.link.com';
|
|
6
|
+
/** `Authorization` scheme of an Agent Attestation Token (RFC 9577). */
|
|
7
|
+
readonly attestationScheme: 'PrivateToken';
|
|
8
|
+
/** Request header carrying an identity presentation, and its `WWW-Authenticate` scheme. */
|
|
9
|
+
readonly presentationHeader: 'Identity-Presentation';
|
|
10
|
+
/** `type` of the problem body of a claims challenge. */
|
|
11
|
+
readonly claimsRequiredType: 'urn:stripe:link:claims-required';
|
|
12
|
+
/** Presentation format of a claims challenge. */
|
|
13
|
+
readonly format: 'dc+sd-jwt';
|
|
14
|
+
/** Seconds a claims challenge's nonce is accepted for. */
|
|
15
|
+
readonly nonceTtl: 300;
|
|
16
|
+
};
|
|
17
|
+
/** One failure of a Link verification, as `@stripe/agent-identity` reports it. */
|
|
18
|
+
export type Failure = {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly message: string;
|
|
21
|
+
};
|
|
22
|
+
/** Verifies Link Agent Attestation Tokens: a `LinkVerifier`, or `Link.Server.tokenVerifier()`. */
|
|
23
|
+
export type AttestationVerifier = Pick<LinkVerifier, 'attestationChallenge' | 'verifyAttestation'>;
|
|
24
|
+
/** Verifies Link identity presentations: a `LinkVerifier`, or `Link.Server.presentationVerifier()`. */
|
|
25
|
+
export type ClaimsVerifier = Pick<LinkVerifier, 'verifyClaims'>;
|
|
26
|
+
/**
|
|
27
|
+
* The parts of `LinkVerifier` from `@stripe/agent-identity` the verifiers use. Pass one
|
|
28
|
+
* `new LinkVerifier({ origin })` per process, so every request shares its issuer key cache.
|
|
29
|
+
*/
|
|
30
|
+
export type LinkVerifier = {
|
|
31
|
+
attestationChallenge(): Promise<{
|
|
32
|
+
wwwAuthenticate: string[];
|
|
33
|
+
}>;
|
|
34
|
+
verifyAttestation(authorization: string | null | undefined): Promise<{
|
|
35
|
+
valid: true;
|
|
36
|
+
issuer: string;
|
|
37
|
+
tokenKeyId: string;
|
|
38
|
+
bindingMode?: 'bearer';
|
|
39
|
+
} | {
|
|
40
|
+
valid: false;
|
|
41
|
+
failures: readonly Failure[];
|
|
42
|
+
}>;
|
|
43
|
+
verifyClaims(presentation: string | null | undefined, options: {
|
|
44
|
+
nonce: string;
|
|
45
|
+
requiredClaims: string[];
|
|
46
|
+
}): Promise<{
|
|
47
|
+
valid: true;
|
|
48
|
+
issuer: string;
|
|
49
|
+
vct: string;
|
|
50
|
+
claims: Record<string, unknown>;
|
|
51
|
+
holderKeyThumbprint: string;
|
|
52
|
+
} | {
|
|
53
|
+
valid: false;
|
|
54
|
+
failures: readonly Failure[];
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
/** A verified Link Agent Attestation Token: Link vouches for the agent, and says nothing else. */
|
|
58
|
+
export type VerifiedAttestation = {
|
|
59
|
+
/** Issuer whose key signed the token. */
|
|
60
|
+
readonly issuer: string;
|
|
61
|
+
/** base64url of the token's `token_key_id`. */
|
|
62
|
+
readonly tokenKeyId: string;
|
|
63
|
+
};
|
|
64
|
+
/** Claims Link signed and the holder disclosed to this server. */
|
|
65
|
+
export type VerifiedClaims = {
|
|
66
|
+
/** Issuer of the credential. */
|
|
67
|
+
readonly issuer: string;
|
|
68
|
+
/** Credential type (`vct`). */
|
|
69
|
+
readonly vct: string;
|
|
70
|
+
/** The disclosed claims, by name. */
|
|
71
|
+
readonly claims: Readonly<Record<string, unknown>>;
|
|
72
|
+
/** RFC 7638 thumbprint of the holder key that signed the presentation. */
|
|
73
|
+
readonly holderKeyThumbprint: string;
|
|
74
|
+
/** The verified email address, lowercased, when `email` and a true `email_verified` were disclosed. */
|
|
75
|
+
readonly email?: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
/** A claims challenge: the problem body of a 401 with `WWW-Authenticate: Identity-Presentation`. */
|
|
78
|
+
export type ClaimsChallenge = {
|
|
79
|
+
readonly type: 'urn:stripe:link:claims-required';
|
|
80
|
+
/** Origin the presentation must be bound to. */
|
|
81
|
+
readonly aud: string;
|
|
82
|
+
/** Nonce the presentation must sign. */
|
|
83
|
+
readonly nonce: string;
|
|
84
|
+
/** Claims to disclose. */
|
|
85
|
+
readonly claims: readonly string[];
|
|
86
|
+
/** Why the server asks, for the person whose claims they are. */
|
|
87
|
+
readonly purpose?: string | undefined;
|
|
88
|
+
readonly formats: readonly string[];
|
|
89
|
+
readonly trusted_issuers: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
/** Creates a presentation for a claims challenge, such as with `link-cli identity credentials present`. */
|
|
92
|
+
export type Present = (parameters: {
|
|
93
|
+
/** Origin the presentation is for: always the request's own origin. */
|
|
94
|
+
audience: string;
|
|
95
|
+
/** Nonce from the challenge. */
|
|
96
|
+
nonce: string;
|
|
97
|
+
/** Claims to disclose. */
|
|
98
|
+
claims: readonly string[];
|
|
99
|
+
/** Why the server asks. */
|
|
100
|
+
purpose?: string | undefined;
|
|
101
|
+
}) => MaybePromise<string | undefined>;
|
|
102
|
+
//# sourceMappingURL=Constants.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Link agent identity values, as Link's Agent Identity SDK and Link CLI use them. */
|
|
2
|
+
export const Constants = {
|
|
3
|
+
/** Link's issuer, the only one the Agent Identity SDK trusts. */
|
|
4
|
+
issuer: 'https://api.link.com',
|
|
5
|
+
/** `Authorization` scheme of an Agent Attestation Token (RFC 9577). */
|
|
6
|
+
attestationScheme: 'PrivateToken',
|
|
7
|
+
/** Request header carrying an identity presentation, and its `WWW-Authenticate` scheme. */
|
|
8
|
+
presentationHeader: 'Identity-Presentation',
|
|
9
|
+
/** `type` of the problem body of a claims challenge. */
|
|
10
|
+
claimsRequiredType: 'urn:stripe:link:claims-required',
|
|
11
|
+
/** Presentation format of a claims challenge. */
|
|
12
|
+
format: 'dc+sd-jwt',
|
|
13
|
+
/** Seconds a claims challenge's nonce is accepted for. */
|
|
14
|
+
nonceTtl: 300,
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=Constants.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type * as Identity from '../../../../identity/Types.js';
|
|
2
|
+
import type { MaybePromise } from '../../../../internal/types.js';
|
|
3
|
+
import type * as Types from '../Constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a prover that answers Link attestation challenges with an Agent Attestation Token.
|
|
6
|
+
*
|
|
7
|
+
* When a server in `scope` answers 401 with `WWW-Authenticate: PrivateToken`, the prover gets a
|
|
8
|
+
* token from `token` (such as `link-cli identity attestations pop`), and resends the request
|
|
9
|
+
* with it in `Authorization`. Later requests to that origin, including paid retries, carry the
|
|
10
|
+
* same token; a rejected one is replaced once. A request that already has an `Authorization`
|
|
11
|
+
* header is left as it is.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const mppx = Mppx.create({
|
|
16
|
+
* identity: [
|
|
17
|
+
* Link.Client.attestation({
|
|
18
|
+
* scope: ['https://api.example'],
|
|
19
|
+
* token: async () => (await linkCli('identity', 'attestations', 'pop')).authorization,
|
|
20
|
+
* }),
|
|
21
|
+
* ],
|
|
22
|
+
* methods: [tempo({ account })],
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function attestation(config: attestation.Config): Identity.Prover;
|
|
27
|
+
export declare namespace attestation {
|
|
28
|
+
type Config = {
|
|
29
|
+
/** Origins that may receive a token, or `'*'` for any origin. */
|
|
30
|
+
readonly scope: Identity.Prover['scope'];
|
|
31
|
+
/**
|
|
32
|
+
* Returns an unused token: Link CLI's `authorization` value (`PrivateToken token="…"`) or the
|
|
33
|
+
* bare token. `undefined` declines.
|
|
34
|
+
*/
|
|
35
|
+
readonly token: (parameters: {
|
|
36
|
+
origin: string;
|
|
37
|
+
}) => MaybePromise<string | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets a token before the first request to an origin instead of after its challenge, so a
|
|
40
|
+
* server that prices requests by the proofs they carry sees it from the start.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
readonly eager?: boolean | undefined;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a prover that answers Link claims challenges with an identity presentation.
|
|
48
|
+
*
|
|
49
|
+
* When a server in `scope` answers 401 with `WWW-Authenticate: Identity-Presentation` and a
|
|
50
|
+
* `urn:stripe:link:claims-required` body, the prover checks that the challenge names the
|
|
51
|
+
* request's own origin as audience, trusts Link, and asks only for claims in `claims`. It then
|
|
52
|
+
* gets a presentation from `present` (such as `link-cli identity credentials present`) and
|
|
53
|
+
* resends the request with it in `Identity-Presentation`. Later requests to that origin carry
|
|
54
|
+
* it until the server asks again.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* Link.Client.claims({
|
|
59
|
+
* claims: ['email', 'email_verified'],
|
|
60
|
+
* present: ({ audience, nonce, claims }) => linkCliPresent({ audience, nonce, claims }),
|
|
61
|
+
* scope: ['https://api.example'],
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function claims(config: claims.Config): Identity.Prover;
|
|
66
|
+
export declare namespace claims {
|
|
67
|
+
type Config = {
|
|
68
|
+
/** Origins that may receive a presentation, or `'*'` for any origin. */
|
|
69
|
+
readonly scope: Identity.Prover['scope'];
|
|
70
|
+
/** Claims the prover may disclose, such as `['email', 'email_verified']`. */
|
|
71
|
+
readonly claims: readonly string[];
|
|
72
|
+
/** Creates a presentation for a challenge, or returns `undefined` to decline. */
|
|
73
|
+
readonly present: Types.Present;
|
|
74
|
+
/** Issuers whose credentials may be presented. Override only for staging and tests. @default ['https://api.link.com'] */
|
|
75
|
+
readonly issuers?: readonly string[] | undefined;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Parses a claims challenge's problem body, or returns `undefined` when it is not one. */
|
|
79
|
+
export declare function claimsChallenge(response: Response): Promise<Types.ClaimsChallenge | undefined>;
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|