-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_request_file
6 lines (6 loc) · 5.21 KB
/
random_request_file
1
2
3
4
5
6
{
"method": "GET",
"baseURL": "https://random-data-api.com/api/number/random_number",
"path": "number",
"zkapp": "import{Field as c,MerkleMap as D,Poseidon as M,PublicKey as L,SmartContract as W,State as h,Struct as G,UInt32 as V,ZkProgram as H,method as y,state as g}from\"o1js\";import{PublicKey as v,UInt64 as T}from\"o1js\";var Q=T.from(10*10**9),I=480;var Y=v.fromBase58(\"B62qnBkcyABfjz2cqJPzNZKjVt9M9kx1vgoiWLbkJUnk16Cz8KX8qC4\"),x=v.fromBase58(\"B62qnmsn4Bm4MzPujKeN1faxedz4p1cCAwA9mKAWzDjfb4c1ysVvWeK\");import{ZkonZkProgram as J,ZkonRequestCoordinator as S,ExternalRequestEvent as F}from\"zkon-zkapp\";import{Field as k,Provable as P,provable as j,Struct as _,UInt32 as m,UInt64 as st}from\"o1js\";import{StringCircuitValue as q}from\"zkon-zkapp\";var E=\"bafkreidke3up3u6reht4ggve3fugvm3k4rnxgjdhf4ukbuqr7tame7gw44\";var N=254n,U=7,B=32n;function Z(o,t,n){if(n*BigInt(t)>N)throw new Error(\"The Packing Plant is only accepting orders that can fit into one Field, try using MultiPackingPlant\");class r extends _({packed:k}){constructor(e){super({packed:e})}static extractField(e){throw new Error(\"Must implement extractField\")}static sizeInBits(){throw new Error(\"Must implement sizeInBits\")}static unpack(e){throw new Error(\"Must implement unpack\")}static checkPack(e){if(e.length>t)throw new Error(`Input of size ${e.length} is larger than expected size of ${t}`)}static pack(e){this.checkPack(e);let i=this.extractField(e[0]),l=Math.min(e.length,t);for(let d=1;d<l;d++){let z=k((2n**this.sizeInBits())**BigInt(d));i=i.add(this.extractField(e[d]).mul(z))}return i}static unpackToBigints(e){let i=new Array(t);i.fill(0n);let l;if(e)l=e.toBigInt();else throw new Error(\"No Packed Value Provided\");for(let d=0;d<t;d++)i[d]=l&(1n<<this.sizeInBits())-1n,l>>=this.sizeInBits();return i}toFields(){return[this.packed]}assertEquals(e){this.packed.assertEquals(e.packed)}}return r.type=j({packed:k},{}),r.l=t,r.bitSize=n,r}function K(o=U){class t extends Z(m,o,B){static extractField(r){return r.value}static sizeInBits(){return B}static unpack(r){let s=P.witness(P.Array(m,o),()=>this.unpackToBigints(r).map(i=>m.from(i)));return r.assertEquals(t.pack(s)),s}static fromUInt32s(r){let s=t.pack(r);return new t(s)}static fromBigInts(r){let s=r.map(e=>m.from(e));return t.fromUInt32s(s)}toBigInts(){return t.unpack(this.packed).map(r=>r.toBigint())}}return t}var w=class extends K(){};var C=()=>{function o(t){let n=t.slice(0,30),r=t.slice(30),s=new q(n).toField(),e=new q(r).toField();return{hashPart1:s,hashPart2:e}}return o(E.toString())};var p=function(o,t,n,r){var s=arguments.length,e=s<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,i;if(typeof Reflect==\"object\"&&typeof Reflect.decorate==\"function\")e=Reflect.decorate(o,t,n,r);else for(var l=o.length-1;l>=0;l--)(i=o[l])&&(e=(s<3?i(e):s>3?i(t,n,e):i(t,n))||e);return s>3&&e&&Object.defineProperty(t,n,e),e},a=function(o,t){if(typeof Reflect==\"object\"&&typeof Reflect.metadata==\"function\")return Reflect.metadata(o,t)},dt=new D().getRoot(),X=H.Proof(J),R=class extends X{},f=class extends G({value:c,salt:c}){hash(){return M.hash([this.value,this.salt])}},{hashPart1:A,hashPart2:b}=C(),O=x,pt=L.fromBase58(\"B62qjGsPY47SMkTykivPBAU3riS9gvMMrGr7ve6ynoHJNBzAhQmtoBn\"),u=class extends W{constructor(){super(...arguments),this.startSlot=h(),this.commit=h(),this.result=h(),this.curRandomValue=h(),this.events={requested:F}}async commitValue(t){this.permissionCheck(),this.checkRoundPass(),this.commit.getAndRequireEquals().assertEquals(c(0),\"Already committed\"),this.commit.set(t.hash())}async reveal(t){this.permissionCheck(),this.result.getAndRequireEquals().assertEquals(c(0),\"reveal: Result already computed\");let r=this.curRandomValue.getAndRequireEquals();this.commit.getAndRequireEquals().assertEquals(t.hash(),\"reveal: wrong commit value\"),this.checkRoundPass();let e=M.hash([t.value,r]);this.result.set(e)}async callZkon(){this.curRandomValue.getAndRequireEquals().assertEquals(c(0),\"random value have already been computed\");let r=await new S(O).sendRequest(this.address,A,b),s=new F({id:r,hash1:A,hash2:b});this.emitEvent(\"requested\",s)}async receiveZkonResponse(t,n){this.curRandomValue.getAndRequireEquals().assertEquals(c(0),\"receiveZkonResponse: prev random value was not consumed. Call reveal first\"),await new S(O).recordRequestFullfillment(t,n),this.curRandomValue.set(n.publicInput.dataField)}permissionCheck(){}checkRoundPass(){let t=this.startSlot.getAndRequireEquals();this.network.globalSlotSinceGenesis.requireBetween(t.add(I),V.MAXINT())}};p([g(V),a(\"design:type\",Object)],u.prototype,\"startSlot\",void 0);p([g(c),a(\"design:type\",Object)],u.prototype,\"commit\",void 0);p([g(c),a(\"design:type\",Object)],u.prototype,\"result\",void 0);p([g(c),a(\"design:type\",Object)],u.prototype,\"curRandomValue\",void 0);p([y,a(\"design:type\",Function),a(\"design:paramtypes\",[f]),a(\"design:returntype\",Promise)],u.prototype,\"commitValue\",null);p([y,a(\"design:type\",Function),a(\"design:paramtypes\",[f]),a(\"design:returntype\",Promise)],u.prototype,\"reveal\",null);p([y,a(\"design:type\",Function),a(\"design:paramtypes\",[c,R]),a(\"design:returntype\",Promise)],u.prototype,\"receiveZkonResponse\",null);var mt=u;export{f as CommitValue,u as RandomManager,R as ZkonProof,X as ZkonProof_,mt as default};\n"
}