Skip to content

Commit

Permalink
refactor: Removed verifyJwt and register
Browse files Browse the repository at this point in the history
  • Loading branch information
zoemaas committed Oct 21, 2024
1 parent eba4fb4 commit d6ce7da
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 55 deletions.
19 changes: 13 additions & 6 deletions packages/oidf-client/__tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { createObjects, getConfig } from '../../agent-config/dist'
import {createAgent} from '@veramo/core'
import oidfClientAgentLogic from './shared/oidfClientAgentLogic'
import {IOIDFClient, OIDFClient} from "../src";
import {CryptoPlatformTestCallback} from "./shared/CryptoPlatformTestCallback";

jest.setTimeout(60000)

import oidfClientAgentLogic from './shared/oidfClientAgentLogic'

let agent: any

const setup = async (): Promise<boolean> => {
const config = await getConfig('packages/oidf-client/agent.yml')
const { localAgent } = await createObjects(config, { localAgent: '/agent' })
agent = localAgent
//const config = await getConfig('packages/oidf-client/agent.yml')
//const { localAgent } = await createObjects(config, { localAgent: '/agent' })
agent = createAgent<IOIDFClient>({
plugins: [
new OIDFClient({
cryptoServiceCallback: new CryptoPlatformTestCallback()
})
]
})

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {
com
} from "../../../../../OpenID-Federation/build/js/packages/openid-federation-modules-openid-federation-client";
import * as jose from 'jose'
import ICryptoServiceCallbackJS = com.sphereon.oid.fed.client.crypto.ICryptoServiceCallbackJS;
import {JWK} from "jose";
import {JWK} from 'jose'
import ICryptoServiceCallback = com.sphereon.oid.fed.client.crypto.ICryptoServiceCallback;

type JWKS = {
keys: JWK[]
}

export class CryptoPlatformCallback implements ICryptoServiceCallbackJS {
export class CryptoPlatformTestCallback implements ICryptoServiceCallback {

async verify(jwt: string): Promise<boolean> {
const decodedProtectedHeader = jose.decodeProtectedHeader(jwt)
Expand Down
73 changes: 49 additions & 24 deletions packages/oidf-client/__tests__/shared/oidfClientAgentLogic.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/oidf-client/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ agent:
- schemaValidation: false
plugins:
- $require: ./packages/oidf-client/dist#OIDFClient
$args:
- cryptoServiceCallback:
$require: './packages/oidf-client?t=class#CryptoPlatformTestCallback'
3 changes: 2 additions & 1 deletion packages/oidf-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"@veramo/remote-client": "4.2.0",
"@veramo/remote-server": "4.2.0",
"jose": "5.9.4",
"nock": "^13.5.5"
"nock": "^13.5.5",
"cross-fetch": "^3.1.8"
},
"files": [
"dist/**/*",
Expand Down
26 changes: 10 additions & 16 deletions packages/oidf-client/src/agent/OIDFClient.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
import {IAgentPlugin} from "@veramo/core";
import {
IOIDFClient,
OIDFClientArgs,
ResolveTrustChainArgs,
ResolveTrustChainCallbackResult,
VerifyJwtArgs,
VerifyJwtResult
ResolveTrustChainCallbackResult
} from "../types/IOIDFClient";
import {
com
} from "../../../../../OpenID-Federation/build/js/packages/openid-federation-modules-openid-federation-client";
import {schema} from "../index";
import FederationClient = com.sphereon.oid.fed.client.FederationClient;
import CryptoServiceJS = com.sphereon.oid.fed.client.crypto.CryptoServiceJS;
import CryptoService = com.sphereon.oid.fed.client.crypto.CryptoService;

export const oidfClientMethods: Array<string> = [
'resolveTrustChain',
'registerCryptoServiceCallback',
'verifyJwt'
'resolveTrustChain'
]

export class OIDFClient implements IAgentPlugin {
readonly oidfClient: FederationClient
readonly schema = schema.IContactManager
readonly schema = schema.IOIDFClient

constructor() {
constructor(args?: OIDFClientArgs) {
const { cryptoServiceCallback } = { ...args }
console.log(cryptoServiceCallback)
this.oidfClient = new FederationClient()
CryptoService.register(cryptoServiceCallback)
}

readonly methods: IOIDFClient = {
resolveTrustChain: this.resolveTrustChain.bind(this),
verifyJwt: this.verifyJwt.bind(this)
}

private async resolveTrustChain(args: ResolveTrustChainArgs): Promise<ResolveTrustChainCallbackResult> {
const { entityIdentifier, trustAnchors } = args
return this.oidfClient.resolveTrustChain(entityIdentifier, trustAnchors)
}

private async verifyJwt(args: VerifyJwtArgs): Promise<VerifyJwtResult> {
const { jwt } = args
return await CryptoServiceJS.verify(jwt)
return await this.oidfClient.resolveTrustChain(entityIdentifier, trustAnchors)
}
}
11 changes: 6 additions & 5 deletions packages/oidf-client/src/types/IOIDFClient.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import {IPluginMethodMap} from "@veramo/core";
import {
com,
Nullable
} from "../../../../../OpenID-Federation/build/js/packages/openid-federation-modules-openid-federation-client";
import ICryptoServiceCallbackJS = com.sphereon.oid.fed.client.crypto.ICryptoServiceCallback;

export interface IOIDFClient extends IPluginMethodMap {
resolveTrustChain(args: ResolveTrustChainArgs): Promise<ResolveTrustChainCallbackResult>
verifyJwt(args: VerifyJwtArgs): Promise<VerifyJwtResult>
}

export type ResolveTrustChainArgs = {
entityIdentifier: string,
trustAnchors: Array<string>
}

export type VerifyJwtArgs = {
jwt: string
export type OIDFClientArgs = {
cryptoServiceCallback?: CryptoServiceCallbackArgs
}

export type ResolveTrustChainCallbackResult = Nullable<Array<string>>
export type CryptoServiceCallbackArgs = ICryptoServiceCallbackJS

export type VerifyJwtResult = boolean
export type ResolveTrustChainCallbackResult = Nullable<Array<string>>
3 changes: 3 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 d6ce7da

Please sign in to comment.