Amend Primitives/Tooling
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import {
|
||||
assembleBytecodeBCH,
|
||||
disassembleBytecodeBCH,
|
||||
base58AddressToLockingBytecode,
|
||||
cashAddressToLockingBytecode,
|
||||
binToHex,
|
||||
hexToBin,
|
||||
isHex,
|
||||
parseScript,
|
||||
} from '@bitauth/libauth';
|
||||
|
||||
/**
|
||||
@@ -20,14 +17,29 @@ export class Script {
|
||||
*
|
||||
* @param bytes {Uint8Array} The raw bytes of the Script.
|
||||
*/
|
||||
constructor(bytes: Uint8Array) {
|
||||
protected constructor(bytes: Uint8Array) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Script Entity from the given Assembly String.
|
||||
* Instantiates a Script from either Bytes or Hex.
|
||||
*
|
||||
* @param asm {string} String of assembly code.
|
||||
* @param script The script as either Bytes or Hex.
|
||||
*
|
||||
* @throws {Error} If the script cannot be decoded.
|
||||
*
|
||||
* @returns The created Script Primitive.
|
||||
*/
|
||||
public static from(script: Uint8Array | string) {
|
||||
return script instanceof Uint8Array
|
||||
? Script.fromBytes(script)
|
||||
: Script.fromHex(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Script Entity from bytes.
|
||||
*
|
||||
* @param bytes {string} Script Bytecode
|
||||
*
|
||||
* @throws {Error} If script cannot be decoded.
|
||||
*
|
||||
@@ -86,44 +98,6 @@ export class Script {
|
||||
return new Script(scriptBin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Script Entity from the given CashAddr.
|
||||
*
|
||||
* @param cashAddr {string} The Address in CashAddr format.
|
||||
*
|
||||
* @throws {Error} If address cannot be decoded.
|
||||
*
|
||||
* @returns {Script} The created Script Entity.
|
||||
*/
|
||||
public static fromCashAddr(cashAddr: string): Script {
|
||||
const decodeResult = cashAddressToLockingBytecode(cashAddr);
|
||||
|
||||
if (typeof decodeResult === 'string') {
|
||||
throw new Error(decodeResult);
|
||||
}
|
||||
|
||||
return new Script(decodeResult.bytecode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Script Entity from the given Legacy Address.
|
||||
*
|
||||
* @param legacyAddress {string} The Address in Legacy format.
|
||||
*
|
||||
* @throws {Error} If address cannot be decoded.
|
||||
*
|
||||
* @returns {Script} The created Script Entity.
|
||||
*/
|
||||
public static fromLegacyAddress(legacyAddress: string): Script {
|
||||
const decodeResult = base58AddressToLockingBytecode(legacyAddress);
|
||||
|
||||
if (typeof decodeResult === 'string') {
|
||||
throw new Error(decodeResult);
|
||||
}
|
||||
|
||||
return new Script(decodeResult.bytecode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this script to a human-readable string of assembly.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user