Skip to main content

README

scrypt-ts

scrypt-ts

Table of contents

Namespaces

Enumerations

Other Classes

SmartContract Classes

Standard Contracts Classes

Interfaces

Array Type Aliases

Other Type Aliases

Types Type Aliases

Variables

Bitwise Operator Functions

Bytes Operations Functions

Global Function Functions

Hashing Functions

Math Functions

Other Functions

assert Functions

decorator Functions

Array Type Aliases

FixedArray

Ƭ FixedArray<T, N>: GrowToSize<T, N, []>

An array is a fixed-size list of values of the same basic type. When you declare an array you have to declare it like this:

Example

let aaa: FixedArray<bigint, 3> = [1n, 3n, 3n];

let abb: FixedArray<FixedArray<bigint, 2>, 3> = [[1n, 3n], [1n, 3n], [1n, 3n]];

let bbb: FixedArray<FixedArray<FixedArray<bigint, 1>, 2>, 3> = [[[1n], [1n]], [[1n], [1n]], [[1n], [1n]]];

Type parameters

NameType
TT
Nextends number

Defined in

dist/smart-contract/builtins/types.d.ts:118


Other Type Aliases

Addr

Ƭ Addr: _PubKeyHash

A domain specific subtype of ByteString, representing an address.

Defined in

dist/smart-contract/builtins/types.d.ts:75

dist/smart-contract/builtins/types.d.ts:37


AddressOption

Ƭ AddressOption: Address

Defined in

dist/bsv/types.d.ts:5


AddressesOption

Ƭ AddressesOption: AddressOption | AddressOption[]

Defined in

dist/bsv/types.d.ts:6


ByteString

Ƭ ByteString: Flavor<string, "bytes">

a ByteString represents a byte array.

Defined in

dist/smart-contract/builtins/types.d.ts:89


ContractId

Ƭ ContractId: Object

ContractId is a unique identifier for a contract. It is the outpoint referenced by the deployment transaction id and the output index.

Type declaration

NameTypeDescription
outputIndexnumberThe output index
txIdstringThe deployment transaction id

Defined in

dist/client/core/types.d.ts:10


LogLevel

Ƭ LogLevel: "verbose" | "debug" | "info" | "warning" | "error" | "off"

Defined in

dist/client/core/logger-controller.d.ts:2


Network

Ƭ Network: Network

Defined in

dist/bsv/types.d.ts:4


OpCodeType

Ƭ OpCodeType: Bytes & { __type: "OpCodeType" }

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:88

node_modules/scryptlib/dist/scryptTypes.d.ts:61


PrivKey

Ƭ PrivKey: Int & { __type: "PrivKey" }

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:69

node_modules/scryptlib/dist/scryptTypes.d.ts:36


PubKey

Ƭ PubKey: _PubKey

A domain specific subtype of ByteString, representing a public key.

Defined in

dist/smart-contract/builtins/types.d.ts:51

dist/smart-contract/builtins/types.d.ts:21


PubKeyHash

Ƭ PubKeyHash: _PubKeyHash

A domain specific subtype of ByteString, representing an address.

Defined in

dist/smart-contract/builtins/types.d.ts:69

dist/smart-contract/builtins/types.d.ts:33


PublicKeyOption

Ƭ PublicKeyOption: PublicKey

Defined in

dist/bsv/types.d.ts:7


PublicKeysOption

Ƭ PublicKeysOption: PublicKeyOption | PublicKeyOption[]

Defined in

dist/bsv/types.d.ts:8


PublicKeysOrAddressesOption

Ƭ PublicKeysOrAddressesOption: AddressesOption | PublicKeysOption

Defined in

dist/bsv/types.d.ts:9


Ripemd160

Ƭ Ripemd160: _Ripemd160

A domain specific subtype of ByteString, representing a RIPEMD-160 hash.

Defined in

dist/smart-contract/builtins/types.d.ts:63

dist/smart-contract/builtins/types.d.ts:29


Sha1

Ƭ Sha1: _Sha1

A domain specific subtype of ByteString, representing a SHA-1 hash.

Defined in

dist/smart-contract/builtins/types.d.ts:81

dist/smart-contract/builtins/types.d.ts:45


Sha256

Ƭ Sha256: _Sha256

A domain specific subtype of ByteString, representing a SHA-256 hash.

Defined in

dist/smart-contract/builtins/types.d.ts:87

dist/smart-contract/builtins/types.d.ts:41


Sig

Ƭ Sig: _Sig

