diff --git a/docs/index.html b/docs/index.html index 2ef63b7..9480559 100644 --- a/docs/index.html +++ b/docs/index.html @@ -57,4 +57,4 @@

Index

Generated by pdoc 0.10.0.

- + \ No newline at end of file diff --git a/docs/simple_sign/index.html b/docs/simple_sign/index.html index d04871a..8f078cf 100644 --- a/docs/simple_sign/index.html +++ b/docs/simple_sign/index.html @@ -28,7 +28,7 @@

Sub-modules

src.simple_sign.sign
-

Python template repository …

+

Orcfax simple sign.

src.simple_sign.version
@@ -67,4 +67,4 @@

Index

Generated by pdoc 0.10.0.

- + \ No newline at end of file diff --git a/docs/simple_sign/sign.html b/docs/simple_sign/sign.html index 0956854..1536e3f 100644 --- a/docs/simple_sign/sign.html +++ b/docs/simple_sign/sign.html @@ -5,7 +5,7 @@ src.simple_sign.sign API documentation - + @@ -22,22 +22,16 @@

Module src.simple_sign.sign

-

Python template repository.

-

Baseline template for future Python code related to this project.

-

Replace this docstring and code below with your own code as required.

+

Orcfax simple sign.

Expand source code -
"""Python template repository.
-
-Baseline template for future Python code related to this project.
-
-Replace this docstring and code below with your own code as required.
-"""
+
"""Orcfax simple sign."""
 
 import argparse
 import logging
+import os
 import sys
 import time
 from typing import Final
@@ -69,6 +63,13 @@ 

Module src.simple_sign.sign

logger = logging.getLogger(__name__) +KNOWN_SIGNERS_CONFIG: Final[str] = "CIP8_NOTARIES" + + +class UnknownSigningKey(Exception): + """Exception to raise when the signing key is unknown.""" + + def signature_in_license_pool(): """Validate whether signing key matches one of those in a pool of licenses associated with the project and return True if so. @@ -83,14 +84,39 @@

Module src.simple_sign.sign

raise NotImplementedError("reading from datum is not yet implemented") -def signature_in_constitution_config(): +def signature_in_constitution_config(pkey: str) -> bool: """Validate whether signing key matches one of those listed in a configuration file. """ - raise NotImplementedError("reading from config is not yet implemented") + raise NotImplementedError( + "reading from a constitution config is not yet implemented" + ) + + +def retrieve_env_notaries() -> list: + """Retrieve notaries from the environment.""" + notaries_env = os.getenv(KNOWN_SIGNERS_CONFIG, "") + if not notaries_env: + return [] + return [notary.strip() for notary in notaries_env.split(",")] + + +def signature_in_dapp_environment(pkey: str) -> bool: + """Validate whether signing key matches one of those configured in + the environment of the dApp. + + Largely a method for early prototyping. This isn't the most secure + approach to doing this and especially not for use in decentralized + systems. This check is only for projects with complete control over + their own project. + """ + notaries = retrieve_env_notaries() + if pkey.strip() not in notaries: + raise UnknownSigningKey(f"{pkey} is an unknown key") + return True -def sign_with_key(data: str, signing_key: str): +def sign_with_key(data: str, signing_key: str) -> str: """Sign with an signing key.""" skey = pyc.SigningKey.from_json(signing_key) vkey = pyc.VerificationKey.from_signing_key(skey) @@ -98,12 +124,12 @@

Module src.simple_sign.sign

return pyc.sign(data, skey) -def signing_handler(data: str, signing_key: str): +def signing_handler(data: str, signing_key: str) -> str: """Handle signing functions.""" return sign_with_key(data, signing_key) -def verify_signature(data: str): +def verify_signature(data: str) -> dict: """Verify a signature with an address.""" try: status = pyc.verify(data) @@ -124,7 +150,7 @@

Module src.simple_sign.sign

} -def verify_handler(data: str): +def verify_handler(data: str) -> dict: """Verify input data.""" return verify_signature(data) @@ -153,6 +179,12 @@

Module src.simple_sign.sign

sign = subparsers.add_parser(arg_sign) subparsers.add_parser(arg_version) verify.add_argument("-d", "--data", type=str, help="data to verify") + verify.add_argument( + "-l", + "--list-env", + action="store_true", + help=f"list known notaries in the environment at {KNOWN_SIGNERS_CONFIG}", + ) sign.add_argument("-d", "--data", type=str, help="data to sign") sign.add_argument("-s", "--signing_key", type=str, help="signing key") args = parser.parse_args() @@ -161,10 +193,19 @@

Module src.simple_sign.sign

sys.exit() if args.cmd == arg_sign: print(signing_handler(args.data, args.signing_key)) - if args.cmd == arg_verify: + if args.cmd == arg_verify and not args.list_env: print(verify_handler(args.data)) if args.cmd == arg_version: print(f"simple-sign version: {get_version()}") + if args.list_env: + notaries = retrieve_env_notaries() + if not notaries: + logger.info( + "no environment notaries, ensuere '%s' is configured", + KNOWN_SIGNERS_CONFIG, + ) + sys.exit() + print(notaries) if __name__ == "__main__": @@ -214,6 +255,12 @@

Functions

