Skip to content

Commit

Permalink
fix: new-sdk-draft1
Browse files Browse the repository at this point in the history
  • Loading branch information
aybarsayan committed Oct 22, 2024
1 parent e622d71 commit 1816e43
Show file tree
Hide file tree
Showing 9 changed files with 1,398 additions and 308 deletions.
2 changes: 1 addition & 1 deletion 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": "0.35.0",
"@kiltprotocol/sdk-js": "1",
"axios": "^1.5.1",
"commander": "^11.1.0",
"dotenv": "^16.3.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable prefer-const */
import * as Kilt from '@kiltprotocol/sdk-js'
import * as Did from '@kiltprotocol/did'

export async function main(): Promise<Kilt.DidUri | null> {
export async function main(): Promise<String | null> {
let apiConfig = Kilt.ConfigService.get('api')
const encodedKiltnerd123Details =
await apiConfig.call.did.queryByWeb3Name('kiltnerd123')

// This function will throw if kiltnerd123 does not exist
const {
document: { uri }
} = Kilt.Did.linkedInfoFromChain(encodedKiltnerd123Details)
console.log(`My name is kiltnerd123 and this is my DID: "${uri}"`)
document: { id }
} = Did.linkedInfoFromChain(encodedKiltnerd123Details)
console.log(`My name is kiltnerd123 and this is my DID: "${id}"`)

return uri
return id
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import * as Kilt from '@kiltprotocol/sdk-js'
import * as Did from '@kiltprotocol/did'

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

const endpoints = kiltnerd123DidDocument?.document?.service
const endpoints = kiltnerd123DidDocument?.didDocument?.service
if (!endpoints) {
console.log('No endpoints for the DID.')
return []
}

console.log('Endpoints:')
console.log(JSON.stringify(endpoints, null, 2))

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

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

export async function main(
endpoints: Kilt.DidServiceEndpoint[]
): Promise<Kilt.ICredential> {
const {
data: [{ credential }]
} = await axios.get<Kilt.KiltPublishedCredentialCollectionV1>(
endpoints: Kilt.Service<DidUrl>[]
): Promise<VerifiableCredential> {
const { data: credential } = await axios.get<VerifiableCredential>(
endpoints[0].serviceEndpoint[0]
)
console.log(`Credentials: ${JSON.stringify(credential, null, 2)}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as Kilt from '@kiltprotocol/sdk-js'
import { VerifiableCredential } from '@kiltprotocol/credentials/lib/cjs/V1/types'

export async function main(credential: Kilt.ICredential): Promise<void> {
export async function main(credential: VerifiableCredential): Promise<void> {
try {
const { attester, revoked } =
await Kilt.Credential.verifyCredential(credential)

// Verify that the credential is not revoked. Exception caught by the catch {} block below.
if (revoked) {
throw new Error('The credential has been revoked, hence it is not valid.')
const result = await Kilt.Verifier.verifyCredential({ credential })
console.log(JSON.stringify(result, null, 2))
if (result.verified == false) {
throw new Error("kiltnerd123's credential is not valid.")
} else {
console.log(`kiltnerd123's credential is valid`)
}
console.log(
`kiltnerd123's credential is valid and has been attested by ${attester}!`
)
} catch {
console.log("kiltnerd123's credential is not valid.")
}
Expand Down
Loading

0 comments on commit 1816e43

Please sign in to comment.