/** * EPM Resolver - Entity Profile Manifest lookup and encryption key resolution * * Provides functionality to: * - Look up EPMs by Peer ID * - Cache EPMs with TTL * - Extract encryption public keys for ECIES * - Support multiple key types (X25519, secp256k1, P-256) */ import type { Libp2p } from 'libp2p'; export declare enum KeyType { Signing = 0, Encryption = 1 } export type KeyExchangeAlgorithm = 'x25519' | 'secp256k1' | 'p256'; export interface EPMKey { publicKey: Uint8Array; publicKeyHex: string; keyType: KeyType; keyAddress?: string; addressType?: string; algorithm?: KeyExchangeAlgorithm; } export interface ChainProof { chain: string; address: string; publicKey: string; keyPath: string; signature: string; signedPayload: string; algorithm: string; encoding: string; } export interface ParsedEPM { dn?: string; legalName?: string; familyName?: string; givenName?: string; email?: string; telephone?: string; keys: EPMKey[]; multiformatAddresses: string[]; raw: Uint8Array; cid?: string; peerID?: string; timestamp: number; /** Ed25519 content signature (hex) */ signature?: string; /** Unix timestamp (seconds) when signed */ signatureTimestamp?: number; /** Chain binding proofs (Bitcoin, Ethereum, Solana) */ chainProofs?: ChainProof[]; } export interface EPMResolverOptions { /** Cache TTL in milliseconds (default: 5 minutes) */ cacheTTL?: number; /** Maximum cache size (default: 1000) */ maxCacheSize?: number; /** IPFS gateway URL for fallback fetching */ ipfsGateway?: string; /** PubSub topic for PNM announcements */ pnmTopic?: string; } /** * EPM Resolver - Looks up Entity Profile Manifests and extracts encryption keys */ export declare class EPMResolver { private cache; private options; private libp2pNode?; private pnmSubscribed; constructor(options?: EPMResolverOptions); /** * Set the libp2p node for P2P EPM resolution */ setNode(node: Libp2p): void; /** * Subscribe to PNM (Publish Notification Message) topic for EPM announcements */ subscribeToPNM(): Promise; /** * Handle incoming PNM announcement */ private handlePNM; /** * Resolve an EPM by Peer ID * * Resolution order: * 1. Check local cache * 2. Query IPNS (if libp2p available) * 3. Fetch from IPFS gateway (if CID known) */ resolveByPeerID(peerID: string): Promise; /** * Resolve EPM by CID (Content Identifier) */ resolveByCID(cid: string): Promise; /** * Resolve EPM via IPNS */ private resolveIPNS; /** * Add a manually fetched EPM to the cache */ addEPM(key: string, epm: ParsedEPM): void; /** * Add a raw EPM buffer and parse it */ addEPMBuffer(key: string, data: Uint8Array): ParsedEPM | null; /** * Add parsed EPM data directly (for when parsing is done externally) */ addParsedEPM(key: string, data: { keys: Array<{ publicKey: string | Uint8Array; keyType: KeyType; algorithm?: KeyExchangeAlgorithm; keyAddress?: string; addressType?: string; }>; multiformatAddresses?: string[]; dn?: string; legalName?: string; email?: string; peerID?: string; cid?: string; }): ParsedEPM; /** * Get encryption public key for a peer * * @param peerID - The peer's identifier * @param preferredAlgorithm - Preferred key exchange algorithm * @returns The encryption key info or null if not found */ getEncryptionKey(peerID: string, preferredAlgorithm?: KeyExchangeAlgorithm): Promise; /** * Get encryption key from a cached/known EPM */ extractEncryptionKey(epm: ParsedEPM, preferredAlgorithm?: KeyExchangeAlgorithm): EPMKey | null; /** * Get signing public key for a peer */ getSigningKey(peerID: string): Promise; /** * Extract signing key from EPM */ extractSigningKey(epm: ParsedEPM): EPMKey | null; /** * Get all keys from an EPM */ getAllKeys(peerID: string): Promise; private getFromCache; private addToCache; /** * Clear the EPM cache */ clearCache(): void; /** * Remove a specific entry from cache */ invalidate(key: string): void; /** * Get cache statistics */ getCacheStats(): { size: number; maxSize: number; ttl: number; }; } /** * Create an EPM resolver instance */ export declare function createEPMResolver(options?: EPMResolverOptions): EPMResolver; /** * Helper: Create encryption context for a recipient using EPM * * This is a convenience function that combines EPM lookup with * EncryptionContext creation from the flatbuffers/wasm library. * * @example * ```typescript * import { createEPMResolver } from 'sdn-js'; * import { EncryptionContext } from 'flatbuffers-encryption'; * * const resolver = createEPMResolver(); * * // Add known EPM (e.g., from PNM subscription) * resolver.addParsedEPM('peer123', { * keys: [{ * publicKey: '0x...', * keyType: KeyType.Encryption, * algorithm: 'x25519', * }], * }); * * // Get encryption key * const key = await resolver.getEncryptionKey('peer123'); * if (key) { * const ctx = EncryptionContext.forEncryption(key.publicKey, { * algorithm: key.algorithm, * }); * const encrypted = ctx.encryptBuffer(data); * const header = ctx.getHeader(); * // Send header + encrypted to recipient * } * ``` */ //# sourceMappingURL=epm-resolver.d.ts.map