import { Aptos, Account, AccountAddressInput } from '@aptos-labs/ts-sdk'; import { ShelbyBlob } from '../blobs.js'; import { a as ErasureCodingProvider } from '../../clay-codes-DdXABBDx.js'; import { BlobName } from '../layout.js'; import { WriteBlobCommitmentsOptions, ShelbyBlobClient } from './ShelbyBlobClient.js'; import { ShelbyClientConfig } from './ShelbyClientConfig.js'; import { ShelbyMetadataClient } from './ShelbyMetadataClient.js'; import { ShelbyRPCClient, BlobOwnerAuth } from './ShelbyRPCClient.js'; import 'zod'; import '@shelby-protocol/clay-codes'; import '../types/blobs.js'; import '../operations/index.js'; import 'graphql-request'; import '../operations/generated/sdk.js'; import 'graphql'; import '../networks.js'; import '../types/storage_providers.js'; import '../commitments.js'; import '../rpc-responses.js'; import '../types/payments.js'; type UploadOptions = WriteBlobCommitmentsOptions; declare class ShelbyClient { /** * The coordination client is used to interact with the Aptos blockchain which handles the commitments * and metadata for blobs. */ readonly coordination: ShelbyBlobClient; /** * The metadata client is used for protocol-level metadata queries. */ readonly metadata: ShelbyMetadataClient; /** * The RPC client is used to interact with the Shelby RPC node which can be responsible for storing, * confirming, and retrieving blobs from the storage layer. * * If not provided, the default RPC client will be created. */ readonly rpc: ShelbyRPCClient; /** * The configuration for the Shelby client. */ readonly config: ShelbyClientConfig; /** * The Aptos client. * * If not provided, a default Aptos client will be created. */ readonly aptos: Aptos; /** * The erasure coding provider used for encoding/decoding operations. * Lazily initialized on first use if not provided. */ private _provider?; /** * Creates a new ShelbyClient instance for interacting with the Shelby Protocol. * This client combines blockchain operations (via coordination) and storage operations (via RPC). * * @param config - The client configuration object. * @param config.aptos.config - The Aptos network configuration. * @param config.shelby.rpc.baseUrl - The base URL of the Shelby RPC node (optional, defaults to devnet). * @param config.shelby.indexer - The indexer configuration for GraphQL queries. * @param provider - Optional erasure coding provider for encoding/decoding operations. * If not provided, a ClayErasureCodingProvider will be created on first use. * Pass a shared provider to reuse across multiple clients. * * @example * ```typescript * // Basic usage (provider created automatically) * const client = new ShelbyClient({ * network: Network.SHELBYNET, * }); * * // Advanced: Share provider across multiple clients * const provider = await ClayErasureCodingProvider.create(); * const mainnetClient = new ShelbyClient(mainnetConfig, provider); * const devnetClient = new ShelbyClient(devnetConfig, provider); * ``` */ constructor(config: ShelbyClientConfig, provider?: ErasureCodingProvider); /** * Sign an authentication challenge for blob owner verification. * * The default implementation delegates to `ShelbyRPCClient.signChallenge` * which works for standard Ed25519 accounts. Kits that use derived / * abstracted accounts (Solana, Ethereum) should override this method to * provide the correct public key bytes and derivation metadata. */ protected signChallenge(account: Account, challenge: string): BlobOwnerAuth; /** * Get the erasure coding provider, creating it if necessary. * This allows lazy initialization for users who don't provide a provider. */ private getProvider; /** * Build orderless transaction options (a random replay-protection nonce) for * the per-blob commit transactions. batchUpload finalizes blobs * concurrently, so without orderless replay protection the parallel * same-account submissions collide on the sequence number ("transaction * already in mempool with a different payload"). The nonce makes each commit * independent regardless of the client's `orderless` config flag. */ private orderlessCommitOptions; /** * Resolve the on-chain UID assigned to `blobName` from a committed register * transaction. `register_blob` only publishes the uid -> name mapping via * `BlobRegisteredEvent` (a pending blob is not yet in the `objects` map, so it * cannot be read back by name), so the upload flow must parse it here before * uploading bytes or committing. */ private uidFromRegisterTx; /** * Await a blob-registration transaction, rephrasing on-chain location * failures into a human-readable message. */ private waitForRegistration; /** * The base URL for the Shelby RPC node. */ get baseUrl(): string; /** * Uploads a blob to the Shelby network. * This method handles the complete upload flow including commitment generation, * blockchain registration, and storage upload. * * Note: This method accepts only `Uint8Array` and buffers the entire blob in memory. * For streaming uploads of large files (e.g. >2 GiB), orchestrate the steps manually * using `generateCommitments()`, `coordination.registerBlob()`, `rpc.putBlobChunksets()`, * and `coordination.commitObject()` with a `ReadableStream`. * * @param params.blobData - The raw data to upload as a Uint8Array. * @param params.signer - The account that signs and pays for the transaction. * @param params.blobName - The name/path of the blob (e.g. "folder/file.txt"). * @param params.options - Optional upload configuration. * @param params.options.chunksetSizeBytes - Custom chunkset size. * @param params.options.build - Additional Aptos transaction options. * * @returns The transaction and generated blob commitments (when implemented). * * @example * ```typescript * await client.upload({ * blobData: Buffer.from("Hello, World!"), * signer: account, * blobName: "hello.txt", * }); * ``` */ upload(params: { blobData: Uint8Array; signer: Account; blobName: BlobName; options?: UploadOptions; }): Promise; /** * Uploads a batch of blobs to the Shelby network. * This method handles the complete upload flow including commitment generation, * blockchain registration, and storage upload. * * Note: This method accepts only `Uint8Array` and buffers each blob in memory. * For streaming uploads of large files, orchestrate the steps manually using * `generateCommitments()`, `coordination.registerBlob()`, `rpc.putBlobChunksets()`, * and `coordination.commitObject()` with a `ReadableStream`. * * @param params.blobs - The blobs to upload. * @param params.blobs.blobData - The raw data to upload as a Uint8Array. * @param params.blobs.blobName - The name/path of the blob (e.g. "folder/file.txt"). * @param params.signer - The account that signs and pays for the transaction. * @param params.options - Optional upload configuration. * @param params.options.chunksetSizeBytes - Custom chunkset size. * @param params.options.build - Additional Aptos transaction options. * * @returns The transaction and generated blob commitments (when implemented). * * @example * ```typescript * await client.batchUpload({ * blobs: [ * { blobData: Buffer.from("Hello, World!"), blobName: "hello.txt" }, * { blobData: Buffer.from("Hello, World 2!"), blobName: "hello2.txt" }, * ], * }); * ``` */ batchUpload(params: { blobs: { blobData: Uint8Array; blobName: BlobName; }[]; signer: Account; options?: UploadOptions; }): Promise; /** * Downloads a blob from the Shelby RPC node. * * @param params.account - The account namespace the blob is stored in (e.g. "0x1") * @param params.blobName - The name of the blob (e.g. "foo/bar") * @param params.range - The range of the blob to download. * * @returns A `ShelbyBlob` object containing the blob data. * * @example * ```typescript * const blob = await client.download({ * account, * blobName: "foo/bar.txt", * }); * ``` */ download(params: { account: AccountAddressInput; blobName: string; range?: { start: number; end?: number; }; }): Promise; /** * * Funds an account with ShelbyUSD tokens. * * @param params.address - The address to fund. * @param params.amount - The amount to fund. * @returns The transaction hash of the funded account. * * @example * ```typescript * const hash = await client.fundAccountWithShelbyUSD({ * address: "0x1", * amount: 100000000, * }); * ``` */ fundAccountWithShelbyUSD(params: { address: AccountAddressInput; amount: number; }): Promise; /** * Fund an account with APT tokens * * @param params.address - The address to fund * @param params.amount - The amount to fund * @returns The transaction hash of the funded account * * @example * ```typescript * const hash = await client.fundAccountWithAPT({ * address: "0x1", * amount: 100000000, * }); * ``` */ fundAccountWithAPT(params: { address: AccountAddressInput; amount: number; }): Promise; } export { ShelbyClient, type UploadOptions };