diff --git a/docs/simple_sign/backend.html b/docs/simple_sign/backend.html new file mode 100644 index 0000000..96da247 --- /dev/null +++ b/docs/simple_sign/backend.html @@ -0,0 +1,818 @@ + + + + + + +src.simple_sign.backend API documentation + + + + + + + + + + + +
+
+
+

Module src.simple_sign.backend

+
+
+

Cardano handlers.

+

This is very much a work in progress aimed at a very small dApp where +the anticipated amount of data to be returned for a query is very +small. The concept of a backend is not really fleshed out either and +so remains unexported until an interface is implemented or some other +useful/interesting concept.

+
+ +Expand source code + +
"""Cardano handlers.
+
+This is very much a work in progress aimed at a very small dApp where
+the anticipated amount of data to be returned for a query is very
+small. The concept of a backend is not really fleshed out either and
+so remains unexported until an interface is implemented or some other
+useful/interesting concept.
+"""
+
+import logging
+from dataclasses import dataclass
+from typing import Callable, Final
+
+import cachetools.func
+import pycardano as pyc
+import pydantic
+import requests
+
+
+@dataclass
+class ValidTx:
+    slot: int
+    tx_id: str
+    address: str
+    staking: str
+
+
+logger = logging.getLogger(__name__)
+
+BACKENDS: Final[list] = ["kupo"]
+
+
+def _sum_dict(key: str, value: int, accumulator: dict):
+    """Increment values in a given dictionary"""
+    if key not in accumulator:
+        accumulator[key] = value
+        return accumulator
+    count = accumulator[key]
+    count = count + value
+    accumulator[key] = count
+    return accumulator
+
+
+def _get_staking_from_addr(addr: str) -> str:
+    """Return a staking address if possible from a given address,
+    otherwise, return the original address string.
+    """
+    try:
+        address = pyc.Address.from_primitive(addr)
+        return str(
+            pyc.Address(staking_part=address.staking_part, network=pyc.Network.MAINNET)
+        )
+    except pyc.exception.InvalidAddressInputException:
+        return str(address)
+    except TypeError as err:
+        logger.error("cannot convert '%s' (%s)", addr, err)
+        return str(addr)
+
+
+class BackendContext:
+    """Backend interfaces.
+
+    NB. this will probably prove to be a naive implementation of this
+    sort of thing, but lets see. Learning from PyCardano.
+    """
+
+    def _retrieve_unspent_utxos(self) -> dict:
+        """Retrieve unspent utxos from the backend."""
+        raise NotImplementedError()
+
+    def retrieve_staked_holders(self, token_policy: str) -> list:
+        """Retrieve a list of staked holders against a given CNT."""
+        raise NotImplementedError()
+
+    def retrieve_nft_holders(
+        self, policy: str, deny_list: list, seek_addr: str = None
+    ) -> list:
+        """Retrieve a list of NFT holders, e.g. a license to operate
+        a decentralized node.
+        """
+        raise NotImplementedError()
+
+    def retrieve_metadata(
+        self, value: int, policy: str, tag: str, callback: Callable = None
+    ) -> list:
+        """Retrieve metadata from the backend."""
+        raise NotImplementedError()
+
+
+class KupoContext(BackendContext):
+    """Kupo backend."""
+
+    def __init__(
+        self,
+        base_url: str,
+        port: int,
+    ):
+        """Initialize this thing..."""
+        self._base_url = base_url
+        self._port = port
+
+    @cachetools.func.ttl_cache(ttl=60)
+    def _retrieve_unspent_utxos(self, addr: str = "") -> dict:
+        """Retrieve unspent utxos from Kupo.
+
+        NB. Kupo must be configured to capture sparingly.
+        """
+        if not addr:
+            resp = requests.get(
+                f"{self._base_url}:{self._port}/matches?unspent", timeout=30
+            )
+            return resp.json()
+        resp = requests.get(
+            f"{self._base_url}:{self._port}/matches/{addr}?unspent", timeout=30
+        )
+        return resp.json()
+
+    def _retrieve_metadata(self, tag: str, tx_list: list[ValidTx]):
+        """Return metadata based on slot and transaction ID. This is
+        very much a Kupo-centric approach. Metadata is not indexed
+        locally and instead needs to be retrieved directly from
+        a node.
+
+        IMPORTANT: The metadata is modified here to provide information
+        about the source address. This is so that the data remains
+        accurately coupled with what is retrieved. We can't do this
+        with Kupo easily otherwise.
+        """
+        md_list = []
+        for tx in tx_list:
+            resp = requests.get(
+                f"{self._base_url}:{self._port}/metadata/{tx.slot}?transaction_id={tx.tx_id}",
+                timeout=30,
+            )
+            if not resp.json():
+                return md_list
+            md_dict = resp.json()
+            try:
+                _ = md_dict[0]["schema"][tag]
+            except (IndexError, KeyError):
+                return md_list
+            md_dict[0]["address"] = tx.address
+            md_dict[0]["staking"] = tx.staking
+            md_dict[0]["transaction"] = tx.tx_id
+            md_list.append(md_dict[0])
+        return md_list
+
+    def retrieve_staked_holders(self, token_policy: str, seek_addr: str = None) -> list:
+        """Retrieve a list of staked holders against a given CNT."""
+        unspent = self._retrieve_unspent_utxos()
+        addresses_with_fact = {}
+        for item in unspent:
+            addr = item["address"]
+            if seek_addr and addr != seek_addr:
+                # don't process further than we have to if we're only
+                # looking for a single address.
+                continue
+            staking = _get_staking_from_addr(addr)
+            assets = item["value"]["assets"]
+            for key, value in assets.items():
+                if token_policy in key:
+                    addresses_with_fact = _sum_dict(staking, value, addresses_with_fact)
+        return addresses_with_fact
+
+    def retrieve_nft_holders(
+        self, policy: str, deny_list: list = None, seek_addr: str = None
+    ) -> list:
+        """Retrieve a list of NFT holders, e.g. a license to operate
+        a decentralized node.
+
+        Filtering can be performed elsewhere, but a deny_list is used
+        to remove some results that are unhelpful, e.g. the minting
+        address if desired.
+        """
+        unspent = self._retrieve_unspent_utxos()
+        holders = {}
+        for item in unspent:
+            addr = item["address"]
+            if seek_addr and addr != seek_addr:
+                # don't process further than we have to if we're only
+                # looking for a single address.
+                continue
+            staking = _get_staking_from_addr(addr)
+            if addr in deny_list:
+                continue
+            assets = item["value"]["assets"]
+            for key, _ in assets.items():
+                if not key.startswith(policy):
+                    continue
+                holders[key] = staking
+        return holders
+
+    @staticmethod
+    def _get_valid_txs(unspent: list[dict], value: int, policy: str) -> list[ValidTx]:
+        """Retrieve a list of valid transactions according to our
+        policy rules.
+        """
+        valid_txs = []
+        if not unspent:
+            return valid_txs
+        for item in unspent:
+            coins = item["value"]["coins"]
+            if coins != value:
+                continue
+            assets = item["value"]["assets"]
+            for asset in assets:
+                if policy not in asset:
+                    continue
+                logger.error(policy)
+                slot = item["created_at"]["slot_no"]
+                tx_id = item["transaction_id"]
+                address = item["address"]
+                valid_tx = ValidTx(
+                    slot=slot,
+                    tx_id=tx_id,
+                    address=address,
+                    staking=_get_staking_from_addr(address),
+                )
+                valid_txs.append(valid_tx)
+        return valid_txs
+
+    @pydantic.validate_call()
+    def retrieve_metadata(
+        self,
+        value: int,
+        policy: str,
+        tag: str,
+        callback: Callable = None,
+    ) -> list:
+        """Retrieve a list of aliased signing addresses. An aliased
+        signing address is an address that has been setup using a
+        protocol that allows NFT holders to participate in a network
+        without having the key to their primary wallets hot/live on the
+        decentralized node that they are operating.
+
+        Kupo queries involved:
+
+        ```sh
+            curl -s "http://0.0.0.0:1442/matches?unspent"
+            curl -s "http://0.0.0.0:1442/metadata/{slot_id}?transaction_id={}"
+        ```
+
+        Strategy 1: Retrieve all aliased keys for a policy ID.
+                    Capture all values that match.
+                    Capture all slots and tx ids for those values.
+                    Retrieve metadata for all those txs.
+                    Augment metadata with address and staking address.
+                    Optionally, use the callback to process the data
+                    according to a set of rules.
+                    Return the metadata or a list of processed values to
+                    the caller.
+
+        NB. the callback must return a list to satisfy the output of the
+        primary function.
+
+        NB. this function is not as generic as it could be.
+
+        """
+        unspent = self._retrieve_unspent_utxos()
+        valid_txs = self._get_valid_txs(unspent, value, policy)
+        if not valid_txs:
+            return valid_txs
+        md = self._retrieve_metadata(tag, valid_txs)
+        if not callback:
+            return md
+        return callback(md)
+
+
+
+
+
+
+
+
+
+

Classes

+
+
+class BackendContext +
+
+

Backend interfaces.

+

NB. this will probably prove to be a naive implementation of this +sort of thing, but lets see. Learning from PyCardano.

+
+ +Expand source code + +
class BackendContext:
+    """Backend interfaces.
+
+    NB. this will probably prove to be a naive implementation of this
+    sort of thing, but lets see. Learning from PyCardano.
+    """
+
+    def _retrieve_unspent_utxos(self) -> dict:
+        """Retrieve unspent utxos from the backend."""
+        raise NotImplementedError()
+
+    def retrieve_staked_holders(self, token_policy: str) -> list:
+        """Retrieve a list of staked holders against a given CNT."""
+        raise NotImplementedError()
+
+    def retrieve_nft_holders(
+        self, policy: str, deny_list: list, seek_addr: str = None
+    ) -> list:
+        """Retrieve a list of NFT holders, e.g. a license to operate
+        a decentralized node.
+        """
+        raise NotImplementedError()
+
+    def retrieve_metadata(
+        self, value: int, policy: str, tag: str, callback: Callable = None
+    ) -> list:
+        """Retrieve metadata from the backend."""
+        raise NotImplementedError()
+
+

Subclasses

+ +

Methods

+
+
+def retrieve_metadata(self, value: int, policy: str, tag: str, callback: Callable = None) ‑> list +
+
+

