Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/sdk-38_rfc8414-auth-server-metadata #256

Merged
merged 14 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"@veramo/url-handler": "4.2.0",
"@sphereon/ssi-types": "workspace:*",
"@sphereon/ssi-sdk.core": "workspace:*",
"@sphereon/pex": "5.0.0-unstable.18",
"@sphereon/pex": "5.0.0-unstable.19",
"@sphereon/pex-models": "^2.3.1",
"@noble/hashes": "1.2.0",
"debug": "^4.3.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"generate-plugin-schema": "ts-node ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
},
"dependencies": {
"@sphereon/pex": "5.0.0-unstable.18",
"@sphereon/pex": "5.0.0-unstable.19",
"@sphereon/pex-models": "^2.3.1",
"@sphereon/ssi-sdk.data-store": "workspace:*",
"cross-fetch": "^3.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/data-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@sphereon/kmp-mdl-mdoc": "0.2.0-SNAPSHOT.22",
"@sphereon/pex": "5.0.0-unstable.18",
"@sphereon/pex": "5.0.0-unstable.19",
"@sphereon/ssi-sdk-ext.did-utils": "0.25.0",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.25.0",
"@sphereon/ssi-sdk.agent-config": "workspace:*",
Expand Down
10 changes: 5 additions & 5 deletions packages/ebsi-support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
},
"dependencies": {
"@ethersproject/random": "^5.7.0",
"@sphereon/did-auth-siop": "0.16.1-feature.jarm.sdk.146",
"@sphereon/did-auth-siop-adapter": "0.16.1-feature.jarm.sdk.146",
"@sphereon/pex": "5.0.0-unstable.18",
"@sphereon/did-auth-siop": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/did-auth-siop-adapter": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/pex": "5.0.0-unstable.19",
"@sphereon/pex-models": "^2.3.1",
"@sphereon/ssi-sdk-ext.did-resolver-ebsi": "0.25.0",
"@sphereon/ssi-sdk-ext.did-utils": "0.25.0",
Expand All @@ -44,8 +44,8 @@
"xstate": "^4.38.3"
},
"devDependencies": {
"@sphereon/oid4vci-client": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-common": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-client": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/oid4vci-common": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.key-manager": "0.25.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.25.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/mdl-mdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"build:clean": "tsc --build --clean && tsc --build"
},
"dependencies": {
"@sphereon/did-auth-siop": "0.16.1-feature.jarm.sdk.146",
"@sphereon/did-auth-siop": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/kmp-mdl-mdoc": "0.2.0-SNAPSHOT.22",
"@sphereon/pex": "5.0.0-unstable.18",
"@sphereon/pex": "5.0.0-unstable.19",
"@sphereon/pex-models": "^2.3.1",
"@sphereon/ssi-sdk-ext.did-utils": "0.25.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.25.0",
Expand All @@ -35,8 +35,8 @@
"uuid": "^9.0.1"
},
"devDependencies": {
"@sphereon/oid4vci-client": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-common": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-client": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/oid4vci-common": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.key-manager": "0.25.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.25.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/oid4vci-holder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"dependencies": {
"@sphereon/kmp-mdl-mdoc": "0.2.0-SNAPSHOT.22",
"@sphereon/oid4vci-client": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-common": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-client": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/oid4vci-common": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/ssi-sdk-ext.did-utils": "0.25.0",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.25.0",
"@sphereon/ssi-sdk-ext.jwt-service": "0.25.0",
Expand Down
10 changes: 7 additions & 3 deletions packages/oid4vci-issuer-rest-api/__tests__/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
import { toJwk } from '@sphereon/ssi-sdk-ext.key-utils'
import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local'
import { OID4VCIIssuer } from '@sphereon/ssi-sdk.oid4vci-issuer'
import { OID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store'
import { IMetadataImportArgs, OID4VCIStore } from '@sphereon/ssi-sdk.oid4vci-issuer-store'
import {
CredentialHandlerLDLocal,
LdDefaultContexts,
Expand Down Expand Up @@ -110,6 +110,7 @@ const privateKeyStore: PrivateKeyStore = new PrivateKeyStore(dbConnection, new S

let importMetadatas = [
{
metadataType: 'issuer',
correlationId: `${baseUrl}/sphereon`,
overwriteExisting: true,
// @ts-ignore
Expand Down Expand Up @@ -163,8 +164,9 @@ let importMetadatas = [
],
} as IssuerMetadata,
},

{
metadataType: 'issuer',

correlationId: `${baseUrl}/dbc2023`,
overwriteExisting: true,
// @ts-ignore
Expand Down Expand Up @@ -290,6 +292,7 @@ let importMetadatas = [
} as IssuerMetadata,
},
{
metadataType: 'issuer',
correlationId: `${baseUrl}/fma2023`,
overwriteExisting: true,
// @ts-ignore
Expand Down Expand Up @@ -431,6 +434,7 @@ let importMetadatas = [
} as IssuerMetadata,
},
{
metadataType: 'issuer',
correlationId: `${baseUrl}/triall2023`,
overwriteExisting: true,
// @ts-ignore
Expand Down Expand Up @@ -571,7 +575,7 @@ let importMetadatas = [
],
} as IssuerMetadata,
},
]
] satisfies Array<IMetadataImportArgs>

console.log(JSON.stringify(importMetadatas, null, 2))

Expand Down
8 changes: 4 additions & 4 deletions packages/oid4vci-issuer-rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"start:dev": "ts-node __tests__/RestAPI.ts"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-issuer": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-issuer-server": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-common": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/oid4vci-issuer": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/oid4vci-issuer-server": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/ssi-express-support": "workspace:*",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.25.0",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
Expand All @@ -35,7 +35,7 @@
"devDependencies": {
"@decentralized-identity/ion-sdk": "^0.6.0",
"@sphereon/did-uni-client": "^0.6.3",
"@sphereon/pex": "5.0.0-unstable.18",
"@sphereon/pex": "5.0.0-unstable.19",
"@sphereon/pex-models": "^2.3.1",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.25.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.25.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer-rest-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"generate-plugin-schema": "ts-node ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-common": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/ssi-types": "workspace:*",
"@veramo/core": "4.2.0",
"cross-fetch": "^3.1.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/oid4vci-issuer-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build:clean": "tsc --build --clean && tsc --build"
},
"dependencies": {
"@sphereon/oid4vci-common": "0.16.1-feature.jarm.sdk.146",
"@sphereon/oid4vci-common": "0.16.1-feature.sdk.38.rfc8414.auth.server.metadata.172",
"@sphereon/ssi-sdk-ext.did-utils": "0.25.0",
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.25.0",
"@sphereon/ssi-sdk.kv-store-temp": "workspace:*",
Expand Down
143 changes: 107 additions & 36 deletions packages/oid4vci-issuer-store/src/agent/OID4VCIStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IssuerMetadata } from '@sphereon/oid4vci-common'
import { AuthorizationServerMetadata, IssuerMetadata } from '@sphereon/oid4vci-common'
import { IKeyValueStore, IValueData, KeyValueStore, ValueStoreType } from '@sphereon/ssi-sdk.kv-store-temp'
import { IAgentPlugin } from '@veramo/core'
import {
Expand All @@ -9,7 +9,7 @@ import {
IMetadataPersistArgs,
Ioid4vciStoreClearArgs,
Ioid4vciStoreExistsArgs,
Ioid4vciStoreGetArgs,
IOid4vciStoreGetArgs,
IOID4VCIStoreOpts,
Ioid4vciStoreRemoveArgs,
} from '../index'
Expand All @@ -25,7 +25,8 @@ export class OID4VCIStore implements IAgentPlugin {
this._defaultOpts = value
}

private readonly _metadataStores: Map<string, IKeyValueStore<IssuerMetadata>>
private readonly _issuerMetadataStores: Map<string, IKeyValueStore<IssuerMetadata>>
private readonly _authorizationServerMetadataStores: Map<string, IKeyValueStore<AuthorizationServerMetadata>>
private readonly _optionStores: Map<string, IKeyValueStore<IIssuerOptions>>
private readonly defaultStoreId: string
private readonly defaultNamespace: string
Expand Down Expand Up @@ -57,22 +58,36 @@ export class OID4VCIStore implements IAgentPlugin {
if (opts.defaultOpts) {
this._defaultOpts = opts.defaultOpts
}
if (opts?.metadataStores && opts.metadataStores instanceof Map) {
this._metadataStores = opts.metadataStores
} else if (opts?.metadataStores) {
this._metadataStores = new Map().set(this.defaultStoreId, opts.metadataStores)
if (opts?.issuerMetadataStores && opts.issuerMetadataStores instanceof Map) {
this._issuerMetadataStores = opts.issuerMetadataStores
} else if (opts?.issuerMetadataStores) {
this._issuerMetadataStores = new Map().set(this.defaultStoreId, opts.issuerMetadataStores)
} else {
this._metadataStores = new Map().set(
this._issuerMetadataStores = new Map().set(
this.defaultStoreId,
new KeyValueStore({
namespace: this.defaultNamespace,
store: new Map<string, IssuerMetadata>(),
}),
)
}
if (opts?.authorizationServerMetadataStores && opts.authorizationServerMetadataStores instanceof Map) {
this._authorizationServerMetadataStores = opts.authorizationServerMetadataStores
} else if (opts?.authorizationServerMetadataStores) {
this._authorizationServerMetadataStores = new Map().set(this.defaultStoreId, opts.authorizationServerMetadataStores)
} else {
this._authorizationServerMetadataStores = new Map().set(
this.defaultStoreId,
new KeyValueStore({
namespace: this.defaultNamespace,
store: new Map<string, AuthorizationServerMetadata>(),
}),
)
}
if (opts && Array.isArray(opts?.importMetadatas)) {
opts.importMetadatas.forEach((meta) =>
this.oid4vciStorePersistMetadata({
metadataType: meta.metadataType,
metadata: meta.metadata,
storeId: meta.storeId ?? this.defaultStoreId,
correlationId: meta.correlationId,
Expand Down Expand Up @@ -100,7 +115,7 @@ export class OID4VCIStore implements IAgentPlugin {
}
}

private async oid4vciStoreGetIssuerOpts({ correlationId, storeId, namespace }: Ioid4vciStoreGetArgs): Promise<IIssuerOptions | undefined> {
private async oid4vciStoreGetIssuerOpts({ correlationId, storeId, namespace }: IOid4vciStoreGetArgs): Promise<IIssuerOptions | undefined> {
return (
(await this.store({ stores: this._optionStores, storeId }).get(
this.prefix({
Expand Down Expand Up @@ -155,52 +170,108 @@ export class OID4VCIStore implements IAgentPlugin {
.then(() => true)
}

private async oid4vciStoreGetMetadata({ correlationId, storeId, namespace }: Ioid4vciStoreGetArgs): Promise<IssuerMetadata | undefined> {
return this.store({ stores: this._metadataStores, storeId }).get(this.prefix({ namespace, correlationId }))
private async oid4vciStoreGetMetadata({
metadataType,
correlationId,
storeId,
namespace,
}: IOid4vciStoreGetArgs): Promise<IssuerMetadata | AuthorizationServerMetadata | undefined> {
if (metadataType === 'authorizationServer') {
return this.store<AuthorizationServerMetadata>({
stores: this._authorizationServerMetadataStores,
storeId,
}).get(this.prefix({ namespace, correlationId }))
}

return this.store<IssuerMetadata>({
stores: this._issuerMetadataStores,
storeId,
}).get(this.prefix({ namespace, correlationId }))
}

private async oid4vciStoreHasMetadata({ correlationId, storeId, namespace }: Ioid4vciStoreExistsArgs): Promise<boolean> {
return this.store({ stores: this._metadataStores, storeId }).has(this.prefix({ namespace, correlationId }))
private async oid4vciStoreHasMetadata({ metadataType, correlationId, storeId, namespace }: Ioid4vciStoreExistsArgs): Promise<boolean> {
if (metadataType === 'authorizationServer') {
return this.store<AuthorizationServerMetadata>({
stores: this._authorizationServerMetadataStores,
storeId,
}).has(this.prefix({ namespace, correlationId }))
}

return this.store<IssuerMetadata>({
stores: this._issuerMetadataStores,
storeId,
}).has(this.prefix({ namespace, correlationId }))
}

private async oid4vciStorePersistMetadata(args: IMetadataPersistArgs): Promise<IValueData<IssuerMetadata>> {
private async oid4vciStorePersistMetadata(args: IMetadataPersistArgs): Promise<IValueData<IssuerMetadata | AuthorizationServerMetadata>> {
const namespace = this.namespaceStr(args)
const storeId = this.storeIdStr(args)
const { correlationId, metadata, ttl } = args
const { correlationId, metadata, ttl, metadataType } = args

if (args?.validation !== false) {
//todo
}
const existing = await this.store({
stores: this._metadataStores,

if (metadataType === 'authorizationServer') {
const existing = await this.store<AuthorizationServerMetadata>({
stores: this._authorizationServerMetadataStores,
storeId,
}).getAsValueData(this.prefix({ namespace, correlationId }))

if (!existing.value || (existing.value && args.overwriteExisting !== false)) {
return await this.store<AuthorizationServerMetadata>({
stores: this._authorizationServerMetadataStores,
storeId,
}).set(this.prefix({ namespace, correlationId }), metadata as AuthorizationServerMetadata, ttl)
}
return existing
}

const existing = await this.store<IssuerMetadata>({
stores: this._issuerMetadataStores,
storeId,
}).getAsValueData(this.prefix({ namespace, correlationId: correlationId }))
}).getAsValueData(this.prefix({ namespace, correlationId }))

if (!existing.value || (existing.value && args.overwriteExisting !== false)) {
// fixme: cast to issuer metadata
return await this.store({ stores: this._metadataStores, storeId }).set(
this.prefix({
namespace,
correlationId: correlationId,
}),
metadata as IssuerMetadata,
ttl,
)
return await this.store<IssuerMetadata>({
stores: this._issuerMetadataStores,
storeId,
}).set(this.prefix({ namespace, correlationId }), metadata as IssuerMetadata, ttl)
}
return existing
}

private async oid4vciStoreRemoveMetadata(args: Ioid4vciStoreRemoveArgs): Promise<boolean> {
const namespace = this.namespaceStr(args)
const storeId = this.storeIdStr(args)
return this.store({ stores: this._metadataStores, storeId }).delete(
this.prefix({
namespace,
correlationId: args.correlationId,
}),
)

if (args.metadataType === 'authorizationServer') {
return this.store<AuthorizationServerMetadata>({
stores: this._authorizationServerMetadataStores,
storeId,
}).delete(this.prefix({ namespace, correlationId: args.correlationId }))
}

return this.store<IssuerMetadata>({
stores: this._issuerMetadataStores,
storeId,
}).delete(this.prefix({ namespace, correlationId: args.correlationId }))
}

private async oid4vciStoreClearAllMetadata({ storeId }: Ioid4vciStoreClearArgs): Promise<boolean> {
return await this.store({ stores: this._metadataStores, storeId })
private async oid4vciStoreClearAllMetadata({ metadataType, storeId }: Ioid4vciStoreClearArgs): Promise<boolean> {
if (metadataType === 'authorizationServer') {
return await this.store<AuthorizationServerMetadata>({
stores: this._authorizationServerMetadataStores,
storeId,
})
.clear()
.then(() => true)
}

return await this.store<IssuerMetadata>({
stores: this._issuerMetadataStores,
storeId,
})
.clear()
.then(() => true)
}
Expand All @@ -210,7 +281,7 @@ export class OID4VCIStore implements IAgentPlugin {
}

private oid4vciStoreDefaultMetadata(): Promise<IKeyValueStore<IssuerMetadata>> {
return Promise.resolve(this.store({ stores: this._metadataStores, storeId: this.defaultStoreId }))
return Promise.resolve(this.store({ stores: this._issuerMetadataStores, storeId: this.defaultStoreId }))
}

private oid4vciStoreDefaultStoreId(): Promise<string> {
Expand Down
Loading