Skip to content

Commit

Permalink
fix: improve subject selection and verification for SDR (#512)
Browse files Browse the repository at this point in the history
fixes #415
  • Loading branch information
rado0x54 committed May 11, 2021
1 parent a232e3a commit 01cb44e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/cli/src/sdr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ sdr
type: 'autocomplete',
pageSize: 15,
suggestOnly: true,
source: async (answers: any, search: string) => {
source: async (answers: any, input: string) => {
const res = fuzzy
.filter(search, subjects)
.filter(input, subjects)
.map((el: any) => (typeof el === 'string' ? el : el.original))
return res
},
validate(val) {
if (!val || !val.startsWith('did:')) {
return "Subject DID does not start with 'did:'..."
}
return true;
}
},
{
type: 'input',
Expand Down Expand Up @@ -221,17 +227,19 @@ sdr
},
])

const msg_data = {
from: answers.iss,
to: answers.sub,
type: 'jwt',
body: jwt,
}

if (!send) {
await agent.handleMessage({ raw: jwt, metaData: [{ type: 'cli' }], save: true })
await agent.handleMessage({ raw: JSON.stringify(msg_data), metaData: [{ type: 'cli' }], save: true })
} else if (answers.sub !== '') {
try {
const result = await agent.sendMessageDIDCommAlpha1({
data: {
from: answers.iss,
to: answers.sub,
type: 'jwt',
body: jwt,
},
data: msg_data,
})
console.log('Sent:', result)
} catch (e) {
Expand Down

0 comments on commit 01cb44e

Please sign in to comment.