@cello-protocol/cli 0.0.306 → 0.0.308
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/.claude-plugin/marketplace.json +15 -0
- package/README.md +107 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +602 -0
- package/dist/daemon/account-page-assets.d.ts +4 -0
- package/dist/daemon/account-page-assets.js +160 -0
- package/dist/daemon/account-page.d.ts +14 -0
- package/dist/daemon/account-page.js +104 -0
- package/dist/daemon/address.d.ts +10 -0
- package/dist/daemon/address.js +34 -0
- package/dist/daemon/away.d.ts +31 -0
- package/dist/daemon/away.js +65 -0
- package/dist/daemon/channel-store.d.ts +112 -0
- package/dist/daemon/channel-store.js +284 -0
- package/dist/daemon/channels.d.ts +46 -0
- package/dist/daemon/channels.js +1049 -0
- package/dist/daemon/contacts.d.ts +26 -0
- package/dist/daemon/contacts.js +74 -0
- package/dist/daemon/engine.d.ts +82 -0
- package/dist/daemon/engine.js +2882 -0
- package/dist/daemon/errors.d.ts +5 -0
- package/dist/daemon/errors.js +16 -0
- package/dist/daemon/governance.d.ts +66 -0
- package/dist/daemon/governance.js +514 -0
- package/dist/daemon/guards.d.ts +36 -0
- package/dist/daemon/guards.js +140 -0
- package/dist/daemon/issuer-client.d.ts +56 -0
- package/dist/daemon/issuer-client.js +143 -0
- package/dist/daemon/link.d.ts +30 -0
- package/dist/daemon/link.js +191 -0
- package/dist/daemon/log.d.ts +1 -0
- package/dist/daemon/log.js +4 -0
- package/dist/daemon/main.d.ts +1 -0
- package/dist/daemon/main.js +513 -0
- package/dist/daemon/paths.d.ts +6 -0
- package/dist/daemon/paths.js +21 -0
- package/dist/daemon/pii.d.ts +24 -0
- package/dist/daemon/pii.js +147 -0
- package/dist/daemon/policy-cadence.d.ts +33 -0
- package/dist/daemon/policy-cadence.js +59 -0
- package/dist/daemon/policy-proposals.d.ts +41 -0
- package/dist/daemon/policy-proposals.js +83 -0
- package/dist/daemon/policy-store.d.ts +47 -0
- package/dist/daemon/policy-store.js +144 -0
- package/dist/daemon/presented.d.ts +36 -0
- package/dist/daemon/presented.js +94 -0
- package/dist/daemon/rate-limit.d.ts +17 -0
- package/dist/daemon/rate-limit.js +44 -0
- package/dist/daemon/reach.d.ts +62 -0
- package/dist/daemon/reach.js +204 -0
- package/dist/daemon/screening.d.ts +97 -0
- package/dist/daemon/screening.js +362 -0
- package/dist/daemon/settings.d.ts +125 -0
- package/dist/daemon/settings.js +73 -0
- package/dist/daemon/signal-rules.d.ts +55 -0
- package/dist/daemon/signal-rules.js +127 -0
- package/dist/daemon/signal-store.d.ts +53 -0
- package/dist/daemon/signal-store.js +114 -0
- package/dist/daemon/store.d.ts +189 -0
- package/dist/daemon/store.js +477 -0
- package/dist/daemon/tiers.d.ts +14 -0
- package/dist/daemon/tiers.js +9 -0
- package/dist/daemon/wallet.d.ts +73 -0
- package/dist/daemon/wallet.js +429 -0
- package/dist/daemon/who-label.d.ts +3 -0
- package/dist/daemon/who-label.js +11 -0
- package/dist/guidance.d.ts +39 -0
- package/dist/guidance.js +98 -0
- package/dist/hermes-bridge.d.ts +34 -0
- package/dist/hermes-bridge.js +223 -0
- package/dist/install-mcp.d.ts +6 -0
- package/dist/install-mcp.js +77 -0
- package/dist/ipc/client.d.ts +18 -0
- package/dist/ipc/client.js +107 -0
- package/dist/ipc/operations.d.ts +30 -0
- package/dist/ipc/operations.js +846 -0
- package/dist/ipc/protocol.d.ts +21 -0
- package/dist/ipc/protocol.js +1 -0
- package/dist/issuer-list-sign.d.ts +12 -0
- package/dist/issuer-list-sign.js +43 -0
- package/dist/local-operations.d.ts +2 -0
- package/dist/local-operations.js +73 -0
- package/dist/mcp-tools.d.ts +14 -0
- package/dist/mcp-tools.js +45 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +160 -0
- package/dist/protocol/aead.d.ts +4 -0
- package/dist/protocol/aead.js +35 -0
- package/dist/protocol/cbor.d.ts +40 -0
- package/dist/protocol/cbor.js +106 -0
- package/dist/protocol/chain.d.ts +44 -0
- package/dist/protocol/chain.js +126 -0
- package/dist/protocol/channel.d.ts +153 -0
- package/dist/protocol/channel.js +298 -0
- package/dist/protocol/encode.d.ts +6 -0
- package/dist/protocol/encode.js +21 -0
- package/dist/protocol/identity.d.ts +27 -0
- package/dist/protocol/identity.js +94 -0
- package/dist/protocol/issuer-list.d.ts +56 -0
- package/dist/protocol/issuer-list.js +193 -0
- package/dist/protocol/issuer-roots.d.ts +6 -0
- package/dist/protocol/issuer-roots.js +10 -0
- package/dist/protocol/key-agreement.d.ts +20 -0
- package/dist/protocol/key-agreement.js +88 -0
- package/dist/protocol/merkle.d.ts +16 -0
- package/dist/protocol/merkle.js +166 -0
- package/dist/protocol/ml-dsa.d.ts +28 -0
- package/dist/protocol/ml-dsa.js +58 -0
- package/dist/protocol/ml-kem.d.ts +14 -0
- package/dist/protocol/ml-kem.js +57 -0
- package/dist/protocol/pq-errors.d.ts +9 -0
- package/dist/protocol/pq-errors.js +23 -0
- package/dist/protocol/pq-warnings.d.ts +1 -0
- package/dist/protocol/pq-warnings.js +18 -0
- package/dist/protocol/presented-signals.d.ts +17 -0
- package/dist/protocol/presented-signals.js +92 -0
- package/dist/protocol/salt.d.ts +5 -0
- package/dist/protocol/salt.js +47 -0
- package/dist/protocol/seal.d.ts +58 -0
- package/dist/protocol/seal.js +220 -0
- package/dist/protocol/signal.d.ts +54 -0
- package/dist/protocol/signal.js +266 -0
- package/dist/protocol/status.d.ts +41 -0
- package/dist/protocol/status.js +64 -0
- package/dist/protocol/structures.d.ts +359 -0
- package/dist/protocol/structures.js +296 -0
- package/dist/protocol/transcript.d.ts +61 -0
- package/dist/protocol/transcript.js +319 -0
- package/dist/protocol/wire.d.ts +212 -0
- package/dist/protocol/wire.js +161 -0
- package/dist/require-node.d.ts +1 -0
- package/dist/require-node.js +10 -0
- package/dist/screener/affordance.d.ts +1 -0
- package/dist/screener/affordance.js +2 -0
- package/dist/screener/classifier-selfcheck.d.ts +29 -0
- package/dist/screener/classifier-selfcheck.js +56 -0
- package/dist/screener/exfil.d.ts +11 -0
- package/dist/screener/exfil.js +45 -0
- package/dist/screener/gitleaks-rules.d.ts +9 -0
- package/dist/screener/gitleaks-rules.js +226 -0
- package/dist/screener/inbound.d.ts +25 -0
- package/dist/screener/inbound.js +102 -0
- package/dist/screener/injection-classifier-onnx.d.ts +20 -0
- package/dist/screener/injection-classifier-onnx.js +89 -0
- package/dist/screener/injection-classifier-wasm.d.ts +2 -0
- package/dist/screener/injection-classifier-wasm.js +97 -0
- package/dist/screener/injection-patterns.d.ts +8 -0
- package/dist/screener/injection-patterns.js +48 -0
- package/dist/screener/injection-windows.d.ts +9 -0
- package/dist/screener/injection-windows.js +37 -0
- package/dist/screener/language.d.ts +15 -0
- package/dist/screener/language.js +71 -0
- package/dist/screener/linear-regex.d.ts +8 -0
- package/dist/screener/linear-regex.js +27 -0
- package/dist/screener/model-installer.d.ts +14 -0
- package/dist/screener/model-installer.js +61 -0
- package/dist/screener/outbound.d.ts +19 -0
- package/dist/screener/outbound.js +62 -0
- package/dist/screener/sanitize.d.ts +44 -0
- package/dist/screener/sanitize.js +361 -0
- package/dist/screener/scan-variants.d.ts +5 -0
- package/dist/screener/scan-variants.js +146 -0
- package/dist/screener/screener-model-manifest.d.ts +16 -0
- package/dist/screener/screener-model-manifest.js +20 -0
- package/dist/screener/screener-state.d.ts +29 -0
- package/dist/screener/screener-state.js +119 -0
- package/dist/screener/secrets.d.ts +18 -0
- package/dist/screener/secrets.js +84 -0
- package/dist/screener/worker.d.ts +6 -0
- package/dist/screener/worker.js +83 -0
- package/dist/setup.d.ts +9 -0
- package/dist/setup.js +259 -0
- package/dist/shipped-issuer-list.d.ts +1 -0
- package/dist/shipped-issuer-list.js +3 -0
- package/dist/signals-text.d.ts +46 -0
- package/dist/signals-text.js +81 -0
- package/dist/verify-seal.d.ts +9 -0
- package/dist/verify-seal.js +30 -0
- package/hermes/plugin/__init__.py +1066 -0
- package/hermes/plugin/plugin.yaml +30 -0
- package/hermes/skills/cello-bridge-setup/SKILL.md +48 -0
- package/hermes/skills/cello-policy/SKILL.md +44 -0
- package/package.json +48 -16
- package/plugins/cello/.claude-plugin/plugin.json +19 -0
- package/plugins/cello/.mcp.json +7 -0
- package/plugins/cello/skills/cello/SKILL.md +117 -0
- package/dist/arg-parse.d.ts +0 -19
- package/dist/arg-parse.d.ts.map +0 -1
- package/dist/arg-parse.js +0 -29
- package/dist/arg-parse.js.map +0 -1
- package/dist/bin/cello.d.ts +0 -15
- package/dist/bin/cello.d.ts.map +0 -1
- package/dist/bin/cello.js +0 -110
- package/dist/bin/cello.js.map +0 -1
- package/dist/cli-args.d.ts +0 -62
- package/dist/cli-args.d.ts.map +0 -1
- package/dist/cli-args.js +0 -129
- package/dist/cli-args.js.map +0 -1
- package/dist/commands.d.ts +0 -196
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js +0 -1544
- package/dist/commands.js.map +0 -1
- package/dist/hermes/assets.d.ts +0 -41
- package/dist/hermes/assets.d.ts.map +0 -1
- package/dist/hermes/assets.js +0 -2281
- package/dist/hermes/assets.js.map +0 -1
- package/dist/hermes/install-hermes.d.ts +0 -50
- package/dist/hermes/install-hermes.d.ts.map +0 -1
- package/dist/hermes/install-hermes.js +0 -232
- package/dist/hermes/install-hermes.js.map +0 -1
- package/dist/json-out.d.ts +0 -41
- package/dist/json-out.d.ts.map +0 -1
- package/dist/json-out.js +0 -59
- package/dist/json-out.js.map +0 -1
- package/dist/node-runtime-guard-init.d.ts +0 -6
- package/dist/node-runtime-guard-init.d.ts.map +0 -1
- package/dist/node-runtime-guard-init.js +0 -7
- package/dist/node-runtime-guard-init.js.map +0 -1
- package/dist/node-runtime-guard.d.ts +0 -48
- package/dist/node-runtime-guard.d.ts.map +0 -1
- package/dist/node-runtime-guard.js +0 -79
- package/dist/node-runtime-guard.js.map +0 -1
- package/dist/parity-commands.d.ts +0 -427
- package/dist/parity-commands.d.ts.map +0 -1
- package/dist/parity-commands.js +0 -953
- package/dist/parity-commands.js.map +0 -1
- package/dist/registry.d.ts +0 -120
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -2169
- package/dist/registry.js.map +0 -1
- package/dist/screener-commands.d.ts +0 -85
- package/dist/screener-commands.d.ts.map +0 -1
- package/dist/screener-commands.js +0 -313
- package/dist/screener-commands.js.map +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Checks a session's history: every signature, each author's chain, the order, and the running root.
|
|
2
|
+
// It needs only the parties' and the server's public keys, so a record can be checked without the server.
|
|
3
|
+
import { ZERO_HASH, equalBytes, toHex } from "./encode.js";
|
|
4
|
+
import { identityId, verifySignature } from "./identity.js";
|
|
5
|
+
import { EMPTY_ROOT, RunningMerkle } from "./merkle.js";
|
|
6
|
+
import { EntryKind, structureHash } from "./structures.js";
|
|
7
|
+
export function witnessed(entry, ack) {
|
|
8
|
+
return { fields: entry.fields, signature: entry.signature, bytes: entry.bytes, ack: ack.fields, ackSignature: ack.signature, ackBytes: ack.bytes };
|
|
9
|
+
}
|
|
10
|
+
// Checks what an author signed against the author's own chain. The server runs this before assigning a position.
|
|
11
|
+
export function authorChainFault(fields, head) {
|
|
12
|
+
const expectedSeq = (head?.seq ?? 0) + 1;
|
|
13
|
+
if (fields.authorSeq !== expectedSeq)
|
|
14
|
+
return "bad_author_seq";
|
|
15
|
+
if (!equalBytes(fields.prevOwnHash, head?.hash ?? ZERO_HASH))
|
|
16
|
+
return "bad_author_chain";
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
export class ChainVerifier {
|
|
20
|
+
#parties;
|
|
21
|
+
#serverId;
|
|
22
|
+
#keysById = new Map();
|
|
23
|
+
#authors = new Map();
|
|
24
|
+
#roots = [EMPTY_ROOT];
|
|
25
|
+
#merkle = new RunningMerkle();
|
|
26
|
+
#closed = new Set();
|
|
27
|
+
#lastAckTime = 0;
|
|
28
|
+
constructor(parties) {
|
|
29
|
+
this.#parties = parties;
|
|
30
|
+
this.#serverId = identityId(parties.server);
|
|
31
|
+
for (const identity of parties.participants)
|
|
32
|
+
this.#keysById.set(toHex(identityId(identity)), identity);
|
|
33
|
+
}
|
|
34
|
+
get position() {
|
|
35
|
+
return this.#merkle.size;
|
|
36
|
+
}
|
|
37
|
+
get root() {
|
|
38
|
+
return this.#merkle.root();
|
|
39
|
+
}
|
|
40
|
+
get lastAckTime() {
|
|
41
|
+
return this.#lastAckTime;
|
|
42
|
+
}
|
|
43
|
+
hasClosed(authorId) {
|
|
44
|
+
return this.#closed.has(toHex(authorId));
|
|
45
|
+
}
|
|
46
|
+
rootAt(position) {
|
|
47
|
+
return this.#roots[position];
|
|
48
|
+
}
|
|
49
|
+
authorHead(authorId) {
|
|
50
|
+
return this.#authors.get(toHex(authorId));
|
|
51
|
+
}
|
|
52
|
+
// Runs every check, and advances only if all of them pass.
|
|
53
|
+
async check(item) {
|
|
54
|
+
const { fields, signature, bytes, ack, ackSignature, ackBytes } = item;
|
|
55
|
+
if (!equalBytes(fields.sessionId, this.#parties.sessionId))
|
|
56
|
+
return "wrong_session";
|
|
57
|
+
if (!equalBytes(fields.serverId, this.#serverId))
|
|
58
|
+
return "entry_wrong_server";
|
|
59
|
+
const author = this.#keysById.get(toHex(fields.authorId));
|
|
60
|
+
if (!author)
|
|
61
|
+
return "not_participant";
|
|
62
|
+
const hash = structureHash(bytes);
|
|
63
|
+
if (ack.position !== this.position + 1)
|
|
64
|
+
return "bad_position";
|
|
65
|
+
if (!equalBytes(ack.serverId, this.#serverId))
|
|
66
|
+
return "ack_wrong_server";
|
|
67
|
+
if (!equalBytes(ack.sessionId, this.#parties.sessionId))
|
|
68
|
+
return "ack_wrong_session";
|
|
69
|
+
if (!equalBytes(ack.entryHash, hash))
|
|
70
|
+
return "ack_wrong_entry";
|
|
71
|
+
if (this.#closed.has(toHex(fields.authorId)))
|
|
72
|
+
return "entry_after_close";
|
|
73
|
+
// The author's not_after binds the server, whose ack carries the time. A refused message can't be landed later,
|
|
74
|
+
// and the time can't be pushed back to get under it, because acks never go backwards.
|
|
75
|
+
if (ack.time < this.#lastAckTime)
|
|
76
|
+
return "ack_time_backwards";
|
|
77
|
+
if (ack.time > fields.notAfter)
|
|
78
|
+
return "entry_expired";
|
|
79
|
+
const chainFault = authorChainFault(fields, this.#authors.get(toHex(fields.authorId)));
|
|
80
|
+
if (chainFault)
|
|
81
|
+
return chainFault;
|
|
82
|
+
if (fields.readPosition > this.position)
|
|
83
|
+
return "read_beyond_tip";
|
|
84
|
+
const readRoot = this.#roots[fields.readPosition];
|
|
85
|
+
if (!readRoot || !equalBytes(fields.readRoot, readRoot))
|
|
86
|
+
return "bad_read_root";
|
|
87
|
+
const next = RunningMerkle.fromBytes(this.position, this.#merkle.toBytes());
|
|
88
|
+
if (!equalBytes(ack.root, next.append(hash)))
|
|
89
|
+
return "ack_wrong_root";
|
|
90
|
+
if (!(await verifySignature(author, "cello-entry", bytes, signature)))
|
|
91
|
+
return "bad_entry_signature";
|
|
92
|
+
if (!(await verifySignature(this.#parties.server, "cello-ack", ackBytes, ackSignature)))
|
|
93
|
+
return "bad_ack_signature";
|
|
94
|
+
this.adopt(fields, hash, ack.time);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
// Rebuilds state from rows this machine already checked and stored, without repeating the signature work.
|
|
98
|
+
adopt(fields, hash, ackTime) {
|
|
99
|
+
const root = this.#merkle.append(hash);
|
|
100
|
+
this.#roots.push(root);
|
|
101
|
+
this.#authors.set(toHex(fields.authorId), { seq: fields.authorSeq, hash });
|
|
102
|
+
if (fields.kind === EntryKind.close)
|
|
103
|
+
this.#closed.add(toHex(fields.authorId));
|
|
104
|
+
this.#lastAckTime = ackTime;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Two acks at one position, both signed by the server, are server misbehaviour anyone can check with its public key.
|
|
108
|
+
export async function provesTwoAcks(server, a, b) {
|
|
109
|
+
if (equalBytes(a.bytes, b.bytes))
|
|
110
|
+
return false;
|
|
111
|
+
if (a.fields.position !== b.fields.position || !equalBytes(a.fields.sessionId, b.fields.sessionId))
|
|
112
|
+
return false;
|
|
113
|
+
const serverId = identityId(server);
|
|
114
|
+
if (!equalBytes(a.fields.serverId, serverId) || !equalBytes(b.fields.serverId, serverId))
|
|
115
|
+
return false;
|
|
116
|
+
return (await verifySignature(server, "cello-ack", a.bytes, a.signature)) && (await verifySignature(server, "cello-ack", b.bytes, b.signature));
|
|
117
|
+
}
|
|
118
|
+
export async function verifyTranscript(parties, items) {
|
|
119
|
+
const verifier = new ChainVerifier(parties);
|
|
120
|
+
for (const item of items) {
|
|
121
|
+
const fault = await verifier.check(item);
|
|
122
|
+
if (fault)
|
|
123
|
+
return { ok: false, position: verifier.position, root: verifier.root, fault, faultAt: item.ack.position };
|
|
124
|
+
}
|
|
125
|
+
return { ok: true, position: verifier.position, root: verifier.root };
|
|
126
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type DualSignature, type PublicIdentity, type Signer } from "./identity.ts";
|
|
2
|
+
import { type ChannelInfoFields, type ChannelKeyEntryFields, type ChannelMemberKeyFields, type ChannelPostAckFields, type ChannelPostFields, type ChannelRecordFields, type ChannelRosterFields, type ChannelStateFields } from "./structures.ts";
|
|
3
|
+
import { type WireSigned } from "./wire.ts";
|
|
4
|
+
export declare const channelInfoCodec: {
|
|
5
|
+
encode(value: {
|
|
6
|
+
fields: ChannelInfoFields;
|
|
7
|
+
signature: DualSignature;
|
|
8
|
+
bytes?: Uint8Array;
|
|
9
|
+
}): WireSigned;
|
|
10
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelInfoFields>;
|
|
11
|
+
};
|
|
12
|
+
export declare const channelPostCodec: {
|
|
13
|
+
encode(value: {
|
|
14
|
+
fields: ChannelPostFields;
|
|
15
|
+
signature: DualSignature;
|
|
16
|
+
bytes?: Uint8Array;
|
|
17
|
+
}): WireSigned;
|
|
18
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelPostFields>;
|
|
19
|
+
};
|
|
20
|
+
export declare const channelPostAckCodec: {
|
|
21
|
+
encode(value: {
|
|
22
|
+
fields: ChannelPostAckFields;
|
|
23
|
+
signature: DualSignature;
|
|
24
|
+
bytes?: Uint8Array;
|
|
25
|
+
}): WireSigned;
|
|
26
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelPostAckFields>;
|
|
27
|
+
};
|
|
28
|
+
export declare const channelStateCodec: {
|
|
29
|
+
encode(value: {
|
|
30
|
+
fields: ChannelStateFields;
|
|
31
|
+
signature: DualSignature;
|
|
32
|
+
bytes?: Uint8Array;
|
|
33
|
+
}): WireSigned;
|
|
34
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelStateFields>;
|
|
35
|
+
};
|
|
36
|
+
export declare const channelMemberKeyCodec: {
|
|
37
|
+
encode(value: {
|
|
38
|
+
fields: ChannelMemberKeyFields;
|
|
39
|
+
signature: DualSignature;
|
|
40
|
+
bytes?: Uint8Array;
|
|
41
|
+
}): WireSigned;
|
|
42
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelMemberKeyFields>;
|
|
43
|
+
};
|
|
44
|
+
export declare const channelRosterCodec: {
|
|
45
|
+
encode(value: {
|
|
46
|
+
fields: ChannelRosterFields;
|
|
47
|
+
signature: DualSignature;
|
|
48
|
+
bytes?: Uint8Array;
|
|
49
|
+
}): WireSigned;
|
|
50
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelRosterFields>;
|
|
51
|
+
};
|
|
52
|
+
export declare const channelKeyEntryCodec: {
|
|
53
|
+
encode(value: {
|
|
54
|
+
fields: ChannelKeyEntryFields;
|
|
55
|
+
signature: DualSignature;
|
|
56
|
+
bytes?: Uint8Array;
|
|
57
|
+
}): WireSigned;
|
|
58
|
+
decode(value: unknown, name?: string): import("./wire.ts").Signed<ChannelKeyEntryFields>;
|
|
59
|
+
};
|
|
60
|
+
export declare function hashBlob(blob: Uint8Array): Uint8Array;
|
|
61
|
+
export declare function postHash(bytes: Uint8Array): Uint8Array;
|
|
62
|
+
export interface ChannelRecordFile {
|
|
63
|
+
bytes: string;
|
|
64
|
+
channel: Record<string, string | number>;
|
|
65
|
+
admin: Record<string, string | number>;
|
|
66
|
+
channelSignature: Record<string, string | number>;
|
|
67
|
+
adminSignature: Record<string, string | number>;
|
|
68
|
+
}
|
|
69
|
+
export interface ChannelRecord {
|
|
70
|
+
fields: ChannelRecordFields;
|
|
71
|
+
channel: PublicIdentity;
|
|
72
|
+
admin: PublicIdentity;
|
|
73
|
+
}
|
|
74
|
+
export declare function signRecord(channel: Signer, admin: Signer, visibility: number): Promise<ChannelRecordFile>;
|
|
75
|
+
export declare function readRecord(raw: unknown, expectedChannelId?: Uint8Array): Promise<ChannelRecord | null>;
|
|
76
|
+
export declare function signInfo(channel: Signer, fields: ChannelInfoFields): Promise<WireSigned>;
|
|
77
|
+
export declare function readInfo(raw: unknown, record: ChannelRecord): Promise<ChannelInfoFields | null>;
|
|
78
|
+
export declare function idsIn(list: Uint8Array): Uint8Array[];
|
|
79
|
+
export declare function includesId(list: Uint8Array, id: Uint8Array): boolean;
|
|
80
|
+
export declare function namedToPost(info: ChannelInfoFields, adminId: Uint8Array, authorId: Uint8Array): boolean;
|
|
81
|
+
export interface PostOnWire {
|
|
82
|
+
post: WireSigned;
|
|
83
|
+
title: string;
|
|
84
|
+
body: string;
|
|
85
|
+
}
|
|
86
|
+
export interface CheckedPost {
|
|
87
|
+
fields: ChannelPostFields;
|
|
88
|
+
signature: DualSignature;
|
|
89
|
+
bytes: Uint8Array;
|
|
90
|
+
title: Uint8Array;
|
|
91
|
+
body: Uint8Array;
|
|
92
|
+
}
|
|
93
|
+
export type PostFault = "bad_post" | "bad_signature";
|
|
94
|
+
export declare function checkPost(raw: unknown, author: PublicIdentity, channelId: Uint8Array): Promise<CheckedPost | PostFault>;
|
|
95
|
+
export declare function readPostAck(raw: unknown, server: PublicIdentity, channelId: Uint8Array): Promise<ChannelPostAckFields | null>;
|
|
96
|
+
export declare function readState(raw: unknown, server: PublicIdentity, channelId: Uint8Array): Promise<ChannelStateFields | null>;
|
|
97
|
+
export interface RosterMemberFile {
|
|
98
|
+
identity: Record<string, string | number>;
|
|
99
|
+
memberKey: WireSigned;
|
|
100
|
+
}
|
|
101
|
+
export interface RosterFile {
|
|
102
|
+
roster: WireSigned;
|
|
103
|
+
members: RosterMemberFile[];
|
|
104
|
+
}
|
|
105
|
+
export interface SealKeys {
|
|
106
|
+
x25519Public: Uint8Array;
|
|
107
|
+
mlKemPublic: Uint8Array;
|
|
108
|
+
}
|
|
109
|
+
export interface OpenKeys extends SealKeys {
|
|
110
|
+
x25519Secret: Uint8Array;
|
|
111
|
+
mlKemSeed: Uint8Array;
|
|
112
|
+
}
|
|
113
|
+
export interface RosterMember {
|
|
114
|
+
agentId: Uint8Array;
|
|
115
|
+
keys: SealKeys;
|
|
116
|
+
}
|
|
117
|
+
export interface CheckedRoster {
|
|
118
|
+
fields: ChannelRosterFields;
|
|
119
|
+
hash: Uint8Array;
|
|
120
|
+
members: RosterMember[];
|
|
121
|
+
}
|
|
122
|
+
export declare function signMemberKey(member: Signer, channelId: Uint8Array, keys: SealKeys, requestedAt: number): Promise<RosterMemberFile>;
|
|
123
|
+
export declare function readMemberKey(raw: unknown, channelId: Uint8Array): Promise<{
|
|
124
|
+
agentId: Uint8Array;
|
|
125
|
+
keys: SealKeys;
|
|
126
|
+
requestedAt: number;
|
|
127
|
+
} | null>;
|
|
128
|
+
export declare function signRoster(channel: Signer, previous: {
|
|
129
|
+
revision: number;
|
|
130
|
+
hash: Uint8Array;
|
|
131
|
+
} | null, generation: number, members: RosterMemberFile[]): Promise<RosterFile>;
|
|
132
|
+
export declare function readRoster(raw: unknown, channel: PublicIdentity): Promise<CheckedRoster | null>;
|
|
133
|
+
export declare function rosterFollows(previous: {
|
|
134
|
+
fields: ChannelRosterFields;
|
|
135
|
+
hash: Uint8Array;
|
|
136
|
+
} | null, next: {
|
|
137
|
+
fields: ChannelRosterFields;
|
|
138
|
+
}): boolean;
|
|
139
|
+
export declare function inRoster(roster: {
|
|
140
|
+
members: readonly RosterMember[];
|
|
141
|
+
}, agentId: Uint8Array): RosterMember | undefined;
|
|
142
|
+
export interface KeyEntryFile {
|
|
143
|
+
entry: WireSigned;
|
|
144
|
+
sealed: string;
|
|
145
|
+
}
|
|
146
|
+
export declare function sealTo(to: SealKeys, plaintext: Uint8Array): Promise<string>;
|
|
147
|
+
export declare function openSealed(keys: OpenKeys, sealed: string): Promise<Uint8Array | null>;
|
|
148
|
+
export declare function sealKeyEntry(channel: Signer, roster: CheckedRoster, member: RosterMember, generation: number, groupKey: Uint8Array): Promise<KeyEntryFile>;
|
|
149
|
+
export declare function readKeyEntry(raw: unknown, channel: PublicIdentity): Promise<{
|
|
150
|
+
fields: ChannelKeyEntryFields;
|
|
151
|
+
sealed: string;
|
|
152
|
+
} | null>;
|
|
153
|
+
export declare function openKeyEntry(raw: unknown, channel: PublicIdentity, memberId: Uint8Array, keys: OpenKeys, generation: number): Promise<Uint8Array | null>;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// What a channel's signed things hold, and how anyone checks them with keys they already have.
|
|
2
|
+
// The server and every reader run these same checks, because a reader doesn't trust the server with a member list or a key.
|
|
3
|
+
import { x25519 } from "@noble/curves/ed25519.js";
|
|
4
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
5
|
+
import { openSessionContent, sealSessionContent } from "./aead.js";
|
|
6
|
+
import { HASH_BYTES, ZERO_HASH, equalBytes } from "./encode.js";
|
|
7
|
+
import { identityId, verifySignature } from "./identity.js";
|
|
8
|
+
import { deriveSessionSecrets } from "./key-agreement.js";
|
|
9
|
+
import { mlKemDecapsulate, mlKemEncapsulate } from "./ml-kem.js";
|
|
10
|
+
import { ChannelPosting, ChannelVisibility, channelInfoStructure, channelKeyEntryStructure, channelMemberKeyStructure, channelPostAckStructure, channelPostStructure, channelRecordBytes, channelRecordStructure, channelRosterStructure, channelStateStructure, rosterMemberBytes, rosterMembersBytes, } from "./structures.js";
|
|
11
|
+
import { fromB64, readStructure, identityCodec, signatureCodec, signedCodec, toB64 } from "./wire.js";
|
|
12
|
+
const ENC = new TextEncoder();
|
|
13
|
+
export const channelInfoCodec = signedCodec(channelInfoStructure);
|
|
14
|
+
export const channelPostCodec = signedCodec(channelPostStructure);
|
|
15
|
+
export const channelPostAckCodec = signedCodec(channelPostAckStructure);
|
|
16
|
+
export const channelStateCodec = signedCodec(channelStateStructure);
|
|
17
|
+
export const channelMemberKeyCodec = signedCodec(channelMemberKeyStructure);
|
|
18
|
+
export const channelRosterCodec = signedCodec(channelRosterStructure);
|
|
19
|
+
export const channelKeyEntryCodec = signedCodec(channelKeyEntryStructure);
|
|
20
|
+
function field(value, name) {
|
|
21
|
+
if (typeof value !== "object" || value === null)
|
|
22
|
+
return undefined;
|
|
23
|
+
return value[name];
|
|
24
|
+
}
|
|
25
|
+
// Bad input from the other side is a refusal, not a crash: every read below answers null for it.
|
|
26
|
+
function tryRead(work) {
|
|
27
|
+
try {
|
|
28
|
+
return work();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function hashBlob(blob) {
|
|
35
|
+
return sha256(blob);
|
|
36
|
+
}
|
|
37
|
+
export function postHash(bytes) {
|
|
38
|
+
return sha256(bytes);
|
|
39
|
+
}
|
|
40
|
+
export async function signRecord(channel, admin, visibility) {
|
|
41
|
+
const fields = { channelId: channel.id, adminId: admin.id, visibility };
|
|
42
|
+
const bytes = channelRecordBytes(fields);
|
|
43
|
+
return {
|
|
44
|
+
bytes: toB64(bytes),
|
|
45
|
+
channel: identityCodec.encode(channel.publicIdentity),
|
|
46
|
+
admin: identityCodec.encode(admin.publicIdentity),
|
|
47
|
+
channelSignature: signatureCodec.encode(await channel.sign("cello-channel-record", bytes)),
|
|
48
|
+
adminSignature: signatureCodec.encode(await admin.sign("cello-channel-record", bytes)),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function readRecordBytes(raw) {
|
|
52
|
+
const bytes = fromB64(raw, "record");
|
|
53
|
+
return { fields: readStructure(channelRecordStructure, bytes, "record"), bytes };
|
|
54
|
+
}
|
|
55
|
+
// Self-certifying: a channel's id is the hash of the key that signed this, so whoever served it can't have changed it.
|
|
56
|
+
export async function readRecord(raw, expectedChannelId) {
|
|
57
|
+
const parsed = tryRead(() => ({
|
|
58
|
+
...readRecordBytes(field(raw, "bytes")),
|
|
59
|
+
channel: identityCodec.decode(field(raw, "channel")),
|
|
60
|
+
admin: identityCodec.decode(field(raw, "admin")),
|
|
61
|
+
channelSignature: signatureCodec.decode(field(raw, "channelSignature")),
|
|
62
|
+
adminSignature: signatureCodec.decode(field(raw, "adminSignature")),
|
|
63
|
+
}));
|
|
64
|
+
if (!parsed)
|
|
65
|
+
return null;
|
|
66
|
+
if (parsed.fields.visibility !== ChannelVisibility.public && parsed.fields.visibility !== ChannelVisibility.private)
|
|
67
|
+
return null;
|
|
68
|
+
const { bytes } = parsed;
|
|
69
|
+
const ids = tryRead(() => ({ channel: identityId(parsed.channel), admin: identityId(parsed.admin) }));
|
|
70
|
+
if (!ids)
|
|
71
|
+
return null;
|
|
72
|
+
if (!equalBytes(ids.channel, parsed.fields.channelId) || !equalBytes(ids.admin, parsed.fields.adminId))
|
|
73
|
+
return null;
|
|
74
|
+
if (expectedChannelId && !equalBytes(parsed.fields.channelId, expectedChannelId))
|
|
75
|
+
return null;
|
|
76
|
+
if (!(await verifySignature(parsed.channel, "cello-channel-record", bytes, parsed.channelSignature)))
|
|
77
|
+
return null;
|
|
78
|
+
if (!(await verifySignature(parsed.admin, "cello-channel-record", bytes, parsed.adminSignature)))
|
|
79
|
+
return null;
|
|
80
|
+
return { fields: parsed.fields, channel: parsed.channel, admin: parsed.admin };
|
|
81
|
+
}
|
|
82
|
+
export async function signInfo(channel, fields) {
|
|
83
|
+
return channelInfoCodec.encode({ fields, signature: await channel.sign("cello-channel-info", channelInfoStructure.encode(fields)) });
|
|
84
|
+
}
|
|
85
|
+
export async function readInfo(raw, record) {
|
|
86
|
+
const signed = tryRead(() => channelInfoCodec.decode(raw));
|
|
87
|
+
if (!signed || !equalBytes(signed.fields.channelId, record.fields.channelId))
|
|
88
|
+
return null;
|
|
89
|
+
if (!Object.values(ChannelPosting).includes(signed.fields.posting))
|
|
90
|
+
return null;
|
|
91
|
+
if (signed.fields.retentionMs < 1 || signed.fields.generation < 1)
|
|
92
|
+
return null;
|
|
93
|
+
if (!(await verifySignature(record.channel, "cello-channel-info", signed.bytes, signed.signature)))
|
|
94
|
+
return null;
|
|
95
|
+
return signed.fields;
|
|
96
|
+
}
|
|
97
|
+
export function idsIn(list) {
|
|
98
|
+
const ids = [];
|
|
99
|
+
for (let at = 0; at + HASH_BYTES <= list.length; at += HASH_BYTES)
|
|
100
|
+
ids.push(list.subarray(at, at + HASH_BYTES));
|
|
101
|
+
return ids;
|
|
102
|
+
}
|
|
103
|
+
export function includesId(list, id) {
|
|
104
|
+
return idsIn(list).some((held) => equalBytes(held, id));
|
|
105
|
+
}
|
|
106
|
+
// Who the channel's own signed settings let post. Being a member is a separate check, which only the caller can make.
|
|
107
|
+
export function namedToPost(info, adminId, authorId) {
|
|
108
|
+
if (equalBytes(adminId, authorId))
|
|
109
|
+
return true;
|
|
110
|
+
if (info.posting === ChannelPosting.posters)
|
|
111
|
+
return includesId(info.posters, authorId);
|
|
112
|
+
return info.posting === ChannelPosting.members;
|
|
113
|
+
}
|
|
114
|
+
// The author's own signature, and that these are the title and body it signed. Rights and size are the server's next check.
|
|
115
|
+
export async function checkPost(raw, author, channelId) {
|
|
116
|
+
const parsed = tryRead(() => {
|
|
117
|
+
const signed = channelPostCodec.decode(field(raw, "post"));
|
|
118
|
+
return { signed, title: fromB64(field(raw, "title"), "title"), body: fromB64(field(raw, "body"), "body") };
|
|
119
|
+
});
|
|
120
|
+
if (!parsed)
|
|
121
|
+
return "bad_post";
|
|
122
|
+
const { fields, signature, bytes } = parsed.signed;
|
|
123
|
+
if (!equalBytes(fields.channelId, channelId) || fields.authorSeq < 1 || fields.generation < 1)
|
|
124
|
+
return "bad_post";
|
|
125
|
+
if (!equalBytes(hashBlob(parsed.title), fields.titleHash) || !equalBytes(hashBlob(parsed.body), fields.bodyHash))
|
|
126
|
+
return "bad_post";
|
|
127
|
+
const authorId = tryRead(() => identityId(author));
|
|
128
|
+
if (!authorId || !equalBytes(authorId, fields.authorId))
|
|
129
|
+
return "bad_signature";
|
|
130
|
+
if (!(await verifySignature(author, "cello-channel-post", bytes, signature)))
|
|
131
|
+
return "bad_signature";
|
|
132
|
+
return { fields, signature, bytes, title: parsed.title, body: parsed.body };
|
|
133
|
+
}
|
|
134
|
+
export async function readPostAck(raw, server, channelId) {
|
|
135
|
+
const signed = tryRead(() => channelPostAckCodec.decode(raw));
|
|
136
|
+
if (!signed || !equalBytes(signed.fields.channelId, channelId))
|
|
137
|
+
return null;
|
|
138
|
+
const serverId = tryRead(() => identityId(server));
|
|
139
|
+
if (!serverId || !equalBytes(serverId, signed.fields.serverId))
|
|
140
|
+
return null;
|
|
141
|
+
return await verifySignature(server, "cello-channel-post-ack", signed.bytes, signed.signature) ? signed.fields : null;
|
|
142
|
+
}
|
|
143
|
+
export async function readState(raw, server, channelId) {
|
|
144
|
+
const signed = tryRead(() => channelStateCodec.decode(raw));
|
|
145
|
+
if (!signed || !equalBytes(signed.fields.channelId, channelId))
|
|
146
|
+
return null;
|
|
147
|
+
const serverId = tryRead(() => identityId(server));
|
|
148
|
+
if (!serverId || !equalBytes(serverId, signed.fields.serverId) || signed.fields.firstHeld < 1)
|
|
149
|
+
return null;
|
|
150
|
+
return await verifySignature(server, "cello-channel-state", signed.bytes, signed.signature) ? signed.fields : null;
|
|
151
|
+
}
|
|
152
|
+
// Over what each member signed, as they signed it, so nothing depends on how JSON was stored.
|
|
153
|
+
function membersHash(members) {
|
|
154
|
+
return sha256(rosterMembersBytes(members.map((member) => {
|
|
155
|
+
const identity = identityCodec.decode(member.identity);
|
|
156
|
+
const signed = channelMemberKeyCodec.decode(member.memberKey);
|
|
157
|
+
return sha256(rosterMemberBytes({ ed: identity.ed, pq: identity.pq, memberKey: signed.bytes, signatureEd: signed.signature.ed, signaturePq: signed.signature.pq }));
|
|
158
|
+
})));
|
|
159
|
+
}
|
|
160
|
+
export async function signMemberKey(member, channelId, keys, requestedAt) {
|
|
161
|
+
const fields = { channelId, agentId: member.id, x25519Public: keys.x25519Public, mlKemPublic: keys.mlKemPublic, requestedAt };
|
|
162
|
+
return {
|
|
163
|
+
identity: identityCodec.encode(member.publicIdentity),
|
|
164
|
+
memberKey: channelMemberKeyCodec.encode({ fields, signature: await member.sign("cello-channel-member-key", channelMemberKeyStructure.encode(fields)) }),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
// Null unless the identity signed this member key, for this channel, itself.
|
|
168
|
+
export async function readMemberKey(raw, channelId) {
|
|
169
|
+
const identity = tryRead(() => identityCodec.decode(field(raw, "identity")));
|
|
170
|
+
const signed = tryRead(() => channelMemberKeyCodec.decode(field(raw, "memberKey")));
|
|
171
|
+
if (!identity || !signed)
|
|
172
|
+
return null;
|
|
173
|
+
const agentId = tryRead(() => identityId(identity));
|
|
174
|
+
if (!agentId)
|
|
175
|
+
return null;
|
|
176
|
+
if (!equalBytes(agentId, signed.fields.agentId) || !equalBytes(signed.fields.channelId, channelId))
|
|
177
|
+
return null;
|
|
178
|
+
if (!(await verifySignature(identity, "cello-channel-member-key", signed.bytes, signed.signature)))
|
|
179
|
+
return null;
|
|
180
|
+
return { agentId, keys: { x25519Public: signed.fields.x25519Public, mlKemPublic: signed.fields.mlKemPublic }, requestedAt: signed.fields.requestedAt };
|
|
181
|
+
}
|
|
182
|
+
// Chained to the roster before it, or to nothing for the first.
|
|
183
|
+
export async function signRoster(channel, previous, generation, members) {
|
|
184
|
+
const fields = { channelId: channel.id, revision: (previous?.revision ?? 0) + 1, generation, prevHash: previous?.hash ?? ZERO_HASH, membersHash: membersHash(members) };
|
|
185
|
+
return { roster: channelRosterCodec.encode({ fields, signature: await channel.sign("cello-channel-roster", channelRosterStructure.encode(fields)) }), members };
|
|
186
|
+
}
|
|
187
|
+
// Checks the channel key's signature, and that each listed member signed their own key. Null for anything else.
|
|
188
|
+
export async function readRoster(raw, channel) {
|
|
189
|
+
const signed = tryRead(() => channelRosterCodec.decode(field(raw, "roster")));
|
|
190
|
+
const list = field(raw, "members");
|
|
191
|
+
if (!signed || !Array.isArray(list))
|
|
192
|
+
return null;
|
|
193
|
+
const channelId = tryRead(() => identityId(channel));
|
|
194
|
+
if (!channelId || !equalBytes(signed.fields.channelId, channelId))
|
|
195
|
+
return null;
|
|
196
|
+
if (!(await verifySignature(channel, "cello-channel-roster", signed.bytes, signed.signature)))
|
|
197
|
+
return null;
|
|
198
|
+
const hashed = tryRead(() => membersHash(list));
|
|
199
|
+
if (!hashed || !equalBytes(hashed, signed.fields.membersHash))
|
|
200
|
+
return null;
|
|
201
|
+
const members = [];
|
|
202
|
+
for (const entry of list) {
|
|
203
|
+
const checked = await readMemberKey(entry, channelId);
|
|
204
|
+
if (!checked)
|
|
205
|
+
return null;
|
|
206
|
+
members.push({ agentId: checked.agentId, keys: checked.keys });
|
|
207
|
+
}
|
|
208
|
+
return { fields: signed.fields, hash: sha256(signed.bytes), members };
|
|
209
|
+
}
|
|
210
|
+
export function rosterFollows(previous, next) {
|
|
211
|
+
if (!previous)
|
|
212
|
+
return next.fields.revision === 1 && equalBytes(next.fields.prevHash, ZERO_HASH);
|
|
213
|
+
return next.fields.revision === previous.fields.revision + 1 && equalBytes(next.fields.prevHash, previous.hash) && next.fields.generation >= previous.fields.generation;
|
|
214
|
+
}
|
|
215
|
+
export function inRoster(roster, agentId) {
|
|
216
|
+
return roster.members.find((member) => equalBytes(member.agentId, agentId));
|
|
217
|
+
}
|
|
218
|
+
const SEAL_DOMAIN = ENC.encode("cello-channel-seal");
|
|
219
|
+
function concat(a, b) {
|
|
220
|
+
const out = new Uint8Array(a.length + b.length);
|
|
221
|
+
out.set(a, 0);
|
|
222
|
+
out.set(b, a.length);
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
// Both key agreements, as in a session, so post-quantum protection covers group keys and join requests too.
|
|
226
|
+
export async function sealTo(to, plaintext) {
|
|
227
|
+
const ephemeral = x25519.utils.randomSecretKey();
|
|
228
|
+
const { ciphertext, sharedSecret } = await mlKemEncapsulate(to.mlKemPublic);
|
|
229
|
+
const { contentKey } = deriveSessionSecrets({
|
|
230
|
+
ownEphemeralSecret: ephemeral,
|
|
231
|
+
peerEphemeralPublic: to.x25519Public,
|
|
232
|
+
sessionId: SEAL_DOMAIN,
|
|
233
|
+
extraSharedSecret: sharedSecret,
|
|
234
|
+
pqTranscript: concat(ciphertext, to.mlKemPublic),
|
|
235
|
+
});
|
|
236
|
+
const box = sealSessionContent(contentKey, plaintext);
|
|
237
|
+
const eph = x25519.getPublicKey(ephemeral);
|
|
238
|
+
contentKey.fill(0);
|
|
239
|
+
ephemeral.fill(0);
|
|
240
|
+
return JSON.stringify({ eph: toB64(eph), kem: toB64(ciphertext), box: toB64(box) });
|
|
241
|
+
}
|
|
242
|
+
export async function openSealed(keys, sealed) {
|
|
243
|
+
const parts = tryRead(() => {
|
|
244
|
+
const raw = JSON.parse(sealed);
|
|
245
|
+
return { eph: fromB64(field(raw, "eph"), "eph"), kem: fromB64(field(raw, "kem"), "kem"), box: fromB64(field(raw, "box"), "box") };
|
|
246
|
+
});
|
|
247
|
+
if (!parts)
|
|
248
|
+
return null;
|
|
249
|
+
try {
|
|
250
|
+
const sharedSecret = await mlKemDecapsulate(keys.mlKemSeed, parts.kem);
|
|
251
|
+
const { contentKey } = deriveSessionSecrets({
|
|
252
|
+
ownEphemeralSecret: keys.x25519Secret,
|
|
253
|
+
peerEphemeralPublic: parts.eph,
|
|
254
|
+
sessionId: SEAL_DOMAIN,
|
|
255
|
+
extraSharedSecret: sharedSecret,
|
|
256
|
+
pqTranscript: concat(parts.kem, keys.mlKemPublic),
|
|
257
|
+
});
|
|
258
|
+
return openSessionContent(contentKey, parts.box);
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// The only way a group key gets sealed: to a member of a roster that has passed readRoster.
|
|
265
|
+
export async function sealKeyEntry(channel, roster, member, generation, groupKey) {
|
|
266
|
+
const sealed = await sealTo(member.keys, ENC.encode(JSON.stringify({ generation, key: toB64(groupKey) })));
|
|
267
|
+
const fields = { channelId: channel.id, generation, memberId: member.agentId, rosterHash: roster.hash, sealedHash: sha256(ENC.encode(sealed)) };
|
|
268
|
+
return { entry: channelKeyEntryCodec.encode({ fields, signature: await channel.sign("cello-channel-key-entry", channelKeyEntryStructure.encode(fields)) }), sealed };
|
|
269
|
+
}
|
|
270
|
+
// What the server needs to see of an entry to file it, with no key to open it. Null if the channel key didn't sign it.
|
|
271
|
+
export async function readKeyEntry(raw, channel) {
|
|
272
|
+
const signed = tryRead(() => channelKeyEntryCodec.decode(field(raw, "entry")));
|
|
273
|
+
const sealed = field(raw, "sealed");
|
|
274
|
+
if (!signed || typeof sealed !== "string")
|
|
275
|
+
return null;
|
|
276
|
+
const channelId = tryRead(() => identityId(channel));
|
|
277
|
+
if (!channelId || !equalBytes(signed.fields.channelId, channelId))
|
|
278
|
+
return null;
|
|
279
|
+
if (!equalBytes(signed.fields.sealedHash, sha256(ENC.encode(sealed))))
|
|
280
|
+
return null;
|
|
281
|
+
if (!(await verifySignature(channel, "cello-channel-key-entry", signed.bytes, signed.signature)))
|
|
282
|
+
return null;
|
|
283
|
+
return { fields: signed.fields, sealed };
|
|
284
|
+
}
|
|
285
|
+
// Null unless the channel key signed this for this member and generation, and it opens with this member's key.
|
|
286
|
+
export async function openKeyEntry(raw, channel, memberId, keys, generation) {
|
|
287
|
+
const entry = await readKeyEntry(raw, channel);
|
|
288
|
+
if (!entry || !equalBytes(entry.fields.memberId, memberId) || entry.fields.generation !== generation)
|
|
289
|
+
return null;
|
|
290
|
+
const opened = await openSealed(keys, entry.sealed);
|
|
291
|
+
if (!opened)
|
|
292
|
+
return null;
|
|
293
|
+
const value = tryRead(() => JSON.parse(new TextDecoder().decode(opened)));
|
|
294
|
+
if (field(value, "generation") !== generation)
|
|
295
|
+
return null;
|
|
296
|
+
const key = tryRead(() => fromB64(field(value, "key"), "key"));
|
|
297
|
+
return key?.length === 32 ? key : null;
|
|
298
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const HASH_BYTES = 32;
|
|
2
|
+
export declare const SESSION_ID_BYTES = 16;
|
|
3
|
+
export declare const ZERO_HASH: Uint8Array;
|
|
4
|
+
export declare function exact(name: string, value: Uint8Array, width: number): Uint8Array;
|
|
5
|
+
export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
6
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Small byte helpers. Signed and hashed bytes are built in structures.ts, as CBOR arrays.
|
|
2
|
+
export const HASH_BYTES = 32;
|
|
3
|
+
export const SESSION_ID_BYTES = 16;
|
|
4
|
+
export const ZERO_HASH = new Uint8Array(HASH_BYTES);
|
|
5
|
+
export function exact(name, value, width) {
|
|
6
|
+
if (!(value instanceof Uint8Array) || value.length !== width) {
|
|
7
|
+
throw new RangeError(`${name} must be ${width} bytes, got ${value instanceof Uint8Array ? value.length : "none"}`);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
export function equalBytes(a, b) {
|
|
12
|
+
if (a.length !== b.length)
|
|
13
|
+
return false;
|
|
14
|
+
let diff = 0;
|
|
15
|
+
for (let i = 0; i < a.length; i++)
|
|
16
|
+
diff |= a[i] ^ b[i];
|
|
17
|
+
return diff === 0;
|
|
18
|
+
}
|
|
19
|
+
export function toHex(bytes) {
|
|
20
|
+
return Buffer.from(bytes).toString("hex");
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const ED25519_SEED_BYTES = 32;
|
|
2
|
+
export declare const ED25519_PUBLIC_KEY_BYTES = 32;
|
|
3
|
+
export declare const ED25519_SIGNATURE_BYTES = 64;
|
|
4
|
+
export declare const CONTEXTS: readonly ["cello-register", "cello-agent-auth", "cello-visit", "cello-server-auth", "cello-session-offer", "cello-session-accept", "cello-session-refuse", "cello-agent-encryption-key", "cello-session-greeting", "cello-session-confirm", "cello-session-assignment", "cello-entry", "cello-ack", "cello-delivery-ack", "cello-seal-request", "cello-seal-certificate", "cello-seal-log-head", "cello-seal-key-binding", "cello-agent-status", "cello-agent-status-witness", "cello-channel-record", "cello-channel-info", "cello-channel-post", "cello-channel-post-ack", "cello-channel-state", "cello-channel-member-key", "cello-channel-roster", "cello-channel-key-entry", "cello-signal", "cello-issuer-list"];
|
|
5
|
+
export type SigningContext = (typeof CONTEXTS)[number];
|
|
6
|
+
export interface PublicIdentity {
|
|
7
|
+
ed: Uint8Array;
|
|
8
|
+
pq: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export interface DualSignature {
|
|
11
|
+
ed: Uint8Array;
|
|
12
|
+
pq: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
export interface IdentitySeeds {
|
|
15
|
+
ed: Uint8Array;
|
|
16
|
+
pq: Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
export interface Signer {
|
|
19
|
+
readonly publicIdentity: PublicIdentity;
|
|
20
|
+
readonly id: Uint8Array;
|
|
21
|
+
sign(context: SigningContext, bytes: Uint8Array): Promise<DualSignature>;
|
|
22
|
+
}
|
|
23
|
+
export declare function frame(context: SigningContext, bytes: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
24
|
+
export declare function identityId(pub: PublicIdentity): Uint8Array;
|
|
25
|
+
export declare function generateIdentitySeeds(): IdentitySeeds;
|
|
26
|
+
export declare function signerFromSeeds(seeds: IdentitySeeds): Promise<Signer>;
|
|
27
|
+
export declare function verifySignature(pub: PublicIdentity, context: SigningContext, bytes: Uint8Array, signature: DualSignature): Promise<boolean>;
|