UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

147 lines (146 loc) 4.46 kB
export interface GatewayEnvelope<T> { data: T; proof: GatewayProof; } export interface GatewayProof { signature: string; timestamp: string; gatewayAddress: string; requestHash: string; responseHash: string; userSignature: string; status: string; chainBlockHeight: number; } export interface Builder { id: string; ownerAddress: string; granteeAddress: string; publicKey: string; appUrl: string; addedAt: string; } export interface Schema { id: string; ownerAddress: string; name: string; definitionUrl: string; scope: string; addedAt: string; } export interface ServerInfo { id: string; ownerAddress: string; serverAddress: string; publicKey: string; serverUrl: string; addedAt: string; } export interface GatewayGrantResponse { id: string; grantorAddress: string; granteeId: string; grant: string; fileIds: string[]; status: "pending" | "confirmed"; addedAt: string; revokedAt: string | null; revocationSignature: string | null; } export interface GrantListItem { id: string; grantorAddress: string; granteeId: string; grant: string; fileIds: string[]; status: "pending" | "confirmed"; addedAt: string; revokedAt: string | null; revocationSignature: string | null; } export interface FileRecord { fileId: string; owner: string; url: string; schemaId: string; createdAt: string; /** * Soft-deletion timestamp (ISO 8601), or null if the file is active. Always present * (`normalizeFileRecord` populates it); non-null only when the gateway returns deletion state * (e.g. listed with `includeDeleted`). Drives the PS sync delete-reconciliation. */ deletedAt: string | null; } export interface FileListResult { files: FileRecord[]; cursor: string | null; } export interface ListFilesOptions { /** * Include soft-deleted files in the result (each carries a non-null `deletedAt`). Default false. * Used by the PS sync download worker to reconcile deletions of files it already holds locally. */ includeDeleted?: boolean; } export interface RegisterFileParams { ownerAddress: string; url: string; schemaId: string; signature: string; } export interface CreateGrantParams { grantorAddress: string; granteeId: string; grant: string; fileIds: string[]; signature: string; } export interface RevokeGrantParams { grantId: string; grantorAddress: string; signature: string; } export interface DeleteFileParams { fileId: string; ownerAddress: string; /** EIP-712 FileDeletion signature, signed by the owner or the owner's registered server. */ signature: string; } export interface RegisterServerParams { ownerAddress: string; serverAddress: string; publicKey: string; serverUrl: string; signature: string; } export interface RegisterServerResult { serverId?: string; alreadyRegistered: boolean; } export interface GatewayClient { isRegisteredBuilder(address: string): Promise<boolean>; getBuilder(address: string): Promise<Builder | null>; getGrant(grantId: string): Promise<GatewayGrantResponse | null>; listGrantsByUser(userAddress: string): Promise<GrantListItem[]>; getSchemaForScope(scope: string): Promise<Schema | null>; getServer(address: string): Promise<ServerInfo | null>; getFile(fileId: string): Promise<FileRecord | null>; listFilesSince(owner: string, cursor: string | null, options?: ListFilesOptions): Promise<FileListResult>; getSchema(schemaId: string): Promise<Schema | null>; registerServer(params: RegisterServerParams): Promise<RegisterServerResult>; registerFile(params: RegisterFileParams): Promise<{ fileId?: string; }>; createGrant(params: CreateGrantParams): Promise<{ grantId?: string; }>; revokeGrant(params: RevokeGrantParams): Promise<void>; /** * Soft-deletes (de-registers) a file at the gateway. Resolves on 200 and on 409 * (already deleted) — 409 is treated as idempotent success. Other non-2xx, including * 404 (file not registered), throw; the PS delete cascade decides whether a 404 is * benign (blob already gone) or a hard failure. */ deleteFile(params: DeleteFileParams): Promise<void>; } export declare function createGatewayClient(baseUrl: string): GatewayClient;