Module encoding

Module encoding 

Source
Expand description

Encoding and decoding between NDN Names and did:ndn DID strings.

§Encoding

A did:ndn DID is the base64url (no padding) encoding of the complete NDN Name TLV wire format, including the outer Name-Type and TLV-Length octets.

did:ndn:<base64url(Name TLV)>

Every NDN name maps to exactly one DID, and every valid did:ndn DID maps to exactly one NDN name. The encoding is lossless across all component types (GenericNameComponent, BLAKE3_DIGEST, ImplicitSha256Digest, versioned components, etc.) without any type-specific special cases.

§Backward compatibility

Earlier drafts of the spec used two forms that are now deprecated:

  • Simple form — colon-joined ASCII component values: /com/acme/alicedid:ndn:com:acme:alice
  • v1: binary formdid:ndn:v1:<base64url(Name TLV)>

Both forms are still accepted by did_to_name for backward compatibility. name_to_did no longer produces either deprecated form.

§Ambiguity in the deprecated scheme

The v1: prefix occupied the same position as the first name-component in the simple form. A name whose first component is literally v1 would produce the same did:ndn:v1:... string as a binary-encoded name, making round-trip decoding impossible without external context. The unified binary form has no such ambiguity.

Functions§

did_to_name
Decode a did:ndn DID string back to an NDN Name.
name_to_did
Encode an NDN Name as a did:ndn DID string.