-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
1,434 additions
and
7 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "pageview", | ||
"views": { | ||
"issuer": { | ||
"type": "documentAccount" | ||
} | ||
}, | ||
"schema": { | ||
"type": "object", | ||
"$defs": { | ||
"DateTime": { | ||
"type": "string", | ||
"title": "DateTime", | ||
"format": "date-time", | ||
"maxLength": 100 | ||
} | ||
}, | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"required": ["page", "address", "timestamp", "customer_user_id"], | ||
"properties": { | ||
"page": { | ||
"type": "string" | ||
}, | ||
"address": { | ||
"type": "string" | ||
}, | ||
"timestamp": { | ||
"$ref": "#/$defs/DateTime" | ||
}, | ||
"customer_user_id": { | ||
"type": "integer" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"version": "2.0", | ||
"interface": false, | ||
"implements": [], | ||
"accountRelation": { | ||
"type": "list" | ||
}, | ||
"immutableFields": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from dotenv import load_dotenv | ||
import os | ||
from pprint import pprint | ||
from datetime import datetime, timezone | ||
from cryptography.hazmat.primitives import serialization | ||
from cryptography.hazmat.primitives.asymmetric import ed25519 | ||
from ceramic_python.did import DID | ||
from ceramic_python.ceramic_client import CeramicClient | ||
from ceramic_client.ceramic_python.model_instance_document import ModelInstanceDocument, ModelInstanceDocumentMetadataArgs | ||
import requests | ||
from key_did_provider_ed25519.src.key_did_provider_ed25519.utils import encode_did | ||
|
||
load_dotenv() | ||
|
||
ENV_ID = os.getenv("ENV_ID") | ||
TABLE_ID = os.getenv("TABLE_ID") | ||
CONTEXT_ID = os.getenv("CONTEXT_ID") | ||
AGENT_ONE_SEED = os.getenv("AGENT_ONE_SEED") | ||
AGENT_TWO_SEED = os.getenv("AGENT_TWO_SEED") | ||
AGENT_THREE_SEED = os.getenv("AGENT_THREE_SEED") | ||
CERAMIC_ENDPOINT = os.getenv("CERAMIC_ENDPOINT") | ||
|
||
orbis_url = "https://studio.useorbis.com/api/db/query/json" | ||
|
||
switcher = { | ||
"agent_one": AGENT_ONE_SEED, | ||
"agent_two": AGENT_TWO_SEED, | ||
"agent_three": AGENT_THREE_SEED | ||
} | ||
|
||
class CeramicActions: | ||
|
||
def __init__(self, agent): | ||
self.private_key = switcher.get(agent) | ||
self.ed25519_private_key = ed25519.Ed25519PrivateKey.from_private_bytes(bytes.fromhex(self.private_key)) | ||
self.ed25519_public_key = self.ed25519_private_key.public_key() | ||
self.did = encode_did(self.ed25519_public_key.public_bytes( | ||
encoding=serialization.Encoding.Raw, | ||
format=serialization.PublicFormat.Raw | ||
)) | ||
|
||
def initialize_ceramic(self): | ||
did = DID( | ||
id=self.did, | ||
private_key=self.private_key, | ||
) | ||
ceramic_client = CeramicClient(CERAMIC_ENDPOINT, did) | ||
return ceramic_client | ||
|
||
def create_document(self, content): | ||
ceramic_client = self.initialize_ceramic() | ||
pprint(f"Initialized Ceramic client with DID: {self.did}") | ||
|
||
metadata_args = ModelInstanceDocumentMetadataArgs( | ||
controller=self.did, | ||
model=TABLE_ID, | ||
context=CONTEXT_ID | ||
) | ||
|
||
# Get the current date and time in UTC | ||
current_time = datetime.now(timezone.utc) | ||
|
||
# Format it as an ISO 8601 string | ||
formatted_time = current_time.isoformat() | ||
|
||
content.update({ | ||
# get datetime | ||
"timestamp": formatted_time, | ||
}) | ||
|
||
doc = ModelInstanceDocument.create(ceramic_client, content, metadata_args) | ||
pprint(f"Stream created with ID: {doc.stream_id}") | ||
return doc | ||
|
||
def get_all_documents(self): | ||
|
||
body = { | ||
"jsonQuery": { | ||
"$raw": { | ||
"query": f"SELECT * FROM {TABLE_ID}", | ||
"params": [] | ||
} | ||
}, | ||
"env": ENV_ID | ||
} | ||
headers = { | ||
"Content-Type": "application/json" | ||
} | ||
response = requests.post(url=orbis_url, headers=headers, json=body) | ||
pprint(response.json()) | ||
return response.json() | ||
|
||
def get_with_filter(self, filter): | ||
|
||
filters = [] | ||
for (key, value) in filter.items(): | ||
filter = f"{key} = {value}" | ||
filters.append(filter) | ||
|
||
# Join the filters with 'AND' if there are multiple filters | ||
joined_filters = " AND ".join(filters) | ||
|
||
body = { | ||
"jsonQuery": { | ||
"$raw": { | ||
"query": f"SELECT * FROM {TABLE_ID} WHERE {joined_filters}", | ||
"params": [] | ||
} | ||
}, | ||
"env": ENV_ID | ||
} | ||
headers = { | ||
"Content-Type": "application/json" | ||
} | ||
response = requests.post(url=orbis_url, headers=headers, json=body) | ||
pprint(response.json()) | ||
return response.json() |
Oops, something went wrong.