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
11 changes: 11 additions & 0 deletions .changeset/fix-emitter-timestamps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@wasmagent/aep": patch
---

fix(aep): use Date.now() instead of performance.now() for default timestamps

- `emit()` / `build()` now defaults `created_at_ms` to `Date.now()` (Unix epoch ms) instead of `performance.now()` (ms since process start). Fixes records showing `1970-01-01` in downstream audit tools.
- `addAction()` without explicit `timestamp_ms` also defaults to `Date.now()`.
- `addAction()` with `capability_decision` now auto-registers to `capability_decisions[]` (deduped), fixing silent empty manifest in downstream `toEvents()`.

Fixes: #14, #15
14 changes: 11 additions & 3 deletions packages/aep/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ export class AEPEmitter {
): void {
this.#actions.push({
action_id: action.action_id ?? `action-${this.#actions.length}`,
timestamp_ms: action.timestamp_ms ?? performance.now(),
timestamp_ms: action.timestamp_ms ?? Date.now(),
...action,
} as ActionEvidence);
if (action.capability_decision) {
const cd = action.capability_decision;
const exists = this.#capabilityDecisions.some(
(d) =>
d.capability === cd.capability && d.subject === cd.subject && d.resource === cd.resource
);
if (!exists) this.#capabilityDecisions.push(cd);
}
}

addCapabilityDecision(decision: CapabilityDecision): void {
Expand Down Expand Up @@ -78,7 +86,7 @@ export class AEPEmitter {
*
* For a fully signed record use `emit()` instead.
*
* @param createdAtMs - Override creation timestamp (defaults to performance.now()).
* @param createdAtMs - Override creation timestamp (defaults to Date.now()).
* @param signerOverride - Optional: provide a signer to sign inline (async variant).
* Prefer `emit()` for async signing.
*/
Expand Down Expand Up @@ -150,7 +158,7 @@ export class AEPEmitter {
actions: this.#actions,
verifier_results: this.#verifierResults,
budget_ledger: this.#budgetLedger,
created_at_ms: createdAtMs ?? performance.now(),
created_at_ms: createdAtMs ?? Date.now(),
};
}

Expand Down
Loading