Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: continue sign VC part #457

Merged
merged 10 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions collab-ai-zone-governance.nq
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
jsonld.LoadDocumentError: Could not retrieve a JSON-LD document from the URL.
at jsonld.get (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:899:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async jsonld.expand (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:300:23)
at async jsonld.toRDF (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:687:16)
at async Command.toRdf (file:///Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/bin/jsonld.js:402:20)
at async Command.parseAsync (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/commander/lib/command.js:936:5)
Error: {
name: 'jsonld.LoadDocumentError',
details: {
code: 'loading document failed',
cause: jsonld.NullRemoteDocument: No remote document found at the given URL.
at jsonld.get (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:891:13)
 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async jsonld.expand (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:300:23)
at async jsonld.toRDF (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:687:16)
at async Command.toRdf (file:///Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/bin/jsonld.js:402:20)
at async Command.parseAsync (/Users/marinedechamp-guillaume/.nvm/versions/node/v18.0.0/lib/node_modules/jsonld-cli/node_modules/commander/lib/command.js:936:5) {
details: {}
},
remoteDoc: { contextUrl: null, documentUrl: '-', document: null }
}
}
110 changes: 89 additions & 21 deletions docs/academy/part-2/describe-resource.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ We'll take 2 examples in this tutorial:
- The storage service [IPFS](https://ipfs.tech)

:::info
Prerequisite: [Install the Axone CLI](https://docs.okp4.network/tutorials/cli-1#installing-the-okp4-cli) to interact with the protocol.
Prerequisite:
- [Install the Axone CLI](https://docs.okp4.network/tutorials/cli-1#installing-the-okp4-cli) to interact with the protocol
- Ensure you have `npm` installed on your system. You can follow the installation guide [here](https://www.npmjs.com/get-npm).
- Install the [json-cli](https://github.com/digitalbazaar/jsonld-cli) with the following command:
```bash
npm install -g jsonld-cli
```
:::

## Step 1: Create keys
Expand Down Expand Up @@ -131,24 +137,23 @@ Let's fill in the template.
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/okp4/ontology/v$major/schema/credential/dataset/description/"
"https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/"
],
"type": "VerifiableCredential",
"id": "https://w3id.org/okp4/ontology/v$major/schema/credential/dataset/description/d1120529-3242-4fa8-ac7c-a99abc3fc73e",
"type": ["VerifiableCredential","DatasetDescriptionCredential"],
"id": "https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8",
"credentialSubject": {
"id": "did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5",
"type": "DatasetDescriptionCredential",
"hasDescription": "This dataset reflects incidents of crime in the City of Los Angeles dating back to 2020. This data is transcribed from original crime reports that are typed on paper and therefore there may be some inaccuracies within the data. Some location fields with missing data are noted as (0°, 0°). Address fields are only provided to the nearest hundred block in order to maintain privacy. This data is as accurate as the data in the database.",
"hasFormat": "https://w3id.org/okp4/ontology/v$major/thesaurus/media-type/text_csv",
"hasGeoCoverage": "https://w3id.org/okp4/ontology/v$major/thesaurus/area-code/840",
"hasFormat": "https://w3id.org/okp4/ontology/v3/thesaurus/media-type/text_csv",
"hasGeoCoverage": "https://w3id.org/okp4/ontology/v3/thesaurus/area-code/840",
"hasTag": [
"Crime",
"Police",
"Los Angeles"
],
"hasTemporalCoverage": "2020-01-01T00:00:00.0000+01:00/2024-02-02T00:00:00.00000+01:00",
"hasTitle": "Crime Data from 2020 to Present",
"hasTopic": "https://w3id.org/okp4/ontology/v$major/thesaurus/topic/security"
"hasTopic": "https://w3id.org/okp4/ontology/v3/thesaurus/topic/security"
},
"issuanceDate": "2024-02-02T09:45:43.475304+01:00",
"issuer": {
Expand Down Expand Up @@ -192,14 +197,13 @@ Here are the following metadata of the service [IPFS](https://ipfs.tech).
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/okp4/ontology/v$major/schema/credential/digital-service/description/"
"https://w3id.org/okp4/ontology/v3/schema/credential/digital-service/description/"
],
"type": "VerifiableCredential",
"id": "https://w3id.org/okp4/ontology/v$major/schema/credential/digital-service/description/72cab400-5bd6-4eb4-8605-a5ee8c1a45c9",
"type": ["VerifiableCredential","DigitalServiceDescriptionCredential"],
"id": "https://w3id.org/okp4/ontology/v3/schema/credential/digital-service/description/5a3bd610-3a5d-4a41-bc90-0e437d453220",
"credentialSubject": {
"id": "did:key:zQ3shhb4SvzBRLbBonsvKb3WX6WoDeKWHpsXXXMhAJETqXAfB",
"type": "DigitalServiceDescriptionCredential",
"hasCategory": "https://w3id.org/okp4/ontology/v$major/thesaurus/digital-service-category/Storage",
"hasCategory": "https://w3id.org/okp4/ontology/v3/thesaurus/digital-service-category/Storage",
"hasDescription": "IPFS is a decentralized protocol designed to facilitate the storage, sharing, and retrieval of files on a global scale",
"hasPublisher": "IPFS",
"hasTag": [
Expand Down Expand Up @@ -241,15 +245,53 @@ By signing the credential, any alteration to the credential's data after it has

To sign your VC, use this command:

:::info
The command is coming soon 🔧
:::
```bash
okp4d credential sign $/MY-DIRECTORY/MY-DATASET.jsonld
--keyring-backend test
--from $MY_ADDR | jsonld toRdf -q - > $MY-DATASET.nq
```

With:

- `/MY-DIRECTORY/MY-DATASET.jsonld` : credential file address
- `MY_ADDR` : issuer address
- `MY-DATASET.nq` : name of the file with the signed credential in RDF format

Example:

You can see that there is a new field in the jsonld with the cryptographic proof.
```bash
okp4d credential sign ipfs-digital-service-description.jsonld
--keyring-backend test
--from issuer-okp4 | jsonld toRdf -q - > ipfs-digital-service-description.nq
```

You can see that there is new fields in the jsonld with the cryptographic proof.

```nquads
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasDescription "This dataset reflects incidents of crime in the City of Los Angeles dating back to 2020. This data is transcribed from original crime reports that are typed on paper and therefore there may be some inaccuracies within the data. Some location fields with missing data are noted as (0°, 0°). Address fields are only provided to the nearest hundred block in order to maintain privacy. This data is as accurate as the data in the database." .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasFormat https://w3id.org/okp4/ontology/v3/thesaurus/media-type/text_csv .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasGeoCoverage https://w3id.org/okp4/ontology/v3/thesaurus/area-code/840 .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasTag "Crime" .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasTag "Los Angeles" .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasTag "Police" .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasTitle "Crime Data from 2020 to Present" .
did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/hasTopic https://w3id.org/okp4/ontology/v3/thesaurus/topic/security .
https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8 http://www.w3.org/1999/02/22-rdf-syntax-ns#type https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/DatasetDescriptionCredential .
https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8 http://www.w3.org/1999/02/22-rdf-syntax-ns#type https://www.w3.org/2018/credentials#VerifiableCredential .
https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8 https://w3id.org/security#proof _:b0 .
https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8 https://www.w3.org/2018/credentials#credentialSubject did:key:zQ3shRfADCmegmmKotqCjzDc9BHWDpbEzp9yMiN5RkJx88oP5 .
https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8 https://www.w3.org/2018/credentials#issuanceDate "2024-02-02T09:45:43.475304+01:00"^^http://www.w3.org/2001/XMLSchema#dateTime .
https://w3id.org/okp4/ontology/v3/schema/credential/dataset/description/5d29ea71-003f-46e7-a74d-d8d598629ed8 https://www.w3.org/2018/credentials#issuer did:key:zQ3shs7auhJSmVJpiUbQWco6bxxEhSqWnVEPvaBHBRvBKw6Q3 .
_:b1 http://purl.org/dc/terms/created "2024-04-03T09:19:27.543122+02:00"^^http://www.w3.org/2001/XMLSchema#dateTime _:b0 .
_:b1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type https://w3id.org/security#EcdsaSecp256k1Signature2019 _:b0 .
_:b1 https://w3id.org/security#jws "eyJhbGciOiJ1bmtub3duIiwiYjY0IjpmYWxzZSwiY3JpdCI6WyJiNjQiXX0..8L1rZp9tfVh-cp0RXBx-IboTqmX7My6w5W4rKI3c1HxA82unFSdAdwKBXE4sBrYYHFCcTdnM13-WKpjbCVYqhw" _:b0 .
_:b1 https://w3id.org/security#proofPurpose https://w3id.org/security#assertionMethod _:b0 .
_:b1 https://w3id.org/security#verificationMethod did:key:zQ3shs7auhJSmVJpiUbQWco6bxxEhSqWnVEPvaBHBRvBKw6Q3#zQ3shs7auhJSmVJpiUbQWco6bxxEhSqWnVEPvaBHBRvBKw6Q3 _:b0 .
```

The VC is now in the hands of the Holder. Note that it is possible that the Issuer is also the Holder.

The Axone blockchain can only register VCs in N-Quads format. Then, you must convert the jsonld files in N-Quads. You can use this tool: https://transform.tools/jsonld-to-nquads.
The Axone blockchain can only register VCs in N-Quads format.

## Step 4: Register the credentials in the blockchain

Expand All @@ -260,19 +302,45 @@ Note that as you interact with the Axone blockchain, you must pay fees in $AXON
:::

```bash
# okp4d tx wasm execute $CONTRACT_ADDR \ --from $MY_ADDR \ --gas 10000000 \ "{\"submit_claims\":{\"metadata\": \"$(cat vc.nq | base64)\"}}"
okp4d tx wasm execute $CONTRACT_ADDR \
--node "https://api.drunemeton.okp4.network:443/rpc" \
--chain-id okp4-drunemeton-1 \
--from $MY_ADDR \
--keyring-backend test
--gas 10000000 \ "{\"submit_claims\":{\"metadata\": \"$(cat $MY-DATASET.nq | base64)\"}}"
```

With:

- `CONTRACT_ADDR` : dataverse contract address (always the same)
- `CONTRACT_ADDR` : dataverse contract address (always the same) - For the Drunemeton testnet use okp418cszlvm6pze0x9sz32qnjq4vtd45xehqs8dq7cwy8yhq35wfnn3qvya8du
- `node "https://api.drunemeton.okp4.network:443/rpc"` : name of the node for the Drunemeton testnet
- `MY_ADDR` : registrant okp4 address
- `vc.nq` : name of the verifiable credential signed in RDF in N-Quads format
- `$MY-DATASET.nq` : name of the file with the signed credential in RDF format

Example:
```bash
okp4d tx wasm execute okp418cszlvm6pze0x9sz32qnjq4vtd45xehqs8dq7cwy8yhq35wfnn3qvya8du \
--node "https://api.drunemeton.okp4.network:443/rpc" \
--chain-id okp4-drunemeton-1 \
--from issuer-okp4 \
--keyring-backend test
--gas 10000000 "{\"submit_claims\":{\"metadata\": \"$(cat ipfs-digital-service-description.nq | base64)\"}}"
```

The Protocol will check the signature and if the public key corresponds to the proof in the VC, the VC is registered in the smart contract (Cognitarium).

The command returns the hash of the transaction. You can find more details of this transaction in the [Explorer](https://explore.okp4.network/). Select the network (Currently Drunemeton-Testnet), click on the Search icon, and paste the transaction hash.

Example:
Hash: 766627052AA0A56F56702038E54EC69491386D35E0D76A47F9D5B2321DD56C3E

<div style={{ display: "flex", justifyContent: "center" }}>
<img src="/img/content/academy/transaction-explorer.webp" alt="Axone explorer" style={{ maxHeight: "340px" }}></img>
</div>

<br>
</br>

:::warning
Remember, the Resource Governance VC ensures the existence of a resource in the protocol: a resource or zone exists in the protocol only if governance is attached to it. Let's do it on the next page.
:::
Loading
Loading