Retrieve metadata from the backend.

+
+ +Expand source code + +
def retrieve_metadata(
+    self, value: int, policy: str, tag: str, callback: Callable = None
+) -> list:
+    """Retrieve metadata from the backend."""
+    raise NotImplementedError()
+
+
+
+def retrieve_nft_holders(self, policy: str, deny_list: list, seek_addr: str = None) ‑> list +
+
+

Retrieve a list of NFT holders, e.g. a license to operate +a decentralized node.

+
+ +Expand source code + +
def retrieve_nft_holders(
+    self, policy: str, deny_list: list, seek_addr: str = None
+) -> list:
+    """Retrieve a list of NFT holders, e.g. a license to operate
+    a decentralized node.
+    """
+    raise NotImplementedError()
+
+
+
+def retrieve_staked_holders(self, token_policy: str) ‑> list +
+
+

Retrieve a list of staked holders against a given CNT.

+
+ +Expand source code + +
def retrieve_staked_holders(self, token_policy: str) -> list:
+    """Retrieve a list of staked holders against a given CNT."""
+    raise NotImplementedError()
+
+
+
+
+
+class KupoContext +(base_url: str, port: int) +
+
+

Kupo backend.

+

Initialize this thing…

+
+ +Expand source code + +
class KupoContext(BackendContext):
+    """Kupo backend."""
+
+    def __init__(
+        self,
+        base_url: str,
+        port: int,
+    ):
+        """Initialize this thing..."""
+        self._base_url = base_url
+        self._port = port
+
+    @cachetools.func.ttl_cache(ttl=60)
+    def _retrieve_unspent_utxos(self, addr: str = "") -> dict:
+        """Retrieve unspent utxos from Kupo.
+
+        NB. Kupo must be configured to capture sparingly.
+        """
+        if not addr:
+            resp = requests.get(
+                f"{self._base_url}:{self._port}/matches?unspent", timeout=30
+            )
+            return resp.json()
+        resp = requests.get(
+            f"{self._base_url}:{self._port}/matches/{addr}?unspent", timeout=30
+        )
+        return resp.json()
+
+    def _retrieve_metadata(self, tag: str, tx_list: list[ValidTx]):
+        """Return metadata based on slot and transaction ID. This is
+        very much a Kupo-centric approach. Metadata is not indexed
+        locally and instead needs to be retrieved directly from
+        a node.
+
+        IMPORTANT: The metadata is modified here to provide information
+        about the source address. This is so that the data remains
+        accurately coupled with what is retrieved. We can't do this
+        with Kupo easily otherwise.
+        """
+        md_list = []
+        for tx in tx_list:
+            resp = requests.get(
+                f"{self._base_url}:{self._port}/metadata/{tx.slot}?transaction_id={tx.tx_id}",
+                timeout=30,
+            )
+            if not resp.json():
+                return md_list
+            md_dict = resp.json()
+            try:
+                _ = md_dict[0]["schema"][tag]
+            except (IndexError, KeyError):
+                return md_list
+            md_dict[0]["address"] = tx.address
+            md_dict[0]["staking"] = tx.staking
+            md_dict[0]["transaction"] = tx.tx_id
+            md_list.append(md_dict[0])
+        return md_list
+
+    def retrieve_staked_holders(self, token_policy: str, seek_addr: str = None) -> list:
+        """Retrieve a list of staked holders against a given CNT."""
+        unspent = self._retrieve_unspent_utxos()
+        addresses_with_fact = {}
+        for item in unspent:
+            addr = item["address"]
+            if seek_addr and addr != seek_addr:
+                # don't process further than we have to if we're only
+                # looking for a single address.
+                continue
+            staking = _get_staking_from_addr(addr)
+            assets = item["value"]["assets"]
+            for key, value in assets.items():
+                if token_policy in key:
+                    addresses_with_fact = _sum_dict(staking, value, addresses_with_fact)
+        return addresses_with_fact
+
+    def retrieve_nft_holders(
+        self, policy: str, deny_list: list = None, seek_addr: str = None
+    ) -> list:
+        """Retrieve a list of NFT holders, e.g. a license to operate
+        a decentralized node.
+
+        Filtering can be performed elsewhere, but a deny_list is used
+        to remove some results that are unhelpful, e.g. the minting
+        address if desired.
+        """
+        unspent = self._retrieve_unspent_utxos()
+        holders = {}
+        for item in unspent:
+            addr = item["address"]
+            if seek_addr and addr != seek_addr:
+                # don't process further than we have to if we're only
+                # looking for a single address.
+                continue
+            staking = _get_staking_from_addr(addr)
+            if addr in deny_list:
+                continue
+            assets = item["value"]["assets"]
+            for key, _ in assets.items():
+                if not key.startswith(policy):
+                    continue
+                holders[key] = staking
+        return holders
+
+    @staticmethod
+    def _get_valid_txs(unspent: list[dict], value: int, policy: str) -> list[ValidTx]:
+        """Retrieve a list of valid transactions according to our
+        policy rules.
+        """
+        valid_txs = []
+        if not unspent:
+            return valid_txs
+        for item in unspent:
+            coins = item["value"]["coins"]
+            if coins != value:
+                continue
+            assets = item["value"]["assets"]
+            for asset in assets:
+                if policy not in asset:
+                    continue
+                logger.error(policy)
+                slot = item["created_at"]["slot_no"]
+                tx_id = item["transaction_id"]
+                address = item["address"]
+                valid_tx = ValidTx(
+                    slot=slot,
+                    tx_id=tx_id,
+                    address=address,
+                    staking=_get_staking_from_addr(address),
+                )
+                valid_txs.append(valid_tx)
+        return valid_txs
+
+    @pydantic.validate_call()
+    def retrieve_metadata(
+        self,
+        value: int,
+        policy: str,
+        tag: str,
+        callback: Callable = None,
+    ) -> list:
+        """Retrieve a list of aliased signing addresses. An aliased
+        signing address is an address that has been setup using a
+        protocol that allows NFT holders to participate in a network
+        without having the key to their primary wallets hot/live on the
+        decentralized node that they are operating.
+
+        Kupo queries involved:
+
+        ```sh
+            curl -s "http://0.0.0.0:1442/matches?unspent"
+            curl -s "http://0.0.0.0:1442/metadata/{slot_id}?transaction_id={}"
+        ```
+
+        Strategy 1: Retrieve all aliased keys for a policy ID.
+                    Capture all values that match.
+                    Capture all slots and tx ids for those values.
+                    Retrieve metadata for all those txs.
+                    Augment metadata with address and staking address.
+                    Optionally, use the callback to process the data
+                    according to a set of rules.
+                    Return the metadata or a list of processed values to
+                    the caller.
+
+        NB. the callback must return a list to satisfy the output of the
+        primary function.
+
+        NB. this function is not as generic as it could be.
+
+        """
+        unspent = self._retrieve_unspent_utxos()
+        valid_txs = self._get_valid_txs(unspent, value, policy)
+        if not valid_txs:
+            return valid_txs
+        md = self._retrieve_metadata(tag, valid_txs)
+        if not callback:
+            return md
+        return callback(md)
+
+

