bip39.py 17 KB

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