@cello-protocol/cli 0.0.305 → 0.0.307

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.
Files changed (234) hide show
  1. package/.claude-plugin/marketplace.json +15 -0
  2. package/README.md +107 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +564 -0
  5. package/dist/daemon/account-page-assets.d.ts +4 -0
  6. package/dist/daemon/account-page-assets.js +160 -0
  7. package/dist/daemon/account-page.d.ts +14 -0
  8. package/dist/daemon/account-page.js +104 -0
  9. package/dist/daemon/address.d.ts +10 -0
  10. package/dist/daemon/address.js +34 -0
  11. package/dist/daemon/away.d.ts +31 -0
  12. package/dist/daemon/away.js +65 -0
  13. package/dist/daemon/channel-store.d.ts +112 -0
  14. package/dist/daemon/channel-store.js +284 -0
  15. package/dist/daemon/channels.d.ts +46 -0
  16. package/dist/daemon/channels.js +1049 -0
  17. package/dist/daemon/contacts.d.ts +26 -0
  18. package/dist/daemon/contacts.js +74 -0
  19. package/dist/daemon/engine.d.ts +80 -0
  20. package/dist/daemon/engine.js +2882 -0
  21. package/dist/daemon/errors.d.ts +5 -0
  22. package/dist/daemon/errors.js +16 -0
  23. package/dist/daemon/governance.d.ts +66 -0
  24. package/dist/daemon/governance.js +514 -0
  25. package/dist/daemon/guards.d.ts +36 -0
  26. package/dist/daemon/guards.js +140 -0
  27. package/dist/daemon/issuer-client.d.ts +56 -0
  28. package/dist/daemon/issuer-client.js +143 -0
  29. package/dist/daemon/link.d.ts +30 -0
  30. package/dist/daemon/link.js +191 -0
  31. package/dist/daemon/log.d.ts +1 -0
  32. package/dist/daemon/log.js +4 -0
  33. package/dist/daemon/main.d.ts +1 -0
  34. package/dist/daemon/main.js +511 -0
  35. package/dist/daemon/paths.d.ts +6 -0
  36. package/dist/daemon/paths.js +21 -0
  37. package/dist/daemon/pii.d.ts +24 -0
  38. package/dist/daemon/pii.js +146 -0
  39. package/dist/daemon/policy-cadence.d.ts +33 -0
  40. package/dist/daemon/policy-cadence.js +59 -0
  41. package/dist/daemon/policy-proposals.d.ts +41 -0
  42. package/dist/daemon/policy-proposals.js +83 -0
  43. package/dist/daemon/policy-store.d.ts +47 -0
  44. package/dist/daemon/policy-store.js +144 -0
  45. package/dist/daemon/presented.d.ts +36 -0
  46. package/dist/daemon/presented.js +94 -0
  47. package/dist/daemon/rate-limit.d.ts +17 -0
  48. package/dist/daemon/rate-limit.js +44 -0
  49. package/dist/daemon/reach.d.ts +63 -0
  50. package/dist/daemon/reach.js +207 -0
  51. package/dist/daemon/screening.d.ts +97 -0
  52. package/dist/daemon/screening.js +362 -0
  53. package/dist/daemon/settings.d.ts +125 -0
  54. package/dist/daemon/settings.js +73 -0
  55. package/dist/daemon/signal-rules.d.ts +55 -0
  56. package/dist/daemon/signal-rules.js +127 -0
  57. package/dist/daemon/signal-store.d.ts +53 -0
  58. package/dist/daemon/signal-store.js +114 -0
  59. package/dist/daemon/store.d.ts +188 -0
  60. package/dist/daemon/store.js +474 -0
  61. package/dist/daemon/tiers.d.ts +14 -0
  62. package/dist/daemon/tiers.js +9 -0
  63. package/dist/daemon/wallet.d.ts +73 -0
  64. package/dist/daemon/wallet.js +428 -0
  65. package/dist/daemon/who-label.d.ts +3 -0
  66. package/dist/daemon/who-label.js +11 -0
  67. package/dist/guidance.d.ts +39 -0
  68. package/dist/guidance.js +98 -0
  69. package/dist/hermes-bridge.d.ts +26 -0
  70. package/dist/hermes-bridge.js +180 -0
  71. package/dist/install-mcp.d.ts +6 -0
  72. package/dist/install-mcp.js +77 -0
  73. package/dist/ipc/client.d.ts +18 -0
  74. package/dist/ipc/client.js +107 -0
  75. package/dist/ipc/operations.d.ts +30 -0
  76. package/dist/ipc/operations.js +835 -0
  77. package/dist/ipc/protocol.d.ts +21 -0
  78. package/dist/ipc/protocol.js +1 -0
  79. package/dist/issuer-list-sign.d.ts +12 -0
  80. package/dist/issuer-list-sign.js +43 -0
  81. package/dist/local-operations.d.ts +2 -0
  82. package/dist/local-operations.js +73 -0
  83. package/dist/mcp-tools.d.ts +14 -0
  84. package/dist/mcp-tools.js +45 -0
  85. package/dist/mcp.d.ts +2 -0
  86. package/dist/mcp.js +155 -0
  87. package/dist/protocol/aead.d.ts +4 -0
  88. package/dist/protocol/aead.js +35 -0
  89. package/dist/protocol/cbor.d.ts +40 -0
  90. package/dist/protocol/cbor.js +106 -0
  91. package/dist/protocol/chain.d.ts +44 -0
  92. package/dist/protocol/chain.js +126 -0
  93. package/dist/protocol/channel.d.ts +153 -0
  94. package/dist/protocol/channel.js +298 -0
  95. package/dist/protocol/encode.d.ts +6 -0
  96. package/dist/protocol/encode.js +21 -0
  97. package/dist/protocol/identity.d.ts +27 -0
  98. package/dist/protocol/identity.js +94 -0
  99. package/dist/protocol/issuer-list.d.ts +56 -0
  100. package/dist/protocol/issuer-list.js +193 -0
  101. package/dist/protocol/issuer-roots.d.ts +6 -0
  102. package/dist/protocol/issuer-roots.js +10 -0
  103. package/dist/protocol/key-agreement.d.ts +20 -0
  104. package/dist/protocol/key-agreement.js +88 -0
  105. package/dist/protocol/merkle.d.ts +16 -0
  106. package/dist/protocol/merkle.js +166 -0
  107. package/dist/protocol/ml-dsa.d.ts +28 -0
  108. package/dist/protocol/ml-dsa.js +58 -0
  109. package/dist/protocol/ml-kem.d.ts +14 -0
  110. package/dist/protocol/ml-kem.js +57 -0
  111. package/dist/protocol/pq-errors.d.ts +9 -0
  112. package/dist/protocol/pq-errors.js +23 -0
  113. package/dist/protocol/pq-warnings.d.ts +1 -0
  114. package/dist/protocol/pq-warnings.js +18 -0
  115. package/dist/protocol/presented-signals.d.ts +17 -0
  116. package/dist/protocol/presented-signals.js +92 -0
  117. package/dist/protocol/salt.d.ts +5 -0
  118. package/dist/protocol/salt.js +47 -0
  119. package/dist/protocol/seal.d.ts +58 -0
  120. package/dist/protocol/seal.js +220 -0
  121. package/dist/protocol/signal.d.ts +54 -0
  122. package/dist/protocol/signal.js +266 -0
  123. package/dist/protocol/status.d.ts +41 -0
  124. package/dist/protocol/status.js +64 -0
  125. package/dist/protocol/structures.d.ts +359 -0
  126. package/dist/protocol/structures.js +296 -0
  127. package/dist/protocol/transcript.d.ts +61 -0
  128. package/dist/protocol/transcript.js +319 -0
  129. package/dist/protocol/wire.d.ts +212 -0
  130. package/dist/protocol/wire.js +161 -0
  131. package/dist/require-node.d.ts +1 -0
  132. package/dist/require-node.js +10 -0
  133. package/dist/screener/affordance.d.ts +1 -0
  134. package/dist/screener/affordance.js +2 -0
  135. package/dist/screener/classifier-selfcheck.d.ts +29 -0
  136. package/dist/screener/classifier-selfcheck.js +56 -0
  137. package/dist/screener/exfil.d.ts +11 -0
  138. package/dist/screener/exfil.js +45 -0
  139. package/dist/screener/gitleaks-rules.d.ts +9 -0
  140. package/dist/screener/gitleaks-rules.js +226 -0
  141. package/dist/screener/inbound.d.ts +25 -0
  142. package/dist/screener/inbound.js +102 -0
  143. package/dist/screener/injection-classifier-onnx.d.ts +20 -0
  144. package/dist/screener/injection-classifier-onnx.js +89 -0
  145. package/dist/screener/injection-classifier-wasm.d.ts +2 -0
  146. package/dist/screener/injection-classifier-wasm.js +97 -0
  147. package/dist/screener/injection-patterns.d.ts +8 -0
  148. package/dist/screener/injection-patterns.js +48 -0
  149. package/dist/screener/injection-windows.d.ts +9 -0
  150. package/dist/screener/injection-windows.js +37 -0
  151. package/dist/screener/language.d.ts +15 -0
  152. package/dist/screener/language.js +71 -0
  153. package/dist/screener/linear-regex.d.ts +8 -0
  154. package/dist/screener/linear-regex.js +27 -0
  155. package/dist/screener/model-installer.d.ts +14 -0
  156. package/dist/screener/model-installer.js +61 -0
  157. package/dist/screener/outbound.d.ts +19 -0
  158. package/dist/screener/outbound.js +62 -0
  159. package/dist/screener/sanitize.d.ts +44 -0
  160. package/dist/screener/sanitize.js +361 -0
  161. package/dist/screener/scan-variants.d.ts +5 -0
  162. package/dist/screener/scan-variants.js +146 -0
  163. package/dist/screener/screener-model-manifest.d.ts +16 -0
  164. package/dist/screener/screener-model-manifest.js +20 -0
  165. package/dist/screener/screener-state.d.ts +29 -0
  166. package/dist/screener/screener-state.js +119 -0
  167. package/dist/screener/secrets.d.ts +18 -0
  168. package/dist/screener/secrets.js +84 -0
  169. package/dist/screener/worker.d.ts +6 -0
  170. package/dist/screener/worker.js +83 -0
  171. package/dist/setup.d.ts +9 -0
  172. package/dist/setup.js +252 -0
  173. package/dist/shipped-issuer-list.d.ts +1 -0
  174. package/dist/shipped-issuer-list.js +3 -0
  175. package/dist/signals-text.d.ts +46 -0
  176. package/dist/signals-text.js +81 -0
  177. package/dist/verify-seal.d.ts +9 -0
  178. package/dist/verify-seal.js +30 -0
  179. package/hermes/plugin/__init__.py +1040 -0
  180. package/hermes/plugin/plugin.yaml +30 -0
  181. package/hermes/skills/cello-bridge-setup/SKILL.md +38 -0
  182. package/hermes/skills/cello-policy/SKILL.md +44 -0
  183. package/package.json +48 -16
  184. package/plugins/cello/.claude-plugin/plugin.json +19 -0
  185. package/plugins/cello/.mcp.json +7 -0
  186. package/plugins/cello/skills/cello/SKILL.md +117 -0
  187. package/dist/arg-parse.d.ts +0 -19
  188. package/dist/arg-parse.d.ts.map +0 -1
  189. package/dist/arg-parse.js +0 -29
  190. package/dist/arg-parse.js.map +0 -1
  191. package/dist/bin/cello.d.ts +0 -15
  192. package/dist/bin/cello.d.ts.map +0 -1
  193. package/dist/bin/cello.js +0 -110
  194. package/dist/bin/cello.js.map +0 -1
  195. package/dist/cli-args.d.ts +0 -62
  196. package/dist/cli-args.d.ts.map +0 -1
  197. package/dist/cli-args.js +0 -129
  198. package/dist/cli-args.js.map +0 -1
  199. package/dist/commands.d.ts +0 -196
  200. package/dist/commands.d.ts.map +0 -1
  201. package/dist/commands.js +0 -1544
  202. package/dist/commands.js.map +0 -1
  203. package/dist/hermes/assets.d.ts +0 -41
  204. package/dist/hermes/assets.d.ts.map +0 -1
  205. package/dist/hermes/assets.js +0 -2281
  206. package/dist/hermes/assets.js.map +0 -1
  207. package/dist/hermes/install-hermes.d.ts +0 -50
  208. package/dist/hermes/install-hermes.d.ts.map +0 -1
  209. package/dist/hermes/install-hermes.js +0 -232
  210. package/dist/hermes/install-hermes.js.map +0 -1
  211. package/dist/json-out.d.ts +0 -41
  212. package/dist/json-out.d.ts.map +0 -1
  213. package/dist/json-out.js +0 -59
  214. package/dist/json-out.js.map +0 -1
  215. package/dist/node-runtime-guard-init.d.ts +0 -6
  216. package/dist/node-runtime-guard-init.d.ts.map +0 -1
  217. package/dist/node-runtime-guard-init.js +0 -7
  218. package/dist/node-runtime-guard-init.js.map +0 -1
  219. package/dist/node-runtime-guard.d.ts +0 -48
  220. package/dist/node-runtime-guard.d.ts.map +0 -1
  221. package/dist/node-runtime-guard.js +0 -79
  222. package/dist/node-runtime-guard.js.map +0 -1
  223. package/dist/parity-commands.d.ts +0 -427
  224. package/dist/parity-commands.d.ts.map +0 -1
  225. package/dist/parity-commands.js +0 -953
  226. package/dist/parity-commands.js.map +0 -1
  227. package/dist/registry.d.ts +0 -120
  228. package/dist/registry.d.ts.map +0 -1
  229. package/dist/registry.js +0 -2169
  230. package/dist/registry.js.map +0 -1
  231. package/dist/screener-commands.d.ts +0 -85
  232. package/dist/screener-commands.d.ts.map +0 -1
  233. package/dist/screener-commands.js +0 -313
  234. package/dist/screener-commands.js.map +0 -1
