@twin.org/identity-service 0.0.3-next.16 → 0.0.3-next.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -182,7 +182,7 @@ export class IdentityService {
182
182
  async verifiableCredentialCreate(verificationMethodId, id, subject, options, controller) {
183
183
  Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
184
184
  Urn.guard(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
185
- Guards.objectValue(IdentityService.CLASS_NAME, "subject", subject);
185
+ Guards.object(IdentityService.CLASS_NAME, "subject", subject);
186
186
  try {
187
187
  const idParts = DocumentHelper.parseId(verificationMethodId);
188
188
  const identityConnector = this.getConnectorByUri(idParts.id);
@@ -1 +1 @@
1
- {"version":3,"file":"identityService.js","sourceRoot":"","sources":["../../src/identityService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EACN,cAAc,EACd,wBAAwB,EAGxB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACN,yBAAyB,EACzB,UAAU,EAOV,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC;IAEtE;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;OAGG;IACH,YAAY,OAA4C;QACvD,MAAM,KAAK,GAAG,wBAAwB,CAAC,KAAK,EAAE,CAAC;QAC/C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QACpE,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,MAAM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QAE5F,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACvE,SAAS,EAAE,eAAe;aAC1B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,EAAU;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,mBAAmB,EAAE,KAAK,KAAK,EAAE,CAAC;YAC3C,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACvE,SAAS,EAAE,KAAK;gBAChB,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IAC9D,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdContextDefinitionRoot, IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport {\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityComponent,\n\ttype IIdentityConnector\n} from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tDidVerificationMethodType,\n\tProofTypes,\n\ttype IDidDocument,\n\ttype IDidDocumentVerificationMethod,\n\ttype IProof,\n\ttype IDidService,\n\ttype IDidVerifiableCredential,\n\ttype IDidVerifiablePresentation\n} from \"@twin.org/standards-w3c-did\";\nimport { Jwt } from \"@twin.org/web\";\nimport type { IIdentityServiceConstructorOptions } from \"./models/IIdentityServiceConstructorOptions.js\";\n\n/**\n * Class which implements the identity contract.\n */\nexport class IdentityService implements IIdentityComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityService>();\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of IdentityService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IIdentityServiceConstructorOptions) {\n\t\tconst names = IdentityConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn IdentityService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new identity.\n\t * @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created identity document.\n\t */\n\tpublic async identityCreate(namespace?: string, controller?: string): Promise<IDidDocument> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByNamespace(namespace);\n\t\t\tconst result = await identityConnector.createDocument(controller);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"identityCreateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an identity.\n\t * @param identity The id of the document to remove.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async identityRemove(identity: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\t\t\tconst result = await identityConnector.removeDocument(controller, identity);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"identityRemoveFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a verification method to the document in JSON Web key Format.\n\t * @param identity The id of the document to add the verification method to.\n\t * @param verificationMethodType The type of the verification method to add.\n\t * @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The verification method.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple keys.\n\t */\n\tpublic async verificationMethodCreate(\n\t\tidentity: string,\n\t\tverificationMethodType: DidVerificationMethodType,\n\t\tverificationMethodId?: string,\n\t\tcontroller?: string\n\t): Promise<IDidDocumentVerificationMethod> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodType),\n\t\t\tverificationMethodType,\n\t\t\tObject.values(DidVerificationMethodType)\n\t\t);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tverificationMethodType,\n\t\t\t\tverificationMethodId\n\t\t\t);\n\n\t\t\treturn verificationMethod;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodCreateFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a verification method from the document.\n\t * @param verificationMethodId The id of the verification method.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple revocable keys.\n\t */\n\tpublic async verificationMethodRemove(\n\t\tverificationMethodId: string,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeVerificationMethod(controller, verificationMethodId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodRemoveFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a service to the document.\n\t * @param identity The id of the document to add the service to.\n\t * @param serviceId The id of the service.\n\t * @param serviceType The type of the service.\n\t * @param serviceEndpoint The endpoint for the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The service.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceCreate(\n\t\tidentity: string,\n\t\tserviceId: string,\n\t\tserviceType: string | string[],\n\t\tserviceEndpoint: string | string[],\n\t\tcontroller?: string\n\t): Promise<IDidService> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\t\tif (Is.array(serviceType)) {\n\t\t\tGuards.arrayValue<string>(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t}\n\t\tif (Is.array(serviceEndpoint)) {\n\t\t\tGuards.arrayValue<string>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(serviceEndpoint),\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceEndpoint), serviceEndpoint);\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst service = await identityConnector.addService(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tserviceId,\n\t\t\t\tserviceType,\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceCreateFailed\",\n\t\t\t\t{ identity, serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a service from the document.\n\t * @param serviceId The id of the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceRemove(serviceId: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(serviceId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeService(controller, serviceId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceRemoveFailed\",\n\t\t\t\t{ serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable credential for a verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param id The id of the credential.\n\t * @param subject The credential subject to store in the verifiable credential.\n\t * @param options Additional options for creating the verifiable credential.\n\t * @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.\n\t * @param options.expirationDate The date the verifiable credential is valid until.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable credential and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiableCredentialCreate(\n\t\tverificationMethodId: string,\n\t\tid: string | undefined,\n\t\tsubject: IJsonLdNodeObject,\n\t\toptions?: {\n\t\t\trevocationIndex?: number;\n\t\t\texpirationDate?: Date;\n\t\t},\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiableCredential: IDidVerifiableCredential;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\t\tGuards.objectValue(IdentityService.CLASS_NAME, nameof(subject), subject);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst service = await identityConnector.createVerifiableCredential(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tid,\n\t\t\t\tsubject,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable credential is valid.\n\t * @param credential The credential to verify.\n\t * @returns The credential stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiableCredentialVerify(credential: string | IDidVerifiableCredential): Promise<{\n\t\trevoked: boolean;\n\t\tverifiableCredential?: IDidVerifiableCredential;\n\t}> {\n\t\tif (Is.object(credential)) {\n\t\t\tGuards.objectValue<IDidVerifiableCredential>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(credential),\n\t\t\t\tcredential\n\t\t\t);\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credential.issuer), credential.issuer);\n\t\t\tGuards.objectValue<IDidVerifiableCredential>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(credential.proof),\n\t\t\t\tcredential.proof\n\t\t\t);\n\n\t\t\ttry {\n\t\t\t\tconst identityConnector = this.getConnectorByUri(credential.issuer);\n\n\t\t\t\tconst service = await identityConnector.checkVerifiableCredential(credential);\n\n\t\t\t\treturn service;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new GeneralError(\n\t\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\t\tundefined,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credential), credential);\n\n\t\tconst jwtDecoded = await Jwt.decode(credential);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiableCredential(credential);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Revoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async verifiableCredentialRevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.revokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialRevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Unrevoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index to un revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async verifiableCredentialUnrevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.unrevokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialUnrevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable presentation from the supplied verifiable credentials.\n\t * @param verificationMethodId The method to associate with the presentation.\n\t * @param presentationId The id of the presentation.\n\t * @param contexts The contexts for the data stored in the verifiable credential.\n\t * @param types The types for the data stored in the verifiable credential.\n\t * @param verifiableCredentials The credentials to use for creating the presentation in jwt format.\n\t * @param options Additional options for creating the verifiable presentation.\n\t * @param options.expirationDate The date the verifiable presentation is valid until.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable presentation and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiablePresentationCreate(\n\t\tverificationMethodId: string,\n\t\tpresentationId: string | undefined,\n\t\tcontexts: IJsonLdContextDefinitionRoot | undefined,\n\t\ttypes: string | string[] | undefined,\n\t\tverifiableCredentials: (string | IDidVerifiableCredential)[],\n\t\toptions?: { expirationDate?: Date },\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiablePresentation: IDidVerifiablePresentation;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createVerifiablePresentation(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tpresentationId,\n\t\t\t\tcontexts,\n\t\t\t\ttypes,\n\t\t\t\tverifiableCredentials,\n\t\t\t\toptions\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable presentation is valid.\n\t * @param presentationJwt The presentation to verify.\n\t * @returns The presentation stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiablePresentationVerify(presentationJwt: string): Promise<{\n\t\trevoked: boolean;\n\t\tverifiablePresentation?: IDidVerifiablePresentation;\n\t\tissuers?: IDidDocument[];\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(presentationJwt), presentationJwt);\n\n\t\tconst jwtDecoded = await Jwt.decode(presentationJwt);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiablePresentation(presentationJwt);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a proof for a document with the specified verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param proofType The type of proof to create.\n\t * @param unsecureDocument The unsecure document to create the proof for.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The proof.\n\t */\n\tpublic async proofCreate(\n\t\tverificationMethodId: string,\n\t\tproofType: ProofTypes,\n\t\tunsecureDocument: IJsonLdNodeObject,\n\t\tcontroller?: string\n\t): Promise<IProof> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\t\tGuards.arrayOneOf<ProofTypes>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(unsecureDocument),\n\t\t\tunsecureDocument\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createProof(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tproofType,\n\t\t\t\tunsecureDocument\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"proofCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify proof for a document with the specified verification method.\n\t * @param document The document to verify.\n\t * @param proof The proof to verify.\n\t * @returns True if the proof is verified.\n\t */\n\tpublic async proofVerify(document: IJsonLdNodeObject, proof: IProof): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(IdentityService.CLASS_NAME, nameof(document), document);\n\t\tGuards.object<IProof>(IdentityService.CLASS_NAME, nameof(proof), proof);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proof.verificationMethod),\n\t\t\tproof.verificationMethod\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(proof.verificationMethod);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.verifyProof(document, proof);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"proofVerifyFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the namespace.\n\t * @param namespace The namespace for the identity.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnectorByNamespace(namespace?: string): IIdentityConnector {\n\t\tconst namespaceMethod = namespace ?? this._defaultNamespace;\n\n\t\tconst connector = IdentityConnectorFactory.getIfExists<IIdentityConnector>(namespaceMethod);\n\n\t\tif (Is.empty(connector)) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"connectorNotFound\", {\n\t\t\t\tnamespace: namespaceMethod\n\t\t\t});\n\t\t}\n\n\t\treturn connector;\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the identity in urn format.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnectorByUri(id: string): IIdentityConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== \"did\") {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: \"did\",\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn this.getConnectorByNamespace(idUri.namespaceMethod());\n\t}\n}\n"]}
1
+ {"version":3,"file":"identityService.js","sourceRoot":"","sources":["../../src/identityService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,G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Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdContextDefinitionRoot, IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport {\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityComponent,\n\ttype IIdentityConnector\n} from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tDidVerificationMethodType,\n\tProofTypes,\n\ttype IDidDocument,\n\ttype IDidDocumentVerificationMethod,\n\ttype IProof,\n\ttype IDidService,\n\ttype IDidVerifiableCredential,\n\ttype IDidVerifiablePresentation\n} from \"@twin.org/standards-w3c-did\";\nimport { Jwt } from \"@twin.org/web\";\nimport type { IIdentityServiceConstructorOptions } from \"./models/IIdentityServiceConstructorOptions.js\";\n\n/**\n * Class which implements the identity contract.\n */\nexport class IdentityService implements IIdentityComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityService>();\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of IdentityService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IIdentityServiceConstructorOptions) {\n\t\tconst names = IdentityConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn IdentityService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new identity.\n\t * @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created identity document.\n\t */\n\tpublic async identityCreate(namespace?: string, controller?: string): Promise<IDidDocument> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByNamespace(namespace);\n\t\t\tconst result = await identityConnector.createDocument(controller);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"identityCreateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an identity.\n\t * @param identity The id of the document to remove.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async identityRemove(identity: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\t\t\tconst result = await identityConnector.removeDocument(controller, identity);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"identityRemoveFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a verification method to the document in JSON Web key Format.\n\t * @param identity The id of the document to add the verification method to.\n\t * @param verificationMethodType The type of the verification method to add.\n\t * @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The verification method.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple keys.\n\t */\n\tpublic async verificationMethodCreate(\n\t\tidentity: string,\n\t\tverificationMethodType: DidVerificationMethodType,\n\t\tverificationMethodId?: string,\n\t\tcontroller?: string\n\t): Promise<IDidDocumentVerificationMethod> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodType),\n\t\t\tverificationMethodType,\n\t\t\tObject.values(DidVerificationMethodType)\n\t\t);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tverificationMethodType,\n\t\t\t\tverificationMethodId\n\t\t\t);\n\n\t\t\treturn verificationMethod;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodCreateFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a verification method from the document.\n\t * @param verificationMethodId The id of the verification method.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple revocable keys.\n\t */\n\tpublic async verificationMethodRemove(\n\t\tverificationMethodId: string,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeVerificationMethod(controller, verificationMethodId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodRemoveFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a service to the document.\n\t * @param identity The id of the document to add the service to.\n\t * @param serviceId The id of the service.\n\t * @param serviceType The type of the service.\n\t * @param serviceEndpoint The endpoint for the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The service.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceCreate(\n\t\tidentity: string,\n\t\tserviceId: string,\n\t\tserviceType: string | string[],\n\t\tserviceEndpoint: string | string[],\n\t\tcontroller?: string\n\t): Promise<IDidService> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\t\tif (Is.array(serviceType)) {\n\t\t\tGuards.arrayValue<string>(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t}\n\t\tif (Is.array(serviceEndpoint)) {\n\t\t\tGuards.arrayValue<string>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(serviceEndpoint),\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceEndpoint), serviceEndpoint);\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst service = await identityConnector.addService(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tserviceId,\n\t\t\t\tserviceType,\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceCreateFailed\",\n\t\t\t\t{ identity, serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a service from the document.\n\t * @param serviceId The id of the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceRemove(serviceId: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(serviceId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeService(controller, serviceId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceRemoveFailed\",\n\t\t\t\t{ serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable credential for a verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param id The id of the credential.\n\t * @param subject The credential subject to store in the verifiable credential.\n\t * @param options Additional options for creating the verifiable credential.\n\t * @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.\n\t * @param options.expirationDate The date the verifiable credential is valid until.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable credential and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiableCredentialCreate(\n\t\tverificationMethodId: string,\n\t\tid: string | undefined,\n\t\tsubject: IJsonLdNodeObject,\n\t\toptions?: {\n\t\t\trevocationIndex?: number;\n\t\t\texpirationDate?: Date;\n\t\t},\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiableCredential: IDidVerifiableCredential;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\t\tGuards.object(IdentityService.CLASS_NAME, nameof(subject), subject);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst service = await identityConnector.createVerifiableCredential(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tid,\n\t\t\t\tsubject,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable credential is valid.\n\t * @param credential The credential to verify.\n\t * @returns The credential stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiableCredentialVerify(credential: string | IDidVerifiableCredential): Promise<{\n\t\trevoked: boolean;\n\t\tverifiableCredential?: IDidVerifiableCredential;\n\t}> {\n\t\tif (Is.object(credential)) {\n\t\t\tGuards.objectValue<IDidVerifiableCredential>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(credential),\n\t\t\t\tcredential\n\t\t\t);\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credential.issuer), credential.issuer);\n\t\t\tGuards.objectValue<IDidVerifiableCredential>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(credential.proof),\n\t\t\t\tcredential.proof\n\t\t\t);\n\n\t\t\ttry {\n\t\t\t\tconst identityConnector = this.getConnectorByUri(credential.issuer);\n\n\t\t\t\tconst service = await identityConnector.checkVerifiableCredential(credential);\n\n\t\t\t\treturn service;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new GeneralError(\n\t\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\t\tundefined,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credential), credential);\n\n\t\tconst jwtDecoded = await Jwt.decode(credential);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiableCredential(credential);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Revoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async verifiableCredentialRevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.revokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialRevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Unrevoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index to un revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async verifiableCredentialUnrevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.unrevokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialUnrevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable presentation from the supplied verifiable credentials.\n\t * @param verificationMethodId The method to associate with the presentation.\n\t * @param presentationId The id of the presentation.\n\t * @param contexts The contexts for the data stored in the verifiable credential.\n\t * @param types The types for the data stored in the verifiable credential.\n\t * @param verifiableCredentials The credentials to use for creating the presentation in jwt format.\n\t * @param options Additional options for creating the verifiable presentation.\n\t * @param options.expirationDate The date the verifiable presentation is valid until.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable presentation and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiablePresentationCreate(\n\t\tverificationMethodId: string,\n\t\tpresentationId: string | undefined,\n\t\tcontexts: IJsonLdContextDefinitionRoot | undefined,\n\t\ttypes: string | string[] | undefined,\n\t\tverifiableCredentials: (string | IDidVerifiableCredential)[],\n\t\toptions?: { expirationDate?: Date },\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiablePresentation: IDidVerifiablePresentation;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createVerifiablePresentation(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tpresentationId,\n\t\t\t\tcontexts,\n\t\t\t\ttypes,\n\t\t\t\tverifiableCredentials,\n\t\t\t\toptions\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable presentation is valid.\n\t * @param presentationJwt The presentation to verify.\n\t * @returns The presentation stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiablePresentationVerify(presentationJwt: string): Promise<{\n\t\trevoked: boolean;\n\t\tverifiablePresentation?: IDidVerifiablePresentation;\n\t\tissuers?: IDidDocument[];\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(presentationJwt), presentationJwt);\n\n\t\tconst jwtDecoded = await Jwt.decode(presentationJwt);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiablePresentation(presentationJwt);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a proof for a document with the specified verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param proofType The type of proof to create.\n\t * @param unsecureDocument The unsecure document to create the proof for.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The proof.\n\t */\n\tpublic async proofCreate(\n\t\tverificationMethodId: string,\n\t\tproofType: ProofTypes,\n\t\tunsecureDocument: IJsonLdNodeObject,\n\t\tcontroller?: string\n\t): Promise<IProof> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\t\tGuards.arrayOneOf<ProofTypes>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(unsecureDocument),\n\t\t\tunsecureDocument\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createProof(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tproofType,\n\t\t\t\tunsecureDocument\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"proofCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify proof for a document with the specified verification method.\n\t * @param document The document to verify.\n\t * @param proof The proof to verify.\n\t * @returns True if the proof is verified.\n\t */\n\tpublic async proofVerify(document: IJsonLdNodeObject, proof: IProof): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(IdentityService.CLASS_NAME, nameof(document), document);\n\t\tGuards.object<IProof>(IdentityService.CLASS_NAME, nameof(proof), proof);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proof.verificationMethod),\n\t\t\tproof.verificationMethod\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(proof.verificationMethod);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.verifyProof(document, proof);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"proofVerifyFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the namespace.\n\t * @param namespace The namespace for the identity.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnectorByNamespace(namespace?: string): IIdentityConnector {\n\t\tconst namespaceMethod = namespace ?? this._defaultNamespace;\n\n\t\tconst connector = IdentityConnectorFactory.getIfExists<IIdentityConnector>(namespaceMethod);\n\n\t\tif (Is.empty(connector)) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"connectorNotFound\", {\n\t\t\t\tnamespace: namespaceMethod\n\t\t\t});\n\t\t}\n\n\t\treturn connector;\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the identity in urn format.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnectorByUri(id: string): IIdentityConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== \"did\") {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: \"did\",\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn this.getConnectorByNamespace(idUri.namespaceMethod());\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @twin.org/identity-service - Changelog
2
2
 
3
+ ## [0.0.3-next.18](https://github.com/twinfoundation/identity/compare/identity-service-v0.0.3-next.17...identity-service-v0.0.3-next.18) (2026-02-27)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * allow empty subject data in vc ([5bbf14e](https://github.com/twinfoundation/identity/commit/5bbf14eefd3c99b6cdca1af0ca741954d1b02cd3))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/identity-models bumped from 0.0.3-next.17 to 0.0.3-next.18
16
+ * devDependencies
17
+ * @twin.org/identity-connector-entity-storage bumped from 0.0.3-next.17 to 0.0.3-next.18
18
+
19
+ ## [0.0.3-next.17](https://github.com/twinfoundation/identity/compare/identity-service-v0.0.3-next.16...identity-service-v0.0.3-next.17) (2026-02-24)
20
+
21
+
22
+ ### Miscellaneous Chores
23
+
24
+ * **identity-service:** Synchronize repo versions
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @twin.org/identity-models bumped from 0.0.3-next.16 to 0.0.3-next.17
32
+ * devDependencies
33
+ * @twin.org/identity-connector-entity-storage bumped from 0.0.3-next.16 to 0.0.3-next.17
34
+
3
35
  ## [0.0.3-next.16](https://github.com/twinfoundation/identity/compare/identity-service-v0.0.3-next.15...identity-service-v0.0.3-next.16) (2026-02-13)
4
36
 
5
37
 
@@ -2618,7 +2618,6 @@
2618
2618
  "schemas": {
2619
2619
  "ConflictResponse": {
2620
2620
  "type": "object",
2621
- "additionalProperties": false,
2622
2621
  "properties": {
2623
2622
  "conflicts": {
2624
2623
  "type": "array",
@@ -2691,7 +2690,6 @@
2691
2690
  "name",
2692
2691
  "message"
2693
2692
  ],
2694
- "additionalProperties": false,
2695
2693
  "description": "Model to describe serialized error."
2696
2694
  },
2697
2695
  "IdentityCreateRequest": {
@@ -2702,7 +2700,6 @@
2702
2700
  "description": "The optional namespace to create the identity in."
2703
2701
  }
2704
2702
  },
2705
- "additionalProperties": false,
2706
2703
  "description": "The data for the request."
2707
2704
  },
2708
2705
  "IdentityProfileCreateRequest": {
@@ -2715,7 +2712,6 @@
2715
2712
  "$ref": "https://schema.twindev.org/json-ld/JsonLdDocument"
2716
2713
  }
2717
2714
  },
2718
- "additionalProperties": false,
2719
2715
  "description": "The data for the request."
2720
2716
  },
2721
2717
  "IdentityProfileGetResponse": {
@@ -2735,7 +2731,6 @@
2735
2731
  "required": [
2736
2732
  "identity"
2737
2733
  ],
2738
- "additionalProperties": false,
2739
2734
  "description": "The response payload."
2740
2735
  },
2741
2736
  "IdentityProfileListResponse": {
@@ -2769,7 +2764,6 @@
2769
2764
  "required": [
2770
2765
  "items"
2771
2766
  ],
2772
- "additionalProperties": false,
2773
2767
  "description": "The response payload."
2774
2768
  },
2775
2769
  "IdentityProfileUpdateRequest": {
@@ -2782,7 +2776,6 @@
2782
2776
  "$ref": "https://schema.twindev.org/json-ld/JsonLdDocument"
2783
2777
  }
2784
2778
  },
2785
- "additionalProperties": false,
2786
2779
  "description": "The data for the request."
2787
2780
  },
2788
2781
  "IdentityProofCreateRequest": {
@@ -2799,7 +2792,6 @@
2799
2792
  "proofType",
2800
2793
  "document"
2801
2794
  ],
2802
- "additionalProperties": false,
2803
2795
  "description": "The data for the request."
2804
2796
  },
2805
2797
  "IdentityProofVerifyRequest": {
@@ -2816,7 +2808,6 @@
2816
2808
  "document",
2817
2809
  "proof"
2818
2810
  ],
2819
- "additionalProperties": false,
2820
2811
  "description": "The data for the request."
2821
2812
  },
