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

crypto/Ed25519

Classes

Ed25519Error

Defined in: src/crypto/Ed25519/errors.js:21 Base error class for Ed25519 operations

Example

throw new Ed25519Error('Ed25519 operation failed', {
  code: 'ED25519_ERROR',
  context: { operation: 'sign' },
  docsPath: '/crypto/ed25519#error-handling',
  cause: originalError
})

Extends

Extended by

Constructors

Constructor
new Ed25519Error(message, options?): Ed25519Error
Defined in: src/crypto/Ed25519/errors.js:26
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
Ed25519Error
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/Ed25519/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

InvalidPublicKeyError

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

Example

throw new InvalidPublicKeyError('Ed25519 public key must be 32 bytes', {
  code: 'ED25519_INVALID_PUBLIC_KEY_LENGTH',
  context: { length: 64, expected: 32 },
  docsPath: '/crypto/ed25519/verify#error-handling'
})

Extends

Constructors

Constructor
new InvalidPublicKeyError(message, options?): InvalidPublicKeyError
Defined in: src/crypto/Ed25519/errors.js:82
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/Ed25519/errors.js:89
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/Ed25519/errors.js:105 Error thrown when secret key is invalid

Example

throw new InvalidSecretKeyError('Ed25519 secret key must be 32 bytes', {
  code: 'ED25519_INVALID_SECRET_KEY_LENGTH',
  context: { length: 64, expected: 32 },
  docsPath: '/crypto/ed25519/sign#error-handling'
})

Extends

Constructors

Constructor
new InvalidSecretKeyError(message, options?): InvalidSecretKeyError
Defined in: src/crypto/Ed25519/errors.js:110
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/Ed25519/errors.js:117
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

InvalidSeedError

Defined in: src/crypto/Ed25519/errors.js:133 Error thrown when seed is invalid

Example

throw new InvalidSeedError('Ed25519 seed must be 32 bytes', {
  code: 'ED25519_INVALID_SEED_LENGTH',
  context: { length: 16, expected: 32 },
  docsPath: '/crypto/ed25519/keypair-from-seed#error-handling'
})

Extends

Constructors

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

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
Ed25519Error.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
Ed25519Error.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
Ed25519Error.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
Ed25519Error.docsPath
name
name: string
Defined in: src/crypto/Ed25519/errors.js:145
Inherited from
Ed25519Error.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
Ed25519Error.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
Ed25519Error.toJSON

InvalidSignatureError

Defined in: src/crypto/Ed25519/errors.js:49 Error thrown when signature is invalid

Example

throw new InvalidSignatureError('Ed25519 signature must be 64 bytes', {
  code: 'ED25519_INVALID_SIGNATURE_LENGTH',
  context: { length: 32, expected: 64 },
  docsPath: '/crypto/ed25519/verify#error-handling'
})

Extends

Constructors

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

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
InvalidSignatureError.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
InvalidSignatureError.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
InvalidSignatureError.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
InvalidSignatureError.docsPath
name
name: string
Defined in: src/crypto/Ed25519/errors.js:61
Inherited from
BaseInvalidSignatureError.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
InvalidSignatureError.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
InvalidSignatureError.toJSON

Variables

Ed25519

const Ed25519: object
Defined in: src/crypto/Ed25519/Ed25519.js:54 Ed25519 Digital Signature Algorithm Edwards-curve Digital Signature Algorithm (EdDSA) using Curve25519. Fast, secure, and deterministic signatures without requiring a hash function. Used in many modern protocols including SSH, TLS 1.3, and cryptocurrency.

Type Declaration

