Skip to content

Commit

Permalink
better error logging for didcomm resolvers + wallet-sdk-cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
maycon-mello committed Jan 11, 2024
1 parent ac51e7f commit 3ee1b4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/cli/src/commands/dids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import inquirer from 'inquirer';
import axios from 'axios';
import {IWallet} from '@docknetwork/wallet-sdk-core/lib/types';
import {createDIDProvider} from '@docknetwork/wallet-sdk-core/src/did-provider';
import {relayService} from '@docknetwork/wallet-sdk-wasm/lib/services/relay-service';
import {getWallet} from '../helpers';

const didsCommand = new Command('dids').description('list, create');
Expand Down Expand Up @@ -40,4 +41,25 @@ didsCommand
console.log(did);
});

/**
* Resolve a DIDComm message
* Ex.: didcomm://https://relay.dock.io/read/659ed4b1655cf81a6a35e140'
*/
didsCommand
.command('resolve-message')
.option('-m, --message <message>', 'Message to be resolved')
.description('Resolve didcomm message')
.action(async ({ message }) => {
const wallet: IWallet = await getWallet();
const didProvider = createDIDProvider({wallet});
const keyPairDocs = await didProvider.getDIDKeyPairs();

const messsage = await relayService.resolveDidcommMessage({
message,
keyPairDocs,
});

console.log(messsage);
});

export {didsCommand};
7 changes: 6 additions & 1 deletion packages/relay-service/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ export async function resolveDidcommMessage({keyPairDocs, message}) {
didCommRecipients.find(did => did.indexOf(doc.controller) > -1),
);

assert(!!keyPairDoc, `keyPairDoc not found for did ${message.to}`);
assert(
!!keyPairDoc,
`keyPairDoc not found for recipients ${JSON.stringify(
didCommRecipients,
)}`,
);
const keyAgreementKey = await getDerivedAgreementKey(keyPairDoc);
result = await didcommDecrypt(jwe, keyAgreementKey);
}
Expand Down

0 comments on commit 3ee1b4c

Please sign in to comment.