Skip to content

Commit

Permalink
Draft
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Chinchilla <[email protected]>
  • Loading branch information
ChrisChinchilla committed Apr 11, 2024
1 parent a1c2a2a commit 04f4fac
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion code_examples/sdk_examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions code_examples/sdk_examples/src/dapp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions code_examples/sdk_examples/src/getFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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')
}
Expand Down
12 changes: 9 additions & 3 deletions code_examples/sdk_examples/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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': {
Expand All @@ -97,6 +101,8 @@ const FAUCET_SEED_ENV = 'FAUCET_SEED'
workshopAccount = faucetAccount
dappAccount = faucetAccount
coreAccount = faucetAccount
console.log('workshopAccount2', workshopAccount.address)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { generateLightDid } from '../claimer/generateLightDid'
export async function attestCredential(
attesterAccount: Kilt.KiltKeyringPair,
attesterDid: Kilt.DidUri,
credential: Kilt.ICredential,
credential: Kilt.ICredential
): Promise<void> {
const api = Kilt.ConfigService.get('api')

Expand Down
65 changes: 33 additions & 32 deletions code_examples/sdk_examples/src/workshop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,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]
// )
}

0 comments on commit 04f4fac

Please sign in to comment.