Skip to content

Commit 89fd2f4

Browse files
committed
upgrade to iron-webcrytpo v2.0.0
1 parent 5c3d84a commit 89fd2f4

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ module.exports = {
1313
'^.+\\.m?js$': '<rootDir>/jest-transform-esm.cjs',
1414
},
1515
transformIgnorePatterns: [
16-
'node_modules/(?!(iron-webcrypto|@noble|@scure|jose)/)',
16+
'node_modules/(?!(iron-webcrypto|uint8array-extras|@noble|@scure|jose)/)',
1717
],
1818
};

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"typecheck": "tsc --noEmit"
4242
},
4343
"dependencies": {
44-
"iron-webcrypto": "^1.2.1",
44+
"iron-webcrypto": "^2.0.0",
4545
"jose": "~6.1.0"
4646
},
4747
"devDependencies": {

src/common/crypto/seal.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ import {
44
defaults,
55
} from 'iron-webcrypto';
66

7-
// Extract the precise Crypto type that iron-webcrypto expects
8-
type IronCrypto = Parameters<typeof ironSeal>[0];
9-
10-
// Cast globalThis.crypto to iron-webcrypto's expected type
11-
// Runtime-safe: DOM Crypto is fully compatible with iron-webcrypto's _Crypto
12-
const ironCrypto: IronCrypto = globalThis.crypto as unknown as IronCrypto;
13-
147
const VERSION_DELIMITER = '~';
158
const CURRENT_MAJOR_VERSION = 2;
169

@@ -56,9 +49,10 @@ export async function sealData(
5649
secret: password,
5750
};
5851

59-
const seal = await ironSeal(ironCrypto, data, passwordObj, {
52+
const seal = await ironSeal(data, passwordObj, {
6053
...defaults,
6154
ttl: ttl * 1000, // Convert seconds to milliseconds
55+
encode: JSON.stringify, // Preserve v1 lenient serialization
6256
});
6357

6458
// Add the version delimiter exactly like iron-session does
@@ -86,7 +80,7 @@ export async function unsealData<T = unknown>(
8680
let data: unknown;
8781
try {
8882
data =
89-
(await ironUnseal(ironCrypto, sealWithoutVersion, passwordMap, {
83+
(await ironUnseal(sealWithoutVersion, passwordMap, {
9084
...defaults,
9185
ttl: ttl * 1000,
9286
})) ?? {};

0 commit comments

Comments
 (0)