Skip to content

Commit d48bc56

Browse files
committed
removed nested try blocks
1 parent 88d2f88 commit d48bc56

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

sdk/src/network-client.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,39 +1599,48 @@ class AleoNetworkClient {
15991599
*
16001600
* @param {ProvingRequest | string} provingRequest - The `ProvingRequest` (generated by the ProgramManager) to submit.
16011601
* @param {string} url - (Optional) The url of the proving service.
1602+
* @param {string} apiKey - (Optional) API key for authentication.
1603+
* @param {string} delegatedProvingJWT - (Optional, deprecated) JWT token for authentication. Use apiKey instead.
16021604
* @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`.
16031605
*/
1604-
async submitProvingRequest(provingRequest: ProvingRequest | string, url?: string, apiKey?: string, delegatedProvingJWT?: string): Promise<ProvingResponse> {
1605-
const prover_uri = url ? url : this.host;
1606-
const provingRequestString =
1607-
provingRequest instanceof ProvingRequest
1608-
? provingRequest.toString()
1609-
: provingRequest;
1606+
async submitProvingRequest(
1607+
provingRequest: ProvingRequest | string,
1608+
url?: string,
1609+
apiKey?: string,
1610+
delegatedProvingJWT?: string
1611+
): Promise<ProvingResponse> {
1612+
const proverUri = url ?? this.host;
1613+
const provingRequestString = provingRequest instanceof ProvingRequest
1614+
? provingRequest.toString()
1615+
: provingRequest;
1616+
1617+
// Build headers with proper auth fallback
1618+
const headers: Record<string, string> = {
1619+
...this.headers,
1620+
"X-ALEO-METHOD": "submitProvingRequest",
1621+
"Content-Type": "application/json"
1622+
};
1623+
1624+
// Add auth header based on what's available
1625+
if (delegatedProvingJWT) {
1626+
headers["Authorization"] = `Bearer ${delegatedProvingJWT}`;
1627+
} else if (apiKey) {
1628+
headers["X-API-Key"] = apiKey;
1629+
}
1630+
16101631
try {
16111632
const response = await retryWithBackoff(() =>
1612-
post(prover_uri + "/prove", {
1613-
body: provingRequestString,
1614-
headers: Object.assign({}, {...this.headers, "X-ALEO-METHOD": "submitProvingRequest"}, {
1615-
"authorization": "Bearer " + delegatedProvingJWT,
1616-
},
1617-
{
1618-
"Content-Type": "application/json",
1619-
}),
1620-
}),
1621-
);
1622-
1623-
try {
1624-
const text = await response.text();
1625-
return parseJSON(text);
1626-
} catch (error: any) {
1627-
throw new Error(
1628-
`Error posting proving request. Aleo network response: ${error.message}`,
1629-
);
1630-
}
1631-
} catch (error: any) {
1632-
throw new Error(
1633-
`Error posting proving request: No response received: ${error.message}`,
1633+
post(`${proverUri}/prove`, {
1634+
body: provingRequestString,
1635+
headers
1636+
})
16341637
);
1638+
1639+
const responseText = await response.text();
1640+
return parseJSON(responseText);
1641+
} catch (error) {
1642+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
1643+
throw new Error(`Failed to submit proving request: ${errorMessage}`);
16351644
}
16361645
}
16371646

0 commit comments

Comments
 (0)