stacks-network / stacks-utils

Utilities for the Stacks blockchain.
https://stacks-utils.now.sh
6 stars 6 forks source link

Invalid addresses are passing #21

Open jhammond2012 opened 3 years ago

jhammond2012 commented 3 years ago

I am using: import { validateStacksAddress } from "stacks-utils"; to validate addresses. If you change the first letter in an address to anything, it still passes as valid.

wileyj commented 3 years ago

The issues seems to come from here: https://github.com/blockstack/c32check

Since the function is using this library to validate an address. https://github.com/blockstack/stacks-utils/blob/master/src/addresses.js#L24-L35

jhammond2012 commented 3 years ago

@wileyj Should I close this issue and open one there?

wileyj commented 3 years ago

i wouldn't close it, i'd like to see what @aulneau thinks first (he would be more familiar with this function).

jcnelson commented 3 years ago

I'm not sure what you're talking about? Can you provide the address used to reproduce this?

$ node
c32Welcome to Node.js v14.16.1.
Type ".help" for more information.
> c32 = require('c32check')
{
  c32encode: [Function: c32encode],
  c32decode: [Function: c32decode],
  c32checkEncode: [Function: c32checkEncode],
  c32checkDecode: [Function: c32checkDecode],
  c32address: [Function: c32address],
  c32addressDecode: [Function: c32addressDecode],
  c32normalize: [Function: c32normalize],
  versions: {
    mainnet: { p2pkh: 22, p2sh: 20 },
    testnet: { p2pkh: 26, p2sh: 21 }
  },
  c32ToB58: [Function: c32ToB58],
  b58ToC32: [Function: b58ToC32]
}
> c32.c32addressDecode('ST2X2FYCY01Y7YR2TGC2Y6661NFF3SMH0NGXPWTV5')
[ 26, 'ba27f99e007c7f605a8305e318c1abde3cd220ac' ]
> c32.c32addressDecode('T2X2FYCY01Y7YR2TGC2Y6661NFF3SMH0NGXPWTV5')
Uncaught Error: Invalid c32check string: checksum mismatch
    at c32checkDecode (/home/jude/node_modules/c32check/lib/checksum.js:88:11)
    at Object.c32addressDecode (/home/jude/node_modules/c32check/lib/address.js:70:39)
>
jhammond2012 commented 3 years ago

@jcnelson can you test with the following:

Expected to valid: SP2CT665Q0JB7P39TZ7BST0QYCAQSMJWBZK8QT35J Expected to be invalid: bP2CT665Q0JB7P39TZ7BST0QYCAQSMJWBZK8QT35J

jcnelson commented 3 years ago

Thanks! I can reproduce it now.

jcnelson commented 3 years ago

PR sent: https://github.com/blockstack/c32check/pull/14