Skip to content
Snippets Groups Projects
Commit b216488e authored by inso's avatar inso
Browse files

Fix send documents

parent 642ec888
Branches
Tags
No related merge requests found
...@@ -13,17 +13,6 @@ from duniterpy.key import SigningKey ...@@ -13,17 +13,6 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API # Here we use the BASIC_MERKLED_API
BMA_ENDPOINT = "BASIC_MERKLED_API cgeek.fr 9330" BMA_ENDPOINT = "BASIC_MERKLED_API cgeek.fr 9330"
# Public key of the certifier
FROM_PUBKEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
FROM_CREDENTIALS_FILE = "/home/username/.credentials.txt"
# Public key to certified
TO_PUBKEY = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
################################################ ################################################
# Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request # Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request
...@@ -103,25 +92,31 @@ async def main(): ...@@ -103,25 +92,31 @@ async def main():
# connection handler from BMA endpoint # connection handler from BMA endpoint
connection = BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) connection = 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)
# create our SelfCertification document to sign the Certification document
identity = await get_identity_document(connection, current_block, TO_PUBKEY)
# prompt hidden user entry # prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ") salt = getpass.getpass("Enter your passphrase (salt): ")
# prompt hidden user entry # prompt hidden user entry
password = getpass.getpass("Enter your password : ") password = getpass.getpass("Enter your password : ")
# prompt hidden user entry
pubkey_from = getpass.getpass("Enter your pubkey : ")
# prompt hidden user entry
pubkey_to = getpass.getpass("Enter certified pubkey : ")
# capture current block to get version and currency and blockstamp
current_block = await bma.blockchain.current(connection)
# create our SelfCertification document to sign the Certification document
identity = await get_identity_document(connection, current_block, pubkey_to)
# send the Certification document to the node # send the Certification document to the node
certification = get_certification_document(current_block, identity, FROM_PUBKEY, salt, password) certification = get_certification_document(current_block, identity, pubkey_from, salt, password)
# Here we request for the path wot/certify # Here we request for the path wot/certify
response = await bma.wot.certify(connection, certification.signed_raw(identity)) response = await bma.wot.certify(connection, certification.signed_raw(identity))
if response.status_code == 200: if response.status == 200:
print(await response.text()) print(await response.text())
else: else:
print("Error while publishing certification : {0}".format(response.text())) print("Error while publishing certification : {0}".format(response.text()))
......
...@@ -14,14 +14,6 @@ from duniterpy.key import SigningKey ...@@ -14,14 +14,6 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API # Here we use the BASIC_MERKLED_API
BMA_ENDPOINT = "BASIC_MERKLED_API cgeek.fr 9330" BMA_ENDPOINT = "BASIC_MERKLED_API cgeek.fr 9330"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
FROM_CREDENTIALS_FILE = "/home/username/.credentials.txt"
# Your unique identifier in the Web of Trust
UID = "MyIdentity"
################################################ ################################################
# Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request # Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request
...@@ -115,6 +107,9 @@ async def main(): ...@@ -115,6 +107,9 @@ async def main():
# prompt hidden user entry # prompt hidden user entry
password = getpass.getpass("Enter your password: ") password = getpass.getpass("Enter your password: ")
# prompt hidden user entry
UID = getpass.getpass("Enter your UID: ")
# create our signed identity document # create our signed identity document
identity = get_identity_document(current_block, UID, salt, password) identity = get_identity_document(current_block, UID, salt, password)
......
...@@ -15,17 +15,6 @@ from duniterpy.key import SigningKey ...@@ -15,17 +15,6 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API # Here we use the BASIC_MERKLED_API
BMA_ENDPOINT = "BASIC_MERKLED_API cgeek.fr 9330" BMA_ENDPOINT = "BASIC_MERKLED_API cgeek.fr 9330"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
FROM_CREDENTIALS_FILE = "/home/username/.credentials.txt"
# Public key of the source account
FROM_PUBKEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Public key of the target account
TO_PUBKEY = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
################################################ ################################################
...@@ -107,27 +96,33 @@ async def main(): ...@@ -107,27 +96,33 @@ async def main():
# connection handler from BMA endpoint # connection handler from BMA endpoint
connection = BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION) connection = 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 : ")
# prompt hidden user entry
pubkey_from = getpass.getpass("Enter your pubkey : ")
# prompt hidden user entry
pubkey_to = getpass.getpass("Enter recipient pubkey : ")
# capture current block to get version and currency and blockstamp # capture current block to get version and currency and blockstamp
current_block = await bma.blockchain.current(connection) current_block = await bma.blockchain.current(connection)
# capture sources of account # capture sources of account
response = await bma.tx.sources(connection, FROM_PUBKEY) response = await bma.tx.sources(connection, pubkey_from)
if len(response['sources']) == 0: if len(response['sources']) == 0:
print("no sources found for account %s" % FROM_PUBKEY) print("no sources found for account %s" % pubkey_to)
exit(1) exit(1)
# get the first source # get the first source
source = response['sources'][0] source = response['sources'][0]
# create the transaction document # create the transaction document
transaction = get_transaction_document(current_block, source, FROM_PUBKEY, TO_PUBKEY) transaction = get_transaction_document(current_block, source, pubkey_from, pubkey_to)
# load credentials from a text file
salt, password = open(FROM_CREDENTIALS_FILE).readlines()
# cleanup newlines
salt, password = salt.strip(), password.strip()
# create keys from credentials # create keys from credentials
key = SigningKey(salt, password) key = SigningKey(salt, password)
...@@ -141,7 +136,7 @@ async def main(): ...@@ -141,7 +136,7 @@ async def main():
if response.status == 200: if response.status == 200:
print(await response.text()) print(await response.text())
else: else:
print("Error while publishing transaction : {0}".format(response.text())) print("Error while publishing transaction : {0}".format(await response.text()))
response.close() response.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment