diff --git a/src/characters/alice.ts b/src/characters/alice.ts index e1361989a..fa640f668 100644 --- a/src/characters/alice.ts +++ b/src/characters/alice.ts @@ -13,13 +13,13 @@ import { EnactedPolicy, PreEnactedPolicy, } from '../policies/policy'; +import { PorterClient } from '../porter'; import { ChecksumAddress } from '../types'; import { RemoteBob } from './bob'; -import { Porter } from './porter'; export class Alice { - private readonly porter: Porter; + private readonly porter: PorterClient; private readonly keyring: Keyring; private constructor( @@ -27,7 +27,7 @@ export class Alice { secretKey: SecretKey, public readonly web3Provider: ethers.providers.Web3Provider ) { - this.porter = new Porter(porterUri); + this.porter = new PorterClient(porterUri); this.keyring = new Keyring(secretKey); } diff --git a/src/characters/bob.ts b/src/characters/bob.ts index 2a5533c85..c08a351c6 100644 --- a/src/characters/bob.ts +++ b/src/characters/bob.ts @@ -9,10 +9,9 @@ import { import { Keyring } from '../keyring'; import { PolicyMessageKit } from '../kits/message'; import { RetrievalResult } from '../kits/retrieval'; +import { PorterClient } from '../porter'; import { zip } from '../utils'; -import { Porter } from './porter'; - export class RemoteBob { private constructor( public readonly decryptingKey: PublicKey, @@ -36,11 +35,11 @@ export class RemoteBob { } export class Bob { - private readonly porter: Porter; + private readonly porter: PorterClient; private readonly keyring: Keyring; constructor(porterUri: string, secretKey: SecretKey) { - this.porter = new Porter(porterUri); + this.porter = new PorterClient(porterUri); this.keyring = new Keyring(secretKey); } diff --git a/src/characters/cbd-recipient.ts b/src/characters/cbd-recipient.ts index 939b25ccd..87bf20c05 100644 --- a/src/characters/cbd-recipient.ts +++ b/src/characters/cbd-recipient.ts @@ -20,10 +20,9 @@ import { getCombineDecryptionSharesFunction, getVariantClass, } from '../dkg'; +import { PorterClient } from '../porter'; import { fromJSON, toJSON } from '../utils'; -import { Porter } from './porter'; - export type ThresholdDecrypterJSON = { porterUri: string; ritualId: number; @@ -34,14 +33,14 @@ export class ThresholdDecrypter { // private readonly verifyingKey: Keyring; private constructor( - private readonly porter: Porter, + private readonly porter: PorterClient, private readonly ritualId: number, private readonly threshold: number ) {} public static create(porterUri: string, dkgRitual: DkgRitual) { return new ThresholdDecrypter( - new Porter(porterUri), + new PorterClient(porterUri), dkgRitual.id, dkgRitual.threshold ); @@ -210,7 +209,11 @@ export class ThresholdDecrypter { ritualId, threshold, }: ThresholdDecrypterJSON) { - return new ThresholdDecrypter(new Porter(porterUri), ritualId, threshold); + return new ThresholdDecrypter( + new PorterClient(porterUri), + ritualId, + threshold + ); } public static fromJSON(json: string) { diff --git a/src/characters/pre-recipient.ts b/src/characters/pre-recipient.ts index c30f9265f..f321c34cb 100644 --- a/src/characters/pre-recipient.ts +++ b/src/characters/pre-recipient.ts @@ -12,10 +12,9 @@ import { Condition, ConditionContext } from '../conditions'; import { Keyring } from '../keyring'; import { PolicyMessageKit } from '../kits/message'; import { RetrievalResult } from '../kits/retrieval'; +import { PorterClient } from '../porter'; import { base64ToU8Receiver, bytesEquals, toJSON, zip } from '../utils'; -import { Porter } from './porter'; - export type PreDecrypterJSON = { porterUri: string; policyEncryptingKeyBytes: Uint8Array; @@ -28,7 +27,7 @@ export class PreDecrypter { // private readonly verifyingKey: Keyring; constructor( - private readonly porter: Porter, + private readonly porter: PorterClient, private readonly keyring: Keyring, private readonly policyEncryptingKey: PublicKey, private readonly publisherVerifyingKey: PublicKey, @@ -43,7 +42,7 @@ export class PreDecrypter { encryptedTreasureMap: EncryptedTreasureMap ): PreDecrypter { return new PreDecrypter( - new Porter(porterUri), + new PorterClient(porterUri), new Keyring(secretKey), policyEncryptingKey, publisherVerifyingKey, @@ -172,7 +171,7 @@ export class PreDecrypter { bobSecretKeyBytes, }: PreDecrypterJSON) { return new PreDecrypter( - new Porter(porterUri), + new PorterClient(porterUri), new Keyring(SecretKey.fromBEBytes(bobSecretKeyBytes)), PublicKey.fromCompressedBytes(policyEncryptingKeyBytes), PublicKey.fromCompressedBytes(publisherVerifyingKeyBytes), diff --git a/src/index.ts b/src/index.ts index 25c662a08..071b3fb38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ export { Alice } from './characters/alice'; export { Bob, RemoteBob } from './characters/bob'; export { Enrico } from './characters/enrico'; export { PreDecrypter } from './characters/pre-recipient'; -export { Porter } from './characters/porter'; +export { PorterClient } from './porter'; // Policies export type { diff --git a/src/policies/policy.ts b/src/policies/policy.ts index 59be31dd0..ffe284939 100644 --- a/src/policies/policy.ts +++ b/src/policies/policy.ts @@ -10,7 +10,7 @@ import { import { PreSubscriptionManagerAgent } from '../agents/subscription-manager'; import { Alice } from '../characters/alice'; import { RemoteBob } from '../characters/bob'; -import { Ursula } from '../characters/porter'; +import { Ursula } from '../porter'; import { toBytes, toEpoch, zip } from '../utils'; import { toCanonicalAddress } from '../web3'; diff --git a/src/characters/porter.ts b/src/porter.ts similarity index 98% rename from src/characters/porter.ts rename to src/porter.ts index 1bcc6aa41..0d306d81b 100644 --- a/src/characters/porter.ts +++ b/src/porter.ts @@ -9,9 +9,9 @@ import { import axios, { AxiosResponse } from 'axios'; import qs from 'qs'; -import { ConditionContext } from '../conditions'; -import { Base64EncodedBytes, ChecksumAddress, HexEncodedBytes } from '../types'; -import { fromBase64, fromHexString, toBase64, toHexString } from '../utils'; +import { ConditionContext } from './conditions'; +import { Base64EncodedBytes, ChecksumAddress, HexEncodedBytes } from './types'; +import { fromBase64, fromHexString, toBase64, toHexString } from './utils'; // /get_ursulas @@ -97,7 +97,7 @@ export type CbdDecryptResult = { errors: Record; }; -export class Porter { +export class PorterClient { readonly porterUrl: URL; constructor(porterUri: string) { diff --git a/src/sdk/cohort.ts b/src/sdk/cohort.ts index 697f7cb8a..d377a6a4b 100644 --- a/src/sdk/cohort.ts +++ b/src/sdk/cohort.ts @@ -1,4 +1,4 @@ -import { Porter } from '../characters/porter'; +import { PorterClient } from '../porter'; import { ChecksumAddress } from '../types'; import { objectEquals } from '../utils'; @@ -19,7 +19,7 @@ export class Cohort { include: string[] = [], exclude: string[] = [] ) { - const porter = new Porter(porterUri); + const porter = new PorterClient(porterUri); const ursulas = await porter.getUrsulas(numUrsulas, exclude, include); const ursulaAddresses = ursulas.map((ursula) => ursula.checksumAddress); return new Cohort(ursulaAddresses, porterUri); diff --git a/test/acceptance/alice-grants.test.ts b/test/acceptance/alice-grants.test.ts index a5fce2365..a887004a0 100644 --- a/test/acceptance/alice-grants.test.ts +++ b/test/acceptance/alice-grants.test.ts @@ -6,7 +6,7 @@ import { } from '@nucypher/nucypher-core'; import { EnactedPolicy, Enrico, MessageKit } from '../../src'; -import { Ursula } from '../../src/characters/porter'; +import { Ursula } from '../../src/porter'; import { ChecksumAddress } from '../../src/types'; import { toBytes } from '../../src/utils'; import { diff --git a/test/docs/cbd.test.ts b/test/docs/cbd.test.ts index 217a45ca0..cffde9aac 100644 --- a/test/docs/cbd.test.ts +++ b/test/docs/cbd.test.ts @@ -2,7 +2,7 @@ import { MessageKit, VerifiedKeyFrag } from '@nucypher/nucypher-core'; import { providers } from 'ethers'; import { Cohort, conditions, PreStrategy, SecretKey } from '../../src'; -import { Ursula } from '../../src/characters/porter'; +import { Ursula } from '../../src/porter'; import { toBytes } from '../../src/utils'; import { fakeUrsulas, diff --git a/test/unit/pre-strategy.test.ts b/test/unit/pre-strategy.test.ts index bdd8ace8f..d68e586b0 100644 --- a/test/unit/pre-strategy.test.ts +++ b/test/unit/pre-strategy.test.ts @@ -6,7 +6,7 @@ import { PreDecrypter, PreStrategy, } from '../../src'; -import { Ursula } from '../../src/characters/porter'; +import { Ursula } from '../../src/porter'; import { toBytes } from '../../src/utils'; import { fakeUrsulas, diff --git a/test/utils.ts b/test/utils.ts index e6e92f427..9792e6b6a 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -40,15 +40,15 @@ import { keccak256 } from 'ethers/lib/utils'; import { Alice, Bob, Cohort, RemoteBob } from '../src'; import { DkgCoordinatorAgent, DkgParticipant } from '../src/agents/coordinator'; import { ThresholdDecrypter } from '../src/characters/cbd-recipient'; +import { DkgClient, DkgRitual, FerveoVariant } from '../src/dkg'; +import { BlockchainPolicy, PreEnactedPolicy } from '../src/policies/policy'; import { CbdDecryptResult, GetUrsulasResult, - Porter, + PorterClient, RetrieveCFragsResult, Ursula, -} from '../src/characters/porter'; -import { DkgClient, DkgRitual, FerveoVariant } from '../src/dkg'; -import { BlockchainPolicy, PreEnactedPolicy } from '../src/policies/policy'; +} from '../src/porter'; import { ChecksumAddress } from '../src/types'; import { toBytes, toHexString, zip } from '../src/utils'; @@ -161,7 +161,7 @@ export const mockRetrieveCFragsRequest = ( ) => { const results = fakeCFragResponse(ursulas, verifiedKFrags, capsule); return jest - .spyOn(Porter.prototype, 'retrieveCFrags') + .spyOn(PorterClient.prototype, 'retrieveCFrags') .mockImplementation(() => { return Promise.resolve(results); }); @@ -481,9 +481,11 @@ export const mockCbdDecrypt = ( encryptedResponses, errors, }; - return jest.spyOn(Porter.prototype, 'cbdDecrypt').mockImplementation(() => { - return Promise.resolve(result); - }); + return jest + .spyOn(PorterClient.prototype, 'cbdDecrypt') + .mockImplementation(() => { + return Promise.resolve(result); + }); }; export const mockRandomSessionStaticSecret = (secret: SessionStaticSecret) => {