timestorage

Time Storage - Backend Documentation

Welcome to the Time Storage Backend! This project provides a highly secure and scalable way to manage and store key-value pairs associated with unique identifiers (UUIDs). It also includes support for file uploads and value locking mechanisms to ensure data integrity. Let’s dive into how to set up, use, and interact with the canisters!


🌐 Canister URLs

Frontend Canisters (Browser Access)

Canister URL
timestorage_admin https://ru4eh-syaaa-aaaah-qp5hq-cai.icp0.io/
timestorage_frontend https://rt5ct-7aaaa-aaaah-qp5ha-cai.icp0.io/

Backend Canisters (Candid Interface)

Canister URL
internet-identity https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=rdmx6-jaaaa-aaaaa-aaadq-cai
test_runner https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=snmf5-yqaaa-aaaah-qp5oa-cai
timestorage_backend https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=r26jp-jiaaa-aaaah-qp5gq-cai

πŸ“‚ File Structure Overview

Here’s a breakdown of the most important files:


πŸ› οΈ Setup and Deployment

  1. Clone the repository.
  2. Navigate to the project directory.
  3. Run the following command to start the local Internet Computer environment:
    dfx start --background
    
  4. Deploy the canister using:
    dfx deploy timestorage_backend
    

πŸ“– Canister Interaction Documentation

Here is a detailed list of the canister β€œendpoints” available in the Time Storage Backend. Each endpoint is explained with its parameters, usage examples, and expected responses.

πŸ‘‰ View the Interactive Mindmap

πŸ”Έβ€‹ isAdmin

Description: Checks if the caller is an admin.

Endpoint:

public shared query (msg) func isAdmin() : async Bool

Example Command:

dfx canister call timestorage_backend isAdmin

Response:


πŸ”Έβ€‹ isEditor

Description: Checks if the caller is an editor.

Endpoint:

public shared query (msg) func isEditor() : async Bool

Example Command:

dfx canister call timestorage_backend isEditor

Response:


πŸ”Έβ€‹ addAdmin

⚠️ Admin role required to execute this function

Description: Adds a new admin to the system.

Endpoint:

public shared (msg) func addAdmin(newAdmin: Principal) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend addAdmin '(principal "[principal_id]")'

Response:


πŸ”Έβ€‹ addEditor

⚠️ Admin role required to execute this function

Description: Adds a new editor to the system.

Endpoint:

public shared (msg) func addEditor(newEditor : Principal) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend addEditor '(principal "[principal_id]")'

Response:


πŸ”Έβ€‹ removeAdmin

⚠️ Admin role required to execute this function

Description: Remove an admin from the system.

Endpoint:

public shared (msg) func removeAdmin(adminToRemove: Principal) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend removeAdmin '(principal "[principal_id]")'

Response:


πŸ”Έβ€‹ removeEditor

⚠️ Admin role required to execute this function

Description: Remove an editor from the system.

Endpoint:

public shared (msg) func removeEditor(editorToRemove : Principal) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend editorToRemove '(principal "[principal_id]")'

Response:


Access Control

Operation Admin Editor Public
Add/Remove Admin βœ… ❌ ❌
Manage UUIDs βœ… βœ… ❌
View All UUIDs βœ… ❌ ❌
Manage Own UUIDs βœ… βœ… ❌
Lock Values βœ… βœ… βœ…
Unlock Values βœ… ❌ ❌

1. insertUUIDStructure

⚠️ Admin role required to execute this function

πŸ› οΈβ€‹ Editor role required to execute this function

Description: Inserts a new structure for a given UUID and memorize the register owner.

Endpoint:

public shared (msg) func insertUUIDStructure(uuid: Text, schema: Text) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend insertUUIDStructure '("uuid-dummy", "{\"name\": \"value\"}")'

Response:


2. uploadFile

Description: Uploads a file and associates it with a given UUID.

Endpoint:

public shared (msg) func uploadFile(uuid: Text, base64FileData: Text, metadata: Types.FileMetadata) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend uploadFile '("uuid-dummy", "<base64_data>", record { fileName = "example.txt"; mimeType = "text/plain"; uploadTimestamp = 1234567890 })'

Response:


3. getFileByUUIDAndId

