@shieldfive/crypto 1.0.0-rc.3 → 1.0.0-rc.5

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 (65) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/format/signature-tail.d.ts +54 -0
  3. package/dist/format/signature-tail.d.ts.map +1 -0
  4. package/dist/format/signature-tail.js +82 -0
  5. package/dist/format/signature-tail.js.map +1 -0
  6. package/dist/index.d.ts +2 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal/types.d.ts +2 -0
  11. package/dist/internal/types.d.ts.map +1 -1
  12. package/dist/internal/types.js +9 -0
  13. package/dist/internal/types.js.map +1 -1
  14. package/dist/migration/v0-bridge.d.ts +22 -2
  15. package/dist/migration/v0-bridge.d.ts.map +1 -1
  16. package/dist/migration/v0-bridge.js.map +1 -1
  17. package/dist/streams/aes-gcm-v1.d.ts +3 -37
  18. package/dist/streams/aes-gcm-v1.d.ts.map +1 -1
  19. package/dist/streams/aes-gcm-v1.js +8 -64
  20. package/dist/streams/aes-gcm-v1.js.map +1 -1
  21. package/dist/suites/aes-gcm-v1/api.d.ts +18 -0
  22. package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -1
  23. package/dist/suites/aes-gcm-v1/api.js +23 -5
  24. package/dist/suites/aes-gcm-v1/api.js.map +1 -1
  25. package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -1
  26. package/dist/suites/aes-gcm-v1/index.js +11 -0
  27. package/dist/suites/aes-gcm-v1/index.js.map +1 -1
  28. package/dist/suites/aes-gcm-v2/api.d.ts +17 -0
  29. package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -1
  30. package/dist/suites/aes-gcm-v2/api.js +19 -3
  31. package/dist/suites/aes-gcm-v2/api.js.map +1 -1
  32. package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -1
  33. package/dist/suites/aes-gcm-v2/index.js +7 -0
  34. package/dist/suites/aes-gcm-v2/index.js.map +1 -1
  35. package/dist/suites/pq-hybrid-v1/api.d.ts +17 -0
  36. package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -1
  37. package/dist/suites/pq-hybrid-v1/api.js +19 -3
  38. package/dist/suites/pq-hybrid-v1/api.js.map +1 -1
  39. package/dist/suites/xchacha-v1/api.d.ts +17 -0
  40. package/dist/suites/xchacha-v1/api.d.ts.map +1 -1
  41. package/dist/suites/xchacha-v1/api.js +19 -3
  42. package/dist/suites/xchacha-v1/api.js.map +1 -1
  43. package/dist/suites/xchacha-v1/index.d.ts.map +1 -1
  44. package/dist/suites/xchacha-v1/index.js +8 -0
  45. package/dist/suites/xchacha-v1/index.js.map +1 -1
  46. package/dist/vault/index.d.ts +192 -0
  47. package/dist/vault/index.d.ts.map +1 -0
  48. package/dist/vault/index.js +445 -0
  49. package/dist/vault/index.js.map +1 -0
  50. package/package.json +6 -1
  51. package/spec/key-derivation.md +21 -5
  52. package/spec/vault-formats.md +101 -0
  53. package/src/format/signature-tail.ts +114 -0
  54. package/src/index.ts +2 -1
  55. package/src/internal/types.ts +9 -0
  56. package/src/migration/v0-bridge.ts +22 -2
  57. package/src/streams/aes-gcm-v1.ts +17 -91
  58. package/src/suites/aes-gcm-v1/api.ts +46 -5
  59. package/src/suites/aes-gcm-v1/index.ts +11 -0
  60. package/src/suites/aes-gcm-v2/api.ts +41 -3
  61. package/src/suites/aes-gcm-v2/index.ts +7 -0
  62. package/src/suites/pq-hybrid-v1/api.ts +41 -3
  63. package/src/suites/xchacha-v1/api.ts +41 -3
  64. package/src/suites/xchacha-v1/index.ts +8 -0
  65. package/src/vault/index.ts +626 -0
@@ -34,6 +34,14 @@ export function parseXChaChaV1SuitePayload(bytes) {
34
34
  if (bytes.length !== XCHACHA_V1_SUITE_PAYLOAD_LENGTH) {
35
35
  throw new RangeError('xchacha-v1: suite payload must be 96 bytes');
36
36
  }
37
+ // The 48-byte secretbox wrap (32-byte key + 16-byte tag) is zero-padded to
38
+ // 72 bytes; the reserved pad (bytes 48..72) MUST be all zero — same
39
+ // invariant suite 0x03 enforces (M6). See parseAesGcmV1SuitePayload.
40
+ for (let i = 48; i < 72; i += 1) {
41
+ if (bytes[i] !== 0) {
42
+ throw new RangeError('xchacha-v1: reserved wrapped_key pad must be zero');
43
+ }
44
+ }
37
45
  return {
38
46
  wrappedKey: bytes.slice(0, 72),
39
47
  wrapNonce: bytes.slice(72, 96),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EACL,SAAS,EACT,YAAY,GAEb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAA;AACtC,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAA;AACxC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAEtC,sFAAsF;AACtF,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAA;AAOjD,MAAM,UAAU,0BAA0B,CACxC,OAA8B;IAE9B,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,UAAU,CAAC,yCAAyC,CAAC,CAAA;IACjE,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,sBAAsB,EAAE,CAAC;QACxD,MAAM,IAAI,UAAU,CAAC,wCAAwC,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S,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;IAC1E,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,MAAoB;IAEpB,OAAO,0BAA0B,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AACxD,CAAC"}
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Vault key chain, name envelopes and agent grants.
3
+ *
4
+ * These are the formats the ShieldFive web app already writes to its
5
+ * database, reproduced here so every non-browser client (the MCP server, the
6
+ * CLI, the mobile app) opens them with ONE reviewed implementation instead of
7
+ * each carrying its own copy.
8
+ *
9
+ * Key chain folders.fk_wrapped / files.csk_wrapped / files.pqk_fk_wrapped:
10
+ * AES-256-GCM, 12-byte random IV stored beside the ciphertext,
11
+ * no AAD. The wrapping key is the parent folder key, or the vault
12
+ * root key for top-level objects.
13
+ *
14
+ * Names files.name / folders.name: a JSON envelope
15
+ * {v, ct, iv, tag, salt, kdf?}. The AES-256-GCM key is
16
+ * Argon2id(password = the base64 text of the parent folder key,
17
+ * salt). v6 additionally authenticates the row UUID as AAD so a
18
+ * server cannot move a name onto another row.
19
+ *
20
+ * Agent grant A fresh 32-byte secret, generated in the owner's browser and
21
+ * never sent to the server, wraps the grant's scope-root keys.
22
+ * Wrapping key = HKDF-SHA-256(secret, salt = grant id,
23
+ * info = HKDF_INFO.AGENT_GRANT_WRAP). Every wrap authenticates
24
+ * the grant id, the object kind and the object id as AAD.
25
+ *
26
+ * Nothing in this module is a new primitive: it composes AES-256-GCM,
27
+ * HKDF-SHA-256, SHA-256 and libsodium's Argon2id13.
28
+ */
29
+ /** Raised for any envelope or wrap that does not open. Never carries key bytes. */
30
+ export declare class VaultCryptoError extends Error {
31
+ readonly code: 'unwrap_failed' | 'name_decrypt_failed' | 'unsupported_envelope' | 'invalid_input' | 'invalid_connection_string';
32
+ constructor(code: VaultCryptoError['code'], message: string);
33
+ }
34
+ /** A wrapped key as the database stores it: base64 ciphertext+tag and base64 IV. */
35
+ export interface WrappedKey {
36
+ wrapped: string;
37
+ iv: string;
38
+ }
39
+ /** Wrap a 32-byte key under a 32-byte key (the fk/csk/pqk chain format). */
40
+ export declare function wrapChainKey(wrappingKey: Uint8Array, key: Uint8Array): Promise<WrappedKey>;
41
+ /** Open one hop of the key chain. Throws `unwrap_failed` on a wrong key or tampering. */
42
+ export declare function unwrapChainKey(wrappingKey: Uint8Array, wrapped: WrappedKey): Promise<Uint8Array>;
43
+ export type NameKdfLevel = 'interactive' | 'moderate';
44
+ export interface NameEnvelope {
45
+ v: 4 | 6;
46
+ ct: string;
47
+ iv: string;
48
+ tag: string;
49
+ salt: string;
50
+ kdf?: NameKdfLevel;
51
+ }
52
+ /** Parse a stored name. Returns null for anything that is not a v4/v6 envelope. */
53
+ export declare function parseNameEnvelope(raw: string | null | undefined): NameEnvelope | null;
54
+ /**
55
+ * Derive the per-envelope name key. The Argon2id password is the base64 TEXT
56
+ * of the folder key, byte-for-byte what the web app passes to libsodium; the
57
+ * input is already 256 bits of entropy, so the cost level is a compatibility
58
+ * parameter, not a security one.
59
+ */
60
+ export declare function deriveNameKey(folderKey: Uint8Array, salt: Uint8Array, level: NameKdfLevel): Promise<Uint8Array>;
61
+ /**
62
+ * Decrypt a v4 or v6 name. `rowId` is the database UUID of the row the name
63
+ * belongs to and is REQUIRED for v6 (it is the AAD). An envelope written
64
+ * without a `kdf` field is tried at interactive, then moderate, which is the
65
+ * web app's own fallback order for a device that cannot know the level.
66
+ */
67
+ export declare function decryptName(options: {
68
+ envelope: NameEnvelope;
69
+ folderKey: Uint8Array;
70
+ rowId?: string;
71
+ }): Promise<string>;
72
+ /**
73
+ * Decrypt a name with an already-derived name key (a grant's `name` wrap),
74
+ * for objects whose parent key the caller does not hold.
75
+ */
76
+ export declare function decryptNameWithKey(options: {
77
+ envelope: NameEnvelope;
78
+ nameKey: Uint8Array;
79
+ rowId?: string;
80
+ }): Promise<string>;
81
+ /**
82
+ * The name key for one envelope: what an owner wraps as a grant's `name`
83
+ * object. For an envelope without a `kdf` field the level is found by opening
84
+ * it, the same fallback `decryptName` uses, so the wrapped key always works.
85
+ */
86
+ export declare function deriveNameKeyForEnvelope(options: {
87
+ envelope: NameEnvelope;
88
+ parentKey: Uint8Array;
89
+ rowId?: string;
90
+ }): Promise<Uint8Array>;
91
+ /** Encrypt a name as a v6 envelope bound to `rowId`, at the web app's default level. */
92
+ export declare function encryptNameV6(options: {
93
+ name: string;
94
+ folderKey: Uint8Array;
95
+ rowId: string;
96
+ }): Promise<NameEnvelope>;
97
+ export declare const GRANT_CONNECTION_PREFIX = "sf-grant-v1:";
98
+ /**
99
+ * What a grant wrap covers.
100
+ *
101
+ * folder a folder key (scope roots, and top-level folders for whole-vault)
102
+ * file the key a file's `csk_wrapped` holds: the content key for suites
103
+ * 0x00-0x02, the classical envelope key for 0x03
104
+ * file_pq the combined content key of a suite-0x03 file
105
+ * name the Argon2id-derived key of ONE name envelope, for objects whose
106
+ * name is sealed under a key outside the grant (a scope root's own
107
+ * name, a file at the vault root). Opens that envelope only.
108
+ *
109
+ * `file`, `file_pq` and `name` are only issued for objects whose parent key the
110
+ * grant does not hold; everything below a scope root is reached by the chain.
111
+ */
112
+ export type GrantObjectKind = 'folder' | 'file' | 'file_pq' | 'name';
113
+ export interface GrantCredential {
114
+ grantId: string;
115
+ /** Sent to the server as a bearer token. The server stores only its SHA-256. */
116
+ token: Uint8Array;
117
+ /** Never leaves the client. Wraps the grant's keys. */
118
+ secret: Uint8Array;
119
+ /** SHA-256 of the owner's ML-KEM public key at grant creation, hex. */
120
+ publicKeyFingerprint: string;
121
+ }
122
+ /** SHA-256 of an ML-KEM public key, hex. Pinned in the connection string. */
123
+ export declare function publicKeyFingerprint(mlKemPublicKey: Uint8Array): string;
124
+ /** Fresh token + secret for a new grant. Call in the owner's unlocked client. */
125
+ export declare function createGrantCredential(options: {
126
+ grantId: string;
127
+ mlKemPublicKey: Uint8Array;
128
+ }): GrantCredential;
129
+ /** `sf-grant-v1:<grant_id>.<token>.<secret>.<pk_fingerprint>` (base64url, hex). */
130
+ export declare function formatConnectionString(c: GrantCredential): string;
131
+ export declare function parseConnectionString(value: string): GrantCredential;
132
+ /** The bearer value a client sends. */
133
+ export declare function grantBearerToken(c: Pick<GrantCredential, 'token'>): string;
134
+ /** What the server stores and looks up: SHA-256 of the bearer token's bytes, hex. */
135
+ export declare function hashGrantToken(bearer: string): string;
136
+ /** GK = HKDF-SHA-256(secret, salt = utf8(grant id), info = AGENT_GRANT_WRAP). */
137
+ export declare function deriveGrantWrapKey(secret: Uint8Array, grantId: string): Promise<Uint8Array>;
138
+ /** Wrap a folder key or file content key for a grant, bound to (grant, kind, object). */
139
+ export declare function wrapKeyForGrant(options: {
140
+ grantWrapKey: Uint8Array;
141
+ grantId: string;
142
+ kind: GrantObjectKind;
143
+ objectId: string;
144
+ key: Uint8Array;
145
+ }): Promise<WrappedKey>;
146
+ export declare function unwrapKeyForGrant(options: {
147
+ grantWrapKey: Uint8Array;
148
+ grantId: string;
149
+ kind: GrantObjectKind;
150
+ objectId: string;
151
+ wrapped: WrappedKey;
152
+ }): Promise<Uint8Array>;
153
+ /** What a grant covers, as the owner decided it when creating the grant. */
154
+ export interface GrantScope {
155
+ grantId: string;
156
+ scopeAll: boolean;
157
+ includeMedia: boolean;
158
+ /** Scope-root folder ids (empty for a whole-vault grant). */
159
+ rootIds: readonly string[];
160
+ /** The grant's own trash folder, or null for a read-only grant. */
161
+ trashFolderId: string | null;
162
+ /** Top-level folders a whole-vault grant must never cover (the Bin, and Media unless opted in). */
163
+ excludedIds: readonly string[];
164
+ /**
165
+ * keyFingerprint() of those folders' keys. A server can relabel a row with
166
+ * another folder's wrapped key; it cannot change a key's fingerprint, so the
167
+ * owner's browser refuses to hand an excluded folder's key to the grant under
168
+ * any id.
169
+ */
170
+ excludedKeyFingerprints: readonly string[];
171
+ }
172
+ /** SHA-256 of a 32-byte key, hex. Reveals nothing usable about a random key. */
173
+ export declare function keyFingerprint(key: Uint8Array): string;
174
+ /** A canonical, order-independent string for a scope. Any change to the scope changes it. */
175
+ export declare function canonicalGrantScope(scope: GrantScope): string;
176
+ /**
177
+ * Wrap a grant secret for the owner: AES-256-GCM under HKDF(RK, grant id,
178
+ * AGENT_GRANT_SECRET), with the canonical scope as AAD. Only the owner's
179
+ * vault root key opens it, and only for exactly this scope.
180
+ */
181
+ export declare function wrapGrantSecret(options: {
182
+ rootKey: Uint8Array;
183
+ scope: GrantScope;
184
+ secret: Uint8Array;
185
+ }): Promise<WrappedKey>;
186
+ /** Open the owner's copy of a grant secret. Fails if the scope differs in any way from the one it was wrapped for. */
187
+ export declare function unwrapGrantSecret(options: {
188
+ rootKey: Uint8Array;
189
+ scope: GrantScope;
190
+ wrapped: WrappedKey;
191
+ }): Promise<Uint8Array>;
192
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vault/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAsBH,mFAAmF;AACnF,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EACT,eAAe,GACf,qBAAqB,GACrB,sBAAsB,GACtB,eAAe,GACf,2BAA2B,CAAA;gBACnB,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM;CAK5D;AA0DD,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;CACX;AAED,4EAA4E;AAC5E,wBAAsB,YAAY,CAChC,WAAW,EAAE,UAAU,EACvB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED,yFAAyF;AACzF,wBAAsB,cAAc,CAClC,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,UAAU,C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