bip39.py 17 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2020 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. bip39.py - Data and routines for BIP39 mnemonic seed phrases
  20. """
  21. from hashlib import sha256
  22. from mmgen.exception import *
  23. from mmgen.baseconv import *
  24. from mmgen.util import is_hex_str
  25. # implements a subset of the baseconv API
  26. class bip39(baseconv):
  27. words = tuple("""
  28. abandon
  29. ability
  30. able
  31. about
  32. above
  33. absent
  34. absorb
  35. abstract
  36. absurd
  37. abuse
  38. access
  39. accident
  40. account
  41. accuse
  42. achieve
  43. acid
  44. acoustic
  45. acquire
  46. across
  47. act
  48. action
  49. actor
  50. actress
  51. actual
  52. adapt
  53. add
  54. addict
  55. address
  56. adjust
  57. admit
  58. adult
  59. advance
  60. advice
  61. aerobic
  62. affair
  63. afford
  64. afraid
  65. again
  66. age
  67. agent
  68. agree
  69. ahead
  70. aim
  71. air
  72. airport
  73. aisle
  74. alarm
  75. album
  76. alcohol
  77. alert
  78. alien
  79. all
  80. alley
  81. allow
  82. almost
  83. alone
  84. alpha
  85. already
  86. also
  87. alter
  88. always
  89. amateur
  90. amazing
  91. among
  92. amount
  93. amused
  94. analyst
  95. anchor
  96. ancient
  97. anger
  98. angle
  99. angry
  100. animal
  101. ankle
  102. announce
  103. annual
  104. another
  105. answer
  106. antenna
  107. antique
  108. anxiety
  109. any
  110. apart
  111. apology
  112. appear
  113. apple
  114. approve
  115. april
  116. arch
  117. arctic
  118. area
  119. arena
  120. argue
  121. arm
  122. armed
  123. armor
  124. army
  125. around
  126. arrange
  127. arrest
  128. arrive
  129. arrow
  130. art
  131. artefact
  132. artist
  133. artwork
  134. ask
  135. aspect
  136. assault
  137. asset
  138. assist
  139. assume
  140. asthma
  141. athlete
  142. atom
  143. attack
  144. attend
  145. attitude
  146. attract
  147. auction
  148. audit
  149. august
  150. aunt
  151. author
  152. auto
  153. autumn
  154. average
  155. avocado
  156. avoid
  157. awake
  158. aware
  159. away
  160. awesome
  161. awful
  162. awkward
  163. axis
  164. baby
  165. bachelor
  166. bacon
  167. badge
  168. bag
  169. balance
  170. balcony
  171. ball
  172. bamboo
  173. banana
  174. banner
  175. bar
  176. barely
  177. bargain
  178. barrel
  179. base
  180. basic
  181. basket
  182. battle
  183. beach
  184. bean
  185. beauty
  186. because
  187. become
  188. beef
  189. before
  190. begin
  191. behave
  192. behind
  193. believe
  194. below
  195. belt
  196. bench
  197. benefit
  198. best
  199. betray
  200. better
  201. between
  202. beyond
  203. bicycle
  204. bid
  205. bike
  206. bind
  207. biology
  208. bird
  209. birth
  210. bitter
  211. black
  212. blade
  213. blame
  214. blanket
  215. blast
  216. bleak
  217. bless
  218. blind
  219. blood
  220. blossom
  221. blouse
  222. blue
  223. blur
  224. blush
  225. board
  226. boat
  227. body
  228. boil
  229. bomb
  230. bone
  231. bonus
  232. book
  233. boost
  234. border
  235. boring
  236. borrow
  237. boss
  238. bottom
  239. bounce
  240. box
  241. boy
  242. bracket
  243. brain
  244. brand
  245. brass
  246. brave
  247. bread
  248. breeze
  249. brick
  250. bridge
  251. brief
  252. bright
  253. bring
  254. brisk
  255. broccoli
  256. broken
  257. bronze
  258. broom
  259. brother
  260. brown
  261. brush
  262. bubble
  263. buddy
  264. budget
  265. buffalo
  266. build
  267. bulb
  268. bulk
  269. bullet
  270. bundle
  271. bunker
  272. burden
  273. burger
  274. burst
  275. bus
  276. business
  277. busy
  278. butter
  279. buyer
  280. buzz
  281. cabbage
  282. cabin
  283. cable
  284. cactus
  285. cage
  286. cake
  287. call
  288. calm
  289. camera
  290. camp
  291. can
  292. canal
  293. cancel
  294. candy
  295. cannon
  296. canoe
  297. canvas
  298. canyon
  299. capable
  300. capital
  301. captain
  302. car
  303. carbon
  304. card
  305. cargo
  306. carpet
  307. carry
  308. cart
  309. case
  310. cash
  311. casino
  312. castle
  313. casual
  314. cat
  315. catalog
  316. catch
  317. category
  318. cattle
  319. caught
  320. cause
  321. caution
  322. cave
  323. ceiling
  324. celery
  325. cement
  326. census
  327. century
  328. cereal
  329. certain
  330. chair
  331. chalk
  332. champion
  333. change
  334. chaos
  335. chapter
  336. charge
  337. chase
  338. chat
  339. cheap
  340. check
  341. cheese
  342. chef
  343. cherry
  344. chest
  345. chicken
  346. chief
  347. child
  348. chimney
  349. choice
  350. choose
  351. chronic
  352. chuckle
  353. chunk
  354. churn
  355. cigar
  356. cinnamon
  357. circle
  358. citizen
  359. city
  360. civil
  361. claim
  362. clap
  363. clarify
  364. claw
  365. clay
  366. clean
  367. clerk
  368. clever
  369. click
  370. client
  371. cliff
  372. climb
  373. clinic
  374. clip
  375. clock
  376. clog
  377. close
  378. cloth
  379. cloud
  380. clown
  381. club
  382. clump
  383. cluster
  384. clutch
  385. coach
  386. coast
  387. coconut
  388. code
  389. coffee
  390. coil
  391. coin
  392. collect
  393. color
  394. column
  395. combine
  396. come
  397. comfort
  398. comic
  399. common
  400. company
  401. concert
  402. conduct
  403. confirm
  404. congress
  405. connect
  406. consider
  407. control
  408. convince
  409. cook
  410. cool
  411. copper
  412. copy
  413. coral
  414. core
  415. corn
  416. correct
  417. cost
  418. cotton
  419. couch
  420. country
  421. couple
  422. course
  423. cousin
  424. cover
  425. coyote
  426. crack
  427. cradle
  428. craft
  429. cram
  430. crane
  431. crash
  432. crater
  433. crawl
  434. crazy
  435. cream
  436. credit
  437. creek
  438. crew
  439. cricket
  440. crime
  441. crisp
  442. critic
  443. crop
  444. cross
  445. crouch
  446. crowd
  447. crucial
  448. cruel
  449. cruise
  450. crumble
  451. crunch
  452. crush
  453. cry
  454. crystal
  455. cube
  456. culture
  457. cup
  458. cupboard
  459. curious
  460. current
  461. curtain
  462. curve
  463. cushion
  464. custom
  465. cute
  466. cycle
  467. dad
  468. damage
  469. damp
  470. dance
  471. danger
  472. daring
  473. dash
  474. daughter
  475. dawn
  476. day
  477. deal
  478. debate
  479. debris
  480. decade
  481. december
  482. decide
  483. decline
  484. decorate
  485. decrease
  486. deer
  487. defense
  488. define
  489. defy
  490. degree
  491. delay
  492. deliver
  493. demand
  494. demise
  495. denial
  496. dentist
  497. deny
  498. depart
  499. depend
  500. deposit
  501. depth
  502. deputy
  503. derive
  504. describe
  505. desert
  506. design
  507. desk
  508. despair
  509. destroy
  510. detail
  511. detect
  512. develop
  513. device
  514. devote
  515. diagram
  516. dial
  517. diamond
  518. diary
  519. dice
  520. diesel
  521. diet
  522. differ
  523. digital
  524. dignity
  525. dilemma
  526. dinner
  527. dinosaur
  528. direct
  529. dirt
  530. disagree
  531. discover
  532. disease
  533. dish
  534. dismiss
  535. disorder
  536. display
  537. distance
  538. divert
  539. divide
  540. divorce
  541. dizzy
  542. doctor
  543. document
  544. dog
  545. doll
  546. dolphin
  547. domain
  548. donate
  549. donkey
  550. donor
  551. door
  552. dose
  553. double
  554. dove
  555. draft
  556. dragon
  557. drama
  558. drastic
  559. draw
  560. dream
  561. dress
  562. drift
  563. drill
  564. drink
  565. drip
  566. drive
  567. drop
  568. drum
  569. dry
  570. duck
  571. dumb
  572. dune
  573. during
  574. dust
  575. dutch
  576. duty
  577. dwarf
  578. dynamic
  579. eager
  580. eagle
  581. early
  582. earn
  583. earth
  584. easily
  585. east
  586. easy
  587. echo
  588. ecology
  589. economy
  590. edge
  591. edit
  592. educate
  593. effort
  594. egg
  595. eight
  596. either
  597. elbow
  598. elder
  599. electric
  600. elegant
  601. element
  602. elephant
  603. elevator
  604. elite
  605. else
  606. embark
  607. embody
  608. embrace
  609. emerge
  610. emotion
  611. employ
  612. empower
  613. empty
  614. enable
  615. enact
  616. end
  617. endless
  618. endorse
  619. enemy
  620. energy
  621. enforce
  622. engage
  623. engine
  624. enhance
  625. enjoy
  626. enlist
  627. enough
  628. enrich
  629. enroll
  630. ensure
  631. enter
  632. entire
  633. entry
  634. envelope
  635. episode
  636. equal
  637. equip
  638. era
  639. erase
  640. erode
  641. erosion
  642. error
  643. erupt
  644. escape
  645. essay
  646. essence
  647. estate
  648. eternal
  649. ethics
  650. evidence
  651. evil
  652. evoke
  653. evolve
  654. exact
  655. example
  656. excess
  657. exchange
  658. excite
  659. exclude
  660. excuse
  661. execute
  662. exercise
  663. exhaust
  664. exhibit
  665. exile
  666. exist
  667. exit
  668. exotic
  669. expand
  670. expect
  671. expire
  672. explain
  673. expose
  674. express
  675. extend
  676. extra
  677. eye
  678. eyebrow
  679. fabric
  680. face
  681. faculty
  682. fade
  683. faint
  684. faith
  685. fall
  686. false
  687. fame
  688. family
  689. famous
  690. fan
  691. fancy
  692. fantasy
  693. farm
  694. fashion
  695. fat
  696. fatal
  697. father
  698. fatigue
  699. fault
  700. favorite
  701. feature
  702. february
  703. federal
  704. fee
  705. feed
  706. feel
  707. female
  708. fence
  709. festival
  710. fetch
  711. fever
  712. few
  713. fiber
  714. fiction
  715. field
  716. figure
  717. file
  718. film
  719. filter
  720. final
  721. find
  722. fine
  723. finger
  724. finish
  725. fire
  726. firm
  727. first
  728. fiscal
  729. fish
  730. fit
  731. fitness
  732. fix
  733. flag
  734. flame
  735. flash
  736. flat
  737. flavor
  738. flee
  739. flight
  740. flip
  741. float
  742. flock
  743. floor
  744. flower
  745. fluid
  746. flush
  747. fly
  748. foam
  749. focus
  750. fog
  751. foil
  752. fold
  753. follow
  754. food
  755. foot
  756. force
  757. forest
  758. forget
  759. fork
  760. fortune
  761. forum
  762. forward
  763. fossil
  764. foster
  765. found
  766. fox
  767. fragile
  768. frame
  769. frequent
  770. fresh
  771. friend
  772. fringe
  773. frog
  774. front
  775. frost
  776. frown
  777. frozen
  778. fruit
  779. fuel
  780. fun
  781. funny
  782. furnace
  783. fury
  784. future
  785. gadget
  786. gain
  787. galaxy
  788. gallery
  789. game
  790. gap
  791. garage
  792. garbage
  793. garden
  794. garlic
  795. garment
  796. gas
  797. gasp
  798. gate
  799. gather
  800. gauge
  801. gaze
  802. general
  803. genius
  804. genre
  805. gentle
  806. genuine
  807. gesture
  808. ghost
  809. giant
  810. gift
  811. giggle
  812. ginger
  813. giraffe
  814. girl
  815. give
  816. glad
  817. glance
  818. glare
  819. glass
  820. glide
  821. glimpse
  822. globe
  823. gloom
  824. glory
  825. glove
  826. glow
  827. glue
  828. goat
  829. goddess
  830. gold
  831. good
  832. goose
  833. gorilla
  834. gospel
  835. gossip
  836. govern
  837. gown
  838. grab
  839. grace
  840. grain
  841. grant
  842. grape
  843. grass
  844. gravity
  845. great
  846. green
  847. grid
  848. grief
  849. grit
  850. grocery
  851. group
  852. grow
  853. grunt
  854. guard
  855. guess
  856. guide
  857. guilt
  858. guitar
  859. gun
  860. gym
  861. habit
  862. hair
  863. half
  864. hammer
  865. hamster
  866. hand
  867. happy
  868. harbor
  869. hard
  870. harsh
  871. harvest
  872. hat
  873. have
  874. hawk
  875. hazard
  876. head
  877. health
  878. heart
  879. heavy
  880. hedgehog
  881. height
  882. hello
  883. helmet
  884. help
  885. hen
  886. hero
  887. hidden
  888. high
  889. hill
  890. hint
  891. hip
  892. hire
  893. history
  894. hobby
  895. hockey
  896. hold
  897. hole
  898. holiday
  899. hollow
  900. home
  901. honey
  902. hood
  903. hope
  904. horn
  905. horror
  906. horse
  907. hospital
  908. host
  909. hotel
  910. hour
  911. hover
  912. hub
  913. huge
  914. human
  915. humble
  916. humor
  917. hundred
  918. hungry
  919. hunt
  920. hurdle
  921. hurry
  922. hurt
  923. husband
  924. hybrid
  925. ice
  926. icon
  927. idea
  928. identify
  929. idle
  930. ignore
  931. ill
  932. illegal
  933. illness
  934. image
  935. imitate
  936. immense
  937. immune
  938. impact
  939. impose
  940. improve
  941. impulse
  942. inch
  943. include
  944. income
  945. increase
  946. index
  947. indicate
  948. indoor
  949. industry
  950. infant
  951. inflict
  952. inform
  953. inhale
  954. inherit
  955. initial
  956. inject
  957. injury
  958. inmate
  959. inner
  960. innocent
  961. input
  962. inquiry
  963. insane
  964. insect
  965. inside
  966. inspire
  967. install
  968. intact
  969. interest
  970. into
  971. invest
  972. invite
  973. involve
  974. iron
  975. island
  976. isolate
  977. issue
  978. item
  979. ivory
  980. jacket
  981. jaguar
  982. jar
  983. jazz
  984. jealous
  985. jeans
  986. jelly
  987. jewel
  988. job
  989. join
  990. joke
  991. journey
  992. joy
  993. judge
  994. juice
  995. jump
  996. jungle
  997. junior
  998. junk
  999. just
  1000. kangaroo
  1001. keen
  1002. keep
  1003. ketchup
  1004. key
  1005. kick
  1006. kid
  1007. kidney
  1008. kind
  1009. kingdom
  1010. kiss
  1011. kit
  1012. kitchen
  1013. kite
  1014. kitten
  1015. kiwi
  1016. knee
  1017. knife
  1018. knock
  1019. know
  1020. lab
  1021. label
  1022. labor
  1023. ladder
  1024. lady
  1025. lake
  1026. lamp
  1027. language
  1028. laptop
  1029. large
  1030. later
  1031. latin
  1032. laugh
  1033. laundry
  1034. lava
  1035. law
  1036. lawn
  1037. lawsuit
  1038. layer
  1039. lazy
  1040. leader
  1041. leaf
  1042. learn
  1043. leave
  1044. lecture
  1045. left
  1046. leg
  1047. legal
  1048. legend
  1049. leisure
  1050. lemon
  1051. lend
  1052. length
  1053. lens
  1054. leopard
  1055. lesson
  1056. letter
  1057. level
  1058. liar
  1059. liberty
  1060. library
  1061. license
  1062. life
  1063. lift
  1064. light
  1065. like
  1066. limb
  1067. limit
  1068. link
  1069. lion
  1070. liquid
  1071. list
  1072. little
  1073. live
  1074. lizard
  1075. load
  1076. loan
  1077. lobster
  1078. local
  1079. lock
  1080. logic
  1081. lonely
  1082. long
  1083. loop
  1084. lottery
  1085. loud
  1086. lounge
  1087. love
  1088. loyal
  1089. lucky
  1090. luggage
  1091. lumber
  1092. lunar
  1093. lunch
  1094. luxury
  1095. lyrics
  1096. machine
  1097. mad
  1098. magic
  1099. magnet
  1100. maid
  1101. mail
  1102. main
  1103. major
  1104. make
  1105. mammal
  1106. man
  1107. manage
  1108. mandate
  1109. mango
  1110. mansion
  1111. manual
  1112. maple
  1113. marble
  1114. march
  1115. margin
  1116. marine
  1117. market
  1118. marriage
  1119. mask
  1120. mass
  1121. master
  1122. match
  1123. material
  1124. math
  1125. matrix
  1126. matter
  1127. maximum
  1128. maze
  1129. meadow
  1130. mean
  1131. measure
  1132. meat
  1133. mechanic
  1134. medal
  1135. media
  1136. melody
  1137. melt
  1138. member
  1139. memory
  1140. mention
  1141. menu
  1142. mercy
  1143. merge
  1144. merit
  1145. merry
  1146. mesh
  1147. message
  1148. metal
  1149. method
  1150. middle
  1151. midnight
  1152. milk
  1153. million
  1154. mimic
  1155. mind
  1156. minimum
  1157. minor
  1158. minute
  1159. miracle
  1160. mirror
  1161. misery
  1162. miss
  1163. mistake
  1164. mix
  1165. mixed
  1166. mixture
  1167. mobile
  1168. model
  1169. modify
  1170. mom
  1171. moment
  1172. monitor
  1173. monkey
  1174. monster
  1175. month
  1176. moon
  1177. moral
  1178. more
  1179. morning
  1180. mosquito
  1181. mother
  1182. motion
  1183. motor
  1184. mountain
  1185. mouse
  1186. move
  1187. movie
  1188. much
  1189. muffin
  1190. mule
  1191. multiply
  1192. muscle
  1193. museum
  1194. mushroom
  1195. music
  1196. must
  1197. mutual
  1198. myself
  1199. mystery
  1200. myth
  1201. naive
  1202. name
  1203. napkin
  1204. narrow
  1205. nasty
  1206. nation
  1207. nature
  1208. near
  1209. neck
  1210. need
  1211. negative
  1212. neglect
  1213. neither
  1214. nephew
  1215. nerve
  1216. nest
  1217. net
  1218. network
  1219. neutral
  1220. never
  1221. news
  1222. next
  1223. nice
  1224. night
  1225. noble
  1226. noise
  1227. nominee
  1228. noodle
  1229. normal
  1230. north
  1231. nose
  1232. notable
  1233. note
  1234. nothing
  1235. notice
  1236. novel
  1237. now
  1238. nuclear
  1239. number
  1240. nurse
  1241. nut
  1242. oak
  1243. obey
  1244. object
  1245. oblige
  1246. obscure
  1247. observe
  1248. obtain
  1249. obvious
  1250. occur
  1251. ocean
  1252. october
  1253. odor
  1254. off
  1255. offer
  1256. office
  1257. often
  1258. oil
  1259. okay
  1260. old
  1261. olive
  1262. olympic
  1263. omit
  1264. once
  1265. one
  1266. onion
  1267. online
  1268. only
  1269. open
  1270. opera
  1271. opinion
  1272. oppose
  1273. option
  1274. orange
  1275. orbit
  1276. orchard
  1277. order
  1278. ordinary
  1279. organ
  1280. orient
  1281. original
  1282. orphan
  1283. ostrich
  1284. other
  1285. outdoor
  1286. outer
  1287. output
  1288. outside
  1289. oval
  1290. oven
  1291. over
  1292. own
  1293. owner
  1294. oxygen
  1295. oyster
  1296. ozone
  1297. pact
  1298. paddle
  1299. page
  1300. pair
  1301. palace
  1302. palm
  1303. panda
  1304. panel
  1305. panic
  1306. panther
  1307. paper
  1308. parade
  1309. parent
  1310. park
  1311. parrot
  1312. party
  1313. pass
  1314. patch
  1315. path
  1316. patient
  1317. patrol
  1318. pattern
  1319. pause
  1320. pave
  1321. payment
  1322. peace
  1323. peanut
  1324. pear
  1325. peasant
  1326. pelican
  1327. pen
  1328. penalty
  1329. pencil
  1330. people
  1331. pepper
  1332. perfect
  1333. permit
  1334. person
  1335. pet
  1336. phone
  1337. photo
  1338. phrase
  1339. physical
  1340. piano
  1341. picnic
  1342. picture
  1343. piece
  1344. pig
  1345. pigeon
  1346. pill
  1347. pilot
  1348. pink
  1349. pioneer
  1350. pipe
  1351. pistol
  1352. pitch
  1353. pizza
  1354. place
  1355. planet
  1356. plastic
  1357. plate
  1358. play
  1359. please
  1360. pledge
  1361. pluck
  1362. plug
  1363. plunge
  1364. poem
  1365. poet
  1366. point
  1367. polar
  1368. pole
  1369. police
  1370. pond
  1371. pony
  1372. pool
  1373. popular
  1374. portion
  1375. position
  1376. possible
  1377. post
  1378. potato
  1379. pottery
  1380. poverty
  1381. powder
  1382. power
  1383. practice
  1384. praise
  1385. predict
  1386. prefer
  1387. prepare
  1388. present
  1389. pretty
  1390. prevent
  1391. price
  1392. pride
  1393. primary
  1394. print
  1395. priority
  1396. prison
  1397. private
  1398. prize
  1399. problem
  1400. process
  1401. produce
  1402. profit
  1403. program
  1404. project
  1405. promote
  1406. proof
  1407. property
  1408. prosper
  1409. protect
  1410. proud
  1411. provide
  1412. public
  1413. pudding
  1414. pull
  1415. pulp
  1416. pulse
  1417. pumpkin
  1418. punch
  1419. pupil
  1420. puppy
  1421. purchase
  1422. purity
  1423. purpose
  1424. purse
  1425. push
  1426. put
  1427. puzzle
  1428. pyramid
  1429. quality
  1430. quantum
  1431. quarter
  1432. question
  1433. quick
  1434. quit
  1435. quiz
  1436. quote
  1437. rabbit
  1438. raccoon
  1439. race
  1440. rack
  1441. radar
  1442. radio
  1443. rail
  1444. rain
  1445. raise
  1446. rally
  1447. ramp
  1448. ranch
  1449. random
  1450. range
  1451. rapid
  1452. rare
  1453. rate
  1454. rather
  1455. raven
  1456. raw
  1457. razor
  1458. ready
  1459. real
  1460. reason
  1461. rebel
  1462. rebuild
  1463. recall
  1464. receive
  1465. recipe
  1466. record
  1467. recycle
  1468. reduce
  1469. reflect
  1470. reform
  1471. refuse
  1472. region
  1473. regret
  1474. regular
  1475. reject
  1476. relax
  1477. release
  1478. relief
  1479. rely
  1480. remain
  1481. remember
  1482. remind
  1483. remove
  1484. render
  1485. renew
  1486. rent
  1487. reopen
  1488. repair
  1489. repeat
  1490. replace
  1491. report
  1492. require
  1493. rescue
  1494. resemble
  1495. resist
  1496. resource
  1497. response
  1498. result
  1499. retire
  1500. retreat
  1501. return
  1502. reunion
  1503. reveal
  1504. review
  1505. reward
  1506. rhythm
  1507. rib
  1508. ribbon
  1509. rice
  1510. rich
  1511. ride
  1512. ridge
  1513. rifle
  1514. right
  1515. rigid
  1516. ring
  1517. riot
  1518. ripple
  1519. risk
  1520. ritual
  1521. rival
  1522. river
  1523. road
  1524. roast
  1525. robot
  1526. robust
  1527. rocket
  1528. romance
  1529. roof
  1530. rookie
  1531. room
  1532. rose
  1533. rotate
  1534. rough
  1535. round
  1536. route
  1537. royal
  1538. rubber
  1539. rude
  1540. rug
  1541. rule
  1542. run
  1543. runway
  1544. rural
  1545. sad
  1546. saddle
  1547. sadness
  1548. safe
  1549. sail
  1550. salad
  1551. salmon
  1552. salon
  1553. salt
  1554. salute
  1555. same
  1556. sample
  1557. sand
  1558. satisfy
  1559. satoshi
  1560. sauce
  1561. sausage
  1562. save
  1563. say
  1564. scale
  1565. scan
  1566. scare
  1567. scatter
  1568. scene
  1569. scheme
  1570. school
  1571. science
  1572. scissors
  1573. scorpion
  1574. scout
  1575. scrap
  1576. screen
  1577. script
  1578. scrub
  1579. sea
  1580. search
  1581. season
  1582. seat
  1583. second
  1584. secret
  1585. section
  1586. security
  1587. seed
  1588. seek
  1589. segment
  1590. select
  1591. sell
  1592. seminar
  1593. senior
  1594. sense
  1595. sentence
  1596. series
  1597. service
  1598. session
  1599. settle
  1600. setup
  1601. seven
  1602. shadow
  1603. shaft
  1604. shallow
  1605. share
  1606. shed
  1607. shell
  1608. sheriff
  1609. shield
  1610. shift
  1611. shine
  1612. ship
  1613. shiver
  1614. shock
  1615. shoe
  1616. shoot
  1617. shop
  1618. short
  1619. shoulder
  1620. shove
  1621. shrimp
  1622. shrug
  1623. shuffle
  1624. shy
  1625. sibling
  1626. sick
  1627. side
  1628. siege
  1629. sight
  1630. sign
  1631. silent
  1632. silk
  1633. silly
  1634. silver
  1635. similar
  1636. simple
  1637. since
  1638. sing
  1639. siren
  1640. sister
  1641. situate
  1642. six
  1643. size
  1644. skate
  1645. sketch
  1646. ski
  1647. skill
  1648. skin
  1649. skirt
  1650. skull
  1651. slab
  1652. slam
  1653. sleep
  1654. slender
  1655. slice
  1656. slide
  1657. slight
  1658. slim
  1659. slogan
  1660. slot
  1661. slow
  1662. slush
  1663. small
  1664. smart
  1665. smile
  1666. smoke
  1667. smooth
  1668. snack
  1669. snake
  1670. snap
  1671. sniff
  1672. snow
  1673. soap
  1674. soccer
  1675. social
  1676. sock
  1677. soda
  1678. soft
  1679. solar
  1680. soldier
  1681. solid
  1682. solution
  1683. solve
  1684. someone
  1685. song
  1686. soon
  1687. sorry
  1688. sort
  1689. soul
  1690. sound
  1691. soup
  1692. source
  1693. south
  1694. space
  1695. spare
  1696. spatial
  1697. spawn
  1698. speak
  1699. special
  1700. speed
  1701. spell
  1702. spend
  1703. sphere
  1704. spice
  1705. spider
  1706. spike
  1707. spin
  1708. spirit
  1709. split
  1710. spoil
  1711. sponsor
  1712. spoon
  1713. sport
  1714. spot
  1715. spray
  1716. spread
  1717. spring
  1718. spy
  1719. square
  1720. squeeze
  1721. squirrel
  1722. stable
  1723. stadium
  1724. staff
  1725. stage
  1726. stairs
  1727. stamp
  1728. stand
  1729. start
  1730. state
  1731. stay
  1732. steak
  1733. steel
  1734. stem
  1735. step
  1736. stereo
  1737. stick
  1738. still
  1739. sting
  1740. stock
  1741. stomach
  1742. stone
  1743. stool
  1744. story
  1745. stove
  1746. strategy
  1747. street
  1748. strike
  1749. strong
  1750. struggle
  1751. student
  1752. stuff
  1753. stumble
  1754. style
  1755. subject
  1756. submit
  1757. subway
  1758. success
  1759. such
  1760. sudden
  1761. suffer
  1762. sugar
  1763. suggest
  1764. suit
  1765. summer
  1766. sun
  1767. sunny
  1768. sunset
  1769. super
  1770. supply
  1771. supreme
  1772. sure
  1773. surface
  1774. surge
  1775. surprise
  1776. surround
  1777. survey
  1778. suspect
  1779. sustain
  1780. swallow
  1781. swamp
  1782. swap
  1783. swarm
  1784. swear
  1785. sweet
  1786. swift
  1787. swim
  1788. swing
  1789. switch
  1790. sword
  1791. symbol
  1792. symptom
  1793. syrup
  1794. system
  1795. table
  1796. tackle
  1797. tag
  1798. tail
  1799. talent
  1800. talk
  1801. tank
  1802. tape
  1803. target
  1804. task
  1805. taste
  1806. tattoo
  1807. taxi
  1808. teach
  1809. team
  1810. tell
  1811. ten
  1812. tenant
  1813. tennis
  1814. tent
  1815. term
  1816. test
  1817. text
  1818. thank
  1819. that
  1820. theme
  1821. then
  1822. theory
  1823. there
  1824. they
  1825. thing
  1826. this
  1827. thought
  1828. three
  1829. thrive
  1830. throw
  1831. thumb
  1832. thunder
  1833. ticket
  1834. tide
  1835. tiger
  1836. tilt
  1837. timber
  1838. time
  1839. tiny
  1840. tip
  1841. tired
  1842. tissue
  1843. title
  1844. toast
  1845. tobacco
  1846. today
  1847. toddler
  1848. toe
  1849. together
  1850. toilet
  1851. token
  1852. tomato
  1853. tomorrow
  1854. tone
  1855. tongue
  1856. tonight
  1857. tool
  1858. tooth
  1859. top
  1860. topic
  1861. topple
  1862. torch
  1863. tornado
  1864. tortoise
  1865. toss
  1866. total
  1867. tourist
  1868. toward
  1869. tower
  1870. town
  1871. toy
  1872. track
  1873. trade
  1874. traffic
  1875. tragic
  1876. train
  1877. transfer
  1878. trap
  1879. trash
  1880. travel
  1881. tray
  1882. treat
  1883. tree
  1884. trend
  1885. trial
  1886. tribe
  1887. trick
  1888. trigger
  1889. trim
  1890. trip
  1891. trophy
  1892. trouble
  1893. truck
  1894. true
  1895. truly
  1896. trumpet
  1897. trust
  1898. truth
  1899. try
  1900. tube
  1901. tuition
  1902. tumble
  1903. tuna
  1904. tunnel
  1905. turkey
  1906. turn
  1907. turtle
  1908. twelve
  1909. twenty
  1910. twice
  1911. twin
  1912. twist
  1913. two
  1914. type
  1915. typical
  1916. ugly
  1917. umbrella
  1918. unable
  1919. unaware
  1920. uncle
  1921. uncover
  1922. under
  1923. undo
  1924. unfair
  1925. unfold
  1926. unhappy
  1927. uniform
  1928. unique
  1929. unit
  1930. universe
  1931. unknown
  1932. unlock
  1933. until
  1934. unusual
  1935. unveil
  1936. update
  1937. upgrade
  1938. uphold
  1939. upon
  1940. upper
  1941. upset
  1942. urban
  1943. urge
  1944. usage
  1945. use
  1946. used
  1947. useful
  1948. useless
  1949. usual
  1950. utility
  1951. vacant
  1952. vacuum
  1953. vague
  1954. valid
  1955. valley
  1956. valve
  1957. van
  1958. vanish
  1959. vapor
  1960. various
  1961. vast
  1962. vault
  1963. vehicle
  1964. velvet
  1965. vendor
  1966. venture
  1967. venue
  1968. verb
  1969. verify
  1970. version
  1971. very
  1972. vessel
  1973. veteran
  1974. viable
  1975. vibrant
  1976. vicious
  1977. victory
  1978. video
  1979. view
  1980. village
  1981. vintage
  1982. violin
  1983. virtual
  1984. virus
  1985. visa
  1986. visit
  1987. visual
  1988. vital
  1989. vivid
  1990. vocal
  1991. voice
  1992. void
  1993. volcano
  1994. volume
  1995. vote
  1996. voyage
  1997. wage
  1998. wagon
  1999. wait
  2000. walk
  2001. wall
  2002. walnut
  2003. want
  2004. warfare
  2005. warm
  2006. warrior
  2007. wash
  2008. wasp
  2009. waste
  2010. water
  2011. wave
  2012. way
  2013. wealth
  2014. weapon
  2015. wear
  2016. weasel
  2017. weather
  2018. web
  2019. wedding
  2020. weekend
  2021. weird
  2022. welcome
  2023. west
  2024. wet
  2025. whale
  2026. what
  2027. wheat
  2028. wheel
  2029. when
  2030. where
  2031. whip
  2032. whisper
  2033. wide
  2034. width
  2035. wife
  2036. wild
  2037. will
  2038. win
  2039. window
  2040. wine
  2041. wing
  2042. wink
  2043. winner
  2044. winter
  2045. wire
  2046. wisdom
  2047. wise
  2048. wish
  2049. witness
  2050. wolf
  2051. woman
  2052. wonder
  2053. wood
  2054. wool
  2055. word
  2056. work
  2057. world
  2058. worry
  2059. worth
  2060. wrap
  2061. wreck
  2062. wrestle
  2063. wrist
  2064. write
  2065. wrong
  2066. yard
  2067. year
  2068. yellow
  2069. you
  2070. young
  2071. youth
  2072. zebra
  2073. zero
  2074. zone
  2075. zoo
  2076. """.split())
  2077. mn_base = 2048
  2078. wl_chksums = { 'bip39': 'f18b9a84' }
  2079. seedlen_map = { 'bip39': { 16:12, 24:18, 32:24 } }
  2080. seedlen_map_rev = { 'bip39': { 12:16, 18:24, 24:32 } }
  2081. # ENT CS MS
  2082. constants = {
  2083. '128': (4, 12),
  2084. '160': (5, 15),
  2085. '192': (6, 18),
  2086. '224': (7, 21),
  2087. '256': (8, 24),
  2088. }
  2089. digits = { 'bip39': words }
  2090. @classmethod
  2091. def nwords2seedlen(cls,nwords,in_bytes=False,in_hex=False):
  2092. for k,v in cls.constants.items():
  2093. if v[1] == nwords:
  2094. return int(k)//8 if in_bytes else int(k)//4 if in_hex else int(k)
  2095. raise MnemonicError('{!r}: invalid word length for BIP39 mnemonic'.format(nwords))
  2096. @classmethod
  2097. def seedlen2nwords(cls,seed_len,in_bytes=False,in_hex=False):
  2098. seed_bits = seed_len * 8 if in_bytes else seed_len * 4 if in_hex else seed_len
  2099. try:
  2100. return cls.constants[str(seed_bits)][1]
  2101. except:
  2102. raise ValueError('{!r}: invalid seed length for BIP39 mnemonic'.format(seed_bits))
  2103. @classmethod
  2104. def tohex(cls,words,wl_id,pad=None):
  2105. assert isinstance(words,(list,tuple)),'words must be list or tuple'
  2106. assert wl_id == 'bip39',"'wl_id' must be 'bip39'"
  2107. wl = cls.digits[wl_id]
  2108. for n,w in enumerate(words):
  2109. if w not in wl:
  2110. raise MnemonicError('word #{} is not in the BIP39 word list'.format(n+1))
  2111. res = ''.join(['{:011b}'.format(wl.index(w)) for w in words])
  2112. for k in cls.constants:
  2113. if len(words) == cls.constants[k][1]:
  2114. bitlen = int(k)
  2115. break
  2116. else:
  2117. raise MnemonicError('{}: invalid BIP39 seed phrase length'.format(len(words)))
  2118. if pad != None:
  2119. assert pad * 4 == bitlen, '{}: invalid pad length'.format(pad)
  2120. seed_bin = res[:bitlen]
  2121. chk_bin = res[bitlen:]
  2122. seed_hex = '{:0{w}x}'.format(int(seed_bin,2),w=bitlen//4)
  2123. seed_bytes = bytes.fromhex(seed_hex)
  2124. chk_len = cls.constants[str(bitlen)][0]
  2125. chk_hex_chk = sha256(seed_bytes).hexdigest()
  2126. chk_bin_chk = '{:0{w}b}'.format(int(chk_hex_chk,16),w=256)[:chk_len]
  2127. if chk_bin != chk_bin_chk:
  2128. raise MnemonicError('invalid BIP39 seed phrase checksum')
  2129. return seed_hex
  2130. @classmethod
  2131. def fromhex(cls,seed_hex,wl_id,pad=None,tostr=False):
  2132. assert is_hex_str(seed_hex),'seed data not a hexadecimal string'
  2133. assert wl_id == 'bip39',"'wl_id' must be 'bip39'"
  2134. assert tostr == False,"'tostr' must be False for 'bip39'"
  2135. wl = cls.digits[wl_id]
  2136. seed_bytes = bytes.fromhex(seed_hex)
  2137. bitlen = len(seed_bytes) * 8
  2138. assert str(bitlen) in cls.constants,'{}: invalid seed bit length'.format(bitlen)
  2139. chk_len,mn_len = cls.constants[str(bitlen)]
  2140. if pad != None:
  2141. assert mn_len == pad, '{}: invalid pad length'.format(pad)
  2142. chk_hex = sha256(seed_bytes).hexdigest()
  2143. seed_bin = '{:0{w}b}'.format(int(seed_hex,16),w=bitlen)
  2144. chk_bin = '{:0{w}b}'.format(int(chk_hex,16),w=256)[:chk_len]
  2145. res = seed_bin + chk_bin
  2146. return tuple(wl[int(res[i*11:(i+1)*11],2)] for i in range(mn_len))
  2147. @classmethod
  2148. def init_mn(cls,mn_id):
  2149. assert mn_id == 'bip39', "'mn_id' must be 'bip39'"