Skip to content

Comments

[SEM-5] Add Policy Enforcement to WDK Core#1

Open
nimdeveloper wants to merge 11 commits intoSemanticPay:mainfrom
nimdeveloper:main
Open

[SEM-5] Add Policy Enforcement to WDK Core#1
nimdeveloper wants to merge 11 commits intoSemanticPay:mainfrom
nimdeveloper:main

Conversation

@nimdeveloper
Copy link

Add registerPolicies

Summary

This PR introduces a policy engine to WDK via registerPolicies, enabling runtime enforcement of constraints on mutating wallet operations. Policies can be scoped by blockchain and method, support async evaluation, and execute deterministically with short-circuit rejection.

Key Changes

  • New API: registerPolicies(policies) (chainable)

  • Policy shape:

    interface Policy {
      name: string;
      target?: {
        wallet?: string;
        protocol?: {
          blockchain?: string;
          label?: string;
        };
      };
      method?: string | string[];
      evaluate({
        method: string,
        params: any,
        target: {
          wallet?: string;
          protocol?: {
            blockchain?: string;
            label?: string;
          };
        },
      }): boolean | Promise<boolean>;
    }
  • Method wrapping: Only mutating methods are wrapped; no double wrapping.

  • Error handling: Introduced PolicyViolationError for explicit rejection signalling.

  • Async support: Fully supported in evaluate.

Tests & Documentation

  • Comprehensive Jest test suite covering validation, filtering (wallet/method), stacking, short-circuiting, async evaluation, and isolation.
  • Coverage reporting integrated in CI.
  • Documentation updated with usage patterns and examples.

Impact

No breaking changes. Existing behaviour remains unchanged unless policies are registered.

This lays the foundation for configurable wallet governance (e.g., limits, whitelists, compliance rules) without coupling policy logic to protocol implementations.

@nimdeveloper nimdeveloper changed the title [SEM-5] Add registerPolicies [SEM-5] Add Policy Enforcement to WDK Core Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant