-
Notifications
You must be signed in to change notification settings - Fork 19
fix: new-sdk-draft1 #329
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
base: master
Are you sure you want to change the base?
fix: new-sdk-draft1 #329
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't an ideal way of doing things, but it's missing from the SDK, so @rflechtner is going to add a new method and then we can update this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, as I explained above, unfortunately (as far as I saw), it’s not included in the new versions of the SDK. |
||
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,13 +1,12 @@ | ||
import axios from 'axios' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aybarsayan Not introduced by you, but this may be a good time to remove the axios package and replace it with a native fetch to make the HTTP requests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can change this in a new pr 😊 |
||
|
||
import * as Kilt from '@kiltprotocol/sdk-js' | ||
import { types } from '@kiltprotocol/credentials' | ||
|
||
export async function main( | ||
endpoints: Kilt.DidServiceEndpoint[] | ||
): Promise<Kilt.ICredential> { | ||
const { | ||
data: [{ credential }] | ||
} = await axios.get<Kilt.KiltPublishedCredentialCollectionV1>( | ||
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)}`) | ||
|
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not a valid import, you're probably looking for |
||
|
||
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.") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fairly certain this doesn't exist… DID-related methods are part of the
Kilt.DidHelpers.
and ``Kilt.DidResolver.`.Or is this some other way to access the methods @rflechtner ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I couldn’t find another way to access the
Did.linkedInfoFromChain
function. I foundapiConfig.call.did.linkedInfoFromChain(encodedKiltnerd123Details)
, but it doesn’t seem to work the same way and gives errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are indeed missing a function to resolve a DID document based on a w3n. This could be something worth adding to the DidResolver that Chris mentioned