Skip to content

Commit

Permalink
fix: tests-running
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Oct 1, 2024
1 parent 4d6f6e6 commit 75927c3
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 48 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO

Add jwt claimset validation
Remove jest and compileroptions from mdoc-client
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthRequest } from '../v-auth-request';
import type { AuthRequest } from '../v-auth-request.js';

// ISO-compliant driving licence — Part 7: Mobile driving licence (mDL) add-on functions
export const ISO_MDL_7_EPHEMERAL_MDOC_PUBLIC_KEY_JWK = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { http, HttpResponse } from 'msw';
import assert from 'node:assert';
import { describe, it } from 'node:test';

import type { JoseJweDecryptCompact, Jwk } from '@protokoll/jose';
import type {
JoseJweDecryptCompact,
JoseJwsVerifyJwt,
Jwk,
} from '@protokoll/jose';
import { joseContext } from '@protokoll/jose/dist/src/u-jose-test-context.js';
import { setupServer } from 'msw/node';
import type { JoseJwsVerifyJwt } from '../../../jose/dist/src/jws/c-jws';
import type { JarmAuthResponseCreate } from '../jarm-auth-response-create/index.js';
import { jarmAuthResponseCreate } from '../jarm-auth-response-create/index.js';
import { jarmAuthResponseSend } from '../jarm-auth-response-send/jarm-auth-response-send.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/jarm/src/v-auth-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as v from 'valibot';
import {
vJarmResponseMode,
vOpenid4vpJarmResponseMode,
} from './v-response-mode-registry';
import { vResponseType } from './v-response-type-registry';
} from './v-response-mode-registry.js';
import { vResponseType } from './v-response-type-registry.js';

