|
1 | 1 | import { seal as sealData, unseal as unsealData } from 'iron-webcrypto'; |
2 | 2 | import type { SessionEncryption as SessionEncryptionInterface } from '../session/types.js'; |
3 | 3 |
|
4 | | -// Extract the precise Crypto type that iron-webcrypto expects |
5 | | -// This avoids importing iron-webcrypto's private _Crypto type |
6 | | -type IronCrypto = Parameters<typeof sealData>[0]; |
7 | | - |
8 | | -// Cast globalThis.crypto to iron-webcrypto's expected type |
9 | | -// Runtime-safe: DOM Crypto is fully compatible with iron-webcrypto's _Crypto |
10 | | -// Type-level workaround: iron-webcrypto's _Crypto expects Uint8Array<ArrayBuffer> |
11 | | -// while DOM Crypto provides Uint8Array<ArrayBufferLike> |
12 | | -const ironCrypto: IronCrypto = globalThis.crypto as unknown as IronCrypto; |
13 | | - |
14 | 4 | /** |
15 | 5 | * A compatible implementation that works with iron-session |
16 | 6 | */ |
@@ -43,7 +33,7 @@ export class SessionEncryption implements SessionEncryptionInterface { |
43 | 33 | }; |
44 | 34 |
|
45 | 35 | // Seal the data using iron-webcrypto with properly formatted password |
46 | | - const seal = await sealData(ironCrypto, data, passwordObj, { |
| 36 | + const seal = await sealData(data, passwordObj, { |
47 | 37 | encryption: { |
48 | 38 | saltBits: 256, |
49 | 39 | algorithm: 'aes-256-cbc', |
@@ -77,7 +67,7 @@ export class SessionEncryption implements SessionEncryptionInterface { |
77 | 67 | const passwordMap = { 1: password }; |
78 | 68 |
|
79 | 69 | // Use iron-webcrypto's unseal function |
80 | | - const data = await unsealData(ironCrypto, sealWithoutVersion, passwordMap, { |
| 70 | + const data = await unsealData(sealWithoutVersion, passwordMap, { |
81 | 71 | encryption: { |
82 | 72 | saltBits: 256, |
83 | 73 | algorithm: 'aes-256-cbc', |
|
0 commit comments