@human-0/posh-sdk
Version:
TypeScript SDK for Proof of Sustainable Humanity (PoSH) identity management
200 lines (187 loc) • 7.61 kB
text/typescript
import { B as BaseProvider, C as ContractCallParams, T as TransactionParams, a as TransactionReceipt, P as ProviderEventFilter, b as ProviderEventLog, c as ProviderEventCallback, d as ProviderUnsubscribe, A as Address, H as HumanId, e as PoshConfig } from './PoshClient-B0NmxKnm.cjs';
export { s as AggregateOptions, x as EventFilter, E as EventManager, k as ExternalProof, u as HumanRegisteredEvent, j as Identity, w as IdentityLinkedEvent, I as IdentityManager, q as ImpactSummary, n as ImpactType, g as PoshClient, f as PoshClientConfig, l as Proof, p as ProofFilter, i as ProofManager, o as ProofQueryOptions, v as ProofRegisteredEvent, m as ProofTier, R as RegisterResult, t as ScoreLevel, S as ScoreManager, r as TierBreakdown, y as TransactionHash, h as TransactionResult, U as Unsubscribe } from './PoshClient-B0NmxKnm.cjs';
import { PublicClient, WalletClient, Hash } from 'viem';
/**
* Viem provider adapter
* Implements BaseProvider using Viem's PublicClient and WalletClient
*/
interface ViemProviderConfig {
publicClient: PublicClient;
walletClient?: WalletClient;
}
declare class ViemProvider implements BaseProvider {
private publicClient;
private walletClient?;
constructor(config: ViemProviderConfig);
readContract<T = any>(params: ContractCallParams): Promise<T>;
writeContract(params: TransactionParams): Promise<Hash>;
waitForTransaction(hash: Hash): Promise<TransactionReceipt>;
estimateGas(params: TransactionParams): Promise<bigint>;
getEvents(params: ContractCallParams & {
filter: ProviderEventFilter;
}): Promise<ProviderEventLog[]>;
watchEvent(params: ContractCallParams & {
callback: ProviderEventCallback;
}): ProviderUnsubscribe;
getBlockNumber(): Promise<bigint>;
getChainId(): Promise<number>;
}
/**
* Contract addresses for different networks
*
* Note: These are placeholder addresses until contracts are deployed
*/
interface ContractAddresses {
humanIdentity: Address;
proofRegistry: Address;
poshNFT: Address;
humanScore: Address;
}
/**
* Base Sepolia testnet addresses (placeholder)
*/
declare const BASE_SEPOLIA_ADDRESSES: ContractAddresses;
/**
* Base mainnet addresses (placeholder)
*/
declare const BASE_MAINNET_ADDRESSES: ContractAddresses;
/**
* Get contract addresses for a given chain ID
*/
declare function getContractAddresses(chainId: number): ContractAddresses | null;
/**
* Contract Registry - Support for multiple contract deployments
*
* This allows the SDK to work with any PoSH-compatible contract deployment,
* not just a single authority's contracts.
*/
interface ContractDeployment {
name: string;
description: string;
chainId: number;
addresses: ContractAddresses;
deployer?: Address;
deployedAt?: Date;
verified?: boolean;
}
/**
* Registry of known PoSH contract deployments
* Anyone can add their deployment here or use custom addresses
*/
declare const KNOWN_DEPLOYMENTS: Record<string, ContractDeployment>;
/**
* Get a known deployment by name
*/
declare function getDeployment(name: string): ContractDeployment | null;
/**
* Register a new deployment (for community use)
*/
declare function registerDeployment(name: string, deployment: ContractDeployment): void;
/**
* List all known deployments
*/
declare function listDeployments(): ContractDeployment[];
/**
* Find deployments by chain ID
*/
declare function getDeploymentsByChain(chainId: number): ContractDeployment[];
/**
* Error classes and error handling utilities
*/
declare class PoshSDKError extends Error {
code: string;
details?: unknown;
remediation?: string;
constructor(message: string, code: string, details?: unknown, remediation?: string);
}
declare class ValidationError extends PoshSDKError {
constructor(message: string, details?: unknown, remediation?: string);
}
declare class ContractError extends PoshSDKError {
contractName: string;
functionName: string;
revertReason?: string;
constructor(message: string, contractName: string, functionName: string, revertReason?: string, details?: unknown, remediation?: string);
}
declare class NetworkError extends PoshSDKError {
chainId: number;
rpcUrl: string;
constructor(message: string, chainId: number, rpcUrl: string, details?: unknown, remediation?: string);
}
declare class ConfigurationError extends PoshSDKError {
constructor(message: string, details?: unknown, remediation?: string);
}
declare enum ErrorCode {
INVALID_ADDRESS = "INVALID_ADDRESS",
INVALID_HUMAN_ID = "INVALID_HUMAN_ID",
INVALID_CONFIG = "INVALID_CONFIG",
ALREADY_REGISTERED = "ALREADY_REGISTERED",
NOT_REGISTERED = "NOT_REGISTERED",
HUMAN_NOT_FOUND = "HUMAN_NOT_FOUND",
PROOF_NOT_FOUND = "PROOF_NOT_FOUND",
RPC_ERROR = "RPC_ERROR",
NETWORK_TIMEOUT = "NETWORK_TIMEOUT",
RATE_LIMITED = "RATE_LIMITED",
TRANSACTION_FAILED = "TRANSACTION_FAILED",
GAS_ESTIMATION_FAILED = "GAS_ESTIMATION_FAILED",
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
PROVIDER_NOT_CONNECTED = "PROVIDER_NOT_CONNECTED",
UNSUPPORTED_PROVIDER = "UNSUPPORTED_PROVIDER",
WALLET_DISCONNECTED = "WALLET_DISCONNECTED"
}
/**
* Validation utilities for SDK inputs
*/
/**
* Validates an Ethereum address format
*/
declare function isValidAddress(address: string): address is Address;
/**
* Validates a humanId format (bytes32)
*/
declare function isValidHumanId(_humanId: string): _humanId is HumanId;
/**
* Validates SDK configuration
*/
declare function validateConfig(config: PoshConfig): void;
/**
* Creates default configuration for Base Sepolia testnet
*/
declare function createDefaultConfig(overrides?: Partial<PoshConfig>): PoshConfig;
/**
* Create configuration from a deployment name
* This allows using pre-registered deployments
*/
declare function createConfigFromDeployment(deploymentName: string, overrides?: Partial<PoshConfig>): Promise<PoshConfig>;
/**
* Validates an address and throws if invalid
*/
declare function validateAddress(address: string, paramName?: string): Address;
/**
* Validates a humanId and throws if invalid
*/
declare function validateHumanId(_humanId: string, _paramName?: string): HumanId;
/**
* Formatting utilities for displaying data
*/
/**
* Format a humanId for display (truncated)
*/
declare function formatHumanId(humanId: HumanId, length?: number): string;
/**
* Format an address for display (truncated)
*/
declare function formatAddress(address: Address, length?: number): string;
/**
* Format a bigint value for display
*/
declare function formatImpactValue(value: bigint, decimals?: number): string;
/**
* Format a date for display
*/
declare function formatDate(date: Date): string;
/**
* Format a date with time for display
*/
declare function formatDateTime(date: Date): string;
export { Address, BASE_MAINNET_ADDRESSES, BASE_SEPOLIA_ADDRESSES, BaseProvider, ConfigurationError, type ContractAddresses, ContractCallParams, type ContractDeployment, ContractError, ErrorCode, HumanId, KNOWN_DEPLOYMENTS, NetworkError, PoshConfig, PoshSDKError, ProviderEventCallback, ProviderEventFilter, ProviderEventLog, ProviderUnsubscribe, TransactionParams, TransactionReceipt, ValidationError, ViemProvider, type ViemProviderConfig, createConfigFromDeployment, createDefaultConfig, formatAddress, formatDate, formatDateTime, formatHumanId, formatImpactValue, getContractAddresses, getDeployment, getDeploymentsByChain, isValidAddress, isValidHumanId, listDeployments, registerDeployment, validateAddress, validateConfig, validateHumanId };