UNPKG

@elysium-onchain-id/identity-sdk

Version:
139 lines 8.05 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Gateway = void 0; const ENS_1 = require("../core/utils/ENS"); const providers_1 = require("@ethersproject/providers"); const ethers_1 = require("ethers"); const Errors_1 = require("../core/errors/Errors"); const solidity_1 = __importDefault(require("@onchain-id/solidity")); class Gateway { static at(addressOrENS, options) { return __awaiter(this, void 0, void 0, function* () { let address; if (!addressOrENS.includes('.')) { address = (0, ENS_1.normalizeAddress)(addressOrENS); } else { if (providers_1.Provider.isProvider(options === null || options === void 0 ? void 0 : options.provider)) { address = yield (0, ENS_1.resolveENS)(addressOrENS, options === null || options === void 0 ? void 0 : options.provider); } else if (ethers_1.Signer.isSigner(options === null || options === void 0 ? void 0 : options.signer) && providers_1.Provider.isProvider(options === null || options === void 0 ? void 0 : options.signer.provider)) { address = yield (0, ENS_1.resolveENS)(addressOrENS, options === null || options === void 0 ? void 0 : options.signer.provider); } else { throw new Errors_1.InvalidProviderError('Resolving ENS requires a Provider.'); } } return new Gateway(address, (options === null || options === void 0 ? void 0 : options.signer) || (options === null || options === void 0 ? void 0 : options.provider)); }); } constructor(address, provider) { this.address = (0, ENS_1.normalizeAddress)(address); this.provider = provider; } instantiateGateway(providerOrSigner) { return __awaiter(this, void 0, void 0, function* () { const _provider = providerOrSigner !== null && providerOrSigner !== void 0 ? providerOrSigner : this.provider; if (this.gatewayInstance && (this.gatewayInstance.provider === _provider || this.gatewayInstance.signer === _provider)) { return this.gatewayInstance; } if (!this.address) { throw new Error('Gateway has no address defined.'); } this.gatewayInstance = new ethers_1.Contract(this.address, solidity_1.default.contracts.Gateway.abi, _provider); return this.gatewayInstance; }); } approveSigner(signer, options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const _signer = (_a = options === null || options === void 0 ? void 0 : options.signer) !== null && _a !== void 0 ? _a : this.provider; if (!ethers_1.Signer.isSigner(_signer)) { throw new Errors_1.InvalidProviderError('Contract operations require a Signer.'); } let instance = this.gatewayInstance; if (!instance || (options === null || options === void 0 ? void 0 : options.signer)) { instance = yield this.instantiateGateway(_signer); } return instance.approveSigner(signer, (_b = options === null || options === void 0 ? void 0 : options.overrides) !== null && _b !== void 0 ? _b : {}); }); } revokeSigner(signer, options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const _signer = (_a = options === null || options === void 0 ? void 0 : options.signer) !== null && _a !== void 0 ? _a : this.provider; if (!ethers_1.Signer.isSigner(_signer)) { throw new Errors_1.InvalidProviderError('Contract operations require a Signer.'); } let instance = this.gatewayInstance; if (!instance || (options === null || options === void 0 ? void 0 : options.signer)) { instance = yield this.instantiateGateway(_signer); } return instance.revokeSigner(signer, (_b = options === null || options === void 0 ? void 0 : options.overrides) !== null && _b !== void 0 ? _b : {}); }); } revokeSignature(signature, options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const _signer = (_a = options === null || options === void 0 ? void 0 : options.signer) !== null && _a !== void 0 ? _a : this.provider; if (!ethers_1.Signer.isSigner(_signer)) { throw new Errors_1.InvalidProviderError('Contract operations require a Signer.'); } let instance = this.gatewayInstance; if (!instance || (options === null || options === void 0 ? void 0 : options.signer)) { instance = yield this.instantiateGateway(_signer); } return instance.revokeSignature(signature, (_b = options === null || options === void 0 ? void 0 : options.overrides) !== null && _b !== void 0 ? _b : {}); }); } approveSignature(signature, options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const _signer = (_a = options === null || options === void 0 ? void 0 : options.signer) !== null && _a !== void 0 ? _a : this.provider; if (!ethers_1.Signer.isSigner(_signer)) { throw new Errors_1.InvalidProviderError('Contract operations require a Signer.'); } let instance = this.gatewayInstance; if (!instance || (options === null || options === void 0 ? void 0 : options.signer)) { instance = yield this.instantiateGateway(_signer); } return instance.approveSignature(signature, (_b = options === null || options === void 0 ? void 0 : options.overrides) !== null && _b !== void 0 ? _b : {}); }); } isSignatureRevoked(signature, options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const _provider = (_b = (_a = options === null || options === void 0 ? void 0 : options.provider) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.signer) !== null && _b !== void 0 ? _b : this.provider; let instance = this.gatewayInstance; if (!instance) { instance = yield this.instantiateGateway(_provider); } return instance.revokedSignatures(signature); }); } isApprovedSigner(signer, options) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const _provider = (_b = (_a = options === null || options === void 0 ? void 0 : options.provider) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.signer) !== null && _b !== void 0 ? _b : this.provider; let instance = this.gatewayInstance; if (!instance) { instance = yield this.instantiateGateway(_provider); } return instance.approvedSigners(signer); }); } } exports.Gateway = Gateway; //# sourceMappingURL=Gateway.js.map