Files
WebDrop/packages/core/src/constants.ts
T

51 lines
1.4 KiB
TypeScript

/** 协议常量,与 docs/protocol.md 一一对应。 */
export const PROTOCOL_VERSION = 1;
export const ID_SIZE = 16;
export const KEY_SIZE = 32;
export const TAG_SIZE = 16;
export const HEADER_SIZE = 26;
/** 帧标志(protocol §4)。 */
export const Flags = {
Final: 1,
Snapshot: 2,
Gated: 4,
Enc: 8,
Control: 16,
} as const;
/** 档位 padding 的明文长度(protocol §6)。 */
export const TIERS = [1024, 4096, 16384, 65536, 262144, 1048576] as const;
/** 单帧明文上限 1 MiB,含 4 字节长度前缀,所以 data 最多 1,048,572 字节。 */
export const MAX_FRAME_PLAINTEXT = 1048576;
export const MAX_FRAME_DATA = MAX_FRAME_PLAINTEXT - 4;
/** raw 模式的负载没有加密开销,单帧上限取 1 MiB。 */
export const RAW_MAX_PAYLOAD = 1048576;
/** HKDF info 标签(protocol §3)。 */
export const Labels = {
enc: 'webdrop/v1/enc',
read: 'webdrop/v1/token/read',
write: 'webdrop/v1/token/write',
owner: 'webdrop/v1/token/owner',
item: 'webdrop/v1/item',
label: 'webdrop/v1/label',
} as const;
/** AAD 前缀。 */
export const AAD_FRAME = 'WD1';
export const AAD_LABEL = 'WD1L';
/** 设备名总长上限(iv + 密文 + tag),与服务端 MaxSeatLabelBytes 一致。 */
export const MAX_LABEL_BYTES = 256;
export const LABEL_IV_SIZE = 12;
export const POW_NONCE_SIZE = 8;
export type ChannelMode = 'enc' | 'raw';
export type ItemKind = 'text' | 'json' | 'file' | 'manifest' | 'other';