@shieldfive/crypto 1.0.0-alpha.11
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/CHANGELOG.md +228 -0
- package/LICENSE +201 -0
- package/README.md +275 -0
- package/SECURITY.md +130 -0
- package/dist/format/header.d.ts +73 -0
- package/dist/format/header.d.ts.map +1 -0
- package/dist/format/header.js +230 -0
- package/dist/format/header.js.map +1 -0
- package/dist/identity/index.d.ts +119 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +217 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/sign.d.ts +92 -0
- package/dist/identity/sign.d.ts.map +1 -0
- package/dist/identity/sign.js +182 -0
- package/dist/identity/sign.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/encoding.d.ts +33 -0
- package/dist/internal/encoding.d.ts.map +1 -0
- package/dist/internal/encoding.js +135 -0
- package/dist/internal/encoding.js.map +1 -0
- package/dist/internal/hkdf.d.ts +14 -0
- package/dist/internal/hkdf.d.ts.map +1 -0
- package/dist/internal/hkdf.js +27 -0
- package/dist/internal/hkdf.js.map +1 -0
- package/dist/internal/hmac.d.ts +9 -0
- package/dist/internal/hmac.d.ts.map +1 -0
- package/dist/internal/hmac.js +18 -0
- package/dist/internal/hmac.js.map +1 -0
- package/dist/internal/runtime.d.ts +29 -0
- package/dist/internal/runtime.d.ts.map +1 -0
- package/dist/internal/runtime.js +67 -0
- package/dist/internal/runtime.js.map +1 -0
- package/dist/internal/sodium.d.ts +12 -0
- package/dist/internal/sodium.d.ts.map +1 -0
- package/dist/internal/sodium.js +34 -0
- package/dist/internal/sodium.js.map +1 -0
- package/dist/internal/types.d.ts +98 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +70 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/kdf/argon2id.d.ts +72 -0
- package/dist/kdf/argon2id.d.ts.map +1 -0
- package/dist/kdf/argon2id.js +98 -0
- package/dist/kdf/argon2id.js.map +1 -0
- package/dist/migration/v0-bridge.d.ts +94 -0
- package/dist/migration/v0-bridge.d.ts.map +1 -0
- package/dist/migration/v0-bridge.js +203 -0
- package/dist/migration/v0-bridge.js.map +1 -0
- package/dist/streams/aes-gcm-v1.d.ts +144 -0
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -0
- package/dist/streams/aes-gcm-v1.js +456 -0
- package/dist/streams/aes-gcm-v1.js.map +1 -0
- package/dist/streams/pq-hybrid-v1.d.ts +219 -0
- package/dist/streams/pq-hybrid-v1.d.ts.map +1 -0
- package/dist/streams/pq-hybrid-v1.js +473 -0
- package/dist/streams/pq-hybrid-v1.js.map +1 -0
- package/dist/suites/aes-gcm-v0/api.d.ts +48 -0
- package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v0/api.js +110 -0
- package/dist/suites/aes-gcm-v0/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/api.d.ts +54 -0
- package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/api.js +181 -0
- package/dist/suites/aes-gcm-v1/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/index.d.ts +59 -0
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/index.js +177 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -0
- package/dist/suites/aes-gcm-v2/api.d.ts +44 -0
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/api.js +162 -0
- package/dist/suites/aes-gcm-v2/api.js.map +1 -0
- package/dist/suites/aes-gcm-v2/index.d.ts +63 -0
- package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/index.js +193 -0
- package/dist/suites/aes-gcm-v2/index.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts +67 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.js +190 -0
- package/dist/suites/pq-hybrid-v1/api.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts +101 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.js +225 -0
- package/dist/suites/pq-hybrid-v1/index.js.map +1 -0
- package/dist/suites/xchacha-v1/api.d.ts +29 -0
- package/dist/suites/xchacha-v1/api.d.ts.map +1 -0
- package/dist/suites/xchacha-v1/api.js +154 -0
- package/dist/suites/xchacha-v1/api.js.map +1 -0
- package/dist/suites/xchacha-v1/index.d.ts +50 -0
- package/dist/suites/xchacha-v1/index.d.ts.map +1 -0
- package/dist/suites/xchacha-v1/index.js +133 -0
- package/dist/suites/xchacha-v1/index.js.map +1 -0
- package/package.json +124 -0
- package/spec/format-v0.md +81 -0
- package/spec/format-v1.md +400 -0
- package/spec/key-derivation.md +167 -0
- package/spec/threat-model.md +242 -0
- package/src/format/header.ts +316 -0
- package/src/identity/index.ts +371 -0
- package/src/identity/sign.ts +221 -0
- package/src/index.ts +224 -0
- package/src/internal/encoding.ts +152 -0
- package/src/internal/hkdf.ts +47 -0
- package/src/internal/hmac.ts +33 -0
- package/src/internal/runtime.ts +80 -0
- package/src/internal/sodium.ts +38 -0
- package/src/internal/types.ts +134 -0
- package/src/kdf/argon2id.ts +165 -0
- package/src/migration/v0-bridge.ts +347 -0
- package/src/streams/aes-gcm-v1.ts +647 -0
- package/src/streams/pq-hybrid-v1.ts +722 -0
- package/src/suites/aes-gcm-v0/api.ts +155 -0
- package/src/suites/aes-gcm-v1/api.ts +292 -0
- package/src/suites/aes-gcm-v1/index.ts +269 -0
- package/src/suites/aes-gcm-v2/api.ts +268 -0
- package/src/suites/aes-gcm-v2/index.ts +289 -0
- package/src/suites/pq-hybrid-v1/api.ts +299 -0
- package/src/suites/pq-hybrid-v1/index.ts +343 -0
- package/src/suites/xchacha-v1/api.ts +254 -0
- package/src/suites/xchacha-v1/index.ts +213 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1 header builder and parser.
|
|
3
|
+
*
|
|
4
|
+
* The header is constructed without the MAC, then the MAC is computed
|
|
5
|
+
* with the content key, then the MAC is appended. On decode, the parser
|
|
6
|
+
* reads everything up to (but not including) the MAC, then the caller
|
|
7
|
+
* verifies the MAC before trusting any field.
|
|
8
|
+
*/
|
|
9
|
+
import { CHUNK_AAD_DOMAIN, CHUNK_AAD_LENGTH, FORMAT_MAGIC, FORMAT_MAGIC_LENGTH, HEADER_FIXED_PREFIX_LENGTH, HEADER_SIZES, HKDF_INFO, MAX_CHUNK_SIZE, MAX_TOTAL_CHUNKS, SUITE, } from '../internal/types.js';
|
|
10
|
+
import { concatBytes, readUint16BE, readUint32BE, readUint64BE, uint16BE, uint32BE, uint64BE, } from '../internal/encoding.js';
|
|
11
|
+
import { hkdfSha256 } from '../internal/hkdf.js';
|
|
12
|
+
import { hmacSha256, hmacSha256Verify } from '../internal/hmac.js';
|
|
13
|
+
const TEXT_ENCODER = new TextEncoder();
|
|
14
|
+
const CHUNK_AAD_DOMAIN_BYTES = TEXT_ENCODER.encode(CHUNK_AAD_DOMAIN);
|
|
15
|
+
const VALID_SUITES = new Set(Object.values(SUITE));
|
|
16
|
+
/**
|
|
17
|
+
* Build the unauthenticated header bytes (everything before the MAC).
|
|
18
|
+
* The caller appends the MAC after deriving header_mac_key.
|
|
19
|
+
*/
|
|
20
|
+
export function buildHeaderUnauthenticated(input) {
|
|
21
|
+
validateHeaderInputs(input);
|
|
22
|
+
return concatBytes([
|
|
23
|
+
FORMAT_MAGIC,
|
|
24
|
+
new Uint8Array([input.suite]),
|
|
25
|
+
new Uint8Array([0x00]), // flags reserved
|
|
26
|
+
input.fileId,
|
|
27
|
+
uint32BE(input.chunkSize),
|
|
28
|
+
uint64BE(input.totalChunks),
|
|
29
|
+
uint64BE(input.plaintextSize),
|
|
30
|
+
uint16BE(input.suitePayload.length),
|
|
31
|
+
input.suitePayload,
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Derive the per-file header MAC key from the content key + file_id.
|
|
36
|
+
*/
|
|
37
|
+
export async function deriveHeaderMacKey(contentKey, fileId) {
|
|
38
|
+
return hkdfSha256({
|
|
39
|
+
ikm: contentKey,
|
|
40
|
+
salt: fileId,
|
|
41
|
+
info: HKDF_INFO.HEADER_MAC,
|
|
42
|
+
length: 32,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a complete authenticated header. `contentKey` is the suite-specific
|
|
47
|
+
* key used to authenticate the header. For the PQ-hybrid suite this is the
|
|
48
|
+
* combined key K (post-HKDF); for AES-GCM and XChaCha suites this is the
|
|
49
|
+
* raw 32-byte content key.
|
|
50
|
+
*/
|
|
51
|
+
export async function buildAuthenticatedHeader(input, contentKey) {
|
|
52
|
+
const unauthenticated = buildHeaderUnauthenticated(input);
|
|
53
|
+
const macKey = await deriveHeaderMacKey(contentKey, input.fileId);
|
|
54
|
+
const mac = await hmacSha256(macKey, unauthenticated);
|
|
55
|
+
return concatBytes([unauthenticated, mac]);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse a header from a byte slice. Returns the parsed fields and the
|
|
59
|
+
* total bytes consumed. Does NOT verify the MAC — callers must call
|
|
60
|
+
* `verifyHeaderMac` separately, after deriving the key.
|
|
61
|
+
*
|
|
62
|
+
* Two-phase parse-then-verify keeps the parser usable for tooling that
|
|
63
|
+
* inspects encrypted files without holding the key.
|
|
64
|
+
*
|
|
65
|
+
* parseHeader does not verify the header MAC. For non-KEM suites
|
|
66
|
+
* (0x01 aes-gcm-v1, 0x02 xchacha-v1), callers MUST call
|
|
67
|
+
* verifyHeaderMac BEFORE doing anything with parsed.suitePayload,
|
|
68
|
+
* including length checks, field extraction, or downstream parsing.
|
|
69
|
+
* KEM suites (0x03 pq-hybrid-v1) cannot follow this rule by
|
|
70
|
+
* construction; see spec/format-v1.md § "0x03 — pq-hybrid" for the
|
|
71
|
+
* required ordering and security argument.
|
|
72
|
+
*
|
|
73
|
+
* Cross-field consistency (totalChunks / chunkSize / plaintextSize) is
|
|
74
|
+
* enforced here via `assertHeaderConsistency`. The same helper runs in
|
|
75
|
+
* `validateHeaderInputs` so encode and decode share one source of
|
|
76
|
+
* truth; both paths MUST stay in sync.
|
|
77
|
+
*/
|
|
78
|
+
export function parseHeader(input) {
|
|
79
|
+
if (input.length < HEADER_FIXED_PREFIX_LENGTH + HEADER_SIZES.HEADER_MAC) {
|
|
80
|
+
throw new HeaderError('header_too_short');
|
|
81
|
+
}
|
|
82
|
+
// Magic
|
|
83
|
+
for (let i = 0; i < FORMAT_MAGIC_LENGTH; i += 1) {
|
|
84
|
+
if (input[i] !== FORMAT_MAGIC[i]) {
|
|
85
|
+
throw new HeaderError('bad_magic');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let offset = FORMAT_MAGIC_LENGTH;
|
|
89
|
+
const suite = input[offset];
|
|
90
|
+
offset += HEADER_SIZES.SUITE;
|
|
91
|
+
if (!VALID_SUITES.has(suite)) {
|
|
92
|
+
throw new HeaderError('unknown_suite');
|
|
93
|
+
}
|
|
94
|
+
const flags = input[offset];
|
|
95
|
+
offset += HEADER_SIZES.FLAGS;
|
|
96
|
+
if (flags !== 0x00) {
|
|
97
|
+
throw new HeaderError('reserved_flags_set');
|
|
98
|
+
}
|
|
99
|
+
const fileId = input.slice(offset, offset + HEADER_SIZES.FILE_ID);
|
|
100
|
+
offset += HEADER_SIZES.FILE_ID;
|
|
101
|
+
const chunkSize = readUint32BE(input, offset);
|
|
102
|
+
offset += HEADER_SIZES.CHUNK_SIZE;
|
|
103
|
+
if (chunkSize === 0 || chunkSize > MAX_CHUNK_SIZE) {
|
|
104
|
+
throw new HeaderError('chunk_size_out_of_range');
|
|
105
|
+
}
|
|
106
|
+
const totalChunks = readUint64BE(input, offset);
|
|
107
|
+
offset += HEADER_SIZES.TOTAL_CHUNKS;
|
|
108
|
+
if (totalChunks > MAX_TOTAL_CHUNKS) {
|
|
109
|
+
throw new HeaderError('total_chunks_out_of_range');
|
|
110
|
+
}
|
|
111
|
+
const plaintextSize = readUint64BE(input, offset);
|
|
112
|
+
offset += HEADER_SIZES.PLAINTEXT_SIZE;
|
|
113
|
+
assertHeaderConsistency({ chunkSize, totalChunks, plaintextSize });
|
|
114
|
+
const suitePayloadLen = readUint16BE(input, offset);
|
|
115
|
+
offset += HEADER_SIZES.SUITE_PAYLOAD_LEN;
|
|
116
|
+
if (offset + suitePayloadLen + HEADER_SIZES.HEADER_MAC > input.length) {
|
|
117
|
+
throw new HeaderError('header_truncated');
|
|
118
|
+
}
|
|
119
|
+
const suitePayload = input.slice(offset, offset + suitePayloadLen);
|
|
120
|
+
offset += suitePayloadLen;
|
|
121
|
+
const macStart = offset;
|
|
122
|
+
const mac = input.slice(macStart, macStart + HEADER_SIZES.HEADER_MAC);
|
|
123
|
+
offset += HEADER_SIZES.HEADER_MAC;
|
|
124
|
+
const unauthenticatedBytes = input.slice(0, macStart);
|
|
125
|
+
return {
|
|
126
|
+
suite: suite,
|
|
127
|
+
flags,
|
|
128
|
+
fileId,
|
|
129
|
+
chunkSize,
|
|
130
|
+
totalChunks,
|
|
131
|
+
plaintextSize,
|
|
132
|
+
suitePayload,
|
|
133
|
+
headerLength: offset,
|
|
134
|
+
unauthenticatedBytes,
|
|
135
|
+
mac,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Verify the parsed header's MAC under the supplied content key.
|
|
140
|
+
* Throws on failure; returns the parsed header on success.
|
|
141
|
+
*/
|
|
142
|
+
export async function verifyHeaderMac(parsed, contentKey) {
|
|
143
|
+
const macKey = await deriveHeaderMacKey(contentKey, parsed.fileId);
|
|
144
|
+
const ok = await hmacSha256Verify(macKey, parsed.unauthenticatedBytes, parsed.mac);
|
|
145
|
+
if (!ok) {
|
|
146
|
+
throw new HeaderError('header_mac_mismatch');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Build the AAD bound into every chunk's AEAD: domain || index || total || is_final.
|
|
151
|
+
*/
|
|
152
|
+
export function buildChunkAad(chunkIndex, totalChunks, isFinal) {
|
|
153
|
+
if (!Number.isSafeInteger(chunkIndex) || chunkIndex < 0) {
|
|
154
|
+
throw new RangeError('buildChunkAad: chunkIndex out of range');
|
|
155
|
+
}
|
|
156
|
+
if (!Number.isSafeInteger(totalChunks) || totalChunks < 0) {
|
|
157
|
+
throw new RangeError('buildChunkAad: totalChunks out of range');
|
|
158
|
+
}
|
|
159
|
+
const out = new Uint8Array(CHUNK_AAD_LENGTH);
|
|
160
|
+
out.set(CHUNK_AAD_DOMAIN_BYTES, 0);
|
|
161
|
+
out.set(uint64BE(chunkIndex), CHUNK_AAD_DOMAIN_BYTES.length);
|
|
162
|
+
out.set(uint64BE(totalChunks), CHUNK_AAD_DOMAIN_BYTES.length + 8);
|
|
163
|
+
out[CHUNK_AAD_DOMAIN_BYTES.length + 16] = isFinal ? 0x01 : 0x00;
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
function validateHeaderInputs(input) {
|
|
167
|
+
if (!VALID_SUITES.has(input.suite)) {
|
|
168
|
+
throw new HeaderError('unknown_suite');
|
|
169
|
+
}
|
|
170
|
+
if (!(input.fileId instanceof Uint8Array)) {
|
|
171
|
+
throw new TypeError('fileId must be a Uint8Array');
|
|
172
|
+
}
|
|
173
|
+
if (input.fileId.length !== HEADER_SIZES.FILE_ID) {
|
|
174
|
+
throw new HeaderError('file_id_wrong_length');
|
|
175
|
+
}
|
|
176
|
+
if (!Number.isSafeInteger(input.chunkSize) ||
|
|
177
|
+
input.chunkSize <= 0 ||
|
|
178
|
+
input.chunkSize > MAX_CHUNK_SIZE) {
|
|
179
|
+
throw new HeaderError('chunk_size_out_of_range');
|
|
180
|
+
}
|
|
181
|
+
if (!Number.isSafeInteger(input.totalChunks) ||
|
|
182
|
+
input.totalChunks < 0 ||
|
|
183
|
+
input.totalChunks > MAX_TOTAL_CHUNKS) {
|
|
184
|
+
throw new HeaderError('total_chunks_out_of_range');
|
|
185
|
+
}
|
|
186
|
+
if (!Number.isSafeInteger(input.plaintextSize) ||
|
|
187
|
+
input.plaintextSize < 0) {
|
|
188
|
+
throw new HeaderError('plaintext_size_out_of_range');
|
|
189
|
+
}
|
|
190
|
+
if (!(input.suitePayload instanceof Uint8Array)) {
|
|
191
|
+
throw new TypeError('suitePayload must be a Uint8Array');
|
|
192
|
+
}
|
|
193
|
+
if (input.suitePayload.length > 0xffff) {
|
|
194
|
+
throw new HeaderError('suite_payload_too_large');
|
|
195
|
+
}
|
|
196
|
+
assertHeaderConsistency({
|
|
197
|
+
chunkSize: input.chunkSize,
|
|
198
|
+
totalChunks: input.totalChunks,
|
|
199
|
+
plaintextSize: input.plaintextSize,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Assert the cross-field invariant tying total_chunks, chunk_size, and
|
|
204
|
+
* plaintext_size together. Shared by `parseHeader` (decode path) and
|
|
205
|
+
* `validateHeaderInputs` (encode path) so both layers reject the same
|
|
206
|
+
* malformed combinations with the same error codes.
|
|
207
|
+
*/
|
|
208
|
+
function assertHeaderConsistency(fields) {
|
|
209
|
+
const { chunkSize, totalChunks, plaintextSize } = fields;
|
|
210
|
+
if (totalChunks === 0 && plaintextSize !== 0) {
|
|
211
|
+
throw new HeaderError('total_chunks_zero_with_plaintext');
|
|
212
|
+
}
|
|
213
|
+
if (totalChunks > 0) {
|
|
214
|
+
const minPlaintext = (totalChunks - 1) * chunkSize + 1;
|
|
215
|
+
const maxPlaintext = totalChunks * chunkSize;
|
|
216
|
+
if (plaintextSize < minPlaintext || plaintextSize > maxPlaintext) {
|
|
217
|
+
throw new HeaderError('plaintext_size_inconsistent');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** Recognizable error class so callers can catch parse failures specifically */
|
|
222
|
+
export class HeaderError extends Error {
|
|
223
|
+
code;
|
|
224
|
+
constructor(code) {
|
|
225
|
+
super(`shieldfive-crypto: header error: ${code}`);
|
|
226
|
+
this.name = 'HeaderError';
|
|
227
|
+
this.code = code;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.js","sourceRoot":"","sources":["../../src/format/header.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAC1B,YAAY,EACZ,SAAS,EACT,cAAc,EACd,gBAAgB,EAEhB,KAAK,GAEN,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,QAAQ,GACT,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAElE,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAA;AACtC,MAAM,sBAAsB,GAAG,YAAY,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AAEpE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAW1D;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAmB;IAC5D,oBAAoB,CAAC,KAAK,CAAC,CAAA;IAC3B,OAAO,WAAW,CAAC;QACjB,YAAY;QACZ,IAAI,UAAU,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,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C,aAAa;KACnC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,uBAAuB,CAAC,MAIhC;IACC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,MAAM,CAAA;IACxD,IAAI,WAAW,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,WAAW,CAAC,kCAAkC,CAAC,CAAA;IAC3D,CAAC;IACD,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,YAAY,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAA;QACtD,MAAM,YAAY,GAAG,WAAW,GAAG,SAAS,CAAA;QAC5C,IAAI,aAAa,GAAG,YAAY,IAAI,aAAa,GAAG,YAAY,EAAE,CAAC;YACjE,MAAM,IAAI,WAAW,CAAC,6BAA6B,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,IAAI,CAAQ;IACrB,YAAY,IAAY;QACtB,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAA;QACjD,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User identity & public-key directory helpers.
|
|
3
|
+
*
|
|
4
|
+
* In a multi-user system, the PQ-hybrid suite needs the recipient's public
|
|
5
|
+
* key to encrypt to. This module provides:
|
|
6
|
+
*
|
|
7
|
+
* - A canonical wire format for publishing a user's public-key bundle
|
|
8
|
+
* (ML-KEM-1024 public key + a self-signed-by-application identity tag).
|
|
9
|
+
* - Helpers for creating, parsing, and verifying public-key bundles.
|
|
10
|
+
* - Helpers for re-encrypting a file's content key to additional
|
|
11
|
+
* recipients (sharing) without re-uploading the file.
|
|
12
|
+
*
|
|
13
|
+
* Cryptographic identity beyond the application's own auth layer is
|
|
14
|
+
* deliberately NOT in scope. The bundle format does not sign the public
|
|
15
|
+
* key with any user-controlled key — the trust anchor is the application's
|
|
16
|
+
* authenticated channel for publishing keys (TLS + auth token). If callers
|
|
17
|
+
* want stronger identity (e.g. SAS verification, gossiped signatures),
|
|
18
|
+
* they wrap this module rather than modify it.
|
|
19
|
+
*/
|
|
20
|
+
export { SIGNATURE_ALGO_ED25519, SIGNATURE_ALGO_ML_DSA_65, ED25519_PUBLIC_KEY_LENGTH, ED25519_SECRET_KEY_LENGTH, ED25519_SIGNATURE_LENGTH, SignatureError, buildSignatureBlock, deriveEd25519PublicKey, parseSignatureBlock, signHeaderAndMacs, verifyHeaderAndMacs, } from './sign.js';
|
|
21
|
+
export type { SignatureBlock } from './sign.js';
|
|
22
|
+
export interface PublicIdentityBundle {
|
|
23
|
+
/** ML-KEM-1024 public key (1568 bytes) */
|
|
24
|
+
mlKemPublicKey: Uint8Array;
|
|
25
|
+
/** Application-assigned user ID (UTF-8 string, ≤255 bytes) */
|
|
26
|
+
userId: string;
|
|
27
|
+
/** Optional metadata blob (≤4 KiB), e.g. a profile JSON */
|
|
28
|
+
metadata?: Uint8Array;
|
|
29
|
+
/** Issuance timestamp (UNIX seconds, uint32) */
|
|
30
|
+
issuedAt: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Wire format for an identity bundle:
|
|
34
|
+
*
|
|
35
|
+
* magic 5 bytes "SF5I" + version
|
|
36
|
+
* issued_at 4 bytes uint32 BE (UNIX seconds)
|
|
37
|
+
* user_id_len 1 byte
|
|
38
|
+
* user_id variable UTF-8
|
|
39
|
+
* ml_kem_pk 1568 bytes
|
|
40
|
+
* metadata_len 2 bytes uint16 BE
|
|
41
|
+
* metadata variable opaque
|
|
42
|
+
*
|
|
43
|
+
* Unsigned. Trust comes from the channel that publishes it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function encodeIdentityBundle(bundle: PublicIdentityBundle): Uint8Array;
|
|
46
|
+
export declare function decodeIdentityBundle(bytes: Uint8Array): PublicIdentityBundle;
|
|
47
|
+
/**
|
|
48
|
+
* Serialize a bundle as a base64 string suitable for storing in a database
|
|
49
|
+
* column or transmitting over a JSON API.
|
|
50
|
+
*/
|
|
51
|
+
export declare function bundleToBase64(bundle: PublicIdentityBundle): string;
|
|
52
|
+
export declare function bundleFromBase64(b64: string): PublicIdentityBundle;
|
|
53
|
+
export interface CreateIdentityOptions {
|
|
54
|
+
userId: string;
|
|
55
|
+
metadata?: Uint8Array;
|
|
56
|
+
/**
|
|
57
|
+
* If provided, the ML-KEM keypair is derived deterministically from
|
|
58
|
+
* this master secret. Otherwise a fresh keypair is generated. Most
|
|
59
|
+
* applications should pass the user's master secret here so that
|
|
60
|
+
* loss of an ML-KEM secret key does not lock the user out.
|
|
61
|
+
*/
|
|
62
|
+
masterSecret?: Uint8Array;
|
|
63
|
+
/** Defaults to current time. */
|
|
64
|
+
issuedAt?: number;
|
|
65
|
+
}
|
|
66
|
+
export interface IdentityKeypair {
|
|
67
|
+
publicBundle: PublicIdentityBundle;
|
|
68
|
+
/** Encoded form of the public bundle for direct publishing. */
|
|
69
|
+
publicBundleBytes: Uint8Array;
|
|
70
|
+
/** ML-KEM-1024 secret key. Treat as highly sensitive. */
|
|
71
|
+
mlKemSecretKey: Uint8Array;
|
|
72
|
+
}
|
|
73
|
+
export declare function createIdentity(options: CreateIdentityOptions): Promise<IdentityKeypair>;
|
|
74
|
+
/**
|
|
75
|
+
* The PQ-hybrid suite encrypts each file's combined key for exactly one
|
|
76
|
+
* recipient (whoever owns the ML-KEM public key the encryptor used).
|
|
77
|
+
* Sharing a file with N additional recipients means: recover the
|
|
78
|
+
* original combined key (only the owner can do this), then produce N new
|
|
79
|
+
* suite_payloads — one per recipient — that decrypt to the SAME combined
|
|
80
|
+
* key. The chunks themselves are not re-encrypted.
|
|
81
|
+
*
|
|
82
|
+
* Each per-recipient suite_payload is stored alongside the file's chunks
|
|
83
|
+
* in the application's database (one row per recipient). The on-disk
|
|
84
|
+
* blob remains unchanged.
|
|
85
|
+
*/
|
|
86
|
+
export interface ShareFileInput {
|
|
87
|
+
/** The file's combined key, recovered by the owner. */
|
|
88
|
+
combinedKey: Uint8Array;
|
|
89
|
+
/** The file's 16-byte file_id. */
|
|
90
|
+
fileId: Uint8Array;
|
|
91
|
+
/** The recipient's identity bundle (provides their ML-KEM public key). */
|
|
92
|
+
recipient: PublicIdentityBundle;
|
|
93
|
+
/** Classical envelope key the recipient holds. */
|
|
94
|
+
recipientEnvelopeKey: Uint8Array;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Build a new suite_payload that decrypts to `combinedKey` for the given
|
|
98
|
+
* recipient. Stored alongside the file as a per-recipient share record.
|
|
99
|
+
*
|
|
100
|
+
* NOTE: the standard `encapsulateForRecipient` produces a NEW combined
|
|
101
|
+
* key. To make sharing work, we use a different construction: we wrap
|
|
102
|
+
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
103
|
+
* envelope) and emit only the wrapped form.
|
|
104
|
+
*/
|
|
105
|
+
export declare function buildShareForRecipient(input: ShareFileInput): Promise<{
|
|
106
|
+
shareBundle: Uint8Array;
|
|
107
|
+
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Recipient side: open a share bundle to recover the file's combined key.
|
|
110
|
+
* The recipient then uses that combined key with the standard PQ-hybrid
|
|
111
|
+
* decrypt path (via the original on-disk file).
|
|
112
|
+
*/
|
|
113
|
+
export declare function openShareAsRecipient(input: {
|
|
114
|
+
shareBundle: Uint8Array;
|
|
115
|
+
fileId: Uint8Array;
|
|
116
|
+
recipientSecretKey: Uint8Array;
|
|
117
|
+
recipientEnvelopeKey: Uint8Array;
|
|
118
|
+
}): Promise<Uint8Array>;
|
|
119
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"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E,qBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAuB1B;AAMD;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,WAAW,EAAE,UAAU,CAAA;IACvB,kCAAkC;IAClC,MAAM,EAAE,UAAU,CAAA;IAClB,0EAA0E;IAC1E,SAAS,EAAE,oBAAoB,CAAA;IAC/B,kDAAkD;IAClD,oBAAoB,EAAE,UAAU,CAAA;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC;IAAE,WAAW,EAAE,UAAU,CAAA;CAAE,CAAC,CAqCtC;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IAChD,WAAW,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,UAAU,CAAA;IAClB,kBAAkB,EAAE,UAAU,CAAA;IAC9B,oBAAoB,EAAE,UAAU,CAAA;CACjC,GAAG,OAAO,CAAC,UAAU,CAAC,CAgDtB"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User identity & public-key directory helpers.
|
|
3
|
+
*
|
|
4
|
+
* In a multi-user system, the PQ-hybrid suite needs the recipient's public
|
|
5
|
+
* key to encrypt to. This module provides:
|
|
6
|
+
*
|
|
7
|
+
* - A canonical wire format for publishing a user's public-key bundle
|
|
8
|
+
* (ML-KEM-1024 public key + a self-signed-by-application identity tag).
|
|
9
|
+
* - Helpers for creating, parsing, and verifying public-key bundles.
|
|
10
|
+
* - Helpers for re-encrypting a file's content key to additional
|
|
11
|
+
* recipients (sharing) without re-uploading the file.
|
|
12
|
+
*
|
|
13
|
+
* Cryptographic identity beyond the application's own auth layer is
|
|
14
|
+
* deliberately NOT in scope. The bundle format does not sign the public
|
|
15
|
+
* key with any user-controlled key — the trust anchor is the application's
|
|
16
|
+
* authenticated channel for publishing keys (TLS + auth token). If callers
|
|
17
|
+
* want stronger identity (e.g. SAS verification, gossiped signatures),
|
|
18
|
+
* they wrap this module rather than modify it.
|
|
19
|
+
*/
|
|
20
|
+
import { ML_KEM_1024_PUBLIC_KEY_BYTES, ML_KEM_1024_SECRET_KEY_BYTES, deriveMlKemKeypair, generateMlKemKeypair, encapsulateForRecipient, decapsulateFromHeader, parsePqHybridV1SuitePayload, buildPqHybridV1SuitePayload, } from '../suites/pq-hybrid-v1/index.js';
|
|
21
|
+
export { SIGNATURE_ALGO_ED25519, SIGNATURE_ALGO_ML_DSA_65, ED25519_PUBLIC_KEY_LENGTH, ED25519_SECRET_KEY_LENGTH, ED25519_SIGNATURE_LENGTH, SignatureError, buildSignatureBlock, deriveEd25519PublicKey, parseSignatureBlock, signHeaderAndMacs, verifyHeaderAndMacs, } from './sign.js';
|
|
22
|
+
import { bytesToBase64, base64ToBytes, concatBytes, uint16BE, uint32BE, readUint16BE, readUint32BE, } from '../internal/encoding.js';
|
|
23
|
+
import { randomBytes } from '../internal/runtime.js';
|
|
24
|
+
import { getSodium } from '../internal/sodium.js';
|
|
25
|
+
const IDENTITY_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x49, 0x01]); // "SF5I" + version
|
|
26
|
+
/**
|
|
27
|
+
* Wire format for an identity bundle:
|
|
28
|
+
*
|
|
29
|
+
* magic 5 bytes "SF5I" + version
|
|
30
|
+
* issued_at 4 bytes uint32 BE (UNIX seconds)
|
|
31
|
+
* user_id_len 1 byte
|
|
32
|
+
* user_id variable UTF-8
|
|
33
|
+
* ml_kem_pk 1568 bytes
|
|
34
|
+
* metadata_len 2 bytes uint16 BE
|
|
35
|
+
* metadata variable opaque
|
|
36
|
+
*
|
|
37
|
+
* Unsigned. Trust comes from the channel that publishes it.
|
|
38
|
+
*/
|
|
39
|
+
export function encodeIdentityBundle(bundle) {
|
|
40
|
+
if (bundle.mlKemPublicKey.length !== ML_KEM_1024_PUBLIC_KEY_BYTES) {
|
|
41
|
+
throw new RangeError(`encodeIdentityBundle: mlKemPublicKey must be ${ML_KEM_1024_PUBLIC_KEY_BYTES} bytes`);
|
|
42
|
+
}
|
|
43
|
+
const userIdBytes = new TextEncoder().encode(bundle.userId);
|
|
44
|
+
if (userIdBytes.length === 0 || userIdBytes.length > 255) {
|
|
45
|
+
throw new RangeError('encodeIdentityBundle: userId must be 1..255 UTF-8 bytes');
|
|
46
|
+
}
|
|
47
|
+
if (!Number.isSafeInteger(bundle.issuedAt) ||
|
|
48
|
+
bundle.issuedAt < 0 ||
|
|
49
|
+
bundle.issuedAt > 0xffff_ffff) {
|
|
50
|
+
throw new RangeError('encodeIdentityBundle: issuedAt must fit in uint32');
|
|
51
|
+
}
|
|
52
|
+
const metadata = bundle.metadata ?? new Uint8Array(0);
|
|
53
|
+
if (metadata.length > 4096) {
|
|
54
|
+
throw new RangeError('encodeIdentityBundle: metadata must be at most 4096 bytes');
|
|
55
|
+
}
|
|
56
|
+
return concatBytes([
|
|
57
|
+
IDENTITY_BUNDLE_MAGIC,
|
|
58
|
+
uint32BE(bundle.issuedAt),
|
|
59
|
+
new Uint8Array([userIdBytes.length]),
|
|
60
|
+
userIdBytes,
|
|
61
|
+
bundle.mlKemPublicKey,
|
|
62
|
+
uint16BE(metadata.length),
|
|
63
|
+
metadata,
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
export function decodeIdentityBundle(bytes) {
|
|
67
|
+
if (bytes.length < IDENTITY_BUNDLE_MAGIC.length + 4 + 1) {
|
|
68
|
+
throw new RangeError('decodeIdentityBundle: input too short');
|
|
69
|
+
}
|
|
70
|
+
for (let i = 0; i < IDENTITY_BUNDLE_MAGIC.length; i += 1) {
|
|
71
|
+
if (bytes[i] !== IDENTITY_BUNDLE_MAGIC[i]) {
|
|
72
|
+
throw new Error('decodeIdentityBundle: bad magic / unknown bundle version');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let offset = IDENTITY_BUNDLE_MAGIC.length;
|
|
76
|
+
const issuedAt = readUint32BE(bytes, offset);
|
|
77
|
+
offset += 4;
|
|
78
|
+
const userIdLen = bytes[offset];
|
|
79
|
+
offset += 1;
|
|
80
|
+
if (userIdLen === 0) {
|
|
81
|
+
throw new Error('decodeIdentityBundle: empty user_id');
|
|
82
|
+
}
|
|
83
|
+
if (offset + userIdLen + ML_KEM_1024_PUBLIC_KEY_BYTES + 2 > bytes.length) {
|
|
84
|
+
throw new Error('decodeIdentityBundle: truncated');
|
|
85
|
+
}
|
|
86
|
+
const userId = new TextDecoder('utf-8', { fatal: true }).decode(bytes.slice(offset, offset + userIdLen));
|
|
87
|
+
offset += userIdLen;
|
|
88
|
+
const mlKemPublicKey = bytes.slice(offset, offset + ML_KEM_1024_PUBLIC_KEY_BYTES);
|
|
89
|
+
offset += ML_KEM_1024_PUBLIC_KEY_BYTES;
|
|
90
|
+
const metadataLen = readUint16BE(bytes, offset);
|
|
91
|
+
offset += 2;
|
|
92
|
+
if (offset + metadataLen !== bytes.length) {
|
|
93
|
+
throw new Error('decodeIdentityBundle: trailing bytes or wrong metadata_len');
|
|
94
|
+
}
|
|
95
|
+
const metadata = bytes.slice(offset, offset + metadataLen);
|
|
96
|
+
const result = {
|
|
97
|
+
mlKemPublicKey,
|
|
98
|
+
userId,
|
|
99
|
+
issuedAt,
|
|
100
|
+
};
|
|
101
|
+
if (metadata.length > 0)
|
|
102
|
+
result.metadata = metadata;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Serialize a bundle as a base64 string suitable for storing in a database
|
|
107
|
+
* column or transmitting over a JSON API.
|
|
108
|
+
*/
|
|
109
|
+
export function bundleToBase64(bundle) {
|
|
110
|
+
return bytesToBase64(encodeIdentityBundle(bundle));
|
|
111
|
+
}
|
|
112
|
+
export function bundleFromBase64(b64) {
|
|
113
|
+
return decodeIdentityBundle(base64ToBytes(b64));
|
|
114
|
+
}
|
|
115
|
+
export async function createIdentity(options) {
|
|
116
|
+
const keypair = options.masterSecret
|
|
117
|
+
? await deriveMlKemKeypair(options.masterSecret)
|
|
118
|
+
: generateMlKemKeypair();
|
|
119
|
+
const bundle = {
|
|
120
|
+
mlKemPublicKey: keypair.publicKey,
|
|
121
|
+
userId: options.userId,
|
|
122
|
+
issuedAt: options.issuedAt ?? Math.floor(Date.now() / 1000),
|
|
123
|
+
};
|
|
124
|
+
if (options.metadata)
|
|
125
|
+
bundle.metadata = options.metadata;
|
|
126
|
+
if (keypair.secretKey.length !== ML_KEM_1024_SECRET_KEY_BYTES) {
|
|
127
|
+
throw new Error(`createIdentity: unexpected secret key length ${keypair.secretKey.length}`);
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
publicBundle: bundle,
|
|
131
|
+
publicBundleBytes: encodeIdentityBundle(bundle),
|
|
132
|
+
mlKemSecretKey: keypair.secretKey,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Build a new suite_payload that decrypts to `combinedKey` for the given
|
|
137
|
+
* recipient. Stored alongside the file as a per-recipient share record.
|
|
138
|
+
*
|
|
139
|
+
* NOTE: the standard `encapsulateForRecipient` produces a NEW combined
|
|
140
|
+
* key. To make sharing work, we use a different construction: we wrap
|
|
141
|
+
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
142
|
+
* envelope) and emit only the wrapped form.
|
|
143
|
+
*/
|
|
144
|
+
export async function buildShareForRecipient(input) {
|
|
145
|
+
const sodium = await getSodium();
|
|
146
|
+
// Generate a fresh transport key for this share.
|
|
147
|
+
// ML-KEM encapsulation gives us the PQ-half of the transport secret.
|
|
148
|
+
const { suitePayload: pqPayload, combinedKey: transportKey } = await encapsulateForRecipient({
|
|
149
|
+
recipientPublicKey: input.recipient.mlKemPublicKey,
|
|
150
|
+
envelopeKey: input.recipientEnvelopeKey,
|
|
151
|
+
fileId: input.fileId,
|
|
152
|
+
});
|
|
153
|
+
// Now wrap the original combined key under the transport key using
|
|
154
|
+
// XSalsa20-Poly1305 secretbox.
|
|
155
|
+
if (transportKey.length !== 32) {
|
|
156
|
+
throw new Error('buildShareForRecipient: transport key length wrong');
|
|
157
|
+
}
|
|
158
|
+
const wrapNonce = randomBytes(24);
|
|
159
|
+
const wrappedCombinedKey = sodium.crypto_secretbox_easy(input.combinedKey, wrapNonce, transportKey);
|
|
160
|
+
if (wrappedCombinedKey.length !== 32 + 16) {
|
|
161
|
+
throw new Error('buildShareForRecipient: secretbox produced unexpected length');
|
|
162
|
+
}
|
|
163
|
+
// Share record format:
|
|
164
|
+
// [4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
165
|
+
return {
|
|
166
|
+
shareBundle: concatBytes([
|
|
167
|
+
uint32BE(pqPayload.length),
|
|
168
|
+
pqPayload,
|
|
169
|
+
wrapNonce,
|
|
170
|
+
wrappedCombinedKey,
|
|
171
|
+
]),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Recipient side: open a share bundle to recover the file's combined key.
|
|
176
|
+
* The recipient then uses that combined key with the standard PQ-hybrid
|
|
177
|
+
* decrypt path (via the original on-disk file).
|
|
178
|
+
*/
|
|
179
|
+
export async function openShareAsRecipient(input) {
|
|
180
|
+
const sodium = await getSodium();
|
|
181
|
+
if (input.shareBundle.length < 4) {
|
|
182
|
+
throw new Error('openShareAsRecipient: share too short');
|
|
183
|
+
}
|
|
184
|
+
let offset = 0;
|
|
185
|
+
const pqLen = readUint32BE(input.shareBundle, offset);
|
|
186
|
+
offset += 4;
|
|
187
|
+
if (offset + pqLen + 24 + 48 !== input.shareBundle.length) {
|
|
188
|
+
throw new Error('openShareAsRecipient: malformed share');
|
|
189
|
+
}
|
|
190
|
+
const pqPayload = input.shareBundle.slice(offset, offset + pqLen);
|
|
191
|
+
offset += pqLen;
|
|
192
|
+
const wrapNonce = input.shareBundle.slice(offset, offset + 24);
|
|
193
|
+
offset += 24;
|
|
194
|
+
const wrappedCombinedKey = input.shareBundle.slice(offset, offset + 48);
|
|
195
|
+
// Sanity-check the suite payload structure (this throws if malformed).
|
|
196
|
+
parsePqHybridV1SuitePayload(pqPayload);
|
|
197
|
+
// Round-trip through builder to ensure we got back the same bytes.
|
|
198
|
+
const checkBytes = buildPqHybridV1SuitePayload(parsePqHybridV1SuitePayload(pqPayload));
|
|
199
|
+
if (checkBytes.length !== pqPayload.length) {
|
|
200
|
+
throw new Error('openShareAsRecipient: pq payload self-check failed');
|
|
201
|
+
}
|
|
202
|
+
const { combinedKey: transportKey } = await decapsulateFromHeader({
|
|
203
|
+
suitePayload: pqPayload,
|
|
204
|
+
recipientSecretKey: input.recipientSecretKey,
|
|
205
|
+
envelopeKey: input.recipientEnvelopeKey,
|
|
206
|
+
fileId: input.fileId,
|
|
207
|
+
});
|
|
208
|
+
const unwrapped = sodium.crypto_secretbox_open_easy(wrappedCombinedKey, wrapNonce, transportKey);
|
|
209
|
+
if (!unwrapped) {
|
|
210
|
+
throw new Error('openShareAsRecipient: secretbox unwrap failed — wrong recipient or tampered share');
|
|
211
|
+
}
|
|
212
|
+
if (unwrapped.length !== 32) {
|
|
213
|
+
throw new Error('openShareAsRecipient: bad combined key length');
|
|
214
|
+
}
|
|
215
|
+
return new Uint8Array(unwrapped);
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,mBAA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