Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPNS contenthash decoding strips first character from peer ID #4527

Closed
eth-limo opened this issue Jan 2, 2024 · 5 comments
Closed

IPNS contenthash decoding strips first character from peer ID #4527

eth-limo opened this issue Jan 2, 2024 · 5 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@eth-limo
Copy link

eth-limo commented Jan 2, 2024

Ethers Version

6.9.1

Search Terms

ipns, contenthash

Describe the Problem

When attempting to decode a contentHash record set to an IPNS peer ID, the first character is stripped, resulting in an unparsable IPNS pointer:

For example (esteroids.eth):

Wrong: ipns://2D3KooWKrB93pwXDdeyz2WRMwcSBny5ECjA1JasB4GTo4ijUUtf

Should be: ipns://12D3KooWKrB93pwXDdeyz2WRMwcSBny5ECjA1JasB4GTo4ijUUtf

Code Snippet

const { ethers } = require("ethers");

const provider = new ethers.JsonRpcProvider(process.env.ETH_RPC_ENDPOINT);

async function lookup(ens) {
  let hostname = ens
  var res = await provider.getResolver(hostname);
  var contentHash = await res.getContentHash();
  var address = await res.getAddress();

  var output = JSON.stringify({
    resolver: res,
    address: address,
    contentHash: contentHash,
  });
  console.log(output);
}

lookup("esteroids.eth");

Contract ABI

No response

Errors

No response

Environment

node.js (v12 or newer)

Environment (Other)

No response

@eth-limo eth-limo added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Jan 2, 2024
@ricmoo
Copy link
Member

ricmoo commented Jan 2, 2024

Thanks! I’ll look into this right away.

@ricmoo
Copy link
Member

ricmoo commented Jan 2, 2024

The problem is that Base58 is more an encoding for numeric data, not binary data, so as a result the leading-0's are getting trimmer (while in base-58, the character "1" is used to indicate the value 0). Looking into the best way to remedy this.

Most protocols that use Base58 as a result tend to specify a bit width to pad to.

I'll update shortly. :)

@ricmoo
Copy link
Member

ricmoo commented Jan 3, 2024

Useful resource: https://medium.com/concerning-pharo/understanding-base58-encoding-23e673e37ff6

I've made the change and am just waiting for the CI to complete.

@ricmoo
Copy link
Member

ricmoo commented Jan 3, 2024

Fixed in v6.9.2.

Thanks! :)

@ricmoo ricmoo added bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. and removed investigate Under investigation and may be a bug. labels Jan 3, 2024
@eth-limo
Copy link
Author

eth-limo commented Jan 4, 2024

Fixed in v6.9.2.

Thanks! :)

Thank you so much @ricmoo! I'll open a new issue if I run into anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

3 participants
@ricmoo @eth-limo and others