Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
36fe731
Replace default export with named exports in utils package to enable …
marcohefti Dec 22, 2022
9882e21
Merge branch 'master' into econ/dw-17/utils-package-tree-shaki
MantisClone Dec 22, 2022
052cf3f
running refactored files through prehook (#1015)
marcohefti Dec 22, 2022
d886e69
Apply changes to utils package to monorepo
marcohefti Dec 25, 2022
693c05d
Apply changes to utils package to payment-processor/test/payment/any-…
marcohefti Dec 25, 2022
d324ee8
Merge branch 'master' into econ/dw-17/utils-package-tree-shaki
MantisClone Jan 3, 2023
83675c4
feat: tombchain (#1024)
leoslr Dec 22, 2022
171dbcc
feat: tombchain (#1024)
leoslr Dec 22, 2022
acf3022
running refactored files through prehook (#1015)
marcohefti Dec 22, 2022
9978434
Apply changes to utils package to monorepo
marcohefti Dec 25, 2022
3513f0e
Apply changes to utils package to payment-processor/test/payment/any-…
marcohefti Dec 25, 2022
4e222d4
Merge remote-tracking branch 'origin/econ/dw-17/utils-package-tree-sh…
marcohefti Jan 3, 2023
e734d6b
fix circular dependency by importing from the corresponding package r…
marcohefti Jan 4, 2023
d243ec5
Merge branch 'master' into econ/dw-17/utils-package-tree-shaki
marcohefti Jan 4, 2023
85a6e77
Merge branch 'master' into econ/dw-17/utils-package-tree-shaki
marcohefti Jan 9, 2023
c2d5504
Resolves #1023: Rename ambiguous functions for clarity
marcohefti Jan 10, 2023
d85a02e
Fix README, identity, and signature file updates
marcohefti Jan 14, 2023
25d66f1
Refactor crypto and ec-utils modules
marcohefti Jan 16, 2023
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
5 changes: 2 additions & 3 deletions packages/advanced-logic/src/extensions/abstract-extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';
import Utils from '@requestnetwork/utils';
import { deepCopy } from '@requestnetwork/utils';

/**
* Abstract class to create extension
Expand Down Expand Up @@ -53,8 +53,7 @@ export abstract class AbstractExtension<TCreationParameters> implements Extensio
): RequestLogicTypes.IExtensionStates {
this.validate(requestState, extensionAction);

const copiedExtensionState: RequestLogicTypes.IExtensionStates =
Utils.deepCopy(extensionsState);
const copiedExtensionState: RequestLogicTypes.IExtensionStates = deepCopy(extensionsState);

if (extensionAction.action === ExtensionTypes.PnFeeReferenceBased.ACTION.CREATE) {
if (requestState.extensions[extensionAction.id]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency';
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';
import Utils from '@requestnetwork/utils';
import { areEqualIdentities, deepCopy } from '@requestnetwork/utils';
import DeclarativePaymentNetwork from './declarative';

/**
Expand Down Expand Up @@ -194,11 +194,11 @@ export default abstract class AddressBasedPaymentNetwork<
if (!requestState.payee) {
throw Error(`The request must have a payee`);
}
if (!Utils.identity.areEqual(actionSigner, requestState.payee)) {
if (!areEqualIdentities(actionSigner, requestState.payee)) {
throw Error(`The signer must be the payee`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// update payment address
copiedExtensionState.values.paymentAddress = extensionAction.parameters.paymentAddress;
Expand Down Expand Up @@ -241,11 +241,11 @@ export default abstract class AddressBasedPaymentNetwork<
if (!requestState.payer) {
throw Error(`The request must have a payer`);
}
if (!Utils.identity.areEqual(actionSigner, requestState.payer)) {
if (!areEqualIdentities(actionSigner, requestState.payer)) {
throw Error(`The signer must be the payer`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// update refund address
copiedExtensionState.values.refundAddress = extensionAction.parameters.refundAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';
import Utils from '@requestnetwork/utils';
import { addAmount, areEqualIdentities, deepCopy, isValidAmount } from '@requestnetwork/utils';
import { AbstractExtension } from '../abstract-extension';

const CURRENT_VERSION = '0.1.0';
Expand Down Expand Up @@ -239,14 +239,14 @@ export default class DeclarativePaymentNetwork<
timestamp: number,
): ExtensionTypes.IState {
this.checkIdentities(extensionState, requestState, actionSigner, RequestLogicTypes.ROLE.PAYER);
if (!Utils.amount.isValid(extensionAction.parameters.amount)) {
if (!isValidAmount(extensionAction.parameters.amount)) {
throw Error(`The amount is not a valid amount`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// increment sentPaymentAmount
copiedExtensionState.values.sentPaymentAmount = Utils.amount.add(
copiedExtensionState.values.sentPaymentAmount = addAmount(
copiedExtensionState.values.sentPaymentAmount,
extensionAction.parameters.amount,
);
Expand Down Expand Up @@ -285,14 +285,14 @@ export default class DeclarativePaymentNetwork<
timestamp: number,
): ExtensionTypes.IState {
this.checkIdentities(extensionState, requestState, actionSigner, RequestLogicTypes.ROLE.PAYEE);
if (!Utils.amount.isValid(extensionAction.parameters.amount)) {
if (!isValidAmount(extensionAction.parameters.amount)) {
throw Error(`The amount is not a valid amount`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// increment sentRefundAmount
copiedExtensionState.values.sentRefundAmount = Utils.amount.add(
copiedExtensionState.values.sentRefundAmount = addAmount(
copiedExtensionState.values.sentRefundAmount,
extensionAction.parameters.amount,
);
Expand Down Expand Up @@ -331,14 +331,14 @@ export default class DeclarativePaymentNetwork<
timestamp: number,
): ExtensionTypes.IState {
this.checkIdentities(extensionState, requestState, actionSigner, RequestLogicTypes.ROLE.PAYEE);
if (!Utils.amount.isValid(extensionAction.parameters.amount)) {
if (!isValidAmount(extensionAction.parameters.amount)) {
throw Error(`The amount is not a valid amount`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// increment receivedPaymentAmount
copiedExtensionState.values.receivedPaymentAmount = Utils.amount.add(
copiedExtensionState.values.receivedPaymentAmount = addAmount(
copiedExtensionState.values.receivedPaymentAmount,
extensionAction.parameters.amount,
);
Expand Down Expand Up @@ -377,14 +377,14 @@ export default class DeclarativePaymentNetwork<
timestamp: number,
): ExtensionTypes.IState {
this.checkIdentities(extensionState, requestState, actionSigner, RequestLogicTypes.ROLE.PAYER);
if (!Utils.amount.isValid(extensionAction.parameters.amount)) {
if (!isValidAmount(extensionAction.parameters.amount)) {
throw Error(`The amount is not a valid amount`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// increment receivedRefundAmount
copiedExtensionState.values.receivedRefundAmount = Utils.amount.add(
copiedExtensionState.values.receivedRefundAmount = addAmount(
copiedExtensionState.values.receivedRefundAmount,
extensionAction.parameters.amount,
);
Expand Down Expand Up @@ -427,7 +427,7 @@ export default class DeclarativePaymentNetwork<
}
this.checkIdentities(extensionState, requestState, actionSigner, RequestLogicTypes.ROLE.PAYEE);

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// assign paymentInfo
copiedExtensionState.values.paymentInfo = extensionAction.parameters.paymentInfo;
Expand Down Expand Up @@ -463,9 +463,9 @@ export default class DeclarativePaymentNetwork<
timestamp: number,
): ExtensionTypes.IState {
let delegateStr: string;
if (Utils.identity.areEqual(actionSigner, requestState.payee)) {
if (areEqualIdentities(actionSigner, requestState.payee)) {
delegateStr = 'payeeDelegate';
} else if (Utils.identity.areEqual(actionSigner, requestState.payer)) {
} else if (areEqualIdentities(actionSigner, requestState.payer)) {
delegateStr = 'payerDelegate';
} else {
throw Error(`The signer must be the payee or the payer`);
Expand All @@ -475,7 +475,7 @@ export default class DeclarativePaymentNetwork<
throw Error(`The ${delegateStr} is already assigned`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// assign payeeDelegate or payerDelegate
copiedExtensionState.values[delegateStr] = extensionAction.parameters.delegate;
Expand Down Expand Up @@ -515,7 +515,7 @@ export default class DeclarativePaymentNetwork<
}
this.checkIdentities(extensionState, requestState, actionSigner, RequestLogicTypes.ROLE.PAYER);

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// assign refundInfo
copiedExtensionState.values.refundInfo = extensionAction.parameters.refundInfo;
Expand Down Expand Up @@ -567,8 +567,8 @@ export default class DeclarativePaymentNetwork<
throw Error(`The request must have a ${requestRoleStr}`);
}
if (
!Utils.identity.areEqual(actionSigner, requestRole) &&
!Utils.identity.areEqual(actionSigner, requestRoleDelegate)
!areEqualIdentities(actionSigner, requestRole) &&
!areEqualIdentities(actionSigner, requestRoleDelegate)
) {
throw Error(`The signer must be the ${requestRoleStr} or the ${requestRoleStr}Delegate`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExtensionTypes, RequestLogicTypes, TypesUtils } from '@requestnetwork/types';
import ReferenceBasedPaymentNetwork from '../reference-based';
import Utils from '@requestnetwork/utils';
import { isValidAmount } from '@requestnetwork/utils';
const CURRENT_VERSION = '0.1.0';

/**
Expand Down Expand Up @@ -92,15 +92,15 @@ export default class Erc777StreamPaymentNetwork<
if (
!extensionAction.parameters.expectedStartDate ||
(extensionAction.parameters.expectedStartDate &&
!Utils.amount.isValid(extensionAction.parameters.expectedStartDate))
!isValidAmount(extensionAction.parameters.expectedStartDate))
) {
throw Error('expectedStartDate is empty or invalid');
}

if (
!extensionAction.parameters.expectedFlowRate ||
(extensionAction.parameters.expectedFlowRate &&
!Utils.amount.isValid(extensionAction.parameters.expectedFlowRate))
!isValidAmount(extensionAction.parameters.expectedFlowRate))
) {
throw Error('expectedFlowRate is empty or invalid');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwork/types';
import ReferenceBasedPaymentNetwork from './reference-based';
import Utils from '@requestnetwork/utils';
import { areEqualIdentities, deepCopy, isValidAmount } from '@requestnetwork/utils';

/**
* Core of the reference based with fee payment networks
Expand Down Expand Up @@ -35,7 +35,7 @@ export abstract class FeeReferenceBasedPaymentNetwork<
throw Error('feeAddress is not a valid address');
}

if (creationParameters.feeAmount && !Utils.amount.isValid(creationParameters.feeAmount)) {
if (creationParameters.feeAmount && !isValidAmount(creationParameters.feeAmount)) {
throw Error('feeAmount is not a valid amount');
}

Expand Down Expand Up @@ -65,7 +65,7 @@ export abstract class FeeReferenceBasedPaymentNetwork<
throw Error('feeAddress is not a valid address');
}

if (addFeeParameters.feeAmount && !Utils.amount.isValid(addFeeParameters.feeAmount)) {
if (addFeeParameters.feeAmount && !isValidAmount(addFeeParameters.feeAmount)) {
throw Error('feeAmount is not a valid amount');
}

Expand Down Expand Up @@ -103,7 +103,7 @@ export abstract class FeeReferenceBasedPaymentNetwork<
}
if (
extensionAction.parameters.feeAmount &&
!Utils.amount.isValid(extensionAction.parameters.feeAmount)
!isValidAmount(extensionAction.parameters.feeAmount)
) {
throw Error('feeAmount is not a valid amount');
}
Expand Down Expand Up @@ -162,7 +162,7 @@ export abstract class FeeReferenceBasedPaymentNetwork<
}
if (
extensionAction.parameters.feeAmount &&
!Utils.amount.isValid(extensionAction.parameters.feeAmount)
!isValidAmount(extensionAction.parameters.feeAmount)
) {
throw Error('feeAmount is not a valid amount');
}
Expand All @@ -172,11 +172,11 @@ export abstract class FeeReferenceBasedPaymentNetwork<
if (!requestState.payee) {
throw Error(`The request must have a payee`);
}
if (!Utils.identity.areEqual(actionSigner, requestState.payee)) {
if (!areEqualIdentities(actionSigner, requestState.payee)) {
throw Error(`The signer must be the payee`);
}

const copiedExtensionState: ExtensionTypes.IState = Utils.deepCopy(extensionState);
const copiedExtensionState: ExtensionTypes.IState = deepCopy(extensionState);

// update fee address and amount
copiedExtensionState.values.feeAddress = extensionAction.parameters.feeAddress;
Expand Down
12 changes: 5 additions & 7 deletions packages/advanced-logic/test/advanced-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as DataBTCCreate from './utils/payment-network/bitcoin/generator-data-c
import * as DataDeclarativeCreate from './utils/payment-network/any/generator-data-create';
import * as DataTestnetBTCCreate from './utils/payment-network/bitcoin/testnet-generator-data-create';

import Utils from '@requestnetwork/utils';
import { deepCopy } from '@requestnetwork/utils';

import { AdvancedLogic } from '../src/index';

Expand All @@ -19,7 +19,7 @@ describe('advanced-logic.ts', () => {
});
describe('applyActionToExtensions', () => {
it('can applyActionToExtensions', () => {
const requestCreatedNoExtensionBefore = Utils.deepCopy(TestData.requestCreatedNoExtension);
const requestCreatedNoExtensionBefore = deepCopy(TestData.requestCreatedNoExtension);
const previousState = {};

const newExtensionState = advancedLogic.applyActionToExtensions(
Expand All @@ -39,9 +39,7 @@ describe('advanced-logic.ts', () => {
});

it('can applyActionToExtensions with pn bitcoin address based', () => {
const requestCreatedNoExtensionBefore = Utils.deepCopy(
DataBTCCreate.requestStateNoExtensions,
);
const requestCreatedNoExtensionBefore = deepCopy(DataBTCCreate.requestStateNoExtensions);

const newExtensionState = advancedLogic.applyActionToExtensions(
requestCreatedNoExtensionBefore.extensions,
Expand All @@ -58,7 +56,7 @@ describe('advanced-logic.ts', () => {
});

it('can applyActionToExtensions with pn testnet bitcoin address based', () => {
const requestCreatedNoExtensionBefore = Utils.deepCopy(
const requestCreatedNoExtensionBefore = deepCopy(
DataTestnetBTCCreate.requestStateNoExtensions,
);

Expand All @@ -79,7 +77,7 @@ describe('advanced-logic.ts', () => {
});

it('can applyActionToExtensions with declarative payment network', () => {
const requestCreatedNoExtensionBefore = Utils.deepCopy(
const requestCreatedNoExtensionBefore = deepCopy(
DataDeclarativeCreate.requestStateNoExtensions,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/advanced-logic/test/extensions/content-data.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExtensionTypes } from '@requestnetwork/types';
import Utils from '@requestnetwork/utils';
import { deepCopy } from '@requestnetwork/utils';

import ContentData from '../../src/extensions/content-data';

Expand All @@ -11,7 +11,7 @@ const contentData = new ContentData();
describe('content-data', () => {
describe('applyActionToExtension', () => {
it('can applyActionToExtensions', () => {
const requestCreatedNoExtensionBefore = Utils.deepCopy(TestData.requestCreatedNoExtension);
const requestCreatedNoExtensionBefore = deepCopy(TestData.requestCreatedNoExtension);
const previousState = {};
const newExtensionState = contentData.applyActionToExtension(
previousState,
Expand Down
Loading