derivePublicKey()
derivePublicKey: (secretKey) => PublicKey
Derive Ed25519 public key from secret key.
Parameters
secretKey
SecretKey 32-byte Ed25519 secret key (seed)
Returns
PublicKey 32-byte Ed25519 public key
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If secret key length is invalid or derivation fails
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const secretKey = new Uint8Array(32); // Your secret key
const publicKey = Ed25519.derivePublicKey(secretKey);
keypairFromSeed()
keypairFromSeed: (seed) => object
Generate Ed25519 keypair from seed deterministically.
Parameters
seed
Seed 32-byte seed for deterministic keypair generation
Returns
object Object containing 32-byte secretKey and 32-byte 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 not 32 bytes
Throws
If keypair generation fails
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const seed = crypto.getRandomValues(new Uint8Array(32));
const keypair = Ed25519.keypairFromSeed(seed);
console.log(keypair.publicKey); // Uint8Array(32)
PUBLIC_KEY_SIZE
PUBLIC_KEY_SIZE: 32
Ed25519 public key size in bytes.
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Example
import { PUBLIC_KEY_SIZE } from './crypto/Ed25519/constants.js';
const publicKey = new Uint8Array(PUBLIC_KEY_SIZE);
SECRET_KEY_SIZE
SECRET_KEY_SIZE: 32
Ed25519 secret key size in bytes.
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Example
import { SECRET_KEY_SIZE } from './crypto/Ed25519/constants.js';
const secretKey = new Uint8Array(SECRET_KEY_SIZE);
SEED_SIZE
SEED_SIZE: 32
Ed25519 seed size in bytes.
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Example
import { SEED_SIZE } from './crypto/Ed25519/constants.js';
const seed = crypto.getRandomValues(new Uint8Array(SEED_SIZE));
sign()
sign: (message, secretKey) => Signature
Sign message with Ed25519 secret key. Produces deterministic signatures using EdDSA.
Parameters
message
Uint8Array<ArrayBufferLike> Message bytes to sign (any length)
secretKey
SecretKey 32-byte Ed25519 secret key
Returns
Signature 64-byte Ed25519 signature
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If secret key length is not 32 bytes
Throws
If signing operation fails
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const message = new TextEncoder().encode('Hello, world!');
const signature = Ed25519.sign(message, secretKey);
SIGNATURE_SIZE
SIGNATURE_SIZE: 64
Ed25519 signature size in bytes.
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Example
import { SIGNATURE_SIZE } from './crypto/Ed25519/constants.js';
const signature = new Uint8Array(SIGNATURE_SIZE);
validatePublicKey()
validatePublicKey: (publicKey) => boolean
Validate Ed25519 public key format and curve membership.
Parameters
publicKey
PublicKey Ed25519 public key to validate
Returns
boolean True if public key is valid and on curve, false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const isValid = Ed25519.validatePublicKey(publicKey);
if (!isValid) console.log('Invalid public key');
validateSecretKey()
validateSecretKey: (secretKey) => boolean
Validate Ed25519 secret key format. Checks length and attempts public key derivation.
Parameters
secretKey
SecretKey Ed25519 secret key to validate
Returns
boolean True if secret key is valid (32 bytes and can derive public key), false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const isValid = Ed25519.validateSecretKey(secretKey);
if (!isValid) console.log('Invalid secret key');
validateSeed()
validateSeed: (seed) => boolean
Validate Ed25519 seed format. Checks if seed has correct 32-byte length.
Parameters
seed
Seed Ed25519 seed to validate
Returns
boolean True if seed is exactly 32 bytes, false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const seed = crypto.getRandomValues(new Uint8Array(32));
const isValid = Ed25519.validateSeed(seed); // true
verify()
verify: (signature, message, publicKey) => boolean
Verify Ed25519 signature. Returns false on verification failure instead of throwing.
Parameters
signature
Signature 64-byte Ed25519 signature to verify
message
Uint8Array<ArrayBufferLike> Original message bytes that were signed
publicKey
PublicKey 32-byte Ed25519 public key
Returns
boolean True if signature is cryptographically valid, false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If public key length is not 32 bytes
Throws
If signature length is not 64 bytes
Example
import * as Ed25519 from './crypto/Ed25519/index.js';
const valid = Ed25519.verify(signature, message, publicKey);
if (valid) console.log('Signature verified');

Example

import { Ed25519 } from './Ed25519/index.js';

// Generate keypair from seed
const seed = new Uint8Array(32); // Random seed
const keypair = Ed25519.keypairFromSeed(seed);

// Sign a message
const message = new TextEncoder().encode('Hello, world!');
const signature = Ed25519.sign(message, keypair.secretKey);

// Verify signature
const valid = Ed25519.verify(signature, message, keypair.publicKey);

PUBLIC_KEY_SIZE

const PUBLIC_KEY_SIZE: 32 = 32
Defined in: src/crypto/Ed25519/constants.js:27 Ed25519 public key size in bytes.

See

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

Since

0.0.0

Example

import { PUBLIC_KEY_SIZE } from './crypto/Ed25519/constants.js';
const publicKey = new Uint8Array(PUBLIC_KEY_SIZE);

SECRET_KEY_SIZE

const SECRET_KEY_SIZE: 32 = 32
Defined in: src/crypto/Ed25519/constants.js:13 Ed25519 secret key size in bytes.

See

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

Since

0.0.0

Example

