Skip to content

Commit

Permalink
Merge branch '3558-create-v1-in-docusaurus-move-all-sdk-related-docs-…
Browse files Browse the repository at this point in the history
…out-of-cookbook-section-and-one-level-up' into 3577-update-sdk-docs-tests-to-only-test-new-versions
  • Loading branch information
ChrisChinchilla committed Aug 15, 2024
2 parents 90c21ee + 06dfbac commit 76246ff
Show file tree
Hide file tree
Showing 246 changed files with 4,512 additions and 158 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/concepts/02_did.md → concepts/02_did.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ KILT thus rejects light DID signatures even if the original claim in the credent

:::tip

For a detailed developer-oriented guide to KILT DIDs, read the [DID Cookbook section](../develop/01_sdk/02_cookbook/01_dids/01_light_did_creation.md).
For a detailed developer-oriented guide to KILT DIDs, read the [DID Cookbook section](/develop/sdk/cookbook/dids/light-did-creation).

:::

Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/03_web3names.md → concepts/03_web3names.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ For example, showing the web3name of a collator's account on the [KILT Stakeboar
}}
/>

For a detailed developer-oriented guide to web3names and account linking, read the [web3name Cookbook section](../develop/01_sdk/02_cookbook/02_web3names/01_claim.md) and the [account linking Cookbook section](../develop/01_sdk/02_cookbook/03_account_linking/01_link.md).
For a detailed developer-oriented guide to web3names and account linking, read the [web3name Cookbook section](/develop/sdk/cookbook/web3names/claim) and the [account linking Cookbook section](/develop/sdk/cookbook/account_linking/link).

## KILT DIDs vs. KILT accounts

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Currently, it costs 0.001 KILT to create a CType on the KILT blockchain.

:::

For a detailed developer-oriented guide to KILT CTypes, read the [CType Cookbook section](../../develop/01_sdk/02_cookbook/04_claiming/01_ctype_creation.md).
For a detailed developer-oriented guide to KILT CTypes, read the [CType Cookbook section](/develop/sdk/cookbook/claiming/ctype-creation).

[kilt-runtime-1.9.0]: https://github.com/KILTprotocol/kilt-node/releases/tag/1.9.0

