pieFi-platform / hashgraph-name-resolution-sdk

MIT License
0 stars 4 forks source link

Support for .cream appears to be broken #17

Open pwoosam opened 2 years ago

pwoosam commented 2 years ago

hashgraph-name-resolution-sdk does not appear to be able to resolve .cream SLDs.

See example app here using hbar.cream as input: https://codesandbox.io/s/hgn-resolver-yj92ln?file=/src/App.tsx

Screen Shot 2022-09-15 at 2 19 19 PM

pwoosam commented 2 years ago

The SLD hashes generated on the browser vs. in node do not match:

Node:

{
    "domain": "0.cream",
    "tldHash": "f79d75e18e2ee2bd340fb0b605f3f2b4891370207ec8cbec3f9889e72f2ec220",
    "sldHash": "3538d21452c4b538ff024c3d8639a6349b9a0cf15ccfaf45864591a65b8b4e1a"
}

Browser:

{
    "domain": "0.cream",
    "tldHash": "f79d75e18e2ee2bd340fb0b605f3f2b4891370207ec8cbec3f9889e72f2ec220",
    "sldHash": "badf2094f7d147223bf11e8d43b71062341ff9f60c0d20a86b87a1000ce83901"
}

The hashes generated in Node are the correct hashes. If anyone is currently having this issue. The workaround is to make an API endpoint running the hashgrapn-name-resolution-sdk serverside instead of in-browser. That's less strain on the mirror node anyways.

pwoosam commented 2 years ago

image Adding prev and curr together will coerce prev into a string by calling .toString(). This creates invalid UTF-8 characters .

The invalid characters have two issues:

  1. They reduce the number of unique hashes that the hashing function can create
  2. They get converted differently by Buffer on the frontend and backend. On the backend is converted to . On the frontend seems to convert to ��

To avoid creating invalid characters, prev should be replaced with prev.toString('hex'). But this will make looking up names fail because the hashes will be completely different than the ones recorded on the HCS topics.

New topic messages will have to be created to backfill the old domains with new versions of the hash. The hashgraph-name-resolution-sdk will need to be updated to handle this patch. And new messages should include both the old hash and the new hash to preserve backwards compatibility with older versions of the hashgraph-name-resolution-sdk.

Tests should be performed to make sure the new topic messages that backfill the existing domain's hashes do not break older versions of the hashgraph-name-resolution-sdk.