Zero-trust transaction validation library for Yield.xyz integrations.
npm install @yieldxyz/shield


> Zero-trust transaction validation for Yield.xyz integrations. Shield ensures every transaction is structurally correct and untampered before signing.
``bash`
npm install @yieldxyz/shield
`typescript
import { Shield } from '@yieldxyz/shield';
const shield = new Shield();
// Get transaction from Yield API
const response = await fetch('https://api.yield.xyz/v1/actions/enter', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.YIELD_API_KEY // Your API key
},
body: JSON.stringify({
yieldId: 'ethereum-eth-lido-staking',
address: userWalletAddress,
arguments: { amount: '0.01' }
})
});
const action = await response.json();
// Validate before signing
for (const transaction of action.transactions) {
const result = shield.validate({
unsignedTransaction: transaction.unsignedTransaction,
yieldId: action.yieldId,
userAddress: userWalletAddress,
args: action.arguments // Optional
});
if (!result.isValid) {
throw new Error(Invalid transaction: ${result.reason});`
}
}
Shield automatically detects and validates transaction types through pattern matching. Each transaction must match exactly one known pattern to be considered valid.
- ethereum-eth-lido-stakingsolana-sol-native-multivalidator-staking
- tron-trx-native-staking
-
Validates a transaction by auto-detecting its type.
Parameters:
`typescript`
{
unsignedTransaction: string; // Transaction from Yield API
yieldId: string; // Yield integration ID
userAddress: string; // User's wallet address
args?: ActionArguments; // Optional arguments
context?: ValidationContext; // Optional context
}
Returns:
`typescript`
{
isValid: boolean;
reason?: string; // Why validation failed
details?: any; // Additional error details
detectedType?: string; // Auto-detected type (for debugging)
}
Check if a yield is supported.
Get all supported yield IDs.
Common validation failures:
- "Invalid referral address" - Wrong referral in transaction"Withdrawal owner does not match user address"
- - Ownership mismatch"Transaction validation failed: No matching operation pattern found"
- - Transaction doesn't match any supported pattern"Transaction validation failed: Ambiguous transaction pattern detected"` - Transaction matches multiple patterns
-
MIT