From 941996ea69fc042680b29d39667b92b56690887f Mon Sep 17 00:00:00 2001 From: Niels Klomp Date: Thu, 15 Aug 2024 01:58:37 +0200 Subject: [PATCH] feat: New JWS signature service that makes use of the managed identifier resolution, allowing for easier and more flexible JWT signing. --- .../src/agent/IdentifierResolution.ts | 10 +- .../functions/managedIdentifierFunctions.ts | 33 +- .../src/types/IIdentifierResolution.ts | 8 + .../identifier-resolution/src/types/common.ts | 12 +- .../src/types/managedIdentifierTypes.ts | 44 +- packages/jwt-service/CHANGELOG.md | 138 ++++++ packages/jwt-service/LICENSE | 201 ++++++++ packages/jwt-service/README.md | 433 ++++++++++++++++++ .../jwt-service/__tests__/localAgent.test.ts | 81 ++++ .../jwt-service/__tests__/restAgent.test.ts | 134 ++++++ .../__tests__/shared/jwtServiceTest.ts | 54 +++ packages/jwt-service/api-extractor.json | 18 + packages/jwt-service/package.json | 69 +++ packages/jwt-service/src/agent/JwtService.ts | 50 ++ packages/jwt-service/src/functions/index.ts | 286 ++++++++++++ packages/jwt-service/src/index.ts | 11 + packages/jwt-service/src/types/IJwtService.ts | 118 +++++ packages/jwt-service/tsconfig.json | 28 ++ packages/key-utils/src/functions.ts | 17 +- packages/key-utils/src/jwk-jcs.ts | 2 +- .../key-utils/src/types/key-util-types.ts | 34 +- packages/tsconfig.json | 3 + pnpm-lock.yaml | 172 ++++++- 23 files changed, 1917 insertions(+), 39 deletions(-) create mode 100644 packages/jwt-service/CHANGELOG.md create mode 100644 packages/jwt-service/LICENSE create mode 100644 packages/jwt-service/README.md create mode 100644 packages/jwt-service/__tests__/localAgent.test.ts create mode 100644 packages/jwt-service/__tests__/restAgent.test.ts create mode 100644 packages/jwt-service/__tests__/shared/jwtServiceTest.ts create mode 100644 packages/jwt-service/api-extractor.json create mode 100644 packages/jwt-service/package.json create mode 100644 packages/jwt-service/src/agent/JwtService.ts create mode 100644 packages/jwt-service/src/functions/index.ts create mode 100644 packages/jwt-service/src/index.ts create mode 100644 packages/jwt-service/src/types/IJwtService.ts create mode 100644 packages/jwt-service/tsconfig.json diff --git a/packages/identifier-resolution/src/agent/IdentifierResolution.ts b/packages/identifier-resolution/src/agent/IdentifierResolution.ts index 743356ce..bedec678 100644 --- a/packages/identifier-resolution/src/agent/IdentifierResolution.ts +++ b/packages/identifier-resolution/src/agent/IdentifierResolution.ts @@ -1,5 +1,5 @@ import { IAgentContext, IAgentPlugin, IDIDManager, IKeyManager } from '@veramo/core' -import { schema } from '..' +import { ManagedIdentifierKeyOpts, ManagedIdentifierKeyResult, schema } from '..' import { getManagedIdentifier, resolveExternalIdentifier } from '../functions' import { ExternalIdentifierDidOpts, @@ -34,6 +34,7 @@ export class IdentifierResolution implements IAgentPlugin { identifierManagedGetByKid: this.identifierGetManagedByKid.bind(this), identifierManagedGetByJwk: this.identifierGetManagedByJwk.bind(this), identifierManagedGetByX5c: this.identifierGetManagedByX5c.bind(this), + identifierManagedGetByKey: this.identifierGetManagedByKey.bind(this), identifierExternalResolve: this.identifierResolveExternal.bind(this), identifierExternalResolveByDid: this.identifierExternalResolveByDid.bind(this), @@ -50,7 +51,8 @@ export class IdentifierResolution implements IAgentPlugin { } /** - * Main method for managed identifiers. We always go through this method (also the others) as we want to integrate a plugin for anomaly detection. Having a single method helps + * Main method for managed identifiers. We always go through this method (also the other methods below) as we want to + * integrate a plugin for anomaly detection. Having a single method helps * @param args * @param context * @private @@ -70,6 +72,10 @@ export class IdentifierResolution implements IAgentPlugin { return (await this.identifierGetManaged({ ...args, method: 'kid' }, context)) as ManagedIdentifierKidResult } + private async identifierGetManagedByKey(args: ManagedIdentifierKeyOpts, context: IAgentContext): Promise { + return (await this.identifierGetManaged({ ...args, method: 'key' }, context)) as ManagedIdentifierKeyResult + } + private async identifierGetManagedByJwk(args: ManagedIdentifierJwkOpts, context: IAgentContext): Promise { return (await this.identifierGetManaged({ ...args, method: 'jwk' }, context)) as ManagedIdentifierJwkResult } diff --git a/packages/identifier-resolution/src/functions/managedIdentifierFunctions.ts b/packages/identifier-resolution/src/functions/managedIdentifierFunctions.ts index 2ca43ad8..05a085ca 100644 --- a/packages/identifier-resolution/src/functions/managedIdentifierFunctions.ts +++ b/packages/identifier-resolution/src/functions/managedIdentifierFunctions.ts @@ -2,18 +2,21 @@ import { getFirstKeyWithRelation } from '@sphereon/ssi-sdk-ext.did-utils' import { calculateJwkThumbprint, JWK, toJwk } from '@sphereon/ssi-sdk-ext.key-utils' import { pemOrDerToX509Certificate } from '@sphereon/ssi-sdk-ext.x509-utils' import { contextHasDidManager, contextHasKeyManager } from '@sphereon/ssi-sdk.agent-config' -import { IAgentContext, IIdentifier, IKeyManager } from '@veramo/core' +import { IAgentContext, IIdentifier, IKey, IKeyManager } from '@veramo/core' import { CryptoEngine, setEngine } from 'pkijs' import { isManagedIdentifierDidOpts, isManagedIdentifierDidResult, isManagedIdentifierJwkOpts, + isManagedIdentifierKeyOpts, isManagedIdentifierKidOpts, isManagedIdentifierX5cOpts, ManagedIdentifierDidOpts, ManagedIdentifierDidResult, ManagedIdentifierJwkOpts, ManagedIdentifierJwkResult, + ManagedIdentifierKeyOpts, + ManagedIdentifierKeyResult, ManagedIdentifierKidOpts, ManagedIdentifierKidResult, ManagedIdentifierOpts, @@ -46,6 +49,32 @@ export async function getManagedKidIdentifier( } satisfies ManagedIdentifierKidResult } +/** + * This function is just a convenience function to get a common result. The user already apparently had a key, so could have called the kid version as well + * @param opts + * @param _context + */ +export async function getManagedKeyIdentifier(opts: ManagedIdentifierKeyOpts, _context?: IAgentContext): Promise { + const method = 'key' + const key: IKey = opts.identifier + if (opts.kmsKeyRef && opts.kmsKeyRef !== key.kid) { + return Promise.reject(Error(`Cannot get a managed key object by providing a key and a kmsKeyRef that are different.}`)) + } + const jwk = toJwk(key.publicKeyHex, key.type, { key }) + const jwkThumbprint = (key.meta?.jwkThumbprint as string) ?? calculateJwkThumbprint({ jwk }) + const kid = opts.kid ?? (key.meta?.verificationMethod?.id as string) ?? jwkThumbprint + const issuer = opts.issuer ?? kid // The different identifiers should set the value. Defaults to the kid + return { + method, + key, + jwk, + jwkThumbprint, + kid, + issuer, + kmsKeyRef: key.kid, + } satisfies ManagedIdentifierKeyResult +} + export async function getManagedDidIdentifier(opts: ManagedIdentifierDidOpts, context: IAgentContext): Promise { const method = 'did' if (!contextHasDidManager(context)) { @@ -166,6 +195,8 @@ export async function getManagedIdentifier( resolutionResult = await getManagedJwkIdentifier(opts, context) } else if (isManagedIdentifierX5cOpts(opts)) { resolutionResult = await getManagedX5cIdentifier(opts, context) + } else if (isManagedIdentifierKeyOpts(opts)) { + resolutionResult = await getManagedKeyIdentifier(opts, context) } else { return Promise.reject(Error(`Could not determine identifier method. Please provide explicitly`)) } diff --git a/packages/identifier-resolution/src/types/IIdentifierResolution.ts b/packages/identifier-resolution/src/types/IIdentifierResolution.ts index 3f11e9a5..76659e3d 100644 --- a/packages/identifier-resolution/src/types/IIdentifierResolution.ts +++ b/packages/identifier-resolution/src/types/IIdentifierResolution.ts @@ -12,6 +12,8 @@ import { ManagedIdentifierDidResult, ManagedIdentifierJwkOpts, ManagedIdentifierJwkResult, + ManagedIdentifierKeyOpts, + ManagedIdentifierKeyResult, ManagedIdentifierKidOpts, ManagedIdentifierKidResult, ManagedIdentifierOpts, @@ -26,6 +28,8 @@ import { export interface IIdentifierResolution extends IPluginMethodMap { /** * Main method for managed identifiers. We always go through this method (also the others) as we want to integrate a plugin for anomaly detection. Having a single method helps + * + * The end result of all these methods is a common baseline response that allows to use a key from the registered KMS systems. It also provides kid and iss(uer) values that can be used in a JWT/JWS for instance * @param args * @param context * @public @@ -40,6 +44,10 @@ export interface IIdentifierResolution extends IPluginMethodMap { identifierManagedGetByX5c(args: ManagedIdentifierX5cOpts, context: IAgentContext): Promise + identifierManagedGetByKey(args: ManagedIdentifierKeyOpts, context: IAgentContext): Promise + + // TODO: We can create a custom managed identifier method allowing developers to register a callback function to get their implementation hooked up. Needs more investigation as it would also impact the KMS + /** * Main method for external identifiers. We always go through this method (also the others) as we want to integrate a plugin for anomaly detection. Having a single method helps * @param args diff --git a/packages/identifier-resolution/src/types/common.ts b/packages/identifier-resolution/src/types/common.ts index 2f18d2e5..c0fa7a3a 100644 --- a/packages/identifier-resolution/src/types/common.ts +++ b/packages/identifier-resolution/src/types/common.ts @@ -1,5 +1,5 @@ import { JWK } from '@sphereon/ssi-sdk-ext.key-utils' -import { IIdentifier } from '@veramo/core' +import { IIdentifier, IKey } from '@veramo/core' import { ExternalIdentifierType } from './externalIdentifierTypes' import { ManagedIdentifierType } from './managedIdentifierTypes' @@ -32,6 +32,16 @@ export function isKidIdentifier(identifier: ManagedIdentifierType | ExternalIden return typeof identifier === 'string' && !identifier.startsWith('did:') } +export function isKeyIdentifier(identifier: ManagedIdentifierType): identifier is IKey { + return ( + typeof identifier === 'string' && + !Array.isArray(identifier) && + typeof identifier === 'object' && + `kid` in identifier && + 'publicKeyHex' in identifier + ) +} + export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] { return Array.isArray(identifier) && identifier.length > 0 // todo: Do we want to do additional validation? We know it must be DER and thus hex for instance } diff --git a/packages/identifier-resolution/src/types/managedIdentifierTypes.ts b/packages/identifier-resolution/src/types/managedIdentifierTypes.ts index 3e2f4814..6d0dfd88 100644 --- a/packages/identifier-resolution/src/types/managedIdentifierTypes.ts +++ b/packages/identifier-resolution/src/types/managedIdentifierTypes.ts @@ -1,21 +1,27 @@ import { JWK } from '@sphereon/ssi-sdk-ext.key-utils' import { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core' -import { isDidIdentifier, isJwkIdentifier, isKidIdentifier, isX5cIdentifier, JwkInfo } from './common' +import { isDidIdentifier, isJwkIdentifier, isKeyIdentifier, isKidIdentifier, isX5cIdentifier, JwkInfo } from './common' /** * Use whenever we need to pass in an identifier. We can pass in kids, DIDs, IIdentifier objects and x5chains * - * The functions below can be used to check the type, and they also provide the proper runtime types + * The functions below can be used to check the type, and they also provide the proper 'runtime' types */ -export type ManagedIdentifierType = IIdentifier /*did*/ | string /*did or kid*/ | string[] /*x5c*/ | JWK - -export type ManagedIdentifierOpts = (ManagedIdentifierJwkOpts | ManagedIdentifierX5cOpts | ManagedIdentifierDidOpts | ManagedIdentifierKidOpts) & +export type ManagedIdentifierType = IIdentifier /*did*/ | string /*did or kid*/ | string[] /*x5c*/ | JWK | IKey + +export type ManagedIdentifierOpts = ( + | ManagedIdentifierJwkOpts + | ManagedIdentifierX5cOpts + | ManagedIdentifierDidOpts + | ManagedIdentifierKidOpts + | ManagedIdentifierKeyOpts +) & ManagedIdentifierOptsBase export type ManagedIdentifierOptsBase = { method?: ManagedIdentifierMethod // If provided always takes precedences otherwise it will be inferred from the identifier identifier: ManagedIdentifierType - kmsKeyRef?: string + kmsKeyRef?: string // The key reference for the KMS system. If provided this value will be used to determine the appropriate key. Otherwise it will be inferred issuer?: string // can be used when a specific issuer needs to end up, for instance when signing JWTs. Will be returned or inferred if not provided kid?: string // can be used when a specific kid value needs to be used. For instance when signing JWTs. Will be returned or inferred if not provided } @@ -45,6 +51,16 @@ export function isManagedIdentifierKidOpts(opts: ManagedIdentifierOptsBase): opt return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier) } +export type ManagedIdentifierKeyOpts = Omit & { + method?: 'key' + identifier: IKey +} + +export function isManagedIdentifierKeyOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierKidOpts { + const { identifier } = opts + return ('method' in opts && opts.method === 'key') || isKeyIdentifier(identifier) +} + export type ManagedIdentifierJwkOpts = Omit & { method?: 'jwk' identifier: JWK @@ -80,7 +96,7 @@ export function isManagedIdentifierDidResult(object: IManagedIdentifierResultBas return object!! && typeof object === 'object' && 'method' in object && object.method === 'did' } -export function isManagedIdentifierX5cResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult { +export function isManagedIdentifierX5cResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierX5cResult { return object!! && typeof object === 'object' && 'method' in object && object.method === 'x5c' } @@ -92,6 +108,10 @@ export function isManagedIdentifierKidResult(object: IManagedIdentifierResultBas return object!! && typeof object === 'object' && 'method' in object && object.method === 'kid' } +export function isManagedIdentifierKeyResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierKeyResult { + return object!! && typeof object === 'object' && 'method' in object && object.method === 'key' +} + export interface ManagedIdentifierDidResult extends IManagedIdentifierResultBase { method: 'did' identifier: IIdentifier @@ -114,13 +134,19 @@ export interface ManagedIdentifierKidResult extends IManagedIdentifierResultBase kid: string } +export interface ManagedIdentifierKeyResult extends IManagedIdentifierResultBase { + method: 'key' + issuer: string + kid: string +} + export interface ManagedIdentifierX5cResult extends IManagedIdentifierResultBase { method: 'x5c' x5c: string[] certificate: any // Certificate(JSON_, but trips schema generator. Probably want to create our own DTO } -export type ManagedIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' +export type ManagedIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' | 'key' export type ManagedIdentifierResult = IManagedIdentifierResultBase & - (ManagedIdentifierX5cResult | ManagedIdentifierDidResult | ManagedIdentifierJwkResult | ManagedIdentifierKidResult) + (ManagedIdentifierX5cResult | ManagedIdentifierDidResult | ManagedIdentifierJwkResult | ManagedIdentifierKidResult | ManagedIdentifierKeyResult) diff --git a/packages/jwt-service/CHANGELOG.md b/packages/jwt-service/CHANGELOG.md new file mode 100644 index 00000000..762556c1 --- /dev/null +++ b/packages/jwt-service/CHANGELOG.md @@ -0,0 +1,138 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +# [0.24.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.23.0...v0.24.0) (2024-08-01) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.23.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.22.0...v0.23.0) (2024-07-23) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.22.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.21.0...v0.22.0) (2024-07-02) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.21.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.20.0...v0.21.0) (2024-06-19) + +### Bug Fixes + +- Multiple DID EBSI fixes ([131faa0](https://github.com/Sphereon-Opensource/SSI-SDK/commit/131faa0b583063cb3d8d5e77a33f337a23b90536)) + +# [0.20.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.19.0...v0.20.0) (2024-06-13) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.19.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.18.2...v0.19.0) (2024-04-25) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +## [0.18.2](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.18.1...v0.18.2) (2024-04-24) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +## [0.18.1](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.18.0...v0.18.1) (2024-04-04) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.18.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.17.0...v0.18.0) (2024-03-19) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.17.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.16.0...v0.17.0) (2024-02-29) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +# [0.16.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.15.0...v0.16.0) (2024-01-13) + +### Bug Fixes + +- did:key ebsi / jcs codec value was wrong ([a71279e](https://github.com/Sphereon-Opensource/SSI-SDK/commit/a71279e3b79bff4add9fa4c889459264419accc6)) + +# [0.15.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.14.1...v0.15.0) (2023-09-30) + +**Note:** Version bump only for package @sphereon/ssi-sdk-ext.mnemonic-seed-manager + +## [0.14.1](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.14.0...v0.14.1) (2023-09-28) + +### Bug Fixes + +- public key mapping updates, fixing ed25519 with multibase encoding ([489d4f2](https://github.com/Sphereon-Opensource/SSI-SDK/commit/489d4f20e0f354eb50b1a16a91472d4e85588113)) + +# [0.14.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.13.0...v0.14.0) (2023-08-09) + +### Bug Fixes + +- RSA import fixes ([77704a2](https://github.com/Sphereon-Opensource/SSI-SDK/commit/77704a2064e1c1d3ffc23e580ddbb36063fc70ae)) + +# [0.13.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.12.1...v0.13.0) (2023-07-30) + +### Features + +- Add agent resolver method ([3c7b21e](https://github.com/Sphereon-Opensource/SSI-SDK/commit/3c7b21e13538fac64581c0c73d0450ef6e9b56f0)) + +## [0.12.1](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.12.0...v0.12.1) (2023-06-24) + +### Bug Fixes + +- Make sure we set the saltLength for RSA PSS ([e19ed6c](https://github.com/Sphereon-Opensource/SSI-SDK/commit/e19ed6c3a7b8454e8074111d33fc59a9c6bcc611)) + +# [0.12.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.11.0...v0.12.0) (2023-05-07) + +### Features + +- Move mnemonic seed generator to crypto extensions ([748a7f9](https://github.com/Sphereon-Opensource/SSI-SDK/commit/748a7f962d563c60aa543c0c6900aa0c0daea42d)) +- Move mnemonic seed generator to crypto extensions ([173ef88](https://github.com/Sphereon-Opensource/SSI-SDK/commit/173ef883deafa4c87f0d589963fb36ccb8789d1b)) + +# [0.10.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.9.0...v0.10.0) (2023-04-30) + +### Bug Fixes + +- bbs+ fixes and updates ([ae9e903](https://github.com/Sphereon-Opensource/SSI-SDK/commit/ae9e9032b23036d44b3791da416229cd6db5b776)) +- cleanup package.json files ([0cc08b6](https://github.com/Sphereon-Opensource/SSI-SDK/commit/0cc08b6acc168b838bff48b42fdabbdea4cd0899)) + +# [0.9.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.8.0...v0.9.0) (2023-03-09) + +### Features + +- Allow to relax JWT timing checks, where the JWT claim is slightly different from the VC claim. Used for issuance and expiration dates ([85bff6d](https://github.com/Sphereon-Opensource/SSI-SDK/commit/85bff6da21dea5d8f636ea1f55b41be00b18b002)) + +# [0.8.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.7.0...v0.8.0) (2022-09-03) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +# [0.7.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.6.0...v0.7.0) (2022-08-05) + +### Features + +- Add migration support to mnemonic seed manager plugin. Fix some entity props in the process ([f7641f4](https://github.com/Sphereon-Opensource/SSI-SDK/commit/f7641f4f56ebe99894ddad6c6827681406d21d2e)) + +# [0.6.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.5.1...v0.6.0) (2022-07-01) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +# [0.5.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.4.0...v0.5.0) (2022-02-23) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +# [0.4.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.3.4...v0.4.0) (2022-02-11) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +## [0.3.4](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.3.3...v0.3.4) (2022-02-11) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +## [0.3.1](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.3.0...v0.3.1) (2022-01-28) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +# [0.3.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.2.0...v0.3.0) (2022-01-16) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-seed-manager + +# [0.2.0](https://github.com/Sphereon-Opensource/SSI-SDK/compare/v0.1.0...v0.2.0) (2021-12-16) + +**Note:** Version bump only for package @sphereon/ssi-sdk-mnemonic-info-generator diff --git a/packages/jwt-service/LICENSE b/packages/jwt-service/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/packages/jwt-service/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/jwt-service/README.md b/packages/jwt-service/README.md new file mode 100644 index 00000000..5b2a6df9 --- /dev/null +++ b/packages/jwt-service/README.md @@ -0,0 +1,433 @@ + +

+
+ Sphereon +
Jwt and JWS signature service +
+

+ +A plugin that in a uniform way can resolve any supported external identifiers, as well as get managed identifiers. It +performs validations as well as return the objects in a uniform way. Public keys will always be resolved and presented +as JWKs. + +Currently, it supports the following identifier methods and types: + +- DIDs (and the internal IIdentifier type) +- JWKs (JWK object and public key in hex) +- kid, KMS key references and jwk thumbprints +- X.509 certificate chains + +TODO: + +- https .well-knowns (JWKSet) +- OIDC Discovery +- X.509 CN en SANs +- OID4VCI Issuers + +Since the plugin dynamically looks for the correct agent plugins based on the types being resolved, this plugin should +be used for any and all identifier resolution. + +No matter whether the plugin is doing resolution of external identifiers or managed/internal identifiers, the results +will always include certain objects, like the JWK key(s) associated, certificates etc. This ensures uniform handling in +all places that rely on key/identifier management. + +## Managed Identifiers + +Managed or internal identifiers, are identifiers that are being controlled by the agent. This means the agent either has +access to the private key, or is using a hardware protected mechanism with access to the private key. All of the managed +methods return both a JWK managed by the agent, an IKey instance, which is the internal key representations, as well as +a kmsKeyRef allowing you to retrieve the key easily later. + +Read an identifier by IIdentifier object or DID (or did URL) + +### DIDs and IIdentifiers + +```typescript +const identifier = await agent.didManagerCreate({ kms: 'local' }) +// Created an idenftier. For example did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0" + +let resolution = await agent.identifierManagedGet({ identifier }) +console.log(JSON.stringify(resolution, null, 2)) + +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierManagedGetByDid({ identifier }) + +resolution = await agent.identifierManagedGet({ + identifier: + 'did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0', +}) +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierManagedGetByDid({ + identifier: + 'did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0', +}) +``` + +result (some parts omited for brevity: + +```json +{ + "method": "did", + "jwk": { + "alg": "ES256", + "kty": "EC", + "crv": "P-256", + "x": "GjhS83y2FihjbF38P_sMUKf935hVvMDsck0DgxxmC34", + "y": "SpVOGx5levQc5M_Y3eAM2ouhfFqtUsPzU__DAITX-hI", + "kid": "77_7PdYbkikec5AR6zSKVIxgNExChvuOLLULBwS6jwc" + }, + "jwkThumbprint": "77_7PdYbkikec5AR6zSKVIxgNExChvuOLLULBwS6jwc", + "identifier": { + "did": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0", + "controllerKeyId": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0#0", + "keys": [ + { + + "kms": "local" + } + ], + "services": [], + "provider": "did:jwk" + }, + "did": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0", + "controllerKeyId": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0#0", + "keys": [ + { + + } + ], + "key": { + "type": "Secp256r1", + "kid": "021a3852f37cb61628636c5dfc3ffb0c50a7fddf9855bcc0ec724d03831c660b7e", + "publicKeyHex": "021a3852f37cb61628636c5dfc3ffb0c50a7fddf9855bcc0ec724d03831c660b7e", + "kms": "local", + "meta": + }, + "kmsKeyRef": "021a3852f37cb61628636c5dfc3ffb0c50a7fddf9855bcc0ec724d03831c660b7e" +} +``` + +### KMS Key reference, JWK Thumbprint + +Read a managed identifier by kmsRef, or jwkThumbprint, using the above example. The response is the same, minus the +identifier object, did and controllerKey values in the result as it will be a single key only in this case. + +```typescript +// JWK Thumbprint +resolution = await agent.identifierManagedGet({ identifier: '77_7PdYbkikec5AR6zSKVIxgNExChvuOLLULBwS6jwc' }) +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierManagedGetByKid({ identifier: '77_7PdYbkikec5AR6zSKVIxgNExChvuOLLULBwS6jwc' }) + +// KMS Key ref +resolution = await agent.identifierManagedGet({ identifier: '021a3852f37cb61628636c5dfc3ffb0c50a7fddf9855bcc0ec724d03831c660b7e' }) +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierManagedGetByKid({ identifier: '021a3852f37cb61628636c5dfc3ffb0c50a7fddf9855bcc0ec724d03831c660b7e' }) + +const jwk = { + alg: 'ES256', + kty: 'EC', + crv: 'P-256', + x: 'GjhS83y2FihjbF38P_sMUKf935hVvMDsck0DgxxmC34', + y: 'SpVOGx5levQc5M_Y3eAM2ouhfFqtUsPzU__DAITX-hI', + kid: '77_7PdYbkikec5AR6zSKVIxgNExChvuOLLULBwS6jwc', +} + +// By JWK object +resolution = await agent.identifierManagedGet({ identifier: jwk }) +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierManagedGetByJwk({ identifier: jwk }) +``` + +## External Identifiers + +We will use the example JWK above again, as that is an in memory construct, we can also resolve it like an external +identifier + +### DIDs + +```typescript +const did = + 'did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4IjoiR2poUzgzeTJGaWhqYkYzOFBfc01VS2Y5MzVoVnZNRHNjazBEZ3h4bUMzNCIsInkiOiJTcFZPR3g1bGV2UWM1TV9ZM2VBTTJvdWhmRnF0VXNQelVfX0RBSVRYLWhJIn0' + +resolution = await agent.identifierExternalResolve({ identifier: did }) +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierExternalResolveByDid({ identifier: did }) +console.log(JSON.stringify(resolution, null, 2)) +``` + +Results in the following JSON, with some properties removed for brevity + +```json +{ + "method": "did", + "did": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "jwks": [ + { + "jwk": { + "alg": "ES256", + "use": "sig", + "kty": "EC", + "crv": "P-256", + "x": "wdIEmfjmaZiGsub9Hffnhbr0xVVVmVLiUYLscgRt-3Y", + "y": "ept3ke4SslZb7ZbweWKmSaM3166ZuvecZ9ciKs6PDcw", + "kid": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + }, + "jwkThumbprint": "gBT5We3eKcs3NNBAeJ40iPHbWvqAmY8C8L36rGwOAJk", + "kid": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + } + ], + "didJwks": { + // These are the JWKs per verification method relationship. For a JWK this includes the above JWK, so we will not repeat it here + "verificationMethod": [ + { + + } + ], + "assertionMethod": [ + { + + } + ], + "authentication": [ + { + + } + ], + "keyAgreement": [], + "capabilityInvocation": [ + { + + } + ], + "capabilityDelegation": [ + { + + } + ] + }, + "didDocument": { + "@context": [ + "https://www.w3.org/ns/did/v1", + { + "@vocab": "https://www.iana.org/assignments/jose#" + } + ], + "id": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "verificationMethod": [ + { + "id": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0", + "type": "JsonWebKey2020", + "controller": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "publicKeyJwk": { + "alg": "ES256", + "use": "sig", + "kty": "EC", + "crv": "P-256", + "x": "wdIEmfjmaZiGsub9Hffnhbr0xVVVmVLiUYLscgRt-3Y", + "y": "ept3ke4SslZb7ZbweWKmSaM3166ZuvecZ9ciKs6PDcw", + "kid": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + } + } + ], + "assertionMethod": [ + "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + ], + "authentication": [ + "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + ], + "capabilityInvocation": [ + "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + ], + "capabilityDelegation": [ + "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0#0" + ] + }, + "didResolutionResult": { + "didDocumentMetadata": {}, + "didResolutionMetadata": { + "contentType": "application/did+ld+json", + "pattern": "^(did:jwk:.+)$", + "did": { + "didString": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "methodSpecificId": "eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "method": "jwk" + } + } + }, + "didParsed": { + "did": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "method": "jwk", + "id": "eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0", + "didUrl": "did:jwk:eyJhbGciOiJFUzI1NiIsInVzZSI6InNpZyIsImt0eSI6IkVDIiwiY3J2IjoiUC0yNTYiLCJ4Ijoid2RJRW1mam1hWmlHc3ViOUhmZm5oYnIweFZWVm1WTGlVWUxzY2dSdC0zWSIsInkiOiJlcHQza2U0U3NsWmI3WmJ3ZVdLbVNhTTMxNjZadXZlY1o5Y2lLczZQRGN3In0" + } +} +``` + +### X.509 Certificate Chains + +You can provide an optional verification time as well using a Date as value. By default the X5C will be fully verified, +unless the verification param is set to false. + +```typescript +const sphereonCA = 'PEM or DER CERT' +const sphereonTest = 'PEM or DER CERT' + +let resolution = await agent.identifierExternalResolve({ + identifier: [sphereonTest, sphereonCA], + trustAnchors: [sphereonCA], +}) + +// This is the same as above, but with the benefit of having fully typed response, instead of a union +resolution = await agent.identifierExternalResolveByX5c({ + identifier: [sphereonTest, sphereonCA], + trustAnchors: [sphereonCA], +}) + +console.log(JSON.stringify(resolution, null, 2)) +``` + +```json +{ + "method": "x5c", + "verificationResult": { + "error": false, + "critical": false, + "message": "Certificate chain was valid", + "verificationTime": "2024-08-13T13:28:16.457Z", + "certificateChain": [ + { + "issuer": { + "dn": { + "DN": "C=NL,O=Sphereon International B.V.,OU=IT,CN=ca.sphereon.com", + "attributes": { + "C": "NL", + "O": "Sphereon International B.V.", + "OU": "IT", + "CN": "ca.sphereon.com" + } + } + }, + "subject": { + "dn": { + "DN": "CN=test123.test.sphereon.com", + "attributes": { + "CN": "test123.test.sphereon.com" + } + } + }, + "publicKeyJWK": { + "key_ops": ["verify"], + "ext": true, + "kty": "EC", + "x": "pyVHVR7IdgWmG_TLb3-K_4dg3XC6GQQWDB61Lna15ns", + "y": "OcVNCBD0kMmqEaKjbczwd2GvbV1AOxgE7AKsa3L0zxM", + "crv": "P-256" + }, + "notBefore": "2024-08-06T20:16:12.000Z", + "notAfter": "2024-11-04T22:16:12.000Z" + }, + { + "issuer": { + "dn": { + "DN": "C=NL,O=Sphereon International B.V.,OU=IT,CN=ca.sphereon.com", + "attributes": { + "C": "NL", + "O": "Sphereon International B.V.", + "OU": "IT", + "CN": "ca.sphereon.com" + } + } + }, + "subject": { + "dn": { + "DN": "C=NL,O=Sphereon International B.V.,OU=IT,CN=ca.sphereon.com", + "attributes": { + "C": "NL", + "O": "Sphereon International B.V.", + "OU": "IT", + "CN": "ca.sphereon.com" + } + } + }, + "publicKeyJWK": { + "key_ops": ["verify"], + "ext": true, + "kty": "EC", + "x": "SIDQp4RJI2s5yYIOBrxiwGRROCjBkbCq8vaf3UlSkAw", + "y": "dRSwvlVFdqdiLXnk2pQqT1vZnDG0I-x-iz2EbdsG0aY", + "crv": "P-256" + }, + "notBefore": "2024-07-28T21:26:49.000Z", + "notAfter": "2034-07-28T21:26:49.000Z" + } + ] + }, + "issuerJWK": { + "key_ops": ["verify"], + "ext": true, + "kty": "EC", + "x": "pyVHVR7IdgWmG_TLb3-K_4dg3XC6GQQWDB61Lna15ns", + "y": "OcVNCBD0kMmqEaKjbczwd2GvbV1AOxgE7AKsa3L0zxM", + "crv": "P-256" + }, + "jwks": [ + { + "jwk": { + "key_ops": ["verify"], + "ext": true, + "kty": "EC", + "x": "pyVHVR7IdgWmG_TLb3-K_4dg3XC6GQQWDB61Lna15ns", + "y": "OcVNCBD0kMmqEaKjbczwd2GvbV1AOxgE7AKsa3L0zxM", + "crv": "P-256" + }, + "kid": "CN=test123.test.sphereon.com", + "jwkThumbprint": "LlITYB6tlvSVtVrMtIEzrkkSQkMSoPslhQ3Rnk1x484" + }, + { + "jwk": { + "key_ops": ["verify"], + "ext": true, + "kty": "EC", + "x": "SIDQp4RJI2s5yYIOBrxiwGRROCjBkbCq8vaf3UlSkAw", + "y": "dRSwvlVFdqdiLXnk2pQqT1vZnDG0I-x-iz2EbdsG0aY", + "crv": "P-256" + }, + "kid": "C=NL,O=Sphereon International B.V.,OU=IT,CN=ca.sphereon.com", + "jwkThumbprint": "1wAefk4zZ8Q8cM-9djHoJhPUtKjVFLqG7u9VftVqulA" + } + ], + "x5c": [ + "MIIC1jCCAnygAwIBAgITALtvb+InWBtzJO3mAeQZIUBXbzAKBggqhkjOPQQDAjBaMQswCQYDVQQGEwJOTDEkMCIGA1UECgwbU3BoZXJlb24gSW50ZXJuYXRpb25hbCBCLlYuMQswCQYDVQQLDAJJVDEYMBYGA1UEAwwPY2Euc3BoZXJlb24uY29tMB4XDTI0MDgwNjIwMTYxMloXDTI0MTEwNDIyMTYxMlowJDEiMCAGA1UEAwwZdGVzdDEyMy50ZXN0LnNwaGVyZW9uLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABKclR1UeyHYFphv0y29/iv+HYN1wuhkEFgwetS52teZ7OcVNCBD0kMmqEaKjbczwd2GvbV1AOxgE7AKsa3L0zxOjggFVMIIBUTAdBgNVHQ4EFgQUoWVOwL15ttB1YPUd0HgvYry0Z+UwHwYDVR0jBBgwFoAU5wfKXZVc+cig/s7jZEUegLMsMsEwYQYIKwYBBQUHAQEEVTBTMFEGCCsGAQUFBzAChkVodHRwOi8vZXUuY2VydC5lemNhLmlvL2NlcnRzL2RhYTFiNGI0LTg1ZmQtNGJhNC1iOTZiLTMzMmFkZDg5OWNlOS5jZXIwEwYDVR0lBAwwCgYIKwYBBQUHAwIwJAYDVR0RBB0wG4IZdGVzdDEyMy50ZXN0LnNwaGVyZW9uLmNvbTAOBgNVHQ8BAf8EBAMCB4AwYQYDVR0fBFowWDBWoFSgUoZQaHR0cDovL2V1LmNybC5lemNhLmlvL2NybC8yY2RmN2M1ZS1iOWNkLTQzMTctYmI1Ni0zODZkMjQ0MzgwZTIvY2FzcGhlcmVvbmNvbS5jcmwwCgYIKoZIzj0EAwIDSAAwRQIgThuggyhKePvRt5YEvfg6MD42N2/63L0ypw0vLZkM+zYCIQD+uInjqsfR6K/D+ebjuOAdhOyeD2nZAW29zN20WIQJsw==", + "MIICCDCCAa6gAwIBAgITAPMgqwtYzWPBXaobHhxG9iSydTAKBggqhkjOPQQDAjBaMQswCQYDVQQGEwJOTDEkMCIGA1UECgwbU3BoZXJlb24gSW50ZXJuYXRpb25hbCBCLlYuMQswCQYDVQQLDAJJVDEYMBYGA1UEAwwPY2Euc3BoZXJlb24uY29tMB4XDTI0MDcyODIxMjY0OVoXDTM0MDcyODIxMjY0OVowWjELMAkGA1UEBhMCTkwxJDAiBgNVBAoMG1NwaGVyZW9uIEludGVybmF0aW9uYWwgQi5WLjELMAkGA1UECwwCSVQxGDAWBgNVBAMMD2NhLnNwaGVyZW9uLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABEiA0KeESSNrOcmCDga8YsBkUTgowZGwqvL2n91JUpAMdRSwvlVFdqdiLXnk2pQqT1vZnDG0I+x+iz2EbdsG0aajUzBRMB0GA1UdDgQWBBTnB8pdlVz5yKD+zuNkRR6AsywywTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMCA0gAMEUCIHH7ie1OAAbff5262rzZVQa8J9zENG8AQlHHFydMdgaXAiEA1Ib82mhHIYDziE0DDbHEAXOs98al+7dpo8fPGVGTeKI=" + ] +} +``` + +### Installation + +```shell +pnpm add @sphereon/ssi-sdk-ext.identifier-resolution +``` + +### Build + +```shell +pnpm run build +``` + +### Test + +The test command runs: + +- `prettier` +- `jest` +- `coverage` + +You can also run only a single section of these tests, using for example `yarn test:unit`. + +```shell +pnmp run test +``` diff --git a/packages/jwt-service/__tests__/localAgent.test.ts b/packages/jwt-service/__tests__/localAgent.test.ts new file mode 100644 index 00000000..678db418 --- /dev/null +++ b/packages/jwt-service/__tests__/localAgent.test.ts @@ -0,0 +1,81 @@ +import { JwkDIDProvider } from '@sphereon/ssi-sdk-ext.did-provider-jwk' +import { getDidJwkResolver } from '@sphereon/ssi-sdk-ext.did-resolver-jwk' +import { IdentifierResolution, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution' +import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager' +import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local' +import { createAgent, IDIDManager, IKeyManager, TAgent } from '@veramo/core' +import { Entities, KeyStore, migrations, PrivateKeyStore } from '@veramo/data-store' +import { DIDManager, MemoryDIDStore } from '@veramo/did-manager' +import { DIDResolverPlugin } from '@veramo/did-resolver' +import { SecretBox } from '@veramo/kms-local' +import { OrPromise } from '@veramo/utils' +import { Resolver } from 'did-resolver' +import { DataSource } from 'typeorm' +import { IJwtService, JwtService } from '../src' +import jwtTests from './shared/jwtServiceTest' + +jest.setTimeout(30000) + +const KMS_SECRET_KEY = 'd17c8674f5db9396f8eecccde25e882bb0336316bc411ae38dc1f3dcd7ed100f' +let databaseFile = ':memory:' +let dbConnection: OrPromise +let agent: TAgent + +const DID_METHOD = 'did:jwk' +// const PRIVATE_KEY_HEX = '7dd923e40f4615ac496119f7e793cc2899e99b64b88ca8603db986700089532b' + +const jwkDIDProvider = new JwkDIDProvider({ + defaultKms: 'mem', +}) + +const setup = async (): Promise => { + const db: OrPromise = new DataSource({ + type: 'sqlite', + database: databaseFile, + synchronize: false, + logging: ['info', 'warn'], + entities: [...Entities], + migrations: [...migrations], + migrationsRun: true, + }).initialize() + const secretBox = new SecretBox(KMS_SECRET_KEY) + + const localAgent = createAgent({ + plugins: [ + new SphereonKeyManager({ + store: new KeyStore(db), + kms: { + local: new SphereonKeyManagementSystem(new PrivateKeyStore(db, secretBox)), + }, + }), + new DIDResolverPlugin({ + resolver: new Resolver({ ...getDidJwkResolver() }), + }), + new DIDManager({ + providers: { + [DID_METHOD]: jwkDIDProvider, + }, + defaultProvider: DID_METHOD, + store: new MemoryDIDStore(), + }), + new IdentifierResolution(), + new JwtService(), + ], + }) + agent = localAgent + dbConnection = db + return true +} + +const tearDown = async (): Promise => { + await (await dbConnection).destroy() + return true +} + +const getAgent = () => agent + +const testContext = { getAgent, setup, tearDown } + +describe('Local integration tests', () => { + jwtTests(testContext) +}) diff --git a/packages/jwt-service/__tests__/restAgent.test.ts b/packages/jwt-service/__tests__/restAgent.test.ts new file mode 100644 index 00000000..1540633f --- /dev/null +++ b/packages/jwt-service/__tests__/restAgent.test.ts @@ -0,0 +1,134 @@ +import { JwkDIDProvider } from '@sphereon/ssi-sdk-ext.did-provider-jwk' +import { getDidJwkResolver } from '@sphereon/ssi-sdk-ext.did-resolver-jwk' +import { IdentifierResolution, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution' +import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager' +import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local' + +import { createAgent, IAgent, IAgentOptions, IDIDManager, IKeyManager, TAgent } from '@veramo/core' +import { Entities, KeyStore, migrations, PrivateKeyStore } from '@veramo/data-store' +import { DIDManager, MemoryDIDStore } from '@veramo/did-manager' +import { DIDResolverPlugin } from '@veramo/did-resolver' +import { SecretBox } from '@veramo/kms-local' +import { AgentRestClient } from '@veramo/remote-client' +import { AgentRouter, RequestWithAgentRouter } from '@veramo/remote-server' +import { OrPromise } from '@veramo/utils' +import { Resolver } from 'did-resolver' + +// @ts-ignore +import express from 'express' +import { Server } from 'http' +import { DataSource } from 'typeorm' + +import { IJwtService, JwtService } from '../src' +import jwtServiceTests from './shared/jwtServiceTest' + +jest.setTimeout(30000) + +const databaseFile = ':memory:' +const port = 13212 +const basePath = '/agent' + +const DID_METHOD = 'did:jwk' +// const PRIVATE_KEY_HEX = '7dd923e40f4615ac496119f7e793cc2899e99b64b88ca8603db986700089532b' + +const jwkDIDProvider = new JwkDIDProvider({ + defaultKms: 'mem', +}) + +let serverAgent: IAgent +let clientAgent: TAgent +let restServer: Server +let dbConnection: OrPromise + +const KMS_SECRET_KEY = 'd17c8674f5db9396f8eecccde25e882bb0336316bc411ae38dc1f3dcd7ed100f' + +const getAgent = (options?: IAgentOptions) => { + if (!serverAgent) { + throw Error('Server agent not available yet (missed await?)') + } + if (!clientAgent) { + clientAgent = createAgent({ + ...options, + plugins: [ + new AgentRestClient({ + url: 'http://localhost:' + port + basePath, + enabledMethods: serverAgent.availableMethods(), + schema: serverAgent.getSchema(), + }), + ], + }) + } + + return clientAgent +} + +const setup = async (): Promise => { + if (serverAgent) { + return true + } + const db: OrPromise = new DataSource({ + type: 'sqlite', + database: databaseFile, + synchronize: false, + logging: ['info', 'warn'], + entities: [...Entities], + migrations: [...migrations], + migrationsRun: true, + }).initialize() + + const secretBox = new SecretBox(KMS_SECRET_KEY) + + const agent = createAgent({ + plugins: [ + new SphereonKeyManager({ + store: new KeyStore(db), + kms: { + local: new SphereonKeyManagementSystem(new PrivateKeyStore(db, secretBox)), + }, + }), + new DIDResolverPlugin({ + resolver: new Resolver({ ...getDidJwkResolver() }), + }), + new DIDManager({ + providers: { + [DID_METHOD]: jwkDIDProvider, + }, + defaultProvider: DID_METHOD, + store: new MemoryDIDStore(), + }), + new IdentifierResolution(), + new JwtService(), + ], + }) + + serverAgent = agent + dbConnection = db + + const agentRouter = AgentRouter({ + exposedMethods: serverAgent.availableMethods(), + }) + + const requestWithAgent = RequestWithAgentRouter({ + agent: serverAgent, + }) + + return new Promise((resolve) => { + const app = express() + app.use(basePath, requestWithAgent, agentRouter) + restServer = app.listen(port, () => { + resolve(true) + }) + }) +} + +const tearDown = async (): Promise => { + restServer.close() + await (await dbConnection).dropDatabase() + return true +} + +const testContext = { getAgent, setup, tearDown } + +describe('REST integration tests', () => { + jwtServiceTests(testContext) +}) diff --git a/packages/jwt-service/__tests__/shared/jwtServiceTest.ts b/packages/jwt-service/__tests__/shared/jwtServiceTest.ts new file mode 100644 index 00000000..938cfa71 --- /dev/null +++ b/packages/jwt-service/__tests__/shared/jwtServiceTest.ts @@ -0,0 +1,54 @@ +import {IIdentifierResolution} from '@sphereon/ssi-sdk-ext.identifier-resolution' +import {IDIDManager, IKeyManager, TAgent} from '@veramo/core' +import {IJwtService} from '../../src' + +type ConfiguredAgent = TAgent + +export default (testContext: { + getAgent: () => ConfiguredAgent; + setup: () => Promise; + tearDown: () => Promise +}) => { + let agent: ConfiguredAgent + // let key: IKey + + + const ietfJwk = { + kty: 'EC', + crv: 'P-256', + x: 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU', + y: 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0', + d: 'jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI', + } + // tbe above key as hex + const privateKeyHex = "8E9B109E719098BF980487DF1F5D77E9CB29606EBED2263B5F57C213DF84F4B2".toLowerCase() + const publicKeyHex = "037fcdce2770f6c45d4183cbee6fdb4b7b580733357be9ef13bacf6e3c7bd15445" + const kid = publicKeyHex + + + beforeAll(async () => { + await testContext.setup().then(() => (agent = testContext.getAgent())) + await agent.keyManagerImport({kid: 'test', type: 'Secp256r1', kms: 'local', privateKeyHex}) + + }) + afterAll(testContext.tearDown) + + + describe('internal identifier-resolution', () => { + + it('should resolve did identifier by did string', async () => { + const jwt = await agent.jwtCreateJwsCompactSignature({ + // Example payloads from IETF spec + issuer: {identifier: kid, noIdentifierInHeader: true}, protectedHeader: {"alg": "ES256"}, payload: 'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ' + }) + + const [header, payload, signature] = jwt.jwt.split('.') + expect(header).toStrictEqual('eyJhbGciOiJFUzI1NiJ9') + expect(payload).toStrictEqual('eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ') + // ES256 uses a nonce, su the signature will never be the same as the ietf version + expect(signature).toEqual('e4ZrhZdbFQ7630Tq51E6RQiJaae9bFNGJszIhtusEwzvO21rzH76Wer6yRn2Zb34VjIm3cVRl0iQctbf4uBY3w') + + }) + + }) +} diff --git a/packages/jwt-service/api-extractor.json b/packages/jwt-service/api-extractor.json new file mode 100644 index 00000000..3e6cf8a3 --- /dev/null +++ b/packages/jwt-service/api-extractor.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "apiReport": { + "enabled": true, + "reportFolder": "./api", + "reportTempFolder": "./api" + }, + + "docModel": { + "enabled": true, + "apiJsonFilePath": "./api/.api.json" + }, + + "dtsRollup": { + "enabled": false + }, + "mainEntryPointFilePath": "/dist/index.d.ts" +} diff --git a/packages/jwt-service/package.json b/packages/jwt-service/package.json new file mode 100644 index 00000000..5f0a24d5 --- /dev/null +++ b/packages/jwt-service/package.json @@ -0,0 +1,69 @@ +{ + "name": "@sphereon/ssi-sdk-ext.jwt-service", + "version": "0.24.0", + "source": "src/index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "veramo": { + "pluginInterfaces": { + "IJwtService": "./src/types/IJwtService.ts" + } + }, + "scripts": { + "build": "tsc --build", + "build:clean": "tsc --build --clean && tsc --build", + "generate-plugin-schema": "sphereon dev generate-plugin-schema" + }, + "dependencies": { + "@sphereon/ssi-sdk.agent-config": "0.29.1-unstable.75", + "@sphereon/ssi-types": "0.29.1-unstable.75", + "@sphereon/ssi-sdk-ext.key-utils": "workspace:*", + "@sphereon/ssi-sdk-ext.did-utils": "workspace:*", + "@sphereon/ssi-sdk-ext.x509-utils": "workspace:*", + "@sphereon/ssi-sdk-ext.identifier-resolution": "workspace:*", + "@sphereon/ssi-sdk-ext.key-manager": "workspace:*", + "uint8arrays": "^3.1.1", + "jwt-decode": "^4.0.0", + "@veramo/core": "4.2.0", + "@veramo/utils": "4.2.0", + "debug": "^4.3.4" + }, + "devDependencies": { + "@sphereon/ssi-sdk.dev": "0.29.1-unstable.75", + "@sphereon/ssi-sdk-ext.kms-local": "workspace:*", + "@sphereon/ssi-sdk-ext.did-provider-jwk": "workspace:*", + "@sphereon/ssi-sdk-ext.did-resolver-jwk": "workspace:*", + "js-crypto-key-utils": "^1.0.7", + "did-resolver": "^4.1.0", + "@veramo/key-manager": "4.2.0", + "@veramo/kms-local": "4.2.0", + "@veramo/data-store": "4.2.0", + "@veramo/did-manager": "4.2.0", + "@veramo/did-resolver": "4.2.0", + "@veramo/remote-client": "4.2.0", + "@veramo/remote-server": "4.2.0", + "typeorm": "0.3.20" + }, + "files": [ + "dist/**/*", + "src/**/*", + "plugin.schema.json", + "README.md", + "LICENSE" + ], + "private": false, + "publishConfig": { + "access": "public" + }, + "repository": "git@github.com:Sphereon-OpenSource/SSI-SDK-crypto-extensions.git", + "author": "Sphereon ", + "license": "Apache-2.0", + "keywords": [ + "Sphereon", + "Identifier resolution", + "JWK", + "DID", + "X.509 Certificates", + "ARF" + ] +} diff --git a/packages/jwt-service/src/agent/JwtService.ts b/packages/jwt-service/src/agent/JwtService.ts new file mode 100644 index 00000000..5f2cd9bd --- /dev/null +++ b/packages/jwt-service/src/agent/JwtService.ts @@ -0,0 +1,50 @@ +import {IAgentPlugin} from '@veramo/core' +import { + createJwsCompact, + CreateJwsCompactArgs, + CreateJwsFlattenedArgs, + CreateJwsJsonArgs, + createJwsJsonFlattened, + createJwsJsonGeneral, + IJwtService, + IRequiredContext, JwsCompactResult, + JwsJsonFlattened, + JwsJsonGeneral, + PreparedJwsObject, + prepareJwsObject, + schema, +} from '..' + + +/** + * @public + */ +export class JwtService implements IAgentPlugin { + readonly schema = schema.IMnemonicInfoGenerator + readonly methods: IJwtService = { + jwtPrepareJws: this.jwtPrepareJws.bind(this), + jwtCreateJwsJsonGeneralSignature: this.jwtCreateJwsJsonGeneralSignature.bind(this), + jwtCreateJwsJsonFlattenedSignature: this.jwtCreateJwsJsonFlattenedSignature.bind(this), + jwtCreateJwsCompactSignature: this.jwtCreateJwsCompactSignature.bind(this), + } + + private async jwtPrepareJws(args: CreateJwsJsonArgs, context: IRequiredContext): Promise { + return await prepareJwsObject(args, context) + } + + private async jwtCreateJwsJsonGeneralSignature(args: CreateJwsJsonArgs, context: IRequiredContext): Promise { + return await createJwsJsonGeneral(args, context) + } + + private async jwtCreateJwsJsonFlattenedSignature(args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise { + return await createJwsJsonFlattened(args, context) + } + + private async jwtCreateJwsCompactSignature( + args: CreateJwsCompactArgs, + context: IRequiredContext + ): Promise { + // We wrap it in a json object for remote REST calls + return { jwt: await createJwsCompact(args, context) } + } +} diff --git a/packages/jwt-service/src/functions/index.ts b/packages/jwt-service/src/functions/index.ts new file mode 100644 index 00000000..4e3dd7ff --- /dev/null +++ b/packages/jwt-service/src/functions/index.ts @@ -0,0 +1,286 @@ +import { + isManagedIdentifierDidResult, + isManagedIdentifierX5cResult, + ManagedIdentifierMethod, + ManagedIdentifierResult, +} from '@sphereon/ssi-sdk-ext.identifier-resolution' +import {bytesToBase64url, encodeJoseBlob} from '@veramo/utils' +import * as u8a from 'uint8arrays' +import { + CreateJwsCompactArgs, + CreateJwsFlattenedArgs, + CreateJwsJsonArgs, + CreateJwsMode, + IRequiredContext, + JwsCompact, + JwsJsonFlattened, + JwsJsonGeneral, + JwsJsonSignature, + JwtHeader, + PreparedJwsObject, +} from '../types/IJwtService' + +export const prepareJwsObject = async (args: CreateJwsJsonArgs, context: IRequiredContext): Promise => { + const { + existingSignatures, + protectedHeader, + unprotectedHeader, + issuer, + payload, + mode = 'auto' + } = args + + const {noIdentifierInHeader = false} = issuer + const combinedHeader = {...unprotectedHeader, ...protectedHeader} + if (!combinedHeader.alg) { + return Promise.reject(`No 'alg' key present in the JWS header`) + } + const identifier = await context.agent.identifierManagedGet(issuer) + await checkAndUpdateJwtHeader({mode, identifier, noIdentifierInHeader, header: protectedHeader}, context) + + const isBytes = payload instanceof Uint8Array + const isString = typeof payload === 'string' + if (!isBytes && !isString) { + if (issuer.noIssPayloadUpdate !== true && !payload.iss && identifier.issuer) { + payload.iss = identifier.issuer + } + } + const payloadBytes = isBytes ? payload : (isString ? u8a.fromString(payload, 'base64url') : u8a.fromString(JSON.stringify(payload), 'utf-8')) + const base64urlHeader = encodeJoseBlob(protectedHeader) + const base64urlPayload = bytesToBase64url(payloadBytes) + + return { + jws: { + unprotectedHeader, + protectedHeader, + payload: payloadBytes, + existingSignatures, + }, + b64: { + protectedHeader: base64urlHeader, + payload: base64urlPayload, + }, + issuer, + identifier, + } +} + +export const createJwsCompact = async (args: CreateJwsCompactArgs, context: IRequiredContext): Promise => { + const {protected: protectedHeader, payload, signature} = await createJwsJsonFlattened(args, context) + return `${protectedHeader}.${payload}.${signature}` +} + +export const createJwsJsonFlattened = async (args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise => { + const jws = await createJwsJsonGeneral(args, context) + if (jws.signatures.length !== 1) { + return Promise.reject(Error(`JWS flattened signature can only contain 1 signature. Found ${jws.signatures.length}`)) + } + return { + ...jws.signatures[0], + payload: jws.payload, + } satisfies JwsJsonFlattened +} + +export const createJwsJsonGeneral = async (args: CreateJwsJsonArgs, context: IRequiredContext): Promise => { + const {payload, protectedHeader, unprotectedHeader, existingSignatures, issuer, mode} = args + const {b64, identifier} = await prepareJwsObject( + { + protectedHeader, + unprotectedHeader, + payload, + existingSignatures, + issuer, + mode, + }, + context + ) + // const algorithm = await signatureAlgorithmFromKey({ key: identifier.key }) + const signature = await context.agent.keyManagerSign({ + keyRef: identifier.kmsKeyRef, + data: `${b64.protectedHeader}.${b64.payload}`, + encoding: undefined + }) + const jsonSignature = { + protected: b64.protectedHeader, + header: unprotectedHeader, + signature, + } satisfies JwsJsonSignature + return { + payload: b64.payload, + signatures: [...(existingSignatures ?? []), jsonSignature], + } satisfies JwsJsonGeneral +} + +/** + * Updates the JWT header to include x5c, kid, jwk objects using the supplied issuer identifier that will be used to sign. If not present will automatically make the header objects available + * @param mode The type of header to check or include + * @param identifier The identifier of the signer. This identifier will be used later to sign + * @param header The JWT header + * @param noIdentifierInHeader + * @param context + */ + +export const checkAndUpdateJwtHeader = async ( + { + mode = 'auto', + identifier, + header, + noIdentifierInHeader = false + }: { + mode?: CreateJwsMode + identifier: ManagedIdentifierResult + noIdentifierInHeader?: boolean + header: JwtHeader + }, + context: IRequiredContext +) => { + if (isMode(mode, identifier.method, 'did')) { + // kid is VM of the DID + // @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4 + await checkAndUpdateDidHeader({header, identifier, noIdentifierInHeader}, context) + } else if (isMode(mode, identifier.method, 'x5c')) { + // Include the x5c in the header. No kid + // @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.6 + await checkAndUpdateX5cHeader({header, identifier, noIdentifierInHeader}, context) + } else if (isMode(mode, identifier.method, 'kid', false)) { + await checkAndUpdateKidHeader({header, identifier, noIdentifierInHeader}, context) + } else if (isMode(mode, identifier.method, 'jwk', false)) { + // Include the JWK in the header as well as its kid if present + // @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.3 + // @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4 + await checkAndUpdateJwkHeader({header, identifier, noIdentifierInHeader}, context) + } else { + // Better safe than sorry. We could let it pass, but we want to force implementers to make a conscious choice + return Promise.reject(`Invalid combination of JWS creation mode ${mode} and identifier method ${identifier.method} chosen`) + } +} + +const checkAndUpdateX5cHeader = async ( + { + header, + identifier, + noIdentifierInHeader = false + }: { + header: JwtHeader + identifier: ManagedIdentifierResult + noIdentifierInHeader?: boolean + }, + context: IRequiredContext +) => { + const {x5c} = header + if (x5c) { + // let's resolve the provided x5c to be sure + const x5cIdentifier = await context.agent.identifierManagedGetByX5c({identifier: x5c}) + if (x5cIdentifier.kmsKeyRef !== identifier.kmsKeyRef) { + return Promise.reject(Error(`An x5c header was present, but its issuer public key did not match the provided signing public key!`)) + } + } else if (!noIdentifierInHeader) { + if (!isManagedIdentifierX5cResult(identifier)) { + return Promise.reject(Error('No x5c header in the JWT, but mode was x5c and also no x5x identifier was provided!')) + } else if (header.jwk || header.kid) { + return Promise.reject(Error('x5c mode was choosen, but jwk or kid headers were provided. These cannot be used together!')) + } + header.x5c = identifier.x5c + } +} + +const checkAndUpdateDidHeader = async ( + { + header, + identifier, + noIdentifierInHeader = false + }: { + header: JwtHeader + identifier: ManagedIdentifierResult + noIdentifierInHeader?: boolean + }, + context: IRequiredContext +) => { + const {kid} = header + if (kid) { + // let's resolve the provided x5c to be sure + const vmIdentifier = await context.agent.identifierManagedGetByDid({identifier: kid}) + if (vmIdentifier.kmsKeyRef !== identifier.kmsKeyRef) { + return Promise.reject(Error(`A kid header was present, but its value did not match the provided signing kid!`)) + } + } else if (!noIdentifierInHeader) { + if (!isManagedIdentifierDidResult(identifier)) { + return Promise.reject(Error('No kid header in the JWT, but mode was did and also no DID identifier was provided!')) + } else if (header.jwk || header.x5c) { + return Promise.reject(Error('did mode was chosen, but jwk or x5c headers were provided. These cannot be used together!')) + } + header.kid = identifier.kid + } +} + +const checkAndUpdateJwkHeader = async ( + { + header, + identifier, + noIdentifierInHeader = false + }: { + header: JwtHeader + identifier: ManagedIdentifierResult + noIdentifierInHeader?: boolean + }, + context: IRequiredContext +) => { + const {jwk} = header + if (jwk) { + // let's resolve the provided x5c to be sure + const jwkIdentifier = await context.agent.identifierManagedGetByJwk({identifier: jwk}) + if (jwkIdentifier.kmsKeyRef !== identifier.kmsKeyRef) { + return Promise.reject(Error(`A jwk header was present, but its value did not match the provided signing jwk or kid!`)) + } + } else if (!noIdentifierInHeader) { + // We basically accept everything for this mode, as we can always create JWKs from any key + if (header.x5c) { + return Promise.reject(Error('jwk mode was chosen, but x5c headers were provided. These cannot be used together!')) + } + header.jwk = identifier.jwk + } +} + +const checkAndUpdateKidHeader = async ( + { + header, + identifier, + noIdentifierInHeader = false + }: { + header: JwtHeader + identifier: ManagedIdentifierResult + noIdentifierInHeader?: boolean + }, + context: IRequiredContext +) => { + const {kid} = header + if (kid) { + // let's resolve the provided x5c to be sure + const kidIdentifier = await context.agent.identifierManagedGetByKid({identifier: kid}) + if (kidIdentifier.kmsKeyRef !== identifier.kmsKeyRef) { + return Promise.reject(Error(`A kid header was present, but its value did not match the provided signing kid!`)) + } + } else if (!noIdentifierInHeader) { + // We basically accept everything for this mode, as we can always create JWKs from any key + if (header.x5c) { + return Promise.reject(Error('kid mode was chosen, but x5c headers were provided. These cannot be used together!')) + } + header.kid = identifier.kid + } +} + +const isMode = (mode: CreateJwsMode, identifierMethod: ManagedIdentifierMethod, checkMode: CreateJwsMode, loose = true) => { + if (loose && (checkMode === 'jwk' || checkMode === 'kid')) { + // we always have the kid and jwk at hand no matter the identifier method, so we are okay with that + // todo: check the impact on the above expressions, as this will now always return true for the both of them + return true + } + if (mode === checkMode) { + if (checkMode !== 'auto' && mode !== identifierMethod) { + throw Error(`Provided mode ${mode} conflicts with identifier method ${identifierMethod}`) + } + return true + } + // we always have the kid and jwk at hand no matter the identifier method, so we are okay with that + return mode === 'auto' && identifierMethod === checkMode +} diff --git a/packages/jwt-service/src/index.ts b/packages/jwt-service/src/index.ts new file mode 100644 index 00000000..63140ba8 --- /dev/null +++ b/packages/jwt-service/src/index.ts @@ -0,0 +1,11 @@ +/** + * @internal + */ +const schema = require('../plugin.schema.json') +export { schema } +/** + * @public + */ +export { JwtService } from './agent/JwtService' +export * from './functions' +export * from './types/IJwtService' diff --git a/packages/jwt-service/src/types/IJwtService.ts b/packages/jwt-service/src/types/IJwtService.ts new file mode 100644 index 00000000..4c9e257f --- /dev/null +++ b/packages/jwt-service/src/types/IJwtService.ts @@ -0,0 +1,118 @@ +import { + IIdentifierResolution, + ManagedIdentifierOpts, + ManagedIdentifierResult +} from '@sphereon/ssi-sdk-ext.identifier-resolution' +import {ISphereonKeyManager} from '@sphereon/ssi-sdk-ext.key-manager' +import {JWK, SignatureAlgorithmJwa} from '@sphereon/ssi-sdk-ext.key-utils' +import {IAgentContext, IPluginMethodMap} from '@veramo/core' + +export type IRequiredContext = IAgentContext // could we still interop with Veramo? +export interface IJwtService extends IPluginMethodMap { + jwtPrepareJws(args: CreateJwsJsonArgs, context: IRequiredContext): Promise + + jwtCreateJwsJsonGeneralSignature(args: CreateJwsJsonArgs, context: IRequiredContext): Promise + + jwtCreateJwsJsonFlattenedSignature(args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise + + jwtCreateJwsCompactSignature(args: CreateJwsCompactArgs, context: IRequiredContext): Promise + + // jwtVerifyJwsCompactSignature(args: {jwt: string}): Promise + + // TODO: JWE/encryption +} + +export interface PreparedJws { + protectedHeader: JwtHeader + payload: Uint8Array + unprotectedHeader?: JwtHeader // only for jws json and also then optional + existingSignatures?: Array // only for jws json and also then optional +} + +export interface JwsJsonSignature { + protected: string + header?: JwtHeader + signature: string +} + +export type JwsCompact = string + +export interface JwsJsonFlattened { + payload: string + protected: string + header?: JwtHeader + signature: string +} + +export interface JwsJsonGeneral { + payload: string + signatures: Array +} + +export interface PreparedJwsObject { + jws: PreparedJws + b64: { payload: string; protectedHeader: string } // header is always json, as it can only be used in JwsJson + issuer: ManagedIdentifierOpts + identifier: ManagedIdentifierResult +} + +export interface BaseJwtHeader { + typ?: string; + alg?: string; + kid?: string; +} +export interface BaseJwtPayload { + iss?: string; + sub?: string; + aud?: string[] | string; + exp?: number; + nbf?: number; + iat?: number; + jti?: string; +} + +export interface JwtHeader extends BaseJwtHeader { + kid?: string + jwk?: JWK + x5c?: string[] + + [key: string]: unknown +} + +export interface JwtPayload extends BaseJwtPayload { + [key: string]: unknown +} + +export interface JwsHeaderOpts { + als: SignatureAlgorithmJwa +} + +export type CreateJwsMode = 'x5c' | 'kid' | 'jwk' | 'did' | 'auto' + +export type CreateJwsArgs = { + mode?: CreateJwsMode + issuer: ManagedIdentifierOpts & { noIssPayloadUpdate?: boolean, noIdentifierInHeader?: boolean } + protectedHeader: JwtHeader + payload: JwtPayload | Uint8Array | string +} + +export type CreateJwsCompactArgs = CreateJwsArgs + +export type CreateJwsFlattenedArgs = Exclude + +/** + * @public + */ +export type CreateJwsJsonArgs = CreateJwsArgs & { + unprotectedHeader?: JwtHeader // only for jws json + existingSignatures?: Array // Only for jws json +} + +/** + * @public + */ +export interface JwsCompactResult { + jwt: JwsCompact; +} + +// export const COMPACT_JWS_REGEX = /^([a-zA-Z0-9_=-]+)\.([a-zA-Z0-9_=-]+)?\.([a-zA-Z0-9_=-]+)$/ diff --git a/packages/jwt-service/tsconfig.json b/packages/jwt-service/tsconfig.json new file mode 100644 index 00000000..628ae45e --- /dev/null +++ b/packages/jwt-service/tsconfig.json @@ -0,0 +1,28 @@ +{ + "extends": "../tsconfig-base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "declarationDir": "dist" + }, + "references": [ + { + "path": "../x509-utils" + }, + { + "path": "../did-utils" + }, + { + "path": "../key-utils" + }, + { + "path": "../kms-local" + }, + { + "path": "../key-manager" + }, + { + "path": "../identifier-resolution" + } + ] +} diff --git a/packages/key-utils/src/functions.ts b/packages/key-utils/src/functions.ts index dda79d82..6ee1f4f5 100644 --- a/packages/key-utils/src/functions.ts +++ b/packages/key-utils/src/functions.ts @@ -19,6 +19,7 @@ import { SIG_KEY_ALGS, SignatureAlgorithmFromKeyArgs, SignatureAlgorithmFromKeyTypeArgs, + SignatureAlgorithmJwa, TKeyType, } from './types' @@ -495,21 +496,21 @@ export const toRawCompressedHexPublicKey = (rawPublicKey: Uint8Array, keyType: T export const hexStringFromUint8Array = (value: Uint8Array): string => u8a.toString(value, 'base16') -export const signatureAlgorithmFromKey = async (args: SignatureAlgorithmFromKeyArgs): Promise => { +export const signatureAlgorithmFromKey = async (args: SignatureAlgorithmFromKeyArgs): Promise => { const { key } = args return signatureAlgorithmFromKeyType({ type: key.type }) } -export const signatureAlgorithmFromKeyType = (args: SignatureAlgorithmFromKeyTypeArgs): SignatureAlgorithmEnum => { +export const signatureAlgorithmFromKeyType = (args: SignatureAlgorithmFromKeyTypeArgs): SignatureAlgorithmJwa => { const { type } = args switch (type) { case 'Ed25519': case 'X25519': - return SignatureAlgorithmEnum.EdDSA + return SignatureAlgorithmJwa.EdDSA case 'Secp256r1': - return SignatureAlgorithmEnum.ES256 + return SignatureAlgorithmJwa.ES256 case 'Secp256k1': - return SignatureAlgorithmEnum.ES256K + return SignatureAlgorithmJwa.ES256K default: throw new Error(`Key type '${type}' not supported`) } @@ -534,9 +535,3 @@ export const keyTypeFromCryptographicSuite = (args: KeyTypeFromCryptographicSuit throw new Error(`Cryptographic suite '${suite}' not supported`) } } - -export enum SignatureAlgorithmEnum { - EdDSA = 'EdDSA', - ES256 = 'ES256', - ES256K = 'ES256K', -} diff --git a/packages/key-utils/src/jwk-jcs.ts b/packages/key-utils/src/jwk-jcs.ts index 6de4b6fe..be91b3c5 100644 --- a/packages/key-utils/src/jwk-jcs.ts +++ b/packages/key-utils/src/jwk-jcs.ts @@ -73,7 +73,7 @@ function validateJwk(jwk: any) { * @param jwk - The JWK to canonicalize. * @returns The JWK with only the required members, ordered lexicographically. */ -function minimalJwk(jwk: any) { +export function minimalJwk(jwk: any) { // "default" case is not needed // eslint-disable-next-line default-case switch (jwk.kty) { diff --git a/packages/key-utils/src/types/key-util-types.ts b/packages/key-utils/src/types/key-util-types.ts index 14124be1..77409a05 100644 --- a/packages/key-utils/src/types/key-util-types.ts +++ b/packages/key-utils/src/types/key-util-types.ts @@ -32,19 +32,30 @@ export enum KeyType { export const SIG_KEY_ALGS = ['ES256', 'ES384', 'ES512', 'EdDSA', 'ES256K', 'Ed25519', 'Secp256k1', 'Secp256r1', 'Bls12381G1', 'Bls12381G2'] export const ENC_KEY_ALGS = ['X25519', 'ECDH_ES_A256KW', 'RSA_OAEP_256'] -export interface JWK { - kty: string - alg?: string - crv?: string +export enum SignatureAlgorithmJwa { + // todo: Compare to spec and to kmp lib + + EdDSA = 'EdDSA', + ES256 = 'ES256', + ES384 = 'ES384', + ES512 = 'ES512', + ES256K = 'ES256K', + RS256 = 'RS256', + RS384 = 'RS384', + RS512 = 'RS512', + PS256 = 'PS256', + PS384 = 'PS384', + PS512 = 'PS512', +} + +export interface JWK extends BaseJWK { d?: string dp?: string dq?: string - e?: string ext?: boolean k?: string key_ops?: string[] kid?: string - n?: string oth?: Array<{ d?: string r?: string @@ -54,8 +65,6 @@ export interface JWK { q?: string qi?: string use?: string - x?: string - y?: string /** JWK "x5c" (X.509 Certificate Chain) Parameter. */ x5c?: string[] /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */ @@ -67,6 +76,15 @@ export interface JWK { [propName: string]: unknown } +export interface BaseJWK { + kty: string + crv?: string + x?: string + y?: string + e?: string + n?: string +} + export type KeyVisibility = 'public' | 'private' export interface X509Opts { diff --git a/packages/tsconfig.json b/packages/tsconfig.json index cb38cf11..d9a42998 100644 --- a/packages/tsconfig.json +++ b/packages/tsconfig.json @@ -45,6 +45,9 @@ }, { "path": "identifier-resolution" + }, + { + "path": "jwt-service" } ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 840de75b..95960338 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -219,7 +219,7 @@ importers: version: link:../key-utils '@transmute/did-key-bls12381': specifier: 0.3.0-unstable.10 - version: 0.3.0-unstable.10 + version: 0.3.0-unstable.10(expo@51.0.26)(react-native@0.74.5) '@veramo/core': specifier: 4.2.0 version: 4.2.0(patch_hash=c5oempznsz4br5w3tcuk2i2mau) @@ -534,6 +534,88 @@ importers: specifier: 0.3.20 version: 0.3.20(pg@8.12.0)(sqlite3@5.1.7)(ts-node@10.9.2) + packages/jwt-service: + dependencies: + '@sphereon/ssi-sdk-ext.did-utils': + specifier: workspace:* + version: link:../did-utils + '@sphereon/ssi-sdk-ext.identifier-resolution': + specifier: workspace:* + version: link:../identifier-resolution + '@sphereon/ssi-sdk-ext.key-manager': + specifier: workspace:* + version: link:../key-manager + '@sphereon/ssi-sdk-ext.key-utils': + specifier: workspace:* + version: link:../key-utils + '@sphereon/ssi-sdk-ext.x509-utils': + specifier: workspace:* + version: link:../x509-utils + '@sphereon/ssi-sdk.agent-config': + specifier: 0.29.1-unstable.75 + version: 0.29.1-unstable.75(ts-node@10.9.2) + '@sphereon/ssi-types': + specifier: 0.29.1-unstable.75 + version: 0.29.1-unstable.75 + '@veramo/core': + specifier: 4.2.0 + version: 4.2.0(patch_hash=c5oempznsz4br5w3tcuk2i2mau) + '@veramo/utils': + specifier: 4.2.0 + version: 4.2.0 + debug: + specifier: ^4.3.4 + version: 4.3.6 + jwt-decode: + specifier: ^4.0.0 + version: 4.0.0 + uint8arrays: + specifier: ^3.1.1 + version: 3.1.1 + devDependencies: + '@sphereon/ssi-sdk-ext.did-provider-jwk': + specifier: workspace:* + version: link:../did-provider-jwk + '@sphereon/ssi-sdk-ext.did-resolver-jwk': + specifier: workspace:* + version: link:../did-resolver-jwk + '@sphereon/ssi-sdk-ext.kms-local': + specifier: workspace:* + version: link:../kms-local + '@sphereon/ssi-sdk.dev': + specifier: 0.29.1-unstable.75 + version: 0.29.1-unstable.75(@types/node@18.19.44) + '@veramo/data-store': + specifier: 4.2.0 + version: 4.2.0(pg@8.12.0)(sqlite3@5.1.7)(ts-node@10.9.2) + '@veramo/did-manager': + specifier: 4.2.0 + version: 4.2.0 + '@veramo/did-resolver': + specifier: 4.2.0 + version: 4.2.0 + '@veramo/key-manager': + specifier: 4.2.0 + version: 4.2.0 + '@veramo/kms-local': + specifier: 4.2.0 + version: 4.2.0 + '@veramo/remote-client': + specifier: 4.2.0 + version: 4.2.0 + '@veramo/remote-server': + specifier: 4.2.0 + version: 4.2.0(express@4.19.2) + did-resolver: + specifier: ^4.1.0 + version: 4.1.0 + js-crypto-key-utils: + specifier: ^1.0.7 + version: 1.0.7 + typeorm: + specifier: 0.3.20 + version: 0.3.20(pg@8.12.0)(sqlite3@5.1.7)(ts-node@10.9.2) + packages/key-manager: dependencies: '@veramo/core': @@ -5273,7 +5355,7 @@ packages: /@transmute/did-context@0.6.1-unstable.37: resolution: {integrity: sha512-p/QnG3QKS4218hjIDgdvJOFATCXsAnZKgy4egqRrJLlo3Y6OaDBg7cA73dixOwUPoEKob0K6rLIGcsCI/L1acw==} - /@transmute/did-key-bls12381@0.3.0-unstable.10: + /@transmute/did-key-bls12381@0.3.0-unstable.10(expo@51.0.26)(react-native@0.74.5): resolution: {integrity: sha512-ExSADdvDxrYeCx8RsKXZGMjJmHrOJ9vyYtziZUaJ97K/sn1uVlvIOTp9V4xHa6j9cT1wTzSqJ325euwGFeK+WQ==} engines: {node: '>=14'} dependencies: @@ -7449,7 +7531,6 @@ packages: /charenc@0.0.2: resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==} - optional: true /chokidar@3.6.0: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} @@ -8144,7 +8225,6 @@ packages: /crypt@0.0.2: resolution: {integrity: sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==} - optional: true /crypto-ld@6.0.0: resolution: {integrity: sha512-XWL1LslqggNoaCI/m3I7HcvaSt9b2tYzdrXO+jHLUj9G1BvRfvV7ZTFDVY5nifYuIGAPdAGu7unPxLRustw3VA==} @@ -8367,6 +8447,13 @@ packages: resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==} dev: true + /des.js@1.1.0: + resolution: {integrity: sha512-r17GxjhUCjSRy8aiJpr8/UadFIzMzJGexI3Nmz4ADi9LYSFx4gTBp80+NaX/YsXWWLhpZ7v/v/ubEc/bCNfKwg==} + dependencies: + inherits: 2.0.4 + minimalistic-assert: 1.0.1 + dev: true + /destroy@1.2.0: resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==} engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} @@ -10676,7 +10763,6 @@ packages: /is-buffer@1.1.6: resolution: {integrity: sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==} - optional: true /is-callable@1.2.7: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} @@ -11493,6 +11579,66 @@ packages: resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==} dev: false + /js-crypto-aes@1.0.6: + resolution: {integrity: sha512-E2hu9z5+YtpDg9Un/bDfmH+I5dv/8aN+ozxv9L0ybZldcQ9T5iYDbBKdlKGBUKI3IvzoWSBSdnZnhwZaRIN46w==} + dependencies: + js-crypto-env: 1.0.5 + dev: true + + /js-crypto-env@1.0.5: + resolution: {integrity: sha512-8/UNN3sG8J+yMzqwSNVaobaWhIz4MqZFoOg5OB0DFXqS8eFjj2YvdmLJqIWXPl57Yw10SvYx0DQOtkfsWIV9Aw==} + dev: true + + /js-crypto-hash@1.0.7: + resolution: {integrity: sha512-GdbcVKjplbXJdR9oF2ks8+sBCLD7BUZ144Bc+Ie8OJuBHSIiHyMzdg2eD+ZYf87awTsKckNn1xIv+31+V2ewcA==} + dependencies: + buffer: 6.0.3 + hash.js: 1.1.7 + js-crypto-env: 1.0.5 + md5: 2.3.0 + sha3: 2.1.4 + dev: true + + /js-crypto-hmac@1.0.7: + resolution: {integrity: sha512-OVn2wjAuOV7ToQYvRKY2VoElCHoRW7BepycPPuH73xbLygDczkef41YsXMpKLnVAyS5kdwMJQy9qlMR9touHTg==} + dependencies: + js-crypto-env: 1.0.5 + js-crypto-hash: 1.0.7 + dev: true + + /js-crypto-key-utils@1.0.7: + resolution: {integrity: sha512-8/y/hpKevnAgr5EXz2x4IXMfqjzYZAzzXXc9OnAyI5JNdUtAufJkGfwlmZ+o40lTHv3k1egCiP/6pG/dZiqiEA==} + dependencies: + asn1.js: 5.4.1 + buffer: 6.0.3 + des.js: 1.1.0 + elliptic: 6.5.6 + js-crypto-aes: 1.0.6 + js-crypto-hash: 1.0.7 + js-crypto-pbkdf: 1.0.7 + js-crypto-random: 1.0.5 + js-encoding-utils: 0.7.3 + lodash.clonedeep: 4.5.0 + dev: true + + /js-crypto-pbkdf@1.0.7: + resolution: {integrity: sha512-FGs1PZeqGWM8k8k5JlAhHbBhLYtls+iVmeJEC22DUJ98Q3qo9Ki4cu3i0oxhjA2VpZ8V4MmV1DJHDTFYY4iOwg==} + dependencies: + js-crypto-hash: 1.0.7 + js-crypto-hmac: 1.0.7 + js-encoding-utils: 0.7.3 + dev: true + + /js-crypto-random@1.0.5: + resolution: {integrity: sha512-WydEQ5rrWLzgSkX1QNsuGinkv7z57UkYnDGo5f5oGtBe9QeUWUehdmPNNG4a4Sf8xGkjZBOhKaZqT1ACnyYCBA==} + dependencies: + js-crypto-env: 1.0.5 + dev: true + + /js-encoding-utils@0.7.3: + resolution: {integrity: sha512-cfjcyPOzkZ2esMAi6eAjuto7GiT6YpPan5xIeQyN/CFqFHTt1sdqP0PJPgzi3HqAqXKN9j9hduynkgwk+AAJOw==} + dev: true + /js-sha3@0.8.0: resolution: {integrity: sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==} @@ -11698,6 +11844,11 @@ packages: resolution: {integrity: sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==} dev: false + /jwt-decode@4.0.0: + resolution: {integrity: sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==} + engines: {node: '>=18'} + dev: false + /keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} dependencies: @@ -12044,6 +12195,10 @@ packages: resolution: {integrity: sha512-kZzYOKspf8XVX5AvmQF94gQW0lejFVgb80G85bU4ZWzoJ6C03PQg3coYAUpSTpQWelrZELd3XWgHzw4Ck5kaIw==} dev: true + /lodash.clonedeep@4.5.0: + resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} + dev: true + /lodash.debounce@4.0.8: resolution: {integrity: sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==} @@ -12302,7 +12457,6 @@ packages: charenc: 0.0.2 crypt: 0.0.2 is-buffer: 1.1.6 - optional: true /md5hex@1.0.0: resolution: {integrity: sha512-c2YOUbp33+6thdCUi34xIyOU/a7bvGKj/3DB1iaPMTuPHf/Q2d5s4sn1FaCOO43XkXggnb08y5W2PU8UNYNLKQ==} @@ -15301,6 +15455,12 @@ packages: inherits: 2.0.4 safe-buffer: 5.2.1 + /sha3@2.1.4: + resolution: {integrity: sha512-S8cNxbyb0UGUM2VhRD4Poe5N58gJnJsLJ5vC7FYWGUmGhcsj4++WaIOBFVDxlG0W3To6xBuiRh+i0Qp2oNCOtg==} + dependencies: + buffer: 6.0.3 + dev: true + /shallow-clone@3.0.1: resolution: {integrity: sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==} engines: {node: '>=8'}