@debridge-finance/borderless-validation-sdk
v0.10.0
Published
Validation SDK for deBridge borderless intents API responses
Readme
@debridge-finance/borderless-validation-sdk
Validation SDK for deBridge borderless intents API (POST /v1.0/bundle) responses.
Purpose
When a user submits a bundle request to the deBridge API, the response contains transactions and signable payloads (EIP-712 messages, permits, Solana transactions, etc.) that the user is expected to sign.
Every field the user signs is a potential attack vector. If the API is compromised (MITM, server bug, malicious rewrite), the user could unknowingly sign a transaction that drains their funds.
This SDK runs on the client before signing. It validates the response structure and checks signable payloads against the original request, protocol invariants, and environment-specific whitelists.
Threats mitigated
- MITM attacks against the API endpoint.
- Bugs on the API side that produce subtly wrong responses.
- Reduced API trust — the client no longer has to take API responses on faith.
- Regression safety net when testing new API versions.
Installation
npm install @debridge-finance/borderless-validation-sdkDeclared peer dependency ranges:
@solana/web3.js >= 1.90.0bs58 >= 5.0.0viem >= 2.0.0zod ^3.0.0 || ^4.0.0
Basic usage
import {
createValidator,
Environment,
ViolationCode,
} from "@debridge-finance/borderless-validation-sdk";
const validator = createValidator({ environment: Environment.Prod });
const url = "https://cross-chain-api.debridge.finance/v1.0/bundle";
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(request),
}).then(res => res.json());
const result = validator.validate(url, request, response);
if (!result.ok) {
if (result.violations.some(v => v.code === ViolationCode.HigherApiVersion)) {
// Special case: the API response was produced for a newer validation
// version than this SDK supports. The SDK cannot reliably validate it.
// Decide in your app whether to block, warn, update the SDK, or use
// another fallback flow.
console.error("API validation version is newer than SDK support:", result.violations);
return;
}
if (result.violations.some(v => v.code === ViolationCode.UnexpectedValidationError)) {
// Special case: this indicates an internal Validation SDK error.
// The client app must decide how to handle it: block signing, report
// telemetry, retry after SDK update, or use another fallback flow.
console.error("Validation SDK internal error:", result.violations);
return;
}
console.error("Validation failed:", result.violations);
// Do NOT let the user sign anything.
return;
}
// Safe to proceed with signing.API
createValidator(config: ValidatorConfig): Validator
type ValidatorConfig = {
environment: Environment;
};
type Validator = {
validate(url: string, request: object, response: object): ValidationResult;
};
type ValidationResult = {
ok: boolean; // true if no violations
violations: Violation[]; // all issues found
};
type Violation = {
code: ViolationCode; // machine-readable identifier
message: string; // human-readable description
path: string; // JSON path of the offending field
expected?: unknown; // the value the validator expected (concrete, comparable to `actual`)
actual?: unknown; // the value found in the response (concrete, comparable to `expected`)
details?: unknown; // extra machine-readable context (e.g. caught error object)
};validator.validate() never throws — every error condition is reported as a Violation. Safe to call in any code path.
Integration guide for UI teams
The SDK is designed to run between receiving the API response and presenting it to the user for signing. Wire it into that seam.
1. Where to call
┌───────────────┐ ┌─────────┐ ┌────────────────────┐ ┌───────────────┐
│ Build request │ ──▶ │ fetch() │ ──▶ │ validator.validate │ ──▶ │ Sign / submit │
└───────────────┘ └─────────┘ └────────────────────┘ └───────────────┘
│
▼
ok ? proceed : block- Before
validate: the user has not yet seen or signed anything. - After
validate: ifresult.ok === false, do not forward any signable payload (intent message, permit, transaction) to the wallet. The API response cannot be trusted.
2. Choosing the environment
import { Environment } from "@debridge-finance/borderless-validation-sdk";Environment.Prod— production without gasless features.Environment.Gasless— production with gasless features.Environment.Dev— developer environment (also known as Stage).
Pass the same environment your app is already configured for — don't make it user-selectable.
3. Pass the exact URL you called
const url = "https://cross-chain-api.debridge.finance/v1.0/bundle";
const response = await fetch(url, { ... });
const result = validator.validate(url, request, response);The url argument is accepted for API compatibility and future endpoint checks. Pass the same string you handed to fetch; do not rely on URL validation until it is explicitly enabled in a release.
4. Handling violations
On result.ok === false:
- Block the signing flow. Do not show a wallet popup or write any pending tx to state.
- Log the full
violationsarray to your error reporting system (Sentry / Datadog / etc.). Includecode,path,expected,actual,details. - Show the user a generic error. Do not leak raw
Violationdata into the UI — messages are for developers, not end-users. A single "Quote is invalid, please retry" is enough. - Do not retry automatically. If the API is compromised, retries make it worse. Let the user manually trigger a retry.
5. Browser compatibility
The SDK is published as both CJS and ESM and uses only browser-compatible APIs (no fs, crypto, Buffer, process).
Tree-shaking: the ESM build preserves named exports. Importing only createValidator will not pull in unused validators.
6. Bundle size
Roughly 1 MB unpacked (a lot of it is source maps — drop them in production). The heaviest peer dep is @solana/web3.js; if your app only deals with EVM trades, your bundler's tree-shaking should eliminate most of it.
7. TypeScript
Full type declarations ship in dist/types/. ValidatorConfig, ValidationResult, Violation, and ViolationCode are all exported — use them directly, don't re-declare.
8. What NOT to do
- ❌ Don't skip validation because "the API is our own." Compromise detection is the whole point.
- ❌ Don't mutate
requestorresponsebetween the API call andvalidate()— the validator needs the exact payload the user received. - ❌ Don't interpret
violations[].messageprogrammatically — message wording may change between versions. Branch oncodeinstead. - ❌ Don't cache the validator if
environmentchanges. Create a new instance viacreateValidatorfor each environment.
Development
For repository development, testing, releases, and Java parity checks, see the development guide.
License
BUSL-1.1
