Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with 11 bit padding messing up checksum check. #33

Merged
merged 1 commit into from
Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ function mnemonicToEntropy (mnemonic, wordlist) {
var entropyBuffer = new Buffer(entropyBytes)
var newChecksum = checksumBits(entropyBuffer)

assert(newChecksum === checksum, 'Invalid mnemonic checksum')
// recreate properly chunked and padded bits to get the properly padded checksum
var bits2 = (entropy + newChecksum).match(/(.{1,11})/g).map(function(index) {
return lpad(index, '0', 11)

}).join('')
var dividerIndex2 = Math.floor(bits2.length / 33) * 32
var newChecksum2 = bits2.slice(dividerIndex2)

assert(newChecksum2 === checksum, 'Invalid mnemonic checksum')

return entropyBuffer.toString('hex')
}
Expand Down
5 changes: 5 additions & 0 deletions test/vectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
"15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419",
"beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut",
"b15509eaa2d09d3efd3e006ef42151b30367dc6e3aa5e44caba3fe4d3e352e65101fbdb86a96776b91946ff06f8eac594dc6ee1d3e82a42dfe1b40fef6bcc3fd"
],
[
"00000000009a54180ac35938181b318ea3ee09c1cb35d552d5d0d2304808eb820bdb562a729283a2b0a35d46d10a39bec48d151f194c48ea2b257db81e82410943874cc1267ae2495122f1705dac461db0f0bc9a0bde6bc8a4e8e3a2b86aa1550c428e81ec7990a1c27c806bc9ed48b7bd7c7535b16cd2fdf3ee8f05d7b9da2fb61efb17f360de3253b69813ea3a5442e065e50a013372f9b628976bcdc8909600634520de93ed34ec8cefd2f9bd21e8922be4a6e1f609a00ace8aef88ab727f85988dae8c5f5a1a64f121f6baa6d117af31edca97a7743c0581753632faab42ff4b9c800024e390c7f8f72e566e333a2e69344f4f7c5d0ac63b2c0bf1aa48f12dc3ea395b2bb38841e14912fcb75192519c25a4913943ca435d73fcd3a74187884524194a4a025a1f3876582c67af84dc05b8fea262028ae049e53f724f9614fd01b66e501936b735c384fb462ea5d490eb0b189173e43a9d0a1c0b5ed06d7e989e5e888e9fa7377a96d55ba67b4d2bcabffb48c467133bd62c7ccdd3bd2a1eac39c2237b98591b598804b2701882fdd800c767a4189b4e92c981a7782df30b2f50beab4b17a0c95451533ff0175792f05fb09c393604453166b277aba0aefe611ebfb0eccf686469b5490933ee75c35555c9ef271993d869282217d62452ad9b078f0f9fdd6725983e4da5280fa9052b2c6648cbd4583ca05d69d1996704953452a3c66ceb9680ecbc3164ca2c8a7d4dbb1852ca22fa4bbda7b97d56b698da2e66e3c8af5fdde3f58dcc10a89570a70e63d0784a842112231e118a767765e140f91001cab2688a97fdfbd2ba620f743813adf8fade4ef625ed410b89d7239a28d78fa1c10fce957f69dd1e81af0d255658e016f5fc943b040f31c17876ea178e6a0758a8b8d389ed76320a41e631fa1deea3cb7bebb6df1593826c9ee8efb094e2397ff8fe73f73c4d1e710144152fe7ba208b3d79f2b221f335d04742a0c7cfad6a1f1deaeef4b6f5cea41b0283f42883fed4e259dccc4d05ffabac26a6d886cc1318aac98e56cedbcf1f047d8789f7e38295a4a7d8c17683c72cedd393eadd498e097f10947a2a38a131d16cc3489274482b47ec4f06eea019d1920cafd49350c767c5901da6ffafb73817d8cc70daf0e286bbbffacd84433fd4d15fb477397bb65e7b785b0a0ca4516540b2c920a4bcade486556f124d3bdac6c2c3bf32eaa5f2699f42194b7be6a1632f7f7b4c7d684dbd6193e3aabbb23be0dc47c10dd306f9bed063efc12e376d4d959e70811e44074bd972f8db8f2c58f9313db6d18b6d38f1318235fb2c864ae10cad3ceb55edc3e861a8aac755505d433362ee428d788e427bd6595abc8f4201a84d1f13d6443df4206871884b1aac83f0637bd6b9242d210297d32572c8a6d97fcf21530cfd5eddd36d6d0b333e3f056fa04ddba500ddd2",
"abandon abandon abandon abuse pipe army climb hen day school small bubble discover agent already grit stem note injury piece afraid afford puppy door swap rally original celery demand flame miracle potato speed fade hurry math spend moon gown math tuition float garage ice trial calm celery ill error ankle pact setup never multiply shift arm proof couch history thumb situate album keen jungle pilot either trim ignore present pride country fade limit glow goddess drum chief dizzy quality diet emerge sadness gallery tuna force reopen episode salmon update join invest inhale pepper swallow know glass vibrant alone milk polar hat antique pottery enhance drill add junk beef basket ride traffic shallow number fury impulse cancel gas coyote behind bridge negative have depth border wood lamp virus dial mutual game claim sentence gauge source clinic spend usage earn symptom yellow flower egg riot message foam spring detail dumb hill fat dust vote cradle hour planet exclude duck actress alarm plug cream stem spawn write right divorce above organ move divert differ frequent group book trim snake crowd kidney tenant ring property budget rabbit lawsuit prevent elegant enter march phone pulse put illegal draft apart dwarf west insect since edit lucky pig mean extend nest cupboard rigid viable insane dose detail bacon else net celery annual dumb debris ready arch soon weapon host black cabin pen avoid pencil scene oxygen panic since version belt trend horn syrup account opera system reveal lumber surface merry entry empower intact cluster banana initial canyon point before scheme quarter double quit obtain very peasant brush whip option tumble survey forum critic spy fiscal program world cart mind basket team mention wet tag teach position stereo degree baby ten cost museum proud cactus north hybrid series satoshi quote arrest record motor beach excess north gather exclude lizard wet coach tube salt fog shine dose next chunk erupt wrap blanket route rose satoshi antenna broken submit master cousin culture over firm april left love subject rail grid sure silver opera pig cave lava into boy fever need venue mimic exhaust artwork choice awful void emerge client snow bullet tiger panther twenty siren corn tooth spoon parent vivid ahead floor book muscle run clown verb arm hawk mimic flush ankle fashion citizen monitor snow twist reduce depth journey bind govern rate exile ethics sugar believe nephew cook chair walk warm later remember plate reform toy impose cargo typical target cabbage gloom oblige appear enjoy secret tide glow long bargain analyst bachelor bag joke course island robot joke limit much abstract client escape melody say leave pistol plate amateur special act pupil sick resource over girl wall aerobic illness strong broom mechanic pyramid wheel they dish sport legal exclude element addict valid naive floor bright black quiz celery invite domain ocean album attract tube round once attitude melody fragile evolve diet involve motion motor small cabbage auction ritual just know frozen result clinic deal curve knife bulb rack poem mixture zoo morning delay table meadow bunker marine extra clean wrist tackle lion guilt ketchup night mask toy fringe casual appear body soul hero march design puzzle kid swift right piano submit path tribe market youth fatal enroll system give door young river battle opinion awkward slot occur click narrow tornado guess hundred token afford umbrella tiny used deal enlist myth wild scrap reduce vault flush tag size problem powder mix episode service cigar pencil brisk luggage demand holiday bottom cause trigger live physical raise this upgrade absorb inner catch slab tumble essence body guitar clutch alter evil wife swear theory wild small man rotate shallow hill that twenty rack drip wrong crowd satoshi electric original uphold slim kiwi security secret bone eagle razor actress float camera chalk clock simple grab resource empty polar suspect current rail lazy concert fancy situate crop dragon ski ten snap bike nut worth hat latin draw hungry segment dilemma stem uphold electric this timber utility brick corn lamp win arrest used annual miss surround sun song search cat dune demise wagon tourist misery shy ramp busy couple unit refuse bitter squeeze joy ship effort will goddess naive search skull oyster pull sad sentence drink health few inspire popular insect grid glass improve person valve tomorrow digital floor clip route key lesson explain spin measure flip marble vintage addict broccoli awesome random film average arrest knock remind empower fog awake episode erode purity silly cycle garment oxygen benefit major voice sweet square hidden drift grid token live salon answer sweet chimney danger pizza magic deny clean forum garbage alter price seed hero visit where grain version oval clutch among welcome struggle first entire cheese trend issue",
"c8143da36c01b19ddba54c4d3127cc1769f1ae7d3e785126b4e4970bba4c30f1248ded216e6d45261e8e637bd2c76b71b14e602c8601c7b85e5648724449f8a7"
]
],
"custom": [
Expand Down