Skip to content

Commit db791fc

Browse files
authored
Merge pull request #1077 from ProvableHQ/rr-delegated-proving-api
[Feature] Add proving request to network client
2 parents a1a5b23 + 03fed30 commit db791fc

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

create-leo-app/template-node/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
5656
const start = Date.now();
5757
console.log("Starting execute!");
5858
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
59-
console.log("Execute finished!", Date.now() - start);
59+
console.log("Execute finished!", Date.now() - start);

sdk/src/network-client.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import {
77
Plaintext,
88
RecordCiphertext,
99
Program,
10+
ProvingRequest,
1011
RecordPlaintext,
1112
PrivateKey,
1213
Transaction,
1314
} from "./wasm.js";
1415
import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js";
16+
import { ProvingResponse } from "./models/provingResponse.js";
1517

1618
type ProgramImports = { [key: string]: string | Program };
1719

@@ -1592,6 +1594,44 @@ class AleoNetworkClient {
15921594
}
15931595
}
15941596

1597+
/**
1598+
* 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.
1599+
*
1600+
* @param {ProvingRequest | string} provingRequest - The `ProvingRequest` (generated by the ProgramManager) to submit.
1601+
* @param {string} url - (Optional) The url of the proving service.
1602+
* @returns {Promise<ProvingResponse>} The ProvingResponse containing the transaction result and the result of the broadcast if the `broadcast` flag was set to `true`.
1603+
*/
1604+
async submitProvingRequest(provingRequest: ProvingRequest | string, url?: string): Promise<ProvingResponse> {
1605+
const prover_uri = url ? url : this.host;
1606+
const provingRequestString =
1607+
provingRequest instanceof ProvingRequest
1608+
? provingRequest.toString()
1609+
: provingRequest;
1610+
try {
1611+
const response = await retryWithBackoff(() =>
1612+
post(prover_uri + "/prove", {
1613+
body: provingRequestString,
1614+
headers: Object.assign({}, {...this.headers, "X-ALEO-METHOD": "submitProvingRequest"}, {
1615+
"Content-Type": "application/json",
1616+
}),
1617+
}),
1618+
);
1619+
1620+
try {
1621+
const text = await response.text();
1622+
return parseJSON(text);
1623+
} catch (error: any) {
1624+
throw new Error(
1625+
`Error posting proving request. Aleo network response: ${error.message}`,
1626+
);
1627+
}
1628+
} catch (error: any) {
1629+
throw new Error(
1630+
`Error posting proving request: No response received: ${error.message}`,
1631+
);
1632+
}
1633+
}
1634+
15951635
/**
15961636
* Await a submitted transaction to be confirmed or rejected on the Aleo network.
15971637
*

0 commit comments

Comments
 (0)