Use Bytes Primitive

This commit is contained in:
Jim Hamill
2025-07-23 00:27:41 +00:00
parent 9af5dc0087
commit e72c678785
10 changed files with 62 additions and 72 deletions
+6 -6
View File
@@ -28,15 +28,15 @@ import {
* ```
*/
export class Script {
protected readonly bytes: Uint8Array;
protected readonly bytes: Bytes;
/**
* Construct a new Script
*
* @param bytes {Uint8Array} The raw bytes of the Script.
*/
protected constructor(bytes: Uint8Array) {
this.bytes = bytes;
protected constructor(bytes: Bytes | Uint8Array) {
this.bytes = Bytes.from(bytes);
}
/**
@@ -48,7 +48,7 @@ export class Script {
*
* @returns The created Script Primitive.
*/
public static from(script: Uint8Array | string) {
public static from(script: Bytes | Uint8Array | string) {
return script instanceof Uint8Array
? this.fromBytes(script)
: this.fromHex(script);
@@ -63,7 +63,7 @@ export class Script {
*
* @returns {Script} The created Script Entity.
*/
public static fromBytes(bytes: Uint8Array): Script {
public static fromBytes(bytes: Bytes | Uint8Array): Script {
// Disassemble the bytecode.
const disassembledBytecode = disassembleBytecodeBCH(bytes);
@@ -213,7 +213,7 @@ export class Script {
*
* @returns {Uint8Array} The compiled bytes.
*/
public toBytes(): Uint8Array {
public toBytes(): Bytes {
return this.bytes;
}