import { SECRET_KEY_SIZE } from './crypto/Ed25519/constants.js';
const secretKey = new Uint8Array(SECRET_KEY_SIZE);

SEED_SIZE

const SEED_SIZE: 32 = 32
Defined in: src/crypto/Ed25519/constants.js:55 Ed25519 seed size in bytes.

See

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

Since

0.0.0

Example

import { SEED_SIZE } from './crypto/Ed25519/constants.js';
const seed = crypto.getRandomValues(new Uint8Array(SEED_SIZE));

SIGNATURE_SIZE

const SIGNATURE_SIZE: 64 = 64
Defined in: src/crypto/Ed25519/constants.js:41 Ed25519 signature size in bytes.

See

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

Since

0.0.0

Example

import { SIGNATURE_SIZE } from './crypto/Ed25519/constants.js';
const signature = new Uint8Array(SIGNATURE_SIZE);

Functions

derivePublicKey()

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

Parameters

secretKey
SecretKey 32-byte Ed25519 secret key (seed)

Returns

PublicKey 32-byte Ed25519 public key

See

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

Since

0.0.0

Throws

If secret key length is invalid or derivation fails

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const secretKey = new Uint8Array(32); // Your secret key
const publicKey = Ed25519.derivePublicKey(secretKey);

keypairFromSeed()

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

Parameters

seed
Seed 32-byte seed for deterministic keypair generation

Returns

object Object containing 32-byte secretKey and 32-byte 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 not 32 bytes

Throws

If keypair generation fails

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const seed = crypto.getRandomValues(new Uint8Array(32));
const keypair = Ed25519.keypairFromSeed(seed);
console.log(keypair.publicKey); // Uint8Array(32)

sign()

sign(message, secretKey): Signature
Defined in: src/crypto/Ed25519/sign.js:24 Sign message with Ed25519 secret key. Produces deterministic signatures using EdDSA.

Parameters

message
Uint8Array<ArrayBufferLike> Message bytes to sign (any length)
secretKey
SecretKey 32-byte Ed25519 secret key

Returns

Signature 64-byte Ed25519 signature

See

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

Since

0.0.0

Throws

If secret key length is not 32 bytes

Throws

If signing operation fails

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const message = new TextEncoder().encode('Hello, world!');
const signature = Ed25519.sign(message, secretKey);

validatePublicKey()

validatePublicKey(publicKey): boolean
Defined in: src/crypto/Ed25519/validatePublicKey.js:19 Validate Ed25519 public key format and curve membership.

Parameters

publicKey
PublicKey Ed25519 public key to validate

Returns

boolean True if public key is valid and on curve, false otherwise

See

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

Since

0.0.0

Throws

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const isValid = Ed25519.validatePublicKey(publicKey);
if (!isValid) console.log('Invalid public key');

validateSecretKey()

validateSecretKey(secretKey): boolean
Defined in: src/crypto/Ed25519/validateSecretKey.js:21 Validate Ed25519 secret key format. Checks length and attempts public key derivation.

Parameters

secretKey
SecretKey Ed25519 secret key to validate

Returns

boolean True if secret key is valid (32 bytes and can derive public key), false otherwise

See

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

Since

0.0.0

Throws

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const isValid = Ed25519.validateSecretKey(secretKey);
if (!isValid) console.log('Invalid secret key');

validateSeed()

validateSeed(seed): boolean
Defined in: src/crypto/Ed25519/validateSeed.js:20 Validate Ed25519 seed format. Checks if seed has correct 32-byte length.

Parameters

seed
Seed Ed25519 seed to validate

Returns

boolean True if seed is exactly 32 bytes, false otherwise

See

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

Since

0.0.0

Throws

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const seed = crypto.getRandomValues(new Uint8Array(32));
const isValid = Ed25519.validateSeed(seed); // true

verify()

verify(signature, message, publicKey): boolean
Defined in: src/crypto/Ed25519/verify.js:25 Verify Ed25519 signature. Returns false on verification failure instead of throwing.

Parameters

signature
Signature 64-byte Ed25519 signature to verify
message
Uint8Array<ArrayBufferLike> Original message bytes that were signed
publicKey
PublicKey 32-byte Ed25519 public key

Returns

boolean True if signature is cryptographically valid, false otherwise

See

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

Since

0.0.0

Throws

If public key length is not 32 bytes

Throws

If signature length is not 64 bytes

Example

import * as Ed25519 from './crypto/Ed25519/index.js';
const valid = Ed25519.verify(signature, message, publicKey);
if (valid) console.log('Signature verified');