@irtio/protocol 0.1.0 → 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/dist/index.d.ts +39 -0
- package/dist/index.js +17 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,34 @@ declare const ErrorCode: {
|
|
|
128
128
|
readonly code: 20;
|
|
129
129
|
readonly message: "client cannot keep up with the stream; reconnect for a fresh snapshot";
|
|
130
130
|
};
|
|
131
|
+
readonly E_TOKEN_EXPIRED: {
|
|
132
|
+
readonly code: 21;
|
|
133
|
+
readonly message: "auth token expired";
|
|
134
|
+
};
|
|
135
|
+
readonly E_TOKEN_INVALID: {
|
|
136
|
+
readonly code: 22;
|
|
137
|
+
readonly message: "auth token signature is invalid";
|
|
138
|
+
};
|
|
139
|
+
readonly E_TOKEN_WRONG_PROJECT: {
|
|
140
|
+
readonly code: 23;
|
|
141
|
+
readonly message: "auth token is for another project";
|
|
142
|
+
};
|
|
143
|
+
readonly E_TOKEN_WRONG_ROOM: {
|
|
144
|
+
readonly code: 24;
|
|
145
|
+
readonly message: "auth token is for another room";
|
|
146
|
+
};
|
|
147
|
+
readonly E_TOKEN_MALFORMED: {
|
|
148
|
+
readonly code: 25;
|
|
149
|
+
readonly message: "auth token is malformed: {reason}";
|
|
150
|
+
};
|
|
151
|
+
readonly E_TOKEN_BAD_ISSUER: {
|
|
152
|
+
readonly code: 26;
|
|
153
|
+
readonly message: "auth token issuer {issuer} is not accepted";
|
|
154
|
+
};
|
|
155
|
+
readonly E_TOKEN_BAD_ALG: {
|
|
156
|
+
readonly code: 27;
|
|
157
|
+
readonly message: "auth token algorithm {alg} is not allowed";
|
|
158
|
+
};
|
|
131
159
|
};
|
|
132
160
|
type ErrorCodeName = keyof typeof ErrorCode;
|
|
133
161
|
interface ErrorCatalogueEntry {
|
|
@@ -153,6 +181,17 @@ type Credential = {
|
|
|
153
181
|
} | {
|
|
154
182
|
readonly kind: 'token';
|
|
155
183
|
readonly token: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Week 13 (D27): the project key AND a JWT. The key stays because the router routes on it —
|
|
187
|
+
* a HELLO carrying only a token has nothing to resolve a tenant from — and the token is
|
|
188
|
+
* verified in the guest supervisor (HS256, per-project secret), never by the router. Wire tag
|
|
189
|
+
* 2; the unused tag 1 (`token`) keeps its meaning of months rather than being repurposed.
|
|
190
|
+
*/
|
|
191
|
+
| {
|
|
192
|
+
readonly kind: 'jwt';
|
|
193
|
+
readonly key: string;
|
|
194
|
+
readonly token: string;
|
|
156
195
|
};
|
|
157
196
|
interface Hello {
|
|
158
197
|
readonly protocolVersion: number;
|
package/dist/index.js
CHANGED
|
@@ -64,7 +64,17 @@ var ErrorCode = {
|
|
|
64
64
|
E_SLOW_CONSUMER: {
|
|
65
65
|
code: 20,
|
|
66
66
|
message: "client cannot keep up with the stream; reconnect for a fresh snapshot"
|
|
67
|
-
}
|
|
67
|
+
},
|
|
68
|
+
// Week 13 (D27): every JWT refusal has a name. `E_AUTH` stays the generic ("no secret
|
|
69
|
+
// configured", "wrong project key"); these say WHICH refusal a token hit, because week 12's
|
|
70
|
+
// staging sessions were survivable precisely because refusals said which they were.
|
|
71
|
+
E_TOKEN_EXPIRED: { code: 21, message: "auth token expired" },
|
|
72
|
+
E_TOKEN_INVALID: { code: 22, message: "auth token signature is invalid" },
|
|
73
|
+
E_TOKEN_WRONG_PROJECT: { code: 23, message: "auth token is for another project" },
|
|
74
|
+
E_TOKEN_WRONG_ROOM: { code: 24, message: "auth token is for another room" },
|
|
75
|
+
E_TOKEN_MALFORMED: { code: 25, message: "auth token is malformed: {reason}" },
|
|
76
|
+
E_TOKEN_BAD_ISSUER: { code: 26, message: "auth token issuer {issuer} is not accepted" },
|
|
77
|
+
E_TOKEN_BAD_ALG: { code: 27, message: "auth token algorithm {alg} is not allowed" }
|
|
68
78
|
};
|
|
69
79
|
var ERROR_CATALOGUE = Object.keys(ErrorCode).map((name) => ({ name, code: ErrorCode[name].code, message: ErrorCode[name].message }));
|
|
70
80
|
var BY_CODE = new Map(
|
|
@@ -100,9 +110,13 @@ function encodeHello(h) {
|
|
|
100
110
|
if (h.credential.kind === "key") {
|
|
101
111
|
w.u8(0);
|
|
102
112
|
w.str(h.credential.key);
|
|
103
|
-
} else {
|
|
113
|
+
} else if (h.credential.kind === "token") {
|
|
104
114
|
w.u8(1);
|
|
105
115
|
w.str(h.credential.token);
|
|
116
|
+
} else {
|
|
117
|
+
w.u8(2);
|
|
118
|
+
w.str(h.credential.key);
|
|
119
|
+
w.str(h.credential.token);
|
|
106
120
|
}
|
|
107
121
|
w.str(h.roomId);
|
|
108
122
|
w.bytes(h.schemaHash8);
|
|
@@ -123,6 +137,7 @@ function decodeHello(bytes) {
|
|
|
123
137
|
let credential;
|
|
124
138
|
if (credKind === 0) credential = { kind: "key", key: r.str() };
|
|
125
139
|
else if (credKind === 1) credential = { kind: "token", token: r.str() };
|
|
140
|
+
else if (credKind === 2) credential = { kind: "jwt", key: r.str(), token: r.str() };
|
|
126
141
|
else throw new Error(`decodeHello: unknown credential kind ${credKind}`);
|
|
127
142
|
const roomId = r.str();
|
|
128
143
|
const schemaHash8 = r.bytes(8);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irtio/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "irtio wire protocol: frames, framing, session payloads, error codes, built-in presence",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@irtio/schema": "0.
|
|
23
|
+
"@irtio/schema": "0.2.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsup",
|