getWalletRecoveryState method

  1. @override
Future<WalletRecoveryState> getWalletRecoveryState(
  1. String chain,
  2. String accountAddress
)
override

Reads embedded-wallet password protection and readiness before signing. See WaasEngine.getWalletRecoveryState for the session-readiness caveat.

Implementation

@override
Future<WalletRecoveryState> getWalletRecoveryState(String chain, String accountAddress) async {
  Future<WalletRecoveryState> instrumentationOperation() async {
    final operationScope = _state.flowScope.capture(replace: false);
    await operationScope.ready();
    if (!_state.initialized) {
      throw DynamicStateException("call initialize() before using the client");
    }
    final authToken = _state.token;
    if (authToken == null) {
      throw DynamicStateException("not authenticated — sign in first");
    }

    final waasSessionId = _state.user?.sessionId;
    if (waasSessionId == null) {
      throw DynamicStateException("no sessionId — sign in (or call refreshUser) first");
    }
    operationScope.check();
    final sessionSignature = await _sessionSigner.sign(waasSessionId);
    operationScope.check();
    operationScope.check();
    final nonceResponse = await _api.get<NonceResponse>(path: "/nonce", token: null, sessionPublicKey: _state.sessionPublicKey, parse: NonceResponse.fromJson);
    operationScope.check();
    final nonce = nonceResponse.nonce;
    operationScope.check();
    final nonceSignature = await _sessionSigner.sign(nonce);
    operationScope.check();
    final signedSessionId = "$sessionSignature/$nonceSignature/$nonce";

    if ((_waasState.waasBoundSessionId ?? waasSessionId) != waasSessionId) {
      operationScope.check();
      await _waasEngine.destroy();
      operationScope.check();
    }
    operationScope.check();
    await _waasEngine.initialize(_config.environmentId, (chain == "SOL" ? "SVM" : chain), authToken, _config.apiBaseUrl, _config.universalLink);
    operationScope.check();
    operationScope.commit(() {
        _waasState.waasBoundSessionId = waasSessionId;
        _waasState.waasBoundSessionIdChanged.emit(_waasState.waasBoundSessionId);
    });
    operationScope.check();
    final recoveryState = await _waasEngine.getWalletRecoveryState((chain == "SOL" ? "SVM" : chain), accountAddress, authToken, signedSessionId);
    operationScope.check();

    _logger.log("info", "waas wallet recovery state fetched");

    return recoveryState;
  }
  return await _api.instrumentation.runAsync("waas.getWalletRecoveryState", instrumentationOperation);
}