Skip to content

Instantly share code, notes, and snippets.

@axic
Created March 11, 2016 21:06
Show Gist options
  • Save axic/352dab80f2c644a9329d to your computer and use it in GitHub Desktop.
Save axic/352dab80f2c644a9329d to your computer and use it in GitHub Desktop.
ERC: Safer Ethereum Address Format - Generator tool
var ethUtil = require('ethereumjs-util')
var fixtures = [
{
name: 'ethbase-1 ',
alphabet: 'abcdefghjklmnopqrstvwxyz',
magic: [ ]
},
{
name: 'ethbase-2 ',
alphabet: '0123456789abcdefhklmnorstuwxz',
magic: [ ]
},
{
name: 'ethbase-3 ',
alphabet: '123456789abcdefhklmnorstuwxz',
magic: [ ]
},
{
name: 'ethbase-4 ',
alphabet: 'ABCDEFGHJKLMNOPQRSTVWXYZ',
magic: [ ]
},
{
name: 'ethbase-5 ',
alphabet: '987654321',
magic: [ ]
},
{
name: 'base-36 ',
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
magic: [ ]
},
{
name: 'base-55 ',
alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuwxyz',
magic: [ ]
},
{
name: 'base-58 ',
alphabet: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
magic: [ ]
},
{
name: 'rfc4648 base32 ',
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
magic: [ ]
},
{
name: 'z-base-32 ',
alphabet: 'ybndrfg8ejkmcpqxot1uwisza345h769',
magic: [ ]
},
{
name: 'crockford base-32',
alphabet: '0123456789ABCDEFGHJKMNPQRSTVWXYZ',
magic: [ ]
},
{
name: 'base32hex ',
alphabet: '0123456789ABCDEFGHIJKLMNOPQRSTUV',
magic: [ ]
},
{
name: 'nintendo base-32 ',
alphabet: '0123456789BCDFGHJKLMNPQRSTVWXYZ',
magic: [ ]
}
]
function encode(address) {
console.log('address ', address.toString('hex'))
for (var i = 0; i < fixtures.length; i++) {
var fixture = fixtures[i]
var bs = require('base-x')(fixture.alphabet)
var flag = 1
var checksum = ethUtil.sha3(address).slice(-4)
var content
if (fixture.magic.length > 0)
content = Buffer.concat([ new Buffer(fixture.magic), new Buffer([ flag ]), address, checksum ])
else
content = Buffer.concat([ new Buffer([ flag ]), address, checksum ])
console.log(fixture.name, bs.encode(content))
}
}
var crypto = require('crypto')
for (var i = 0; i < 2; i++) {
encode(crypto.randomBytes(20))
console.log('--')
}
for (var i = 0; i < 2; i++) {
encode(Buffer.concat([ new Buffer([0]), crypto.randomBytes(19)])) // 'ICAP direct'
console.log('--')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment