smartpolicy

v0.2.0
io.github.smartpolicy-protocol/smartpolicy Checked 18 hours ago Published 4 months ago

Runtime authorization for AI agents and smart contracts via an immutable on-chain policy registry

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

policy_check

THE canonical SmartPolicy question: may `subject` perform `action` under policy `policyId`? Returns allowed (boolean) plus the reasons. Maps 1:1 to PolicyRegistry.isAllowed — a protected contract gives the identical answer on-chain. Free.

ParameterTypeDescription
action *stringAction name (e.g. "withdraw") or 0x-prefixed bytes32. Names are keccak256-hashed, matching keccak256("withdraw") in the protected contract.
policyId *Policy ID as decimal string or integer
subject *string

policy_get

Read a policy: owner, expiry, active/locked state, membership mode, member count, metadata URI. Free.

ParameterTypeDescription
policyId *Policy ID as decimal string or integer

grant_issue

Issue a short-lived single-use EIP-712 grant authorizing `subject` to perform `action` under `policyId`, redeemable ONLY at the `target` contract. The subject must pass policy_check first; the policy must list this server's issuer address (grant_issuer_info) via addIssuer. Pass the result to target's PolicyGate.withGrant function. Verify with grant_verify before broadcasting.

ParameterTypeDescription
action *stringAction name (e.g. "withdraw") or 0x-prefixed bytes32. Names are keccak256-hashed, matching keccak256("withdraw") in the protected contract.
policyId *Policy ID as decimal string or integer
subject *string
target *the contract that will consume the grant (the integrator/gate); only it may redeem
contextstringOptional bytes32 binding the gated call's parameters. Set to keccak256(abi.encode(...)) of the exact parameters the caller must use (e.g. the recipient and amount for a transfer); the on-chain gate re…
ttlSecondsintegerRequested grant lifetime in seconds; clamped to the server's maxGrantTtlSeconds (see grant_issuer_info)

grant_issuer_info

This server's grant-issuer address (authorize it on a policy via addIssuer) and limits.

policy_fees

Current protocol fees in wei (read live). createPolicy needs exactly creationFee as msg.value; every other write needs exactly updateFee. Read this before building any write tx — wrong value reverts.

grant_verify

Pre-flight a grant before broadcasting: checks the on-chain GrantVerifier for validity (signature, validity window, issuer authorization, policy active) and whether the nonce is already used. Returns {valid, nonceUsed}. Note: does NOT check subject==caller or target — the gate enforces those on redemption.

ParameterTypeDescription
grant *objectthe grant object exactly as returned by grant_issue
signature *string

policy_create

Build the unsigned transaction that creates a new policy. Returns {to, value, data} for YOUR wallet to sign and submit — the submitting address becomes the policy owner. `value` is the protocol creation fee in wei.

ParameterTypeDescription
expiresAtintegerunix seconds; 0 = never expires
metadataHashstringoptional keccak256 of the metadata document — on-chain tamper-evidence for the URI's content
metadataURIstringoptional metadata pointer, informational only; prefer ipfs:// (content-immutable)
openMembershipbooleantrue: every address counts as a member
transferablebooleantrue: ownership can be transferred later

policy_update

Build the unsigned transaction for a policy rule change (submit from the owner or an admin wallet; `value` is the protocol update fee in wei). Operations: addMembers, removeMembers, setActionRule (UNSET|MEMBERS|ANYONE|NOBODY), addIssuer, removeIssuer, addAdmin, removeAdmin, setExpiry.

ParameterTypeDescription
operation *
policyId *Policy ID as decimal string or integer