eosjs-ios-browser-signature-provider-interface
Version:
A Signature Provider Interface for communicating with an authenticator from iOS browsers using the EOSIO Authentication Transport Protocol Specification.
75 lines • 3.54 kB
JavaScript
;
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 __());
};
})();
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var eosjs_signature_provider_interface_1 = require("eosjs-signature-provider-interface");
var ExpiringLocalStorageProvider_1 = require("./ExpiringLocalStorageProvider");
var utils = __importStar(require("./utils"));
var SignatureProvider = /** @class */ (function (_super) {
__extends(SignatureProvider, _super);
function SignatureProvider(args) {
var _this = _super.call(this, args) || this;
_this.onWindowHashChange = function () {
var response = window.location.hash.replace('#', '');
var responseEnvelope = eosjs_signature_provider_interface_1.unpackEnvelope(response);
if (!eosjs_signature_provider_interface_1.instanceOfResponseEnvelope(responseEnvelope)) {
return;
}
utils.removeRequestId();
_this.handleResponse(responseEnvelope);
};
_this.localStorage = new ExpiringLocalStorageProvider_1.ExpiringLocalStorageProvider();
_this.expiryMs = 100 * 60 * 1000; // Cache for 100 minutes
_this.protocol = args.options.protocol;
window.addEventListener('hashchange', _this.onWindowHashChange);
return _this;
}
SignatureProvider.prototype.getCachedKeys = function () {
var keys = this.localStorage.get('publicKeys');
return keys || [];
};
SignatureProvider.prototype.setCachedKeys = function (keys) {
this.localStorage.set('publicKeys', keys, this.expiryMs);
};
SignatureProvider.prototype.clearCachedKeys = function () {
this.localStorage.remove('publicKeys');
};
SignatureProvider.prototype.cleanUp = function () {
window.removeEventListener('hashchange', this.onWindowHashChange);
};
SignatureProvider.prototype.sendRequest = function (requestEnvelop) {
utils.removeHash();
utils.appendRequestId(requestEnvelop.id);
var browserUrl = window.location.href;
var arr = browserUrl.split('/');
var declaredDomain = arr[0] + "//" + arr[2];
requestEnvelop.declaredDomain = declaredDomain;
requestEnvelop.returnUrl = window.location.href;
requestEnvelop.callbackUrl = '';
var encoded = eosjs_signature_provider_interface_1.packEnvelope(requestEnvelop);
var url = this.protocol + "://request?payload=" + encoded;
window.location = url;
window.open(url, '_system');
};
return SignatureProvider;
}(eosjs_signature_provider_interface_1.SignatureProviderInterface));
exports.SignatureProvider = SignatureProvider;
//# sourceMappingURL=SignatureProvider.js.map