-
Notifications
You must be signed in to change notification settings - Fork 20
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
doc: w3n query #261
Merged
Merged
doc: w3n query #261
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 9 additions & 14 deletions
23
code_examples/sdk_examples/src/core_features/web3names/02_query_did_name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
import { assert } from 'console' | ||
|
||
import * as Kilt from '@kiltprotocol/sdk-js' | ||
|
||
export async function verifyNameAndDidEquality( | ||
web3Name: Kilt.Did.Web3Name, | ||
did: Kilt.DidUri | ||
): Promise<void> { | ||
export async function queryDidDocument( | ||
web3Name: Kilt.Did.Web3Name | ||
): Promise<Kilt.DidDocument> { | ||
const api = Kilt.ConfigService.get('api') | ||
|
||
console.log( | ||
`Querying the blockchain for the web3name "${web3Name}" and the DID "${did}"...` | ||
) | ||
console.log(`Querying the blockchain for the web3name "${web3Name}"`) | ||
// Query the owner of the provided web3name. | ||
const encodedWeb3NameOwner = await api.call.did.queryByWeb3Name(web3Name) | ||
const { | ||
document: { uri } | ||
} = Kilt.Did.linkedInfoFromChain(encodedWeb3NameOwner) | ||
// Assert that it is the right owner. | ||
assert(uri === did) | ||
|
||
// Extract the DidDocument and other linked information from the encodedWeb3NameOwner. | ||
const { document } = Kilt.Did.linkedInfoFromChain(encodedWeb3NameOwner) | ||
|
||
return document | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
id: web3name-query | ||
title: Resolve a web3name | ||
--- | ||
|
||
import TsJsBlock from '@site/src/components/TsJsBlock'; | ||
|
||
import QueryDid from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/web3names/02_query_did_name.ts'; | ||
|
||
|
||
A web3name can be resolved in a similar manner to [how a DID is resolved](../01_dids/04_did_query.md). | ||
Resolving the web3name will provide the same information as resolving a DID does. | ||
|
||
To query and retrieve the DID document associated with a web3name, you can use the following code example: | ||
|
||
|
||
<TsJsBlock> | ||
{QueryDid} | ||
</TsJsBlock> | ||
|
||
In the code example above, the `queryDidDocument` function takes a web3Name parameter, which represents the web3name to be resolved. | ||
It internally uses the `api.call.did.queryByWeb3Name` method to query the information of the provided web3name from the blockchain. | ||
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. Same as above. |
||
|
||
The function then decodes the result using `Kilt.Did.linkedInfoFromChain` to extract the associated DID document and any other linked blockchain accounts. Finally, it returns the resolved DID document. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this the right direction to go? We would not be able to catch any of these inconsistencies if the naming changes, at some point. What about adding comments to the code snippet directly?
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 think adding comments to the code make it less readable. e.g. hard to spot what is actually going on, finding the function calls in between all the comments.
Yes this can get outdated, but I would hope that not only the code example is checked when there is an error, but also the guide where the code is used. 😓