Skip to content

Commit

Permalink
add first validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fermentfan committed Aug 17, 2022
1 parent 61ae02f commit 1c33a80
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/agent/did-ethr-meta-transaction-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,29 @@ export class DidEthrMetaTransactionPlugin implements IAgentPlugin {
addAttribute: this.addDelegate.bind(this),
}

/** {@inheritDoc DidProviderEthrMetaPlugin.myPluginFoo} */


/** {@inheritDoc DidProviderEthrMetaPlugin.addDelegate} */
private async addDelegate(args: IAddAttributeArgs, context: IRequiredContext): Promise<IAddAttributeResult> {
if(!args.did) {
throw new Error("DID must not be empty")
}
if(!args.attributeName) {
throw new Error("attributeName must not be empty")
}
if(!args.attributeValue) {
throw new Error("attributeValue must not be empty")
}

const did = await context.agent.didManagerGet({
did: args.did
})
if(!did) {
throw new Error("DID not found")
}
if(did.provider !== 'ethr') {
throw new Error("DID provider must be of type ethr")
}
// you can call other agent methods (that are declared in the `IRequiredContext`)
//const didDoc = await context.agent.resolveDid({ didUrl: args.did })
// or emit some events
Expand Down

0 comments on commit 1c33a80

Please sign in to comment.