Skip to content

Commit a8555d6

Browse files
authored
upgrade iron-webcrypto to v2.0.0 (#12)
Remove explicit crypto parameter from seal/unseal calls as v2 uses globalThis.crypto automatically. Eliminates 9 lines of type workarounds.
1 parent d6dd4bb commit a8555d6

File tree

3 files changed

+27
-49
lines changed

3 files changed

+27
-49
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
"vitest": "^4.0.10"
3636
},
3737
"dependencies": {
38-
"@workos-inc/node": "^8.0.0-rc.3",
39-
"iron-webcrypto": "^1.2.1",
40-
"jose": "^6.1.2"
38+
"@workos-inc/node": "8.0.0-rc.5",
39+
"iron-webcrypto": "^2.0.0",
40+
"jose": "^6.1.3"
4141
},
4242
"engines": {
4343
"node": ">=20.0.0"

pnpm-lock.yaml

Lines changed: 22 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/encryption/ironWebcryptoEncryption.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import { seal as sealData, unseal as unsealData } from 'iron-webcrypto';
22
import type { SessionEncryption as SessionEncryptionInterface } from '../session/types.js';
33

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-
144
/**
155
* A compatible implementation that works with iron-session
166
*/
@@ -43,7 +33,7 @@ export class SessionEncryption implements SessionEncryptionInterface {
4333
};
4434

4535
// 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, {
4737
encryption: {
4838
saltBits: 256,
4939
algorithm: 'aes-256-cbc',
@@ -77,7 +67,7 @@ export class SessionEncryption implements SessionEncryptionInterface {
7767
const passwordMap = { 1: password };
7868

7969
// Use iron-webcrypto's unseal function
80-
const data = await unsealData(ironCrypto, sealWithoutVersion, passwordMap, {
70+
const data = await unsealData(sealWithoutVersion, passwordMap, {
8171
encryption: {
8272
saltBits: 256,
8373
algorithm: 'aes-256-cbc',

0 commit comments

Comments
 (0)