Skip to main content

DataTrails Simplehash in python

Prescribed python code that defines the hashing algorithm for DLT Anchoring.

Support

This package currently is tested against Python versions 3.8,3.9,3.10,3.11 and 3.12.

The current default version is 3.8 - this means that this package will not use any features specific to versions 3.8 and later.

After End of Life of a particular Python version, support is offered on a best effort basis. We may ask you to update your Python version to help solve the problem, if it cannot be reasonably resolved in your current version.

Installation

Use standard python pip utility:

python3 -m pip install datatrails-simplehash

If your version of python3 is too old an error of this type or similar will be emitted:

Which Version

To Determine which version of the simple hash script to use, i.e. simplehashv1 or simplehashv2, look at the response from the v1alpha2/blockchain list api and correlate the version with the hash_schema_version in the simple_hash_details section.

Alternatively look for the SimpleHashInfo section in the datatrails app, found on the transaction page of a simple hash event, and correlate the version with schema_version.

Examples

You can then use the code to recreate the simple hash of a list of SIMPLE_HASH events from DataTrails.

Importing in own code

Permissioned Assets V1

"""From a list of events.
"""

from datatrails_simplehash.v1 import (
    anchor_events,
    SimpleHashError,
)

with open("credentials/token", mode="r", encoding="utf-8") as tokenfile:
    auth_token = tokenfile.read().strip()

# SimpleHashClientAuthError is raised if the auth token is invalid or expired.
# if any pending events a SimpleHashPendingEventFound error will be thrown
# if any of the events do not contain the required field then a SimpleHashFieldMissing error will be thrown
api_query = (
    "https://app.datatrails.ai"
    "/archivist/v2/assets/-/events"
    "?proof_mechanism=SIMPLE_HASH"
    "&timestamp_accepted_since=2022-10-07T07:01:34Z"
    "&timestamp_accepted_before=2022-10-16T13:14:56Z"
    "&order_by=SIMPLEHASHV1"
)
try:
    simplehash = anchor_events(api_query, auth=auth_token)
except SimpleHashError as ex:
    print("Error", ex)

else:
    print("simplehash=", simplehash)

Permissioned Assets V2

"""From a list of events.
"""

from datatrails_simplehash.v2 import (
    anchor_events,
    SimpleHashError,
)

with open("credentials/token", mode="r", encoding="utf-8") as tokenfile:
    auth_token = tokenfile.read().strip()

# SimpleHashClientAuthError is raised if the auth token is invalid or expired.
# if any pending events a SimpleHashPendingEventFound error will be thrown
# if any of the events do not contain the required field then a SimpleHashFieldMissing error will be thrown
api_query = (
    "https://app.datatrails.ai"
    "/archivist/v2/assets/-/events"
    "?proof_mechanism=SIMPLE_HASH"
    "&timestamp_accepted_since=2022-10-07T07:01:34Z"
    "&timestamp_accepted_before=2022-10-16T13:14:56Z"
    "&order_by=SIMPLEHASHV1"
)
try:
    simplehash = anchor_events(api_query, auth=auth_token)
except SimpleHashError as ex:
    print("Error", ex)

else:
    print("simplehash=", simplehash)

Public Assets V1

"""From a list of events.
"""

from datatrails_simplehash.v1 import (
    anchor_events,
    SimpleHashError,
)

# SimpleHashClientAuthError is raised if the auth token is invalid or expired.
# if any pending events a SimpleHashPendingEventFound error will be thrown
# if any of the events do not contain the required field then a SimpleHashFieldMissing error will be thrown
api_query = (
    "https://app.datatrails.ai"
    "/archivist/v2/publicassets/-/events"
    "?proof_mechanism=SIMPLE_HASH"
    "&timestamp_accepted_since=2022-10-07T07:01:34Z"
    "&timestamp_accepted_before=2022-10-16T13:14:56Z"
    "&order_by=SIMPLEHASHV1"
)
try:
    simplehash = anchor_events(api_query)
except SimpleHashError as ex:
    print("Error", ex)

else:
    print("simplehash=", simplehash)

Public Assets V2

"""From a list of events.
"""

from datatrails_simplehash.v2 import (
    anchor_events,
    SimpleHashError,
)

# SimpleHashClientAuthError is raised if the auth token is invalid or expired.
# if any pending events a SimpleHashPendingEventFound error will be thrown
# if any of the events do not contain the required field then a SimpleHashFieldMissing error will be thrown
api_query = (
    "https://app.datatrails.ai"
    "/archivist/v2/publicassets/-/events"
    "?proof_mechanism=SIMPLE_HASH"
    "&timestamp_accepted_since=2022-10-07T07:01:34Z"
    "&timestamp_accepted_before=2022-10-16T13:14:56Z"
    "&order_by=SIMPLEHASHV1"
)
try:
    simplehash = anchor_events(api_query)
except SimpleHashError as ex:
    print("Error", ex)

else:
    print("simplehash=", simplehash)

Command Line

This functionality is also available on the cmdline.

Using a virtual env and published wheel

This can be executed anywhere using a virtualenv and published wheel. Credentials are stored in files in credentials directory.

Using an auth token directly and for permissioned assets

#!/usr/bin/env bash
#
python3 -m venv simplehash-venv
source simplehash-venv/bin/activate
python3 -m pip install -q datatrails_simplehash

api_query="https://app.datatrails.ai"
api_query+="/archivist/v2/assets/-/events"
api_query+="?proof_mechanism=SIMPLE_HASH"
api_query+="&timestamp_accepted_since=2022-10-07T07:01:34Z"
api_query+="&timestamp_accepted_before=2022-10-16T13:14:56Z"
api_query+="&order_by=SIMPLEHASHV1"

