From 7293c3ff7492205b737570ae9dcb5b723fa60db0 Mon Sep 17 00:00:00 2001 From: Dino Rodriguez Date: Mon, 3 Aug 2020 18:51:14 -0400 Subject: [PATCH] refactor: drop cycle & types in protocol --- src/hooks/memo.ts | 2 +- src/services/basePayId.ts | 2 +- src/types/database.ts | 2 +- src/types/{publicAPI.ts => protocol.ts} | 28 +++++++++++++++++++------ src/types/verifiedAddress.ts | 24 --------------------- test/unit/formatPaymentInfo.test.ts | 2 +- test/unit/getAddressDetailsType.test.ts | 2 +- 7 files changed, 27 insertions(+), 35 deletions(-) rename src/types/{publicAPI.ts => protocol.ts} (71%) delete mode 100644 src/types/verifiedAddress.ts diff --git a/src/hooks/memo.ts b/src/hooks/memo.ts index cc31e545..9c5f4be8 100644 --- a/src/hooks/memo.ts +++ b/src/hooks/memo.ts @@ -1,4 +1,4 @@ -import { PaymentInformation } from '../types/publicAPI' +import { PaymentInformation } from '../types/protocol' /** * This function is expected to be overwritten by companies deploying diff --git a/src/services/basePayId.ts b/src/services/basePayId.ts index 81e288e5..6211759b 100644 --- a/src/services/basePayId.ts +++ b/src/services/basePayId.ts @@ -1,5 +1,5 @@ import { AddressInformation } from '../types/database' -import { AddressDetailsType, PaymentInformation } from '../types/publicAPI' +import { AddressDetailsType, PaymentInformation } from '../types/protocol' import { ParsedAcceptHeader } from './headers' diff --git a/src/types/database.ts b/src/types/database.ts index e0a4aa41..090a4b51 100644 --- a/src/types/database.ts +++ b/src/types/database.ts @@ -1,4 +1,4 @@ -import { CryptoAddressDetails, FiatAddressDetails } from './publicAPI' +import { CryptoAddressDetails, FiatAddressDetails } from './protocol' /** * Model of the Account table schema for the database. diff --git a/src/types/publicAPI.ts b/src/types/protocol.ts similarity index 71% rename from src/types/publicAPI.ts rename to src/types/protocol.ts index 914a163f..a2aca0fe 100644 --- a/src/types/publicAPI.ts +++ b/src/types/protocol.ts @@ -1,8 +1,3 @@ -/* eslint-disable import/no-cycle -- -Cycle between this file and types/verifiedAddress.ts. Should we combine these into one? -*/ -import { VerifiedAddress } from './verifiedAddress' - /** * Type of payment address in PaymentInformation. */ @@ -41,9 +36,30 @@ export interface PaymentInformation { /** * Address information included inside of a PaymentInformation object. */ -export interface Address { +interface Address { readonly paymentNetwork: string readonly environment?: string readonly addressDetailsType: AddressDetailsType readonly addressDetails: CryptoAddressDetails | FiatAddressDetails } + +/** + * Object containing address information alongside signatures. + */ +interface VerifiedAddress { + readonly payload: VerifiedAddressPayload + readonly signatures: readonly VerifiedAddressSignature[] +} + +interface VerifiedAddressPayload { + payId: string + payIdAddress: Address +} + +/** + * JWS object for verification. + */ +interface VerifiedAddressSignature { + protected: string + signature: string +} diff --git a/src/types/verifiedAddress.ts b/src/types/verifiedAddress.ts deleted file mode 100644 index 454f5765..00000000 --- a/src/types/verifiedAddress.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* eslint-disable import/no-cycle -- -Cycle between this file and types/publicApi.ts. Should we combine these into one? */ -import { Address } from './publicAPI' - -/** - * Object containing address information alongside signatures. - */ -export interface VerifiedAddress { - readonly payload: VerifiedAddressPayload - readonly signatures: readonly VerifiedAddressSignature[] -} - -interface VerifiedAddressPayload { - payId: string - payIdAddress: Address -} - -/** - * JWS object for verification. - */ -interface VerifiedAddressSignature { - protected: string - signature: string -} diff --git a/test/unit/formatPaymentInfo.test.ts b/test/unit/formatPaymentInfo.test.ts index dfa79381..653a4843 100644 --- a/test/unit/formatPaymentInfo.test.ts +++ b/test/unit/formatPaymentInfo.test.ts @@ -1,7 +1,7 @@ import { assert } from 'chai' import { formatPaymentInfo } from '../../src/services/basePayId' -import { AddressDetailsType } from '../../src/types/publicAPI' +import { AddressDetailsType } from '../../src/types/protocol' describe('Base PayID - formatPaymentInfo()', function (): void { it('Returns CryptoAddressDetails & FiatAddressDetails for addressDetailsTypes when formatting array with multiple AddressInformation', function () { diff --git a/test/unit/getAddressDetailsType.test.ts b/test/unit/getAddressDetailsType.test.ts index 5529c6ae..ea7f6f0f 100644 --- a/test/unit/getAddressDetailsType.test.ts +++ b/test/unit/getAddressDetailsType.test.ts @@ -1,7 +1,7 @@ import { assert } from 'chai' import { getAddressDetailsType } from '../../src/services/basePayId' -import { AddressDetailsType } from '../../src/types/publicAPI' +import { AddressDetailsType } from '../../src/types/protocol' describe('Base PayID - getAddressDetailsType()', function (): void { it('Returns FiatAddressDetails for addressDetailsType when formatting ACH AddressInformation', function () {