@sirosfoundation/wmp-js 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/discovery.d.ts +26 -0
- package/dist/discovery.js +58 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +6 -2
- package/dist/invitation.d.ts +111 -0
- package/dist/invitation.js +188 -0
- package/dist/openid4x.d.ts +127 -1
- package/dist/openid4x.js +33 -1
- package/dist/peer.d.ts +9 -1
- package/dist/peer.js +37 -1
- package/dist/types.d.ts +25 -1
- package/dist/types.js +11 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @sirosfoundation/wmp-js
|
|
2
2
|
|
|
3
3
|
[](https://github.com/sirosfoundation/wmp-js/actions/workflows/ci.yml)
|
|
4
|
+
[](https://scorecard.dev/viewer/?uri=github.com/sirosfoundation/wmp-js)
|
|
4
5
|
[](LICENSE)
|
|
5
6
|
|
|
6
7
|
TypeScript implementation of the Wallet Messaging Protocol (WMP) — a JSON-RPC 2.0 protocol for bidirectional communication between wallet frontends and backend services.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WMP endpoint discovery — mirrors go-wmp/pkg/wmp/discovery.go.
|
|
3
|
+
*/
|
|
4
|
+
/** Well-known WMP configuration as served at /.well-known/wmp-configuration. */
|
|
5
|
+
export interface WellKnownConfig {
|
|
6
|
+
supported_versions: string[];
|
|
7
|
+
endpoints: Record<string, string>;
|
|
8
|
+
security_modes: string[];
|
|
9
|
+
capabilities?: Record<string, unknown>;
|
|
10
|
+
identity_providers?: string[];
|
|
11
|
+
trust_frameworks?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Extract the domain from a WMP identifier.
|
|
15
|
+
*
|
|
16
|
+
* Supports x509:san:dns, x509:san:uri, https://, and did:web schemes.
|
|
17
|
+
* Returns an empty string if the scheme is not recognised (e.g. did:key).
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractDomain(identifier: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Fetch the well-known WMP configuration for any WMP identifier.
|
|
22
|
+
*
|
|
23
|
+
* Extracts the domain and fetches `https://<domain>/.well-known/wmp-configuration`.
|
|
24
|
+
* Throws if no domain can be extracted or the fetch fails.
|
|
25
|
+
*/
|
|
26
|
+
export declare function discoverEndpoint(identifier: string, fetchFn?: typeof globalThis.fetch): Promise<WellKnownConfig>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WMP endpoint discovery — mirrors go-wmp/pkg/wmp/discovery.go.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Extract the domain from a WMP identifier.
|
|
6
|
+
*
|
|
7
|
+
* Supports x509:san:dns, x509:san:uri, https://, and did:web schemes.
|
|
8
|
+
* Returns an empty string if the scheme is not recognised (e.g. did:key).
|
|
9
|
+
*/
|
|
10
|
+
export function extractDomain(identifier) {
|
|
11
|
+
if (identifier.startsWith("x509:san:dns:")) {
|
|
12
|
+
return identifier.slice("x509:san:dns:".length);
|
|
13
|
+
}
|
|
14
|
+
if (identifier.startsWith("x509:san:uri:")) {
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL(identifier.slice("x509:san:uri:".length));
|
|
17
|
+
return url.hostname;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (identifier.startsWith("https://")) {
|
|
24
|
+
try {
|
|
25
|
+
const url = new URL(identifier);
|
|
26
|
+
return url.hostname;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (identifier.startsWith("did:web:")) {
|
|
33
|
+
const rest = identifier.slice("did:web:".length);
|
|
34
|
+
const domain = rest.split(":")[0];
|
|
35
|
+
return decodeURIComponent(domain);
|
|
36
|
+
}
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetch the well-known WMP configuration for any WMP identifier.
|
|
41
|
+
*
|
|
42
|
+
* Extracts the domain and fetches `https://<domain>/.well-known/wmp-configuration`.
|
|
43
|
+
* Throws if no domain can be extracted or the fetch fails.
|
|
44
|
+
*/
|
|
45
|
+
export async function discoverEndpoint(identifier, fetchFn = globalThis.fetch.bind(globalThis)) {
|
|
46
|
+
const domain = extractDomain(identifier);
|
|
47
|
+
if (!domain) {
|
|
48
|
+
throw new Error(`Cannot extract domain from identifier "${identifier}": use session parameters or a profile resolver`);
|
|
49
|
+
}
|
|
50
|
+
const url = `https://${domain}/.well-known/wmp-configuration`;
|
|
51
|
+
const resp = await fetchFn(url, {
|
|
52
|
+
headers: { Accept: "application/json" },
|
|
53
|
+
});
|
|
54
|
+
if (!resp.ok) {
|
|
55
|
+
throw new Error(`WMP discovery failed for ${url}: HTTP ${resp.status}`);
|
|
56
|
+
}
|
|
57
|
+
return (await resp.json());
|
|
58
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @siros/wmp — Wallet Messaging Protocol client library
|
|
3
3
|
*/
|
|
4
|
-
export { VERSION, Method, ErrorCode, FlowType, CloseReason, AckStatus, CancelReason, ResolveType, ServiceClass, } from "./types.js";
|
|
5
|
-
export type { Metadata, IdentityAssertion, TrustHint, RelayEntry, SecurityMode, Capabilities, AuthObject, SessionCreateParams, SessionCreateResult, SessionResumeParams, SessionCloseParams, SessionAuthenticateParams, SessionAuthenticateResult, MessageDeliverParams, MessageAckParams, MessagePollParams, MessagePollResult, MessageStatusParams, CapabilityUpdateParams, CapabilityUpdateResult, CapabilityListParams, CapabilityListResult, FlowStartParams, FlowStartResult, FlowProgressParams, FlowActionParams, FlowActionResult, FlowCompleteParams, FlowErrorParams, FlowCancelParams, FlowCancelResult, ResolveParams, ResolveResult, RelayRegisterParams, RelayRegisterResult, RelayCap, MethodName, } from "./types.js";
|
|
4
|
+
export { VERSION, Method, ErrorCode, FlowType, CloseReason, AckStatus, CancelReason, ResolveType, ServiceClass, AuthType, } from "./types.js";
|
|
5
|
+
export type { Metadata, IdentityAssertion, TrustHint, RelayEntry, SecurityMode, Capabilities, AuthObject, SessionCreateParams, SessionCreateResult, SessionResumeParams, SessionResumeResult, SessionCloseParams, SessionAuthenticateParams, SessionAuthenticateResult, MessageDeliverParams, MessageAckParams, MessagePollParams, MessagePollResult, MessageStatusParams, CapabilityUpdateParams, CapabilityUpdateResult, CapabilityListParams, CapabilityListResult, FlowStartParams, FlowStartResult, FlowProgressParams, FlowActionParams, FlowActionResult, FlowCompleteParams, FlowErrorParams, FlowCancelParams, FlowCancelResult, ResolveParams, ResolveResult, RelayRegisterParams, RelayRegisterResult, RelayCap, MethodName, } from "./types.js";
|
|
6
6
|
export { WMPError, createRequest, createNotification, createResponse, createErrorResponse, decodeMessage, decodeBatch, isRequest, isResponse, isNotification, } from "./jsonrpc.js";
|
|
7
7
|
export type { RPCError, Request, Response, Message } from "./jsonrpc.js";
|
|
8
8
|
export { WebSocketTransport, HttpSseTransport } from "./transport.js";
|
|
@@ -13,7 +13,11 @@ export { Peer } from "./peer.js";
|
|
|
13
13
|
export type { Handler, PeerOptions } from "./peer.js";
|
|
14
14
|
export { MLSMethod, CipherSuiteX25519AES128GCM, CipherSuiteP256AES128GCM, CredentialType, MLSProfile, mlsMethods, NoopMLSHandler, NoopMLSProvider, } from "./mls.js";
|
|
15
15
|
export type { MLSMethodName, GroupCreateParams, GroupCreateResult, GroupJoinParams, GroupJoinResult, GroupAddParams, GroupAddResult, GroupRemoveParams, GroupRemoveResult, GroupUpdateParams, MessageFetchParams, MessageFetchResult, KeyPackage, KeyPackagesResponse, EncryptedEnvelope, MLSHandler, MLSProvider, } from "./mls.js";
|
|
16
|
-
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, } from "./openid4x.js";
|
|
17
|
-
export type { CredentialFormatType, OID4VCICapability, OID4VPCapability, CredentialDisplay, CredentialConfigurationSupported, CredentialResult, VPTokenResult, SignSubFlowParams, SelectionAction, ConsentAction, CredentialSelection, FlowStartHandler, ActionHandler, OpenID4xConfig, } from "./openid4x.js";
|
|
16
|
+
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, buildVCIFlowStart, withAttestation, } from "./openid4x.js";
|
|
17
|
+
export type { CredentialFormatType, OID4VCICapability, OID4VPCapability, CredentialDisplay, CredentialConfigurationSupported, CredentialResult, CredentialEvent, CredentialNotificationParams, VPTokenResult, ClientAttestation, ClientAttestationProvider, OID4VCIFlowParams, OID4VPFlowParams, SignSubFlowParams, SelectionAction, ConsentAction, CredentialSelection, FlowStartHandler, ActionHandler, OpenID4xConfig, } from "./openid4x.js";
|
|
18
18
|
export { Relay } from "./relay.js";
|
|
19
19
|
export type { RelayConfig, QueuedMessage } from "./relay.js";
|
|
20
|
+
export { extractDomain, discoverEndpoint } from "./discovery.js";
|
|
21
|
+
export type { WellKnownConfig } from "./discovery.js";
|
|
22
|
+
export { InvitationPurpose, createInvitation, invitationSigningPayload, invitationToURI, invitationToHTTPSURI, parseInvitationURI, parseInvitationJSON, isInvitationExpired, generateNonce, MemoryInvitationStore, validateInvitationNonce, } from "./invitation.js";
|
|
23
|
+
export type { Invitation, CreateInvitationOptions, InvitationStore, } from "./invitation.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @siros/wmp — Wallet Messaging Protocol client library
|
|
3
3
|
*/
|
|
4
4
|
// Types
|
|
5
|
-
export { VERSION, Method, ErrorCode, FlowType, CloseReason, AckStatus, CancelReason, ResolveType, ServiceClass, } from "./types.js";
|
|
5
|
+
export { VERSION, Method, ErrorCode, FlowType, CloseReason, AckStatus, CancelReason, ResolveType, ServiceClass, AuthType, } from "./types.js";
|
|
6
6
|
// JSON-RPC
|
|
7
7
|
export { WMPError, createRequest, createNotification, createResponse, createErrorResponse, decodeMessage, decodeBatch, isRequest, isResponse, isNotification, } from "./jsonrpc.js";
|
|
8
8
|
// Transport
|
|
@@ -14,6 +14,10 @@ export { Peer } from "./peer.js";
|
|
|
14
14
|
// MLS
|
|
15
15
|
export { MLSMethod, CipherSuiteX25519AES128GCM, CipherSuiteP256AES128GCM, CredentialType, MLSProfile, mlsMethods, NoopMLSHandler, NoopMLSProvider, } from "./mls.js";
|
|
16
16
|
// OpenID4x
|
|
17
|
-
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, } from "./openid4x.js";
|
|
17
|
+
export { CredentialFormat, allFormats, isValidFormat, GrantType, ResponseMode, ProofType, OID4FlowType, VCIStep, VPStep, OID4Action, OpenID4xProfile, buildVCIFlowStart, withAttestation, } from "./openid4x.js";
|
|
18
18
|
// Relay
|
|
19
19
|
export { Relay } from "./relay.js";
|
|
20
|
+
// Discovery
|
|
21
|
+
export { extractDomain, discoverEndpoint } from "./discovery.js";
|
|
22
|
+
// Invitation
|
|
23
|
+
export { InvitationPurpose, createInvitation, invitationSigningPayload, invitationToURI, invitationToHTTPSURI, parseInvitationURI, parseInvitationJSON, isInvitationExpired, generateNonce, MemoryInvitationStore, validateInvitationNonce, } from "./invitation.js";
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WMP Invitation — session bootstrap via out-of-band invitation exchange.
|
|
3
|
+
* See wmp-invitation.md for the specification.
|
|
4
|
+
*/
|
|
5
|
+
import type { Capabilities } from "./types.js";
|
|
6
|
+
/** Invitation purpose values. */
|
|
7
|
+
export declare const InvitationPurpose: {
|
|
8
|
+
readonly Session: "session";
|
|
9
|
+
readonly OID4VCI: "oid4vci";
|
|
10
|
+
readonly OID4VP: "oid4vp";
|
|
11
|
+
readonly Join: "join";
|
|
12
|
+
};
|
|
13
|
+
/** A self-contained, signed invitation that bootstraps a WMP session. */
|
|
14
|
+
export interface Invitation {
|
|
15
|
+
/** Inviter's wallet provider identifier (domain-based, discoverable). */
|
|
16
|
+
provider: string;
|
|
17
|
+
/** Inviter's participant identifier (may be non-discoverable, e.g. did:key). */
|
|
18
|
+
sender: string;
|
|
19
|
+
/** Unique, cryptographically random nonce (at least 128 bits). */
|
|
20
|
+
nonce: string;
|
|
21
|
+
/** Inviter's relay endpoint URL (optional shortcut, skips well-known fetch). */
|
|
22
|
+
relay?: string;
|
|
23
|
+
/** Purpose of the invitation. Default: "session". */
|
|
24
|
+
purpose?: string;
|
|
25
|
+
/** Existing session to join (when purpose is "join"). */
|
|
26
|
+
session_id?: string;
|
|
27
|
+
/** Human-readable label for the inviter (informational only). */
|
|
28
|
+
label?: string;
|
|
29
|
+
/** Pre-advertised capabilities (informational, subject to negotiation). */
|
|
30
|
+
capabilities?: Capabilities;
|
|
31
|
+
/** ISO 8601 expiry timestamp. */
|
|
32
|
+
expires_at: string;
|
|
33
|
+
/** Detached JWS signature over the invitation payload. */
|
|
34
|
+
signature: string;
|
|
35
|
+
}
|
|
36
|
+
/** Options for creating an invitation. */
|
|
37
|
+
export interface CreateInvitationOptions {
|
|
38
|
+
provider: string;
|
|
39
|
+
sender: string;
|
|
40
|
+
/** TTL in seconds. Default: 300 (5 minutes). */
|
|
41
|
+
ttl?: number;
|
|
42
|
+
relay?: string;
|
|
43
|
+
purpose?: string;
|
|
44
|
+
session_id?: string;
|
|
45
|
+
label?: string;
|
|
46
|
+
capabilities?: Capabilities;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate a cryptographically random nonce with the "inv-" prefix.
|
|
50
|
+
* Uses 128 bits of randomness.
|
|
51
|
+
*/
|
|
52
|
+
export declare function generateNonce(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Create an unsigned invitation. The caller must set `signature` after
|
|
55
|
+
* signing the payload with the sender's key.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createInvitation(opts: CreateInvitationOptions): Invitation;
|
|
58
|
+
/**
|
|
59
|
+
* Get the signing payload for an invitation (all fields except `signature`).
|
|
60
|
+
* The caller should JCS-canonicalize and sign this JSON.
|
|
61
|
+
*/
|
|
62
|
+
export declare function invitationSigningPayload(inv: Invitation): Record<string, unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* Serialize an invitation to a `wmp://invite?data=<base64url>` URI.
|
|
65
|
+
*/
|
|
66
|
+
export declare function invitationToURI(inv: Invitation): string;
|
|
67
|
+
/**
|
|
68
|
+
* Serialize an invitation to an HTTPS fallback URI:
|
|
69
|
+
* `https://<provider-domain>/wmp/invite#<base64url>`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function invitationToHTTPSURI(inv: Invitation): string;
|
|
72
|
+
/**
|
|
73
|
+
* Parse an invitation from a `wmp://invite?data=...` URI or
|
|
74
|
+
* `https://...#...` HTTPS fallback URI.
|
|
75
|
+
* Does NOT verify the signature.
|
|
76
|
+
*/
|
|
77
|
+
export declare function parseInvitationURI(uri: string): Invitation;
|
|
78
|
+
/**
|
|
79
|
+
* Parse an invitation from raw JSON.
|
|
80
|
+
* Does NOT verify the signature.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseInvitationJSON(data: string | object): Invitation;
|
|
83
|
+
/**
|
|
84
|
+
* Check whether an invitation has expired.
|
|
85
|
+
*/
|
|
86
|
+
export declare function isInvitationExpired(inv: Invitation): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* InvitationStore tracks issued invitation nonces.
|
|
89
|
+
*/
|
|
90
|
+
export interface InvitationStore {
|
|
91
|
+
/** Store a nonce with its invitation. Rejects if nonce already exists. */
|
|
92
|
+
put(nonce: string, inv: Invitation): void;
|
|
93
|
+
/** Atomically consume a nonce. Returns the invitation or undefined. */
|
|
94
|
+
consume(nonce: string): Invitation | undefined;
|
|
95
|
+
/** Remove expired nonces. Returns the count removed. */
|
|
96
|
+
cleanup(): number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Thread-safe (single-threaded JS) in-memory invitation store.
|
|
100
|
+
*/
|
|
101
|
+
export declare class MemoryInvitationStore implements InvitationStore {
|
|
102
|
+
private nonces;
|
|
103
|
+
put(nonce: string, inv: Invitation): void;
|
|
104
|
+
consume(nonce: string): Invitation | undefined;
|
|
105
|
+
cleanup(): number;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Validate an invitation_nonce from a wmp.session.create request.
|
|
109
|
+
* Returns the original invitation on success, or throws with an error reason.
|
|
110
|
+
*/
|
|
111
|
+
export declare function validateInvitationNonce(store: InvitationStore, nonce: string | undefined): Invitation;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WMP Invitation — session bootstrap via out-of-band invitation exchange.
|
|
3
|
+
* See wmp-invitation.md for the specification.
|
|
4
|
+
*/
|
|
5
|
+
import { extractDomain } from "./discovery.js";
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Constants
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
/** Invitation purpose values. */
|
|
10
|
+
export const InvitationPurpose = {
|
|
11
|
+
Session: "session",
|
|
12
|
+
OID4VCI: "oid4vci",
|
|
13
|
+
OID4VP: "oid4vp",
|
|
14
|
+
Join: "join",
|
|
15
|
+
};
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Nonce generation
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/**
|
|
20
|
+
* Generate a cryptographically random nonce with the "inv-" prefix.
|
|
21
|
+
* Uses 128 bits of randomness.
|
|
22
|
+
*/
|
|
23
|
+
export function generateNonce() {
|
|
24
|
+
const bytes = new Uint8Array(16);
|
|
25
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
26
|
+
// base64url encode without padding
|
|
27
|
+
const b64 = btoa(String.fromCharCode(...bytes))
|
|
28
|
+
.replace(/\+/g, "-")
|
|
29
|
+
.replace(/\//g, "_")
|
|
30
|
+
.replace(/=+$/, "");
|
|
31
|
+
return `inv-${b64}`;
|
|
32
|
+
}
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Invitation creation & parsing
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* Create an unsigned invitation. The caller must set `signature` after
|
|
38
|
+
* signing the payload with the sender's key.
|
|
39
|
+
*/
|
|
40
|
+
export function createInvitation(opts) {
|
|
41
|
+
const ttl = opts.ttl ?? 300;
|
|
42
|
+
const expiresAt = new Date(Date.now() + ttl * 1000).toISOString();
|
|
43
|
+
return {
|
|
44
|
+
provider: opts.provider,
|
|
45
|
+
sender: opts.sender,
|
|
46
|
+
nonce: generateNonce(),
|
|
47
|
+
relay: opts.relay,
|
|
48
|
+
purpose: opts.purpose ?? InvitationPurpose.Session,
|
|
49
|
+
session_id: opts.session_id,
|
|
50
|
+
label: opts.label,
|
|
51
|
+
capabilities: opts.capabilities,
|
|
52
|
+
expires_at: expiresAt,
|
|
53
|
+
signature: "", // caller sets after signing
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the signing payload for an invitation (all fields except `signature`).
|
|
58
|
+
* The caller should JCS-canonicalize and sign this JSON.
|
|
59
|
+
*/
|
|
60
|
+
export function invitationSigningPayload(inv) {
|
|
61
|
+
const { signature: _, ...rest } = inv;
|
|
62
|
+
// Remove undefined values
|
|
63
|
+
return JSON.parse(JSON.stringify(rest));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Serialize an invitation to a `wmp://invite?data=<base64url>` URI.
|
|
67
|
+
*/
|
|
68
|
+
export function invitationToURI(inv) {
|
|
69
|
+
const json = JSON.stringify(inv);
|
|
70
|
+
const b64 = btoa(json)
|
|
71
|
+
.replace(/\+/g, "-")
|
|
72
|
+
.replace(/\//g, "_")
|
|
73
|
+
.replace(/=+$/, "");
|
|
74
|
+
return `wmp://invite?data=${b64}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Serialize an invitation to an HTTPS fallback URI:
|
|
78
|
+
* `https://<provider-domain>/wmp/invite#<base64url>`.
|
|
79
|
+
*/
|
|
80
|
+
export function invitationToHTTPSURI(inv) {
|
|
81
|
+
const domain = extractDomain(inv.provider);
|
|
82
|
+
if (!domain) {
|
|
83
|
+
throw new Error(`Cannot extract domain from provider "${inv.provider}"`);
|
|
84
|
+
}
|
|
85
|
+
const json = JSON.stringify(inv);
|
|
86
|
+
const b64 = btoa(json)
|
|
87
|
+
.replace(/\+/g, "-")
|
|
88
|
+
.replace(/\//g, "_")
|
|
89
|
+
.replace(/=+$/, "");
|
|
90
|
+
return `https://${domain}/wmp/invite#${b64}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parse an invitation from a `wmp://invite?data=...` URI or
|
|
94
|
+
* `https://...#...` HTTPS fallback URI.
|
|
95
|
+
* Does NOT verify the signature.
|
|
96
|
+
*/
|
|
97
|
+
export function parseInvitationURI(uri) {
|
|
98
|
+
let encoded;
|
|
99
|
+
if (uri.startsWith("wmp://invite")) {
|
|
100
|
+
const url = new URL(uri);
|
|
101
|
+
const data = url.searchParams.get("data");
|
|
102
|
+
if (!data) {
|
|
103
|
+
const ref = url.searchParams.get("ref");
|
|
104
|
+
if (ref) {
|
|
105
|
+
throw new Error(`Invitation uses ref="${ref}": fetch the URL to get the full invitation`);
|
|
106
|
+
}
|
|
107
|
+
throw new Error("Invitation URI missing 'data' parameter");
|
|
108
|
+
}
|
|
109
|
+
encoded = data;
|
|
110
|
+
}
|
|
111
|
+
else if (uri.includes("/wmp/invite#")) {
|
|
112
|
+
const idx = uri.lastIndexOf("#");
|
|
113
|
+
if (idx < 0 || idx === uri.length - 1) {
|
|
114
|
+
throw new Error("HTTPS invitation URI missing fragment");
|
|
115
|
+
}
|
|
116
|
+
encoded = uri.slice(idx + 1);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error(`Unrecognised invitation URI scheme: "${uri}"`);
|
|
120
|
+
}
|
|
121
|
+
// base64url decode
|
|
122
|
+
const padded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
123
|
+
const json = atob(padded);
|
|
124
|
+
return JSON.parse(json);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Parse an invitation from raw JSON.
|
|
128
|
+
* Does NOT verify the signature.
|
|
129
|
+
*/
|
|
130
|
+
export function parseInvitationJSON(data) {
|
|
131
|
+
if (typeof data === "string") {
|
|
132
|
+
return JSON.parse(data);
|
|
133
|
+
}
|
|
134
|
+
return data;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check whether an invitation has expired.
|
|
138
|
+
*/
|
|
139
|
+
export function isInvitationExpired(inv) {
|
|
140
|
+
return new Date(inv.expires_at).getTime() < Date.now();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Thread-safe (single-threaded JS) in-memory invitation store.
|
|
144
|
+
*/
|
|
145
|
+
export class MemoryInvitationStore {
|
|
146
|
+
nonces = new Map();
|
|
147
|
+
put(nonce, inv) {
|
|
148
|
+
if (this.nonces.has(nonce)) {
|
|
149
|
+
throw new Error(`Nonce "${nonce}" already exists`);
|
|
150
|
+
}
|
|
151
|
+
this.nonces.set(nonce, inv);
|
|
152
|
+
}
|
|
153
|
+
consume(nonce) {
|
|
154
|
+
const inv = this.nonces.get(nonce);
|
|
155
|
+
if (!inv)
|
|
156
|
+
return undefined;
|
|
157
|
+
if (isInvitationExpired(inv)) {
|
|
158
|
+
this.nonces.delete(nonce);
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
this.nonces.delete(nonce);
|
|
162
|
+
return inv;
|
|
163
|
+
}
|
|
164
|
+
cleanup() {
|
|
165
|
+
let count = 0;
|
|
166
|
+
for (const [nonce, inv] of this.nonces) {
|
|
167
|
+
if (isInvitationExpired(inv)) {
|
|
168
|
+
this.nonces.delete(nonce);
|
|
169
|
+
count++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return count;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Validate an invitation_nonce from a wmp.session.create request.
|
|
177
|
+
* Returns the original invitation on success, or throws with an error reason.
|
|
178
|
+
*/
|
|
179
|
+
export function validateInvitationNonce(store, nonce) {
|
|
180
|
+
if (!nonce) {
|
|
181
|
+
throw new Error("missing invitation_nonce");
|
|
182
|
+
}
|
|
183
|
+
const inv = store.consume(nonce);
|
|
184
|
+
if (!inv) {
|
|
185
|
+
throw new Error("invalid_invitation_nonce");
|
|
186
|
+
}
|
|
187
|
+
return inv;
|
|
188
|
+
}
|
package/dist/openid4x.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Provides OID4VCI (credential issuance) and OID4VP (credential presentation)
|
|
5
5
|
* flow handling via the WMP profile system.
|
|
6
6
|
*/
|
|
7
|
-
import type { FlowStartParams, FlowStartResult, FlowActionParams, FlowActionResult, FlowProgressParams, FlowCompleteParams, FlowErrorParams, ResolveParams, ResolveResult } from "./types.js";
|
|
7
|
+
import type { FlowStartParams, FlowStartResult, FlowActionParams, FlowActionResult, FlowProgressParams, FlowCompleteParams, FlowErrorParams, Metadata, ResolveParams, ResolveResult } from "./types.js";
|
|
8
8
|
import type { Profile, PeerContext, FlowHandler, ResolveHandler } from "./profile.js";
|
|
9
9
|
export declare const CredentialFormat: {
|
|
10
10
|
readonly VC_SDJWT: "vc+sd-jwt";
|
|
@@ -98,18 +98,143 @@ export interface CredentialResult {
|
|
|
98
98
|
credential: string;
|
|
99
99
|
vct?: string;
|
|
100
100
|
c_nonce?: string;
|
|
101
|
+
notification_id?: string;
|
|
102
|
+
}
|
|
103
|
+
/** OID4VCI §10 credential lifecycle events. */
|
|
104
|
+
export type CredentialEvent = "credential_accepted" | "credential_failure";
|
|
105
|
+
/** Params for wmp.credential.notification. */
|
|
106
|
+
export interface CredentialNotificationParams {
|
|
107
|
+
wmp: Metadata;
|
|
108
|
+
flow_id: string;
|
|
109
|
+
notification_id: string;
|
|
110
|
+
event: CredentialEvent;
|
|
111
|
+
event_description?: string;
|
|
101
112
|
}
|
|
102
113
|
export interface VPTokenResult {
|
|
103
114
|
vp_token?: string | string[];
|
|
104
115
|
presentation_submission?: unknown;
|
|
105
116
|
response_code?: string;
|
|
106
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Client attestation credentials (WIA + PoP) for issuer authentication.
|
|
120
|
+
* Produced by a {@link ClientAttestationProvider}.
|
|
121
|
+
*/
|
|
122
|
+
export interface ClientAttestation {
|
|
123
|
+
/** WIA JWT (typ: oauth-client-attestation+jwt) */
|
|
124
|
+
client_attestation: string;
|
|
125
|
+
/** PoP JWT (typ: oauth-client-attestation-pop+jwt) signed by wallet instance key */
|
|
126
|
+
client_attestation_pop: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Provider interface for obtaining OAuth client attestation credentials.
|
|
130
|
+
*
|
|
131
|
+
* Callers implement this to decouple wmp-js from any specific wallet backend.
|
|
132
|
+
* The provider is responsible for:
|
|
133
|
+
* 1. Obtaining a WIA JWT from the wallet provider (implementation-defined)
|
|
134
|
+
* 2. Signing the PoP JWT with the wallet instance key (aud = issuer AS URL)
|
|
135
|
+
*
|
|
136
|
+
* Example implementations:
|
|
137
|
+
* - SIROS: calls /wallet-provider/wia/generate, signs PoP with passkey-PRF key
|
|
138
|
+
* - EUDI: calls the PID provider's WIA endpoint, signs PoP with device key
|
|
139
|
+
* - Test: returns static test JWTs
|
|
140
|
+
*/
|
|
141
|
+
export interface ClientAttestationProvider {
|
|
142
|
+
/**
|
|
143
|
+
* Get attestation credentials for a specific issuer.
|
|
144
|
+
* @param audience - The issuer's AS URL (used as PoP aud claim)
|
|
145
|
+
* @returns WIA + PoP JWTs, or null if attestation is not available/required
|
|
146
|
+
*/
|
|
147
|
+
getAttestation(audience: string): Promise<ClientAttestation | null>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* OID4VCI-specific parameters for wmp.flow.start.
|
|
151
|
+
* Passed as the `params` field of FlowStartParams when flow_type = "oid4vci".
|
|
152
|
+
*
|
|
153
|
+
* Client attestation fields support draft-ietf-oauth-attestation-based-client-auth-04:
|
|
154
|
+
* - `client_attestation`: WIA JWT from the provider
|
|
155
|
+
* - `client_attestation_pop`: PoP JWT signed by the wallet instance key (aud = AS URL)
|
|
156
|
+
*
|
|
157
|
+
* The instance key is held client-side (never on the backend).
|
|
158
|
+
* The backend forwards these as HTTP headers without modification.
|
|
159
|
+
*/
|
|
160
|
+
/** Common fields shared by all OID4VCI flow param variants. */
|
|
161
|
+
interface OID4VCIFlowParamsBase {
|
|
162
|
+
/** OAuth redirect URI for authorization code flow */
|
|
163
|
+
redirect_uri?: string;
|
|
164
|
+
/** WIA JWT (typ: oauth-client-attestation+jwt) obtained via ClientAttestationProvider */
|
|
165
|
+
client_attestation?: string;
|
|
166
|
+
/** PoP JWT (typ: oauth-client-attestation-pop+jwt) signed by wallet instance key */
|
|
167
|
+
client_attestation_pop?: string;
|
|
168
|
+
/** Authorization code from OAuth redirect */
|
|
169
|
+
auth_code?: string;
|
|
170
|
+
/** PKCE code verifier (saved by client before redirect) */
|
|
171
|
+
code_verifier?: string;
|
|
172
|
+
}
|
|
173
|
+
/** OID4VCI params with an inline credential offer. */
|
|
174
|
+
export interface OID4VCIFlowParamsWithOffer extends OID4VCIFlowParamsBase {
|
|
175
|
+
/** Credential offer URI (openid-credential-offer://...) */
|
|
176
|
+
offer: string;
|
|
177
|
+
credential_offer_uri?: never;
|
|
178
|
+
}
|
|
179
|
+
/** OID4VCI params with a credential offer by reference. */
|
|
180
|
+
export interface OID4VCIFlowParamsWithURI extends OID4VCIFlowParamsBase {
|
|
181
|
+
offer?: never;
|
|
182
|
+
/** Credential offer URI by reference (https://...) */
|
|
183
|
+
credential_offer_uri: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* OID4VCI-specific parameters for wmp.flow.start.
|
|
187
|
+
* Passed as the `params` field of FlowStartParams when flow_type = "oid4vci".
|
|
188
|
+
*
|
|
189
|
+
* Exactly one of `offer` or `credential_offer_uri` must be provided.
|
|
190
|
+
*/
|
|
191
|
+
export type OID4VCIFlowParams = OID4VCIFlowParamsWithOffer | OID4VCIFlowParamsWithURI;
|
|
192
|
+
/**
|
|
193
|
+
* OID4VP-specific parameters for wmp.flow.start.
|
|
194
|
+
* Passed as the `params` field of FlowStartParams when flow_type = "oid4vp".
|
|
195
|
+
*/
|
|
196
|
+
export interface OID4VPFlowParams {
|
|
197
|
+
/** Request URI (openid4vp://...) */
|
|
198
|
+
request_uri?: string;
|
|
199
|
+
/** Request URI by reference (https://...) */
|
|
200
|
+
request_uri_ref?: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Helper to build WMP FlowStartParams for an OID4VCI flow.
|
|
204
|
+
* If attestation is provided, it is included in the params.
|
|
205
|
+
*/
|
|
206
|
+
export declare function buildVCIFlowStart(sessionId: string, flowId: string, params: OID4VCIFlowParams, timeout?: number): FlowStartParams;
|
|
207
|
+
/**
|
|
208
|
+
* Helper to build VCI flow params with attestation from a provider.
|
|
209
|
+
* Calls the provider to obtain WIA + PoP, then merges into the params.
|
|
210
|
+
*
|
|
211
|
+
* @param provider - The attestation provider (caller-supplied)
|
|
212
|
+
* @param audience - The issuer's AS URL for PoP audience binding
|
|
213
|
+
* @param params - Base OID4VCI flow params (offer, redirect_uri, etc.)
|
|
214
|
+
* @returns params with attestation fields populated (or unchanged if provider returns null)
|
|
215
|
+
*/
|
|
216
|
+
export declare function withAttestation(provider: ClientAttestationProvider, audience: string, params: OID4VCIFlowParams): Promise<OID4VCIFlowParams>;
|
|
217
|
+
/**
|
|
218
|
+
* TransactionData represents a single transaction data object from
|
|
219
|
+
* the verifier's OID4VP authorization request (TS12/SCA).
|
|
220
|
+
*/
|
|
221
|
+
export interface TransactionData {
|
|
222
|
+
type: string;
|
|
223
|
+
params?: Record<string, unknown>;
|
|
224
|
+
/** Credential IDs this transaction data applies to */
|
|
225
|
+
credential_ids?: string[];
|
|
226
|
+
/** Hash algorithm for transaction_data_hashes */
|
|
227
|
+
hash_alg?: string;
|
|
228
|
+
/** Algorithm identifier for the hashes claim in KB-JWT */
|
|
229
|
+
transaction_data_hashes_alg?: string;
|
|
230
|
+
}
|
|
107
231
|
export interface SignSubFlowParams {
|
|
108
232
|
action: string;
|
|
109
233
|
nonce: string;
|
|
110
234
|
audience: string;
|
|
111
235
|
proof_type?: string;
|
|
112
236
|
parent_flow_id: string;
|
|
237
|
+
transaction_data?: TransactionData[];
|
|
113
238
|
}
|
|
114
239
|
export interface SelectionAction {
|
|
115
240
|
selected_indices: number[];
|
|
@@ -165,3 +290,4 @@ export declare class OpenID4xProfile implements Profile, FlowHandler, ResolveHan
|
|
|
165
290
|
resolveTypes(): string[];
|
|
166
291
|
handleResolve(_params: ResolveParams): Promise<ResolveResult>;
|
|
167
292
|
}
|
|
293
|
+
export {};
|
package/dist/openid4x.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* flow handling via the WMP profile system.
|
|
6
6
|
*/
|
|
7
7
|
import { WMPError } from "./jsonrpc.js";
|
|
8
|
-
import { ErrorCode } from "./types.js";
|
|
8
|
+
import { ErrorCode, VERSION } from "./types.js";
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
// Credential format constants — aligned with wallet-common VerifiableCredentialFormat
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
@@ -93,6 +93,38 @@ export const OID4Action = {
|
|
|
93
93
|
SelectCredentials: "select_credentials",
|
|
94
94
|
Cancel: "cancel",
|
|
95
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Helper to build WMP FlowStartParams for an OID4VCI flow.
|
|
98
|
+
* If attestation is provided, it is included in the params.
|
|
99
|
+
*/
|
|
100
|
+
export function buildVCIFlowStart(sessionId, flowId, params, timeout) {
|
|
101
|
+
return {
|
|
102
|
+
wmp: { version: VERSION, session_id: sessionId },
|
|
103
|
+
flow_type: OID4FlowType.OID4VCI,
|
|
104
|
+
flow_id: flowId,
|
|
105
|
+
params,
|
|
106
|
+
timeout,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Helper to build VCI flow params with attestation from a provider.
|
|
111
|
+
* Calls the provider to obtain WIA + PoP, then merges into the params.
|
|
112
|
+
*
|
|
113
|
+
* @param provider - The attestation provider (caller-supplied)
|
|
114
|
+
* @param audience - The issuer's AS URL for PoP audience binding
|
|
115
|
+
* @param params - Base OID4VCI flow params (offer, redirect_uri, etc.)
|
|
116
|
+
* @returns params with attestation fields populated (or unchanged if provider returns null)
|
|
117
|
+
*/
|
|
118
|
+
export async function withAttestation(provider, audience, params) {
|
|
119
|
+
const attestation = await provider.getAttestation(audience);
|
|
120
|
+
if (!attestation)
|
|
121
|
+
return params;
|
|
122
|
+
return {
|
|
123
|
+
...params,
|
|
124
|
+
client_attestation: attestation.client_attestation,
|
|
125
|
+
client_attestation_pop: attestation.client_attestation_pop,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
96
128
|
// ---------------------------------------------------------------------------
|
|
97
129
|
// OpenID4x Profile
|
|
98
130
|
// ---------------------------------------------------------------------------
|
package/dist/peer.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { type Transport } from "./transport.js";
|
|
9
9
|
import { type Profile, type PeerContext } from "./profile.js";
|
|
10
|
-
import { type SessionCreateParams, type SessionCreateResult, type SessionCloseParams, type FlowStartParams, type FlowStartResult, type FlowProgressParams, type FlowActionParams, type FlowActionResult, type FlowCompleteParams, type FlowErrorParams, type FlowCancelParams, type FlowCancelResult, type ResolveParams, type ResolveResult, type Capabilities, type SecurityMode } from "./types.js";
|
|
10
|
+
import { type SessionCreateParams, type SessionCreateResult, type SessionResumeResult, type SessionCloseParams, type FlowStartParams, type FlowStartResult, type FlowProgressParams, type FlowActionParams, type FlowActionResult, type FlowCompleteParams, type FlowErrorParams, type FlowCancelParams, type FlowCancelResult, type ResolveParams, type ResolveResult, type Capabilities, type SecurityMode } from "./types.js";
|
|
11
11
|
/**
|
|
12
12
|
* Handler processes incoming WMP method calls.
|
|
13
13
|
* All methods are optional — unimplemented methods return "method not found".
|
|
@@ -36,6 +36,8 @@ export declare class Peer implements PeerContext {
|
|
|
36
36
|
private pending;
|
|
37
37
|
private callTimeout;
|
|
38
38
|
private sessionId?;
|
|
39
|
+
private negotiatedVersion?;
|
|
40
|
+
private resumptionToken?;
|
|
39
41
|
private closed;
|
|
40
42
|
constructor(transport: Transport, opts?: PeerOptions);
|
|
41
43
|
/** Register a profile. Call before starting to receive messages. */
|
|
@@ -57,6 +59,12 @@ export declare class Peer implements PeerContext {
|
|
|
57
59
|
sender?: string;
|
|
58
60
|
ttl?: number;
|
|
59
61
|
}): Promise<SessionCreateResult>;
|
|
62
|
+
/** Resume a previously established WMP session using a resumption token. */
|
|
63
|
+
resumeSession(opts?: {
|
|
64
|
+
lastReceivedId?: string;
|
|
65
|
+
}): Promise<SessionResumeResult>;
|
|
66
|
+
/** The current resumption token (set after session.create or session.resume). */
|
|
67
|
+
get token(): string | undefined;
|
|
60
68
|
/**
|
|
61
69
|
* Bind a session ID to the underlying transport. For HttpSseTransport,
|
|
62
70
|
* this sets the Wmp-Session-Id header and session_id query parameter.
|
package/dist/peer.js
CHANGED
|
@@ -18,6 +18,8 @@ export class Peer {
|
|
|
18
18
|
pending = new Map();
|
|
19
19
|
callTimeout;
|
|
20
20
|
sessionId;
|
|
21
|
+
negotiatedVersion;
|
|
22
|
+
resumptionToken;
|
|
21
23
|
closed = false;
|
|
22
24
|
constructor(transport, opts) {
|
|
23
25
|
this.transport = transport;
|
|
@@ -84,8 +86,42 @@ export class Peer {
|
|
|
84
86
|
// Propagate session ID to transport for header/URL binding.
|
|
85
87
|
this.bindSessionToTransport(result.wmp.session_id);
|
|
86
88
|
}
|
|
89
|
+
if (result.wmp?.version) {
|
|
90
|
+
this.negotiatedVersion = result.wmp.version;
|
|
91
|
+
}
|
|
92
|
+
if (result.resumption_token) {
|
|
93
|
+
this.resumptionToken = result.resumption_token;
|
|
94
|
+
}
|
|
87
95
|
return result;
|
|
88
96
|
}
|
|
97
|
+
/** Resume a previously established WMP session using a resumption token. */
|
|
98
|
+
async resumeSession(opts) {
|
|
99
|
+
if (!this.sessionId || !this.resumptionToken) {
|
|
100
|
+
throw new Error("no session or resumption token to resume");
|
|
101
|
+
}
|
|
102
|
+
const params = {
|
|
103
|
+
wmp: { version: this.negotiatedVersion ?? VERSION },
|
|
104
|
+
session_id: this.sessionId,
|
|
105
|
+
resumption_token: this.resumptionToken,
|
|
106
|
+
last_received_id: opts?.lastReceivedId,
|
|
107
|
+
};
|
|
108
|
+
const result = await this.call(Method.SessionResume, params);
|
|
109
|
+
if (result.wmp?.session_id) {
|
|
110
|
+
this.sessionId = result.wmp.session_id;
|
|
111
|
+
this.bindSessionToTransport(result.wmp.session_id);
|
|
112
|
+
}
|
|
113
|
+
if (result.wmp?.version) {
|
|
114
|
+
this.negotiatedVersion = result.wmp.version;
|
|
115
|
+
}
|
|
116
|
+
if (result.resumption_token) {
|
|
117
|
+
this.resumptionToken = result.resumption_token;
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/** The current resumption token (set after session.create or session.resume). */
|
|
122
|
+
get token() {
|
|
123
|
+
return this.resumptionToken;
|
|
124
|
+
}
|
|
89
125
|
/**
|
|
90
126
|
* Bind a session ID to the underlying transport. For HttpSseTransport,
|
|
91
127
|
* this sets the Wmp-Session-Id header and session_id query parameter.
|
|
@@ -347,7 +383,7 @@ export class Peer {
|
|
|
347
383
|
// -------------------------------------------------------------------------
|
|
348
384
|
wmpMeta() {
|
|
349
385
|
return {
|
|
350
|
-
version: VERSION,
|
|
386
|
+
version: this.negotiatedVersion ?? VERSION,
|
|
351
387
|
session_id: this.sessionId,
|
|
352
388
|
timestamp: new Date().toISOString(),
|
|
353
389
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export declare const Method: {
|
|
|
70
70
|
readonly FlowComplete: "wmp.flow.complete";
|
|
71
71
|
readonly FlowError: "wmp.flow.error";
|
|
72
72
|
readonly FlowCancel: "wmp.flow.cancel";
|
|
73
|
+
readonly CredentialNotification: "wmp.credential.notification";
|
|
73
74
|
readonly Resolve: "wmp.resolve";
|
|
74
75
|
readonly RelayRegister: "wmp.relay.register";
|
|
75
76
|
};
|
|
@@ -99,8 +100,20 @@ export declare const ErrorCode: {
|
|
|
99
100
|
export interface AuthObject {
|
|
100
101
|
type: string;
|
|
101
102
|
token?: string;
|
|
103
|
+
signature?: string;
|
|
104
|
+
x5c?: string[];
|
|
102
105
|
[key: string]: unknown;
|
|
103
106
|
}
|
|
107
|
+
/** Authentication type constants. */
|
|
108
|
+
export declare const AuthType: {
|
|
109
|
+
readonly Bearer: "bearer";
|
|
110
|
+
readonly DPoP: "dpop";
|
|
111
|
+
readonly MTLS: "mtls";
|
|
112
|
+
readonly SignedChallenge: "signed_challenge";
|
|
113
|
+
readonly X5C: "x5c";
|
|
114
|
+
/** @deprecated Use SignedChallenge instead. */
|
|
115
|
+
readonly DIDAuth: "did_auth";
|
|
116
|
+
};
|
|
104
117
|
export interface SessionCreateParams {
|
|
105
118
|
wmp: Metadata;
|
|
106
119
|
participants?: string[];
|
|
@@ -108,17 +121,28 @@ export interface SessionCreateParams {
|
|
|
108
121
|
security: SecurityMode;
|
|
109
122
|
ttl?: number;
|
|
110
123
|
auth?: AuthObject;
|
|
124
|
+
invitation_nonce?: string;
|
|
111
125
|
}
|
|
112
126
|
export interface SessionCreateResult {
|
|
113
127
|
wmp: Metadata;
|
|
114
128
|
capabilities?: Capabilities;
|
|
115
129
|
security: SecurityMode;
|
|
116
130
|
challenge?: string;
|
|
131
|
+
resumption_token?: string;
|
|
117
132
|
}
|
|
118
133
|
export interface SessionResumeParams {
|
|
119
134
|
wmp: Metadata;
|
|
120
135
|
session_id: string;
|
|
121
|
-
|
|
136
|
+
resumption_token: string;
|
|
137
|
+
last_received_id?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface SessionResumeResult {
|
|
140
|
+
wmp: Metadata;
|
|
141
|
+
resumed: boolean;
|
|
142
|
+
resumption_token?: string;
|
|
143
|
+
missed_messages: number;
|
|
144
|
+
capabilities?: Capabilities;
|
|
145
|
+
security: SecurityMode;
|
|
122
146
|
}
|
|
123
147
|
export interface SessionCloseParams {
|
|
124
148
|
wmp: Metadata;
|
package/dist/types.js
CHANGED
|
@@ -22,6 +22,7 @@ export const Method = {
|
|
|
22
22
|
FlowComplete: "wmp.flow.complete",
|
|
23
23
|
FlowError: "wmp.flow.error",
|
|
24
24
|
FlowCancel: "wmp.flow.cancel",
|
|
25
|
+
CredentialNotification: "wmp.credential.notification",
|
|
25
26
|
Resolve: "wmp.resolve",
|
|
26
27
|
RelayRegister: "wmp.relay.register",
|
|
27
28
|
};
|
|
@@ -50,6 +51,16 @@ export const ErrorCode = {
|
|
|
50
51
|
VersionNotSupported: -31013,
|
|
51
52
|
QueueFull: -31014,
|
|
52
53
|
};
|
|
54
|
+
/** Authentication type constants. */
|
|
55
|
+
export const AuthType = {
|
|
56
|
+
Bearer: "bearer",
|
|
57
|
+
DPoP: "dpop",
|
|
58
|
+
MTLS: "mtls",
|
|
59
|
+
SignedChallenge: "signed_challenge",
|
|
60
|
+
X5C: "x5c",
|
|
61
|
+
/** @deprecated Use SignedChallenge instead. */
|
|
62
|
+
DIDAuth: "did_auth",
|
|
63
|
+
};
|
|
53
64
|
// Close reason constants.
|
|
54
65
|
export const CloseReason = {
|
|
55
66
|
Complete: "complete",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sirosfoundation/wmp-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Wallet Messaging Protocol (WMP) client library — JSON-RPC 2.0 over WebSocket and HTTP+SSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,9 +25,10 @@
|
|
|
25
25
|
"lint": "tsc --noEmit"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^
|
|
29
|
-
"
|
|
30
|
-
"
|
|
28
|
+
"@types/node": "^26.0.0",
|
|
29
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
30
|
+
"typescript": "^7.0.2",
|
|
31
|
+
"vitest": "^4.1.9"
|
|
31
32
|
},
|
|
32
33
|
"license": "BSD-2-Clause",
|
|
33
34
|
"repository": {
|