Created
January 28, 2021 13:30
-
-
Save vnavascues/d28f32c4246b93fdf5e7e88b4dee3c2c to your computer and use it in GitHub Desktop.
ENS domain btc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EIP | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2304.md#p2pkhversion | |
// | |
// Testing addresses | |
// https://github.com/ensdomains/address-encoder/blob/master/src/__tests__/index.test.ts#L16 | |
// | |
// P2PKH case | |
// | |
// Stored bytes | |
// 76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac | |
// | |
// Expected address | |
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa | |
// | |
// Resulting address | |
// 12NvYg7CXwVYtMDYia7n9viekJ6d5 | |
const bs58 = require("bs58") | |
p2pkhBytes = Buffer.from("76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac", "hex"); | |
p2pkhAddr = bs58.encode(Buffer.concat([Buffer.from("00","hex"), p2pkhBytes.slice(3,3 + p2pkhBytes.readUInt8(2))])); | |
// Python version | |
// from base58check import b58encode | |
// b58encode(bytes.fromhex('0062e907b15cbf27d5425399ebf6f0fb50ebb88f18')).decode('utf-8') | |
// P2SH | |
// Stored bytes | |
// a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1887 | |
// | |
// Expected address | |
// 3Ai1JZ8pdJb2ksieUV8FsxSNVJCpoPi8W6 | |
// | |
// Resulting address (not starting with 3) | |
// LDDFSe7ry9LK8TSz6sfgZ3FwzjMZ | |
p2shBytes = Buffer.from("a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1887","hex"); | |
p2shAddr = bs58.encode(Buffer.concat([Buffer.from("05", "hex"), p2shBytes.slice(2, 2 + p2shBytes.readUInt8(1))])); | |
// Python version | |
// b58encode(bytes.fromhex('0562e907b15cbf27d5425399ebf6f0fb50ebb88f18')).decode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment