diff --git a/assets/index-B0wH_rPa.js b/assets/index-BUcCvcfh.js similarity index 99% rename from assets/index-B0wH_rPa.js rename to assets/index-BUcCvcfh.js index 405ae7c..5c6249b 100644 --- a/assets/index-B0wH_rPa.js +++ b/assets/index-BUcCvcfh.js @@ -50,4 +50,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho provided: ${r} expected: ${n}`);return n.map((i,o)=>({element:r[o],type:i.type??i}))}function Zp(e){if(typeof e=="object"){const{low:n,high:r}=e;return[Ve(n),Ve(r)]}const t=cd(e);return[Ve(t.low),Ve(t.high)]}function Rt(e,t,n,r){if(e===void 0)throw Error(`Missing parameter for type ${t}`);if(Array.isArray(e)){const i=[];i.push(Ve(e.length));const o=fi(t);return e.reduce((a,s)=>a.concat(Rt(s,o,n,r)),i)}if(n[t]&&n[t].members.length){if(Bn(t))return Zp(e);if(t==="core::starknet::eth_address::EthAddress")return Es(t,e);const{members:i}=n[t],o=e;return i.reduce((a,s)=>a.concat(Rt(o[s.name],s.type,n,r)),[])}if(Hn(t))return ub(e,t).reduce((o,a)=>{const s=Rt(a.element,a.type,n,r);return o.concat(s)},[]);if(Bn(t))return Zp(e);if(vr(t,r)){const{variants:i}=r[t];if(sl(t)){const f=e;if(f.isSome()){const p=i.find(_=>_.name==="Some");if(typeof p>"u")throw Error("Error in abi : Option has no 'Some' variant.");const y=p.type;if(y==="()")return"0";const m=Rt(f.unwrap(),y,n,r);return Array.isArray(m)?["0",...m]:["0",m]}return"1"}if(ll(t)){const f=e;if(f.isOk()){const _=i.find(h=>h.name==="Ok");if(typeof _>"u")throw Error("Error in abi : Result has no 'Ok' variant.");const w=_.type;if(w==="()")return"0";const d=Rt(f.unwrap(),w,n,r);return Array.isArray(d)?["0",...d]:["0",d]}const p=i.find(_=>_.name==="Err");if(typeof p>"u")throw Error("Error in abi : Result has no 'Err' variant.");const y=p.type;if(y==="()")return"1";const m=Rt(f.unwrap(),y,n,r);return Array.isArray(m)?["1",...m]:["1",m]}const o=e,a=o.activeVariant(),s=i.find(f=>f.name===a);if(typeof s>"u")throw Error(`Not find in abi : Enum has no '${a}' variant.`);const u=s.type,l=i.findIndex(f=>f.name===a);if(u==="()")return l.toString();const c=Rt(o.unwrap(),u,n,r);return Array.isArray(c)?[l.toString(),...c]:[l.toString(),c]}if(typeof e=="object")throw Error(`Parameter ${e} do not align with abi parameter ${t}`);return Es(t,e)}function cb(e,t,n,r){const{name:i,type:o}=t;let{value:a}=e.next();switch(!0){case Ln(o):if(!Array.isArray(a)&&!Yo(a))throw Error(`ABI expected parameter ${i} to be array or long string, got ${a}`);return typeof a=="string"&&(a=id(a)),Rt(a,t.type,n,r);case o==="core::starknet::eth_address::EthAddress":return Es(o,a);case(Xo(o,n)||Hn(o)||Bn(o)):return Rt(a,o,n,r);case vr(o,r):return Rt(a,o,n,r);default:return Es(o,a)}}function Ec(e,t){let n;switch(!0){case ul(e):return n=t.next().value,!!BigInt(n);case Bn(e):const r=t.next().value,i=t.next().value;return al({low:r,high:i});case e==="core::starknet::eth_address::EthAddress":return n=t.next().value,BigInt(n);default:return n=t.next().value,BigInt(n)}}function Kt(e,t,n,r){if(t.type==="()")return{};if(Bn(t.type)){const i=e.next().value,o=e.next().value;return al({low:i,high:o})}if(Ln(t.type)){const i=[],o={name:"",type:fi(t.type)},a=BigInt(e.next().value);for(;i.length(i[o.name]=Kt(e,o,n,r),i),{});if(r&&t.type in r&&r[t.type]){const i=Number(e.next().value),o=r[t.type].variants.reduce((s,u,l)=>l===i?(s[u.name]=Kt(e,{name:"",type:u.type},n,r),s):(s[u.name]=void 0,s),{});if(t.type.startsWith("core::option::Option")){const s=i===0?o.Some:void 0;return new vc(i,s)}if(t.type.startsWith("core::result::Result")){let s;return i===0?s=o.Ok:s=o.Err,new wc(i,s)}return new T1(o)}if(Hn(t.type))return fd(t.type).reduce((o,a,s)=>{const u=a!=null&&a.name?a.name:s,l=a!=null&&a.type?a.type:a,c={name:u,type:l};return o[u]=Kt(e,c,n,r),o},{});if(Ln(t.type)){const i=[],o={name:"",type:fi(t.type)},a=BigInt(e.next().value);for(;i.length{if(oe(typeof e=="string"||typeof e=="number"||typeof e=="bigint",`Validate: arg ${t.name} should be a felt typed as (String, Number or BigInt)`),typeof e=="string"&&!kt(e))return;const n=BigInt(e.toString(10));oe(n>=0n&&n<=2n**252n-1n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 2^252-1]`)},dd=(e,t)=>{typeof e=="number"&&oe(e<=Number.MAX_SAFE_INTEGER,"Validation: Parameter is to large to be typed as Number use (BigInt or String)"),oe(typeof e=="string"||typeof e=="number"||typeof e=="bigint"||typeof e=="object"&&"low"in e&&"high"in e,`Validate: arg ${t.name} of cairo type ${t.type} should be type (String, Number or BigInt), but is ${typeof e} ${e}.`);const n=typeof e=="object"?al(e):H(e);switch(t.type){case"core::integer::u8":oe(n>=0n&&n<=255n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0 - 255]`);break;case"core::integer::u16":oe(n>=0n&&n<=65535n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 65535]`);break;case"core::integer::u32":oe(n>=0n&&n<=4294967295n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 4294967295]`);break;case"core::integer::u64":oe(n>=0n&&n<=2n**64n-1n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 2^64-1]`);break;case"core::integer::u128":oe(n>=0n&&n<=2n**128n-1n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 2^128-1]`);break;case"core::integer::u256":oe(n>=0n&&n<=2n**256n-1n,`Validate: arg ${t.name} is ${t.type} 0 - 2^256-1`);break;case"core::starknet::class_hash::ClassHash":oe(n>=0n&&n<=2n**252n-1n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 2^252-1]`);break;case"core::starknet::contract_address::ContractAddress":oe(n>=0n&&n<=2n**252n-1n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 2^252-1]`);break}},L1=(e,t)=>{oe(typeof e=="boolean",`Validate: arg ${t.name} of cairo type ${t.type} should be type (Boolean)`)},B1=(e,t,n)=>{if(t.type==="core::integer::u256"){dd(e,t);return}if(t.type==="core::starknet::eth_address::EthAddress"){oe(typeof e!="object",`EthAdress type is waiting a BigNumberish. Got ${e}`);const r=BigInt(e.toString(10));oe(r>=0n&&r<=2n**160n-1n,`Validate: arg ${t.name} cairo typed ${t.type} should be in range [0, 2^160-1]`);return}oe(typeof e=="object"&&!Array.isArray(e),`Validate: arg ${t.name} is cairo type struct (${t.type}), and should be defined as js object (not array)`),n[t.type].members.forEach(({name:r})=>{oe(Object.keys(e).includes(r),`Validate: arg ${t.name} should have a property ${r}`)})},P1=(e,t)=>{oe(typeof e=="object"&&!Array.isArray(e),`Validate: arg ${t.name} is cairo type Enum (${t.type}), and should be defined as js object (not array)`);const n=Object.getOwnPropertyNames(Object.getPrototypeOf(e)),r=[...Object.getOwnPropertyNames(e),...n];if(!(sl(t.type)&&r.includes("isSome")&&r.includes("isNone"))&&!(ll(t.type)&&r.includes("isOk")&&r.includes("isErr"))&&!(r.includes("variant")&&r.includes("activeVariant")))throw new Error(`Validate Enum: argument ${t.name}, type ${t.type}, value received ${e}, is not an Enum.`)},D1=(e,t)=>{oe(typeof e=="object"&&!Array.isArray(e),`Validate: arg ${t.name} should be a tuple (defined as object)`)},U1=(e,t,n,r)=>{const i=fi(t.type);if(!(ws(i)&&rd(e)))switch(oe(Array.isArray(e),`Validate: arg ${t.name} should be an Array`),!0){case ws(i):e.forEach(o=>O1(o,t));break;case Hn(i):e.forEach(o=>D1(o,{name:t.name,type:i}));break;case Ln(i):e.forEach(o=>U1(o,{name:"",type:i},n,r));break;case Xo(i,n):e.forEach(o=>B1(o,{name:t.name,type:i},n));break;case vr(i,r):e.forEach(o=>P1(o,{name:t.name,type:i}));break;case(ld(i)||ud(i)):e.forEach(o=>dd(o,t));break;case ul(i):e.forEach(o=>L1(o,t));break;default:throw new Error(`Validate Unhandled: argument ${t.name}, type ${t.type}, value ${e}`)}};function Kp(e,t,n,r){e.inputs.reduce((i,o)=>{const a=t[i];switch(!0){case hr(o.name):return i;case ws(o.type):O1(a,o);break;case(ld(o.type)||ud(o.type)):dd(a,o);break;case ul(o.type):L1(a,o);break;case Ln(o.type):U1(a,o,n,r);break;case Xo(o.type,n):B1(a,o,n);break;case vr(o.type,r):P1(a,o);break;case Hn(o.type):D1(a,o);break;default:throw new Error(`Validate Unhandled: argument ${o.name}, type ${o.type}, value ${a}`)}return i+1},0)}var ee=class{constructor(e){this.structs=ee.getAbiStruct(e),this.enums=ee.getAbiEnum(e),this.parser=nb(e),this.abi=this.parser.getLegacyFormat()}validate(e,t,n=[]){if(e!=="DEPLOY"){const o=this.abi.filter(a=>{if(a.type!=="function")return!1;const s=a.stateMutability==="view"||a.state_mutability==="view";return e==="INVOKE"?!s:s}).map(a=>a.name);oe(o.includes(t),`${e==="INVOKE"?"invocable":"viewable"} method not found in abi`)}const r=this.abi.find(o=>e==="DEPLOY"?o.name===t&&o.type==="constructor":o.name===t&&o.type==="function");if(Vp(t,n,r))return;const i=this.parser.methodInputsLength(r);if(n.length!==i)throw Error(`Invalid number of arguments, expected ${i} arguments, but got ${n.length}`);Kp(r,n,this.structs,this.enums)}compile(e,t){const n=this.abi.find(a=>a.name===e);if(Vp(e,t,n))return[];let r;if(Array.isArray(t))r=t;else{const a=lb(t,n.inputs,this.structs,this.enums);r=Object.values(a),Kp(n,r,this.structs,this.enums)}const i=r[Symbol.iterator](),o=n.inputs.reduce((a,s)=>hr(s.name)&&!Pn(s.type)?a:a.concat(cb(i,s,this.structs,this.enums)),[]);return Object.defineProperty(o,"__compiled__",{enumerable:!1,writable:!1,value:!0}),o}static compile(e){const t=r=>{const i=(a,s=".")=>{const u=Array.isArray(a)?[a.length.toString(),...a]:a;return Object.entries(u).flatMap(([l,c])=>{let f=c;rd(f)&&(f=id(f)),l==="entrypoint"&&(f=Ct(f));const p=Array.isArray(u)&&l==="0"?"$$len":l;if(il(f))return[[`${s}${p}`,Ve(f)]];if(Object(f)===f){const y=Object.getOwnPropertyNames(Object.getPrototypeOf(f)),m=[...Object.getOwnPropertyNames(f),...y];if(m.includes("isSome")&&m.includes("isNone")){const _=f,w=_.isSome()?0:1;return _.isSome()?i({0:w,1:_.unwrap()},`${s}${p}.`):[[`${s}${p}`,Ve(w)]]}if(m.includes("isOk")&&m.includes("isErr")){const _=f,w=_.isOk()?0:1;return i({0:w,1:_.unwrap()},`${s}${p}.`)}if(m.includes("variant")&&m.includes("activeVariant")){const _=f,w=_.activeVariant(),h=Object.keys(_.variant).findIndex(g=>g===w);return typeof _.unwrap()=="object"&&Object.keys(_.unwrap()).length===0?[[`${s}${p}`,Ve(h)]]:i({0:h,1:_.unwrap()},`${s}${p}.`)}return i(f,`${s}${p}.`)}return[[`${s}${p}`,Ve(f)]]})};return Object.fromEntries(i(r))};let n;if(Array.isArray(e)){const r={...e},i=t(r);n=Object.values(i)}else{const r=t(e);n=Object.values(r)}return Object.defineProperty(n,"__compiled__",{enumerable:!1,writable:!1,value:!0}),n}parse(e,t){const{outputs:n}=this.abi.find(o=>o.name===e),r=t.flat()[Symbol.iterator](),i=n.flat().reduce((o,a,s)=>{const u=a.name??s;return o[u]=Sc(r,a,this.structs,this.enums,o),o[u]&&o[`${u}_len`]&&delete o[`${u}_len`],o},{});return Object.keys(i).length===1&&0 in i?i[0]:i}format(e,t,n){const r=this.parse(e,t);return Ma(r,n)}static getAbiStruct(e){return e.filter(t=>t.type==="struct").reduce((t,n)=>({...t,[n.name]:n}),{})}static getAbiEnum(e){const t=e.filter(n=>n.type==="enum").reduce((n,r)=>({...n,[r.name]:r}),{});return delete t["core::bool"],t}static toCalldata(e=[]){return ee.compile(e)}static toHex(e=[]){return ee.compile(e).map(n=>L(n))}},$1={};pe($1,{calculateContractAddressFromHash:()=>_b,calculateDeclareTransactionHash:()=>gb,calculateDeployAccountTransactionHash:()=>yb,calculateDeployTransactionHash:()=>pb,calculateTransactionHash:()=>mb,calculateTransactionHashCommon:()=>Qo,computeCompiledClassHash:()=>Eb,computeContractClassHash:()=>xb,computeHashOnElements:()=>Le,computeLegacyContractClassHash:()=>V1,computeSierraContractClassHash:()=>Z1,default:()=>j1,feeTransactionVersion:()=>H1,feeTransactionVersion_2:()=>F1,formatSpaces:()=>Lo,getSelector:()=>ol,getSelectorFromName:()=>Ct,getVersionsByType:()=>gd,keccakBn:()=>S1,poseidon:()=>s2,starknetKeccak:()=>td,transactionVersion:()=>hd,transactionVersion_2:()=>pd});var z1={};pe(z1,{starkCurve:()=>B2,weierstrass:()=>g2});var fb={};pe(fb,{parse:()=>Dn,parseAlwaysAsBig:()=>M1,stringify:()=>St,stringifyAlwaysAsBig:()=>hb});var db=e=>{if(!Vo(e))return parseFloat(e);const t=parseInt(e,10);return Number.isSafeInteger(t)?t:BigInt(e)},Dn=e=>qy(String(e),void 0,db),M1=e=>qy(String(e),void 0,X2),St=(e,t,n,r)=>Yy(e,t,n,r),hb=St,hd=Kf,pd=Wf,H1=Km,F1=Wm;function gd(e){return e==="fee"?{v1:H1,v2:F1}:{v1:hd,v2:pd}}function Le(e){return[...e,e.length].reduce((t,n)=>el(H(t),H(n)),0).toString()}function Qo(e,t,n,r,i,o,a,s=[]){const u=Le(i),l=[e,t,n,r,u,o,a,...s];return Le(l)}function pb(e,t,n,r,i="constructor"){return Qo("0x6465706c6f79",n,e,Ct(i),t,0,r)}function gb(e,t,n,r,i,o,a){return Qo("0x6465636c617265",n,t,0,[e],r,i,[o,...a?[a]:[]])}function yb(e,t,n,r,i,o,a,s){const u=[t,r,...n];return Qo("0x6465706c6f795f6163636f756e74",i,e,0,u,o,a,[s])}function mb(e,t,n,r,i,o){return Qo("0x696e766f6b65",t,e,0,n,r,i,[o])}function _b(e,t,n,r){const i=ee.compile(n),o=Le(i),a=Ve("0x535441524b4e45545f434f4e54524143545f41444452455353");return Le([a,r,e,t,o])}function vb(e,t){return e==="attributes"||e==="accessible_scopes"?Array.isArray(t)&&t.length===0?void 0:t:e==="debug_info"?null:t===null?void 0:t}function Lo(e){let t=!1;const n=[];for(const r of e)r==='"'&&!(n.length>0&&n.slice(-1)[0]==="\\")&&(t=!t),t?n.push(r):n.push(r===":"?": ":r===","?", ":r);return n.join("")}function j1(e){const{abi:t,program:n}=e,i=Lo(St({abi:t,program:n},vb));return Ue(yi(Si(i)).toString(16))}function V1(e){const t=typeof e=="string"?Dn(e):e,n=L(qm),r=Le(t.entry_points_by_type.EXTERNAL.flatMap(l=>[l.selector,l.offset])),i=Le(t.entry_points_by_type.L1_HANDLER.flatMap(l=>[l.selector,l.offset])),o=Le(t.entry_points_by_type.CONSTRUCTOR.flatMap(l=>[l.selector,l.offset])),a=Le(t.program.builtins.map(l=>Mn(l))),s=j1(t),u=Le(t.program.data);return Le([n,r,i,o,a,s,u])}function wb(e){return On(e.flatMap(t=>BigInt(Mn(t))))}function au(e){const t=e.flatMap(n=>[BigInt(n.selector),BigInt(n.offset),wb(n.builtins)]);return On(t)}function Eb(e){const n=BigInt(Mn("COMPILED_CLASS_V1")),r=au(e.entry_points_by_type.EXTERNAL),i=au(e.entry_points_by_type.L1_HANDLER),o=au(e.entry_points_by_type.CONSTRUCTOR),a=On(e.bytecode.map(s=>BigInt(s)));return L(On([n,r,i,o,a]))}function su(e){const t=e.flatMap(n=>[BigInt(n.selector),BigInt(n.function_idx)]);return On(t)}function Sb(e){const t=Lo(St(e.abi,null));return BigInt(Ue(yi(Si(t)).toString(16)))}function Z1(e){const n=BigInt(Mn("CONTRACT_CLASS_V0.1.0")),r=su(e.entry_points_by_type.EXTERNAL),i=su(e.entry_points_by_type.L1_HANDLER),o=su(e.entry_points_by_type.CONSTRUCTOR),a=Sb(e),s=On(e.sierra_program.map(u=>BigInt(u)));return L(On([n,r,i,o,a,s]))}function xb(e){const t=typeof e=="string"?Dn(e):e;return"sierra_program"in t?Z1(t):V1(t)}var K1={};pe(K1,{compressProgram:()=>yd,decompressProgram:()=>xc,estimatedFeeToMaxFee:()=>_d,formatSignature:()=>md,makeAddress:()=>kb,randomAddress:()=>W1,signatureToDecimalArray:()=>Tr,signatureToHexArray:()=>Nr});function yd(e){const t=typeof e=="string"?e:St(e),n=cC(t);return Mm(n)}function xc(e){if(Array.isArray(e))return e;const t=$m(fC(zm(e)));return Dn(t)}function W1(){const e=zy.randomPrivateKey();return Fy(e)}function kb(e){return Ue(e).toLowerCase()}function md(e){if(!e)throw Error("formatSignature: provided signature is undefined");if(Array.isArray(e))return e.map(t=>L(t));try{const{r:t,s:n}=e;return[L(t),L(n)]}catch{throw new Error("Signature need to be weierstrass.SignatureType or an array for custom")}}function Tr(e){return _1(md(e))}function Nr(e){return v1(md(e))}function _d(e,t=.5){const n=Math.round((1+t)*100);return H(e)*H(n)/100n}function An(e){return"sierra_program"in(typeof e=="string"?Dn(e):e)}var G1=typeof window<"u"&&window.fetch||typeof global<"u"&&global.fetch||kC,Cb={};pe(Cb,{createSierraContractClass:()=>q1,parseContract:()=>Y1,wait:()=>Ss});function Ss(e){return new Promise(t=>{setTimeout(t,e)})}function q1(e){const t={...e};return delete t.sierra_program_debug_info,t.abi=Lo(St(e.abi)),t.sierra_program=Lo(St(e.sierra_program)),t.sierra_program=yd(t.sierra_program),t}function Y1(e){const t=typeof e=="string"?Dn(e):e;return An(e)?q1(t):{...t,..."program"in t&&{program:yd(t.program)}}}var bb=class{parseGetBlockResponse(e){return{timestamp:e.timestamp,block_hash:"block_hash"in e?e.block_hash:"",block_number:"block_number"in e?e.block_number:-1,new_root:"new_root"in e?e.new_root:"",parent_hash:e.parent_hash,status:"status"in e?e.status:"PENDING",transactions:e.transactions}}parseGetTransactionResponse(e){return{calldata:"calldata"in e?e.calldata:[],contract_address:"contract_address"in e?e.contract_address:"",sender_address:"sender_address"in e?e.sender_address:"",max_fee:"max_fee"in e?e.max_fee:"",nonce:"nonce"in e?e.nonce:"",signature:"signature"in e?e.signature:[],transaction_hash:e.transaction_hash,version:e.version}}parseFeeEstimateResponse(e){return{overall_fee:H(e[0].overall_fee),gas_consumed:H(e[0].gas_consumed),gas_price:H(e[0].gas_price)}}parseFeeEstimateBulkResponse(e){return e.map(t=>({overall_fee:H(t.overall_fee),gas_consumed:H(t.gas_consumed),gas_price:H(t.gas_price)}))}parseCallContractResponse(e){return{result:e}}parseSimulateTransactionResponse(e){return e.map(t=>({...t,suggestedMaxFee:_d(BigInt(t.fee_estimation.overall_fee))}))}parseContractClassResponse(e){return{...e,abi:typeof e.abi=="string"?JSON.parse(e.abi):e.abi}}};function Ab(e,t=e.constructor){const{captureStackTrace:n}=Error;n&&n(e,t)}function Tb(e,t){const{setPrototypeOf:n}=Object;n?n(e,t):e.__proto__=t}var Nb=class extends Error{constructor(e){super(e),Object.defineProperty(this,"name",{value:new.target.name,enumerable:!1,configurable:!0}),Tb(this,new.target.prototype),Ab(this)}},pr=class extends Nb{},Ib=class extends pr{constructor(e,t){super(e),this.errorCode=t}},Rb=class extends pr{constructor(e,t){super(e),this.errorCode=t}},Ob={};pe(Ob,{StarknetIdContract:()=>J1,getStarknetIdContract:()=>vd,useDecoded:()=>X1,useEncoded:()=>Q1});var Bt="abcdefghijklmnopqrstuvwxyz0123456789-",Fr=BigInt(Bt.length+1),me="这来",Wp=BigInt(Bt.length),kc=BigInt(me.length),Gp=BigInt(me.length+1);function Cc(e){let t=0;for(;e.endsWith(me[me.length-1]);)e=e.substring(0,e.length-1),t+=1;return[e,t]}function X1(e){let t="";return e.forEach(n=>{for(;n!==ro;){const o=n%Fr;if(n/=Fr,o===BigInt(Bt.length)){const a=n/Gp;if(a===ro){const s=n%Gp;n=a,s===ro?t+=Bt[0]:t+=me[Number(s)-1]}else{const s=n%kc;t+=me[Number(s)],n/=kc}}else t+=Bt[Number(o)]}const[r,i]=Cc(t);i&&(t=r+(i%2===0?me[me.length-1].repeat(i/2-1)+me[0]+Bt[1]:me[me.length-1].repeat((i-1)/2+1))),t+="."}),t&&t.concat("stark")}function Q1(e){let t=BigInt(0),n=BigInt(1);if(e.endsWith(me[0]+Bt[1])){const[r,i]=Cc(e.substring(0,e.length-2));e=r+me[me.length-1].repeat(2*(i+1))}else{const[r,i]=Cc(e);i&&(e=r+me[me.length-1].repeat(1+2*(i-1)))}for(let r=0;r(e.MAINNET="0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678",e.TESTNET="0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce",e))(J1||{});function vd(e){switch(e){case"0x534e5f4d41494e":return"0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";case"0x534e5f474f45524c49":return"0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce";default:throw new Error("Starknet.id is not yet deployed on this network")}}async function wd(e,t,n){const r=await e.getChainId(),i=n??vd(r);try{const a=(await e.callContract({contractAddress:i,entrypoint:"address_to_domain",calldata:ee.compile({address:t})})).result.map(u=>BigInt(u)).slice(1),s=X1(a);if(!s)throw Error("Starkname not found");return s}catch(o){throw o instanceof Error&&o.message==="Starkname not found"?o:Error("Could not get stark name")}}async function Ed(e,t,n){const r=await e.getChainId(),i=n??vd(r);try{return(await e.callContract({contractAddress:i,entrypoint:"domain_to_address",calldata:ee.compile({domain:[Q1(t.replace(".stark","")).toString(10)]})})).result[0]}catch{throw Error("Could not get address from stark name")}}var Lb=Object.values(Xf),se=class{constructor(e){this.hash=null,this.number=null,this.tag=null,this.valueOf=()=>this.number,this.toString=()=>this.hash,this.setIdentifier(e)}setIdentifier(e){typeof e=="string"&&kt(e)?this.hash=e:typeof e=="bigint"?this.hash=L(e):typeof e=="number"?this.number=e:typeof e=="string"&&Lb.includes(e)?this.tag=e:this.tag="pending"}get queryIdentifier(){return this.number!==null?`blockNumber=${this.number}`:this.hash!==null?`blockHash=${this.hash}`:`blockNumber=${this.tag}`}get identifier(){return this.number!==null?{block_number:this.number}:this.hash!==null?{block_hash:this.hash}:this.tag}set identifier(e){this.setIdentifier(e)}get sequencerIdentifier(){return this.hash!==null?{blockHash:this.hash}:{blockNumber:this.number??this.tag}}},qp=(e,t=!1)=>{t||console.warn("Using default public node url, please provide nodeUrl in provider options!");const n=e==="SN_MAIN"?e1:Jm,r=Math.floor(Math.random()*n.length);return n[r]},lu={headers:{"Content-Type":"application/json"},blockIdentifier:"pending",retries:200},Ha=class{constructor(e){this.responseParser=new bb,this.getBlockHashAndNumber=this.getBlockLatestAccepted,this.getStateUpdate=this.getBlockStateUpdate,this.traceBlockTransactions=this.getBlockTransactionsTraces,this.getTransactionCount=this.getBlockTransactionCount,this.traceTransaction=this.getTransactionTrace,this.getSimulateTransaction=this.simulateTransaction;const{nodeUrl:t,retries:n,headers:r,blockIdentifier:i,chainId:o}=e||{};Object.values(Gf).includes(t)?this.nodeUrl=qp(t,e==null?void 0:e.default):t?this.nodeUrl=t:this.nodeUrl=qp(void 0,e==null?void 0:e.default),this.retries=n||lu.retries,this.headers={...lu.headers,...r},this.blockIdentifier=i||lu.blockIdentifier,this.chainId=o}fetch(e,t,n=0){const r={id:n,jsonrpc:"2.0",method:e,...t&&{params:t}};return G1(this.nodeUrl,{method:"POST",body:St(r),headers:this.headers})}errorHandler(e,t,n,r){if(n){const{code:i,message:o,data:a}=n;throw new pr(`RPC: ${e} with params ${St(t)} ${i}: ${o}: ${St(a)}`)}if(r instanceof pr)throw r;if(r)throw Error(r.message)}async fetchEndpoint(e,t){var n;try{const r=await this.fetch(e,t),{error:i,result:o}=await r.json();return this.errorHandler(e,t,i),o}catch(r){throw this.errorHandler(e,t,(n=r==null?void 0:r.response)==null?void 0:n.data,r),r}}async getChainId(){return this.chainId??(this.chainId=await this.fetchEndpoint("starknet_chainId")),this.chainId}async getSpecVersion(){return this.fetchEndpoint("starknet_specVersion")}async getNonceForAddress(e,t=this.blockIdentifier){const n=L(e),r=new se(t).identifier;return this.fetchEndpoint("starknet_getNonce",{contract_address:n,block_id:r})}async getBlock(e=this.blockIdentifier){return this.getBlockWithTxHashes(e).then(this.responseParser.parseGetBlockResponse)}async getBlockLatestAccepted(){return this.fetchEndpoint("starknet_blockHashAndNumber")}async getBlockNumber(){return this.fetchEndpoint("starknet_blockNumber")}async getBlockWithTxHashes(e=this.blockIdentifier){const t=new se(e).identifier;return this.fetchEndpoint("starknet_getBlockWithTxHashes",{block_id:t})}async getBlockWithTxs(e=this.blockIdentifier){const t=new se(e).identifier;return this.fetchEndpoint("starknet_getBlockWithTxs",{block_id:t})}async getBlockStateUpdate(e=this.blockIdentifier){const t=new se(e).identifier;return this.fetchEndpoint("starknet_getStateUpdate",{block_id:t})}async getBlockTransactionsTraces(e=this.blockIdentifier){const t=new se(e).identifier;return this.fetchEndpoint("starknet_traceBlockTransactions",{block_id:t})}async getBlockTransactionCount(e=this.blockIdentifier){const t=new se(e).identifier;return this.fetchEndpoint("starknet_getBlockTransactionCount",{block_id:t})}async getPendingTransactions(){const{transactions:e}=await this.getBlock("pending");return Promise.all(e.map(t=>this.getTransactionByHash(t)))}async getTransaction(e){return this.getTransactionByHash(e).then(this.responseParser.parseGetTransactionResponse)}async getTransactionByHash(e){const t=L(e);return this.fetchEndpoint("starknet_getTransactionByHash",{transaction_hash:t})}async getTransactionByBlockIdAndIndex(e,t){const n=new se(e).identifier;return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex",{block_id:n,index:t})}async getTransactionReceipt(e){const t=L(e);return this.fetchEndpoint("starknet_getTransactionReceipt",{transaction_hash:t})}async getTransactionTrace(e){const t=L(e);return this.fetchEndpoint("starknet_traceTransaction",{transaction_hash:t})}async getTransactionStatus(e){const t=L(e);return this.fetchEndpoint("starknet_getTransactionStatus",{transaction_hash:t})}async simulateTransaction(e,{blockIdentifier:t=this.blockIdentifier,skipValidate:n=!1,skipFeeCharge:r=!0}){const i=new se(t).identifier,o=[];return n&&o.push(Me.ESimulationFlag.SKIP_VALIDATE),r&&o.push(Me.ESimulationFlag.SKIP_FEE_CHARGE),this.fetchEndpoint("starknet_simulateTransactions",{block_id:i,transactions:e.map(a=>this.buildTransaction(a)),simulation_flags:o}).then(this.responseParser.parseSimulateTransactionResponse)}async waitForTransaction(e,t){const n=L(e);let{retries:r}=this,i=!1,o=!1;const a=(t==null?void 0:t.retryInterval)??5e3,s=(t==null?void 0:t.errorStates)??[Me.ETransactionStatus.REJECTED,Me.ETransactionExecutionStatus.REVERTED],u=(t==null?void 0:t.successStates)??[Me.ETransactionExecutionStatus.SUCCEEDED,Me.ETransactionStatus.ACCEPTED_ON_L2,Me.ETransactionStatus.ACCEPTED_ON_L1];let l;for(;!i;){await Ss(a);try{l=await this.getTransactionStatus(n);const f=l.execution_status,p=l.finality_status;if(!p)throw new Error("waiting for transaction status");if(u.includes(f)||u.includes(p))i=!0;else if(s.includes(f)||s.includes(p)){const y=`${f}: ${p}`,m=new Error(y);throw m.response=l,o=!0,m}}catch(f){if(f instanceof Error&&o)throw f;if(r<=0)throw new Error(`waitForTransaction timed-out with retries ${this.retries}`)}r-=1}let c=null;for(;c===null;){try{c=await this.getTransactionReceipt(n)}catch{if(r<=0)throw new Error(`waitForTransaction timed-out with retries ${this.retries}`)}r-=1,await Ss(a)}return c}async getStorageAt(e,t,n=this.blockIdentifier){const r=L(e),i=y1(t),o=new se(n).identifier;return this.fetchEndpoint("starknet_getStorageAt",{contract_address:r,key:i,block_id:o})}async getClassHashAt(e,t=this.blockIdentifier){const n=L(e),r=new se(t).identifier;return this.fetchEndpoint("starknet_getClassHashAt",{block_id:r,contract_address:n})}async getClassByHash(e){return this.getClass(e)}async getClass(e,t=this.blockIdentifier){const n=L(e),r=new se(t).identifier;return this.fetchEndpoint("starknet_getClass",{class_hash:n,block_id:r}).then(this.responseParser.parseContractClassResponse)}async getClassAt(e,t=this.blockIdentifier){const n=L(e),r=new se(t).identifier;return this.fetchEndpoint("starknet_getClassAt",{block_id:r,contract_address:n}).then(this.responseParser.parseContractClassResponse)}async getCode(e,t){throw new Error("RPC does not implement getCode function")}async getContractVersion(e,t,{blockIdentifier:n=this.blockIdentifier,compiler:r=!0}={}){let i;if(e)i=await this.getClassAt(e,n);else if(t)i=await this.getClass(t,n);else throw Error("getContractVersion require contractAddress or classHash");return An(i)?r?{cairo:"1",compiler:cl(i.abi).compiler}:{cairo:"1",compiler:void 0}:{cairo:"0",compiler:"0"}}async getEstimateFee(e,t,n=this.blockIdentifier){return this.getInvokeEstimateFee(e,t,n)}async getInvokeEstimateFee(e,t,n=this.blockIdentifier){const r=new se(n).identifier,i=this.buildTransaction({type:"INVOKE_FUNCTION",...e,...t},"fee");return this.fetchEndpoint("starknet_estimateFee",{request:[i],block_id:r}).then(this.responseParser.parseFeeEstimateResponse)}async getDeclareEstimateFee(e,t,n=this.blockIdentifier){const r=new se(n).identifier,i=this.buildTransaction({type:"DECLARE",...e,...t},"fee");return this.fetchEndpoint("starknet_estimateFee",{request:[i],block_id:r}).then(this.responseParser.parseFeeEstimateResponse)}async getDeployAccountEstimateFee(e,t,n=this.blockIdentifier){const r=new se(n).identifier,i=this.buildTransaction({type:"DEPLOY_ACCOUNT",...e,...t},"fee");return this.fetchEndpoint("starknet_estimateFee",{request:[i],block_id:r}).then(this.responseParser.parseFeeEstimateResponse)}async getEstimateFeeBulk(e,{blockIdentifier:t=this.blockIdentifier,skipValidate:n=!1}){n&&console.warn("getEstimateFeeBulk RPC does not support skipValidate");const r=new se(t).identifier;return this.fetchEndpoint("starknet_estimateFee",{request:e.map(i=>this.buildTransaction(i,"fee")),block_id:r}).then(this.responseParser.parseFeeEstimateBulkResponse)}async invokeFunction(e,t){return this.fetchEndpoint("starknet_addInvokeTransaction",{invoke_transaction:{sender_address:e.contractAddress,calldata:ee.toHex(e.calldata),type:Me.ETransactionType.INVOKE,max_fee:L(t.maxFee||0),version:"0x1",signature:Nr(e.signature),nonce:L(t.nonce)}})}async declareContract({contract:e,signature:t,senderAddress:n,compiledClassHash:r},i){return An(e)?this.fetchEndpoint("starknet_addDeclareTransaction",{declare_transaction:{type:Me.ETransactionType.DECLARE,contract_class:{sierra_program:xc(e.sierra_program),contract_class_version:e.contract_class_version,entry_points_by_type:e.entry_points_by_type,abi:e.abi},compiled_class_hash:r||"",version:Zm,max_fee:L(i.maxFee||0),signature:Nr(t),sender_address:n,nonce:L(i.nonce)}}):this.fetchEndpoint("starknet_addDeclareTransaction",{declare_transaction:{type:Me.ETransactionType.DECLARE,contract_class:{program:e.program,entry_points_by_type:e.entry_points_by_type,abi:e.abi},version:Vm,max_fee:L(i.maxFee||0),signature:Nr(t),sender_address:n,nonce:L(i.nonce)}})}async deployAccountContract({classHash:e,constructorCalldata:t,addressSalt:n,signature:r},i){return this.fetchEndpoint("starknet_addDeployAccountTransaction",{deploy_account_transaction:{constructor_calldata:ee.toHex(t||[]),class_hash:L(e),contract_address_salt:L(n||0),type:Me.ETransactionType.DEPLOY_ACCOUNT,max_fee:L(i.maxFee||0),version:L(i.version||0),signature:Nr(r),nonce:L(i.nonce)}})}async callContract(e,t=this.blockIdentifier){const n=new se(t).identifier,r=await this.fetchEndpoint("starknet_call",{request:{contract_address:e.contractAddress,entry_point_selector:Ct(e.entrypoint),calldata:ee.toHex(e.calldata)},block_id:n});return this.responseParser.parseCallContractResponse(r)}async estimateMessageFee(e,t=this.blockIdentifier){const{from_address:n,to_address:r,entry_point_selector:i,payload:o}=e,a={from_address:L(n),to_address:L(r),entry_point_selector:ol(i),payload:ed(o)},s=new se(t).identifier;return this.fetchEndpoint("starknet_estimateMessageFee",{message:a,block_id:s})}async getSyncingStats(){return this.fetchEndpoint("starknet_syncing")}async getEvents(e){return this.fetchEndpoint("starknet_getEvents",{filter:e})}async getStarkName(e,t){return wd(this,e,t)}async getAddressFromStarkName(e,t){return Ed(this,e,t)}buildTransaction(e,t){const n=gd(t),r={signature:Nr(e.signature),nonce:L(e.nonce),max_fee:L(e.maxFee||0)};if(e.type==="INVOKE_FUNCTION")return{type:Me.ETransactionType.INVOKE,sender_address:e.contractAddress,calldata:ee.toHex(e.calldata),version:L(e.version||n.v1),...r};if(e.type==="DECLARE")return An(e.contract)?{type:e.type,contract_class:{...e.contract,sierra_program:xc(e.contract.sierra_program)},compiled_class_hash:e.compiledClassHash||"",sender_address:e.senderAddress,version:L(e.version||n.v2),...r}:{type:e.type,contract_class:e.contract,sender_address:e.senderAddress,version:L(e.version||n.v1),...r};if(e.type==="DEPLOY_ACCOUNT")return{type:e.type,constructor_calldata:ee.toHex(e.constructorCalldata||[]),class_hash:L(e.classHash),contract_address_salt:L(e.addressSalt||0),version:L(e.version||n.v1),...r};throw Error("RPC buildTransaction received unknown TransactionType")}},Bb=class{},Pb=class extends Bb{parseGetBlockResponse(e){return{...e,new_root:e.state_root,parent_hash:e.parent_block_hash,transactions:Object.values(e.transactions).map(t=>"transaction_hash"in t&&t.transaction_hash).filter(Boolean)}}parseGetTransactionResponse(e){if(e.status==="NOT_RECEIVED"&&e.finality_status==="NOT_RECEIVED")throw new pr;return{...e,calldata:"calldata"in e.transaction?e.transaction.calldata:[],contract_class:"contract_class"in e.transaction?e.transaction.contract_class:void 0,entry_point_selector:"entry_point_selector"in e.transaction?e.transaction.entry_point_selector:void 0,max_fee:"max_fee"in e.transaction?e.transaction.max_fee:void 0,nonce:e.transaction.nonce,sender_address:"sender_address"in e.transaction?e.transaction.sender_address:void 0,signature:"signature"in e.transaction?e.transaction.signature:void 0,transaction_hash:"transaction_hash"in e.transaction?e.transaction.transaction_hash:void 0,version:"version"in e.transaction?e.transaction.version:void 0}}parseGetTransactionReceiptResponse(e){return{...e,messages_sent:e.l2_to_l1_messages,..."revert_error"in e&&{revert_reason:e.revert_error}}}parseFeeEstimateResponse(e){if("overall_fee"in e){let t={};try{t={gas_consumed:H(e.gas_usage),gas_price:H(e.gas_price)}}catch{}return{overall_fee:H(e.overall_fee),...t}}return{overall_fee:H(e.amount)}}parseFeeEstimateBulkResponse(e){return[].concat(e).map(t=>{if("overall_fee"in t){let n={};try{n={gas_consumed:H(t.gas_usage),gas_price:H(t.gas_price)}}catch{}return{overall_fee:H(t.overall_fee),...n}}return{overall_fee:H(t.amount)}})}parseSimulateTransactionResponse(e){const t="overall_fee"in e.fee_estimation?e.fee_estimation.overall_fee:e.fee_estimation.amount;return[{transaction_trace:e.trace,fee_estimation:e.fee_estimation,suggestedMaxFee:_d(BigInt(t))}]}parseCallContractResponse(e){return{result:e.result}}parseInvokeFunctionResponse(e){return{transaction_hash:e.transaction_hash}}parseDeployContractResponse(e){return{transaction_hash:e.transaction_hash,contract_address:e.address}}parseDeclareContractResponse(e){return{transaction_hash:e.transaction_hash,class_hash:e.class_hash}}parseGetStateUpdateResponse(e){const t=Object.entries(e.state_diff.nonces).map(([r,i])=>({contract_address:r,nonce:i})),n=Object.entries(e.state_diff.storage_diffs).map(([r,i])=>({address:r,storage_entries:i}));return{...e,state_diff:{...e.state_diff,storage_diffs:n,nonces:t}}}parseContractClassResponse(e){const t=An(e)?e:Y1(e);return{...t,abi:typeof t.abi=="string"?JSON.parse(t.abi):t.abi}}},Db=/^(?:\w+:)?\/\/(\S+)$/,Ub=/^localhost[:?\d]*(?:[^:?\d]\S*)?$/,$b=/^[^\s.]+\.\S{2,}$/;function zb(e){if(!e||typeof e!="string")return!1;const t=e.match(Db);if(!t)return!1;const n=t[1];return n?!!(Ub.test(n)||$b.test(n)):!1}function Ui(e,t,n){return zb(n)?n:Dm(e,n??t)}function Mb(e){return e===void 0||Object.keys(e).length===0||Object.keys(e).length===1&&Object.entries(e).every(([t,n])=>t==="blockIdentifier"&&n===null)}var Yp={network:"SN_GOERLI",blockIdentifier:"pending"},xs=class{constructor(e=Yp){this.responseParser=new Pb,"network"in e?(this.baseUrl=xs.getNetworkFromName(e.network),this.feederGatewayUrl=Ui(this.baseUrl,"feeder_gateway"),this.gatewayUrl=Ui(this.baseUrl,"gateway")):(this.baseUrl=e.baseUrl,this.feederGatewayUrl=Ui(this.baseUrl,"feeder_gateway",e.feederGatewayUrl),this.gatewayUrl=Ui(this.baseUrl,"gateway",e.gatewayUrl)),this.chainId=(e==null?void 0:e.chainId)??xs.getChainIdFromBaseUrl(this.baseUrl),this.headers=e.headers,this.blockIdentifier=(e==null?void 0:e.blockIdentifier)||Yp.blockIdentifier}static getNetworkFromName(e){switch(e){case"SN_MAIN":case"0x534e5f4d41494e":return"https://alpha-mainnet.starknet.io";case"SN_GOERLI":case"0x534e5f474f45524c49":return"https://alpha4.starknet.io";default:throw new Error("Could not detect base url from NetworkName")}}static getChainIdFromBaseUrl(e){try{return new URL(e).host.includes("mainnet.starknet.io")?"0x534e5f4d41494e":"0x534e5f474f45524c49"}catch{return console.error(`Could not parse baseUrl: ${e}`),"0x534e5f474f45524c49"}}getFetchUrl(e){return["add_transaction"].includes(e)?this.gatewayUrl:this.feederGatewayUrl}getFetchMethod(e){return["add_transaction","call_contract","estimate_fee","estimate_message_fee","estimate_fee_bulk","simulate_transaction"].includes(e)?"POST":"GET"}getQueryString(e){return Mb(e)?"":`?${Object.entries(e).map(([n,r])=>n==="blockIdentifier"?`${new se(r).queryIdentifier}`:`${n}=${r}`).join("&")}`}getHeaders(e){return e==="POST"?{"Content-Type":"application/json",...this.headers}:this.headers}async fetchEndpoint(e,...[t,n]){const r=this.getFetchUrl(e),i=this.getFetchMethod(e),o=this.getQueryString(t),a=Dm(r,e,o);return this.fetch(a,{method:i,body:n})}async fetch(e,t){const n=Ui(this.baseUrl,"",e),r=(t==null?void 0:t.method)??"GET",i=this.getHeaders(r),o=St(t==null?void 0:t.body);try{const a=await G1(n,{method:r,body:o,headers:i}),s=await a.text();if(!a.ok){let l;try{l=Dn(s)}catch{throw new Rb(a.statusText,a.status)}throw new Ib(l.message,l.code)}return(t!=null&&t.parseAlwaysAsBigInt?M1:Dn)(s)}catch(a){throw a instanceof Error&&!(a instanceof pr)?Error(`Could not ${r} from endpoint \`${n}\`: ${a.message}`):a}}async getChainId(){return Promise.resolve(this.chainId)}async callContract({contractAddress:e,entrypoint:t,calldata:n=[]},r=this.blockIdentifier){return this.fetchEndpoint("call_contract",{blockIdentifier:r},{contract_address:e,entry_point_selector:Ct(t),calldata:ee.compile(n)}).then(this.responseParser.parseCallContractResponse)}async getBlock(e=this.blockIdentifier){return this.fetchEndpoint("get_block",{blockIdentifier:e}).then(this.responseParser.parseGetBlockResponse)}async getNonceForAddress(e,t=this.blockIdentifier){return this.fetchEndpoint("get_nonce",{contractAddress:e,blockIdentifier:t})}async getStorageAt(e,t,n=this.blockIdentifier){const r=H(t).toString(10);return this.fetchEndpoint("get_storage_at",{blockIdentifier:n,contractAddress:e,key:r})}async getTransaction(e){const t=L(e);return this.fetchEndpoint("get_transaction",{transactionHash:t}).then(n=>{if(Object.values(n).length===1)throw new pr(n.status);return this.responseParser.parseGetTransactionResponse(n)})}async getTransactionReceipt(e){const t=L(e);return this.fetchEndpoint("get_transaction_receipt",{transactionHash:t}).then(this.responseParser.parseGetTransactionReceiptResponse)}async getClassAt(e,t=this.blockIdentifier){return this.fetchEndpoint("get_full_contract",{blockIdentifier:t,contractAddress:e}).then(this.responseParser.parseContractClassResponse)}async getClassHashAt(e,t=this.blockIdentifier){return this.fetchEndpoint("get_class_hash_at",{blockIdentifier:t,contractAddress:e})}async getClassByHash(e,t=this.blockIdentifier){return this.fetchEndpoint("get_class_by_hash",{classHash:e,blockIdentifier:t}).then(this.responseParser.parseContractClassResponse)}async getCompiledClassByClassHash(e,t=this.blockIdentifier){return this.fetchEndpoint("get_compiled_class_by_class_hash",{classHash:e,blockIdentifier:t})}async getContractVersion(e,t,{blockIdentifier:n=this.blockIdentifier,compiler:r=!0}={}){let i;if(e)i=await this.getClassAt(e,n);else if(t)i=await this.getClassByHash(t,n);else throw Error("getContractVersion require contractAddress or classHash");return An(i)?r?{cairo:"1",compiler:cl(i.abi).compiler}:{cairo:"1",compiler:void 0}:{cairo:"0",compiler:"0"}}async invokeFunction(e,t){return this.fetchEndpoint("add_transaction",void 0,{type:"INVOKE_FUNCTION",sender_address:e.contractAddress,calldata:ee.compile(e.calldata??[]),signature:Tr(e.signature),nonce:L(t.nonce),max_fee:L(t.maxFee||0),version:"0x1"}).then(this.responseParser.parseInvokeFunctionResponse)}async deployAccountContract({classHash:e,constructorCalldata:t,addressSalt:n,signature:r},i){return this.fetchEndpoint("add_transaction",void 0,{type:"DEPLOY_ACCOUNT",contract_address_salt:n??W1(),constructor_calldata:ee.compile(t??[]),class_hash:L(e),max_fee:L(i.maxFee||0),version:L(i.version||0),nonce:L(i.nonce),signature:Tr(r)}).then(this.responseParser.parseDeployContractResponse)}async declareContract({senderAddress:e,contract:t,signature:n,compiledClassHash:r},i){return An(t)?this.fetchEndpoint("add_transaction",void 0,{type:"DECLARE",sender_address:e,compiled_class_hash:r,contract_class:t,nonce:L(i.nonce),signature:Tr(n),max_fee:L(i.maxFee||0),version:L(pd)}).then(this.responseParser.parseDeclareContractResponse):this.fetchEndpoint("add_transaction",void 0,{type:"DECLARE",contract_class:t,nonce:L(i.nonce),signature:Tr(n),sender_address:e,max_fee:L(i.maxFee||0),version:L(hd)}).then(this.responseParser.parseDeclareContractResponse)}async getEstimateFee(e,t,n=this.blockIdentifier,r=!1){return this.getInvokeEstimateFee(e,t,n,r)}async getInvokeEstimateFee(e,t,n=this.blockIdentifier,r=!1){const i=this.buildTransaction({type:"INVOKE_FUNCTION",...e,...t},"fee");return this.fetchEndpoint("estimate_fee",{blockIdentifier:n,skipValidate:r},i).then(this.responseParser.parseFeeEstimateResponse)}async getDeclareEstimateFee(e,t,n=this.blockIdentifier,r=!1){const i=this.buildTransaction({type:"DECLARE",...e,...t},"fee");return this.fetchEndpoint("estimate_fee",{blockIdentifier:n,skipValidate:r},i).then(this.responseParser.parseFeeEstimateResponse)}async getDeployAccountEstimateFee(e,t,n=this.blockIdentifier,r=!1){const i=this.buildTransaction({type:"DEPLOY_ACCOUNT",...e,...t},"fee");return this.fetchEndpoint("estimate_fee",{blockIdentifier:n,skipValidate:r},i).then(this.responseParser.parseFeeEstimateResponse)}async getEstimateFeeBulk(e,{blockIdentifier:t=this.blockIdentifier,skipValidate:n=!1}){const r=e.map(i=>this.buildTransaction(i,"fee"));return this.fetchEndpoint("estimate_fee_bulk",{blockIdentifier:t,skipValidate:n},r).then(this.responseParser.parseFeeEstimateBulkResponse)}async getCode(e,t=this.blockIdentifier){return this.fetchEndpoint("get_code",{contractAddress:e,blockIdentifier:t})}async waitForTransaction(e,t){let n,r=!1,i=0;const o=(t==null?void 0:t.retryInterval)??5e3,a=(t==null?void 0:t.errorStates)??["REJECTED","NOT_RECEIVED","REVERTED"],s=(t==null?void 0:t.successStates)??["SUCCEEDED","ACCEPTED_ON_L1","ACCEPTED_ON_L2"];for(;!r;)if(await Ss(o),n=await this.getTransactionStatus(e),n.finality_status==="NOT_RECEIVED"&&i<3)i+=1;else if(s.includes(n.finality_status)||s.includes(n.execution_status))r=!0;else if(a.includes(n.finality_status)||a.includes(n.execution_status)){let l;n.tx_failure_reason?l=`${n.tx_status}: ${n.tx_failure_reason.code} -${n.tx_failure_reason.error_message}`:n.tx_revert_reason?l=`${n.tx_status}: ${n.tx_revert_reason}`:l=n.tx_status;const c=new Error(l);throw c.response=n,c}return await this.getTransactionReceipt(e)}async getTransactionStatus(e){const t=L(e);return this.fetchEndpoint("get_transaction_status",{transactionHash:t})}async getContractAddresses(){return this.fetchEndpoint("get_contract_addresses")}async getTransactionTrace(e){const t=L(e);return this.fetchEndpoint("get_transaction_trace",{transactionHash:t})}async estimateMessageFee({from_address:e,to_address:t,entry_point_selector:n,payload:r},i=this.blockIdentifier){const o={from_address:w1(e),to_address:Jf(t),entry_point_selector:ol(n),payload:ed(r)};return this.fetchEndpoint("estimate_message_fee",{blockIdentifier:i},o)}async getSimulateTransaction(e,{blockIdentifier:t=this.blockIdentifier,skipValidate:n=!1,skipExecute:r=!1}){e.length>1&&console.warn("Sequencer simulate process only first element from invocations list"),r&&console.warn("Sequencer can't skip account __execute__");const i=this.buildTransaction(e[0]);return this.fetchEndpoint("simulate_transaction",{blockIdentifier:t,skipValidate:n??!1},i).then(this.responseParser.parseSimulateTransactionResponse)}async getStateUpdate(e=this.blockIdentifier){const t=new se(e).sequencerIdentifier;return this.fetchEndpoint("get_state_update",{...t}).then(this.responseParser.parseGetStateUpdateResponse)}async getBlockTraces(e=this.blockIdentifier){const t=new se(e).sequencerIdentifier;return this.fetchEndpoint("get_block_traces",{...t})}async getStarkName(e,t){return wd(this,e,t)}async getAddressFromStarkName(e,t){return Ed(this,e,t)}buildTransaction(e,t){const n=gd(t),r={signature:Tr(e.signature),nonce:L(e.nonce)};if(e.type==="INVOKE_FUNCTION")return{type:e.type,sender_address:e.contractAddress,calldata:ee.compile(e.calldata??[]),version:L(e.version||n.v1),...r};if(e.type==="DECLARE")return An(e.contract)?{type:e.type,contract_class:e.contract,compiled_class_hash:e.compiledClassHash,sender_address:e.senderAddress,version:L(e.version||n.v2),...r}:{type:e.type,contract_class:e.contract,sender_address:e.senderAddress,version:L(e.version||n.v1),...r};if(e.type==="DEPLOY_ACCOUNT")return{type:e.type,constructor_calldata:ee.compile(e.constructorCalldata||[]),class_hash:L(e.classHash),contract_address_salt:L(e.addressSalt||0),version:L(e.version||n.v1),...r};throw Error("Sequencer buildTransaction received unknown TransactionType")}},e_=class{constructor(e){e instanceof e_?this.provider=e.provider:e instanceof Ha||e instanceof xs?this.provider=e:e&&"rpc"in e?this.provider=new Ha(e.rpc):e&&"sequencer"in e?this.provider=new xs(e.sequencer):this.provider=new Ha}async getChainId(){return this.provider.getChainId()}async getBlock(e){return this.provider.getBlock(e)}async getClassAt(e,t){return this.provider.getClassAt(e,t)}async getClassHashAt(e,t){return this.provider.getClassHashAt(e,t)}getClassByHash(e){return this.provider.getClassByHash(e)}async getEstimateFee(e,t,n){return this.provider.getEstimateFee(e,t,n)}async getInvokeEstimateFee(e,t,n,r){return this.provider.getInvokeEstimateFee(e,t,n,r)}async getEstimateFeeBulk(e,t){return this.provider.getEstimateFeeBulk(e,t)}async getNonceForAddress(e,t){return this.provider.getNonceForAddress(e,t)}async getStorageAt(e,t,n){return this.provider.getStorageAt(e,t,n)}async getTransaction(e){return this.provider.getTransaction(e)}async getTransactionReceipt(e){return this.provider.getTransactionReceipt(e)}async callContract(e,t){return this.provider.callContract(e,t)}async invokeFunction(e,t){return this.provider.invokeFunction(e,t)}async deployAccountContract(e,t){return this.provider.deployAccountContract(e,t)}async declareContract(e,t){return this.provider.declareContract(e,t)}async getDeclareEstimateFee(e,t,n,r){return this.provider.getDeclareEstimateFee(e,t,n,r)}getDeployAccountEstimateFee(e,t,n,r){return this.provider.getDeployAccountEstimateFee(e,t,n,r)}async getCode(e,t){return this.provider.getCode(e,t)}async waitForTransaction(e,t){return this.provider.waitForTransaction(e,t)}async getSimulateTransaction(e,t){return this.provider.getSimulateTransaction(e,t)}async getStateUpdate(e){return this.provider.getStateUpdate(e)}async getStarkName(e,t){return wd(this,e,t)}async getAddressFromStarkName(e,t){return Ed(this,e,t)}async getContractVersion(e,t,n){return this.provider.getContractVersion(e,t,n)}},Hb={};pe(Hb,{fromCallsToExecuteCalldata:()=>Sd,fromCallsToExecuteCalldataWithNonce:()=>Fb,fromCallsToExecuteCalldata_cairo1:()=>n_,getExecuteCalldata:()=>Vb,transformCallsToMulticallArrays:()=>t_,transformCallsToMulticallArrays_cairo1:()=>jb});var t_=e=>{const t=[],n=[];return e.forEach(r=>{const i=ee.compile(r.calldata||[]);t.push({to:H(r.contractAddress).toString(10),selector:H(Ct(r.entrypoint)).toString(10),data_offset:n.length.toString(),data_len:i.length.toString()}),n.push(...i)}),{callArray:t,calldata:ee.compile({calldata:n})}},Sd=e=>{const{callArray:t,calldata:n}=t_(e);return[...ee.compile({callArray:t}),...n]},Fb=(e,t)=>[...Sd(e),H(t).toString()],jb=e=>e.map(n=>({to:H(n.contractAddress).toString(10),selector:H(Ct(n.entrypoint)).toString(10),calldata:ee.compile(n.calldata||[])})),n_=e=>{const t=e.map(n=>({contractAddress:n.contractAddress,entrypoint:n.entrypoint,calldata:Array.isArray(n.calldata)&&"__compiled__"in n.calldata?n.calldata:ee.compile(n.calldata)}));return ee.compile({orderCalls:t})},Vb=(e,t="0")=>t==="1"?n_(e):Sd(e),Zb={};pe(Zb,{encodeData:()=>l_,encodeType:()=>a_,encodeValue:()=>kd,getDependencies:()=>xd,getMessageHash:()=>Yb,getStructHash:()=>Bo,getTypeHash:()=>s_,isMerkleTreeType:()=>o_,prepareSelector:()=>i_});var Kb={};pe(Kb,{MerkleTree:()=>Yr,proofMerklePath:()=>r_});var Yr=class{constructor(e){this.branches=[],this.leaves=e,this.root=this.build(e)}build(e){if(e.length===1)return e[0];e.length!==this.leaves.length&&this.branches.push(e);const t=[];for(let n=0;ni>=o?1:-1);return el(n,r)}getProof(e,t=this.leaves,n=[]){const r=t.indexOf(e);if(r===-1)throw new Error("leaf not found");if(t.length===1)return n;const i=r%2===0,o=(i?t[r+1]:t[r-1])??"0x0",a=[...n,o],s=this.leaves.length===t.length?-1:this.branches.findIndex(l=>l.length===t.length),u=this.branches[s+1]??[this.root];return this.getProof(Yr.hash(i?e:o,i?o:e),u,a)}};function r_(e,t,n){if(n.length===0)return e===t;const[r,...i]=n;return r_(e,Yr.hash(t,r),i)}function Wb(e){try{return L(e)}catch{if(typeof e=="string")return L(Mn(e));throw new Error(`Invalid BigNumberish: ${e}`)}}var Gb=e=>{const t=e;return!!(t.types&&t.primaryType&&t.message)};function i_(e){return kt(e)?e:Ct(e)}function o_(e){return e.type==="merkletree"}var xd=(e,t,n=[])=>(t[t.length-1]==="*"&&(t=t.slice(0,-1)),n.includes(t)||!e[t]?n:[t,...e[t].reduce((r,i)=>[...r,...xd(e,i.type,r).filter(o=>!r.includes(o))],[])]);function qb(e,t){if(t.parent&&t.key){const r=e[t.parent].find(o=>o.name===t.key);if(!o_(r))throw new Error(`${t.key} is not a merkle tree`);if(r.contains.endsWith("*"))throw new Error(`Merkle tree contain property must not be an array but was given ${t.key}`);return r.contains}return"raw"}var a_=(e,t)=>{const[n,...r]=xd(e,t);return(n?[n,...r.sort()]:[]).map(o=>`${o}(${e[o].map(a=>`${a.name}:${a.type}`)})`).join("")},s_=(e,t)=>Ct(a_(e,t)),kd=(e,t,n,r={})=>{if(e[t])return[t,Bo(e,t,n)];if(Object.keys(e).map(i=>`${i}*`).includes(t)){const i=n.map(o=>Bo(e,t.slice(0,-1),o));return[t,Le(i)]}if(t==="merkletree"){const i=qb(e,r),o=n.map(s=>kd(e,i,s)[1]),{root:a}=new Yr(o);return["felt",a]}return t==="felt*"?["felt*",Le(n)]:t==="selector"?["felt",i_(n)]:[t,Wb(n)]},l_=(e,t,n)=>{const[r,i]=e[t].reduce(([o,a],s)=>{if(n[s.name]===void 0||n[s.name]===null)throw new Error(`Cannot encode data: missing data for '${s.name}'`);const u=n[s.name],[l,c]=kd(e,s.type,u,{parent:t,key:s.name});return[[...o,l],[...a,c]]},[["felt"],[s_(e,t)]]);return[r,i]},Bo=(e,t,n)=>Le(l_(e,t,n)[1]),Yb=(e,t)=>{if(!Gb(e))throw new Error("Typed data does not match JSON schema");const n=[Mn("StarkNet Message"),Bo(e.types,"StarkNetDomain",e.domain),t,Bo(e.types,e.primaryType,e.message)];return Le(n)};new e_({rpc:{default:!0}});var Xb={};pe(Xb,{getAbiEvents:()=>Qb,parseEvents:()=>Jb});function Qb(e){return e.filter(t=>t.type==="event"&&(t.size||t.kind!=="enum")).reduce((t,n)=>{const r=n.name.slice(n.name.lastIndexOf(":")+1),i={...n};return i.name=r,{...t,[Ue(yi(Si(r)).toString(16))]:i}},{})}function Jb(e,t,n,r){return e.flat().reduce((o,a)=>{var y,m;const s=t[a.keys[0]];if(!s)return o;const u={};u[s.name]={},a.keys.shift();const l=a.keys[Symbol.iterator](),c=a.data[Symbol.iterator](),f=((y=s.members)==null?void 0:y.filter(_=>_.kind==="key"))||s.keys,p=((m=s.members)==null?void 0:m.filter(_=>_.kind==="data"))||s.data;return f.forEach(_=>{u[s.name][_.name]=Sc(l,_,n,r,u[s.name])}),p.forEach(_=>{u[s.name][_.name]=Sc(c,_,n,r,u[s.name])}),o.push(u),o},[])}const jn=window.Telegram.WebApp;new Ha({nodeUrl:"https://starknet-sepolia.public.blastapi.io/rpc/v0_7"});function eA(){const[e,t]=G.useState(!1);G.useState("");const[n,r]=G.useState(null),[i,o]=G.useState(""),{unityProvider:a,isLoaded:s,loadingProgression:u,addEventListener:l,removeEventListener:c,sendMessage:f}=So.useUnityContext({productName:"Focus Bear",productVersion:"1.0.0",companyName:"Arism Lab",loaderUrl:"assets/BuildGame.loader.js",dataUrl:"assets/BuildGame.data.unityweb",frameworkUrl:"assets/BuildGame.framework.js.unityweb",codeUrl:"assets/BuildGame.wasm.unityweb",streamingAssetsUrl:"StreamingAssets"}),[p,y]=G.useState(window.devicePixelRatio),m=G.useCallback(g=>{f("DialogCanvas","SetMessageText",g),f("AddressLayout","SetAddress",g)},[f]),_=G.useCallback(g=>{f("DialogCanvas","SetMessageText",g)},[f]),w=G.useCallback(()=>{const g="0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003",v=K1.randomAddress();r(v);const S=z1.starkCurve.getStarkKey(v),x=ee.compile({owner:S,guardian:"0"}),E=$1.calculateContractAddressFromHash(S,g,x,0);o(E)});G.useEffect(()=>{i!=="null"&&(jn.BiometricManager.authenticate({reason:"Authenticate to store private key"},(g,v)=>{if(g){const S=n;jn.BiometricManager.updateBiometricToken(S,x=>{x?m(i):_("Failed to create the Address.")})}else _("Authentication failed.")}),console.log("Updated account address=",i))},[i]);const d=G.useCallback(()=>{w();const g={reason:"Securely store your private key using biometric authentication"};jn.BiometricManager.requestAccess(g,v=>{v?t(!0):(_("Access Denied. Fail to create Account"),t(!1))})},[]),h=G.useCallback(()=>{jn.BiometricManager.authenticate({reason:"Authenticate to retrieve private key"},(g,v)=>{if(g){const S=v.toString();_(S)}else console.error("Authentication failed.")})},[_]);return G.useEffect(()=>{f("MainGameCanvas","HideMainScreen")},[e]),G.useEffect(()=>(l("OnCreateWalletButtonClicked",d),()=>{c("OnCreateWalletButtonClicked",d)}),[l,c,d]),G.useEffect(()=>(l("OnExportKeyButtonClicked",h),()=>{c("OnExportKeyButtonClicked",h)}),[l,c,h]),G.useEffect(function(){jn.ready(),jn.isClosingConfirmationEnabled=!0,jn.BiometricManager.init(()=>{})},[]),G.useEffect(()=>{const g=()=>{y(window.devicePixelRatio)},v=window.matchMedia(`screen and (resolution: ${p}dppx)`);return v.addEventListener("change",g),()=>{v.removeEventListener("change",g)}},[p]),sn.jsxs("div",{id:"unity-container",className:"unity-responsive",children:[sn.jsx(So.Unity,{unityProvider:a,style:{width:"100%",height:"100%"},devicePixelRatio:p}),!s&&sn.jsxs("div",{id:"unity-loading-bar",children:[sn.jsx("div",{id:"unity-logo"}),sn.jsx("div",{id:"unity-progress-bar-empty",children:sn.jsx("div",{id:"unity-progress-bar-full",style:{width:`${u*100}%`}})})]})]})}uu.createRoot(document.getElementById("root")).render(sn.jsx(C_.StrictMode,{children:sn.jsx(eA,{})}))});export default tA(); +${n.tx_failure_reason.error_message}`:n.tx_revert_reason?l=`${n.tx_status}: ${n.tx_revert_reason}`:l=n.tx_status;const c=new Error(l);throw c.response=n,c}return await this.getTransactionReceipt(e)}async getTransactionStatus(e){const t=L(e);return this.fetchEndpoint("get_transaction_status",{transactionHash:t})}async getContractAddresses(){return this.fetchEndpoint("get_contract_addresses")}async getTransactionTrace(e){const t=L(e);return this.fetchEndpoint("get_transaction_trace",{transactionHash:t})}async estimateMessageFee({from_address:e,to_address:t,entry_point_selector:n,payload:r},i=this.blockIdentifier){const o={from_address:w1(e),to_address:Jf(t),entry_point_selector:ol(n),payload:ed(r)};return this.fetchEndpoint("estimate_message_fee",{blockIdentifier:i},o)}async getSimulateTransaction(e,{blockIdentifier:t=this.blockIdentifier,skipValidate:n=!1,skipExecute:r=!1}){e.length>1&&console.warn("Sequencer simulate process only first element from invocations list"),r&&console.warn("Sequencer can't skip account __execute__");const i=this.buildTransaction(e[0]);return this.fetchEndpoint("simulate_transaction",{blockIdentifier:t,skipValidate:n??!1},i).then(this.responseParser.parseSimulateTransactionResponse)}async getStateUpdate(e=this.blockIdentifier){const t=new se(e).sequencerIdentifier;return this.fetchEndpoint("get_state_update",{...t}).then(this.responseParser.parseGetStateUpdateResponse)}async getBlockTraces(e=this.blockIdentifier){const t=new se(e).sequencerIdentifier;return this.fetchEndpoint("get_block_traces",{...t})}async getStarkName(e,t){return wd(this,e,t)}async getAddressFromStarkName(e,t){return Ed(this,e,t)}buildTransaction(e,t){const n=gd(t),r={signature:Tr(e.signature),nonce:L(e.nonce)};if(e.type==="INVOKE_FUNCTION")return{type:e.type,sender_address:e.contractAddress,calldata:ee.compile(e.calldata??[]),version:L(e.version||n.v1),...r};if(e.type==="DECLARE")return An(e.contract)?{type:e.type,contract_class:e.contract,compiled_class_hash:e.compiledClassHash,sender_address:e.senderAddress,version:L(e.version||n.v2),...r}:{type:e.type,contract_class:e.contract,sender_address:e.senderAddress,version:L(e.version||n.v1),...r};if(e.type==="DEPLOY_ACCOUNT")return{type:e.type,constructor_calldata:ee.compile(e.constructorCalldata||[]),class_hash:L(e.classHash),contract_address_salt:L(e.addressSalt||0),version:L(e.version||n.v1),...r};throw Error("Sequencer buildTransaction received unknown TransactionType")}},e_=class{constructor(e){e instanceof e_?this.provider=e.provider:e instanceof Ha||e instanceof xs?this.provider=e:e&&"rpc"in e?this.provider=new Ha(e.rpc):e&&"sequencer"in e?this.provider=new xs(e.sequencer):this.provider=new Ha}async getChainId(){return this.provider.getChainId()}async getBlock(e){return this.provider.getBlock(e)}async getClassAt(e,t){return this.provider.getClassAt(e,t)}async getClassHashAt(e,t){return this.provider.getClassHashAt(e,t)}getClassByHash(e){return this.provider.getClassByHash(e)}async getEstimateFee(e,t,n){return this.provider.getEstimateFee(e,t,n)}async getInvokeEstimateFee(e,t,n,r){return this.provider.getInvokeEstimateFee(e,t,n,r)}async getEstimateFeeBulk(e,t){return this.provider.getEstimateFeeBulk(e,t)}async getNonceForAddress(e,t){return this.provider.getNonceForAddress(e,t)}async getStorageAt(e,t,n){return this.provider.getStorageAt(e,t,n)}async getTransaction(e){return this.provider.getTransaction(e)}async getTransactionReceipt(e){return this.provider.getTransactionReceipt(e)}async callContract(e,t){return this.provider.callContract(e,t)}async invokeFunction(e,t){return this.provider.invokeFunction(e,t)}async deployAccountContract(e,t){return this.provider.deployAccountContract(e,t)}async declareContract(e,t){return this.provider.declareContract(e,t)}async getDeclareEstimateFee(e,t,n,r){return this.provider.getDeclareEstimateFee(e,t,n,r)}getDeployAccountEstimateFee(e,t,n,r){return this.provider.getDeployAccountEstimateFee(e,t,n,r)}async getCode(e,t){return this.provider.getCode(e,t)}async waitForTransaction(e,t){return this.provider.waitForTransaction(e,t)}async getSimulateTransaction(e,t){return this.provider.getSimulateTransaction(e,t)}async getStateUpdate(e){return this.provider.getStateUpdate(e)}async getStarkName(e,t){return wd(this,e,t)}async getAddressFromStarkName(e,t){return Ed(this,e,t)}async getContractVersion(e,t,n){return this.provider.getContractVersion(e,t,n)}},Hb={};pe(Hb,{fromCallsToExecuteCalldata:()=>Sd,fromCallsToExecuteCalldataWithNonce:()=>Fb,fromCallsToExecuteCalldata_cairo1:()=>n_,getExecuteCalldata:()=>Vb,transformCallsToMulticallArrays:()=>t_,transformCallsToMulticallArrays_cairo1:()=>jb});var t_=e=>{const t=[],n=[];return e.forEach(r=>{const i=ee.compile(r.calldata||[]);t.push({to:H(r.contractAddress).toString(10),selector:H(Ct(r.entrypoint)).toString(10),data_offset:n.length.toString(),data_len:i.length.toString()}),n.push(...i)}),{callArray:t,calldata:ee.compile({calldata:n})}},Sd=e=>{const{callArray:t,calldata:n}=t_(e);return[...ee.compile({callArray:t}),...n]},Fb=(e,t)=>[...Sd(e),H(t).toString()],jb=e=>e.map(n=>({to:H(n.contractAddress).toString(10),selector:H(Ct(n.entrypoint)).toString(10),calldata:ee.compile(n.calldata||[])})),n_=e=>{const t=e.map(n=>({contractAddress:n.contractAddress,entrypoint:n.entrypoint,calldata:Array.isArray(n.calldata)&&"__compiled__"in n.calldata?n.calldata:ee.compile(n.calldata)}));return ee.compile({orderCalls:t})},Vb=(e,t="0")=>t==="1"?n_(e):Sd(e),Zb={};pe(Zb,{encodeData:()=>l_,encodeType:()=>a_,encodeValue:()=>kd,getDependencies:()=>xd,getMessageHash:()=>Yb,getStructHash:()=>Bo,getTypeHash:()=>s_,isMerkleTreeType:()=>o_,prepareSelector:()=>i_});var Kb={};pe(Kb,{MerkleTree:()=>Yr,proofMerklePath:()=>r_});var Yr=class{constructor(e){this.branches=[],this.leaves=e,this.root=this.build(e)}build(e){if(e.length===1)return e[0];e.length!==this.leaves.length&&this.branches.push(e);const t=[];for(let n=0;ni>=o?1:-1);return el(n,r)}getProof(e,t=this.leaves,n=[]){const r=t.indexOf(e);if(r===-1)throw new Error("leaf not found");if(t.length===1)return n;const i=r%2===0,o=(i?t[r+1]:t[r-1])??"0x0",a=[...n,o],s=this.leaves.length===t.length?-1:this.branches.findIndex(l=>l.length===t.length),u=this.branches[s+1]??[this.root];return this.getProof(Yr.hash(i?e:o,i?o:e),u,a)}};function r_(e,t,n){if(n.length===0)return e===t;const[r,...i]=n;return r_(e,Yr.hash(t,r),i)}function Wb(e){try{return L(e)}catch{if(typeof e=="string")return L(Mn(e));throw new Error(`Invalid BigNumberish: ${e}`)}}var Gb=e=>{const t=e;return!!(t.types&&t.primaryType&&t.message)};function i_(e){return kt(e)?e:Ct(e)}function o_(e){return e.type==="merkletree"}var xd=(e,t,n=[])=>(t[t.length-1]==="*"&&(t=t.slice(0,-1)),n.includes(t)||!e[t]?n:[t,...e[t].reduce((r,i)=>[...r,...xd(e,i.type,r).filter(o=>!r.includes(o))],[])]);function qb(e,t){if(t.parent&&t.key){const r=e[t.parent].find(o=>o.name===t.key);if(!o_(r))throw new Error(`${t.key} is not a merkle tree`);if(r.contains.endsWith("*"))throw new Error(`Merkle tree contain property must not be an array but was given ${t.key}`);return r.contains}return"raw"}var a_=(e,t)=>{const[n,...r]=xd(e,t);return(n?[n,...r.sort()]:[]).map(o=>`${o}(${e[o].map(a=>`${a.name}:${a.type}`)})`).join("")},s_=(e,t)=>Ct(a_(e,t)),kd=(e,t,n,r={})=>{if(e[t])return[t,Bo(e,t,n)];if(Object.keys(e).map(i=>`${i}*`).includes(t)){const i=n.map(o=>Bo(e,t.slice(0,-1),o));return[t,Le(i)]}if(t==="merkletree"){const i=qb(e,r),o=n.map(s=>kd(e,i,s)[1]),{root:a}=new Yr(o);return["felt",a]}return t==="felt*"?["felt*",Le(n)]:t==="selector"?["felt",i_(n)]:[t,Wb(n)]},l_=(e,t,n)=>{const[r,i]=e[t].reduce(([o,a],s)=>{if(n[s.name]===void 0||n[s.name]===null)throw new Error(`Cannot encode data: missing data for '${s.name}'`);const u=n[s.name],[l,c]=kd(e,s.type,u,{parent:t,key:s.name});return[[...o,l],[...a,c]]},[["felt"],[s_(e,t)]]);return[r,i]},Bo=(e,t,n)=>Le(l_(e,t,n)[1]),Yb=(e,t)=>{if(!Gb(e))throw new Error("Typed data does not match JSON schema");const n=[Mn("StarkNet Message"),Bo(e.types,"StarkNetDomain",e.domain),t,Bo(e.types,e.primaryType,e.message)];return Le(n)};new e_({rpc:{default:!0}});var Xb={};pe(Xb,{getAbiEvents:()=>Qb,parseEvents:()=>Jb});function Qb(e){return e.filter(t=>t.type==="event"&&(t.size||t.kind!=="enum")).reduce((t,n)=>{const r=n.name.slice(n.name.lastIndexOf(":")+1),i={...n};return i.name=r,{...t,[Ue(yi(Si(r)).toString(16))]:i}},{})}function Jb(e,t,n,r){return e.flat().reduce((o,a)=>{var y,m;const s=t[a.keys[0]];if(!s)return o;const u={};u[s.name]={},a.keys.shift();const l=a.keys[Symbol.iterator](),c=a.data[Symbol.iterator](),f=((y=s.members)==null?void 0:y.filter(_=>_.kind==="key"))||s.keys,p=((m=s.members)==null?void 0:m.filter(_=>_.kind==="data"))||s.data;return f.forEach(_=>{u[s.name][_.name]=Sc(l,_,n,r,u[s.name])}),p.forEach(_=>{u[s.name][_.name]=Sc(c,_,n,r,u[s.name])}),o.push(u),o},[])}const jn=window.Telegram.WebApp;new Ha({nodeUrl:"https://starknet-sepolia.public.blastapi.io/rpc/v0_7"});function eA(){const[e,t]=G.useState(!1);G.useState("");const[n,r]=G.useState(null),[i,o]=G.useState(""),{unityProvider:a,isLoaded:s,loadingProgression:u,addEventListener:l,removeEventListener:c,sendMessage:f}=So.useUnityContext({productName:"Focus Bear",productVersion:"1.0.0",companyName:"Arism Lab",loaderUrl:"assets/BuildGame.loader.js",dataUrl:"assets/BuildGame.data.unityweb",frameworkUrl:"assets/BuildGame.framework.js.unityweb",codeUrl:"assets/BuildGame.wasm.unityweb",streamingAssetsUrl:"StreamingAssets"}),[p,y]=G.useState(window.devicePixelRatio),m=G.useCallback(g=>{f("AddressLayout","SetAddress",g)},[f]),_=G.useCallback(g=>{f("DialogCanvas","SetMessageText",g)},[f]),w=G.useCallback(()=>{const g="0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003",v=K1.randomAddress();r(v);const S=z1.starkCurve.getStarkKey(v),x=ee.compile({owner:S,guardian:"0"}),E=$1.calculateContractAddressFromHash(S,g,x,0);o(E)});G.useEffect(()=>{i!=="null"&&(jn.BiometricManager.authenticate({reason:"Authenticate to store private key"},(g,v)=>{if(g){const S=n;jn.BiometricManager.updateBiometricToken(S,x=>{x?m(i):_("Failed to create the Address.")})}else _("Authentication failed.")}),console.log("Updated account address=",i))},[i]);const d=G.useCallback(()=>{w();const g={reason:"Securely store your private key using biometric authentication"};jn.BiometricManager.requestAccess(g,v=>{v?t(!0):(_("Access Denied. Fail to create Account"),t(!1))})},[]),h=G.useCallback(()=>{jn.BiometricManager.authenticate({reason:"Authenticate to retrieve private key"},(g,v)=>{if(g){const S=v.toString();_(S)}else console.error("Authentication failed.")})},[_]);return G.useEffect(()=>{f("MainGameCanvas","HideMainScreen")},[e]),G.useEffect(()=>(l("OnCreateWalletButtonClicked",d),()=>{c("OnCreateWalletButtonClicked",d)}),[l,c,d]),G.useEffect(()=>(l("OnExportKeyButtonClicked",h),()=>{c("OnExportKeyButtonClicked",h)}),[l,c,h]),G.useEffect(function(){jn.ready(),jn.isClosingConfirmationEnabled=!0,jn.BiometricManager.init(()=>{})},[]),G.useEffect(()=>{const g=()=>{y(window.devicePixelRatio)},v=window.matchMedia(`screen and (resolution: ${p}dppx)`);return v.addEventListener("change",g),()=>{v.removeEventListener("change",g)}},[p]),sn.jsxs("div",{id:"unity-container",className:"unity-responsive",children:[sn.jsx(So.Unity,{unityProvider:a,style:{width:"100%",height:"100%"},devicePixelRatio:p}),!s&&sn.jsxs("div",{id:"unity-loading-bar",children:[sn.jsx("div",{id:"unity-logo"}),sn.jsx("div",{id:"unity-progress-bar-empty",children:sn.jsx("div",{id:"unity-progress-bar-full",style:{width:`${u*100}%`}})})]})]})}uu.createRoot(document.getElementById("root")).render(sn.jsx(C_.StrictMode,{children:sn.jsx(eA,{})}))});export default tA(); diff --git a/index.html b/index.html index 36d1628..c85dcd9 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ Focus Bear - +