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 • 3.43 kB
{"version":3,"file":"CredoRsaPssProvider.mjs","names":[],"sources":["../../../../src/crypto/webcrypto/providers/CredoRsaPssProvider.ts"],"sourcesContent":["import * as core from 'webcrypto-core'\nimport { PublicJwk } from '../../../modules/kms'\nimport type { CredoWalletWebCrypto } from '../CredoWalletWebCrypto'\nimport { CredoWebCryptoKey } from '../CredoWebCryptoKey'\nimport type {\n CredoWebCryptoKeyPair,\n JsonWebKey,\n KeyFormat,\n KeyUsage,\n RsaHashedImportParams,\n RsaHashedKeyGenParams,\n RsaSsaParams,\n} from '../types'\n\nexport class CredoRsaPssProvider extends core.RsaPssProvider {\n public constructor(private walletWebCrypto: CredoWalletWebCrypto) {\n super()\n }\n\n public async onSign(\n algorithm: RsaSsaParams & { name: 'RSA-PSS' },\n key: CredoWebCryptoKey,\n data: ArrayBuffer\n ): Promise<ArrayBuffer> {\n return new Uint8Array(await this.walletWebCrypto.sign(key, new Uint8Array(data), algorithm)).buffer\n }\n\n public async onVerify(\n algorithm: RsaSsaParams & { name: 'RSA-PSS' },\n key: CredoWebCryptoKey,\n signature: ArrayBuffer,\n data: ArrayBuffer\n ): Promise<boolean> {\n return this.walletWebCrypto.verify(key, algorithm, new Uint8Array(data), new Uint8Array(signature))\n }\n\n public async onGenerateKey(\n algorithm: RsaHashedKeyGenParams & { name: 'RSA-PSS' },\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CredoWebCryptoKeyPair> {\n const key = await this.walletWebCrypto.generate(algorithm)\n const publicJwk = PublicJwk.fromPublicJwk(key.publicJwk)\n\n return {\n publicKey: new CredoWebCryptoKey(publicJwk, algorithm, extractable, 'public', keyUsages),\n privateKey: new CredoWebCryptoKey(publicJwk, algorithm, extractable, 'private', keyUsages),\n }\n }\n\n public async onExportKey(format: KeyFormat, key: CredoWebCryptoKey): Promise<JsonWebKey | ArrayBuffer> {\n const exported = await this.walletWebCrypto.exportKey(format, key)\n if (exported instanceof Uint8Array) return new Uint8Array(exported).buffer\n return exported\n }\n\n public async onImportKey(\n format: KeyFormat,\n keyData: JsonWebKey | ArrayBuffer,\n algorithm: RsaHashedImportParams & { name: 'RSA-PSS' },\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CredoWebCryptoKey> {\n return this.walletWebCrypto.importKey(\n format,\n (keyData as JsonWebKey).kty ? (keyData as JsonWebKey) : new Uint8Array(keyData as ArrayBuffer),\n algorithm,\n extractable,\n keyUsages\n )\n }\n}\n"],"mappings":";;;;;AAcA,IAAa,sBAAb,cAAyC,KAAK,eAAe;CAC3D,YAAmB,iBAA+C;EAChE,MAAM;EADmB,KAAA,kBAAA;CAE3B;CAEA,MAAa,OACX,WACA,KACA,MACsB;EACtB,OAAO,IAAI,WAAW,MAAM,KAAK,gBAAgB,KAAK,KAAK,IAAI,WAAW,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC;CAC/F;CAEA,MAAa,SACX,WACA,KACA,WACA,MACkB;EAClB,OAAO,KAAK,gBAAgB,OAAO,KAAK,WAAW,IAAI,WAAW,IAAI,GAAG,IAAI,WAAW,SAAS,CAAC;CACpG;CAEA,MAAa,cACX,WACA,aACA,WACgC;EAChC,MAAM,MAAM,MAAM,KAAK,gBAAgB,SAAS,SAAS;EACzD,MAAM,YAAY,UAAU,cAAc,IAAI,SAAS;EAEvD,OAAO;GACL,WAAW,IAAI,kBAAkB,WAAW,WAAW,aAAa,UAAU,SAAS;GACvF,YAAY,IAAI,kBAAkB,WAAW,WAAW,aAAa,WAAW,SAAS;EAC3F;CACF;CAEA,MAAa,YAAY,QAAmB,KAA2D;EACrG,MAAM,WAAW,MAAM,KAAK,gBAAgB,UAAU,QAAQ,GAAG;EACjE,IAAI,oBAAoB,YAAY,OAAO,IAAI,WAAW,QAAQ,CAAC,CAAC;EACpE,OAAO;CACT;CAEA,MAAa,YACX,QACA,SACA,WACA,aACA,WAC4B;EAC5B,OAAO,KAAK,gBAAgB,UAC1B,QACC,QAAuB,MAAO,UAAyB,IAAI,WAAW,OAAsB,GAC7F,WACA,aACA,SACF;CACF;AACF"}