Skip to content

Commit

Permalink
apply pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Jul 25, 2024
1 parent 597444a commit f0027ab
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
17 changes: 5 additions & 12 deletions packages/shared/src/porter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,14 @@ export const getPorterUri = (domain: Domain): string => {
return getPorterUris(domain)[0];
};

export const getPorterUris = (domain: Domain, porterUri?: string | string[]): string[] => {
const porterUris: string[] = [];
if (porterUri) {
if (porterUri instanceof Array) {
porterUris.push(...porterUri);
} else {
porterUris.push(porterUri);
}
}
export const getPorterUris = (domain: Domain, porterUris: string[] = []): string[] => {
const fullList = [...porterUris];
const uri = defaultPorterUri[domain];
if (!uri) {
throw new Error(`No default Porter URI found for domain: ${domain}`);
}
porterUris.push(uri);
return porterUris;
fullList.push(uri);
return fullList;
};

// /get_ursulas
Expand Down Expand Up @@ -165,7 +158,7 @@ export class PorterClient {
if (lastError !== undefined) {
throw lastError;
}
throw new Error("Porter returns bad response");
throw new Error('Porter returns bad response: ${resp.status} - ${resp.data}');
}

public async getUrsulas(
Expand Down
13 changes: 5 additions & 8 deletions packages/shared/test/porter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ describe('PorterClient', () => {
};

expect(getUrsulasSpy).toBeCalledTimes(fakePorterUris.length);
expect(getUrsulasSpy).toHaveBeenNthCalledWith(1, expect.objectContaining(
{ ...params, baseURL: fakePorterUris[0] })
);
expect(getUrsulasSpy).toHaveBeenNthCalledWith(2, expect.objectContaining(
{ ...params, baseURL: fakePorterUris[1] })
);
expect(getUrsulasSpy).toHaveBeenNthCalledWith(3, expect.objectContaining(
{ ...params, baseURL: fakePorterUris[2] }));
fakePorterUris.forEach((value, index) => {
expect(getUrsulasSpy).toHaveBeenNthCalledWith(index + 1, expect.objectContaining(
{ ...params, baseURL: value })
);
});
});

it('returns error in case all porters fail', async () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/taco/src/taco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const encryptWithPublicKey = async (
* Must match the `ritualId`.
* @param {ThresholdMessageKit} messageKit - The kit containing the message to be decrypted
* @param authProvider - The authentication provider that will be used to provide the authorization
* @param {string} [porterUri] - The URI for the Porter service. If not provided, a value will be obtained
* @param {string} [porterUri] - The URI(s) for the Porter service. If not provided, a value will be obtained
* from the Domain
* @param {Record<string, CustomContextParam>} [customParameters] - Optional custom parameters that may be required
* depending on the condition used
Expand All @@ -145,10 +145,10 @@ export const decrypt = async (
domain: Domain,
messageKit: ThresholdMessageKit,
authProvider?: EIP4361AuthProvider,
porterUri?: string | string[],
porterUris: string[] = [],
customParameters?: Record<string, CustomContextParam>,
): Promise<Uint8Array> => {
const porterUris: string[] = getPorterUris(domain, porterUri);
const porterUrisFull: string[] = getPorterUris(domain, porterUris);

const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey(
provider,
Expand All @@ -164,7 +164,7 @@ export const decrypt = async (
return retrieveAndDecrypt(
provider,
domain,
porterUris,
porterUrisFull,
messageKit,
ritualId,
ritual.sharesNum,
Expand Down
2 changes: 1 addition & 1 deletion packages/taco/test/taco.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('taco', () => {
domains.DEVNET,
messageKit,
authProvider,
fakePorterUri,
[fakePorterUri],
);
expect(decryptedMessage).toEqual(toBytes(message));
expect(getParticipantsSpy).toHaveBeenCalled();
Expand Down

0 comments on commit f0027ab

Please sign in to comment.