---
title: "Class: PublicKey"
canonical_url: "https://nimiq.dev/web-client/reference/classes/publickey"
---
# Class: PublicKey

[@nimiq/core](../globals) / PublicKey

Defined in: @nimiq/core/types/wasm/web.d.ts:1939

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

## Constructors

### Constructor

> **new PublicKey**(`bytes`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1993

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`

## Properties

### serializedSize

> `readonly` **serializedSize**: `number`

Defined in: @nimiq/core/types/wasm/web.d.ts:2014

---

### SIZE

> `readonly` `static` **SIZE**: `number`

Defined in: @nimiq/core/types/wasm/web.d.ts:2015

## Methods

### __getClassname()

> **__getClassname**(): `string`

Defined in: @nimiq/core/types/wasm/web.d.ts:1942

#### Returns

`string`

---

### [dispose]()

> **[dispose]**(): `void`

Defined in: @nimiq/core/types/wasm/web.d.ts:1941

#### Returns

`void`

---

### compare()

> **compare**(`other`): `number`

Defined in: @nimiq/core/types/wasm/web.d.ts:1953

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`

---

### equals()

> **equals**(`other`): `boolean`

Defined in: @nimiq/core/types/wasm/web.d.ts:1967

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

#### Parameters

##### other

`PublicKey`

#### Returns

`boolean`

---

### free()

> **free**(): `void`

Defined in: @nimiq/core/types/wasm/web.d.ts:1940

#### Returns

`void`

---

### serialize()

> **serialize**(): `Uint8Array`

Defined in: @nimiq/core/types/wasm/web.d.ts:1997

Serializes the public key to a byte array.

#### Returns

`Uint8Array`

---

### toAddress()

> **toAddress**(): [`Address`](Address)

Defined in: @nimiq/core/types/wasm/web.d.ts:2005

Gets the public key's address.

#### Returns

[`Address`](Address)

---

### toHex()

> **toHex**(): `string`

Defined in: @nimiq/core/types/wasm/web.d.ts:2009

Formats the public key into a hex string.

#### Returns

`string`

---

### verify()

> **verify**(`signature`, `data`): `boolean`

Defined in: @nimiq/core/types/wasm/web.d.ts:2013

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

#### Parameters

##### signature

[`Signature`](Signature)

##### data

`Uint8Array`

#### Returns

`boolean`

---

### combinations()

> `static` **combinations**(`keys`, `num_signers`): `PublicKey`<span>
> 
> 
> 
> </span>

Defined in: @nimiq/core/types/wasm/web.d.ts:1946

Generates all possible combinations (sums) of delinearized public keys for a given number of signers.

#### Parameters

##### keys

(`string` | `Uint8Array`<`ArrayBufferLike`> | `PublicKey`)<span>



</span>



##### num_signers

`number`

#### Returns

`PublicKey`<span>



</span>



---

### derive()

> `static` **derive**(`private_key`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1957

Derives a public key from an existing private key.

#### Parameters

##### private_key

[`PrivateKey`](PrivateKey)

#### Returns

`PublicKey`

---

### deserialize()

> `static` **deserialize**(`bytes`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1963

Deserializes a public key from a byte array.

Throws when the byte array contains less than 32 bytes.

#### Parameters

##### bytes

`Uint8Array`

#### Returns

`PublicKey`

---

### fromAny()

> `static` **fromAny**(`key`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1973

Parses a public key from a PublicKey instance, a hex string representation, or a byte array.

Throws when an PublicKey cannot be parsed from the argument.

#### Parameters

##### key

`string` | `Uint8Array`<`ArrayBufferLike`> | `PublicKey`

#### Returns

`PublicKey`

---

### fromHex()

> `static` **fromHex**(`hex`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1979

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`

---

### fromRaw()

> `static` **fromRaw**(`raw_bytes`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1983

Deserializes a public key from its raw representation.

#### Parameters

##### raw_bytes

`Uint8Array`

#### Returns

`PublicKey`

---

### fromSpki()

> `static` **fromSpki**(`spki_bytes`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:1987

Deserializes a public key from its SPKI representation.

#### Parameters

##### spki_bytes

`Uint8Array`

#### Returns

`PublicKey`

---

### sum()

> `static` **sum**(`keys`): `PublicKey`

Defined in: @nimiq/core/types/wasm/web.d.ts:2001

Sums public keys into one combined public key.

#### Parameters

##### keys

(`string` | `Uint8Array`<`ArrayBufferLike`> | `PublicKey`)<span>



</span>



#### Returns

`PublicKey`


## Sitemap

See the full [sitemap](https://nimiq.dev/sitemap.md) for all pages.
