UNPKG

wttp-core

Version:

Core contracts, interfaces, and TypeScript types for the Web3 Transfer Protocol (WTTP).

476 lines 12.5 kB
/** * WTTP Methods Enum - mirrors the Solidity enum * Used for method-based access control and request handling */ export declare enum Method { /** Retrieve only resource headers and metadata */ HEAD = 0, /** Retrieve resource content */ GET = 1, /** Submit data to be processed (not fully implemented in WTTP) */ POST = 2, /** Create or replace a resource */ PUT = 3, /** Update parts of a resource */ PATCH = 4, /** Remove a resource */ DELETE = 5, /** Query which methods are supported for a resource */ OPTIONS = 6, /** Retrieve storage locations for resource data points */ LOCATE = 7, /** Update resource headers */ DEFINE = 8 } /** * Gets the total number of methods in the Method enum * @returns The count of methods (currently 9) */ export declare function getMethodCount(): number; /** * Converts an array of methods to a bitmask representation * Used for efficient method permission storage (1 bit per method) * @param methods Array of WTTP methods to convert * @returns Bitmask representing allowed methods as uint16 */ export declare function methodsToBitmask(methods: Method[]): number; /** * Converts a bitmask back to an array of methods * @param mask The bitmask to convert * @returns Array of methods represented by the bitmask */ export declare function bitmaskToMethods(mask: number): Method[]; /** * All methods bitmask - enables all 9 methods */ export declare const ALL_METHODS_BITMASK: number; /** * Read-only methods bitmask - only HEAD, GET, OPTIONS, LOCATE */ export declare const READ_ONLY_METHODS_BITMASK: number; /** * Write methods bitmask - POST, PUT, PATCH, DELETE, DEFINE */ export declare const WRITE_METHODS_BITMASK: number; /** * Default admin role - uses ethers ZeroHash * Admins have full access to all resources and methods */ export declare const DEFAULT_ADMIN_ROLE: string; /** * Blacklist role - computed using keccak256("BLACKLIST_ROLE") * Accounts with this role are denied access to all methods */ export declare const BLACKLIST_ROLE: string; /** * Public access role - allows unrestricted access * Uses all 1s in bytes32 format for maximum permissiveness */ export declare const PUBLIC_ROLE = "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; /** * Intra-site communication role - for internal service-to-service communication * Different from existing roles, used for trusted internal operations */ export declare const INTRA_SITE_ROLE: string; /** * Collection of all default roles for easy access */ export declare const DEFAULT_ROLES: { readonly ADMIN: string; readonly BLACKLIST: string; readonly PUBLIC: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; readonly INTRA_SITE: string; }; /** * Master chain ID - currently set to Sepolia testnet * Chain ID 11155111 for Ethereum Sepolia testnet */ export declare const MASTER_CHAIN_ID = 11155111; /** * Creates an origins array with exactly getMethodCount() elements * @param role The role to assign to all methods * @returns Origins array suitable for CORSPolicy */ export declare function createOriginsArray(role: string): string[]; /** * Creates an origins array with different roles for read vs write operations * @param readRole Role for read operations (HEAD, GET, OPTIONS, LOCATE) * @param writeRole Role for write operations (POST, PUT, PATCH, DELETE, DEFINE) * @returns Origins array with mixed access */ export declare function createMixedOriginsArray(readRole: string, writeRole: string): string[]; /** * Origins preset: All methods public */ export declare const ORIGINS_PUBLIC: string[]; /** * Origins preset: All methods admin only */ export declare const ORIGINS_ADMIN_ONLY: string[]; /** * Origins preset: All methods blacklisted (denied) */ export declare const ORIGINS_BLACKLISTED: string[]; /** * Origins preset: All methods for intra-site communication */ export declare const ORIGINS_INTRA_SITE: string[]; /** * Origins preset: Read methods public, write methods admin */ export declare const ORIGINS_READ_PUBLIC_WRITE_ADMIN: string[]; /** * Origins preset: Read methods public, write methods intra-site */ export declare const ORIGINS_READ_PUBLIC_WRITE_INTRA: string[]; /** * Origins preset: Read methods public, write methods blacklisted */ export declare const ORIGINS_READ_ONLY_PUBLIC: string[]; /** * Origins preset: API pattern - read public, post/patch intra-site, put/delete/define admin */ export declare const ORIGINS_API_PATTERN: string[]; /** * Origins preset: Immutable content - read public, patch/delete blacklisted, others admin */ export declare const ORIGINS_IMMUTABLE_CONTENT: string[]; /** * Collection of all origins presets for easy access */ export declare const ORIGINS_PRESETS: { readonly PUBLIC: string[]; readonly ADMIN_ONLY: string[]; readonly BLACKLISTED: string[]; readonly INTRA_SITE: string[]; readonly READ_PUBLIC_WRITE_ADMIN: string[]; readonly READ_PUBLIC_WRITE_INTRA: string[]; readonly READ_ONLY_PUBLIC: string[]; readonly API_PATTERN: string[]; readonly IMMUTABLE_CONTENT: string[]; }; /** * Fully public header - allows all methods for all users * Uses PUBLIC_ROLE for all method access */ export declare const PUBLIC_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Admin-only header - restricts all methods to admin role * Only admins can access any methods */ export declare const ADMIN_ONLY_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Read-only public header - allows read operations for public, write operations for admins * Balanced access control for content sites */ export declare const READ_ONLY_PUBLIC_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * API header - designed for API endpoints with mixed access patterns * Read operations public, write operations restricted */ export declare const API_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Intra-site communication header - for internal service communication * Only allows intra-site role and admin access */ export declare const INTRA_SITE_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Immutable public content header - for permanent, cacheable public content * Content that never changes and can be cached indefinitely */ export declare const IMMUTABLE_PUBLIC_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Read-only public header with limited methods - only allows read operations * Completely prevents write operations by not including them in methods bitmask */ export declare const STRICT_READ_ONLY_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Collection of all default headers for easy access */ export declare const DEFAULT_HEADERS: { readonly PUBLIC: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; readonly ADMIN_ONLY: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; readonly READ_ONLY_PUBLIC: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; readonly API: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; readonly INTRA_SITE: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; readonly IMMUTABLE_PUBLIC: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; readonly STRICT_READ_ONLY: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; }; /** * Default header to use when no specific header is specified * Uses read-only public access pattern as a sensible default */ export declare const DEFAULT_HEADER: { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; /** * Creates a custom header with specified parameters * @param options Header configuration options * @returns Complete HeaderInfoStruct */ export declare function createCustomHeader(options: { methods?: Method[]; origins?: string[]; cachePreset?: number; corsPreset?: number; immutable?: boolean; redirectCode?: number; redirectLocation?: string; customCache?: string; customCors?: string; }): { cache: { immutableFlag: boolean; preset: number; custom: string; }; cors: { methods: number; origins: string[]; preset: number; custom: string; }; redirect: { code: number; location: string; }; }; //# sourceMappingURL=constants.d.ts.map