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

crypto/P256

Classes

InvalidPrivateKeyError

Defined in: src/crypto/P256/errors.js:80 Error for invalid private keys

See

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

Since

0.0.0

Extends

Constructors

Constructor
new InvalidPrivateKeyError(message, options?): InvalidPrivateKeyError
Defined in: src/crypto/P256/errors.js:85
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
InvalidPrivateKeyError
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/P256/errors.js:92
Inherited from
BaseInvalidPrivateKeyError.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

InvalidPublicKeyError

Defined in: src/crypto/P256/errors.js:58 Error for invalid public keys

See

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

Since

0.0.0

Extends

Constructors

Constructor
new InvalidPublicKeyError(message, options?): InvalidPublicKeyError
Defined in: src/crypto/P256/errors.js:63
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/P256/errors.js:70
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

InvalidSignatureError

Defined in: src/crypto/P256/errors.js:36 Error for invalid signatures

See

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

Since

0.0.0

Extends

Constructors

Constructor
new InvalidSignatureError(message, options?): InvalidSignatureError
Defined in: src/crypto/P256/errors.js:41
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/P256/errors.js:48
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

P256Error

Defined in: src/crypto/P256/errors.js:14 Base error for P256 operations

See

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

Since

0.0.0

Extends

Constructors

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

Interfaces

P256Constructor

Defined in: src/crypto/P256/P256Constructor.ts:15

Properties

CURVE_ORDER
CURVE_ORDER: bigint
Defined in: src/crypto/P256/P256Constructor.ts:22
derivePublicKey()
derivePublicKey: (privateKey) => P256PublicKeyType
Defined in: src/crypto/P256/P256Constructor.ts:18 Derive public key from private key
Parameters
privateKey
P256PrivateKeyType 32-byte private key
Returns
P256PublicKeyType 64-byte uncompressed public key (x || y coordinates)
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If private key is invalid
Example
import * as P256 from './crypto/P256/index.js';
const privateKey = new Uint8Array(32);
const publicKey = P256.derivePublicKey(privateKey);
ecdh()
ecdh: (privateKey, publicKey) => Uint8Array<ArrayBufferLike>
Defined in: src/crypto/P256/P256Constructor.ts:19 Perform ECDH key exchange Computes shared secret from your private key and their public key. Returns the x-coordinate of the shared point.
Parameters
privateKey
P256PrivateKeyType Your 32-byte private key
publicKey
P256PublicKeyType Their 64-byte uncompressed public key
Returns
Uint8Array<ArrayBufferLike> 32-byte shared secret
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If private key is invalid
Throws
If public key is invalid
Throws
If ECDH computation fails
Example
import * as P256 from './crypto/P256/index.js';
const myPrivateKey = new Uint8Array(32);
const theirPublicKey = P256.derivePublicKey(theirPrivateKey);
const sharedSecret = P256.ecdh(myPrivateKey, theirPublicKey);
PRIVATE_KEY_SIZE
PRIVATE_KEY_SIZE: number
Defined in: src/crypto/P256/P256Constructor.ts:23
PUBLIC_KEY_SIZE
PUBLIC_KEY_SIZE: number
Defined in: src/crypto/P256/P256Constructor.ts:24
SHARED_SECRET_SIZE
SHARED_SECRET_SIZE: number
Defined in: src/crypto/P256/P256Constructor.ts:26
sign()
sign: (messageHash, privateKey) => P256SignatureType
Defined in: src/crypto/P256/P256Constructor.ts:16 Sign a message hash with a private key Uses deterministic ECDSA (RFC 6979) for signature generation.
Parameters
messageHash
HashType 32-byte message hash to sign
privateKey
P256PrivateKeyType 32-byte private key
Returns
P256SignatureType ECDSA signature with r, s components
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If private key is invalid
Throws
If signing fails
Example
import * as P256 from './crypto/P256/index.js';
import * as Keccak256 from './crypto/Keccak256/index.js';
const messageHash = Keccak256.hashString('Hello!');
const privateKey = new Uint8Array(32);
const signature = P256.sign(messageHash, privateKey);
SIGNATURE_COMPONENT_SIZE
SIGNATURE_COMPONENT_SIZE: number
Defined in: src/crypto/P256/P256Constructor.ts:25
validatePrivateKey()
validatePrivateKey: (privateKey) => boolean
Defined in: src/crypto/P256/P256Constructor.ts:20 Validate a private key Checks if the private key is in the valid range [1, n-1]
Parameters
privateKey
P256PrivateKeyType Private 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 * as P256 from './crypto/P256/index.js';
const privateKey = new Uint8Array(32);
const isValid = P256.validatePrivateKey(privateKey);
validatePublicKey()
validatePublicKey: (publicKey) => boolean
Defined in: src/crypto/P256/P256Constructor.ts:21 Validate a public key Checks if the public key is a valid point on the P256 curve
Parameters
publicKey
P256PublicKeyType 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 * as P256 from './crypto/P256/index.js';
const publicKey = new Uint8Array(64);
const isValid = P256.validatePublicKey(publicKey);
verify()
verify: (signature, messageHash, publicKey) => boolean
Defined in: src/crypto/P256/P256Constructor.ts:17 Verify an ECDSA signature
Parameters
signature
P256SignatureType ECDSA signature to verify (r and s are HashType)
messageHash
HashType 32-byte message hash that was signed
publicKey
P256PublicKeyType 64-byte uncompressed public key
Returns
boolean True if signature is valid, false otherwise
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If public key format is invalid
Example
import * as P256 from './crypto/P256/index.js';
import * as Hash from './primitives/Hash/index.js';
const r = Hash.from(rBytes);
const s = Hash.from(sBytes);
const valid = P256.verify({ r, s }, messageHash, publicKey);
if (valid) console.log('Signature is valid!');

