Skip to content

Commit 88971e5

Browse files
Merge branch 'mainnet' into feat/query-trait
2 parents 8328ac7 + 0f3c60c commit 88971e5

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

sdk/src/network-client.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ interface AleoNetworkClientOptions {
2121
headers?: { [key: string]: string };
2222
}
2323

24+
/**
25+
* Options for submitting a proving request.
26+
*
27+
* @property provingRequest {ProvingRequest | string} The proving request being submitted to the network.
28+
* @property url {string} The URL of the delegated proving service.
29+
* @property apiKey {string} The API key to use for authentication.
30+
*/
31+
interface DelegatedProvingParams {
32+
provingRequest: ProvingRequest | string;
33+
url?: string;
34+
apiKey?: string;
35+
}
36+
2437
/**
2538
* Client library that encapsulates REST calls to publicly exposed endpoints of Aleo nodes. The methods provided in this
2639
* allow users to query public information from the Aleo blockchain and submit transactions to the network.
@@ -1618,38 +1631,39 @@ class AleoNetworkClient {
16181631
/**
16191632
* Submit a `ProvingRequest` to a remote proving service for delegated proving. If the broadcast flag of the `ProvingRequest` is set to `true` the remote service will attempt to broadcast the result `Transaction` on behalf of the requestor.
16201633
*
1621-
* @param {ProvingRequest | string} provingRequest - The `ProvingRequest` (generated by the ProgramManager) to submit.
1622-
* @param {string} url - (Optional) The url of the proving service.
1634+
* @param {DelegatedProvingParams} options - The optional parameters required to submit a proving request.
16231635
* @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`.
16241636
*/
1625-
async submitProvingRequest(provingRequest: ProvingRequest | string, url?: string): Promise<ProvingResponse> {
1626-
const prover_uri = url ? url : this.host;
1627-
const provingRequestString =
1628-
provingRequest instanceof ProvingRequest
1629-
? provingRequest.toString()
1630-
: provingRequest;
1637+
async submitProvingRequest(options: DelegatedProvingParams): Promise<ProvingResponse> {
1638+
const proverUri = options.url ?? this.host;
1639+
const provingRequestString = options.provingRequest instanceof ProvingRequest
1640+
? options.provingRequest.toString()
1641+
: options.provingRequest;
1642+
1643+
// Build headers with proper auth fallback
1644+
const headers: Record<string, string> = {
1645+
...this.headers,
1646+
"X-ALEO-METHOD": "submitProvingRequest",
1647+
"Content-Type": "application/json"
1648+
};
1649+
1650+
// Add auth header based on what's available
1651+
if (options.apiKey) {
1652+
headers["X-Provable-API-Key"] = options.apiKey;
1653+
}
1654+
16311655
try {
16321656
const response = await retryWithBackoff(() =>
1633-
post(prover_uri + "/prove", {
1634-
body: provingRequestString,
1635-
headers: Object.assign({}, {...this.headers, "X-ALEO-METHOD": "submitProvingRequest"}, {
1636-
"Content-Type": "application/json",
1637-
}),
1638-
}),
1639-
);
1640-
1641-
try {
1642-
const text = await response.text();
1643-
return parseJSON(text);
1644-
} catch (error: any) {
1645-
throw new Error(
1646-
`Error posting proving request. Aleo network response: ${error.message}`,
1647-
);
1648-
}
1649-
} catch (error: any) {
1650-
throw new Error(
1651-
`Error posting proving request: No response received: ${error.message}`,
1657+
post(`${proverUri}/prove`, {
1658+
body: provingRequestString,
1659+
headers
1660+
})
16521661
);
1662+
const responseText = await response.text();
1663+
return parseJSON(responseText);
1664+
} catch (error) {
1665+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
1666+
throw new Error(`Failed to submit proving request: ${errorMessage}`);
16531667
}
16541668
}
16551669

0 commit comments

Comments
 (0)