Skip to main content
@tevm/voltaire
@tevm/voltaire / crypto/ChaCha20Poly1305

crypto/ChaCha20Poly1305

Classes

ChaCha20Poly1305Error

Defined in: src/crypto/ChaCha20Poly1305/errors.js:21 Base error for ChaCha20-Poly1305 operations

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example

Extends

Extended by

Constructors

Constructor
new ChaCha20Poly1305Error(message, options?): ChaCha20Poly1305Error
Defined in: src/crypto/ChaCha20Poly1305/errors.js:26
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
ChaCha20Poly1305Error
Overrides
CryptoError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
CryptoError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
CryptoError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
CryptoError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
CryptoError.docsPath
name
name: string
Defined in: src/crypto/ChaCha20Poly1305/errors.js:33
Inherited from
CryptoError.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
CryptoError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
CryptoError.toJSON

DecryptionError

Defined in: src/crypto/ChaCha20Poly1305/errors.js:118 Decryption failure error

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example

Extends

Constructors

Constructor
new DecryptionError(message, options?): DecryptionError
Defined in: src/crypto/ChaCha20Poly1305/errors.js:123
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
DecryptionError
Overrides
ChaCha20Poly1305Error.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
ChaCha20Poly1305Error.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
ChaCha20Poly1305Error.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
ChaCha20Poly1305Error.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
ChaCha20Poly1305Error.docsPath
name
name: string
Defined in: src/crypto/ChaCha20Poly1305/errors.js:130
Inherited from
ChaCha20Poly1305Error.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
ChaCha20Poly1305Error.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
ChaCha20Poly1305Error.toJSON

InvalidKeyError

Defined in: src/crypto/ChaCha20Poly1305/errors.js:53 Invalid key error

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example

Extends

Constructors

Constructor
new InvalidKeyError(message, options?): InvalidKeyError
Defined in: src/crypto/ChaCha20Poly1305/errors.js:58
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
InvalidKeyError
Overrides
ChaCha20Poly1305Error.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
ChaCha20Poly1305Error.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
ChaCha20Poly1305Error.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
ChaCha20Poly1305Error.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
ChaCha20Poly1305Error.docsPath
name
name: string
Defined in: src/crypto/ChaCha20Poly1305/errors.js:65
Inherited from
ChaCha20Poly1305Error.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
ChaCha20Poly1305Error.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
ChaCha20Poly1305Error.toJSON

InvalidNonceError

Defined in: src/crypto/ChaCha20Poly1305/errors.js:85 Invalid nonce error

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example

Extends

Constructors

Constructor
new InvalidNonceError(message, options?): InvalidNonceError
Defined in: src/crypto/ChaCha20Poly1305/errors.js:90
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
InvalidNonceError
Overrides
ChaCha20Poly1305Error.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
ChaCha20Poly1305Error.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
ChaCha20Poly1305Error.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
ChaCha20Poly1305Error.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
ChaCha20Poly1305Error.docsPath
name
name: string
Defined in: src/crypto/ChaCha20Poly1305/errors.js:97
Inherited from
ChaCha20Poly1305Error.name

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
ChaCha20Poly1305Error.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
ChaCha20Poly1305Error.toJSON

Variables

ChaCha20Poly1305

const ChaCha20Poly1305: object
Defined in: src/crypto/ChaCha20Poly1305/ChaCha20Poly1305.js:39 ChaCha20-Poly1305 Authenticated Encryption (RFC 8439) Provides authenticated encryption using ChaCha20 stream cipher with Poly1305 MAC. Optimized for software implementations. Uses @noble/ciphers for cryptographic operations.

Type Declaration

