-
Notifications
You must be signed in to change notification settings - Fork 1
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 PaymentRequest and Payment messages #61
Add PaymentRequest and Payment messages #61
Conversation
protocol/payment.go
Outdated
|
||
const ( | ||
// PaymentRequestMessageType is a Iden3PaymentMessage payment type | ||
PaymentRequestMessageType iden3comm.ProtocolMessage = iden3comm.DidCommProtocol + "credentials/0.1/payment-request" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be under Iden3Protocol domain name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also changed PaymentMessageType to same Iden3Protocol domain.
protocol/payment.go
Outdated
|
||
// EthereumEip712Signature2021 represents the Ethereum EIP712 signature. | ||
type EthereumEip712Signature2021 struct { | ||
Type string `json:"type"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verifiable.ProofType
do not merge til erc20 payment spec, please |
protocol/payment.go
Outdated
func (p *PaymentContext) UnmarshalJSON(data []byte) error { | ||
var str string | ||
var strCol []string | ||
var itemCol []interface{} | ||
|
||
if err := json.Unmarshal(data, &str); err == nil { | ||
p.str = &str | ||
return nil | ||
} | ||
if err := json.Unmarshal(data, &strCol); err == nil { | ||
p.strCol = strCol | ||
return nil | ||
} | ||
if err := json.Unmarshal(data, &itemCol); err == nil { | ||
p.itemCol = itemCol | ||
return nil | ||
} | ||
return errors.Errorf("failed to unmarshal PaymentContext: %s", string(data)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I see here is that if we would try to unmarshal the input json into already initialized object, we would not fullfill that constraint that only one field should be non-empty. What do you think about more explicit unmarshaling by explicitly checking json types instead of base our logic on returned errors?
func (p *PaymentContext) UnmarshalJSON(data []byte) error { | |
var str string | |
var strCol []string | |
var itemCol []interface{} | |
if err := json.Unmarshal(data, &str); err == nil { | |
p.str = &str | |
return nil | |
} | |
if err := json.Unmarshal(data, &strCol); err == nil { | |
p.strCol = strCol | |
return nil | |
} | |
if err := json.Unmarshal(data, &itemCol); err == nil { | |
p.itemCol = itemCol | |
return nil | |
} | |
return errors.Errorf("failed to unmarshal PaymentContext: %s", string(data)) | |
} | |
func (p *PaymentContext) UnmarshalJSON(data []byte) error { | |
var o any | |
err := json.Unmarshal(data, &o) | |
if err != nil { | |
return err | |
} | |
switch v := o.(type) { | |
case string: | |
p.str = &v | |
p.strCol = nil | |
p.itemCol = nil | |
case []any: | |
p.str = nil | |
p.itemCol = nil | |
p.strCol = make([]string, len(v)) | |
for i := range v { | |
s, ok := v[i].(string) | |
if !ok { | |
p.strCol = nil | |
p.itemCol = v | |
break | |
} | |
p.strCol[i] = s | |
} | |
default: | |
return errors.Errorf("failed to unmarshal PaymentContext: %s", | |
string(data)) | |
} | |
return nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I like your proposal. Let me change it.
Done,
chore: Refactor marshallers with clearer and more consistent performer
protocol/payment.go
Outdated
Recipient string `json:"recipient"` | ||
Amount string `json:"amount"` // Not negative number | ||
ExpirationDate string `json:"expirationDate"` | ||
Proof EthereumEip712Signature2021Col `json:"proof"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one doubt regarding that. From the protocol persperctive we can have different proof types here. So we can design structure not to break interfaces later.
What do you think @x1m3 @volodymyr-basiuk ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also it can be an object, not always an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I agree. We need to handle objects and arrays and change Proof structure in a way that can be extended in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmidyllic Internal representation is a collection, but EthereumEip712Signature2021Col is implementing the json unmarshal interface and accepts and object. Output is always a list. So, it is working with single objects or lists.
Naming is not the best.
Regarding diferent ProfTypes we can always change implementation later but, let me try to do a proposal hidding this prooftype into a superobject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Changed it to class that can be extended in the future with other proof types.
protocol/payment.go
Outdated
dataType string | ||
crypto []Iden3PaymentRequestCryptoV1 | ||
rails []Iden3PaymentRailsRequestV1 | ||
railsERC []Iden3PaymentRailsERC20RequestV1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call it railsERC20
protocol/payment.go
Outdated
// Iden3PaymentCryptoV1 represents the Iden3PaymentCryptoV1 payment data. | ||
type Iden3PaymentCryptoV1 struct { | ||
ID string `json:"id"` | ||
Type string `json:"type"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we define separate type - iden3comm.PaymentType/PaymentRequestType or similar ?
For this fild Type
only one value are possible - Iden3PaymentCryptoV1
.
The same for Iden3PaymentRailsV1/Request and Iden3PaymentRailsERC20V1/Request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
No description provided.