Declarative rules are in early access and are not enabled by default. Talk to us if you’d like to participate.
PolicyRules helpers, see Manage Policies.
Before you start
- Create and initialize a Dynamic client (see Creating a Dynamic Client, Initializing the Dynamic Client).
- Use
@dynamic-labs-sdk/clientand@dynamic-labs-sdk/react-hooks1.42.0 or later. The helpers are exported from@dynamic-labs-sdk/client/waas, and the hooks from@dynamic-labs-sdk/react-hooks. walletAccountbelow is the WaaS wallet account, for example one returned bygetWalletAccounts().- A layer holds legacy rules or declarative rules, never both. A write that would mix them is refused, and until declarative rules are enabled for your environment a declarative write is refused with
rule_syntax_disabled.
Read rules
getWalletPolicyLayer and getSignerPolicyLayer return the layer. readPolicyLayerRules returns its entries, and isDeclarativePolicyRule tells declarative rules apart from legacy ones.
- JavaScript
- React
getSignerPolicyLayer({ walletAccount }) or useGetSignerPolicyLayer({ walletAccount }).
Add or update a rule
An upsert creates the rule, or updates it when itsruleId already exists on the layer. Leave ruleId out to create a rule, and the returned layer contains the generated id.
- JavaScript
- React
upsertSignerPolicyRule({ walletAccount, rule }) or useUpsertSignerPolicyRule.
Remove a rule
- JavaScript
- React
removeSignerPolicyRule({ walletAccount, ruleId }) or useRemoveSignerPolicyRule.
Replace the layer’s rules
replacePolicyLayerRules sets the layer’s full rule list, so any rule you leave out is removed. Keep the ruleId of every rule you are keeping. Use scope: { walletId } for the wallet layer, where walletId is the wallet’s verifiedCredentialId, or scope: { shareSetId } for the caller’s own signer layer. Only environment admins and business-account admins can replace a layer.
- JavaScript
- React
Errors
The write helpers throw anAPIError when the request is refused. Its code tells you why, for example rule_syntax_disabled when declarative rules are not enabled for the environment, or composition_layer_edit_mixed_rule_syntax when the write would mix legacy and declarative rules.
Next steps
Rule examples
Ready-made declarative rules.
Manage Policies
The legacy
PolicyRules helpers.