diff --git a/duniterpy/documents/peer.py b/duniterpy/documents/peer.py index 323125bb3e28a2ccb4b548bde9c92777acfbba84..cf74b3ca5c2998a7c3c81c6a35c0f6e11564ea1a 100644 --- a/duniterpy/documents/peer.py +++ b/duniterpy/documents/peer.py @@ -1,4 +1,5 @@ import re +from typing import Generator from ..api.bma import ConnectionHandler from .document import Document, MalformedDocumentError @@ -188,6 +189,8 @@ class BMAEndpoint(Endpoint): Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance + :param str proxy: Proxy url + :rtype: Generator[ConnectionHandler, None, None] """ if self.server: yield ConnectionHandler("http", "ws", self.server, self.port, "", proxy, session) @@ -244,7 +247,8 @@ class SecuredBMAEndpoint(BMAEndpoint): Return connection handler instance for the endpoint :param aiohttp.ClientSession session: AIOHTTP client session instance - :rtype: ConnectionHandler + :param str proxy: Proxy url + :rtype: Generator[ConnectionHandler, None, None] """ if self.server: yield ConnectionHandler("https", "wss", self.server, self.port, self.path, proxy, session) diff --git a/examples/create_and_publish_identity.py b/examples/create_and_publish_identity.py index fd1082d7c802bcde3e589fbda288d92b87f078ba..559fd83dd9bd8942e19b12b6427b04726015405b 100644 --- a/examples/create_and_publish_identity.py +++ b/examples/create_and_publish_identity.py @@ -3,7 +3,7 @@ import aiohttp import getpass import duniterpy.api.bma as bma -from duniterpy.documents import BMAEndpoint, BlockUID, Identity +from duniterpy.documents import BMAEndpoint, SecuredBMAEndpoint, BlockUID, Identity from duniterpy.key import SigningKey @@ -11,11 +11,11 @@ from duniterpy.key import SigningKey # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] -# Here we use the BASIC_MERKLED_API -BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" +# Here we use the secure BASIC_MERKLED_API (BMAS) +BMA_ENDPOINT = "BMAS g1-test.duniter.org 443" # Your unique identifier in the Web of Trust -UID = "MyIdentity" +UID = "MyIdentityTest" ################################################ # Latest duniter-python-api is asynchronous and you have to create an aiohttp session to send request @@ -63,7 +63,7 @@ async def main(): """ # connection handler from BMA endpoint - connection = next(BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = next(SecuredBMAEndpoint.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) diff --git a/examples/request_data.py b/examples/request_data.py index 5e3df5abe749a4180fad6fae4226bb0f6840ea96..1680352c8bdfb746654afa53b483f0a24d29d903 100644 --- a/examples/request_data.py +++ b/examples/request_data.py @@ -1,14 +1,14 @@ import asyncio import aiohttp import duniterpy.api.bma as bma -from duniterpy.documents import BMAEndpoint +from duniterpy.documents import BMAEndpoint, SecuredBMAEndpoint # CONFIG ####################################### # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] -# Here we use the BASIC_MERKLED_API -BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" +# Here we use the secure BASIC_MERKLED_API (BMAS) +BMA_ENDPOINT = "BMAS g1-test.duniter.org 443" ################################################ @@ -16,12 +16,13 @@ BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" # ( http://pythonhosted.org/aiohttp ) AIOHTTP_SESSION = aiohttp.ClientSession() + async def main(): """ Main code """ # connection handler from BMA endpoint - connection = next(BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # Get the node summary infos response = await bma.node.summary(connection) diff --git a/examples/save_revoke_document.py b/examples/save_revoke_document.py index 50b53f9febef3218e6537dba309428e062e296bb..3664de56a99c987dbd35010eb5d6cf4740c23de5 100644 --- a/examples/save_revoke_document.py +++ b/examples/save_revoke_document.py @@ -1,7 +1,7 @@ import asyncio import aiohttp import duniterpy.api.bma as bma -from duniterpy.documents import BMAEndpoint, BlockUID, Identity +from duniterpy.documents import BMAEndpoint, SecuredBMAEndpoint, BlockUID, Identity from duniterpy.documents import Revocation from duniterpy.key import SigningKey import getpass @@ -20,8 +20,8 @@ else: # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] -# Here we use the BASIC_MERKLED_API -BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" +# Here we use the secure BASIC_MERKLED_API (BMAS) +BMA_ENDPOINT = "BMAS g1-test.duniter.org 443" # WARNING : Hide this file in a safe and secure place # If one day you forget your credentials, @@ -34,6 +34,7 @@ AIOHTTP_SESSION = aiohttp.ClientSession() # Current protocol version PROTOCOL_VERSION = 10 + async def get_identity_document(connection, currency, pubkey): """ Get the Identity document of the pubkey @@ -111,8 +112,8 @@ async def main(): print("Bad credentials!") exit(0) - # connection handler from BMA endpoint - connection = next(BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + # connection handler from BMAS endpoint + connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # capture current block to get currency name current_block = await bma.blockchain.current(connection) diff --git a/examples/send_certification.py b/examples/send_certification.py index f0db5b788642c52cf5c85b9a4811ee6bacff6d02..b7318cbd479d17b38044acc67c84ca43a4a5c35d 100644 --- a/examples/send_certification.py +++ b/examples/send_certification.py @@ -2,7 +2,7 @@ import asyncio import aiohttp import getpass import duniterpy.api.bma as bma -from duniterpy.documents import BMAEndpoint, BlockUID, Identity, Certification +from duniterpy.documents import BMAEndpoint, SecuredBMAEndpoint, BlockUID, Identity, Certification from duniterpy.key import SigningKey @@ -10,8 +10,8 @@ from duniterpy.key import SigningKey # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] -# Here we use the BASIC_MERKLED_API -BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" +# Here we use the secure BASIC_MERKLED_API (BMAS) +BMA_ENDPOINT = "BMAS g1-test.duniter.org 443" ################################################ @@ -19,6 +19,7 @@ BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" # ( http://pythonhosted.org/aiohttp ) AIOHTTP_SESSION = aiohttp.ClientSession() + async def get_identity_document(connection, current_block, pubkey): """ Get the identity document of the pubkey @@ -85,12 +86,13 @@ def get_certification_document(current_block, self_cert_document, from_pubkey, s return certification + async def main(): """ Main code """ # connection handler from BMA endpoint - connection = next(BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") diff --git a/examples/send_membership.py b/examples/send_membership.py index cdabad203bd09d5fcabb262431051e4ad1e4e8a6..b1d22ea8ac11c2a182fa542731fb9f952d4d3fa5 100644 --- a/examples/send_membership.py +++ b/examples/send_membership.py @@ -3,7 +3,7 @@ import aiohttp import getpass import duniterpy.api.bma as bma -from duniterpy.documents import BMAEndpoint, BlockUID, Identity, Membership +from duniterpy.documents import BMAEndpoint, SecuredBMAEndpoint, BlockUID, Identity, Membership from duniterpy.key import SigningKey @@ -11,8 +11,8 @@ from duniterpy.key import SigningKey # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] -# Here we use the BASIC_MERKLED_API -BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" +# Here we use the secure BASIC_MERKLED_API (BMAS) +BMA_ENDPOINT = "BMAS g1-test.duniter.org 443" ################################################ @@ -91,12 +91,13 @@ def get_membership_document(mtype, current_block, identity, salt, password): return membership + async def main(): """ Main code """ # connection handler from BMA endpoint - connection = next(BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = next(SecuredBMAEndpoint.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) diff --git a/examples/send_transaction.py b/examples/send_transaction.py index 1fa6d1f4c9c3fe484da11d9676cf64dbdb6dd296..a78f3a3c220342c978a5a9499ed4e7cfc0d5e657 100644 --- a/examples/send_transaction.py +++ b/examples/send_transaction.py @@ -3,7 +3,7 @@ import getpass import aiohttp from duniterpy.api import bma -from duniterpy.documents import BMAEndpoint, BlockUID, Transaction +from duniterpy.documents import BMAEndpoint, SecuredBMAEndpoint, BlockUID, Transaction from duniterpy.documents.transaction import InputSource, OutputSource, Unlock, SIGParameter from duniterpy.grammars.output import Condition, SIG from duniterpy.key import SigningKey @@ -12,8 +12,8 @@ from duniterpy.key import SigningKey # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] -# Here we use the BASIC_MERKLED_API -BMA_ENDPOINT = "BASIC_MERKLED_API g1.duniter.org 10901" +# Here we use the secure BASIC_MERKLED_API (BMAS) +BMA_ENDPOINT = "BMAS g1-test.duniter.org 443" ################################################ @@ -89,12 +89,13 @@ def get_transaction_document(current_block, source, from_pubkey, to_pubkey): return transaction + async def main(): """ Main code """ # connection handler from BMA endpoint - connection = next(BMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) + connection = next(SecuredBMAEndpoint.from_inline(BMA_ENDPOINT).conn_handler(AIOHTTP_SESSION)) # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ")