示例#1
0
    def test_read_trusted(self):
        prikey, pubkey = Ed25519Cipher.generate_keys()
        self.mam_stream.add_trusted_pubkey('test', pubkey)
        self.mam_stream.channel_pwd = 'test'
        test_mam_stream = MAML_Ed25519(self.mam_stream.root_address,
                                       self.mam_stream.channel_pwd)

        self.mam_stream.write('data_to_be_sent1', pubkey, prikey)
        self.mam_stream.write('data_to_be_sent2', pubkey, prikey)
        self.mam_stream.write('data_to_be_sent3', pubkey, prikey)

        read_res = test_mam_stream.read()
        self.assertEqual('data_to_be_sent1', read_res.msg.data_payload)
        read_res = test_mam_stream.read()
        self.assertEqual('data_to_be_sent2', read_res.msg.data_payload)
        read_res = test_mam_stream.read()
        self.assertEqual('data_to_be_sent3', read_res.msg.data_payload)
示例#2
0
文件: test_maml.py 项目: msbroy/MAML
    def test_read_trusted(self):
        prikey, pubkey = Ed25519Cipher.generate_keys()
        self.mam_stream.add_trusted_pubkey('test', pubkey)
        self.mam_stream.write_pwd = 'test'
        test_mam_stream = MaskedAuthMsgStream(self.mam_stream.root_address, self.mam_stream.write_pwd, self.mam_stream.read_pwd)

        write_res1 = self.mam_stream.write('data_to_be_sent1', pubkey, prikey)
        write_res2 = self.mam_stream.write('data_to_be_sent2', pubkey, prikey)
        write_res3 = self.mam_stream.write('data_to_be_sent3', pubkey, prikey)

        test_mam_stream.add_trusted_pubkey('test', pubkey)
        read_res = test_mam_stream.read()
        self.assertEqual('data_to_be_sent1', read_res.msgs[0].payload)
        read_res = test_mam_stream.read()
        self.assertEqual('data_to_be_sent2', read_res.msgs[0].payload)
        read_res = test_mam_stream.read()
        self.assertEqual('data_to_be_sent3', read_res.msgs[0].payload)
示例#3
0
    def test_create_auth_msg(self):
        prikey, pubkey = Ed25519Cipher.generate_keys()
        auth_msg = AuthMessage().finalize(payload='data_to_be_sent',
                                          pubkey=pubkey,
                                          prikey=prikey)
        auth_msg_json = auth_msg.to_json()
        obj1 = FactoryAuthMsg.create_auth_msg_from_json(auth_msg_json)
        self.assertTrue(isinstance(obj1, AuthMessage))

        stream_auth_msg = StreamAuthMessage().finalize(
            payload='data_to_be_sent',
            pubkey=pubkey,
            prikey=prikey,
            addr='TESTADDRESS',
            forward_addr="TESTFORWARDADDRESS")
        stream_auth_msg_json = stream_auth_msg.to_json()
        obj2 = FactoryAuthMsg.create_auth_msg_from_json(stream_auth_msg_json)
        self.assertTrue(isinstance(obj2, StreamAuthMessage))
示例#4
0
def submit_page():
    prikey, pubkey = Ed25519Cipher.generate_keys()
    pubkey_str = pubkey.to_ascii(encoding='base64').decode()
    address = hash_tryte(pubkey_str)
    html = '''
    <!DOCTYPE html>
    <html>
    
    <head>
    <title>Web+IOTA test page</title>
    </head>
    
    <body>
    
    <h1>Welcome to IOTA-based decentralized internet!</h1>
    
    </body>
    </html>
    '''
    msg = AuthMessage().finalize(html, pubkey, prikey)
    tangle_con.send_msg_to_addr(Address(address),
                                msg.to_json(),
                                tag='IOTA9GATEWAY')
    return jsonify(msg.to_json()), 200
示例#5
0
 def test_set_pubkey(self):
     msg_obj = Message()
     prikey, pubkey = Ed25519Cipher.generate_keys()
     msg_obj.set_pubkey(pubkey)
     self.assertTrue(msg_obj.pubkey)
示例#6
0
 def finalize(self, payload: str, pubkey, prikey):
     self._set_data_payload(payload)
     self._set_pubkey(pubkey)
     self._generate_salt()
     self._set_signature(Ed25519Cipher.sign_message((payload + self.salt).encode(), prikey).decode())
     return self
示例#7
0
import random
import string
from iota import Address
from ciphers import Ed25519Cipher
from mam_lite import MAML_Ed25519

addr_test = Address(''.join(random.choices(string.ascii_uppercase + '9',
                                           k=81)))
mam_stream_1 = MAML_Ed25519(root_address=addr_test,
                            channel_password='******')
mam_stream_2 = MAML_Ed25519(root_address=addr_test,
                            channel_password='******')

# generate pubkey and make it trusted
prikey, pubkey = Ed25519Cipher.generate_keys()
mam_stream_1.add_trusted_pubkey('test_entity', pubkey)
mam_stream_2.add_trusted_pubkey('test_entity', pubkey)

# write with first MAML stream
write_res = mam_stream_1.write('data_to_be_sent', pubkey, prikey)

# read and validate with another
read_res = mam_stream_2.read()

# split the channel
mam_stream_1.split_channel('test_pass_2')

# write new msg to new channel
write_res = mam_stream_1.write('data_to_be_sent_2', pubkey, prikey)

# switch the channel on second stream
示例#8
0
 def test_read(self):
     prikey, pubkey = Ed25519Cipher.generate_keys()
     self.mam_stream.write('data_to_be_sent', pubkey, prikey)
     read_res = self.mam_stream.read()
     self.assertEqual('data_to_be_sent', read_res.msg.data_payload)
示例#9
0
文件: message.py 项目: AleBuser/MAMCR
 def finalize(self, data: str, extra_data: str, pubkey, prikey,timestamp):
     self.set_data_payload(data)
     self.set_pubkey(pubkey)
     self.set_signature(Ed25519Cipher.sign_message((data + extra_data).encode(), prikey).decode())
     self.set_timestamp(timestamp)
     return self