Skip to content

Commit 8d5a743

Browse files
authored
chore: some cleanup and typing improvements (#340)
Signed-off-by: Timo Glastra <timo@animo.id>
1 parent 4a4c1b0 commit 8d5a743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+130
-105
lines changed

.github/workflows/build-test-publish-on-push-cached.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ jobs:
105105
node-version: 20
106106
cache: 'pnpm'
107107
# we are not using the github action for biome, but the package.json script. this makes sure we are using the same versions.
108-
- name: Run Biome
108+
- name: Run Biome
109109
run: pnpm run biome:ci
110110

111+
- name: Run test typecheck
112+
run: pnpm run types:check:tests
113+
111114
# Only run this job when the push is on main
112115
publish:
113116
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

.github/workflows/release.yml

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ jobs:
88
steps:
99
- name: Checkout repository
1010
uses: actions/checkout@v4
11-
11+
1212
- name: Check if user is in CODEOWNERS
1313
id: check_user
1414
run: |
15-
CODEOWNERS_PATH="CODEOWNERS"
16-
if [ ! -f "$CODEOWNERS_PATH" ]; then
17-
echo "CODEOWNERS file not found."
18-
exit 1
19-
fi
20-
21-
# Extract GitHub usernames from CODEOWNERS file (assumes usernames, not emails or teams)
22-
USERS=$(grep '@' $CODEOWNERS_PATH | sed -E 's/.*@([^ ]+).*/\1/' | sed 's/://g' | tr '\n' ' ')
23-
24-
# Check if the actor is in the list of users
25-
if [[ ! " $USERS " =~ " ${{ github.actor }} " ]]; then
26-
echo "Error: Actor ${{ github.actor }} is not listed in CODEOWNERS."
27-
exit 1
28-
else
29-
echo "Actor ${{ github.actor }} is listed in CODEOWNERS."
30-
fi
15+
CODEOWNERS_PATH="CODEOWNERS"
16+
if [ ! -f "$CODEOWNERS_PATH" ]; then
17+
echo "CODEOWNERS file not found."
18+
exit 1
19+
fi
20+
21+
# Extract GitHub usernames from CODEOWNERS file (assumes usernames, not emails or teams)
22+
USERS=$(grep '@' $CODEOWNERS_PATH | sed -E 's/.*@([^ ]+).*/\1/' | sed 's/://g' | tr '\n' ' ')
23+
24+
# Check if the actor is in the list of users
25+
if [[ ! " $USERS " =~ " ${{ github.actor }} " ]]; then
26+
echo "Error: Actor ${{ github.actor }} is not listed in CODEOWNERS."
27+
exit 1
28+
else
29+
echo "Actor ${{ github.actor }} is listed in CODEOWNERS."
30+
fi
3131
# we can add an approval stage with the environment so it can only be run when accepted by two authorized users.
3232
build:
3333
needs: check-author
@@ -126,10 +126,13 @@ jobs:
126126
node-version: 20
127127
cache: 'pnpm'
128128
# we are not using the github action for biome, but the package.json script. this makes sure we are using the same versions.
129-
- name: Run Biome
129+
- name: Run Biome
130130
run: pnpm run biome:ci
131131

132-
publish:
132+
- name: Run test typecheck
133+
run: pnpm run types:check:tests
134+
135+
publish:
133136
# needs permissions to write tags to the repository
134137
permissions:
135138
contents: write
@@ -182,5 +185,5 @@ jobs:
182185
echo "registry=https://registry.npmjs.org/" >> .npmrc
183186
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
184187
185-
- name: 'Publish latest version'
186-
run: pnpm publish:latest
188+
- name: 'Publish latest version'
189+
run: pnpm publish:latest

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.2.5/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.3.8/schema.json",
33
"vcs": {
44
"enabled": true,
55
"clientKind": "git",

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
"description": "sd-jwt implementation in typescript",
44
"scripts": {
55
"build": "lerna run build --stream",
6-
"lint": "biome lint ./packages",
6+
"lint": "biome check .",
77
"format": "biome format . --write",
88
"biome:ci": "biome ci .",
99
"test": "vitest run --coverage.enabled=true --coverage.include=packages/*",
1010
"test:watch": "vitest",
1111
"clean": "lerna clean -y",
1212
"publish:latest": "lerna publish --no-private --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest",
1313
"publish:next": "lerna publish --no-private --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes",
14-
"prepare": "husky"
14+
"prepare": "husky",
15+
"types:check:tests": "tsc --project tsconfig.test.json"
1516
},
1617
"keywords": [
1718
"sd-jwt",

packages/core/src/test/index.spec.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('index', () => {
5959

6060
expect(credential).toBeDefined();
6161

62-
const presentation = await sdjwt.present<typeof claims>(
62+
const presentation = await sdjwt.present(
6363
credential,
6464
{ foo: true },
6565
{
@@ -173,7 +173,7 @@ describe('index', () => {
173173
},
174174
);
175175

176-
const presentation = await sdjwt.present<typeof claims>(
176+
const presentation = await sdjwt.present(
177177
credential,
178178
{ foo: true },
179179
{
@@ -249,7 +249,7 @@ describe('index', () => {
249249
},
250250
);
251251

252-
const presentation = await sdjwt.present<typeof claims>(
252+
const presentation = await sdjwt.present(
253253
credential,
254254
{ foo: true },
255255
{
@@ -263,7 +263,9 @@ describe('index', () => {
263263
},
264264
);
265265

266-
const results = await sdjwt.verify(presentation, ['foo'], true);
266+
const results = await sdjwt.verify(presentation, {
267+
requiredClaimKeys: ['foo'],
268+
});
267269
expect(results).toBeDefined();
268270
});
269271

@@ -359,7 +361,7 @@ describe('index', () => {
359361
},
360362
);
361363

362-
const presentation = await sdjwt.present<typeof claims>(
364+
const presentation = await sdjwt.present(
363365
credential,
364366
{ foo: true },
365367
{
@@ -403,7 +405,7 @@ describe('index', () => {
403405
},
404406
);
405407
try {
406-
await sdjwt.present<typeof claims>(
408+
await sdjwt.present(
407409
credential,
408410
{ foo: true },
409411
{
@@ -445,7 +447,7 @@ describe('index', () => {
445447
},
446448
);
447449

448-
const presentation = await sdjwt.present<typeof claims>(
450+
const presentation = await sdjwt.present(
449451
credential,
450452
{ foo: true },
451453
{
@@ -488,7 +490,7 @@ describe('index', () => {
488490
},
489491
);
490492

491-
const presentation = sdjwt.present<typeof claims>(
493+
const presentation = sdjwt.present(
492494
credential,
493495
{ foo: true },
494496
{
@@ -501,7 +503,7 @@ describe('index', () => {
501503
},
502504
},
503505
);
504-
expect(presentation).rejects.toThrow(
506+
await expect(presentation).rejects.toThrow(
505507
'Key Binding sign algorithm not specified',
506508
);
507509
});
@@ -526,13 +528,13 @@ describe('index', () => {
526528
},
527529
);
528530
const sdjwt = new SDJwtInstance<SdJwtPayload>({});
529-
expect(sdjwt.keys('')).rejects.toThrow('Hasher not found');
530-
expect(sdjwt.presentableKeys('')).rejects.toThrow('Hasher not found');
531-
expect(sdjwt.getClaims('')).rejects.toThrow('Hasher not found');
531+
await expect(sdjwt.keys('')).rejects.toThrow('Hasher not found');
532+
await expect(sdjwt.presentableKeys('')).rejects.toThrow('Hasher not found');
533+
await expect(sdjwt.getClaims('')).rejects.toThrow('Hasher not found');
532534
expect(() => sdjwt.decode('')).toThrowError('Hasher not found');
533-
expect(
534-
sdjwt.present<typeof claims>(credential, { foo: true }),
535-
).rejects.toThrow('Hasher not found');
535+
await expect(sdjwt.present(credential, { foo: true })).rejects.toThrow(
536+
'Hasher not found',
537+
);
536538
});
537539

538540
test('presentableKeys', async () => {
@@ -581,19 +583,15 @@ describe('index', () => {
581583
},
582584
);
583585

584-
const presentation = await sdjwt.present<typeof claims>(
585-
credential,
586-
undefined,
587-
{
588-
kb: {
589-
payload: {
590-
aud: '1',
591-
iat: 1,
592-
nonce: '342',
593-
},
586+
const presentation = await sdjwt.present(credential, undefined, {
587+
kb: {
588+
payload: {
589+
aud: '1',
590+
iat: 1,
591+
nonce: '342',
594592
},
595593
},
596-
);
594+
});
597595

598596
const decoded = await sdjwt.decode(presentation);
599597
expect(decoded.jwt).toBeDefined();

packages/core/test/app-e2e.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('App', () => {
131131
});
132132

133133
const requiredClaimKeys = ['firstname', 'id', 'data.ssn'];
134-
const verified = await sdjwt.verify(encodedSdjwt, requiredClaimKeys);
134+
const verified = await sdjwt.verify(encodedSdjwt, { requiredClaimKeys });
135135
expect(verified).toBeDefined();
136136
});
137137

@@ -233,9 +233,11 @@ async function JSONtest(filename: string) {
233233

234234
const presentationClaims = await sdjwt.getClaims(presentedSDJwt);
235235

236-
expect(presentationClaims).toEqual(test.presenatedClaims);
236+
expect(presentationClaims).toEqual(test.presentedClaims);
237237

238-
const verified = await sdjwt.verify(encodedSdjwt, test.requiredClaimKeys);
238+
const verified = await sdjwt.verify(encodedSdjwt, {
239+
requiredClaimKeys: test.requiredClaimKeys,
240+
});
239241

240242
expect(verified).toBeDefined();
241243
expect(verified).toStrictEqual({
@@ -248,7 +250,7 @@ type TestJson = {
248250
claims: SdJwtPayload;
249251
disclosureFrame: DisclosureFrame<SdJwtPayload>;
250252
presentationFrames: PresentationFrame<SdJwtPayload>;
251-
presenatedClaims: object;
253+
presentedClaims: object;
252254
requiredClaimKeys: string[];
253255
};
254256

packages/core/test/array_data_types.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"5": true
1818
}
1919
},
20-
"presenatedClaims": {
20+
"presentedClaims": {
2121
"data_types": [null, 42, 3.14, "foo", ["Test"], { "foo": "bar" }]
2222
},
2323
"requiredClaimKeys": [

packages/core/test/array_full_sd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
},
1414
"presentationFrames": { "is_over": { "18": true } },
15-
"presenatedClaims": {
15+
"presentedClaims": {
1616
"is_over": {
1717
"18": false
1818
}

packages/core/test/array_in_sd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"_sd": ["sd_array"]
77
},
88
"presentationFrames": { "sd_array": true },
9-
"presenatedClaims": {
9+
"presentedClaims": {
1010
"sd_array": ["32", "23"]
1111
},
1212
"requiredClaimKeys": ["sd_array"]

packages/core/test/array_nested_in_plain.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
}
2424
},
25-
"presenatedClaims": {
25+
"presentedClaims": {
2626
"nested_array": [["foo"], ["qux"]]
2727
},
2828
"requiredClaimKeys": ["nested_array.0.0", "nested_array.1.0"]

0 commit comments

Comments
 (0)