UNPKG

airgap-coin-lib

Version:

The airgap-coin-lib is a protocol agnostic library to prepare, sign and broadcast cryptocurrency transactions.

65 lines 3.04 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var SCALEDecoder_1 = require("../scale/SCALEDecoder"); var SCALEClass_1 = require("../scale/type/SCALEClass"); var SCALEEnum_1 = require("../scale/type/SCALEEnum"); var SCALEHash_1 = require("../scale/type/SCALEHash"); var SIGNATURE_BITS = 64 * 8; // 64 bytes var SubstrateSignatureType; (function (SubstrateSignatureType) { SubstrateSignatureType[SubstrateSignatureType["Ed25519"] = 0] = "Ed25519"; SubstrateSignatureType[SubstrateSignatureType["Sr25519"] = 1] = "Sr25519"; SubstrateSignatureType[SubstrateSignatureType["Ecdsa"] = 2] = "Ecdsa"; })(SubstrateSignatureType = exports.SubstrateSignatureType || (exports.SubstrateSignatureType = {})); var SubstrateSignature = /** @class */ (function (_super) { __extends(SubstrateSignature, _super); function SubstrateSignature(type, signature) { var _this = _super.call(this) || this; _this.type = type; _this.signature = signature; _this.scaleFields = [_this.type, _this.signature]; return _this; } SubstrateSignature.create = function (type, signature) { return new SubstrateSignature(SCALEEnum_1.SCALEEnum.from(type), signature ? SCALEHash_1.SCALEHash.from(signature) : SCALEHash_1.SCALEHash.empty(SIGNATURE_BITS)); }; SubstrateSignature.decode = function (network, raw) { var decoder = new SCALEDecoder_1.SCALEDecoder(network, raw); var type = decoder.decodeNextEnum(function (value) { return SubstrateSignatureType[SubstrateSignatureType[value]]; }); var signature = decoder.decodeNextHash(SIGNATURE_BITS); return { bytesDecoded: type.bytesDecoded + signature.bytesDecoded, decoded: new SubstrateSignature(type.decoded, signature.decoded) }; }; Object.defineProperty(SubstrateSignature.prototype, "isSigned", { get: function () { return !this.signature.isEmpty; }, enumerable: true, configurable: true }); SubstrateSignature.prototype.toString = function () { return JSON.stringify({ type: SubstrateSignatureType[this.type.value], isSigned: this.isSigned, signature: this.signature.toString() }, null, 2); }; return SubstrateSignature; }(SCALEClass_1.SCALEClass)); exports.SubstrateSignature = SubstrateSignature; //# sourceMappingURL=SubstrateSignature.js.map