A domain specific subtype of ByteString, representing a signature.

Defined in

dist/smart-contract/builtins/types.d.ts:57

dist/smart-contract/builtins/types.d.ts:25


SigHashPreimage

Ƭ SigHashPreimage: Bytes & { __type: "SigHashPreimage" }

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:87

node_modules/scryptlib/dist/scryptTypes.d.ts:58


SigHashType

Ƭ SigHashType: Bytes & { __type: "SigHashType" }

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:86

node_modules/scryptlib/dist/scryptTypes.d.ts:55


SignatureOption

Ƭ SignatureOption: Object

Type declaration

NameTypeDescription
csIdx?numberIndex of the OP_CODESEPARATOR to split the previous output script at during verification. If undefined, the whole script is used.
pubKeyOrAddrPublicKeysOrAddressesOption-
sigHashType?SignatureHashType-

Defined in

dist/bsv/types.d.ts:10


SignaturesOption

Ƭ SignaturesOption: SignatureOption | SignatureOption[]

Defined in

dist/bsv/types.d.ts:19


SubBytes

Ƭ SubBytes: PubKey | Sig | Sha256 | Sha1 | SigHashType | Ripemd160 | OpCodeType

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:95


TxHash

Ƭ TxHash: string

Defined in

dist/bsv/abstract-provider.d.ts:7


UTXO

Ƭ UTXO: IUnspentOutput

Defined in

dist/bsv/types.d.ts:3


Types Type Aliases

auto

Ƭ auto: any

The auto keyword specifies that the type of the variable, of basic type, declared will be automatically deducted from its initializer.

Defined in

dist/smart-contract/builtins/types.d.ts:102

Variables

Scrypt

Const Scrypt: Object

Type declaration

NameType
bsvApiBsvApi
contractApiContractApi
getConfig<T>(name: string, defaultValue?: T) => T
init(config: ScryptConfig) => void

Defined in

dist/client/index.d.ts:4

Bitwise Operator Functions

lshift

lshift(x, n): bigint

Arithmetic left shift, returns x * 2^n. More detail about [Bitwise Operator][https://docs.scrypt.io/how-to-write-a-contract/built-ins#bitwise-operator](https://docs.scrypt.io/how-to-write-a-contract/built-ins#bitwise-operator)

Parameters

NameType
xbigint
nbigint

Returns

bigint

Defined in

dist/smart-contract/builtins/functions.d.ts:149


rshift

rshift(x, n): bigint

Arithmetic right shift, returns x / 2^n. More detail about [Bitwise Operator][https://docs.scrypt.io/how-to-write-a-contract/built-ins#bitwise-operator](https://docs.scrypt.io/how-to-write-a-contract/built-ins#bitwise-operator)

Parameters

NameType
xbigint
nbigint

Returns

bigint

Defined in

dist/smart-contract/builtins/functions.d.ts:155


Bytes Operations Functions

byteString2Int

byteString2Int(a): bigint

ByteString can be converted to bigint using function byteString2Int.

Parameters

NameType
aByteString

Returns

bigint

Defined in

dist/smart-contract/builtins/functions.d.ts:32


int2ByteString

int2ByteString(n, size?): ByteString

bigint can be converted to string with int2ByteString. If size is not passed, the number n is converted to a ByteString with as few bytes as possible. Otherwise, converts the number n to a ByteString of the specified size, including the sign bit. Fails if the number cannot be accommodated.

Parameters

NameTypeDescription
nbiginta number being converts
size?bigintthe size of the ByteString

Returns

ByteString

Defined in

dist/smart-contract/builtins/functions.d.ts:27


len

len(a): bigint

Returns the length of the ByteString. Not the length of the string.

Parameters

NameTypeDescription
aByteStringa ByteString

Returns

bigint

The length of the ByteString.

Defined in

dist/smart-contract/builtins/functions.d.ts:39


reverseByteString

reverseByteString(b, size): ByteString

Returns reversed bytes of b, which is of size bytes. Note size must be a compiled-time constant. It is often useful when converting a number between little-endian and big-endian.

Parameters

NameTypeDescription
bByteStringa ByteString to be reversed
sizebigintthe size of the ByteString.

Returns

ByteString

reversed ByteString.

Defined in

dist/smart-contract/builtins/functions.d.ts:48


Global Function Functions

equals

equals<T>(a, b): boolean

Comparing two struct/FixedArray

Type parameters

Name
T

Parameters

NameType
aT
bT

Returns

boolean

returns true if equal; otherwise returns false

Defined in

dist/smart-contract/builtins/types.d.ts:124


Hashing Functions

hash160

hash160(a): Ripemd160

A RIPEMD160 hash of a SHA256 hash, which is always 160 bits or 20 bytes long. This value is commonly used inside Bitcoin, particularly for Bitcoin addresses.

See: https://en.wikipedia.org/wiki/RIPEMD

Parameters

NameTypeDescription
aByteStringByteString Data, a.k.a. pre-image, which can be any size.

Returns

Ripemd160

The hash in the form of a string.

Defined in

dist/smart-contract/builtins/functions.d.ts:117


hash256

hash256(a): Sha256

A double SHA256 hash, which is always 256 bits or 32 bytes bytes long. This hash function is commonly used inside Bitcoin, particularly for the hash of a block and the hash of a transaction.

See: https://www.movable-type.co.uk/scripts/sha256.html

Parameters

NameTypeDescription
aByteStringByteString data, a.k.a. pre-image, which can be any size.

Returns

Sha256

The hash in the form of a string.

Defined in

dist/smart-contract/builtins/functions.d.ts:129


pubKey2Addr

pubKey2Addr(a): Addr

Get Addr for PubKey. Under the hood this just wraps the hash160 function.

Parameters

NameType
aPubKey

Returns

Addr

address for the passed public key.

Defined in

dist/smart-contract/builtins/functions.d.ts:137


ripemd160

ripemd160(a): Ripemd160

A RIPEMD160 hash, which is always 160 bits or 20 bytes long. See: https://en.wikipedia.org/wiki/RIPEMD

Parameters

NameTypeDescription
aByteStringByteString Data, a.k.a. pre-image, which can be any size.

Returns

Ripemd160

The hash in the form of a ByteString.

Defined in

dist/smart-contract/builtins/functions.d.ts:85


sha1

sha1(a): Sha1

A SHA or SHA1 hash, which is always 160 bits or 20 bytes long.

See: https://en.wikipedia.org/wiki/SHA-1

Parameters

NameTypeDescription
aByteStringByteString Data, a.k.a. pre-image, which can be any size.

Returns

Sha1

The hash in the form of a string.

Defined in

dist/smart-contract/builtins/functions.d.ts:95


sha256

sha256(a): Sha256

A SHA256 hash, which is always 256 bits or 32 bytes long.

See: https://www.movable-type.co.uk/scripts/sha256.html

Parameters

NameTypeDescription
aByteStringByteString Data, a.k.a. pre-image, which can be any size.

Returns

Sha256

The hash in the form of a string.

Defined in

dist/smart-contract/builtins/functions.d.ts:105


Math Functions

abs

abs(a): bigint

The input a is made positive.

Parameters

NameType
abigint

Returns

bigint

Defined in

dist/smart-contract/builtins/functions.d.ts:61


max

max(a, b): bigint

Returns the largest of a and b.

Parameters

NameType
abigint
bbigint

Returns

bigint

Defined in

dist/smart-contract/builtins/functions.d.ts:71


min

min(a, b): bigint

Returns the smallest of a and b.

Parameters

NameType
abigint
bbigint

Returns

bigint

Defined in

dist/smart-contract/builtins/functions.d.ts:66


within

within(x, min, max): boolean

Returns true if x is within the specified range (left-inclusive), false otherwise.

Parameters

NameType
xbigint
minbigint
maxbigint

Returns

boolean

Defined in

dist/smart-contract/builtins/functions.d.ts:76


Other Functions

Addr

Addr(b): Addr

Creates an Addr instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

Addr

  • A domain specific address representation.

Defined in

dist/smart-contract/builtins/types.d.ts:75


OpCodeType

OpCodeType(b): OpCodeType

Parameters

NameType
bBytes

Returns

OpCodeType

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:88


PrivKey

PrivKey(n): PrivKey

Parameters

NameType
nInt

Returns

PrivKey

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:69


PubKey

PubKey(b): PubKey

Creates a PubKey instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

PubKey

  • A domain specific public key representation.

Defined in

dist/smart-contract/builtins/types.d.ts:51


PubKeyHash

PubKeyHash(b): PubKeyHash

Creates a PubKeyHash instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

PubKeyHash

  • A domain specific address representation.

Defined in

dist/smart-contract/builtins/types.d.ts:69


Ripemd160

Ripemd160(b): Ripemd160

Creates a Ripemd160 instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

Ripemd160

  • A domain specific RIPEMD-160 hash representation.

Defined in

dist/smart-contract/builtins/types.d.ts:63


Sha1

Sha1(b): Sha1

Creates a Sha1 instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

Sha1

  • A domain specific SHA-1 hash representation.

Defined in

dist/smart-contract/builtins/types.d.ts:81


Sha256

Sha256(b): Sha256

Creates a Sha256 instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

Sha256

  • A domain specific SHA-256 hash representation.

Defined in

dist/smart-contract/builtins/types.d.ts:87


Sig

Sig(b): Sig

Creates a Sig instance from a ByteString.

Parameters

NameTypeDescription
bByteStringInput ByteString.

Returns

Sig

  • A domain specific digital signature representation.

Defined in

dist/smart-contract/builtins/types.d.ts:57


SigHashPreimage

SigHashPreimage(b): SigHashPreimage

Parameters

NameType
bBytes

Returns

SigHashPreimage

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:87


SigHashType

SigHashType(s): SigHashType

Parameters

NameType
s0 | SignatureHashType

Returns

SigHashType

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:86


alterFileExt

alterFileExt(filename, toExt, fromExt?): string

Parameters

NameType
filenamestring
toExtstring
fromExt?string

Returns

string

Defined in

dist/smart-contract/utils/index.d.ts:11


and

and(a, b): Int

Parameters

NameType
aInt
bInt

Returns

Int

Defined in

node_modules/scryptlib/dist/builtins.d.ts:15


buildOpreturnScript

buildOpreturnScript(data): Script

Parameters

NameType
datastring

Returns

Script

Defined in

node_modules/scryptlib/dist/builtins.d.ts:22


buildPublicKeyHashScript

buildPublicKeyHashScript(pubKeyHash): Script

Parameters

NameType
pubKeyHashRipemd160

Returns

Script

Defined in

node_modules/scryptlib/dist/builtins.d.ts:23


camelCaseCapitalized

camelCaseCapitalized(str): string

Parameters

NameType
strstring

Returns

string

Defined in

dist/smart-contract/utils/index.d.ts:12


fill

fill<E, N>(value, length): FixedArray<E, N>

Returns an FixedArray with all size elements set to value, where value can be any type. Note that length must be a numeric literal or a compiled-time constant

Type parameters

NameType
EE
Nextends number

Parameters

NameTypeDescription
valueEthe value of each element to set
lengthNthe length of FixedArray

Returns

FixedArray<E, N>

Defined in

dist/smart-contract/builtins/functions.d.ts:18


filterUTXO

filterUTXO(utxos, options): IUnspentOutput[]

Parameters

NameType
utxosIUnspentOutput[]
optionsUtxoQueryOptions

Returns

IUnspentOutput[]

Defined in

dist/bsv/utils.d.ts:12


findSig

findSig(sigResponses, pubKeyOrAddr, sigHashType?): Sig

Parameters

NameType
sigResponsesSignatureResponse[]
pubKeyOrAddrPublicKey | Address
sigHashType?SignatureHashType

Returns

Sig

Defined in

dist/smart-contract/utils/index.d.ts:7


findSigs

findSigs(sigResponses, queries): Sig[]

Parameters

NameType
sigResponsesSignatureResponse[]
queries(PublicKey | Address | SignatureOption)[]

Returns

Sig[]

Defined in

dist/smart-contract/utils/index.d.ts:8


fromByteString

fromByteString(bs): string

convert ByteString to utf8 string

Parameters

NameTypeDescription
bsByteStringByteString

Returns

string

utf8 string

Defined in

dist/smart-contract/utils/index.d.ts:18


getDummyP2pkhUTXOs

getDummyP2pkhUTXOs(count?): UTXO[]

Parameters

NameType
count?number

Returns

UTXO[]

Defined in

dist/bsv/utils.d.ts:4


getDummySig

getDummySig(): Sig

Returns

Sig

Defined in

dist/smart-contract/utils/index.d.ts:5


getRandomAddress

getRandomAddress(network?): Address

Parameters

NameType
network?Network

Returns

Address

Defined in

dist/bsv/utils.d.ts:5


getSortedItem

getSortedItem<K, V>(collection, k): SortedItem<K>

Type parameters

Name
K
V

Parameters

NameType
collectionMap<K, V> | Set<K>
kK

Returns

SortedItem<K>

Defined in

node_modules/scryptlib/dist/scryptTypes.d.ts:93


invert

invert(a): Int

Parameters

NameType
aInt

Returns

Int

Defined in

node_modules/scryptlib/dist/builtins.d.ts:18


isInNodeEnv

isInNodeEnv(): boolean

Returns

boolean

Defined in

dist/smart-contract/utils/index.d.ts:10


mapIter

mapIter<T>(iterable, callback): Generator<any, void, unknown>

Type parameters

Name
T

Parameters

NameType
iterableIterableIterator<T>
callback(x: any) => any

Returns

Generator<any, void, unknown>

Defined in

dist/smart-contract/utils/index.d.ts:9


or

or(a, b): Int

Parameters

NameType
aInt
bInt

Returns

Int

Defined in

node_modules/scryptlib/dist/builtins.d.ts:16


parseAddresses

parseAddresses(publicKeysOrAddresses, network): AddressOption[]

Parameters

NameType
publicKeysOrAddressesPublicKeysOrAddressesOption
networkNetwork

Returns

AddressOption[]

Defined in

dist/bsv/utils.d.ts:7


parseSignatureOption

parseSignatureOption(signaturesOption, network): { address: AddressOption ; sigHashType: SignatureHashType }[]

Parameters

NameType
signaturesOptionPublicKeysOrAddressesOption | SignaturesOption
networkNetwork

Returns

{ address: AddressOption ; sigHashType: SignatureHashType }[]

Defined in

dist/bsv/utils.d.ts:8


slice

slice(byteString, start, end?): ByteString

Returns a section of a ByteString.

Parameters

NameTypeDescription
byteStringByteStringThe ByteString.
startBigIntThe beginning byte index of the specified portion of ByteString, included.
end?BigIntThe end byte index of the specified portion of ByteString, excluded. If this value is not specified, the sub-section continues to the end of ByteString.

Returns

ByteString

Defined in

dist/smart-contract/builtins/functions.d.ts:11


toByteString

toByteString(literal, isUtf8?): ByteString

Converts a literal to ByteString. If not passing isUtf8 or isUtf8 is false, then literal should be in the format of hex literal, i.e. /^([0-9a-fA-F]{2})*$/ Otherwise, literal should be in the format of utf8 literal, i.e. hello world

Parameters

NameTypeDescription
literalstringliteral string, can be hex literal or utf8 literal, depends on the isUtf8 marker
isUtf8?booleanmarker indicating whether literal is utf8 or hex

Returns

ByteString

Defined in

dist/smart-contract/builtins/types.d.ts:97


toHex

toHex(x): string

Parameters

NameType
xObject
x.toString(format: "hex") => string

Returns

string

Defined in

node_modules/scryptlib/dist/utils.d.ts:18


toNumber

toNumber(sighashType): number

Parameters

NameType
sighashTypeSigHashType

Returns

number

Defined in

dist/smart-contract/utils/index.d.ts:6


utxoFromOutput

utxoFromOutput(tx, outputIndex): UTXO

Parameters

NameType
txTransaction
outputIndexnumber

Returns

UTXO

Defined in

dist/bsv/utils.d.ts:6


xor

xor(a, b): Int

Parameters

NameType
aInt
bInt

Returns

Int

Defined in

node_modules/scryptlib/dist/builtins.d.ts:17


assert Functions

assert

assert(condition, msg?): asserts condition

assert(condition: boolean, errorMsg?: string) Throw an Error with the optional error message if condition is false. Otherwise, nothing happens.

Parameters

NameType
conditionboolean
msg?string

Returns

asserts condition

Defined in

dist/smart-contract/builtins/functions.d.ts:143


decorator Functions

method

method(sigHashType?): (target: any, methodName: string, descriptor: PropertyDescriptor) => PropertyDescriptor

Indicates whether the method is a contract method, and ordinary methods do not affect the execution of the contract

Parameters

NameType
sigHashType?SigHashType

Returns

fn

▸ (target, methodName, descriptor): PropertyDescriptor

Parameters
NameType
targetany
methodNamestring
descriptorPropertyDescriptor
Returns

PropertyDescriptor

Defined in

dist/smart-contract/decorators.d.ts:17


prop

prop(state?): (target: any, propertyName: string) => void

Indicates whether the property is an property of a contract, and ordinary class properties cannot be accessed in contract methods

Parameters

NameTypeDescription
state?booleanWhether the property is a property of a stateful contract

Returns

fn

▸ (target, propertyName): void

Parameters
NameType
targetany
propertyNamestring
Returns

void

Defined in

dist/smart-contract/decorators.d.ts:31