Skip to content

Commit

Permalink
feat: export didcomm mediator utils (#1181)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat authored Jun 5, 2023
1 parent e7138d3 commit 264b6a7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class Agent implements IAgent {
* @public
*/
async execute<P = any, R = any>(method: string, args: P): Promise<R> {
Debug('veramo:agent:' + method)('%o', args)
Debug('veramo:agent:' + method)('%s %o', 'arg', args)
if (!this.methods[method]) throw Error('Method not available: ' + method)
const _args = args || {}
if (this.schemaValidation && this.schema.components.methods[method]) {
Expand All @@ -183,7 +183,7 @@ export class Agent implements IAgent {
if (this.schemaValidation && this.schema.components.methods[method]) {
validateReturnType(method, result, this.schema)
}
Debug('veramo:agent:' + method + ':result')('%o', result)
Debug('veramo:agent:' + method)('%s %o', 'res', result)
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,34 @@ const debug = Debug('veramo:did-comm:coordinate-mediation-message-handler')

type IContext = IAgentContext<IDIDManager & IKeyManager & IDIDComm & IDataStore>

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export const MEDIATE_REQUEST_MESSAGE_TYPE = 'https://didcomm.org/coordinate-mediation/2.0/mediate-request'

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export const MEDIATE_GRANT_MESSAGE_TYPE = 'https://didcomm.org/coordinate-mediation/2.0/mediate-grant'

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export const MEDIATE_DENY_MESSAGE_TYPE = 'https://didcomm.org/coordinate-mediation/2.0/mediate-deny'

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export const STATUS_REQUEST_MESSAGE_TYPE = 'https://didcomm.org/messagepickup/3.0/status-request'

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export const DELIVERY_REQUEST_MESSAGE_TYPE = 'https://didcomm.org/messagepickup/3.0/delivery-request'

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export function createMediateRequestMessage(
recipientDidUrl: string,
mediatorDidUrl: string,
Expand All @@ -28,6 +52,9 @@ export function createMediateRequestMessage(
}
}

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export function createMediateGrantMessage(
recipientDidUrl: string,
mediatorDidUrl: string,
Expand All @@ -46,6 +73,40 @@ export function createMediateGrantMessage(
}
}

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export function createStatusRequestMessage(
recipientDidUrl: string,
mediatorDidUrl: string,
): IDIDCommMessage {
return {
id: v4(),
type: STATUS_REQUEST_MESSAGE_TYPE,
to: mediatorDidUrl,
from: recipientDidUrl,
return_route: 'all',
body: {},
}
}

/**
* @beta This API may change without a BREAKING CHANGE notice.
*/
export function createDeliveryRequestMessage(
recipientDidUrl: string,
mediatorDidUrl: string,
): IDIDCommMessage {
return {
id: v4(),
type: DELIVERY_REQUEST_MESSAGE_TYPE,
to: mediatorDidUrl,
from: recipientDidUrl,
return_route: 'all',
body: { limit: 2 },
}
}

/**
* A plugin for the {@link @veramo/message-handler#MessageHandler} that handles Mediator Coordinator messages for the mediator role.
* @beta This API may change without a BREAKING CHANGE notice.
Expand Down
2 changes: 1 addition & 1 deletion packages/did-comm/src/protocols/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { TrustPingMessageHandler } from './trust-ping-message-handler.js'
export { CoordinateMediationMediatorMessageHandler, CoordinateMediationRecipientMessageHandler } from "./coordinate-mediation-message-handler.js"
export * from "./coordinate-mediation-message-handler.js"
export { RoutingMessageHandler } from "./routing-message-handler.js"
export { PickupMediatorMessageHandler, PickupRecipientMessageHandler } from "./messagepickup-message-handler.js"

0 comments on commit 264b6a7

Please sign in to comment.