Skip to content

Class: PublicKey

The non-secret (public) part of an asymmetric key pair that is typically used to digitally verify or encrypt data.

Constructors

new PublicKey()

new PublicKey(bytes): PublicKey

Creates a new public key from a byte array.

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

Parameters

bytes: Uint8Array

Returns

PublicKey

Defined in

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

Properties

serializedSize

readonly serializedSize: number

Defined in

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


SIZE

readonly static SIZE: number

Defined in

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

Methods

__getClassname()

__getClassname(): string

Returns

string

Defined in

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


compare()

compare(other): number

Compares this public key to the other public key.

Returns -1 if this public key is smaller than the other public key, 0 if they are equal, and 1 if this public key is larger than the other public key.

Parameters

other: PublicKey

Returns

number

Defined in

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


equals()

equals(other): boolean

Returns if this public key is equal to the other public key.

Parameters

other: PublicKey

Returns

boolean

Defined in

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


free()

free(): void

Returns

void

Defined in

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


serialize()

serialize(): Uint8Array

Serializes the public key to a byte array.

Returns

Uint8Array

Defined in

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


toAddress()

toAddress(): Address

Gets the public key's address.

Returns

Address

Defined in

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


toHex()

toHex(): string

Formats the public key into a hex string.

Returns

string

Defined in

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


verify()

verify(signature, data): boolean

Verifies that a signature is valid for this public key and the provided data.

Parameters

signature: Signature

data: Uint8Array

Returns

boolean

Defined in

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


derive()

static derive(private_key): PublicKey

Derives a public key from an existing private key.

Parameters

private_key: PrivateKey

Returns

PublicKey

Defined in

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


deserialize()

static deserialize(bytes): PublicKey

Deserializes a public key from a byte array.

Throws when the byte array contains less than 32 bytes.

Parameters

bytes: Uint8Array

Returns

PublicKey

Defined in

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


fromHex()

static fromHex(hex): PublicKey

Parses a public key from its hex representation.

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

Parameters

hex: string

Returns

PublicKey

Defined in

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


fromRaw()

static fromRaw(raw_bytes): PublicKey

Deserializes a public key from its raw representation.

Parameters

raw_bytes: Uint8Array

Returns

PublicKey

Defined in

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


fromSpki()

static fromSpki(spki_bytes): PublicKey

Deserializes a public key from its SPKI representation.

Parameters

spki_bytes: Uint8Array

Returns

PublicKey

Defined in

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