Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions plugin/src/wire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// fragmentation. If text exceeds that, the sender splits into N envelopes
// sharing the same `id` and assembles via (`seq`, `total`).

import { randomUUID } from "node:crypto";

export const WIRE_VERSION = 1 as const;

/** Maximum bytes for a single envelope's JSON encoding. */
Expand Down Expand Up @@ -202,13 +204,9 @@ export async function verifyEnvelope(env: Envelope, secret: string): Promise<boo
return timingSafeEqual(providedBuf, expected);
}

/** Generate a short, monotonically-tending message id (24 base36 chars). */
/** Generate a cryptographically-random, collision-resistant message id. */
export function newId(): string {
const t = Date.now().toString(36).padStart(9, "0");
const r = Math.floor(Math.random() * 36 ** 12)
.toString(36)
.padStart(12, "0");
return `${t}${r}`;
return randomUUID();
}

/**
Expand Down
Loading