def main():
    w3 = Web3(HTTPProvider('http://localhost:8545'))
    print(w3.admin.peers)
    print('Peers:')
    for peer in w3.admin.peers:
        print(' -> ' + peer['network']['remoteAddress'] + ' ' + peer['name'] +
              ' ' + str(peer['caps']))

    shh = Shh(w3)
    print('Whisper version: ' + shh.version)
    print('Whisper info: [memory: ' + str(shh.info.memory) + ', messages: ' +
          str(shh.info.messages) + ', max_message_size: ' +
          str(shh.info.maxMessageSize) + ', min_pow: ' + str(shh.info.minPow))

    symKeyID = shh.generateSymKeyFromPassword(
        'shh!! this is a secret password')
    print('Identity: ' + symKeyID)
    print('Symmetric key: ' + shh.getSymKey(symKeyID))

    result = shh.post({
        'payload': Web3.toHex(text='Hello world!'),
        'symKeyID': symKeyID,
        'topic': '0x12340000',
        'powTarget': 2.5,
        'powTime': 2
    })
    print('Message sent: ' + str(result))
Beispiel #2
0
    def __init__(self):
        self.w3 = Web3(HTTPProvider('http://localhost:8545'))
        Shh.attach(self.w3, "shh")
        self.shh = self.w3.shh
        #Chain ID of Ropsten Test Net is 3, replace it to 1 for Main Net
        self.chainId = self.w3.net.chainId
        self.defaultTopic = "0x5a4ea131"
        self.privateKey = '0x862e3b865d47553509e7e97229a6e868c6656dd654799dd411ffbdcf8f2fa800'
        self.defaultRecipientPubKey = ''
        self.defaultPwd = 'core2duo'
        self.kid = ''
        self.defaultkId = '8158692724d0353cdf336f843ebea2de6932d811e2e6b06cb5c18bec67d37866'
        self.payloadMsg = ''

        self.data = {
            'msgs': '',
            'text': "",
            'symKeyId': '',
            'name': "",
            'asymKeyId': '',
            'sympw': "",
            'asym': True,
            'configured': False,
            'topic': self.defaultTopic,
            'recipientPubKey': self.defaultRecipientPubKey,
            'asymPubKey': ""
        }
        self.data['symKeyId'] = self.shh.generateSymKeyFromPassword(
            self.defaultPwd)
        print('data: ', self.data)
        self.getFilterMessage()
Beispiel #3
0
class Bot(threading.Thread):
    def __init__(self, name):
        super(Bot, self).__init__()
        self.name = name
        self.shh = Shh(Web3(HTTPProvider('http://localhost:8545')))
        print(self.name + ': Whisper version: ' + self.shh.version)
        print(self.name + ': Whisper info: [memory: ' +
              str(self.shh.info.memory) + ', messages: ' +
              str(self.shh.info.messages) + ', max_message_size: ' +
              str(self.shh.info.maxMessageSize) + ', min_pow: ' +
              str(self.shh.info.minPow))
        self.symKeyID = self.shh.generateSymKeyFromPassword(
            'shh!! this is a secret password')
        print(self.name + ': Identity: ' + self.symKeyID)
        print(self.name + ': Symmetric key: ' +
              self.shh.getSymKey(self.symKeyID))

    def filter(self):
        message_filter = self.shh.newMessageFilter({
            'topic': '0x12340000',
            'symKeyID': self.symKeyID
        })
        return message_filter

    def run(self):
        filter_id = self.filter().filter_id
        print(self.name + ': Waiting for messages...')
        while True:
            messages = self.shh.getMessages(filter_id)
            for message in messages:
                print(self.name + ': Received message: ' +
                      Web3.toText(message['payload']))
                print(self.name + ': Envelope: ' + str(message))
            time.sleep(0.3)
Beispiel #4
0
 def __init__(self, name):
     super(Bot, self).__init__()
     self.name = name
     self.shh = Shh(Web3(HTTPProvider('http://localhost:8545')))
     print(self.name + ': Whisper version: ' + self.shh.version)
     print(self.name + ': Whisper info: [memory: ' +
           str(self.shh.info.memory) + ', messages: ' +
           str(self.shh.info.messages) + ', max_message_size: ' +
           str(self.shh.info.maxMessageSize) + ', min_pow: ' +
           str(self.shh.info.minPow))
     self.symKeyID = self.shh.generateSymKeyFromPassword(
         'shh!! this is a secret password')
     print(self.name + ': Identity: ' + self.symKeyID)
     print(self.name + ': Symmetric key: ' +
           self.shh.getSymKey(self.symKeyID))
Beispiel #5
0
    def __init__(self, provider):
        self._requestManager = RequestManager(provider)

        self.eth = Eth(self)
        self.db = Db(self)
        self.shh = Shh(self)
        self.net = Net(self)
        self.personal = Personal(self)
        self.version = Version(self)
        self.txpool = TxPool(self)
        self.miner = Miner(self)
        self.admin = Admin(self)
Beispiel #6
0
    def __init__(self, provider):
        self._requestManager = RequestManager(provider)
        self.currentProvider = provider

        self.eth = Eth(self)
        self.db = Db(self._requestManager)
        self.shh = Shh(self._requestManager)
        self.net = Net(self._requestManager)
        self.personal = Personal(self._requestManager)
        self.version = Version(self._requestManager)
        self.txpool = TxPool(self._requestManager)
        self.miner = Miner(self._requestManager)
        self.admin = Admin(self._requestManager)

        self.providers = {
            'RPCProvider': RPCProvider,
            'IPCProvider': IPCProvider,
            'TestRPCProvider': TestRPCProvider,
        }

        self.RPCProvider = RPCProvider
        self.IPCProvider = IPCProvider
        self.TestRPCProvider = TestRPCProvider

        # Encoding and Decoding
        self.toHex = to_hex
        self.toAscii = decode_hex
        self.toUtf8 = compose(decode_hex, force_text)
        self.fromAscii = encode_hex
        self.fromUtf8 = encode_hex
        self.toDecimal = to_decimal
        self.fromDecimal = from_decimal

        # Currency Utility
        self.toWei = to_wei
        self.fromWei = from_wei

        # Address Utility
        self.isAddress = is_address
        self.isChecksumAddress = is_checksum_address
        self.toChecksumAddress = to_checksum_address
Beispiel #7
0
    address_to = b_pubKey
    #address_to = a_pubKey
    host = "http://localhost:8500"
    #host = "http://localhost:8501"
else:
    print("Unknown node")
    sys.exit(0)

# Connection
#---------------------------------------------------------------------

print("host", host)
web3 = Web3(HTTPProvider(host))
from web3.shh import Shh

Shh.attach(web3, "shh")

#kId = web3.shh.addPrivateKey(keyPair)
#pubKey = web3.shh.getPublicKey(kId)

# A sending messages to B and B then checking

# keyPair used for decryption
print("keyPair for filter", keyPair)
myFilter = pollFilter(topic, keyPair)

print("yo sending")
sendMessage(address_to, topic, "hello")
sendMessage(address_to, topic, "hi also")

# XXX this works, well hell a does
Beispiel #8
0
def include_shh_module(web3):
    Shh.attach(web3, "shh")
Beispiel #9
0
def include_shh_module(web3):
    Shh.attach(web3, "shh")