diff --git a/src/address.ts b/src/address.ts index 1b43464..c5a7304 100644 --- a/src/address.ts +++ b/src/address.ts @@ -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)) } diff --git a/tests/unitTests/src/index.ts b/tests/unitTests/src/index.ts index ce8e513..314bed5 100644 --- a/tests/unitTests/src/index.ts +++ b/tests/unitTests/src/index.ts @@ -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)