1 | {"version":3,"file":"rsa-oaep.cjs","sources":["../crypto/rsa-oaep.js"],"sourcesContent":["/**\n * RSA-OAEP is an asymmetric keypair used for encryption\n */\n\nimport * as webcrypto from 'lib0/webcrypto'\nexport { exportKeyJwk } from './common.js'\n\n/**\n * @typedef {Array<'encrypt'|'decrypt'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['encrypt', 'decrypt']\n\n/**\n * Note that the max data size is limited by the size of the RSA key.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>}\n */\nexport const encrypt = (key, data) =>\n webcrypto.subtle.encrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(buf => new Uint8Array(buf))\n\n/**\n * @experimental The API is not final!\n *\n * Decrypt some data using AES-GCM method.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} decrypted buffer\n */\nexport const decrypt = (key, data) =>\n webcrypto.subtle.decrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(data => new Uint8Array(data))\n\n/**\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n * @return {Promise<CryptoKeyPair>}\n */\nexport const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.generateKey(\n {\n name: 'RSA-OAEP',\n modulusLength: 4096,\n publicExponent: new Uint8Array([1, 0, 1]),\n hash: 'SHA-256'\n },\n extractable,\n usages\n )\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, extractable, /** @type {Usages} */ (usages))\n}\n"],"names":["webcrypto"],"mappings":";;;;;;;;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