Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Invalid addresses are passing #21

Open
ImTheCodeFarmer opened this issue Apr 12, 2021 · 7 comments
Open

Invalid addresses are passing #21

ImTheCodeFarmer opened this issue Apr 12, 2021 · 7 comments

Comments

@ImTheCodeFarmer
Copy link

ImTheCodeFarmer commented Apr 12, 2021

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
Copy link

wileyj commented Apr 12, 2021

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

@ImTheCodeFarmer
Copy link
Author

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

@wileyj
Copy link

wileyj commented Apr 12, 2021

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

@jcnelson
Copy link

jcnelson commented Apr 15, 2021

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)
>

@ImTheCodeFarmer
Copy link
Author

@jcnelson can you test with the following:

Expected to valid: SP2CT665Q0JB7P39TZ7BST0QYCAQSMJWBZK8QT35J
Expected to be invalid: bP2CT665Q0JB7P39TZ7BST0QYCAQSMJWBZK8QT35J

@jcnelson
Copy link

Thanks! I can reproduce it now.

@jcnelson
Copy link

PR sent: stacks-network/c32check#14

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants