xmrwallet.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. help.xmrwallet: xmrwallet help notes for MMGen suite
  12. """
  13. def help(proto,cfg):
  14. return """
  15. Many operations take an optional ‘wallets’ argument: one or more address
  16. indexes (expressed as a comma-separated list and/or hyphenated range) in
  17. the default or specified key-address file, each corresponding to a Monero
  18. wallet with the same index. If the argument is omitted, all wallets are
  19. operated upon.
  20. All operations except for ‘relay’ require a running Monero daemon (monerod).
  21. Unless --daemon is specified, the daemon is assumed to be listening on
  22. localhost at the default RPC port.
  23. If --tx-relay-daemon is specified, the monerod at HOST:PORT will be used to
  24. relay any created transactions. PROXY_HOST:PROXY_PORT, if specified, may
  25. point to a SOCKS proxy, in which case HOST may be a Tor onion address.
  26. All communications use the RPC protocol via SSL (HTTPS) or Tor. RPC over
  27. plain HTTP is not supported.
  28. SUPPORTED OPERATIONS
  29. create - create wallet for all or specified addresses in key-address file
  30. sync - sync wallet for all or specified addresses in key-address file
  31. list - same as ‘sync’, but also list detailed address info for accounts
  32. label - set a label for an address
  33. new - create a new account in a wallet, or a new address in an account
  34. transfer - transfer specified XMR amount from specified wallet:account to
  35. specified address
  36. sweep - sweep funds in specified wallet:account to new address in same
  37. account or new account in another wallet
  38. relay - relay a transaction from a transaction file created using ‘sweep’
  39. or ‘transfer’ with the --no-relay option
  40. submit - submit an autosigned transaction to a wallet and the network
  41. txview - view a transaction file or files created using ‘sweep’ or
  42. ‘transfer’ with the --no-relay option
  43. dump - produce JSON dumps of wallet metadata (accounts, addresses and
  44. labels) for a list or range of wallets
  45. restore - same as ‘create’, but additionally restore wallet metadata from
  46. the corresponding JSON dump files created with ‘dump’
  47. export-outputs - export outputs of watch-only wallets for later import
  48. into their corresponding offline wallets
  49. import-key-images - import key images signed by offline wallets into their
  50. corresponding watch-only wallets
  51. ‘LABEL’ OPERATION NOTES
  52. This operation takes a LABEL_SPEC arg with the following format:
  53. WALLET:ACCOUNT:ADDRESS,"label text"
  54. where WALLET is a wallet number, ACCOUNT an account index, and ADDRESS an
  55. address index.
  56. ‘NEW’ OPERATION NOTES
  57. This operation takes a NEW_ADDRESS_SPEC arg with the following format:
  58. WALLET[:ACCOUNT][,"label text"]
  59. where WALLET is a wallet number and ACCOUNT an account index. If ACCOUNT is
  60. omitted, a new account will be created in the wallet, otherwise a new address
  61. will be created in the specified account. An optional label text may be
  62. appended to the spec following a comma.
  63. ‘TRANSFER’ OPERATION NOTES
  64. The transfer operation takes a TRANSFER_SPEC arg with the following format:
  65. SOURCE:ACCOUNT:ADDRESS,AMOUNT
  66. where SOURCE is a wallet number; ACCOUNT the source account index; and ADDRESS
  67. and AMOUNT the destination Monero address and XMR amount, respectively.
  68. ‘SWEEP’ OPERATION NOTES
  69. The sweep operation takes a SWEEP_SPEC arg with the following format:
  70. SOURCE:ACCOUNT[,DEST]
  71. where SOURCE and DEST are wallet numbers and ACCOUNT an account index.
  72. If DEST is omitted, a new address will be created in ACCOUNT of SOURCE and
  73. all funds from ACCOUNT of SOURCE will be swept into it.
  74. If DEST is included, all funds from ACCOUNT of SOURCE will be swept into a
  75. newly created account in DEST, or the last existing account, if requested
  76. by the user.
  77. The user is prompted before addresses are created or funds are transferred.
  78. Note that multiple sweep operations may be required to sweep all the funds
  79. in an account.
  80. ‘SUBMIT’ AND ‘RELAY’ OPERATION NOTES
  81. By default, transactions are relayed to a monerod running on localhost at the
  82. default RPC port. To relay transactions to a remote or non-default monerod
  83. via optional SOCKS proxy, use the --tx-relay-daemon option described above.
  84. When ‘submit’ is used with --autosign, the transaction filename must be
  85. omitted.
  86. ‘DUMP’ AND ‘RESTORE’ OPERATION NOTES
  87. These commands produce and read JSON wallet dump files with the same
  88. filenames as their source wallets, plus a .dump extension.
  89. It’s highly advisable to make regular dumps of your Monero wallets and back
  90. up the dump files, which can be used to easily regenerate the wallets using
  91. the ‘restore’ operation, should the need arise. For watch-only autosigning
  92. wallets, creating the dumps is as easy as executing ‘mmgen-xmrwallet
  93. --autosign dump’ from your wallet directory. The dump files are formatted
  94. JSON and thus suitable for efficient incremental backup using git.
  95. SECURITY WARNING
  96. If you have an existing MMGen Monero hot wallet setup, you’re strongly
  97. advised to migrate to offline autosigning to avoid further exposing your
  98. private keys on your network-connected machine. See OFFLINE AUTOSIGNING
  99. and ‘Replacing Existing Hot Wallets with Watch-Only Wallets’ below.
  100. EXAMPLES
  101. Note that the transacting examples in this section apply for a hot wallet
  102. setup, which is now deprecated. See OFFLINE AUTOSIGNING below.
  103. Generate an XMR key-address file with 5 addresses from your default wallet:
  104. $ mmgen-keygen --coin=xmr 1-5
  105. Create 3 Monero wallets from the key-address file:
  106. $ mmgen-xmrwallet create *.akeys.mmenc 1-3
  107. After updating the blockchain, sync wallets 1 and 2:
  108. $ mmgen-xmrwallet sync *.akeys.mmenc 1,2
  109. Sweep all funds from account #0 of wallet 1 to a new address:
  110. $ mmgen-xmrwallet sweep *.akeys.mmenc 1:0
  111. Same as above, but use a TX relay on the Tor network:
  112. $ mmgen-xmrwallet --tx-relay-daemon=abcdefghijklmnop.onion:127.0.0.1:9050 sweep *.akeys.mmenc 1:0
  113. Sweep all funds from account #0 of wallet 1 to wallet 2:
  114. $ mmgen-xmrwallet sweep *.akeys.mmenc 1:0,2
  115. Send 0.1 XMR from account #0 of wallet 2 to an external address:
  116. $ mmgen-xmrwallet transfer *.akeys.mmenc 2:0:<monero address>,0.1
  117. Sweep all funds from account #0 of wallet 2 to a new address, saving the
  118. transaction to a file:
  119. $ mmgen-xmrwallet --no-relay sweep *.akeys.mmenc 2:0
  120. Relay the created sweep transaction via a host on the Tor network:
  121. $ mmgen-xmrwallet --tx-relay-daemon=abcdefghijklmnop.onion:127.0.0.1:9050 relay *XMR*.sigtx
  122. Create a new account in wallet 2:
  123. $ mmgen-xmrwallet new *.akeys.mmenc 2
  124. Create a new address in account 1 of wallet 2, with label:
  125. $ mmgen-xmrwallet new *.akeys.mmenc 2:1,"from ABC exchange"
  126. View all the XMR transaction files in the current directory, sending output
  127. to pager:
  128. $ mmgen-xmrwallet --pager txview *XMR*.sigtx
  129. OFFLINE AUTOSIGNING
  130. Tutorial
  131. Master the basic concepts of the MMGen wallet system and the processes of
  132. wallet creation, conversion and backup described in the Getting Started
  133. guide. Optionally create a default MMGen wallet on your offline machine
  134. using ‘mmgen-walletgen’. If you choose not to do this, you’ll be prompted
  135. for a seed phrase at the start of each signing session.
  136. Familiarize yourself with the autosigning setup process as described in
  137. ‘mmgen-autosign --help’. Prepare your removable device and set up the
  138. mountpoints on your offline and online machines according to the instructions
  139. therein. Install ‘monero-wallet-rpc’ on your offline machine and the Monero
  140. CLI wallet and daemon binaries on your online machine.
  141. On the offline machine, insert the removable device and execute:
  142. $ mmgen-autosign --xmrwallets=1-2,7 setup
  143. This will create 3 Monero signing wallets with indexes 1, 2 and 7 and primary
  144. addresses matching your seed’s Monero addresses with the same indexes. (Note
  145. that these particular indexes are arbitrary, for purposes of illustration
  146. only. Feel free to choose your own list and/or range – or perhaps just the
  147. number ‘1’ if one wallet is all you require).
  148. These signing wallets are written to volatile memory and exist only for the
  149. duration of the signing session, just like the temporary MMGen signing wallet
  150. they’re generated from (see ‘mmgen-autosign --help’).
  151. A viewkey-address file for the 3 addresses will also be written to the
  152. removable device. The data in this file will be used to create and access
  153. watch-only wallets on your online machine that match the signing wallets
  154. you’ve just created.
  155. When the setup operation completes, extract the removable device and restart
  156. the autosign script in wait mode:
  157. $ mmgen-autosign --coins=xmr --stealth-led wait
  158. Your only further physical interaction with the offline signing machine now
  159. (assuming everything goes as planned) will be inserting and extracting the
  160. removable device on it. And this is the whole point of autosigning: to make
  161. cold signing as convenient as possible, almost like transacting with a hot
  162. wallet.
  163. If your signing machine is an SoC with MMGen LED support (see ‘mmgen-autosign
  164. --help’), a quickly flashing LED will indicate that signing is in progress, a
  165. slowly flashing LED an error condition, and no LED that the program is idle
  166. and waiting for device insertion.
  167. On your online machine, start monerod, wait until it’s fully synced with the
  168. network, insert the removable device and execute:
  169. $ mmgen-xmrwallet --autosign --restore-height=current create
  170. This will create 3 watch-only wallets matching your 3 offline signing wallets
  171. and write them to the current directory (an alternate wallet directory may be
  172. specified with the --wallet-dir option).
  173. Note that --restore-height=current is required to prevent a time-consuming
  174. full sync of the wallets from the Genesis block, a meaningless waste of time
  175. in this case since the wallets contain no funds.
  176. Also make note of the --autosign option, a requirement for ALL autosigning
  177. operations with ‘mmgen-xmrwallet’.
  178. Now list your newly created wallets:
  179. $ mmgen-xmrwallet --autosign list
  180. Note that you can also use the ‘sync’ operation here, which produces more
  181. abbreviated output than ‘list’.
  182. Send some XMR (preferably a tiny amount) to the primary address of wallet #7.
  183. Once the transaction has confirmed, invoke ‘sync’ or ‘list’ again to verify
  184. the funds have arrived.
  185. Since offline wallet #7 has no knowledge of the funds received by its online
  186. counterpart, we need to update its state. Export the outputs of watch-only
  187. wallet #7 as follows:
  188. $ mmgen-xmrwallet --autosign export-outputs 7
  189. The outputs are now saved to the removable device and will be imported into
  190. offline wallet #7 when you sign your first transaction.
  191. Now you’re ready to begin transacting. Let’s start by sweeping your funds in
  192. wallet #7’s primary address (account 0) to a new address in the same account:
  193. $ mmgen-xmrwallet --autosign sweep 7:0
  194. This operation creates an unsigned sweep transaction and saves it to the
  195. removable device.
  196. Now extract the removable device and insert it on the offline machine. Wait
  197. for the quick LED flashing to stop (or the blue ‘safe to extract’ message, in
  198. the absence of LED support), signalling that signing is complete.
  199. Note that the offline wallet has performed two operations in one go here:
  200. an import of wallet outputs from the previous step and the signing of your
  201. just-created sweep transaction.
  202. Extract the removable device, insert it on your online machine and submit the
  203. signed sweep transaction to the watch-only wallet, which will broadcast it to
  204. the network:
  205. $ mmgen-xmrwallet --autosign submit
  206. Note that you may also relay the transaction to a remote daemon, optionally
  207. via a Tor proxy, using the --tx-relay-daemon option documented above.
  208. Once your transaction has confirmed, invoke ‘list’ or ‘sync’ to view your
  209. wallets’ balances.
  210. Congratulations, you’ve performed your first autosigned Monero transaction!
  211. For other examples, consult the EXAMPLES section above, noting the following
  212. differences that apply to autosigning:
  213. 1) The --autosign option must always be included.
  214. 2) The key-address file argument must always be omitted.
  215. 3) The ‘relay’ operation is replaced by ‘submit’, with TX filename omitted.
  216. 4) Always remember to sign your transactions after a ‘sweep’ or ‘transfer’
  217. operation.
  218. 5) Always remember to export a wallet’s outputs when it has received funds
  219. from an outside source.
  220. Exporting Outputs
  221. Exporting outputs from a wallet is generally required only in two cases:
  222. a) after the wallet has received funds from an outside source or another
  223. wallet; and
  224. c) at the start of each signing session (after ‘mmgen-autosign setup’).
  225. However, sometimes things go wrong and an offline wallet may be unable to
  226. sign a transaction due to missing outputs. In this case, you may export all
  227. outputs from its corresponding watch-only wallet with the following command:
  228. $ mmgen-xmrwallet --autosign --export-all export-outputs <wallet index>
  229. Then reinsert the removable device on the offline machine to redo the
  230. signing operation, which should now succeed.
  231. At the start of each new signing session, you must export ALL outputs from
  232. ALL wallets you intend to transact with:
  233. $ mmgen-xmrwallet --autosign --export-all export-outputs [wallet indexes]
  234. This is necessary because the signing wallets have just been created and
  235. therefore know nothing about the state of their watch-only counterparts.
  236. Replacing Existing Hot Wallets with Watch-Only Wallets
  237. If you have an existing MMGen Monero hot wallet setup, you can migrate to
  238. offline transaction signing by ‘cloning’ your existing hot wallets as
  239. watch-only ones via the ‘dump’ and ‘restore’ operations described below.
  240. For additional security, it’s also wise to create new watch-only wallets that
  241. have never had keys exposed on an online machine and gradually transfer all
  242. funds from your ‘cloned’ wallets to them. The creation of new wallets is
  243. explained in the Tutorial above.
  244. Start the cloning process by making dump files of your hot wallets’ metadata
  245. (accounts, subaddresses and labels). ‘cd’ to the wallet directory (or use
  246. --wallet-dir) and execute:
  247. $ mmgen-xmrwallet dump /path/to/key-address-file.akeys{.mmenc}
  248. If you’ve been transacting with the wallets, you know where their key-address
  249. file is along with its encryption password, if any. Supply an additional
  250. index range and/or list at the end of the command line if the key-address
  251. file contains more wallets than exist on disk or there are wallets you wish
  252. to ignore.
  253. Do a directory listing to verify that the dump files are present alongside
  254. their source wallet files ending with ‘MoneroWallet’. Then execute:
  255. $ mmgen-xmrwallet --watch-only restore /path/to/key-address-file.akeys{.mmenc}
  256. This will create watch-only wallets that “mirror” the old hot wallets and
  257. populate them with the metadata saved in the dump files.
  258. Note that watch-only wallet filenames end with ‘MoneroWatchOnlyWallet’. Your
  259. old hot wallets will be ignored from here on. Eventually, you’ll want to
  260. destroy them.
  261. Your new wallets must now be synced with the blockchain. Begin by starting
  262. monerod and synchronizing with the network.
  263. Mount ‘/mnt/mmgen_autosign’ and locate the file in the ‘xmr’ directory with
  264. the .vkeys extension, which contains the passwords you’ll need to log into
  265. the wallets. This is a plain text file viewable with ‘cat’, ‘less’ or your
  266. favorite text editor.
  267. Then log into each watch-only wallet in turn as follows:
  268. $ monero-wallet-cli --wallet <wallet filename>
  269. Upon login, each wallet will begin syncing, a process which can take more
  270. than an hour depending on your hardware. Note, however, that the process
  271. is interruptible: you may exit ‘monero-wallet-cli’ at any point, log back
  272. in again and resume where you left off.
  273. Once your watch-only wallets are synced, you need to export their outputs:
  274. $ mmgen-xmrwallet --autosign export-outputs
  275. Now insert the removable device on the offline machine and wait until the LED
  276. stops flashing (or ‘safe to extract’). The wallet outputs are now imported
  277. into the signing wallets and corresponding signed key images have been
  278. written to the removable device.
  279. Insert the removable device on your online machine and import the key images
  280. into your watch-only wallets:
  281. $ mmgen-xmrwallet --autosign import-key-images
  282. Congratulations, your watch-only wallets are now complete and you may begin
  283. transacting! First perform a ‘sync’ or ‘list’ to ensure that your balances
  284. are correct. Then you might try sweeping some funds as described in the
  285. Tutorial above.
  286. Once you’ve gained proficiency with the autosigning process and feel ready
  287. to delete your old hot wallets, make sure to do so securely using ‘shred’,
  288. ‘wipe’ or some other secure deletion utility.
  289. """.strip()