Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for base 58 private key?

Tags:

bitcoin

I'm looking for a regex that will validate a base 58 bitcoin private key. I found this one for public addresses:

/^[13n][1-9A-Za-z][^OIl]{20,40}/

But I don't know what the requirements are for a private key.

like image 708
cilphex Avatar asked Dec 01 '22 21:12

cilphex


1 Answers

var regex = /^[5KL][1-9A-HJ-NP-Za-km-z]{50,51}$/

In javascript.

All valid WIF private keys will match this, and the only extra stuff this will match is "WIF private key"-ish strings with invalid checksums.

Shortest possible WIF key (all 00 bytes, missing the compressed 01 byte) 51 length 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAbuatmU

Longest possible WIF key (all ff bytes with the extra 01 compression byte) 52 length L5oLkpV3aqBjhki6LmvChTCq73v9gyymzzMpBbhDLjDpKCuAXpsi

like image 64
user3074620 Avatar answered Dec 04 '22 03:12

user3074620