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

Avax with prefix #359

Merged
merged 9 commits into from
Aug 10, 2022
Merged
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
lib
.DS_Store
*.swp
10 changes: 10 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,16 @@ const vectors: Array<TestVector> = [
coinType: 9000,
passingVectors: [
{ text: 'avax1a5h6v9weng8guuah6aamagea0xhsd04mvs2zun', hex: 'ed2fa615d99a0e8e73b7d77bbea33d79af06bebb' },
{
text: 'P-avax1a5h6v9weng8guuah6aamagea0xhsd04mvs2zun',
hex: 'ed2fa615d99a0e8e73b7d77bbea33d79af06bebb',
canonical: 'avax1a5h6v9weng8guuah6aamagea0xhsd04mvs2zun'
},
{
text: 'X-avax1a5h6v9weng8guuah6aamagea0xhsd04mvs2zun',
hex: 'ed2fa615d99a0e8e73b7d77bbea33d79af06bebb',
canonical: 'avax1a5h6v9weng8guuah6aamagea0xhsd04mvs2zun'
},
],
},
{
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ const cardanoChain = (
name,
});

function makeAvaxDecoder (hrp: string): (data: string) => Buffer {
const decodeBech32 = makeBech32Decoder(hrp)
return (data: string) => {
let address
const [id, possibleAddr] = data.split('-')
if (!possibleAddr) { address = id }
else { address = possibleAddr }

return decodeBech32(address)
}
}

function decodeNearAddr(data: string): Buffer {
const regex = /(^(([a-z\d]+[\-_])*[a-z\d]+\.)*([a-z\d]+[\-_])*[a-z\d]+$)/g;
if(!regex.test(data)) {
Expand Down Expand Up @@ -1550,7 +1562,7 @@ export const formats: IFormat[] = [
hexChecksumChain('GO_LEGACY', 6060),
bech32mChain('XCH', 8444, 'xch', 90),
getConfig('NULS', 8964, nulsAddressEncoder, nulsAddressDecoder),
bech32Chain('AVAX', 9000, 'avax'),
getConfig('AVAX', 9000, makeBech32Encoder('avax'), makeAvaxDecoder('avax')),
hexChecksumChain('NRG_LEGACY', 9797),
getConfig('ARDR', 16754, ardrAddressEncoder, ardrAddressDecoder),
zcashChain('ZEL', 19167, 'za', [[0x1c, 0xb8]], [[0x1c, 0xbd]]),
Expand Down