airgap-coin-lib
Version:
The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.
78 lines • 4.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var hex_1 = require("../../../../../utils/hex");
var SCALEAccountId_1 = require("./type/SCALEAccountId");
var SCALEArray_1 = require("./type/SCALEArray");
var SCALEBoolean_1 = require("./type/SCALEBoolean");
var SCALEBytes_1 = require("./type/SCALEBytes");
var SCALECompactInt_1 = require("./type/SCALECompactInt");
var SCALEData_1 = require("./type/SCALEData");
var SCALEEnum_1 = require("./type/SCALEEnum");
var SCALEEra_1 = require("./type/SCALEEra");
var SCALEHash_1 = require("./type/SCALEHash");
var SCALEInt_1 = require("./type/SCALEInt");
var SCALEOptional_1 = require("./type/SCALEOptional");
var SCALEString_1 = require("./type/SCALEString");
var SCALETuple_1 = require("./type/SCALETuple");
var SCALEDecoder = /** @class */ (function () {
function SCALEDecoder(network, bytes) {
this.network = network;
this.hex = typeof bytes === 'string' ? hex_1.stripHexPrefix(bytes) : Buffer.from(bytes).toString('hex');
}
SCALEDecoder.prototype.decodeNextAccountId = function () {
return this.decodeNextValue(SCALEAccountId_1.SCALEAccountId.decode);
};
SCALEDecoder.prototype.decodeNextArray = function (decoderMethod) {
return this.decodeNextValue(function (network, hex) { return SCALEArray_1.SCALEArray.decode(network, hex, decoderMethod); });
};
SCALEDecoder.prototype.decodeNextBoolean = function () {
return this.decodeNextValuePartial(SCALEBoolean_1.SCALEBoolean.decode);
};
SCALEDecoder.prototype.decodeNextBytes = function () {
return this.decodeNextValuePartial(SCALEBytes_1.SCALEBytes.decode);
};
SCALEDecoder.prototype.decodeNextCompactInt = function () {
return this.decodeNextValuePartial(SCALECompactInt_1.SCALECompactInt.decode);
};
SCALEDecoder.prototype.decodeNextEra = function () {
return this.decodeNextValuePartial(SCALEEra_1.SCALEEra.decode);
};
SCALEDecoder.prototype.decodeNextHash = function (bitLength) {
return this.decodeNextValue(function (_, hex) { return SCALEHash_1.SCALEHash.decode(hex, bitLength); });
};
SCALEDecoder.prototype.decodeNextInt = function (bitLength) {
return this.decodeNextValue(function (_, hex) { return SCALEInt_1.SCALEInt.decode(hex, bitLength); });
};
SCALEDecoder.prototype.decodeNextOptional = function (decoderMethod) {
return this.decodeNextValue(function (network, hex) { return SCALEOptional_1.SCALEOptional.decode(network, hex, decoderMethod); });
};
SCALEDecoder.prototype.decodeNextString = function () {
return this.decodeNextValuePartial(SCALEString_1.SCALEString.decode);
};
SCALEDecoder.prototype.decodeNextTuple = function (firstDecoderMethod, secondDecoderMethod) {
return this.decodeNextValue(function (network, hex) { return SCALETuple_1.SCALETuple.decode(network, hex, firstDecoderMethod, secondDecoderMethod); });
};
SCALEDecoder.prototype.decodeNextEnum = function (getEnumValue) {
return this.decodeNextValue(function (_, hex) { return SCALEEnum_1.SCALEEnum.decode(hex, getEnumValue); });
};
SCALEDecoder.prototype.decodeNextData = function () {
return this.decodeNextValue(function (_, hex) { return SCALEData_1.SCALEData.decode(hex); });
};
SCALEDecoder.prototype.decodeNextObject = function (decoderMethod) {
return this.decodeNextValue(decoderMethod);
};
SCALEDecoder.prototype.decodeNextValuePartial = function (decoderPartialMethod, nibbleLength) {
return this.decodeNextValue(function (_, hex) { return decoderPartialMethod(hex); }, nibbleLength);
};
SCALEDecoder.prototype.decodeNextValue = function (decoderMethod, nibbleLength) {
var decoded = decoderMethod(this.network, this.hex.substr(0, nibbleLength));
this.moveCursor(decoded.bytesDecoded);
return decoded;
};
SCALEDecoder.prototype.moveCursor = function (bytes) {
this.hex = this.hex.slice(bytes * 2);
};
return SCALEDecoder;
}());
exports.SCALEDecoder = SCALEDecoder;
//# sourceMappingURL=SCALEDecoder.js.map