API Reference
PolicyEngine
import { PolicyEngine } from '@envoy/core'
import { TezosAdapter } from '@envoy/tezos'
const engine = new PolicyEngine({
adapter: new TezosAdapter({ rpc: 'https://rpc.tezos.example' }),
policy: './policy.yaml', // path to YAML file, or inline object
auditLog: true, // default true
})
engine.transfer(params)
Execute a transfer. Throws PolicyViolationError if blocked by policy.
await engine.transfer({
to: 'tz1alice...', // recipient address
amount: 100, // amount in chain-native unit (XTZ, SOL, etc.)
token: 'XTZ', // optional — default is native token
memo: 'payment', // optional
})
engine.check(params)
Dry-run policy check without executing the transaction. Returns { allowed: boolean, reasons: string[] }.
const result = await engine.check({
to: 'tz1unknown...',
amount: 50000,
})
// result.allowed === false
// result.reasons === ['exceeds daily_max_xtz (500)', 'recipient not in allowlist']
engine.getAuditLog()
Returns the audit log as an array of decision records.
const log = engine.getAuditLog()
// [{ timestamp, action: 'transfer', allowed: false, reasons: [...], params: {...} }, ...]
TezosAdapter
import { TezosAdapter } from '@envoy/tezos'
const adapter = new TezosAdapter({
rpc: 'https://mainnet.api.tez.ie', // Tezos RPC node URL
signer: mySigner, // optional — Taquito InMemorySigner or similar
network: 'mainnet', // 'mainnet' | 'ghostnet' | custom
})
SolanaAdapter
import { SolanaAdapter } from '@envoy/solana'
const adapter = new SolanaAdapter({
rpc: 'https://api.mainnet-beta.solana.com',
keypair: myKeypair, // @solana/web3.js Keypair
})
EvmAdapter
import { EvmAdapter } from '@envoy/evm'
const adapter = new EvmAdapter({
rpc: 'https://mainnet.infura.io/v3/YOUR_KEY',
privateKey: '0x...', // or use a Signer
chainId: 1, // 1=Ethereum, 137=Polygon, etc.
})
PolicyViolationError
try {
await engine.transfer({ to: 'tz1bad...', amount: 99999 })
} catch (err) {
if (err instanceof PolicyViolationError) {
console.log(err.reasons) // string[] — why it was blocked
console.log(err.action) // 'transfer'
console.log(err.params) // original params
}
}
Examples
Example 1: Balance check (read-only, no policy needed)
import { TezosAdapter } from '@envoy/tezos'
const adapter = new TezosAdapter({ rpc: 'https://mainnet.api.tez.ie' })
const balance = await adapter.getBalance('tz1alice...')
console.log(balance) // XTZ in mutez
Example 2: Policy-controlled transfer
import { PolicyEngine } from '@envoy/core'
import { TezosAdapter } from '@envoy/tezos'
const engine = new PolicyEngine({
adapter: new TezosAdapter({ rpc: 'https://mainnet.api.tez.ie', signer }),
policy: { limits: { daily_max_xtz: 500 }, allowlist: ['tz1alice...'] },
})
await engine.transfer({ to: 'tz1alice...', amount: 100 }) // OK
await engine.transfer({ to: 'tz1unknown...', amount: 100 }) // throws PolicyViolationError
Example 3: Solana SOL transfer with rate limiting
import { PolicyEngine } from '@envoy/core'
import { SolanaAdapter } from '@envoy/solana'
import { Keypair } from '@solana/web3.js'
const engine = new PolicyEngine({
adapter: new SolanaAdapter({ rpc: 'https://api.mainnet-beta.solana.com', keypair }),
policy: { limits: { per_tx_max_sol: 1 }, rate_limit: { max_tx_per_hour: 5 } },
})
await engine.transfer({ to: 'So1ana...', amount: 0.5 }) // OK