1
- import { Account , initThreadPool , ProgramManager , AleoKeyProvider , AleoKeyProviderParams } from "@provablehq/sdk" ;
1
+ import { Account , initThreadPool , ProgramManager , AleoKeyProvider , OfflineKeyProvider , CREDITS_PROGRAM_KEYS } from "@provablehq/sdk" ;
2
2
3
3
await initThreadPool ( ) ;
4
4
5
- const programName = "hello_hello.aleo"
6
5
7
- const hello_hello_program = `
8
- program ${ programName } ;
9
6
10
- function hello:
11
- input r0 as u32.public;
12
- input r1 as u32.private;
13
- add r0 r1 into r2;
14
- output r2 as u32.private;`
15
-
16
- async function localProgramExecution ( program , programName , aleoFunction , inputs ) {
7
+ async function localProgramExecution ( ) {
17
8
const programManager = new ProgramManager ( ) ;
18
9
19
10
// Create a temporary account for the execution of the program
@@ -22,38 +13,19 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
22
13
23
14
// Create a key provider in order to re-use the same key for each execution
24
15
const keyProvider = new AleoKeyProvider ( ) ;
16
+ const offlineKeyProvider = new OfflineKeyProvider ( ) ;
25
17
keyProvider . useCache ( true ) ;
26
18
programManager . setKeyProvider ( keyProvider ) ;
27
19
28
- // Pre-synthesize the program keys and then cache them in memory using key provider
29
- const keyPair = await programManager . synthesizeKeys ( hello_hello_program , aleoFunction , inputs ) ;
30
- programManager . keyProvider . cacheKeys ( `${ programName } :${ aleoFunction } ` , keyPair ) ;
20
+ const [ transferPublicProver , transferPublicVerifier ] = await keyProvider . fetchCreditsKeys ( CREDITS_PROGRAM_KEYS . transfer_public ) ;
21
+ console . log ( transferPublicVerifier . toString ( ) ) ;
31
22
32
23
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
33
24
// that was used to cache the keys in the previous step.
34
- const keyProviderParams = new AleoKeyProviderParams ( { cacheKey : `${ programName } :${ aleoFunction } ` } ) ;
35
-
36
- // Execute once using the key provider params defined above. This will use the cached proving keys and make
37
- // execution significantly faster.
38
- let executionResponse = await programManager . run (
39
- program ,
40
- aleoFunction ,
41
- inputs ,
42
- true ,
43
- undefined ,
44
- keyProviderParams ,
45
- ) ;
46
- console . log ( "hello_hello/hello executed - result:" , executionResponse . getOutputs ( ) ) ;
47
-
48
- // Verify the execution using the verifying key that was generated earlier.
49
- if ( programManager . verifyExecution ( executionResponse , 9_000_000 ) ) {
50
- console . log ( "hello_hello/hello execution verified!" ) ;
51
- } else {
52
- throw ( "Execution failed verification!" ) ;
53
- }
25
+
54
26
}
55
27
56
28
const start = Date . now ( ) ;
57
29
console . log ( "Starting execute!" ) ;
58
- await localProgramExecution ( hello_hello_program , programName , "hello" , [ "5u32" , "5u32" ] ) ;
30
+ await localProgramExecution ( ) ;
59
31
console . log ( "Execute finished!" , Date . now ( ) - start ) ;
0 commit comments