2822
2813
  "IdentityProofVerifyResponse": {
@@ -2829,7 +2820,6 @@
2829
2820
  "required": [
2830
2821
  "verified"
2831
2822
  ],
2832
- "additionalProperties": false,
2833
2823
  "description": "The response payload."
2834
2824
  },
2835
2825
  "IdentityServiceCreateRequest": {
@@ -2873,7 +2863,6 @@
2873
2863
  "type",
2874
2864
  "endpoint"
2875
2865
  ],
2876
- "additionalProperties": false,
2877
2866
  "description": "The data for the request."
2878
2867
  },
2879
2868
  "IdentityVerifiableCredentialCreateRequest": {
@@ -2898,7 +2887,6 @@
2898
2887
  "required": [
2899
2888
  "subject"
2900
2889
  ],
2901
- "additionalProperties": false,
2902
2890
  "description": "The data for the request."
2903
2891
  },
2904
2892
  "IdentityVerifiableCredentialCreateResponse": {
@@ -2916,7 +2904,6 @@
2916
2904
  "verifiableCredential",
2917
2905
  "jwt"
2918
2906
  ],
2919
- "additionalProperties": false,
2920
2907
  "description": "The response payload."
2921
2908
  },
2922
2909
  "IdentityVerifiableCredentialVerifyResponse": {
@@ -2933,7 +2920,6 @@
2933
2920
  "required": [
2934
2921
  "revoked"
2935
2922
  ],
2936
- "additionalProperties": false,
2937
2923
  "description": "The response payload."
2938
2924
  },
