Skip to content

Let Address.fromString resolve human-readable names through a registered resolver #548

Description

@LusoCryptoLabs

Address.fromString only understands addresses. A wallet or dapp that wants to accept a name where an address goes (alice.example instead of ckt1q...) has to special-case it before calling CCC, and every one of them does that again.

Proposal: one small hook, off by default.

Address.registerNameResolver({
  suffixes: [".example"],
  resolve: async (name, client) => lookup(name), // a CKB address string, or null
});
await Address.fromString("alice.example", client);

fromString would behave exactly as today for every input it accepts today. Only when parsing fails, a resolver is registered, and the string ends with one of its suffixes, is the resolver asked for an address, which is then parsed the ordinary way, so nothing a resolver returns can skip the usual checks. A record of clients keyed by prefix cannot be matched to a name, so a name would resolve only against a single client; anything else stays unresolved rather than guessed.

Two shapes are possible and I would rather ask than pick:

  1. A static registry on Address, as above: one call at startup, works
    everywhere an address is parsed. Simplest for wallets; it is global state.
  2. A resolver carried by the Client (an option, or a method), so it scopes
    with the client and nothing is global. One more thing to pass around.

Motivation: names on CKB exist already (.bit) and CCC has nowhere to plug them
in; I am building another registry with an HTTP resolver, and its client would
register itself here with one call. The hook itself is not specific to any of
them.

I have a small patch with tests for shape 1 (about 100 lines plus tests, no new
dependencies) and can open it as a PR if either shape is welcome.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions