xmrwallet.py 19 KB

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