Skip to content

Commit 1746f27

Browse files
feat(sdk): Updates to jose 6.x
- Jose 6.x drops support for node key objects, instead requiring/using CryptoKeys natively - This means it removes support for node 18.x, but we have already dropped support for it - While here, updates other deps, including ones dependabot has been suggesting typescript and related fixes 🤖 🎨 Autoformat Signed-off-by: David Mihalcik <[email protected]>
1 parent 82f30de commit 1746f27

File tree

11 files changed

+327
-1576
lines changed

11 files changed

+327
-1576
lines changed

cli/package-lock.json

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

cli/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@
2929
"opentdf": "./bin/opentdf.mjs"
3030
},
3131
"devDependencies": {
32-
"@eslint/eslintrc": "^3.2.0",
33-
"@eslint/js": "^9.20.0",
32+
"@eslint/eslintrc": "^3.3.0",
33+
"@eslint/js": "^9.21.0",
3434
"@esm-bundle/chai": "4.3.4-fix.0",
3535
"@types/mocha": "10.0.10",
36-
"@types/node": "^22.13.4",
36+
"@types/node": "^22.13.5",
3737
"@types/readable-stream": "^4.0.18",
38-
"@types/sinon": "^17.0.3",
38+
"@types/sinon": "^17.0.4",
3939
"@types/yargs": "^17.0.33",
4040
"chai": "^5.2.0",
41-
"eslint-config-prettier": "^10.0.1",
41+
"eslint-config-prettier": "^10.0.2",
4242
"eslint-plugin-chai-friendly": "^1.0.1",
4343
"eslint-plugin-prettier": "^5.2.3",
44-
"globals": "^15.15.0",
44+
"globals": "^16.0.0",
4545
"license-checker-rseidelsohn": "^4.4.2",
4646
"mocha": "^11.1.0",
47-
"prettier": "^3.5.1",
47+
"prettier": "^3.5.2",
4848
"sinon": "^19.0.2",
4949
"ts-node": "^10.9.2",
5050
"typescript": "^5.7.3",
51-
"typescript-eslint": "^8.24.1"
51+
"typescript-eslint": "^8.25.0"
5252
},
5353
"dependencies": {
5454
"@opentdf/sdk": "file:../lib/opentdf-sdk-0.3.0.tgz",

cli/src/cli.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { webcrypto } from 'crypto';
2222
import * as assertions from '@opentdf/sdk/assertions';
2323
import { attributeFQNsAsValues } from '@opentdf/sdk/nano';
2424
import { base64 } from '@opentdf/sdk/encodings';
25-
import { importPKCS8, importSPKI, KeyLike } from 'jose'; // for RS256
25+
import { type CryptoKey, importPKCS8, importSPKI } from 'jose'; // for RS256
2626

2727
type AuthToProcess = {
2828
auth?: string;
@@ -143,20 +143,20 @@ async function parseAssertionVerificationKeys(
143143
}
144144
}
145145
for (const assertionName in u.Keys) {
146-
const assertionKey = u.Keys[assertionName];
146+
const assertionKey: assertions.AssertionKey = u.Keys[assertionName];
147147
// Ensure each entry has the required 'key' and 'alg' fields
148148
if (typeof assertionKey !== 'object' || assertionKey === null) {
149149
throw new CLIError('CRITICAL', `Invalid assertion for ${assertionName}: Must be an object`);
150150
}
151151

152-
if (typeof assertionKey.key !== 'string' || typeof assertionKey.alg !== 'string') {
152+
if (typeof assertionKey.alg !== 'string') {
153153
throw new CLIError(
154154
'CRITICAL',
155155
`Invalid assertion for ${assertionName}: Missing or invalid 'key' or 'alg'`
156156
);
157157
}
158158
try {
159-
u.Keys[assertionName].key = await correctAssertionKeys(assertionKey.alg, assertionKey.key);
159+
u.Keys[assertionName].key = await correctAssertionKeys(assertionKey);
160160
} catch (err) {
161161
throw new CLIError('CRITICAL', `Issue converting assertion key from string: ${err.message}`);
162162
}
@@ -182,10 +182,10 @@ async function parseReadOptions(argv: Partial<mainArgs>): Promise<ReadOptions> {
182182
return r;
183183
}
184184

185-
async function correctAssertionKeys(
186-
alg: string,
187-
key: KeyLike | Uint8Array
188-
): Promise<KeyLike | Uint8Array> {
185+
async function correctAssertionKeys({
186+
alg,
187+
key,
188+
}: assertions.AssertionKey): Promise<CryptoKey | Uint8Array> {
189189
if (alg === 'HS256') {
190190
// Convert key string to Uint8Array
191191
if (typeof key !== 'string') {
@@ -240,17 +240,17 @@ async function parseAssertionConfig(s: string): Promise<assertions.AssertionConf
240240
if (!assertions.isAssertionConfig(assertion)) {
241241
throw new CLIError('CRITICAL', `invalid assertion config ${JSON.stringify(assertion)}`);
242242
}
243-
if (assertion.signingKey) {
244-
const { alg, key } = assertion.signingKey;
245-
try {
246-
assertion.signingKey.key = await correctAssertionKeys(alg, key);
247-
} catch (err) {
248-
throw new CLIError(
249-
'CRITICAL',
250-
`Issue converting assertion key from string: ${err.message}`,
251-
err
252-
);
253-
}
243+
if (!assertion.signingKey) {
244+
continue;
245+
}
246+
try {
247+
assertion.signingKey.key = await correctAssertionKeys(assertion.signingKey);
248+
} catch (err) {
249+
throw new CLIError(
250+
'CRITICAL',
251+
`Issue converting assertion key from string: ${err.message}`,
252+
err
253+
);
254254
}
255255
}
256256
return a;

0 commit comments

Comments
 (0)