datatrails_simplehashv1 \
    --auth-token-file "credentials/token" \
    "${api_query}"

deactivate
rm -rf simplehash-venv

Or for schema version 2:

#!/usr/bin/env bash
#
python3 -m venv simplehash-venv
source simplehash-venv/bin/activate
python3 -m pip install -q datatrails_simplehash

api_query="https://app.datatrails.ai"
api_query+="/archivist/v2/assets/-/events"
api_query+="?proof_mechanism=SIMPLE_HASH"
api_query+="&timestamp_accepted_since=2022-10-07T07:01:34Z"
api_query+="&timestamp_accepted_before=2022-10-16T13:14:56Z"
api_query+="&order_by=SIMPLEHASHV1"

datatrails_simplehashv2 \
    --auth-token-file "credentials/token" \
    "${api_query}"

deactivate
rm -rf simplehash-venv

Using a client id and secret and for permissioned assets

#!/usr/bin/env bash
#
python3 -m venv simplehash-venv
source simplehash-venv/bin/activate
python3 -m pip install -q datatrails_simplehash

api_query="https://app.datatrails.ai"
api_query+="/archivist/v2/assets/-/events"
api_query+="?proof_mechanism=SIMPLE_HASH"
api_query+="&timestamp_accepted_since=2022-10-07T07:01:34Z"
api_query+="&timestamp_accepted_before=2022-10-16T13:14:56Z"
api_query+="&order_by=SIMPLEHASHV1"

CLIENT_ID=$(cat credentials/client_id)
datatrails_simplehashv1 \
    --client-id "${CLIENT_ID}" \
    --client-secret-file "credentials/client_secret" \
    "${api_query}"

deactivate
rm -rf simplehash-venv

Or for schema version 2:

#!/usr/bin/env bash
#
python3 -m venv simplehash-venv
source simplehash-venv/bin/activate
python3 -m pip install -q datatrails_simplehash

api_query="https://app.datatrails.ai"
api_query+="/archivist/v2/assets/-/events"
api_query+="?proof_mechanism=SIMPLE_HASH"
api_query+="&timestamp_accepted_since=2022-10-07T07:01:34Z"
api_query+="&timestamp_accepted_before=2022-10-16T13:14:56Z"
api_query+="&order_by=SIMPLEHASHV1"

CLIENT_ID=$(cat credentials/client_id)
datatrails_simplehashv2 \
    --client-id "${CLIENT_ID}" \
    --client-secret-file "credentials/client_secret" \
    "${api_query}"

deactivate
rm -rf simplehash-venv

Querying the public assets (does not require authentication)

#!/usr/bin/env bash
#
python3 -m venv simplehash-venv
source simplehash-venv/bin/activate
python3 -m pip install -q datatrails_simplehash

start_time = "2022-11-16T00:00:00Z"
end_time = "2022-11-17T00:00:00Z"
datatrails_url = "https://app.datatrails.ai"
endpoint = "archivist/v2/publicassets/-/events"

api_query="https://app.datatrails.ai"
api_query+="/archivist/v2/publicassets/-/events"
api_query+="?proof_mechanism=SIMPLE_HASH"
api_query+="&timestamp_accepted_since=2022-10-07T07:01:34Z"
api_query+="&timestamp_accepted_before=2022-10-16T13:14:56Z"
api_query+="&order_by=SIMPLEHASHV1"

datatrails_simplehashv1 "${api_query}"

deactivate
rm -rf simplehash-venv

Or for schema version 2:

#!/usr/bin/env bash
#
python3 -m venv simplehash-venv
source simplehash-venv/bin/activate
python3 -m pip install -q datatrails_simplehash

start_time = "2022-11-16T00:00:00Z"
end_time = "2022-11-17T00:00:00Z"
datatrails_url = "https://app.datatrails.ai"
endpoint = "archivist/v2/publicassets/-/events"

api_query="https://app.datatrails.ai"
api_query+="/archivist/v2/publicassets/-/events"
api_query+="?proof_mechanism=SIMPLE_HASH"
api_query+="&timestamp_accepted_since=2022-10-07T07:01:34Z"
api_query+="&timestamp_accepted_before=2022-10-16T13:14:56Z"
api_query+="&order_by=SIMPLEHASHV1"

datatrails_simplehashv2 "${api_query}"

deactivate
rm -rf simplehash-venv

Metadata

Release files for datatrails-simplehash 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datatrails-simplehash 0.5.0
File Size Uploaded Provenance Actions
datatrails-simplehash-0.5.0.tar.gz 15.3 kB Without provenance Details for datatrails-simplehash-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datatrails-simplehash 0.5.0
File Interpreter ABI Platform Actions
datatrails_simplehash-0.5.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for datatrails_simplehash-0.5.0-py2.py3-none-any.whl

Total release size: 25.0 kB

Release files / datatrails-simplehash-0.5.0.tar.gz

Download URL datatrails-simplehash-0.5.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
53e98bedf32be585edebcc2ee209964cc1163e479efa04c4a01bcfab83ea3f92
BLAKE2b-256 checksum
How to use checksums
895263aa6a19a51b2bd647fff58a989b8d5773015f33e168005514e65e5d5fdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / datatrails_simplehash-0.5.0-py2.py3-none-any.whl

Download URL datatrails_simplehash-0.5.0-py2.py3-none-any.whl
Size 9.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
17b6e34d164c3b2e738f42ede752a00a71c99c4f4ca41b2ad33cbded0f9f1641
BLAKE2b-256 checksum
How to use checksums
545f0a3bc130b4004d403011848d9f91a3a63d75b6b74f52911b3f9fc5590d6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Security for datatrails-simplehash 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page