Resolve "WIP: UTXO Selection and Storage"
This commit is contained in:
@@ -27,6 +27,19 @@ export class Bytes {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates bytes from an Uint8Array.
|
||||
*
|
||||
* @param bytes The bytes as a Uint8Array.
|
||||
*
|
||||
* @throws {Error} If Base64 is invalid.
|
||||
*
|
||||
* @returns Instance of Bytes.
|
||||
*/
|
||||
public static fromBytes(bytes: Uint8Array): Bytes {
|
||||
return new this(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates bytes from a Base64 string.
|
||||
*
|
||||
@@ -34,7 +47,7 @@ export class Bytes {
|
||||
*
|
||||
* @throws {Error} If Base64 is invalid.
|
||||
*
|
||||
* @returns {Bytes} Instance of Bytes.
|
||||
* @returns Instance of Bytes.
|
||||
*/
|
||||
public static fromBase64(base64: string): Bytes {
|
||||
// If the Base64 is invalid, throw an error.
|
||||
@@ -42,43 +55,43 @@ export class Bytes {
|
||||
throw new Error('Invalid base64 string');
|
||||
}
|
||||
|
||||
return new Bytes(base64ToBin(base64));
|
||||
return new this(base64ToBin(base64));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates bytes from a BigInt (LE encoded).
|
||||
*
|
||||
* @param number {number} The bigint number.
|
||||
* @param number The bigint number.
|
||||
*
|
||||
* @throws {Error} If number is invalid.
|
||||
*
|
||||
* @returns {Bytes} Instance of Bytes.
|
||||
* @returns Instance of Bytes.
|
||||
*/
|
||||
public static fromBigInt(number: bigint): Bytes {
|
||||
return new Bytes(bigIntToBinUintLE(number));
|
||||
return new this(bigIntToBinUintLE(number));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates bytes from a BigInt (64 Bit LE encoded).
|
||||
*
|
||||
* @param number {number} The bigint number.
|
||||
* @param number The bigint number.
|
||||
*
|
||||
* @throws {Error} If number is invalid.
|
||||
*
|
||||
* @returns {Bytes} Instance of Bytes.
|
||||
* @returns Instance of Bytes.
|
||||
*/
|
||||
public static fromBigInt64(number: bigint): Bytes {
|
||||
return new Bytes(bigIntToBinUint64LE(number));
|
||||
return new this(bigIntToBinUint64LE(number));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates bytes from a hex string.
|
||||
*
|
||||
* @param hex {string} The hex string.
|
||||
* @param hex The hex string.
|
||||
*
|
||||
* @throws {Error} If hex is invalid.
|
||||
*
|
||||
* @returns {Bytes} Instance of Bytes.
|
||||
* @returns Instance of Bytes.
|
||||
*/
|
||||
public static fromHex(hex: string): Bytes {
|
||||
// If the hex is invalid, throw an error.
|
||||
@@ -86,24 +99,24 @@ export class Bytes {
|
||||
throw new Error('Invalid hexidecimal string');
|
||||
}
|
||||
|
||||
return new Bytes(hexToBin(hex));
|
||||
return new this(hexToBin(hex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates bytes from a UTF8 string.
|
||||
*
|
||||
* @param utf8 {string} The UTF8 string.
|
||||
* @param utf8 The UTF8 string.
|
||||
*
|
||||
* @returns {Bytes} Instance of Bytes.
|
||||
* @returns Instance of Bytes.
|
||||
*/
|
||||
public static fromUtf8(utf8: string): Bytes {
|
||||
return new Bytes(utf8ToBin(utf8));
|
||||
return new this(utf8ToBin(utf8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return bytes as a Base64 string.
|
||||
*
|
||||
* @returns {string} Bytes as a Base64 string.
|
||||
* @returns Bytes as a Base64 string.
|
||||
*/
|
||||
public toBase64(): string {
|
||||
return binToBase64(this.bytes);
|
||||
@@ -116,7 +129,7 @@ export class Bytes {
|
||||
/**
|
||||
* Return bytes as a hex string.
|
||||
*
|
||||
* @returns {string} Bytes as a hex string.
|
||||
* @returns Bytes as a hex string.
|
||||
*/
|
||||
public toHex(): string {
|
||||
return binToHex(this.bytes);
|
||||
@@ -125,7 +138,7 @@ export class Bytes {
|
||||
/**
|
||||
* Return bytes as a UTF8 string
|
||||
*
|
||||
* @returns {string} Bytes as a UTF8 string.
|
||||
* @returns Bytes as a UTF8 string.
|
||||
*/
|
||||
public toUtf8(): string {
|
||||
return binToUtf8(this.bytes);
|
||||
@@ -134,7 +147,7 @@ export class Bytes {
|
||||
/**
|
||||
* Return bytes as a Uint8Array
|
||||
*
|
||||
* @returns {Uint8Array} Bytes as a Uint8Array.
|
||||
* @returns Bytes as a Uint8Array.
|
||||
*/
|
||||
public toBytes(): Uint8Array {
|
||||
return this.bytes;
|
||||
|
||||
Reference in New Issue
Block a user