@gryt/core 0.13.0 → 0.15.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 +18 -3
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -0
- package/dist/mls/deliveryService.fake.d.ts +96 -0
- package/dist/mls/deliveryService.fake.js +413 -0
- package/dist/mls/dmDriver.d.ts +1 -1
- package/dist/mls/dmDriver.js +222 -2
- package/dist/mls/interfaces.d.ts +54 -3
- package/dist/pairing/approver.d.ts +71 -0
- package/dist/pairing/approver.js +198 -0
- package/dist/pairing/channel.d.ts +17 -0
- package/dist/pairing/channel.js +81 -0
- package/dist/pairing/interfaces.d.ts +87 -0
- package/dist/pairing/interfaces.js +1 -0
- package/dist/pairing/newDevice.d.ts +62 -0
- package/dist/pairing/newDevice.js +209 -0
- package/dist/pairing/relayClient.d.ts +45 -0
- package/dist/pairing/relayClient.js +48 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +3 -0
- package/package.json +7 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PairingFetch } from "./interfaces.js";
|
|
2
|
+
/** A refusal from the relay: its status and the `error` it sent, or "network" when nothing came back. */
|
|
3
|
+
export declare class PairingRelayError extends Error {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly code: string;
|
|
6
|
+
constructor(status: number, code: string);
|
|
7
|
+
}
|
|
8
|
+
export interface RelayMessage {
|
|
9
|
+
seq: number;
|
|
10
|
+
type: "claim" | "reveal" | "sealed";
|
|
11
|
+
pkA?: string;
|
|
12
|
+
pkN?: string;
|
|
13
|
+
body?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PairingRelay {
|
|
16
|
+
create(commit: string): Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
code: string;
|
|
19
|
+
token: string;
|
|
20
|
+
expiresAt: string;
|
|
21
|
+
}>;
|
|
22
|
+
claim(by: {
|
|
23
|
+
id: string;
|
|
24
|
+
} | {
|
|
25
|
+
code: string;
|
|
26
|
+
}, pkA: string): Promise<{
|
|
27
|
+
id: string;
|
|
28
|
+
token: string;
|
|
29
|
+
commit: string;
|
|
30
|
+
location: string | null;
|
|
31
|
+
yourLocation: string | null;
|
|
32
|
+
}>;
|
|
33
|
+
post(id: string, token: string, message: {
|
|
34
|
+
type: "reveal";
|
|
35
|
+
pkN: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: "sealed";
|
|
38
|
+
body: string;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
/** The other side's messages after `after`, waiting up to `waitSeconds`. Asking past one acks it. */
|
|
41
|
+
poll(id: string, token: string, after: number, waitSeconds: number, signal?: AbortSignal): Promise<RelayMessage[]>;
|
|
42
|
+
close(id: string, token: string): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
/** The relay's HTTP API as auth#45 built it, under `{origin}/api/v1/pairing`. */
|
|
45
|
+
export declare function createPairingRelay(origin: string, fetch: PairingFetch): PairingRelay;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** A refusal from the relay: its status and the `error` it sent, or "network" when nothing came back. */
|
|
2
|
+
export class PairingRelayError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
code;
|
|
5
|
+
constructor(status, code) {
|
|
6
|
+
super(`Pairing relay: ${status} ${code}`);
|
|
7
|
+
this.name = "PairingRelayError";
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** The relay's HTTP API as auth#45 built it, under `{origin}/api/v1/pairing`. */
|
|
13
|
+
export function createPairingRelay(origin, fetch) {
|
|
14
|
+
const base = `${origin.replace(/\/+$/, "")}/api/v1/pairing/sessions`;
|
|
15
|
+
async function call(method, path, body, token, signal) {
|
|
16
|
+
const headers = {};
|
|
17
|
+
if (body !== undefined)
|
|
18
|
+
headers["content-type"] = "application/json";
|
|
19
|
+
if (token)
|
|
20
|
+
headers.authorization = `Bearer ${token}`;
|
|
21
|
+
let res;
|
|
22
|
+
try {
|
|
23
|
+
res = await fetch(`${base}${path}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body), signal });
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
if (signal?.aborted)
|
|
27
|
+
throw e;
|
|
28
|
+
throw new PairingRelayError(0, "network");
|
|
29
|
+
}
|
|
30
|
+
if (res.status === 204)
|
|
31
|
+
return {};
|
|
32
|
+
const json = (await res.json().catch(() => null));
|
|
33
|
+
if (res.status >= 400 || !json)
|
|
34
|
+
throw new PairingRelayError(res.status, String(json?.error ?? "unknown"));
|
|
35
|
+
return json;
|
|
36
|
+
}
|
|
37
|
+
const path = (id) => `/${encodeURIComponent(id)}`;
|
|
38
|
+
return {
|
|
39
|
+
create: async (commit) => (await call("POST", "", { commit })),
|
|
40
|
+
claim: async (by, pkA) => (await call("POST", "/claim", { ...by, pkA })),
|
|
41
|
+
post: async (id, token, message) => void (await call("POST", `${path(id)}/messages`, message, token)),
|
|
42
|
+
poll: async (id, token, after, waitSeconds, signal) => {
|
|
43
|
+
const res = await call("GET", `${path(id)}/messages?after=${after}&wait=${waitSeconds}`, undefined, token, signal);
|
|
44
|
+
return (Array.isArray(res.messages) ? res.messages : []);
|
|
45
|
+
},
|
|
46
|
+
close: async (id, token) => void (await call("DELETE", path(id), undefined, token)),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FakeDeliveryService, MemoryMlsStore } from "./mls/deliveryService.fake.js";
|
package/dist/testing.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gryt/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Gryt's shared application logic: one implementation of the things the desktop and mobile apps both do.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./testing": {
|
|
19
|
+
"types": "./dist/testing.d.ts",
|
|
20
|
+
"default": "./dist/testing.js"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
@@ -35,6 +39,7 @@
|
|
|
35
39
|
"access": "public"
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
|
-
"@gryt/crypto": "0.
|
|
42
|
+
"@gryt/crypto": "0.9.0",
|
|
43
|
+
"@noble/hashes": "^2.3.0"
|
|
39
44
|
}
|
|
40
45
|
}
|