From dd0a11303fbf830534cc556f9814a1ad187ae2ef Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Wed, 29 Nov 2023 16:42:00 +0800 Subject: [PATCH] docs: building basic docs --- README.md | 65 +++++++++++-------- .../validators/content_registry.ak | 6 +- specs/admin_actions.md | 0 specs/scripts_specs.md | 61 +++++++++++++++++ specs/setup.md | 0 specs/user_actions.md | 0 6 files changed, 102 insertions(+), 30 deletions(-) create mode 100644 specs/admin_actions.md create mode 100644 specs/scripts_specs.md create mode 100644 specs/setup.md create mode 100644 specs/user_actions.md diff --git a/README.md b/README.md index 2be6e95..c68e521 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # aiken-content-ownership This is the implementation of on-chain content ownership with below features: + 1. User can create content and leverage Cardano blockchain to record ownership 2. The content owner can update the content anytime 3. The content owner can transfer content ownership to others @@ -8,44 +9,54 @@ This is the implementation of on-chain content ownership with below features: 5. Scalable: Up to 10,000 users, each with 10,000 piece of content 6. User can use any native asset on Cardano to represent ownership identity -## Building +# Script Actions -```sh -aiken build -``` +## Scripts -## Testing +The specification of all scripts involved could be found at [scripts_specs.md](./specs/scripts_specs.md). Scripts are labelled with number 1 - 6. And we would use the label for referring to validation logic needed on below. -You can write tests in any module using the `test` keyword. For example: +## Setup -```gleam -test foo() { - 1 + 1 == 2 -} -``` +The are 4 steps of setting up the applications: -To run all tests, simply do: +1. Minting `oracle_nft`, one time minting policy with empty token name with quantity of 1. + - Validation: 1.1 +2. Sending the the `oracle_nft` to `oracle_validator` with initialized inline datum of specifying all compile scripts, addresses with owner keys. Setting both registry counts to `0`. + - Validation: N/A +3. Creating `content_registry` by minting `content_registry_ref_token` to `content_registry` address. + - Validation: 2.1, 3.1 +4. Creating `ownership_registry` by minting `ownership_registry_ref_token` to `ownership_registry` address. + - Validation: 2.2, 4.1 -```sh -aiken check -``` +Step 3 and 4 would be repeated anytime, considering: -To run only tests matching the string `foo`, do: +- Operating concurrency (1 UTxO = 1 concurrency) +- Registry size (desired size to be tested) -```sh -aiken check -m foo -``` +## User Actions -## Documentation +1. Create Content + - Validation: 4.1, 6.1 +2. Update Content + - Validation: 4.2 +3. Transfer Ownership + - Validation: 6.2 -If you're writing a library, you might want to generate an HTML documentation for it. +## Admin Actions -Use: +1. Rotate keys + - Validation: 2.3 +2. Stop Oracle + - Validation: 1.2, 2.4 +3. Stop Content Registry + - Validation: 3.2, 4.3 +4. Stop Ownership Registry + - Validation: 5.2, 6.3 -```sh -aiken docs -``` +# Testing -## Resources +There is unit tests in this implementation. To run all tests, simply do: -Find more on the [Aiken's user manual](https://aiken-lang.org). +```sh +aiken check +``` diff --git a/lib/aiken-content-ownership/validators/content_registry.ak b/lib/aiken-content-ownership/validators/content_registry.ak index 1e0188f..5fc746e 100644 --- a/lib/aiken-content-ownership/validators/content_registry.ak +++ b/lib/aiken-content-ownership/validators/content_registry.ak @@ -178,7 +178,7 @@ pub fn content_registry_logic( ref_token.2nd, ), ) - let is_regisry_updated = + let is_registry_updated = check_is_content_registry_updated( content_input.output.datum, content_output.datum, @@ -191,11 +191,11 @@ pub fn content_registry_logic( raw_ownership_ref_datum expect Some(original_owner) = dict.get(ownership_ref_datum.registry, content_number) - let is_update_authoized = + let is_update_authorized = inputs_token_quantity(inputs, original_owner) > 0 let is_registry_value_clean = list.length(flatten(content_output.value)) == 2 - is_regisry_updated && is_update_authoized && is_registry_value_clean + is_registry_updated && is_update_authorized && is_registry_value_clean } StopContentRegistry -> when diff --git a/specs/admin_actions.md b/specs/admin_actions.md new file mode 100644 index 0000000..e69de29 diff --git a/specs/scripts_specs.md b/specs/scripts_specs.md new file mode 100644 index 0000000..79afc68 --- /dev/null +++ b/specs/scripts_specs.md @@ -0,0 +1,61 @@ +## Specification of Smart Contracts + +1. One Time Minting Policy + + - Serve as reference token living on oracle validator + - Param: Input UTxO + - Validation rules: + 1. Minting rule: Param input is spent + 2. Burning rule: Only negative amount exists regarding this policy + +2. Oracle Validator + + - Locking the oracle token with information for the Dapp + - Validation rules: + 1. Create new content registry: The content registry reference token is minted (with correct name) + 2. Create new ownership registry: The ownership registry reference token is minted (with correct name) + 3. Rotate key: Transaction is signed by both operating key and stop key + - Redeemer info: new operation key and key stop key + 4. Stop app: Oracle token is burned with signature from stop key + +3. Content Registry Reference Token + + - The minting policy of the reference token locked in content registry validator + - Param: oracle token policy + - Validation rules: + 1. Minting rule: oracle_datum_updated && registry_initial_datum_correct && oracle_output_value_clean && registry_output_value_clean + 2. Burning rule: Only negative amount exists regarding this policy + +4. Content Registry Validator + + - Param: oracle token policy + - Validation rules: + 1. Create content + - Redeemer info: `content_hash` and `owner` token + - ref_tokens_equal && current_count_equal && content_new_datum_correct && ownership_new_datum_correct && content_registry_value_clean && ownership_registry_value_clean + 2. Update content + - Redeemer: `new_content_hash` and `content_number` in the registry + - is_registry_updated && is_update_authorized && is_registry_value_clean + 3. Stop content registry + - Content registry reference is burn + - Signed by stop key + +5. Ownership Registry Reference Token + + - The minting policy of the reference token locked in ownership registry validator + - Param: oracle token policy + - Validation rules: + 1. Minting rule: oracle_datum_updated && registry_initial_datum_correct && oracle_output_value_clean && registry_output_value_clean + 2. Burning rule: Only negative amount exists regarding this policy + +6. Ownership Registry Validator + + - Param: oracle token policy + - Validation rules: + 1. Create ownership record: Content ownership input is also validating with create content redeemer + 2. Transfer ownership + - Redeemer: `new_owner_token` and `content_number` in the registry + - is_original_owner_authorized && is_registry_updated && is_registry_value_clean + 3. Stop ownership registry + - Ownership registry reference is burn + - Signed by stop key diff --git a/specs/setup.md b/specs/setup.md new file mode 100644 index 0000000..e69de29 diff --git a/specs/user_actions.md b/specs/user_actions.md new file mode 100644 index 0000000..e69de29