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

Iden3PaymentRailsRequestV1 #275

Merged
merged 54 commits into from
Nov 19, 2024
Merged

Iden3PaymentRailsRequestV1 #275

merged 54 commits into from
Nov 19, 2024

Conversation

volodymyr-basiuk
Copy link
Collaborator

No description provided.

@volodymyr-basiuk volodymyr-basiuk changed the title [WIP] init Iden3PaymentRailsRequestV1 [WIP] Iden3PaymentRailsRequestV1 Oct 1, 2024
@volodymyr-basiuk volodymyr-basiuk marked this pull request as ready for review October 7, 2024 11:06
@volodymyr-basiuk volodymyr-basiuk changed the title [WIP] Iden3PaymentRailsRequestV1 Iden3PaymentRailsRequestV1 Oct 15, 2024
src/iden3comm/handlers/payment.ts Outdated Show resolved Hide resolved
primaryType: 'Iden3PaymentRailsRequestV1',
domain: {
...domain,
salt: ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why salt is empty?

Copy link
Collaborator Author

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)");

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

signer: Signer,
opts: {
payments: [
{
Copy link
Collaborator

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

paymentValidationHandler: (txId: string, data: PaymentRequestDataInfo) => Promise<void>;
paymentValidationHandler: (
txId: string,
data: Iden3PaymentRequestCryptoV1 | Iden3PaymentRailsRequestV1
Copy link
Collaborator

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?

const selectedPayment = paymentReq.data.find((p) => {
const proofs = Array.isArray(p.proof) ? p.proof : [p.proof];
return (
proofs.filter(
Copy link
Collaborator

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

throw new Error(`failed request. not supported '${selectedPayment.type}' payment type `);
}

if (selectedPayment.currency !== SupportedCurrencies.ETHWEI) {
Copy link
Collaborator

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?

amount: bigint;
currency: SupportedCurrencies | string;
chainId: string;
expirationDate?: Date;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better ISO string?

}

/** @beta PaymentRequestMessageHandlerOptions represents payment-request handler options */
export type PaymentRequestMessageHandlerOptions = {
paymentHandler: (data: PaymentRequestDataInfo) => Promise<string>;
paymentHandler: (
data: Iden3PaymentRequestCryptoV1 | Iden3PaymentRailsRequestV1 | Iden3PaymentRailsERC20RequestV1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would creare separate

Comment on lines 282 to 291
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;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Comment on lines 491 to 523
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
}
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
);

Kolezhniuk
Kolezhniuk previously approved these changes Nov 1, 2024
vmidyllic
vmidyllic previously approved these changes Nov 6, 2024
vmidyllic
vmidyllic previously approved these changes Nov 18, 2024
Copy link
Collaborator

@Kolezhniuk Kolezhniuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done

@volodymyr-basiuk volodymyr-basiuk merged commit fa0ac64 into main Nov 19, 2024
2 checks passed
@volodymyr-basiuk volodymyr-basiuk deleted the feat/mc-payment branch November 19, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants