xmrwallet.py 17 KB

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