@push.rocks/smartcrypto 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/.smartconfig.json +6 -5
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/index.d.ts +4 -0
  4. package/dist_ts/index.js +4 -1
  5. package/dist_ts/smartcrypto.classes.keypair.d.ts +6 -1
  6. package/dist_ts/smartcrypto.classes.keypair.js +11 -5
  7. package/dist_ts/smartcrypto.classes.privatekey.d.ts +13 -0
  8. package/dist_ts/smartcrypto.classes.privatekey.js +26 -1
  9. package/dist_ts/smartcrypto.classes.smartcrypto.d.ts +2 -2
  10. package/dist_ts/smartcrypto.classes.smartcrypto.js +3 -3
  11. package/dist_ts/smartcrypto.errors.d.ts +17 -0
  12. package/dist_ts/smartcrypto.errors.js +27 -0
  13. package/dist_ts/smartcrypto.internal.d.ts +12 -0
  14. package/dist_ts/smartcrypto.internal.js +133 -0
  15. package/dist_ts/smartcrypto.pkcs8.d.ts +14 -0
  16. package/dist_ts/smartcrypto.pkcs8.js +252 -0
  17. package/dist_ts/smartcrypto.webcrypto.d.ts +49 -0
  18. package/dist_ts/smartcrypto.webcrypto.js +179 -0
  19. package/dist_ts/smartcrypto.x25519.d.ts +46 -0
  20. package/dist_ts/smartcrypto.x25519.js +339 -0
  21. package/{license → license.md} +2 -1
  22. package/package.json +14 -9
  23. package/readme.md +138 -55
  24. package/ts/00_commitinfo_data.ts +1 -1
  25. package/ts/index.ts +7 -0
  26. package/ts/smartcrypto.classes.keypair.ts +18 -4
  27. package/ts/smartcrypto.classes.privatekey.ts +34 -0
  28. package/ts/smartcrypto.classes.smartcrypto.ts +3 -3
  29. package/ts/smartcrypto.errors.ts +54 -0
  30. package/ts/smartcrypto.internal.ts +162 -0
  31. package/ts/smartcrypto.pkcs8.ts +311 -0
  32. package/ts/smartcrypto.webcrypto.ts +266 -0
  33. package/ts/smartcrypto.x25519.ts +493 -0
  34. package/readme.hints.md +0 -1