Ancestors

+ +

Methods

+
+
+def retrieve_metadata(self, value: int, policy: str, tag: str, callback: Callable = None) ‑> list +
+
+

Retrieve a list of aliased signing addresses. An aliased +signing address is an address that has been setup using a +protocol that allows NFT holders to participate in a network +without having the key to their primary wallets hot/live on the +decentralized node that they are operating.

+

Kupo queries involved:

+
    curl -s "http://0.0.0.0:1442/matches?unspent"
+    curl -s "http://0.0.0.0:1442/metadata/{slot_id}?transaction_id={}"
+
+

Strategy 1: Retrieve all aliased keys for a policy ID. +Capture all values that match. +Capture all slots and tx ids for those values. +Retrieve metadata for all those txs. +Augment metadata with address and staking address. +Optionally, use the callback to process the data +according to a set of rules. +Return the metadata or a list of processed values to +the caller.

+

NB. the callback must return a list to satisfy the output of the +primary function.

+

NB. this function is not as generic as it could be.

+
+ +Expand source code + +
@pydantic.validate_call()
+def retrieve_metadata(
+    self,
+    value: int,
+    policy: str,
+    tag: str,
+    callback: Callable = None,
+) -> list:
+    """Retrieve a list of aliased signing addresses. An aliased
+    signing address is an address that has been setup using a
+    protocol that allows NFT holders to participate in a network
+    without having the key to their primary wallets hot/live on the
+    decentralized node that they are operating.
+
+    Kupo queries involved:
+
+    ```sh
+        curl -s "http://0.0.0.0:1442/matches?unspent"
+        curl -s "http://0.0.0.0:1442/metadata/{slot_id}?transaction_id={}"
+    ```
+
+    Strategy 1: Retrieve all aliased keys for a policy ID.
+                Capture all values that match.
+                Capture all slots and tx ids for those values.
+                Retrieve metadata for all those txs.
+                Augment metadata with address and staking address.
+                Optionally, use the callback to process the data
+                according to a set of rules.
+                Return the metadata or a list of processed values to
+                the caller.
+
+    NB. the callback must return a list to satisfy the output of the
+    primary function.
+
+    NB. this function is not as generic as it could be.
+
+    """
+    unspent = self._retrieve_unspent_utxos()
+    valid_txs = self._get_valid_txs(unspent, value, policy)
+    if not valid_txs:
+        return valid_txs
+    md = self._retrieve_metadata(tag, valid_txs)
+    if not callback:
+        return md
+    return callback(md)
+
+
+
+def retrieve_nft_holders(self, policy: str, deny_list: list = None, seek_addr: str = None) ‑> list +
+
+

