Methods
destroy()
Cleans up Javascript references associated with this decoder instance.
Does not explicitly free WASM memory. Future calls to this instance will fail.
- Source:
peekCommandDataLength() → {number|null}
Peeks at the header of Command Data in this instance's buffer.
- Source:
Throws:
-
If the decoder instance has been destroyed.
- Type
- Error
Returns:
The payload length, or `null`.
- Type
- number | null
peekPublicKeyListInfo() → {Object|null}
Peeks at the header of a Public Key List field in this instance's buffer.
- Source:
Throws:
-
If the decoder instance has been destroyed.
- Type
- Error
Returns:
Key count and type code, or `null`.
- Type
- Object | null
peekSignatureListInfo() → {Object|null}
Peeks at the header of a Signature List field in this instance's buffer.
- Source:
Throws:
-
If the decoder instance has been destroyed.
- Type
- Error
Returns:
Item count and type code, or `null`.
- Type
- Object | null
peekTag() → {number|null}
Peeks at the tag (first byte, masked) of the next field in this instance's buffer.
- Source:
Throws:
-
If the decoder instance has been destroyed.
- Type
- Error
Returns:
The tag value (e.g., `CTE.CTE_TAG_PUBLIC_KEY_LIST`) or `null` if at EOF/error.
- Type
- number | null
readCommandDataPayload() → {Object|null}
Reads and consumes a Command Data field payload from this instance's buffer.
- Source:
Throws:
-
If read fails, instance destroyed, or memory access fails.
- Type
- Error
Returns:
An object containing the payload bytes as `data`, or `null`.
- Type
- Object | null
readIxDataBoolean()
Reads IxData: Boolean constant. @returns {boolean}
- Source:
readIxDataFloat32()
Reads IxData: Fixed float32. @returns {number}
- Source:
readIxDataFloat64()
Reads IxData: Fixed float64. @returns {number}
- Source:
readIxDataIndexReference()
Reads IxData: Legacy Index Reference (0-15). @returns {number}
- Source:
readIxDataInt16()
Reads IxData: Fixed int16. @returns {number}
- Source:
readIxDataInt32()
Reads IxData: Fixed int32. @returns {number}
- Source:
readIxDataInt64()
Reads IxData: Fixed int64. @returns {bigint}
- Source:
readIxDataInt8()
Reads IxData: Fixed int8. @returns {number}
- Source:
readIxDataSleb128()
Reads IxData: SLEB128 encoded value. @returns {bigint}
- Source:
readIxDataUint16()
Reads IxData: Fixed uint16. @returns {number}
- Source:
readIxDataUint32()
Reads IxData: Fixed uint32. @returns {number}
- Source:
readIxDataUint64()
Reads IxData: Fixed uint64. @returns {bigint}
- Source:
readIxDataUint8()
Reads IxData: Fixed uint8. @returns {number}
- Source:
readIxDataUleb128()
Reads IxData: ULEB128 encoded value. @returns {bigint}
- Source:
readPublicKeyListData() → {Uint8Array|null}
Reads and consumes a Public Key List field from this instance's buffer.
- Source:
Throws:
-
If read fails, instance destroyed, or memory access fails.
- Type
- Error
Returns:
A copy of the key data, or `null`.
- Type
- Uint8Array | null
readSignatureListData() → {Uint8Array|null}
Reads and consumes a Signature List field from this instance's buffer.
- Source:
Throws:
-
If read fails, instance destroyed, or memory access fails.
- Type
- Error
Returns:
A copy of the signature/hash data, or `null`.
- Type
- Uint8Array | null
reset()
Resets the decoder's read position to the beginning of the loaded buffer for this instance.
- Source:
Throws:
-
If the decoder instance has been destroyed.
- Type
- Error
(async, static) create(cteBuffer) → {Promise.<CteDecoder>}
Asynchronously creates and initializes a new, independent CTE decoder instance with the provided data buffer.
Loads and instantiates a fresh copy of the decoder WASM module and copies the input buffer into its memory.
Parameters:
Name | Type | Description |
---|---|---|
cteBuffer |
Uint8Array | The buffer containing the CTE encoded data. Size must not exceed `CTE.CTE_MAX_TRANSACTION_SIZE`. |
- Source:
Throws:
-
If input is invalid, WASM binary/instantiation fails, exports are missing, buffer size is exceeded, or C-level decoder initialization fails.
- Type
- Error
Returns:
A promise that resolves to the initialized CteDecoder instance.
- Type
- Promise.<CteDecoder>
Example
import { CteDecoder } from '@leachain/ctejs-core'; // Use package name
async function main(encodedBytes) {
try {
const decoder = await CteDecoder.create(encodedBytes);
console.log('Decoder ready!');
// Proceed with decoding...
} catch (err) {
console.error("Failed to create decoder:", err);
}
}