@sirosfoundation/wmp-js 0.2.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/LICENSE +24 -0
- package/README.md +115 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/jsonrpc.d.ts +48 -0
- package/dist/jsonrpc.js +74 -0
- package/dist/mls.d.ts +215 -0
- package/dist/mls.js +176 -0
- package/dist/native.d.ts +71 -0
- package/dist/native.js +186 -0
- package/dist/node.d.ts +12 -0
- package/dist/node.js +12 -0
- package/dist/openid4x.d.ts +167 -0
- package/dist/openid4x.js +201 -0
- package/dist/peer.d.ts +95 -0
- package/dist/peer.js +380 -0
- package/dist/profile.d.ts +51 -0
- package/dist/profile.js +74 -0
- package/dist/relay.d.ts +47 -0
- package/dist/relay.js +113 -0
- package/dist/schema.d.ts +32 -0
- package/dist/schema.js +109 -0
- package/dist/transport.d.ts +100 -0
- package/dist/transport.js +199 -0
- package/dist/types.d.ts +295 -0
- package/dist/types.js +88 -0
- package/package.json +41 -0
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native messaging transports — WMP over stdio (NDJSON) and Unix sockets.
|
|
3
|
+
*
|
|
4
|
+
* Per wmp-transport.md §5, native messaging uses newline-delimited JSON
|
|
5
|
+
* over stdin/stdout (for browser extension native messaging and CLI agents)
|
|
6
|
+
* or Unix domain sockets (for local IPC).
|
|
7
|
+
*
|
|
8
|
+
* These transports are Node.js–only (they require `stream.Readable`/`Writable`
|
|
9
|
+
* or `net.Socket`).
|
|
10
|
+
*/
|
|
11
|
+
import type { Readable, Writable } from "node:stream";
|
|
12
|
+
import type { Socket } from "node:net";
|
|
13
|
+
import { type Message } from "./jsonrpc.js";
|
|
14
|
+
import type { Transport, TransportEventName, TransportEvents } from "./transport.js";
|
|
15
|
+
type Listener = (...args: unknown[]) => void;
|
|
16
|
+
declare class Emitter {
|
|
17
|
+
private listeners;
|
|
18
|
+
on(event: string, fn: Listener): void;
|
|
19
|
+
off(event: string, fn: Listener): void;
|
|
20
|
+
protected emit(event: string, ...args: unknown[]): void;
|
|
21
|
+
}
|
|
22
|
+
export interface StdioTransportOptions {
|
|
23
|
+
/** Readable stream for incoming messages. Default: process.stdin */
|
|
24
|
+
input?: Readable;
|
|
25
|
+
/** Writable stream for outgoing messages. Default: process.stdout */
|
|
26
|
+
output?: Writable;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* StdioTransport — newline-delimited JSON over stdin/stdout.
|
|
30
|
+
*
|
|
31
|
+
* Suitable for:
|
|
32
|
+
* - Browser extension native messaging hosts
|
|
33
|
+
* - CLI agent communication (MCP-style)
|
|
34
|
+
* - Subprocess WMP peers
|
|
35
|
+
*/
|
|
36
|
+
export declare class StdioTransport extends Emitter implements Transport {
|
|
37
|
+
private input;
|
|
38
|
+
private output;
|
|
39
|
+
private buffer;
|
|
40
|
+
private closed;
|
|
41
|
+
constructor(opts?: StdioTransportOptions);
|
|
42
|
+
private onData;
|
|
43
|
+
private onClose;
|
|
44
|
+
send(msg: Message): Promise<void>;
|
|
45
|
+
close(): void;
|
|
46
|
+
on<K extends TransportEventName>(event: K, listener: TransportEvents[K]): void;
|
|
47
|
+
off<K extends TransportEventName>(event: K, listener: TransportEvents[K]): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* UnixSocketTransport — NDJSON over a Unix domain socket.
|
|
51
|
+
*
|
|
52
|
+
* Suitable for local IPC between wallet CLI and agent processes.
|
|
53
|
+
*
|
|
54
|
+
* Usage:
|
|
55
|
+
* import { connect } from "node:net";
|
|
56
|
+
* const sock = connect("/tmp/wmp.sock");
|
|
57
|
+
* const transport = new UnixSocketTransport(sock);
|
|
58
|
+
*/
|
|
59
|
+
export declare class UnixSocketTransport extends Emitter implements Transport {
|
|
60
|
+
private socket;
|
|
61
|
+
private buffer;
|
|
62
|
+
private closed;
|
|
63
|
+
constructor(socket: Socket);
|
|
64
|
+
private onData;
|
|
65
|
+
private onClose;
|
|
66
|
+
send(msg: Message): Promise<void>;
|
|
67
|
+
close(): void;
|
|
68
|
+
on<K extends TransportEventName>(event: K, listener: TransportEvents[K]): void;
|
|
69
|
+
off<K extends TransportEventName>(event: K, listener: TransportEvents[K]): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
package/dist/native.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native messaging transports — WMP over stdio (NDJSON) and Unix sockets.
|
|
3
|
+
*
|
|
4
|
+
* Per wmp-transport.md §5, native messaging uses newline-delimited JSON
|
|
5
|
+
* over stdin/stdout (for browser extension native messaging and CLI agents)
|
|
6
|
+
* or Unix domain sockets (for local IPC).
|
|
7
|
+
*
|
|
8
|
+
* These transports are Node.js–only (they require `stream.Readable`/`Writable`
|
|
9
|
+
* or `net.Socket`).
|
|
10
|
+
*/
|
|
11
|
+
import { decodeMessage } from "./jsonrpc.js";
|
|
12
|
+
class Emitter {
|
|
13
|
+
listeners = new Map();
|
|
14
|
+
on(event, fn) {
|
|
15
|
+
let set = this.listeners.get(event);
|
|
16
|
+
if (!set) {
|
|
17
|
+
set = new Set();
|
|
18
|
+
this.listeners.set(event, set);
|
|
19
|
+
}
|
|
20
|
+
set.add(fn);
|
|
21
|
+
}
|
|
22
|
+
off(event, fn) {
|
|
23
|
+
this.listeners.get(event)?.delete(fn);
|
|
24
|
+
}
|
|
25
|
+
emit(event, ...args) {
|
|
26
|
+
this.listeners.get(event)?.forEach((fn) => fn(...args));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* StdioTransport — newline-delimited JSON over stdin/stdout.
|
|
31
|
+
*
|
|
32
|
+
* Suitable for:
|
|
33
|
+
* - Browser extension native messaging hosts
|
|
34
|
+
* - CLI agent communication (MCP-style)
|
|
35
|
+
* - Subprocess WMP peers
|
|
36
|
+
*/
|
|
37
|
+
export class StdioTransport extends Emitter {
|
|
38
|
+
input;
|
|
39
|
+
output;
|
|
40
|
+
buffer = "";
|
|
41
|
+
closed = false;
|
|
42
|
+
constructor(opts) {
|
|
43
|
+
super();
|
|
44
|
+
this.input = opts?.input ?? process.stdin;
|
|
45
|
+
this.output = opts?.output ?? process.stdout;
|
|
46
|
+
this.input.setEncoding("utf8");
|
|
47
|
+
this.input.on("data", (chunk) => this.onData(chunk));
|
|
48
|
+
this.input.on("end", () => this.onClose());
|
|
49
|
+
this.input.on("error", (err) => this.emit("error", err));
|
|
50
|
+
// Emit open on next tick (stream is already connected)
|
|
51
|
+
queueMicrotask(() => this.emit("open"));
|
|
52
|
+
}
|
|
53
|
+
onData(chunk) {
|
|
54
|
+
this.buffer += chunk;
|
|
55
|
+
// Split on newlines — each line is a complete JSON-RPC message
|
|
56
|
+
const lines = this.buffer.split("\n");
|
|
57
|
+
// Last element is incomplete (may be empty string if chunk ended with \n)
|
|
58
|
+
this.buffer = lines.pop();
|
|
59
|
+
for (const line of lines) {
|
|
60
|
+
const trimmed = line.trim();
|
|
61
|
+
if (!trimmed)
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
const msg = decodeMessage(trimmed);
|
|
65
|
+
this.emit("message", msg);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
onClose() {
|
|
73
|
+
if (this.closed)
|
|
74
|
+
return;
|
|
75
|
+
this.closed = true;
|
|
76
|
+
this.emit("close");
|
|
77
|
+
}
|
|
78
|
+
async send(msg) {
|
|
79
|
+
if (this.closed) {
|
|
80
|
+
throw new Error("Transport is closed");
|
|
81
|
+
}
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
const data = JSON.stringify(msg) + "\n";
|
|
84
|
+
this.output.write(data, "utf8", (err) => {
|
|
85
|
+
if (err)
|
|
86
|
+
reject(err);
|
|
87
|
+
else
|
|
88
|
+
resolve();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
close() {
|
|
93
|
+
if (this.closed)
|
|
94
|
+
return;
|
|
95
|
+
this.closed = true;
|
|
96
|
+
// Don't destroy process.stdin/stdout — just mark closed
|
|
97
|
+
this.emit("close");
|
|
98
|
+
}
|
|
99
|
+
on(event, listener) {
|
|
100
|
+
super.on(event, listener);
|
|
101
|
+
}
|
|
102
|
+
off(event, listener) {
|
|
103
|
+
super.off(event, listener);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Unix socket transport
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
/**
|
|
110
|
+
* UnixSocketTransport — NDJSON over a Unix domain socket.
|
|
111
|
+
*
|
|
112
|
+
* Suitable for local IPC between wallet CLI and agent processes.
|
|
113
|
+
*
|
|
114
|
+
* Usage:
|
|
115
|
+
* import { connect } from "node:net";
|
|
116
|
+
* const sock = connect("/tmp/wmp.sock");
|
|
117
|
+
* const transport = new UnixSocketTransport(sock);
|
|
118
|
+
*/
|
|
119
|
+
export class UnixSocketTransport extends Emitter {
|
|
120
|
+
socket;
|
|
121
|
+
buffer = "";
|
|
122
|
+
closed = false;
|
|
123
|
+
constructor(socket) {
|
|
124
|
+
super();
|
|
125
|
+
this.socket = socket;
|
|
126
|
+
this.socket.setEncoding("utf8");
|
|
127
|
+
this.socket.on("connect", () => this.emit("open"));
|
|
128
|
+
this.socket.on("data", (chunk) => this.onData(chunk));
|
|
129
|
+
this.socket.on("end", () => this.onClose());
|
|
130
|
+
this.socket.on("close", () => this.onClose());
|
|
131
|
+
this.socket.on("error", (err) => this.emit("error", err));
|
|
132
|
+
// If already connected, emit open
|
|
133
|
+
if (!this.socket.connecting) {
|
|
134
|
+
queueMicrotask(() => this.emit("open"));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
onData(chunk) {
|
|
138
|
+
this.buffer += chunk;
|
|
139
|
+
const lines = this.buffer.split("\n");
|
|
140
|
+
this.buffer = lines.pop();
|
|
141
|
+
for (const line of lines) {
|
|
142
|
+
const trimmed = line.trim();
|
|
143
|
+
if (!trimmed)
|
|
144
|
+
continue;
|
|
145
|
+
try {
|
|
146
|
+
const msg = decodeMessage(trimmed);
|
|
147
|
+
this.emit("message", msg);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
this.emit("error", err instanceof Error ? err : new Error(String(err)));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
onClose() {
|
|
155
|
+
if (this.closed)
|
|
156
|
+
return;
|
|
157
|
+
this.closed = true;
|
|
158
|
+
this.emit("close");
|
|
159
|
+
}
|
|
160
|
+
async send(msg) {
|
|
161
|
+
if (this.closed) {
|
|
162
|
+
throw new Error("Transport is closed");
|
|
163
|
+
}
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
const data = JSON.stringify(msg) + "\n";
|
|
166
|
+
this.socket.write(data, "utf8", (err) => {
|
|
167
|
+
if (err)
|
|
168
|
+
reject(err);
|
|
169
|
+
else
|
|
170
|
+
resolve();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
close() {
|
|
175
|
+
if (this.closed)
|
|
176
|
+
return;
|
|
177
|
+
this.closed = true;
|
|
178
|
+
this.socket.end();
|
|
179
|
+
}
|
|
180
|
+
on(event, listener) {
|
|
181
|
+
super.on(event, listener);
|
|
182
|
+
}
|
|
183
|
+
off(event, listener) {
|
|
184
|
+
super.off(event, listener);
|
|
185
|
+
}
|
|
186
|
+
}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js entry point — re-exports everything from the main entry
|
|
3
|
+
* plus Node.js-only modules (native transports, schema validation).
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* import { createValidator, StdioTransport } from '@sirosfoundation/wmp-js/node';
|
|
7
|
+
*/
|
|
8
|
+
export * from "./index.js";
|
|
9
|
+
export { StdioTransport, UnixSocketTransport } from "./native.js";
|
|
10
|
+
export type { StdioTransportOptions } from "./native.js";
|
|
11
|
+
export { createValidator } from "./schema.js";
|
|
12
|
+
export type { Validator, ValidationError } from "./schema.js";
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js entry point — re-exports everything from the main entry
|
|
3
|
+
* plus Node.js-only modules (native transports, schema validation).
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* import { createValidator, StdioTransport } from '@sirosfoundation/wmp-js/node';
|
|
7
|
+
*/
|
|
8
|
+
export * from "./index.js";
|
|
9
|
+
// Native transports (Node.js only — stdio NDJSON, Unix sockets)
|
|
10
|
+
export { StdioTransport, UnixSocketTransport } from "./native.js";
|
|
11
|
+
// Schema validation (Node.js only — requires fs)
|
|
12
|
+
export { createValidator } from "./schema.js";
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WMP OpenID4x profile — mirrors go-wmp/pkg/wmp/openid4x/openid4x.go.
|
|
3
|
+
*
|
|
4
|
+
* Provides OID4VCI (credential issuance) and OID4VP (credential presentation)
|
|
5
|
+
* flow handling via the WMP profile system.
|
|
6
|
+
*/
|
|
7
|
+
import type { FlowStartParams, FlowStartResult, FlowActionParams, FlowActionResult, FlowProgressParams, FlowCompleteParams, FlowErrorParams, ResolveParams, ResolveResult } from "./types.js";
|
|
8
|
+
import type { Profile, PeerContext, FlowHandler, ResolveHandler } from "./profile.js";
|
|
9
|
+
export declare const CredentialFormat: {
|
|
10
|
+
readonly VC_SDJWT: "vc+sd-jwt";
|
|
11
|
+
readonly DC_SDJWT: "dc+sd-jwt";
|
|
12
|
+
readonly MSO_MDOC: "mso_mdoc";
|
|
13
|
+
readonly JWT_VC_JSON: "jwt_vc_json";
|
|
14
|
+
};
|
|
15
|
+
export type CredentialFormatType = (typeof CredentialFormat)[keyof typeof CredentialFormat];
|
|
16
|
+
export declare const allFormats: CredentialFormatType[];
|
|
17
|
+
export declare function isValidFormat(format: string): format is CredentialFormatType;
|
|
18
|
+
export declare const GrantType: {
|
|
19
|
+
readonly AuthorizationCode: "authorization_code";
|
|
20
|
+
readonly PreAuthorizedCode: "pre-authorized_code";
|
|
21
|
+
};
|
|
22
|
+
export declare const ResponseMode: {
|
|
23
|
+
readonly DirectPost: "direct_post";
|
|
24
|
+
readonly DirectPostJWT: "direct_post.jwt";
|
|
25
|
+
readonly DCAPI: "dc_api";
|
|
26
|
+
readonly DCAPIJWT: "dc_api.jwt";
|
|
27
|
+
};
|
|
28
|
+
export declare const ProofType: {
|
|
29
|
+
readonly JWT: "jwt";
|
|
30
|
+
readonly Attestation: "attestation";
|
|
31
|
+
readonly CWT: "cwt";
|
|
32
|
+
};
|
|
33
|
+
export declare const OID4FlowType: {
|
|
34
|
+
readonly OID4VCI: "oid4vci";
|
|
35
|
+
readonly OID4VP: "oid4vp";
|
|
36
|
+
};
|
|
37
|
+
export declare const VCIStep: {
|
|
38
|
+
readonly ParsingOffer: "parsing_offer";
|
|
39
|
+
readonly ResolvingMetadata: "resolving_metadata";
|
|
40
|
+
readonly MetadataFetched: "metadata_fetched";
|
|
41
|
+
readonly EvaluatingTrust: "evaluating_trust";
|
|
42
|
+
readonly TrustEvaluated: "trust_evaluated";
|
|
43
|
+
readonly AwaitingOfferAcceptance: "awaiting_offer_acceptance";
|
|
44
|
+
readonly AwaitingTxCode: "awaiting_tx_code";
|
|
45
|
+
readonly AuthorizationPending: "authorization_pending";
|
|
46
|
+
readonly GeneratingProof: "generating_proof";
|
|
47
|
+
readonly RequestingCredential: "requesting_credential";
|
|
48
|
+
readonly CredentialReceived: "credential_received";
|
|
49
|
+
};
|
|
50
|
+
export declare const VPStep: {
|
|
51
|
+
readonly ParsingRequest: "parsing_request";
|
|
52
|
+
readonly RequestParsed: "request_parsed";
|
|
53
|
+
readonly EvaluatingTrust: "evaluating_trust";
|
|
54
|
+
readonly TrustEvaluated: "trust_evaluated";
|
|
55
|
+
readonly MatchingCredentials: "matching_credentials";
|
|
56
|
+
readonly AwaitingConsent: "awaiting_consent";
|
|
57
|
+
readonly GeneratingPresentation: "generating_presentation";
|
|
58
|
+
};
|
|
59
|
+
export declare const OID4Action: {
|
|
60
|
+
readonly AcceptOffer: "accept_offer";
|
|
61
|
+
readonly ProvideTxCode: "provide_tx_code";
|
|
62
|
+
readonly Authorize: "authorize";
|
|
63
|
+
readonly SelectCredentials: "select_credentials";
|
|
64
|
+
readonly Cancel: "cancel";
|
|
65
|
+
};
|
|
66
|
+
export interface OID4VCICapability {
|
|
67
|
+
supported_grants: string[];
|
|
68
|
+
supported_formats: string[];
|
|
69
|
+
supported_proof_types?: string[];
|
|
70
|
+
batch_issuance?: boolean;
|
|
71
|
+
}
|
|
72
|
+
export interface OID4VPCapability {
|
|
73
|
+
supported_response_modes: string[];
|
|
74
|
+
supported_formats: string[];
|
|
75
|
+
supported_algorithms?: string[];
|
|
76
|
+
}
|
|
77
|
+
export interface CredentialDisplay {
|
|
78
|
+
name: string;
|
|
79
|
+
locale?: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
logo_uri?: string;
|
|
82
|
+
logo_alt_text?: string;
|
|
83
|
+
background_color?: string;
|
|
84
|
+
text_color?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface CredentialConfigurationSupported {
|
|
87
|
+
format: string;
|
|
88
|
+
scope?: string;
|
|
89
|
+
vct?: string;
|
|
90
|
+
doctype?: string;
|
|
91
|
+
cryptographic_binding_methods_supported?: string[];
|
|
92
|
+
credential_signing_alg_values_supported?: string[];
|
|
93
|
+
proof_types_supported?: Record<string, unknown>;
|
|
94
|
+
display?: CredentialDisplay[];
|
|
95
|
+
}
|
|
96
|
+
export interface CredentialResult {
|
|
97
|
+
format: string;
|
|
98
|
+
credential: string;
|
|
99
|
+
vct?: string;
|
|
100
|
+
c_nonce?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface VPTokenResult {
|
|
103
|
+
vp_token?: string | string[];
|
|
104
|
+
presentation_submission?: unknown;
|
|
105
|
+
response_code?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface SignSubFlowParams {
|
|
108
|
+
action: string;
|
|
109
|
+
nonce: string;
|
|
110
|
+
audience: string;
|
|
111
|
+
proof_type?: string;
|
|
112
|
+
parent_flow_id: string;
|
|
113
|
+
}
|
|
114
|
+
export interface SelectionAction {
|
|
115
|
+
selected_indices: number[];
|
|
116
|
+
consent: boolean;
|
|
117
|
+
}
|
|
118
|
+
export interface ConsentAction {
|
|
119
|
+
selections: CredentialSelection[];
|
|
120
|
+
consent: boolean;
|
|
121
|
+
}
|
|
122
|
+
export interface CredentialSelection {
|
|
123
|
+
credential_id: string;
|
|
124
|
+
credential_query_id?: string;
|
|
125
|
+
disclosed_claims: string[];
|
|
126
|
+
}
|
|
127
|
+
export type FlowStartHandler = (params: FlowStartParams) => Promise<FlowStartResult>;
|
|
128
|
+
export type ActionHandler = (params: FlowActionParams) => Promise<FlowActionResult>;
|
|
129
|
+
export interface OpenID4xConfig {
|
|
130
|
+
/** OID4VCI capability. Omit to disable issuance. */
|
|
131
|
+
oid4vci?: OID4VCICapability;
|
|
132
|
+
/** OID4VP capability. Omit to disable presentation. */
|
|
133
|
+
oid4vp?: OID4VPCapability;
|
|
134
|
+
/** Called when an OID4VCI flow starts. */
|
|
135
|
+
onVCIStart?: FlowStartHandler;
|
|
136
|
+
/** Called when an action arrives for an OID4VCI flow. */
|
|
137
|
+
onVCIAction?: ActionHandler;
|
|
138
|
+
/** Called when an OID4VP flow starts. */
|
|
139
|
+
onVPStart?: FlowStartHandler;
|
|
140
|
+
/** Called when an action arrives for an OID4VP flow. */
|
|
141
|
+
onVPAction?: ActionHandler;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* OpenID4xProfile implements Profile, FlowHandler, and ResolveHandler
|
|
145
|
+
* for OID4VCI and OID4VP credential exchange flows.
|
|
146
|
+
*
|
|
147
|
+
* Usage:
|
|
148
|
+
* const profile = new OpenID4xProfile({ oid4vci: {...}, oid4vp: {...} });
|
|
149
|
+
* peer.use(profile);
|
|
150
|
+
*/
|
|
151
|
+
export declare class OpenID4xProfile implements Profile, FlowHandler, ResolveHandler {
|
|
152
|
+
readonly name = "openid4x";
|
|
153
|
+
private config;
|
|
154
|
+
private peer?;
|
|
155
|
+
private flowTypeMap;
|
|
156
|
+
constructor(config: OpenID4xConfig);
|
|
157
|
+
capabilities(): string[];
|
|
158
|
+
init(ctx: PeerContext): void;
|
|
159
|
+
flowTypes(): string[];
|
|
160
|
+
startFlow(params: FlowStartParams): Promise<FlowStartResult>;
|
|
161
|
+
handleAction(params: FlowActionParams): Promise<FlowActionResult>;
|
|
162
|
+
handleProgress(_params: FlowProgressParams): void;
|
|
163
|
+
handleComplete(params: FlowCompleteParams): void;
|
|
164
|
+
handleError(params: FlowErrorParams): void;
|
|
165
|
+
resolveTypes(): string[];
|
|
166
|
+
handleResolve(_params: ResolveParams): Promise<ResolveResult>;
|
|
167
|
+
}
|
package/dist/openid4x.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WMP OpenID4x profile — mirrors go-wmp/pkg/wmp/openid4x/openid4x.go.
|
|
3
|
+
*
|
|
4
|
+
* Provides OID4VCI (credential issuance) and OID4VP (credential presentation)
|
|
5
|
+
* flow handling via the WMP profile system.
|
|
6
|
+
*/
|
|
7
|
+
import { WMPError } from "./jsonrpc.js";
|
|
8
|
+
import { ErrorCode } from "./types.js";
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Credential format constants — aligned with wallet-common VerifiableCredentialFormat
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export const CredentialFormat = {
|
|
13
|
+
VC_SDJWT: "vc+sd-jwt",
|
|
14
|
+
DC_SDJWT: "dc+sd-jwt",
|
|
15
|
+
MSO_MDOC: "mso_mdoc",
|
|
16
|
+
JWT_VC_JSON: "jwt_vc_json",
|
|
17
|
+
};
|
|
18
|
+
export const allFormats = [
|
|
19
|
+
CredentialFormat.VC_SDJWT,
|
|
20
|
+
CredentialFormat.DC_SDJWT,
|
|
21
|
+
CredentialFormat.MSO_MDOC,
|
|
22
|
+
CredentialFormat.JWT_VC_JSON,
|
|
23
|
+
];
|
|
24
|
+
export function isValidFormat(format) {
|
|
25
|
+
return allFormats.includes(format);
|
|
26
|
+
}
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Grant type constants for OID4VCI
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
export const GrantType = {
|
|
31
|
+
AuthorizationCode: "authorization_code",
|
|
32
|
+
PreAuthorizedCode: "pre-authorized_code",
|
|
33
|
+
};
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Response mode constants for OID4VP
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
export const ResponseMode = {
|
|
38
|
+
DirectPost: "direct_post",
|
|
39
|
+
DirectPostJWT: "direct_post.jwt",
|
|
40
|
+
DCAPI: "dc_api",
|
|
41
|
+
DCAPIJWT: "dc_api.jwt",
|
|
42
|
+
};
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Proof type constants
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
export const ProofType = {
|
|
47
|
+
JWT: "jwt",
|
|
48
|
+
Attestation: "attestation",
|
|
49
|
+
CWT: "cwt",
|
|
50
|
+
};
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Flow type constants
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
export const OID4FlowType = {
|
|
55
|
+
OID4VCI: "oid4vci",
|
|
56
|
+
OID4VP: "oid4vp",
|
|
57
|
+
};
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Step constants for OID4VCI flows
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
export const VCIStep = {
|
|
62
|
+
ParsingOffer: "parsing_offer",
|
|
63
|
+
ResolvingMetadata: "resolving_metadata",
|
|
64
|
+
MetadataFetched: "metadata_fetched",
|
|
65
|
+
EvaluatingTrust: "evaluating_trust",
|
|
66
|
+
TrustEvaluated: "trust_evaluated",
|
|
67
|
+
AwaitingOfferAcceptance: "awaiting_offer_acceptance",
|
|
68
|
+
AwaitingTxCode: "awaiting_tx_code",
|
|
69
|
+
AuthorizationPending: "authorization_pending",
|
|
70
|
+
GeneratingProof: "generating_proof",
|
|
71
|
+
RequestingCredential: "requesting_credential",
|
|
72
|
+
CredentialReceived: "credential_received",
|
|
73
|
+
};
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Step constants for OID4VP flows
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
export const VPStep = {
|
|
78
|
+
ParsingRequest: "parsing_request",
|
|
79
|
+
RequestParsed: "request_parsed",
|
|
80
|
+
EvaluatingTrust: "evaluating_trust",
|
|
81
|
+
TrustEvaluated: "trust_evaluated",
|
|
82
|
+
MatchingCredentials: "matching_credentials",
|
|
83
|
+
AwaitingConsent: "awaiting_consent",
|
|
84
|
+
GeneratingPresentation: "generating_presentation",
|
|
85
|
+
};
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Action constants
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
export const OID4Action = {
|
|
90
|
+
AcceptOffer: "accept_offer",
|
|
91
|
+
ProvideTxCode: "provide_tx_code",
|
|
92
|
+
Authorize: "authorize",
|
|
93
|
+
SelectCredentials: "select_credentials",
|
|
94
|
+
Cancel: "cancel",
|
|
95
|
+
};
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// OpenID4x Profile
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
/**
|
|
100
|
+
* OpenID4xProfile implements Profile, FlowHandler, and ResolveHandler
|
|
101
|
+
* for OID4VCI and OID4VP credential exchange flows.
|
|
102
|
+
*
|
|
103
|
+
* Usage:
|
|
104
|
+
* const profile = new OpenID4xProfile({ oid4vci: {...}, oid4vp: {...} });
|
|
105
|
+
* peer.use(profile);
|
|
106
|
+
*/
|
|
107
|
+
export class OpenID4xProfile {
|
|
108
|
+
name = "openid4x";
|
|
109
|
+
config;
|
|
110
|
+
peer;
|
|
111
|
+
flowTypeMap = new Map();
|
|
112
|
+
constructor(config) {
|
|
113
|
+
this.config = config;
|
|
114
|
+
}
|
|
115
|
+
// --- Profile ---
|
|
116
|
+
capabilities() {
|
|
117
|
+
const caps = [];
|
|
118
|
+
if (this.config.oid4vci)
|
|
119
|
+
caps.push("oid4vci");
|
|
120
|
+
if (this.config.oid4vp)
|
|
121
|
+
caps.push("oid4vp");
|
|
122
|
+
return caps;
|
|
123
|
+
}
|
|
124
|
+
init(ctx) {
|
|
125
|
+
this.peer = ctx;
|
|
126
|
+
}
|
|
127
|
+
// --- FlowHandler ---
|
|
128
|
+
flowTypes() {
|
|
129
|
+
const types = [];
|
|
130
|
+
if (this.config.oid4vci)
|
|
131
|
+
types.push(OID4FlowType.OID4VCI);
|
|
132
|
+
if (this.config.oid4vp)
|
|
133
|
+
types.push(OID4FlowType.OID4VP);
|
|
134
|
+
return types;
|
|
135
|
+
}
|
|
136
|
+
async startFlow(params) {
|
|
137
|
+
switch (params.flow_type) {
|
|
138
|
+
case OID4FlowType.OID4VCI: {
|
|
139
|
+
this.flowTypeMap.set(params.flow_id, OID4FlowType.OID4VCI);
|
|
140
|
+
if (this.config.onVCIStart) {
|
|
141
|
+
return this.config.onVCIStart(params);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
wmp: params.wmp,
|
|
145
|
+
flow_id: params.flow_id,
|
|
146
|
+
flow_type: params.flow_type,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
case OID4FlowType.OID4VP: {
|
|
150
|
+
this.flowTypeMap.set(params.flow_id, OID4FlowType.OID4VP);
|
|
151
|
+
if (this.config.onVPStart) {
|
|
152
|
+
return this.config.onVPStart(params);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
wmp: params.wmp,
|
|
156
|
+
flow_id: params.flow_id,
|
|
157
|
+
flow_type: params.flow_type,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
default:
|
|
161
|
+
throw new WMPError(ErrorCode.FlowError, `Unsupported flow type: ${params.flow_type}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async handleAction(params) {
|
|
165
|
+
const flowType = this.flowTypeMap.get(params.flow_id);
|
|
166
|
+
switch (flowType) {
|
|
167
|
+
case OID4FlowType.OID4VCI:
|
|
168
|
+
if (this.config.onVCIAction) {
|
|
169
|
+
return this.config.onVCIAction(params);
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
case OID4FlowType.OID4VP:
|
|
173
|
+
if (this.config.onVPAction) {
|
|
174
|
+
return this.config.onVPAction(params);
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
wmp: params.wmp,
|
|
180
|
+
flow_id: params.flow_id,
|
|
181
|
+
action: params.action,
|
|
182
|
+
status: "accepted",
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
handleProgress(_params) {
|
|
186
|
+
// Override via middleware or subclass.
|
|
187
|
+
}
|
|
188
|
+
handleComplete(params) {
|
|
189
|
+
this.flowTypeMap.delete(params.flow_id);
|
|
190
|
+
}
|
|
191
|
+
handleError(params) {
|
|
192
|
+
this.flowTypeMap.delete(params.flow_id);
|
|
193
|
+
}
|
|
194
|
+
// --- ResolveHandler ---
|
|
195
|
+
resolveTypes() {
|
|
196
|
+
return ["vctm", "issuer_metadata"];
|
|
197
|
+
}
|
|
198
|
+
async handleResolve(_params) {
|
|
199
|
+
throw new WMPError(ErrorCode.CapabilityNotSupported, "OpenID4x resolve not implemented");
|
|
200
|
+
}
|
|
201
|
+
}
|