Retrieve a list of NFT holders, e.g. a license to operate +a decentralized node.

+

Filtering can be performed elsewhere, but a deny_list is used +to remove some results that are unhelpful, e.g. the minting +address if desired.

+
+ +Expand source code + +
def retrieve_nft_holders(
+    self, policy: str, deny_list: list = None, seek_addr: str = None
+) -> list:
+    """Retrieve a list of NFT holders, e.g. a license to operate
+    a decentralized node.
+
+    Filtering can be performed elsewhere, but a deny_list is used
+    to remove some results that are unhelpful, e.g. the minting
+    address if desired.
+    """
+    unspent = self._retrieve_unspent_utxos()
+    holders = {}
+    for item in unspent:
+        addr = item["address"]
+        if seek_addr and addr != seek_addr:
+            # don't process further than we have to if we're only
+            # looking for a single address.
+            continue
+        staking = _get_staking_from_addr(addr)
+        if addr in deny_list:
+            continue
+        assets = item["value"]["assets"]
+        for key, _ in assets.items():
+            if not key.startswith(policy):
+                continue
+            holders[key] = staking
+    return holders
+
+
+
+

Inherited members

+ +
+
+class ValidTx +(slot: int, tx_id: str, address: str, staking: str) +
+
+

ValidTx(slot: int, tx_id: str, address: str, staking: str)

