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

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

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

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

## Constructors

### Constructor

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

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

Creates a new public key from a byte array.

Compatible with the `-7` COSE algorithm identifier.

## Example

```javascript
// Create/register a credential with the Webauthn API:
const cred = await navigator.credentials.create({
    publicKey: {
        pubKeyCredParams: [{
            type: "public-key",
            alg: -7, // ES256 = ECDSA over P-256 with SHA-256
       }],
       // ...
    },
});

// Then create an instance of ES256PublicKey from the credential response:
const publicKey = new Nimiq.ES256PublicKey(new Uint8Array(cred.response.getPublicKey()));
```

#### Parameters

##### bytes

`Uint8Array`

#### Returns

`ES256PublicKey`

## Methods

### __getClassname()

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

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

#### Returns

`string`

---

### [dispose]()

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

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

#### Returns

`void`

---

### compare()

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

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

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

`ES256PublicKey`

#### Returns

`number`

---

### equals()

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

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

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

#### Parameters

##### other

`ES256PublicKey`

#### Returns

`boolean`

---

### free()

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

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

#### Returns

`void`

---

### serialize()

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

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

Serializes the public key to a byte array.

#### Returns

`Uint8Array`

---

### toAddress()

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

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

Gets the public key's address.

#### Returns

[`Address`](Address)

---

### toHex()

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

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

Formats the public key into a hex string.

#### Returns

`string`

---

### verify()

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

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

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

#### Parameters

##### signature

[`ES256Signature`](ES256Signature)

##### data

`Uint8Array`

#### Returns

`boolean`

---

### deserialize()

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

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

Deserializes a public key from a byte array.

Throws when the byte array contains less than 33 bytes.

#### Parameters

##### bytes

`Uint8Array`

#### Returns

`ES256PublicKey`

---

### fromHex()

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

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

Parses a public key from its hex representation.

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

#### Parameters

##### hex

`string`

#### Returns

`ES256PublicKey`

---

### fromRaw()

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

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

Deserializes a public key from its raw representation.

#### Parameters

##### raw_bytes

`Uint8Array`

#### Returns

`ES256PublicKey`

---

### fromSpki()

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

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

Deserializes a public key from its SPKI representation.

#### Parameters

##### spki_bytes

`Uint8Array`

#### Returns

`ES256PublicKey`


## Sitemap

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