import { Salt } from "./expirable-nonce.js"; import { IntentPayload, IntentPrimitive, MultiPayload } from "./shared-types.js"; import { IIntentSigner } from "./interfaces/intent-signer.js"; import { ISaltManager } from "./interfaces/salt-manager.js"; import { EnvConfig } from "@defuse-protocol/internal-utils"; //#region src/intents/intent-payload-builder.d.ts interface IntentPayloadBuilderConfig { envConfig: EnvConfig; saltManager: ISaltManager; } /** * Type helper to make signer_id required when HasSigner is true */ type IntentPayloadWithSigner = HasSigner extends true ? IntentPayload & { signer_id: string; } : IntentPayload; /** * Fluent builder for constructing intent payloads with environment context. * Provides a convenient API for generating intents that can be signed with different standards. * * @example * ```typescript * const sdk = new IntentsSDK({ env: 'production', referral: 'my-app' }); * * // Build an intent payload * const payload = await sdk.intentBuilder() * .setSigner('0x1234...') // EVM address or NEAR account * .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) // 5 minutes * .addIntent({ * intent: 'ft_withdraw', * token: 'usdc.omft.near', * amount: '1000000', * receiver_id: 'user.near' * }) * .build(); * * // Sign with your preferred method * const multiPayload = await signer.signIntent(payload); * ``` */ declare class IntentPayloadBuilder { private envConfig; private saltManager; private verifyingContract; private signerId?; private deadline?; private intents; private customNonce?; private customRandomBytes?; constructor(config: IntentPayloadBuilderConfig); /** * Set the signer ID (address or account that will sign the intent). * Can be an EVM address (for ERC191) or NEAR account ID (for NEP413). * * @param signerId - The identifier of the signer (must be a valid NEAR account ID) * @returns The builder instance for chaining with updated type * @throws Error if signerId is not a valid NEAR account ID */ setSigner(signerId: string): IntentPayloadBuilder; /** * Set the deadline for the intent expiration. * If not set, defaults to 1 minute from build time. * * @param deadline - The expiration time for the intent * @returns The builder instance for chaining */ setDeadline(deadline: Date): this; /** * Add an intent to the payload. * Multiple intents can be added and will execute atomically. * * @param intent - The intent primitive to add * @returns The builder instance for chaining */ addIntent(intent: IntentPrimitive): this; /** * Add multiple intents to the payload at once. * * @param intents - Array of intent primitives to add * @returns The builder instance for chaining */ addIntents(intents: IntentPrimitive[]): this; /** * Override the verifying contract address. * Use with caution - normally this is automatically set based on environment. * * @param contractAddress - The contract address to use * @returns The builder instance for chaining */ setVerifyingContract(contractAddress: string): this; /** * Set a pre-built nonce directly. * Use this when you have a complete nonce from an external source * or need to reuse/invalidate a specific nonce. * * For most cases where you need custom random bytes, use {@link setNonceRandomBytes} instead, * which handles salt fetching and nonce encoding automatically. * * @param nonce - Custom nonce string (base64 encoded) * @returns The builder instance for chaining */ setNonce(nonce: string): this; /** * Set custom random bytes for nonce generation. * The nonce will be automatically created at build time using these bytes, * the deadline, and the contract salt. * * Use this when you need control over the random portion of the nonce * (e.g., embedding a start timestamp via {@link VersionedNonceBuilder.createTimestampedNonceBytes}). * * For pre-built nonces, use {@link setNonce} instead. * * @param randomBytes - 15 bytes to use as the random portion of the nonce * @returns The builder instance for chaining */ setNonceRandomBytes(randomBytes: Uint8Array): this; /** * Clear all intents from the builder. * * @returns The builder instance for chaining */ clearIntents(): this; /** * Reset the builder to its initial state. * Keeps environment and salt manager but clears all user-set values. * * @returns The builder instance for chaining */ reset(): IntentPayloadBuilder; /** * Build the intent payload using a custom salt. * Use this method if you need explicit control over the salt. * * @param salt - The salt to use for nonce generation * @returns The constructed intent payload with appropriate typing */ buildWithSalt(salt: Salt): IntentPayloadWithSigner; /** * Build the intent payload. Automatically fetches a fresh salt if needed. * This is the recommended method for most use cases. * * @returns Promise resolving to the constructed intent payload with appropriate typing */ build(): Promise>; /** * Build and sign the intent payload in one step. * Convenience method that combines build() and signing. * * @param signer - The intent signer to use * @returns Promise resolving to the signed multi-payload and the raw payload */ buildAndSign(signer: IIntentSigner): Promise<{ signed: MultiPayload; payload: IntentPayloadWithSigner; }>; /** * Create a new builder instance with the same configuration. * Useful when you need multiple independent builders. * * @returns A new IntentPayloadBuilder instance */ clone(): IntentPayloadBuilder; /** * Get the current state of the builder as a plain object. * Useful for debugging or inspecting the builder configuration. * * @returns Object containing the current builder state */ getState(): { envConfig: EnvConfig; verifyingContract: string; signerId?: string; deadline?: Date; intents: IntentPrimitive[]; customNonce?: string; }; } //#endregion export { IntentPayloadBuilder };