1
- import { Account , initThreadPool , ProgramManager , AleoKeyProvider , AleoKeyProviderParams } from "@provablehq/sdk" ;
1
+ import { Account , AleoKeyProvider , AleoKeyProviderParams , initThreadPool , ProgramManager , PrivateKey } from "@provablehq/sdk" ;
2
2
3
- await initThreadPool ( ) ;
3
+ import * as process from "node:process" ;
4
4
5
5
const programName = "hello_hello.aleo"
6
6
@@ -13,7 +13,7 @@ function hello:
13
13
add r0 r1 into r2;
14
14
output r2 as u32.private;`
15
15
16
- async function localProgramExecution ( program , programName , aleoFunction , inputs ) {
16
+ async function localProgramExecution ( program , programName , functionName , inputs ) {
17
17
const programManager = new ProgramManager ( ) ;
18
18
19
19
// Create a temporary account for the execution of the program
@@ -25,19 +25,21 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
25
25
keyProvider . useCache ( true ) ;
26
26
programManager . setKeyProvider ( keyProvider ) ;
27
27
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 ) ;
28
+ // Pre-synthesize the program keys and then cache them in memory using key provider.
29
+ console . log ( "Synthesizing hello_hello/hello keys" ) ;
30
+ const keyPair = await programManager . synthesizeKeys ( hello_hello_program , functionName , inputs ) ;
31
+ programManager . keyProvider . cacheKeys ( `${ programName } :${ functionName } ` , keyPair ) ;
31
32
32
33
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
33
34
// that was used to cache the keys in the previous step.
34
- const keyProviderParams = new AleoKeyProviderParams ( { cacheKey : `${ programName } :${ aleoFunction } ` } ) ;
35
+ const keyProviderParams = new AleoKeyProviderParams ( { cacheKey : `${ programName } :${ functionName } ` } ) ;
35
36
36
37
// Execute once using the key provider params defined above. This will use the cached proving keys and make
37
38
// execution significantly faster.
39
+ console . log ( "Executing hello_hello/hello" ) ;
38
40
let executionResponse = await programManager . run (
39
41
program ,
40
- aleoFunction ,
42
+ functionName ,
41
43
inputs ,
42
44
true ,
43
45
undefined ,
@@ -53,7 +55,33 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
53
55
}
54
56
}
55
57
58
+ // Create a remote program execution transaction.
59
+ async function remoteProgramExecution ( programName , functionName , inputs ) {
60
+ // Create a key provider in order to re-use the same key for each execution
61
+ const keyProvider = new AleoKeyProvider ( ) ;
62
+ keyProvider . useCache ( true ) ;
63
+
64
+ const programManager = new ProgramManager ( "http://34.168.156.3:3030" , keyProvider ) ;
65
+
66
+ const tx = await programManager . buildExecutionTransaction (
67
+ {
68
+ programName,
69
+ functionName,
70
+ priorityFee : 0 ,
71
+ privateFee : false ,
72
+ inputs,
73
+ privateKey : PrivateKey . from_string ( process . env [ "PUZZLE_PK" ] )
74
+ }
75
+ ) ;
76
+ console . log ( "Resulting transaction" )
77
+ }
78
+
56
79
const start = Date . now ( ) ;
57
- console . log ( "Starting execute!" ) ;
80
+ console . log ( "Starting local execute!" ) ;
58
81
await localProgramExecution ( hello_hello_program , programName , "hello" , [ "5u32" , "5u32" ] ) ;
59
- console . log ( "Execute finished!" , Date . now ( ) - start ) ;
82
+ console . log ( "Local execute finished!" , Date . now ( ) - start ) ;
83
+
84
+ console . log ( "Starting remote execute" ) ;
85
+ const auctionTicket = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n auction: {\n starting_bid: 1000u64.private,\n name: 35399035103896773146887283777field.private,\n item: {\n id: 2711777270856651361584090827715149911900945757872672230578290769243507539617field.private,\n offchain_data: [\n 988474637487226873250021955104421895943605632761729320744454284792013483886field.private,\n 1018595503607749325560812785092303652308909717269501712857428145700763090203field.private,\n 1866354748676879328546224733327549476838379876255164483333908854380501015560field.private,\n 17649382157field.private\n ]\n }\n },\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n settings: {\n auction_privacy: 1field.private,\n bid_types_accepted: 2field.private\n },\n _nonce: 3369967065799891136255379173673996324404175734426175774361522329924029135340group.public,\n _version: 0u8.public\n}" ;
86
+ const privateBid = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n bid: {\n amount: 50000u64.private,\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n bid_public_key: 7957235921075215080384898776027711008106448988910535634014947882222019778701group.private\n },\n bid_id: 7560059211950188901208146469854635725646381155467709838136796808753178551929field.private,\n _nonce: 6603986437928263590097393830337419611438422585243442121397081002092267314422group.public,\n _version: 0u8.public\n}" ;
87
+ await remoteProgramExecution ( "private_auction_test_3.aleo" , "select_winner_private" , [ auctionTicket , privateBid ] ) ;
0 commit comments