Skip to content

Commit

Permalink
rm opts from createPaymentRails
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Oct 30, 2024
1 parent 4c28e58 commit d432b92
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 142 deletions.
72 changes: 34 additions & 38 deletions src/iden3comm/handlers/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,24 @@ export async function createPaymentRailsV1(
receiver: DID,
agent: string,
signer: Signer,
opts: {
payments: [
{
credentials: {
type: string;
context: string;
}[];
description?: string;
chains: PaymentRailsChainInfo[];
}
];
}
payments: [
{
credentials: {
type: string;
context: string;
}[];
description?: string;
chains: PaymentRailsChainInfo[];
}
]
): Promise<PaymentRequestMessage> {
const payments: PaymentRequestInfo[] = [];
for (let i = 0; i < opts.payments.length; i++) {
const { credentials, description } = opts.payments[i];
const paymentRequestInfo: PaymentRequestInfo[] = [];
for (let i = 0; i < payments.length; i++) {
const { credentials, description } = payments[i];
const dataArr: Iden3PaymentRailsRequestV1[] = [];
for (let j = 0; j < opts.payments[i].chains.length; j++) {
for (let j = 0; j < payments[i].chains.length; j++) {
const { nonce, amount, currency, chainId, recipient, verifyingContract, expirationDate } =
opts.payments[i].chains[j];
payments[i].chains[j];

if (recipient !== (await signer.getAddress())) {
throw new Error('recipient is not the signer');
Expand Down Expand Up @@ -167,13 +165,13 @@ export async function createPaymentRailsV1(
]
});
}
payments.push({
paymentRequestInfo.push({
data: dataArr,
credentials,
description
});
}
return createPaymentRequest(sender, receiver, agent, payments);
return createPaymentRequest(sender, receiver, agent, paymentRequestInfo);
}

/**
Expand All @@ -191,24 +189,22 @@ export async function createERC20PaymentRailsV1(
receiver: DID,
agent: string,
signer: Signer,
opts: {
payments: [
{
credentials: {
type: string;
context: string;
}[];
description?: string;
chains: ERC20PaymentRailsChainInfo[];
}
];
}
payments: [
{
credentials: {
type: string;
context: string;
}[];
description?: string;
chains: ERC20PaymentRailsChainInfo[];
}
]
): Promise<PaymentRequestMessage> {
const payments: PaymentRequestInfo[] = [];
for (let i = 0; i < opts.payments.length; i++) {
const { credentials, description } = opts.payments[i];
const paymentRequestInfo: PaymentRequestInfo[] = [];
for (let i = 0; i < payments.length; i++) {
const { credentials, description } = payments[i];
const dataArr: Iden3PaymentRailsERC20RequestV1[] = [];
for (let j = 0; j < opts.payments[i].chains.length; j++) {
for (let j = 0; j < payments[i].chains.length; j++) {
const {
tokenAddress,
features,
Expand All @@ -219,7 +215,7 @@ export async function createERC20PaymentRailsV1(
recipient,
verifyingContract,
expirationDate
} = opts.payments[i].chains[j];
} = payments[i].chains[j];

if (recipient !== (await signer.getAddress())) {
throw new Error('recipient is not the signer');
Expand Down Expand Up @@ -274,13 +270,13 @@ export async function createERC20PaymentRailsV1(
]
});
}
payments.push({
paymentRequestInfo.push({
data: dataArr,
credentials,
description
});
}
return createPaymentRequest(sender, receiver, agent, payments);
return createPaymentRequest(sender, receiver, agent, paymentRequestInfo);
}

/**
Expand Down
202 changes: 98 additions & 104 deletions tests/handlers/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,39 +767,37 @@ describe('payment-request handler', () => {
it.skip('payment-request handler (Iden3PaymentRailsRequestV1, integration test)', async () => {
const rpcProvider = new JsonRpcProvider(RPC_URL);
const ethSigner = new ethers.Wallet(WALLET_KEY, rpcProvider);
const paymentRequest = await createPaymentRailsV1(issuerDID, userDID, agent, ethSigner, {
payments: [
{
credentials: [
{
type: 'AML',
context: 'http://test.com'
}
],
description: 'Iden3PaymentRailsRequestV1 payment-request integration test',
chains: [
{
nonce: 1n,
amount: 100n,
currency: SupportedCurrencies.ETH_WEI,
chainId: '80002',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
},
{
nonce: 2n,
amount: 10000n,
currency: SupportedCurrencies.ETH_WEI,
chainId: '1101',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
}
]
}
]
});
const paymentRequest = await createPaymentRailsV1(issuerDID, userDID, agent, ethSigner, [
{
credentials: [
{
type: 'AML',
context: 'http://test.com'
}
],
description: 'Iden3PaymentRailsRequestV1 payment-request integration test',
chains: [
{
nonce: 1n,
amount: 100n,
currency: SupportedCurrencies.ETH_WEI,
chainId: '80002',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
},
{
nonce: 2n,
amount: 10000n,
currency: SupportedCurrencies.ETH_WEI,
chainId: '1101',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
}
]
}
]);

const msgBytesRequest = await packageManager.pack(
MediaType.PlainMessage,
Expand All @@ -823,41 +821,39 @@ describe('payment-request handler', () => {
it.skip('payment-request handler (Iden3PaymentRailsERC20RequestV1, integration test)', async () => {
const rpcProvider = new JsonRpcProvider(RPC_URL);
const ethSigner = new ethers.Wallet(WALLET_KEY, rpcProvider);
const paymentRequest = await createERC20PaymentRailsV1(issuerDID, userDID, agent, ethSigner, {
payments: [
{
credentials: [
{
type: 'AML',
context: 'http://test.com'
}
],
description: 'Iden3PaymentRailsERC20RequestV1 payment-request integration test',
chains: [
{
tokenAddress: '0x5fb4a5c46d7f2067AA235fbEA350A0261eAF71E3',
nonce: 22n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '80002',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
},
{
tokenAddress: '0x5fb4a5c46d7f2067AA235fbEA350A0261eAF71E3',
nonce: 23n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '1101',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
}
]
}
]
});
const paymentRequest = await createERC20PaymentRailsV1(issuerDID, userDID, agent, ethSigner, [
{
credentials: [
{
type: 'AML',
context: 'http://test.com'
}
],
description: 'Iden3PaymentRailsERC20RequestV1 payment-request integration test',
chains: [
{
tokenAddress: '0x5fb4a5c46d7f2067AA235fbEA350A0261eAF71E3',
nonce: 22n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '80002',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
},
{
tokenAddress: '0x5fb4a5c46d7f2067AA235fbEA350A0261eAF71E3',
nonce: 23n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '1101',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
}
]
}
]);

const msgBytesRequest = await packageManager.pack(
MediaType.PlainMessage,
Expand Down Expand Up @@ -890,42 +886,40 @@ describe('payment-request handler', () => {
it.skip('payment-request handler (Iden3PaymentRailsERC20RequestV1 Permit, integration test)', async () => {
const rpcProvider = new JsonRpcProvider(RPC_URL);
const ethSigner = new ethers.Wallet(WALLET_KEY, rpcProvider);
const paymentRequest = await createERC20PaymentRailsV1(issuerDID, userDID, agent, ethSigner, {
payments: [
{
credentials: [
{
type: 'AML',
context: 'http://test.com'
}
],
description: 'Iden3PaymentRailsERC20RequestV1 payment-request integration test',
chains: [
{
tokenAddress: '0x2FE40749812FAC39a0F380649eF59E01bccf3a1A',
features: [PaymentFeatures.EIP_2612],
nonce: 33n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '80002',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x6f742EBA99C3043663f995a7f566e9F012C07925',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
},
{
tokenAddress: '0x5fb4a5c46d7f2067AA235fbEA350A0261eAF71E3',
nonce: 34n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '1101',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
}
]
}
]
});
const paymentRequest = await createERC20PaymentRailsV1(issuerDID, userDID, agent, ethSigner, [
{
credentials: [
{
type: 'AML',
context: 'http://test.com'
}
],
description: 'Iden3PaymentRailsERC20RequestV1 payment-request integration test',
chains: [
{
tokenAddress: '0x2FE40749812FAC39a0F380649eF59E01bccf3a1A',
features: [PaymentFeatures.EIP_2612],
nonce: 33n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '80002',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x6f742EBA99C3043663f995a7f566e9F012C07925',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
},
{
tokenAddress: '0x5fb4a5c46d7f2067AA235fbEA350A0261eAF71E3',
nonce: 34n,
amount: 30n,
currency: SupportedCurrencies.ERC20Token,
chainId: '1101',
recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a',
verifyingContract: '0x40F63e736146ACC1D30844093d41cbFcF515559a',
expirationDate: new Date(new Date().setHours(new Date().getHours() + 1))
}
]
}
]);

const msgBytesRequest = await packageManager.pack(
MediaType.PlainMessage,
Expand Down

0 comments on commit d432b92

Please sign in to comment.