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.19 kB
{"version":3,"file":"jwkThumbprint.mjs","names":[],"sources":["../../../../src/modules/kms/jwk/jwkThumbprint.ts"],"sourcesContent":["import { Hasher, type HashName } from '../../../crypto/hashes/Hasher'\nimport { TypedArrayEncoder } from '../../../utils'\nimport { zParseWithErrorHandling } from '../../../utils/zod'\nimport { type KmsJwkPublic, zKmsJwkPublic } from './knownJwk'\n\nexport const zJwkThumbprintComponents = zKmsJwkPublic.transform((data) => {\n if (data.kty === 'EC') {\n return { crv: data.crv, kty: data.kty, x: data.x, y: data.y }\n }\n\n if (data.kty === 'OKP') {\n return { crv: data.crv, kty: data.kty, x: data.x }\n }\n\n if (data.kty === 'RSA') {\n return { e: data.e, kty: data.kty, n: data.n }\n }\n\n if (data.kty === 'oct') {\n return { k: data.k, kty: data.kty }\n }\n\n throw new Error('Unsupported kty')\n})\n\nexport interface CalculateJwkThumbprintOptions {\n /**\n * The jwk to calcualte the thumbprint for.\n */\n jwk: KmsJwkPublic\n\n /**\n * The hashing algorithm to use for calculating the thumbprint\n */\n hashAlgorithm: HashName\n}\n\nexport function calculateJwkThumbprint(options: CalculateJwkThumbprintOptions): Uint8Array {\n const jwkThumbprintComponents = zParseWithErrorHandling(\n zJwkThumbprintComponents,\n options.jwk,\n `Provided jwk does not match a supported jwk structure. Either the 'kty' is not supported, or required values are missing.`\n )\n\n const thumbprint = Hasher.hash(\n TypedArrayEncoder.fromUtf8String(JSON.stringify(jwkThumbprintComponents)),\n options.hashAlgorithm\n )\n\n return thumbprint\n}\n"],"mappings":";;;;;;AAKA,MAAa,2BAA2B,cAAc,WAAW,SAAS;CACxE,IAAI,KAAK,QAAQ,MACf,OAAO;EAAE,KAAK,KAAK;EAAK,KAAK,KAAK;EAAK,GAAG,KAAK;EAAG,GAAG,KAAK;CAAE;CAG9D,IAAI,KAAK,QAAQ,OACf,OAAO;EAAE,KAAK,KAAK;EAAK,KAAK,KAAK;EAAK,GAAG,KAAK;CAAE;CAGnD,IAAI,KAAK,QAAQ,OACf,OAAO;EAAE,GAAG,KAAK;EAAG,KAAK,KAAK;EAAK,GAAG,KAAK;CAAE;CAG/C,IAAI,KAAK,QAAQ,OACf,OAAO;EAAE,GAAG,KAAK;EAAG,KAAK,KAAK;CAAI;CAGpC,MAAM,IAAI,MAAM,iBAAiB;AACnC,CAAC;AAcD,SAAgB,uBAAuB,SAAoD;CACzF,MAAM,0BAA0B,wBAC9B,0BACA,QAAQ,KACR,2HACF;CAOA,OALmB,OAAO,KACxB,kBAAkB,eAAe,KAAK,UAAU,uBAAuB,CAAC,GACxE,QAAQ,aAGM;AAClB"}