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

crypto/X25519

Classes

InvalidPublicKeyError

Defined in: src/crypto/X25519/errors.js:87 Error thrown when public key is invalid

See

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

Since

0.0.0

Throws

Example

import { InvalidPublicKeyError } from './crypto/X25519/index.js';
throw new InvalidPublicKeyError('Invalid public key', {
  code: 'X25519_INVALID_PUBLIC_KEY_LENGTH',
  context: { length: 16, expected: 32 },
  docsPath: '/crypto/x25519/scalarmult#error-handling'
});

Extends

Constructors

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

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
InvalidPublicKeyError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
InvalidPublicKeyError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
InvalidPublicKeyError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
InvalidPublicKeyError.docsPath
name
name: string
Defined in: src/crypto/X25519/errors.js:99
Inherited from
BaseInvalidPublicKeyError.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
InvalidPublicKeyError.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
InvalidPublicKeyError.toJSON

InvalidSecretKeyError

Defined in: src/crypto/X25519/errors.js:55 Error thrown when secret key is invalid

See

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

Since

0.0.0

Throws

Example

import { InvalidSecretKeyError } from './crypto/X25519/index.js';
throw new InvalidSecretKeyError('Invalid secret key', {
  code: 'X25519_INVALID_SECRET_KEY_LENGTH',
  context: { length: 16, expected: 32 },
  docsPath: '/crypto/x25519/scalarmult#error-handling'
});

Extends

Constructors

Constructor
new InvalidSecretKeyError(message, options?): InvalidSecretKeyError
Defined in: src/crypto/X25519/errors.js:60
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
InvalidSecretKeyError
Overrides
InvalidPrivateKeyError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
InvalidPrivateKeyError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
InvalidPrivateKeyError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
InvalidPrivateKeyError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
InvalidPrivateKeyError.docsPath
name
name: string
Defined in: src/crypto/X25519/errors.js:67
Inherited from
InvalidPrivateKeyError.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
InvalidPrivateKeyError.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
InvalidPrivateKeyError.toJSON

X25519Error

Defined in: src/crypto/X25519/errors.js:23 Base error for X25519 operations

See

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

Since

0.0.0

Throws

Example

import { X25519Error } from './crypto/X25519/index.js';
throw new X25519Error('Invalid operation', {
  code: 'X25519_ERROR',
  context: { operation: 'scalarmult' },
  docsPath: '/crypto/x25519#error-handling'
});

Extends

Constructors

Constructor
new X25519Error(message, options?): X25519Error
Defined in: src/crypto/X25519/errors.js:28
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
X25519Error
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
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
CryptoError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
CryptoError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
CryptoError.docsPath
name
name: string
Defined in: src/crypto/X25519/errors.js:35
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

Type Aliases

PublicKey

PublicKey = Uint8Array
Defined in: src/crypto/X25519/PublicKey.ts:12 X25519 public key (32 bytes)

See

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

Since

0.0.0

Example

import type { PublicKey } from './crypto/X25519/PublicKey.js';
const publicKey: PublicKey = new Uint8Array(32);

SecretKey

SecretKey = Uint8Array
Defined in: src/crypto/X25519/SecretKey.ts:12 X25519 secret key (32 bytes)

See

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

Since

0.0.0

Example

import type { SecretKey } from './crypto/X25519/SecretKey.js';
const secretKey: SecretKey = new Uint8Array(32);

SharedSecret

SharedSecret = Uint8Array
Defined in: src/crypto/X25519/SharedSecret.ts:12 Shared secret from key exchange (32 bytes)

See

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

Since

0.0.0

Example

import type { SharedSecret } from './crypto/X25519/SharedSecret.js';
const shared: SharedSecret = new Uint8Array(32);

Variables

PUBLIC_KEY_SIZE

const PUBLIC_KEY_SIZE: 32 = 32
Defined in: src/crypto/X25519/constants.js:29 Public key size in bytes

See

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

Since

0.0.0

Throws

Example

import { PUBLIC_KEY_SIZE } from './crypto/X25519/index.js';
console.log(PUBLIC_KEY_SIZE); // 32

SECRET_KEY_SIZE

const SECRET_KEY_SIZE: 32 = 32
Defined in: src/crypto/X25519/constants.js:14 Secret key size in bytes

See

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

Since

0.0.0

Throws

Example

import { SECRET_KEY_SIZE } from './crypto/X25519/index.js';
console.log(SECRET_KEY_SIZE); // 32

SHARED_SECRET_SIZE

const SHARED_SECRET_SIZE: 32 = 32
Defined in: src/crypto/X25519/constants.js:44 Shared secret size in bytes

See

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

Since

0.0.0

Throws

Example

