Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transparent payment instruction, attachments to the protocol #73

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package iden3comm

// Attachment represents a DIDComm message attachment
type Attachment struct {
ID string `json:"id"`
Description string `json:"description,omitempty"`
MediaType MediaType `json:"media_type"`
Data AttachData `json:"data"`
}

// AttachData represents the data field in a DIDComm attachment
type AttachData struct {
JSON interface{} `json:"json,omitempty"`
// Future fields can be added here:
// JWS interface{} `json:"jws,omitempty"`
// Hash interface{} `json:"hash,omitempty"`
// Link interface{} `json:"link,omitempty"`
}
2 changes: 2 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type BasicMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []Attachment `json:"attachments,omitempty"`
}

// ProtocolMessage is IDEN3Comm message
Expand Down
4 changes: 4 additions & 0 deletions protocol/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type AuthorizationResponseMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// AuthorizationMessageResponseBody is struct the represents authorization response data
Expand All @@ -51,6 +53,8 @@ type AuthorizationRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// AuthorizationRequestMessageBody is body for authorization request
Expand Down
25 changes: 25 additions & 0 deletions protocol/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package protocol

import (
"fmt"

"github.com/iden3/iden3comm/v2"
)

// GoalCode represents the goal code of targeted protocol message
type GoalCode string

const (
// ProposalRequest is the goal code for proposal request
ProposalRequest GoalCode = "iden3comm.credentials.v1-1.proposal-request"
)

// GetProtocolMessageTypeByGoalCode returns the protocol message type by goal code
func GetProtocolMessageTypeByGoalCode(goalCode GoalCode) (iden3comm.ProtocolMessage, error) {
switch goalCode {
case ProposalRequest:
return CredentialProposalRequestMessageType, nil
default:
return "", fmt.Errorf("unknown goal code %s", goalCode)
}
}
2 changes: 2 additions & 0 deletions protocol/contract_invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type ContractInvokeRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// ContractInvokeRequestMessageBody is body for contract invoke request
Expand Down
22 changes: 22 additions & 0 deletions protocol/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ type CredentialIssuanceRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialIssuanceRequestMessageBody represents data for credential issuance request
Expand All @@ -124,6 +126,8 @@ type CredentialsOfferMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialsOfferMessageBody is struct the represents offer message
Expand Down Expand Up @@ -153,6 +157,8 @@ type CredentialIssuanceMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// IssuanceMessageBody is struct the represents message when credential is issued
Expand All @@ -173,6 +179,8 @@ type CredentialFetchRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialFetchRequestMessageBody is msg body for fetch request
Expand Down Expand Up @@ -201,6 +209,8 @@ type CredentialStatusUpdateMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialStatusUpdateMessageBody the structure that represents the body of credential status update message
Expand All @@ -223,6 +233,8 @@ type CredentialRefreshMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialRefreshMessageBody is msg body for refresh message
Expand All @@ -245,6 +257,8 @@ type CredentialsOnchainOfferMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialsOnchainOfferMessageBody is struct the represents onchain offer message
Expand All @@ -271,6 +285,8 @@ type CredentialsProposalRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialsProposalMessage represents Iden3message for credential proposal
Expand All @@ -291,6 +307,8 @@ type CredentialsProposalMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialsProposalRequestBody is msg body for proposal requests
Expand Down Expand Up @@ -364,6 +382,8 @@ type CredentialPaymentRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialPaymentRequestBody is msg body for payment requests
Expand Down Expand Up @@ -422,6 +442,8 @@ type CredentialPaymentMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// CredentialPaymentBody is msg body for payment
Expand Down
2 changes: 2 additions & 0 deletions protocol/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type DeviceRegistrationRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// DeviceRegistrationRequestMessageBody is struct the represents body for register device request request
Expand Down
2 changes: 2 additions & 0 deletions protocol/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type MessageFetchRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// MessageFetchRequestMessageBody is struct the represents body for message fetch request.
Expand Down
4 changes: 4 additions & 0 deletions protocol/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type PaymentRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// PaymentRequestMessageBody represents the body of the PaymentRequestMessage.
Expand Down Expand Up @@ -284,6 +286,8 @@ type PaymentMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// PaymentMessageBody represents the body of the PaymentMessage.
Expand Down
2 changes: 2 additions & 0 deletions protocol/problem_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type ProblemReportMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// ProblemReportMessageBody is struct the represents body for problem report
Expand Down
4 changes: 4 additions & 0 deletions protocol/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type ProofGenerationRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// ProofGenerationRequestMessageBody is struct the represents body for proof generation request
Expand All @@ -46,6 +48,8 @@ type ProofGenerationResponseMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// ResponseMessageBody is struct the represents request for revocation status
Expand Down
4 changes: 4 additions & 0 deletions protocol/revocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type RevocationStatusRequestMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// RevocationStatusRequestMessageBody is struct the represents request for revocation status
Expand All @@ -46,6 +48,8 @@ type RevocationStatusResponseMessage struct {

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// RevocationStatusResponseMessageBody is struct the represents request for revocation status
Expand Down
53 changes: 53 additions & 0 deletions protocol/transparent_payment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package protocol

import (
"github.com/iden3/iden3comm/v2"
)

const (
// TransparentPaymentInstructionMessageType defines the message type for transparent payment instruction
TransparentPaymentInstructionMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/1.0/transparent-payment-instruction"
)

// TransparentPaymentInstructionMessage represents a message for transparent payment instruction
type TransparentPaymentInstructionMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`
Body TransparentPaymentInstructionMessageBody `json:"body"`

From string `json:"from"`
To string `json:"to"`

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`

Attachments []iden3comm.Attachment `json:"attachments,omitempty"`
}

// TransparentPaymentInstructionMessageBody represents the body of the transparent payment instruction message
type TransparentPaymentInstructionMessageBody struct {
GoalCode GoalCode `json:"goal_code"`
DID string `json:"did,omitempty"`
Credentials []CredentialSchemaInfo `json:"credentials"`
PaymentData TransparentPaymentData `json:"paymentData"`
}

// CredentialSchemaInfo represents credential information in the transparent payment instruction
type CredentialSchemaInfo struct {
Context string `json:"context"`
Type string `json:"type"`
}

// TransparentPaymentData represents payment data in the transparent payment instruction
type TransparentPaymentData struct {
Type string `json:"type"`
Signature string `json:"signature"`
Recipient string `json:"recipient"`
Amount string `json:"amount"`
Token string `json:"token,omitempty"`
Expiration int64 `json:"expiration"`
Nonce uint64 `json:"nonce"`
Metadata string `json:"metadata,omitempty"`
}
Loading