2939
2925
  "IdentityVerifiablePresentationCreateRequest": {
@@ -2982,7 +2968,6 @@
2982
2968
  "required": [
2983
2969
  "verifiableCredentials"
2984
2970
  ],
2985
- "additionalProperties": false,
2986
2971
  "description": "The data for the request."
2987
2972
  },
2988
2973
  "IdentityVerifiablePresentationCreateResponse": {
@@ -3000,7 +2985,6 @@
3000
2985
  "verifiablePresentation",
3001
2986
  "jwt"
3002
2987
  ],
3003
- "additionalProperties": false,
3004
2988
  "description": "The response payload."
3005
2989
  },
3006
2990
  "IdentityVerifiablePresentationVerifyResponse": {
@@ -3024,7 +3008,6 @@
3024
3008
  "required": [
3025
3009
  "revoked"
3026
3010
  ],
3027
- "additionalProperties": false,
3028
3011
  "description": "The response payload."
3029
3012
  },
3030
3013
  "IdentityVerificationMethodCreateRequest": {
@@ -3041,7 +3024,6 @@
3041
3024
  "required": [
3042
3025
  "verificationMethodType"
3043
3026
  ],
3044
- "additionalProperties": false,
3045
3027
  "description": "The data for the request."
3046
3028
  },
3047
3029
  "JsonLdDocument": {
@@ -3293,12 +3275,10 @@
3293
3275
  }
3294
3276
  ]
3295
3277
  }
3296
- },
3297
- "additionalProperties": false
3278
+ }
3298
3279
  },
3299
3280
  "NotFoundResponse": {
3300
3281
  "type": "object",
3301
- "additionalProperties": false,
3302
3282
  "properties": {
3303
3283
  "notFoundId": {
3304
3284
  "type": "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/identity-service",
3
- "version": "0.0.3-next.16",
3
+ "version": "0.0.3-next.18",
4
4
  "description": "Identity contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "@twin.org/data-json-ld": "next",
23
23
  "@twin.org/entity": "next",
24
24
  "@twin.org/entity-storage-models": "next",
25
- "@twin.org/identity-models": "0.0.3-next.16",
25
+ "@twin.org/identity-models": "0.0.3-next.18",
26
26
  "@twin.org/standards-w3c-did": "next",
27
27
  "@twin.org/vault-models": "next",
28
28
  "@twin.org/web": "next"