Type Aliases

P256PrivateKeyType

P256PrivateKeyType = Uint8Array
Defined in: src/crypto/P256/P256PrivateKeyType.ts:7 Private key (32 bytes scalar value)

See

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

Since

0.0.0

P256PublicKeyType

P256PublicKeyType = Uint8Array
Defined in: src/crypto/P256/P256PublicKeyType.ts:9 Uncompressed public key (64 bytes) Format: x-coordinate (32 bytes) || y-coordinate (32 bytes)

See

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

Since

0.0.0

P256SignatureType

P256SignatureType = object
Defined in: src/crypto/P256/P256SignatureType.ts:11 ECDSA signature (r, s components) Components:
  • r: x-coordinate of the ephemeral public key (32 bytes, HashType)
  • s: signature proof value (32 bytes, HashType)

See

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

Since

0.0.0

Properties

r
r: HashType
Defined in: src/crypto/P256/P256SignatureType.ts:12
s
s: HashType
Defined in: src/crypto/P256/P256SignatureType.ts:13

Variables

CURVE_ORDER

const CURVE_ORDER: bigint = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n
Defined in: src/crypto/P256/constants.js:8 P256 curve order (number of points on the curve)

See

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

Since

0.0.0

P256

const P256: P256Constructor
Defined in: src/crypto/P256/P256.js:67 P256 namespace with cryptographic operations

PRIVATE_KEY_SIZE

const PRIVATE_KEY_SIZE: number = 32
Defined in: src/crypto/P256/constants.js:18 Private key size in bytes

See

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

Since

0.0.0

PUBLIC_KEY_SIZE

const PUBLIC_KEY_SIZE: number = 64
Defined in: src/crypto/P256/constants.js:27 Uncompressed public key size in bytes (64 bytes, no prefix)

See

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

Since

0.0.0

SHARED_SECRET_SIZE

const SHARED_SECRET_SIZE: number = 32
Defined in: src/crypto/P256/constants.js:45 ECDH shared secret size in bytes

See

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

Since

0.0.0

SIGNATURE_COMPONENT_SIZE

