From cd9b18ca14520eae0fbf5905c4c53edc9213aac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Mon, 25 Mar 2024 11:20:49 +0100 Subject: [PATCH 01/11] feat: private token policy --- .../private-token-policy-v1.pact | 107 +++++++++++++++++ .../private-token-policy-v1.repl | 111 ++++++++++++++++++ .../private-token-policy.md | 35 ++++++ 3 files changed, 253 insertions(+) create mode 100644 examples/policies/private-token-policy/private-token-policy-v1.pact create mode 100644 examples/policies/private-token-policy/private-token-policy-v1.repl create mode 100644 examples/policies/private-token-policy/private-token-policy.md diff --git a/examples/policies/private-token-policy/private-token-policy-v1.pact b/examples/policies/private-token-policy/private-token-policy-v1.pact new file mode 100644 index 00000000..e782d1ce --- /dev/null +++ b/examples/policies/private-token-policy/private-token-policy-v1.pact @@ -0,0 +1,107 @@ +(namespace (read-msg 'ns)) + +(module private-token-policy-v1 GOVERNANCE + + (defconst ADMIN-KS:string "marmalade-examples.private-token-policy") + + (defcap GOVERNANCE () + (enforce-guard ADMIN-KS)) + + (implements kip.token-policy-v2) + (implements kip.updatable-uri-policy-v1) + (use kip.token-policy-v2 [token-info]) + (use marmalade-v2.guard-policy-v1 [URI-GUARD-MSG-KEY]) + + (defcap TOKEN_REVEALED (token-id:string uri:string) + @doc "Emitted when the token URI has been revealed" + @event + true + ) + + (defun has-guard-policy:bool (policies) + (> (length (filter (lambda (policy) (= policy marmalade-v2.guard-policy-v1)) policies)) 0)) + + (defun enforce-init:bool + ( token:object{token-info} + ) + + (enforce (has-guard-policy (at 'policies token)) "Guard policy is required for private tokens") + + (read-msg URI-GUARD-MSG-KEY) + + true + ) + + (defun enforce-mint:bool + ( token:object{token-info} + account:string + guard:guard + amount:decimal + ) + true + ) + + (defun enforce-burn:bool + ( token:object{token-info} + account:string + amount:decimal + ) + true + ) + + (defun enforce-offer:bool + ( token:object{token-info} + seller:string + amount:decimal + timeout:integer + sale-id:string ) + true + ) + + (defun enforce-buy:bool + ( token:object{token-info} + seller:string + buyer:string + buyer-guard:guard + amount:decimal + sale-id:string ) + true + ) + + (defun enforce-withdraw:bool + ( token:object{token-info} + seller:string + amount:decimal + timeout:integer + sale-id:string ) + true + ) + + (defun enforce-transfer:bool + ( token:object{token-info} + sender:string + guard:guard + receiver:string + amount:decimal ) + true + ) + + (defun enforce-update-uri:bool + ( token:object{kip.token-policy-v2.token-info} + new-uri:string + ) + (let* ( + (token-id:string (at 'id token)) + (token-info:object{kip.token-policy-v2.token-info} (marmalade-v2.ledger.get-token-info token-id)) + (token-uri-hash:string (at 'uri token-info)) + ) + (enforce (not (= new-uri "")) "URI cannot be empty") + + (enforce (= token-uri-hash (hash new-uri)) "URI does not match the hash") + + (emit-event (TOKEN_REVEALED token-id new-uri)) + + true + ) + ) +) \ No newline at end of file diff --git a/examples/policies/private-token-policy/private-token-policy-v1.repl b/examples/policies/private-token-policy/private-token-policy-v1.repl new file mode 100644 index 00000000..ac5a9f14 --- /dev/null +++ b/examples/policies/private-token-policy/private-token-policy-v1.repl @@ -0,0 +1,111 @@ +;;load policy manager, ledger +(load "../../../pact/marmalade.repl") + +(begin-tx "load policy") + (env-data { + "ns": "marmalade-examples" + , "private-token-policy": ["private-token-policy"] + , "upgrade": false} + ) + (env-sigs [ + { 'key: 'private-token-policy + ,'caps: [] + }]) + + (ns.write-registry (read-msg 'ns) (read-keyset 'private-token-policy) true) + (define-namespace + (read-msg 'ns) + (read-keyset 'private-token-policy) (read-keyset 'private-token-policy) + ) + + (namespace (read-msg 'ns)) + + (define-keyset (+ (read-msg 'ns) ".private-token-policy") (read-keyset 'private-token-policy)) + + (load "private-token-policy-v1.pact") + (typecheck "marmalade-examples.private-token-policy-v1") + +(commit-tx) + +(begin-tx "Require guard-policy") + (use marmalade-v2.ledger) + (use marmalade-examples.private-token-policy-v1) + (use mini-guard-utils) + + (env-data { + "token-id": (create-token-id { 'uri: (hash "ipfs://secret-uri"), 'precision: 0, 'policies: [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] } ALWAYS-TRUE) + ,"token-id-without-guard-policy": (create-token-id { 'uri: (hash "ipfs://secret-uri"), 'precision: 0, 'policies: [marmalade-examples.private-token-policy-v1] } ALWAYS-TRUE) + }) + + (expect-failure "Failed to create a token without guard-policy" + "Guard policy is required for private tokens" + (create-token (read-msg 'token-id-without-guard-policy) 0 (hash "ipfs://secret-uri") [marmalade-examples.private-token-policy-v1] ALWAYS-TRUE)) + + (expect-failure "Failed to create a token without uri-guard" + "Failure: Tx Failed: No such key in message: uri_guard" + (create-token (read-msg 'token-id) 0 (hash "ipfs://secret-uri") [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] ALWAYS-TRUE)) + +(commit-tx) + +(begin-tx "Create private token") + (use marmalade-v2.ledger) + (use marmalade-examples.private-token-policy-v1) + (use marmalade-v2.guard-policy-v1 [GUARD_SUCCESS]) + (use mini-guard-utils) + + (env-data { + "token-id": (create-token-id { 'uri: (hash "ipfs://secret-uri"), 'precision: 0, 'policies: [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] } ALWAYS-TRUE) + ,"uri_guard": {"keys": ["e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"], "pred": "keys-all"} + }) + + (expect "Token created successfully" + true + (create-token (read-msg 'token-id) 0 (hash "ipfs://secret-uri") [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] ALWAYS-TRUE)) + + (expect "create-token events" + [ {"name": "marmalade-v2.guard-policy-v1.GUARDS","params": [(read-msg 'token-id) {"burn-guard": GUARD_SUCCESS,"mint-guard": GUARD_SUCCESS,"sale-guard": GUARD_SUCCESS,"transfer-guard": GUARD_SUCCESS,"uri-guard":(read-keyset 'uri_guard)}] }, + {"name": "marmalade-v2.ledger.TOKEN","params": [(read-msg 'token-id) 0 [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] (hash "ipfs://secret-uri") ALWAYS-TRUE]}] + (map (remove "module-hash") (env-events true))) + +(commit-tx) + +(begin-tx "Reveal private token URI") + (use marmalade-v2.ledger) + (use marmalade-examples.private-token-policy-v1) + (use mini-guard-utils) + + (env-data { + "secret-uri": "ipfs://secret-uri" + ,"token-id": (create-token-id { 'uri: (hash "ipfs://secret-uri"), 'precision: 0, 'policies: [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] } ALWAYS-TRUE) + ,"uri-guard": {"keys": ["e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"], "pred": "keys-all"} + }) + + (expect-failure "fail if new URI is empty string" + "URI cannot be empty" + (update-uri (read-msg 'token-id) "")) + + (expect-failure "fail if new URI is wrong" + "URI does not match the hash" + (update-uri (read-msg 'token-id) "ipfs://wrong-uri")) + + (env-sigs [ + { 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3 + ,'caps: [ + (marmalade-v2.ledger.UPDATE-URI (read-msg 'token-id) (read-msg 'secret-uri)) + ,(marmalade-v2.guard-policy-v1.UPDATE-URI (read-msg 'token-id) (read-msg 'secret-uri))] + }]) + + (expect "successfully reveal the URI" + true + (update-uri (read-msg 'token-id) (read-msg 'secret-uri))) + + (expect "update uri events" + [{"name": "marmalade-examples.private-token-policy-v1.TOKEN_REVEALED","params": [(read-msg 'token-id) (read-msg 'secret-uri)]} + ,{"name": "marmalade-v2.ledger.UPDATE-URI","params": [(read-msg 'token-id) (read-msg 'secret-uri)]}] + (map (remove "module-hash") (env-events true))) + + (expect-failure "cannot update the URI after revealing" + "URI does not match the hash" + (update-uri (read-msg 'token-id) "ipfs://something-new")) + +(commit-tx) diff --git a/examples/policies/private-token-policy/private-token-policy.md b/examples/policies/private-token-policy/private-token-policy.md new file mode 100644 index 00000000..73e30b16 --- /dev/null +++ b/examples/policies/private-token-policy/private-token-policy.md @@ -0,0 +1,35 @@ +# Private token policy + +Private token policy allows creators to make an airdrop without revealing the metadata of the token beforehand. The token URI can be revealed at any time, making the metadata known to all. + +## Requirements: + +Concrete policy `guard-policy` must be used in conjunction with `private-token-policy` to make sure only an authorized account can update the token URI. + +While creating a token, the URI should be the hash of the actual URI. This can be calculated using a local call to the node so there is no trace recorded on the chain. + +## Specification, capabilities, events: + +**Capabilities**: + - `GOVERNANCE`: enforces access control of contract upgrades. + +**Events**: + - `TOKEN_REVEALED (token-id uri)`: Emitted when the token URI has been revealed. + +## Policy Functions + +**`enforce-init`:** Enforced during `marmalade-v2.ledger.create-token`, and will ensure the concrete `guard-policy` is present along with the URI guard. + +**`enforce-mint`:** Enabled without limitation. + +**`enforce-burn`:** Enabled without limitation. + +**`enforce-offer`:** Enabled without limitation. + +**`enforce-buy`:** Enabled without limitation. + +**`enforce-withdraw`:** Enabled without limitation. + +**`enforce-transfer`:** Enabled without limitation. + +**`enforce-update-uri`:** Enforced during `marmalade-v2.ledger.update-uri`, and it will make sure that the saved hash of the URI matches the hashed new URI. \ No newline at end of file From 0ddf259ff451163d3028248948252f0f2e3df61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Mon, 25 Mar 2024 11:22:43 +0100 Subject: [PATCH 02/11] chore: added policy test to github actions --- .github/workflows/test-example-policies.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test-example-policies.yml b/.github/workflows/test-example-policies.yml index 0ec1b407..c327b438 100644 --- a/.github/workflows/test-example-policies.yml +++ b/.github/workflows/test-example-policies.yml @@ -37,3 +37,13 @@ jobs: uses: ./.github/actions/repl with: target: examples/policies/timed-mint-policy/timed-mint-policy-v1.repl + + - name: Test soul-bound-policy-v1 + uses: ./.github/actions/repl + with: + target: examples/policies/soul-bound-policy/soul-bound-policy-v1.repl + + - name: Test private-token-policy-v1 + uses: ./.github/actions/repl + with: + target: examples/policies/private-token-policy/private-token-policy-v1.repl From 26e3b82673bd1dce6d69de910728183e9b86bf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Mon, 25 Mar 2024 11:30:19 +0100 Subject: [PATCH 03/11] chore: remove soul-bound-policy test from github actions --- .github/workflows/test-example-policies.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test-example-policies.yml b/.github/workflows/test-example-policies.yml index c327b438..c17eda9b 100644 --- a/.github/workflows/test-example-policies.yml +++ b/.github/workflows/test-example-policies.yml @@ -38,11 +38,6 @@ jobs: with: target: examples/policies/timed-mint-policy/timed-mint-policy-v1.repl - - name: Test soul-bound-policy-v1 - uses: ./.github/actions/repl - with: - target: examples/policies/soul-bound-policy/soul-bound-policy-v1.repl - - name: Test private-token-policy-v1 uses: ./.github/actions/repl with: From 2b487d452fb9759ff9cee2de36d6c63a9a389836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Mon, 8 Apr 2024 19:50:41 +0200 Subject: [PATCH 04/11] chore: allow updating uri regardles of this policy --- .../private-token-policy-v1.pact | 35 +++++++++++++++++-- .../private-token-policy-v1.repl | 28 ++++++++++----- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/examples/policies/private-token-policy/private-token-policy-v1.pact b/examples/policies/private-token-policy/private-token-policy-v1.pact index e782d1ce..690e8cae 100644 --- a/examples/policies/private-token-policy/private-token-policy-v1.pact +++ b/examples/policies/private-token-policy/private-token-policy-v1.pact @@ -12,6 +12,12 @@ (use kip.token-policy-v2 [token-info]) (use marmalade-v2.guard-policy-v1 [URI-GUARD-MSG-KEY]) + (defschema revealed-tokens-schema + revealed:bool + ) + + (deftable revealed-tokens:{revealed-tokens-schema}) + (defcap TOKEN_REVEALED (token-id:string uri:string) @doc "Emitted when the token URI has been revealed" @event @@ -90,18 +96,43 @@ ( token:object{kip.token-policy-v2.token-info} new-uri:string ) + true + ) + + (defun reveal-uri:bool (token-id:string new-uri:string) (let* ( - (token-id:string (at 'id token)) (token-info:object{kip.token-policy-v2.token-info} (marmalade-v2.ledger.get-token-info token-id)) (token-uri-hash:string (at 'uri token-info)) + (already-revealed:bool (is-revealed token-id)) ) + (enforce (not already-revealed) "Token URI already revealed") + (enforce (not (= new-uri "")) "URI cannot be empty") (enforce (= token-uri-hash (hash new-uri)) "URI does not match the hash") + (marmalade-v2.ledger.update-uri token-id new-uri) + (emit-event (TOKEN_REVEALED token-id new-uri)) + + (insert revealed-tokens token-id { 'revealed: true }) true ) ) -) \ No newline at end of file + + (defun is-revealed:bool (token-id:string) + (with-default-read revealed-tokens token-id + { 'revealed : false } + { 'revealed := revealed } + revealed + ) + ) +) + +(if (read-msg 'upgrade) + true + (create-table revealed-tokens) +) + +(enforce-guard ADMIN-KS) \ No newline at end of file diff --git a/examples/policies/private-token-policy/private-token-policy-v1.repl b/examples/policies/private-token-policy/private-token-policy-v1.repl index ac5a9f14..9d830a20 100644 --- a/examples/policies/private-token-policy/private-token-policy-v1.repl +++ b/examples/policies/private-token-policy/private-token-policy-v1.repl @@ -79,14 +79,19 @@ ,"token-id": (create-token-id { 'uri: (hash "ipfs://secret-uri"), 'precision: 0, 'policies: [marmalade-examples.private-token-policy-v1 marmalade-v2.guard-policy-v1] } ALWAYS-TRUE) ,"uri-guard": {"keys": ["e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"], "pred": "keys-all"} }) + + (expect "token has not been revealed" + false + (is-revealed (read-msg 'token-id)) + ) (expect-failure "fail if new URI is empty string" "URI cannot be empty" - (update-uri (read-msg 'token-id) "")) + (reveal-uri (read-msg 'token-id) "")) (expect-failure "fail if new URI is wrong" "URI does not match the hash" - (update-uri (read-msg 'token-id) "ipfs://wrong-uri")) + (reveal-uri (read-msg 'token-id) "ipfs://wrong-uri")) (env-sigs [ { 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3 @@ -97,15 +102,20 @@ (expect "successfully reveal the URI" true - (update-uri (read-msg 'token-id) (read-msg 'secret-uri))) + (reveal-uri (read-msg 'token-id) (read-msg 'secret-uri))) - (expect "update uri events" - [{"name": "marmalade-examples.private-token-policy-v1.TOKEN_REVEALED","params": [(read-msg 'token-id) (read-msg 'secret-uri)]} - ,{"name": "marmalade-v2.ledger.UPDATE-URI","params": [(read-msg 'token-id) (read-msg 'secret-uri)]}] + (expect "reveal uri events" + [{"name": "marmalade-v2.ledger.UPDATE-URI","params": [(read-msg 'token-id) (read-msg 'secret-uri)]} + ,{"name": "marmalade-examples.private-token-policy-v1.TOKEN_REVEALED","params": [(read-msg 'token-id) (read-msg 'secret-uri)]} ] (map (remove "module-hash") (env-events true))) + + (expect "token has been revealed" + true + (is-revealed (read-msg 'token-id)) + ) - (expect-failure "cannot update the URI after revealing" - "URI does not match the hash" - (update-uri (read-msg 'token-id) "ipfs://something-new")) + (expect-failure "cannot reveal the URI again" + "Token URI already revealed" + (reveal-uri (read-msg 'token-id) "ipfs://something-new")) (commit-tx) From 9ee751eec9503c64dfec0680440f10ac3eedfdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Mon, 8 Apr 2024 19:59:23 +0200 Subject: [PATCH 05/11] chore: update documentation --- .../private-token-policy/private-token-policy.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/policies/private-token-policy/private-token-policy.md b/examples/policies/private-token-policy/private-token-policy.md index 73e30b16..059a5c38 100644 --- a/examples/policies/private-token-policy/private-token-policy.md +++ b/examples/policies/private-token-policy/private-token-policy.md @@ -8,7 +8,13 @@ Concrete policy `guard-policy` must be used in conjunction with `private-token-p While creating a token, the URI should be the hash of the actual URI. This can be calculated using a local call to the node so there is no trace recorded on the chain. -## Specification, capabilities, events: +## Specification, tables, capabilities, events: + +**Schemas**: `revealed-tokens-schema` is a schema that stores which tokens have been revealed + - `revealed`: shows if the URI has been revealed. + +**Tables**: `revealed-tokens` table stores which tokens have been revealed. + - `id`: the id of the token **Capabilities**: - `GOVERNANCE`: enforces access control of contract upgrades. @@ -32,4 +38,8 @@ While creating a token, the URI should be the hash of the actual URI. This can b **`enforce-transfer`:** Enabled without limitation. -**`enforce-update-uri`:** Enforced during `marmalade-v2.ledger.update-uri`, and it will make sure that the saved hash of the URI matches the hashed new URI. \ No newline at end of file +**`enforce-update-uri`:** Enabled without limitation. + +**`reveal-uri`:** Will make sure that the saved hash of the URI matches the hashed new URI and will invoke `marmalade-v2.ledger.update-uri`. + +**`is-revealed`:** Check if the URI has been revealed. \ No newline at end of file From 5ada6a4db474559a32cb464c195c7a84c675563e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Tue, 9 Apr 2024 12:08:38 +0200 Subject: [PATCH 06/11] chore: log the output to the console if the test failed --- .github/actions/repl/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/repl/action.yml b/.github/actions/repl/action.yml index 10e8eb84..a47ebb2d 100644 --- a/.github/actions/repl/action.yml +++ b/.github/actions/repl/action.yml @@ -15,4 +15,4 @@ runs: bin/pact -t ${{ inputs.target }} > out.log 2>&1 cat out.log r=`tail -1 out.log | grep "Load successful"` - if [ -n "$r" ]; then exit 0; else echo "Pact run failed."; exit 1; fi + if [ -n "$r" ]; then exit 0; else cat out.log; echo "Pact run failed."; exit 1; fi From 5bfd024293c50cc95089663f32e959da2dbee189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Tue, 9 Apr 2024 12:34:21 +0200 Subject: [PATCH 07/11] chore: updated the repl gh action --- .github/actions/repl/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/repl/action.yml b/.github/actions/repl/action.yml index a47ebb2d..1658471c 100644 --- a/.github/actions/repl/action.yml +++ b/.github/actions/repl/action.yml @@ -15,4 +15,4 @@ runs: bin/pact -t ${{ inputs.target }} > out.log 2>&1 cat out.log r=`tail -1 out.log | grep "Load successful"` - if [ -n "$r" ]; then exit 0; else cat out.log; echo "Pact run failed."; exit 1; fi + if [ -n "$r" ]; then exit 0; else cat out.log; echo "\nPact run failed."; exit 1; fi From 91ddee899bff8eb0a72a32c213afba40b534cfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Thu, 11 Apr 2024 13:26:28 +0200 Subject: [PATCH 08/11] chore: disable updating uri before revealing --- .../private-token-policy-v1.pact | 8 +++++--- .../private-token-policy-v1.repl | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/policies/private-token-policy/private-token-policy-v1.pact b/examples/policies/private-token-policy/private-token-policy-v1.pact index 690e8cae..e252868d 100644 --- a/examples/policies/private-token-policy/private-token-policy-v1.pact +++ b/examples/policies/private-token-policy/private-token-policy-v1.pact @@ -96,7 +96,9 @@ ( token:object{kip.token-policy-v2.token-info} new-uri:string ) - true + (let ((revealed:bool (is-revealed (at 'id token)))) + (enforce revealed "Update disabled prior to revealing") + ) ) (defun reveal-uri:bool (token-id:string new-uri:string) @@ -110,12 +112,12 @@ (enforce (not (= new-uri "")) "URI cannot be empty") (enforce (= token-uri-hash (hash new-uri)) "URI does not match the hash") + + (insert revealed-tokens token-id { 'revealed: true }) (marmalade-v2.ledger.update-uri token-id new-uri) (emit-event (TOKEN_REVEALED token-id new-uri)) - - (insert revealed-tokens token-id { 'revealed: true }) true ) diff --git a/examples/policies/private-token-policy/private-token-policy-v1.repl b/examples/policies/private-token-policy/private-token-policy-v1.repl index 9d830a20..438a26ff 100644 --- a/examples/policies/private-token-policy/private-token-policy-v1.repl +++ b/examples/policies/private-token-policy/private-token-policy-v1.repl @@ -84,6 +84,11 @@ false (is-revealed (read-msg 'token-id)) ) + + (expect-failure "shoud not be able to update uri before revealing" + "Update disabled prior to revealing" + (marmalade-v2.ledger.update-uri (read-msg 'token-id) "") + ) (expect-failure "fail if new URI is empty string" "URI cannot be empty" @@ -117,5 +122,17 @@ (expect-failure "cannot reveal the URI again" "Token URI already revealed" (reveal-uri (read-msg 'token-id) "ipfs://something-new")) + + (env-sigs [ + { 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3 + ,'caps: [ + (marmalade-v2.ledger.UPDATE-URI (read-msg 'token-id) "ipfs://updated") + ,(marmalade-v2.guard-policy-v1.UPDATE-URI (read-msg 'token-id) "ipfs://updated")] + }]) + + (expect "shoud be able to update uri after revealing" + true + (marmalade-v2.ledger.update-uri (read-msg 'token-id) "ipfs://updated") + ) (commit-tx) From 64dee0354ebb18f516892c89bb288bec69f06647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Thu, 11 Apr 2024 13:28:51 +0200 Subject: [PATCH 09/11] chore: updated the documentation --- .../policies/private-token-policy/private-token-policy.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/policies/private-token-policy/private-token-policy.md b/examples/policies/private-token-policy/private-token-policy.md index 059a5c38..71d0606c 100644 --- a/examples/policies/private-token-policy/private-token-policy.md +++ b/examples/policies/private-token-policy/private-token-policy.md @@ -8,6 +8,8 @@ Concrete policy `guard-policy` must be used in conjunction with `private-token-p While creating a token, the URI should be the hash of the actual URI. This can be calculated using a local call to the node so there is no trace recorded on the chain. +Note: token URI can still be updated but the `uri-guard` but only after revealing the initial URI. + ## Specification, tables, capabilities, events: **Schemas**: `revealed-tokens-schema` is a schema that stores which tokens have been revealed @@ -38,7 +40,7 @@ While creating a token, the URI should be the hash of the actual URI. This can b **`enforce-transfer`:** Enabled without limitation. -**`enforce-update-uri`:** Enabled without limitation. +**`enforce-update-uri`:** Enforced during `marmalade-v2.ledger.update-uri`, and will allow updating only if the token has been revealed before. **`reveal-uri`:** Will make sure that the saved hash of the URI matches the hashed new URI and will invoke `marmalade-v2.ledger.update-uri`. From 1fd447c3528188bfa2274658f3f596ae546ca3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Thu, 11 Apr 2024 13:29:54 +0200 Subject: [PATCH 10/11] fix: typo in the docs --- examples/policies/private-token-policy/private-token-policy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/policies/private-token-policy/private-token-policy.md b/examples/policies/private-token-policy/private-token-policy.md index 71d0606c..342705c9 100644 --- a/examples/policies/private-token-policy/private-token-policy.md +++ b/examples/policies/private-token-policy/private-token-policy.md @@ -8,7 +8,7 @@ Concrete policy `guard-policy` must be used in conjunction with `private-token-p While creating a token, the URI should be the hash of the actual URI. This can be calculated using a local call to the node so there is no trace recorded on the chain. -Note: token URI can still be updated but the `uri-guard` but only after revealing the initial URI. +Note: token URI can still be updated by the `uri-guard` but only after revealing the initial URI. ## Specification, tables, capabilities, events: From a63fb7d2c750f0cf1d59b45f20d05f2f12979707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Maga=C5=A1?= Date: Thu, 16 May 2024 12:55:54 +0200 Subject: [PATCH 11/11] chore: stringify policy when comparing --- .../policies/private-token-policy/private-token-policy-v1.pact | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/policies/private-token-policy/private-token-policy-v1.pact b/examples/policies/private-token-policy/private-token-policy-v1.pact index e252868d..e22bd53d 100644 --- a/examples/policies/private-token-policy/private-token-policy-v1.pact +++ b/examples/policies/private-token-policy/private-token-policy-v1.pact @@ -25,7 +25,7 @@ ) (defun has-guard-policy:bool (policies) - (> (length (filter (lambda (policy) (= policy marmalade-v2.guard-policy-v1)) policies)) 0)) + (> (length (filter (lambda (policy) (= (format "{}" [policy]) "marmalade-v2.guard-policy-v1")) policies)) 0)) (defun enforce-init:bool ( token:object{token-info}