From 2112d9d26ba46fbf7abace1884f79cfea1a20392 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Thu, 11 Apr 2024 15:34:51 +0200 Subject: [PATCH] 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] + // ) }