Skip to content

Commit ddb8b08

Browse files
committed
add zkapp to store the password tree root
1 parent dd4e4e8 commit ddb8b08

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/pluginInteropServer/plugins/simplePasswordTree.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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";
22
import ProvePasswordInTreeProgram, { PASSWORD_TREE_HEIGHT, PasswordTreePublicInput, PasswordTreeWitness } from "../zkPrograms/passwordTreeProof";
33
import { PluginType } from "../plugin";
44

@@ -88,4 +88,39 @@ export const SimplePasswordTree: PluginType = {
8888
prove,
8989
}
9090

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+
}

tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103103
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104104

105+
106+
"experimentalDecorators": true, // needed for decorators
107+
"emitDecoratorMetadata": true, // needed for decorators
108+
"useDefineForClassFields": false, // ensure correct behaviour of class fields with decorators
109+
105110
/* Completeness */
106111
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107112
"skipLibCheck": true /* Skip type checking all .d.ts files. */

0 commit comments

Comments
 (0)