Classes

ES256PublicKey

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

Constructors

new ES256PublicKey()

new ES256PublicKey(`bytes`): [ES256PublicKey](ES256PublicKey)

Creates a new public key from a byte array.

Compatible with the -7 COSE algorithm identifier.

Example

// 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()));
ParameterType
FirstUint8Array

Methods

__getClassname()

\_\_getClassname(): `string`

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.

ParameterType
FirstES256PublicKey

equals()

equals(`other`): `boolean`

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

ParameterType
FirstES256PublicKey

free()

free(): `void`

serialize()

serialize(): `Uint8Array`

Serializes the public key to a byte array.


toAddress()

toAddress(): [Address](Address)

Gets the public key's address.

Returns
Address

toHex()

toHex(): `string`

Formats the public key into a hex string.


verify()

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

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

ParameterType
FirstUint8Array

deserialize()

`static` deserialize(`bytes`): [ES256PublicKey](ES256PublicKey)

Deserializes a public key from a byte array.

Throws when the byte array contains less than 33 bytes.

ParameterType
FirstUint8Array

fromHex()

`static` fromHex(`hex`): [ES256PublicKey](ES256PublicKey)

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.

ParameterType
Firststring

fromRaw()

`static` fromRaw(`raw_bytes`): [ES256PublicKey](ES256PublicKey)

Deserializes a public key from its raw representation.

ParameterType
FirstUint8Array

fromSpki()

`static` fromSpki(`spki_bytes`): [ES256PublicKey](ES256PublicKey)

Deserializes a public key from its SPKI representation.

ParameterType
FirstUint8Array

On this page