Documentation / @cashconnect-js/core / primitives/public-key
PublicKey
Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:25
Public Key Entity.
Example
// 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()
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
| Parameter | Type | Description |
|---|---|---|
publicKey | string | Bytes | Uint8Array<ArrayBufferLike> | The public key in either hex or bytes. |
Returns
The created Public Key Primitive.
Throws
If the public key cannot be decoded.
fromBytes()
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
| Parameter | Type | Description |
|---|---|---|
publicKeyBytes | Bytes | Uint8Array<ArrayBufferLike> | Uint8Array containing the Public Key bytes. |
Returns
The created Public Key entity.
Throws
If Public Key cannot be created.
fromHex()
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
| Parameter | Type | Description |
|---|---|---|
publicKeyHex | string | Hexadecimal encoding of the Public Key bytes. |
Returns
The created Public Key entity.
Throws
If Public Key cannot be created.
fromRaw()
static fromRaw(bytes): PublicKey;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:93
Creates an instance from serialized data.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Bytes | Uint8Array<ArrayBufferLike> | Serialized Primitive Data |
Returns
A new instance of this primitive.
Remarks
This method is UNSAFE and MUST only be used where input is already verified or trusted.
isValid()
static isValid(publicKey): boolean;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:97
Parameters
| Parameter | Type |
|---|---|
publicKey | string | Uint8Array<ArrayBufferLike> |
Returns
boolean
toHex()
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()
toBytes(): Bytes;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:121
Get the raw bytes of this Public Key.
Returns
The raw bytes of the Public Key.
toString()
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()
toRaw(): Bytes;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:141
Converts this primitive to a serializable representation.
Returns
Serialzied primitive data.
deriveHash160()
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()
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()
deriveAddress(): Address;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:177
Derive the Address for this Public Key.
Returns
The Address for this Public Key.
verifyMessageSchnorr()
verifyMessageSchnorr(message, signature): boolean;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:185
Parameters
| Parameter | Type |
|---|---|
message | string | Uint8Array<ArrayBufferLike> |
signature | string | Uint8Array<ArrayBufferLike> |
Returns
boolean
verifyMessageDER()
verifyMessageDER(message, signature): boolean;Defined in: cashconnect-js/packages/core/src/primitives/public-key.ts:198
Parameters
| Parameter | Type |
|---|---|
message | string | Uint8Array<ArrayBufferLike> |
signature | string | Uint8Array<ArrayBufferLike> |
Returns
boolean
verifyMessageHashCompact()
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
| Parameter | Type | Description |
|---|---|---|
messageHash | Uint8Array | The hash of the message. |
signature | Uint8Array | The signature of the message. |
Returns
boolean
True if signature and message hash verifies, false otherwise..
verifyMessageHashDER()
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
| Parameter | Type | Description |
|---|---|---|
messageHash | string | Uint8Array<ArrayBufferLike> | The hash of the message. |
signature | string | Uint8Array<ArrayBufferLike> | The signature of the message. |
Returns
boolean
True if signature and message hash verifies, false otherwise..
verifyMessageHashSchnorr()
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
| Parameter | Type | Description |
|---|---|---|
messageHash | string | Uint8Array<ArrayBufferLike> | The hash of the message. |
signature | string | Uint8Array<ArrayBufferLike> | The signature of the message. |
Returns
boolean
True if signature and message hash verifies, false otherwise..