airsign-sdk-core
Version:
AirSign Protocol Core SDK - secure nearby crypto & data exchange
70 lines • 2.35 kB
TypeScript
/**
* AirSign Protocol Message Handling
*
* Provides message envelope validation, presence packet parsing,
* and protocol-level message processing with security checks.
*/
import { type PresencePacket, type MessageEnvelope, type MessageMeta, type ValidationConfig, MessageType } from './types.js';
/**
* Parse and validate a presence packet from JSON string
*
* @param packetJson - JSON string containing presence packet
* @returns Validated presence packet
* @throws {AirSignError} If packet is invalid
*
* @example
* ```typescript
* const packet = parsePresence('{"proto":"airsign-v1","ephemeral_pub":"...", ...}');
* console.log(packet.name); // Device name
* ```
*/
export declare function parsePresence(packetJson: string): PresencePacket;
/**
* Create a new message envelope with validation
*
* @param type - Message type
* @param payload - Message payload as string
* @param meta - Message metadata
* @param senderSig - Optional sender signature (hex)
* @param senderPub - Optional sender public key (hex)
* @returns Validated message envelope
* @throws {AirSignError} If parameters are invalid
*
* @example
* ```typescript
* const envelope = createMessageEnvelope(
* MessageType.PAYMENT_URI,
* 'ethereum:0x123...?value=1000000000000000000',
* { expiry: Date.now() + 300000 }
* );
* ```
*/
export declare function createMessageEnvelope(type: MessageType, payload: string, meta: MessageMeta, senderSig?: string, senderPub?: string): MessageEnvelope;
/**
* Validate a received message envelope
*
* @param envelope - Message envelope to validate
* @param config - Validation configuration
* @returns Promise resolving to true if valid
* @throws {AirSignError} If message is invalid
*
* @example
* ```typescript
* await validateMessageEnvelope(receivedMessage);
* console.log('Message is valid and safe to process');
* ```
*/
export declare function validateMessageEnvelope(envelope: MessageEnvelope, config?: ValidationConfig): Promise<boolean>;
/**
* Clean up replay protection storage (call periodically)
*/
export declare function cleanupReplayProtection(): void;
/**
* Get current replay protection statistics
*
* @returns Object with replay protection stats
*/
export declare function getReplayProtectionStats(): {
seenMessages: number;
};
//# sourceMappingURL=protocol.d.ts.map