@sirosfoundation/wmp-js 0.5.2 → 0.7.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/dist/completion.d.ts +107 -0
- package/dist/completion.js +544 -0
- package/dist/consent.d.ts +53 -0
- package/dist/consent.js +136 -0
- package/dist/discovery.d.ts +48 -8
- package/dist/discovery.js +119 -38
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +10 -0
- package/dist/evidence.d.ts +1 -0
- package/dist/evidence.js +1 -0
- package/dist/index.d.ts +14 -6
- package/dist/index.js +12 -3
- package/dist/jsonrpc.d.ts +2 -0
- package/dist/jsonrpc.js +4 -1
- package/dist/openid4x.d.ts +165 -17
- package/dist/openid4x.js +176 -3
- package/dist/peer.d.ts +234 -3
- package/dist/peer.js +1007 -51
- package/dist/profile.d.ts +39 -0
- package/dist/random.d.ts +2 -0
- package/dist/random.js +7 -0
- package/dist/relay.js +4 -2
- package/dist/session-store.d.ts +75 -3
- package/dist/session-store.js +105 -4
- package/dist/signflow.d.ts +173 -0
- package/dist/signflow.js +464 -0
- package/dist/transport.d.ts +45 -4
- package/dist/transport.js +209 -42
- package/dist/types.d.ts +2 -0
- package/dist/types.js +2 -0
- package/dist/version.d.ts +30 -0
- package/dist/version.js +61 -0
- package/package.json +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `select_credentials` consent action (WMP OpenID4x profile 3.2.3.1,
|
|
3
|
+
* schema/methods/select-credentials-params.json).
|
|
4
|
+
*
|
|
5
|
+
* The params are a closed set: `consent` and `selections` of
|
|
6
|
+
* `{query_id, selection_handle}`. Nothing that identifies a credential, a claim
|
|
7
|
+
* or the user can ride along, so the orchestrator learns only that the user
|
|
8
|
+
* consented and for which of the verifier's own query ids. Unknown members are
|
|
9
|
+
* REFUSED here, unlike elsewhere in WMP (Core 9.5): ignoring a member would
|
|
10
|
+
* still have received it. Errors never echo a value.
|
|
11
|
+
*/
|
|
12
|
+
import type { ConsentAction } from "./openid4x.js";
|
|
13
|
+
export declare class ActionParamsError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** True for a well-formed selection handle (profile 3.2.3.1, 3.3.2). */
|
|
17
|
+
export declare function isSelectionHandle(h: unknown): h is string;
|
|
18
|
+
/** True for a well-formed query_id (1 to 256 code points, the form of the schema pattern). */
|
|
19
|
+
export declare function isQueryId(q: unknown): q is string;
|
|
20
|
+
/**
|
|
21
|
+
* A fresh selection handle: 128 random bits as 22 base64url characters
|
|
22
|
+
* (profile 3.3.2). It MUST NOT be derived from a credential, its identifier,
|
|
23
|
+
* its content or the user, and MUST NOT be reused in another flow: mint one per
|
|
24
|
+
* flow and keep it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function newSelectionHandle(): string;
|
|
27
|
+
export interface SelectCredentialsContext {
|
|
28
|
+
/** The ids of the verifier's credential queries (or input descriptors). Each query_id must be one. */
|
|
29
|
+
queryIds?: readonly string[];
|
|
30
|
+
/** The handle of the match result for this request, when it carried one: every selection must equal it. */
|
|
31
|
+
matchHandle?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks the `params` of a select_credentials action. Throws
|
|
35
|
+
* {@link ActionParamsError} on the first violation: a member outside the closed
|
|
36
|
+
* set, a wrong type, a malformed query_id or handle, a handle that differs
|
|
37
|
+
* between elements (or from `matchHandle`), a query_id that is repeated (or not
|
|
38
|
+
* in `queryIds`), selections present when consent is false, or absent/empty when
|
|
39
|
+
* it is true.
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateSelectCredentialsParams(params: unknown, ctx?: SelectCredentialsContext): ConsentAction;
|
|
42
|
+
/**
|
|
43
|
+
* Builds select_credentials params after validating them: the user declined
|
|
44
|
+
* (`consent: false`) or consents to the given query ids, all under one handle
|
|
45
|
+
* (the match result's, or {@link newSelectionHandle}).
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildSelectCredentials(decision: {
|
|
48
|
+
consent: false;
|
|
49
|
+
} | {
|
|
50
|
+
consent: true;
|
|
51
|
+
queryIds: readonly string[];
|
|
52
|
+
selectionHandle: string;
|
|
53
|
+
}, ctx?: SelectCredentialsContext): ConsentAction;
|
package/dist/consent.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `select_credentials` consent action (WMP OpenID4x profile 3.2.3.1,
|
|
3
|
+
* schema/methods/select-credentials-params.json).
|
|
4
|
+
*
|
|
5
|
+
* The params are a closed set: `consent` and `selections` of
|
|
6
|
+
* `{query_id, selection_handle}`. Nothing that identifies a credential, a claim
|
|
7
|
+
* or the user can ride along, so the orchestrator learns only that the user
|
|
8
|
+
* consented and for which of the verifier's own query ids. Unknown members are
|
|
9
|
+
* REFUSED here, unlike elsewhere in WMP (Core 9.5): ignoring a member would
|
|
10
|
+
* still have received it. Errors never echo a value.
|
|
11
|
+
*/
|
|
12
|
+
import { getRandomValues } from "./random.js";
|
|
13
|
+
export class ActionParamsError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(`non-conforming action params: ${message}`);
|
|
16
|
+
this.name = "ActionParamsError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// 22 or more base64url characters, no padding, a length a base64url encoding can have (4n, 4n+2, 4n+3).
|
|
20
|
+
const HANDLE_FORM = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
21
|
+
// No ASCII or Unicode whitespace, no C0/C1 controls, no zero-width or byte-order-mark characters.
|
|
22
|
+
const FORBIDDEN_IN_QUERY_ID = [
|
|
23
|
+
[0x0000, 0x0020], // C0 controls and the space
|
|
24
|
+
[0x007f, 0x00a0], // DEL, C1 controls and the no-break space
|
|
25
|
+
[0x1680, 0x1680],
|
|
26
|
+
[0x2000, 0x200b], // spaces and zero-width characters
|
|
27
|
+
[0x2028, 0x202f],
|
|
28
|
+
[0x205f, 0x2060],
|
|
29
|
+
[0x3000, 0x3000],
|
|
30
|
+
[0xfeff, 0xfeff], // byte-order mark
|
|
31
|
+
];
|
|
32
|
+
/** True for a well-formed selection handle (profile 3.2.3.1, 3.3.2). */
|
|
33
|
+
export function isSelectionHandle(h) {
|
|
34
|
+
return typeof h === "string" && h.length >= 22 && HANDLE_FORM.test(h);
|
|
35
|
+
}
|
|
36
|
+
/** True for a well-formed query_id (1 to 256 code points, the form of the schema pattern). */
|
|
37
|
+
export function isQueryId(q) {
|
|
38
|
+
if (typeof q !== "string")
|
|
39
|
+
return false;
|
|
40
|
+
let n = 0;
|
|
41
|
+
for (const ch of q) {
|
|
42
|
+
const cp = ch.codePointAt(0);
|
|
43
|
+
if (FORBIDDEN_IN_QUERY_ID.some(([lo, hi]) => cp >= lo && cp <= hi))
|
|
44
|
+
return false;
|
|
45
|
+
n++;
|
|
46
|
+
}
|
|
47
|
+
return n >= 1 && n <= 256;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A fresh selection handle: 128 random bits as 22 base64url characters
|
|
51
|
+
* (profile 3.3.2). It MUST NOT be derived from a credential, its identifier,
|
|
52
|
+
* its content or the user, and MUST NOT be reused in another flow: mint one per
|
|
53
|
+
* flow and keep it.
|
|
54
|
+
*/
|
|
55
|
+
export function newSelectionHandle() {
|
|
56
|
+
const bytes = getRandomValues(16);
|
|
57
|
+
let bin = "";
|
|
58
|
+
for (const b of bytes)
|
|
59
|
+
bin += String.fromCodePoint(b);
|
|
60
|
+
return btoa(bin).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
61
|
+
}
|
|
62
|
+
function isObj(v) {
|
|
63
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
64
|
+
}
|
|
65
|
+
function refuse(msg) {
|
|
66
|
+
throw new ActionParamsError(msg);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks the `params` of a select_credentials action. Throws
|
|
70
|
+
* {@link ActionParamsError} on the first violation: a member outside the closed
|
|
71
|
+
* set, a wrong type, a malformed query_id or handle, a handle that differs
|
|
72
|
+
* between elements (or from `matchHandle`), a query_id that is repeated (or not
|
|
73
|
+
* in `queryIds`), selections present when consent is false, or absent/empty when
|
|
74
|
+
* it is true.
|
|
75
|
+
*/
|
|
76
|
+
export function validateSelectCredentialsParams(params, ctx = {}) {
|
|
77
|
+
if (!isObj(params))
|
|
78
|
+
refuse("params is not an object");
|
|
79
|
+
for (const k of Object.keys(params)) {
|
|
80
|
+
if (k !== "consent" && k !== "selections")
|
|
81
|
+
refuse("params carries a member outside the closed set");
|
|
82
|
+
}
|
|
83
|
+
if (typeof params.consent !== "boolean")
|
|
84
|
+
refuse("consent is not a boolean");
|
|
85
|
+
const consent = params.consent;
|
|
86
|
+
const sel = params.selections;
|
|
87
|
+
if (sel !== undefined && !Array.isArray(sel))
|
|
88
|
+
refuse("selections is not an array");
|
|
89
|
+
if (!consent) {
|
|
90
|
+
if (sel !== undefined && sel.length > 0)
|
|
91
|
+
refuse("selections present although consent is false");
|
|
92
|
+
return { consent: false, ...(sel !== undefined ? { selections: [] } : {}) };
|
|
93
|
+
}
|
|
94
|
+
if (sel === undefined || sel.length === 0)
|
|
95
|
+
refuse("selections absent or empty although consent is true");
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
let handle;
|
|
98
|
+
const out = [];
|
|
99
|
+
// Every index, holes of a sparse array included (forEach would skip them): a hole is not a selection.
|
|
100
|
+
for (let i = 0; i < sel.length; i++) {
|
|
101
|
+
const s = sel[i];
|
|
102
|
+
if (!isObj(s))
|
|
103
|
+
refuse(`selections[${i}] is not an object`);
|
|
104
|
+
for (const k of Object.keys(s)) {
|
|
105
|
+
if (k !== "query_id" && k !== "selection_handle")
|
|
106
|
+
refuse(`selections[${i}] carries a member outside the closed set`);
|
|
107
|
+
}
|
|
108
|
+
if (!isQueryId(s.query_id))
|
|
109
|
+
refuse(`selections[${i}].query_id is missing or malformed`);
|
|
110
|
+
if (!isSelectionHandle(s.selection_handle))
|
|
111
|
+
refuse(`selections[${i}].selection_handle is missing or malformed`);
|
|
112
|
+
if (seen.has(s.query_id))
|
|
113
|
+
refuse("query_id repeated");
|
|
114
|
+
seen.add(s.query_id);
|
|
115
|
+
if (ctx.queryIds && !ctx.queryIds.includes(s.query_id))
|
|
116
|
+
refuse(`selections[${i}].query_id is not an id of the request`);
|
|
117
|
+
if (handle !== undefined && s.selection_handle !== handle)
|
|
118
|
+
refuse("selection_handle differs between elements");
|
|
119
|
+
handle = s.selection_handle;
|
|
120
|
+
out.push({ query_id: s.query_id, selection_handle: s.selection_handle });
|
|
121
|
+
}
|
|
122
|
+
if (ctx.matchHandle !== undefined && handle !== ctx.matchHandle)
|
|
123
|
+
refuse("selection_handle differs from the match result's handle");
|
|
124
|
+
return { consent: true, selections: out };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Builds select_credentials params after validating them: the user declined
|
|
128
|
+
* (`consent: false`) or consents to the given query ids, all under one handle
|
|
129
|
+
* (the match result's, or {@link newSelectionHandle}).
|
|
130
|
+
*/
|
|
131
|
+
export function buildSelectCredentials(decision, ctx = {}) {
|
|
132
|
+
const params = decision.consent
|
|
133
|
+
? { consent: true, selections: Array.from(decision.queryIds, (q) => ({ query_id: q, selection_handle: decision.selectionHandle })) } // visits holes too
|
|
134
|
+
: { consent: false };
|
|
135
|
+
return validateSelectCredentialsParams(params, ctx);
|
|
136
|
+
}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WMP endpoint discovery — mirrors go-wmp/pkg/wmp/discovery.go.
|
|
3
3
|
*/
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Well-known WMP configuration as served at /.well-known/wmp-configuration,
|
|
6
|
+
* or below it for a tenant.
|
|
7
|
+
*/
|
|
5
8
|
export interface WellKnownConfig {
|
|
9
|
+
/**
|
|
10
|
+
* The discovery base the document describes:
|
|
11
|
+
* `https://<host><tenant-path>`. Required for a tenant path.
|
|
12
|
+
*/
|
|
13
|
+
discovery_base?: string;
|
|
6
14
|
supported_versions: string[];
|
|
7
15
|
endpoints: Record<string, string>;
|
|
8
16
|
security_modes: string[];
|
|
@@ -38,14 +46,46 @@ export interface RecipientMetadata {
|
|
|
38
46
|
*/
|
|
39
47
|
export declare function extractDomain(identifier: string): string;
|
|
40
48
|
/**
|
|
41
|
-
*
|
|
49
|
+
* Where the well-known configuration of a domain-based identifier is found
|
|
50
|
+
* (WMP Core 7.5.1): a host and, for a tenant of a host that serves several
|
|
51
|
+
* providers, the tenant's path.
|
|
52
|
+
*/
|
|
53
|
+
export interface DiscoveryBase {
|
|
54
|
+
/** The host, with its port when the identifier names one. */
|
|
55
|
+
host: string;
|
|
56
|
+
/** Empty for the whole host; otherwise starts with "/", no trailing "/". */
|
|
57
|
+
tenantPath: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Derive the discovery base of an identifier, or `null` when it has none.
|
|
61
|
+
*
|
|
62
|
+
* x509:san:dns:example.com -> example.com
|
|
63
|
+
* https://example.com/tenant1 -> example.com, /tenant1
|
|
64
|
+
* x509:san:uri:https://example.com/tenant -> example.com, /tenant
|
|
65
|
+
* did:web:example.com -> example.com
|
|
66
|
+
*
|
|
67
|
+
* A did:web identifier with a path has none: the did:web method resolves it
|
|
68
|
+
* through its DID Document, whose WMPMessaging service names the endpoint
|
|
69
|
+
* (WMP Core 7.5.4). An identifier with a query, a fragment, userinfo or a
|
|
70
|
+
* "." or ".." path segment has none either.
|
|
71
|
+
*/
|
|
72
|
+
export declare function discoveryBase(identifier: string): DiscoveryBase | null;
|
|
73
|
+
/**
|
|
74
|
+
* The URL of a base's configuration: the well-known segment inserted between
|
|
75
|
+
* the host and the tenant path, as RFC 8414 Section 3.1 does.
|
|
76
|
+
*/
|
|
77
|
+
export declare function wellKnownUrl(base: DiscoveryBase): string;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch the well-known WMP configuration for a domain-based WMP identifier.
|
|
42
80
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
81
|
+
* The configuration is fetched at exactly the URL of the identifier's
|
|
82
|
+
* discovery base ({@link discoveryBase}, {@link wellKnownUrl}):
|
|
83
|
+
* `https://host/tenant1` resolves at
|
|
84
|
+
* `https://host/.well-known/wmp-configuration/tenant1`. A tenant never gets
|
|
85
|
+
* its host's configuration, and the document's `discovery_base` must name
|
|
86
|
+
* the base: required for a tenant, checked when present for a whole host.
|
|
48
87
|
*
|
|
49
|
-
* Throws if
|
|
88
|
+
* Throws if the identifier has no discovery base, the fetch fails, or the
|
|
89
|
+
* document is for another base.
|
|
50
90
|
*/
|
|
51
91
|
export declare function discoverEndpoint(identifier: string, fetchFn?: typeof globalThis.fetch): Promise<WellKnownConfig>;
|
package/dist/discovery.js
CHANGED
|
@@ -48,54 +48,135 @@ export function extractDomain(identifier) {
|
|
|
48
48
|
}
|
|
49
49
|
return "";
|
|
50
50
|
}
|
|
51
|
+
const HOST_RE = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(:\d{1,5})?$/i;
|
|
52
|
+
const IPV6_HOST_RE = /^\[[0-9a-f:.]+\](:\d{1,5})?$/i;
|
|
53
|
+
function hostBase(host) {
|
|
54
|
+
if (host.length > 259 || !(HOST_RE.test(host) || IPV6_HOST_RE.test(host))) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return { host, tenantPath: "" };
|
|
58
|
+
}
|
|
51
59
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* at the URL's own path prefix FIRST (`https://host/wmp-engine/.well-known/
|
|
56
|
-
* wmp-configuration`) — path-prefixed deployments (a reverse proxy's
|
|
57
|
-
* location) serve it there — and falls back to the domain root.
|
|
58
|
-
* For bare identifiers (domains, DIDs), fetches the domain root.
|
|
59
|
-
*
|
|
60
|
-
* Throws if no domain can be extracted or every fetch fails.
|
|
60
|
+
* The base of an https URL, read from the string as written: `URL` would
|
|
61
|
+
* resolve dot segments and drop an empty query, and the identifier is what
|
|
62
|
+
* the tenant path is compared with.
|
|
61
63
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
throw new Error(`Cannot extract domain from identifier "${identifier}": use session parameters or a profile resolver`);
|
|
64
|
+
function urlBase(raw) {
|
|
65
|
+
if (!raw.startsWith("https://") || /[?#\\\s]/.test(raw)) {
|
|
66
|
+
return null;
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
68
|
+
const rest = raw.slice("https://".length);
|
|
69
|
+
const slash = rest.indexOf("/");
|
|
70
|
+
const base = hostBase(slash < 0 ? rest : rest.slice(0, slash));
|
|
71
|
+
if (!base) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
let end = rest.length;
|
|
75
|
+
while (slash >= 0 && end > slash && rest[end - 1] === "/") {
|
|
76
|
+
end--;
|
|
77
|
+
}
|
|
78
|
+
const tenantPath = slash < 0 ? "" : rest.slice(slash, end);
|
|
79
|
+
for (const segment of tenantPath.split("/")) {
|
|
80
|
+
let decoded;
|
|
71
81
|
try {
|
|
72
|
-
|
|
73
|
-
const path = url.pathname.replace(/\/+$/, "").replace(/\/wmp$/, "");
|
|
74
|
-
if (path && path !== "/") {
|
|
75
|
-
candidates.push(`${url.origin}${path}/.well-known/wmp-configuration`);
|
|
76
|
-
}
|
|
82
|
+
decoded = decodeURIComponent(segment);
|
|
77
83
|
}
|
|
78
84
|
catch {
|
|
79
|
-
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (decoded === "." || decoded === "..") {
|
|
88
|
+
return null;
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
91
|
+
return { host: base.host, tenantPath };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Derive the discovery base of an identifier, or `null` when it has none.
|
|
95
|
+
*
|
|
96
|
+
* x509:san:dns:example.com -> example.com
|
|
97
|
+
* https://example.com/tenant1 -> example.com, /tenant1
|
|
98
|
+
* x509:san:uri:https://example.com/tenant -> example.com, /tenant
|
|
99
|
+
* did:web:example.com -> example.com
|
|
100
|
+
*
|
|
101
|
+
* A did:web identifier with a path has none: the did:web method resolves it
|
|
102
|
+
* through its DID Document, whose WMPMessaging service names the endpoint
|
|
103
|
+
* (WMP Core 7.5.4). An identifier with a query, a fragment, userinfo or a
|
|
104
|
+
* "." or ".." path segment has none either.
|
|
105
|
+
*/
|
|
106
|
+
export function discoveryBase(identifier) {
|
|
107
|
+
if (identifier.startsWith("x509:san:dns:")) {
|
|
108
|
+
return hostBase(identifier.slice("x509:san:dns:".length));
|
|
109
|
+
}
|
|
110
|
+
if (identifier.startsWith("x509:san:uri:")) {
|
|
111
|
+
return urlBase(identifier.slice("x509:san:uri:".length));
|
|
112
|
+
}
|
|
113
|
+
if (identifier.startsWith("https://")) {
|
|
114
|
+
return urlBase(identifier);
|
|
115
|
+
}
|
|
116
|
+
if (identifier.startsWith("did:web:")) {
|
|
117
|
+
const parts = identifier.slice("did:web:".length).split(":");
|
|
118
|
+
if (parts.length !== 1) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
85
121
|
try {
|
|
86
|
-
|
|
87
|
-
headers: { Accept: "application/json" },
|
|
88
|
-
});
|
|
89
|
-
if (resp.ok) {
|
|
90
|
-
return (await resp.json());
|
|
91
|
-
}
|
|
92
|
-
lastError = new Error(`WMP discovery failed for ${url}: HTTP ${resp.status}`);
|
|
122
|
+
return hostBase(decodeURIComponent(parts[0]));
|
|
93
123
|
}
|
|
94
|
-
catch
|
|
95
|
-
|
|
124
|
+
catch {
|
|
125
|
+
return null;
|
|
96
126
|
}
|
|
97
127
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The URL of a base's configuration: the well-known segment inserted between
|
|
132
|
+
* the host and the tenant path, as RFC 8414 Section 3.1 does.
|
|
133
|
+
*/
|
|
134
|
+
export function wellKnownUrl(base) {
|
|
135
|
+
return `https://${base.host}/.well-known/wmp-configuration${base.tenantPath}`;
|
|
136
|
+
}
|
|
137
|
+
/** Whether a configuration describes the base it was fetched for. */
|
|
138
|
+
function describesBase(config, base) {
|
|
139
|
+
if (config.discovery_base === undefined || config.discovery_base === "") {
|
|
140
|
+
return base.tenantPath === "";
|
|
141
|
+
}
|
|
142
|
+
// The declared base is compared as written: a trailing "/" is not the
|
|
143
|
+
// base, only an identifier's path is trimmed.
|
|
144
|
+
if (typeof config.discovery_base !== "string" ||
|
|
145
|
+
config.discovery_base.endsWith("/")) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
// The scheme compares case-insensitively, like the host.
|
|
149
|
+
const got = urlBase(config.discovery_base.replace(/^https:/i, "https:"));
|
|
150
|
+
return (got !== null &&
|
|
151
|
+
got.host.toLowerCase() === base.host.toLowerCase() &&
|
|
152
|
+
got.tenantPath === base.tenantPath);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Fetch the well-known WMP configuration for a domain-based WMP identifier.
|
|
156
|
+
*
|
|
157
|
+
* The configuration is fetched at exactly the URL of the identifier's
|
|
158
|
+
* discovery base ({@link discoveryBase}, {@link wellKnownUrl}):
|
|
159
|
+
* `https://host/tenant1` resolves at
|
|
160
|
+
* `https://host/.well-known/wmp-configuration/tenant1`. A tenant never gets
|
|
161
|
+
* its host's configuration, and the document's `discovery_base` must name
|
|
162
|
+
* the base: required for a tenant, checked when present for a whole host.
|
|
163
|
+
*
|
|
164
|
+
* Throws if the identifier has no discovery base, the fetch fails, or the
|
|
165
|
+
* document is for another base.
|
|
166
|
+
*/
|
|
167
|
+
export async function discoverEndpoint(identifier, fetchFn = globalThis.fetch.bind(globalThis)) {
|
|
168
|
+
const base = discoveryBase(identifier);
|
|
169
|
+
if (!base) {
|
|
170
|
+
throw new Error(`Identifier "${identifier}" has no discovery base: use session parameters or a profile resolver`);
|
|
171
|
+
}
|
|
172
|
+
const url = wellKnownUrl(base);
|
|
173
|
+
const resp = await fetchFn(url, { headers: { Accept: "application/json" } });
|
|
174
|
+
if (!resp.ok) {
|
|
175
|
+
throw new Error(`WMP discovery failed for ${url}: HTTP ${resp.status}`);
|
|
176
|
+
}
|
|
177
|
+
const config = (await resp.json());
|
|
178
|
+
if (config === null || typeof config !== "object" || !describesBase(config, base)) {
|
|
179
|
+
throw new Error(`WMP discovery failed for ${url}: the configuration is not for https://${base.host}${base.tenantPath}`);
|
|
180
|
+
}
|
|
181
|
+
return config;
|
|
101
182
|
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WMPError } from "./jsonrpc.js";
|
|
2
|
+
/**
|
|
3
|
+
* The -31005 (Capability not supported) error whose data is
|
|
4
|
+
* {"unsupported": item} plus the additive members in `extra` (Core 3.8.1);
|
|
5
|
+
* mirrors go-wmp NewUnsupportedError. A key "unsupported" in extra is ignored.
|
|
6
|
+
*/
|
|
7
|
+
export declare function unsupportedError(unsupported: string, extra?: Record<string, unknown>): WMPError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WMPError } from "./jsonrpc.js";
|
|
2
|
+
import { ErrorCode } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The -31005 (Capability not supported) error whose data is
|
|
5
|
+
* {"unsupported": item} plus the additive members in `extra` (Core 3.8.1);
|
|
6
|
+
* mirrors go-wmp NewUnsupportedError. A key "unsupported" in extra is ignored.
|
|
7
|
+
*/
|
|
8
|
+
export function unsupportedError(unsupported, extra) {
|
|
9
|
+
return new WMPError(ErrorCode.CapabilityNotSupported, "Capability not supported", { ...extra, unsupported });
|
|
10
|
+
}
|
package/dist/evidence.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare const EventReasonCode: {
|
|
|
38
38
|
readonly Timeout: "timeout";
|
|
39
39
|
readonly SystemError: "system_error";
|
|
40
40
|
readonly DelegationInvalid: "delegation_invalid";
|
|
41
|
+
readonly PlaintextHashMismatch: "plaintext_hash_mismatch";
|
|
41
42
|
};
|
|
42
43
|
export interface EvidenceEventReason {
|
|
43
44
|
code: string;
|
package/dist/evidence.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -15,16 +15,24 @@ export { MLSMethod, CipherSuiteX25519AES128GCM, CipherSuiteP256AES128GCM, Creden
|
|
|
15
15
|
export { TsMlsProvider } from "./mls-provider.js";
|
|
16
16
|
export type { TsMlsProviderOptions } from "./mls-provider.js";
|
|
17
17
|
export type { MLSMethodName, GroupCreateParams, GroupCreateResult, GroupJoinParams, GroupJoinResult, GroupAddParams, GroupAddResult, GroupRemoveParams, GroupRemoveResult, GroupUpdateParams, MessageFetchParams, MessageFetchResult, KeyPackage, KeyPackagesResponse, EncryptedEnvelope, MLSHandler, MLSProvider, } from "./mls.js";
|
|
18
|
-
export {
|
|
19
|
-
export
|
|
18
|
+
export { SUPPORTED_VERSIONS, parseVersion, negotiateVersion, versionRejection } from "./version.js";
|
|
19
|
+
export { unsupportedError } from "./errors.js";
|
|
20
|
+
export { validateCompletionResult, validateMatchResult, dcqlQueryIds, splitReplaySecrets, redactedMembers, CompletionResultError, DEFAULT_SECRET_MEMBERS, REPLAY_SECRET_MEMBERS, MAX_ENCRYPTED_CREDENTIAL_COUNT, MAX_RESPONSE_JWE_LEN, } from "./completion.js";
|
|
21
|
+
export type { ReplaySplit } from "./completion.js";
|
|
22
|
+
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, buildVCIFlowStart, withAttestation, transactionDataHashesAlgs, SubFlowRejectedError, } from "./openid4x.js";
|
|
23
|
+
export type { CredentialFormatType, OID4VCICapability, OID4VPCapability, CredentialDisplay, CredentialConfigurationSupported, CredentialResult, CredentialEvent, CredentialNotificationParams, VPTokenResult, ClientAttestation, ClientAttestationProvider, OID4VCIFlowParams, OID4VPFlowParams, SignSubFlowParams, SelectionAction, ConsentAction, CredentialSelection, CredentialToInclude, CredentialResponseEncryption, TransactionData, FlowStartHandler, ActionHandler, OpenID4xConfig, } from "./openid4x.js";
|
|
24
|
+
export { CAPABILITY_TRANSACTION_DATA, TRANSACTION_DATA_VERSION_1, TRANSACTION_DATA_HASH_ALGS, SIGN_ACTIONS, MAX_PROOF_COUNT, SignFlow, boundNotifier, offersTransactionData, transactionDataUnsupportedData, transactionDataUnsupportedError, transactionDataHash, decodeTransactionData, checkTransactionDataEntry, parseSignSubFlowParams, parseMatchStartParams, completeSubFlow, failSubFlow, rejectSubFlow, validateSignResult, unsupportedTransactionData, } from "./signflow.js";
|
|
25
|
+
export type { TransactionDataCapability, MatchStartParams, MatchResult, FlowNotifier } from "./signflow.js";
|
|
26
|
+
export { ActionParamsError, validateSelectCredentialsParams, buildSelectCredentials, newSelectionHandle, isSelectionHandle, isQueryId, } from "./consent.js";
|
|
27
|
+
export type { SelectCredentialsContext } from "./consent.js";
|
|
20
28
|
export { EvidenceEvent, EventReasonCode } from "./evidence.js";
|
|
21
29
|
export type { EvidenceEventType, EvidenceEventReason, EvidenceIssuer, ExternalSystem, ExternalErds, EvidenceNotifyParams, } from "./evidence.js";
|
|
22
30
|
export { Relay } from "./relay.js";
|
|
23
31
|
export type { RelayConfig, QueuedMessage } from "./relay.js";
|
|
24
|
-
export { MemorySessionStore } from "./session-store.js";
|
|
25
|
-
export type { Session, SessionStore } from "./session-store.js";
|
|
26
|
-
export { extractDomain, discoverEndpoint } from "./discovery.js";
|
|
27
|
-
export type { WellKnownConfig } from "./discovery.js";
|
|
32
|
+
export { MemorySessionStore, SessionStoreError, isSessionExpired, sessionOwnedBy, tokensEqual, } from "./session-store.js";
|
|
33
|
+
export type { Session, SessionStore, SessionStoreErrorCode, TokenRotator, SessionCreator, SessionUpdater, ExpiredSessionLister, } from "./session-store.js";
|
|
34
|
+
export { extractDomain, discoverEndpoint, discoveryBase, wellKnownUrl, } from "./discovery.js";
|
|
35
|
+
export type { WellKnownConfig, DiscoveryBase } from "./discovery.js";
|
|
28
36
|
export type { ErdsMetadata, RecipientMetadata } from "./discovery.js";
|
|
29
37
|
export { InvitationPurpose, createInvitation, invitationSigningPayload, invitationToURI, invitationToHTTPSURI, parseInvitationURI, parseInvitationJSON, isInvitationExpired, generateNonce, MemoryInvitationStore, validateInvitationNonce, } from "./invitation.js";
|
|
30
38
|
export type { Invitation, CreateInvitationOptions, InvitationStore, } from "./invitation.js";
|
package/dist/index.js
CHANGED
|
@@ -14,15 +14,24 @@ export { Peer } from "./peer.js";
|
|
|
14
14
|
// MLS
|
|
15
15
|
export { MLSMethod, CipherSuiteX25519AES128GCM, CipherSuiteP256AES128GCM, CredentialType, MLSProfile, mlsMethods, NoopMLSHandler, NoopMLSProvider, } from "./mls.js";
|
|
16
16
|
export { TsMlsProvider } from "./mls-provider.js";
|
|
17
|
+
// Version negotiation and errors
|
|
18
|
+
export { SUPPORTED_VERSIONS, parseVersion, negotiateVersion, versionRejection } from "./version.js";
|
|
19
|
+
export { unsupportedError } from "./errors.js";
|
|
20
|
+
// Completion-result rules (OpenID4x profile 3.1.4, 3.3)
|
|
21
|
+
export { validateCompletionResult, validateMatchResult, dcqlQueryIds, splitReplaySecrets, redactedMembers, CompletionResultError, DEFAULT_SECRET_MEMBERS, REPLAY_SECRET_MEMBERS, MAX_ENCRYPTED_CREDENTIAL_COUNT, MAX_RESPONSE_JWE_LEN, } from "./completion.js";
|
|
17
22
|
// OpenID4x
|
|
18
|
-
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, buildVCIFlowStart, withAttestation, } from "./openid4x.js";
|
|
23
|
+
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, buildVCIFlowStart, withAttestation, transactionDataHashesAlgs, SubFlowRejectedError, } from "./openid4x.js";
|
|
24
|
+
// Sign sub-flow responder, transaction_data, match (profile 3.1.5, 3.2.5, 3.2.6, 3.3)
|
|
25
|
+
export { CAPABILITY_TRANSACTION_DATA, TRANSACTION_DATA_VERSION_1, TRANSACTION_DATA_HASH_ALGS, SIGN_ACTIONS, MAX_PROOF_COUNT, SignFlow, boundNotifier, offersTransactionData, transactionDataUnsupportedData, transactionDataUnsupportedError, transactionDataHash, decodeTransactionData, checkTransactionDataEntry, parseSignSubFlowParams, parseMatchStartParams, completeSubFlow, failSubFlow, rejectSubFlow, validateSignResult, unsupportedTransactionData, } from "./signflow.js";
|
|
26
|
+
// select_credentials consent action (profile 3.2.3.1)
|
|
27
|
+
export { ActionParamsError, validateSelectCredentialsParams, buildSelectCredentials, newSelectionHandle, isSelectionHandle, isQueryId, } from "./consent.js";
|
|
19
28
|
// Evidence (ERDS)
|
|
20
29
|
export { EvidenceEvent, EventReasonCode } from "./evidence.js";
|
|
21
30
|
// Relay
|
|
22
31
|
export { Relay } from "./relay.js";
|
|
23
32
|
// Session store (server-side)
|
|
24
|
-
export { MemorySessionStore } from "./session-store.js";
|
|
33
|
+
export { MemorySessionStore, SessionStoreError, isSessionExpired, sessionOwnedBy, tokensEqual, } from "./session-store.js";
|
|
25
34
|
// Discovery
|
|
26
|
-
export { extractDomain, discoverEndpoint } from "./discovery.js";
|
|
35
|
+
export { extractDomain, discoverEndpoint, discoveryBase, wellKnownUrl, } from "./discovery.js";
|
|
27
36
|
// Invitation
|
|
28
37
|
export { InvitationPurpose, createInvitation, invitationSigningPayload, invitationToURI, invitationToHTTPSURI, parseInvitationURI, parseInvitationJSON, isInvitationExpired, generateNonce, MemoryInvitationStore, validateInvitationNonce, } from "./invitation.js";
|
package/dist/jsonrpc.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export declare function decodeBatch(data: string, opts?: DecodeOptions): Message
|
|
|
47
47
|
export declare class WMPError extends Error {
|
|
48
48
|
readonly code: number;
|
|
49
49
|
readonly data?: unknown;
|
|
50
|
+
/** The message as it goes on the wire (error.message), without the "wmp: rpc error" prefix of Error.message. */
|
|
51
|
+
readonly rpcMessage: string;
|
|
50
52
|
constructor(code: number, message: string, data?: unknown);
|
|
51
53
|
toRPCError(): RPCError;
|
|
52
54
|
}
|
package/dist/jsonrpc.js
CHANGED
|
@@ -108,14 +108,17 @@ export function decodeBatch(data, opts) {
|
|
|
108
108
|
export class WMPError extends Error {
|
|
109
109
|
code;
|
|
110
110
|
data;
|
|
111
|
+
/** The message as it goes on the wire (error.message), without the "wmp: rpc error" prefix of Error.message. */
|
|
112
|
+
rpcMessage;
|
|
111
113
|
constructor(code, message, data) {
|
|
112
114
|
super(`wmp: rpc error ${code}: ${message}`);
|
|
113
115
|
this.name = "WMPError";
|
|
114
116
|
this.code = code;
|
|
115
117
|
this.data = data;
|
|
118
|
+
this.rpcMessage = message;
|
|
116
119
|
}
|
|
117
120
|
toRPCError() {
|
|
118
|
-
return { code: this.code, message: this.
|
|
121
|
+
return { code: this.code, message: this.rpcMessage, data: this.data };
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
/** @deprecated Request IDs are now random; this function is a no-op for compatibility. */
|