Skip to content

feat: let callers set an explicit versionTime on create/update - #48

Merged
stormer78 merged 2 commits into
mainfrom
fix/log-entry-monotonic-versiontime
Jun 28, 2026
Merged

feat: let callers set an explicit versionTime on create/update#48
stormer78 merged 2 commits into
mainfrom
fix/log-entry-monotonic-versiontime

Conversation

@stormer78

Copy link
Copy Markdown
Collaborator

What

Adds an optional version_time to CreateDIDConfig and UpdateDIDConfig so callers can set an explicit versionTime on the log entries they create. Default None preserves today's behavior exactly (the lib stamps now()).

let cfg = CreateDIDConfig::builder()
    .address(addr).authorization_key(k).did_document(doc).parameters(p)
    .version_time(Utc::now().fixed_offset() - Duration::hours(1)) // optional
    .build()?;

Why

versionTime serializes at second granularity (SecondsFormat::Secs) and verify_version_time requires each entry to be strictly greater than the previous and not in the future. create_did/update_did hardcoded create_log_entry(None, …)now(), so a caller creating multiple entries in quick succession (e.g. a service that does create-then-update back-to-back) gets two same-second entries that serialize identically and make the DID unresolvable ("versionTime must be greater than previous").

Notably this passes every in-memory test (the monotonic check runs on the full-precision parsed DateTime) but fails once the log is serialized + re-resolved — which is exactly how it bites in practice.

Rather than have the lib invent timestamps (bumping to prev+1s trips the not-in-the-future check; widening serialization precision would change the canonical/hashed form and break existing dids), the clean fix is to let the caller decide: a batch of updates can backdate + space the entries (e.g. now−1h, now−1h+1min) so the log stays strictly increasing and in the past. The low-level DIDWebVHState::create_log_entry already took Option<DateTime<FixedOffset>>; this just surfaces it on the high-level builders.

Scope

  • version_time is honored on the single-entry operations: genesis create_did, the standard update_did, and the migrate path.
  • The deactivation path can append two entries (pre-rotation teardown + final); one caller-supplied value can't keep them distinct, so it keeps the default per-entry now() stamping (unchanged).

Test

create_then_update_with_spaced_version_times_validates — a genesis backdated to now−1h plus an update at now−1h+1min validates end-to-end (report.truncated.is_none()), the sequence that fails with same-second defaults. All existing tests unchanged and green.

create_did and update_did hardcoded the new log entry's versionTime to now().
versionTime serializes at second granularity and must be strictly increasing and
not in the future, so a caller creating multiple entries in quick succession (e.g.
a VTA doing create-then-update back-to-back) produces same-second entries that
serialize identically and make the DID unresolvable.

Expose an optional version_time on CreateDIDConfig and UpdateDIDConfig (default
None preserves the now() behavior exactly). Callers that batch updates can now
backdate and space the entries — e.g. now-1h, now-1h+1min — keeping the log
strictly increasing and in the past. The low-level create_log_entry already
accepted this; the high-level builders just hadn't surfaced it.

Honored on the single-entry operations (genesis create, standard update, migrate);
the multi-entry deactivation path keeps per-entry now() stamping since one
caller-supplied value can't keep its two entries distinct.

Test: a genesis backdated to now-1h plus an update at now-1h+1min validates
end-to-end (report.truncated.is_none()) — the sequence that fails with same-second
defaults.

Signed-off-by: Glenn Gore <glenn@affinidi.com>
Bumps the crate to 0.5.6 (publishable for the caller-settable versionTime
feature) and updates Cargo.lock to the latest compatible dependency versions.
All direct-dependency latest releases are within the existing version
requirements; no manifest req changes were needed.

Signed-off-by: Glenn Gore <glenn@affinidi.com>
@stormer78
stormer78 merged commit 56ad2ac into main Jun 28, 2026
6 checks passed
@stormer78
stormer78 deleted the fix/log-entry-monotonic-versiontime branch June 28, 2026 22:15
stormer78 added a commit to OpenVTC/verifiable-trust-infrastructure that referenced this pull request Jun 28, 2026
The VTA creates its did:webvh at setup and updates it moments later (e.g.
'services didcomm enable'). versionTime serialises at second granularity and must
be strictly increasing and not in the future, so two entries minted in the same
second serialise identically and make the DID unresolvable — surfacing as a
resolution failure ("versionTime must be greater than previous") only once a
client fetches did.jsonl.

Set an explicit versionTime on the genesis-create and standard-update log
entries: backdated a day and spaced a minute apart by entry index
(backdated_version_time). The wall-clock value is irrelevant to did:webvh; this
keeps the log strictly increasing and in the past regardless of how fast the
entries are minted. Requires didwebvh-rs 0.5.6, which exposes version_time on
CreateDIDConfig/UpdateDIDConfig (decentralized-identity/didwebvh-rs#48).

Validated end-to-end: a fresh VTA set up and didcomm-enabled back-to-back with no
delay now resolves and completes a containerised did:peer agent round-trip.

Signed-off-by: Glenn Gore <glenn@affinidi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant