Skip to content

Commit

Permalink
merged main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
olomix committed Aug 29, 2023
2 parents 5469947 + 8513869 commit 5ed124a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
35 changes: 35 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,41 @@ func CreateAuthorizationRequestWithMessage(reason, message, sender,
return request
}

// CreateContractInvokeRequest creates new contract invoke request message
// reason - describes purpose of request
// sender - sender identifier
// transactionData - data for on chain verification
// zkRequests - zero knowledge proof request(s)
func CreateContractInvokeRequest(
reason, sender string,
transactionData protocol.TransactionData,
zkRequests ...protocol.ZeroKnowledgeProofRequest,
) protocol.ContractInvokeRequestMessage {
return CreateContractInvokeRequestWithMessage(reason, "", sender, transactionData, zkRequests...)
}

// CreateContractInvokeRequestWithMessage creates new contract invoke request message with message
func CreateContractInvokeRequestWithMessage(
reason, message, sender string,
transactionData protocol.TransactionData,
zkRequests ...protocol.ZeroKnowledgeProofRequest,
) protocol.ContractInvokeRequestMessage {
reqID := uuid.New().String()
return protocol.ContractInvokeRequestMessage{
Typ: packers.MediaTypePlainMessage,
Type: protocol.ContractInvokeRequestMessageType,
ID: reqID,
ThreadID: reqID,
From: sender,
Body: protocol.ContractInvokeRequestMessageBody{
Reason: reason,
Message: message,
TransactionData: transactionData,
Scope: zkRequests,
},
}
}

// VerifyAuthResponse performs verification of auth response based on auth request
func (v *Verifier) VerifyAuthResponse(
ctx context.Context,
Expand Down
47 changes: 47 additions & 0 deletions transport/notification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package transport

import (
"context"
"encoding/json"

"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/iden3/iden3comm/v2/protocol"
"github.com/iden3/iden3comm/v2/transport/notification"
"github.com/pkg/errors"
)

// SendPushAuthRequest sends authorization request to the user via a push notification.
func SendPushAuthRequest(
ctx context.Context,
diddoc verifiable.DIDDocument,
authMsg protocol.AuthorizationRequestMessage,
) (*notification.UserNotificationResult, error) {
authMsgBytes, err := json.Marshal(authMsg)
if err != nil {
return nil, errors.WithStack(err)
}
return notification.Notify(
ctx,
authMsgBytes,
diddoc,
nil,
)
}

// SendPushContractInvokeRequest sends a contract invoke request to the user via a push notification.
func SendPushContractInvokeRequest(
ctx context.Context,
diddoc verifiable.DIDDocument,
contractInvokeMsg protocol.ContractInvokeRequestMessage,
) (*notification.UserNotificationResult, error) {
ciMsgBytes, err := json.Marshal(contractInvokeMsg)
if err != nil {
return nil, errors.WithStack(err)
}
return notification.Notify(
ctx,
ciMsgBytes,
diddoc,
nil,
)
}

0 comments on commit 5ed124a

Please sign in to comment.