Skip to content

Commit d1ec728

Browse files
authored
feats: better error handling for well known did genesis (#69)
## 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.
1 parent 443b431 commit d1ec728

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

backend/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function deduceAccountAddress(): Promise<string> {
6161
*
6262
* @param didDocument
6363
*/
64-
async function validateOurKeys(didDocument: Kilt.DidDocument) {
64+
export async function validateOurKeys(didDocument: Kilt.DidDocument) {
6565
const localKeyPairs = generateKeyPairs(DAPP_DID_MNEMONIC)
6666

6767
// A DID can have several keys of type 'keyAgreement', but only up to one key of each of the other types.

scripts/genesisWellKnownDidConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import path from 'path'
55
import * as Kilt from '@kiltprotocol/sdk-js'
66
import dotenv from 'dotenv'
77

8+
import { validateOurKeys } from '../backend/src/config'
9+
import { fetchDidDocument } from '../backend/src/utils/fetchDidDocument'
10+
811
import { generateAccount } from './launchUtils/generateAccount'
912
import { generateKeyPairs } from './launchUtils/generateKeyPairs'
1013
import { VerifiableDomainLinkagePresentation } from './launchUtils/types'
@@ -142,6 +145,10 @@ async function main() {
142145
const dAppsDidKeys = generateKeyPairs(dAppMnemonic)
143146
const dappAccount = generateAccount(fundsMnemonic)
144147

148+
// Check that the DID keys saved on the blockchain match the one being derived from your mnemonic
149+
const ourDidDocumentOnChain = await fetchDidDocument()
150+
await validateOurKeys(ourDidDocumentOnChain)
151+
145152
// Writes the attestation on the blockchain
146153
await selfAttestCredential(
147154
domainCredential,

scripts/wellKnownDIDConfiguration.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,16 @@ export async function selfAttestCredential(
285285
const result = await Kilt.Blockchain.signAndSubmitTx(
286286
submitTx,
287287
submitterAccount
288-
)
288+
).catch((reason) => {
289+
throw new Error(
290+
'Could not sing and submit transaction:' +
291+
JSON.stringify(reason, null, 2) +
292+
'\n' +
293+
'Make sure the keys saved on chain match the ones being derived from your mnemonic on this projects.'
294+
)
295+
})
289296

290-
if (result.isError) {
297+
if (result?.isError) {
291298
throw new Error('Attestation failed')
292299
} else {
293300
console.log('Attestation successful')

0 commit comments

Comments
 (0)