UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

181 lines (180 loc) 5.41 kB
export interface KeyPair { publicKey: Uint8Array; secretKey: Uint8Array; } export interface X25519KeyPair { publicKey: Uint8Array; privateKey: Uint8Array; } export interface Falcon512KeyPair { publicKey: Uint8Array; privateKey: Uint8Array; } export interface MLKEMKeyPair { publicKey: Uint8Array; secretKey: Uint8Array; } export interface PQPreKeyBundle { registrationId: number; deviceId: number; identityKey: Uint8Array; falcon512PublicKey: Uint8Array; signedPreKey: { keyId: number; publicKey: Uint8Array; signature: Uint8Array; }; oneTimePreKey?: { keyId: number; publicKey: Uint8Array; }; pqPreKey: { keyId: number; publicKey: Uint8Array; signature: Uint8Array; }; } export interface PQXDHResult { rootKey: Uint8Array; chainKey: Uint8Array; ourDHKeyPair: X25519KeyPair; peerDHPublicKey: Uint8Array; peerIdentityKey: Uint8Array; pqSharedSecret: Uint8Array; } export interface RatchetState { rootKey: Uint8Array; sendingChainKey: Uint8Array; sendingMessageCount: number; receivingChainKey: Uint8Array; receivingMessageCount: number; ourDHKeyPair: X25519KeyPair; peerDHPublicKey: Uint8Array | null; previousSendingCount: number; skipMessageKeys: Map<string, Uint8Array>; } export interface EncryptedMessage { type: MessageType; body: Uint8Array; registrationId?: number; } export declare enum MessageType { PREKEY_MESSAGE = 3, NORMAL_MESSAGE = 1 } export type SPQRPhase = "idle" | "sending_pk" | "waiting_for_ct" | "sending_ct_pk" | "done"; export type SPQRReceivePhase = "idle" | "receiving_pk" | "receiving_ct" | "done"; export interface SPQRState { cycleId: number; sendingPQKeys: MLKEMKeyPair | null; sendingChunks: Uint8Array[]; sendingChunkIndex: number; sendingPhase: SPQRPhase; receivedChunks: Map<number, Uint8Array>; receivingPhase: SPQRReceivePhase; expectedTotalChunks: number; receivedSharedSecret: Uint8Array | null; currentSPQRKey: Uint8Array; spqrChainKey: Uint8Array; spqrMessageCount: number; } export interface SPQRChunk { cycleId: number; chunkIndex: number; totalChunks: number; data: Uint8Array; } export interface PQSessionState { pqxdhComplete: boolean; ratchetState: RatchetState; spqrState: SPQRState; peerIdentityKey: Uint8Array; peerRegistrationId: number; peerDeviceId: number; pendingInitialMessage?: { ephemeralPublicKey: Uint8Array; mlkemCiphertext: Uint8Array; identityKey: Uint8Array; signedPreKeyId: number; oneTimePreKeyId: number | null; pqPreKeyId: number; }; } export interface PQIdentity { x25519KeyPair: X25519KeyPair; registrationId: number; } export interface SerializedRatchetState { rootKey: string; sendingChainKey: string; sendingMessageCount: number; receivingChainKey: string; receivingMessageCount: number; ourDHPrivateKey: string; ourDHPublicKey: string; peerDHPublicKey: string | null; previousSendingCount: number; skipMessageKeys: Record<string, string>; } export interface SerializedSPQRState { cycleId: number; sendingPQPublicKey: string | null; sendingPQSecretKey: string | null; sendingChunks: string[]; sendingChunkIndex: number; sendingPhase: string; receivedChunks: Record<string, string>; receivingPhase: string; expectedTotalChunks: number; receivedSharedSecret: string | null; currentSPQRKey: string; spqrChainKey: string; spqrMessageCount: number; } export interface SerializedPQSessionState { pqxdhComplete: boolean; ratchetState: SerializedRatchetState; spqrState: SerializedSPQRState; peerIdentityKey: string; peerRegistrationId: number; peerDeviceId: number; pendingInitialMessage?: { ephemeralPublicKey: string; mlkemCiphertext: string; identityKey: string; signedPreKeyId: number; oneTimePreKeyId: number | null; pqPreKeyId: number; }; } export declare enum PQErrorCode { INVALID_KEY = "INVALID_KEY", HANDSHAKE_FAILED = "HANDSHAKE_FAILED", ENCRYPTION_FAILED = "ENCRYPTION_FAILED", DECRYPTION_FAILED = "DECRYPTION_FAILED", SESSION_NOT_FOUND = "SESSION_NOT_FOUND", SPQR_ERROR = "SPQR_ERROR", ERASURE_ERROR = "ERASURE_ERROR", SERIALIZATION_ERROR = "SERIALIZATION_ERROR" } export declare class PQError extends Error { code: PQErrorCode; constructor(code: PQErrorCode, message: string); } export declare const DEFAULT_DEVICE_ID = 1; export declare const ROOT_KEY_SIZE = 32; export declare const CHAIN_KEY_SIZE = 32; export declare const MESSAGE_KEY_SIZE = 32; export declare const DH_KEY_SIZE = 32; export declare const SIGNATURE_SIZE = 666; export declare const MLKEM_PUBLIC_KEY_SIZE = 1184; export declare const MLKEM_SECRET_KEY_SIZE = 2400; export declare const MLKEM_CIPHERTEXT_SIZE = 1088; export declare const MLKEM_SHARED_SECRET_SIZE = 32; export declare const AES_GCM_IV_SIZE = 12; export declare const AES_GCM_TAG_SIZE = 16; export declare const SPQR_CHUNK_DATA_SIZE = 34; export declare const SPQR_CHUNK_HEADER_SIZE = 8; export declare const SPQR_CHUNK_SIZE: number; export declare const SPQR_DATA_CHUNKS = 28; export declare const SPQR_TOTAL_CHUNKS = 56;