+
+ +Expand source code + +
@dataclass
+class ValidTx:
+    slot: int
+    tx_id: str
+    address: str
+    staking: str
+
+

Class variables

+
+
var address : str
+
+
+
+
var slot : int
+
+
+
+
var staking : str
+
+
+
+
var tx_id : str
+
+
+
+
+
+
+
+
+ +
+ + + \ No newline at end of file diff --git a/docs/simple_sign/index.html b/docs/simple_sign/index.html index f72ad6c..80f04ff 100644 --- a/docs/simple_sign/index.html +++ b/docs/simple_sign/index.html @@ -26,10 +26,18 @@

Module src.simple_sign

Sub-modules

+
src.simple_sign.backend
+
+

Cardano handlers …

+
src.simple_sign.sign

Orcfax simple sign.

+
src.simple_sign.types
+
+

Simple-sign data types

+
src.simple_sign.version

Simple sign version.

@@ -56,7 +64,9 @@

Index

  • Sub-modules

  • diff --git a/docs/simple_sign/sign.html b/docs/simple_sign/sign.html index 618ad69..272259c 100644 --- a/docs/simple_sign/sign.html +++ b/docs/simple_sign/sign.html @@ -29,6 +29,8 @@

    Module src.simple_sign.sign

    """Orcfax simple sign."""
     
    +# pylint: disable=W0613
    +
     import argparse
     import logging
     import os
    @@ -64,20 +66,47 @@ 

    Module src.simple_sign.sign

    KNOWN_SIGNERS_CONFIG: Final[str] = "CIP8_NOTARIES" +KUPO_URL: Final[str] = "KUPO_URL_NOTARIES" class UnknownSigningKey(Exception): """Exception to raise when the signing key is unknown.""" -def signature_in_license_pool(): +def retrieve_aliased(pkey: str) -> str: + """Retrieve another public key aliased by the given lookup. + + The result might then be used to verify using one of the other + methods in this library, e.g. + + 1. lookup aliased staking key. + 2. lookup staking key in license pool. + 3. if not exists, raise exception, else, pass. + + We want to do this on an address by address basis. The difficulty + is consistent parsing of metadata that allows this function to be + broadly applicable across functions. + """ + raise NotImplementedError("reading staked values is not yet implemented") + + +def signature_belongs_to_staked_pool( + pkey: str, token_policy_id: str, min_stake: int +) -> bool: + """Validate whether the signing key belongs to a someone who has + enough stake in a given token. + """ + raise NotImplementedError("reading staked values is not yet implemented") + + +def signature_in_license_pool(pkey: str, policy_id: str) -> bool: """Validate whether signing key matches one of those in a pool of licenses associated with the project and return True if so. """ raise NotImplementedError("reading from license pool is not yet implemented") -def signature_in_constitution_datum_utxo(): +def signature_in_constitution_datum_utxo(pkey: str) -> bool: """Validate whether signing key matches one of those a list of addresses in a given constitution UTxO. """ @@ -174,7 +203,6 @@

    Module src.simple_sign.sign

    epilog="for more information visit https://orcfax.io/", ) subparsers = parser.add_subparsers(dest="cmd") - subparsers.add_parser(arg_sign) verify = subparsers.add_parser(arg_verify) sign = subparsers.add_parser(arg_sign) subparsers.add_parser(arg_version) @@ -194,14 +222,17 @@

    Module src.simple_sign.sign

    if args.cmd == arg_sign: print(signing_handler(args.data, args.signing_key)) if args.cmd == arg_verify and not args.list_env: + if not args.data: + logger.error("supply data with the `-d` flag") + sys.exit() print(verify_handler(args.data)) if args.cmd == arg_version: print(f"simple-sign version: {get_version()}") - if args.list_env: + if args.cmd == "verify" and args.list_env: notaries = retrieve_env_notaries() if not notaries: logger.info( - "no environment notaries, ensuere '%s' is configured", + "no environment notaries, ensure '%s' is configured", KNOWN_SIGNERS_CONFIG, ) sys.exit() @@ -250,7 +281,6 @@

    Functions

    epilog="for more information visit https://orcfax.io/", ) subparsers = parser.add_subparsers(dest="cmd") - subparsers.add_parser(arg_sign) verify = subparsers.add_parser(arg_verify) sign = subparsers.add_parser(arg_sign) subparsers.add_parser(arg_version) @@ -270,20 +300,59 @@

    Functions

    if args.cmd == arg_sign: print(signing_handler(args.data, args.signing_key)) if args.cmd == arg_verify and not args.list_env: + if not args.data: + logger.error("supply data with the `-d` flag") + sys.exit() print(verify_handler(args.data)) if args.cmd == arg_version: print(f"simple-sign version: {get_version()}") - if args.list_env: + if args.cmd == "verify" and args.list_env: notaries = retrieve_env_notaries() if not notaries: logger.info( - "no environment notaries, ensuere '%s' is configured", + "no environment notaries, ensure '%s' is configured", KNOWN_SIGNERS_CONFIG, ) sys.exit() print(notaries)
    +
    +def retrieve_aliased(pkey: str) ‑> str +
    +
    +

    Retrieve another public key aliased by the given lookup.

    +

    The result might then be used to verify using one of the other +methods in this library, e.g.

    +
      +
    1. lookup aliased staking key.
    2. +
    3. lookup staking key in license pool.
    4. +
    5. if not exists, raise exception, else, pass.
    6. +
    +

    We want to do this on an address by address basis. The difficulty +is consistent parsing of metadata that allows this function to be +broadly applicable across functions.

    +
    + +Expand source code + +
    def retrieve_aliased(pkey: str) -> str:
    +    """Retrieve another public key aliased by the given lookup.
    +
    +    The result might then be used to verify using one of the other
    +    methods in this library, e.g.
    +
    +    1. lookup aliased staking key.
    +    2. lookup staking key in license pool.
    +    3. if not exists, raise exception, else, pass.
    +
    +    We want to do this on an address by address basis. The difficulty
    +    is consistent parsing of metadata that allows this function to be
    +    broadly applicable across functions.
    +    """
    +    raise NotImplementedError("reading staked values is not yet implemented")
    +
    +
    def retrieve_env_notaries() ‑> list
    @@ -318,6 +387,25 @@

    Functions

    return pyc.sign(data, skey) +
    +def signature_belongs_to_staked_pool(pkey: str, token_policy_id: str, min_stake: int) ‑> bool +
    +
    +

    Validate whether the signing key belongs to a someone who has +enough stake in a given token.

    +
    + +Expand source code + +
    def signature_belongs_to_staked_pool(
    +    pkey: str, token_policy_id: str, min_stake: int
    +) -> bool:
    +    """Validate whether the signing key belongs to a someone who has
    +    enough stake in a given token.
    +    """
    +    raise NotImplementedError("reading staked values is not yet implemented")
    +
    +
    def signature_in_constitution_config(pkey: str) ‑> bool
    @@ -338,7 +426,7 @@

    Functions

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

    Validate whether signing key matches one of those a list of @@ -347,7 +435,7 @@

    Functions

    Expand source code -
    def signature_in_constitution_datum_utxo():
    +
    def signature_in_constitution_datum_utxo(pkey: str) -> bool:
         """Validate whether signing key matches one of those a list of
         addresses in a given constitution UTxO.
         """
    @@ -384,7 +472,7 @@ 

    Functions

    -def signature_in_license_pool() +def signature_in_license_pool(pkey: str, policy_id: str) ‑> bool

    Validate whether signing key matches one of those in a pool of @@ -393,7 +481,7 @@

    Functions

    Expand source code -
    def signature_in_license_pool():
    +
    def signature_in_license_pool(pkey: str, policy_id: str) -> bool:
         """Validate whether signing key matches one of those in a pool of
         licenses associated with the project and return True if so.
         """
    @@ -499,8 +587,10 @@ 

    Index

  • Functions

    • main
    • +
    • retrieve_aliased
    • retrieve_env_notaries
    • sign_with_key
    • +
    • signature_belongs_to_staked_pool
    • signature_in_constitution_config
    • signature_in_constitution_datum_utxo
    • signature_in_dapp_environment
    • diff --git a/docs/simple_sign/types.html b/docs/simple_sign/types.html new file mode 100644 index 0000000..958298b --- /dev/null +++ b/docs/simple_sign/types.html @@ -0,0 +1,123 @@ + + + + + + +src.simple_sign.types API documentation + + + + + + + + + + + +
      +
      +
      +

      Module src.simple_sign.types

      +
      +
      +

      Simple-sign data types

      +
      + +Expand source code + +
      """Simple-sign data types"""
      +
      +from dataclasses import dataclass
      +
      +
      +@dataclass
      +class Alias:
      +    alias: str
      +    address: str
      +    staking: str
      +    tx: str
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class Alias +(alias: str, address: str, staking: str, tx: str) +
      +
      +

      Alias(alias: str, address: str, staking: str, tx: str)

      +
      + +Expand source code + +
      @dataclass
      +class Alias:
      +    alias: str
      +    address: str
      +    staking: str
      +    tx: str
      +
      +

      Class variables

      +
      +
      var address : str
      +
      +
      +
      +
      var alias : str
      +
      +
      +
      +
      var staking : str
      +
      +
      +
      +
      var tx : str
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      + + + \ No newline at end of file