feat(nbcr-2023-002): structured token-id (token-component + array form)#20
Open
irfan798 wants to merge 1 commit into
Open
feat(nbcr-2023-002): structured token-id (token-component + array form)#20irfan798 wants to merge 1 commit into
irfan798 wants to merge 1 commit into
Conversation
10dcf1d to
b59d56d
Compare
Introduce a forward-looking, byte-efficient representation of token-id on top of the minimal hex-string change. Two interchangeable wire forms are supported: - the existing tstr form carrying the UAI dotted text, and - a new typed array '[+ token-id]' where each component keeps its native CBOR type (e.g. '[hex-string, biguint]' for ERC-721 / ERC-1155). CDDL additions: - 'encoded-bytes' as the extension point for tagged byte-string encodings. Today it aliases 'hex-string' (CBOR tag 263). Future specs MAY add base58, base64, bech32 and similar once their CBOR tags are registered with IANA. - 'token-component = tstr / encoded-bytes / biguint' as a single atomic component of a UAI-style identifier. - 'token-id = token-component / [2*4 token-component]' as a scalar or compound identifier (bounded at four entries to fit realistic UAI identifiers without inviting unbounded nesting). The dotted tstr form and the array form are semantically equivalent. The 'detailed-account' shape stays identical; only the grammar of 'token-ids' is lifted from '[+ tstr / hex-string]' to '[+ token-id]'. The per-chain comment for ERC-721 / ERC-1155 now names the typed array as the preferred form and includes a CBOR diagnostic notation example to make the wire shape concrete. Producers MAY choose either form per identifier and consumers MUST accept both. Previously-emitted payloads under the minimal grammar remain valid. Refs LIQ-843
b59d56d to
0bad87b
Compare
Base automatically changed from
feat/nbcr-2023-002-detailed-account-hex-string
to
main
May 4, 2026 13:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on top of #19 (minimal
hex-string+ UAI dot form). Adds a forward-looking, byte-efficient structured representation oftoken-idwhile keeping the minimal PR's tstr form fully valid.Producers MAY choose either form per identifier; consumers MUST accept both.
What changes
Three new CDDL rules extend the
token-idsgrammar:detailed-accountgains only one line change:token-ids: [+ tstr / hex-string]becomestoken-ids: [+ token-id]. Shape, tag, and keymap are unchanged.Component arrays are bounded at 2 to 4 entries: realistic UAI identifiers are 2–3 components, and the cap prevents unbounded nesting without constraining any current use case.
The per-chain comment for ERC-721 / ERC-1155 now names the typed array as the preferred wire form and includes a CBOR diagnostic notation example to make the shape concrete.
On-wire impact
For an ERC-1155 identifier
0xfaafdc07907ff5120a76b34b731b278c38d6043c.508851954656174721695133294256171964208:tstrtstr(UAI dotted text, 80 chars)[hex-string, biguint](typed array)Savings scale with token-id width. For a portfolio mixing ERC-20 contracts (already covered by #19's
hex-string) with a handful of NFT identifiers, the additional savings from the array form easily compound into 1-2 fewer animated-QR frames per sync.Parser impact
Tag
41402(detailed-account) and the keymap (account = 1,token-ids = 2) are unchanged. All additions live at thetoken-idsvalue level.tstr/hex-stringpath stays valid for every chain. Parsers that only handle the minimal PR's grammar continue to decode correctly for scalar identifiers.[hex-string, biguint](or more generally[2*4 token-component]). On decode, an array of 2+ components represents a compound identifier; consumers reconstitute the UAI dotted text by joining the components with.if they need a string view.Illustrative sketches below target the string-view rendering path (error handling and byte-string size guards elided).
TypeScript (extends
DetailedAccountin@ngraveio/ur-syncandHexStringin@ngraveio/ur-hex-string)C (tinycbor APIs)
Both sketches assume the entry iterator already points at the token-id value (the caller has stepped into
token-ids). The TypeScript side composes with the existingHexStringpromotion logic; the C side composes with the existing tinycbor iteration used by thedetailed-accountreader.Extensibility
encoded-bytesis the grammar-level extension socket. Adding base58, base64, or bech32 support in a future spec is a one-line CDDL change (expand theencoded-bytesunion), with a matching IANA CBOR tag registration. Thetoken-idandtoken-componentrules do not need to change.Indicative byte savings per identifier once each encoding lands and replaces the current
tstrform (all sizes include CBOR headers):tstrencoded-bytesbase58-stringbase58-stringbech32-stringbech32-stringbase64-stringFor reference, the already-shipped
hex-stringsaves ~20 B (~45%) on an EVM ERC-20 contract address. Savings depend on how compactly the text form encodes the underlying bytes: hex and bech32 expand bytes most, so recovering them wins the most; base58 and base64 are tighter text forms and save proportionally less.Backward compatibility
Not in this PR
encoded-bytesmembers (base58, bech32, ...). Tracked separately.References