Skip to content

Support genesis-hash network identifiers in DIDs and chain IDs - #711

Open
andynelson wants to merge 1 commit into
mainfrom
feature/did-genesis-network
Open

andynelson wants to merge 1 commit into
mainfrom
feature/did-genesis-network

Conversation

@andynelson

@andynelson andynelson commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Chain IDs can already name a network either by name (ccd:testnet) or by genesis hash prefix (ccd:4221332d34e1694168c2a0c0b3fd0f27), but DIDs only accepted the named form (did:ccd:testnet:…). This brings DIDs in line, so any network, including a custom one, can be addressed as did:ccd:<32-hex genesis prefix>:….

Builds on Concordium/concordium-base#986 (merged); deps/concordium-base now points at that commit on main.

Compatibility

  • Existing DIDs, chain IDs and stored settings are unchanged. Named networks are still written as testnet/mainnet, and parsing did:ccd:testnet:… still gives network === 'Testnet'.
  • The genesis form is opt-in everywhere.
  • A named network and its genesis prefix count as the same chain (DIDNetwork.sameChain, matching the Rust equality in base).
  • Counterparties (wallets, verifiers) need the updated concordium-base before they accept did:ccd:<prefix>:…, so adopt per integration.

Changes

sdk

  • Network (in types.ts) is now 'Testnet' | 'Mainnet' | GenesisHashPrefix.Type.
  • New GenesisHashPrefix module in src/types/ (Type, TESTNET, MAINNET, instanceOf, fromHexString, fromGenesisHash, toHexString), following the BlockHash-style modules.
  • New networkHelpers.ts: networkToString, networkFromString, isSameNetwork, getNetworkGenesisHashPrefix, networkFromChainId, networkToChainId, getKeyDerivationNetwork.
  • Key derivation is unchanged in meaning: getKeyDerivationNetwork maps mainnet (by name or genesis prefix) to Mainnet (coin type 919) and every other network to Testnet (coin type 1). Applied in ConcordiumHdWallet and getIdProof, the only places the network reaches WASM key derivation.
  • New ConcordiumDID class in web3-id/types.ts, next to DIDString, IdentityProviderDID and ContractInstanceDID: fromJSON, toJSON and identifierOf, with a DIDIdentifier union for every DID type (acc, cred, sci, pkc, idp, encidcred). It is now the only code that builds or parses did:ccd: strings.
  • IdentityProviderDID, ContractInstanceDID, the create*DID helpers and credential metadata parsing use it. New IdentityProviderDID.fromChainId, createAccountAddressDID, createPublicKeyDID.
  • Network checks when verifying credentials compare by chain (isSameNetwork) instead of by regex.

Effect on code that checks Network exhaustively

Existing calls compile and behave as before. The only TypeScript that stops compiling is code assuming Network has exactly two values, e.g.

switch (network) {
    case 'Testnet': ...
    case 'Mainnet': ...
    default: { const _: never = network; } // now errors: GenesisHashPrefix is possible
}

or passing a Network into something typed 'Testnet' | 'Mainnet'. As with #[non_exhaustive] in Concordium/concordium-base#986, I don't expect this in practice, so the CHANGELOG lists it under Changed rather than as a breaking change.

wallet-connectors (peer dependency on @concordium/web-sdk unchanged, >= 12.0.2)

  • Opt-in chainIdFormat: 'genesis' on Network and a withGenesisChainId(network) helper, producing ccd:<genesis prefix>. The default stays ccd:<name> (so STAGENET remains ccd:stagenet). getChainId is exported.

verification-web-ui

  • network config accepts a custom network: { chainId: 'ccd:<prefix>', walletDeepLinks?: { ios?, android? } }.
  • The network is resolved in one place (utils/network.ts) instead of four inconsistent sources; legacy 'testnet'/'mainnet' values in localStorage still resolve.
  • Custom networks without deep links fall back to QR / the WalletConnect URI.
  • Fixes CryptoX deep links to use the schemes the apps actually register (checked against cryptox-ios Info.plists / AppDelegate.swift and the cryptox-android manifest): mainnet cryptoxmainnet:// / cryptox-wc-mainnet:// → cryptox:// / cryptox-wc://, and Android testnet cryptox-wc-testnet:// → cryptox-wc:// (both Android builds register only cryptox-wc).
  • Adds a test script (node:test via tsx).

Testing

  • sdk: test/ci passes (695 tests), including new did.test.ts (parse/format round trips for every DID type and network form, compatibility snapshots for named networks, and key derivation for genesis-prefix networks) and an end-to-end VerifiablePresentationV1 prove → verify with the testnet genesis prefix and a custom prefix through WASM.
  • wallet-connectors: 32 tests pass, including chain IDs for TESTNET, MAINNET, STAGENET and a custom network.
  • verification-web-ui: 15 tests pass; build:lib OK.
  • Lint and prettier clean.

@andynelson
andynelson force-pushed the feature/did-genesis-network branch from c233494 to 324c972 Compare November 12, 2026 14:18
@andynelson
andynelson marked this pull request as draft November 12, 2026 14:25
@andynelson
andynelson force-pushed the feature/did-genesis-network branch 5 times, most recently from 476c536 to cb10333 Compare November 12, 2026 16:25
@andynelson
andynelson marked this pull request as ready for review November 12, 2026 16:29
@andynelson
andynelson requested a review from limemloh November 12, 2026 16:30
Bump concordium-base to main (Concordium/concordium-base#986), which
accepts did:ccd:<genesis hash prefix>:..., and adopt it across the SDK
packages. Existing DIDs, chain IDs and stored settings are
unchanged; the genesis form is opt-in.

- sdk: widen Network to 'Testnet' | 'Mainnet' | GenesisHashPrefix.Type;
  add the GenesisHashPrefix module and network helpers (chain IDs,
  chain equality, key derivation: mainnet derives as Mainnet, every other
  network as Testnet); add a ConcordiumDID class covering every
  Concordium DID type and route the DID classes, create*DID helpers and
  credential metadata parsing through it; compare networks by chain
  when verifying.
- wallet-connectors: opt-in chainIdFormat: 'genesis' / withGenesisChainId
  for ccd:<genesis hash prefix> chain IDs.
- verification-web-ui: accept a custom network ({ chainId,
  walletDeepLinks }), resolve the network in one place, and fix the
  CryptoX deep-link schemes (mainnet, and Android testnet).
@andynelson
andynelson force-pushed the feature/did-genesis-network branch from cb10333 to d6101ef Compare November 12, 2026 16:33

This branch has not been deployed

No deployments
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