diff --git a/packages/waas/src/auth.ts b/packages/waas/src/auth.ts index a27dc2826..ccb49c607 100644 --- a/packages/waas/src/auth.ts +++ b/packages/waas/src/auth.ts @@ -22,9 +22,11 @@ import { AdoptChildWalletArgs } from './intents' import { + ConfirmationRequiredResponse, FeeOptionsResponse, isChildWalletAdoptedResponse, isCloseSessionResponse, + isConfirmationRequiredResponse, isFeeOptionsResponse, isFinishValidateSessionResponse, isGetAdopterResponse, @@ -333,6 +335,11 @@ export class SequenceWaaS { return this.waitForSessionValid() } + private async handleConfirmationRequired(response: ConfirmationRequiredResponse) { + const intent2 = await this.waas.confirmIntent(response.data.salt, "111111") + return intent2 + } + private headers() { return { 'X-Access-Key': this.config.projectAccessKey @@ -775,6 +782,16 @@ export class SequenceWaaS { return response } + if (isConfirmationRequiredResponse(response)) { + const intent2 = await this.handleConfirmationRequired(response) + if (intent2) { + const response2 = await this.sendIntent(intent2) + if (isExpectedResponse(response2)) { + return response2 + } + } + } + if (isValidationRequiredResponse(response)) { const proceed = await this.handleValidationRequired(args.validation) diff --git a/packages/waas/src/base.ts b/packages/waas/src/base.ts index cdde0f509..7b6ec4296 100644 --- a/packages/waas/src/base.ts +++ b/packages/waas/src/base.ts @@ -4,6 +4,7 @@ import { changeIntentTime, closeSession, combineTransactionIntents, + confirmIntent, feeOptions, finishValidateSession, getAdopter, @@ -50,7 +51,8 @@ import { IntentDataOpenSession, IntentDataSendTransaction, IntentDataSignMessage, - IntentDataValidateSession + IntentDataValidateSession, + IntentDataConfirmIntent, } from './clients/intent.gen' import { getDefaultSubtleCryptoBackend, SubtleCryptoBackend } from './subtle-crypto' import { getDefaultSecureStoreBackend, SecureStoreBackend } from './secure-store' @@ -513,6 +515,17 @@ export class SequenceWaaSBase { return this.signIntent(intent) } + async confirmIntent(salt: string, secretCode: string): Promise> { + const intent = confirmIntent({ + lifespan: DEFAULT_LIFESPAN, + wallet: await this.getWalletAddress(), + confirmationID: salt, + challengeAnswer: ethers.id(salt + secretCode), + }) + + return this.signIntent(intent) + } + async getSession(): Promise> { const sessionId = await this.sessionId.get() if (!sessionId) { diff --git a/packages/waas/src/intents/responses.ts b/packages/waas/src/intents/responses.ts index 6af89ba43..7a1829e00 100644 --- a/packages/waas/src/intents/responses.ts +++ b/packages/waas/src/intents/responses.ts @@ -10,7 +10,8 @@ import { IntentResponseGetSession, IntentResponseIdToken, IntentResponseValidationFinished, - IntentResponseValidationStarted + IntentResponseValidationStarted, + IntentResponseConfirmationRequired, } from '../clients/intent.gen' import { WebrpcEndpointError, WebrpcError } from '../clients/authenticator.gen' @@ -127,6 +128,7 @@ export interface Response { export type InitiateAuthResponse = Response export type ValidateSessionResponse = Response +export type ConfirmationRequiredResponse = Response export type FinishValidateSessionResponse = Response export type GetSessionResponse = Response export type LinkAccountResponse = Response @@ -249,6 +251,15 @@ export function isFinishValidateSessionResponse(receipt: any): receipt is Finish return typeof receipt === 'object' && receipt.code === IntentResponseCode.validationFinished && typeof receipt.data === 'object' } +export function isConfirmationRequiredResponse(receipt: any): receipt is ConfirmationRequiredResponse { + return ( + typeof receipt === 'object' && + receipt.code === IntentResponseCode.confirmationRequired && + typeof receipt.data === 'object' && + typeof receipt.data.salt === 'string' + ) +} + export function isCloseSessionResponse(receipt: any): receipt is CloseSessionResponse { return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'sessionClosed' } diff --git a/packages/waas/src/intents/session.ts b/packages/waas/src/intents/session.ts index e8028fe77..4a534bbc4 100644 --- a/packages/waas/src/intents/session.ts +++ b/packages/waas/src/intents/session.ts @@ -11,7 +11,8 @@ import { IntentDataGetIdToken, IntentName, IntentDataAdoptChildWallet, - IntentDataGetAdopter + IntentDataGetAdopter, + IntentDataConfirmIntent, } from '../clients/intent.gen' interface BaseArgs { @@ -83,3 +84,9 @@ export type GetAdopterArgs = BaseArgs & IntentDataGetAdopter export function getAdopter({ lifespan, ...data }: GetAdopterArgs): Intent { return makeIntent(IntentName.getAdopter, lifespan, data) } + +export type ConfirmIntentArgs = BaseArgs & IntentDataConfirmIntent + +export function confirmIntent({ lifespan, ...data }: ConfirmIntentArgs): Intent { + return makeIntent(IntentName.confirmIntent, lifespan, data) +}