export const vAuthRequest = v.looseObject({
state: v.optional(v.string()),
Expand Down
3 changes: 1 addition & 2 deletions packages/mdoc/mdoc-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"build": "tsc",
"format": "prettier --check . --ignore-path ../../../.gitignore",
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"test": "jest"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"cbor-x": "^1.5.4",
Expand Down
10 changes: 5 additions & 5 deletions packages/mdoc/mdoc-client/src/c-mdoc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JWK } from 'jose';
import {
import type {
MacProtectedHeaders,
ProtectedHeaders,
UnprotectedHeaders,
Expand All @@ -10,7 +10,7 @@ import type { DigestAlgorithm } from './mdoc/model/types.js';

export type MaybePromise<TType> = Promise<TType> | TType;

export type X509Context = {
export interface X509Context {
getIssuerName: (input: {
certificate: Uint8Array;
}) => Exclude<unknown, null | undefined> | undefined;
Expand All @@ -37,9 +37,9 @@ export type X509Context = {
notBefore: Date;
notAfter: Date;
}>;
};
}

export type MdocContext = {
export interface MdocContext {
crypto: {
random: (length: number) => Promise<Uint8Array>;
digest: (input: {
Expand Down Expand Up @@ -116,4 +116,4 @@ export type MdocContext = {
};

x509: X509Context;
};
}
18 changes: 10 additions & 8 deletions packages/mdoc/mdoc-client/src/cose/key/cose-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
import { concat, uint8ArrayToString } from '../../u-buffer.js';
import { Algorithms } from '../headers.js';
import { Curve } from './curve.js';
import { JWKKeyOps, JWKKeyOpsToCOSE, KeyOps } from './key-ops.js';
import { JWKKeyType, KeyType } from './kty.js';
import type { KeyOps } from './key-ops.js';
import { JWKKeyOps, JWKKeyOpsToCOSE } from './key-ops.js';
import type { KeyType } from './kty.js';
import { JWKKeyType } from './kty.js';
import {
COSEKeyParam,
JWKParam,
Expand All @@ -20,7 +22,7 @@ import {
const toArray = (v: unknown | unknown[]) => (Array.isArray(v) ? v : [v]);

function normalize(input: string | Uint8Array): string {
let encoded = input;
const encoded = input;
if (encoded instanceof Uint8Array) {
return uint8ArrayToString(encoded);
} else {
Expand Down Expand Up @@ -107,7 +109,7 @@ export class COSEKey extends TypedMap<
const kty = jwk.kty;
for (const [key, value] of Object.entries(jwk)) {
const jwkKey =
KTYSpecificJWKParamsRev[kty!]?.get(key) ||
KTYSpecificJWKParamsRev[kty]?.get(key) ||
(JWKParam[key as keyof typeof JWKParam] as number);
const formatter = JWKToCOSEValue.get(key);
if (jwkKey && formatter) {
Expand All @@ -124,14 +126,14 @@ export class COSEKey extends TypedMap<
* @returns {JWK} - The JWK representation of the COSEKey.
*/
toJWK(): JWK {
const kty = JWKKeyType[this.get(COSEKeyParam.KeyType) as number] as string;
const kty = JWKKeyType[this.get(COSEKeyParam.KeyType) as number]!;
const result: JWK = { kty };

for (const [key, value] of this) {
const jwkKey =
KTYSpecificJWKParams[kty as string]?.get(key) ??
(JWKParam[key] as string);
const parser = JWKFromCOSEValue.get(jwkKey as string);
KTYSpecificJWKParams[kty]?.get(key) ??
(JWKParam[key]!);
const parser = JWKFromCOSEValue.get(jwkKey);
if (parser && jwkKey) {
const parsed = parser(value);
// @ts-expect-error JWK has no index signature
Expand Down
4 changes: 1 addition & 3 deletions packages/mdoc/mdoc-client/src/cose/key/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export enum JWKParam {
k = COSEKeyParam.k,
}

export const KTYSpecificJWKParams: {
[k: string]: Map<number, string> | undefined;
} = {
export const KTYSpecificJWKParams: Record<string, Map<number, string> | undefined> = {
EC: new Map([
[-1, 'crv'],
[-2, 'x'],
Expand Down
12 changes: 7 additions & 5 deletions packages/mdoc/mdoc-client/src/cose/mac0.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import type { MdocContext } from '../c-mdoc.js';
import { addExtension, cborEncode } from '../cbor/index.js';
import { COSEBase } from './cose-base.js';
import type {
MacAlgorithms} from './headers.js';
import {
Headers,
MacAlgorithmNames,
MacAlgorithms,
MacProtectedHeaders,
type SupportedMacAlg,
UnprotectedHeaders,

UnprotectedHeaders
} from './headers.js';
export type VerifyOptions = {
import type {SupportedMacAlg} from './headers.js';
export interface VerifyOptions {
externalAAD?: Uint8Array;
detachedPayload?: Uint8Array;
algorithms?: MacAlgorithms[];
};
}

export class Mac0 extends COSEBase {
constructor(
Expand Down
3 changes: 2 additions & 1 deletion packages/mdoc/mdoc-client/src/cose/sign1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { MdocContext } from '../c-mdoc.js';
import { addExtension, cborEncode } from '../cbor/index.js';
import { ProtectedHeaders, UnprotectedHeaders } from './headers.js';
import { SignatureBase, type VerifyOptions } from './signature-base.js';
import { SignatureBase } from './signature-base.js';
import type {VerifyOptions} from './signature-base.js';

export class Sign1 extends SignatureBase {
constructor(
Expand Down
7 changes: 4 additions & 3 deletions packages/mdoc/mdoc-client/src/cose/signature-base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { COSEBase } from './cose-base.js';
import { AlgorithmNames, Algorithms, Headers } from './headers.js';
import type { Algorithms} from './headers.js';
import { AlgorithmNames, Headers } from './headers.js';

export type VerifyOptions = {
export interface VerifyOptions {
externalAAD?: Uint8Array;
detachedPayload?: Uint8Array;
algorithms?: Algorithms[];
};
}

export class SignatureBase extends COSEBase {
constructor(
Expand Down
7 changes: 6 additions & 1 deletion packages/mdoc/mdoc-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export * from './c-mdoc.js';
export { DataItem, cborDecode, cborEncode } from './cbor/index.js';
export {
DataItem,
cborDecode,
cborDecodeUnknown,
cborEncode,
} from './cbor/index.js';
export { COSEKey, COSEKeyToRAW } from './cose/key/cose-key.js';
export { DeviceResponse } from './mdoc/model/device-response.js';
export { DeviceSignedDocument } from './mdoc/model/device-signed-document.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mdoc/mdoc-client/src/mdoc/model/issuer-auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MdocContext, X509Context } from '../../c-mdoc.js';
import { DataItem } from '../../cbor/data-item.js';
import { cborDecode } from '../../cbor/index.js';
import { ProtectedHeaders, UnprotectedHeaders } from '../../cose/headers.js';
import type { ProtectedHeaders, UnprotectedHeaders } from '../../cose/headers.js';
import { Sign1 } from '../../cose/sign1.js';
import type { MSO } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/mdoc/mdoc-client/src/mdoc/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export class Verifier {
: undefined,
issuerSignature: {
// TODO
alg: document.issuerSigned.issuerAuth.algName as string,
alg: document.issuerSigned.issuerAuth.algName!,
isValid: dr
.filter(check => check.category === 'ISSUER_AUTH')
.every(check => check.status === 'PASSED'),
Expand Down
5 changes: 5 additions & 0 deletions packages/mdoc/mdoc-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "@protokoll/tsconfig/internal-package.json",
"include": ["src"],
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node10",
"resolveJsonModule": false
},
"exclude": ["node_modules"]
}
3 changes: 2 additions & 1 deletion packages/mdoc/mdoc-node/__tests__/cbor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
cborEncode,
DataItem,
} from '@protokoll/mdoc-client';
import { cborDecodeUnknown } from '@protokoll/mdoc-client';

describe('cbor', () => {
it('should properly decode a nested map', () => {
Expand All @@ -20,7 +21,7 @@ describe('cbor', () => {

it('should properly encoded and decoded maps', () => {
const encoded = cborEncode(DataItem.fromData({ foo: 'baz' }));
const decoded = cborDecode(encoded);
const decoded = cborDecodeUnknown(encoded);
const reEncode = cborEncode(decoded);
expect(areEqual(reEncode, encoded)).toBeTruthy();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/mdoc/mdoc-node/__tests__/diagnostic.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('diagnostic info', () => {
);
});

it('should return the version', async () => {
it('should return the version', () => {
expect(diagnosticInfo).toMatchSnapshot();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type {
DeviceSignedDocument} from '@protokoll/mdoc-client';
import {
COSEKey,
COSEKeyToRAW,
DataItem,
DeviceResponse,
DeviceSignedDocument,
Document,
MDoc,
Verifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type {
DeviceSignedDocument} from '@protokoll/mdoc-client';
import {
DataItem,
DeviceResponse,
DeviceSignedDocument,
Document,
MDoc,
Verifier,
cborEncode,
parse,
} from '@protokoll/mdoc-client';
import * as jose from 'jose';
import type * as jose from 'jose';
import { mdocContext } from '../mdoc-test-context.js';
import {
DEVICE_JWK,
Expand Down
10 changes: 6 additions & 4 deletions packages/mdoc/mdoc-node/__tests__/issuing/issuing-mdoc.tests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type {
DeviceSignedDocument,
IssuerSignedDocument,
} from '@protokoll/mdoc-client';
import {
COSEKey,
DeviceSignedDocument,
Document,
IssuerSignedDocument,
MDoc,
Verifier,
parse,
} from '@protokoll/mdoc-client';
import * as jose from 'jose';
import type * as jose from 'jose';
import { mdocContext } from '../mdoc-test-context.js';
import {
DEVICE_JWK,
Expand Down Expand Up @@ -95,7 +97,7 @@ describe('issuing an MDOC', () => {

it('should include the namespace and attributes', () => {
const attrValues = parsedDocument.getIssuerNameSpace('org.iso.18013.5.1');
// @ts-ignore
// @ts-expect error this will work
const currentAge =
new Date(Date.now() - new Date('2007-03-25').getTime()).getFullYear() -
1970;
Expand Down
4 changes: 2 additions & 2 deletions packages/mdoc/mdoc-node/__tests__/mdoc-test-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Mac0, Sign1 } from '@auth0/cose';
import { p256 } from '@noble/curves/p256';
import { hkdf } from '@panva/hkdf';
import { X509Certificate, X509ChainBuilder } from '@peculiar/x509';
import { MdocContext, X509Context } from '@protokoll/mdoc-client';
import type { MdocContext, X509Context } from '@protokoll/mdoc-client';
import * as jose from 'jose';
import { importX509 } from 'jose';
import crypto from 'node:crypto';
Expand Down Expand Up @@ -134,7 +134,7 @@ export const mdocContext: MdocContext = {

// The chain is reversed here as the `x5c` header (the expected input),
// has the leaf certificate as the first entry, while the `x509` library expects this as the last
let parsedChain = chain
const parsedChain = chain
.map(c => new X509Certificate(new Uint8Array(c.rawData)))
.reverse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { hex } from 'buffer-tag';
describe('parse an issuer signed mdoc', () => {
let parsed: MDoc;

beforeAll(async () => {
beforeAll(() => {
const mdoc = hex`a36776657273696f6e63312e3069646f63756d656e747381a267646f6354797065756f72672e69736f2e31383031332e352e312e6d444c6c6973737565725369676e6564a26a6e616d65537061636573a26f6f72672e637573746f6d2e7465737481d818585bb90004686469676573744944006672616e646f6d5820966ca23f9523c3c085c19da467221e98f357dc499843f95a87f83e2d4b394d9e71656c656d656e744964656e74696669657264636f6f6c6c656c656d656e7456616c7565f5716f72672e69736f2e31383031332e352e318ed8185867b90004686469676573744944006672616e646f6d5820e20827abe5f1d4d33a15c31c2a469e1dbb6950b60a7bd042587e9f189a4e4ce571656c656d656e744964656e7469666965726b66616d696c795f6e616d656c656c656d656e7456616c756565536d697468d8185865b90004686469676573744944016672616e646f6d5820974b01204b62a16a5878d4100fb988f10afd00f9f4fe8e42fbe2acb0f882f40f71656c656d656e744964656e7469666965726a676976656e5f6e616d656c656c656d656e7456616c7565644a6f686ed818586eb90004686469676573744944026672616e646f6d5820f9005be7afe8e5556ad2ad66bf1b03d6b79c394223eb990782db2bf9ac5f803f71656c656d656e744964656e7469666965726a62697274685f646174656c656c656d656e7456616c7565d903ec6a313938302d30362d3135d8185862b90004686469676573744944036672616e646f6d5820f62a463b617cf5939bdc1a6d067af7e2207a982aeb6f3523930bc501a07f841571656c656d656e744964656e7469666965726b6167655f6f7665725f32316c656c656d656e7456616c7565f5d8185862b90004686469676573744944046672616e646f6d5820cfc02bff03aa2dc7e8e029f4f4a51f78329053e89af968434807d029c31e625671656c656d656e744964656e7469666965726b6167655f6f7665725f34336c656c656d656e7456616c7565f5d818586eb90004686469676573744944056672616e646f6d5820e626ff8c159690c89ba1b69d5e96b63a644324298169d9d1b3e9bf00c37a7e2671656c656d656e744964656e7469666965726a69737375655f646174656c656c656d656e7456616c7565d903ec6a323032332d30332d3031d818586fb90004686469676573744944066672616e646f6d5820c0ccd83efce6b8d247a9fb430fce033896713441b7884320e9badba37d18795471656c656d656e744964656e7469666965726b6578706972795f646174656c656c656d656e7456616c7565d903ec6a323032382d30332d3331d8185868b90004686469676573744944076672616e646f6d5820fc420e24beae5c05378985840749b7453944b23f9c5a894fe1b5f4ffbeea5c2e71656c656d656e744964656e7469666965726f69737375696e675f636f756e7472796c656c656d656e7456616c7565625553d818586eb90004686469676573744944086672616e646f6d5820a4690fd8cf423a15377b37008c69d420003924c8f7783cdb8936eb4456c6e52671656c656d656e744964656e7469666965727169737375696e675f617574686f726974796c656c656d656e7456616c7565664e5920444d56d8185873b90004686469676573744944096672616e646f6d58200fb56a89a94d9eef9bc5017c6e59a33ba4ca194d8b79d4bb12ef6b77e5792dcd71656c656d656e744964656e7469666965727469737375696e675f6a7572697364696374696f6e6c656c656d656e7456616c7565684e657720596f726bd8185871b900046864696765737449440a6672616e646f6d582075da3a6d87f2232fa400b5cdd2f90092490fa193b8fcf67713d7f7f205eac12971656c656d656e744964656e7469666965726f646f63756d656e745f6e756d6265726c656c656d656e7456616c75656b30312d3333332d37303730d8185863b900046864696765737449440b6672616e646f6d58206d909cc8859fe746e4ee03ef6eac7d2c41b40245fb79ff9cb8b637ed46adee7971656c656d656e744964656e74696669657268706f7274726169746c656c656d656e7456616c75656462737472d81858b1b900046864696765737449440c6672616e646f6d5820f80cdeed9a991f24eb4f5e75f5d327980f812ed67f0eaf94676b40cf9845298671656c656d656e744964656e7469666965727264726976696e675f70726976696c656765736c656c656d656e7456616c756581b900037576656869636c655f63617465676f72795f636f646561436a69737375655f646174656a323032332d30332d30316b6578706972795f646174656a323032382d30332d3331d818587ab900046864696765737449440d6672616e646f6d5820cf2c1e264bc4446761537c17d52b0024fc8ee5d1d30114d623c252559fbc5eb471656c656d656e744964656e74696669657276756e5f64697374696e6775697368696e675f7369676e6c656c656d656e7456616c75656d7462642d75732e6e792e646d766a697373756572417574688443a10126a20442313118218159022e3082022a308201d0a003020102021457c6ccd308bde43eca3744f2a87138dabbb884e8300a06082a8648ce3d0403023053310b30090603550406130255533111300f06035504080c084e657720596f726b310f300d06035504070c06416c62616e79310f300d060355040a0c064e5920444d56310f300d060355040b0c064e5920444d56301e170d3233303931343134353531385a170d3333303931313134353531385a3053310b30090603550406130255533111300f06035504080c084e657720596f726b310f300d06035504070c06416c62616e79310f300d060355040a0c064e5920444d56310f300d060355040b0c064e5920444d563059301306072a8648ce3d020106082a8648ce3d03010703420004893c2d8347906dc6cd69b7f636af4bfd533f96184f0aadacd10830da4471dbdb60ac170d1cfc534fae2d9dcd488f7747fdf978d925ea31e9e9083c382ba9ed53a38181307f301d0603551d0e04160414ab6d2e03b91d492240338fbccadefd9333eaf6c7301f0603551d23041830168014ab6d2e03b91d492240338fbccadefd9333eaf6c7300f0603551d130101ff040530030101ff302c06096086480186f842010d041f161d4f70656e53534c2047656e657261746564204365727469666963617465300a06082a8648ce3d0403020348003045022009fd0cab97b03e78f64e74d7dcee88668c476a0afc5aa2cebffe07d3be772ea9022100da38abc98a080f49f24ffece1fffc8a6cdd5b2c0b5da8fc7b767ac3a95dcb83e59035fd81859035ab900066776657273696f6e63312e306f646967657374416c676f726974686d675348412d3235366c76616c756544696765737473b900026f6f72672e637573746f6d2e74657374a1005820f78b02ae285ad50f0543d45c0985a09ac8f021948da1c7fbf4194892a5877764716f72672e69736f2e31383031332e352e31ae0058203659fe5ac06f2092f8bb8e6457a9cacc289e335cacf863e777f37545369314960158209881b964f33d36fdd87fca84e3dae3868cae405216f8ab499ba3b8b9b61cf6a8025820c42062a2ce0c68c7f316a4c625bd20946d3acd1f49b95d6e210fa01b6541e782035820b404e27767d66eda5744260d3f385e952f9092dfed012cc4434fd0abd7f9b06d045820d05d33268617cd4cedfceb4295f29ab8ac237cb1a6b03b3a113b3390a9c549f9055820f1bd9a2f74be31880231c9a52b215ff38e736acc1190f2f46669551a8d793c35065820e02df0407ceeee151fc4572aa37824c228b86623ce7d2550ae96bad1855c634c075820655c6f8e3e31b79e288f6b815f65bb5f8de17484aba0f31ad8427bc0b93bb5550858205d5d5c441b07802de0a355576d1545458c7519778982955dce552930951e4743095820aac192504c7bcc55f0ce82407df7fce71ace7cd360477efe17c7b0ac7b660c400a58206e41d0fe61717ecf970261b10b8f608010862199c13828a1fee7100cf2865a4b0b58208654d131837036322c4ce4cec296e51bf665351cb9a910b64ac53798f0a2e9be0c582027d8d339a308b8f6bd00069e6fbe79ae027f9e1909eed75cbbc8d4fd4fc29d0b0d5820b45fd1323c6902bb680aedbc22bcc4a7d87d3cfb19502ec551fd2e2dede419c86d6465766963654b6579496e666fb90001696465766963654b6579a40102215820881879ca7a238b19bf0f4c1f8c00e9a2e19ba7a6f73eae92b851d4de1b508559225820a314b538039127b5cd50735f54519e33c134450545c5603ad9f263facc56d377200167646f6354797065756f72672e69736f2e31383031332e352e312e6d444c6c76616c6964697479496e666fb90003667369676e6564c074323032332d31302d31385431363a30303a32345a6976616c696446726f6dc074323032332d31302d31385431363a30303a32345a6a76616c6964556e74696cc074323032372d31302d31385431363a30303a32345a58404581f12205d8cf13f369ef68fe05b72cdaa5b61191eaa179c53c54608a9a07d34fac15b7b7eac7f7881d9e640f4e9c842c7cd547f6ec8e11b7da26246e78e4b66673746174757300`;
parsed = await parse(mdoc);
parsed = parse(mdoc);
});

it('should match the snapshot', async () => {
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 75927c3

Please sign in to comment.