import { SHARED_SECRET_SIZE } from './crypto/X25519/index.js';
console.log(SHARED_SECRET_SIZE); // 32

X25519

const X25519: object
Defined in: src/crypto/X25519/X25519.js:56 X25519 Elliptic Curve Diffie-Hellman Curve25519 key exchange algorithm for secure shared secret generation. Fast, simple, and designed for ECDH key agreement. Used in modern protocols like TLS 1.3, WireGuard, Signal, and SSH.

Type Declaration

derivePublicKey()
derivePublicKey: (secretKey) => PublicKey
Derive public key from secret key
Parameters
secretKey
SecretKey 32-byte secret key
Returns
PublicKey 32-byte public key
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If secret key is invalid
Example
import { X25519 } from './crypto/X25519/index.js';
const secretKey = crypto.getRandomValues(new Uint8Array(32));
const publicKey = X25519.derivePublicKey(secretKey);
console.log(publicKey.length); // 32
generateKeypair()
generateKeypair: () => object
Generate random keypair Uses crypto.getRandomValues for secure random generation
Returns
object Object with secretKey and publicKey
publicKey
publicKey: PublicKey
secretKey
secretKey: SecretKey
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { X25519 } from './crypto/X25519/index.js';
const keypair = X25519.generateKeypair();
console.log(keypair.secretKey.length); // 32
console.log(keypair.publicKey.length); // 32
generateSecretKey()
generateSecretKey: () => SecretKey
Generate random secret key Uses crypto.getRandomValues for secure random generation
Returns
SecretKey 32-byte random secret key
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { X25519 } from './crypto/X25519/index.js';
const secretKey = X25519.generateSecretKey();
const publicKey = X25519.derivePublicKey(secretKey);
console.log(secretKey.length); // 32
keypairFromSeed()
keypairFromSeed: (seed) => object
Generate X25519 keypair from seed
Parameters
seed
Uint8Array<ArrayBufferLike> 32-byte seed for deterministic generation
Returns
object Object with secretKey and publicKey
publicKey
publicKey: PublicKey
secretKey
secretKey: SecretKey
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If seed length is invalid
Example
import { X25519 } from './crypto/X25519/index.js';
const seed = crypto.getRandomValues(new Uint8Array(32));
const keypair = X25519.keypairFromSeed(seed);
console.log(keypair.secretKey.length); // 32
console.log(keypair.publicKey.length); // 32
PUBLIC_KEY_SIZE
PUBLIC_KEY_SIZE: 32
Public key size in bytes
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { PUBLIC_KEY_SIZE } from './crypto/X25519/index.js';
console.log(PUBLIC_KEY_SIZE); // 32
scalarmult()
scalarmult: (secretKey, publicKey) => SharedSecret
Perform X25519 scalar multiplication (ECDH) Computes shared secret from your secret key and their public key.
Parameters
secretKey
SecretKey Your 32-byte secret key
publicKey
PublicKey Their 32-byte public key
Returns
SharedSecret 32-byte shared secret
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If secret key is invalid
Throws
If public key is invalid
Throws
If scalar multiplication fails
Example
import { X25519 } from './crypto/X25519/index.js';
const mySecret = crypto.getRandomValues(new Uint8Array(32));
const theirPublic = X25519.derivePublicKey(theirSecret);
const shared = X25519.scalarmult(mySecret, theirPublic);
console.log(shared.length); // 32
SECRET_KEY_SIZE
SECRET_KEY_SIZE: 32
Secret key size in bytes
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { SECRET_KEY_SIZE } from './crypto/X25519/index.js';
console.log(SECRET_KEY_SIZE); // 32
SHARED_SECRET_SIZE
SHARED_SECRET_SIZE: 32
Shared secret size in bytes
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { SHARED_SECRET_SIZE } from './crypto/X25519/index.js';
console.log(SHARED_SECRET_SIZE); // 32
validatePublicKey()
validatePublicKey: (publicKey) => boolean
Validate a public key Checks if the public key has correct length
Parameters
publicKey
PublicKey Public key to validate
Returns
boolean True if valid, false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { X25519 } from './crypto/X25519/index.js';
const publicKey = new Uint8Array(32);
const valid = X25519.validatePublicKey(publicKey);
validateSecretKey()
validateSecretKey: (secretKey) => boolean
Validate a secret key Checks if the secret key has correct length and can derive a public key
Parameters
secretKey
SecretKey Secret key to validate
Returns
boolean True if valid, false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import { X25519 } from './crypto/X25519/index.js';
const secretKey = new Uint8Array(32);
const valid = X25519.validateSecretKey(secretKey);

See

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

Since

0.0.0

Throws

Example

import { X25519 } from './crypto/X25519/index.js';

