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

Banano support #385

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This library currently supports the following cryptocurrencies and address forma
- ATOM (bech32)
- AVAX (bech32)
- AVAXC (checksummed-hex)
- BANANO (banano-base32)
- BCD (base58check P2PKH and P2SH, and bech32 segwit)
- BCH (base58check and cashAddr; decodes to cashAddr)
- BCN (base58xmr)
Expand Down
14 changes: 14 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,20 @@ const vectors: Array<TestVector> = [
{ text: 'TJCnKsPa7y5okkXvQAidZBzqx3QyQ6sxMW', hex: '415a523b449890854c8fc460ab602df9f31fe4293f' },
],
},
{
name: 'BAN',
coinType: 198,
passingVectors: [
{
text: 'ban_15dng9kx49xfumkm4q6qpaxneie6oynebiwpums3ktdd6t3f3dhp69nxgb38',
hex: '0d7471e5d11faddce5315c97b23b464184afa8c4c396dcf219696b2682d0adf6'
},
{
text: 'ban_1anrzcuwe64rwxzcco8dkhpyxpi8kd7zsjc1oeimpc3ppca4mrjtwnqposrs',
hex: '2298fab7c61058e77ea554cb93edeeda0692cbfcc540ab213b2836b29029e23a'
}
],
},
{
name: 'BCN',
coinType: 204,
Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,22 @@ function nanoAddressDecoder(data: string): Buffer {
return Buffer.from(decoded).slice(0, -5);
}

function bananoAddressEncoder(data: Buffer): string {
const encoded = nanoBase32Encode(Uint8Array.from(data));
const checksum = blake2b(Uint8Array.from(data), null, 5).reverse();
const checksumEncoded = nanoBase32Encode(checksum);

const address = `ban_${encoded}${checksumEncoded}`;

return address;
}

function bananoAddressDecoder(data: string): Buffer {
const decoded = nanoBase32Decode(data.slice(4));

return Buffer.from(decoded).slice(0, -5);
}

function etnAddressEncoder(data: Buffer): string {
const buf = Buffer.concat([Buffer.from([18]), data]);

Expand Down Expand Up @@ -1507,6 +1523,7 @@ export const formats: IFormat[] = [
bitcoinChain('LCC', 192, 'lcc', [[0x1c]], [[0x32], [0x05]]),
eosioChain('EOS', 194, 'EOS'),
getConfig('TRX', 195, bs58Encode, bs58Decode),
getConfig('BAN', 198, bananoAddressEncoder, bananoAddressDecoder),
getConfig('BCN', 204, bcnAddressEncoder, bcnAddressDecoder),
eosioChain('FIO', 235, 'FIO'),
getConfig('BSV', 236, bsvAddresEncoder, bsvAddressDecoder),
Expand Down