Skip to content

Commit ed78558

Browse files
Update to SnarkVM v4.0.0
1 parent e17086b commit ed78558

28 files changed

+912
-409
lines changed

sdk/rollup.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default networks.map((network) => {
1212
input: {
1313
"node-polyfill": "./src/node-polyfill.ts",
1414
"browser": "./src/browser.ts",
15-
"worker": "./src/worker.ts",
1615
"node": "./src/node.ts",
1716
},
1817
output: {

sdk/src/browser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ async function initializeWasm() {
5151
console.warn("initializeWasm is deprecated, you no longer need to use it");
5252
}
5353

54-
export { createAleoWorker } from "./managed-worker.js";
55-
5654
export { ProgramManager } from "./program-manager.js";
5755

5856
export { logAndThrow } from "./utils.js";

sdk/src/managed-worker.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

sdk/src/network-client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,14 @@ class AleoNetworkClient {
373373
}
374374

375375
if (unspent) {
376+
const recordViewKey = recordPlaintext.recordViewKey(viewKey).toString();
376377
// Otherwise record the nonce that has been found
377378
const serialNumber =
378379
recordPlaintext.serialNumberString(
379380
resolvedPrivateKey,
380381
"credits.aleo",
381382
"credits",
383+
recordViewKey
382384
);
383385
// Attempt to see if the serial number is spent
384386
try {

sdk/src/program-manager.ts

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,100 @@ class ProgramManager {
696696
);
697697
}
698698

699+
/**
700+
* Builds a SnarkVM `Authorization` for a specific function without building a circuit first. This should be used when fast authorization generation is needed and the invoker is confident inputs are coorect.
701+
*
702+
* @param {AuthorizationOptions} options - The options for building the `Authorization`
703+
* @returns {Promise<Authorization>} - A promise that resolves to an `Authorization` or throws an Error.
704+
*
705+
* @example
706+
* /// Import the mainnet version of the sdk.
707+
* import { AleoKeyProvider, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
708+
*
709+
* // Create a new NetworkClient, KeyProvider, and RecordProvider.
710+
* const keyProvider = new AleoKeyProvider();
711+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
712+
* keyProvider.useCache = true;
713+
*
714+
* // Initialize a ProgramManager with the key and record providers.
715+
* const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider);
716+
*
717+
* // Build the unchecked `Authorization`.
718+
* const authorization = await programManager.buildAuthorizationUnchecked({
719+
* programName: "credits.aleo",
720+
* functionName: "transfer_public",
721+
* inputs: [
722+
* "aleo1vwls2ete8dk8uu2kmkmzumd7q38fvshrht8hlc0a5362uq8ftgyqnm3w08",
723+
* "10000000u64",
724+
* ],
725+
* });
726+
*/
727+
async buildAuthorizationUnchecked(
728+
options: AuthorizationOptions,
729+
): Promise<Authorization> {
730+
// Destructure the options object to access the parameters.
731+
const {
732+
programName,
733+
functionName,
734+
inputs,
735+
} = options;
736+
737+
const privateKey = options.privateKey;
738+
let program = options.programSource;
739+
let imports = options.programImports;
740+
741+
// Ensure the function exists on the network.
742+
if (program === undefined) {
743+
try {
744+
program = <string>(
745+
await this.networkClient.getProgram(programName)
746+
);
747+
} catch (e: any) {
748+
logAndThrow(
749+
`Error finding ${programName}. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network the program is deployed to the network.`,
750+
);
751+
}
752+
} else if (program instanceof Program) {
753+
program = program.toString();
754+
}
755+
756+
// Get the private key from the account if it is not provided in the parameters.
757+
let executionPrivateKey = privateKey;
758+
if (
759+
typeof privateKey === "undefined" &&
760+
typeof this.account !== "undefined"
761+
) {
762+
executionPrivateKey = this.account.privateKey();
763+
}
764+
765+
if (typeof executionPrivateKey === "undefined") {
766+
throw "No private key provided and no private key set in the ProgramManager";
767+
}
768+
769+
// Resolve the program imports if they exist.
770+
const numberOfImports = Program.fromString(program).getImports().length;
771+
if (numberOfImports > 0 && !imports) {
772+
try {
773+
imports = <ProgramImports>(
774+
await this.networkClient.getProgramImports(programName)
775+
);
776+
} catch (e: any) {
777+
logAndThrow(
778+
`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`,
779+
);
780+
}
781+
}
782+
783+
// Build and return an `Authorization` for the desired function.
784+
return await WasmProgramManager.buildAuthorizationUnchecked(
785+
executionPrivateKey,
786+
program,
787+
functionName,
788+
inputs,
789+
imports
790+
);
791+
}
792+
699793
/**
700794
* Builds a SnarkVM fee `Authorization` for `credits.aleo/fee_private` or `credits.aleo/fee_public`. If a record is provided `fee_private` will be executed, otherwise `fee_public` will be executed.
701795
*
@@ -2153,6 +2247,7 @@ class ProgramManager {
21532247
* Verify a proof from an offline execution. This is useful when it is desired to do offchain proving and verification.
21542248
*
21552249
* @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
2250+
* @param {blockHeight} blockHeight The ledger height when the execution was generated.
21562251
* @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
21572252
* @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
21582253
* @returns {boolean} True if the proof is valid, false otherwise
@@ -2181,7 +2276,7 @@ class ProgramManager {
21812276
* const isValid = programManager.verifyExecution(executionResponse, imports, importedVerifyingKeys);
21822277
* assert(isValid);
21832278
*/
2184-
verifyExecution(executionResponse: ExecutionResponse, imports?: ImportedPrograms, importedVerifyingKeys?: ImportedVerifyingKeys): boolean {
2279+
verifyExecution(executionResponse: ExecutionResponse, blockHeight: number, imports?: ImportedPrograms, importedVerifyingKeys?: ImportedVerifyingKeys): boolean {
21852280
try {
21862281
const execution = <FunctionExecution>(
21872282
executionResponse.getExecution()
@@ -2196,10 +2291,11 @@ class ProgramManager {
21962291
function_id,
21972292
imports,
21982293
importedVerifyingKeys,
2294+
blockHeight
21992295
);
22002296
} catch (e) {
22012297
console.warn(
2202-
"The execution was not found in the response, cannot verify the execution",
2298+
`The execution was not found in the response, cannot verify the execution: ${e}`,
22032299
);
22042300
return false;
22052301
}

sdk/src/worker.ts

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)