decrypt()
decrypt: (ciphertext, key, nonce, additionalData?) => Uint8Array<ArrayBufferLike>
Decrypt data with ChaCha20-Poly1305
Parameters
ciphertext
Uint8Array<ArrayBufferLike> Encrypted data with authentication tag
key
Uint8Array<ArrayBufferLike> 32-byte key (256 bits)
nonce
Uint8Array<ArrayBufferLike> 12-byte nonce (96 bits) used during encryption
additionalData?
Uint8Array<ArrayBufferLike> Optional additional authenticated data
Returns
Uint8Array<ArrayBufferLike> Decrypted plaintext
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
If key is not 32 bytes
Throws
If nonce is not 12 bytes
Throws
If authentication fails or decryption error
Example
encrypt()
encrypt: (plaintext, key, nonce, additionalData?) => Uint8Array<ArrayBufferLike>
Encrypt data with ChaCha20-Poly1305
Parameters
plaintext
Uint8Array<ArrayBufferLike> Data to encrypt
key
Uint8Array<ArrayBufferLike> 32-byte key (256 bits)
nonce
Uint8Array<ArrayBufferLike> 12-byte nonce (96 bits)
additionalData?
Uint8Array<ArrayBufferLike> Optional additional authenticated data
Returns
Uint8Array<ArrayBufferLike> Ciphertext with authentication tag appended (16 bytes)
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
If key is not 32 bytes
Throws
If nonce is not 12 bytes
Throws
If encryption fails
Example
generateKey()
generateKey: () => Uint8Array<ArrayBufferLike>
Generate random ChaCha20-Poly1305 key
Returns
Uint8Array<ArrayBufferLike> 32-byte random key (256 bits)
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
Example
generateNonce()
generateNonce: () => Uint8Array<ArrayBufferLike>
Generate random nonce
Returns
Uint8Array<ArrayBufferLike> 12-byte random nonce (96 bits)
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
Example
KEY_SIZE
KEY_SIZE: number
ChaCha20-Poly1305 key size in bytes (256 bits)
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
Example
NONCE_SIZE
NONCE_SIZE: number
Nonce/IV size in bytes (96 bits)
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
Example
TAG_SIZE
TAG_SIZE: number
Authentication tag size in bytes (128 bits)
See
https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation
Since
0.0.0
Throws
Example

Example


KEY_SIZE

const KEY_SIZE: 32 = 32
Defined in: src/crypto/ChaCha20Poly1305/constants.js:13 ChaCha20-Poly1305 key size in bytes (256 bits)

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example


NONCE_SIZE

const NONCE_SIZE: 12 = 12
Defined in: src/crypto/ChaCha20Poly1305/constants.js:27 Nonce/IV size in bytes (96 bits)

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example


TAG_SIZE

const TAG_SIZE: 16 = 16
Defined in: src/crypto/ChaCha20Poly1305/constants.js:41 Authentication tag size in bytes (128 bits)

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example

Functions

decrypt()

decrypt(ciphertext, key, nonce, additionalData?): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/ChaCha20Poly1305/decrypt.js:31 Decrypt data with ChaCha20-Poly1305

Parameters

ciphertext
Uint8Array<ArrayBufferLike> Encrypted data with authentication tag
key
Uint8Array<ArrayBufferLike> 32-byte key (256 bits)
nonce
Uint8Array<ArrayBufferLike> 12-byte nonce (96 bits) used during encryption
additionalData?
Uint8Array<ArrayBufferLike> Optional additional authenticated data

Returns

Uint8Array<ArrayBufferLike> Decrypted plaintext

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

If key is not 32 bytes

Throws

If nonce is not 12 bytes

Throws

If authentication fails or decryption error

Example


encrypt()

encrypt(plaintext, key, nonce, additionalData?): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/ChaCha20Poly1305/encrypt.js:31 Encrypt data with ChaCha20-Poly1305

Parameters

plaintext
Uint8Array<ArrayBufferLike> Data to encrypt
key
Uint8Array<ArrayBufferLike> 32-byte key (256 bits)
nonce
Uint8Array<ArrayBufferLike> 12-byte nonce (96 bits)
additionalData?
Uint8Array<ArrayBufferLike> Optional additional authenticated data

Returns

Uint8Array<ArrayBufferLike> Ciphertext with authentication tag appended (16 bytes)

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

If key is not 32 bytes

Throws

If nonce is not 12 bytes

Throws

If encryption fails

Example


generateKey()

generateKey(): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/ChaCha20Poly1305/generateKey.js:17 Generate random ChaCha20-Poly1305 key

Returns

Uint8Array<ArrayBufferLike> 32-byte random key (256 bits)

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example


generateNonce()

generateNonce(): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/ChaCha20Poly1305/generateNonce.js:17 Generate random nonce

Returns

Uint8Array<ArrayBufferLike> 12-byte random nonce (96 bits)

See

https://voltaire.tevm.sh/crypto/chacha20poly1305 for crypto documentation

Since

0.0.0

Throws

Example