UNPKG

pepunamessdk

Version:

TypeScript SDK for Pepu Name Service - Simple domain name resolution to wallet addresses

114 lines (113 loc) 4.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PNS = void 0; const ethers_1 = require("ethers"); // PNS SDK with domain resolution and info class PNS { constructor() { const provider = new ethers_1.ethers.JsonRpcProvider('https://rpc-pepu-v2-mainnet-0.t.conduit.xyz'); this.contract = new ethers_1.ethers.Contract('0x3676De521bAcCC7A8Aae0feF4DD4cd131D2F86B2', [ { "inputs": [ { "name": "name", "type": "string" }, { "name": "tld", "type": "string" } ], "name": "resolveName", "outputs": [{ "name": "walletAddress", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [ { "name": "name", "type": "string" }, { "name": "tld", "type": "string" } ], "name": "getDomainStatus", "outputs": [ { "name": "exists", "type": "bool" }, { "name": "expired", "type": "bool" }, { "name": "remainingDays", "type": "uint256" }, { "name": "fee", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "name": "name", "type": "string" }, { "name": "tld", "type": "string" } ], "name": "getDomainInfo", "outputs": [ { "name": "walletAddress", "type": "address" }, { "name": "owner", "type": "address" }, { "name": "registrationTimestamp", "type": "uint256" }, { "name": "expiryTimestamp", "type": "uint256" }, { "name": "tldInfo", "type": "string" } ], "stateMutability": "view", "type": "function" } ], provider); } /** * Resolve a domain name to wallet address * @param domain - Domain name (e.g., "teck.pepu") * @returns Promise<string> - Wallet address or empty string if not found */ async resolve(domain) { try { const [name, tld] = domain.split('.'); const address = await this.contract.resolveName(name, `.${tld}`); return address === ethers_1.ethers.ZeroAddress ? '' : address; } catch (error) { return ''; } } /** * Get domain status (exists, expired, remaining days, fee) * @param domain - Domain name (e.g., "teck.pepu") * @returns Promise<object> - Domain status information */ async getDomainStatus(domain) { try { const [name, tld] = domain.split('.'); const [exists, expired, remainingDays, fee] = await this.contract.getDomainStatus(name, `.${tld}`); return { exists, expired, remainingDays, fee }; } catch (error) { return { exists: false, expired: false, remainingDays: BigInt(0), fee: BigInt(0) }; } } /** * Get detailed domain information * @param domain - Domain name (e.g., "teck.pepu") * @returns Promise<object> - Detailed domain information */ async getDomainInfo(domain) { try { const [name, tld] = domain.split('.'); const info = await this.contract.getDomainInfo(name, `.${tld}`); if (info.walletAddress === ethers_1.ethers.ZeroAddress) { return null; } return { walletAddress: info.walletAddress, owner: info.owner, registrationTimestamp: info.registrationTimestamp, expiryTimestamp: info.expiryTimestamp, tld: info.tldInfo }; } catch (error) { return null; } } } exports.PNS = PNS;