/** * @name sap-sdk-parsers * @description Shared input parsers and helpers for SAP SDK tool argument validation. * * Extracted from sap-sdk-tools.ts to break the circular dependency between * sap-sdk-tools.ts and identity-builders.ts. Both files import from this module * instead of importing each other. * * @module tools/sap-sdk-parsers */ import { PublicKey } from '@solana/web3.js'; import BN from 'bn.js'; import { SettlementMode, TokenType, type Capability, type PricingTier, type VolumeCurveBreakpoint } from '@oobe-protocol-labs/synapse-sap-sdk/types'; export type JsonRecord = Record; export declare function asRecord(input: unknown): JsonRecord; export declare function requiredString(input: JsonRecord, field: string): string; export declare function optionalString(input: JsonRecord, field: string): string | undefined; export declare function requiredNumber(input: JsonRecord, field: string): number; export declare function optionalNumber(input: JsonRecord, field: string): number | undefined; export declare function requiredBn(input: JsonRecord, field: string): BN; export declare function optionalBn(input: JsonRecord, field: string, fallback: BN): BN; export declare function optionalBoolean(input: JsonRecord, field: string): boolean | undefined; export declare function requiredPublicKey(input: JsonRecord, field: string): PublicKey; export declare function optionalPublicKey(input: JsonRecord, field: string): PublicKey | undefined; export declare function parseVolumeCurve(value: unknown): VolumeCurveBreakpoint[]; export declare function optionalTokenType(input: JsonRecord): { tokenType: typeof TokenType[keyof typeof TokenType]; decimalsFallback: number; }; export declare function optionalSettlementMode(input: JsonRecord): typeof SettlementMode[keyof typeof SettlementMode]; /** * Hard limits enforced by the SAP mainnet validator (validator.rs). * Rejecting here — at builder time — surfaces an actionable message in the * tool result instead of a post-preview RPC simulation failure (Anchor * errors 6003 TooManyProtocols... see synapse-sap-sdk anchor-errors.ts). * * All values mirror `programs/synapse-agent-sap/src/state.rs` AgentAccount * constants and `validator.rs` checks byte-for-byte: * * | Constant | Value | Anchor error | * |-----------------------|-------|------------------------------------| * | MAX_NAME_LEN | 64 | 6000 NameTooLong / 6022 EmptyName | * | MAX_DESC_LEN | 256 | 6001 / 6024 | * | MAX_URI_LEN | 256 | 6002 UriTooLong | * | MAX_AGENT_ID_LEN | 128 | 6025 AgentIdTooLong | * | MAX_CAPABILITIES | 10 | 6003 TooManyCapabilities | * | MAX_PRICING_TIERS | 5 | 6004 TooManyPricingTiers | * | MAX_PROTOCOLS | 5 | 6005 TooManyProtocols | * | MAX_VOLUME_CURVE_PTS | 5 | 6034 TooManyVolumeCurvePoints | * * Name must also contain no control chars (6023 ControlCharInName, bytes * < 0x20). x402Endpoint must start with "https://" (6032). Capability ids * must be colon-namespaced with non-empty parts (6026) and unique (6027). * Tier ids must be non-empty (6028) and unique (6029), rateLimit > 0 * (6030), min ≤ max price (6035), curve afterCalls strictly ascending * (6033) with non-increasing prices (6142). * * @see synapse-agent-sap/programs/synapse-agent-sap/src/validator.rs */ export declare const MAX_NAME_LEN = 64; export declare const MAX_DESCRIPTION_LEN = 256; export declare const MAX_URI_LEN = 256; export declare const MAX_AGENT_ID_LEN = 128; export declare const MAX_CAPABILITIES = 10; export declare const MAX_PROTOCOLS = 5; export declare const MAX_PRICING_TIERS = 5; export declare const MAX_VOLUME_CURVE_POINTS = 5; /** Mirrors validator.rs validate_name: non-empty, ≤64B, no control chars. */ export declare function validateNameOnChain(name: string): void; /** Mirrors validator.rs validate_description: non-empty, ≤256B. */ export declare function validateDescriptionOnChain(description: string): void; /** Mirrors validator.rs validate_agent_id: ≤128B. */ export declare function validateAgentIdOnChain(agentId: string): void; /** Mirrors validator.rs validate_uri: ≤256B. */ export declare function validateUriOnChain(uri: string, field: string): void; /** Mirrors validator.rs validate_x402_endpoint: ≤256B AND starts with "https://". */ export declare function validateX402EndpointOnChain(endpoint: string): void; /** Mirrors validator.rs validate_capability_format + duplicate check. */ export declare function validateCapabilityIdsOnChain(ids: readonly string[]): void; export declare function parseCapabilities(value: unknown): Capability[]; /** * Full on-chain validation of already-parsed capabilities (counts, id * format, duplicates, per-field byte lengths and field size limits). * Call AFTER parseCapabilities — mirrors validator.rs validate_capabilities * including the per-Capability #[max_len] bounds from state.rs. */ export declare function validateCapabilitiesOnChain(caps: readonly Capability[]): void; export declare function parsePricingTiers(value: unknown): PricingTier[]; /** * Full on-chain validation of already-parsed pricing tiers. Mirrors * validator.rs validate_pricing: count ≤ 5, non-empty unique tierIds, * rateLimit > 0, min ≤ max price, and the volume-curve invariants * (≤ 5 points, strictly ascending afterCalls, non-increasing prices). * Call AFTER parsePricingTiers. */ export declare function validatePricingTiersOnChain(tiers: readonly PricingTier[]): void; /** * Optional-field identity payload validation shared by the register/update * arg parsers (local signer runtime) and the hosted identity builders. * null = field absent → skipped, mirroring validator.rs validate_update. */ export declare function validateIdentityArgsOnChain(args: { readonly name?: string | null; readonly description?: string | null; readonly agentId?: string | null; readonly agentUri?: string | null; readonly x402Endpoint?: string | null; readonly capabilities?: Capability[] | null; readonly pricing?: PricingTier[] | null; readonly protocols?: string[] | null; }): void; export declare function parseProtocols(value: unknown): string[]; //# sourceMappingURL=sap-sdk-parsers.d.ts.map