// Generate two keypairs
const seed1 = crypto.getRandomValues(new Uint8Array(32));
const seed2 = crypto.getRandomValues(new Uint8Array(32));
const keypair1 = X25519.keypairFromSeed(seed1);
const keypair2 = X25519.keypairFromSeed(seed2);

// Perform key exchange
const shared1 = X25519.scalarmult(keypair1.secretKey, keypair2.publicKey);
const shared2 = X25519.scalarmult(keypair2.secretKey, keypair1.publicKey);
// shared1 === shared2 (same shared secret from both sides)

Functions

derivePublicKey()

derivePublicKey(secretKey): PublicKey
Defined in: src/crypto/X25519/derivePublicKey.js:21 Derive public key from secret key

Parameters

secretKey
SecretKey 32-byte secret key

Returns

PublicKey 32-byte public key

See

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

Since

0.0.0

Throws

If secret key is invalid

Example

import { X25519 } from './crypto/X25519/index.js';
const secretKey = crypto.getRandomValues(new Uint8Array(32));
const publicKey = X25519.derivePublicKey(secretKey);
console.log(publicKey.length); // 32

generateKeypair()

generateKeypair(): object
Defined in: src/crypto/X25519/generateKeypair.js:21 Generate random keypair Uses crypto.getRandomValues for secure random generation

Returns

object Object with secretKey and publicKey
publicKey
publicKey: PublicKey
secretKey
secretKey: SecretKey

See

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

Since

0.0.0

Throws

Example

import { X25519 } from './crypto/X25519/index.js';
const keypair = X25519.generateKeypair();
console.log(keypair.secretKey.length); // 32
console.log(keypair.publicKey.length); // 32

generateSecretKey()

generateSecretKey(): SecretKey
Defined in: src/crypto/X25519/generateSecretKey.js:20 Generate random secret key Uses crypto.getRandomValues for secure random generation

Returns

SecretKey 32-byte random secret key

See

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

Since

0.0.0

Throws

Example

import { X25519 } from './crypto/X25519/index.js';
const secretKey = X25519.generateSecretKey();
const publicKey = X25519.derivePublicKey(secretKey);
console.log(secretKey.length); // 32

keypairFromSeed()

keypairFromSeed(seed): object
Defined in: src/crypto/X25519/keypairFromSeed.js:22 Generate X25519 keypair from seed

Parameters

seed
Uint8Array<ArrayBufferLike> 32-byte seed for deterministic generation

Returns

object Object with secretKey and publicKey
publicKey
publicKey: PublicKey
secretKey
secretKey: SecretKey

See

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

Since

0.0.0

Throws

If seed length is invalid

Example

import { X25519 } from './crypto/X25519/index.js';
const seed = crypto.getRandomValues(new Uint8Array(32));
const keypair = X25519.keypairFromSeed(seed);
console.log(keypair.secretKey.length); // 32
console.log(keypair.publicKey.length); // 32

scalarmult()

scalarmult(secretKey, publicKey): SharedSecret
Defined in: src/crypto/X25519/scalarmult.js:31 Perform X25519 scalar multiplication (ECDH) Computes shared secret from your secret key and their public key.

Parameters

secretKey
SecretKey Your 32-byte secret key
publicKey
PublicKey Their 32-byte public key

Returns

SharedSecret 32-byte shared secret

See

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

Since

0.0.0

Throws

If secret key is invalid

Throws

If public key is invalid

Throws

If scalar multiplication fails

Example

import { X25519 } from './crypto/X25519/index.js';
const mySecret = crypto.getRandomValues(new Uint8Array(32));
const theirPublic = X25519.derivePublicKey(theirSecret);
const shared = X25519.scalarmult(mySecret, theirPublic);
console.log(shared.length); // 32

validatePublicKey()

validatePublicKey(publicKey): boolean
Defined in: src/crypto/X25519/validatePublicKey.js:20 Validate a public key Checks if the public key has correct length

Parameters

publicKey
PublicKey Public key to validate

Returns

boolean True if valid, false otherwise

See

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

Since

0.0.0

Throws

Example

import { X25519 } from './crypto/X25519/index.js';
const publicKey = new Uint8Array(32);
const valid = X25519.validatePublicKey(publicKey);

validateSecretKey()

validateSecretKey(secretKey): boolean
Defined in: src/crypto/X25519/validateSecretKey.js:21 Validate a secret key Checks if the secret key has correct length and can derive a public key

Parameters

secretKey
SecretKey Secret key to validate

Returns

boolean True if valid, false otherwise

See

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

Since

0.0.0

Throws

Example

import { X25519 } from './crypto/X25519/index.js';
const secretKey = new Uint8Array(32);
const valid = X25519.validateSecretKey(secretKey);