@nervosnetwork/ckb-sdk-utils
Version:
Utils module of @nervosnetwork/ckb-sdk-core
30 lines • 1.19 kB
JavaScript
import { serializeArray, serializeTable, serializeFixVec } from './basic.js';
import { ParameterRequiredException } from '../exceptions/index.js';
export const serializeCodeHash = (codeHash) => serializeArray(codeHash);
export const serializeHashType = (hashType) => {
if (hashType === 'data')
return '0x00';
if (hashType === 'type')
return '0x01';
if (hashType === 'data1')
return '0x02';
if (hashType === 'data2')
return '0x04';
throw new TypeError("Hash type must be either of 'data' or 'type'");
};
export const serializeArgs = (args) => serializeFixVec(args);
export const serializeScript = (script) => {
if (!script)
throw new ParameterRequiredException('Script');
const { codeHash = '', hashType, args = '' } = script;
const serializedCodeHash = serializeCodeHash(codeHash);
const serializedHashType = serializeHashType(hashType);
const serializedArgs = serializeArgs(args);
const table = new Map([
['codeHash', serializedCodeHash],
['hashType', serializedHashType],
['args', serializedArgs],
]);
return serializeTable(table);
};
//# sourceMappingURL=script.js.map