Skip to content

Commit

Permalink
Merge pull request #193 from docknetwork/chore/improve-logging-for-di…
Browse files Browse the repository at this point in the history
…dcomm-handlers

chore/improve logging for didcomm handlers
  • Loading branch information
maycon-mello authored Jan 11, 2024
2 parents a11042f + 3ee1b4c commit aa5102e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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
7 changes: 5 additions & 2 deletions packages/transactions/lib/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const TransactionEvents = {
async function getAllTransactions() {
try {
const data = await getLocalStorage().getItem('transactions');
return JSON.parse(data);
return JSON.parse(data) || [];
} catch (err) {
return [];
}
Expand Down Expand Up @@ -207,8 +207,11 @@ export class Transactions {
return;
}

let dbTransactions = await getAllTransactions();

const dbTransactions = await getAllTransactions();
if (!dbTransactions) {
dbTransactions = [];
}

const handleTransaction = tx => {
if (tx.from !== address && tx.to !== address) {
Expand Down

0 comments on commit aa5102e

Please sign in to comment.