@human-0/posh-sdk
Version:
TypeScript SDK for Proof of Sustainable Humanity (PoSH) identity management
960 lines (944 loc) • 28.4 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/contracts/registry.ts
var registry_exports = {};
__export(registry_exports, {
KNOWN_DEPLOYMENTS: () => KNOWN_DEPLOYMENTS,
getDeployment: () => getDeployment,
getDeploymentsByChain: () => getDeploymentsByChain,
listDeployments: () => listDeployments,
registerDeployment: () => registerDeployment
});
function getDeployment(name) {
return KNOWN_DEPLOYMENTS[name] || null;
}
function registerDeployment(name, deployment) {
KNOWN_DEPLOYMENTS[name] = deployment;
}
function listDeployments() {
return Object.values(KNOWN_DEPLOYMENTS);
}
function getDeploymentsByChain(chainId) {
return Object.values(KNOWN_DEPLOYMENTS).filter((d) => d.chainId === chainId);
}
var KNOWN_DEPLOYMENTS;
var init_registry = __esm({
"src/contracts/registry.ts"() {
KNOWN_DEPLOYMENTS = {
// Official HUMAN-0 deployment on Base Sepolia (testnet)
"human0-base-sepolia": {
name: "HUMAN-0 Base Sepolia",
description: "Official HUMAN-0 testnet deployment",
chainId: 84532,
addresses: {
humanIdentity: "0x00000000000000000000000000000000000000001",
proofRegistry: "0x00000000000000000000000000000000000000002",
poshNFT: "0x00000000000000000000000000000000000000003",
humanScore: "0x00000000000000000000000000000000000000004"
},
verified: false
// Will be true once deployed and verified
},
// Official HUMAN-0 deployment on Base Mainnet
"human0-base-mainnet": {
name: "HUMAN-0 Base Mainnet",
description: "Official HUMAN-0 mainnet deployment",
chainId: 8453,
addresses: {
humanIdentity: "0x00000000000000000000000000000000000000011",
proofRegistry: "0x00000000000000000000000000000000000000012",
poshNFT: "0x00000000000000000000000000000000000000013",
humanScore: "0x00000000000000000000000000000000000000014"
},
verified: false
}
// Example: Community deployment
// 'community-optimism': {
// name: 'Community PoSH on Optimism',
// description: 'Community-run PoSH deployment',
// chainId: 10,
// addresses: { ... },
// },
};
}
});
// src/utils/errors.ts
var PoshSDKError = class extends Error {
constructor(message, code, details, remediation) {
super(message);
this.name = "PoshSDKError";
this.code = code;
this.details = details;
this.remediation = remediation;
}
};
var ValidationError = class extends PoshSDKError {
constructor(message, details, remediation) {
super(message, "VALIDATION_ERROR", details, remediation);
this.name = "ValidationError";
}
};
var ContractError = class extends PoshSDKError {
constructor(message, contractName, functionName, revertReason, details, remediation) {
super(message, "CONTRACT_ERROR", details, remediation);
this.name = "ContractError";
this.contractName = contractName;
this.functionName = functionName;
this.revertReason = revertReason;
}
};
var NetworkError = class extends PoshSDKError {
constructor(message, chainId, rpcUrl, details, remediation) {
super(message, "NETWORK_ERROR", details, remediation);
this.name = "NetworkError";
this.chainId = chainId;
this.rpcUrl = rpcUrl;
}
};
var ConfigurationError = class extends PoshSDKError {
constructor(message, details, remediation) {
super(message, "CONFIGURATION_ERROR", details, remediation);
this.name = "ConfigurationError";
}
};
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
ErrorCode2["INVALID_ADDRESS"] = "INVALID_ADDRESS";
ErrorCode2["INVALID_HUMAN_ID"] = "INVALID_HUMAN_ID";
ErrorCode2["INVALID_CONFIG"] = "INVALID_CONFIG";
ErrorCode2["ALREADY_REGISTERED"] = "ALREADY_REGISTERED";
ErrorCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
ErrorCode2["HUMAN_NOT_FOUND"] = "HUMAN_NOT_FOUND";
ErrorCode2["PROOF_NOT_FOUND"] = "PROOF_NOT_FOUND";
ErrorCode2["RPC_ERROR"] = "RPC_ERROR";
ErrorCode2["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
ErrorCode2["RATE_LIMITED"] = "RATE_LIMITED";
ErrorCode2["TRANSACTION_FAILED"] = "TRANSACTION_FAILED";
ErrorCode2["GAS_ESTIMATION_FAILED"] = "GAS_ESTIMATION_FAILED";
ErrorCode2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
ErrorCode2["PROVIDER_NOT_CONNECTED"] = "PROVIDER_NOT_CONNECTED";
ErrorCode2["UNSUPPORTED_PROVIDER"] = "UNSUPPORTED_PROVIDER";
ErrorCode2["WALLET_DISCONNECTED"] = "WALLET_DISCONNECTED";
return ErrorCode2;
})(ErrorCode || {});
// src/utils/validation.ts
function isValidAddress(address) {
return /^0x[a-fA-F0-9]{40}$/.test(address);
}
function isValidHumanId(_humanId) {
return /^0x[a-fA-F0-9]{64}$/.test(_humanId);
}
function validateConfig(config) {
if (typeof config.chainId !== "number" || config.chainId <= 0 || Number.isNaN(config.chainId)) {
throw new ValidationError(
"Invalid chainId: must be a positive number",
{ chainId: config.chainId },
"Provide a valid chainId (e.g., 84532 for Base Sepolia, 8453 for Base Mainnet)"
);
}
if (!config.contracts) {
throw new ValidationError(
"Missing contracts configuration",
void 0,
"Provide contract addresses for humanIdentity, proofRegistry, poshNFT, and humanScore"
);
}
const requiredContracts = ["humanIdentity", "proofRegistry", "poshNFT", "humanScore"];
for (const contractName of requiredContracts) {
const address = config.contracts[contractName];
if (!address) {
throw new ValidationError(
`Missing contract address: ${contractName}`,
{ contractName },
`Provide a valid address for ${contractName} contract`
);
}
if (!isValidAddress(address)) {
throw new ValidationError(
`Invalid contract address for ${contractName}: ${address}`,
{ contractName, address },
"Provide a valid Ethereum address (0x followed by 40 hexadecimal characters)"
);
}
}
if (config.rpcUrl !== void 0) {
if (typeof config.rpcUrl !== "string" || config.rpcUrl.trim() === "") {
throw new ValidationError(
"Invalid rpcUrl: must be a non-empty string",
{ rpcUrl: config.rpcUrl },
"Provide a valid RPC URL (e.g., https://sepolia.base.org)"
);
}
try {
new URL(config.rpcUrl);
} catch {
throw new ValidationError(
`Invalid rpcUrl format: ${config.rpcUrl}`,
{ rpcUrl: config.rpcUrl },
"Provide a valid URL for the RPC endpoint"
);
}
}
if (config.cache !== void 0) {
if (typeof config.cache.enabled !== "boolean") {
throw new ValidationError(
"Invalid cache.enabled: must be a boolean",
{ enabled: config.cache.enabled },
"Set cache.enabled to true or false"
);
}
if (typeof config.cache.ttl !== "number" || config.cache.ttl < 0) {
throw new ValidationError(
"Invalid cache.ttl: must be a non-negative number",
{ ttl: config.cache.ttl },
"Set cache.ttl to a positive number in milliseconds (e.g., 60000 for 1 minute)"
);
}
if (typeof config.cache.maxSize !== "number" || config.cache.maxSize <= 0) {
throw new ValidationError(
"Invalid cache.maxSize: must be a positive number",
{ maxSize: config.cache.maxSize },
"Set cache.maxSize to a positive number (e.g., 1000)"
);
}
}
if (config.retry !== void 0) {
if (typeof config.retry.enabled !== "boolean") {
throw new ValidationError(
"Invalid retry.enabled: must be a boolean",
{ enabled: config.retry.enabled },
"Set retry.enabled to true or false"
);
}
if (typeof config.retry.maxAttempts !== "number" || config.retry.maxAttempts < 1) {
throw new ValidationError(
"Invalid retry.maxAttempts: must be at least 1",
{ maxAttempts: config.retry.maxAttempts },
"Set retry.maxAttempts to a positive number (e.g., 3)"
);
}
if (config.retry.backoff !== "linear" && config.retry.backoff !== "exponential") {
throw new ValidationError(
'Invalid retry.backoff: must be "linear" or "exponential"',
{ backoff: config.retry.backoff },
'Set retry.backoff to either "linear" or "exponential"'
);
}
if (typeof config.retry.initialDelay !== "number" || config.retry.initialDelay < 0) {
throw new ValidationError(
"Invalid retry.initialDelay: must be a non-negative number",
{ initialDelay: config.retry.initialDelay },
"Set retry.initialDelay to a positive number in milliseconds (e.g., 1000 for 1 second)"
);
}
}
}
function createDefaultConfig(overrides) {
const defaultConfig = {
chainId: 84532,
// Base Sepolia
contracts: {
// These are placeholder addresses - should be replaced with actual deployed addresses
humanIdentity: "0x0000000000000000000000000000000000000001",
proofRegistry: "0x0000000000000000000000000000000000000002",
poshNFT: "0x0000000000000000000000000000000000000003",
humanScore: "0x0000000000000000000000000000000000000004"
},
cache: {
enabled: true,
ttl: 6e4,
// 1 minute
maxSize: 1e3
},
retry: {
enabled: true,
maxAttempts: 3,
backoff: "exponential",
initialDelay: 1e3
// 1 second
}
};
return {
...defaultConfig,
...overrides,
contracts: {
...defaultConfig.contracts,
...overrides?.contracts
},
cache: overrides?.cache ? {
...defaultConfig.cache,
...overrides.cache
} : defaultConfig.cache,
retry: overrides?.retry ? {
...defaultConfig.retry,
...overrides.retry
} : defaultConfig.retry
};
}
async function createConfigFromDeployment(deploymentName, overrides) {
const { getDeployment: getDeployment2 } = await Promise.resolve().then(() => (init_registry(), registry_exports));
const deployment = getDeployment2(deploymentName);
if (!deployment) {
throw new ValidationError(
`Unknown deployment: ${deploymentName}`,
{ deploymentName },
"Use a known deployment name or provide custom contract addresses"
);
}
return createDefaultConfig({
chainId: deployment.chainId,
contracts: deployment.addresses,
...overrides
});
}
function validateAddress(address, paramName = "address") {
if (!isValidAddress(address)) {
throw new ValidationError(
`Invalid ${paramName}: ${address}`,
{ [paramName]: address },
"Provide a valid Ethereum address (0x followed by 40 hexadecimal characters)"
);
}
return address;
}
function validateHumanId(_humanId, _paramName = "humanId") {
if (!isValidHumanId(_humanId)) {
throw new ValidationError(
`Invalid ${_paramName}: ${_humanId}`,
{ [_paramName]: _humanId },
"Provide a valid humanId (0x followed by 64 hexadecimal characters)"
);
}
return _humanId;
}
// src/utils/cache.ts
var Cache = class {
constructor(ttl = 6e4, maxSize = 1e3) {
this.cache = /* @__PURE__ */ new Map();
this.ttl = ttl;
this.maxSize = maxSize;
}
set(key, value) {
if (this.cache.size >= this.maxSize) {
const firstKey = this.cache.keys().next().value;
if (firstKey) {
this.cache.delete(firstKey);
}
}
this.cache.set(key, {
value,
expiresAt: Date.now() + this.ttl
});
}
get(key) {
const entry = this.cache.get(key);
if (!entry) {
return null;
}
if (Date.now() > entry.expiresAt) {
this.cache.delete(key);
return null;
}
return entry.value;
}
has(key) {
return this.get(key) !== null;
}
delete(key) {
this.cache.delete(key);
}
clear() {
this.cache.clear();
}
size() {
return this.cache.size;
}
};
// src/contracts/abis.ts
var HUMAN_IDENTITY_ABI = [
{
type: "function",
name: "register",
inputs: [],
outputs: [{ name: "humanId", type: "bytes32" }],
stateMutability: "nonpayable"
},
{
type: "function",
name: "isRegistered",
inputs: [{ name: "wallet", type: "address" }],
outputs: [{ name: "", type: "bool" }],
stateMutability: "view"
},
{
type: "function",
name: "getHumanId",
inputs: [{ name: "wallet", type: "address" }],
outputs: [{ name: "", type: "bytes32" }],
stateMutability: "view"
},
{
type: "event",
name: "HumanRegistered",
inputs: [
{ name: "humanId", type: "bytes32", indexed: true },
{ name: "wallet", type: "address", indexed: true },
{ name: "timestamp", type: "uint256", indexed: false }
]
}
];
// src/core/IdentityManager.ts
var IdentityManager = class {
constructor(config, provider) {
this.config = config;
this.provider = provider;
this.cache = new Cache(
config.cache?.ttl || 6e4,
config.cache?.maxSize || 1e3
);
}
/**
* Check if an address is registered
* Note: Mock implementation - returns false until contracts are deployed
*/
async isRegistered(address) {
validateAddress(address);
const cacheKey = `isRegistered:${address}`;
const cached = this.cache.get(cacheKey);
if (cached !== null) {
return cached;
}
const result = false;
if (this.config.cache?.enabled) {
this.cache.set(cacheKey, result);
}
return result;
}
/**
* Get humanId for an address
* Note: Mock implementation - returns null until contracts are deployed
*/
async getHumanId(address) {
validateAddress(address);
const cacheKey = `humanId:${address}`;
const cached = this.cache.get(cacheKey);
if (cached !== null) {
return cached;
}
const result = null;
if (this.config.cache?.enabled) {
this.cache.set(cacheKey, result);
}
return result;
}
/**
* Get wallet address for a humanId
* Note: Mock implementation
*/
async getWallet(_humanId) {
return "0x0000000000000000000000000000000000000000";
}
/**
* Get registration time for a humanId
* Note: Mock implementation
*/
async getRegistrationTime(_humanId) {
return /* @__PURE__ */ new Date();
}
/**
* Register a new identity
* Requires a provider with write capabilities
*/
async register() {
if (!this.provider) {
throw new PoshSDKError(
"Provider required for write operations",
"PROVIDER_REQUIRED",
"Initialize PoshClient with a provider that supports write operations"
);
}
try {
const hash = await this.provider.writeContract({
address: this.config.contracts.humanIdentity,
abi: HUMAN_IDENTITY_ABI,
functionName: "register",
args: []
});
const receipt = await this.provider.waitForTransaction(hash);
if (receipt.status !== "success") {
throw new PoshSDKError(
"Registration transaction failed",
"TRANSACTION_FAILED",
"The registration transaction was reverted. Please try again."
);
}
const humanId = "0x0000000000000000000000000000000000000000000000000000000000000000";
this.cache.clear();
return {
hash,
humanId
};
} catch (error) {
if (error instanceof PoshSDKError) {
throw error;
}
throw new PoshSDKError(
"Failed to register identity",
"REGISTRATION_FAILED",
error instanceof Error ? error.message : "Unknown error occurred"
);
}
}
/**
* Link an external proof to identity
* Requires a provider with write capabilities
*/
async linkExternalProof(_proofHash, _provider) {
if (!this.provider) {
throw new PoshSDKError(
"Provider required for write operations",
"PROVIDER_REQUIRED",
"Initialize PoshClient with a provider that supports write operations"
);
}
try {
throw new PoshSDKError(
"External proof linking not yet implemented",
"NOT_IMPLEMENTED",
"This feature will be available in a future version"
);
} catch (error) {
if (error instanceof PoshSDKError) {
throw error;
}
throw new PoshSDKError(
"Failed to link external proof",
"LINK_PROOF_FAILED",
error instanceof Error ? error.message : "Unknown error occurred"
);
}
}
/**
* Estimate gas for registration
*/
async estimateRegisterGas() {
if (!this.provider) {
throw new PoshSDKError(
"Provider required for gas estimation",
"PROVIDER_REQUIRED",
"Initialize PoshClient with a provider"
);
}
try {
const gas = await this.provider.estimateGas({
address: this.config.contracts.humanIdentity,
abi: HUMAN_IDENTITY_ABI,
functionName: "register",
args: []
});
return gas;
} catch (error) {
throw new PoshSDKError(
"Failed to estimate gas",
"GAS_ESTIMATION_FAILED",
error instanceof Error ? error.message : "Unknown error occurred"
);
}
}
/**
* Estimate gas for linking external proof
*/
async estimateLinkProofGas() {
if (!this.provider) {
throw new PoshSDKError(
"Provider required for gas estimation",
"PROVIDER_REQUIRED",
"Initialize PoshClient with a provider"
);
}
return 150000n;
}
};
// src/core/ProofManager.ts
var ProofManager = class {
constructor(config, _provider) {
this.config = config;
this.cache = new Cache(
config.cache?.ttl || 6e4,
config.cache?.maxSize || 1e3
);
}
/**
* Get all proofs for a humanId
* Note: Mock implementation - returns empty array until contracts are deployed
*/
async getHumanProofs(humanId, options) {
const cacheKey = `proofs:${humanId}:${JSON.stringify(options || {})}`;
const cached = this.cache.get(cacheKey);
if (cached !== null) {
return cached;
}
const result = [];
if (this.config.cache?.enabled) {
this.cache.set(cacheKey, result);
}
return result;
}
/**
* Get proof count for a humanId
* Note: Mock implementation
*/
async getProofCount(humanId) {
const proofs = await this.getHumanProofs(humanId);
return proofs.length;
}
/**
* Get total impact for a humanId
* Note: Mock implementation - returns 0 until contracts are deployed
*/
async getTotalImpact(humanId, impactType) {
const proofs = await this.getHumanProofs(humanId);
if (impactType) {
return proofs.filter((p) => p.impactType === impactType).reduce((sum, p) => sum + p.impactValue, 0n);
}
return proofs.reduce((sum, p) => sum + p.impactValue, 0n);
}
};
// src/core/ScoreManager.ts
var ScoreManager = class {
constructor(config, _provider) {
this.config = config;
this.cache = new Cache(
config.cache?.ttl || 6e4,
config.cache?.maxSize || 1e3
);
}
/**
* Get score for a humanId
* Note: Mock implementation - returns 0 until contracts are deployed
*/
async getScore(humanId) {
const cacheKey = `score:${humanId}`;
const cached = this.cache.get(cacheKey);
if (cached !== null) {
return cached;
}
const result = 0;
if (this.config.cache?.enabled) {
this.cache.set(cacheKey, result);
}
return result;
}
/**
* Get level for a humanId
* Note: Mock implementation
*/
async getLevel(humanId) {
const score = await this.getScore(humanId);
return this.getLevelFromScore(score);
}
/**
* Check if score meets threshold
*/
async meetsThreshold(humanId, threshold) {
const score = await this.getScore(humanId);
return score >= threshold;
}
/**
* Get tier breakdown for a humanId
* Note: Mock implementation
*/
async getTierBreakdown(_humanId) {
return {
tierA: 0,
tierB: 0,
tierC: 0,
total: 0
};
}
/**
* Get level from score value
*/
getLevelFromScore(score) {
if (score >= 1e6) {
return { level: 5, name: "Diamond", minScore: 1e6, maxScore: null };
}
if (score >= 1e5) {
return { level: 4, name: "Platinum", minScore: 1e5, maxScore: 999999 };
}
if (score >= 1e4) {
return { level: 3, name: "Gold", minScore: 1e4, maxScore: 99999 };
}
if (score >= 1e3) {
return { level: 2, name: "Silver", minScore: 1e3, maxScore: 9999 };
}
if (score >= 100) {
return { level: 1, name: "Bronze", minScore: 100, maxScore: 999 };
}
return { level: 0, name: "None", minScore: 0, maxScore: 99 };
}
};
// src/core/EventManager.ts
var EventManager = class {
constructor(_config, _provider) {
}
/**
* Subscribe to HumanRegistered events
* Note: Mock implementation - no events until contracts are deployed
*/
onHumanRegistered(_callback) {
return () => {
};
}
/**
* Subscribe to ProofRegistered events
* Note: Mock implementation
*/
onProofRegistered(_callback) {
return () => {
};
}
/**
* Subscribe to IdentityLinked events
* Note: Mock implementation
*/
onIdentityLinked(_callback) {
return () => {
};
}
/**
* Get historical HumanRegistered events
* Note: Mock implementation
*/
async getHumanRegisteredEvents(_filter) {
return [];
}
/**
* Get historical ProofRegistered events
* Note: Mock implementation
*/
async getProofRegisteredEvents(_filter) {
return [];
}
/**
* Get historical IdentityLinked events
* Note: Mock implementation
*/
async getIdentityLinkedEvents(_filter) {
return [];
}
};
// src/core/PoshClient.ts
var PoshClient = class {
constructor(config) {
validateConfig(config);
this.config = config;
this.provider = config.provider;
this.identity = new IdentityManager(config, this.provider);
this.proofs = new ProofManager(config, this.provider);
this.score = new ScoreManager(config, this.provider);
this.events = new EventManager(config, this.provider);
}
/**
* Get current configuration
*/
getConfig() {
return { ...this.config };
}
/**
* Update configuration
* Note: This creates a new client instance internally
*/
updateConfig(updates) {
this.config = {
...this.config,
...updates,
contracts: {
...this.config.contracts,
...updates.contracts
}
};
validateConfig(this.config);
}
};
// src/types/proof.ts
var ProofTier = /* @__PURE__ */ ((ProofTier2) => {
ProofTier2[ProofTier2["A"] = 1] = "A";
ProofTier2[ProofTier2["B"] = 2] = "B";
ProofTier2[ProofTier2["C"] = 3] = "C";
return ProofTier2;
})(ProofTier || {});
// src/providers/ViemProvider.ts
var ViemProvider = class {
constructor(config) {
this.publicClient = config.publicClient;
this.walletClient = config.walletClient;
}
async readContract(params) {
const result = await this.publicClient.readContract({
address: params.address,
abi: params.abi,
functionName: params.functionName,
args: params.args || []
});
return result;
}
async writeContract(params) {
if (!this.walletClient) {
throw new Error("WalletClient is required for write operations");
}
const { request } = await this.publicClient.simulateContract({
address: params.address,
abi: params.abi,
functionName: params.functionName,
args: params.args || [],
value: params.value,
gas: params.gas,
account: this.walletClient.account
});
const hash = await this.walletClient.writeContract(request);
return hash;
}
async waitForTransaction(hash) {
const receipt = await this.publicClient.waitForTransactionReceipt({
hash
});
return {
transactionHash: receipt.transactionHash,
blockNumber: receipt.blockNumber,
status: receipt.status,
gasUsed: receipt.gasUsed,
logs: receipt.logs
};
}
async estimateGas(params) {
if (!this.walletClient) {
throw new Error("WalletClient is required for gas estimation");
}
const gas = await this.publicClient.estimateContractGas({
address: params.address,
abi: params.abi,
functionName: params.functionName,
args: params.args || [],
value: params.value,
account: this.walletClient.account
});
return gas;
}
async getEvents(params) {
const logs = await this.publicClient.getLogs({
address: params.address,
fromBlock: params.filter.fromBlock,
toBlock: params.filter.toBlock,
event: params.abi.find((item) => item.name === params.functionName)
});
return logs.map((log) => ({
address: log.address,
topics: log.topics,
data: log.data,
blockNumber: log.blockNumber,
transactionHash: log.transactionHash,
logIndex: log.logIndex
}));
}
watchEvent(params) {
const unwatch = this.publicClient.watchContractEvent({
address: params.address,
abi: params.abi,
eventName: params.functionName,
onLogs: (logs) => {
logs.forEach((log) => {
params.callback({
address: log.address,
topics: log.topics,
data: log.data,
blockNumber: log.blockNumber,
transactionHash: log.transactionHash,
logIndex: log.logIndex
});
});
}
});
return unwatch;
}
async getBlockNumber() {
return await this.publicClient.getBlockNumber();
}
async getChainId() {
return await this.publicClient.getChainId();
}
};
// src/index.ts
init_registry();
// src/contracts/addresses.ts
var BASE_SEPOLIA_ADDRESSES = {
humanIdentity: "0x00000000000000000000000000000000000000001",
proofRegistry: "0x00000000000000000000000000000000000000002",
poshNFT: "0x00000000000000000000000000000000000000003",
humanScore: "0x00000000000000000000000000000000000000004"
};
var BASE_MAINNET_ADDRESSES = {
humanIdentity: "0x00000000000000000000000000000000000000011",
proofRegistry: "0x00000000000000000000000000000000000000012",
poshNFT: "0x00000000000000000000000000000000000000013",
humanScore: "0x00000000000000000000000000000000000000014"
};
function getContractAddresses(chainId) {
switch (chainId) {
case 84532:
return BASE_SEPOLIA_ADDRESSES;
case 8453:
return BASE_MAINNET_ADDRESSES;
default:
return null;
}
}
// src/utils/formatting.ts
function formatHumanId(humanId, length = 8) {
if (humanId.length <= length + 2) {
return humanId;
}
return `${humanId.slice(0, length + 2)}...${humanId.slice(-length)}`;
}
function formatAddress(address, length = 6) {
if (address.length <= length + 2) {
return address;
}
return `${address.slice(0, length + 2)}...${address.slice(-length)}`;
}
function formatImpactValue(value, decimals = 18) {
const divisor = BigInt(10 ** decimals);
const integerPart = value / divisor;
const fractionalPart = value % divisor;
if (fractionalPart === 0n) {
return integerPart.toString();
}
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
const trimmed = fractionalStr.replace(/0+$/, "");
return `${integerPart}.${trimmed}`;
}
function formatDate(date) {
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric"
});
}
function formatDateTime(date) {
return date.toLocaleString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit"
});
}
export { BASE_MAINNET_ADDRESSES, BASE_SEPOLIA_ADDRESSES, ConfigurationError, ContractError, ErrorCode, EventManager, IdentityManager, KNOWN_DEPLOYMENTS, NetworkError, PoshClient, PoshSDKError, ProofManager, ProofTier, ScoreManager, ValidationError, ViemProvider, createConfigFromDeployment, createDefaultConfig, formatAddress, formatDate, formatDateTime, formatHumanId, formatImpactValue, getContractAddresses, getDeployment, getDeploymentsByChain, isValidAddress, isValidHumanId, listDeployments, registerDeployment, validateAddress, validateConfig, validateHumanId };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map