batchWalletPolicyRules method
Future<WaasPolicyLayerResponse>
batchWalletPolicyRules(
- String chain,
- String accountAddress,
- List<
PolicyLayerRuleOperation> operations
override
Applies policy rule operations to an embedded wallet in one atomic batch.
Implementation
@override
Future<WaasPolicyLayerResponse> batchWalletPolicyRules(String chain, String accountAddress, List<PolicyLayerRuleOperation> operations) async {
Future<WaasPolicyLayerResponse> instrumentationOperation() async {
final operationScope = _state.flowScope.capture(replace: false);
await operationScope.ready();
if (!_state.initialized) {
throw DynamicStateException("call initialize() before using the client");
}
if (_state.token == null) {
throw DynamicStateException("not authenticated — sign in first");
}
final policyWalletMatch = firstOrNull(_state.user?.verifiedCredentials.map((credential) => (((credential.walletProvider ?? "") == "embeddedWallet") && (((credential.chain ?? "") == (switch (chain) { "EVM" => "eip155", "SOL" => "solana", "BTC" => "bip122", _ => chain.toLowerCase() })) && ((credential.address ?? "") == accountAddress)) ? credential : null)).where((v) => v != null).map((v) => v!).toList() ?? const []);
final policyWallet = policyWalletMatch;
if (policyWallet == null) {
throw DynamicStateException("no embedded wallet found for this chain and account address");
}
operationScope.check();
final layer = await _api.patch<WaasPolicyLayerResponse>(path: "/waas/${Uri.encodeComponent(policyWallet.id)}/policy-layer", body: <String, dynamic>{"op": "batch", "operations": operations}, token: _state.token, sessionPublicKey: _state.sessionPublicKey, parse: WaasPolicyLayerResponse.fromJson);
operationScope.check();
return layer;
}
return await _api.instrumentation.runAsync("policyEngine.batchWalletPolicyRules", instrumentationOperation);
}