Skip to content

Commit

Permalink
fix: new-sdk-draft2
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsayan committed Oct 28, 2024
1 parent 1816e43 commit 2fb4bf2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions code_examples/sdk_examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test": "ts-node src/test.ts"
},
"dependencies": {
"@kiltprotocol/sdk-js": "1",
"@kiltprotocol/sdk-js": "^1.0.0",
"axios": "^1.5.1",
"commander": "^11.1.0",
"dotenv": "^16.3.1",
Expand All @@ -36,4 +36,4 @@
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Kilt from '@kiltprotocol/sdk-js'
import * as Did from '@kiltprotocol/did'
import {Did} from "@kiltprotocol/types"

export async function main(id: String): Promise<Object[]> {
const kiltnerd123DidDocument = await Did.resolve(id)
export async function main(id: Did): Promise<Object[]> {
const kiltnerd123DidDocument = await Kilt.DidResolver.resolve(id)
console.log(`kiltnerd123's DID Document:`)
console.log(JSON.stringify(kiltnerd123DidDocument, null, 2))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios from 'axios'

import * as Kilt from '@kiltprotocol/sdk-js'
import { VerifiableCredential } from '@kiltprotocol/credentials/lib/cjs/V1/types'
import { types } from '@kiltprotocol/credentials'

export async function main(
endpoints: Kilt.Service<DidUrl>[]
): Promise<VerifiableCredential> {
const { data: credential } = await axios.get<VerifiableCredential>(
endpoints: types.DidUrl[]
): Promise<types.VerifiableCredential> {
const { data: credential } = await axios.get<types.VerifiableCredential>(
endpoints[0].serviceEndpoint[0]
)
console.log(`Credentials: ${JSON.stringify(credential, null, 2)}`)
Expand Down
39 changes: 21 additions & 18 deletions docs/develop/01_sdk/01_quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ To enable ES modules in your project, add `"type": "module"` to the `package.jso

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? _/}
{/* TODO: Do we need to test this or provide JS/TS equivalent? */}

```js
async function main() {}
async function main() {
}

main()
```
Expand All @@ -83,8 +84,10 @@ main()
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'
import * as Kilt from "@kiltprotocol/sdk-js";
import axios from "axios";
import * as Did from "@kiltprotocol/did";
import {types}from "@kiltprotocol/credentials"
```

Now, you can access the SDK and all its functionality.
Expand Down Expand Up @@ -124,9 +127,9 @@ You should add all other code before this function call:

<SnippetBlock
className="language-ts"

> {Disconnect}
> </SnippetBlock>
>
{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.

Expand Down Expand Up @@ -166,9 +169,9 @@ Between the `Kilt.connect()` and `Kilt.disconnect()` lines, add the following co
<SnippetBlock
className="language-ts"
dropTail="1"

> {FetchDid}
> </SnippetBlock>
>
{FetchDid}
</SnippetBlock>

Try running the code and check the result.

Expand All @@ -188,9 +191,9 @@ It retrieves the services exposed by the DID found for `kiltnerd123`:
<SnippetBlock
className="language-ts"
dropTail="1"

> {FetchEndpoints}
> </SnippetBlock>
>
{FetchEndpoints}
</SnippetBlock>

The code should print endpoints as JSON.

Expand All @@ -212,15 +215,15 @@ Add it before `await Kilt.disconnect()`:

<SnippetBlock
className="language-ts"

> {VerifyCredential}
> </SnippetBlock>
>
{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/01_what_is_kilt.md).
- If you want to dive deeper into the SDK, read the next section, [the KILT Cookbook](./02_cookbook/01_dids/01_light_did_creation.md).
- If you want to explore more of KILT's features, read our [Concepts section](../../concepts/01_what_is_kilt.md).
- If you want to dive deeper into the SDK, read the next section, [the KILT Cookbook](./02_cookbook/01_dids/01_light_did_creation.md).

:::
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@docusaurus/preset-classic": "^3.1.0",
"@docusaurus/remark-plugin-npm2yarn": "^3.1.0",
"@docusaurus/theme-mermaid": "^3.1.0",
"@kiltprotocol/sdk-js": "1.0",
"@mdx-js/react": "^3.0.0",
"archiver": "^6.0.1",
"clsx": "^2.1.0",
Expand Down

0 comments on commit 2fb4bf2

Please sign in to comment.