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:
- A static registry on
Address, as above: one call at startup, works
everywhere an address is parsed. Simplest for wallets; it is global state.
- 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.
Address.fromStringonly understands addresses. A wallet or dapp that wants to accept a name where an address goes (alice.exampleinstead ofckt1q...) has to special-case it before calling CCC, and every one of them does that again.Proposal: one small hook, off by default.
fromStringwould 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:
Address, as above: one call at startup, workseverywhere an address is parsed. Simplest for wallets; it is global state.
Client(an option, or a method), so it scopeswith 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.