Expand Down Expand Up @@ -124,7 +124,7 @@ const newCType = CType.fromProperties(oldCType.title, oldCType.properties, 'V1')
```

The new CType has the same title and properties as the existing one, but be based on the new metaschema, resulting in a different hash and id.
After [registering the new CType on the KILT blockchain](../../develop/01_sdk/02_cookbook/04_claiming/01_ctype_creation.md), you can use the new CType as a drop-in replacement in issuing credentials.
After [registering the new CType on the KILT blockchain](/develop/sdk/claiming/ctype-creation), you can use the new CType as a drop-in replacement in issuing credentials.

Verifiers depending on these CTypes should accept both the old and new CType during a transition period.
Test thoroughly to ensure the correct behavior and functionality of the new CTypes in your application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ The to-be-attested `Credential` contains the original claim, data needed for fut

:::info

For a detailed developer-oriented guide to KILT claims, read the [Claim Cookbook section](../../develop/01_sdk/02_cookbook/04_claiming/02_attestation_request.md).
For a detailed developer-oriented guide to KILT claims, read the [Claim Cookbook section](/develop/sdk/cookbook/claiming/attestation-request).

:::
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ After the credential has been attested, the Claimer can store it in their wallet

:::info

For a detailed developer-oriented guide to KILT attestations, read the [Attestation cookbook section](../../develop/01_sdk/02_cookbook/04_claiming/03_attestation_creation.md).
For a detailed developer-oriented guide to KILT attestations, read the [Attestation cookbook section](/develop/sdk/cookbook/claiming/attestation-creation).

:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This increases the privacy of the Claimer since they only need to show attribute

:::info

For a detailed developer-oriented guide to KILT presentation creation, read the [presentation creation cookbook section](../../develop/01_sdk/02_cookbook/04_claiming/04_presentation_creation.md).
For a detailed developer-oriented guide to KILT presentation creation, read the [presentation creation cookbook section](/develop/sdk/cookbook/claiming/presentation-creation).

:::

Expand Down Expand Up @@ -107,7 +107,7 @@ Therefore, the Verifier has to check if the CType matches one of the requested C

:::info

For a detailed developer-oriented guide to KILT credential verification, read the [verification cookbook section](../../develop/01_sdk/02_cookbook/04_claiming/05_presentation_verification.md).
For a detailed developer-oriented guide to KILT credential verification, read the [verification cookbook section](/develop/sdk/cookbook/claiming/presentation-verification).

:::

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ For example, `did:kilt:4q4QzFTs9hKh4QizLB3B7zuGYCG3QPamiBFEgwM6gTM7gK3g`
Currently only supports version 1.
- `blockNumber`: The block number of the relay chain to use for the generation of the DIP proof.
If not provided, uses the last finalized block.
- `linkedAccounts`: An array of [account addresses linked to the DID](../../develop/01_sdk/02_cookbook/03_account_linking/01_link.md##linking-an-account-to-a-did) to reveal in the generated proof.
- `web3Name`: Whether to reveal [the web3name of the DID subject](../../develop/01_sdk/02_cookbook/02_web3names/01_claim.md) in the generated proof.
- `linkedAccounts`: An array of [account addresses linked to the DID](/develop/sdk/cookbook/account_linking/account-link#linking-an-account-to-a-did) to reveal in the generated proof.
- `web3Name`: Whether to reveal [the web3name of the DID subject](/develop/sdk/cookbook/web3names/claim) in the generated proof.

In the example code, the configuration also has extra parameters for the time-bound DID signature extension [mentioned below](#creating-extensions-for-specific-proofs).

Expand Down Expand Up @@ -108,7 +108,7 @@ await signAndSubmitTx(consumerApi, dipSubmittable, submitterKeypair)
Linked accounts let you specify which accounts you want to prove that you control when you make the cross-chain proof.
As part of the proof provided, you can also include other values, such as the web3name.

For all the accounts you want to link, use the `associateAccountToChainArgs` method, [as detailed in this guide](../../develop/01_sdk/02_cookbook/03_account_linking/01_link.md##linking-an-account-to-a-did).
For all the accounts you want to link, use the `associateAccountToChainArgs` method, [as detailed in this guide](/develop/sdk/cookbook/account_linking/account-link#linking-an-account-to-a-did).

You can then batch all the linked account transactions and authorize them using the `authorizeTx` method.

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/concepts/08_messaging.md → concepts/08_messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ Therefore, this scheme still works if a DID should expose multiple encryption ke

:::caution
While no one can read or change what's inside an encrypted message even if they intercept it while traveling on the network, a sophisticated attacker may try to guess what's inside and trick either side of the channel by resubmitting a copy of that message later.
For a detailed developer-oriented guide about how to protect against *replay attacks*, read the [Replay Protection Cookbook section](../develop/01_sdk/02_cookbook/06_messaging/02_replay_protection.md).
For a detailed developer-oriented guide about how to protect against *replay attacks*, read the [Replay Protection Cookbook section](/develop/sdk/cookbook/messaging/replay-protection).
:::
File renamed without changes.
227 changes: 227 additions & 0 deletions develop/01_sdk/01_quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
---
id: quickstart
title: Quickstart
---

import CodeBlock from '@theme/CodeBlock';
import SnippetBlock from '@site/src/components/SnippetBlock';
import TsJsSnippet from '@site/src/components/TsJsSnippet';
import TsJsBlock from '@site/src/components/TsJsBlock';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

import PrintHelloWorld from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/01_print_hello_world.ts';
import ConnectSpirit from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/02_connect_spirit.ts';
import ConnectPere from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/02_connect_pere.ts';
import FetchDid from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/03_fetch_did.ts';
import FetchEndpoints from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/04_fetch_endpoints.ts';
import FetchEndpointData from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/05_fetch_endpoint_data.ts';
import VerifyCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/06_verify_credential.ts';
import Disconnect from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/getting_started/07_disconnect.ts';

Get started with KILT by following this guide, which teaches you to:

1. Import the **KILT SDK** into your project
2. Connect to the **KILT blockchain**
3. Query a **web3name** to retrieve its **DID**
4. Verify a **credential** using a **DID service**

:::info Prerequisites

This quickstart guide provides hands-on experience to enhance your understanding of KILT.
Basic knowledge of JavaScript and command-line tools is recommended.

:::

## Setup

Create a new project and directory and move into the directory by running `mkdir kilt-rocks && cd kilt-rocks`.

<Tabs groupId="ts-js-choice">
<TabItem value='ts' label='Typescript' default>

Inside the `kilt-rocks` project directory, install the **KILT SDK**, **Typescript**, **ts-node**, and **Axios** dependencies:

```bash npm2yarn
npm init -y
npm install @kiltprotocol/sdk-js ts-node typescript axios
```

With the required dependencies installed, create a TypeScript file with `touch quickstart.ts`.

</TabItem>
<TabItem value='js' label='Javascript'>

From inside the `kilt-rocks` project directory, install the **KILT SDK**, **Node**, and **Axios** dependencies:

```bash npm2yarn
npm init -y
npm install @kiltprotocol/sdk-js node axios
```

With the required dependencies installed, create a JavaScript file with `touch quickstart.js`.

To enable ES modules in your project, add `"type": "module"` to the `package.json` file.

</TabItem>
</Tabs>

Declare an `async main` function in the `quickstart.ts` file that executes the rest of the code in this quickstart and call the `main()` function by default:

{/* TODO: Do we need to test this or provide JS/TS equivalent? */}

```js
async function main() {
}

