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

How to convert JSON "address" to bech32? #36

Closed
cjb opened this issue Feb 16, 2020 · 3 comments
Closed

How to convert JSON "address" to bech32? #36

cjb opened this issue Feb 16, 2020 · 3 comments

Comments

@cjb
Copy link

cjb commented Feb 16, 2020

It'd be nice to be able to prove (to myself) that the JSON generated by hs-airdrop is really going to send the reward to the address I passed to hs-airdrop, and not some other address. But the formats aren't the same -- the one on the command line starts with hs and is 42 chars long and the one in the payload's address field is 40 chars long and doesn't match it. Is there a conversion function? Or is that field not where the target address goes..?

@pinheadmz
Copy link
Member

Great question. Shortest answer: Handshake airdrop addresses are segwit p2pkh addresses in bech32 format. That means they contain a version and a 20-byte hash. The JSON output splits the two values up and displays them both in hex.

Here's an example using the first faucet address in https://github.com/handshake-org/hs-tree-data/blob/master/proof.json:

$ bin/hs-airdrop hs1q86q9ska4j263p3cmgycqfrxgnjhrvs227uzpz2

...
  "key": {
    "type": "ADDRESS",
    "version": 0,
    "address": "3e80585bb592b510c71b4130048cc89cae36414a",
    "value": 15000500000000,
    "sponsor": true
  },
...

And here's the proof using hsd as a library and calling the Address module:

$ node

> const {Address} = require('hsd')

> new Address({version: 0, hash: Buffer.from('3e80585bb592b510c71b4130048cc89cae36414a', 'hex')})
<Address: version=0 str=hs1q86q9ska4j263p3cmgycqfrxgnjhrvs227uzpz2>

@boymanjor
Copy link
Contributor

@cjb does @pinheadmz's response alleviate your issue?

@cjb
Copy link
Author

cjb commented Feb 18, 2020

Yes! That worked. Thanks for the great answer.

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

3 participants