@@ -0,0 +1,28 @@
1
+ import "./pq-warnings.ts";
2
+ export declare const ML_DSA_PUBLIC_KEY_BYTES = 1312;
3
+ export declare const ML_DSA_SIGNATURE_BYTES = 2420;
4
+ export declare const ML_DSA_SEED_BYTES = 32;
5
+ export type MlDsaPublicKey = Uint8Array;
6
+ export type MlDsaSignature = Uint8Array;
7
+ export interface MlDsaKeyProvider {
8
+ getPublicKey(): Promise<MlDsaPublicKey>;
9
+ sign(message: Uint8Array): Promise<MlDsaSignature>;
10
+ }
11
+ export declare const ML_DSA_ALGORITHM_LABEL = "ML-DSA-44";
12
+ export declare const ML_DSA_ALGORITHM: {
13
+ readonly name: "ML-DSA-44";
14
+ };
15
+ declare const INSPECT: unique symbol;
16
+ export declare class InMemoryMlDsaKeyProvider implements MlDsaKeyProvider {
17
+ #private;
18
+ private constructor();
19
+ static fromSeed(seed: Uint8Array): Promise<InMemoryMlDsaKeyProvider>;
20
+ getPublicKey(): Promise<MlDsaPublicKey>;
21
+ sign(message: Uint8Array): Promise<MlDsaSignature>;
22
+ toJSON(): Record<string, string>;
23
+ toString(): string;
24
+ [INSPECT](): string;
25
+ }
26
+ export declare function mlDsaGenerateSeed(): Uint8Array;
27
+ export declare function mlDsaProviderFromSeed(seed: Uint8Array): Promise<MlDsaKeyProvider>;
28
+ export {};
@@ -0,0 +1,58 @@
1
+ import "./pq-warnings.js";
2
+ import { webcrypto } from "node:crypto";
3
+ import { PqCryptoError, isUnsupportedAlgorithm } from "./pq-errors.js";
4
+ export const ML_DSA_PUBLIC_KEY_BYTES = 1312;
5
+ export const ML_DSA_SIGNATURE_BYTES = 2420;
6
+ export const ML_DSA_SEED_BYTES = 32;
7
+ export const ML_DSA_ALGORITHM_LABEL = "ML-DSA-44";
8
+ export const ML_DSA_ALGORITHM = { name: ML_DSA_ALGORITHM_LABEL };
9
+ function mlDsaUnsupported(err) {
10
+ return new PqCryptoError("pq_runtime_unsupported", `ML-DSA-44 is not available in this Node (${process.version}); CELLO needs Node >= 24.7`, { cause: err });
11
+ }
12
+ const INSPECT = Symbol.for("nodejs.util.inspect.custom");
13
+ export class InMemoryMlDsaKeyProvider {
14
+ #key;
15
+ #publicKey;
16
+ constructor(key, publicKey) {
17
+ this.#key = key;
18
+ this.#publicKey = publicKey;
19
+ }
20
+ static async fromSeed(seed) {
21
+ if (!(seed instanceof Uint8Array) || seed.length !== ML_DSA_SEED_BYTES) {
22
+ throw new PqCryptoError("ml_dsa_seed_invalid", `ML-DSA-44 seed must be ${ML_DSA_SEED_BYTES} bytes, got ${seed?.length}`);
23
+ }
24
+ let key;
25
+ try {
26
+ key = await webcrypto.subtle.importKey("raw-seed", new Uint8Array(seed), ML_DSA_ALGORITHM, false, ["sign"]);
27
+ }
28
+ catch (err) {
29
+ if (isUnsupportedAlgorithm(err))
30
+ throw mlDsaUnsupported(err);
31
+ throw new PqCryptoError("ml_dsa_seed_invalid", "ML-DSA-44 seed import failed", { cause: err });
32
+ }
33
+ const publicKey = await webcrypto.subtle.getPublicKey(key, ["verify"]);
34
+ const pub = await webcrypto.subtle.exportKey("raw-public", publicKey);
35
+ return new InMemoryMlDsaKeyProvider(key, new Uint8Array(pub));
36
+ }
37
+ async getPublicKey() {
38
+ return this.#publicKey.slice();
39
+ }
40
+ async sign(message) {
41
+ return new Uint8Array(await webcrypto.subtle.sign(ML_DSA_ALGORITHM, this.#key, new Uint8Array(message)));
42
+ }
43
+ toJSON() {
44
+ return { type: "InMemoryMlDsaKeyProvider", publicKey: Buffer.from(this.#publicKey).toString("hex") };
45
+ }
46
+ toString() {
47
+ return `InMemoryMlDsaKeyProvider(pubkey=${Buffer.from(this.#publicKey).toString("hex")})`;
48
+ }
49
+ [INSPECT]() {
50
+ return this.toString();
51
+ }
52
+ }
53
+ export function mlDsaGenerateSeed() {
54
+ return webcrypto.getRandomValues(new Uint8Array(ML_DSA_SEED_BYTES));
55
+ }
56
+ export async function mlDsaProviderFromSeed(seed) {
57
+ return InMemoryMlDsaKeyProvider.fromSeed(seed);
58
+ }
@@ -0,0 +1,14 @@
1
+ import "./pq-warnings.ts";
2
+ export declare const ML_KEM_PUBLIC_KEY_BYTES = 1184;
3
+ export declare const ML_KEM_CIPHERTEXT_BYTES = 1088;
4
+ export declare const ML_KEM_SEED_BYTES = 64;
5
+ export declare const ML_KEM_SHARED_SECRET_BYTES = 32;
6
+ export declare function mlKemGenerateSeed(): Uint8Array;
7
+ export declare function mlKemKeypairFromSeed(seed: Uint8Array): Promise<{
8
+ publicKey: Uint8Array;
9
+ }>;
10
+ export declare function mlKemEncapsulate(publicKey: Uint8Array): Promise<{
11
+ ciphertext: Uint8Array;
12
+ sharedSecret: Uint8Array;
13
+ }>;
14
+ export declare function mlKemDecapsulate(seed: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,57 @@
1
+ import "./pq-warnings.js";
2
+ import { webcrypto } from "node:crypto";
3
+ import { PqCryptoError, isUnsupportedAlgorithm } from "./pq-errors.js";
4
+ export const ML_KEM_PUBLIC_KEY_BYTES = 1184;
5
+ export const ML_KEM_CIPHERTEXT_BYTES = 1088;
6
+ export const ML_KEM_SEED_BYTES = 64;
7
+ export const ML_KEM_SHARED_SECRET_BYTES = 32;
8
+ const ALG = { name: "ML-KEM-768" };
9
+ const subtle = webcrypto.subtle;
10
+ const pq = subtle;
11
+ function unsupported(err) {
12
+ return new PqCryptoError("pq_runtime_unsupported", `ML-KEM-768 is not available in this Node (${process.version}); CELLO needs Node >= 24.7`, { cause: err });
13
+ }
14
+ async function importSeed(seed) {
15
+ if (!(seed instanceof Uint8Array) || seed.length !== ML_KEM_SEED_BYTES) {
16
+ throw new PqCryptoError("ml_kem_seed_invalid", `ML-KEM-768 seed must be ${ML_KEM_SEED_BYTES} bytes, got ${seed?.length}`);
17
+ }
18
+ try {
19
+ return await pq.importKey("raw-seed", seed, ALG, false, ["decapsulateBits"]);
20
+ }
21
+ catch (err) {
22
+ if (isUnsupportedAlgorithm(err))
23
+ throw unsupported(err);
24
+ throw new PqCryptoError("ml_kem_seed_invalid", "ML-KEM-768 seed import failed", { cause: err });
25
+ }
26
+ }
27
+ export function mlKemGenerateSeed() {
28
+ return webcrypto.getRandomValues(new Uint8Array(ML_KEM_SEED_BYTES));
29
+ }
30
+ export async function mlKemKeypairFromSeed(seed) {
31
+ const key = await importSeed(seed);
32
+ const pub = await subtle.exportKey("raw-public", await pq.getPublicKey(key, ["encapsulateBits"]));
33
+ return { publicKey: new Uint8Array(pub) };
34
+ }
35
+ export async function mlKemEncapsulate(publicKey) {
36
+ if (!(publicKey instanceof Uint8Array) || publicKey.length !== ML_KEM_PUBLIC_KEY_BYTES) {
37
+ throw new PqCryptoError("ml_kem_public_key_invalid", `ML-KEM-768 public key must be ${ML_KEM_PUBLIC_KEY_BYTES} bytes, got ${publicKey?.length}`);
38
+ }
39
+ let key;
40
+ try {
41
+ key = await pq.importKey("raw-public", publicKey, ALG, true, ["encapsulateBits"]);
42
+ }
43
+ catch (err) {
44
+ if (isUnsupportedAlgorithm(err))
45
+ throw unsupported(err);
46
+ throw new PqCryptoError("ml_kem_public_key_invalid", "ML-KEM-768 public key failed the FIPS 203 encapsulation-key check", { cause: err });
47
+ }
48
+ const { ciphertext, sharedKey } = await pq.encapsulateBits(ALG, key);
49
+ return { ciphertext: new Uint8Array(ciphertext), sharedSecret: new Uint8Array(sharedKey) };
50
+ }
51
+ export async function mlKemDecapsulate(seed, ciphertext) {
52
+ const key = await importSeed(seed);
53
+ if (!(ciphertext instanceof Uint8Array) || ciphertext.length !== ML_KEM_CIPHERTEXT_BYTES) {
54
+ throw new PqCryptoError("ml_kem_ciphertext_invalid", `ML-KEM-768 ciphertext must be ${ML_KEM_CIPHERTEXT_BYTES} bytes, got ${ciphertext?.length}`);
55
+ }
56
+ return new Uint8Array(await pq.decapsulateBits(ALG, key, ciphertext));
57
+ }
@@ -0,0 +1,9 @@
1
+ export declare const PQ_CRYPTO_ERROR_REASONS: readonly ["ml_kem_seed_invalid", "ml_kem_public_key_invalid", "ml_kem_ciphertext_invalid", "ml_dsa_seed_invalid", "pq_context_unknown", "pq_runtime_unsupported"];
2
+ export type PqCryptoErrorReason = (typeof PQ_CRYPTO_ERROR_REASONS)[number];
3
+ export declare class PqCryptoError extends Error {
4
+ readonly reason: PqCryptoErrorReason;
5
+ constructor(reason: PqCryptoErrorReason, message: string, options?: {
6
+ cause?: unknown;
7
+ });
8
+ }
9
+ export declare function isUnsupportedAlgorithm(err: unknown): boolean;
@@ -0,0 +1,23 @@
1
+ export const PQ_CRYPTO_ERROR_REASONS = [
2
+ "ml_kem_seed_invalid",
3
+ "ml_kem_public_key_invalid",
4
+ "ml_kem_ciphertext_invalid",
5
+ "ml_dsa_seed_invalid",
6
+ "pq_context_unknown",
7
+ "pq_runtime_unsupported",
8
+ ];
9
+ export class PqCryptoError extends Error {
10
+ reason;
11
+ constructor(reason, message, options) {
12
+ super(message, options);
13
+ this.name = "PqCryptoError";
14
+ this.reason = reason;
15
+ }
16
+ }
17
+ export function isUnsupportedAlgorithm(err) {
18
+ if (!(err instanceof Error))
19
+ return false;
20
+ if (err.name === "NotSupportedError")
21
+ return true;
22
+ return err.code === "ERR_INVALID_ARG_VALUE" && /type (KeyFormat|Algorithm)/.test(err.message);
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ const PQ_APIS = ["ML-KEM-768", "ML-DSA-44", "getPublicKey", "encapsulateBits", "decapsulateBits"];
2
+ const PATTERN = new RegExp(`^The (${PQ_APIS.join("|")}) Web Crypto API `);
3
+ let installed = false;
4
+ function install() {
5
+ if (installed)
6
+ return;
7
+ installed = true;
8
+ const replaced = process.listeners("warning");
9
+ process.removeAllListeners("warning");
10
+ process.on("warning", (w) => {
11
+ if (w.name === "ExperimentalWarning" && PATTERN.test(w.message))
12
+ return;
13
+ for (const listener of replaced)
14
+ listener(w);
15
+ });
16
+ }
17
+ install();
18
+ export {};
@@ -0,0 +1,17 @@
1
+ import { type PublicIdentity } from "./identity.ts";
2
+ import { MAX_PRESENTED_BYTES, MAX_PRESENTED_SIGNALS, type EncryptionKeyFields, encryptionKeyBytes } from "./structures.ts";
3
+ export declare const PRESENTED_SIGNALS_LABEL = "cello-presented-signals-v1";
4
+ export { MAX_PRESENTED_BYTES, MAX_PRESENTED_SIGNALS };
5
+ export declare class PresentedTooMany extends RangeError {
6
+ }
7
+ export declare function encodePresented(files: readonly Uint8Array[]): Uint8Array;
8
+ export declare function decodePresented(plain: Uint8Array): Uint8Array[] | null;
9
+ export declare function sealUnderSession(sessionKey: Uint8Array, files: readonly Uint8Array[]): Uint8Array;
10
+ export declare function openUnderSession(sessionKey: Uint8Array, box: Uint8Array): Uint8Array[] | "unreadable";
11
+ export declare function sealToKey(calleeMlKemPublic: Uint8Array, files: readonly Uint8Array[]): Promise<{
12
+ signalsCiphertext: Uint8Array;
13
+ sealedSignals: Uint8Array;
14
+ }>;
15
+ export declare function openFromKey(mlKemSeeds: readonly Uint8Array[], signalsCiphertext: Uint8Array, sealedSignals: Uint8Array): Promise<Uint8Array[] | "unreadable">;
16
+ export declare function checkEncryptionKey(wire: unknown, agent: PublicIdentity, agentId: Uint8Array): Promise<EncryptionKeyFields>;
17
+ export { encryptionKeyBytes };
@@ -0,0 +1,92 @@
1
+ // The signals each side shows when a call is made, and how they travel sealed. Two ways in, one shape inside.
2
+ // A caller seals to the callee's published encryption key, the way a refusal is sealed: ML-KEM encapsulation, a key made from the shared secret, AES-GCM.
3
+ // A callee seals under the session key, like its name. Inside, a flat CBOR array: a label, then each signed signal file whole.
4
+ import { createHash } from "node:crypto";
5
+ import { openSessionContent, sealSessionContent } from "./aead.js";
6
+ import { decodeCbor, encodeCbor } from "./cbor.js";
7
+ import { verifySignature } from "./identity.js";
8
+ import { mlKemDecapsulate, mlKemEncapsulate } from "./ml-kem.js";
9
+ import { MAX_PRESENTED_BYTES, MAX_PRESENTED_SIGNALS, encryptionKeyBytes } from "./structures.js";
10
+ import { signedEncryptionKey } from "./wire.js";
11
+ import { equalBytes } from "./encode.js";
12
+ export const PRESENTED_SIGNALS_LABEL = "cello-presented-signals-v1";
13
+ export { MAX_PRESENTED_BYTES, MAX_PRESENTED_SIGNALS };
14
+ // The key a request's signals are sealed under. Its own label, so a secret made for a refusal can't open a set or the other way round.
15
+ const requestSignalsKey = (sharedSecret) => new Uint8Array(createHash("sha256").update("cello-request-signals").update(sharedSecret).digest());
16
+ export class PresentedTooMany extends RangeError {
17
+ }
18
+ // What goes inside a box. The caller of this refuses a set that is too big before sealing, and says which limit.
19
+ export function encodePresented(files) {
20
+ if (files.length > MAX_PRESENTED_SIGNALS)
21
+ throw new PresentedTooMany(`at most ${MAX_PRESENTED_SIGNALS} signals go with a call, and this set has ${files.length}`);
22
+ const plain = new Uint8Array(encodeCbor([PRESENTED_SIGNALS_LABEL, ...files]));
23
+ return plain;
24
+ }
25
+ // Null for anything that isn't a flat array of our label and byte strings, or has too many.
26
+ export function decodePresented(plain) {
27
+ try {
28
+ const items = decodeCbor(plain);
29
+ if (!Array.isArray(items) || items[0] !== PRESENTED_SIGNALS_LABEL || items.length - 1 > MAX_PRESENTED_SIGNALS)
30
+ return null;
31
+ const files = items.slice(1);
32
+ if (!files.every((file) => file instanceof Uint8Array))
33
+ return null;
34
+ return files.map((file) => new Uint8Array(file));
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ // Under the session key, as the callee's name is. An empty set is sent as no box at all, which is how "nothing sent" reads.
41
+ export function sealUnderSession(sessionKey, files) {
42
+ if (files.length === 0)
43
+ return new Uint8Array(0);
44
+ const box = sealSessionContent(sessionKey, encodePresented(files));
45
+ if (box.length > MAX_PRESENTED_BYTES)
46
+ throw new PresentedTooMany(`these signals total ${box.length} bytes sealed, and the limit is ${MAX_PRESENTED_BYTES}`);
47
+ return box;
48
+ }
49
+ // Empty means none were sent. A box that won't open, or opens to something else, is refused rather than read as none.
50
+ export function openUnderSession(sessionKey, box) {
51
+ if (box.length === 0)
52
+ return [];
53
+ const plain = openSessionContent(sessionKey, box);
54
+ const files = plain ? decodePresented(plain) : null;
55
+ return files ?? "unreadable";
56
+ }
57
+ // To the callee's published key. Returns what goes in the offer's two fields.
58
+ export async function sealToKey(calleeMlKemPublic, files) {
59
+ if (files.length === 0)
60
+ return { signalsCiphertext: new Uint8Array(0), sealedSignals: new Uint8Array(0) };
61
+ const plain = encodePresented(files);
62
+ const { ciphertext, sharedSecret } = await mlKemEncapsulate(calleeMlKemPublic);
63
+ const box = sealSessionContent(requestSignalsKey(sharedSecret), plain);
64
+ sharedSecret.fill(0);
65
+ if (box.length > MAX_PRESENTED_BYTES)
66
+ throw new PresentedTooMany(`these signals total ${box.length} bytes sealed, and the limit is ${MAX_PRESENTED_BYTES}`);
67
+ return { signalsCiphertext: ciphertext, sealedSignals: box };
68
+ }
69
+ // With each of the callee's own seeds, newest first, because an offer may have been sealed to a key since replaced. Both fields empty means none were sent.
70
+ export async function openFromKey(mlKemSeeds, signalsCiphertext, sealedSignals) {
71
+ if (signalsCiphertext.length === 0 && sealedSignals.length === 0)
72
+ return [];
73
+ for (const seed of mlKemSeeds) {
74
+ const sharedSecret = await mlKemDecapsulate(seed, signalsCiphertext);
75
+ const plain = openSessionContent(requestSignalsKey(sharedSecret), sealedSignals);
76
+ sharedSecret.fill(0);
77
+ const files = plain ? decodePresented(plain) : null;
78
+ if (files)
79
+ return files;
80
+ }
81
+ return "unreadable";
82
+ }
83
+ // A published key as a caller reads it: signed by the agent it says it belongs to, whose identity the caller already holds from the id it typed.
84
+ export async function checkEncryptionKey(wire, agent, agentId) {
85
+ const signed = signedEncryptionKey.decode(wire, "encryptionKey");
86
+ if (!equalBytes(signed.fields.agentId, agentId))
87
+ throw new RangeError("this encryption key names a different agent");
88
+ if (!(await verifySignature(agent, "cello-agent-encryption-key", signed.bytes, signed.signature)))
89
+ throw new RangeError("this encryption key isn't signed by the agent it names");
90
+ return signed.fields;
91
+ }
92
+ export { encryptionKeyBytes };
@@ -0,0 +1,5 @@
1
+ export declare const SALT_CONTRIBUTION_BYTES = 32;
2
+ export declare const SESSION_SALT_BYTES = 32;
3
+ export declare function generateSaltContribution(): Uint8Array;
4
+ export declare function deriveSessionSalt(ourContribution: Uint8Array, peerContribution: Uint8Array): Uint8Array;
5
+ export declare function saltedContentHash(salt: Uint8Array, content: Uint8Array): Uint8Array;
@@ -0,0 +1,47 @@
1
+ import { hkdf } from "@noble/hashes/hkdf.js";
2
+ import { sha256 } from "@noble/hashes/sha2.js";
3
+ import { hmac } from "@noble/hashes/hmac.js";
4
+ import { randomBytes } from "node:crypto";
5
+ export const SALT_CONTRIBUTION_BYTES = 32;
6
+ export const SESSION_SALT_BYTES = 32;
7
+ const ENC = new TextEncoder();
8
+ const INFO_SESSION_SALT = ENC.encode("cello-session-salt");
9
+ export function generateSaltContribution() {
10
+ return new Uint8Array(randomBytes(SALT_CONTRIBUTION_BYTES));
11
+ }
12
+ function isAllZero(b) {
13
+ let acc = 0;
14
+ for (const x of b)
15
+ acc |= x;
16
+ return acc === 0;
17
+ }
18
+ export function deriveSessionSalt(ourContribution, peerContribution) {
19
+ if (peerContribution.length !== SALT_CONTRIBUTION_BYTES) {
20
+ throw new Error(`session salt: the peer contribution must be ${SALT_CONTRIBUTION_BYTES} bytes`);
21
+ }
22
+ if (isAllZero(peerContribution)) {
23
+ throw new Error("session salt: the peer contribution is all zeros");
24
+ }
25
+ if (ourContribution.length !== SALT_CONTRIBUTION_BYTES) {
26
+ throw new Error(`session salt: our contribution must be ${SALT_CONTRIBUTION_BYTES} bytes`);
27
+ }
28
+ if (isAllZero(ourContribution)) {
29
+ throw new Error("session salt: our contribution is all zeros");
30
+ }
31
+ if (Buffer.compare(Buffer.from(ourContribution), Buffer.from(peerContribution)) === 0) {
32
+ throw new Error("session salt: the peer sent back our own contribution");
33
+ }
34
+ const [first, second] = Buffer.compare(Buffer.from(ourContribution), Buffer.from(peerContribution)) < 0
35
+ ? [ourContribution, peerContribution]
36
+ : [peerContribution, ourContribution];
37
+ const ikm = new Uint8Array(first.length + second.length);
38
+ ikm.set(first, 0);
39
+ ikm.set(second, first.length);
40
+ return hkdf(sha256, ikm, new Uint8Array(0), INFO_SESSION_SALT, SESSION_SALT_BYTES);
41
+ }
42
+ export function saltedContentHash(salt, content) {
43
+ const msg = new Uint8Array(1 + content.length);
44
+ msg[0] = 0x00;
45
+ msg.set(content, 1);
46
+ return hmac(sha256, salt, msg);
47
+ }
@@ -0,0 +1,58 @@
1
+ import { type DualSignature, type PublicIdentity } from "./identity.ts";
2
+ import { type AcceptFields, type DeliveryAckFields, type OfferFields, type SealCertificateFields, type SealLogHeadFields, type SealRequestFields } from "./structures.ts";
3
+ import { type Signed, type WireSigned } from "./wire.ts";
4
+ export declare const SEAL_RECORD_FORMAT = "cello-seal";
5
+ export interface SealRecordOnWire {
6
+ format: typeof SEAL_RECORD_FORMAT;
7
+ certificate: WireSigned;
8
+ request: WireSigned;
9
+ offer: WireSigned;
10
+ accept: WireSigned;
11
+ deliveryAck: WireSigned | null;
12
+ deliveryProof: string[];
13
+ sealer: Record<string, string | number>;
14
+ counterparty: Record<string, string | number>;
15
+ sealKey: Record<string, string | number>;
16
+ server: Record<string, string | number>;
17
+ sealKeyBinding: Record<string, string | number>;
18
+ log: {
19
+ index: number;
20
+ head: WireSigned;
21
+ path: string[];
22
+ };
23
+ }
24
+ export interface SealRecord {
25
+ certificate: Signed<SealCertificateFields>;
26
+ request: Signed<SealRequestFields>;
27
+ offer: Signed<OfferFields>;
28
+ accept: Signed<AcceptFields>;
29
+ deliveryAck: Signed<DeliveryAckFields> | null;
30
+ deliveryProof: Uint8Array[];
31
+ sealer: PublicIdentity;
32
+ counterparty: PublicIdentity;
33
+ sealKey: PublicIdentity;
34
+ server: PublicIdentity;
35
+ sealKeyBinding: DualSignature;
36
+ log: {
37
+ index: number;
38
+ head: Signed<SealLogHeadFields>;
39
+ path: Uint8Array[];
40
+ };
41
+ }
42
+ export declare function encodeHashes(hashes: readonly Uint8Array[]): string[];
43
+ export declare function decodeSealRecord(raw: unknown): SealRecord;
44
+ export declare function sealId(certificateBytes: Uint8Array): Uint8Array;
45
+ export type SealFault = "malformed_record" | "unknown_format" | "wrong_seal_key" | "bad_seal_key_binding" | "bad_seal_signature" | "wrong_sealer_keys" | "bad_seal_request" | "seal_request_mismatch" | "wrong_counterparty_keys" | "no_session_agreement" | "impossible_positions" | "delivery_ack_mismatch" | "bad_delivery_ack_signature" | "delivery_proof_failed" | "bad_log_head_signature" | "log_proof_failed";
46
+ export type SealCheck = {
47
+ ok: true;
48
+ record: SealRecord;
49
+ } | {
50
+ ok: false;
51
+ fault: SealFault;
52
+ message: string;
53
+ };
54
+ export declare function refusedPositions(record: SealRecord): number[];
55
+ export declare function checkSealRecord(raw: unknown, sealKeyId: Uint8Array): Promise<SealCheck>;
56
+ export declare function describeSeal(record: SealRecord): Record<string, string>;
57
+ export declare function readableTime(time: number): string | null;
58
+ export declare function sealSummary(record: SealRecord): Record<string, unknown>;