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.33 kB
{"version":3,"file":"X25519KeyAgreementKey2019.mjs","names":[],"sources":["../../../../../src/modules/dids/domain/verificationMethod/X25519KeyAgreementKey2019.ts"],"sourcesContent":["import { CredoError } from '../../../../error'\nimport { TypedArrayEncoder } from '../../../../utils'\nimport { PublicJwk, X25519PublicJwk } from '../../../kms'\n\nimport { VerificationMethod } from './VerificationMethod'\n\nexport const VERIFICATION_METHOD_TYPE_X25519_KEY_AGREEMENT_KEY_2019 = 'X25519KeyAgreementKey2019'\ntype X25519KeyAgreementKey2019 = VerificationMethod & {\n type: typeof VERIFICATION_METHOD_TYPE_X25519_KEY_AGREEMENT_KEY_2019\n}\n\n/**\n * Get a X25519KeyAgreementKey2019 verification method.\n */\nexport function getX25519KeyAgreementKey2019({\n publicJwk,\n id,\n controller,\n}: {\n id: string\n publicJwk: PublicJwk<X25519PublicJwk>\n controller: string\n}) {\n return new VerificationMethod({\n id,\n type: VERIFICATION_METHOD_TYPE_X25519_KEY_AGREEMENT_KEY_2019,\n controller,\n publicKeyBase58: TypedArrayEncoder.toBase58(publicJwk.publicKey.publicKey),\n })\n}\n\n/**\n * Check whether a verification method is a X25519KeyAgreementKey2019 verification method.\n */\nexport function isX25519KeyAgreementKey2019(\n verificationMethod: VerificationMethod\n): verificationMethod is X25519KeyAgreementKey2019 {\n return verificationMethod.type === VERIFICATION_METHOD_TYPE_X25519_KEY_AGREEMENT_KEY_2019\n}\n\n/**\n * Get a key from a X25519KeyAgreementKey2019 verification method.\n */\nexport function getPublicJwkFrommX25519KeyAgreementKey2019(verificationMethod: X25519KeyAgreementKey2019) {\n if (!verificationMethod.publicKeyBase58) {\n throw new CredoError('verification method is missing publicKeyBase58')\n }\n\n return PublicJwk.fromPublicKey({\n kty: 'OKP',\n crv: 'X25519',\n publicKey: TypedArrayEncoder.fromBase58(verificationMethod.publicKeyBase58),\n })\n}\n"],"mappings":";;;;;;;;AAMA,MAAa,yDAAyD;;;;AAQtE,SAAgB,6BAA6B,EAC3C,WACA,IACA,cAKC;CACD,OAAO,IAAI,mBAAmB;EAC5B;EACA,MAAM;EACN;EACA,iBAAiB,kBAAkB,SAAS,UAAU,UAAU,SAAS;CAC3E,CAAC;AACH;;;;AAKA,SAAgB,4BACd,oBACiD;CACjD,OAAO,mBAAmB,SAAS;AACrC;;;;AAKA,SAAgB,2CAA2C,oBAA+C;CACxG,IAAI,CAAC,mBAAmB,iBACtB,MAAM,IAAI,WAAW,gDAAgD;CAGvE,OAAO,UAAU,cAAc;EAC7B,KAAK;EACL,KAAK;EACL,WAAW,kBAAkB,WAAW,mBAAmB,eAAe;CAC5E,CAAC;AACH"}