@sirosfoundation/wmp-js 0.2.0 → 0.5.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/README.md +1 -0
- package/dist/discovery.d.ts +46 -0
- package/dist/discovery.js +70 -0
- package/dist/evidence.d.ts +92 -0
- package/dist/evidence.js +54 -0
- package/dist/index.d.ts +15 -4
- package/dist/index.js +11 -2
- package/dist/invitation.d.ts +131 -0
- package/dist/invitation.js +210 -0
- package/dist/jsonrpc.d.ts +9 -3
- package/dist/jsonrpc.js +60 -10
- package/dist/mls-provider.d.ts +65 -0
- package/dist/mls-provider.js +216 -0
- package/dist/mls.d.ts +8 -0
- package/dist/mls.js +8 -0
- package/dist/native.d.ts +9 -5
- package/dist/native.js +62 -57
- package/dist/node.d.ts +1 -1
- package/dist/openid4x.d.ts +150 -4
- package/dist/openid4x.js +69 -1
- package/dist/peer.d.ts +27 -1
- package/dist/peer.js +109 -5
- package/dist/schema.d.ts +2 -1
- package/dist/schema.js +12 -5
- package/dist/session-store.d.ts +33 -0
- package/dist/session-store.js +36 -0
- package/dist/transport.d.ts +8 -0
- package/dist/transport.js +28 -3
- package/dist/types.d.ts +63 -5
- package/dist/types.js +25 -0
- package/package.json +9 -5
package/dist/transport.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ declare class Emitter {
|
|
|
37
37
|
export interface WebSocketTransportOptions {
|
|
38
38
|
/** WebSocket subprotocol. Default: "wmp.v1" */
|
|
39
39
|
protocols?: string | string[];
|
|
40
|
+
/** Allow unencrypted ws:// URLs. Default: false. */
|
|
41
|
+
allowInsecure?: boolean;
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* WebSocket transport — bidirectional, persistent connection.
|
|
@@ -92,6 +94,12 @@ export declare class HttpSseTransport extends Emitter implements Transport {
|
|
|
92
94
|
* Separated from the constructor so callers can register listeners first.
|
|
93
95
|
*/
|
|
94
96
|
connectSSE(lastEventId?: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Reconnect the SSE stream with the current authorization/session state.
|
|
99
|
+
* Useful after calling setAuthorization.
|
|
100
|
+
*/
|
|
101
|
+
reconnectSSE(lastEventId?: string): void;
|
|
102
|
+
private setupEventSource;
|
|
95
103
|
send(msg: Message): Promise<void>;
|
|
96
104
|
close(): void;
|
|
97
105
|
on<K extends TransportEventName>(event: K, listener: TransportEvents[K]): void;
|
package/dist/transport.js
CHANGED
|
@@ -32,6 +32,19 @@ export class WebSocketTransport extends Emitter {
|
|
|
32
32
|
constructor(url, opts) {
|
|
33
33
|
super();
|
|
34
34
|
const protocols = opts?.protocols ?? "wmp.v1";
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = new URL(url);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new Error("Invalid WebSocket URL");
|
|
41
|
+
}
|
|
42
|
+
if (parsed.protocol !== "wss:" && parsed.protocol !== "ws:") {
|
|
43
|
+
throw new Error(`Invalid WebSocket URL scheme: ${parsed.protocol}. Use ws:// or wss://`);
|
|
44
|
+
}
|
|
45
|
+
if (parsed.protocol === "ws:" && !opts?.allowInsecure) {
|
|
46
|
+
throw new Error("Unencrypted ws:// WebSocket URLs are not allowed unless allowInsecure is true");
|
|
47
|
+
}
|
|
35
48
|
this.ws = new WebSocket(url, protocols);
|
|
36
49
|
this.ws.onopen = () => this.emit("open");
|
|
37
50
|
this.ws.onclose = () => this.emit("close");
|
|
@@ -41,7 +54,7 @@ export class WebSocketTransport extends Emitter {
|
|
|
41
54
|
};
|
|
42
55
|
this.ws.onmessage = (ev) => {
|
|
43
56
|
try {
|
|
44
|
-
const msg = decodeMessage(String(ev.data));
|
|
57
|
+
const msg = decodeMessage(String(ev.data), { maxSize: 4 * 1024 * 1024 });
|
|
45
58
|
this.emit("message", msg);
|
|
46
59
|
}
|
|
47
60
|
catch (err) {
|
|
@@ -108,6 +121,18 @@ export class HttpSseTransport extends Emitter {
|
|
|
108
121
|
* Separated from the constructor so callers can register listeners first.
|
|
109
122
|
*/
|
|
110
123
|
connectSSE(lastEventId) {
|
|
124
|
+
this.eventSource?.close();
|
|
125
|
+
this.eventSource = null;
|
|
126
|
+
this.setupEventSource(lastEventId);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Reconnect the SSE stream with the current authorization/session state.
|
|
130
|
+
* Useful after calling setAuthorization.
|
|
131
|
+
*/
|
|
132
|
+
reconnectSSE(lastEventId) {
|
|
133
|
+
this.connectSSE(lastEventId);
|
|
134
|
+
}
|
|
135
|
+
setupEventSource(lastEventId) {
|
|
111
136
|
// Build the SSE URL with session_id (required for tenant routing)
|
|
112
137
|
// and optional lastEventId for event replay.
|
|
113
138
|
let url = this.eventsUrl;
|
|
@@ -129,7 +154,7 @@ export class HttpSseTransport extends Emitter {
|
|
|
129
154
|
// WMP events use the "wmp" event type per the spec.
|
|
130
155
|
this.eventSource.addEventListener("wmp", (ev) => {
|
|
131
156
|
try {
|
|
132
|
-
const msg = decodeMessage(ev.data);
|
|
157
|
+
const msg = decodeMessage(ev.data, { maxSize: 4 * 1024 * 1024 });
|
|
133
158
|
this.emit("message", msg);
|
|
134
159
|
}
|
|
135
160
|
catch (err) {
|
|
@@ -139,7 +164,7 @@ export class HttpSseTransport extends Emitter {
|
|
|
139
164
|
// Also handle default "message" events for compatibility.
|
|
140
165
|
this.eventSource.onmessage = (ev) => {
|
|
141
166
|
try {
|
|
142
|
-
const msg = decodeMessage(ev.data);
|
|
167
|
+
const msg = decodeMessage(ev.data, { maxSize: 4 * 1024 * 1024 });
|
|
143
168
|
this.emit("message", msg);
|
|
144
169
|
}
|
|
145
170
|
catch (err) {
|
package/dist/types.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface Metadata {
|
|
|
15
15
|
identity_assertions?: IdentityAssertion[];
|
|
16
16
|
relay_chain?: RelayEntry[];
|
|
17
17
|
trace_id?: string;
|
|
18
|
+
sender_delegate?: SenderDelegate;
|
|
19
|
+
deliver_after?: string;
|
|
18
20
|
}
|
|
19
21
|
export interface IdentityAssertion {
|
|
20
22
|
type: string;
|
|
@@ -44,6 +46,17 @@ export interface RelayEntry {
|
|
|
44
46
|
signature?: string;
|
|
45
47
|
service_class?: string;
|
|
46
48
|
}
|
|
49
|
+
export interface SenderDelegate {
|
|
50
|
+
id: string;
|
|
51
|
+
identity_assertions?: IdentityAssertion[];
|
|
52
|
+
authorization?: DelegateAuthorization;
|
|
53
|
+
}
|
|
54
|
+
export interface DelegateAuthorization {
|
|
55
|
+
type: string;
|
|
56
|
+
credential?: string;
|
|
57
|
+
scope?: string[];
|
|
58
|
+
valid_until?: string;
|
|
59
|
+
}
|
|
47
60
|
export interface SecurityMode {
|
|
48
61
|
mode: string;
|
|
49
62
|
min_tls_version?: string;
|
|
@@ -70,6 +83,7 @@ export declare const Method: {
|
|
|
70
83
|
readonly FlowComplete: "wmp.flow.complete";
|
|
71
84
|
readonly FlowError: "wmp.flow.error";
|
|
72
85
|
readonly FlowCancel: "wmp.flow.cancel";
|
|
86
|
+
readonly CredentialNotification: "wmp.credential.notification";
|
|
73
87
|
readonly Resolve: "wmp.resolve";
|
|
74
88
|
readonly RelayRegister: "wmp.relay.register";
|
|
75
89
|
};
|
|
@@ -95,12 +109,31 @@ export declare const ErrorCode: {
|
|
|
95
109
|
readonly IdentityAssertionInvalid: -31012;
|
|
96
110
|
readonly VersionNotSupported: -31013;
|
|
97
111
|
readonly QueueFull: -31014;
|
|
112
|
+
readonly DelegationInvalid: -31015;
|
|
113
|
+
readonly ConsignmentModeUnsupported: -31016;
|
|
114
|
+
readonly AssuranceLevelUnsupported: -31017;
|
|
115
|
+
readonly PolicyUnsupported: -31018;
|
|
98
116
|
};
|
|
99
117
|
export interface AuthObject {
|
|
100
118
|
type: string;
|
|
101
119
|
token?: string;
|
|
120
|
+
proof?: string;
|
|
121
|
+
challenge?: string;
|
|
122
|
+
signature?: string;
|
|
123
|
+
x5c?: string[];
|
|
124
|
+
did_auth?: unknown;
|
|
102
125
|
[key: string]: unknown;
|
|
103
126
|
}
|
|
127
|
+
/** Authentication type constants. */
|
|
128
|
+
export declare const AuthType: {
|
|
129
|
+
readonly Bearer: "bearer";
|
|
130
|
+
readonly DPoP: "dpop";
|
|
131
|
+
readonly MTLS: "mtls";
|
|
132
|
+
readonly SignedChallenge: "signed_challenge";
|
|
133
|
+
readonly X5C: "x5c";
|
|
134
|
+
/** @deprecated Use SignedChallenge instead. */
|
|
135
|
+
readonly DIDAuth: "did_auth";
|
|
136
|
+
};
|
|
104
137
|
export interface SessionCreateParams {
|
|
105
138
|
wmp: Metadata;
|
|
106
139
|
participants?: string[];
|
|
@@ -108,17 +141,28 @@ export interface SessionCreateParams {
|
|
|
108
141
|
security: SecurityMode;
|
|
109
142
|
ttl?: number;
|
|
110
143
|
auth?: AuthObject;
|
|
144
|
+
invitation_nonce?: string;
|
|
111
145
|
}
|
|
112
146
|
export interface SessionCreateResult {
|
|
113
147
|
wmp: Metadata;
|
|
114
148
|
capabilities?: Capabilities;
|
|
115
149
|
security: SecurityMode;
|
|
116
150
|
challenge?: string;
|
|
151
|
+
resumption_token?: string;
|
|
117
152
|
}
|
|
118
153
|
export interface SessionResumeParams {
|
|
119
154
|
wmp: Metadata;
|
|
120
155
|
session_id: string;
|
|
121
|
-
|
|
156
|
+
resumption_token: string;
|
|
157
|
+
last_received_id?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface SessionResumeResult {
|
|
160
|
+
wmp: Metadata;
|
|
161
|
+
resumed: boolean;
|
|
162
|
+
resumption_token?: string;
|
|
163
|
+
missed_messages: number;
|
|
164
|
+
capabilities?: Capabilities;
|
|
165
|
+
security: SecurityMode;
|
|
122
166
|
}
|
|
123
167
|
export interface SessionCloseParams {
|
|
124
168
|
wmp: Metadata;
|
|
@@ -126,14 +170,12 @@ export interface SessionCloseParams {
|
|
|
126
170
|
}
|
|
127
171
|
export interface SessionAuthenticateParams {
|
|
128
172
|
wmp: Metadata;
|
|
129
|
-
|
|
130
|
-
token?: string;
|
|
131
|
-
response?: string;
|
|
132
|
-
[key: string]: unknown;
|
|
173
|
+
auth: AuthObject;
|
|
133
174
|
}
|
|
134
175
|
export interface SessionAuthenticateResult {
|
|
135
176
|
wmp: Metadata;
|
|
136
177
|
authenticated: boolean;
|
|
178
|
+
identity?: string;
|
|
137
179
|
}
|
|
138
180
|
export declare const CloseReason: {
|
|
139
181
|
readonly Complete: "complete";
|
|
@@ -147,6 +189,12 @@ export interface MessageDeliverParams {
|
|
|
147
189
|
content_type?: string;
|
|
148
190
|
body?: unknown;
|
|
149
191
|
ciphertext?: string;
|
|
192
|
+
reply_to?: string;
|
|
193
|
+
in_reply_to?: string;
|
|
194
|
+
message_type?: string;
|
|
195
|
+
consignment_mode?: string;
|
|
196
|
+
recipient_assurance_level?: string;
|
|
197
|
+
applicable_policies?: string[];
|
|
150
198
|
}
|
|
151
199
|
export interface MessageAckParams {
|
|
152
200
|
wmp: Metadata;
|
|
@@ -174,6 +222,16 @@ export declare const AckStatus: {
|
|
|
174
222
|
readonly Processed: "processed";
|
|
175
223
|
readonly Failed: "failed";
|
|
176
224
|
};
|
|
225
|
+
export declare const ConsignmentMode: {
|
|
226
|
+
readonly Basic: "basic";
|
|
227
|
+
readonly Consented: "consented";
|
|
228
|
+
readonly ConsentedSigned: "consented_signed";
|
|
229
|
+
};
|
|
230
|
+
export declare const AssuranceLevel: {
|
|
231
|
+
readonly Low: "low";
|
|
232
|
+
readonly Substantial: "substantial";
|
|
233
|
+
readonly High: "high";
|
|
234
|
+
};
|
|
177
235
|
export interface CapabilityUpdateParams {
|
|
178
236
|
wmp: Metadata;
|
|
179
237
|
add?: Capabilities;
|
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
|
};
|
|
@@ -49,6 +50,20 @@ export const ErrorCode = {
|
|
|
49
50
|
IdentityAssertionInvalid: -31012,
|
|
50
51
|
VersionNotSupported: -31013,
|
|
51
52
|
QueueFull: -31014,
|
|
53
|
+
DelegationInvalid: -31015,
|
|
54
|
+
ConsignmentModeUnsupported: -31016,
|
|
55
|
+
AssuranceLevelUnsupported: -31017,
|
|
56
|
+
PolicyUnsupported: -31018,
|
|
57
|
+
};
|
|
58
|
+
/** Authentication type constants. */
|
|
59
|
+
export const AuthType = {
|
|
60
|
+
Bearer: "bearer",
|
|
61
|
+
DPoP: "dpop",
|
|
62
|
+
MTLS: "mtls",
|
|
63
|
+
SignedChallenge: "signed_challenge",
|
|
64
|
+
X5C: "x5c",
|
|
65
|
+
/** @deprecated Use SignedChallenge instead. */
|
|
66
|
+
DIDAuth: "did_auth",
|
|
52
67
|
};
|
|
53
68
|
// Close reason constants.
|
|
54
69
|
export const CloseReason = {
|
|
@@ -63,6 +78,16 @@ export const AckStatus = {
|
|
|
63
78
|
Processed: "processed",
|
|
64
79
|
Failed: "failed",
|
|
65
80
|
};
|
|
81
|
+
export const ConsignmentMode = {
|
|
82
|
+
Basic: "basic",
|
|
83
|
+
Consented: "consented",
|
|
84
|
+
ConsentedSigned: "consented_signed",
|
|
85
|
+
};
|
|
86
|
+
export const AssuranceLevel = {
|
|
87
|
+
Low: "low",
|
|
88
|
+
Substantial: "substantial",
|
|
89
|
+
High: "high",
|
|
90
|
+
};
|
|
66
91
|
export const FlowType = {
|
|
67
92
|
Approval: "approval",
|
|
68
93
|
Sign: "sign",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sirosfoundation/wmp-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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": {
|
|
@@ -35,7 +36,10 @@
|
|
|
35
36
|
"url": "https://github.com/sirosfoundation/wmp-js.git"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
39
|
+
"@noble/curves": "^2.0.1",
|
|
40
|
+
"@noble/hashes": "^2.2.0",
|
|
38
41
|
"ajv": "^8.20.0",
|
|
39
|
-
"ajv-formats": "^3.0.1"
|
|
42
|
+
"ajv-formats": "^3.0.1",
|
|
43
|
+
"ts-mls": "^1.6.2"
|
|
40
44
|
}
|
|
41
45
|
}
|