@ckb-lumos/toolkit
Advanced tools
Comparing version 0.20.0 to 0.21.0-next.0
@@ -13,23 +13,13 @@ "use strict"; | ||
exports.validators = exports.transformers = exports.normalizers = exports.VERSION = void 0; | ||
var _reader = require("./reader.js"); | ||
var _normalizers = _interopRequireWildcard(require("./normalizers")); | ||
exports.normalizers = _normalizers; | ||
var _transformers = _interopRequireWildcard(require("./transformers")); | ||
exports.transformers = _transformers; | ||
var _validators = _interopRequireWildcard(require("./validators")); | ||
exports.validators = _validators; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const VERSION = "__development_build__"; | ||
exports.VERSION = VERSION; | ||
//# sourceMappingURL=index.js.map |
@@ -19,9 +19,5 @@ "use strict"; | ||
exports.NormalizeWitnessArgs = NormalizeWitnessArgs; | ||
var _jsbi = _interopRequireDefault(require("jsbi")); | ||
var _reader = require("./reader"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// This package provides normalizer functions. Even though CKB uses molecule | ||
@@ -47,13 +43,9 @@ // as the serialization layer. There is still CKB specific knowledge that does | ||
let intValue = _jsbi.default.BigInt(value).toString(16); | ||
if (intValue.length % 2 !== 0) { | ||
intValue = "0" + intValue; | ||
} | ||
if (intValue.length / 2 > length) { | ||
throw new Error(`${debugPath} is ${intValue.length / 2} bytes long, expected length is ${length}!`); | ||
} | ||
const view = new DataView(new ArrayBuffer(length)); | ||
for (let i = 0; i < intValue.length / 2; i++) { | ||
@@ -63,6 +55,4 @@ const start = intValue.length - (i + 1) * 2; | ||
} | ||
value = view.buffer; | ||
} | ||
if (value.byteLength < length) { | ||
@@ -73,3 +63,2 @@ const array = new Uint8Array(length); | ||
} | ||
return value; | ||
@@ -81,12 +70,8 @@ }; | ||
*/ | ||
function normalizeRawData(length) { | ||
return function (debugPath, value) { | ||
value = new _reader.Reader(value).toArrayBuffer(); | ||
if (length > 0 && value.byteLength !== length) { | ||
throw new Error(`${debugPath} has invalid length ${value.byteLength}, required: ${length}`); | ||
} | ||
return value; | ||
@@ -98,17 +83,11 @@ }; | ||
*/ | ||
function normalizeObject(debugPath, object, keys) { | ||
const result = {}; | ||
for (const [key, f] of Object.entries(keys)) { | ||
const value = object[key]; | ||
if (!value) { | ||
throw new Error(`${debugPath} is missing ${key}!`); | ||
} | ||
result[key] = f(`${debugPath}.${key}`, value); | ||
} | ||
return result; | ||
@@ -119,4 +98,2 @@ } | ||
*/ | ||
function NormalizeScript(script, { | ||
@@ -131,18 +108,12 @@ debugPath = "script" | ||
return 0; | ||
case "type": | ||
return 1; | ||
case "data1": | ||
return 2; | ||
case 0: | ||
return value; | ||
case 1: | ||
return value; | ||
case 2: | ||
return value; | ||
default: | ||
@@ -158,4 +129,2 @@ throw new Error(`${debugPath}.hashType has invalid value: ${value}`); | ||
*/ | ||
function NormalizeOutPoint(outPoint, { | ||
@@ -172,4 +141,2 @@ debugPath = "outPoint" | ||
*/ | ||
function toNormalize(normalize) { | ||
@@ -185,4 +152,2 @@ return function (debugPath, value) { | ||
*/ | ||
function NormalizeCellInput(cellInput, { | ||
@@ -199,4 +164,2 @@ debugPath = "cell_input" | ||
*/ | ||
function NormalizeCellOutput(cellOutput, { | ||
@@ -209,3 +172,2 @@ debugPath = "cellOutput" | ||
}); | ||
if (cellOutput.type) { | ||
@@ -216,3 +178,2 @@ result.type_ = NormalizeScript(cellOutput.type, { | ||
} | ||
return result; | ||
@@ -223,4 +184,2 @@ } | ||
*/ | ||
function NormalizeCellDep(cellDep, { | ||
@@ -235,12 +194,8 @@ debugPath = "cell_dep" | ||
return 0; | ||
case "depGroup": | ||
return 1; | ||
case 0: | ||
return value; | ||
case 1: | ||
return value; | ||
default: | ||
@@ -255,4 +210,2 @@ throw new Error(`${debugPath}.depType has invalid value: ${value}`); | ||
*/ | ||
function toNormalizeArray(normalizeFunction) { | ||
@@ -268,4 +221,2 @@ return function (debugPath, array) { | ||
*/ | ||
function NormalizeRawTransaction(rawTransaction, { | ||
@@ -286,4 +237,2 @@ debugPath = "raw_transaction" | ||
*/ | ||
function NormalizeTransaction(transaction, { | ||
@@ -304,4 +253,2 @@ debugPath = "transaction" | ||
*/ | ||
function NormalizeRawHeader(rawHeader, { | ||
@@ -326,4 +273,2 @@ debugPath = "raw_header" | ||
*/ | ||
function NormalizeHeader(header, { | ||
@@ -344,4 +289,2 @@ debugPath = "header" | ||
*/ | ||
function NormalizeUncleBlock(uncleBlock, { | ||
@@ -358,4 +301,2 @@ debugPath = "uncle_block" | ||
*/ | ||
function NormalizeBlock(block, { | ||
@@ -374,4 +315,2 @@ debugPath = "block" | ||
*/ | ||
function NormalizeCellbaseWitness(cellbaseWitness, { | ||
@@ -388,4 +327,2 @@ debugPath = "cellbase_witness" | ||
*/ | ||
function NormalizeWitnessArgs(witnessArgs, { | ||
@@ -395,17 +332,13 @@ debugPath = "witness_args" | ||
const result = {}; | ||
if (witnessArgs.lock) { | ||
result.lock = normalizeRawData(-1)(`${debugPath}.lock`, witnessArgs.lock); | ||
} | ||
if (witnessArgs.inputType) { | ||
result.inputType = normalizeRawData(-1)(`${debugPath}.inputType`, witnessArgs.inputType); | ||
} | ||
if (witnessArgs.outputType) { | ||
result.outputType = normalizeRawData(-1)(`${debugPath}.outputType`, witnessArgs.outputType); | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=normalizers.js.map |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.Reader = void 0; | ||
class BaseReader { | ||
@@ -24,3 +23,2 @@ constructor() { | ||
} | ||
static isReader(x) { | ||
@@ -31,5 +29,3 @@ if (x == null) return false; | ||
} | ||
} | ||
class ArrayBufferReader extends BaseReader { | ||
@@ -40,21 +36,15 @@ constructor(buffer) { | ||
} | ||
length() { | ||
return this.view.byteLength; | ||
} | ||
indexAt(i) { | ||
return this.view.getUint8(i); | ||
} | ||
toArrayBuffer() { | ||
return this.view.buffer; | ||
} | ||
serializeJson() { | ||
return "0x" + Array.prototype.map.call(new Uint8Array(this.view.buffer), x => ("00" + x.toString(16)).slice(-2)).join(""); | ||
} | ||
} | ||
class HexStringReader extends BaseReader { | ||
@@ -65,26 +55,19 @@ constructor(string) { | ||
} | ||
length() { | ||
return this.string.length / 2 - 1; | ||
} | ||
indexAt(i) { | ||
return parseInt(this.string.substr(2 + i * 2, 2), 16); | ||
} | ||
toArrayBuffer() { | ||
const buffer = new ArrayBuffer(this.length()); | ||
const view = new DataView(buffer); | ||
for (let i = 0; i < this.length(); i++) { | ||
view.setUint8(i, this.indexAt(i)); | ||
} | ||
return buffer; | ||
} | ||
serializeJson() { | ||
return this.string; | ||
} | ||
} | ||
@@ -94,12 +77,8 @@ /** | ||
*/ | ||
class Reader extends BaseReader { | ||
constructor(input) { | ||
super(); | ||
if (input instanceof HexStringReader || input instanceof ArrayBufferReader) { | ||
return input; | ||
} | ||
if (typeof input === "string") { | ||
@@ -109,41 +88,29 @@ if (!input.startsWith("0x") || input.length % 2 !== 0) { | ||
} | ||
return new HexStringReader(input); | ||
} | ||
if (input instanceof ArrayBuffer) { | ||
return new ArrayBufferReader(input); | ||
} | ||
if (input instanceof Uint8Array) { | ||
return new ArrayBufferReader(Uint8Array.from(input).buffer); | ||
} | ||
throw new Error("Reader can only accept hex string or ArrayBuffer!"); | ||
} | ||
static from(x) { | ||
return new Reader(x); | ||
} | ||
static fromRawString(string) { | ||
const buffer = new ArrayBuffer(string.length); | ||
const view = new DataView(buffer); | ||
for (let i = 0; i < string.length; i++) { | ||
const c = string.charCodeAt(i); | ||
if (c > 0xff) { | ||
throw new Error("fromRawString can only accept UTF-8 raw string!"); | ||
} | ||
view.setUint8(i, c); | ||
} | ||
return new ArrayBufferReader(buffer); | ||
} | ||
} | ||
exports.Reader = Reader; | ||
//# sourceMappingURL=reader.js.map |
@@ -18,9 +18,5 @@ "use strict"; | ||
exports.TransformWitnessArgs = TransformWitnessArgs; | ||
var validators = _interopRequireWildcard(require("./validators")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
// This package provides transformer functions that transform JavaScript objects | ||
@@ -44,2 +40,3 @@ // into JSON ready objects that can be passed to RPC. It following the following | ||
// here will transform them to valid hex strings required by CKB. | ||
function invokeSerializeJson(debugPath, value) { | ||
@@ -49,18 +46,12 @@ if (value instanceof Object && value.serializeJson instanceof Function) { | ||
} | ||
return value; | ||
} | ||
function transformObject(debugPath, object, keys) { | ||
object = invokeSerializeJson(debugPath, object); | ||
if (!(object instanceof Object)) { | ||
throw new Error(`Transformed ${debugPath} is not an object!`); | ||
} | ||
const result = {}; | ||
for (const [key, f] of Object.entries(keys)) { | ||
let value = object[key]; | ||
if (!value) { | ||
@@ -70,3 +61,2 @@ const camelKey = key.replace(/(_[a-z])/g, group => group.toUpperCase().replace("_", "")); | ||
} | ||
if (value) { | ||
@@ -76,3 +66,2 @@ result[key] = f(`${debugPath}.${key}`, value); | ||
} | ||
return result; | ||
@@ -83,4 +72,2 @@ } | ||
*/ | ||
function TransformScript(script, { | ||
@@ -95,3 +82,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -102,3 +88,2 @@ validators.ValidateScript(script, { | ||
} | ||
return script; | ||
@@ -109,4 +94,2 @@ } | ||
*/ | ||
function TransformOutPoint(outPoint, { | ||
@@ -120,3 +103,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -127,6 +109,4 @@ validators.ValidateOutPoint(outPoint, { | ||
} | ||
return outPoint; | ||
} | ||
function toInvoke(transform) { | ||
@@ -143,4 +123,2 @@ return function (debugPath, value) { | ||
*/ | ||
function TransformCellInput(cellInput, { | ||
@@ -154,3 +132,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -161,3 +138,2 @@ validators.ValidateCellInput(cellInput, { | ||
} | ||
return cellInput; | ||
@@ -168,4 +144,2 @@ } | ||
*/ | ||
function TransformCellOutput(cellOutput, { | ||
@@ -180,3 +154,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -187,3 +160,2 @@ validators.ValidateCellOutput(cellOutput, { | ||
} | ||
return cellOutput; | ||
@@ -194,8 +166,5 @@ } | ||
*/ | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformCellDep(cellDep, { | ||
@@ -209,3 +178,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -216,6 +184,4 @@ validators.ValidateCellDep(cellDep, { | ||
} | ||
return cellDep; | ||
} | ||
function toInvokeArray(invokeFunction) { | ||
@@ -228,7 +194,6 @@ return function (debugPath, array) { | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformRawTransaction(rawTransaction, { | ||
@@ -246,3 +211,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -253,10 +217,8 @@ validators.ValidateRawTransaction(rawTransaction, { | ||
} | ||
return rawTransaction; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformTransaction(transaction, { | ||
@@ -275,3 +237,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -282,10 +243,8 @@ validators.ValidateTransaction(transaction, { | ||
} | ||
return transaction; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformRawHeader(rawHeader, { | ||
@@ -307,3 +266,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -314,10 +272,8 @@ validators.ValidateRawHeader(rawHeader, { | ||
} | ||
return rawHeader; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformHeader(header, { | ||
@@ -340,3 +296,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -347,10 +302,8 @@ validators.ValidateHeader(header, { | ||
} | ||
return header; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformUncleBlock(uncleBlock, { | ||
@@ -364,3 +317,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -371,10 +323,8 @@ validators.ValidateUncleBlock(uncleBlock, { | ||
} | ||
return uncleBlock; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformBlock(block, { | ||
@@ -390,3 +340,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -397,10 +346,8 @@ validators.ValidateBlock(block, { | ||
} | ||
return block; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformCellbaseWitness(cellbaseWitness, { | ||
@@ -414,3 +361,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -421,10 +367,8 @@ validators.ValidateCellbaseWitness(cellbaseWitness, { | ||
} | ||
return cellbaseWitness; | ||
} | ||
/** | ||
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide} | ||
*/ | ||
function TransformWitnessArgs(witnessArgs, { | ||
@@ -439,3 +383,2 @@ validation = true, | ||
}); | ||
if (validation) { | ||
@@ -446,5 +389,4 @@ validators.ValidateWitnessArgs(witnessArgs, { | ||
} | ||
return witnessArgs; | ||
} | ||
//# sourceMappingURL=transformers.js.map |
@@ -19,3 +19,2 @@ "use strict"; | ||
exports.ValidateWitnessArgs = ValidateWitnessArgs; | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
@@ -25,2 +24,3 @@ // This package provides validator functions that check JSON objects are | ||
// directly | ||
function assertObject(debugPath, object) { | ||
@@ -31,3 +31,2 @@ if (!(object instanceof Object)) { | ||
} | ||
function assertObjectWithKeys(debugPath, object, expectedKeys, optionalKeys = []) { | ||
@@ -39,13 +38,9 @@ assertObject(debugPath, object); | ||
const errorMessage = `${debugPath} does not have correct keys! Required keys: [${expectedKeys.sort().join(", ")}], optional keys: [${optionalKeys.sort().join(", ")}], actual keys: [${providedKeys.join(", ")}]`; | ||
if (providedKeys.length < requiredLength || providedKeys.length > maximalLength) { | ||
throw new Error(errorMessage); | ||
} | ||
let optionalProvidedKeys = providedKeys.filter(key => !expectedKeys.includes(key)); | ||
if (providedKeys.length - optionalProvidedKeys.length !== requiredLength) { | ||
throw new Error(errorMessage); | ||
} | ||
if (optionalProvidedKeys.find(key => !optionalKeys.includes(key))) { | ||
@@ -55,3 +50,2 @@ throw new Error(errorMessage); | ||
} | ||
function assertHexString(debugPath, string) { | ||
@@ -62,6 +56,4 @@ if (!/^0x([0-9a-fA-F][0-9a-fA-F])*$/.test(string)) { | ||
} | ||
function assertHash(debugPath, hash) { | ||
assertHexString(debugPath, hash); | ||
if (hash.length !== 66) { | ||
@@ -71,3 +63,2 @@ throw new Error(`${debugPath} must be a hex string of 66 bytes long!`); | ||
} | ||
function assertInteger(debugPath, i) { | ||
@@ -77,3 +68,2 @@ if (i === "0x0") { | ||
} | ||
if (!/^0x[1-9a-fA-F][0-9a-fA-F]*$/.test(i)) { | ||
@@ -83,3 +73,2 @@ throw new Error(`${debugPath} must be a hex integer!`); | ||
} | ||
function ValidateScript(script, { | ||
@@ -92,3 +81,2 @@ nestedValidation = true, | ||
assertHexString(`${debugPath}.args`, script.args); | ||
if (script.hashType !== "data" && script.hashType !== "type" && script.hashType !== "data1") { | ||
@@ -98,3 +86,2 @@ throw new Error(`${debugPath}.hashType must be either data or type!`); | ||
} | ||
function ValidateOutPoint(outPoint, { | ||
@@ -108,3 +95,2 @@ nestedValidation = true, | ||
} | ||
function ValidateCellInput(cellInput, { | ||
@@ -116,3 +102,2 @@ nestedValidation = true, | ||
assertInteger(`${debugPath}.since`, cellInput.since); | ||
if (nestedValidation) { | ||
@@ -124,3 +109,2 @@ ValidateOutPoint(cellInput.previousOutput, { | ||
} | ||
function ValidateCellOutput(cellOutput, { | ||
@@ -132,3 +116,2 @@ nestedValidation = true, | ||
assertInteger(`${debugPath}.capacity`, cellOutput.capacity); | ||
if (nestedValidation) { | ||
@@ -138,3 +121,2 @@ ValidateScript(cellOutput.lock, { | ||
}); | ||
if (cellOutput.type) { | ||
@@ -147,3 +129,2 @@ ValidateScript(cellOutput.type, { | ||
} | ||
function ValidateCellDep(cellDep, { | ||
@@ -154,7 +135,5 @@ nestedValidation = true, | ||
assertObjectWithKeys(debugPath, cellDep, ["outPoint", "depType"], []); | ||
if (cellDep.depType !== "code" && cellDep.depType !== "depGroup") { | ||
throw new Error(`${debugPath}.depType must be either code or depGroup!`); | ||
} | ||
if (nestedValidation) { | ||
@@ -166,3 +145,2 @@ ValidateOutPoint(cellDep.outPoint, { | ||
} | ||
function assertArray(debugPath, array, validateFunction, nestedValidation) { | ||
@@ -172,3 +150,2 @@ if (!Array.isArray(array)) { | ||
} | ||
if (nestedValidation) { | ||
@@ -180,3 +157,2 @@ for (let i = 0; i < array.length; i++) { | ||
} | ||
function toAssert(validateFunction, nestedValidation) { | ||
@@ -190,3 +166,2 @@ return function (debugPath, value) { | ||
} | ||
function assertCommonTransaction(debugPath, rawTransaction, nestedValidation) { | ||
@@ -200,3 +175,2 @@ assertInteger(`${debugPath}.version`, rawTransaction.version); | ||
} | ||
function ValidateRawTransaction(rawTransaction, { | ||
@@ -209,3 +183,2 @@ nestedValidation = true, | ||
} | ||
function ValidateTransaction(transaction, { | ||
@@ -219,3 +192,2 @@ nestedValidation = true, | ||
} | ||
function assertCommonHeader(debugPath, rawHeader) { | ||
@@ -233,3 +205,2 @@ assertInteger(`${debugPath}.version`, rawHeader.version); | ||
} | ||
function ValidateRawHeader(rawHeader, { | ||
@@ -242,3 +213,2 @@ nestedValidation = true, | ||
} | ||
function ValidateHeader(header, { | ||
@@ -250,3 +220,2 @@ nestedValidation = true, | ||
assertHexString(`${debugPath}.nonce`, header.nonce); | ||
if (header.nonce.length !== 34) { | ||
@@ -256,6 +225,4 @@ throw new Error(`${debugPath}.nonce must be a hex string of 34 bytes long!`); | ||
} | ||
function assertProposalShortId(debugPath, shortId) { | ||
assertHexString(debugPath, shortId); | ||
if (shortId.length !== 22) { | ||
@@ -265,3 +232,2 @@ throw new Error(`${debugPath} must be a hex string of 22 bytes long!`); | ||
} | ||
function ValidateUncleBlock(uncleBlock, { | ||
@@ -272,3 +238,2 @@ nestedValidation = true, | ||
assertObjectWithKeys(debugPath, uncleBlock, ["header", "proposals"], []); | ||
if (nestedValidation) { | ||
@@ -279,6 +244,4 @@ ValidateHeader(uncleBlock.header, { | ||
} | ||
assertArray(`${debugPath}.proposals`, uncleBlock.proposals, assertProposalShortId, nestedValidation); | ||
} | ||
function ValidateBlock(block, { | ||
@@ -289,3 +252,2 @@ nestedValidation = true, | ||
assertObjectWithKeys(debugPath, block, ["header", "uncles", "transactions", "proposals"], []); | ||
if (nestedValidation) { | ||
@@ -296,3 +258,2 @@ ValidateHeader(block.header, { | ||
} | ||
assertArray(`${debugPath}.uncles`, block.uncles, toAssert(ValidateUncleBlock, nestedValidation), nestedValidation); | ||
@@ -302,3 +263,2 @@ assertArray(`${debugPath}.transactions`, block.transactions, toAssert(ValidateTransaction, nestedValidation), nestedValidation); | ||
} | ||
function ValidateCellbaseWitness(cellbaseWitness, { | ||
@@ -310,3 +270,2 @@ nestedValidation = true, | ||
assertHexString(`${debugPath}.message`, cellbaseWitness.message); | ||
if (nestedValidation) { | ||
@@ -318,3 +277,2 @@ ValidateScript(cellbaseWitness.lock, { | ||
} | ||
function ValidateWitnessArgs(witnessArgs, { | ||
@@ -325,11 +283,8 @@ nestedValidation = true, | ||
assertObjectWithKeys(debugPath, witnessArgs, [], ["lock", "inputType", "outputType"]); | ||
if (witnessArgs.lock) { | ||
assertHexString(`${debugPath}.lock`, witnessArgs.lock); | ||
} | ||
if (witnessArgs.inputType) { | ||
assertHexString(`${debugPath}.inputType`, witnessArgs.inputType); | ||
} | ||
if (witnessArgs.outputType) { | ||
@@ -336,0 +291,0 @@ assertHexString(`${debugPath}.outputType`, witnessArgs.outputType); |
{ | ||
"name": "@ckb-lumos/toolkit", | ||
"version": "0.20.0", | ||
"version": "0.21.0-next.0", | ||
"description": "JavaScript toolkits used to build dapps for Nervos CKB", | ||
@@ -18,11 +18,2 @@ "main": "lib/index.js", | ||
], | ||
"scripts": { | ||
"build": "yarn run build:js", | ||
"build:js": "babel -s --plugins @babel/plugin-proposal-export-namespace-from --plugins @babel/plugin-transform-modules-commonjs src --out-dir lib", | ||
"clean": "rm -rf lib", | ||
"test": "ava", | ||
"fmt": "prettier --write \"{src,tests}/**/*.js\"", | ||
"lint": "eslint -c ../../.eslintrc.js \"{src,tests}/**/*.js\"", | ||
"update-test-files": "curl -L https://raw.githubusercontent.com/nervosnetwork/ckb/5a7efe7a0b720de79ff3761dc6e8424b8d5b22ea/util/types/schemas/blockchain.mol -o testfiles/blockchain.mol && moleculec --language - --schema-file testfiles/blockchain.mol --format json > testfiles/blockchain.json && moleculec-es -inputFile testfiles/blockchain.json -outputFile testfiles/blockchain.esm.js && rollup -f umd -i testfiles/blockchain.esm.js -o testfiles/blockchain.umd.js --name Blockchain && rm testfiles/blockchain.mol testfiles/blockchain.json testfiles/blockchain.esm.js" | ||
}, | ||
"author": "Xuejie Xiao", | ||
@@ -37,3 +28,16 @@ "license": "MIT", | ||
}, | ||
"gitHead": "28756be37c312eca132cac0c00b40510803030e0" | ||
} | ||
"devDependencies": { | ||
"@babel/plugin-proposal-export-namespace-from": "^7.18.9", | ||
"@babel/plugin-transform-modules-commonjs": "^7.21.5", | ||
"jsbi": "^4.1.0" | ||
}, | ||
"scripts": { | ||
"build": "pnpm run build:js", | ||
"build:js": "babel -s --plugins @babel/plugin-proposal-export-namespace-from --plugins @babel/plugin-transform-modules-commonjs src --out-dir lib", | ||
"clean": "rm -rf lib", | ||
"test": "ava", | ||
"fmt": "prettier --write \"{src,tests}/**/*.js\"", | ||
"lint": "eslint -c ../../.eslintrc.js \"{src,tests}/**/*.js\"", | ||
"update-test-files": "curl -L https://raw.githubusercontent.com/nervosnetwork/ckb/5a7efe7a0b720de79ff3761dc6e8424b8d5b22ea/util/types/schemas/blockchain.mol -o testfiles/blockchain.mol && moleculec --language - --schema-file testfiles/blockchain.mol --format json > testfiles/blockchain.json && moleculec-es -inputFile testfiles/blockchain.json -outputFile testfiles/blockchain.esm.js && rollup -f umd -i testfiles/blockchain.esm.js -o testfiles/blockchain.umd.js --name Blockchain && rm testfiles/blockchain.mol testfiles/blockchain.json testfiles/blockchain.esm.js" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
155229
3