sign = subparsers.add_parser(arg_sign) subparsers.add_parser(arg_version) verify.add_argument("-d", "--data", type=str, help="data to verify") + verify.add_argument( + "-l", + "--list-env", + action="store_true", + help=f"list known notaries in the environment at {KNOWN_SIGNERS_CONFIG}", + ) sign.add_argument("-d", "--data", type=str, help="data to sign") sign.add_argument("-s", "--signing_key", type=str, help="signing key") args = parser.parse_args() @@ -222,14 +269,40 @@

Functions

sys.exit() if args.cmd == arg_sign: print(signing_handler(args.data, args.signing_key)) - if args.cmd == arg_verify: + if args.cmd == arg_verify and not args.list_env: print(verify_handler(args.data)) if args.cmd == arg_version: - print(f"simple-sign version: {get_version()}")
+ print(f"simple-sign version: {get_version()}") + if args.list_env: + notaries = retrieve_env_notaries() + if not notaries: + logger.info( + "no environment notaries, ensuere '%s' is configured", + KNOWN_SIGNERS_CONFIG, + ) + sys.exit() + print(notaries)
+
+
+
+def retrieve_env_notaries() ‑> list +
+
+

Retrieve notaries from the environment.

+
+ +Expand source code + +
def retrieve_env_notaries() -> list:
+    """Retrieve notaries from the environment."""
+    notaries_env = os.getenv(KNOWN_SIGNERS_CONFIG, "")
+    if not notaries_env:
+        return []
+    return [notary.strip() for notary in notaries_env.split(",")]
-def sign_with_key(data: str, signing_key: str) +def sign_with_key(data: str, signing_key: str) ‑> str

Sign with an signing key.

@@ -237,7 +310,7 @@

Functions

Expand source code -
def sign_with_key(data: str, signing_key: str):
+
def sign_with_key(data: str, signing_key: str) -> str:
     """Sign with an signing key."""
     skey = pyc.SigningKey.from_json(signing_key)
     vkey = pyc.VerificationKey.from_signing_key(skey)
@@ -246,7 +319,7 @@ 

Functions

-def signature_in_constitution_config() +def signature_in_constitution_config(pkey: str) ‑> bool

Validate whether signing key matches one of those listed in a @@ -255,11 +328,13 @@

Functions

Expand source code -
def signature_in_constitution_config():
+
def signature_in_constitution_config(pkey: str) -> bool:
     """Validate whether signing key matches one of those listed in a
     configuration file.
     """
-    raise NotImplementedError("reading from config is not yet implemented")
+ raise NotImplementedError( + "reading from a constitution config is not yet implemented" + )
@@ -279,6 +354,35 @@

Functions

raise NotImplementedError("reading from datum is not yet implemented")
+
+def signature_in_dapp_environment(pkey: str) ‑> bool +
+
+

Validate whether signing key matches one of those configured in +the environment of the dApp.

+

Largely a method for early prototyping. This isn't the most secure +approach to doing this and especially not for use in decentralized +systems. This check is only for projects with complete control over +their own project.

+
+ +Expand source code + +
def signature_in_dapp_environment(pkey: str) -> bool:
+    """Validate whether signing key matches one of those configured in
+    the environment of the dApp.
+
+    Largely a method for early prototyping. This isn't the most secure
+    approach to doing this and especially not for use in decentralized
+    systems. This check is only for projects with complete control over
+    their own project.
+    """
+    notaries = retrieve_env_notaries()
+    if pkey.strip() not in notaries:
+        raise UnknownSigningKey(f"{pkey} is an unknown key")
+    return True
+
+
def signature_in_license_pool()
@@ -297,7 +401,7 @@

Functions

-def signing_handler(data: str, signing_key: str) +def signing_handler(data: str, signing_key: str) ‑> str

Handle signing functions.

@@ -305,13 +409,13 @@

Functions

Expand source code -
def signing_handler(data: str, signing_key: str):
+
def signing_handler(data: str, signing_key: str) -> str:
     """Handle signing functions."""
     return sign_with_key(data, signing_key)
-def verify_handler(data: str) +def verify_handler(data: str) ‑> dict

Verify input data.

@@ -319,13 +423,13 @@

Functions

Expand source code -
def verify_handler(data: str):
+
def verify_handler(data: str) -> dict:
     """Verify input data."""
     return verify_signature(data)
-def verify_signature(data: str) +def verify_signature(data: str) ‑> dict

Verify a signature with an address.

@@ -333,7 +437,7 @@

Functions

Expand source code -
def verify_signature(data: str):
+
def verify_signature(data: str) -> dict:
     """Verify a signature with an address."""
     try:
         status = pyc.verify(data)
@@ -357,6 +461,28 @@ 

Functions

+

Classes

+
+
+class UnknownSigningKey +(*args, **kwargs) +
+
+

Exception to raise when the signing key is unknown.

+
+ +Expand source code + +
class UnknownSigningKey(Exception):
+    """Exception to raise when the signing key is unknown."""
+
+

Ancestors

+
    +
  • builtins.Exception
  • +
  • builtins.BaseException
  • +
+
+
@@ -389,4 +524,4 @@

Index

Generated by pdoc 0.10.0.

- + \ No newline at end of file diff --git a/docs/simple_sign/version.html b/docs/simple_sign/version.html index 647f3b6..a6c5d50 100644 --- a/docs/simple_sign/version.html +++ b/docs/simple_sign/version.html @@ -98,4 +98,4 @@

Index

Generated by pdoc 0.10.0.

- + \ No newline at end of file