Skip to content

@aldea/sdk / Exports / BCS

Class: BCS

BCS implementation for Aldea builtins and types as defined in an ABI.

Usage

Instantitate BCS with an ABI document. From then, any Jig or function/method args can be encoded/decoded. Methods can be matched using the <JIG_NAME>($|_)<METHOD_NAME> convention, where $ matches an instance method and _ matches a static method.

const bcs = new BCS(abi)

// Encoding Jig state
const encoded = bcs.encode('MyJig', values)
const decoded = bcs.decode('MyJig', encoded)

// Encoding method args
const encoded = bcs.encode('MyJig$update', args)
const decoded = bcs.decode('MyJig$update', encoded)

Optionally a BCS instance can be instantiated with support for serializing and deserializing ABI documents and Package bundles.

const bcs = new BCS({ addAbiTypes: true, addPkgTypes: true })
const encodedAbi = bcs.encode('abi', abi)
const encodedPkg = bcs.encode('pkg', pkg)

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new BCS(abiOrOpts, options?): BCS

Parameters

NameType
abiOrOptsAbi | Partial<BCSOpts>
options?Partial<BCSOpts>

Returns

BCS

Defined in

packages/core/dist/bcs.d.ts:62

Properties

abi

Private Optional abi: any

Defined in

packages/core/dist/bcs.d.ts:59


collectJigFieldTypes

Private collectJigFieldTypes: any

Defined in

packages/core/dist/bcs.d.ts:94


collectMethodArgTypes

Private collectMethodArgTypes: any

Defined in

packages/core/dist/bcs.d.ts:95


decodeType

Private decodeType: any

Defined in

packages/core/dist/bcs.d.ts:91


decodeTypes

Private decodeTypes: any

Defined in

packages/core/dist/bcs.d.ts:90


encodeType

Private encodeType: any

Defined in

packages/core/dist/bcs.d.ts:93


encodeTypes

Private encodeTypes: any

Defined in

packages/core/dist/bcs.d.ts:92


jigNames

Private jigNames: any

Defined in

packages/core/dist/bcs.d.ts:60


registerAbiTypes

Private registerAbiTypes: any

Defined in

packages/core/dist/bcs.d.ts:98


registerMagicTypes

Private registerMagicTypes: any

Defined in

packages/core/dist/bcs.d.ts:97


registerPkgTypes

Private registerPkgTypes: any

Defined in

packages/core/dist/bcs.d.ts:99


registerPrimitiveTypes

Private registerPrimitiveTypes: any

Defined in

packages/core/dist/bcs.d.ts:96


typeEncoders

Private typeEncoders: any

Defined in

packages/core/dist/bcs.d.ts:61


pkg

Static pkg: BCSMini<[string[], Map<string, string>]>

Defined in

packages/core/dist/bcs.d.ts:58

Methods

decode

decode(name, data): any

Decodes the given data using the specified type encoder.

Parameters

NameType
namestring
dataUint8Array

Returns

any

Defined in

packages/core/dist/bcs.d.ts:66


encode

encode(name, val, writer?): Uint8Array

Encoders the given value(s) using the specified type encoder.

Parameters

NameType
namestring
valany
writer?BufWriter

Returns

Uint8Array

Defined in

packages/core/dist/bcs.d.ts:70


getTypeEncoder

getTypeEncoder<T>(name): BCSEncoder<T>

Returns the registered BCSEncoder for the given type name.

Type parameters

Name
T

Parameters

NameType
namestring

Returns

BCSEncoder<T>

Defined in

packages/core/dist/bcs.d.ts:74


registerObjectType

registerObjectType(name, fields): void

Registers the given array of FieldNode's as an object type encoder.

Parameters

NameType
namestring
fieldsFieldNode[]

Returns

void

Defined in

packages/core/dist/bcs.d.ts:82


registerTupleType

registerTupleType(name, types): void

Registers the given array of TypeNode's as a tuple type encoder.

The work tuple is used here to describe a fixed length list of variable types. In terms of Aldea, this would apple to function/method arguments.

Parameters

NameType
namestring
typesTypeNode[]

Returns

void

Defined in

packages/core/dist/bcs.d.ts:89


registerType

registerType<T>(name, encoder): void

Registers the given type encoder.

Type parameters

Name
T

Parameters

NameType
namestring
encoderBCSEncoderInitParams<T>

Returns

void

Defined in

packages/core/dist/bcs.d.ts:78