@@ -0,0 +1,493 @@
1
+ import { SmartCryptoError, createSmartCryptoError } from './smartcrypto.errors.js';
2
+ import {
3
+ bytesEqual,
4
+ concatBytes,
5
+ decodeCanonicalBase64Url,
6
+ encodeBase64Url,
7
+ getWebCrypto,
8
+ isAllZero,
9
+ requireLength,
10
+ requirePlainDataObject,
11
+ requireUint8Array,
12
+ sha256,
13
+ toArrayBuffer,
14
+ } from './smartcrypto.internal.js';
15
+ import {
16
+ SMARTCRYPTO_AES_256_KEY_BYTES,
17
+ SMARTCRYPTO_AES_GCM_NONCE_BYTES,
18
+ SMARTCRYPTO_AES_GCM_TAG_BYTES,
19
+ aesGcmDecrypt,
20
+ aesGcmEncrypt,
21
+ } from './smartcrypto.webcrypto.js';
22
+
23
+ export const SMARTCRYPTO_X25519_PROFILE = 'x25519-hkdf-sha256-aes-256-gcm-v1' as const;
24
+ export const SMARTCRYPTO_X25519_KEY_BYTES = 32;
25
+ export const SMARTCRYPTO_MAX_CIPHERTEXT_BYTES = 16 * 1024 * 1024;
26
+ export const SMARTCRYPTO_MAX_RECIPIENT_KEY_ID_BYTES = 512;
27
+
28
+ const x25519PrivateKeyPkcs8Prefix = new Uint8Array([
29
+ 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
30
+ 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20,
31
+ ]);
32
+ const expectedEnvelopeKeys = [
33
+ 'schemaVersion',
34
+ 'profile',
35
+ 'recipientKeyId',
36
+ 'ephemeralPublicKey',
37
+ 'nonce',
38
+ 'ciphertext',
39
+ 'tag',
40
+ 'contextDigest',
41
+ ] as const;
42
+ const textEncoder = new TextEncoder();
43
+
44
+ export interface IX25519KeyPair {
45
+ publicKey: Uint8Array;
46
+ privateKey: Uint8Array;
47
+ }
48
+
49
+ export interface IX25519EnvelopeV1 {
50
+ schemaVersion: 1;
51
+ profile: typeof SMARTCRYPTO_X25519_PROFILE;
52
+ recipientKeyId: string;
53
+ ephemeralPublicKey: string;
54
+ nonce: string;
55
+ ciphertext: string;
56
+ tag: string;
57
+ contextDigest: string;
58
+ }
59
+
60
+ export interface ISealX25519EnvelopeOptions {
61
+ plaintext: Uint8Array;
62
+ recipientPublicKey: Uint8Array;
63
+ recipientKeyId: string;
64
+ context: Uint8Array;
65
+ }
66
+
67
+ export interface IOpenX25519EnvelopeOptions {
68
+ envelope: unknown;
69
+ recipientPrivateKey: Uint8Array;
70
+ expectedRecipientKeyId: string;
71
+ context: Uint8Array;
72
+ }
73
+
74
+ const requireRecipientKeyId = (
75
+ valueArg: unknown,
76
+ envelopeArg = false,
77
+ ): { value: string; encoded: Uint8Array } => {
78
+ const errorCode = envelopeArg ? 'INVALID_ENVELOPE' : 'INVALID_ARGUMENT';
79
+ if (typeof valueArg !== 'string' || valueArg.length === 0) {
80
+ throw createSmartCryptoError(errorCode);
81
+ }
82
+ if (valueArg.length > SMARTCRYPTO_MAX_RECIPIENT_KEY_ID_BYTES) {
83
+ throw createSmartCryptoError('SIZE_LIMIT_EXCEEDED');
84
+ }
85
+ for (let index = 0; index < valueArg.length; index++) {
86
+ const codeUnit = valueArg.charCodeAt(index);
87
+ if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
88
+ const nextCodeUnit = valueArg.charCodeAt(index + 1);
89
+ if (
90
+ index + 1 >= valueArg.length
91
+ || nextCodeUnit < 0xdc00
92
+ || nextCodeUnit > 0xdfff
93
+ ) {
94
+ throw createSmartCryptoError(errorCode);
95
+ }
96
+ index++;
97
+ } else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
98
+ throw createSmartCryptoError(errorCode);
99
+ }
100
+ }
101
+ const encoded = textEncoder.encode(valueArg);
102
+ if (encoded.byteLength > SMARTCRYPTO_MAX_RECIPIENT_KEY_ID_BYTES) {
103
+ throw createSmartCryptoError('SIZE_LIMIT_EXCEEDED');
104
+ }
105
+ return { value: valueArg, encoded };
106
+ };
107
+
108
+ const assertX25519CryptoKey = (
109
+ keyArg: CryptoKey,
110
+ typeArg: 'private' | 'public',
111
+ ): void => {
112
+ if (
113
+ keyArg === null
114
+ || typeof keyArg !== 'object'
115
+ || keyArg.type !== typeArg
116
+ || keyArg.algorithm?.name !== 'X25519'
117
+ || !keyArg.extractable
118
+ ) {
119
+ throw createSmartCryptoError('INVALID_KEY');
120
+ }
121
+ };
122
+
123
+ /** Imports exactly 32 raw X25519 public-key bytes. */
124
+ export const importX25519PublicKey = async (rawKeyArg: Uint8Array): Promise<CryptoKey> => {
125
+ const rawKey = requireLength(
126
+ requireUint8Array(rawKeyArg, 'INVALID_KEY'),
127
+ SMARTCRYPTO_X25519_KEY_BYTES,
128
+ 'INVALID_KEY',
129
+ );
130
+ try {
131
+ return await getWebCrypto().subtle.importKey(
132
+ 'raw',
133
+ toArrayBuffer(rawKey),
134
+ { name: 'X25519' },
135
+ true,
136
+ [],
137
+ );
138
+ } catch {
139
+ throw createSmartCryptoError('INVALID_KEY');
140
+ }
141
+ };
142
+
143
+ /** Exports one extractable X25519 public key as exactly 32 raw bytes. */
144
+ export const exportX25519PublicKey = async (keyArg: CryptoKey): Promise<Uint8Array> => {
145
+ assertX25519CryptoKey(keyArg, 'public');
146
+ try {
147
+ return requireLength(
148
+ new Uint8Array(await getWebCrypto().subtle.exportKey('raw', keyArg)),
149
+ SMARTCRYPTO_X25519_KEY_BYTES,
150
+ 'INVALID_KEY',
151
+ );
152
+ } catch (error) {
153
+ if (error instanceof SmartCryptoError) {
154
+ throw error;
155
+ }
156
+ throw createSmartCryptoError('INVALID_KEY');
157
+ }
158
+ };
159
+
160
+ /** Imports exactly 32 raw X25519 private-key bytes through canonical RFC 8410 PKCS#8. */
161
+ export const importX25519PrivateKey = async (rawKeyArg: Uint8Array): Promise<CryptoKey> => {
162
+ const rawKey = requireLength(
163
+ requireUint8Array(rawKeyArg, 'INVALID_KEY'),
164
+ SMARTCRYPTO_X25519_KEY_BYTES,
165
+ 'INVALID_KEY',
166
+ );
167
+ const pkcs8 = concatBytes(x25519PrivateKeyPkcs8Prefix, rawKey);
168
+ const pkcs8Buffer = toArrayBuffer(pkcs8);
169
+ try {
170
+ return await getWebCrypto().subtle.importKey(
171
+ 'pkcs8',
172
+ pkcs8Buffer,
173
+ { name: 'X25519' },
174
+ true,
175
+ ['deriveBits'],
176
+ );
177
+ } catch {
178
+ throw createSmartCryptoError('INVALID_KEY');
179
+ } finally {
180
+ rawKey.fill(0);
181
+ pkcs8.fill(0);
182
+ new Uint8Array(pkcs8Buffer).fill(0);
183
+ }
184
+ };
185
+
186
+ /** Exports one extractable X25519 private key as exactly 32 raw bytes. */
187
+ export const exportX25519PrivateKey = async (keyArg: CryptoKey): Promise<Uint8Array> => {
188
+ assertX25519CryptoKey(keyArg, 'private');
189
+ let pkcs8: Uint8Array | undefined;
190
+ try {
191
+ pkcs8 = new Uint8Array(await getWebCrypto().subtle.exportKey('pkcs8', keyArg));
192
+ if (
193
+ pkcs8.byteLength !== x25519PrivateKeyPkcs8Prefix.byteLength + SMARTCRYPTO_X25519_KEY_BYTES
194
+ || !bytesEqual(pkcs8.subarray(0, x25519PrivateKeyPkcs8Prefix.byteLength), x25519PrivateKeyPkcs8Prefix)
195
+ ) {
196
+ throw createSmartCryptoError('INVALID_KEY');
197
+ }
198
+ return pkcs8.slice(x25519PrivateKeyPkcs8Prefix.byteLength);
199
+ } catch (error) {
200
+ if (error instanceof SmartCryptoError) {
201
+ throw error;
202
+ }
203
+ throw createSmartCryptoError('INVALID_KEY');
204
+ } finally {
205
+ pkcs8?.fill(0);
206
+ }
207
+ };
208
+
209
+ /** Generates an exportable raw X25519 key pair. */
210
+ export const generateX25519KeyPair = async (): Promise<IX25519KeyPair> => {
211
+ try {
212
+ const keyPair = await getWebCrypto().subtle.generateKey(
213
+ { name: 'X25519' },
214
+ true,
215
+ ['deriveBits'],
216
+ ) as CryptoKeyPair;
217
+ return {
218
+ publicKey: await exportX25519PublicKey(keyPair.publicKey),
219
+ privateKey: await exportX25519PrivateKey(keyPair.privateKey),
220
+ };
221
+ } catch (error) {
222
+ if (error instanceof SmartCryptoError) {
223
+ throw error;
224
+ }
225
+ throw createSmartCryptoError('CRYPTO_OPERATION_FAILED');
226
+ }
227
+ };
228
+
229
+ const deriveSharedSecret = async (
230
+ privateKeyArg: CryptoKey,
231
+ publicKeyArg: CryptoKey,
232
+ ): Promise<Uint8Array> => {
233
+ try {
234
+ const sharedSecret = new Uint8Array(await getWebCrypto().subtle.deriveBits(
235
+ { name: 'X25519', public: publicKeyArg },
236
+ privateKeyArg,
237
+ SMARTCRYPTO_X25519_KEY_BYTES * 8,
238
+ ));
239
+ if (
240
+ sharedSecret.byteLength !== SMARTCRYPTO_X25519_KEY_BYTES
241
+ || isAllZero(sharedSecret)
242
+ ) {
243
+ sharedSecret.fill(0);
244
+ throw createSmartCryptoError('INVALID_SHARED_SECRET');
245
+ }
246
+ return sharedSecret;
247
+ } catch (error) {
248
+ if (error instanceof SmartCryptoError) {
249
+ throw error;
250
+ }
251
+ throw createSmartCryptoError('INVALID_SHARED_SECRET');
252
+ }
253
+ };
254
+
255
+ const deriveAesKey = async (
256
+ sharedSecretArg: Uint8Array,
257
+ recipientKeyIdArg: Uint8Array,
258
+ contextDigestArg: Uint8Array,
259
+ ): Promise<Uint8Array> => {
260
+ const profile = textEncoder.encode(SMARTCRYPTO_X25519_PROFILE);
261
+ const saltInput = concatBytes(profile, new Uint8Array([0]), recipientKeyIdArg);
262
+ const info = concatBytes(profile, new Uint8Array([0]), contextDigestArg);
263
+ const salt = await sha256(saltInput);
264
+ const sharedSecretBuffer = toArrayBuffer(sharedSecretArg);
265
+ let saltBuffer: ArrayBuffer | undefined;
266
+ let infoBuffer: ArrayBuffer | undefined;
267
+ try {
268
+ const keyMaterial = await getWebCrypto().subtle.importKey(
269
+ 'raw',
270
+ sharedSecretBuffer,
271
+ { name: 'HKDF' },
272
+ false,
273
+ ['deriveBits'],
274
+ );
275
+ new Uint8Array(sharedSecretBuffer).fill(0);
276
+ saltBuffer = toArrayBuffer(salt);
277
+ infoBuffer = toArrayBuffer(info);
278
+ return new Uint8Array(await getWebCrypto().subtle.deriveBits(
279
+ {
280
+ name: 'HKDF',
281
+ hash: 'SHA-256',
282
+ salt: saltBuffer,
283
+ info: infoBuffer,
284
+ },
285
+ keyMaterial,
286
+ SMARTCRYPTO_AES_256_KEY_BYTES * 8,
287
+ ));
288
+ } catch {
289
+ throw createSmartCryptoError('CRYPTO_OPERATION_FAILED');
290
+ } finally {
291
+ saltInput.fill(0);
292
+ info.fill(0);
293
+ salt.fill(0);
294
+ new Uint8Array(sharedSecretBuffer).fill(0);
295
+ if (saltBuffer) {
296
+ new Uint8Array(saltBuffer).fill(0);
297
+ }
298
+ if (infoBuffer) {
299
+ new Uint8Array(infoBuffer).fill(0);
300
+ }
301
+ }
302
+ };
303
+
304
+ /** Strictly validates an envelope, including exact fields and canonical encodings. */
305
+ export const parseX25519Envelope = (envelopeArg: unknown): IX25519EnvelopeV1 => {
306
+ const envelope = requirePlainDataObject(envelopeArg, expectedEnvelopeKeys);
307
+ if (envelope.schemaVersion !== 1) {
308
+ throw createSmartCryptoError('UNSUPPORTED_VERSION');
309
+ }
310
+ if (envelope.profile !== SMARTCRYPTO_X25519_PROFILE) {
311
+ throw createSmartCryptoError('UNSUPPORTED_PROFILE');
312
+ }
313
+ const recipientKeyId = requireRecipientKeyId(envelope.recipientKeyId, true).value;
314
+ decodeCanonicalBase64Url(
315
+ envelope.ephemeralPublicKey,
316
+ SMARTCRYPTO_X25519_KEY_BYTES,
317
+ SMARTCRYPTO_X25519_KEY_BYTES,
318
+ );
319
+ decodeCanonicalBase64Url(
320
+ envelope.nonce,
321
+ SMARTCRYPTO_AES_GCM_NONCE_BYTES,
322
+ SMARTCRYPTO_AES_GCM_NONCE_BYTES,
323
+ );
324
+ decodeCanonicalBase64Url(
325
+ envelope.ciphertext,
326
+ SMARTCRYPTO_MAX_CIPHERTEXT_BYTES,
327
+ );
328
+ decodeCanonicalBase64Url(
329
+ envelope.tag,
330
+ SMARTCRYPTO_AES_GCM_TAG_BYTES,
331
+ SMARTCRYPTO_AES_GCM_TAG_BYTES,
332
+ );
333
+ decodeCanonicalBase64Url(envelope.contextDigest, 32, 32);
334
+ return {
335
+ schemaVersion: 1,
336
+ profile: SMARTCRYPTO_X25519_PROFILE,
337
+ recipientKeyId,
338
+ ephemeralPublicKey: envelope.ephemeralPublicKey as string,
339
+ nonce: envelope.nonce as string,
340
+ ciphertext: envelope.ciphertext as string,
341
+ tag: envelope.tag as string,
342
+ contextDigest: envelope.contextDigest as string,
343
+ };
344
+ };
345
+
346
+ /** Seals bytes to one recipient using the fixed v1 X25519 profile. */
347
+ export const sealX25519Envelope = async (
348
+ optionsArg: ISealX25519EnvelopeOptions,
349
+ ): Promise<IX25519EnvelopeV1> => {
350
+ if (optionsArg === null || typeof optionsArg !== 'object') {
351
+ throw createSmartCryptoError('INVALID_ARGUMENT');
352
+ }
353
+ const plaintextInput = optionsArg.plaintext;
354
+ const contextInput = optionsArg.context;
355
+ const recipientKeyIdInput = optionsArg.recipientKeyId;
356
+ const recipientPublicKeyInput = optionsArg.recipientPublicKey;
357
+ if (!(plaintextInput instanceof Uint8Array)) {
358
+ throw createSmartCryptoError('INVALID_ARGUMENT');
359
+ }
360
+ if (plaintextInput.byteLength > SMARTCRYPTO_MAX_CIPHERTEXT_BYTES) {
361
+ throw createSmartCryptoError('SIZE_LIMIT_EXCEEDED');
362
+ }
363
+ if (!(contextInput instanceof Uint8Array)) {
364
+ throw createSmartCryptoError('INVALID_ARGUMENT');
365
+ }
366
+ const recipientKeyId = requireRecipientKeyId(recipientKeyIdInput);
367
+ let plaintext: Uint8Array | undefined;
368
+ let context: Uint8Array | undefined;
369
+ let sharedSecret: Uint8Array | undefined;
370
+ let aesKey: Uint8Array | undefined;
371
+ try {
372
+ plaintext = new Uint8Array(plaintextInput);
373
+ context = new Uint8Array(contextInput);
374
+ const recipientPublicKey = await importX25519PublicKey(recipientPublicKeyInput);
375
+ const ephemeralKeyPair = await getWebCrypto().subtle.generateKey(
376
+ { name: 'X25519' },
377
+ false,
378
+ ['deriveBits'],
379
+ ) as CryptoKeyPair;
380
+ const ephemeralPublicKey = new Uint8Array(
381
+ await getWebCrypto().subtle.exportKey('raw', ephemeralKeyPair.publicKey),
382
+ );
383
+ requireLength(
384
+ ephemeralPublicKey,
385
+ SMARTCRYPTO_X25519_KEY_BYTES,
386
+ 'CRYPTO_OPERATION_FAILED',
387
+ );
388
+ sharedSecret = await deriveSharedSecret(ephemeralKeyPair.privateKey, recipientPublicKey);
389
+ const contextDigest = await sha256(context);
390
+ aesKey = await deriveAesKey(sharedSecret, recipientKeyId.encoded, contextDigest);
391
+ const encryptedData = await aesGcmEncrypt({ key: aesKey, plaintext, aad: context });
392
+ return {
393
+ schemaVersion: 1,
394
+ profile: SMARTCRYPTO_X25519_PROFILE,
395
+ recipientKeyId: recipientKeyId.value,
396
+ ephemeralPublicKey: encodeBase64Url(ephemeralPublicKey),
397
+ nonce: encodeBase64Url(encryptedData.nonce),
398
+ ciphertext: encodeBase64Url(encryptedData.ciphertext),
399
+ tag: encodeBase64Url(encryptedData.tag),
400
+ contextDigest: encodeBase64Url(contextDigest),
401
+ };
402
+ } catch (error) {
403
+ if (error instanceof SmartCryptoError) {
404
+ throw error;
405
+ }
406
+ throw createSmartCryptoError('CRYPTO_OPERATION_FAILED');
407
+ } finally {
408
+ plaintext?.fill(0);
409
+ context?.fill(0);
410
+ recipientKeyId.encoded.fill(0);
411
+ sharedSecret?.fill(0);
412
+ aesKey?.fill(0);
413
+ }
414
+ };
415
+
416
+ /** Opens one strict v1 envelope after checking recipient and exact context bindings. */
417
+ export const openX25519Envelope = async (
418
+ optionsArg: IOpenX25519EnvelopeOptions,
419
+ ): Promise<Uint8Array> => {
420
+ if (optionsArg === null || typeof optionsArg !== 'object') {
421
+ throw createSmartCryptoError('INVALID_ARGUMENT');
422
+ }
423
+ const envelopeInput = optionsArg.envelope;
424
+ const contextInput = optionsArg.context;
425
+ const expectedRecipientKeyIdInput = optionsArg.expectedRecipientKeyId;
426
+ const recipientPrivateKeyInput = optionsArg.recipientPrivateKey;
427
+ const envelope = parseX25519Envelope(envelopeInput);
428
+ if (!(contextInput instanceof Uint8Array)) {
429
+ throw createSmartCryptoError('INVALID_ARGUMENT');
430
+ }
431
+ const expectedRecipientKeyId = requireRecipientKeyId(expectedRecipientKeyIdInput);
432
+ let context: Uint8Array | undefined;
433
+ try {
434
+ context = new Uint8Array(contextInput);
435
+ if (envelope.recipientKeyId !== expectedRecipientKeyId.value) {
436
+ throw createSmartCryptoError('RECIPIENT_MISMATCH');
437
+ }
438
+ const contextDigest = await sha256(context);
439
+ const encodedContextDigest = decodeCanonicalBase64Url(envelope.contextDigest, 32, 32);
440
+ if (!bytesEqual(contextDigest, encodedContextDigest)) {
441
+ contextDigest.fill(0);
442
+ encodedContextDigest.fill(0);
443
+ throw createSmartCryptoError('CONTEXT_MISMATCH');
444
+ }
445
+ const recipientPrivateKey = await importX25519PrivateKey(recipientPrivateKeyInput);
446
+ let ephemeralPublicKey: CryptoKey;
447
+ try {
448
+ ephemeralPublicKey = await importX25519PublicKey(
449
+ decodeCanonicalBase64Url(
450
+ envelope.ephemeralPublicKey,
451
+ SMARTCRYPTO_X25519_KEY_BYTES,
452
+ SMARTCRYPTO_X25519_KEY_BYTES,
453
+ ),
454
+ );
455
+ } catch {
456
+ throw createSmartCryptoError('INVALID_ENVELOPE');
457
+ }
458
+ let sharedSecret: Uint8Array | undefined;
459
+ let aesKey: Uint8Array | undefined;
460
+ try {
461
+ sharedSecret = await deriveSharedSecret(recipientPrivateKey, ephemeralPublicKey);
462
+ aesKey = await deriveAesKey(sharedSecret, expectedRecipientKeyId.encoded, contextDigest);
463
+ return await aesGcmDecrypt({
464
+ key: aesKey,
465
+ encryptedData: {
466
+ nonce: decodeCanonicalBase64Url(
467
+ envelope.nonce,
468
+ SMARTCRYPTO_AES_GCM_NONCE_BYTES,
469
+ SMARTCRYPTO_AES_GCM_NONCE_BYTES,
470
+ ),
471
+ ciphertext: decodeCanonicalBase64Url(
472
+ envelope.ciphertext,
473
+ SMARTCRYPTO_MAX_CIPHERTEXT_BYTES,
474
+ ),
475
+ tag: decodeCanonicalBase64Url(
476
+ envelope.tag,
477
+ SMARTCRYPTO_AES_GCM_TAG_BYTES,
478
+ SMARTCRYPTO_AES_GCM_TAG_BYTES,
479
+ ),
480
+ },
481
+ aad: context,
482
+ });
483
+ } finally {
484
+ contextDigest.fill(0);
485
+ encodedContextDigest.fill(0);
486
+ sharedSecret?.fill(0);
487
+ aesKey?.fill(0);
488
+ }
489
+ } finally {
490
+ context?.fill(0);
491
+ expectedRecipientKeyId.encoded.fill(0);
492
+ }
493
+ };
package/readme.hints.md DELETED
@@ -1 +0,0 @@
1
-