Skip to content

Class: KeyPair

A keypair represents a private key and its respective public key. It is used for signing data, usually transactions.

Constructors

new KeyPair()

new KeyPair(private_key, public_key): KeyPair

Parameters

private_key: PrivateKey

public_key: PublicKey

Returns

KeyPair

Defined in

@nimiq/core/types/wasm/web.d.ts:1264

Properties

privateKey

readonly privateKey: PrivateKey

Gets the keypair's private key.

Defined in

@nimiq/core/types/wasm/web.d.ts:1294


publicKey

readonly publicKey: PublicKey

Gets the keypair's public key.

Defined in

@nimiq/core/types/wasm/web.d.ts:1298

Methods

free()

free(): void

Returns

void

Defined in

@nimiq/core/types/wasm/web.d.ts:1232


serialize()

serialize(): Uint8Array

Serializes the keypair to a byte array.

Returns

Uint8Array

Defined in

@nimiq/core/types/wasm/web.d.ts:1269


sign()

sign(data): Signature

Signs arbitrary data, returns a signature object.

Parameters

data: Uint8Array

Returns

Signature

Defined in

@nimiq/core/types/wasm/web.d.ts:1275


signTransaction()

signTransaction(transaction): void

Signs a transaction and sets the signature proof on the transaction object.

Parameters

transaction: Transaction

Returns

void

Defined in

@nimiq/core/types/wasm/web.d.ts:1280


toAddress()

toAddress(): Address

Gets the keypair's address.

Returns

Address

Defined in

@nimiq/core/types/wasm/web.d.ts:1285


toHex()

toHex(): string

Formats the keypair into a hex string.

Returns

string

Defined in

@nimiq/core/types/wasm/web.d.ts:1290


derive()

static derive(private_key): KeyPair

Derives a keypair from an existing private key.

Parameters

private_key: PrivateKey

Returns

KeyPair

Defined in

@nimiq/core/types/wasm/web.d.ts:1243


fromHex()

static fromHex(hex): KeyPair

Parses a keypair from its hex representation.

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

Parameters

hex: string

Returns

KeyPair

Defined in

@nimiq/core/types/wasm/web.d.ts:1251


generate()

static generate(): KeyPair

Generates a new keypair from secure randomness.

Returns

KeyPair

Defined in

@nimiq/core/types/wasm/web.d.ts:1237


unserialize()

static unserialize(bytes): KeyPair

Deserializes a keypair from a byte array.

Throws when the byte array contains less than 64 bytes.

Parameters

bytes: Uint8Array

Returns

KeyPair

Defined in

@nimiq/core/types/wasm/web.d.ts:1259