oli-python
Advanced tools
| Metadata-Version: 2.4 | ||
| Name: oli-python | ||
| Version: 2.0.5 | ||
| Version: 2.0.6 | ||
| Summary: Python SDK for interacting with the Open Labels Initiative; A standard, registry and trust layer for EVM address labels. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/openlabelsinitiative/oli-python |
@@ -44,8 +44,11 @@ import time | ||
| # Merge chain_id (CAIP2) & address to CAIP10 format | ||
| caip10 = f"{chain_id}:{address}" | ||
| # Encode the label data | ||
| data = self.oli.utils_other.encode_label_data(chain_id, tags) | ||
| data = self.oli.utils_other.encode_label_data(caip10, tags) | ||
| # Build the attestation | ||
| attestation = self.build_offchain_attestation( | ||
| recipient=address, | ||
| recipient="0x0000000000000000000000000000000000000001", # use 0x...1 to track python tooling was used | ||
| schema=self.oli.oli_label_pool_schema, | ||
@@ -112,8 +115,11 @@ data=data, | ||
| # Merge chain_id (CAIP2) & address to CAIP10 format | ||
| caip10 = f"{chain_id}:{address}" | ||
| # Encode the label data | ||
| data = self.oli.utils_other.encode_label_data(chain_id, tags) | ||
| data = self.oli.utils_other.encode_label_data(caip10, tags) | ||
| # Build the attestation | ||
| attestation = self.build_offchain_attestation( | ||
| recipient=address, | ||
| recipient="0x0000000000000000000000000000000000000001", # use 0x...1 to track python tooling was used | ||
| schema=self.oli.oli_label_pool_schema, | ||
@@ -169,6 +175,5 @@ data=data, | ||
| # Build the attestation | ||
| recipient = "0x0000000000000000000000000000000000000000" | ||
| ref_uid = "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
| attestation = self.build_offchain_attestation( | ||
| recipient=recipient, | ||
| recipient="0x0000000000000000000000000000000000000001", # use 0x...1 to track python tooling was used | ||
| schema=self.oli.oli_label_trust_schema, | ||
@@ -175,0 +180,0 @@ data=data, |
@@ -21,3 +21,3 @@ class OnchainAttestations: | ||
| ref_uid (str): Reference UID | ||
| gas_limit (int): Gas limit for the transaction. If set to -1, the function will estimate the gas limit. | ||
| gas_limit (int): Gas limit for the transaction. If set to -1, the function will estimate the gas limit | ||
@@ -40,4 +40,7 @@ Returns: | ||
| # Prepare CAIP10 format for the address | ||
| caip10 = f"{chain_id}:{address}" | ||
| # Encode the label data | ||
| data = self.oli.utils_other.encode_label_data(chain_id, tags) | ||
| data = self.oli.utils_other.encode_label_data(caip10, tags) | ||
@@ -48,3 +51,3 @@ # Create the attestation | ||
| 'data': { | ||
| 'recipient': self.oli.w3.to_checksum_address(address), | ||
| 'recipient': "0x0000000000000000000000000000000000000001", # use 0x...1 to track python tooling was used | ||
| 'expirationTime': 0, | ||
@@ -134,6 +137,9 @@ 'revocable': True, | ||
| # Merge chain_id (CAIP2) & address to CAIP10 format | ||
| caip10 = f"{label['chain_id']}:{label['address']}" | ||
| # ABI encode data for each attestation | ||
| data = self.oli.utils_other.encode_label_data(label['chain_id'], label['tags']) | ||
| data = self.oli.utils_other.encode_label_data(caip10, label['tags']) | ||
| full_data.append({ | ||
| 'recipient': self.oli.w3.to_checksum_address(label['address']), | ||
| 'recipient': "0x0000000000000000000000000000000000000001", # use 0x...1 to track python tooling was used | ||
| 'expirationTime': 0, | ||
@@ -213,3 +219,3 @@ 'revocable': True, | ||
| 'data': { | ||
| 'recipient': "0x0000000000000000000000000000000000000000", # Trust lists are not tied to a specific address | ||
| 'recipient': "0x0000000000000000000000000000000000000001", # Trust lists are not tied to a specific address, use 0x...1 to track python tooling was used | ||
| 'expirationTime': 0, # never expires | ||
@@ -216,0 +222,0 @@ 'revocable': True, # can be revoked |
@@ -16,3 +16,3 @@ import json | ||
| def encode_label_data(self, chain_id: str, tags_json: dict) -> str: | ||
| def encode_label_data(self, caip10: str, tags_json: dict) -> str: | ||
| """ | ||
@@ -22,3 +22,3 @@ Encode label data in the OLI format. | ||
| Args: | ||
| chain_id (str): Chain ID in CAIP-2 format of the label (e.g. 'eip155:8453') | ||
| caip10 (str): address and chain_id in caip10 format (e.g. 'eip155:8453:0x3Ae5F83668B75328446c649B6ab342aC46D73B3c') | ||
| tags_json (dict): Dictionary of tag data following the OLI format | ||
@@ -32,5 +32,11 @@ | ||
| tags_json = json.dumps(tags_json) | ||
| # Convert address to checksum if possible | ||
| try: | ||
| caip10 = caip10[:caip10.rfind(":")+1] + self.oli.w3.to_checksum_address(caip10.split(":")[-1]) | ||
| except: | ||
| pass | ||
| # ABI encode the data | ||
| encoded_data = encode(['string', 'string'], [chain_id, tags_json]) | ||
| encoded_data = encode(['string', 'string'], [caip10, tags_json]) | ||
| return f"0x{encoded_data.hex()}" | ||
@@ -37,0 +43,0 @@ |
@@ -10,10 +10,2 @@ class UtilsValidator: | ||
| self.oli = oli_client | ||
| self.allowed_prefixes = [ | ||
| 'eip155:', # Ethereum and EVM-compatible chains | ||
| 'solana:', # Solana | ||
| 'tron:', # TRON | ||
| 'stellar:', # Stellar | ||
| 'bip122:', # Bitcoin | ||
| 'SN_MAIN' # Starknet | ||
| ] | ||
| # URLs for helpful resources | ||
@@ -25,2 +17,3 @@ self.url_1_label_schema = "https://github.com/openlabelsinitiative/OLI/tree/main/1_label_schema" | ||
| self.url_caip2_format = "https://docs.portalhq.io/resources/chain-id-formatting" | ||
| self.url_caip10_format = "https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md" | ||
@@ -102,3 +95,3 @@ def fix_simple_tags_formatting(self, tags: dict) -> dict: | ||
| Args: | ||
| address (str): Address to check | ||
| address (str): Address that is labelled to check | ||
| chain_id (str): Chain ID to check | ||
@@ -113,3 +106,3 @@ tags (dict): Tags to check | ||
| # basic checks | ||
| self.validate_address(address) | ||
| self.validate_address_to_be_labelled(address) | ||
| self.validate_chain_id(chain_id) | ||
@@ -152,21 +145,21 @@ self.validate_tags(tags, auto_fix=auto_fix) | ||
| """ | ||
| # Check if the chain_id starts with any of the allowed prefixes | ||
| for prefix in self.allowed_prefixes: | ||
| if chain_id.startswith(prefix): | ||
| # For eip155, further validate that the rest is a number or 'any' | ||
| if prefix == 'eip155:': | ||
| rest = chain_id[len(prefix):] | ||
| if rest.isdigit(): | ||
| return True | ||
| elif rest == 'any': | ||
| print("Please ensure the label is accurate and consistent across all EVM chains before setting chain_id = 'eip155:any'.") | ||
| return True | ||
| else: | ||
| print(f"Invalid eip155 chain_id format: {chain_id}") | ||
| raise ValueError("For eip155 chains, format must be 'eip155:' followed by a number or 'any'") | ||
| return True | ||
| # Check if the chain_id has one ":" in it which is not at the start or end | ||
| if ":" in chain_id and chain_id.count(":") == 1 and chain_id.find(":") != 0 and chain_id.find(":") != len(chain_id)-1: | ||
| prefix = chain_id[:chain_id.find(":")+1].lower() | ||
| # For eip155, further validate that the rest is a number or 'any' | ||
| if prefix == 'eip155:': | ||
| rest = chain_id[len(prefix):] | ||
| if rest.isdigit(): | ||
| return True | ||
| elif rest == 'any': | ||
| print("Please ensure the label is accurate and consistent across all EVM chains before setting chain_id = 'eip155:any'.") | ||
| return True | ||
| else: | ||
| print(f"Invalid eip155 chain_id format: {chain_id}") | ||
| raise ValueError("For eip155 chains, format must be 'eip155:' followed by a number or 'any'") | ||
| return True | ||
| # If we get here, the chain_id didn't match any allowed format | ||
| print(f"Unsupported chain ID format: {chain_id}") | ||
| raise ValueError(f"Chain ID must be in CAIP-2 format (e.g., Base -> 'eip155:8453'), see this guide on CAIP-2: {self.url_caip2_format}") | ||
| raise ValueError(f"Chain ID must be in CAIP-2 format (e.g., Base -> 'eip155:8453' or Starknet -> 'starknet:SN_MAIN'), see this guide on CAIP-2: {self.url_caip2_format}") | ||
@@ -189,2 +182,20 @@ def validate_address(self, address: str) -> bool: | ||
| def validate_address_to_be_labelled(self, address: str) -> bool: | ||
| """ | ||
| Validates if address to be labelled is within CAIP10 limits | ||
| Args: | ||
| address (str): Address to check | ||
| Returns: | ||
| bool: True if correct, False otherwise | ||
| """ | ||
| if len(address) > 66 or len(address) == 0: | ||
| print(f"Unexpected address length ({len(address)}): '{address}'") | ||
| raise ValueError(f"Address to be labelled exceeds maximum length of 66 characters or is empty. See this guide on CAIP-10 address limitations: {self.url_caip10_format}") | ||
| if ":" in address: | ||
| print(f"Address to be labelled must not contain ':' character: '{address}'") | ||
| raise ValueError(f"Address to be labelled must not contain ':' character. See this guide on CAIP-10 address limitations: {self.url_caip10_format}") | ||
| return True | ||
| def validate_tags(self, tags: dict, auto_fix: bool=False) -> bool: | ||
@@ -191,0 +202,0 @@ """ |
+1
-1
@@ -85,3 +85,3 @@ from web3 import Web3 | ||
| # Label Pool Schema for OLI Label Pool | ||
| self.oli_label_pool_schema = '0xb763e62d940bed6f527dd82418e146a904e62a297b8fa765c9b3e1f0bc6fdd68' | ||
| self.oli_label_pool_schema = '0xcff83309b59685fdae9dad7c63d969150676d51d8eeda66799d1c4898b84556a' # v2.0.0 of EAS schema | ||
@@ -88,0 +88,0 @@ # Label Trust Schema for OLI Label Trust |
+1
-0
@@ -14,2 +14,3 @@ import requests | ||
| self.api_url = "https://api.openlabelsinitiative.org" | ||
| self.api_url = "http://0.0.0.0:8080" # testing | ||
| self.api_key = api_key | ||
@@ -16,0 +17,0 @@ |
+1
-1
| Metadata-Version: 2.4 | ||
| Name: oli-python | ||
| Version: 2.0.5 | ||
| Version: 2.0.6 | ||
| Summary: Python SDK for interacting with the Open Labels Initiative; A standard, registry and trust layer for EVM address labels. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/openlabelsinitiative/oli-python |
+1
-1
@@ -8,3 +8,3 @@ from setuptools import setup, find_packages | ||
| name="oli-python", | ||
| version="2.0.5", | ||
| version="2.0.6", | ||
| author="Lorenz Lehmann", | ||
@@ -11,0 +11,0 @@ author_email="lorenz@growthepie.com", |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
137816
1.4%2004
1.06%