This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 158
/
service.go
723 lines (591 loc) · 20.7 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package didexchange
import (
"encoding/json"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/hyperledger/aries-framework-go/pkg/common/log"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/dispatcher"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/decorator"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/route"
vdriapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdri"
"github.com/hyperledger/aries-framework-go/pkg/internal/logutil"
"github.com/hyperledger/aries-framework-go/pkg/kms/legacykms"
"github.com/hyperledger/aries-framework-go/pkg/storage"
"github.com/hyperledger/aries-framework-go/pkg/store/connection"
)
var logger = log.New("aries-framework/did-exchange/service")
const (
// DIDExchange did exchange protocol
DIDExchange = "didexchange"
// DIDExchangeSpec defines the did-exchange spec
DIDExchangeSpec = "https://didcomm.org/didexchange/1.0/"
// InvitationMsgType defines the did-exchange invite message type.
InvitationMsgType = DIDExchangeSpec + "invitation"
// RequestMsgType defines the did-exchange request message type.
RequestMsgType = DIDExchangeSpec + "request"
// ResponseMsgType defines the did-exchange response message type.
ResponseMsgType = DIDExchangeSpec + "response"
// AckMsgType defines the did-exchange ack message type.
AckMsgType = DIDExchangeSpec + "ack"
)
// message type to store data for eventing. This is retrieved during callback.
type message struct {
Msg service.DIDCommMsgMap
ThreadID string
Options *options
NextStateName string
ConnRecord *connection.Record
// err is used to determine whether callback was stopped
// e.g the user received an action event and executes Stop(err) function
// in that case `err` is equal to `err` which was passing to Stop function
err error
}
// provider contains dependencies for the DID exchange protocol and is typically created by using aries.Context()
type provider interface {
OutboundDispatcher() dispatcher.Outbound
StorageProvider() storage.Provider
TransientStorageProvider() storage.Provider
Signer() legacykms.Signer
VDRIRegistry() vdriapi.Registry
Service(id string) (interface{}, error)
}
// stateMachineMsg is an internal struct used to pass data to state machine.
type stateMachineMsg struct {
service.DIDCommMsg
connRecord *connection.Record
options *options
}
// Service for DID exchange protocol
type Service struct {
service.Action
service.Message
ctx *context
callbackChannel chan *message
connectionStore *connectionStore
}
type context struct {
outboundDispatcher dispatcher.Outbound
signer legacykms.Signer
connectionStore *connectionStore
vdriRegistry vdriapi.Registry
routeSvc route.ProtocolService
}
// opts are used to provide client properties to DID Exchange service
type opts interface {
// PublicDID allows for setting public DID
PublicDID() string
// Label allows for setting label
Label() string
}
// New return didexchange service
func New(prov provider) (*Service, error) {
connRecorder, err := newConnectionStore(prov)
if err != nil {
return nil, fmt.Errorf("failed to initialize connection store : %w", err)
}
s, err := prov.Service(route.Coordination)
if err != nil {
return nil, err
}
routeSvc, ok := s.(route.ProtocolService)
if !ok {
return nil, errors.New("cast service to Route Service failed")
}
const callbackChannelSize = 10
svc := &Service{
ctx: &context{
outboundDispatcher: prov.OutboundDispatcher(),
signer: prov.Signer(),
vdriRegistry: prov.VDRIRegistry(),
connectionStore: connRecorder,
routeSvc: routeSvc,
},
// TODO channel size - https://github.com/hyperledger/aries-framework-go/issues/246
callbackChannel: make(chan *message, callbackChannelSize),
connectionStore: connRecorder,
}
// start the listener
go svc.startInternalListener()
return svc, nil
}
// HandleInbound handles inbound didexchange messages.
func (s *Service) HandleInbound(msg service.DIDCommMsg, myDID, theirDID string) (string, error) {
logger.Debugf("receive inbound message : %s", msg)
// fetch the thread id
thID, err := threadID(msg)
if err != nil {
return "", err
}
// valid state transition and get the next state
next, err := s.nextState(msg.Type(), thID)
if err != nil {
return "", fmt.Errorf("handle inbound - next state : %w", err)
}
// connection record
connRecord, err := s.connectionRecord(msg)
if err != nil {
return "", err
}
// TODO: get rid of this msg.(service.DIDCommMsgMap)
internalMsg := &message{
Msg: msg.(service.DIDCommMsgMap),
ThreadID: thID,
NextStateName: next.Name(),
ConnRecord: connRecord,
}
go func(msg *message, aEvent chan<- service.DIDCommAction) {
if err = s.handle(msg, aEvent); err != nil {
logutil.LogError(logger, DIDExchange, "processMessage", err.Error(),
logutil.CreateKeyValueString("msgType", msg.Msg.Type()),
logutil.CreateKeyValueString("msgID", msg.Msg.ID()),
logutil.CreateKeyValueString("connectionID", msg.ConnRecord.ConnectionID))
}
logutil.LogDebug(logger, DIDExchange, "processMessage", "success",
logutil.CreateKeyValueString("msgType", msg.Msg.Type()),
logutil.CreateKeyValueString("msgID", msg.Msg.ID()),
logutil.CreateKeyValueString("connectionID", msg.ConnRecord.ConnectionID))
}(internalMsg, s.ActionEvent())
logutil.LogDebug(logger, DIDExchange, "handleInbound", "success",
logutil.CreateKeyValueString("msgType", internalMsg.Msg.Type()),
logutil.CreateKeyValueString("msgID", internalMsg.Msg.ID()),
logutil.CreateKeyValueString("connectionID", internalMsg.ConnRecord.ConnectionID))
return connRecord.ConnectionID, nil
}
// Name return service name
func (s *Service) Name() string {
return DIDExchange
}
func findNamespace(msgType string) string {
namespace := theirNSPrefix
if msgType == InvitationMsgType || msgType == ResponseMsgType {
namespace = myNSPrefix
}
return namespace
}
// Accept msg checks the msg type
func (s *Service) Accept(msgType string) bool {
return msgType == InvitationMsgType ||
msgType == RequestMsgType ||
msgType == ResponseMsgType ||
msgType == AckMsgType
}
// HandleOutbound handles outbound didexchange messages.
func (s *Service) HandleOutbound(msg service.DIDCommMsg, myDID, theirDID string) (string, error) {
return "", errors.New("not implemented")
}
func (s *Service) nextState(msgType, thID string) (state, error) {
nsThID, err := connection.CreateNamespaceKey(findNamespace(msgType), thID)
if err != nil {
return nil, err
}
current, err := s.currentState(nsThID)
if err != nil {
return nil, err
}
logger.Debugf("retrieved current state [%s] using nsThID [%s]", current.Name(), nsThID)
next, err := stateFromMsgType(msgType)
if err != nil {
return nil, err
}
logger.Debugf("check if current state [%s] can transition to [%s]", current.Name(), next.Name())
if !current.CanTransitionTo(next) {
return nil, fmt.Errorf("invalid state transition: %s -> %s", current.Name(), next.Name())
}
return next, nil
}
func (s *Service) handle(msg *message, aEvent chan<- service.DIDCommAction) error { //nolint funlen
next, err := stateFromName(msg.NextStateName)
if err != nil {
return fmt.Errorf("invalid state name: %w", err)
}
for !isNoOp(next) {
s.sendMsgEvents(&service.StateMsg{
ProtocolName: DIDExchange,
Type: service.PreState,
Msg: msg.Msg,
StateID: next.Name(),
Properties: createEventProperties(msg.ConnRecord.ConnectionID, msg.ConnRecord.InvitationID),
})
logger.Debugf("sent pre event for state %s", next.Name())
var (
action stateAction
followup state
connectionRecord *connection.Record
)
connectionRecord, followup, action, err = next.ExecuteInbound(
&stateMachineMsg{
DIDCommMsg: msg.Msg,
connRecord: msg.ConnRecord,
options: msg.Options,
},
msg.ThreadID,
s.ctx)
if err != nil {
return fmt.Errorf("failed to execute state %s %w", next.Name(), err)
}
connectionRecord.State = next.Name()
logger.Debugf("finished execute state: %s", next.Name())
if err = s.update(msg.Msg.Type(), connectionRecord); err != nil {
return fmt.Errorf("failed to persist state %s %w", next.Name(), err)
}
logger.Debugf("persisted the connection record using connection id %s", connectionRecord.ConnectionID)
if err = action(); err != nil {
return fmt.Errorf("failed to execute state action %s %w", next.Name(), err)
}
logger.Debugf("finish execute state action: %s", next.Name())
prev := next
next = followup
haltExecution := false
// trigger action event based on message type for inbound messages
if canTriggerActionEvents(connectionRecord.State, connectionRecord.Namespace) {
msg.NextStateName = next.Name()
if err = s.sendActionEvent(msg, aEvent); err != nil {
return fmt.Errorf("handle inbound: %w", err)
}
haltExecution = true
}
s.sendMsgEvents(&service.StateMsg{
ProtocolName: DIDExchange,
Type: service.PostState,
Msg: msg.Msg,
StateID: prev.Name(),
Properties: createEventProperties(connectionRecord.ConnectionID, connectionRecord.InvitationID),
})
logger.Debugf("sent post event for state %s", prev.Name())
if haltExecution {
break
}
}
return nil
}
func (s *Service) handleWithoutAction(msg *message) error {
return s.handle(msg, nil)
}
func createEventProperties(connectionID, invitationID string) *didExchangeEvent {
return &didExchangeEvent{
connectionID: connectionID,
invitationID: invitationID,
}
}
func createErrorEventProperties(connectionID, invitationID string, err error) *didExchangeEventError {
return &didExchangeEventError{
err: err,
didExchangeEvent: createEventProperties(connectionID, invitationID),
}
}
// sendActionEvent triggers the action event. This function stores the state of current processing and passes a callback
// function in the event message.
func (s *Service) sendActionEvent(internalMsg *message, aEvent chan<- service.DIDCommAction) error {
// save data to support AcceptExchangeRequest APIs (when client will not be able to invoke the callback function)
err := s.storeEventTransientData(internalMsg)
if err != nil {
return fmt.Errorf("send action event : %w", err)
}
if aEvent != nil {
// trigger action event
aEvent <- service.DIDCommAction{
ProtocolName: DIDExchange,
Message: internalMsg.Msg,
Continue: func(args interface{}) {
switch v := args.(type) {
case opts:
internalMsg.Options = &options{publicDID: v.PublicDID(), label: v.Label()}
default:
// nothing to do
}
s.processCallback(internalMsg)
},
Stop: func(err error) {
// sets an error to the message
internalMsg.err = err
s.processCallback(internalMsg)
},
Properties: createEventProperties(internalMsg.ConnRecord.ConnectionID, internalMsg.ConnRecord.InvitationID),
}
}
return nil
}
// sendEvent triggers the message events.
func (s *Service) sendMsgEvents(msg *service.StateMsg) {
// trigger the message events
for _, handler := range s.MsgEvents() {
handler <- *msg
}
}
// startInternalListener listens to messages in gochannel for callback messages from clients.
func (s *Service) startInternalListener() {
for msg := range s.callbackChannel {
// TODO https://github.com/hyperledger/aries-framework-go/issues/242 - retry logic
// if no error - do handle
if msg.err == nil {
msg.err = s.handleWithoutAction(msg)
}
// no error - continue
if msg.err == nil {
continue
}
if err := s.abandon(msg.ThreadID, msg.Msg, msg.err); err != nil {
logger.Errorf("process callback : %s", err)
}
}
}
// AcceptInvitation accepts/approves connection invitation.
func (s *Service) AcceptInvitation(connectionID, publicDID, label string) error {
return s.accept(connectionID, publicDID, label, stateNameInvited, "accept exchange invitation")
}
// AcceptExchangeRequest accepts/approves connection request.
func (s *Service) AcceptExchangeRequest(connectionID, publicDID, label string) error {
return s.accept(connectionID, publicDID, label, stateNameRequested, "accept exchange request")
}
func (s *Service) accept(connectionID, publicDID, label, stateID, errMsg string) error {
msg, err := s.getEventTransientData(connectionID)
if err != nil {
return fmt.Errorf("failed to accept invitation for connectionID=%s : %s : %w", connectionID, errMsg, err)
}
connRecord, err := s.connectionStore.GetConnectionRecord(connectionID)
if err != nil {
return fmt.Errorf("%s : %w", errMsg, err)
}
if connRecord.State != stateID {
return fmt.Errorf("current state (%s) is different from "+
"expected state (%s)", connRecord.State, stateID)
}
msg.Options = &options{publicDID: publicDID, label: label}
return s.handleWithoutAction(msg)
}
func (s *Service) storeEventTransientData(msg *message) error {
bytes, err := json.Marshal(msg)
if err != nil {
return fmt.Errorf("store transient data : %w", err)
}
return s.connectionStore.SaveEvent(msg.ConnRecord.ConnectionID, bytes)
}
func (s *Service) getEventTransientData(connectionID string) (*message, error) {
val, err := s.connectionStore.GetEvent(connectionID)
if err != nil {
return nil, fmt.Errorf("get transient data : %w", err)
}
msg := &message{}
err = json.Unmarshal(val, msg)
if err != nil {
return nil, fmt.Errorf("get transient data : %w", err)
}
return msg, nil
}
// abandon updates the state to abandoned and trigger failure event.
func (s *Service) abandon(thID string, msg service.DIDCommMsg, processErr error) error {
// update the state to abandoned
nsThID, err := connection.CreateNamespaceKey(findNamespace(msg.Type()), thID)
if err != nil {
return err
}
connRec, err := s.connectionStore.GetConnectionRecordByNSThreadID(nsThID)
if err != nil {
return fmt.Errorf("unable to update the state to abandoned: %w", err)
}
connRec.State = (&abandoned{}).Name()
err = s.update(msg.Type(), connRec)
if err != nil {
return fmt.Errorf("unable to update the state to abandoned: %w", err)
}
// send the message event
s.sendMsgEvents(&service.StateMsg{
ProtocolName: DIDExchange,
Type: service.PostState,
Msg: msg,
StateID: stateNameAbandoned,
Properties: createErrorEventProperties(thID, "", processErr),
})
return nil
}
func (s *Service) processCallback(msg *message) {
// pass the callback data to internal channel. This is created to unblock consumer go routine and wrap the callback
// channel internally.
s.callbackChannel <- msg
}
func isNoOp(s state) bool {
_, ok := s.(*noOp)
return ok
}
func threadID(didCommMsg service.DIDCommMsg) (string, error) {
if didCommMsg.Type() == InvitationMsgType {
return generateRandomID(), nil
}
return didCommMsg.ThreadID()
}
func (s *Service) currentState(nsThID string) (state, error) {
connRec, err := s.connectionStore.GetConnectionRecordByNSThreadID(nsThID)
if err != nil {
if errors.Is(err, storage.ErrDataNotFound) {
return &null{}, nil
}
return nil, fmt.Errorf("cannot fetch state from store: thID=%s err=%s", nsThID, err)
}
return stateFromName(connRec.State)
}
func (s *Service) update(msgType string, connectionRecord *connection.Record) error {
if (msgType == RequestMsgType && connectionRecord.State == stateNameRequested) ||
(msgType == InvitationMsgType && connectionRecord.State == stateNameInvited) {
return s.connectionStore.saveConnectionRecordWithMapping(connectionRecord)
}
return s.connectionStore.saveConnectionRecord(connectionRecord)
}
func (s *Service) connectionRecord(msg service.DIDCommMsg) (*connection.Record, error) {
switch msg.Type() {
case InvitationMsgType:
return s.invitationMsgRecord(msg)
case RequestMsgType:
return s.requestMsgRecord(msg)
case ResponseMsgType:
return s.responseMsgRecord(msg)
case AckMsgType:
return s.ackMsgRecord(msg)
}
return nil, errors.New("invalid message type")
}
func (s *Service) invitationMsgRecord(msg service.DIDCommMsg) (*connection.Record, error) {
thID, msgErr := msg.ThreadID()
if msgErr != nil {
return nil, msgErr
}
invitation := &Invitation{}
err := msg.Decode(invitation)
if err != nil {
return nil, err
}
recKey, err := s.ctx.getInvitationRecipientKey(invitation)
if err != nil {
return nil, err
}
connRecord := &connection.Record{
ConnectionID: generateRandomID(),
ThreadID: thID,
State: stateNameNull,
InvitationID: invitation.ID,
InvitationDID: invitation.DID,
ServiceEndPoint: invitation.ServiceEndpoint,
RecipientKeys: []string{recKey},
TheirLabel: invitation.Label,
Namespace: findNamespace(msg.Type()),
}
if err := s.connectionStore.saveConnectionRecord(connRecord); err != nil {
return nil, err
}
return connRecord, nil
}
func (s *Service) requestMsgRecord(msg service.DIDCommMsg) (*connection.Record, error) {
request := Request{}
err := msg.Decode(&request)
if err != nil {
return nil, fmt.Errorf("unmarshalling failed: %s", err)
}
connRecord := &connection.Record{
ConnectionID: generateRandomID(),
ThreadID: request.ID,
State: stateNameNull,
TheirDID: request.Connection.DID,
Namespace: theirNSPrefix,
}
if err := s.connectionStore.saveConnectionRecord(connRecord); err != nil {
return nil, err
}
return connRecord, nil
}
func (s *Service) responseMsgRecord(payload service.DIDCommMsg) (*connection.Record, error) {
return s.fetchConnectionRecord(myNSPrefix, payload)
}
func (s *Service) ackMsgRecord(payload service.DIDCommMsg) (*connection.Record, error) {
return s.fetchConnectionRecord(theirNSPrefix, payload)
}
func (s *Service) fetchConnectionRecord(nsPrefix string, payload service.DIDCommMsg) (*connection.Record, error) {
msg := &struct {
Thread decorator.Thread `json:"~thread,omitempty"`
}{}
err := payload.Decode(msg)
if err != nil {
return nil, err
}
key, err := connection.CreateNamespaceKey(nsPrefix, msg.Thread.ID)
if err != nil {
return nil, err
}
return s.connectionStore.GetConnectionRecordByNSThreadID(key)
}
func generateRandomID() string {
return uuid.New().String()
}
// canTriggerActionEvents true based on role and state.
// 1. Role is invitee and state is invited
// 2. Role is inviter and state is requested
func canTriggerActionEvents(stateID, ns string) bool {
return (stateID == stateNameInvited && ns == myNSPrefix) || (stateID == stateNameRequested && ns == theirNSPrefix)
}
type options struct {
publicDID string
label string
}
// CreateImplicitInvitation creates implicit invitation. Inviter DID is required, invitee DID is optional.
// If invitee DID is not provided new peer DID will be created for implicit invitation exchange request.
func (s *Service) CreateImplicitInvitation(inviterLabel, inviterDID, inviteeLabel, inviteeDID string) (string, error) {
logger.Debugf("implicit invitation requested inviterDID[%s] inviteeDID[%s]", inviterDID, inviteeDID)
didDoc, err := s.ctx.vdriRegistry.Resolve(inviterDID)
if err != nil {
return "", fmt.Errorf("resolve public did[%s]: %w", inviterDID, err)
}
dest, err := service.CreateDestination(didDoc)
if err != nil {
return "", err
}
thID := generateRandomID()
connRecord := &connection.Record{
ConnectionID: generateRandomID(),
ThreadID: thID,
State: stateNameNull,
InvitationDID: inviterDID,
Implicit: true,
ServiceEndPoint: dest.ServiceEndpoint,
RecipientKeys: dest.RecipientKeys,
TheirLabel: inviterLabel,
Namespace: findNamespace(InvitationMsgType),
}
if e := s.connectionStore.saveConnectionRecordWithMapping(connRecord); e != nil {
return "", fmt.Errorf("failed to save new connection record for implicit invitation: %w", e)
}
invitation := &Invitation{
ID: uuid.New().String(),
Label: inviterLabel,
DID: inviterDID,
Type: InvitationMsgType}
msg, err := createDIDCommMsg(invitation)
if err != nil {
return "", fmt.Errorf("failed to create DIDCommMsg for implicit invitation: %w", err)
}
// TODO: get rid of this msg.(service.DIDCommMsgMap)
next := &requested{}
internalMsg := &message{
Msg: msg.(service.DIDCommMsgMap),
ThreadID: thID,
NextStateName: next.Name(),
ConnRecord: connRecord,
}
internalMsg.Options = &options{publicDID: inviteeDID, label: inviteeLabel}
go func(msg *message, aEvent chan<- service.DIDCommAction) {
if err = s.handle(msg, aEvent); err != nil {
logger.Errorf("error from handle for implicit invitation: %s", err)
}
}(internalMsg, s.ActionEvent())
return connRecord.ConnectionID, nil
}
func createDIDCommMsg(invitation *Invitation) (service.DIDCommMsg, error) {
payload, err := json.Marshal(invitation)
if err != nil {
return nil, fmt.Errorf("marshal invitation: %w", err)
}
return service.ParseDIDCommMsgMap(payload)
}