const SIGNATURE_COMPONENT_SIZE: number = 32
Defined in: src/crypto/P256/constants.js:36 Signature component size in bytes (r and s are each 32 bytes)

See

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

Since

0.0.0

Functions

derivePublicKey()

derivePublicKey(privateKey): P256PublicKeyType
Defined in: src/crypto/P256/derivePublicKey.js:21 Derive public key from private key

Parameters

privateKey
P256PrivateKeyType 32-byte private key

Returns

P256PublicKeyType 64-byte uncompressed public key (x || y coordinates)

See

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

Since

0.0.0

Throws

If private key is invalid

Example

import * as P256 from './crypto/P256/index.js';
const privateKey = new Uint8Array(32);
const publicKey = P256.derivePublicKey(privateKey);

ecdh()

ecdh(privateKey, publicKey): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/P256/ecdh.js:32 Perform ECDH key exchange Computes shared secret from your private key and their public key. Returns the x-coordinate of the shared point.

Parameters

privateKey
P256PrivateKeyType Your 32-byte private key
publicKey
P256PublicKeyType Their 64-byte uncompressed public key

Returns

Uint8Array<ArrayBufferLike> 32-byte shared secret

See

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

Since

0.0.0

Throws

If private key is invalid

Throws

If public key is invalid

Throws

If ECDH computation fails

Example

import * as P256 from './crypto/P256/index.js';
const myPrivateKey = new Uint8Array(32);
const theirPublicKey = P256.derivePublicKey(theirPrivateKey);
const sharedSecret = P256.ecdh(myPrivateKey, theirPublicKey);

sign()

sign(messageHash, privateKey): P256SignatureType
Defined in: src/crypto/P256/sign.js:28 Sign a message hash with a private key Uses deterministic ECDSA (RFC 6979) for signature generation.

Parameters

messageHash
HashType 32-byte message hash to sign
privateKey
P256PrivateKeyType 32-byte private key

Returns

P256SignatureType ECDSA signature with r, s components

See

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

Since

0.0.0

Throws

If private key is invalid

Throws

If signing fails

Example

import * as P256 from './crypto/P256/index.js';
import * as Keccak256 from './crypto/Keccak256/index.js';
const messageHash = Keccak256.hashString('Hello!');
const privateKey = new Uint8Array(32);
const signature = P256.sign(messageHash, privateKey);

validatePrivateKey()

validatePrivateKey(privateKey): boolean
Defined in: src/crypto/P256/validatePrivateKey.js:22 Validate a private key Checks if the private key is in the valid range [1, n-1]

Parameters

privateKey
P256PrivateKeyType Private 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 * as P256 from './crypto/P256/index.js';
const privateKey = new Uint8Array(32);
const isValid = P256.validatePrivateKey(privateKey);

validatePublicKey()

validatePublicKey(publicKey): boolean
Defined in: src/crypto/P256/validatePublicKey.js:22 Validate a public key Checks if the public key is a valid point on the P256 curve

Parameters

publicKey
P256PublicKeyType 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 * as P256 from './crypto/P256/index.js';
const publicKey = new Uint8Array(64);
const isValid = P256.validatePublicKey(publicKey);

verify()

verify(signature, messageHash, publicKey): boolean
Defined in: src/crypto/P256/verify.js:26 Verify an ECDSA signature

Parameters

signature
P256SignatureType ECDSA signature to verify (r and s are HashType)
messageHash
HashType 32-byte message hash that was signed
publicKey
P256PublicKeyType 64-byte uncompressed public key

Returns

boolean True if signature is valid, false otherwise

See

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

Since

0.0.0

Throws

If public key format is invalid

Example

import * as P256 from './crypto/P256/index.js';
import * as Hash from './primitives/Hash/index.js';
const r = Hash.from(rBytes);
const s = Hash.from(sBytes);
const valid = P256.verify({ r, s }, messageHash, publicKey);
if (valid) console.log('Signature is valid!');