Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 16 additions & 6 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ import {
type PickFeedRuntimeHealth,
} from "./lib/live-draft-orchestration";

function cryptographicId(prefix = ""): string {
const webCrypto = globalThis.crypto;
if (webCrypto && typeof webCrypto.randomUUID === "function") return `${prefix}${webCrypto.randomUUID()}`;
if (!webCrypto || typeof webCrypto.getRandomValues !== "function") {
throw new Error("A cryptographic random source is required to mint this identifier.");
}
const bytes = new Uint8Array(16);
webCrypto.getRandomValues(bytes);
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
return `${prefix}${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}

const DASHBOARD_LOADED_AT = new Date().toISOString();

const DEMO_PLAYERS: DraftPlayer[] = [
Expand Down Expand Up @@ -236,8 +248,7 @@ function requestExtensionCommand(
payload: Record<string, unknown>,
timeoutMs = 1_250,
): Promise<Record<string, unknown>> {
const transitionRequestId = String(payload.transitionRequestId || globalThis.crypto?.randomUUID?.()
|| `${Date.now()}-${Math.random().toString(36).slice(2)}`);
const transitionRequestId = String(payload.transitionRequestId || cryptographicId());
return new Promise((resolve) => {
let settled = false;
const finish = (result: Record<string, unknown>) => {
Expand Down Expand Up @@ -312,8 +323,8 @@ const SNAKE_ACTION_RESPONSE_BUDGET_MS = 6_000;
// but normal poll timing must not permanently cancel operator intent.
const PICK_FEED_HEALTH_WINDOW_MS = 4_000;
const COMMAND_CENTER_PUBLISHER = {
sessionId: globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random().toString(36).slice(2)}`,
documentId: globalThis.crypto?.randomUUID?.() || `document-${Date.now()}-${Math.random().toString(36).slice(2)}`,
sessionId: cryptographicId(),
documentId: cryptographicId("document-"),
startedAt: new Date().toISOString(),
};
// Keep action request ids unique across a dashboard-only reload while the ESPN
Expand Down Expand Up @@ -1056,8 +1067,7 @@ export default function Home() {
setActionState("League transition is waiting for the exact ESPN actuator to revoke. No draft action can be sent.");
return null;
}
const ownerToken = globalThis.crypto?.randomUUID?.()
|| `${Date.now()}-${Math.random().toString(36).slice(2)}`;
const ownerToken = cryptographicId();
bindingTransitionOwnerRef.current = ownerToken;
// Revoke the page-local epoch synchronously while the old exact identity
// is still intact. Clearing any of these refs first would make the cancel
Expand Down
6 changes: 3 additions & 3 deletions config/draft-day-release.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 2,
"extensionVersion": "0.2.33",
"extensionPackageSha256": "85285f5ad85607ae96a6b555b3e6211bd72660b0ddf816ee8ec9971e81bba5da",
"extensionSourceSha256": "15f6330ab11574c8415bcff506ef9941bf60ffed85bd3091637b7a0fa6eb2ad4",
"extensionVersion": "0.2.34",
"extensionPackageSha256": "96b093060f1afea8f387594d7318b456f9fe5a6d6df11a15cbb1157f0bd89aca",
"extensionSourceSha256": "bdcf3e98f150a3a50724b2f73c2e610e67e734edf36e6a8e36a926a194acde10",
"extensionSourceFileCount": 19
}
18 changes: 14 additions & 4 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ import {
} from "./workspace-lifecycle.js";
import { renewExistingWriterLease, writerLeaseMatchesBinding } from "./writer-lease.js";

function cryptographicId(prefix = "") {
const webCrypto = globalThis.crypto;
if (webCrypto && typeof webCrypto.randomUUID === "function") return `${prefix}${webCrypto.randomUUID()}`;
if (!webCrypto || typeof webCrypto.getRandomValues !== "function") {
throw new Error("A cryptographic random source is required to mint this identifier.");
}
const bytes = new Uint8Array(16);
webCrypto.getRandomValues(bytes);
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
return `${prefix}${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}

const appTabs = new Set();
let espnContext = null;
let liveRoomWatch = null;
Expand Down Expand Up @@ -372,8 +384,7 @@ async function auctionUncertaintyMessageNow(message, sender) {
if (!pending && Object.keys(records).length >= MAX_AUCTION_CLICK_UNCERTAINTIES) {
return { ok: false, code: "AUCTION_UNCERTAINTY_CAPACITY_REACHED" };
}
const token = pending ? message.payload.token
: globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random().toString(36).slice(2)}`;
const token = pending ? message.payload.token : cryptographicId();
const tokenHash = pending?.tokenHash || await auctionTokenHash(token);
if (actionBinding !== authorizedBinding
|| actionBindingGeneration !== authorizedBindingGeneration
Expand Down Expand Up @@ -644,8 +655,7 @@ function successorWatchPreservesEstablishedAuthority(

function newWriterLease(binding, now = Date.now()) {
if (!binding) return null;
const leaseId = globalThis.crypto?.randomUUID?.()
|| `${now}-${Math.random().toString(36).slice(2)}`;
const leaseId = cryptographicId();
return {
leaseId,
appTabId: binding.appTabId,
Expand Down
16 changes: 14 additions & 2 deletions extension/espn-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@ let trackedDraftClock = { key: "", seconds: null, observedAt: 0 };
let trackedDraftNamespace = "";
let latestProducerContext = null;
let contextProducerRevision = 0;
const contextProducerSessionId = globalThis.crypto?.randomUUID?.()
|| `producer-${Date.now()}-${Math.random().toString(36).slice(2)}`;

function cryptographicId(prefix = "") {
const webCrypto = globalThis.crypto;
if (webCrypto && typeof webCrypto.randomUUID === "function") return `${prefix}${webCrypto.randomUUID()}`;
if (!webCrypto || typeof webCrypto.getRandomValues !== "function") {
throw new Error("A cryptographic random source is required to mint this identifier.");
}
const bytes = new Uint8Array(16);
webCrypto.getRandomValues(bytes);
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
return `${prefix}${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
}

const contextProducerSessionId = cryptographicId("producer-");
let actionExecutionTail = Promise.resolve();
const inFlightActionResults = new Map();
const completedActionResults = new Map();
Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "DraftForge ESPN Companion",
"version": "0.2.33",
"version": "0.2.34",
"description": "Securely connects DraftForge to your signed-in ESPN Fantasy draft room.",
"permissions": ["tabs", "storage"],
"host_permissions": [
Expand Down
Loading
Loading