delegateWaasKeyShares method

  1. @override
Future<void> delegateWaasKeyShares(
  1. String chain,
  2. String accountAddress,
  3. List<WaasPolicyRule>? initialSignerRules,
  4. String? password,
)
override

Delegates an embedded wallet's signing authority to a new, server-managed share set, then refreshes the user so the new share-set metadata (walletProperties.otherShareSets) is visible. initialSignerRules optionally seeds the delegated signer's own policy layer at delegation time. password is required only when the wallet is password-encrypted — see getWalletRecoveryState.

Implementation

@override
Future<void> delegateWaasKeyShares(String chain, String accountAddress, List<WaasPolicyRule>? initialSignerRules, String? password) async {
  Future<void> 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();
    await _waasEngine.delegateKeyShares((chain == "SOL" ? "SVM" : chain), accountAddress, authToken, signedSessionId, initialSignerRules, password);
    operationScope.check();

    operationScope.check();
    final refreshedUser = await _api.get<SdkUser>(path: "/users", token: _state.token, sessionPublicKey: _state.sessionPublicKey, parse: SdkUser.fromJson);
    operationScope.check();
    operationScope.commit(() {
        _state.user = refreshedUser;
        _state.userChanged.emit(_state.user);
    });
    _logger.log("info", "waas key shares delegated");
  }
  return await _api.instrumentation.runAsync("waas.delegateWaasKeyShares", instrumentationOperation);
}