-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
810ae46
commit 4da523c
Showing
5 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters