Skip to content

Commit

Permalink
Merge pull request #14 from blockstack/fix/require-leading-s
Browse files Browse the repository at this point in the history
fix: require that c32 addresses start with `S`
  • Loading branch information
jcnelson authored Apr 16, 2021
2 parents 5b0e305 + 5a9d37b commit 5777e44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export function c32addressDecode(c32addr: string) : [number, string] {
if (c32addr.length <= 5) {
throw new Error('Invalid c32 address: invalid length')
}
if (c32addr[0] != 'S') {
throw new Error('Invalid c32 address: must start with "S"')
}
return c32checkDecode(c32addr.slice(1))
}

Expand Down
3 changes: 2 additions & 1 deletion tests/unitTests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ export function c32addressTests() {
() => c32addressDecode('ST2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQYAC0RQ0'),
() => c32addressDecode('ST2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQYAC0RR'),
() => c32addressDecode('ST2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQYAC0R'),
() => c32addressDecode('ST2J')
() => c32addressDecode('ST2J'),
() => c32addressDecode('bP2CT665Q0JB7P39TZ7BST0QYCAQSMJWBZK8QT35J')
]

t.plan(invalids.length + invalidDecodes.length)
Expand Down

0 comments on commit 5777e44

Please sign in to comment.