@swtc/serializer
Version:
swtc serializer
28 lines • 1.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bn_plus_js_1 = __importDefault(require("bn-plus.js"));
const Utils_1 = require("../Utils");
const SerializedType_1 = __importDefault(require("./SerializedType"));
const STHash128 = new SerializedType_1.default({
id: 4,
serialize(so, val) {
// const hash = UInt128.from_json(val);
// if (isString(val) && /^[0-9A-F]{32}$/i.test(val)) {
// what situation from latest lib-guomi
if ((0, Utils_1.isString)(val) && /^[0-9A-F]{0,64}$/i.test(val) && val.length <= 32) {
(0, Utils_1.serializeHex)(so, val, true); // noLength = true
}
else {
throw new Error("Invalid Hash128");
}
},
parse(so) {
const val = so.read(16);
return new bn_plus_js_1.default([0].concat(val), 256).toString(16).toUpperCase();
}
});
exports.default = STHash128;
//# sourceMappingURL=STHash128.js.map