Skip to content

Commit

Permalink
feat! porter is not a character; renamed to porter client
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jun 29, 2023
1 parent d06b234 commit a72e752
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/characters/alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ 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(
porterUri: string,
secretKey: SecretKey,
public readonly web3Provider: ethers.providers.Web3Provider
) {
this.porter = new Porter(porterUri);
this.porter = new PorterClient(porterUri);
this.keyring = new Keyring(secretKey);
}

Expand Down
7 changes: 3 additions & 4 deletions src/characters/bob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down
13 changes: 8 additions & 5 deletions src/characters/cbd-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
);
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions src/characters/pre-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -43,7 +42,7 @@ export class PreDecrypter {
encryptedTreasureMap: EncryptedTreasureMap
): PreDecrypter {
return new PreDecrypter(
new Porter(porterUri),
new PorterClient(porterUri),
new Keyring(secretKey),
policyEncryptingKey,
publisherVerifyingKey,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/policies/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 4 additions & 4 deletions src/characters/porter.ts → src/porter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -97,7 +97,7 @@ export type CbdDecryptResult = {
errors: Record<string, string>;
};

export class Porter {
export class PorterClient {
readonly porterUrl: URL;

constructor(porterUri: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/cohort.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Porter } from '../characters/porter';
import { PorterClient } from '../porter';
import { ChecksumAddress } from '../types';
import { objectEquals } from '../utils';

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/alice-grants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/docs/cbd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/pre-strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 10 additions & 8 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit a72e752

Please sign in to comment.