{"_id":"@hackbg/miscreant-esm","_rev":"4-2c8d6e51d5294dac8e5f644206a31d17","name":"@hackbg/miscreant-esm","dist-tags":{"latest":"0.3.2-patch.3"},"versions":{"0.3.2-patch.1":{"name":"@hackbg/miscreant-esm","version":"0.3.2-patch.1","keywords":["cryptography","encryption","streaming","security"],"author":{"name":"Tony Arcieri"},"license":"MIT","_id":"@hackbg/miscreant-esm@0.3.2-patch.1","maintainers":[{"name":"exactlywhoyouthinkitis","email":"hello@hack.bg"},{"name":"denismaxim0v","email":"denis@hack.bg"},{"name":"aakamenov","email":"asparuh@hack.bg"},{"name":"atanas-krondev","email":"atanas@hack.bg"},{"name":"imollov","email":"ivelin@hack.bg"},{"name":"mradkov","email":"milenradkov@me.com"}],"homepage":"https://miscreant.io","bugs":{"url":"https://github.com/miscreant/miscreant.js/issues"},"dist":{"shasum":"dbd411a584d02db594c9a379317706688f4f1fa4","tarball":"https://registry.npmjs.org/@hackbg/miscreant-esm/-/miscreant-esm-0.3.2-patch.1.tgz","fileCount":61,"integrity":"sha512-eq5GaTU+FvxVSEz1wYtZIklG0Z4s7g7DW+0CQvc8VVIbv45+P5ScVmF4i86e4/TkOMbPK/8FfUsHqvNSL4/zhw==","signatures":[{"sig":"MEYCIQCdF8DqNlMHCBimGPL120GCCcJ4EtbvogVl3UFgkD1cjAIhAMfAt4yZ2fbYEPtimxmHXbwRcs36MojAq2jUV1jcP3kn","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":118711},"main":"./src/index.dist.mjs","ubik":true,"_from":"file:hackbg-miscreant-esm-0.3.2-patch.1.tgz","types":"./src/index.dist.d.ts","exports":{".":{"import":"./src/index.dist.mjs","source":"./src/index.ts","default":"./src/index.dist.cjs"}},"gitHead":"082cbe2a7d7e19ef5f599ca9b5f3feaae981de68","scripts":{"test":"mocha --require ts-node/register test/**/*.spec.ts","check":"tsc --noEmit"},"_npmUser":{"name":"exactlywhoyouthinkitis","email":"hello@hack.bg"},"_resolved":"/run/user/1000/c144d4718ff8def759adb2a731fff8e1/hackbg-miscreant-esm-0.3.2-patch.1.tgz","_integrity":"sha512-eq5GaTU+FvxVSEz1wYtZIklG0Z4s7g7DW+0CQvc8VVIbv45+P5ScVmF4i86e4/TkOMbPK/8FfUsHqvNSL4/zhw==","repository":{"url":"git+https://github.com/miscreant/miscreant.js.git","type":"git"},"_npmVersion":"9.6.7","description":"(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions","directories":{"test":"test"},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"devDependencies":{"chai":"^4.2.0","mocha":"^7.0.0","ts-node":"^8.3.0","tjson-js":"^0.1.2","async-file":"^2.0.2","typescript":"5.2.2","@types/chai":"^4.2.0","@types/node":"^13.1.0","@types/utf8":"^3.0.1","@hackbg/ubik":"./ubik","@types/mocha":"^5.2.7","webcrypto-core":"1.0.17","chai-as-promised":"^7.1.1","mocha-typescript":"^1.1.0","source-map-loader":"^0.2.3","@types/chai-as-promised":"^7.1.0","uglifyjs-webpack-plugin":"^2.2.0"},"_npmOperationalInternal":{"tmp":"tmp/miscreant-esm_0.3.2-patch.1_1694339861924_0.4607019458270172","host":"s3://npm-registry-packages"}},"0.3.2-patch.2":{"name":"@hackbg/miscreant-esm","version":"0.3.2-patch.2","keywords":["cryptography","encryption","streaming","security"],"author":{"name":"Tony Arcieri"},"license":"MIT","_id":"@hackbg/miscreant-esm@0.3.2-patch.2","maintainers":[{"name":"exactlywhoyouthinkitis","email":"hello@hack.bg"},{"name":"denismaxim0v","email":"denis@hack.bg"},{"name":"aakamenov","email":"asparuh@hack.bg"},{"name":"atanas-krondev","email":"atanas@hack.bg"},{"name":"imollov","email":"ivelin@hack.bg"},{"name":"mradkov","email":"milenradkov@me.com"}],"homepage":"https://miscreant.io","bugs":{"url":"https://github.com/miscreant/miscreant.js/issues"},"dist":{"shasum":"6e078cc8b7e6035ad243d40af8cb3a3b1c8a7eba","tarball":"https://registry.npmjs.org/@hackbg/miscreant-esm/-/miscreant-esm-0.3.2-patch.2.tgz","fileCount":61,"integrity":"sha512-L9iNUEUTkL2x+14BAlAUoiZXqWnYb1k46eHJqsZTYVX+9CtNx1scdlnBJBaqdwdXOz5DsHNvY+dxxy1Usjbl8Q==","signatures":[{"sig":"MEQCIHSFRQLDIDaSMJ8B71IlLqPyMM3cfPcq4KF+hrQsq5LpAiAluLz0T9sIh67ZD3Tqfua1uwKa04IPYyRjqydg5prkEA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":118739},"main":"./src/index.dist.mjs","ubik":true,"_from":"file:hackbg-miscreant-esm-0.3.2-patch.2.tgz","types":"./src/index.dist.d.ts","exports":{".":{"import":"./src/index.dist.mjs","source":"./src/index.ts","default":"./src/index.dist.cjs"}},"gitHead":"082cbe2a7d7e19ef5f599ca9b5f3feaae981de68","scripts":{"test":"mocha --require ts-node/register test/**/*.spec.ts","check":"tsc --noEmit"},"_npmUser":{"name":"exactlywhoyouthinkitis","email":"hello@hack.bg"},"_resolved":"/run/user/1000/bb6723f27de40e31966defd43b2401bb/hackbg-miscreant-esm-0.3.2-patch.2.tgz","_integrity":"sha512-L9iNUEUTkL2x+14BAlAUoiZXqWnYb1k46eHJqsZTYVX+9CtNx1scdlnBJBaqdwdXOz5DsHNvY+dxxy1Usjbl8Q==","repository":{"url":"git+https://github.com/miscreant/miscreant.js.git","type":"git"},"_npmVersion":"9.6.7","description":"(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions","directories":{"test":"test"},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"devDependencies":{"chai":"^4.2.0","mocha":"^7.0.0","ts-node":"^8.3.0","tjson-js":"^0.1.2","async-file":"^2.0.2","typescript":"5.2.2","@types/chai":"^4.2.0","@types/node":"^13.1.0","@types/utf8":"^3.0.1","@hackbg/ubik":"./ubik","@types/mocha":"^5.2.7","webcrypto-core":"1.0.17","chai-as-promised":"^7.1.1","mocha-typescript":"^1.1.0","source-map-loader":"^0.2.3","@types/chai-as-promised":"^7.1.0","uglifyjs-webpack-plugin":"^2.2.0"},"_npmOperationalInternal":{"tmp":"tmp/miscreant-esm_0.3.2-patch.2_1694340967393_0.2783005349263259","host":"s3://npm-registry-packages"}},"0.3.2-patch.3":{"name":"@hackbg/miscreant-esm","version":"0.3.2-patch.3","keywords":["cryptography","encryption","streaming","security"],"author":{"name":"Tony Arcieri"},"license":"MIT","_id":"@hackbg/miscreant-esm@0.3.2-patch.3","maintainers":[{"name":"exactlywhoyouthinkitis","email":"hello@hack.bg"},{"name":"denismaxim0v","email":"denis@hack.bg"},{"name":"aakamenov","email":"asparuh@hack.bg"},{"name":"atanas-krondev","email":"atanas@hack.bg"},{"name":"imollov","email":"ivelin@hack.bg"},{"name":"mradkov","email":"milenradkov@me.com"}],"homepage":"https://miscreant.io","bugs":{"url":"https://github.com/miscreant/miscreant.js/issues"},"dist":{"shasum":"1e082b9cf4b872e3d3057c08ecef4c16028869db","tarball":"https://registry.npmjs.org/@hackbg/miscreant-esm/-/miscreant-esm-0.3.2-patch.3.tgz","fileCount":80,"integrity":"sha512-CxWupG9uSc0e0toliMBc+ZSC2cXuHqcSgvwCgCiWXkpF6adzcttNFr6KyumI3utO/WQKQrdgq93LcQEueBjTHQ==","signatures":[{"sig":"MEUCIQDOgOeamAq7C7Ma4Lpzcrb8kkXqgiDf0HsBHX/L3KF8KAIgMGOQ5YC9i11RTHyNII9vi647SYbKu/csw6jZ+2wvf5A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":166348},"main":"./src/index.dist.mjs","ubik":true,"_from":"file:hackbg-miscreant-esm-0.3.2-patch.3.tgz","types":"./src/index.dist.d.ts","exports":{".":{"import":"./src/index.dist.mjs","source":"./src/index.ts","default":"./src/index.dist.cjs"}},"gitHead":"082cbe2a7d7e19ef5f599ca9b5f3feaae981de68","scripts":{"test":"mocha --require ts-node/register test/**/*.spec.ts","check":"tsc --noEmit"},"_npmUser":{"name":"exactlywhoyouthinkitis","email":"hello@hack.bg"},"_resolved":"/run/user/1000/ac525de80628b190f1243eb7cf1a37e8/hackbg-miscreant-esm-0.3.2-patch.3.tgz","_integrity":"sha512-CxWupG9uSc0e0toliMBc+ZSC2cXuHqcSgvwCgCiWXkpF6adzcttNFr6KyumI3utO/WQKQrdgq93LcQEueBjTHQ==","repository":{"url":"git+https://github.com/miscreant/miscreant.js.git","type":"git"},"_npmVersion":"9.6.7","description":"(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions","directories":{"test":"test"},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"devDependencies":{"chai":"^4.2.0","mocha":"^7.0.0","ts-node":"^8.3.0","tjson-js":"^0.1.2","async-file":"^2.0.2","typescript":"5.2.2","@types/chai":"^4.2.0","@types/node":"^13.1.0","@types/utf8":"^3.0.1","@hackbg/ubik":"./ubik","@types/mocha":"^5.2.7","webcrypto-core":"1.0.17","chai-as-promised":"^7.1.1","mocha-typescript":"^1.1.0","source-map-loader":"^0.2.3","@types/chai-as-promised":"^7.1.0","uglifyjs-webpack-plugin":"^2.2.0"},"_npmOperationalInternal":{"tmp":"tmp/miscreant-esm_0.3.2-patch.3_1694341104506_0.9732948893663418","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-09-10T09:57:41.800Z","modified":"2025-03-19T17:39:50.058Z","0.3.2-patch.1":"2023-09-10T09:57:42.112Z","0.3.2-patch.2":"2023-09-10T10:16:07.611Z","0.3.2-patch.3":"2023-09-10T10:18:24.765Z"},"bugs":{"url":"https://github.com/miscreant/miscreant.js/issues"},"author":{"name":"Tony Arcieri"},"license":"MIT","homepage":"https://miscreant.io","keywords":["cryptography","encryption","streaming","security"],"repository":{"url":"git+https://github.com/miscreant/miscreant.js.git","type":"git"},"description":"(ESM port) Misuse resistant symmetric encryption library providing AES-SIV (RFC 5297), AES-PMAC-SIV, and STREAM constructions","maintainers":[{"email":"ivelin@hack.bg","name":"imollov"},{"email":"atanas@hack.bg","name":"atanas-krondev"},{"email":"milenradkov@me.com","name":"mradkov"},{"email":"hello@hack.bg","name":"exactlywhoyouthinkitis"}],"readme":"# miscreant.js [![Latest Version][npm-shield]][npm-link] [![Build Status][build-image]][build-link] [![MIT licensed][license-image]][license-link] [![Gitter Chat][gitter-image]][gitter-link]\n\n> The best crypto you've never heard of, brought to you by [Phil Rogaway]\n\nJavaScript-compatible TypeScript implementation of **Miscreant**:\nAdvanced symmetric encryption library which provides the [AES-SIV] ([RFC 5297]),\n[AES-PMAC-SIV], and [STREAM] constructions. These algorithms are easy-to-use\n(or rather, hard-to-misuse) and support encryption of individual messages or\nmessage streams.\n\n**AES-SIV** provides [nonce-reuse misuse-resistance] (NRMR): accidentally\nreusing a nonce with this construction is not a security catastrophe,\nunlike it is with more popular AES encryption modes like [AES-GCM].\nWith **AES-SIV**, the worst outcome of reusing a nonce is an attacker\ncan see you've sent the same plaintext twice, as opposed to almost all other\nAES modes where it can facilitate [chosen ciphertext attacks] and/or\nfull plaintext recovery.\n\n## Help and Discussion\n\nHave questions? Want to suggest a feature or change?\n\n- [Gitter]: web-based chat about miscreant projects including **miscreant.js**\n- [Google Group]: join via web or email ([miscreant-crypto+subscribe@googlegroups.com])\n\n## Security Notice\n\nThough this library is written by cryptographic professionals, it has not\nundergone a thorough security audit, and cryptographic professionals are still\nhumans that make mistakes.\n\n**USE AT YOUR OWN RISK**\n\n## Installation\n\nVia [npm](https://www.npmjs.com/):\n\n```bash\nnpm install miscreant\n```\n\nVia [Yarn](https://yarnpkg.com/):\n\n```bash\nyarn install miscreant\n```\n\nImport Miscreant into your project with:\n\n```js\nimport * as miscreant from \"miscreant\";\n```\n\n## Import\n\nImport Miscreant into your project with the following:\n\n```js\nimport * as miscreant from \"miscreant\";\n```\n\n## API: Symmetric Encryption (AEAD)\n\nThe Authenticated Encryption with Associated Data API, or `AEAD` API, is the recommended API for encrypting and\ndecrypting data with Miscreant. It accepts a nonce, optional associated data (i.e. data you'd like to authenticate\nalong with the encrypted message), and a message to encrypt.\n\nWhen decrypting, the same nonce and associated data must be supplied as were passed at the time of encryption. If\nanything is amiss, e.g. if the ciphertext has been tampered with, the cipher will detect it and throw an error.\n\n### miscreant.AEAD.importKey()\n\nThe **miscreant.AEAD.importKey()** method creates a new instance of an **AES-SIV** AEAD encryptor/decryptor.\n\n#### Syntax\n\n```\nmiscreant.AEAD.importKey(keyData, algorithm[, provider = new miscreant.WebCryptoProvider()])\n```\n\n#### Parameters\n\n* **keyData**: a [Uint8Array] containing the encryption key to use. Key must be 32-bytes (for AES-128) or 64-bytes\n  (for AES-256), as SIV uses two distinct AES keys to perform its operations.\n* **algorithm**: a string describing the algorithm to use. The following algorithms are supported:\n  * `\"AES-SIV\"`: CMAC-based construction described in [RFC 5297]. Slower but\n  standardized and more common.\n  * `\"AES-PMAC-SIV\"`: PMAC-based construction. Supports potentially faster\n  implementations, but is non-standard and only available in Miscreant libraries.\n* **provider**: a cryptography provider that implements Miscreant's [ICryptoProvider] interface.\n\n#### Return Value\n\nThe **miscreant.AEAD.importKey()** method returns a [Promise] that, when fulfilled, returns an `AEAD` encryptor/decryptor.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint32Array(32);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\n\nlet key = await miscreant.AEAD.importKey(keyData, \"AES-PMAC-SIV\");\n```\n\n### `seal()`\n\nThe **seal()** method encrypts a message along with an optional *associated data* value which will be authenticated\nalong with the message.\n\n#### Syntax\n\n```\nkey.seal(plaintext, nonce[, associatedData = \"\"])\n```\n\n#### Parameters\n\n* **plaintext**: [Uint8Array] data to be encrypted.\n* **nonce**: a single-use value which MUST be unique per encrypted message. Can be any length, and use any uniqueness\n  strategy you like, e.g. a counter or a cryptographically secure random number generator.\n* **associatedData**: (optional) [Uint8Array] that will be *authenticated* along with the message (but not encrypted).\n\n#### Return Value\n\nThe **seal()** method returns a [Promise] that, when fulfilled, returns a [Uint8Array] containing the resulting ciphertext.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint8Array(32);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\n\nlet key = await miscreant.SIV.importKey(keyData, \"AES-PMAC-SIV\");\n\n// Encrypt plaintext\n\nlet plaintext = new Uint8Array([2,3,5,7,11,13,17,19,23,29]);\nlet nonce = new Uint8Array(16);\nwindow.crypto.getRandomValues(nonce);\n\nlet ciphertext = await key.seal(plaintext, nonce);\n```\n\n### `open()`\n\nThe **open()** method decrypts a message which has been encrypted using **AES-SIV** or **AES-PMAC-SIV**.\n\n#### Syntax\n\n```\nkey.open(ciphertext, nonce[, associatedData = \"\"])\n```\n\n#### Parameters\n\n* **ciphertext**: [Uint8Array] containing an encrypted message.\n* **nonce**: [Uint8Array] supplied when the message was originally encrypted.\n* **associatedData**: (optional) [Uint8Array] supplied when the message was originally encrypted.\n\n#### Return Value\n\nThe **open()** method returns a [Promise] that, when fulfilled, returns a [Uint8Array] containing the decrypted plaintext.\n\n#### Exceptions\n\nIf the message has been tampered with or is otherwise corrupted, the promise will be rejected with an **IntegrityError**.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint8Array(32);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\n\nlet key = await miscreant.SIV.importKey(keyData, \"AES-PMAC-SIV\");\n\n// Encrypt plaintext\n\nlet plaintext = new Uint8Array([2,3,5,7,11,13,17,19,23,29]);\nlet nonce = new Uint8Array(16);\nwindow.crypto.getRandomValues(nonce);\n\nlet ciphertext = await key.seal(plaintext, nonce);\n\n// Decrypt ciphertext\nvar decrypted = await key.open(ciphertext, nonce);\n```\n\n## STREAM API\n\nMiscreant implements an interface that permits incremental processing of encrypted data based on the [STREAM]\nconstruction, which is provably secure against a wide range of attacks including truncation and reordering attacks.\n\nThe API is provided in the form of `miscreant.StreamEncryptor` and `miscreant.StreamDecryptor` classes, which each take\na per-***STREAM*** key and nonce, and from there operate a message-at-a-time on input plaintext/ciphertext along with\noptional per-message associated data (i.e. data you'd like to authenticate along with the encrypted message).\n\n### miscreant.StreamEncryptor.importKey()\n\nThe **miscreant.StreamEncryptor.importKey()** method creates a new instance of a **STREAM** encryptor, capable of\nencrypting a stream of authenticated messages and ensuring their integrity, ordering, and termination.\n\n#### Syntax\n\n```\nmiscreant.StreamEncryptor.importKey(keyData, nonceData, algorithm[, provider = new miscreant.WebCryptoProvider()])\n```\n\n#### Parameters\n\n* **keyData**: a [Uint8Array] containing the encryption key to use. Key must be 32-bytes (for AES-128) or 64-bytes\n  (for AES-256), as SIV uses two distinct AES keys to perform its operations.\n* **nonceData**: a 64-bit (8-byte) [Uint8Array] which MUST be unique to this message stream (for a given key).\n* **algorithm**: a string describing the algorithm to use. The following algorithms are supported:\n  * `\"AES-SIV\"`: CMAC-based construction described in [RFC 5297]. Slower but standardized and more common.\n  * `\"AES-PMAC-SIV\"`: PMAC-based construction. Supports potentially faster implementations, but is non-standard and\n    only available in Miscreant libraries.\n* **provider**: a cryptography provider that implements Miscreant's [ICryptoProvider] interface.\n\n#### Return Value\n\nThe **miscreant.StreamEncryptor.importKey()** method returns a [Promise] that, when fulfilled, returns a `StreamEncryptor` object.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint32Array(32);\nlet nonceData = new Uint8Array(8);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\nwindow.crypto.getRandomValues(nonceData);\n\nlet encryptor = await miscreant.StreamEncryptor.importKey(keyData, nonceData, \"AES-PMAC-SIV\");\n```\n\n### `seal()`\n\nThe **seal()** method of `miscreant.StreamEncryptor` encrypts a message, and also takes  an optional *associated data*\nvalue which will be authenticated along with the message (but not encrypted).\n\nNote that unlike the `AEAD` API, **STREAM** encodes the position of the message into the message stream, so the order\nin which `seal()` is called is significant.\n\n#### Syntax\n\n```\nencryptor.seal(plaintext, [lastBlock = false[, associatedData = \"\"]])\n```\n\n#### Parameters\n\n* **plaintext**: [Uint8Array] data to be encrypted.\n* **lastBlock**: (optional; default: false) is this the last block in the stream?\n* **associatedData**: (optional) [Uint8Array] that will be *authenticated* along with the message (but not encrypted).\n\n#### Return Value\n\nThe **seal()** method returns a [Promise] that, when fulfilled, returns a [Uint8Array] containing the resulting ciphertext.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint32Array(32);\nlet nonceData = new Uint8Array(8);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\nwindow.crypto.getRandomValues(nonceData);\n\nlet encryptor = await miscreant.StreamEncryptor.importKey(keyData, nonceData, \"AES-PMAC-SIV\");\n\n// Encrypt plaintext\n\nlet msg1 = new Uint8Array([1,2]);\nlet msg2 = new Uint8Array([3,4,5]);\nlet msg3 = new Uint8Array([6,7,8,9]);\n\nlet ciphertext1 = await encryptor.seal(msg1);\nlet ciphertext2 = await encryptor.seal(msg2);\nlet ciphertext3 = await encryptor.seal(msg3, true);\n```\n\n### `miscreant.StreamDecryptor.importKey()`\n\nThe **miscreant.StreamDecryptor.importKey()** method creates a new instance of a **STREAM** decryptor, capable of\ndecrypting a previously encrypted stream of authenticated messages and ensuring their integrity, ordering, and termination.\n\n#### Syntax\n\n```\nmiscreant.StreamDecryptor.importKey(keyData, nonceData, algorithm[, provider = new miscreant.WebCryptoProvider()])\n```\n\n#### Parameters\n\n* **keyData**: a [Uint8Array] containing the encryption key to use. Key must be 32-bytes (for AES-128) or 64-bytes\n  (for AES-256), as SIV uses two distinct AES keys to perform its operations.\n* **nonceData**: a 64-bit (8-byte) [Uint8Array] which MUST be unique to this message stream (for a given key).\n* **algorithm**: a string describing the algorithm to use. The following algorithms are supported:\n  * `\"AES-SIV\"`: CMAC-based construction described in [RFC 5297]. Slower but standardized and more common.\n  * `\"AES-PMAC-SIV\"`: PMAC-based construction. Supports potentially faster implementations, but is non-standard and\n    only available in Miscreant libraries.\n* **provider**: a cryptography provider that implements Miscreant's [ICryptoProvider] interface.\n\n#### Return Value\n\nThe **miscreant.StreamDecryptor.importKey()** method returns a [Promise] that, when fulfilled, returns a `StreamDecryptor` object.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint32Array(32);\nlet nonceData = new Uint8Array(8);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\nwindow.crypto.getRandomValues(nonceData);\n\nlet decryptor = await miscreant.StreamDecryptor.importKey(keyData, nonceData, \"AES-PMAC-SIV\");\n```\n\n### `open()`\n\nThe **open()** method decrypts a stream of messages which has been encrypted using **AES-SIV** or **AES-PMAC-SIV**.\n\n#### Syntax\n\n```\ndecryptor.open(ciphertext, [lastBlock = false[, associatedData = \"\"]])\n```\n\n#### Parameters\n\n* **ciphertext**: [Uint8Array] containing an encrypted message.\n* **lastBlock**: (optional; default: false) is this the last block in the stream?\n* **associatedData**: (optional) [Uint8Array] supplied when the message was originally encrypted.\n\n#### Return Value\n\nThe **open()** method returns a [Promise] that, when fulfilled, returns a [Uint8Array] containing the decrypted plaintext.\n\n#### Exceptions\n\nIf the message has been tampered with or is otherwise corrupted, the promise will be rejected with an **IntegrityError**.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint32Array(32);\nlet nonceData = new Uint8Array(8);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\nwindow.crypto.getRandomValues(nonceData);\n\nlet encryptor = await miscreant.StreamEncryptor.importKey(keyData, nonceData, \"AES-PMAC-SIV\");\n\n// Encrypt plaintext\n\nlet msg1 = new Uint8Array([1,2]);\nlet msg2 = new Uint8Array([3,4,5]);\nlet msg3 = new Uint8Array([6,7,8,9]);\n\nlet ciphertext1 = await encryptor.seal(msg1);\nlet ciphertext2 = await encryptor.seal(msg2);\nlet ciphertext3 = await encryptor.seal(msg3, true);\n\n// Decrypt ciphertext\nlet decryptor = await miscreant.StreamDecryptor.importKey(keyData, nonceData, \"AES-PMAC-SIV\");\n\nvar decrypted1 = await key.open(ciphertext1);\nvar decrypted2 = await key.open(ciphertext2);\nvar decrypted3 = await key.open(ciphertext3, true);\n```\n\n## SIV API\n\nThe `SIV` API is a power-user API that allows you to make full use of the multiple header feature the SIV construction provides.\n\n### miscreant.SIV.importKey()\n\nThe **miscreant.SIV.importKey()** method creates a new instance of an **AES-SIV** encryptor/decryptor.\n\n#### Syntax\n\n```\nmiscreant.SIV.importKey(keyData, algorithm[, provider = new miscreant.WebCryptoProvider()])\n```\n\n#### Parameters\n\n* **keyData**: a [Uint8Array] containing the encryption key to use. Key must be 32-bytes (for AES-128) or 64-bytes\n  (for AES-256), as SIV uses two distinct AES keys to perform its operations.\n* **algorithm**: a string describing the algorithm to use. The following algorithms are supported:\n  * `\"AES-SIV\"`: CMAC-based construction described in [RFC 5297]. Slower but standardized and more common.\n  * `\"AES-PMAC-SIV\"`: PMAC-based construction. Supports potentially faster implementations, but is non-standard and\n    only available in Miscreant libraries.\n* **provider**: a cryptography provider that implements Miscreant's [ICryptoProvider] interface.\n\n#### Return Value\n\nThe **miscreant.SIV.importKey()** method returns a [Promise] that, when fulfilled, returns a SIV encryptor/decryptor.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint32Array(32);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\n\nlet key = await miscreant.SIV.importKey(keyData, \"AES-PMAC-SIV\");\n```\n\n### seal()\n\nThe **seal()** method encrypts a message along with a set of message headers known as *associated data*.\n\n#### Syntax\n\n```\nkey.seal(associatedData, plaintext)\n```\n\n#### Parameters\n\n* **associatedData**: array of [Uint8Array] values containing data which won't be encrypted, but will be *authenticated*\n  along with the message. This is useful for including a *nonce* for the message, ensuring that if the same message is\n  encrypted twice, the ciphertext will not repeat.\n* **plaintext**: a [Uint8Array] data to be encrypted.\n\n#### Return Value\n\nThe **seal()** method returns a [Promise] that, when fulfilled, returns a [Uint8Array] containing the resulting ciphertext.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint8Array(32);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\n\nlet key = await miscreant.SIV.importKey(keyData, \"AES-PMAC-SIV\");\n\n// Encrypt plaintext\n\nlet plaintext = new Uint8Array([2,3,5,7,11,13,17,19,23,29]);\nlet nonce = new Uint8Array(16);\nwindow.crypto.getRandomValues(nonce);\n\nlet ciphertext = await key.seal(plaintext, [nonce]);\n```\n\n### open()\n\nThe **open()** method decrypts a message which has been encrypted using **AES-SIV** or **AES-PMAC-SIV**.\n\n#### Syntax\n\n```\nkey.open(associatedData, ciphertext)\n```\n\n#### Parameters\n\n* **associatedData**: array of [Uint8Array] values supplied as associated data when the message was originally encrypted.\n* **ciphertext**: a [Uint8Array] containing an encrypted message.\n\n#### Return Value\n\nThe **open()** method returns a [Promise] that, when fulfilled, returns a [Uint8Array] containing the decrypted plaintext.\n\nIf the message has been tampered with or is otherwise corrupted, the promise will be rejected with an **IntegrityError**.\n\n#### Example\n\n```typescript\nimport * as miscreant from \"miscreant\";\n\nlet keyData = new Uint8Array(32);\n\n// Assuming window.crypto.getRandomValues is available\nwindow.crypto.getRandomValues(keyData);\n\nlet key = await SIV.importKey(keyData, \"AES-PMAC-SIV\");\n\n// Encrypt plaintext\n\nlet plaintext = new Uint8Array([2,3,5,7,11,13,17,19,23,29]);\nlet nonce = new Uint8Array(16);\nwindow.crypto.getRandomValues(nonce);\n\nlet ciphertext = await key.seal(plaintext, [nonce]);\n\n// Decrypt ciphertext\nvar decrypted = await key.open(ciphertext, [nonce]);\n```\n\n## Code of Conduct\n\nWe abide by the [Contributor Covenant][cc] and ask that you do as well.\n\nFor more information, please see [CODE_OF_CONDUCT.md].\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/miscreant/miscreant\n\n## Copyright\n\nCopyright (c) 2017-2019 [The Miscreant Developers][AUTHORS].\n\nSoftware AES implementation derived from the Go standard library:\nCopyright (c) 2012 The Go Authors. All rights reserved.\n\nSee [LICENSE.txt] for further details.\n\n[//]: # (badges)\n\n[npm-shield]: https://img.shields.io/npm/v/miscreant.svg\n[npm-link]: https://www.npmjs.com/package/miscreant\n[build-image]: https://travis-ci.org/miscreant/miscreant.js.svg?branch=develop\n[build-link]: https://travis-ci.org/miscreant/miscreant.js\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg\n[license-link]: https://github.com/miscreant/miscreant.js/blob/develop/LICENSE.txt\n[gitter-image]: https://badges.gitter.im/badge.svg\n[gitter-link]: https://gitter.im/miscreant/Lobby\n\n[//]: # (general links)\n\n[Phil Rogaway]: https://en.wikipedia.org/wiki/Phillip_Rogaway\n[AES-SIV]: https://github.com/miscreant/meta/wiki/AES-SIV\n[RFC 5297]: https://tools.ietf.org/html/rfc5297\n[AES-PMAC-SIV]: https://github.com/miscreant/meta/wiki/AES-PMAC-SIV\n[STREAM]: https://github.com/miscreant/meta/wiki/STREAM\n[nonce-reuse misuse-resistance]: https://github.com/miscreant/meta/wiki/Nonce-Reuse-Misuse-Resistance\n[AES-GCM]: https://en.wikipedia.org/wiki/Galois/Counter_Mode\n[chosen ciphertext attacks]: https://en.wikipedia.org/wiki/Chosen-ciphertext_attack\n[Gitter]: https://gitter.im/miscreant/Lobby\n[Google Group]: https://groups.google.com/forum/#!forum/miscreant-crypto\n[miscreant-crypto+subscribe@googlegroups.com]: mailto:miscreant-crypto+subscribe@googlegroups.com?subject=subscribe\n[cc]: https://contributor-covenant.org\n[CODE_OF_CONDUCT.md]: https://github.com/miscreant/miscreant.js/blob/develop/CODE_OF_CONDUCT.md\n[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\n[Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\n[Crypto]: https://developer.mozilla.org/en-US/docs/Web/API/Crypto\n[AUTHORS]: https://github.com/miscreant/miscreant.js/blob/develop/AUTHORS.md\n[LICENSE.txt]: https://github.com/miscreant/miscreant.js/blob/develop/LICENSE.txt\n","readmeFilename":"README.md"}