diff --git a/packages/shared/src/porter.ts b/packages/shared/src/porter.ts index 4dc054924..c89afe043 100644 --- a/packages/shared/src/porter.ts +++ b/packages/shared/src/porter.ts @@ -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 @@ -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( diff --git a/packages/shared/test/porter.test.ts b/packages/shared/test/porter.test.ts index 113f3012a..a5c92d437 100644 --- a/packages/shared/test/porter.test.ts +++ b/packages/shared/test/porter.test.ts @@ -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 () => { diff --git a/packages/taco/src/taco.ts b/packages/taco/src/taco.ts index 93d29b764..ce6572bf1 100644 --- a/packages/taco/src/taco.ts +++ b/packages/taco/src/taco.ts @@ -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} [customParameters] - Optional custom parameters that may be required * depending on the condition used @@ -145,10 +145,10 @@ export const decrypt = async ( domain: Domain, messageKit: ThresholdMessageKit, authProvider?: EIP4361AuthProvider, - porterUri?: string | string[], + porterUris: string[] = [], customParameters?: Record, ): Promise => { - const porterUris: string[] = getPorterUris(domain, porterUri); + const porterUrisFull: string[] = getPorterUris(domain, porterUris); const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey( provider, @@ -164,7 +164,7 @@ export const decrypt = async ( return retrieveAndDecrypt( provider, domain, - porterUris, + porterUrisFull, messageKit, ritualId, ritual.sharesNum, diff --git a/packages/taco/test/taco.test.ts b/packages/taco/test/taco.test.ts index f965fa80c..8fd2545a0 100644 --- a/packages/taco/test/taco.test.ts +++ b/packages/taco/test/taco.test.ts @@ -93,7 +93,7 @@ describe('taco', () => { domains.DEVNET, messageKit, authProvider, - fakePorterUri, + [fakePorterUri], ); expect(decryptedMessage).toEqual(toBytes(message)); expect(getParticipantsSpy).toHaveBeenCalled();