2

I am currently only checking if the address is 56 chars long an if it is alphanumeric.

Is there a checksum in an address to verify it.

Are there any other rules ?

3 Answers 3

5

Stellar uses Ed25519 public/private keys. So you can research that if you want some more details.

If you're using a library (like the JS SDK) it's as simple as calling:

StrKey.isValidEd25519PublicKey(address);

If you want to see the details of how that's implemented, you can see here: https://github.com/stellar/js-stellar-base/blob/master/src/strkey.js#L110

In short: There is a version byte, a payload/data, and a checksum.

2

The previous answer is correct, but just to be a little more precise about what is going on, Stellar private keys are computed as follows. First, a 35-byte value is computed as follow:

  • The fist byte is 'S' << 3.
  • The next 32 bytes are the Ed25519 private key seed
  • The last two bytes are a CRC16 checksum of the first 33 bytes.

Then the whole thing is encoded using RFC4648 base-32 encoding.

0

In a <form>, one can use a simple regexp to match the Secret Key value:

    <form onSubmit={onSubmit}>
      <label>Secret Key: </label>
      <input 
    type='text' id='secretKey' required 
    pattern='^S[0-9A-Z]{55}$' 
      title='^S[0-9A-Z]{55}$'
      />  
      <button type="submit"> Store</button>
    </form>
...
  const onSubmit = event => {
    event.preventDefault()
    alert(event.target.secretKey.value)
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.