UNPKG

@credo-ts/core

Version:

<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1

1 lines • 2.09 kB
{"version":3,"file":"JsonWebKey2020.mjs","names":[],"sources":["../../../../../src/modules/dids/domain/verificationMethod/JsonWebKey2020.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\nimport { PublicJwk } from '../../../kms'\nimport type { VerificationMethod } from './VerificationMethod'\n\nexport const VERIFICATION_METHOD_TYPE_JSON_WEB_KEY_2020 = 'JsonWebKey2020'\n\ntype GetJsonWebKey2020Options = {\n did: string\n\n verificationMethodId?: string\n publicJwk: PublicJwk\n}\n\n/**\n * Get a JsonWebKey2020 verification method.\n */\nexport function getJsonWebKey2020(options: GetJsonWebKey2020Options) {\n const verificationMethodId = options.verificationMethodId ?? `${options.did}#${options.publicJwk.fingerprint}`\n\n return {\n id: verificationMethodId,\n type: VERIFICATION_METHOD_TYPE_JSON_WEB_KEY_2020,\n controller: options.did,\n publicKeyJwk: options.publicJwk.toJson(),\n }\n}\n\n/**\n * Check whether a verification method is a JsonWebKey2020 verification method.\n */\nexport function isJsonWebKey2020(\n verificationMethod: VerificationMethod\n): verificationMethod is VerificationMethod & { type: 'JsonWebKey2020' } {\n return verificationMethod.type === VERIFICATION_METHOD_TYPE_JSON_WEB_KEY_2020\n}\n\n/**\n * Get a key from a JsonWebKey2020 verification method.\n */\nexport function getPublicJwkFromJsonWebKey2020(verificationMethod: VerificationMethod & { type: 'JsonWebKey2020' }) {\n if (!verificationMethod.publicKeyJwk) {\n throw new CredoError(\n `Missing publicKeyJwk on verification method with type ${VERIFICATION_METHOD_TYPE_JSON_WEB_KEY_2020}`\n )\n }\n\n return PublicJwk.fromUnknown(verificationMethod.publicKeyJwk)\n}\n"],"mappings":";;;;;AAIA,MAAa,6CAA6C;;;;AAY1D,SAAgB,kBAAkB,SAAmC;CAGnE,OAAO;EACL,IAH2B,QAAQ,wBAAwB,GAAG,QAAQ,IAAI,GAAG,QAAQ,UAAU;EAI/F,MAAM;EACN,YAAY,QAAQ;EACpB,cAAc,QAAQ,UAAU,OAAO;CACzC;AACF;;;;AAKA,SAAgB,iBACd,oBACuE;CACvE,OAAO,mBAAmB,SAAS;AACrC;;;;AAKA,SAAgB,+BAA+B,oBAAqE;CAClH,IAAI,CAAC,mBAAmB,cACtB,MAAM,IAAI,WACR,yDAAyD,4CAC3D;CAGF,OAAO,UAAU,YAAY,mBAAmB,YAAY;AAC9D"}