Skip to content

Commit

Permalink
feats: better error handling for well known did genesis (#69)
Browse files Browse the repository at this point in the history
## fixes KILTProtocol/ticket#No_ticket

@aybarsayan had imported his mnemonic from Sporran and was having
trouble generating a **well-known-did-config** because his DID keys on
the chain where different than the ones derivated on the project.

There was an error popping up that did not explained much. Now the
error(s) explains more.
  • Loading branch information
kilted-andres authored Jan 31, 2024
1 parent 443b431 commit d1ec728
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function deduceAccountAddress(): Promise<string> {
*
* @param didDocument
*/
async function validateOurKeys(didDocument: Kilt.DidDocument) {
export async function validateOurKeys(didDocument: Kilt.DidDocument) {
const localKeyPairs = generateKeyPairs(DAPP_DID_MNEMONIC)

// A DID can have several keys of type 'keyAgreement', but only up to one key of each of the other types.
Expand Down
7 changes: 7 additions & 0 deletions scripts/genesisWellKnownDidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import path from 'path'
import * as Kilt from '@kiltprotocol/sdk-js'
import dotenv from 'dotenv'

import { validateOurKeys } from '../backend/src/config'
import { fetchDidDocument } from '../backend/src/utils/fetchDidDocument'

import { generateAccount } from './launchUtils/generateAccount'
import { generateKeyPairs } from './launchUtils/generateKeyPairs'
import { VerifiableDomainLinkagePresentation } from './launchUtils/types'
Expand Down Expand Up @@ -142,6 +145,10 @@ async function main() {
const dAppsDidKeys = generateKeyPairs(dAppMnemonic)
const dappAccount = generateAccount(fundsMnemonic)

// Check that the DID keys saved on the blockchain match the one being derived from your mnemonic
const ourDidDocumentOnChain = await fetchDidDocument()
await validateOurKeys(ourDidDocumentOnChain)

// Writes the attestation on the blockchain
await selfAttestCredential(
domainCredential,
Expand Down
11 changes: 9 additions & 2 deletions scripts/wellKnownDIDConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,16 @@ export async function selfAttestCredential(
const result = await Kilt.Blockchain.signAndSubmitTx(
submitTx,
submitterAccount
)
).catch((reason) => {
throw new Error(
'Could not sing and submit transaction:' +
JSON.stringify(reason, null, 2) +
'\n' +
'Make sure the keys saved on chain match the ones being derived from your mnemonic on this projects.'
)
})

if (result.isError) {
if (result?.isError) {
throw new Error('Attestation failed')
} else {
console.log('Attestation successful')
Expand Down

0 comments on commit d1ec728

Please sign in to comment.