Validation
Client-side input validation helpers — check arguments before sending transactions.
Pre-alpha — not production ready
@aura-protocol/sdk-ts targets Solana devnet only. APIs may change without notice. Do not use for real funds until a stable release and audit are published.
The SDK exports a set of lightweight validators that mirror the on-chain program's argument checks. Run them before building instructions to surface errors early without spending SOL on failed preflight transactions.
import {
validateAgentId,
validateDwalletId,
validateAddress,
validateAmountUsd,
validateMultisigThreshold,
validateGuardians,
validateSwarmMembers,
MAX_AGENT_ID_LEN,
MAX_DWALLET_ID_LEN,
MAX_ADDRESS_LEN,
MAX_GUARDIANS,
MAX_SWARM_MEMBERS,
} from '@aura-protocol/sdk-ts';Constants
| Constant | Value | Description |
|---|---|---|
MAX_AGENT_ID_LEN | 64 | Maximum UTF-8 byte length of an agent ID |
MAX_DWALLET_ID_LEN | 64 | Maximum UTF-8 byte length of a dWallet ID |
MAX_ADDRESS_LEN | 128 | Maximum UTF-8 byte length of a chain address |
MAX_GUARDIANS | 10 | Maximum number of guardians in a multisig |
MAX_SWARM_MEMBERS | 16 | Maximum number of agents in a swarm |
Validators
validateAgentId
Throws if agentId is empty or exceeds MAX_AGENT_ID_LEN bytes.
function validateAgentId(agentId: string): voidvalidateAgentId('agent-prod-1'); // ok
validateAgentId(''); // throws: "agentId must not be empty"validateDwalletId
Throws if dwalletId is empty or exceeds MAX_DWALLET_ID_LEN bytes.
function validateDwalletId(dwalletId: string): voidvalidateAddress
Throws if address is empty or exceeds MAX_ADDRESS_LEN bytes.
function validateAddress(address: string): voidvalidateAddress('0xdeadbeef...'); // ok
validateAddress(''); // throws: "address must not be empty"validateAmountUsd
Throws if amountUsd is zero or negative.
function validateAmountUsd(amountUsd: number | bigint): voidvalidateAmountUsd(250); // ok
validateAmountUsd(0); // throws: "amountUsd must be greater than zero"validateMultisigThreshold
Throws if threshold is zero or exceeds guardianCount.
function validateMultisigThreshold(threshold: number, guardianCount: number): voidvalidateMultisigThreshold(2, 3); // ok — 2-of-3 multisig
validateMultisigThreshold(4, 3); // throws: threshold (4) must not exceed guardian count (3)
validateMultisigThreshold(0, 3); // throws: threshold must be greater than zerovalidateGuardians
Throws if the guardian list is empty or exceeds MAX_GUARDIANS.
function validateGuardians(guardians: unknown[]): voidvalidateGuardians([g1, g2, g3]); // ok
validateGuardians([]); // throws: "guardians list must not be empty"validateSwarmMembers
Throws if the swarm member list is empty or exceeds MAX_SWARM_MEMBERS.
function validateSwarmMembers(members: unknown[]): voidUsage Pattern
Validate arguments before building instructions to fail fast and clearly:
import {
AuraClient,
validateAgentId,
validateAmountUsd,
validateGuardians,
validateMultisigThreshold,
} from '@aura-protocol/sdk-ts';
import BN from 'bn.js';
const agentId = 'agent-prod-1';
const amountUsd = 250;
const guardians = [g1.publicKey, g2.publicKey, g3.publicKey];
const threshold = 2;
// Validate before any async RPC work
validateAgentId(agentId);
validateAmountUsd(amountUsd);
validateGuardians(guardians);
validateMultisigThreshold(threshold, guardians.length);
// Now safe to build instructions
const client = new AuraClient({ connection });
const now = new BN(Math.floor(Date.now() / 1000));
await client.configureMultisig(
owner,
{ owner: owner.publicKey, treasury },
{ requiredSignatures: threshold, guardians, timestamp: now },
);Simulation-Based Validation
For final confirmation before sending, simulate the transaction to surface any on-chain policy failures:
import { Transaction } from '@solana/web3.js';
import BN from 'bn.js';
const now = new BN(Math.floor(Date.now() / 1000));
const instruction = await client.proposeTransactionInstruction(
{ aiAuthority: aiAuthority.publicKey, treasury },
{
amountUsd: new BN(250),
targetChain: 2,
txType: 0,
protocolId: null,
currentTimestamp: now,
expectedOutputUsd: null,
actualOutputUsd: null,
quoteAgeSecs: null,
counterpartyRiskScore: 15,
recipientOrContract: '0xdeadbeef...',
sanctionsProof: [],
},
);
const tx = new Transaction().add(instruction);
tx.feePayer = aiAuthority.publicKey;
const { blockhash } = await client.connection.getLatestBlockhash();
tx.recentBlockhash = blockhash;
const sim = await client.connection.simulateTransaction(tx);
if (sim.value.err) {
throw new Error(`Simulation failed: ${JSON.stringify(sim.value.logs)}`);
}
return client.sendInstructions(aiAuthority, [instruction]);