2017-09-21 17:24:51 +02:00
|
|
|
|
2013-06-21 14:44:37 +02:00
|
|
|
import time
|
|
|
|
import hashlib
|
2017-09-21 17:24:51 +02:00
|
|
|
from binascii import hexlify
|
2013-06-21 21:44:28 +02:00
|
|
|
from pyelliptic import arithmetic
|
2017-09-21 17:24:51 +02:00
|
|
|
from pyelliptic.openssl import OpenSSL
|
2013-06-24 21:51:01 +02:00
|
|
|
import tr
|
2017-02-08 13:41:56 +01:00
|
|
|
import queues
|
2017-01-14 23:20:15 +01:00
|
|
|
import state
|
2017-09-21 17:24:51 +02:00
|
|
|
import shared
|
|
|
|
import defaults
|
|
|
|
import highlevelcrypto
|
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
from debug import logger
|
|
|
|
from addresses import decodeAddress, encodeAddress, encodeVarint
|
2019-01-31 16:42:22 +01:00
|
|
|
from fallback import RIPEMD160Hash
|
2017-09-21 17:24:51 +02:00
|
|
|
from helper_threading import StoppableThread
|
|
|
|
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2019-08-01 13:37:26 +02:00
|
|
|
class addressGenerator(StoppableThread):
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2019-08-01 13:37:26 +02:00
|
|
|
name = "addressGenerator"
|
2017-09-21 17:24:51 +02:00
|
|
|
|
2015-11-24 01:55:17 +01:00
|
|
|
def stopThread(self):
|
|
|
|
try:
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.addressGeneratorQueue.put(("stopThread", "data"))
|
2015-11-24 01:55:17 +01:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
super(addressGenerator, self).stopThread()
|
2013-06-21 14:44:37 +02:00
|
|
|
|
|
|
|
def run(self):
|
2019-05-09 14:48:29 +02:00
|
|
|
|
2017-01-14 23:20:15 +01:00
|
|
|
while state.shutdown == 0:
|
2017-02-08 13:41:56 +01:00
|
|
|
queueValue = queues.addressGeneratorQueue.get()
|
2013-06-21 14:44:37 +02:00
|
|
|
nonceTrialsPerByte = 0
|
|
|
|
payloadLengthExtraBytes = 0
|
2016-10-28 22:07:16 +02:00
|
|
|
live = True
|
2013-06-26 17:55:33 +02:00
|
|
|
if queueValue[0] == 'createChan':
|
2017-09-21 17:24:51 +02:00
|
|
|
command, addressVersionNumber, streamNumber, label, \
|
|
|
|
deterministicPassphrase, live = queueValue
|
2013-06-26 17:55:33 +02:00
|
|
|
eighteenByteRipe = False
|
|
|
|
numberOfAddressesToMake = 1
|
2013-09-18 06:04:01 +02:00
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = 1
|
2013-06-26 17:55:33 +02:00
|
|
|
elif queueValue[0] == 'joinChan':
|
2017-09-21 17:24:51 +02:00
|
|
|
command, chanAddress, label, deterministicPassphrase, \
|
|
|
|
live = queueValue
|
2013-06-26 17:55:33 +02:00
|
|
|
eighteenByteRipe = False
|
2013-07-22 07:10:22 +02:00
|
|
|
addressVersionNumber = decodeAddress(chanAddress)[1]
|
|
|
|
streamNumber = decodeAddress(chanAddress)[2]
|
2013-06-26 17:55:33 +02:00
|
|
|
numberOfAddressesToMake = 1
|
2013-09-18 06:04:01 +02:00
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = 1
|
2013-06-26 17:55:33 +02:00
|
|
|
elif len(queueValue) == 7:
|
2017-09-21 17:24:51 +02:00
|
|
|
command, addressVersionNumber, streamNumber, label, \
|
|
|
|
numberOfAddressesToMake, deterministicPassphrase, \
|
|
|
|
eighteenByteRipe = queueValue
|
2013-09-21 19:30:46 +02:00
|
|
|
try:
|
2017-09-21 17:24:51 +02:00
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = \
|
|
|
|
BMConfigParser().getint(
|
|
|
|
'bitmessagesettings',
|
|
|
|
'numberofnullbytesonaddress'
|
|
|
|
)
|
2013-09-21 19:30:46 +02:00
|
|
|
except:
|
|
|
|
if eighteenByteRipe:
|
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = 2
|
|
|
|
else:
|
2017-09-21 17:24:51 +02:00
|
|
|
# the default
|
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = 1
|
2013-06-21 14:44:37 +02:00
|
|
|
elif len(queueValue) == 9:
|
2017-09-21 17:24:51 +02:00
|
|
|
command, addressVersionNumber, streamNumber, label, \
|
|
|
|
numberOfAddressesToMake, deterministicPassphrase, \
|
|
|
|
eighteenByteRipe, nonceTrialsPerByte, \
|
|
|
|
payloadLengthExtraBytes = queueValue
|
2013-09-21 19:30:46 +02:00
|
|
|
try:
|
2017-09-21 17:24:51 +02:00
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = \
|
|
|
|
BMConfigParser().getint(
|
|
|
|
'bitmessagesettings',
|
|
|
|
'numberofnullbytesonaddress'
|
|
|
|
)
|
2013-09-21 19:30:46 +02:00
|
|
|
except:
|
|
|
|
if eighteenByteRipe:
|
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = 2
|
|
|
|
else:
|
2017-09-21 17:24:51 +02:00
|
|
|
# the default
|
|
|
|
numberOfNullBytesDemandedOnFrontOfRipeHash = 1
|
2015-11-24 01:55:17 +01:00
|
|
|
elif queueValue[0] == 'stopThread':
|
|
|
|
break
|
2013-06-21 14:44:37 +02:00
|
|
|
else:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.error(
|
|
|
|
'Programming error: A structure with the wrong number'
|
|
|
|
' of values was passed into the addressGeneratorQueue.'
|
|
|
|
' Here is the queueValue: %r\n', queueValue)
|
2013-09-13 06:27:34 +02:00
|
|
|
if addressVersionNumber < 3 or addressVersionNumber > 4:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.error(
|
|
|
|
'Program error: For some reason the address generator'
|
|
|
|
' queue has been given a request to create at least'
|
|
|
|
' one version %s address which it cannot do.\n',
|
|
|
|
addressVersionNumber)
|
2013-06-21 14:44:37 +02:00
|
|
|
if nonceTrialsPerByte == 0:
|
2017-01-11 14:27:19 +01:00
|
|
|
nonceTrialsPerByte = BMConfigParser().getint(
|
2013-06-21 14:44:37 +02:00
|
|
|
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
2017-09-21 17:24:51 +02:00
|
|
|
if nonceTrialsPerByte < \
|
|
|
|
defaults.networkDefaultProofOfWorkNonceTrialsPerByte:
|
|
|
|
nonceTrialsPerByte = \
|
|
|
|
defaults.networkDefaultProofOfWorkNonceTrialsPerByte
|
2013-06-21 14:44:37 +02:00
|
|
|
if payloadLengthExtraBytes == 0:
|
2017-01-11 14:27:19 +01:00
|
|
|
payloadLengthExtraBytes = BMConfigParser().getint(
|
2013-06-21 14:44:37 +02:00
|
|
|
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
2017-09-21 17:24:51 +02:00
|
|
|
if payloadLengthExtraBytes < \
|
|
|
|
defaults.networkDefaultPayloadLengthExtraBytes:
|
|
|
|
payloadLengthExtraBytes = \
|
|
|
|
defaults.networkDefaultPayloadLengthExtraBytes
|
2013-09-13 06:27:34 +02:00
|
|
|
if command == 'createRandomAddress':
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.UISignalQueue.put((
|
2019-05-09 14:48:29 +02:00
|
|
|
'updateStatusBar'
|
2017-09-21 17:24:51 +02:00
|
|
|
))
|
|
|
|
# This next section is a little bit strange. We're going
|
|
|
|
# to generate keys over and over until we find one
|
|
|
|
# that starts with either \x00 or \x00\x00. Then when
|
|
|
|
# we pack them into a Bitmessage address, we won't store
|
|
|
|
# the \x00 or \x00\x00 bytes thus making the address shorter.
|
2013-09-13 06:27:34 +02:00
|
|
|
startTime = time.time()
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix = 0
|
|
|
|
potentialPrivSigningKey = OpenSSL.rand(32)
|
2017-09-21 17:24:51 +02:00
|
|
|
potentialPubSigningKey = highlevelcrypto.pointMult(
|
|
|
|
potentialPrivSigningKey)
|
2013-09-13 06:27:34 +02:00
|
|
|
while True:
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix += 1
|
|
|
|
potentialPrivEncryptionKey = OpenSSL.rand(32)
|
2014-05-21 12:06:20 +02:00
|
|
|
potentialPubEncryptionKey = highlevelcrypto.pointMult(
|
2013-09-13 06:27:34 +02:00
|
|
|
potentialPrivEncryptionKey)
|
|
|
|
sha = hashlib.new('sha512')
|
|
|
|
sha.update(
|
|
|
|
potentialPubSigningKey + potentialPubEncryptionKey)
|
2019-01-31 16:42:22 +01:00
|
|
|
ripe = RIPEMD160Hash(sha.digest()).digest()
|
|
|
|
if (
|
|
|
|
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] ==
|
|
|
|
'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
|
|
|
|
):
|
2013-09-18 06:04:01 +02:00
|
|
|
break
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.info(
|
2019-01-31 16:42:22 +01:00
|
|
|
'Generated address with ripe digest: %s', hexlify(ripe))
|
2015-01-08 23:11:30 +01:00
|
|
|
try:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.info(
|
|
|
|
'Address generator calculated %s addresses at %s'
|
|
|
|
' addresses per second before finding one with'
|
|
|
|
' the correct ripe-prefix.',
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix,
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix
|
|
|
|
/ (time.time() - startTime))
|
2015-01-08 23:11:30 +01:00
|
|
|
except ZeroDivisionError:
|
2017-09-21 17:24:51 +02:00
|
|
|
# The user must have a pretty fast computer.
|
|
|
|
# time.time() - startTime equaled zero.
|
2015-01-08 23:11:30 +01:00
|
|
|
pass
|
2017-09-21 17:24:51 +02:00
|
|
|
address = encodeAddress(
|
2019-01-31 16:42:22 +01:00
|
|
|
addressVersionNumber, streamNumber, ripe)
|
2013-09-13 06:27:34 +02:00
|
|
|
|
2017-09-21 17:24:51 +02:00
|
|
|
# An excellent way for us to store our keys
|
|
|
|
# is in Wallet Import Format. Let us convert now.
|
2013-09-13 06:27:34 +02:00
|
|
|
# https://en.bitcoin.it/wiki/Wallet_import_format
|
|
|
|
privSigningKey = '\x80' + potentialPrivSigningKey
|
|
|
|
checksum = hashlib.sha256(hashlib.sha256(
|
|
|
|
privSigningKey).digest()).digest()[0:4]
|
|
|
|
privSigningKeyWIF = arithmetic.changebase(
|
|
|
|
privSigningKey + checksum, 256, 58)
|
|
|
|
|
|
|
|
privEncryptionKey = '\x80' + potentialPrivEncryptionKey
|
|
|
|
checksum = hashlib.sha256(hashlib.sha256(
|
|
|
|
privEncryptionKey).digest()).digest()[0:4]
|
|
|
|
privEncryptionKeyWIF = arithmetic.changebase(
|
|
|
|
privEncryptionKey + checksum, 256, 58)
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().add_section(address)
|
|
|
|
BMConfigParser().set(address, 'label', label)
|
|
|
|
BMConfigParser().set(address, 'enabled', 'true')
|
|
|
|
BMConfigParser().set(address, 'decoy', 'false')
|
|
|
|
BMConfigParser().set(address, 'noncetrialsperbyte', str(
|
2013-09-13 06:27:34 +02:00
|
|
|
nonceTrialsPerByte))
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(address, 'payloadlengthextrabytes', str(
|
2013-09-13 06:27:34 +02:00
|
|
|
payloadLengthExtraBytes))
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(
|
2017-09-21 17:24:51 +02:00
|
|
|
address, 'privsigningkey', privSigningKeyWIF)
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(
|
2017-09-21 17:24:51 +02:00
|
|
|
address, 'privencryptionkey', privEncryptionKeyWIF)
|
2017-01-15 10:50:02 +01:00
|
|
|
BMConfigParser().save()
|
2013-09-13 06:27:34 +02:00
|
|
|
|
|
|
|
# The API and the join and create Chan functionality
|
|
|
|
# both need information back from the address generator.
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.apiAddressGeneratorReturnQueue.put(address)
|
2013-09-13 06:27:34 +02:00
|
|
|
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.UISignalQueue.put((
|
2019-05-09 14:48:29 +02:00
|
|
|
'updateStatusBar'
|
2017-09-21 17:24:51 +02:00
|
|
|
))
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.UISignalQueue.put(('writeNewAddressToTable', (
|
2013-09-13 06:27:34 +02:00
|
|
|
label, address, streamNumber)))
|
|
|
|
shared.reloadMyAddressHashes()
|
|
|
|
if addressVersionNumber == 3:
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.workerQueue.put((
|
2019-01-31 16:42:22 +01:00
|
|
|
'sendOutOrStoreMyV3Pubkey', ripe))
|
2013-09-13 06:27:34 +02:00
|
|
|
elif addressVersionNumber == 4:
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.workerQueue.put((
|
2013-09-13 06:27:34 +02:00
|
|
|
'sendOutOrStoreMyV4Pubkey', address))
|
|
|
|
|
2017-09-21 17:24:51 +02:00
|
|
|
elif command == 'createDeterministicAddresses' \
|
|
|
|
or command == 'getDeterministicAddress' \
|
|
|
|
or command == 'createChan' or command == 'joinChan':
|
2013-09-13 06:27:34 +02:00
|
|
|
if len(deterministicPassphrase) == 0:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.warning(
|
|
|
|
'You are creating deterministic'
|
|
|
|
' address(es) using a blank passphrase.'
|
|
|
|
' Bitmessage will do it but it is rather stupid.')
|
2013-09-13 06:27:34 +02:00
|
|
|
if command == 'createDeterministicAddresses':
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.UISignalQueue.put((
|
2017-09-21 17:24:51 +02:00
|
|
|
'updateStatusBar',
|
|
|
|
tr._translate(
|
|
|
|
"MainWindow",
|
|
|
|
"Generating %1 new addresses."
|
|
|
|
).arg(str(numberOfAddressesToMake))
|
|
|
|
))
|
2013-09-13 06:27:34 +02:00
|
|
|
signingKeyNonce = 0
|
|
|
|
encryptionKeyNonce = 1
|
2017-09-21 17:24:51 +02:00
|
|
|
# We fill out this list no matter what although we only
|
|
|
|
# need it if we end up passing the info to the API.
|
|
|
|
listOfNewAddressesToSendOutThroughTheAPI = []
|
2013-09-13 06:27:34 +02:00
|
|
|
|
2018-05-02 17:29:55 +02:00
|
|
|
for _ in range(numberOfAddressesToMake):
|
2017-09-21 17:24:51 +02:00
|
|
|
# This next section is a little bit strange. We're
|
|
|
|
# going to generate keys over and over until we find
|
|
|
|
# one that has a RIPEMD hash that starts with either
|
|
|
|
# \x00 or \x00\x00. Then when we pack them into a
|
|
|
|
# Bitmessage address, we won't store the \x00 or
|
2013-09-13 06:27:34 +02:00
|
|
|
# \x00\x00 bytes thus making the address shorter.
|
2013-06-21 14:44:37 +02:00
|
|
|
startTime = time.time()
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix = 0
|
|
|
|
while True:
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix += 1
|
2013-09-13 06:27:34 +02:00
|
|
|
potentialPrivSigningKey = hashlib.sha512(
|
2017-09-21 17:24:51 +02:00
|
|
|
deterministicPassphrase +
|
|
|
|
encodeVarint(signingKeyNonce)
|
|
|
|
).digest()[:32]
|
2013-09-13 06:27:34 +02:00
|
|
|
potentialPrivEncryptionKey = hashlib.sha512(
|
2017-09-21 17:24:51 +02:00
|
|
|
deterministicPassphrase +
|
|
|
|
encodeVarint(encryptionKeyNonce)
|
|
|
|
).digest()[:32]
|
2014-05-21 12:06:20 +02:00
|
|
|
potentialPubSigningKey = highlevelcrypto.pointMult(
|
2013-09-13 06:27:34 +02:00
|
|
|
potentialPrivSigningKey)
|
2014-05-21 12:06:20 +02:00
|
|
|
potentialPubEncryptionKey = highlevelcrypto.pointMult(
|
2013-06-21 14:44:37 +02:00
|
|
|
potentialPrivEncryptionKey)
|
2013-09-13 06:27:34 +02:00
|
|
|
signingKeyNonce += 2
|
|
|
|
encryptionKeyNonce += 2
|
2013-06-21 14:44:37 +02:00
|
|
|
sha = hashlib.new('sha512')
|
|
|
|
sha.update(
|
|
|
|
potentialPubSigningKey + potentialPubEncryptionKey)
|
2019-01-31 16:42:22 +01:00
|
|
|
ripe = RIPEMD160Hash(sha.digest()).digest()
|
|
|
|
if (
|
|
|
|
ripe[:numberOfNullBytesDemandedOnFrontOfRipeHash] ==
|
|
|
|
'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
|
|
|
|
):
|
2013-09-18 06:04:01 +02:00
|
|
|
break
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.info(
|
2019-01-31 16:42:22 +01:00
|
|
|
'Generated address with ripe digest: %s', hexlify(ripe))
|
2015-01-08 23:11:30 +01:00
|
|
|
try:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.info(
|
|
|
|
'Address generator calculated %s addresses'
|
|
|
|
' at %s addresses per second before finding'
|
|
|
|
' one with the correct ripe-prefix.',
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix,
|
|
|
|
numberOfAddressesWeHadToMakeBeforeWeFoundOneWithTheCorrectRipePrefix /
|
|
|
|
(time.time() - startTime)
|
|
|
|
)
|
2015-01-08 23:11:30 +01:00
|
|
|
except ZeroDivisionError:
|
2017-09-21 17:24:51 +02:00
|
|
|
# The user must have a pretty fast computer.
|
|
|
|
# time.time() - startTime equaled zero.
|
2015-01-08 23:11:30 +01:00
|
|
|
pass
|
2017-09-21 17:24:51 +02:00
|
|
|
address = encodeAddress(
|
2019-01-31 16:42:22 +01:00
|
|
|
addressVersionNumber, streamNumber, ripe)
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2013-09-13 06:27:34 +02:00
|
|
|
saveAddressToDisk = True
|
2017-09-21 17:24:51 +02:00
|
|
|
# If we are joining an existing chan, let us check
|
|
|
|
# to make sure it matches the provided Bitmessage address
|
2013-09-13 06:27:34 +02:00
|
|
|
if command == 'joinChan':
|
|
|
|
if address != chanAddress:
|
2017-09-21 17:24:51 +02:00
|
|
|
listOfNewAddressesToSendOutThroughTheAPI.append(
|
|
|
|
'chan name does not match address')
|
2013-06-26 17:55:33 +02:00
|
|
|
saveAddressToDisk = False
|
2013-09-13 06:27:34 +02:00
|
|
|
if command == 'getDeterministicAddress':
|
|
|
|
saveAddressToDisk = False
|
2013-06-26 17:55:33 +02:00
|
|
|
|
2016-10-28 22:07:16 +02:00
|
|
|
if saveAddressToDisk and live:
|
2017-09-21 17:24:51 +02:00
|
|
|
# An excellent way for us to store our keys is
|
|
|
|
# in Wallet Import Format. Let us convert now.
|
2013-09-13 06:27:34 +02:00
|
|
|
# https://en.bitcoin.it/wiki/Wallet_import_format
|
|
|
|
privSigningKey = '\x80' + potentialPrivSigningKey
|
|
|
|
checksum = hashlib.sha256(hashlib.sha256(
|
|
|
|
privSigningKey).digest()).digest()[0:4]
|
|
|
|
privSigningKeyWIF = arithmetic.changebase(
|
|
|
|
privSigningKey + checksum, 256, 58)
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2013-09-13 06:27:34 +02:00
|
|
|
privEncryptionKey = '\x80' + \
|
|
|
|
potentialPrivEncryptionKey
|
|
|
|
checksum = hashlib.sha256(hashlib.sha256(
|
|
|
|
privEncryptionKey).digest()).digest()[0:4]
|
|
|
|
privEncryptionKeyWIF = arithmetic.changebase(
|
|
|
|
privEncryptionKey + checksum, 256, 58)
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2013-09-13 06:27:34 +02:00
|
|
|
try:
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().add_section(address)
|
2015-01-08 23:11:30 +01:00
|
|
|
addressAlreadyExists = False
|
2013-09-13 06:27:34 +02:00
|
|
|
except:
|
|
|
|
addressAlreadyExists = True
|
2017-09-21 17:24:51 +02:00
|
|
|
|
2015-01-08 23:11:30 +01:00
|
|
|
if addressAlreadyExists:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.info(
|
|
|
|
'%s already exists. Not adding it again.',
|
|
|
|
address
|
|
|
|
)
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.UISignalQueue.put((
|
2017-09-21 17:24:51 +02:00
|
|
|
'updateStatusBar',
|
|
|
|
tr._translate(
|
|
|
|
"MainWindow",
|
|
|
|
"%1 is already in 'Your Identities'."
|
|
|
|
" Not adding it again."
|
|
|
|
).arg(address)
|
|
|
|
))
|
2015-01-08 23:11:30 +01:00
|
|
|
else:
|
2017-09-21 17:24:51 +02:00
|
|
|
logger.debug('label: %s', label)
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(address, 'label', label)
|
|
|
|
BMConfigParser().set(address, 'enabled', 'true')
|
|
|
|
BMConfigParser().set(address, 'decoy', 'false')
|
2017-09-21 17:24:51 +02:00
|
|
|
if command == 'joinChan' \
|
|
|
|
or command == 'createChan':
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(address, 'chan', 'true')
|
|
|
|
BMConfigParser().set(
|
2017-09-21 17:24:51 +02:00
|
|
|
address, 'noncetrialsperbyte',
|
|
|
|
str(nonceTrialsPerByte))
|
2017-01-11 14:27:19 +01:00
|
|
|
BMConfigParser().set(
|
2017-09-21 17:24:51 +02:00
|
|
|
address, 'payloadlengthextrabytes',
|
|
|
|
str(payloadLengthExtraBytes))
|
|
|
|
BMConfigParser().set(
|
|
|
|
address, 'privSigningKey',
|
|
|
|
privSigningKeyWIF)
|
|
|
|
BMConfigParser().set(
|
|
|
|
address, 'privEncryptionKey',
|
|
|
|
privEncryptionKeyWIF)
|
2017-01-15 10:50:02 +01:00
|
|
|
BMConfigParser().save()
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2017-09-21 17:24:51 +02:00
|
|
|
queues.UISignalQueue.put((
|
|
|
|
'writeNewAddressToTable',
|
|
|
|
(label, address, str(streamNumber))
|
|
|
|
))
|
2013-09-13 06:27:34 +02:00
|
|
|
listOfNewAddressesToSendOutThroughTheAPI.append(
|
|
|
|
address)
|
2019-01-31 16:42:22 +01:00
|
|
|
shared.myECCryptorObjects[ripe] = \
|
2017-09-21 17:24:51 +02:00
|
|
|
highlevelcrypto.makeCryptor(
|
2016-03-23 23:26:57 +01:00
|
|
|
hexlify(potentialPrivEncryptionKey))
|
2019-01-31 16:42:22 +01:00
|
|
|
shared.myAddressesByHash[ripe] = address
|
2017-09-21 17:24:51 +02:00
|
|
|
tag = hashlib.sha512(hashlib.sha512(
|
|
|
|
encodeVarint(addressVersionNumber) +
|
2019-01-31 16:42:22 +01:00
|
|
|
encodeVarint(streamNumber) + ripe
|
2017-09-21 17:24:51 +02:00
|
|
|
).digest()).digest()[32:]
|
2013-09-15 03:06:26 +02:00
|
|
|
shared.myAddressesByTag[tag] = address
|
2013-09-13 06:27:34 +02:00
|
|
|
if addressVersionNumber == 3:
|
2017-09-21 17:24:51 +02:00
|
|
|
# If this is a chan address,
|
|
|
|
# the worker thread won't send out
|
|
|
|
# the pubkey over the network.
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.workerQueue.put((
|
2019-01-31 16:42:22 +01:00
|
|
|
'sendOutOrStoreMyV3Pubkey', ripe))
|
2013-09-13 06:27:34 +02:00
|
|
|
elif addressVersionNumber == 4:
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.workerQueue.put((
|
2013-09-13 06:27:34 +02:00
|
|
|
'sendOutOrStoreMyV4Pubkey', address))
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.UISignalQueue.put((
|
2017-09-21 17:24:51 +02:00
|
|
|
'updateStatusBar',
|
|
|
|
tr._translate(
|
|
|
|
"MainWindow", "Done generating address")
|
|
|
|
))
|
|
|
|
elif saveAddressToDisk and not live \
|
|
|
|
and not BMConfigParser().has_section(address):
|
|
|
|
listOfNewAddressesToSendOutThroughTheAPI.append(
|
|
|
|
address)
|
2013-06-21 14:44:37 +02:00
|
|
|
|
2013-09-13 06:27:34 +02:00
|
|
|
# Done generating addresses.
|
2017-09-21 17:24:51 +02:00
|
|
|
if command == 'createDeterministicAddresses' \
|
|
|
|
or command == 'joinChan' or command == 'createChan':
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.apiAddressGeneratorReturnQueue.put(
|
2015-12-05 11:18:51 +01:00
|
|
|
listOfNewAddressesToSendOutThroughTheAPI)
|
|
|
|
elif command == 'getDeterministicAddress':
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.apiAddressGeneratorReturnQueue.put(address)
|
2013-09-13 06:27:34 +02:00
|
|
|
else:
|
|
|
|
raise Exception(
|
2017-09-21 17:24:51 +02:00
|
|
|
"Error in the addressGenerator thread. Thread was" +
|
|
|
|
" given a command it could not understand: " + command)
|
2017-02-08 13:41:56 +01:00
|
|
|
queues.addressGeneratorQueue.task_done()
|