Skip to content

Commit

Permalink
send auth and proof notifications (#57)
Browse files Browse the repository at this point in the history
* send auth and proof notifications
* add constructor for create contract invoke message
  • Loading branch information
ilya-korotya authored Aug 16, 2023
1 parent 0200e3b commit a4998d8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
33 changes: 33 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,39 @@ 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 {
return protocol.ContractInvokeRequestMessage{
Typ: packers.MediaTypePlainMessage,
Type: protocol.AuthorizationRequestMessageType,
ID: uuid.New().String(),
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/iden3/go-rapidsnark/verifier v0.0.5
github.com/iden3/go-schema-processor v1.3.1
github.com/iden3/iden3comm v1.1.0
github.com/iden3/iden3comm v1.1.1-0.20230810141028-42068fe8ad57
github.com/ipfs/go-ipfs-api v0.6.0
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f
github.com/pkg/errors v0.9.1
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ github.com/iden3/go-schema-processor v1.3.1 h1:LJfFInfYGMOp0bTKKC17R8q4XI+VtqhFL
github.com/iden3/go-schema-processor v1.3.1/go.mod h1:NwJ1nuGdRlCFaN1/V6mS0AOAdvpLcGf4KKq0mluLG7U=
github.com/iden3/iden3comm v1.1.0 h1:feWurfGJV6YZyxi4J3U2jqQ+RUo0mo36Aoqyck1ZnHg=
github.com/iden3/iden3comm v1.1.0/go.mod h1:1bJHz0xNhwbQGDxYfVwMVYsdsMjFQRkHJF/eq5Rc9wE=
github.com/iden3/iden3comm v1.1.1-0.20230810101037-f49961bb9e6c h1:JSsDSdkhkZNPD6dwNG3jua1QWbTERmA+oALrcy+Q3aU=
github.com/iden3/iden3comm v1.1.1-0.20230810101037-f49961bb9e6c/go.mod h1:1bJHz0xNhwbQGDxYfVwMVYsdsMjFQRkHJF/eq5Rc9wE=
github.com/iden3/iden3comm v1.1.1-0.20230810105009-6a98a9309fed h1:2aBuvK/GPWiqMDu2NoNKp8X2Wrm6xEiQC0uH6oeyz7Y=
github.com/iden3/iden3comm v1.1.1-0.20230810105009-6a98a9309fed/go.mod h1:1bJHz0xNhwbQGDxYfVwMVYsdsMjFQRkHJF/eq5Rc9wE=
github.com/iden3/iden3comm v1.1.1-0.20230810141028-42068fe8ad57 h1:+UukNLBWlCIvUqDA79pHBCXYarGt6VQH2WsNJv9dUYs=
github.com/iden3/iden3comm v1.1.1-0.20230810141028-42068fe8ad57/go.mod h1:1bJHz0xNhwbQGDxYfVwMVYsdsMjFQRkHJF/eq5Rc9wE=
github.com/iden3/wasmer-go v0.0.1 h1:TZKh8Se8B/73PvWrcu+FTU9L1k5XYAmtFbioj7l0Uog=
github.com/iden3/wasmer-go v0.0.1/go.mod h1:ZnZBAO012M7o+Q1INXLRIxKQgEcH2FuwL0Iga8A4ufg=
github.com/ipfs/boxo v0.8.0 h1:UdjAJmHzQHo/j3g3b1bAcAXCj/GM6iTwvSlBDvPBNBs=
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/verifiable"
"github.com/iden3/iden3comm/protocol"
"github.com/iden3/iden3comm/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 a4998d8

Please sign in to comment.