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

Nano custom alphabet encoding not giving correct result. Help? #16

Open
gogo199432 opened this issue Mar 6, 2021 · 0 comments
Open

Comments

@gogo199432
Copy link

Hey, so I'm trying to use the custom alphabet functionality of this lib since I'm trying to implement a Nano cryptocurrency client in CSharp. However for some reason I get the wrong encoding at the end, and since I'm too stupid to understand your code, I was hoping you could help me out?

Links for the nano stuff I'm using for reference:
https://docs.nano.org/integration-guides/the-basics/#seed (here the public address section)
https://docs.nano.org/integration-guides/key-management/

I get the byte array with this function:

  public static byte[] ConvertHexToByteArray(string hex)
  {
            return Enumerable.Range(0, hex.Length / 2).Select(x => Convert.ToByte(hex.Substring(x * 2, 2), 16))
                .ToArray();
  }

I have a test that checks for the string->byte array conversion so it should be okay. I'm trying to encode the public key to public address.
Key: 5b65b0e8173ee0802c2c3e6c9080d1a16b06de1176c938a924f58670904e82c4
Address: 1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjt

Here is my code:

public byte[] PublicKey { get; private set; }

public string PublicAddress { get; private set; }

private static readonly CustomBase32Encoding Encoder = new CustomBase32Encoding("13456789abcdefghijkmnopqrstuwxyz", null);

public void GeneratePublicAddress()
{
    
    var blake2BConfig = new Blake2BConfig
    {
        OutputSizeInBytes = 5
    };
    var hasher = Blake2B.Create(blake2BConfig);
    hasher.Update(PublicKey, 0, 5);
    var digestHash = hasher.Finish();

   // The important stuff here:
    var base32Pub = Encoder.GetString(PublicKey);
    
    PublicAddress = "nano_"+base32Pub+Encoder.GetString(digestHash);
}

Thanks in advance :)

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

No branches or pull requests

1 participant