airgap-coin-lib
Version:
The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.
87 lines • 4.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var SCALEDecoder_1 = require("../scale/SCALEDecoder");
var SCALEData_1 = require("../scale/type/SCALEData");
var SCALEEnum_1 = require("../scale/type/SCALEEnum");
var SCALEHash_1 = require("../scale/type/SCALEHash");
var SCALEInt_1 = require("../scale/type/SCALEInt");
var SCALETuple_1 = require("../scale/type/SCALETuple");
var SubstrateJudgement;
(function (SubstrateJudgement) {
SubstrateJudgement[SubstrateJudgement["UNKNOWN"] = 0] = "UNKNOWN";
SubstrateJudgement[SubstrateJudgement["FEE_PAID"] = 1] = "FEE_PAID";
SubstrateJudgement[SubstrateJudgement["REASONABLE"] = 2] = "REASONABLE";
SubstrateJudgement[SubstrateJudgement["KNOWN_GOOD"] = 3] = "KNOWN_GOOD";
SubstrateJudgement[SubstrateJudgement["OUT_OF_DATE"] = 4] = "OUT_OF_DATE";
SubstrateJudgement[SubstrateJudgement["LOW_QUALITY"] = 5] = "LOW_QUALITY";
SubstrateJudgement[SubstrateJudgement["ERRORNEOUS"] = 6] = "ERRORNEOUS";
})(SubstrateJudgement || (SubstrateJudgement = {}));
var SubstrateIdentityInfo = /** @class */ (function () {
function SubstrateIdentityInfo(display, legal, web, riot, email, image, twitter) {
this.display = display;
this.legal = legal;
this.web = web;
this.riot = riot;
this.email = email;
this.image = image;
this.twitter = twitter;
}
SubstrateIdentityInfo.decode = function (network, raw) {
var decoder = new SCALEDecoder_1.SCALEDecoder(network, raw);
var additional = decoder.decodeNextArray(function (network, hex) {
return SCALETuple_1.SCALETuple.decode(network, hex, function (_, hex) { return SCALEData_1.SCALEData.decode(hex); }, function (_, hex) { return SCALEData_1.SCALEData.decode(hex); });
});
var display = decoder.decodeNextData();
var legal = decoder.decodeNextData();
var web = decoder.decodeNextData();
var riot = decoder.decodeNextData();
var email = decoder.decodeNextData();
var fingerprint = decoder.decodeNextOptional(function (_, hex) { return SCALEHash_1.SCALEHash.decode(hex, 20); });
var image = decoder.decodeNextData();
var twitter = decoder.decodeNextData();
return {
bytesDecoded: additional.bytesDecoded +
display.bytesDecoded +
legal.bytesDecoded +
web.bytesDecoded +
riot.bytesDecoded +
email.bytesDecoded +
fingerprint.bytesDecoded +
image.bytesDecoded +
twitter.bytesDecoded,
decoded: new SubstrateIdentityInfo(display.decoded, legal.decoded, web.decoded, riot.decoded, email.decoded, image.decoded, twitter.decoded)
};
};
return SubstrateIdentityInfo;
}());
exports.SubstrateIdentityInfo = SubstrateIdentityInfo;
var SubstrateRegistration = /** @class */ (function () {
function SubstrateRegistration(judgements, deposit, identityInfo) {
this.judgements = judgements;
this.deposit = deposit;
this.identityInfo = identityInfo;
}
SubstrateRegistration.decode = function (network, runtimeVersion, raw) {
var decoder = new SCALEDecoder_1.SCALEDecoder(network, raw);
var judgements = decoder.decodeNextArray(function (network, hex) {
return SCALETuple_1.SCALETuple.decode(network, hex, function (_, first) { return SCALEInt_1.SCALEInt.decode(first, 32); }, function (_, second) {
var value = SCALEEnum_1.SCALEEnum.decode(second, function (value) { return SubstrateJudgement[SubstrateJudgement[value]]; });
var bytesDecoded = value.bytesDecoded;
if (value.decoded.value === SubstrateJudgement.FEE_PAID) {
var balance = SCALEInt_1.SCALEInt.decode(second.slice(0, bytesDecoded * 2), 128);
bytesDecoded += balance.bytesDecoded;
}
return {
bytesDecoded: bytesDecoded,
decoded: value.decoded
};
});
});
var deposit = decoder.decodeNextInt(128);
var identityInfo = decoder.decodeNextObject(SubstrateIdentityInfo.decode);
return new SubstrateRegistration(judgements.decoded, deposit.decoded, identityInfo.decoded);
};
return SubstrateRegistration;
}());
exports.SubstrateRegistration = SubstrateRegistration;
//# sourceMappingURL=SubstrateRegistration.js.map