@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 • 4.54 kB
Source Map (JSON)
{"version":3,"file":"KmsOperation.mjs","names":[],"sources":["../../../../src/modules/kms/options/KmsOperation.ts"],"sourcesContent":["import { KeyManagementError } from '../error/KeyManagementError'\nimport { getJwkHumanDescription, type KmsJwkPrivate, type KnownJwaSignatureAlgorithm } from '../jwk'\nimport type { KmsCreateKeyType } from './KmsCreateKeyOptions'\nimport type { KmsDecryptDataDecryption } from './KmsDecryptOptions'\nimport type { KmsEncryptDataEncryption } from './KmsEncryptOptions'\nimport type { KmsKeyAgreementDecryptOptions } from './KmsKeyAgreementDecryptOptions'\nimport type { KmsKeyAgreementEncryptOptions } from './KmsKeyAgreementEncryptOptions'\n\nexport type KmsOperationCreateKey = {\n operation: 'createKey'\n type: KmsCreateKeyType\n}\n\nexport type KmsOperationImportKey = {\n operation: 'importKey'\n privateJwk: KmsJwkPrivate\n}\n\nexport type KmsOperationDeleteKey = {\n operation: 'deleteKey'\n}\n\nexport type KmsOperationSign = {\n operation: 'sign'\n algorithm: KnownJwaSignatureAlgorithm\n}\n\nexport type KmsOperationVerify = {\n operation: 'verify'\n algorithm: KnownJwaSignatureAlgorithm\n}\n\nexport type KmsOperationEncrypt = {\n operation: 'encrypt'\n encryption: KmsEncryptDataEncryption\n keyAgreement?: KmsKeyAgreementEncryptOptions\n}\n\nexport type KmsOperationDecrypt = {\n operation: 'decrypt'\n decryption: KmsDecryptDataDecryption\n keyAgreement?: KmsKeyAgreementDecryptOptions\n}\n\nexport type KmsOperationRandomBytes = {\n operation: 'randomBytes'\n}\n\nexport type KmsOperation =\n | KmsOperationCreateKey\n | KmsOperationImportKey\n | KmsOperationDeleteKey\n | KmsOperationSign\n | KmsOperationVerify\n | KmsOperationEncrypt\n | KmsOperationDecrypt\n | KmsOperationRandomBytes\n\nexport function getKmsOperationHumanDescription(operation: KmsOperation) {\n if (operation.operation === 'deleteKey') {\n return \"'deleteKey' operation\"\n }\n\n if (operation.operation === 'createKey') {\n let base = `'createKey' operation with kty '${operation.type.kty}'`\n\n if (operation.type.kty === 'EC' || operation.type.kty === 'OKP') {\n base += ` and crv '${operation.type.crv}'`\n } else if (operation.type.kty === 'RSA') {\n base += ` and bit length '${operation.type.modulusLength}'`\n } else if (operation.type.kty === 'oct') {\n base += ` and algorithm '${operation.type.algorithm}'`\n\n if (operation.type.algorithm === 'aes' || operation.type.algorithm === 'hmac') {\n base += ` with key length '${operation.type.length}'`\n }\n }\n\n return base\n }\n\n if (operation.operation === 'importKey') {\n return `'importKey' operation with ${getJwkHumanDescription(operation.privateJwk)}`\n }\n\n if (operation.operation === 'sign' || operation.operation === 'verify') {\n return `'${operation.operation}' operation with algorithm '${operation.algorithm}'`\n }\n\n if (operation.operation === 'encrypt') {\n let message = `'encrypt' operation with encryption algorithm '${operation.encryption.algorithm}'`\n if (operation.keyAgreement) {\n message += `and key agreement algorithm '${operation.keyAgreement.algorithm}'`\n }\n return message\n }\n\n if (operation.operation === 'decrypt') {\n let message = `'decrypt' operation with encryption algorithm '${operation.decryption.algorithm}'`\n if (operation.keyAgreement) {\n message += `and key agreement algorithm '${operation.keyAgreement.algorithm}'`\n }\n return message\n }\n\n if (operation.operation === 'randomBytes') {\n return `'randomBytes' operation`\n }\n\n throw new KeyManagementError('Unsupported operation')\n}\n"],"mappings":";;;;;;;AA0DA,SAAgB,gCAAgC,WAAyB;AACvE,KAAI,UAAU,cAAc,YAC1B,QAAO;AAGT,KAAI,UAAU,cAAc,aAAa;EACvC,IAAI,OAAO,mCAAmC,UAAU,KAAK,IAAI;AAEjE,MAAI,UAAU,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,MACxD,SAAQ,aAAa,UAAU,KAAK,IAAI;WAC/B,UAAU,KAAK,QAAQ,MAChC,SAAQ,oBAAoB,UAAU,KAAK,cAAc;WAChD,UAAU,KAAK,QAAQ,OAAO;AACvC,WAAQ,mBAAmB,UAAU,KAAK,UAAU;AAEpD,OAAI,UAAU,KAAK,cAAc,SAAS,UAAU,KAAK,cAAc,OACrE,SAAQ,qBAAqB,UAAU,KAAK,OAAO;;AAIvD,SAAO;;AAGT,KAAI,UAAU,cAAc,YAC1B,QAAO,8BAA8B,uBAAuB,UAAU,WAAW;AAGnF,KAAI,UAAU,cAAc,UAAU,UAAU,cAAc,SAC5D,QAAO,IAAI,UAAU,UAAU,8BAA8B,UAAU,UAAU;AAGnF,KAAI,UAAU,cAAc,WAAW;EACrC,IAAI,UAAU,kDAAkD,UAAU,WAAW,UAAU;AAC/F,MAAI,UAAU,aACZ,YAAW,gCAAgC,UAAU,aAAa,UAAU;AAE9E,SAAO;;AAGT,KAAI,UAAU,cAAc,WAAW;EACrC,IAAI,UAAU,kDAAkD,UAAU,WAAW,UAAU;AAC/F,MAAI,UAAU,aACZ,YAAW,gCAAgC,UAAU,aAAa,UAAU;AAE9E,SAAO;;AAGT,KAAI,UAAU,cAAc,cAC1B,QAAO;AAGT,OAAM,IAAI,mBAAmB,wBAAwB"}