@ping-app/ping-openmls-sdk 0.0.0-stage → 0.10.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 +94 -2
- package/dist/index.cjs +2782 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1229 -0
- package/dist/index.d.ts +1229 -0
- package/dist/index.js +2715 -0
- package/dist/index.js.map +1 -0
- package/dist/notification-preview.cjs +137 -0
- package/dist/notification-preview.cjs.map +1 -0
- package/dist/notification-preview.d.cts +85 -0
- package/dist/notification-preview.d.ts +85 -0
- package/dist/notification-preview.js +98 -0
- package/dist/notification-preview.js.map +1 -0
- package/dist/storage/indexeddb.cjs +153 -0
- package/dist/storage/indexeddb.cjs.map +1 -0
- package/dist/storage/indexeddb.d.cts +21 -0
- package/dist/storage/indexeddb.d.ts +21 -0
- package/dist/storage/indexeddb.js +128 -0
- package/dist/storage/indexeddb.js.map +1 -0
- package/dist/transport/websocket.cjs +121 -0
- package/dist/transport/websocket.cjs.map +1 -0
- package/dist/transport/websocket.d.cts +23 -0
- package/dist/transport/websocket.d.ts +23 -0
- package/dist/transport/websocket.js +94 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types-B1GFwNXa.d.cts +535 -0
- package/dist/types-B1GFwNXa.d.ts +535 -0
- package/dist/worker.cjs +841 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +2 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +848 -0
- package/dist/worker.js.map +1 -0
- package/package.json +61 -4
- package/wasm/package.json +17 -0
- package/wasm/ping_wasm.d.ts +909 -0
- package/wasm/ping_wasm.js +3028 -0
- package/wasm/ping_wasm_bg.wasm +0 -0
- package/wasm/ping_wasm_bg.wasm.d.ts +112 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { S as Storage } from '../types-B1GFwNXa.cjs';
|
|
2
|
+
|
|
3
|
+
declare class IndexedDbStorage implements Storage {
|
|
4
|
+
private dbPromise;
|
|
5
|
+
constructor();
|
|
6
|
+
get(namespace: string, key: string): Promise<Uint8Array | null>;
|
|
7
|
+
put(namespace: string, key: string, value: Uint8Array): Promise<void>;
|
|
8
|
+
del(namespace: string, key: string): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* One `readwrite` transaction for the whole batch. Every request is issued
|
|
11
|
+
* synchronously inside it (an await on anything else would let the
|
|
12
|
+
* transaction auto-commit), so a failure or a crash mid-way aborts all of
|
|
13
|
+
* it: the per-row MLS store relies on that to keep a checkpoint atomic.
|
|
14
|
+
*/
|
|
15
|
+
applyBatch(namespace: string, puts: Array<[key: string, value: Uint8Array]>, deletes: string[]): Promise<void>;
|
|
16
|
+
/** Every `[key, value]` under `namespace` with the prefix, in one read. */
|
|
17
|
+
listEntries(namespace: string, prefix: string): Promise<Array<[key: string, value: Uint8Array]>>;
|
|
18
|
+
listKeys(namespace: string, prefix: string): Promise<string[]>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { IndexedDbStorage };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { S as Storage } from '../types-B1GFwNXa.js';
|
|
2
|
+
|
|
3
|
+
declare class IndexedDbStorage implements Storage {
|
|
4
|
+
private dbPromise;
|
|
5
|
+
constructor();
|
|
6
|
+
get(namespace: string, key: string): Promise<Uint8Array | null>;
|
|
7
|
+
put(namespace: string, key: string, value: Uint8Array): Promise<void>;
|
|
8
|
+
del(namespace: string, key: string): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* One `readwrite` transaction for the whole batch. Every request is issued
|
|
11
|
+
* synchronously inside it (an await on anything else would let the
|
|
12
|
+
* transaction auto-commit), so a failure or a crash mid-way aborts all of
|
|
13
|
+
* it: the per-row MLS store relies on that to keep a checkpoint atomic.
|
|
14
|
+
*/
|
|
15
|
+
applyBatch(namespace: string, puts: Array<[key: string, value: Uint8Array]>, deletes: string[]): Promise<void>;
|
|
16
|
+
/** Every `[key, value]` under `namespace` with the prefix, in one read. */
|
|
17
|
+
listEntries(namespace: string, prefix: string): Promise<Array<[key: string, value: Uint8Array]>>;
|
|
18
|
+
listKeys(namespace: string, prefix: string): Promise<string[]>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { IndexedDbStorage };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// src/storage/indexeddb.ts
|
|
2
|
+
var DB_NAME = "ping-sdk";
|
|
3
|
+
var DB_VERSION = 1;
|
|
4
|
+
var STORE = "kv";
|
|
5
|
+
function open() {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const req = indexedDB.open(DB_NAME, DB_VERSION);
|
|
8
|
+
req.onupgradeneeded = () => {
|
|
9
|
+
const db = req.result;
|
|
10
|
+
if (!db.objectStoreNames.contains(STORE)) {
|
|
11
|
+
const os = db.createObjectStore(STORE, { keyPath: ["ns", "key"] });
|
|
12
|
+
os.createIndex("ns", "ns", { unique: false });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
req.onsuccess = () => resolve(req.result);
|
|
16
|
+
req.onerror = () => reject(req.error);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
var IndexedDbStorage = class {
|
|
20
|
+
dbPromise;
|
|
21
|
+
constructor() {
|
|
22
|
+
this.dbPromise = open();
|
|
23
|
+
}
|
|
24
|
+
async get(namespace, key) {
|
|
25
|
+
const db = await this.dbPromise;
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const tx = db.transaction(STORE, "readonly");
|
|
28
|
+
const r = tx.objectStore(STORE).get([namespace, key]);
|
|
29
|
+
r.onsuccess = () => resolve(r.result?.value ?? null);
|
|
30
|
+
r.onerror = () => reject(r.error);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async put(namespace, key, value) {
|
|
34
|
+
const db = await this.dbPromise;
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
37
|
+
tx.objectStore(STORE).put({ ns: namespace, key, value });
|
|
38
|
+
tx.oncomplete = () => resolve();
|
|
39
|
+
tx.onerror = () => reject(tx.error);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async del(namespace, key) {
|
|
43
|
+
const db = await this.dbPromise;
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
46
|
+
tx.objectStore(STORE).delete([namespace, key]);
|
|
47
|
+
tx.oncomplete = () => resolve();
|
|
48
|
+
tx.onerror = () => reject(tx.error);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One `readwrite` transaction for the whole batch. Every request is issued
|
|
53
|
+
* synchronously inside it (an await on anything else would let the
|
|
54
|
+
* transaction auto-commit), so a failure or a crash mid-way aborts all of
|
|
55
|
+
* it: the per-row MLS store relies on that to keep a checkpoint atomic.
|
|
56
|
+
*/
|
|
57
|
+
async applyBatch(namespace, puts, deletes) {
|
|
58
|
+
if (puts.length === 0 && deletes.length === 0) return;
|
|
59
|
+
const db = await this.dbPromise;
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
62
|
+
let settled = false;
|
|
63
|
+
const fail = (e) => {
|
|
64
|
+
if (settled) return;
|
|
65
|
+
settled = true;
|
|
66
|
+
reject(e instanceof Error ? e : new Error(String(e)));
|
|
67
|
+
};
|
|
68
|
+
tx.oncomplete = () => {
|
|
69
|
+
if (!settled) {
|
|
70
|
+
settled = true;
|
|
71
|
+
resolve();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
tx.onerror = () => fail(tx.error);
|
|
75
|
+
tx.onabort = () => fail(tx.error ?? new Error("applyBatch aborted"));
|
|
76
|
+
try {
|
|
77
|
+
const os = tx.objectStore(STORE);
|
|
78
|
+
for (const [key, value] of puts) os.put({ ns: namespace, key, value });
|
|
79
|
+
for (const key of deletes) os.delete([namespace, key]);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
try {
|
|
82
|
+
tx.abort();
|
|
83
|
+
} catch {
|
|
84
|
+
}
|
|
85
|
+
fail(e);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Every `[key, value]` under `namespace` with the prefix, in one read. */
|
|
90
|
+
async listEntries(namespace, prefix) {
|
|
91
|
+
const db = await this.dbPromise;
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const tx = db.transaction(STORE, "readonly");
|
|
94
|
+
const idx = tx.objectStore(STORE).index("ns");
|
|
95
|
+
const req = idx.openCursor(IDBKeyRange.only(namespace));
|
|
96
|
+
const out = [];
|
|
97
|
+
req.onsuccess = () => {
|
|
98
|
+
const cur = req.result;
|
|
99
|
+
if (!cur) return resolve(out);
|
|
100
|
+
const row = cur.value;
|
|
101
|
+
if (!prefix || row.key.startsWith(prefix)) out.push([row.key, row.value]);
|
|
102
|
+
cur.continue();
|
|
103
|
+
};
|
|
104
|
+
req.onerror = () => reject(req.error);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async listKeys(namespace, prefix) {
|
|
108
|
+
const db = await this.dbPromise;
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const tx = db.transaction(STORE, "readonly");
|
|
111
|
+
const idx = tx.objectStore(STORE).index("ns");
|
|
112
|
+
const req = idx.openCursor(IDBKeyRange.only(namespace));
|
|
113
|
+
const out = [];
|
|
114
|
+
req.onsuccess = () => {
|
|
115
|
+
const cur = req.result;
|
|
116
|
+
if (!cur) return resolve(out);
|
|
117
|
+
const row = cur.value;
|
|
118
|
+
if (!prefix || row.key.startsWith(prefix)) out.push(row.key);
|
|
119
|
+
cur.continue();
|
|
120
|
+
};
|
|
121
|
+
req.onerror = () => reject(req.error);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export {
|
|
126
|
+
IndexedDbStorage
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=indexeddb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/storage/indexeddb.ts"],"sourcesContent":["// Default IndexedDB-backed Storage implementation. Hosts can supply their own.\n\nimport type { Storage } from \"../types\";\n\nconst DB_NAME = \"ping-sdk\";\nconst DB_VERSION = 1;\nconst STORE = \"kv\";\n\ninterface Row { ns: string; key: string; value: Uint8Array }\n\nfunction open(): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n const req = indexedDB.open(DB_NAME, DB_VERSION);\n req.onupgradeneeded = () => {\n const db = req.result;\n if (!db.objectStoreNames.contains(STORE)) {\n const os = db.createObjectStore(STORE, { keyPath: [\"ns\", \"key\"] });\n os.createIndex(\"ns\", \"ns\", { unique: false });\n }\n };\n req.onsuccess = () => resolve(req.result);\n req.onerror = () => reject(req.error);\n });\n}\n\nexport class IndexedDbStorage implements Storage {\n private dbPromise: Promise<IDBDatabase>;\n\n constructor() { this.dbPromise = open(); }\n\n async get(namespace: string, key: string): Promise<Uint8Array | null> {\n const db = await this.dbPromise;\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE, \"readonly\");\n const r = tx.objectStore(STORE).get([namespace, key]);\n r.onsuccess = () => resolve(((r.result as Row | undefined)?.value) ?? null);\n r.onerror = () => reject(r.error);\n });\n }\n\n async put(namespace: string, key: string, value: Uint8Array): Promise<void> {\n const db = await this.dbPromise;\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).put({ ns: namespace, key, value } as Row);\n tx.oncomplete = () => resolve();\n tx.onerror = () => reject(tx.error);\n });\n }\n\n async del(namespace: string, key: string): Promise<void> {\n const db = await this.dbPromise;\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE, \"readwrite\");\n tx.objectStore(STORE).delete([namespace, key]);\n tx.oncomplete = () => resolve();\n tx.onerror = () => reject(tx.error);\n });\n }\n\n /**\n * One `readwrite` transaction for the whole batch. Every request is issued\n * synchronously inside it (an await on anything else would let the\n * transaction auto-commit), so a failure or a crash mid-way aborts all of\n * it: the per-row MLS store relies on that to keep a checkpoint atomic.\n */\n async applyBatch(\n namespace: string,\n puts: Array<[key: string, value: Uint8Array]>,\n deletes: string[],\n ): Promise<void> {\n if (puts.length === 0 && deletes.length === 0) return;\n const db = await this.dbPromise;\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE, \"readwrite\");\n let settled = false;\n const fail = (e: unknown) => {\n if (settled) return;\n settled = true;\n reject(e instanceof Error ? e : new Error(String(e)));\n };\n tx.oncomplete = () => {\n if (!settled) {\n settled = true;\n resolve();\n }\n };\n tx.onerror = () => fail(tx.error);\n tx.onabort = () => fail(tx.error ?? new Error(\"applyBatch aborted\"));\n try {\n const os = tx.objectStore(STORE);\n for (const [key, value] of puts) os.put({ ns: namespace, key, value } as Row);\n for (const key of deletes) os.delete([namespace, key]);\n } catch (e) {\n // A request that throws synchronously (an unserialisable key) does\n // not abort the transaction on its own; the requests already issued\n // would commit. Abort explicitly so the batch stays all-or-nothing.\n try {\n tx.abort();\n } catch {\n // Already aborted or finished.\n }\n fail(e);\n }\n });\n }\n\n /** Every `[key, value]` under `namespace` with the prefix, in one read. */\n async listEntries(\n namespace: string,\n prefix: string,\n ): Promise<Array<[key: string, value: Uint8Array]>> {\n const db = await this.dbPromise;\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE, \"readonly\");\n const idx = tx.objectStore(STORE).index(\"ns\");\n const req = idx.openCursor(IDBKeyRange.only(namespace));\n const out: Array<[string, Uint8Array]> = [];\n req.onsuccess = () => {\n const cur = req.result;\n if (!cur) return resolve(out);\n const row = cur.value as Row;\n if (!prefix || row.key.startsWith(prefix)) out.push([row.key, row.value]);\n cur.continue();\n };\n req.onerror = () => reject(req.error);\n });\n }\n\n async listKeys(namespace: string, prefix: string): Promise<string[]> {\n const db = await this.dbPromise;\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE, \"readonly\");\n const idx = tx.objectStore(STORE).index(\"ns\");\n const req = idx.openCursor(IDBKeyRange.only(namespace));\n const out: string[] = [];\n req.onsuccess = () => {\n const cur = req.result;\n if (!cur) return resolve(out);\n const row = cur.value as Row;\n if (!prefix || row.key.startsWith(prefix)) out.push(row.key);\n cur.continue();\n };\n req.onerror = () => reject(req.error);\n });\n }\n}\n"],"mappings":";AAIA,IAAM,UAAU;AAChB,IAAM,aAAa;AACnB,IAAM,QAAQ;AAId,SAAS,OAA6B;AACpC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,MAAM,UAAU,KAAK,SAAS,UAAU;AAC9C,QAAI,kBAAkB,MAAM;AAC1B,YAAM,KAAK,IAAI;AACf,UAAI,CAAC,GAAG,iBAAiB,SAAS,KAAK,GAAG;AACxC,cAAM,KAAK,GAAG,kBAAkB,OAAO,EAAE,SAAS,CAAC,MAAM,KAAK,EAAE,CAAC;AACjE,WAAG,YAAY,MAAM,MAAM,EAAE,QAAQ,MAAM,CAAC;AAAA,MAC9C;AAAA,IACF;AACA,QAAI,YAAY,MAAM,QAAQ,IAAI,MAAM;AACxC,QAAI,UAAU,MAAM,OAAO,IAAI,KAAK;AAAA,EACtC,CAAC;AACH;AAEO,IAAM,mBAAN,MAA0C;AAAA,EACvC;AAAA,EAER,cAAc;AAAE,SAAK,YAAY,KAAK;AAAA,EAAG;AAAA,EAEzC,MAAM,IAAI,WAAmB,KAAyC;AACpE,UAAM,KAAK,MAAM,KAAK;AACtB,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAM,KAAK,GAAG,YAAY,OAAO,UAAU;AAC3C,YAAM,IAAI,GAAG,YAAY,KAAK,EAAE,IAAI,CAAC,WAAW,GAAG,CAAC;AACpD,QAAE,YAAY,MAAM,QAAU,EAAE,QAA4B,SAAU,IAAI;AAC1E,QAAE,UAAU,MAAM,OAAO,EAAE,KAAK;AAAA,IAClC,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,IAAI,WAAmB,KAAa,OAAkC;A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UAAI,YAAY,MAAM;AACpB,cAAM,MAAM,IAAI;AAChB,YAAI,CAAC,IAAK,QAAO,QAAQ,GAAG;AAC5B,cAAM,MAAM,IAAI;AAChB,YAAI,CAAC,UAAU,IAAI,IAAI,WAAW,MAAM,EAAG,KAAI,KAAK,IAAI,GAAG;AAC3D,YAAI,SAAS;AAAA,MACf;AACA,UAAI,UAAU,MAAM,OAAO,IAAI,KAAK;AAAA,IACtC,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/transport/websocket.ts
|
|
21
|
+
var websocket_exports = {};
|
|
22
|
+
__export(websocket_exports, {
|
|
23
|
+
WebSocketTransport: () => WebSocketTransport
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(websocket_exports);
|
|
26
|
+
|
|
27
|
+
// src/wire-contract.ts
|
|
28
|
+
var PING_WIRE_CONTRACT_VERSION = 2;
|
|
29
|
+
var CONTENT_TYPE_JSON = "application/vnd.ping.wire.v2+json";
|
|
30
|
+
var PING_WIRE_CONTRACT_HEADER = "X-Ping-Wire-Contract";
|
|
31
|
+
var PING_WIRE_CONTRACT_HEADER_VALUE = `ping/${PING_WIRE_CONTRACT_VERSION}`;
|
|
32
|
+
|
|
33
|
+
// src/transport/websocket.ts
|
|
34
|
+
var WebSocketTransport = class {
|
|
35
|
+
constructor(cfg) {
|
|
36
|
+
this.cfg = cfg;
|
|
37
|
+
this.fetchImpl = cfg.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
38
|
+
this.openSocket();
|
|
39
|
+
}
|
|
40
|
+
cfg;
|
|
41
|
+
ws = null;
|
|
42
|
+
liveHandlers = /* @__PURE__ */ new Set();
|
|
43
|
+
fetchImpl;
|
|
44
|
+
openSocket() {
|
|
45
|
+
if (typeof WebSocket === "undefined") return;
|
|
46
|
+
const url = `${this.cfg.baseUrl.replace(/^http/, "ws")}/stream`;
|
|
47
|
+
this.ws = new WebSocket(url);
|
|
48
|
+
this.ws.onmessage = (ev) => {
|
|
49
|
+
const text = typeof ev.data === "string" ? ev.data : new TextDecoder().decode(ev.data);
|
|
50
|
+
try {
|
|
51
|
+
const env = JSON.parse(text, reviver);
|
|
52
|
+
for (const h of this.liveHandlers) h(env);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (typeof console !== "undefined") console.debug("[ping-sdk] WS frame parse error:", e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.ws.onclose = () => setTimeout(() => this.openSocket(), 1e3);
|
|
58
|
+
}
|
|
59
|
+
async send(envelope) {
|
|
60
|
+
const res = await this.fetchImpl(`${this.cfg.baseUrl}/send`, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: {
|
|
63
|
+
"content-type": CONTENT_TYPE_JSON,
|
|
64
|
+
[PING_WIRE_CONTRACT_HEADER]: PING_WIRE_CONTRACT_HEADER_VALUE,
|
|
65
|
+
...this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify(envelope, replacer)
|
|
68
|
+
});
|
|
69
|
+
if (res.status === 409) throw new Error("EpochOccupied");
|
|
70
|
+
if (!res.ok) throw new Error(`transport send failed: ${res.status}`);
|
|
71
|
+
}
|
|
72
|
+
async fetchSince(conversationId, cursor, limit) {
|
|
73
|
+
const url = new URL(`${this.cfg.baseUrl}/sync`);
|
|
74
|
+
url.searchParams.set("conv", toHex(conversationId));
|
|
75
|
+
url.searchParams.set("cursor", btoaUrl(cursor));
|
|
76
|
+
url.searchParams.set("limit", String(limit));
|
|
77
|
+
const res = await this.fetchImpl(url.toString(), {
|
|
78
|
+
headers: { ...this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {} }
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) throw new Error(`transport fetch failed: ${res.status}`);
|
|
81
|
+
const text = await res.text();
|
|
82
|
+
return JSON.parse(text, reviver);
|
|
83
|
+
}
|
|
84
|
+
subscribe(onEvent) {
|
|
85
|
+
this.liveHandlers.add(onEvent);
|
|
86
|
+
return { unsubscribe: () => this.liveHandlers.delete(onEvent) };
|
|
87
|
+
}
|
|
88
|
+
async discoverDevices(userId) {
|
|
89
|
+
const res = await this.fetchImpl(`${this.cfg.baseUrl}/devices/${toHex(userId)}`, {
|
|
90
|
+
headers: { ...this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {} }
|
|
91
|
+
});
|
|
92
|
+
if (!res.ok) throw new Error(`device discovery failed: ${res.status}`);
|
|
93
|
+
const text = await res.text();
|
|
94
|
+
return JSON.parse(text, reviver);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function replacer(_k, v) {
|
|
98
|
+
if (v instanceof Uint8Array) return { _bytes: Array.from(v) };
|
|
99
|
+
return v;
|
|
100
|
+
}
|
|
101
|
+
function reviver(_k, v) {
|
|
102
|
+
if (v && typeof v === "object" && Array.isArray(v._bytes)) {
|
|
103
|
+
return new Uint8Array(v._bytes);
|
|
104
|
+
}
|
|
105
|
+
return v;
|
|
106
|
+
}
|
|
107
|
+
function toHex(b) {
|
|
108
|
+
let s = "";
|
|
109
|
+
for (const v of b) s += v.toString(16).padStart(2, "0");
|
|
110
|
+
return s;
|
|
111
|
+
}
|
|
112
|
+
function btoaUrl(b) {
|
|
113
|
+
let s = "";
|
|
114
|
+
for (const v of b) s += String.fromCharCode(v);
|
|
115
|
+
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
116
|
+
}
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
WebSocketTransport
|
|
120
|
+
});
|
|
121
|
+
//# sourceMappingURL=websocket.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transport/websocket.ts","../../src/wire-contract.ts"],"sourcesContent":["// Reference WebSocket transport. Treats the server as an opaque relay that:\n// - accepts a CBOR-encoded MessageEnvelope on `send`\n// - returns events newer than a cursor on `fetchSince`\n// - streams new events on the WS itself for `subscribe`\n// - exposes a directory endpoint for `discoverDevices`\n//\n// This is a sample. Real deployments will tune framing / auth.\n\nimport type { ConversationId, DiscoveredDevice, MessageEnvelope, Transport, UserId } from \"../types\";\nimport {\n CONTENT_TYPE_JSON,\n PING_WIRE_CONTRACT_HEADER,\n PING_WIRE_CONTRACT_HEADER_VALUE,\n} from \"../wire-contract\";\n\nexport interface WsTransportConfig {\n baseUrl: string; // ws[s]://...\n authHeader?: string; // optional bearer token\n fetchImpl?: typeof fetch; // override for SSR / tests\n}\n\nexport class WebSocketTransport implements Transport {\n private ws: WebSocket | null = null;\n private liveHandlers = new Set<(env: MessageEnvelope) => void>();\n private fetchImpl: typeof fetch;\n\n constructor(private cfg: WsTransportConfig) {\n this.fetchImpl = cfg.fetchImpl ?? globalThis.fetch.bind(globalThis);\n this.openSocket();\n }\n\n private openSocket() {\n if (typeof WebSocket === \"undefined\") return;\n const url = `${this.cfg.baseUrl.replace(/^http/, \"ws\")}/stream`;\n this.ws = new WebSocket(url);\n this.ws.onmessage = (ev) => {\n // Server sends one JSON envelope per text frame.\n const text = typeof ev.data === \"string\" ? ev.data : new TextDecoder().decode(ev.data as ArrayBuffer);\n try {\n const env = JSON.parse(text, reviver) as MessageEnvelope;\n for (const h of this.liveHandlers) h(env);\n } catch (e) {\n if (typeof console !== \"undefined\") console.debug(\"[ping-sdk] WS frame parse error:\", e);\n }\n };\n this.ws.onclose = () => setTimeout(() => this.openSocket(), 1000);\n }\n\n async send(envelope: MessageEnvelope): Promise<void> {\n // We're emitting the JSON projection of the ping-wire-contract. Production transports\n // would use CONTENT_TYPE_CBOR with a real CBOR codec; for the demo path the JSON shape\n // is the documented development projection.\n const res = await this.fetchImpl(`${this.cfg.baseUrl}/send`, {\n method: \"POST\",\n headers: {\n \"content-type\": CONTENT_TYPE_JSON,\n [PING_WIRE_CONTRACT_HEADER]: PING_WIRE_CONTRACT_HEADER_VALUE,\n ...(this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}),\n },\n body: JSON.stringify(envelope, replacer),\n });\n if (res.status === 409) throw new Error(\"EpochOccupied\");\n if (!res.ok) throw new Error(`transport send failed: ${res.status}`);\n }\n\n async fetchSince(conversationId: ConversationId, cursor: Uint8Array, limit: number): Promise<MessageEnvelope[]> {\n const url = new URL(`${this.cfg.baseUrl}/sync`);\n url.searchParams.set(\"conv\", toHex(conversationId));\n url.searchParams.set(\"cursor\", btoaUrl(cursor));\n url.searchParams.set(\"limit\", String(limit));\n const res = await this.fetchImpl(url.toString(), {\n headers: { ...(this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}) },\n });\n if (!res.ok) throw new Error(`transport fetch failed: ${res.status}`);\n const text = await res.text();\n return JSON.parse(text, reviver) as MessageEnvelope[];\n }\n\n subscribe(onEvent: (env: MessageEnvelope) => void): { unsubscribe(): void } {\n this.liveHandlers.add(onEvent);\n return { unsubscribe: () => this.liveHandlers.delete(onEvent) };\n }\n\n async discoverDevices(userId: UserId): Promise<DiscoveredDevice[]> {\n const res = await this.fetchImpl(`${this.cfg.baseUrl}/devices/${toHex(userId)}`, {\n headers: { ...(this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}) },\n });\n if (!res.ok) throw new Error(`device discovery failed: ${res.status}`);\n const text = await res.text();\n return JSON.parse(text, reviver) as DiscoveredDevice[];\n }\n}\n\n// ---- Wire codec ----\n//\n// Demo wire format: JSON with byte fields wrapped as `{ _bytes: number[] }`. The relay's\n// `envFromJson`/`envToJson` use the same shape. The spec calls for CBOR; v0.2 swaps in a\n// real CBOR codec, but the JSON form is much friendlier to debug.\n//\n// (decodeEnvelope helpers used to live here; collapsed into inline JSON.parse calls above.)\n\nfunction replacer(_k: string, v: unknown): unknown {\n if (v instanceof Uint8Array) return { _bytes: Array.from(v) };\n return v;\n}\nfunction reviver(_k: string, v: unknown): unknown {\n if (v && typeof v === \"object\" && Array.isArray((v as { _bytes?: number[] })._bytes)) {\n return new Uint8Array((v as { _bytes: number[] })._bytes);\n }\n return v;\n}\n\nfunction toHex(b: Uint8Array): string {\n let s = \"\"; for (const v of b) s += v.toString(16).padStart(2, \"0\"); return s;\n}\nfunction btoaUrl(b: Uint8Array): string {\n let s = \"\"; for (const v of b) s += String.fromCharCode(v);\n return btoa(s).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n","// Ping wire contract — TypeScript counterpart to the `ping-wire-contract` Rust crate.\n//\n// MUST stay in lockstep with `core/ping-wire-contract/src/lib.rs`. The full normative spec\n// lives in `docs/PING_WIRE_CONTRACT.md`.\n//\n// What this module is for: code paths that cross the network boundary (transports, relays,\n// service workers) that need to advertise or validate ping-wire-contract conformance from\n// JavaScript without round-tripping through WASM.\n\nimport type { MessageEnvelope } from \"./types\";\n\n/**\n * Ping wire contract version. Bumped on incompatible profile changes.\n *\n * Currently `2` — CR-6 changes the `content_hash` semantics for `Application` envelopes\n * (now hashed over plaintext, not the MLS ciphertext). Receivers run a 90-day dual-accept\n * window per Q-ARCH-02; see [[validate]] for the per-version routing.\n */\nexport const PING_WIRE_CONTRACT_VERSION = 2;\n\n/** Lowest envelope version accepted by [[validate]] during the dual-accept window. */\nexport const WIRE_VERSION_MIN_ACCEPTED = 1;\n\n/** Canonical CBOR content type. Production transports SHOULD use this. */\nexport const CONTENT_TYPE_CBOR = \"application/vnd.ping.wire.v2+cbor\";\n\n/** JSON projection — development and tooling only. Production MUST NOT use this. */\nexport const CONTENT_TYPE_JSON = \"application/vnd.ping.wire.v2+json\";\n\n/** Legacy v1 CBOR type, accepted during the CR-6 dual-accept window. */\nexport const CONTENT_TYPE_CBOR_LEGACY_V1 = \"application/vnd.ping.wire.v1+cbor\";\n\n/** Legacy v1 JSON type, accepted during the CR-6 dual-accept window. */\nexport const CONTENT_TYPE_JSON_LEGACY_V1 = \"application/vnd.ping.wire.v1+json\";\n\n/** Header used over transports that don't surface a content type (e.g. WebSocket). */\nexport const PING_WIRE_CONTRACT_HEADER = \"X-Ping-Wire-Contract\";\n\n/** Header value: `ping/<VERSION>`. */\nexport const PING_WIRE_CONTRACT_HEADER_VALUE = `ping/${PING_WIRE_CONTRACT_VERSION}`;\n\nexport type ValidationErrorKind =\n | \"UnsupportedVersion\"\n | \"BadConversationIdLen\"\n | \"BadSenderDeviceLen\"\n | \"ContentHashMismatch\";\n\nexport class ValidationError extends Error {\n constructor(public readonly kind: ValidationErrorKind, message: string) {\n super(message);\n this.name = \"PingWireContractValidationError\";\n }\n}\n\nconst KIND_DISCRIMINANT: Record<MessageEnvelope[\"kind\"], number> = {\n Application: 1,\n Commit: 2,\n Welcome: 3,\n Proposal: 4,\n KeyPackage: 5,\n};\n\nasync function sha256(bytes: Uint8Array): Promise<Uint8Array> {\n // `crypto.subtle` is available in browsers, Node 20+, and Workers. `bytes.buffer`\n // is typed as `ArrayBufferLike` which TS won't accept as `BufferSource` (the union\n // includes `SharedArrayBuffer`); pass an explicit ArrayBuffer slice instead.\n const ab = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;\n const hash = await crypto.subtle.digest(\"SHA-256\", ab);\n return new Uint8Array(hash);\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Validate an envelope against the ping-wire-contract.\n *\n * Receivers claiming contract conformance MUST call this before applying any envelope.\n * External consumers using the raw envelope under their own profile are not bound by\n * these rules.\n *\n * CR-6 dual-accept window: `v ∈ [WIRE_VERSION_MIN_ACCEPTED, PING_WIRE_CONTRACT_VERSION]`\n * passes the version gate. For v=2 `Application` envelopes the content_hash is over\n * plaintext, so this function skips that check — callers MUST run\n * [[verifyApplicationContentHash]] after MLS decrypt to close the loop.\n */\nexport async function validate(env: MessageEnvelope): Promise<void> {\n if (env.v < WIRE_VERSION_MIN_ACCEPTED || env.v > PING_WIRE_CONTRACT_VERSION) {\n throw new ValidationError(\n \"UnsupportedVersion\",\n `unsupported wire-contract version: envelope says v=${env.v}, expected v∈[${WIRE_VERSION_MIN_ACCEPTED}, ${PING_WIRE_CONTRACT_VERSION}]`,\n );\n }\n if (env.conversation_id.length !== 16) {\n throw new ValidationError(\n \"BadConversationIdLen\",\n `conversation_id must be 16 bytes (ULID), got ${env.conversation_id.length}`,\n );\n }\n if (env.sender_device.length !== 32) {\n throw new ValidationError(\n \"BadSenderDeviceLen\",\n `sender_device must be 32 bytes, got ${env.sender_device.length}`,\n );\n }\n // CR-6 routing: skip the hash check for v=2 application envelopes.\n if (env.v >= 2 && env.kind === \"Application\") {\n return;\n }\n const buf = new Uint8Array(1 + env.payload.length);\n buf[0] = KIND_DISCRIMINANT[env.kind];\n buf.set(env.payload, 1);\n const computed = await sha256(buf);\n if (!bytesEqual(computed, env.content_hash)) {\n throw new ValidationError(\n \"ContentHashMismatch\",\n \"content_hash mismatch: envelope is forged, corrupted, or built by a non-conformant sender\",\n );\n }\n}\n\n/**\n * Verify a v=2 `Application` envelope's content_hash against the decrypted plaintext.\n *\n * Caller MUST run this after MLS decrypt for application envelopes whose `v >= 2`. For\n * v=1 envelopes or handshake kinds this is a no-op (those are covered by [[validate]]).\n */\nexport async function verifyApplicationContentHash(\n env: MessageEnvelope,\n plaintext: Uint8Array,\n): Promise<void> {\n if (env.v < 2 || env.kind !== \"Application\") return;\n const computed = await sha256(plaintext);\n if (!bytesEqual(computed, env.content_hash)) {\n throw new ValidationError(\n \"ContentHashMismatch\",\n \"v=2 application content_hash mismatch against decrypted plaintext\",\n );\n }\n}\n\n/**\n * True if the supplied content type negotiates the ping-wire-contract.\n *\n * Accepts the v2 canonical types AND the v1 legacy types during the CR-6 dual-accept\n * window. Tolerates whitespace and parameters (e.g. `; charset=utf-8`).\n */\nexport function negotiates(contentType: string | null | undefined): boolean {\n if (!contentType) return false;\n const primary = contentType.split(\";\")[0]?.trim().toLowerCase() ?? \"\";\n return (\n primary === CONTENT_TYPE_CBOR\n || primary === CONTENT_TYPE_JSON\n || primary === CONTENT_TYPE_CBOR_LEGACY_V1\n || primary === CONTENT_TYPE_JSON_LEGACY_V1\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkBO,IAAM,6BAA6B;AASnC,IAAM,oBAAoB;AAS1B,IAAM,4BAA4B;AAGlC,IAAM,kCAAkC,QAAQ,0BAA0B;;;ADlB1E,IAAM,qBAAN,MAA8C;AAAA,EAKnD,YAAoB,KAAwB;AAAxB;AAClB,SAAK,YAAY,IAAI,aAAa,WAAW,MAAM,KAAK,UAAU;AAClE,SAAK,WAAW;AAAA,EAClB;AAAA,EAHoB;AAAA,EAJZ,KAAuB;AAAA,EACvB,eAAe,oBAAI,IAAoC;AAAA,EACvD;AAAA,EAOA,aAAa;AACnB,QAAI,OAAO,cAAc,YAAa;AACtC,UAAM,MAAM,GAAG,KAAK,IAAI,QAAQ,QAAQ,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AAO;AAC9E;AACA,SAAS,QAAQ,GAAuB;AACtC,MAAI,IAAI;AAAI,aAAW,KAAK,EAAG,MAAK,OAAO,aAAa,CAAC;AACzD,SAAO,KAAK,CAAC,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AAC1E;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-B1GFwNXa.cjs';
|
|
2
|
+
|
|
3
|
+
interface WsTransportConfig {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
authHeader?: string;
|
|
6
|
+
fetchImpl?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
declare class WebSocketTransport implements Transport {
|
|
9
|
+
private cfg;
|
|
10
|
+
private ws;
|
|
11
|
+
private liveHandlers;
|
|
12
|
+
private fetchImpl;
|
|
13
|
+
constructor(cfg: WsTransportConfig);
|
|
14
|
+
private openSocket;
|
|
15
|
+
send(envelope: MessageEnvelope): Promise<void>;
|
|
16
|
+
fetchSince(conversationId: ConversationId, cursor: Uint8Array, limit: number): Promise<MessageEnvelope[]>;
|
|
17
|
+
subscribe(onEvent: (env: MessageEnvelope) => void): {
|
|
18
|
+
unsubscribe(): void;
|
|
19
|
+
};
|
|
20
|
+
discoverDevices(userId: UserId): Promise<DiscoveredDevice[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { WebSocketTransport, type WsTransportConfig };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-B1GFwNXa.js';
|
|
2
|
+
|
|
3
|
+
interface WsTransportConfig {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
authHeader?: string;
|
|
6
|
+
fetchImpl?: typeof fetch;
|
|
7
|
+
}
|
|
8
|
+
declare class WebSocketTransport implements Transport {
|
|
9
|
+
private cfg;
|
|
10
|
+
private ws;
|
|
11
|
+
private liveHandlers;
|
|
12
|
+
private fetchImpl;
|
|
13
|
+
constructor(cfg: WsTransportConfig);
|
|
14
|
+
private openSocket;
|
|
15
|
+
send(envelope: MessageEnvelope): Promise<void>;
|
|
16
|
+
fetchSince(conversationId: ConversationId, cursor: Uint8Array, limit: number): Promise<MessageEnvelope[]>;
|
|
17
|
+
subscribe(onEvent: (env: MessageEnvelope) => void): {
|
|
18
|
+
unsubscribe(): void;
|
|
19
|
+
};
|
|
20
|
+
discoverDevices(userId: UserId): Promise<DiscoveredDevice[]>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { WebSocketTransport, type WsTransportConfig };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/wire-contract.ts
|
|
2
|
+
var PING_WIRE_CONTRACT_VERSION = 2;
|
|
3
|
+
var CONTENT_TYPE_JSON = "application/vnd.ping.wire.v2+json";
|
|
4
|
+
var PING_WIRE_CONTRACT_HEADER = "X-Ping-Wire-Contract";
|
|
5
|
+
var PING_WIRE_CONTRACT_HEADER_VALUE = `ping/${PING_WIRE_CONTRACT_VERSION}`;
|
|
6
|
+
|
|
7
|
+
// src/transport/websocket.ts
|
|
8
|
+
var WebSocketTransport = class {
|
|
9
|
+
constructor(cfg) {
|
|
10
|
+
this.cfg = cfg;
|
|
11
|
+
this.fetchImpl = cfg.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
12
|
+
this.openSocket();
|
|
13
|
+
}
|
|
14
|
+
cfg;
|
|
15
|
+
ws = null;
|
|
16
|
+
liveHandlers = /* @__PURE__ */ new Set();
|
|
17
|
+
fetchImpl;
|
|
18
|
+
openSocket() {
|
|
19
|
+
if (typeof WebSocket === "undefined") return;
|
|
20
|
+
const url = `${this.cfg.baseUrl.replace(/^http/, "ws")}/stream`;
|
|
21
|
+
this.ws = new WebSocket(url);
|
|
22
|
+
this.ws.onmessage = (ev) => {
|
|
23
|
+
const text = typeof ev.data === "string" ? ev.data : new TextDecoder().decode(ev.data);
|
|
24
|
+
try {
|
|
25
|
+
const env = JSON.parse(text, reviver);
|
|
26
|
+
for (const h of this.liveHandlers) h(env);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
if (typeof console !== "undefined") console.debug("[ping-sdk] WS frame parse error:", e);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
this.ws.onclose = () => setTimeout(() => this.openSocket(), 1e3);
|
|
32
|
+
}
|
|
33
|
+
async send(envelope) {
|
|
34
|
+
const res = await this.fetchImpl(`${this.cfg.baseUrl}/send`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"content-type": CONTENT_TYPE_JSON,
|
|
38
|
+
[PING_WIRE_CONTRACT_HEADER]: PING_WIRE_CONTRACT_HEADER_VALUE,
|
|
39
|
+
...this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(envelope, replacer)
|
|
42
|
+
});
|
|
43
|
+
if (res.status === 409) throw new Error("EpochOccupied");
|
|
44
|
+
if (!res.ok) throw new Error(`transport send failed: ${res.status}`);
|
|
45
|
+
}
|
|
46
|
+
async fetchSince(conversationId, cursor, limit) {
|
|
47
|
+
const url = new URL(`${this.cfg.baseUrl}/sync`);
|
|
48
|
+
url.searchParams.set("conv", toHex(conversationId));
|
|
49
|
+
url.searchParams.set("cursor", btoaUrl(cursor));
|
|
50
|
+
url.searchParams.set("limit", String(limit));
|
|
51
|
+
const res = await this.fetchImpl(url.toString(), {
|
|
52
|
+
headers: { ...this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {} }
|
|
53
|
+
});
|
|
54
|
+
if (!res.ok) throw new Error(`transport fetch failed: ${res.status}`);
|
|
55
|
+
const text = await res.text();
|
|
56
|
+
return JSON.parse(text, reviver);
|
|
57
|
+
}
|
|
58
|
+
subscribe(onEvent) {
|
|
59
|
+
this.liveHandlers.add(onEvent);
|
|
60
|
+
return { unsubscribe: () => this.liveHandlers.delete(onEvent) };
|
|
61
|
+
}
|
|
62
|
+
async discoverDevices(userId) {
|
|
63
|
+
const res = await this.fetchImpl(`${this.cfg.baseUrl}/devices/${toHex(userId)}`, {
|
|
64
|
+
headers: { ...this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {} }
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok) throw new Error(`device discovery failed: ${res.status}`);
|
|
67
|
+
const text = await res.text();
|
|
68
|
+
return JSON.parse(text, reviver);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function replacer(_k, v) {
|
|
72
|
+
if (v instanceof Uint8Array) return { _bytes: Array.from(v) };
|
|
73
|
+
return v;
|
|
74
|
+
}
|
|
75
|
+
function reviver(_k, v) {
|
|
76
|
+
if (v && typeof v === "object" && Array.isArray(v._bytes)) {
|
|
77
|
+
return new Uint8Array(v._bytes);
|
|
78
|
+
}
|
|
79
|
+
return v;
|
|
80
|
+
}
|
|
81
|
+
function toHex(b) {
|
|
82
|
+
let s = "";
|
|
83
|
+
for (const v of b) s += v.toString(16).padStart(2, "0");
|
|
84
|
+
return s;
|
|
85
|
+
}
|
|
86
|
+
function btoaUrl(b) {
|
|
87
|
+
let s = "";
|
|
88
|
+
for (const v of b) s += String.fromCharCode(v);
|
|
89
|
+
return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
WebSocketTransport
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/wire-contract.ts","../../src/transport/websocket.ts"],"sourcesContent":["// Ping wire contract — TypeScript counterpart to the `ping-wire-contract` Rust crate.\n//\n// MUST stay in lockstep with `core/ping-wire-contract/src/lib.rs`. The full normative spec\n// lives in `docs/PING_WIRE_CONTRACT.md`.\n//\n// What this module is for: code paths that cross the network boundary (transports, relays,\n// service workers) that need to advertise or validate ping-wire-contract conformance from\n// JavaScript without round-tripping through WASM.\n\nimport type { MessageEnvelope } from \"./types\";\n\n/**\n * Ping wire contract version. Bumped on incompatible profile changes.\n *\n * Currently `2` — CR-6 changes the `content_hash` semantics for `Application` envelopes\n * (now hashed over plaintext, not the MLS ciphertext). Receivers run a 90-day dual-accept\n * window per Q-ARCH-02; see [[validate]] for the per-version routing.\n */\nexport const PING_WIRE_CONTRACT_VERSION = 2;\n\n/** Lowest envelope version accepted by [[validate]] during the dual-accept window. */\nexport const WIRE_VERSION_MIN_ACCEPTED = 1;\n\n/** Canonical CBOR content type. Production transports SHOULD use this. */\nexport const CONTENT_TYPE_CBOR = \"application/vnd.ping.wire.v2+cbor\";\n\n/** JSON projection — development and tooling only. Production MUST NOT use this. */\nexport const CONTENT_TYPE_JSON = \"application/vnd.ping.wire.v2+json\";\n\n/** Legacy v1 CBOR type, accepted during the CR-6 dual-accept window. */\nexport const CONTENT_TYPE_CBOR_LEGACY_V1 = \"application/vnd.ping.wire.v1+cbor\";\n\n/** Legacy v1 JSON type, accepted during the CR-6 dual-accept window. */\nexport const CONTENT_TYPE_JSON_LEGACY_V1 = \"application/vnd.ping.wire.v1+json\";\n\n/** Header used over transports that don't surface a content type (e.g. WebSocket). */\nexport const PING_WIRE_CONTRACT_HEADER = \"X-Ping-Wire-Contract\";\n\n/** Header value: `ping/<VERSION>`. */\nexport const PING_WIRE_CONTRACT_HEADER_VALUE = `ping/${PING_WIRE_CONTRACT_VERSION}`;\n\nexport type ValidationErrorKind =\n | \"UnsupportedVersion\"\n | \"BadConversationIdLen\"\n | \"BadSenderDeviceLen\"\n | \"ContentHashMismatch\";\n\nexport class ValidationError extends Error {\n constructor(public readonly kind: ValidationErrorKind, message: string) {\n super(message);\n this.name = \"PingWireContractValidationError\";\n }\n}\n\nconst KIND_DISCRIMINANT: Record<MessageEnvelope[\"kind\"], number> = {\n Application: 1,\n Commit: 2,\n Welcome: 3,\n Proposal: 4,\n KeyPackage: 5,\n};\n\nasync function sha256(bytes: Uint8Array): Promise<Uint8Array> {\n // `crypto.subtle` is available in browsers, Node 20+, and Workers. `bytes.buffer`\n // is typed as `ArrayBufferLike` which TS won't accept as `BufferSource` (the union\n // includes `SharedArrayBuffer`); pass an explicit ArrayBuffer slice instead.\n const ab = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;\n const hash = await crypto.subtle.digest(\"SHA-256\", ab);\n return new Uint8Array(hash);\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Validate an envelope against the ping-wire-contract.\n *\n * Receivers claiming contract conformance MUST call this before applying any envelope.\n * External consumers using the raw envelope under their own profile are not bound by\n * these rules.\n *\n * CR-6 dual-accept window: `v ∈ [WIRE_VERSION_MIN_ACCEPTED, PING_WIRE_CONTRACT_VERSION]`\n * passes the version gate. For v=2 `Application` envelopes the content_hash is over\n * plaintext, so this function skips that check — callers MUST run\n * [[verifyApplicationContentHash]] after MLS decrypt to close the loop.\n */\nexport async function validate(env: MessageEnvelope): Promise<void> {\n if (env.v < WIRE_VERSION_MIN_ACCEPTED || env.v > PING_WIRE_CONTRACT_VERSION) {\n throw new ValidationError(\n \"UnsupportedVersion\",\n `unsupported wire-contract version: envelope says v=${env.v}, expected v∈[${WIRE_VERSION_MIN_ACCEPTED}, ${PING_WIRE_CONTRACT_VERSION}]`,\n );\n }\n if (env.conversation_id.length !== 16) {\n throw new ValidationError(\n \"BadConversationIdLen\",\n `conversation_id must be 16 bytes (ULID), got ${env.conversation_id.length}`,\n );\n }\n if (env.sender_device.length !== 32) {\n throw new ValidationError(\n \"BadSenderDeviceLen\",\n `sender_device must be 32 bytes, got ${env.sender_device.length}`,\n );\n }\n // CR-6 routing: skip the hash check for v=2 application envelopes.\n if (env.v >= 2 && env.kind === \"Application\") {\n return;\n }\n const buf = new Uint8Array(1 + env.payload.length);\n buf[0] = KIND_DISCRIMINANT[env.kind];\n buf.set(env.payload, 1);\n const computed = await sha256(buf);\n if (!bytesEqual(computed, env.content_hash)) {\n throw new ValidationError(\n \"ContentHashMismatch\",\n \"content_hash mismatch: envelope is forged, corrupted, or built by a non-conformant sender\",\n );\n }\n}\n\n/**\n * Verify a v=2 `Application` envelope's content_hash against the decrypted plaintext.\n *\n * Caller MUST run this after MLS decrypt for application envelopes whose `v >= 2`. For\n * v=1 envelopes or handshake kinds this is a no-op (those are covered by [[validate]]).\n */\nexport async function verifyApplicationContentHash(\n env: MessageEnvelope,\n plaintext: Uint8Array,\n): Promise<void> {\n if (env.v < 2 || env.kind !== \"Application\") return;\n const computed = await sha256(plaintext);\n if (!bytesEqual(computed, env.content_hash)) {\n throw new ValidationError(\n \"ContentHashMismatch\",\n \"v=2 application content_hash mismatch against decrypted plaintext\",\n );\n }\n}\n\n/**\n * True if the supplied content type negotiates the ping-wire-contract.\n *\n * Accepts the v2 canonical types AND the v1 legacy types during the CR-6 dual-accept\n * window. Tolerates whitespace and parameters (e.g. `; charset=utf-8`).\n */\nexport function negotiates(contentType: string | null | undefined): boolean {\n if (!contentType) return false;\n const primary = contentType.split(\";\")[0]?.trim().toLowerCase() ?? \"\";\n return (\n primary === CONTENT_TYPE_CBOR\n || primary === CONTENT_TYPE_JSON\n || primary === CONTENT_TYPE_CBOR_LEGACY_V1\n || primary === CONTENT_TYPE_JSON_LEGACY_V1\n );\n}\n","// Reference WebSocket transport. Treats the server as an opaque relay that:\n// - accepts a CBOR-encoded MessageEnvelope on `send`\n// - returns events newer than a cursor on `fetchSince`\n// - streams new events on the WS itself for `subscribe`\n// - exposes a directory endpoint for `discoverDevices`\n//\n// This is a sample. Real deployments will tune framing / auth.\n\nimport type { ConversationId, DiscoveredDevice, MessageEnvelope, Transport, UserId } from \"../types\";\nimport {\n CONTENT_TYPE_JSON,\n PING_WIRE_CONTRACT_HEADER,\n PING_WIRE_CONTRACT_HEADER_VALUE,\n} from \"../wire-contract\";\n\nexport interface WsTransportConfig {\n baseUrl: string; // ws[s]://...\n authHeader?: string; // optional bearer token\n fetchImpl?: typeof fetch; // override for SSR / tests\n}\n\nexport class WebSocketTransport implements Transport {\n private ws: WebSocket | null = null;\n private liveHandlers = new Set<(env: MessageEnvelope) => void>();\n private fetchImpl: typeof fetch;\n\n constructor(private cfg: WsTransportConfig) {\n this.fetchImpl = cfg.fetchImpl ?? globalThis.fetch.bind(globalThis);\n this.openSocket();\n }\n\n private openSocket() {\n if (typeof WebSocket === \"undefined\") return;\n const url = `${this.cfg.baseUrl.replace(/^http/, \"ws\")}/stream`;\n this.ws = new WebSocket(url);\n this.ws.onmessage = (ev) => {\n // Server sends one JSON envelope per text frame.\n const text = typeof ev.data === \"string\" ? ev.data : new TextDecoder().decode(ev.data as ArrayBuffer);\n try {\n const env = JSON.parse(text, reviver) as MessageEnvelope;\n for (const h of this.liveHandlers) h(env);\n } catch (e) {\n if (typeof console !== \"undefined\") console.debug(\"[ping-sdk] WS frame parse error:\", e);\n }\n };\n this.ws.onclose = () => setTimeout(() => this.openSocket(), 1000);\n }\n\n async send(envelope: MessageEnvelope): Promise<void> {\n // We're emitting the JSON projection of the ping-wire-contract. Production transports\n // would use CONTENT_TYPE_CBOR with a real CBOR codec; for the demo path the JSON shape\n // is the documented development projection.\n const res = await this.fetchImpl(`${this.cfg.baseUrl}/send`, {\n method: \"POST\",\n headers: {\n \"content-type\": CONTENT_TYPE_JSON,\n [PING_WIRE_CONTRACT_HEADER]: PING_WIRE_CONTRACT_HEADER_VALUE,\n ...(this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}),\n },\n body: JSON.stringify(envelope, replacer),\n });\n if (res.status === 409) throw new Error(\"EpochOccupied\");\n if (!res.ok) throw new Error(`transport send failed: ${res.status}`);\n }\n\n async fetchSince(conversationId: ConversationId, cursor: Uint8Array, limit: number): Promise<MessageEnvelope[]> {\n const url = new URL(`${this.cfg.baseUrl}/sync`);\n url.searchParams.set(\"conv\", toHex(conversationId));\n url.searchParams.set(\"cursor\", btoaUrl(cursor));\n url.searchParams.set(\"limit\", String(limit));\n const res = await this.fetchImpl(url.toString(), {\n headers: { ...(this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}) },\n });\n if (!res.ok) throw new Error(`transport fetch failed: ${res.status}`);\n const text = await res.text();\n return JSON.parse(text, reviver) as MessageEnvelope[];\n }\n\n subscribe(onEvent: (env: MessageEnvelope) => void): { unsubscribe(): void } {\n this.liveHandlers.add(onEvent);\n return { unsubscribe: () => this.liveHandlers.delete(onEvent) };\n }\n\n async discoverDevices(userId: UserId): Promise<DiscoveredDevice[]> {\n const res = await this.fetchImpl(`${this.cfg.baseUrl}/devices/${toHex(userId)}`, {\n headers: { ...(this.cfg.authHeader ? { authorization: this.cfg.authHeader } : {}) },\n });\n if (!res.ok) throw new Error(`device discovery failed: ${res.status}`);\n const text = await res.text();\n return JSON.parse(text, reviver) as DiscoveredDevice[];\n }\n}\n\n// ---- Wire codec ----\n//\n// Demo wire format: JSON with byte fields wrapped as `{ _bytes: number[] }`. The relay's\n// `envFromJson`/`envToJson` use the same shape. The spec calls for CBOR; v0.2 swaps in a\n// real CBOR codec, but the JSON form is much friendlier to debug.\n//\n// (decodeEnvelope helpers used to live here; collapsed into inline JSON.parse calls above.)\n\nfunction replacer(_k: string, v: unknown): unknown {\n if (v instanceof Uint8Array) return { _bytes: Array.from(v) };\n return v;\n}\nfunction reviver(_k: string, v: unknown): unknown {\n if (v && typeof v === \"object\" && Array.isArray((v as { _bytes?: number[] })._bytes)) {\n return new Uint8Array((v as { _bytes: number[] })._bytes);\n }\n return v;\n}\n\nfunction toHex(b: Uint8Array): string {\n let s = \"\"; for (const v of b) s += v.toString(16).padStart(2, \"0\"); return s;\n}\nfunction btoaUrl(b: Uint8Array): string {\n let s = \"\"; for (const v of b) s += String.fromCharCode(v);\n return btoa(s).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\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