@prflght/sdk
v0.1.2
Published
TypeScript SDK for the prflght transaction firewall
Downloads
187
Readme
@prflght/sdk
TypeScript SDK for the prflght firewall. Wraps POST /check into a typed firewall.check(tx) call and handles prepending attestation instructions.
Install
npm install @prflght/sdk
# or
pnpm add @prflght/sdkUsage
import { Firewall, FirewallDenyError } from '@prflght/sdk'
const firewall = new Firewall({
apiUrl: 'https://api.prflght.xyz',
agentId: '<your-agent-pubkey>',
apiKey: process.env.PRFLGHT_API_KEY, // from dashboard at app.prflght.xyz
})
// Build your transaction as usual
const tx = buildMyTransaction()
const txBase64 = Buffer.from(tx.serialize()).toString('base64')
try {
const result = await firewall.check(txBase64)
// Prepend attestation instructions before submitting
const attestationIxs = firewall.inject(result.instructions)
const finalTx = buildTransactionWithIxs([...attestationIxs, ...myIxs])
await sendAndConfirm(finalTx)
} catch (err) {
if (err instanceof FirewallDenyError) {
console.error('Blocked:', err.message) // deny reason
}
}API
new Firewall(config)
{
apiUrl: string // base URL of the Risk Engine
agentId: string // agent's Solana pubkey
apiKey?: string // API key from app.prflght.xyz (required for hosted API)
fetch?: typeof globalThis.fetch // optional custom fetch
}firewall.check(tx: string): Promise<CheckResult>
Throws FirewallDenyError if denied. Returns CheckResult on allow.
firewall.tryCheck(tx: string): Promise<CheckResult>
Same as check but never throws - returns decision: "deny" instead.
firewall.inject(instructions: SerializedIx[]): Instruction[]
Converts attestation instructions from API format to @solana/kit Instruction[].
createFirewall(config) (functional alternative)
Same as new Firewall() but returns a plain object.
Types
interface CheckResult {
decision: 'allow' | 'deny'
instructions: SerializedIx[]
policyHash: string | null
expiry: number | null
reason: string | null
}
class FirewallDenyError extends Error {
constructor(public reason: string)
}