Skip to content

Commit

Permalink
πŸƒπŸ½ Learn2EarnWorker ekle
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed May 18, 2024
1 parent 810ae46 commit 4da523c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
29 changes: 23 additions & 6 deletions blog/mina-berkeley/contracts/Learn2EarnWorker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { Learn2Earn } from "./Learn2Earn";
import { HumanIDv1, HumanIDv1Witness, readPublicKey } from "@kimlikdao/sdk/mina/HumanIDv1";
import { MerkleTree, Mina, PublicKey } from "o1js";
import { LEARN2EARN, Learn2Earn } from "./Learn2Earn";

Learn2Earn.compile();
console.log("Worker loaded and parsed");

/**
* @param truncatedHumanIDv1
*/
const getWitness = (truncatedHumanIDv1: number) => {
console.time("compiling Learn2Earn")

const Learn2EarnCompiled = Learn2Earn.compile().then(() => {
console.timeEnd("compiling Learn2Earn");
postMessage("compiled");
});

const learn2Earn = new Learn2Earn(PublicKey.fromBase58(LEARN2EARN));

const getWitness = (humanIDv1Id: bigint) =>
Promise.resolve(new HumanIDv1Witness(new MerkleTree(33).getWitness(humanIDv1Id & 0xFFFFFFFFn)));

onmessage = (event) => {
const sender = readPublicKey(event.data);
const humanIDv1 = HumanIDv1.fromBytes(event.data.subarray(33));

return Promise.all([getWitness(humanIDv1.id.toBigInt()), Learn2EarnCompiled])
.then(([witness, _]) => Mina.transaction(sender, () => learn2Earn.claimReward(humanIDv1, witness))
.prove()
.then((tx) => postMessage(tx.toJSON())));
}
32 changes: 32 additions & 0 deletions blog/mina-berkeley/contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": [
"dom",
"esnext"
],
"outDir": "./build",
"rootDir": ".",
"strict": true,
"strictPropertyInitialization": false, // to enable generic constructors, e.g. on CircuitValue
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowJs": true,
"declaration": true,
"sourceMap": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"useDefineForClassFields": false,
},
"include": [
".",
],
"exclude": [
"./build"
]
}
3 changes: 2 additions & 1 deletion blog/mina-berkeley/sayfa.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import dom from "/lib/util/dom";
const ClaimButton = dom.adla("mbcl");

const Learn2EarnWorker = new Worker("/blog/mina-berkeley/contracts/Learn2EarnWorker.ts", { type: "module" });
Learn2EarnWorker.onmessage = console.log;

ClaimButton.onclick = () => { }
ClaimButton.onclick = () => Learn2EarnWorker.postMessage(new Uint8Array(33 + 256));
2 changes: 1 addition & 1 deletion dapp
Submodule dapp updated 1 files
+1 βˆ’1 lib
2 changes: 1 addition & 1 deletion sdk
Submodule sdk updated 2 files
+1 βˆ’1 lib
+44 βˆ’1 mina/HumanIDv1.ts

0 comments on commit 4da523c

Please sign in to comment.