UNPKG

@iden3/js-iden3-auth

Version:

iden3-auth implementation in JavaScript

42 lines (41 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthPubSignalsV2 = void 0; const js_iden3_core_1 = require("@iden3/js-iden3-core"); const ownershipVerifier_1 = require("../circuits/ownershipVerifier"); const common_1 = require("../circuits/common"); const js_sdk_1 = require("@0xpolygonid/js-sdk"); const defaultAuthVerifyOpts = 5 * 60 * 1000; // 5 minutes class AuthPubSignalsV2 extends ownershipVerifier_1.IDOwnershipPubSignals { constructor(pubSignals) { super(); this.pubSignals = new js_sdk_1.AuthV2PubSignals(); this.pubSignals = this.pubSignals.pubSignalsUnmarshal(js_sdk_1.byteEncoder.encode(JSON.stringify(pubSignals))); this.userId = this.pubSignals.userID; this.challenge = this.pubSignals.challenge; } verifyQuery() { throw new Error(`authV2 circuit doesn't support queries`); } async verifyStates(resolvers, opts) { const resolver = (0, common_1.getResolverByID)(resolvers, this.userId); if (!resolver) { throw new Error(`resolver not found for id ${this.userId.string()}`); } const gist = await (0, common_1.checkGlobalState)(resolver, this.pubSignals.GISTRoot); let acceptedStateTransitionDelay = defaultAuthVerifyOpts; if (opts?.acceptedStateTransitionDelay) { acceptedStateTransitionDelay = opts.acceptedStateTransitionDelay; } if (!gist.latest) { const timeDiff = Date.now() - (0, js_iden3_core_1.getDateFromUnixTimestamp)(Number(gist.transitionTimestamp)).getTime(); if (timeDiff > acceptedStateTransitionDelay) { throw new Error('global state is outdated'); } } } verifyIdOwnership(sender, challenge) { return super.verifyIdOwnership(sender, challenge); } } exports.AuthPubSignalsV2 = AuthPubSignalsV2;