Description: Retrieves a file associated with a UUID and a file ID.

Endpoint:

public shared query (msg) func getFileByUUIDAndId(uuid: Text, fileId: Text) : async Types.Result<Types.FileResponse, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend getFileByUUIDAndId '("uuid-dummy", "file-1")'

Response:


4. updateValue

Description: Updates a specific value associated with a UUID.

Endpoint:

public shared (msg) func updateValue(req: Types.ValueUpdateRequest) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend updateValue '(record { uuid = "uuid-dummy"; key = "exampleKey"; newValue = "newValue" })'

Response:


5. updateManyValues

Description: Updates multiple key-value pairs for a given UUID.

Endpoint:

public shared (msg) func updateManyValues(uuid: Text, updates: [(Text, Text)]) : async Result.Result<Text, [Text]>

Parameters:

Example Command:

dfx canister call timestorage_backend updateManyValues '("uuid-dummy", vec { record { "exampleKey"; "new-value1" }; record { "key2"; "new-value2" }; record { "key3"; "value3" } })'

Response:


6. lockValue

Description: Locks a specific value for a UUID.

Endpoint:

public shared (msg) func lockValue(req: Types.ValueLockRequest) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend lockValue '(record { uuid = "uuid-dummy"; key = "exampleKey"; lock = true })'

Response:


7. unlockValue

⚠️ Admin role required to execute this function

Description: Unlocks a specific value for a UUID.

Endpoint:

public shared (msg) func unlockValue(req: Types.ValueUnlockRequest) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend unlockValue '(record { uuid = "uuid-dummy"; key = "exampleKey"})'

Response:


8. lockAllValues

Description: Locks all values for a given UUID.

Endpoint:

public shared (msg) func lockAllValues(req: Types.ValueLockAllRequest) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend lockAllValues '(record { uuid = "uuid-dummy"; lock = true })'

Response:


9. unlockAllValues

⚠️ Admin role required to execute this function

Description: Unlocks all values for a given UUID.

Endpoint:

public shared (msg) func unlockAllValues(req : Types.ValueUnlockAllRequest) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend unlockAllValues '(record { uuid = "uuid-dummy" })'

Response:


10. getValue

Description: Retrieves a specific value associated with a UUID.

Endpoint:

public shared query (msg) func getValue(req: Types.ValueRequest) : async Result.Result<Text, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend getValue '(record { uuid = "uuid-dummy"; key = "exampleKey" })'

Response:


11. getAllValues

Description: Retrieves all key-value pairs associated with a UUID.

Endpoint:

public shared query (msg) func getAllValues(uuid: Text) : async Result.Result<[(Text, Text)], Text>

Parameters:

Example Command:

dfx canister call timestorage_backend getAllValues '("uuid-dummy")'

Response:


12. getValueLockStatus

Description: Retrieves the lock status of a specific value.

Endpoint:

public shared query (msg) func getValueLockStatus(req: Types.ValueLockStatusRequest) : async Result.Result<Types.ValueLockStatus, Text>

Parameters:

Example Command:

dfx canister call timestorage_backend getValueLockStatus '(record { uuid = "uuid-dummy"; key = "exampleKey" })'

Response:


13.​ getAllUUIDs

⚠️ Admin role required to execute this function

πŸ› οΈβ€‹ Editor role required to execute this function

Descrizione: Retrieves all UUIDs minted or UUIDs owned by a specific principal if specified.

Endpoint:

public shared query (msg) func getAllUUIDs(ownerPrincipal : ?Principal) : async Result.Result<[Text], Text>

Parameters:

Access Control:

Example Commands:

# Get all UUIDs (admin only)
dfx canister call timestorage_backend getAllUUIDs

# Get UUIDs for specific principal
dfx canister call timestorage_backend getAllUUIDs '(opt principal [principal_id])'

Responses:


πŸ“Œβ€‹ getUUIDInfo

Description: Retrieves all information associated with a UUID.

Endpoint:

public shared query (msg) func getUUIDInfo(uuid: Text) : async Result.Result<(Text, [Types.FileResponse]), Text>

Parameters:

Example Command:

dfx canister call timestorage_backend getUUIDInfo '("uuid-dummy")'

Response: