Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getVerificationMethods(): Promise> {
// Note: sadly this.assert() does not assert "one in a list"
if ([statuses.READY, statuses.IDENTITY_VERIFICATION_NEEDED].indexOf(this.status) === -1) {
const { name: ready } = statusDefs[statuses.READY];
const { name: verification } = statusDefs[statuses.IDENTITY_VERIFICATION_NEEDED];
const message = `Expected status ${ready} or ${verification} but got ${this.statusName} trying to get verification methods.`;
throw new PreconditionFailed(message);
}
return this._session.getVerificationMethods();
}
async verifyProvisionalIdentity(verification: EmailVerification | OIDCVerification) {
if (!('email' in verification) && !('oidcIdToken' in verification))
throw new InternalError(`Assertion error: unsupported verification method for provisional identity: ${JSON.stringify(verification)}`);
if (!this._provisionalIdentity)
throw new PreconditionFailed('Cannot call verifyProvisionalIdentity() without having called attachProvisionalIdentity() before');
if (verification.email && this._provisionalIdentity.value !== verification.email)
throw new InvalidArgument('"verification.email" does not match provisional identity');
if (verification.oidcIdToken) {
let jwtPayload;
try {
jwtPayload = JSON.parse(utils.toString(utils.fromBase64(verification.oidcIdToken.split('.')[1])));
} catch (e) {
throw new InvalidArgument('Failed to parse "verification.oidcIdToken"');
}
if (this._provisionalIdentity.value !== jwtPayload.email)
throw new InvalidArgument('"verification.oidcIdToken" does not match provisional identity');
}
const tankerKeys = await this._verifyAndGetProvisionalIdentityKeys(verification);
assert(status: number, to: string): void {
if (this.status !== status) {
const { name } = statusDefs[status];
const message = `Expected status ${name} but got ${this.statusName} trying to ${to}.`;
throw new PreconditionFailed(message);
}
}