UNPKG

eosjs-signature-provider-interface

Version:

An abstract class that implements the EOSJS SignatureProvider interface, and provides helper methods for interacting with an authenticator using the EOSIO Authentication Transport Protocol Specification.

47 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var instanceOf_1 = require("./instanceOf"); var interfaces_1 = require("./interfaces"); exports.packEnvelope = function (envelope) { return exports.hexEncode(JSON.stringify(envelope)); }; exports.unpackEnvelope = function (packedEnvelope) { return JSON.parse(exports.hexDecode(packedEnvelope)); }; exports.envelopeDataType = function (envelope) { if (!instanceOf_1.instanceOfRequestEnvelope(envelope) && !instanceOf_1.instanceOfResponseEnvelope(envelope)) { return null; } var data = instanceOf_1.instanceOfRequestEnvelope(envelope) ? envelope.request : envelope.response; if (interfaces_1.EnvelopeDataType.SELECTIVE_DISCLOSURE in data) { return interfaces_1.EnvelopeDataType.SELECTIVE_DISCLOSURE; } else if (interfaces_1.EnvelopeDataType.TRANSACTION_SIGNATURE in data) { return interfaces_1.EnvelopeDataType.TRANSACTION_SIGNATURE; } return null; }; exports.arrayToHex = function (data) { return data.reduce(function (result, x) { return result + ("00" + x.toString(16)).slice(-2); }, ''); }; exports.hexToArray = function (hex) { var l = hex.length / 2; var result = new Uint8Array(l); for (var i = 0; i < l; i++) { result[i] = parseInt(hex.substr(i * 2, 2), 16); } return result; }; exports.hexEncode = function (str) { if (typeof str !== 'string') { return null; } return Buffer.from(str).toString('hex'); }; exports.hexDecode = function (hex) { if (typeof hex !== 'string') { return null; } return Buffer.from(hex, 'hex').toString(); }; //# sourceMappingURL=utils.js.map