@mavrykdynamics/taquito-local-forging
Version:
Provide local forging functionality to be with taquito
36 lines (35 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Uint8ArrayConsumer = void 0;
const taquito_core_1 = require("@mavrykdynamics/taquito-core");
class Uint8ArrayConsumer {
static fromHexString(hex) {
const lowHex = hex.toLowerCase();
if (/^(([a-f]|\d){2})*$/.test(lowHex)) {
const arr = new Uint8Array((lowHex.match(/([a-z]|\d){2}/g) || []).map((byte) => parseInt(byte, 16)));
return new Uint8ArrayConsumer(arr);
}
else {
throw new taquito_core_1.InvalidHexStringError(lowHex);
}
}
constructor(arr, offset = 0) {
this.arr = arr;
this.offset = offset;
}
consume(count) {
const subArr = this.arr.subarray(this.offset, this.offset + count);
this.offset += count;
return subArr;
}
get(idx) {
return this.arr[this.offset + idx];
}
length() {
return this.arr.length - this.offset;
}
slice(start, end) {
return new Uint8ArrayConsumer(this.arr.slice(start, end));
}
}
exports.Uint8ArrayConsumer = Uint8ArrayConsumer;