Skip to content

Class: PrivateKey ​

The secret (private) part of an asymmetric key pair that is typically used to digitally sign or decrypt data.

Table of contents ​

Constructors ​

Methods ​

Constructors ​

constructor ​

• new PrivateKey(bytes): PrivateKey

Creates a new private key from a byte array.

Throws when the byte array is not exactly 32 bytes long.

Parameters ​

NameType
bytesUint8Array

Returns ​

PrivateKey

Defined in ​

web.d.ts:1425

Methods ​

free ​

▸ free(): void

Returns ​

void

Defined in ​

web.d.ts:1405


serialize ​

▸ serialize(): Uint8Array

Serializes the private key to a byte array.

Returns ​

Uint8Array

Defined in ​

web.d.ts:1430


toHex ​

▸ toHex(): string

Formats the private key into a hex string.

Returns ​

string

Defined in ​

web.d.ts:1443


fromHex ​

▸ fromHex(hex): PrivateKey

Parses a private key from its hex representation.

Throws when the string is not valid hex format or when it represents less than 32 bytes.

Parameters ​

NameType
hexstring

Returns ​

PrivateKey

Defined in ​

web.d.ts:1438


generate ​

▸ generate(): PrivateKey

Generates a new private key from secure randomness.

Returns ​

PrivateKey

Defined in ​

web.d.ts:1410


unserialize ​

▸ unserialize(bytes): PrivateKey

Deserializes a private key from a byte array.

Throws when the byte array contains less than 32 bytes.

Parameters ​

NameType
bytesUint8Array

Returns ​

PrivateKey

Defined in ​

web.d.ts:1418