1
- import { Experimental , Field , JsonProof , MerkleTree , Poseidon , verify } from "o1js" ;
1
+ import { Permissions , DeployArgs , Experimental , Field , JsonProof , MerkleTree , Poseidon , PrivateKey , PublicKey , SmartContract , State , method , state , verify , Mina , AccountUpdate } from "o1js" ;
2
2
import ProvePasswordInTreeProgram , { PASSWORD_TREE_HEIGHT , PasswordTreePublicInput , PasswordTreeWitness } from "../zkPrograms/passwordTreeProof" ;
3
3
import { PluginType } from "../plugin" ;
4
4
@@ -88,4 +88,39 @@ export const SimplePasswordTree: PluginType = {
88
88
prove,
89
89
}
90
90
91
- export default SimplePasswordTree ;
91
+ export default SimplePasswordTree ;
92
+
93
+ class PasswordTreeRootStorage extends SmartContract {
94
+ @state ( Field ) treeRoot = State < Field > ( ) ;
95
+
96
+ deploy ( args ?: DeployArgs ) {
97
+ super . deploy ( args ) ;
98
+
99
+ this . account . permissions . set ( {
100
+ ...Permissions . allImpossible ( ) ,
101
+ editState : Permissions . signature ( ) ,
102
+ access : Permissions . signature ( ) ,
103
+ } ) ;
104
+ }
105
+ }
106
+
107
+ export async function updateTreeRootStorage (
108
+ contractPrivateKey : PrivateKey ,
109
+ feePayerPrivateKey : PrivateKey ,
110
+ treeRoot : Field
111
+ ) {
112
+ const contractPublicKey = contractPrivateKey . toPublicKey ( ) ;
113
+ const contract = new PasswordTreeRootStorage ( contractPublicKey ) ;
114
+ const feePayerPublicKey = feePayerPrivateKey . toPublicKey ( ) ;
115
+ const txfn = contract . account . isNew . get ( ) ?
116
+ ( ) => {
117
+ AccountUpdate . fundNewAccount ( feePayerPublicKey ) ;
118
+ contract . treeRoot . set ( treeRoot ) ;
119
+ contract . deploy ( ) ;
120
+ } : ( ) => {
121
+ contract . treeRoot . set ( treeRoot ) ;
122
+ }
123
+ const txn = await Mina . transaction ( feePayerPublicKey , txfn ) ;
124
+ await txn . prove ( ) ;
125
+ await txn . sign ( [ feePayerPrivateKey , contractPrivateKey ] ) . send ( ) ;
126
+ }
0 commit comments