Skip to content

Documentation / @cashconnect-js/core / primitives/public-key

PublicKey ​

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:25

Public Key Entity.

Example ​

ts
// Import our primitives
import { PublicKey } from '@xocash/primitives';

// Create a Public Key from Hex.
const publicKey = PublicKey.from('publicKeyHex');

// Derive the address.
const address = publicKey.deriveAddress();

// Output as a CashAddr.
console.log(address.toCashAddr());

Methods ​

from() ​

ts
static from(publicKey): PublicKey;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:47

Instantiates a Public Key from either Public Key Hex or Public Key Bytes.

Parameters ​
ParameterTypeDescription
publicKeystring | Bytes | Uint8Array<ArrayBufferLike>The public key in either hex or bytes.
Returns ​

PublicKey

The created Public Key Primitive.

Throws ​

If the public key cannot be decoded.

fromBytes() ​

ts
static fromBytes(publicKeyBytes): PublicKey;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:62

Create a Public Key entity from the given hexadecimal string.

Parameters ​
ParameterTypeDescription
publicKeyBytesBytes | Uint8Array<ArrayBufferLike>Uint8Array containing the Public Key bytes.
Returns ​

PublicKey

The created Public Key entity.

Throws ​

If Public Key cannot be created.

fromHex() ​

ts
static fromHex(publicKeyHex): PublicKey;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:80

Create a Public Key entity from the given hexadecimal string.

Parameters ​
ParameterTypeDescription
publicKeyHexstringHexadecimal encoding of the Public Key bytes.
Returns ​

PublicKey

The created Public Key entity.

Throws ​

If Public Key cannot be created.

fromRaw() ​

ts
static fromRaw(bytes): PublicKey;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:93

Creates an instance from serialized data.

Parameters ​
ParameterTypeDescription
bytesBytes | Uint8Array<ArrayBufferLike>Serialized Primitive Data
Returns ​

PublicKey

A new instance of this primitive.

Remarks ​

This method is UNSAFE and MUST only be used where input is already verified or trusted.

isValid() ​

ts
static isValid(publicKey): boolean;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:97

Parameters ​
ParameterType
publicKeystring | Uint8Array<ArrayBufferLike>
Returns ​

boolean

toHex() ​

ts
toHex(): string;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:112

Encode the raw bytes of this Public Key to a hexadecimal representation.

Returns ​

string

The raw bytes Public Key encoded as Hexadecimal.

toBytes() ​

ts
toBytes(): Bytes;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:121

Get the raw bytes of this Public Key.

Returns ​

Bytes

The raw bytes of the Public Key.

toString() ​

ts
toString(): string;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:131

Return the hexadecimal representation of the raw bytes of the Public Key.

Returns ​

string

The raw bytes of the Public Key as hexadecimal.

toRaw() ​

ts
toRaw(): Bytes;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:141

Converts this primitive to a serializable representation.

Returns ​

Bytes

Serialzied primitive data.

deriveHash160() ​

ts
deriveHash160(): Uint8Array;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:150

Derive the Hash160 for this Public Key.

Returns ​

Uint8Array

The Hash160 of the Public Key.

deriveHash160Hex() ​

ts
deriveHash160Hex(): string;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:166

Derive the Hash160 as Hex for this Public Key.

Returns ​

string

The Hash160 of the Public Key as hex.

deriveAddress() ​

ts
deriveAddress(): Address;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:177

Derive the Address for this Public Key.

Returns ​

Address

The Address for this Public Key.

verifyMessageSchnorr() ​

ts
verifyMessageSchnorr(message, signature): boolean;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:185

Parameters ​
ParameterType
messagestring | Uint8Array<ArrayBufferLike>
signaturestring | Uint8Array<ArrayBufferLike>
Returns ​

boolean

verifyMessageDER() ​

ts
verifyMessageDER(message, signature): boolean;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:198

Parameters ​
ParameterType
messagestring | Uint8Array<ArrayBufferLike>
signaturestring | Uint8Array<ArrayBufferLike>
Returns ​

boolean

verifyMessageHashCompact() ​

ts
verifyMessageHashCompact(messageHash, signature): boolean;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:219

Verify that a compact message hash was signed with the corresponding Private Key.

Parameters ​
ParameterTypeDescription
messageHashUint8ArrayThe hash of the message.
signatureUint8ArrayThe signature of the message.
Returns ​

boolean

True if signature and message hash verifies, false otherwise..

verifyMessageHashDER() ​

ts
verifyMessageHashDER(messageHash, signature): boolean;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:240

Verify that a DER message hash was signed with the corresponding Private Key.

Parameters ​
ParameterTypeDescription
messageHashstring | Uint8Array<ArrayBufferLike>The hash of the message.
signaturestring | Uint8Array<ArrayBufferLike>The signature of the message.
Returns ​

boolean

True if signature and message hash verifies, false otherwise..

verifyMessageHashSchnorr() ​

ts
verifyMessageHashSchnorr(messageHash, signature): boolean;

Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:269

Verify that a Schnorr message hash was signed with the corresponding Private Key.

Parameters ​
ParameterTypeDescription
messageHashstring | Uint8Array<ArrayBufferLike>The hash of the message.
signaturestring | Uint8Array<ArrayBufferLike>The signature of the message.
Returns ​

boolean

True if signature and message hash verifies, false otherwise..