main()
```

**With the setup completed, let's get started! 🔥**

### Import the KILT SDK

Begin by importing the **KILT SDK** and **Axios** at the top of the file:

```js
import * as Kilt from '@kiltprotocol/sdk-js'
import axios from 'axios'
```

Now, you can access the SDK and all its functionality.
The next step is connecting to the **KILT blockchain**.

### Connect to the KILT Blockchain

To perform operations that rely on the **KILT blockchain**, such as querying and verifying a credential, you must first connect to the **KILT blockchain**.

Within the `main` function, configure the SDK to connect to a KILT node using the `Kilt.connect()` method:

<Tabs groupId="chain-choice">
<TabItem value='pere' label='Peregrine (Testnet)' default>
<p>Peregrine is the development blockchain.
Connect to this network for testing and development purposes.</p>
<SnippetBlock
className="language-ts"
dropTail="1"
>
{ConnectPere}
</SnippetBlock>
</TabItem>
<TabItem value='spirit' label='Spiritnet (Production)'>
<p>Spiritnet is the production blockchain.
When you are ready to publish your DApp, connect to the Spiritnet network for production purposes.</p>
<SnippetBlock
className="language-ts"
dropTail="1"
>
{ConnectSpirit}
</SnippetBlock>
</TabItem>
</Tabs>

To ensure proper cleanup, call the `Kilt.disconnect()` function at the bottom of the `main()` function.
You should add all other code before this function call:

<SnippetBlock
className="language-ts"
>
{Disconnect}
</SnippetBlock>

By adding `await Kilt.disconnect()`, you ensure that the connection to the blockchain node is properly closed when the script finishes executing, which helps maintain the integrity of your application and is a good practice to follow.

Run the code by calling the name of the file.
If you set up everything correctly, you should see no output showing that your code connected to the **KILT blockchain**.

<Tabs groupId="ts-js-choice">
<TabItem value='ts' label='Typescript' default>

```bash
yarn ts-node quickstart.ts
```

</TabItem>
<TabItem value='js' label='Javascript'>

```bash
node quickstart.js
```

</TabItem>
</Tabs>

As you add to the code in this file, you can always run it with the same command.

**Congratulations! 🔥**

You have connected to a KILT blockchain node.
The next step is to start querying data from the blockchain.

## Query a KILT Identity

The following code queries information related to a **web3name** (`kiltnerd123`) and uses it to retrieve the **KILT DID** linked to it.

Between the `Kilt.connect()` and `Kilt.disconnect()` lines, add the following code:

<SnippetBlock
className="language-ts"
dropTail="1"
>
{FetchDid}
</SnippetBlock>

Try running the code and check the result.

Did you get the DID? You now have `kiltnerd123`'s DID.
The next step is to see if `kiltnerd123` has any publicly linked KILT credentials to retrieve and verify.

## Retrieve and Verify a Credential

A **KILT DID** can expose services that allow external resources to be linked to the DID.
**KILT credentials** represent one type of external resource.

You can retrieve the **services** attached to kiltnerd123's DID and see if they link to any public credentials to **query** and **verify**.

Add the following code after the code you added in the previous step but before the `await Kilt.disconnect()`.
It retrieves the services exposed by the DID found for `kiltnerd123`:

<SnippetBlock
className="language-ts"
dropTail="1"
>
{FetchEndpoints}
</SnippetBlock>

The code should print endpoints as JSON.

The next step is to see if you can find a credential among them.
You do this by selecting one of the endpoints and querying the URL to see if it returns a KILT credential collection as described in the [KiltPublishedCredentialCollectionV1 specification](https://github.com/KILTprotocol/spec-KiltPublishedCredentialCollectionV1).

Add the following code after the code you added in the previous step but before `await Kilt.disconnect()`:

<TsJsSnippet dropTail="1">
{FetchEndpointData}
</TsJsSnippet>

If the script completes without errors, you retrieved the published credential using the URL specified in the service.

The next step is to make sure the credential is **valid** and has a valid **structure**.

The following code outputs a string depending on whether the credential is valid, revoked, or not valid.
Add it before `await Kilt.disconnect()`:

<SnippetBlock
className="language-ts"
>
{VerifyCredential}
</SnippetBlock>

Run the code and wait to see if you can retrieve **and** verify one of kiltnerd123's credentials!

:::info Next steps

- If you want to explore more of KILT's features, read our [Concepts section](/concepts/what-is-kilt).
- If you want to dive deeper into the SDK, read the next section, [the KILT Cookbook](./02_dids/01_light_did_creation.md).

:::
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions develop/01_sdk/04_claiming/01_ctype_creation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
id: ctype-creation
title: Create a CType
---

import TsJsBlock from '@site/src/components/TsJsBlock';

import CreateCType from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/claiming/01_create_ctype.ts';
import FetchCType from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/claiming/02_fetch_ctype.ts';

Every KILT credential has to conform to a CType.
A CType describes which properties a credential has and what type these properties have.
CTypes must be registered on the Spiritnet blockchain.
To learn more about CTypes, see the [CType concept section](/concepts/credentials/ctypes).

The creation of a CType in KILT involves two steps: the definition of a CType and the anchoring of its hash on the KILT blockchain.

:::info DID required
The creator of a CType is required to have a full DID with an attestation key.
To see how to manage DIDs, please refer to the [DID section](../02_dids/03_full_did_update.md).
:::

:::info CTypes are unique
The creation of a new CType requires the CType hash to be unique.
Before writing a new CType, Attesters should check whether there is already an existing CType which matches their requirements.

Visit our [CType index repository](https://github.com/KILTprotocol/ctype-index) for a non-exhaustive list of existing CTypes.
:::

The following snippets show how to create a CType:

<TsJsBlock>
{CreateCType}
</TsJsBlock>


## Retrieve a CType from its ID

CTypes can be queried directly from any KILT archive nodes.
The following example shows how to query a CType using the SDK:

<TsJsBlock>
{FetchCType}
</TsJsBlock>
21 changes: 21 additions & 0 deletions develop/01_sdk/04_claiming/03_attestation_creation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
id: attestation-creation
title: Attest a Claim (Issue a Credential)
---

import TsJsBlock from '@site/src/components/TsJsBlock';

import CreateAttestation from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/claiming/04_create_attestation.ts';

Once an Attester has received a to-be-attested `Credential` from a Claimer, they will typically verify the information in the claim.
If the claims correspond to truth, the Attester will proceed by attesting the root hash of the credential on the KILT blockchain, timestamping the attestation operation.
A deposit is reserved from the balance of the KILT account submitting the creation transaction, which is returned if and when the attestation is removed from the chain.

:::info
An Attester is required to have a full DID with an attestation key.
To see how to manage DIDs, please refer to the [DID section](../02_dids/03_full_did_update.md).
:::

<TsJsBlock>
{CreateAttestation}
</TsJsBlock>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ This is to save space on credentials that actually benefit from CBOR compression
Hence, creating public credentials without the SDK requires the credential to be CBOR-encoded!
:::

[ctypes-link]: ../../../../concepts/05_credentials/02_ctypes.md
[ctypes-link]: /concepts/credentials/ctypes
Loading

0 comments on commit 76246ff

Please sign in to comment.