Use Bytes Primitive
This commit is contained in:
@@ -24,15 +24,15 @@ import { secp256k1, sha256, ripemd160, utf8ToBin } from '@bitauth/libauth';
|
||||
*/
|
||||
export class PublicKey {
|
||||
// The raw bytes representing the Public Key.
|
||||
protected readonly bytes: Uint8Array;
|
||||
protected readonly bytes: Bytes;
|
||||
|
||||
/**
|
||||
* Construct a new Public Key.
|
||||
*
|
||||
* @param bytes The raw bytes (33) for the Public Key.
|
||||
*/
|
||||
protected constructor(bytes: Uint8Array) {
|
||||
this.bytes = bytes;
|
||||
protected constructor(bytes: Bytes | Uint8Array) {
|
||||
this.bytes = Bytes.from(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ export class PublicKey {
|
||||
*
|
||||
* @returns The created Public Key Primitive.
|
||||
*/
|
||||
public static from(publicKey: Uint8Array | string) {
|
||||
public static from(publicKey: Bytes | Uint8Array | string) {
|
||||
return publicKey instanceof Uint8Array
|
||||
? this.fromBytes(publicKey)
|
||||
: this.fromHex(publicKey);
|
||||
@@ -59,7 +59,7 @@ export class PublicKey {
|
||||
*
|
||||
* @returns The created Public Key entity.
|
||||
*/
|
||||
public static fromBytes(publicKeyBytes: Uint8Array): PublicKey {
|
||||
public static fromBytes(publicKeyBytes: Bytes | Uint8Array): PublicKey {
|
||||
// Ensure that exactly 33 Bytes are given.
|
||||
if (!secp256k1.validatePublicKey(publicKeyBytes)) {
|
||||
throw new Error(`Invalid Public Key.`);
|
||||
@@ -90,7 +90,7 @@ export class PublicKey {
|
||||
*
|
||||
* @returns A new instance of this primitive.
|
||||
*/
|
||||
public static fromRaw(bytes: Uint8Array) {
|
||||
public static fromRaw(bytes: Bytes | Uint8Array) {
|
||||
return new this(bytes);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ export class PublicKey {
|
||||
*
|
||||
* @returns The raw bytes of the Public Key.
|
||||
*/
|
||||
public toBytes(): Uint8Array {
|
||||
public toBytes(): Bytes {
|
||||
// Return the raw bytes for this Public Key.
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user