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:1424

Properties

privateKey

readonly privateKey: PrivateKey

Gets the keypair's private key.

Defined in

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


publicKey

readonly publicKey: PublicKey

Gets the keypair's public key.

Defined in

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

Methods

free()

free(): void

Returns

void

Defined in

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


serialize()

serialize(): Uint8Array

Serializes the keypair to a byte array.

Returns

Uint8Array

Defined in

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


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:1435


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:1440


toAddress()

toAddress(): Address

Gets the keypair's address.

Returns

Address

Defined in

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


toHex()

toHex(): string

Formats the keypair into a hex string.

Returns

string

Defined in

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


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:1403


deserialize()

static deserialize(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:1419


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:1411


generate()

static generate(): KeyPair

Generates a new keypair from secure randomness.

Returns

KeyPair

Defined in

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