From 1213e05ff9720775cac2c09fcfa246219ed71e72 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Thu, 21 Mar 2024 16:44:33 +0100 Subject: [PATCH 01/22] Draft Signed-off-by: Chris Chinchilla --- .../src/workshop/attester/generateAccount.ts | 4 +- .../src/workshop/attester/generateDid.ts | 63 ++++++++----------- .../develop/03_workshop/04_attester/02_did.md | 35 ++++------- 3 files changed, 39 insertions(+), 63 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts b/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts index 02da570b3..4a195e76d 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts @@ -5,7 +5,7 @@ import * as Kilt from '@kiltprotocol/sdk-js' export function generateAccount( mnemonic = Kilt.Utils.Crypto.mnemonicGenerate() ): { - account: Kilt.KiltKeyringPair + account: Kilt.KiltKeyringPair & { type: "ed25519" } mnemonic: string } { return { @@ -31,4 +31,4 @@ if (require.main === module) { throw e } })() -} +} \ No newline at end of file diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index e0c900c78..b18b622c2 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -1,51 +1,40 @@ import { config as envConfig } from 'dotenv' import * as Kilt from '@kiltprotocol/sdk-js' - +// TODO: No longer needed in content, but needed for tutorial? +// TODO: What to do? +// TODO: And generateAccount needed changes, why? import { generateAccount } from './generateAccount' -import { generateKeypairs } from './generateKeypairs' - -export async function createFullDid( - submitterAccount: Kilt.KiltKeyringPair -): Promise<{ - mnemonic: string - fullDid: Kilt.DidDocument -}> { - const api = Kilt.ConfigService.get('api') - const mnemonic = Kilt.Utils.Crypto.mnemonicGenerate() - const { - authentication, - keyAgreement, - assertionMethod, - capabilityDelegation - } = generateKeypairs(mnemonic) - // Get tx that will create the DID on chain and DID-URI that can be used to resolve the DID Document. - const fullDidCreationTx = await Kilt.Did.getStoreTx( - { - authentication: [authentication], - keyAgreement: [keyAgreement], - assertionMethod: [assertionMethod], - capabilityDelegation: [capabilityDelegation] - }, - submitterAccount.address, - async ({ data }) => ({ - signature: authentication.sign(data), - keyType: authentication.type +export async function createFullDid() { + const api = await Kilt.connect(process.env.WSS_ADDRESS as string); + const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string; + const { account } = generateAccount(accountMnemonic); + const { type, publicKey } = account; + + const txs = [ + api.tx.did.createFromAccount({ [type]: publicKey }), + api.tx.did.setAttestationKey({ [type]: publicKey }), + ]; + + console.log("Creating DID from account…"); + await Kilt.Blockchain.signAndSubmitTx(api.tx.utility.batch(txs), account) + .then((result) => { + console.log(result); }) - ) - - await Kilt.Blockchain.signAndSubmitTx(fullDidCreationTx, submitterAccount) + .catch((error) => { + console.log(error); + }); - const didUri = Kilt.Did.getFullDidUriFromKey(authentication) - const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)) - const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid) + const didUri = Kilt.Did.getFullDidUriFromKey(account); + const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)); + const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid); if (!document) { - throw new Error('Full DID was not successfully created.') + throw new Error("Full DID was not successfully created."); } - return { mnemonic, fullDid: document } + console.log(document); } // Don't execute if this is imported by another file. diff --git a/docs/develop/03_workshop/04_attester/02_did.md b/docs/develop/03_workshop/04_attester/02_did.md index bc294b575..b3bafdcfd 100644 --- a/docs/develop/03_workshop/04_attester/02_did.md +++ b/docs/develop/03_workshop/04_attester/02_did.md @@ -58,43 +58,30 @@ In summary, you register a DID on the blockchain by an account submitting the DI As an Attester needs to interact with the chain, you must create a full DID. -### Generate key pairs - -An Attester needs an authentication and attestation key at minimum. -Since three of the key types sign transactions, you can use the same key for them using the default KILT keyring to generate them, which is the same keyring used to generate accounts. - -Add the following code to the `attester/generateKeypairs` file. - - - {GenerateKeypairs} - +### Write DID to chain -Throughout the code are `account.derive` methods that use key derivation syntax. You can read more about this syntax in [the Substrate documentation](https://docs.substrate.io/reference/command-line-tools/subkey/#working-with-derived-keys). +The KILT SDK provides multiple methods to create DIDs, this workshop highlights the `createFromAccount` method, that creates a DID from any pre-existing substrate-compatible account. -The `generateKeypairs` function code derives base and sub keys from a particular path relevant to the use case for each key. -It uses the sr25519 key type, which is the default key type for KILT. + + -This method works for three of the four key types needed, so the `generateKeyAgreement` function helps generate the key-agreement key pair using the mnemonic. -The function takes the mnemonic and creates another key pair from it using the `sr25519PairFromSeed(mnemonicToMiniSecret(mnemonic))` combination of functions. -The function then creates a secret key based on the earlier temporary key pair and a derivation path relevant to key agreement. +:::info other methods -The function returns the key pair needed by generating one more key pair suitable for encryption and decryption using the secret key. +ff -### Write DID to chain +::: -Once you have created all the necessary keys for a DID, you can create the on-chain DID. -To create a DID, load the account created in the [last section](./01_account.md) and use it to pay for the DID registration. Create and submit the extrinsic (aka transaction) that registers the DID. {GenerateDid} -The `createFullDid` function takes the key pair generated for the submitter in the previous step and creates a full DID. It returns a mnemonic as a string and DID document. -Inside the function, the `getStoreTx` method creates a DID creation operation based on the four key pairs created earlier. -It returns the extrinsic (aka transaction) that registers the DID. +The `txs` array holds the two transactions containing the extrinsics needed to submit to the chain for the Attester's DID creation. + +The `createFromAccount` method takes the public key of the account to attach the DID to, and the `setAttestationKey` method takes the same parameter to set the attestation key the DID will need and use. -The `signAndSubmitTx` method takes that extrinsic and submits it to the chain, also passing the submitter's account. +The `signAndSubmitTx` method then takes those transactions and submits them as a batch to the chain. ## Run the code From 315666441118b20b2466e4d6ac8461bc0731af83 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 26 Mar 2024 17:49:58 +0100 Subject: [PATCH 02/22] Factor into tests Signed-off-by: Chris Chinchilla --- .../src/workshop/attester/generateDid.ts | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index b18b622c2..1c931028e 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -1,15 +1,17 @@ -import { config as envConfig } from 'dotenv' +import { config as envConfig } from "dotenv"; -import * as Kilt from '@kiltprotocol/sdk-js' -// TODO: No longer needed in content, but needed for tutorial? -// TODO: What to do? -// TODO: And generateAccount needed changes, why? -import { generateAccount } from './generateAccount' +import * as Kilt from "@kiltprotocol/sdk-js"; +import { generateAccount } from "./generateAccount"; -export async function createFullDid() { +export async function createFullDid( + submitterAccount: Kilt.KiltKeyringPair +): Promise<{ + mnemonic: string; + fullDid: Kilt.DidDocument; +}> { const api = await Kilt.connect(process.env.WSS_ADDRESS as string); - const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string; - const { account } = generateAccount(accountMnemonic); + const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string; + const { account } = generateAccount(mnemonic); const { type, publicKey } = account; const txs = [ @@ -18,44 +20,42 @@ export async function createFullDid() { ]; console.log("Creating DID from account…"); - await Kilt.Blockchain.signAndSubmitTx(api.tx.utility.batch(txs), account) - .then((result) => { - console.log(result); - }) - .catch((error) => { - console.log(error); - }); - - const didUri = Kilt.Did.getFullDidUriFromKey(account); - const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)); - const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid); - - if (!document) { + const didDocument = await Kilt.Blockchain.signAndSubmitTx( + api.tx.utility.batch(txs), + account + ).then(async () => { + const didUri = Kilt.Did.getFullDidUriFromKey(account); + const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)); + const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid); + return document + }); + + if (!didDocument) { throw new Error("Full DID was not successfully created."); } - console.log(document); + return { mnemonic, fullDid: didDocument }; } // Don't execute if this is imported by another file. if (require.main === module) { - ;(async () => { - envConfig() + (async () => { + envConfig(); try { - await Kilt.connect(process.env.WSS_ADDRESS as string) + await Kilt.connect(process.env.WSS_ADDRESS as string); // Load attester account - const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string - const { account } = generateAccount(accountMnemonic) - const { mnemonic, fullDid } = await createFullDid(account) + const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string; + const { account } = generateAccount(accountMnemonic); + const { mnemonic, fullDid } = await createFullDid(account); - console.log('\nsave following to .env to continue\n') - console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`) - console.error(`ATTESTER_DID_URI="${fullDid.uri}"\n`) + console.log("\nsave following to .env to continue\n"); + console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`); + console.error(`ATTESTER_DID_URI="${fullDid.uri}"\n`); } catch (e) { - console.log('Error while creating attester DID') - throw e + console.log("Error while creating attester DID"); + throw e; } - })() + })(); } From 9daa9a3b765ff7ca976c546fb31e101c71ea1580 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 26 Mar 2024 18:08:25 +0100 Subject: [PATCH 03/22] Update docs Signed-off-by: Chris Chinchilla --- .../develop/03_workshop/04_attester/02_did.md | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/develop/03_workshop/04_attester/02_did.md b/docs/develop/03_workshop/04_attester/02_did.md index b3bafdcfd..2386bf454 100644 --- a/docs/develop/03_workshop/04_attester/02_did.md +++ b/docs/develop/03_workshop/04_attester/02_did.md @@ -5,6 +5,7 @@ title: DID import CodeBlock from '@theme/CodeBlock'; import TsJsBlock from '@site/src/components/TsJsBlock'; +import SnippetBlock from '@site/src/components/SnippetBlock'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -26,12 +27,12 @@ Other users can now encrypt messages using your public encryption key and send a Kilt supports two DID types: **light** and **full**. -There are many differences between the two types, but the most crucial is that you can use a light DID offline, but a full DID needs access to the blockchain to work. +There are differences between the two types, but the most crucial is that you can use a light DID offline, but a full DID needs access to the blockchain to work. Read the [DID documentation](../../../develop/01_sdk/02_cookbook/01_dids/01_light_did_creation.md) to learn more about the difference between the light and full types. :::info KILT DID -There are four different key types that a DID supports: +A DID supports four different key types: - An _authentication key pair_, used to sign claims and present authenticated credentials - A _key-agreement key pair_, used to encrypt/decrypt messages @@ -62,12 +63,11 @@ As an Attester needs to interact wi The KILT SDK provides multiple methods to create DIDs, this workshop highlights the `createFromAccount` method, that creates a DID from any pre-existing substrate-compatible account. - - + -:::info other methods +:::info Bring your own account -ff +This workshop assumes you followed the [create account step](./01_account.md), but if you have a pre-existing account, you can use that instead by adding the `ATTESTER_ACCOUNT_ADDRESS` and `ATTESTER_ACCOUNT_MNEMONIC` to the `.env` file. ::: @@ -104,15 +104,17 @@ Now run the code with: -Once you have run the script, the output should provide you with your `ATTESTER_DID_MNEMONIC` and `ATTESTER_DID_URI`. -The output should look like the following, but not identical since the DIDs are constructed from your account: +Once you have run the script, the output should provide you with the `ATTESTER_DID_MNEMONIC` and `ATTESTER_DID_URI`. +Using the `createFromAccount` method means that the `ATTESTER_DID_MNEMONIC` and `ATTESTER_ACCOUNT_MNEMONIC` are the same. + +The output should look like the following, but not identical since the code creates the DIDs from your account: ``` ATTESTER_DID_MNEMONIC="beyond large galaxy… ATTESTER_DID_URI="did:kilt:4ohMvUHsyeD…" ``` -Save it in the `.env` file, which should now look like the following: +Save the values in the `.env` file, which should now look like the following: ```env title=".env" WSS_ADDRESS=wss://peregrine.kilt.io From b2b37ba5661aafe5d039827d6fea00de17b1b2f7 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 26 Mar 2024 18:08:42 +0100 Subject: [PATCH 04/22] Lint Signed-off-by: Chris Chinchilla --- .../src/workshop/attester/generateAccount.ts | 4 +- .../src/workshop/attester/generateDid.ts | 61 +++++++++---------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts b/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts index 4a195e76d..74e647445 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateAccount.ts @@ -5,7 +5,7 @@ import * as Kilt from '@kiltprotocol/sdk-js' export function generateAccount( mnemonic = Kilt.Utils.Crypto.mnemonicGenerate() ): { - account: Kilt.KiltKeyringPair & { type: "ed25519" } + account: Kilt.KiltKeyringPair & { type: 'ed25519' } mnemonic: string } { return { @@ -31,4 +31,4 @@ if (require.main === module) { throw e } })() -} \ No newline at end of file +} diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 1c931028e..11b04070e 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -1,61 +1,60 @@ -import { config as envConfig } from "dotenv"; - -import * as Kilt from "@kiltprotocol/sdk-js"; -import { generateAccount } from "./generateAccount"; +import { config as envConfig } from 'dotenv' +import * as Kilt from '@kiltprotocol/sdk-js' +import { generateAccount } from './generateAccount' export async function createFullDid( submitterAccount: Kilt.KiltKeyringPair ): Promise<{ - mnemonic: string; - fullDid: Kilt.DidDocument; + mnemonic: string + fullDid: Kilt.DidDocument }> { - const api = await Kilt.connect(process.env.WSS_ADDRESS as string); - const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string; - const { account } = generateAccount(mnemonic); - const { type, publicKey } = account; + const api = await Kilt.connect(process.env.WSS_ADDRESS as string) + const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string + const { account } = generateAccount(mnemonic) + const { type, publicKey } = account const txs = [ api.tx.did.createFromAccount({ [type]: publicKey }), - api.tx.did.setAttestationKey({ [type]: publicKey }), - ]; + api.tx.did.setAttestationKey({ [type]: publicKey }) + ] - console.log("Creating DID from account…"); + console.log('Creating DID from account…') const didDocument = await Kilt.Blockchain.signAndSubmitTx( api.tx.utility.batch(txs), account ).then(async () => { - const didUri = Kilt.Did.getFullDidUriFromKey(account); - const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)); - const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid); + const didUri = Kilt.Did.getFullDidUriFromKey(account) + const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)) + const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid) return document - }); + }) if (!didDocument) { - throw new Error("Full DID was not successfully created."); + throw new Error('Full DID was not successfully created.') } - return { mnemonic, fullDid: didDocument }; + return { mnemonic, fullDid: didDocument } } // Don't execute if this is imported by another file. if (require.main === module) { - (async () => { - envConfig(); + ;(async () => { + envConfig() try { - await Kilt.connect(process.env.WSS_ADDRESS as string); + await Kilt.connect(process.env.WSS_ADDRESS as string) // Load attester account - const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string; - const { account } = generateAccount(accountMnemonic); - const { mnemonic, fullDid } = await createFullDid(account); + const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string + const { account } = generateAccount(accountMnemonic) + const { mnemonic, fullDid } = await createFullDid(account) - console.log("\nsave following to .env to continue\n"); - console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`); - console.error(`ATTESTER_DID_URI="${fullDid.uri}"\n`); + console.log('\nsave following to .env to continue\n') + console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`) + console.error(`ATTESTER_DID_URI="${fullDid.uri}"\n`) } catch (e) { - console.log("Error while creating attester DID"); - throw e; + console.log('Error while creating attester DID') + throw e } - })(); + })() } From 802d3abe7663530bb0e50e9eaf8e9618b8bb887c Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Thu, 28 Mar 2024 15:12:17 +0100 Subject: [PATCH 05/22] Draft Signed-off-by: Chris Chinchilla --- .../src/workshop/attester/attestCredential.ts | 7 +------ .../src/workshop/attester/generateDid.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts index 0344f8a82..44a5101cb 100644 --- a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts +++ b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts @@ -23,12 +23,7 @@ export async function attestCredential( // Create the tx and authorize it. const tx = api.tx.attestation.add(claimHash, cTypeHash, null) - const extrinsic = await Kilt.Did.authorizeTx( - attesterDid, - tx, - signCallback, - attesterAccount.address - ) + const extrinsic = api.tx.did.dispatchAs(attesterAccount.address, tx) // Submit the tx to write the attestation to the chain. console.log('Attester -> create attestation...') diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 11b04070e..def627d5b 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -8,22 +8,27 @@ export async function createFullDid( mnemonic: string fullDid: Kilt.DidDocument }> { - const api = await Kilt.connect(process.env.WSS_ADDRESS as string) + // console.log(process.env.WSS_ADDRESS) + // const api = await Kilt.connect(process.env.WSS_ADDRESS as string) + const api = Kilt.ConfigService.get('api') const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string - const { account } = generateAccount(mnemonic) - const { type, publicKey } = account + // const { account: didAccount } = generateDidAccount(mnemonic) + const { type, publicKey } = submitterAccount const txs = [ - api.tx.did.createFromAccount({ [type]: publicKey }), - api.tx.did.setAttestationKey({ [type]: publicKey }) + api.tx.did.createFromAccount({ [type as 'ed25519']: publicKey }), + api.tx.did.dispatchAs( + submitterAccount.address, + api.tx.did.setAttestationKey({ [type as 'ed25519']: publicKey }) + ) ] console.log('Creating DID from account…') const didDocument = await Kilt.Blockchain.signAndSubmitTx( api.tx.utility.batch(txs), - account + submitterAccount ).then(async () => { - const didUri = Kilt.Did.getFullDidUriFromKey(account) + const didUri = Kilt.Did.getFullDidUriFromKey(submitterAccount) const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)) const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid) return document From 3bb956866d312a7ee2f78b4cfe8f2d7dfee38565 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Thu, 28 Mar 2024 16:29:37 +0100 Subject: [PATCH 06/22] Lint Signed-off-by: Chris Chinchilla --- .../src/core_features/signCallback/index.ts | 2 +- .../src/dapp/dapp/04_attest_credential.ts | 23 ++++++++++--------- .../src/workshop/attester/attestCredential.ts | 2 ++ .../src/workshop/attester/generateDid.ts | 5 +--- docusaurus.config.js | 1 - 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/code_examples/sdk_examples/src/core_features/signCallback/index.ts b/code_examples/sdk_examples/src/core_features/signCallback/index.ts index da9341892..9d68391a8 100644 --- a/code_examples/sdk_examples/src/core_features/signCallback/index.ts +++ b/code_examples/sdk_examples/src/core_features/signCallback/index.ts @@ -5,8 +5,8 @@ import { useSignExtrinsicCallback } from './useExtrinsicCallback' import { useStoreTxSignCallback } from './useStoreTxSignCallback' // The _keyUri parameter is there to show that the DID key pair is looked up using the URI -// eslint-disable-next-line @typescript-eslint/no-unused-vars export function lookupDidKeyPair( + // eslint-disable-next-line @typescript-eslint/no-unused-vars _keyUri: Kilt.DidResourceUri ): Kilt.KiltKeyringPair { return Kilt.Utils.Crypto.makeKeypairFromSeed() diff --git a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts index 46d758ce2..75f8a1eb1 100644 --- a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts +++ b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts @@ -12,7 +12,6 @@ export async function main({ domainLinkageCredential: Kilt.ICredential }) { const api = Kilt.ConfigService.get('api') - const { cTypeHash, claimHash } = Kilt.Attestation.fromCredentialAndDid( domainLinkageCredential, didUri @@ -20,18 +19,20 @@ export async function main({ const attestationTx = api.tx.attestation.add(claimHash, cTypeHash, null) // We authorize the call using the attestation key of the Dapps DID. - const submitTx = await Kilt.Did.authorizeTx( - didUri, - attestationTx, - async ({ data }) => ({ - signature: assertionMethodKey.sign(data), - keyType: assertionMethodKey.type - }), - dappAccount.address - ) + const extrinsic = api.tx.did.dispatchAs(dappAccount.address, attestationTx) + + // const submitTx = await Kilt.Did.authorizeTx( + // didUri, + // attestationTx, + // async ({ data }) => ({ + // signature: assertionMethodKey.sign(data), + // keyType: assertionMethodKey.type + // }), + // dappAccount.address + // ) // Since DIDs can not hold any balance, we pay for the transaction using our blockchain account - const result = await Kilt.Blockchain.signAndSubmitTx(submitTx, dappAccount) + const result = await Kilt.Blockchain.signAndSubmitTx(extrinsic, dappAccount) if (result.isError) { console.log('Attestation failed') diff --git a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts index 44a5101cb..94f692af7 100644 --- a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts +++ b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts @@ -11,6 +11,8 @@ export async function attestCredential( attesterAccount: Kilt.KiltKeyringPair, attesterDid: Kilt.DidUri, credential: Kilt.ICredential, + // TODO: Sort later + // eslint-disable-next-line @typescript-eslint/no-unused-vars signCallback: Kilt.SignExtrinsicCallback ): Promise { const api = Kilt.ConfigService.get('api') diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index def627d5b..5f0050dad 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -1,5 +1,5 @@ -import { config as envConfig } from 'dotenv' import * as Kilt from '@kiltprotocol/sdk-js' +import { config as envConfig } from 'dotenv' import { generateAccount } from './generateAccount' export async function createFullDid( @@ -8,11 +8,8 @@ export async function createFullDid( mnemonic: string fullDid: Kilt.DidDocument }> { - // console.log(process.env.WSS_ADDRESS) - // const api = await Kilt.connect(process.env.WSS_ADDRESS as string) const api = Kilt.ConfigService.get('api') const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string - // const { account: didAccount } = generateDidAccount(mnemonic) const { type, publicKey } = submitterAccount const txs = [ diff --git a/docusaurus.config.js b/docusaurus.config.js index e9a2e8350..e81909af6 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -238,7 +238,6 @@ module.exports = { outDir: "docs/concepts/07_dip", // the base directory to output to. documents: ["README.md"], // the file names to download, modifyContent(filename, content) { - console.log(content) if (filename.includes("README")) { return { filename: "02_provider.md", From 90dc96e2b38d6471ac3ba850945fbb47537fc099 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 2 Apr 2024 13:08:56 +0200 Subject: [PATCH 07/22] Update dependencies Signed-off-by: Chris Chinchilla --- code_examples/sdk_examples/package.json | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/code_examples/sdk_examples/package.json b/code_examples/sdk_examples/package.json index 6edd12b47..db44f9467 100644 --- a/code_examples/sdk_examples/package.json +++ b/code_examples/sdk_examples/package.json @@ -14,26 +14,26 @@ }, "dependencies": { "@kiltprotocol/sdk-js": "0.35.0", - "axios": "^1.5.1", - "commander": "^11.1.0", - "dotenv": "^16.3.1", - "web3": "^4.1.2" + "axios": "^1.6.8", + "commander": "^12.0.0", + "dotenv": "^16.4.5", + "web3": "^4.7.0" }, "devDependencies": { - "@polkadot/types": "^10.4.0", - "@types/node": "^20.8.6", - "@types/node-fetch": "^2.6.6", - "@typescript-eslint/eslint-plugin": "^5.36.0", - "@typescript-eslint/parser": "^6.8.0", - "eslint": "^8.51.0", - "eslint-config-prettier": "^9.0.0", + "@polkadot/types": "^10.12.4", + "@types/node": "^20.12.2", + "@types/node-fetch": "^2.6.11", + "@typescript-eslint/eslint-plugin": "^7.5.0", + "@typescript-eslint/parser": "^7.5.0", + "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", "eslint-formatter-codeframe": "^7.32.1", - "eslint-plugin-import": "^2.28.1", + "eslint-plugin-import": "^2.29.1", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^5.0.1", - "node-fetch": "^2.6.7", - "prettier": "^3.0.3", - "ts-node": "^10.9.1", - "typescript": "^5.2.2" + "eslint-plugin-prettier": "^5.1.3", + "node-fetch": "^3.3.2", + "prettier": "^3.2.5", + "ts-node": "^10.9.2", + "typescript": "^5.4.3" } } From 2e030ec65d983628b7172d8f77495f4a7b5002b5 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 2 Apr 2024 13:27:16 +0200 Subject: [PATCH 08/22] Revert Signed-off-by: Chris Chinchilla --- code_examples/sdk_examples/package.json | 34 ++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/code_examples/sdk_examples/package.json b/code_examples/sdk_examples/package.json index db44f9467..6edd12b47 100644 --- a/code_examples/sdk_examples/package.json +++ b/code_examples/sdk_examples/package.json @@ -14,26 +14,26 @@ }, "dependencies": { "@kiltprotocol/sdk-js": "0.35.0", - "axios": "^1.6.8", - "commander": "^12.0.0", - "dotenv": "^16.4.5", - "web3": "^4.7.0" + "axios": "^1.5.1", + "commander": "^11.1.0", + "dotenv": "^16.3.1", + "web3": "^4.1.2" }, "devDependencies": { - "@polkadot/types": "^10.12.4", - "@types/node": "^20.12.2", - "@types/node-fetch": "^2.6.11", - "@typescript-eslint/eslint-plugin": "^7.5.0", - "@typescript-eslint/parser": "^7.5.0", - "eslint": "^8.57.0", - "eslint-config-prettier": "^9.1.0", + "@polkadot/types": "^10.4.0", + "@types/node": "^20.8.6", + "@types/node-fetch": "^2.6.6", + "@typescript-eslint/eslint-plugin": "^5.36.0", + "@typescript-eslint/parser": "^6.8.0", + "eslint": "^8.51.0", + "eslint-config-prettier": "^9.0.0", "eslint-formatter-codeframe": "^7.32.1", - "eslint-plugin-import": "^2.29.1", + "eslint-plugin-import": "^2.28.1", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^5.1.3", - "node-fetch": "^3.3.2", - "prettier": "^3.2.5", - "ts-node": "^10.9.2", - "typescript": "^5.4.3" + "eslint-plugin-prettier": "^5.0.1", + "node-fetch": "^2.6.7", + "prettier": "^3.0.3", + "ts-node": "^10.9.1", + "typescript": "^5.2.2" } } From 02b7db9669e82a741fe2d97e6e86c2b1d6eb40a7 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 2 Apr 2024 14:13:37 +0200 Subject: [PATCH 09/22] Update docs Signed-off-by: Chris Chinchilla --- docs/develop/03_workshop/04_attester/02_did.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/develop/03_workshop/04_attester/02_did.md b/docs/develop/03_workshop/04_attester/02_did.md index 2386bf454..d70bc08ef 100644 --- a/docs/develop/03_workshop/04_attester/02_did.md +++ b/docs/develop/03_workshop/04_attester/02_did.md @@ -81,6 +81,8 @@ The `txs` array holds the two transactions containing the extrinsics needed to s The `createFromAccount` method takes the public key of the account to attach the DID to, and the `setAttestationKey` method takes the same parameter to set the attestation key the DID will need and use. +An Attester account needs to have an attestation key to write CTypes and attestations on chain. Use the `setAttestationKey` method to set this. For this example transaction, the Attester account uses the `dispatchAs` proxy method to assign the attestation key to the same account. However, you can also use this method to assign the attestation key to another account. + The `signAndSubmitTx` method then takes those transactions and submits them as a batch to the chain. ## Run the code From 8b3022cd5363a4b81a286d698808ab08f1ed95f1 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 9 Apr 2024 12:46:13 +0200 Subject: [PATCH 10/22] Respond to feedback Signed-off-by: Chris Chinchilla --- .../src/workshop/attester/attestCredential.ts | 3 --- .../src/workshop/attester/generateDid.ts | 20 +++++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts index 94f692af7..f48e3f8d8 100644 --- a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts +++ b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts @@ -11,9 +11,6 @@ export async function attestCredential( attesterAccount: Kilt.KiltKeyringPair, attesterDid: Kilt.DidUri, credential: Kilt.ICredential, - // TODO: Sort later - // eslint-disable-next-line @typescript-eslint/no-unused-vars - signCallback: Kilt.SignExtrinsicCallback ): Promise { const api = Kilt.ConfigService.get('api') diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 5f0050dad..6061c57df 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -3,33 +3,31 @@ import { config as envConfig } from 'dotenv' import { generateAccount } from './generateAccount' export async function createFullDid( - submitterAccount: Kilt.KiltKeyringPair + creatorAccount: Kilt.KiltKeyringPair & { type: 'ed25519' } ): Promise<{ mnemonic: string fullDid: Kilt.DidDocument }> { const api = Kilt.ConfigService.get('api') const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string - const { type, publicKey } = submitterAccount + const { type, publicKey } = creatorAccount const txs = [ - api.tx.did.createFromAccount({ [type as 'ed25519']: publicKey }), + api.tx.did.createFromAccount(creatorAccount.address), api.tx.did.dispatchAs( - submitterAccount.address, + creatorAccount.address, api.tx.did.setAttestationKey({ [type as 'ed25519']: publicKey }) ) ] console.log('Creating DID from account…') - const didDocument = await Kilt.Blockchain.signAndSubmitTx( + await Kilt.Blockchain.signAndSubmitTx( api.tx.utility.batch(txs), - submitterAccount - ).then(async () => { - const didUri = Kilt.Did.getFullDidUriFromKey(submitterAccount) + creatorAccount + ) + const didUri = Kilt.Did.getFullDidUriFromKey(creatorAccount) const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)) - const { document } = Kilt.Did.linkedInfoFromChain(encodedFullDid) - return document - }) + const { document: didDocument } = Kilt.Did.linkedInfoFromChain(encodedFullDid) if (!didDocument) { throw new Error('Full DID was not successfully created.') From 3087168b306cfb26244bde440cb2fb1a529028c0 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 9 Apr 2024 14:09:12 +0200 Subject: [PATCH 11/22] Draft Signed-off-by: Chris Chinchilla --- .../src/workshop/attester/generateDid.ts | 15 +++++++-------- code_examples/sdk_examples/src/workshop/index.ts | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 6061c57df..95fc8e57d 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -5,11 +5,10 @@ import { generateAccount } from './generateAccount' export async function createFullDid( creatorAccount: Kilt.KiltKeyringPair & { type: 'ed25519' } ): Promise<{ - mnemonic: string fullDid: Kilt.DidDocument }> { const api = Kilt.ConfigService.get('api') - const mnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string + const { type, publicKey } = creatorAccount const txs = [ @@ -25,15 +24,15 @@ export async function createFullDid( api.tx.utility.batch(txs), creatorAccount ) - const didUri = Kilt.Did.getFullDidUriFromKey(creatorAccount) - const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)) - const { document: didDocument } = Kilt.Did.linkedInfoFromChain(encodedFullDid) + const didUri = Kilt.Did.getFullDidUriFromKey(creatorAccount) + const encodedFullDid = await api.call.did.query(Kilt.Did.toChain(didUri)) + const { document: didDocument } = Kilt.Did.linkedInfoFromChain(encodedFullDid) if (!didDocument) { throw new Error('Full DID was not successfully created.') } - return { mnemonic, fullDid: didDocument } + return { fullDid: didDocument } } // Don't execute if this is imported by another file. @@ -47,10 +46,10 @@ if (require.main === module) { // Load attester account const accountMnemonic = process.env.ATTESTER_ACCOUNT_MNEMONIC as string const { account } = generateAccount(accountMnemonic) - const { mnemonic, fullDid } = await createFullDid(account) + const { fullDid } = await createFullDid(account) console.log('\nsave following to .env to continue\n') - console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`) + // console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`) console.error(`ATTESTER_DID_URI="${fullDid.uri}"\n`) } catch (e) { console.log('Error while creating attester DID') diff --git a/code_examples/sdk_examples/src/workshop/index.ts b/code_examples/sdk_examples/src/workshop/index.ts index 5a868b865..ded6fed45 100644 --- a/code_examples/sdk_examples/src/workshop/index.ts +++ b/code_examples/sdk_examples/src/workshop/index.ts @@ -36,9 +36,9 @@ export async function testWorkshop( await getFunds(account, attesterAccount.address, 5) // Create attester DID & ensure CType. - const { fullDid: attesterDid, mnemonic: attesterMnemonic } = + const { fullDid: attesterDid} = await createFullDid(attesterAccount) - const { assertionMethod } = generateAttesterKeypairs(attesterMnemonic) + const { assertionMethod } = generateAttesterKeypairs() await ensureStoredCtype( attesterAccount, From a1c2a2ae371a209eda08a16074cb7e42f8c0232d Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 9 Apr 2024 17:43:38 +0200 Subject: [PATCH 12/22] Test Signed-off-by: Chris Chinchilla --- code_examples/sdk_examples/src/dapp/index.ts | 4 ++-- .../sdk_examples/src/workshop/attester/attestCredential.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code_examples/sdk_examples/src/dapp/index.ts b/code_examples/sdk_examples/src/dapp/index.ts index 4ad3f5937..1e222d8de 100644 --- a/code_examples/sdk_examples/src/dapp/index.ts +++ b/code_examples/sdk_examples/src/dapp/index.ts @@ -21,10 +21,10 @@ export async function testDapp(account: Kilt.KeyringPair, wssAddress: string) { await getFunds(account, dappAccount.address, 4) // Create attester DID & ensure CType. - const { fullDid: attesterDid, mnemonic: attesterMnemonic } = + const { fullDid: attesterDid} = await createFullDid(dappAccount) const { assertionMethod: assertionMethodKey } = - generateAttesterKeypairs(attesterMnemonic) + generateAttesterKeypairs() const domainLinkageCType = await getDomainLinkageCType() const { domainLinkageCredential } = getDomainLinkageCredential({ diff --git a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts index f48e3f8d8..ece96fd90 100644 --- a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts +++ b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts @@ -44,7 +44,7 @@ export async function attestingFlow( // ... send the request to the attester // The attester checks the attributes and attests the provided credential. - await attestCredential(attesterAccount, attesterDid, credential, signCallback) + await attestCredential(attesterAccount, attesterDid, credential) // Return the generated credential. return credential From 2112d9d26ba46fbf7abace1884f79cfea1a20392 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Thu, 11 Apr 2024 15:34:51 +0200 Subject: [PATCH 13/22] Draft Signed-off-by: Chris Chinchilla --- code_examples/sdk_examples/package.json | 2 +- .../src/dapp/dapp/04_attest_credential.ts | 1 + code_examples/sdk_examples/src/dapp/index.ts | 6 +- code_examples/sdk_examples/src/getFunds.ts | 2 + code_examples/sdk_examples/src/test.ts | 12 +++- .../src/workshop/attester/attestCredential.ts | 3 +- .../sdk_examples/src/workshop/index.ts | 66 ++++++++++--------- 7 files changed, 51 insertions(+), 41 deletions(-) diff --git a/code_examples/sdk_examples/package.json b/code_examples/sdk_examples/package.json index 6edd12b47..dd6319ec6 100644 --- a/code_examples/sdk_examples/package.json +++ b/code_examples/sdk_examples/package.json @@ -10,7 +10,7 @@ "style": "prettier --check --config .prettierrc '**/*.ts'", "style:fix": "yarn style --write", "fix": "yarn lint:fix && yarn style:fix", - "test": "ts-node src/test.ts" + "test": "ts-node src/test.ts workshop" }, "dependencies": { "@kiltprotocol/sdk-js": "0.35.0", diff --git a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts index 75f8a1eb1..3eabc3b76 100644 --- a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts +++ b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import * as Kilt from '@kiltprotocol/sdk-js' export async function main({ diff --git a/code_examples/sdk_examples/src/dapp/index.ts b/code_examples/sdk_examples/src/dapp/index.ts index 1e222d8de..f5afed159 100644 --- a/code_examples/sdk_examples/src/dapp/index.ts +++ b/code_examples/sdk_examples/src/dapp/index.ts @@ -21,10 +21,8 @@ export async function testDapp(account: Kilt.KeyringPair, wssAddress: string) { await getFunds(account, dappAccount.address, 4) // Create attester DID & ensure CType. - const { fullDid: attesterDid} = - await createFullDid(dappAccount) - const { assertionMethod: assertionMethodKey } = - generateAttesterKeypairs() + const { fullDid: attesterDid } = await createFullDid(dappAccount) + const { assertionMethod: assertionMethodKey } = generateAttesterKeypairs() const domainLinkageCType = await getDomainLinkageCType() const { domainLinkageCredential } = getDomainLinkageCredential({ diff --git a/code_examples/sdk_examples/src/getFunds.ts b/code_examples/sdk_examples/src/getFunds.ts index ef3e49cc9..5a878bc2b 100644 --- a/code_examples/sdk_examples/src/getFunds.ts +++ b/code_examples/sdk_examples/src/getFunds.ts @@ -7,6 +7,7 @@ async function failproofSubmit( submitter: Kilt.KeyringPair ) { try { + console.log("account", submitter.address) await Kilt.Blockchain.signAndSubmitTx(tx, submitter) } catch { // Try a second time after a small delay and fetching the right nonce. @@ -32,6 +33,7 @@ export async function getFunds( recipient, Kilt.BalanceUtils.convertToTxUnit(new BN(kiltAmount), 0) ) + console.log('faucet', faucetAccount.address) await failproofSubmit(tx, faucetAccount) console.log('Successfully transferred tokens') } diff --git a/code_examples/sdk_examples/src/test.ts b/code_examples/sdk_examples/src/test.ts index 30e19597f..5e083c39a 100644 --- a/code_examples/sdk_examples/src/test.ts +++ b/code_examples/sdk_examples/src/test.ts @@ -59,8 +59,8 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' await Kilt.init() const wssAddress = process.env.WSS_ADDRESS || 'wss://peregrine.kilt.io' - const mnemonic = process.env[MNEMONIC_ENV] - const faucetSeed = process.env[FAUCET_SEED_ENV] + const mnemonic = '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' + const faucetSeed = '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' let baseAccountStrategy: 'base-mnemonic' | 'faucet-seed' = 'base-mnemonic' @@ -79,14 +79,18 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' switch (baseAccountStrategy) { case 'base-mnemonic': { + console.log("mnemonic", mnemonic) + const baseAccount = new Kilt.Utils.Keyring({ type: 'sr25519', ss58Format: Kilt.Utils.ss58Format }).addFromMnemonic(mnemonic as string) + console.log('base', baseAccount.address) + workshopAccount = baseAccount.derive('//workshop') dappAccount = baseAccount.derive('//dapp') coreAccount = baseAccount.derive('//core') - +console.log('workshopAccount', workshopAccount.address) break } case 'faucet-seed': { @@ -97,6 +101,8 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' workshopAccount = faucetAccount dappAccount = faucetAccount coreAccount = faucetAccount + console.log('workshopAccount2', workshopAccount.address) + } } diff --git a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts index ece96fd90..cdde50f27 100644 --- a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts +++ b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { config as envConfig } from 'dotenv' import * as Kilt from '@kiltprotocol/sdk-js' @@ -10,7 +11,7 @@ import { generateLightDid } from '../claimer/generateLightDid' export async function attestCredential( attesterAccount: Kilt.KiltKeyringPair, attesterDid: Kilt.DidUri, - credential: Kilt.ICredential, + credential: Kilt.ICredential ): Promise { const api = Kilt.ConfigService.get('api') diff --git a/code_examples/sdk_examples/src/workshop/index.ts b/code_examples/sdk_examples/src/workshop/index.ts index ded6fed45..be3c086fa 100644 --- a/code_examples/sdk_examples/src/workshop/index.ts +++ b/code_examples/sdk_examples/src/workshop/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import * as Kilt from '@kiltprotocol/sdk-js' import { attestingFlow } from './attester/attestCredential' @@ -32,40 +33,41 @@ export async function testWorkshop( age: 27, name: 'Karl' }) - + console.log(account.address) + console.log(attesterAccount.address) await getFunds(account, attesterAccount.address, 5) - // Create attester DID & ensure CType. - const { fullDid: attesterDid} = - await createFullDid(attesterAccount) - const { assertionMethod } = generateAttesterKeypairs() + // // Create attester DID & ensure CType. + // const { fullDid: attesterDid} = + // await createFullDid(attesterAccount) + // const { assertionMethod } = generateAttesterKeypairs() - await ensureStoredCtype( - attesterAccount, - attesterDid.uri, - async ({ data }) => ({ - signature: assertionMethod.sign(data), - keyType: assertionMethod.type - }) - ) + // await ensureStoredCtype( + // attesterAccount, + // attesterDid.uri, + // async ({ data }) => ({ + // signature: assertionMethod.sign(data), + // keyType: assertionMethod.type + // }) + // ) - // Do attestation & verification. - const credential = await attestingFlow( - lightDid.uri, - attesterAccount, - attesterDid.uri, - async ({ data }) => ({ - signature: assertionMethod.sign(data), - keyType: assertionMethod.type - }) - ) - await verificationFlow( - credential, - async ({ data }) => ({ - signature: authentication.sign(data), - keyType: authentication.type, - keyUri: `${lightDid.uri}${lightDid.authentication[0].id}` - }), - [attesterDid.uri] - ) + // // Do attestation & verification. + // const credential = await attestingFlow( + // lightDid.uri, + // attesterAccount, + // attesterDid.uri, + // async ({ data }) => ({ + // signature: assertionMethod.sign(data), + // keyType: assertionMethod.type + // }) + // ) + // await verificationFlow( + // credential, + // async ({ data }) => ({ + // signature: authentication.sign(data), + // keyType: authentication.type, + // keyUri: `${lightDid.uri}${lightDid.authentication[0].id}` + // }), + // [attesterDid.uri] + // ) } From 75167dae0faf901f8ef54acd5125d9b7f9085982 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Mon, 15 Apr 2024 12:33:18 +0200 Subject: [PATCH 14/22] Prettier Signed-off-by: Chris Chinchilla --- code_examples/sdk_examples/src/getFunds.ts | 2 +- code_examples/sdk_examples/src/test.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/code_examples/sdk_examples/src/getFunds.ts b/code_examples/sdk_examples/src/getFunds.ts index 5a878bc2b..2551bd062 100644 --- a/code_examples/sdk_examples/src/getFunds.ts +++ b/code_examples/sdk_examples/src/getFunds.ts @@ -7,7 +7,7 @@ async function failproofSubmit( submitter: Kilt.KeyringPair ) { try { - console.log("account", submitter.address) + console.log('account', submitter.address) await Kilt.Blockchain.signAndSubmitTx(tx, submitter) } catch { // Try a second time after a small delay and fetching the right nonce. diff --git a/code_examples/sdk_examples/src/test.ts b/code_examples/sdk_examples/src/test.ts index 5e083c39a..573bd7ac1 100644 --- a/code_examples/sdk_examples/src/test.ts +++ b/code_examples/sdk_examples/src/test.ts @@ -59,8 +59,10 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' await Kilt.init() const wssAddress = process.env.WSS_ADDRESS || 'wss://peregrine.kilt.io' - const mnemonic = '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' - const faucetSeed = '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' + const mnemonic = + '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' + const faucetSeed = + '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' let baseAccountStrategy: 'base-mnemonic' | 'faucet-seed' = 'base-mnemonic' @@ -79,7 +81,7 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' switch (baseAccountStrategy) { case 'base-mnemonic': { - console.log("mnemonic", mnemonic) + console.log('mnemonic', mnemonic) const baseAccount = new Kilt.Utils.Keyring({ type: 'sr25519', @@ -90,7 +92,7 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' workshopAccount = baseAccount.derive('//workshop') dappAccount = baseAccount.derive('//dapp') coreAccount = baseAccount.derive('//core') -console.log('workshopAccount', workshopAccount.address) + console.log('workshopAccount', workshopAccount.address) break } case 'faucet-seed': { @@ -102,7 +104,6 @@ console.log('workshopAccount', workshopAccount.address) dappAccount = faucetAccount coreAccount = faucetAccount console.log('workshopAccount2', workshopAccount.address) - } } From 77bb3b202a418ded956899adec256210a601ab46 Mon Sep 17 00:00:00 2001 From: Antonio Antonino Date: Tue, 16 Apr 2024 07:14:04 +0200 Subject: [PATCH 15/22] Fix mnemonic vs seed confusion --- code_examples/sdk_examples/src/test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code_examples/sdk_examples/src/test.ts b/code_examples/sdk_examples/src/test.ts index 573bd7ac1..cc450eb7e 100644 --- a/code_examples/sdk_examples/src/test.ts +++ b/code_examples/sdk_examples/src/test.ts @@ -59,8 +59,7 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' await Kilt.init() const wssAddress = process.env.WSS_ADDRESS || 'wss://peregrine.kilt.io' - const mnemonic = - '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' + const mnemonic = undefined const faucetSeed = '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' @@ -86,7 +85,7 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' const baseAccount = new Kilt.Utils.Keyring({ type: 'sr25519', ss58Format: Kilt.Utils.ss58Format - }).addFromMnemonic(mnemonic as string) + }).addFromMnemonic(mnemonic as unknown as string) console.log('base', baseAccount.address) workshopAccount = baseAccount.derive('//workshop') From c9454a26a4f6b4b088ac64a2583b262ec7fec862 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 16 Apr 2024 11:22:21 +0200 Subject: [PATCH 16/22] Fixes! Signed-off-by: Chris Chinchilla --- .github/workflows/test.yml | 1 + code_examples/sdk_examples/package.json | 2 +- .../messaging/_replay_protection_01.ts | 1 - .../messaging/_replay_protection_02.ts | 2 - .../messaging/_replay_protection_03.ts | 2 - .../src/dapp/dapp/01_domain_linkage_ctype.ts | 2 +- .../src/dapp/dapp/06_dapp_introduction.ts | 1 - code_examples/sdk_examples/src/getFunds.ts | 2 - code_examples/sdk_examples/src/test.ts | 56 +++------------- .../src/workshop/attester/attestCredential.ts | 2 +- .../src/workshop/attester/generateDid.ts | 6 +- .../sdk_examples/src/workshop/index.ts | 65 +++++++++---------- 12 files changed, 46 insertions(+), 96 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f9dc9cdac..ebf3ffd6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,6 +44,7 @@ jobs: env: NODE_OPTIONS: --unhandled-rejections=strict BASE_MNEMONIC: ${{ secrets.BASE_MNEMONIC }} + FAUCET_SEED: ${{ secrets.FAUCET_SEED }} run: | yarn install --frozen-lockfile yarn test ${{ matrix.test_case }} diff --git a/code_examples/sdk_examples/package.json b/code_examples/sdk_examples/package.json index dd6319ec6..6edd12b47 100644 --- a/code_examples/sdk_examples/package.json +++ b/code_examples/sdk_examples/package.json @@ -10,7 +10,7 @@ "style": "prettier --check --config .prettierrc '**/*.ts'", "style:fix": "yarn style --write", "fix": "yarn lint:fix && yarn style:fix", - "test": "ts-node src/test.ts workshop" + "test": "ts-node src/test.ts" }, "dependencies": { "@kiltprotocol/sdk-js": "0.35.0", diff --git a/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_01.ts b/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_01.ts index b5a28ca38..a87e21a4f 100644 --- a/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_01.ts +++ b/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_01.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ - export function main() { const MAX_ACCEPTED_AGE = 60_000 // ms -> 1 minute const MIN_ACCEPTED_AGE = -1_000 // allow for some imprecision in system time diff --git a/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_02.ts b/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_02.ts index 9549f1ab2..e305c48ab 100644 --- a/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_02.ts +++ b/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_02.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ - import { blake2AsHex } from '@polkadot/util-crypto' import * as Kilt from '@kiltprotocol/sdk-js' diff --git a/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_03.ts b/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_03.ts index 8dc8bbafb..237a98de1 100644 --- a/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_03.ts +++ b/code_examples/sdk_examples/src/core_features/messaging/_replay_protection_03.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ - export function main( submissions: Map, MAX_ACCEPTED_AGE: number diff --git a/code_examples/sdk_examples/src/dapp/dapp/01_domain_linkage_ctype.ts b/code_examples/sdk_examples/src/dapp/dapp/01_domain_linkage_ctype.ts index 1d9df6ada..818f2b429 100644 --- a/code_examples/sdk_examples/src/dapp/dapp/01_domain_linkage_ctype.ts +++ b/code_examples/sdk_examples/src/dapp/dapp/01_domain_linkage_ctype.ts @@ -1,6 +1,6 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import * as Kilt from '@kiltprotocol/sdk-js' -/* eslint-disable @typescript-eslint/no-unused-vars */ export async function main(): Promise { const { creator, diff --git a/code_examples/sdk_examples/src/dapp/dapp/06_dapp_introduction.ts b/code_examples/sdk_examples/src/dapp/dapp/06_dapp_introduction.ts index 4a6212224..b2a20dcef 100644 --- a/code_examples/sdk_examples/src/dapp/dapp/06_dapp_introduction.ts +++ b/code_examples/sdk_examples/src/dapp/dapp/06_dapp_introduction.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import * as Kilt from '@kiltprotocol/sdk-js' // `window` object: Should be used only in the following example. diff --git a/code_examples/sdk_examples/src/getFunds.ts b/code_examples/sdk_examples/src/getFunds.ts index 2551bd062..ef3e49cc9 100644 --- a/code_examples/sdk_examples/src/getFunds.ts +++ b/code_examples/sdk_examples/src/getFunds.ts @@ -7,7 +7,6 @@ async function failproofSubmit( submitter: Kilt.KeyringPair ) { try { - console.log('account', submitter.address) await Kilt.Blockchain.signAndSubmitTx(tx, submitter) } catch { // Try a second time after a small delay and fetching the right nonce. @@ -33,7 +32,6 @@ export async function getFunds( recipient, Kilt.BalanceUtils.convertToTxUnit(new BN(kiltAmount), 0) ) - console.log('faucet', faucetAccount.address) await failproofSubmit(tx, faucetAccount) console.log('Successfully transferred tokens') } diff --git a/code_examples/sdk_examples/src/test.ts b/code_examples/sdk_examples/src/test.ts index cc450eb7e..10c71b2b5 100644 --- a/code_examples/sdk_examples/src/test.ts +++ b/code_examples/sdk_examples/src/test.ts @@ -8,10 +8,6 @@ import { testCoreFeatures } from './core_features' import { testDapp } from './dapp' import { testStaking } from './staking' import { testWorkshop } from './workshop' - -const MNEMONIC_ENV = 'BASE_MNEMONIC' -const FAUCET_SEED_ENV = 'FAUCET_SEED' - ;(async () => { const whichToRun = { workshop: false, @@ -57,54 +53,18 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED' envConfig() await Kilt.init() - const wssAddress = process.env.WSS_ADDRESS || 'wss://peregrine.kilt.io' - const mnemonic = undefined - const faucetSeed = - '0xe566550fec3ca23d80dfe9e9529ada463b93fc33f17219c1089de906f7253f1c' - - let baseAccountStrategy: 'base-mnemonic' | 'faucet-seed' = 'base-mnemonic' - - // Faucet seed only a fallback if mnemonic is not specified. Otherwise mnemonic always wins. - if (!mnemonic && faucetSeed) { - baseAccountStrategy = 'faucet-seed' - } else if (!mnemonic && !faucetSeed) { - console.log( - `Neither base mnemonic "${MNEMONIC_ENV}" nor faucet seed "${FAUCET_SEED_ENV}" have been specified. - Please specify at least one of them.` - ) - throw new Error('Account mnemonic or faucet seed is missing.') - } + const faucetSeed = process.env.FAUCET_SEED let [workshopAccount, dappAccount, coreAccount] = new Array(3) - switch (baseAccountStrategy) { - case 'base-mnemonic': { - console.log('mnemonic', mnemonic) - - const baseAccount = new Kilt.Utils.Keyring({ - type: 'sr25519', - ss58Format: Kilt.Utils.ss58Format - }).addFromMnemonic(mnemonic as unknown as string) - console.log('base', baseAccount.address) - - workshopAccount = baseAccount.derive('//workshop') - dappAccount = baseAccount.derive('//dapp') - coreAccount = baseAccount.derive('//core') - console.log('workshopAccount', workshopAccount.address) - break - } - case 'faucet-seed': { - const faucetAccount = Kilt.Utils.Crypto.makeKeypairFromSeed( - hexToU8a(faucetSeed), - 'sr25519' - ) as Kilt.KeyringPair - workshopAccount = faucetAccount - dappAccount = faucetAccount - coreAccount = faucetAccount - console.log('workshopAccount2', workshopAccount.address) - } - } + const faucetAccount = Kilt.Utils.Crypto.makeKeypairFromSeed( + hexToU8a(faucetSeed), + 'sr25519' + ) as Kilt.KeyringPair + workshopAccount = faucetAccount + dappAccount = faucetAccount + coreAccount = faucetAccount // If any of these flows fail, just send some more tokens to the account that is failing. try { diff --git a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts index cdde50f27..ad4474641 100644 --- a/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts +++ b/code_examples/sdk_examples/src/workshop/attester/attestCredential.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import { config as envConfig } from 'dotenv' import * as Kilt from '@kiltprotocol/sdk-js' @@ -34,6 +33,7 @@ export async function attestingFlow( claimerDid: Kilt.DidUri, attesterAccount: Kilt.KiltKeyringPair, attesterDid: Kilt.DidUri, + // eslint-disable-next-line @typescript-eslint/no-unused-vars signCallback: Kilt.SignExtrinsicCallback ): Promise { // First the claimer. diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 95fc8e57d..f3a7728a6 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -10,12 +10,12 @@ export async function createFullDid( const api = Kilt.ConfigService.get('api') const { type, publicKey } = creatorAccount - + console.log('creatorAccount', creatorAccount.address) const txs = [ - api.tx.did.createFromAccount(creatorAccount.address), + api.tx.did.createFromAccount({ [type]: publicKey }), api.tx.did.dispatchAs( creatorAccount.address, - api.tx.did.setAttestationKey({ [type as 'ed25519']: publicKey }) + api.tx.did.setAttestationKey({ [type]: publicKey }) ) ] diff --git a/code_examples/sdk_examples/src/workshop/index.ts b/code_examples/sdk_examples/src/workshop/index.ts index be3c086fa..1dc8ff550 100644 --- a/code_examples/sdk_examples/src/workshop/index.ts +++ b/code_examples/sdk_examples/src/workshop/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import * as Kilt from '@kiltprotocol/sdk-js' import { attestingFlow } from './attester/attestCredential' @@ -33,41 +32,39 @@ export async function testWorkshop( age: 27, name: 'Karl' }) - console.log(account.address) - console.log(attesterAccount.address) + await getFunds(account, attesterAccount.address, 5) - // // Create attester DID & ensure CType. - // const { fullDid: attesterDid} = - // await createFullDid(attesterAccount) - // const { assertionMethod } = generateAttesterKeypairs() + // Create attester DID & ensure CType. + const { fullDid: attesterDid } = await createFullDid(attesterAccount) + const { assertionMethod } = generateAttesterKeypairs() - // await ensureStoredCtype( - // attesterAccount, - // attesterDid.uri, - // async ({ data }) => ({ - // signature: assertionMethod.sign(data), - // keyType: assertionMethod.type - // }) - // ) + await ensureStoredCtype( + attesterAccount, + attesterDid.uri, + async ({ data }) => ({ + signature: assertionMethod.sign(data), + keyType: assertionMethod.type + }) + ) - // // Do attestation & verification. - // const credential = await attestingFlow( - // lightDid.uri, - // attesterAccount, - // attesterDid.uri, - // async ({ data }) => ({ - // signature: assertionMethod.sign(data), - // keyType: assertionMethod.type - // }) - // ) - // await verificationFlow( - // credential, - // async ({ data }) => ({ - // signature: authentication.sign(data), - // keyType: authentication.type, - // keyUri: `${lightDid.uri}${lightDid.authentication[0].id}` - // }), - // [attesterDid.uri] - // ) + // Do attestation & verification. + const credential = await attestingFlow( + lightDid.uri, + attesterAccount, + attesterDid.uri, + async ({ data }) => ({ + signature: assertionMethod.sign(data), + keyType: assertionMethod.type + }) + ) + await verificationFlow( + credential, + async ({ data }) => ({ + signature: authentication.sign(data), + keyType: authentication.type, + keyUri: `${lightDid.uri}${lightDid.authentication[0].id}` + }), + [attesterDid.uri] + ) } From f3338d33e22162fbd2da4e02b8eeac6d3bb45b3a Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 16 Apr 2024 15:02:03 +0200 Subject: [PATCH 17/22] Tweaks Signed-off-by: Chris Chinchilla --- .../sdk_examples/src/workshop/attester/generateDid.ts | 2 +- docs/concepts/07_dip/02_provider.md | 4 ++-- docs/develop/03_workshop/04_attester/01_account.md | 9 ++------- docs/develop/03_workshop/04_attester/02_did.md | 3 ++- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index f3a7728a6..7e8d9d367 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -10,7 +10,7 @@ export async function createFullDid( const api = Kilt.ConfigService.get('api') const { type, publicKey } = creatorAccount - console.log('creatorAccount', creatorAccount.address) + const txs = [ api.tx.did.createFromAccount({ [type]: publicKey }), api.tx.did.dispatchAs( diff --git a/docs/concepts/07_dip/02_provider.md b/docs/concepts/07_dip/02_provider.md index 0b384009e..1803e52dd 100644 --- a/docs/concepts/07_dip/02_provider.md +++ b/docs/concepts/07_dip/02_provider.md @@ -1,4 +1,4 @@ -# Decentralized Identity Provider (DIP) provider pallet +# Provider pallet This pallet is a core component of the Decentralized Identity Provider protocol. It enables a Substrate-based chain (provider) to bridge the identities of its users to other connected chains (consumers) trustlessly. @@ -21,7 +21,7 @@ After removal, the identity becomes unusable cross-chain, although it will still Being chain-agnostic, most of the runtime configurations must be passed to the pallet's `Config` trait. Specifically: * `type CommitOriginCheck: EnsureOrigin`: The check ensuring a given runtime origin is allowed to generate and remove identity commitments. -* `type CommitOrigin: SubmitterInfo`: The resulting origin if `CommitOriginCheck` returns with errors. The origin is not required to be an `AccountId`, but must include information about the `AccountId` of the tx submitter. +* `type CommitOrigin: SubmitterInfo`: The resulting origin if `CommitOriginCheck` returns without errors. The origin is not required to be an `AccountId`, but must include information about the `AccountId` of the tx submitter. * `type Identifier: Parameter + MaxEncodedLen`: The type of an identifier used to retrieve identity information about a subject. * `type IdentityCommitmentGenerator: IdentityCommitmentGenerator`: The type responsible for generating identity commitments, given the identity information associated to a given `Identifier`. * `type IdentityProvider: IdentityProvider`: The type responsible for retrieving the information associated to a subject given their identifier. The information can potentially be retrieved from any source, using a combination of on-chain and off-chain solutions. diff --git a/docs/develop/03_workshop/04_attester/01_account.md b/docs/develop/03_workshop/04_attester/01_account.md index baf89e28e..e885b9944 100644 --- a/docs/develop/03_workshop/04_attester/01_account.md +++ b/docs/develop/03_workshop/04_attester/01_account.md @@ -66,14 +66,9 @@ The `generateAccount` method returns an object with the following two properties Generating these values takes two steps: 1. Create the `mnemonic` value using the `mnemonicGenerate()` method from the `Utils.Crypto` package. -2. The `account` value first needs a `keyring` value defined, which is a data structure for defining the key pair type with the following parameters: +2. The `account` value first needs a `keyring` value defined, which is a data structure for defining the key pair type as `ed25519`. - 1. `ss58Format`: Specifies the encoding format for the key. Substrate-based blockchains commonly use [SS58](https://docs.substrate.io/reference/address-formats/). - The value `38` represents the KILT blockchain prefix. - 2. `type`: Specifies the user's cryptographic algorithm. - Substrate-based blockchains commonly use sr25519. - - The function then returns the value using the `addFromMnemonic()` method to create a key pair for the address using the given mnemonic. +The function then returns the value using the `makeKeypairFromUri()` method to create a key pair for the address using the given mnemonic. The rest of the code runs the `generateAccount` function and logs the results to the console. diff --git a/docs/develop/03_workshop/04_attester/02_did.md b/docs/develop/03_workshop/04_attester/02_did.md index d70bc08ef..d2cff5b16 100644 --- a/docs/develop/03_workshop/04_attester/02_did.md +++ b/docs/develop/03_workshop/04_attester/02_did.md @@ -64,10 +64,11 @@ As an Attester needs to interact wi The KILT SDK provides multiple methods to create DIDs, this workshop highlights the `createFromAccount` method, that creates a DID from any pre-existing substrate-compatible account. + :::info Bring your own account -This workshop assumes you followed the [create account step](./01_account.md), but if you have a pre-existing account, you can use that instead by adding the `ATTESTER_ACCOUNT_ADDRESS` and `ATTESTER_ACCOUNT_MNEMONIC` to the `.env` file. +This workshop assumes you followed the [create account step](./01_account.md), but if you have a pre-existing account, you can use that instead. ::: From a527385365fa511f69265a0508549fdc9d097075 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 16 Apr 2024 16:44:08 +0200 Subject: [PATCH 18/22] Update code_examples/sdk_examples/src/workshop/attester/generateDid.ts Co-authored-by: Raphael Flechtner <39338561+rflechtner@users.noreply.github.com> --- code_examples/sdk_examples/src/workshop/attester/generateDid.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 7e8d9d367..4541ab558 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -3,7 +3,7 @@ import { config as envConfig } from 'dotenv' import { generateAccount } from './generateAccount' export async function createFullDid( - creatorAccount: Kilt.KiltKeyringPair & { type: 'ed25519' } + creatorAccount: Kilt.KiltKeyringPair & { type: 'ed25519' | 'sr25519' | 'ecdsa' } ): Promise<{ fullDid: Kilt.DidDocument }> { From 8b730f76ae50de9132b0be9c2f82c11e43a9cf13 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 16 Apr 2024 16:45:54 +0200 Subject: [PATCH 19/22] Respond to feedback Signed-off-by: Chris Chinchilla --- .../src/dapp/dapp/04_attest_credential.ts | 18 +++++++++--------- .../src/workshop/attester/generateDid.ts | 1 - .../03_workshop/04_attester/01_account.md | 2 +- docs/develop/03_workshop/04_attester/02_did.md | 1 - 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts index 3eabc3b76..774183c2d 100644 --- a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts +++ b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts @@ -22,15 +22,15 @@ export async function main({ // We authorize the call using the attestation key of the Dapps DID. const extrinsic = api.tx.did.dispatchAs(dappAccount.address, attestationTx) - // const submitTx = await Kilt.Did.authorizeTx( - // didUri, - // attestationTx, - // async ({ data }) => ({ - // signature: assertionMethodKey.sign(data), - // keyType: assertionMethodKey.type - // }), - // dappAccount.address - // ) + const submitTx = await Kilt.Did.authorizeTx( + didUri, + attestationTx, + async ({ data }) => ({ + signature: assertionMethodKey.sign(data), + keyType: assertionMethodKey.type + }), + dappAccount.address + ) // Since DIDs can not hold any balance, we pay for the transaction using our blockchain account const result = await Kilt.Blockchain.signAndSubmitTx(extrinsic, dappAccount) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 7e8d9d367..292b26da8 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -49,7 +49,6 @@ if (require.main === module) { const { fullDid } = await createFullDid(account) console.log('\nsave following to .env to continue\n') - // console.error(`ATTESTER_DID_MNEMONIC="${mnemonic}"\n`) console.error(`ATTESTER_DID_URI="${fullDid.uri}"\n`) } catch (e) { console.log('Error while creating attester DID') diff --git a/docs/develop/03_workshop/04_attester/01_account.md b/docs/develop/03_workshop/04_attester/01_account.md index e885b9944..37dbc776e 100644 --- a/docs/develop/03_workshop/04_attester/01_account.md +++ b/docs/develop/03_workshop/04_attester/01_account.md @@ -66,7 +66,7 @@ The `generateAccount` method returns an object with the following two properties Generating these values takes two steps: 1. Create the `mnemonic` value using the `mnemonicGenerate()` method from the `Utils.Crypto` package. -2. The `account` value first needs a `keyring` value defined, which is a data structure for defining the key pair type as `ed25519`. +2. The `account` value first needs a `keyring` value defined, which is a data structure for defining the key pair type. This example uses `ed25519`, but `sr25519`, `ed25519`, or `ecdsa` are also valid. The function then returns the value using the `makeKeypairFromUri()` method to create a key pair for the address using the given mnemonic. diff --git a/docs/develop/03_workshop/04_attester/02_did.md b/docs/develop/03_workshop/04_attester/02_did.md index d2cff5b16..f230f2ea5 100644 --- a/docs/develop/03_workshop/04_attester/02_did.md +++ b/docs/develop/03_workshop/04_attester/02_did.md @@ -108,7 +108,6 @@ Now run the code with: Once you have run the script, the output should provide you with the `ATTESTER_DID_MNEMONIC` and `ATTESTER_DID_URI`. -Using the `createFromAccount` method means that the `ATTESTER_DID_MNEMONIC` and `ATTESTER_ACCOUNT_MNEMONIC` are the same. The output should look like the following, but not identical since the code creates the DIDs from your account: From d5e9dfd1154440c53700c3d1b2dabc7af68338f8 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Wed, 17 Apr 2024 13:13:48 +0200 Subject: [PATCH 20/22] Update Signed-off-by: Chris Chinchilla --- .../sdk_examples/src/workshop/attester/generateDid.ts | 6 +++--- docs/develop/03_workshop/04_attester/02_did.md | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts index 1cd3e5a98..54557bcef 100644 --- a/code_examples/sdk_examples/src/workshop/attester/generateDid.ts +++ b/code_examples/sdk_examples/src/workshop/attester/generateDid.ts @@ -11,13 +11,13 @@ export async function createFullDid( }> { const api = Kilt.ConfigService.get('api') - const { type, publicKey } = creatorAccount + const verificationMethod = Kilt.Did.publicKeyToChain(creatorAccount) const txs = [ - api.tx.did.createFromAccount({ [type]: publicKey }), + api.tx.did.createFromAccount(verificationMethod), api.tx.did.dispatchAs( creatorAccount.address, - api.tx.did.setAttestationKey({ [type]: publicKey }) + api.tx.did.setAttestationKey(verificationMethod) ) ] diff --git a/docs/develop/03_workshop/04_attester/02_did.md b/docs/develop/03_workshop/04_attester/02_did.md index f230f2ea5..dc44f932a 100644 --- a/docs/develop/03_workshop/04_attester/02_did.md +++ b/docs/develop/03_workshop/04_attester/02_did.md @@ -78,9 +78,11 @@ Create and submit the extrinsic (aka transaction) that registers the DID. {GenerateDid} +The `publicKeyToChain` helper method returns a public key of the correct type. + The `txs` array holds the two transactions containing the extrinsics needed to submit to the chain for the Attester's DID creation. -The `createFromAccount` method takes the public key of the account to attach the DID to, and the `setAttestationKey` method takes the same parameter to set the attestation key the DID will need and use. +The `createFromAccount` method takes the authenticated key of the account to attach the DID to, and the `setAttestationKey` method takes the same parameter to set the attestation key the DID needs and uses. An Attester account needs to have an attestation key to write CTypes and attestations on chain. Use the `setAttestationKey` method to set this. For this example transaction, the Attester account uses the `dispatchAs` proxy method to assign the attestation key to the same account. However, you can also use this method to assign the attestation key to another account. From d4f8c09ecd5799fe351b7724813eebbf2a646628 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Wed, 17 Apr 2024 16:17:20 +0200 Subject: [PATCH 21/22] Update docs/develop/03_workshop/04_attester/01_account.md Co-authored-by: Raphael Flechtner <39338561+rflechtner@users.noreply.github.com> --- docs/develop/03_workshop/04_attester/01_account.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/develop/03_workshop/04_attester/01_account.md b/docs/develop/03_workshop/04_attester/01_account.md index 37dbc776e..e2710f623 100644 --- a/docs/develop/03_workshop/04_attester/01_account.md +++ b/docs/develop/03_workshop/04_attester/01_account.md @@ -66,7 +66,7 @@ The `generateAccount` method returns an object with the following two properties Generating these values takes two steps: 1. Create the `mnemonic` value using the `mnemonicGenerate()` method from the `Utils.Crypto` package. -2. The `account` value first needs a `keyring` value defined, which is a data structure for defining the key pair type. This example uses `ed25519`, but `sr25519`, `ed25519`, or `ecdsa` are also valid. +2. The `account` value first needs a `keyring` value defined, which is a data structure for defining the key pair type. This example uses `ed25519`, but `sr25519` or `ecdsa` are also valid. The function then returns the value using the `makeKeypairFromUri()` method to create a key pair for the address using the given mnemonic. From db6a5f543916f085629390e442715646c05912c8 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Wed, 17 Apr 2024 16:17:50 +0200 Subject: [PATCH 22/22] Remove defunct function Signed-off-by: Chris Chinchilla --- .../sdk_examples/src/dapp/dapp/04_attest_credential.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts index 774183c2d..6d76666cb 100644 --- a/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts +++ b/code_examples/sdk_examples/src/dapp/dapp/04_attest_credential.ts @@ -22,16 +22,6 @@ export async function main({ // We authorize the call using the attestation key of the Dapps DID. const extrinsic = api.tx.did.dispatchAs(dappAccount.address, attestationTx) - const submitTx = await Kilt.Did.authorizeTx( - didUri, - attestationTx, - async ({ data }) => ({ - signature: assertionMethodKey.sign(data), - keyType: assertionMethodKey.type - }), - dappAccount.address - ) - // Since DIDs can not hold any balance, we pay for the transaction using our blockchain account const result = await Kilt.Blockchain.signAndSubmitTx(extrinsic, dappAccount)