-
Notifications
You must be signed in to change notification settings - Fork 36
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
Iden3PaymentRailsRequestV1 #275
Conversation
src/iden3comm/handlers/payment.ts
Outdated
primaryType: 'Iden3PaymentRailsRequestV1', | ||
domain: { | ||
...domain, | ||
salt: '' |
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.
why salt is empty?
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.
Because now we don't use it in domain separator (name, version, chain id and contract address is enough).
I believe we can remove this field since it's not even in the contract domain type:
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
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.
removed
src/iden3comm/handlers/payment.ts
Outdated
signer: Signer, | ||
opts: { | ||
payments: [ | ||
{ |
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 would add a type for this
src/iden3comm/handlers/payment.ts
Outdated
paymentValidationHandler: (txId: string, data: PaymentRequestDataInfo) => Promise<void>; | ||
paymentValidationHandler: ( | ||
txId: string, | ||
data: Iden3PaymentRequestCryptoV1 | Iden3PaymentRailsRequestV1 |
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.
Just to know, why the name is Iden3PaymentRails
request?
src/iden3comm/handlers/payment.ts
Outdated
const selectedPayment = paymentReq.data.find((p) => { | ||
const proofs = Array.isArray(p.proof) ? p.proof : [p.proof]; | ||
return ( | ||
proofs.filter( |
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 guess better to use find
instead of filter
src/iden3comm/handlers/payment.ts
Outdated
throw new Error(`failed request. not supported '${selectedPayment.type}' payment type `); | ||
} | ||
|
||
if (selectedPayment.currency !== SupportedCurrencies.ETHWEI) { |
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.
can we rename it ETH_WEI or something like that?
src/iden3comm/handlers/payment.ts
Outdated
amount: bigint; | ||
currency: SupportedCurrencies | string; | ||
chainId: string; | ||
expirationDate?: Date; |
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.
maybe better ISO string?
src/iden3comm/handlers/payment.ts
Outdated
} | ||
|
||
/** @beta PaymentRequestMessageHandlerOptions represents payment-request handler options */ | ||
export type PaymentRequestMessageHandlerOptions = { | ||
paymentHandler: (data: PaymentRequestDataInfo) => Promise<string>; | ||
paymentHandler: ( | ||
data: Iden3PaymentRequestCryptoV1 | Iden3PaymentRailsRequestV1 | 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.
I would creare separate
src/iden3comm/handlers/payment.ts
Outdated
const paymentReq = paymentRequest.body.payments[i]; | ||
if (paymentReq.type !== PaymentRequestType.PaymentRequest) { | ||
throw new Error(`failed request. not supported '${paymentReq.type}' payment type `); | ||
const dataArray = Array.isArray(paymentReq.data) ? paymentReq.data : [paymentReq.data]; | ||
const selectedPayment = | ||
dataArray.length === 1 | ||
? dataArray[0] | ||
: dataArray.find((p) => { | ||
return p.type === PaymentRequestDataType.Iden3PaymentRequestCryptoV1 | ||
? p.id === ctx.nonce | ||
: p.nonce === ctx.nonce; | ||
}); |
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.
const paymentReq = paymentRequest.body.payments[i]; | |
if (paymentReq.type !== PaymentRequestType.PaymentRequest) { | |
throw new Error(`failed request. not supported '${paymentReq.type}' payment type `); | |
const dataArray = Array.isArray(paymentReq.data) ? paymentReq.data : [paymentReq.data]; | |
const selectedPayment = | |
dataArray.length === 1 | |
? dataArray[0] | |
: dataArray.find((p) => { | |
return p.type === PaymentRequestDataType.Iden3PaymentRequestCryptoV1 | |
? p.id === ctx.nonce | |
: p.nonce === ctx.nonce; | |
}); | |
const { data } = paymentRequest.body.payments[i]; | |
const selectedPayment = Array.isArray(data) | |
? data.find((p) => { | |
return p.type === PaymentRequestDataType.Iden3PaymentRequestCryptoV1 | |
? p.id === ctx.nonce | |
: p.nonce === ctx.nonce; | |
}) | |
: data; |
src/iden3comm/handlers/payment.ts
Outdated
dataArr.push( | ||
type === PaymentRequestDataType.Iden3PaymentRailsRequestV1 | ||
? { | ||
type, | ||
'@context': [ | ||
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`, | ||
'https://w3id.org/security/suites/eip712sig-2021/v1' | ||
], | ||
recipient, | ||
amount: amount.toString(), | ||
currency, | ||
expirationDate: new Date(expiration).toISOString(), | ||
nonce: nonce.toString(), | ||
metadata: '0x', | ||
proof | ||
} | ||
: { | ||
type, | ||
'@context': [ | ||
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`, | ||
'https://w3id.org/security/suites/eip712sig-2021/v1' | ||
], | ||
features: features || [], | ||
tokenAddress: tokenAddress || '', | ||
recipient, | ||
amount: amount.toString(), | ||
currency, | ||
expirationDate: new Date(expiration).toISOString(), | ||
nonce: nonce.toString(), | ||
metadata: '0x', | ||
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.
dataArr.push( | |
type === PaymentRequestDataType.Iden3PaymentRailsRequestV1 | |
? { | |
type, | |
'@context': [ | |
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`, | |
'https://w3id.org/security/suites/eip712sig-2021/v1' | |
], | |
recipient, | |
amount: amount.toString(), | |
currency, | |
expirationDate: new Date(expiration).toISOString(), | |
nonce: nonce.toString(), | |
metadata: '0x', | |
proof | |
} | |
: { | |
type, | |
'@context': [ | |
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`, | |
'https://w3id.org/security/suites/eip712sig-2021/v1' | |
], | |
features: features || [], | |
tokenAddress: tokenAddress || '', | |
recipient, | |
amount: amount.toString(), | |
currency, | |
expirationDate: new Date(expiration).toISOString(), | |
nonce: nonce.toString(), | |
metadata: '0x', | |
proof | |
} | |
); | |
const d: Iden3PaymentRailsRequestV1 = { | |
type: PaymentRequestDataType.Iden3PaymentRailsRequestV1, | |
'@context': [ | |
`https://schema.iden3.io/core/jsonld/payment.jsonld#${type}`, | |
'https://w3id.org/security/suites/eip712sig-2021/v1' | |
], | |
recipient, | |
amount: amount.toString(), | |
currency, | |
expirationDate: new Date(expiration).toISOString(), | |
nonce: nonce.toString(), | |
metadata: '0x', | |
proof | |
}; | |
dataArr.push( | |
type === PaymentRequestDataType.Iden3PaymentRailsRequestV1 | |
? d | |
: ({ ...d, type, tokenAddress } as Iden3PaymentRailsERC20RequestV1) | |
); |
eac7597
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.
Well done
No description provided.