def test_add_get_drop_node(meta_repo): nodes_repo = NodesRepo(meta_repo.conn) inserted = Node(currency="testcurrency", pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ", endpoints="""BASIC_MERKLED_API test-net.duniter.fr 13.222.11.22 9201 BASIC_MERKLED_API testnet.duniter.org 80 UNKNOWNAPI some useless information""", peer_blockstamp=BlockUID.empty(), uid="doe", current_buid="15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", current_ts=12376543345, previous_buid="14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67", state=0, software="duniter", version="0.30.17") nodes_repo.insert(inserted) node = nodes_repo.get_one(currency="testcurrency", pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") assert node.currency == "testcurrency" assert node.pubkey == "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ" assert node.endpoints[0] == BMAEndpoint("test-net.duniter.fr", "13.222.11.22", None, 9201) assert node.endpoints[1] == BMAEndpoint("testnet.duniter.org", None, None, 80) assert node.endpoints[2] == UnknownEndpoint("UNKNOWNAPI", ["some", "useless", "information"]) assert node.previous_buid == block_uid("14-AEFFCB00E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") assert node.current_buid == block_uid("15-76543400E78B56CC21FB1DDC6CBAB24E0FACC9A798F5ED8736EA007F38617D67") assert node.state == 0 assert node.software == "duniter" assert node.version == "0.30.17" assert node.merkle_peers_root == Node.MERKLE_EMPTY_ROOT assert node.merkle_peers_leaves == tuple() nodes_repo.drop(node) node = nodes_repo.get_one(pubkey="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ") assert node is None
async def main(): """ Main code """ # connection handler from BMA endpoint connection = BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler() # capture current block to get version and currency and blockstamp current_block = await get_current_block(connection) # load credentials from a text file salt, password = open(FROM_CREDENTIALS_FILE).readlines() # cleanup newlines salt, password = salt.strip(), password.strip() # create our signed identity document identity = get_identity_document(current_block, UID, salt, password) # send the identity document to the node data = {identity: identity.signed_raw()} response = await bma.wot.Add(connection).post(AIOHTTP_SESSION, **data) print(response) response.close()
async def main(): """ Main code """ # connection handler from BMA endpoint connection = BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler() # capture current block to get currency name current_block = await get_current_block(connection) # create our SelfCertification document to sign the revoke document identity_document = await get_identity_document(connection, current_block['currency'], PUBKEY) # load credentials from a text file salt, password = open(CREDENTIALS_FILE_PATH).readlines() # cleanup newlines salt, password = salt.strip(), password.strip() # get the revoke document revoke_document = await get_revoke_document(identity_document, salt, password) # save revoke document in a file fp = open(REVOKE_DOCUMENT_FILE_PATH, 'w') fp.write(revoke_document) fp.close() # document saved print("Revoke document saved in %s" % REVOKE_DOCUMENT_FILE_PATH)
def peer_doc(self): peer = Peer(2, self.forge.currency, self.forge.key.pubkey, BlockUID.empty(), [BMAEndpoint(None, "127.0.0.1", None, self.http.port)], None) peer.sign([self.forge.key]) return peer
async def main(): """ Main code """ # connection handler from BMA endpoint connection = BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler() # capture current block to get version and currency and blockstamp current_block = await get_current_block(connection) # create our SelfCertification document to sign the Certification document identity = await get_identity_document(connection, current_block, TO_PUBKEY) # load credentials from a text file salt, password = open(FROM_CREDENTIALS_FILE).readlines() # cleanup newlines salt, password = salt.strip(), password.strip() # send the Certification document to the node certification = get_certification_document(current_block, identity, FROM_PUBKEY, salt, password) # Here we request for the path wot/certify data = {'cert': certification.signed_raw(identity)} response = await bma.wot.Certify(connection).post(AIOHTTP_SESSION, **data) print(response) response.close()
async def main(): """ Main code """ # connection handler from BMA endpoint connection = next( BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # capture current block to get version and currency and blockstamp current_block = await bma.blockchain.current(connection) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") # prompt hidden user entry password = getpass.getpass("Enter your password: "******"Error while publishing identity : {0}".format(await response.text())) response.close()
async def go(): _, srv, port, url = await self.create_server( 'GET', '/tx/sources/pubkey', handler) with self.assertRaises(jsonschema.exceptions.ValidationError): async with aiohttp.ClientSession() as session: connection = next( BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)) await sources(connection, 'pubkey')
async def go(): _, srv, port, url = await self.create_server( 'GET', '/blockchain/with/certs', handler) with self.assertRaises(jsonschema.exceptions.ValidationError): async with aiohttp.ClientSession() as session: connection = next( BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)) await certifications(connection)
async def go(): _, port, url = await self.create_server('GET', '/network/peering', handler) with self.assertRaises(jsonschema.exceptions.ValidationError): async with aiohttp.ClientSession() as session: connection = next( BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)) await network.peering(connection)
async def main(): """ Main code """ # connection handler from BMA endpoint connection = next( BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") # prompt hidden user entry password = getpass.getpass("Enter your password: "******"Enter your pubkey: ") # prompt entry pubkey_to = input("Enter recipient pubkey: ") # capture current block to get version and currency and blockstamp current_block = await bma.blockchain.current(connection) # capture sources of account response = await bma.tx.sources(connection, pubkey_from) if len(response['sources']) == 0: print("no sources found for account %s" % pubkey_to) exit(1) # get the first source source = response['sources'][0] # create the transaction document transaction = get_transaction_document(current_block, source, pubkey_from, pubkey_to) # create keys from credentials key = SigningKey(salt, password, ScryptParams(4096, 16, 1)) # sign document transaction.sign([key]) # send the Transaction document to the node response = await bma.tx.process(connection, transaction.signed_raw()) if response.status == 200: print(await response.text()) else: print("Error while publishing transaction: {0}".format( await response.text())) response.close()
async def go(): _, srv, port, url = await self.create_server( 'GET', '/blockchain/memberships/8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU', handler) with self.assertRaises(jsonschema.exceptions.ValidationError): async with aiohttp.ClientSession() as session: connection = next( BMAEndpoint("127.0.0.1", None, None, port).conn_handler(session)) await memberships( connection, "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU")
async def main(): """ Main code """ ######################################################################################### # connection handler from BMA endpoint connection = next( BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # capture current block to get version and currency and blockstamp current_block = await bma.blockchain.current(connection) # prompt hidden user entry #salt = getpass.getpass("Enter your passphrase (salt): ") salt = sys.argv[1] # prompt hidden user entry #password = getpass.getpass("Enter your password: "******"Enter your UID: ") UID = sys.argv[3] ######################################################################################### # create our signed identity document identity = get_identity_document(current_block, UID, salt, password) # FIRST Send the identity document to the node responseid = await bma.wot.add(connection, identity.signed_raw()) if responseid.status == 200: print(await responseid.text()) else: print("Error while publishing identity : {0}".format( await responseid.text())) responseid.close() ######################################################################################### # create a membership demand document membership = get_membership_document("IN", current_block, identity, salt, password) # SECOND Send the membership document to the node response = await bma.blockchain.membership(connection, membership.signed_raw()) if response.status == 200: print(await response.text()) else: print("Error while publishing membership : {0}".format( await response.text())) response.close()
async def main(): """ Main code """ # connection handler from BMA endpoint connection = BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler() # Get the node summary infos response = await bma.node.Summary(connection).get(AIOHTTP_SESSION) print(response) # Get the current block data response = await bma.blockchain.Current(connection).get(AIOHTTP_SESSION) print(response) # Get the block number 0 response = await bma.blockchain.Block(connection, 0).get(AIOHTTP_SESSION) print(response)
async def main(): """ Main code """ # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") # prompt hidden user entry password = getpass.getpass("Enter your password: "******"Enter your public key: ") # init signer instance signer = SigningKey(salt, password, ScryptParams(4096, 16, 1)) # check public key if signer.pubkey != pubkey: print("Bad credentials!") exit(0) # connection handler from BMA endpoint connection = next( BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # capture current block to get currency name current_block = await bma.blockchain.current(connection) # create our Identity document to sign the revoke document identity_document = await get_identity_document(connection, current_block['currency'], pubkey) # get the revoke document revoke_document = get_revoke_document(identity_document, salt, password) # save revoke document in a file fp = open(REVOKE_DOCUMENT_FILE_PATH, 'w') fp.write(revoke_document) fp.close() # document saved print("Revoke document saved in %s" % REVOKE_DOCUMENT_FILE_PATH)
async def main(): """ Main code """ # connection handler from BMA endpoint connection = next( BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") # prompt hidden user entry password = getpass.getpass("Enter your password: "******"Enter your pubkey: ") # prompt entry pubkey_to = input("Enter certified pubkey: ") # capture current block to get version and currency and blockstamp current_block = await bma.blockchain.current(connection) # create our Identity document to sign the Certification document identity = await get_identity_document(connection, current_block, pubkey_to) # send the Certification document to the node certification = get_certification_document(current_block, identity, pubkey_from, salt, password) # Here we request for the path wot/certify response = await bma.wot.certify(connection, certification.signed_raw(identity)) if response.status == 200: print(await response.text()) else: print("Error while publishing certification: {0}".format( await response.text())) response.close()
async def main(): """ Main code """ # connection handler from BMA endpoint connection = next( BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # Get the node summary infos response = await bma.node.summary(connection) print(response) # Get the current block data response = await bma.blockchain.parameters(connection) print(response) # Get the current block data response = await bma.blockchain.current(connection) print(response) # Get the block number 10 response = await bma.blockchain.block(connection, 10) print(response)