@onflow/fcl
Advanced tools
Comparing version 0.0.67-alpha.27 to 0.0.67-alpha.28
@@ -5,3 +5,3 @@ ### Unreleased | ||
### 0.0.67-alpha.[19..27] - 2020-11-26 | ||
### 0.0.67-alpha.[19..28] - 2020-11-26 | ||
@@ -8,0 +8,0 @@ - 2020-11-26 -- Early exit `HTTP/POST` so that it can work like an `HTTP/RPC` |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/config"),r=require("@onflow/util-invariant"),n=require("@onflow/interaction"),t=require("@onflow/sdk-latest-block"),o=require("@onflow/util-address"),i=require("@onflow/sdk-account"),u=require("@onflow/rlp"),a=require("@onflow/sdk-resolve"),s=require("@onflow/util-actor"),c=require("@onflow/sdk-send"),f=require("@onflow/sdk-decode"),l=require("@onflow/sdk-build-transaction-status"),d=require("@onflow/sdk-build-get-events"),p=require("@onflow/util-uid"),h=require("@onflow/util-template"),m=require("@onflow/sdk-build-transaction"),v=require("@onflow/sdk-build-script"),y=require("@onflow/sdk-build-ping"),g=require("@onflow/sdk-build-get-account"),P=require("@onflow/sdk-build-get-latest-block"),b=require("@onflow/sdk-build-get-block-by-id"),w=require("@onflow/sdk-build-get-block-by-height"),E=require("@onflow/sdk-build-authorizations"),x=require("@onflow/sdk-build-arguments"),I=require("@onflow/sdk-build-proposer"),k=require("@onflow/sdk-build-payer"),S=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),A=require("@onflow/sdk-build-params");function O(){return(O=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function R(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function C(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return R(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?R(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T=function(e,r){return Buffer.from(e.padStart(2*r,0),"hex")},N=function(e){return T(e,8)},B=function(e){return Buffer.from(JSON.stringify(e),"utf8")},L=function(e){return u.encode(e).toString("hex")},z=function(e){return _(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(B),(r=e.refBlock,T(r,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var r,n},U=function(e){var r=q(e);return e.payloadSigs.map(function(e){return{signerIndex:r.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,r){return e.signerIndex>r.signerIndex?1:e.signerIndex<r.signerIndex?-1:e.keyId>r.keyId?1:e.keyId<r.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(r=e.sig,Buffer.from(r,"hex"))];var r})},q=function(e){var r=new Map,n=0,t=function(e){r.has(e)||(r.set(e,n),n++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),r},_=function(e){J.forEach(function(r){return Y(e,r)}),K.forEach(function(r){return Y(e.proposalKey,r,"proposalKey")})},D=function(e){return"number"==typeof e},F=function(e){return"string"==typeof e},M=function(e){return null!==e&&"object"==typeof e},H=function(e){return M(e)&&e instanceof Array},J=[{name:"script",check:F},{name:"arguments",check:H},{name:"refBlock",check:F,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:M},{name:"payer",check:F},{name:"authorizers",check:H}],K=[{name:"address",check:F},{name:"keyId",check:D},{name:"sequenceNum",check:D}],G=[{name:"payloadSigs",check:H}],V=[{name:"address",check:F},{name:"keyId",check:D},{name:"sig",check:F}],Y=function(e,r,n,t){var o=r.name,i=r.check,u=r.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw W(o,n,t);if(!i(e[o]))throw X(o,n,t)},Z=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},W=function(e,r,n){return new Error("Missing field "+Z(e,r,n))},X=function(e,r,n){return new Error("Invalid field "+Z(e,r,n))},$="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Q(e,r,n){if(!e.s){if(n instanceof ee){if(!n.s)return void(n.o=Q.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Q.bind(null,e,r),Q.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var ee=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Q(t,1,i(this.v))}catch(e){Q(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Q(t,1,r?r(o):o):n?Q(t,1,n(o)):Q(t,2,o)}catch(e){Q(t,2,e)}},t},e}();function re(e){return e instanceof ee&&1&e.s}function ne(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}var te=function e(n,t,o,i){void 0===i&&(i=3);try{r.invariant(i,"Account Resolve Recursion Limit Exceeded",{ix:n,accounts:t}),console.log("resolveAccounts",t,n);var u=function(e,r,n){if("function"==typeof e[$]){var t,o,i,u=e[$]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!re(n))return void n.then(e,i||(i=Q.bind(null,o=new ee,2)));n=n.v}o?Q(o,1,n):o=n}catch(e){Q(o||(o=new ee),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!re(u))return void u.then(n,o||(o=Q.bind(null,t=new ee,2)));u=u.v}t?Q(t,1,u):t=u}catch(e){Q(t||(t=new ee),2,e)}}(),t}(s,function(e){return r(s[e])})}(t,function(r){function t(){function t(){u.tempId!=r.tempId&&delete n.accounts[u.tempId]}console.log(">>>",{old:u,ax:r});var o=function(){if(Array.isArray(r))return console.log("RECURSE!!",r),Promise.resolve(e(n,r,u,i-1)).then(function(){});n.accounts[r.tempId]=n.accounts[r.tempId]||r,n.accounts[r.tempId].role.proposer=n.accounts[r.tempId].role.proposer||r.role.proposer,n.accounts[r.tempId].role.payer=n.accounts[r.tempId].role.payer||r.role.payer,n.accounts[r.tempId].role.authorizer=n.accounts[r.tempId].role.authorizer||r.role.authorizer,n.proposer===u.tempId&&(n.proposer=r.tempId),n.payer===u.tempId&&(n.payer=r.tempId),n.authorizations=n.authorizations.map(function(e){return e===u.tempId?r.tempId:e})}();return o&&o.then?o.then(t):t()}var u=o||r,a=function(){if(ie(r.resolve))return Promise.resolve(r.resolve(r,function(e,r){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}catch(e){throw console.error("buildPreSignable",e),e}}(r,n))).then(function(e){r=e})}();return a&&a.then?a.then(t):t()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},oe=function(e){return"string"==typeof e},ie=function(e){return"function"==typeof e};function ue(e,r){return function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,r,n){try{return{"@type":"Signable","@vsn":"1.0.0",message:r,addr:o.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(function(e){return n.arguments[e].asArgument}),data:{},interaction:n}}catch(e){throw console.error("buildSignable",e),e}}(t,r,e))).then(function(r){e.accounts[n].signature=r.signature})}catch(e){return Promise.reject(e)}}}function ae(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:o.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:o.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(r){return o.sansPrefix(e.accounts[r].addr)}).reduce(function(e,r){return e.find(function(e){return e===r})?e:[].concat(e,[r])},[])}}e.config().put("sdk.resolve",function(o){try{return Promise.resolve(o).then(function(u){return o=u,Promise.resolve(function(t){try{var o=function(){if(n.isTransaction(t)||n.isScript(t)){var o=function(){return r.invariant(oe(i),"Cadence needs to be a string at this point."),Promise.resolve(e.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,r){return e.replace(r[0],r[1])},i)})).then(function(e){t.message.cadence=e})},i=n.get(t,"ix.cadence");r.invariant(ie(i)||oe(i),"Cadence needs to be a function or a string.");var u=function(){if(ie(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return t}):t)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{if(n.isTransaction(e)||n.isScript(e))for(var t=0,o=Object.entries(e.arguments);t<o.length;t++){var i=o[t];e.arguments[i[0]].asArgument=(r.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),ie(u.xform)?u.xform(u.value):ie(u.xform.asArgument)?u.xform.asArgument(u.value):void r.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(o)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n.isTransaction(e))return ne(function(){return console.log("START",e),console.log("AAA",e.accounts),Promise.resolve(te(e,Object.values(e.accounts))).then(function(){return console.log("BBB",e.accounts),Promise.resolve(te(e,Object.values(e.accounts))).then(function(){console.log("CCC",e.accounts),console.log("END",e)})})},function(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e})}();return Promise.resolve(r&&r.then?r.then(function(r){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(t.latestBlock()).then(function(r){e.message.refBlock=r.id})}();return Promise.resolve(r&&r.then?r.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var t=function(){if(n.isTransaction(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});r.invariant(t,"Transactions require a proposer");var o=function(){if(null==t.sequenceNum)return Promise.resolve(i.account(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[t.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n.isTransaction(e))return ne(function(){var r,n=function(e){var r=new Set(e.authorizations);return r.add(e.proposer),r.delete(e.payer),Array.from(r)}(e),t=(r=ae(e),L(z(r)));return Promise.resolve(Promise.all(n.map(ue(e,t)))).then(function(){var r=function(e){var r=new Set([e.payer]);return Array.from(r)}(e),t=function(e){return L(function(e){return function(e){G.forEach(function(r){return Y(e,r)}),e.payloadSigs.forEach(function(e,r){V.forEach(function(n){return Y(e,n,"payloadSigs",r)})})}(e),[z(e),U(e)]}(e))}(O({},ae(e),{payloadSigs:n.map(function(r){return e.accounts[r].signature})}));return Promise.resolve(Promise.all(r.map(ue(e,t)))).then(function(){})})},function(r){throw console.error("Signatures",r,{ix:e}),r})}();return Promise.resolve(r&&r.then?r.then(function(r){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return o})})})})})})})}catch(e){return Promise.reject(e)}});var se,ce,fe=function(e){try{return Promise.resolve(c.send([l.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},le=function(e){return e.status>=4},de=function(e){return e.status>=3},pe=function(e){return e.status>=2},he=((se={})[s.INIT]=function(e){try{return Promise.resolve(fe(e.self())).then(function(r){le(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},se[s.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,s.UPDATED,e.all())},se[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},se[s.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},se.POLL=function(e){try{return Promise.resolve(fe(e.self())).then(function(r){var n,t;le(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(s.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},se),me=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ve=function(e){return s.spawn(he,me(e))};function ye(e){function r(r){return s.subscriber(me(e),ve,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return s.snapshoter(e,ve)},subscribe:r,onceFinalized:n(pe),onceExecuted:n(de),onceSealed:n(le)}}ye.isUnknown=function(e){return e.status>=0},ye.isPending=function(e){return e.status>=1},ye.isFinalized=pe,ye.isExecuted=de,ye.isSealed=le,ye.isExpired=function(e){return 5===e.status};var ge=function(r){try{var n=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Pe=((ce={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(t.latestBlock()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(ge(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(c.send([getEvents(e.self(),r.height,n.height-1)]).then(f.decode)).then(function(r){for(var n,t=C(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(ge(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ce[s.SUBSCRIBE]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(ge(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},ce[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ce),be=function(e){return s.spawn(Pe,e)},we={f_type:"Service",f_vsn:"1.0.0"},Ee={f_type:"Identity",f_vsn:"1.0.0"},xe={f_type:"USER",f_vsn:"1.0.0"},Ie={f_type:"PollingResponse",f_vsn:"1.0.0"},ke={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({old:e},we,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function je(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Ae={"back-channel-rpc":je,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:O({},Ee,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:O({},Ee,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:Se};function Oe(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Re(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function Ce(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,t=Object.entries(e.params||{});n<t.length;n++){var o=t[n];r.searchParams.append(o[0],o[1])}return r}function Te(e,r){void 0===r&&(r={});var n=r.method||"POST",t="GET"===n?void 0:JSON.stringify(r.data||e.data||{});return fetch(Ce(e),{method:n,headers:O({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},Ie,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:je(e.authorizationUpdates),local:Se((e.local||[])[0])})}}function Be(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},ke,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var Le="FCL_IFRAME",ze=function(){},Ue=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function qe(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return{send:ze,close:ze};var t=n.onClose||ze,o=n.onMessage||ze,i=n.onReady||ze;window.addEventListener("message",c);var u=function(e){r.invariant(!document.getElementById(Le),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=Le,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(Le)&&document.getElementById(Le).remove()}]}(Ce(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(Ue.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}var _e,De={"HTTP/GET":"GET","HTTP/POST":"POST"},Fe=function(e){return r.invariant(De[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),De[e.method]},Me=function(e,n){try{return n.data=e.data,Promise.resolve(Te(e,{data:n}).then(function(e){return console.info("WAT IS THIS",e),e}).then(Ne)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var t=!0,o=qe(n.local,{onClose:function(){t=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(n,{method:Fe(n)}).then(Ne)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,t)})}})}catch(e){return Promise.reject(e)}}(n.updates,function(){return t}).then(function(e){return o(),Be(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},He=function(e,r){try{try{return Promise.resolve(Je[e.method](e,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r}),n}}catch(e){return Promise.reject(e)}},Je={"HTTP/RPC":Me,"HTTP/POST":Me,"IFRAME/RPC":function(e,r){return new Promise(function(n,t){var o=p.uid();r.data=e.data,qe(e,{onReady:function(n,t){var i=t.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})}catch(e){throw e}},onClose:function(){t("Declined: Externally Halted")},onMessage:function(e,r){var i=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=Ne(e.data.result);switch(u.status){case"APPROVED":n(Be(u.data)),i();break;case"DECLINED":t("Declined: "+(u.reason||"No reason supplied")),i();break;default:t("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function Ke(e,r,n){if(!e.s){if(n instanceof Ve){if(!n.s)return void(n.o=Ke.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Ke.bind(null,e,r),Ke.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Ge=function(e){try{return ur(),Promise.resolve(Ze()).then(function(r){var n=Re(r.services,"authz"),t=Re(r.services,"pre-authz");return O({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(He(t,r)).then(cr)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(He(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ve=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Ke(t,1,i(this.v))}catch(e){Ke(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ke(t,1,r?r(o):o):n?Ke(t,1,n(o)):Ke(t,2,o)}catch(e){Ke(t,2,e)}},t},e}();function Ye(e){return e instanceof Ve&&1&e.s}var Ze=function(){try{return Promise.resolve(new Promise(function(r){try{return ur(),Promise.resolve(lr()).then(function(n){return n.loggedIn&&ar(n)?r(n):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var n,t,i,u=(n={handshake:e,l6n:window.location.origin},t=n.l6n,(i=new URL(n.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(i.href))[1];window.addEventListener("message",function e(n){var t=n.data;try{return t.type===rr||t.type===Qe?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==er?Promise.resolve():(u(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=C(e.authorizations);!(n=t()).done;)r.push(O({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(O({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,i,u=(t=r,i=n,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(r){return function(e,r){try{return Ae[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),a=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,u);return O({},xe,{addr:o.withPrefix(e.addr),cid:Oe(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return s.send(We,$e,e),Promise.resolve(lr()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},We="CURRENT_USER",Xe="CURRENT_USER/UPDATED",$e="SET_CURRENT_USER",Qe="FCL::CANCEL",er="FCL::CHALLENGE::RESPONSE",rr="FCL::CHALLENGE::CANCEL",nr='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',tr=function(e){try{return sessionStorage.setItem(We,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},or=function(){return e.config().get("persistSession",!0)},ir=((_e={})[s.INIT]=function(e){try{return e.merge(JSON.parse(nr)),Promise.resolve(or()).then(function(r){var n=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(nr),r=JSON.parse(sessionStorage.getItem(We));return null!=r&&e.f_vsn!==r.f_vsn?(sessionStorage.removeItem(We),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){ar(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},_e[s.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,Xe,O({},e.all()))},_e[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},_e.SNAPSHOT=function(e,r){try{return r.reply(O({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},_e[$e]=function(e,r,n){try{return e.merge(n),Promise.resolve(or()).then(function(r){r&&tr(e.all()),e.broadcast(Xe,O({},e.all()))})}catch(e){return Promise.reject(e)}},_e.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(nr)),Promise.resolve(or()).then(function(r){r&&tr(e.all()),e.broadcast(Xe,O({},e.all()))})}catch(e){return Promise.reject(e)}},_e),ur=function(){return s.spawn(ir,We)};function ar(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function sr(){ur(),s.send(We,"DEL_CURRENT_USER")}function cr(e){console.log("rawr(authz)[A]",{authz:e});var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=r.proposer&&n.push(["PROPOSER",r.proposer]);for(var t,o=C(r.payer||[]);!(t=o()).done;)n.push(["PAYER",t.value]);for(var i,u=C(r.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);console.log("rawr(authz)[B]",{authz:e,axs:n,resp:r});var a=n.map(function(e){var r=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return He(n,e)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}});return console.log("rawr(authz)[x]",{authz:e,result:a}),a}function fr(e){ur();var r=s.spawn(function(r){try{var n;return r.send(We,s.SUBSCRIBE),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(Ye(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!Ye(i)){t=1;break}i=i.s}}var u=new Ve,a=Ke.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Ke(u,1,i)})).then(void 0,a),u;function s(r){i=r;do{if(!(o=e())||Ye(o)&&!o.v)return void Ke(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ye(i=n())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=n())&&i.then?i.then(s).then(void 0,a):s(i):Ke(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(We,s.UNSUBSCRIBE),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return s.send(r,"@EXIT")}}function lr(){return ur(),s.send(We,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var dr=function(){return{authenticate:Ze,unauthenticate:sr,authorization:Ge,subscribe:fr,snapshot:lr}},pr=dr().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return i.account}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return c.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return l.getTransactionStatus}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return d.getEvents}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return m.transaction}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return v.script}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return y.ping}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return g.getAccount}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return b.getBlockById}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return w.getBlockByHeight}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return E.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return E.authorizations}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return x.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return x.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return I.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return k.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return S.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return j.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return A.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return A.params}}),exports.VERSION="0.0.67-alpha.27",exports.authenticate=function(){return dr().authenticate()},exports.authz=pr,exports.currentUser=dr,exports.events=function(e){return{subscribe:function(r){return s.subscriber(e,be,r)}}},exports.logIn=function(){return dr().authenticate()},exports.reauthenticate=function(){return dr().unauthenticate(),dr().authenticate()},exports.serialize=function(r,t){void 0===r&&(r=[]),void 0===t&&(t={});try{return Promise.resolve(e.config().get("sdk.resolve",t.resolve||a.resolve(t))).then(function(e){function o(){return Promise.resolve(e(t)(r)).then(function(e){return JSON.stringify(e,null,2)})}var i=function(){if(Array.isArray(r))return Promise.resolve(n.pipe(n.interaction(),r)).then(function(e){r=e})}();return i&&i.then?i.then(o):o()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return dr().authenticate()},exports.tx=ye,exports.unauthenticate=function(){return dr().unauthenticate()}; | ||
var e=require("@onflow/config"),r=require("@onflow/util-invariant"),n=require("@onflow/interaction"),t=require("@onflow/sdk-latest-block"),o=require("@onflow/util-address"),i=require("@onflow/sdk-account"),u=require("@onflow/rlp"),a=require("@onflow/sdk-resolve"),s=require("@onflow/util-actor"),c=require("@onflow/sdk-send"),f=require("@onflow/sdk-decode"),l=require("@onflow/sdk-build-transaction-status"),d=require("@onflow/sdk-build-get-events"),p=require("@onflow/util-uid"),h=require("@onflow/util-template"),m=require("@onflow/sdk-build-transaction"),v=require("@onflow/sdk-build-script"),y=require("@onflow/sdk-build-ping"),g=require("@onflow/sdk-build-get-account"),P=require("@onflow/sdk-build-get-latest-block"),b=require("@onflow/sdk-build-get-block-by-id"),w=require("@onflow/sdk-build-get-block-by-height"),E=require("@onflow/sdk-build-authorizations"),x=require("@onflow/sdk-build-arguments"),I=require("@onflow/sdk-build-proposer"),k=require("@onflow/sdk-build-payer"),S=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),A=require("@onflow/sdk-build-params");function O(){return(O=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function R(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function C(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return R(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?R(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T=function(e,r){return Buffer.from(e.padStart(2*r,0),"hex")},N=function(e){return T(e,8)},B=function(e){return Buffer.from(JSON.stringify(e),"utf8")},L=function(e){return u.encode(e).toString("hex")},z=function(e){return q(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(B),(r=e.refBlock,T(r,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var r,n},U=function(e){var r=_(e);return e.payloadSigs.map(function(e){return{signerIndex:r.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,r){return e.signerIndex>r.signerIndex?1:e.signerIndex<r.signerIndex?-1:e.keyId>r.keyId?1:e.keyId<r.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(r=e.sig,Buffer.from(r,"hex"))];var r})},_=function(e){var r=new Map,n=0,t=function(e){r.has(e)||(r.set(e,n),n++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),r},q=function(e){J.forEach(function(r){return Y(e,r)}),K.forEach(function(r){return Y(e.proposalKey,r,"proposalKey")})},D=function(e){return"number"==typeof e},F=function(e){return"string"==typeof e},M=function(e){return null!==e&&"object"==typeof e},H=function(e){return M(e)&&e instanceof Array},J=[{name:"script",check:F},{name:"arguments",check:H},{name:"refBlock",check:F,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:M},{name:"payer",check:F},{name:"authorizers",check:H}],K=[{name:"address",check:F},{name:"keyId",check:D},{name:"sequenceNum",check:D}],G=[{name:"payloadSigs",check:H}],V=[{name:"address",check:F},{name:"keyId",check:D},{name:"sig",check:F}],Y=function(e,r,n,t){var o=r.name,i=r.check,u=r.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw Z(o,n,t);if(!i(e[o]))throw W(o,n,t)},X=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},Z=function(e,r,n){return new Error("Missing field "+X(e,r,n))},W=function(e,r,n){return new Error("Invalid field "+X(e,r,n))},$="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Q(e,r,n){if(!e.s){if(n instanceof ee){if(!n.s)return void(n.o=Q.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Q.bind(null,e,r),Q.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var ee=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Q(t,1,i(this.v))}catch(e){Q(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Q(t,1,r?r(o):o):n?Q(t,1,n(o)):Q(t,2,o)}catch(e){Q(t,2,e)}},t},e}();function re(e){return e instanceof ee&&1&e.s}function ne(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}var te=function e(n,t,o,i){void 0===i&&(i=3);try{r.invariant(i,"Account Resolve Recursion Limit Exceeded",{ix:n,accounts:t}),console.log("resolveAccounts",t,n);var u=function(e,r,n){if("function"==typeof e[$]){var t,o,i,u=e[$]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!re(n))return void n.then(e,i||(i=Q.bind(null,o=new ee,2)));n=n.v}o?Q(o,1,n):o=n}catch(e){Q(o||(o=new ee),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!re(u))return void u.then(n,o||(o=Q.bind(null,t=new ee,2)));u=u.v}t?Q(t,1,u):t=u}catch(e){Q(t||(t=new ee),2,e)}}(),t}(s,function(e){return r(s[e])})}(t,function(r){function t(){function t(){u.tempId!=r.tempId&&delete n.accounts[u.tempId]}console.log(">>>",{old:u,ax:r});var o=function(){if(Array.isArray(r))return console.log("RECURSE!!",r),Promise.resolve(e(n,r,u,i-1)).then(function(){});n.accounts[r.tempId]=n.accounts[r.tempId]||r,n.accounts[r.tempId].role.proposer=n.accounts[r.tempId].role.proposer||r.role.proposer,n.accounts[r.tempId].role.payer=n.accounts[r.tempId].role.payer||r.role.payer,n.accounts[r.tempId].role.authorizer=n.accounts[r.tempId].role.authorizer||r.role.authorizer,n.proposer===u.tempId&&(n.proposer=r.tempId),n.payer===u.tempId&&(n.payer=r.tempId),n.authorizations=n.authorizations.map(function(e){return e===u.tempId?r.tempId:e})}();return o&&o.then?o.then(t):t()}var u=o||r,a=function(){if(ie(r.resolve))return Promise.resolve(r.resolve(r,function(e,r){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}catch(e){throw console.error("buildPreSignable",e),e}}(r,n))).then(function(e){r=e})}();return a&&a.then?a.then(t):t()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},oe=function(e){return"string"==typeof e},ie=function(e){return"function"==typeof e};function ue(e,r){return function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,r,n){try{return{"@type":"Signable","@vsn":"1.0.0",message:r,addr:o.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(function(e){return n.arguments[e].asArgument}),data:{},interaction:n}}catch(e){throw console.error("buildSignable",e),e}}(t,r,e))).then(function(r){e.accounts[n].signature=r.signature})}catch(e){return Promise.reject(e)}}}function ae(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:o.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:o.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(r){return o.sansPrefix(e.accounts[r].addr)}).reduce(function(e,r){return e.find(function(e){return e===r})?e:[].concat(e,[r])},[])}}e.config().put("sdk.resolve",function(o){try{return Promise.resolve(o).then(function(u){return o=u,Promise.resolve(function(t){try{var o=function(){if(n.isTransaction(t)||n.isScript(t)){var o=function(){return r.invariant(oe(i),"Cadence needs to be a string at this point."),Promise.resolve(e.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,r){return e.replace(r[0],r[1])},i)})).then(function(e){t.message.cadence=e})},i=n.get(t,"ix.cadence");r.invariant(ie(i)||oe(i),"Cadence needs to be a function or a string.");var u=function(){if(ie(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return t}):t)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{if(n.isTransaction(e)||n.isScript(e))for(var t=0,o=Object.entries(e.arguments);t<o.length;t++){var i=o[t];e.arguments[i[0]].asArgument=(r.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),ie(u.xform)?u.xform(u.value):ie(u.xform.asArgument)?u.xform.asArgument(u.value):void r.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(o)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n.isTransaction(e))return ne(function(){return console.log("START",e),console.log("AAA",e.accounts),Promise.resolve(te(e,Object.values(e.accounts))).then(function(){return console.log("BBB",e.accounts),Promise.resolve(te(e,Object.values(e.accounts))).then(function(){console.log("CCC",e.accounts),console.log("END",e)})})},function(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e})}();return Promise.resolve(r&&r.then?r.then(function(r){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(t.latestBlock()).then(function(r){e.message.refBlock=r.id})}();return Promise.resolve(r&&r.then?r.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var t=function(){if(n.isTransaction(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});r.invariant(t,"Transactions require a proposer");var o=function(){if(null==t.sequenceNum)return Promise.resolve(i.account(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[t.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n.isTransaction(e))return ne(function(){var r,n=function(e){var r=new Set(e.authorizations);return r.add(e.proposer),r.delete(e.payer),Array.from(r)}(e),t=(r=ae(e),L(z(r)));return Promise.resolve(Promise.all(n.map(ue(e,t)))).then(function(){var r=function(e){var r=new Set([e.payer]);return Array.from(r)}(e),t=function(e){return L(function(e){return function(e){G.forEach(function(r){return Y(e,r)}),e.payloadSigs.forEach(function(e,r){V.forEach(function(n){return Y(e,n,"payloadSigs",r)})})}(e),[z(e),U(e)]}(e))}(O({},ae(e),{payloadSigs:n.map(function(r){return e.accounts[r].signature})}));return Promise.resolve(Promise.all(r.map(ue(e,t)))).then(function(){})})},function(r){throw console.error("Signatures",r,{ix:e}),r})}();return Promise.resolve(r&&r.then?r.then(function(r){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return console.log("PRE_SEND IX",o),o})})})})})})})}catch(e){return Promise.reject(e)}});var se,ce,fe=function(e){try{return Promise.resolve(c.send([l.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},le=function(e){return e.status>=4},de=function(e){return e.status>=3},pe=function(e){return e.status>=2},he=((se={})[s.INIT]=function(e){try{return Promise.resolve(fe(e.self())).then(function(r){le(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},se[s.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,s.UPDATED,e.all())},se[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},se[s.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},se.POLL=function(e){try{return Promise.resolve(fe(e.self())).then(function(r){var n,t;le(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(s.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},se),me=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ve=function(e){return s.spawn(he,me(e))};function ye(e){function r(r){return s.subscriber(me(e),ve,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return s.snapshoter(e,ve)},subscribe:r,onceFinalized:n(pe),onceExecuted:n(de),onceSealed:n(le)}}ye.isUnknown=function(e){return e.status>=0},ye.isPending=function(e){return e.status>=1},ye.isFinalized=pe,ye.isExecuted=de,ye.isSealed=le,ye.isExpired=function(e){return 5===e.status};var ge=function(r){try{var n=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Pe=((ce={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(t.latestBlock()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(ge(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(c.send([getEvents(e.self(),r.height,n.height-1)]).then(f.decode)).then(function(r){for(var n,t=C(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(ge(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ce[s.SUBSCRIBE]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(ge(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},ce[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ce),be=function(e){return s.spawn(Pe,e)},we={f_type:"Service",f_vsn:"1.0.0"},Ee={f_type:"Identity",f_vsn:"1.0.0"},xe={f_type:"USER",f_vsn:"1.0.0"},Ie={f_type:"PollingResponse",f_vsn:"1.0.0"},ke={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({old:e},we,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function je(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Ae={"back-channel-rpc":je,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:O({},Ee,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:O({},Ee,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},we,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:Se};function Oe(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Re(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function Ce(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,t=Object.entries(e.params||{});n<t.length;n++){var o=t[n];r.searchParams.append(o[0],o[1])}return r}function Te(e,r){void 0===r&&(r={});var n=r.method||"POST",t="GET"===n?void 0:JSON.stringify(r.data||e.data||{});return fetch(Ce(e),{method:n,headers:O({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},Ie,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:je(e.authorizationUpdates),local:Se((e.local||[])[0])})}}function Be(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return O({},ke,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var Le="FCL_IFRAME",ze=function(){},Ue=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function _e(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return{send:ze,close:ze};var t=n.onClose||ze,o=n.onMessage||ze,i=n.onReady||ze;window.addEventListener("message",c);var u=function(e){r.invariant(!document.getElementById(Le),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=Le,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(Le)&&document.getElementById(Le).remove()}]}(Ce(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(Ue.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}var qe,De={"HTTP/GET":"GET","HTTP/POST":"POST"},Fe=function(e){return r.invariant(De[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),De[e.method]},Me=function(e,n){try{return n.data=e.data,Promise.resolve(Te(e,{data:n}).then(Ne)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var t=!0,o=_e(n.local,{onClose:function(){t=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(n,{method:Fe(n)}).then(Ne)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,t)})}})}catch(e){return Promise.reject(e)}}(n.updates,function(){return t}).then(function(e){return o(),Be(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},He=function(e,r){try{try{return Promise.resolve(Je[e.method](e,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r}),n}}catch(e){return Promise.reject(e)}},Je={"HTTP/RPC":Me,"HTTP/POST":Me,"IFRAME/RPC":function(e,r){return new Promise(function(n,t){var o=p.uid();r.data=e.data,_e(e,{onReady:function(n,t){var i=t.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})}catch(e){throw e}},onClose:function(){t("Declined: Externally Halted")},onMessage:function(e,r){var i=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=Ne(e.data.result);switch(u.status){case"APPROVED":n(Be(u.data)),i();break;case"DECLINED":t("Declined: "+(u.reason||"No reason supplied")),i();break;default:t("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function Ke(e,r,n){if(!e.s){if(n instanceof Ve){if(!n.s)return void(n.o=Ke.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Ke.bind(null,e,r),Ke.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Ge=function(e){try{return ur(),Promise.resolve(Xe()).then(function(r){var n=Re(r.services,"authz"),t=Re(r.services,"pre-authz");return O({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(He(t,r)).then(cr)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(He(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ve=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Ke(t,1,i(this.v))}catch(e){Ke(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ke(t,1,r?r(o):o):n?Ke(t,1,n(o)):Ke(t,2,o)}catch(e){Ke(t,2,e)}},t},e}();function Ye(e){return e instanceof Ve&&1&e.s}var Xe=function(){try{return Promise.resolve(new Promise(function(r){try{return ur(),Promise.resolve(lr()).then(function(n){return n.loggedIn&&ar(n)?r(n):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var n,t,i,u=(n={handshake:e,l6n:window.location.origin},t=n.l6n,(i=new URL(n.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(i.href))[1];window.addEventListener("message",function e(n){var t=n.data;try{return t.type===rr||t.type===Qe?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==er?Promise.resolve():(u(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=C(e.authorizations);!(n=t()).done;)r.push(O({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(O({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,i,u=(t=r,i=n,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(r){return function(e,r){try{return Ae[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),a=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,u);return O({},xe,{addr:o.withPrefix(e.addr),cid:Oe(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return s.send(Ze,$e,e),Promise.resolve(lr()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ze="CURRENT_USER",We="CURRENT_USER/UPDATED",$e="SET_CURRENT_USER",Qe="FCL::CANCEL",er="FCL::CHALLENGE::RESPONSE",rr="FCL::CHALLENGE::CANCEL",nr='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',tr=function(e){try{return sessionStorage.setItem(Ze,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},or=function(){return e.config().get("persistSession",!0)},ir=((qe={})[s.INIT]=function(e){try{return e.merge(JSON.parse(nr)),Promise.resolve(or()).then(function(r){var n=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(nr),r=JSON.parse(sessionStorage.getItem(Ze));return null!=r&&e.f_vsn!==r.f_vsn?(sessionStorage.removeItem(Ze),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){ar(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},qe[s.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,We,O({},e.all()))},qe[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},qe.SNAPSHOT=function(e,r){try{return r.reply(O({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},qe[$e]=function(e,r,n){try{return e.merge(n),Promise.resolve(or()).then(function(r){r&&tr(e.all()),e.broadcast(We,O({},e.all()))})}catch(e){return Promise.reject(e)}},qe.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(nr)),Promise.resolve(or()).then(function(r){r&&tr(e.all()),e.broadcast(We,O({},e.all()))})}catch(e){return Promise.reject(e)}},qe),ur=function(){return s.spawn(ir,Ze)};function ar(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function sr(){ur(),s.send(Ze,"DEL_CURRENT_USER")}function cr(e){console.log("rawr(authz)[A]",{authz:e});var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=r.proposer&&n.push(["PROPOSER",r.proposer]);for(var t,o=C(r.payer||[]);!(t=o()).done;)n.push(["PAYER",t.value]);for(var i,u=C(r.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);console.log("rawr(authz)[B]",{authz:e,axs:n,resp:r});var a=n.map(function(e){var r=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return He(n,e)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}});return console.log("rawr(authz)[x]",{authz:e,result:a}),a}function fr(e){ur();var r=s.spawn(function(r){try{var n;return r.send(Ze,s.SUBSCRIBE),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(Ye(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!Ye(i)){t=1;break}i=i.s}}var u=new Ve,a=Ke.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Ke(u,1,i)})).then(void 0,a),u;function s(r){i=r;do{if(!(o=e())||Ye(o)&&!o.v)return void Ke(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ye(i=n())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=n())&&i.then?i.then(s).then(void 0,a):s(i):Ke(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(Ze,s.UNSUBSCRIBE),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return s.send(r,"@EXIT")}}function lr(){return ur(),s.send(Ze,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var dr=function(){return{authenticate:Xe,unauthenticate:sr,authorization:Ge,subscribe:fr,snapshot:lr}},pr=dr().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return i.account}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return c.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return l.getTransactionStatus}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return d.getEvents}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return m.transaction}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return v.script}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return y.ping}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return g.getAccount}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return b.getBlockById}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return w.getBlockByHeight}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return E.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return E.authorizations}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return x.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return x.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return I.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return k.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return S.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return j.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return A.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return A.params}}),exports.VERSION="0.0.67-alpha.28",exports.authenticate=function(){return dr().authenticate()},exports.authz=pr,exports.currentUser=dr,exports.events=function(e){return{subscribe:function(r){return s.subscriber(e,be,r)}}},exports.logIn=function(){return dr().authenticate()},exports.reauthenticate=function(){return dr().unauthenticate(),dr().authenticate()},exports.serialize=function(r,t){void 0===r&&(r=[]),void 0===t&&(t={});try{return Promise.resolve(e.config().get("sdk.resolve",t.resolve||a.resolve(t))).then(function(e){function o(){return Promise.resolve(e(t)(r)).then(function(e){return JSON.stringify(e,null,2)})}var i=function(){if(Array.isArray(r))return Promise.resolve(n.pipe(n.interaction(),r)).then(function(e){r=e})}();return i&&i.then?i.then(o):o()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return dr().authenticate()},exports.tx=ye,exports.unauthenticate=function(){return dr().unauthenticate()}; | ||
//# sourceMappingURL=fcl.js.map |
@@ -1,2 +0,2 @@ | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as t}from"@onflow/util-invariant";import{isTransaction as n,isScript as r,get as o,pipe as a,interaction as s}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as i}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as c,withPrefix as u}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as d}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as p}from"@onflow/sdk-resolve";import{subscriber as f,spawn as m,snapshoter as h,INIT as y,SUBSCRIBE as g,UPDATED as w,UNSUBSCRIBE as E,SNAPSHOT as k,send as v}from"@onflow/util-actor";import{send as I}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as b}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as x}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as S}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";function A(){return(A=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},C=function(e){return R(e,8)},P=function(e){return Buffer.from(JSON.stringify(e),"utf8")},N=function(e){return l(e).toString("hex")},T=function(e){return O(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(P),(t=e.refBlock,R(t,32)),e.gasLimit,C(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,C(e.payer),e.authorizers.map(C)];var t,n},L=function(e){var t=z(e);return e.payloadSigs.map(function(e){return{signerIndex:t.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,t){return e.signerIndex>t.signerIndex?1:e.signerIndex<t.signerIndex?-1:e.keyId>t.keyId?1:e.keyId<t.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(t=e.sig,Buffer.from(t,"hex"))];var t})},z=function(e){var t=new Map,n=0,r=function(e){t.has(e)||(t.set(e,n),n++)};return r(e.proposalKey.address),r(e.payer),e.authorizers.forEach(r),t},O=function(e){B.forEach(function(t){return J(e,t)}),j.forEach(function(t){return J(e.proposalKey,t,"proposalKey")})},_=function(e){return"number"==typeof e},D=function(e){return"string"==typeof e},F=function(e){return null!==e&&"object"==typeof e},U=function(e){return F(e)&&e instanceof Array},B=[{name:"script",check:D},{name:"arguments",check:U},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:_},{name:"proposalKey",check:F},{name:"payer",check:D},{name:"authorizers",check:U}],j=[{name:"address",check:D},{name:"keyId",check:_},{name:"sequenceNum",check:_}],M=[{name:"payloadSigs",check:U}],H=[{name:"address",check:D},{name:"keyId",check:_},{name:"sig",check:D}],J=function(e,t,n,r){var o=t.name,a=t.check,s=t.defaultVal;if(null==e[o]&&null!=s&&(e[o]=s),null==e[o])throw K(o,n,r);if(!a(e[o]))throw G(o,n,r)},q=function(e,t,n){return t?null==n?t+"."+e:t+"."+n+"."+e:e},K=function(e,t,n){return new Error("Missing field "+q(e,t,n))},G=function(e,t,n){return new Error("Invalid field "+q(e,t,n))};const V=e=>"string"==typeof e,Y=e=>"function"==typeof e;async function Z(e,n,r,o=3){t(o,"Account Resolve Recursion Limit Exceeded",{ix:e,accounts:n}),console.log("resolveAccounts",n,e);for(let t of n){var a=r||t;Y(t.resolve)&&(t=await t.resolve(t,X(t,e))),console.log(">>>",{old:a,ax:t}),Array.isArray(t)?(console.log("RECURSE!!",t),await Z(e,t,a,o-1)):(e.accounts[t.tempId]=e.accounts[t.tempId]||t,e.accounts[t.tempId].role.proposer=e.accounts[t.tempId].role.proposer||t.role.proposer,e.accounts[t.tempId].role.payer=e.accounts[t.tempId].role.payer||t.role.payer,e.accounts[t.tempId].role.authorizer=e.accounts[t.tempId].role.authorizer||t.role.authorizer,e.proposer===a.tempId&&(e.proposer=t.tempId),e.payer===a.tempId&&(e.payer=t.tempId),e.authorizations=e.authorizations.map(e=>e===a.tempId?t.tempId:e)),a.tempId!=t.tempId&&delete e.accounts[a.tempId]}}function W(e,t){return async function(n){const r=e.accounts[n];if(null!=r.signature)return;const{signature:o}=await r.signingFunction(function(e,t,n){try{return{"@type":"Signable","@vsn":"1.0.0",message:t,addr:c(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(e=>n.arguments[e].asArgument),data:{},interaction:n}}catch(e){throw console.error("buildSignable",e),e}}(r,t,e));e.accounts[n].signature=o}}function X(e,t){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:t.message.cadence,args:t.message.arguments.map(e=>t.arguments[e].asArgument),data:{},interaction:t}}catch(e){throw console.error("buildPreSignable",e),e}}function $(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(t=>e.arguments[t].asArgument),proposalKey:{address:c(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:c(e.accounts[e.payer].addr),authorizers:e.authorizations.map(t=>c(e.accounts[t].addr)).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[])}}e().put("sdk.resolve",async function(a){return a=await a,await async function(a){if(n(a)||r(a)){var s=o(a,"ix.cadence");t(Y(s)||V(s),"Cadence needs to be a function or a string."),Y(s)&&(s=await s({})),t(V(s),"Cadence needs to be a string at this point."),a.message.cadence=await e().where(/^0x/).then(e=>Object.entries(e).reduce((e,[t,n])=>e.replace(t,n),s))}return a}(a),await async function(e){function o(e){return t(null!=typeof e.xform,"No type specified for argument: "+e.value),Y(e.xform)?e.xform(e.value):Y(e.xform.asArgument)?e.xform.asArgument(e.value):void t(!1,"Invalid Argument",e)}if(n(e)||r(e))for(let[t,n]of Object.entries(e.arguments))e.arguments[t].asArgument=o(n);return e}(a),await async function(e){if(n(e))try{console.log("START",e),console.log("AAA",e.accounts),await Z(e,Object.values(e.accounts)),console.log("BBB",e.accounts),await Z(e,Object.values(e.accounts)),console.log("CCC",e.accounts),console.log("END",e)}catch(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e}return e}(a),await async function(e){return n(e)&&null==e.message.refBlock&&(e.message.refBlock=(await i()).id),e}(a),await async function(e){if(n(e)){var r=Object.values(e.accounts).find(e=>e.role.proposer);t(r,"Transactions require a proposer"),null==r.sequenceNum&&(e.accounts[r.tempId].sequenceNum=await d(r.addr).then(e=>e.keys).then(e=>e.find(e=>e.index===r.keyId)).then(e=>e.sequenceNumber))}return e}(a),await async function(e){if(n(e))try{let n=function(e){let t=new Set(e.authorizations);return t.add(e.proposer),t.delete(e.payer),Array.from(t)}(e);const r=(t=$(e),N(T(t)));await Promise.all(n.map(W(e,r)));let o=function(e){let t=new Set([e.payer]);return Array.from(t)}(e);const a=function(e){return N(function(e){return function(e){M.forEach(function(t){return J(e,t)}),e.payloadSigs.forEach(function(e,t){H.forEach(function(n){return J(e,n,"payloadSigs",t)})})}(e),[T(e),L(e)]}(e))}(A({},$(e),{payloadSigs:n.map(t=>e.accounts[t].signature)}));await Promise.all(o.map(W(e,a)))}catch(t){throw console.error("Signatures",t,{ix:e}),t}var t;return e}(a),a});const Q=async(t=[],n={})=>{const r=await e().get("sdk.resolve",n.resolve||p(n));return Array.isArray(t)&&(t=await a(s(),t)),JSON.stringify(await r(n)(t),null,2)},ee=async e=>I([x(e)]).then(b),te=e=>e.status>=4,ne=e=>e.status>=3,re=e=>e.status>=2,oe={[y]:async e=>{const t=await ee(e.self());te(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[g]:(e,t)=>{e.subscribe(t.from),e.send(t.from,w,e.all())},[E]:(e,t)=>{e.unsubscribe(t.from)},[k]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await ee(e.self());var n,r;te(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(w,t),e.merge(t)}},ae=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},se=e=>m(oe,ae(e));function ie(e){function t(t){return f(ae(e),se,t)}function n(e){return function(n={}){const r=n.suppress||!1;return new Promise((n,o)=>{const a=t(t=>{t.statusCode&&!r?(o(t.errorMessage),a()):e(t)&&(n(t),a())})})}}return{snapshot:function(){return h(e,se)},subscribe:t,onceFinalized:n(re),onceExecuted:n(ne),onceSealed:n(te)}}ie.isUnknown=e=>e.status>=0,ie.isPending=e=>e.status>=1,ie.isFinalized=re,ie.isExecuted=ne,ie.isSealed=te,ie.isExpired=e=>5===e.status;const ce=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),ue={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await ce(e));else{let n=await i();e.put("hwm",n);const r=await I([getEvents(e.self(),t.height,n.height-1)]).then(b);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await ce(e))}},[g]:async(e,t)=>{e.hasSubs()||e.put("tick",await ce(e)),e.subscribe(t.from)},[E]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},de=e=>m(ue,e);function le(e){return{subscribe:t=>f(e,de,t)}}const pe={f_type:"Service",f_vsn:"1.0.0"},fe={f_type:"Identity",f_vsn:"1.0.0"},me={f_type:"USER",f_vsn:"1.0.0"},he={f_type:"PollingResponse",f_vsn:"1.0.0"},ye={f_type:"CompositeSignature",f_vsn:"1.0.0"};function ge(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({old:e},pe,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function we(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const Ee={"back-channel-rpc":we,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},fe,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},fe,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:u(e.addr),name:e.name,icon:e.icon}})}},frame:ge};function ke(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function ve(e=[],t){return e.find(e=>e.type===t)}function Ie(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[n,r]of Object.entries(e.params||{}))t.searchParams.append(n,r);return t}function be(e,t={}){const n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(Ie(e),{method:n,headers:A({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(e=>e.json())}function xe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},he,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:we(e.authorizationUpdates),local:ge((e.local||[])[0])})}}function Se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},ye,{addr:c(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const Ae="FCL_IFRAME",Re=()=>{},Ce=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Pe(e,n={}){if(console.log("FRAME",{service:e,opts:n}),null==e)return{send:Re,close:Re};const r=n.onClose||Re,o=n.onMessage||Re,a=n.onReady||Re;window.addEventListener("message",c);const[s,i]=function(e){t(!document.getElementById(Ae),"Attempt at triggering multiple Frames",{src:e});const n=document.createElement("iframe");return n.src=e,n.id=Ae,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,()=>{document.getElementById(Ae)&&document.getElementById(Ae).remove()}]}(Ie(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(Ce.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&a(e,{send:d,close:u}),o(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&a(e,{send:d,close:u}),"FCL::CHALLENGE::CANCEL"===e.data.type&&u(),"FCL::CANCEL"===e.data.type&&u()}catch(e){console.error("Frame Callback Error",e),u()}}function u(){try{window.removeEventListener("message",c),i(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const Ne={"HTTP/GET":"GET","HTTP/POST":"POST"},Te=e=>(t(Ne[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Ne[e.method]);async function Le(e,n){n.data=e.data;const r=await be(e,{data:n}).then(e=>(console.info("WAT IS THIS",e),e)).then(xe);if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("PENDING"===r.status){var o=!0;const{close:e}=Pe(r.local,{onClose(){o=!1}});return async function e(n,r=(()=>!0)){if(t(n,"Missing Polling Service",{service:n}),!r())throw new Error("Externally Halted");const o=await be(n,{method:Te(n)}).then(xe);switch(o.status){case"APPROVED":return o.data;case"DECLINED":throw new Error("Declined: "+(o.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(o.updates,r)}}(r.updates,()=>o).then(t=>(e(),Se(t))).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")}const ze={"HTTP/RPC":Le,"HTTP/POST":Le,"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const o=S();t.data=e.data,Pe(e,{onReady(n,{send:r}){try{r({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose(){r("Declined: Externally Halted")},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;const a=xe(e.data.result);switch(a.status){case"APPROVED":n(Se(a.data)),t();break;case"DECLINED":r("Declined: "+(a.reason||"No reason supplied")),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};async function Oe(e,t){try{return ze[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const _e="CURRENT_USER",De="CURRENT_USER/UPDATED",Fe='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ue=async e=>(sessionStorage.setItem(_e,JSON.stringify(e)),e),Be=()=>e().get("persistSession",!0),je={[y]:async e=>{if(e.merge(JSON.parse(Fe)),await Be()){const t=await(async()=>{const e=JSON.parse(Fe),t=JSON.parse(sessionStorage.getItem(_e));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(_e),e):t||e})();He(t)&&e.merge(t)}},[g]:(e,t)=>{e.subscribe(t.from),e.send(t.from,De,A({},e.all()))},[E]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(A({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Be()&&Ue(e.all()),e.broadcast(De,A({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Fe)),await Be()&&Ue(e.all()),e.broadcast(De,A({},e.all()))}},Me=()=>m(je,_e);function He(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Je(){return new Promise(async t=>{Me();const n=await Ve();if(n.loggedIn&&He(n))return t(n);const[r,o]=function({handshake:e,l6n:t}){var n=new URL(e);return n.searchParams.append("l6n",t),function(e){if(document.getElementById("FCL_IFRAME"))return;const t=document.createElement("iframe");return t.src=e,t.id="FCL_IFRAME",t.allow="usb *",t.frameBorder="0",t.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(t),[t,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}(n.href)}({handshake:await e().get("challenge.handshake"),l6n:window.location.origin}),a=async({data:e})=>{if("FCL::CHALLENGE::CANCEL"===e.type||"FCL::CANCEL"===e.type)return o(),void window.removeEventListener("message",a);"FCL::CHALLENGE::RESPONSE"===e.type&&(o(),window.removeEventListener("message",a),v(_e,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?u(e.addr):null,e.paddr=e.paddr?u(e.paddr):null,e}(e)).services||[],await async function(e,t){if(null==e||null==t)return[];const n=new URL(e);n.searchParams.append("code",t);const r=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(r))return r;const o=[];if(Array.isArray(r.authorizations))for(let e of r.authorizations)o.push(A({type:"authz",keyId:r.keyId},e));return null!=r.provider&&o.push(A({type:"authn",id:"wallet-provider#authn"},r.provider)),o}(e.hks,e.code)).map(t=>function(e,t){try{return Ee[e.type](e,t)}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));const n=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return A({},me,{addr:u(e.addr),cid:ke(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await Ve()))};window.addEventListener("message",a)})}function qe(){Me(),v(_e,"DEL_CURRENT_USER")}async function Ke(e){Me();const t=await Je(),n=ve(t.services,"authz"),r=ve(t.services,"pre-authz");return A({},e,r?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){console.log("rawr(authz)[A]",{authz:e});const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}))(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])n.push(["PAYER",e]);for(let e of t.authorization||[])n.push(["AUTHORIZER",e]);console.log("rawr(authz)[B]",{authz:e,axs:n,resp:t});var r=n.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>Oe(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}));return console.log("rawr(authz)[x]",{authz:e,result:r}),r}(await Oe(r,t))}:{tempId:"CURRENT_USER",resolve:null,addr:c(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>Oe(n,e)})}function Ge(e){Me();const t=m(async t=>{for(t.send(_e,g);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(_e,E);e(n.data)}});return()=>v(t,"@EXIT")}function Ve(){return Me(),v(_e,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ye=()=>({authenticate:Je,unauthenticate:qe,authorization:Ke,subscribe:Ge,snapshot:Ve}),Ze=()=>Ye().authenticate(),We=()=>Ye().unauthenticate(),Xe=()=>(Ye().unauthenticate(),Ye().authenticate()),$e=()=>Ye().authenticate(),Qe=()=>Ye().authenticate(),et=Ye().authorization,tt="0.0.67-alpha.27";export{tt as VERSION,Ze as authenticate,et as authz,Ye as currentUser,le as events,Qe as logIn,Xe as reauthenticate,Q as serialize,$e as signUp,ie as tx,We as unauthenticate}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as t}from"@onflow/util-invariant";import{isTransaction as n,isScript as r,get as o,pipe as a,interaction as s}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as i}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as c,withPrefix as u}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as d}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as p}from"@onflow/sdk-resolve";import{subscriber as f,spawn as m,snapshoter as h,INIT as y,SUBSCRIBE as g,UPDATED as w,UNSUBSCRIBE as E,SNAPSHOT as k,send as v}from"@onflow/util-actor";import{send as b}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as I}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as x}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as S}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";function A(){return(A=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},C=function(e){return R(e,8)},P=function(e){return Buffer.from(JSON.stringify(e),"utf8")},N=function(e){return l(e).toString("hex")},T=function(e){return O(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(P),(t=e.refBlock,R(t,32)),e.gasLimit,C(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,C(e.payer),e.authorizers.map(C)];var t,n},L=function(e){var t=z(e);return e.payloadSigs.map(function(e){return{signerIndex:t.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,t){return e.signerIndex>t.signerIndex?1:e.signerIndex<t.signerIndex?-1:e.keyId>t.keyId?1:e.keyId<t.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(t=e.sig,Buffer.from(t,"hex"))];var t})},z=function(e){var t=new Map,n=0,r=function(e){t.has(e)||(t.set(e,n),n++)};return r(e.proposalKey.address),r(e.payer),e.authorizers.forEach(r),t},O=function(e){B.forEach(function(t){return J(e,t)}),j.forEach(function(t){return J(e.proposalKey,t,"proposalKey")})},_=function(e){return"number"==typeof e},D=function(e){return"string"==typeof e},F=function(e){return null!==e&&"object"==typeof e},U=function(e){return F(e)&&e instanceof Array},B=[{name:"script",check:D},{name:"arguments",check:U},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:_},{name:"proposalKey",check:F},{name:"payer",check:D},{name:"authorizers",check:U}],j=[{name:"address",check:D},{name:"keyId",check:_},{name:"sequenceNum",check:_}],M=[{name:"payloadSigs",check:U}],H=[{name:"address",check:D},{name:"keyId",check:_},{name:"sig",check:D}],J=function(e,t,n,r){var o=t.name,a=t.check,s=t.defaultVal;if(null==e[o]&&null!=s&&(e[o]=s),null==e[o])throw K(o,n,r);if(!a(e[o]))throw G(o,n,r)},q=function(e,t,n){return t?null==n?t+"."+e:t+"."+n+"."+e:e},K=function(e,t,n){return new Error("Missing field "+q(e,t,n))},G=function(e,t,n){return new Error("Invalid field "+q(e,t,n))};const V=e=>"string"==typeof e,Y=e=>"function"==typeof e;async function X(e,n,r,o=3){t(o,"Account Resolve Recursion Limit Exceeded",{ix:e,accounts:n}),console.log("resolveAccounts",n,e);for(let t of n){var a=r||t;Y(t.resolve)&&(t=await t.resolve(t,W(t,e))),console.log(">>>",{old:a,ax:t}),Array.isArray(t)?(console.log("RECURSE!!",t),await X(e,t,a,o-1)):(e.accounts[t.tempId]=e.accounts[t.tempId]||t,e.accounts[t.tempId].role.proposer=e.accounts[t.tempId].role.proposer||t.role.proposer,e.accounts[t.tempId].role.payer=e.accounts[t.tempId].role.payer||t.role.payer,e.accounts[t.tempId].role.authorizer=e.accounts[t.tempId].role.authorizer||t.role.authorizer,e.proposer===a.tempId&&(e.proposer=t.tempId),e.payer===a.tempId&&(e.payer=t.tempId),e.authorizations=e.authorizations.map(e=>e===a.tempId?t.tempId:e)),a.tempId!=t.tempId&&delete e.accounts[a.tempId]}}function Z(e,t){return async function(n){const r=e.accounts[n];if(null!=r.signature)return;const{signature:o}=await r.signingFunction(function(e,t,n){try{return{"@type":"Signable","@vsn":"1.0.0",message:t,addr:c(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(e=>n.arguments[e].asArgument),data:{},interaction:n}}catch(e){throw console.error("buildSignable",e),e}}(r,t,e));e.accounts[n].signature=o}}function W(e,t){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:t.message.cadence,args:t.message.arguments.map(e=>t.arguments[e].asArgument),data:{},interaction:t}}catch(e){throw console.error("buildPreSignable",e),e}}function $(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(t=>e.arguments[t].asArgument),proposalKey:{address:c(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:c(e.accounts[e.payer].addr),authorizers:e.authorizations.map(t=>c(e.accounts[t].addr)).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[])}}e().put("sdk.resolve",async function(a){return a=await a,await async function(a){if(n(a)||r(a)){var s=o(a,"ix.cadence");t(Y(s)||V(s),"Cadence needs to be a function or a string."),Y(s)&&(s=await s({})),t(V(s),"Cadence needs to be a string at this point."),a.message.cadence=await e().where(/^0x/).then(e=>Object.entries(e).reduce((e,[t,n])=>e.replace(t,n),s))}return a}(a),await async function(e){function o(e){return t(null!=typeof e.xform,"No type specified for argument: "+e.value),Y(e.xform)?e.xform(e.value):Y(e.xform.asArgument)?e.xform.asArgument(e.value):void t(!1,"Invalid Argument",e)}if(n(e)||r(e))for(let[t,n]of Object.entries(e.arguments))e.arguments[t].asArgument=o(n);return e}(a),await async function(e){if(n(e))try{console.log("START",e),console.log("AAA",e.accounts),await X(e,Object.values(e.accounts)),console.log("BBB",e.accounts),await X(e,Object.values(e.accounts)),console.log("CCC",e.accounts),console.log("END",e)}catch(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e}return e}(a),await async function(e){return n(e)&&null==e.message.refBlock&&(e.message.refBlock=(await i()).id),e}(a),await async function(e){if(n(e)){var r=Object.values(e.accounts).find(e=>e.role.proposer);t(r,"Transactions require a proposer"),null==r.sequenceNum&&(e.accounts[r.tempId].sequenceNum=await d(r.addr).then(e=>e.keys).then(e=>e.find(e=>e.index===r.keyId)).then(e=>e.sequenceNumber))}return e}(a),await async function(e){if(n(e))try{let n=function(e){let t=new Set(e.authorizations);return t.add(e.proposer),t.delete(e.payer),Array.from(t)}(e);const r=(t=$(e),N(T(t)));await Promise.all(n.map(Z(e,r)));let o=function(e){let t=new Set([e.payer]);return Array.from(t)}(e);const a=function(e){return N(function(e){return function(e){M.forEach(function(t){return J(e,t)}),e.payloadSigs.forEach(function(e,t){H.forEach(function(n){return J(e,n,"payloadSigs",t)})})}(e),[T(e),L(e)]}(e))}(A({},$(e),{payloadSigs:n.map(t=>e.accounts[t].signature)}));await Promise.all(o.map(Z(e,a)))}catch(t){throw console.error("Signatures",t,{ix:e}),t}var t;return e}(a),console.log("PRE_SEND IX",a),a});const Q=async(t=[],n={})=>{const r=await e().get("sdk.resolve",n.resolve||p(n));return Array.isArray(t)&&(t=await a(s(),t)),JSON.stringify(await r(n)(t),null,2)},ee=async e=>b([x(e)]).then(I),te=e=>e.status>=4,ne=e=>e.status>=3,re=e=>e.status>=2,oe={[y]:async e=>{const t=await ee(e.self());te(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[g]:(e,t)=>{e.subscribe(t.from),e.send(t.from,w,e.all())},[E]:(e,t)=>{e.unsubscribe(t.from)},[k]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await ee(e.self());var n,r;te(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(w,t),e.merge(t)}},ae=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},se=e=>m(oe,ae(e));function ie(e){function t(t){return f(ae(e),se,t)}function n(e){return function(n={}){const r=n.suppress||!1;return new Promise((n,o)=>{const a=t(t=>{t.statusCode&&!r?(o(t.errorMessage),a()):e(t)&&(n(t),a())})})}}return{snapshot:function(){return h(e,se)},subscribe:t,onceFinalized:n(re),onceExecuted:n(ne),onceSealed:n(te)}}ie.isUnknown=e=>e.status>=0,ie.isPending=e=>e.status>=1,ie.isFinalized=re,ie.isExecuted=ne,ie.isSealed=te,ie.isExpired=e=>5===e.status;const ce=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),ue={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await ce(e));else{let n=await i();e.put("hwm",n);const r=await b([getEvents(e.self(),t.height,n.height-1)]).then(I);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await ce(e))}},[g]:async(e,t)=>{e.hasSubs()||e.put("tick",await ce(e)),e.subscribe(t.from)},[E]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},de=e=>m(ue,e);function le(e){return{subscribe:t=>f(e,de,t)}}const pe={f_type:"Service",f_vsn:"1.0.0"},fe={f_type:"Identity",f_vsn:"1.0.0"},me={f_type:"USER",f_vsn:"1.0.0"},he={f_type:"PollingResponse",f_vsn:"1.0.0"},ye={f_type:"CompositeSignature",f_vsn:"1.0.0"};function ge(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({old:e},pe,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function we(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const Ee={"back-channel-rpc":we,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},fe,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},fe,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},pe,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:u(e.addr),name:e.name,icon:e.icon}})}},frame:ge};function ke(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function ve(e=[],t){return e.find(e=>e.type===t)}function be(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[n,r]of Object.entries(e.params||{}))t.searchParams.append(n,r);return t}function Ie(e,t={}){const n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(be(e),{method:n,headers:A({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(e=>e.json())}function xe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},he,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:we(e.authorizationUpdates),local:ge((e.local||[])[0])})}}function Se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},ye,{addr:c(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const Ae="FCL_IFRAME",Re=()=>{},Ce=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Pe(e,n={}){if(console.log("FRAME",{service:e,opts:n}),null==e)return{send:Re,close:Re};const r=n.onClose||Re,o=n.onMessage||Re,a=n.onReady||Re;window.addEventListener("message",c);const[s,i]=function(e){t(!document.getElementById(Ae),"Attempt at triggering multiple Frames",{src:e});const n=document.createElement("iframe");return n.src=e,n.id=Ae,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,()=>{document.getElementById(Ae)&&document.getElementById(Ae).remove()}]}(be(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(Ce.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&a(e,{send:d,close:u}),o(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&a(e,{send:d,close:u}),"FCL::CHALLENGE::CANCEL"===e.data.type&&u(),"FCL::CANCEL"===e.data.type&&u()}catch(e){console.error("Frame Callback Error",e),u()}}function u(){try{window.removeEventListener("message",c),i(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const Ne={"HTTP/GET":"GET","HTTP/POST":"POST"},Te=e=>(t(Ne[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Ne[e.method]);async function Le(e,n){n.data=e.data;const r=await Ie(e,{data:n}).then(xe);if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("PENDING"===r.status){var o=!0;const{close:e}=Pe(r.local,{onClose(){o=!1}});return async function e(n,r=(()=>!0)){if(t(n,"Missing Polling Service",{service:n}),!r())throw new Error("Externally Halted");const o=await Ie(n,{method:Te(n)}).then(xe);switch(o.status){case"APPROVED":return o.data;case"DECLINED":throw new Error("Declined: "+(o.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(o.updates,r)}}(r.updates,()=>o).then(t=>(e(),Se(t))).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")}const ze={"HTTP/RPC":Le,"HTTP/POST":Le,"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const o=S();t.data=e.data,Pe(e,{onReady(n,{send:r}){try{r({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose(){r("Declined: Externally Halted")},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;const a=xe(e.data.result);switch(a.status){case"APPROVED":n(Se(a.data)),t();break;case"DECLINED":r("Declined: "+(a.reason||"No reason supplied")),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};async function Oe(e,t){try{return ze[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const _e="CURRENT_USER",De="CURRENT_USER/UPDATED",Fe='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ue=async e=>(sessionStorage.setItem(_e,JSON.stringify(e)),e),Be=()=>e().get("persistSession",!0),je={[y]:async e=>{if(e.merge(JSON.parse(Fe)),await Be()){const t=await(async()=>{const e=JSON.parse(Fe),t=JSON.parse(sessionStorage.getItem(_e));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(_e),e):t||e})();He(t)&&e.merge(t)}},[g]:(e,t)=>{e.subscribe(t.from),e.send(t.from,De,A({},e.all()))},[E]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(A({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Be()&&Ue(e.all()),e.broadcast(De,A({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Fe)),await Be()&&Ue(e.all()),e.broadcast(De,A({},e.all()))}},Me=()=>m(je,_e);function He(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Je(){return new Promise(async t=>{Me();const n=await Ve();if(n.loggedIn&&He(n))return t(n);const[r,o]=function({handshake:e,l6n:t}){var n=new URL(e);return n.searchParams.append("l6n",t),function(e){if(document.getElementById("FCL_IFRAME"))return;const t=document.createElement("iframe");return t.src=e,t.id="FCL_IFRAME",t.allow="usb *",t.frameBorder="0",t.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(t),[t,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}(n.href)}({handshake:await e().get("challenge.handshake"),l6n:window.location.origin}),a=async({data:e})=>{if("FCL::CHALLENGE::CANCEL"===e.type||"FCL::CANCEL"===e.type)return o(),void window.removeEventListener("message",a);"FCL::CHALLENGE::RESPONSE"===e.type&&(o(),window.removeEventListener("message",a),v(_e,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?u(e.addr):null,e.paddr=e.paddr?u(e.paddr):null,e}(e)).services||[],await async function(e,t){if(null==e||null==t)return[];const n=new URL(e);n.searchParams.append("code",t);const r=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(r))return r;const o=[];if(Array.isArray(r.authorizations))for(let e of r.authorizations)o.push(A({type:"authz",keyId:r.keyId},e));return null!=r.provider&&o.push(A({type:"authn",id:"wallet-provider#authn"},r.provider)),o}(e.hks,e.code)).map(t=>function(e,t){try{return Ee[e.type](e,t)}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));const n=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return A({},me,{addr:u(e.addr),cid:ke(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await Ve()))};window.addEventListener("message",a)})}function qe(){Me(),v(_e,"DEL_CURRENT_USER")}async function Ke(e){Me();const t=await Je(),n=ve(t.services,"authz"),r=ve(t.services,"pre-authz");return A({},e,r?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){console.log("rawr(authz)[A]",{authz:e});const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}))(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])n.push(["PAYER",e]);for(let e of t.authorization||[])n.push(["AUTHORIZER",e]);console.log("rawr(authz)[B]",{authz:e,axs:n,resp:t});var r=n.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>Oe(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}));return console.log("rawr(authz)[x]",{authz:e,result:r}),r}(await Oe(r,t))}:{tempId:"CURRENT_USER",resolve:null,addr:c(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>Oe(n,e)})}function Ge(e){Me();const t=m(async t=>{for(t.send(_e,g);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(_e,E);e(n.data)}});return()=>v(t,"@EXIT")}function Ve(){return Me(),v(_e,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ye=()=>({authenticate:Je,unauthenticate:qe,authorization:Ke,subscribe:Ge,snapshot:Ve}),Xe=()=>Ye().authenticate(),Ze=()=>Ye().unauthenticate(),We=()=>(Ye().unauthenticate(),Ye().authenticate()),$e=()=>Ye().authenticate(),Qe=()=>Ye().authenticate(),et=Ye().authorization,tt="0.0.67-alpha.28";export{tt as VERSION,Xe as authenticate,et as authz,Ye as currentUser,le as events,Qe as logIn,We as reauthenticate,Q as serialize,$e as signUp,ie as tx,Ze as unauthenticate}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as n}from"@onflow/util-invariant";import{isTransaction as r,isScript as t,get as o,pipe as i,interaction as u}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as a}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as s,withPrefix as c}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as f}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as d}from"@onflow/sdk-resolve";import{INIT as m,SUBSCRIBE as h,UPDATED as p,UNSUBSCRIBE as v,SNAPSHOT as y,subscriber as g,spawn as P,snapshoter as w,send as b}from"@onflow/util-actor";import{send as E}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as k}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as I}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as S}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";function x(){return(x=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function A(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function R(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return A(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var j=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},C=function(e){return j(e,8)},T=function(e){return Buffer.from(JSON.stringify(e),"utf8")},N=function(e){return l(e).toString("hex")},L=function(e){return _(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(T),(n=e.refBlock,j(n,32)),e.gasLimit,C(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,C(e.payer),e.authorizers.map(C)];var n,r},z=function(e){var n=O(e);return e.payloadSigs.map(function(e){return{signerIndex:n.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,n){return e.signerIndex>n.signerIndex?1:e.signerIndex<n.signerIndex?-1:e.keyId>n.keyId?1:e.keyId<n.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(n=e.sig,Buffer.from(n,"hex"))];var n})},O=function(e){var n=new Map,r=0,t=function(e){n.has(e)||(n.set(e,r),r++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),n},_=function(e){M.forEach(function(n){return K(e,n)}),H.forEach(function(n){return K(e.proposalKey,n,"proposalKey")})},D=function(e){return"number"==typeof e},F=function(e){return"string"==typeof e},U=function(e){return null!==e&&"object"==typeof e},B=function(e){return U(e)&&e instanceof Array},M=[{name:"script",check:F},{name:"arguments",check:B},{name:"refBlock",check:F,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:U},{name:"payer",check:F},{name:"authorizers",check:B}],H=[{name:"address",check:F},{name:"keyId",check:D},{name:"sequenceNum",check:D}],J=[{name:"payloadSigs",check:B}],q=[{name:"address",check:F},{name:"keyId",check:D},{name:"sig",check:F}],K=function(e,n,r,t){var o=n.name,i=n.check,u=n.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw V(o,r,t);if(!i(e[o]))throw Y(o,r,t)},G=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},V=function(e,n,r){return new Error("Missing field "+G(e,n,r))},Y=function(e,n,r){return new Error("Invalid field "+G(e,n,r))},Z="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function W(e,n,r){if(!e.s){if(r instanceof X){if(!r.s)return void(r.o=W.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(W.bind(null,e,n),W.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var X=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{W(t,1,i(this.v))}catch(e){W(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?W(t,1,n?n(o):o):r?W(t,1,r(o)):W(t,2,o)}catch(e){W(t,2,e)}},t},e}();function $(e){return e instanceof X&&1&e.s}function Q(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var ee=function e(r,t,o,i){void 0===i&&(i=3);try{n(i,"Account Resolve Recursion Limit Exceeded",{ix:r,accounts:t}),console.log("resolveAccounts",t,r);var u=function(e,n,r){if("function"==typeof e[Z]){var t,o,i,u=e[Z]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!$(r))return void r.then(e,i||(i=W.bind(null,o=new X,2)));r=r.v}o?W(o,1,r):o=r}catch(e){W(o||(o=new X),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,n,r){var t,o,i=-1;return function r(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!$(u))return void u.then(r,o||(o=W.bind(null,t=new X,2)));u=u.v}t?W(t,1,u):t=u}catch(e){W(t||(t=new X),2,e)}}(),t}(s,function(e){return n(s[e])})}(t,function(n){function t(){function t(){u.tempId!=n.tempId&&delete r.accounts[u.tempId]}console.log(">>>",{old:u,ax:n});var o=function(){if(Array.isArray(n))return console.log("RECURSE!!",n),Promise.resolve(e(r,n,u,i-1)).then(function(){});r.accounts[n.tempId]=r.accounts[n.tempId]||n,r.accounts[n.tempId].role.proposer=r.accounts[n.tempId].role.proposer||n.role.proposer,r.accounts[n.tempId].role.payer=r.accounts[n.tempId].role.payer||n.role.payer,r.accounts[n.tempId].role.authorizer=r.accounts[n.tempId].role.authorizer||n.role.authorizer,r.proposer===u.tempId&&(r.proposer=n.tempId),r.payer===u.tempId&&(r.payer=n.tempId),r.authorizations=r.authorizations.map(function(e){return e===u.tempId?n.tempId:e})}();return o&&o.then?o.then(t):t()}var u=o||n,a=function(){if(re(n.resolve))return Promise.resolve(n.resolve(n,function(e,n){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(function(e){return n.arguments[e].asArgument}),data:{},interaction:n}}catch(e){throw console.error("buildPreSignable",e),e}}(n,r))).then(function(e){n=e})}();return a&&a.then?a.then(t):t()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ne=function(e){return"string"==typeof e},re=function(e){return"function"==typeof e};function te(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){try{return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:s(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}catch(e){throw console.error("buildSignable",e),e}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function oe(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(n){return e.arguments[n].asArgument}),proposalKey:{address:s(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:s(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return s(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}e().put("sdk.resolve",function(i){try{return Promise.resolve(i).then(function(u){return i=u,Promise.resolve(function(i){try{var u=function(){if(r(i)||t(i)){var u=function(){return n(ne(a),"Cadence needs to be a string at this point."),Promise.resolve(e().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},a)})).then(function(e){i.message.cadence=e})},a=o(i,"ix.cadence");n(re(a)||ne(a),"Cadence needs to be a function or a string.");var s=function(){if(re(a))return Promise.resolve(a({})).then(function(e){a=e})}();return s&&s.then?s.then(u):u()}}();return Promise.resolve(u&&u.then?u.then(function(){return i}):i)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var o=function(e){return n(null!=typeof e.xform,"No type specified for argument: "+e.value),re(e.xform)?e.xform(e.value):re(e.xform.asArgument)?e.xform.asArgument(e.value):void n(!1,"Invalid Argument",e)};if(r(e)||t(e))for(var i=0,u=Object.entries(e.arguments);i<u.length;i++){var a=u[i];e.arguments[a[0]].asArgument=o(a[1])}return Promise.resolve(e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(e))return Q(function(){return console.log("START",e),console.log("AAA",e.accounts),Promise.resolve(ee(e,Object.values(e.accounts))).then(function(){return console.log("BBB",e.accounts),Promise.resolve(ee(e,Object.values(e.accounts))).then(function(){console.log("CCC",e.accounts),console.log("END",e)})})},function(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e})}();return Promise.resolve(n&&n.then?n.then(function(n){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(e)&&null==e.message.refBlock)return Promise.resolve(a()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var t=function(){if(r(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});n(t,"Transactions require a proposer");var o=function(){if(null==t.sequenceNum)return Promise.resolve(f(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(n){e.accounts[t.tempId].sequenceNum=n})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(e))return Q(function(){var n,r=function(e){var n=new Set(e.authorizations);return n.add(e.proposer),n.delete(e.payer),Array.from(n)}(e),t=(n=oe(e),N(L(n)));return Promise.resolve(Promise.all(r.map(te(e,t)))).then(function(){var n=function(e){var n=new Set([e.payer]);return Array.from(n)}(e),t=function(e){return N(function(e){return function(e){J.forEach(function(n){return K(e,n)}),e.payloadSigs.forEach(function(e,n){q.forEach(function(r){return K(e,r,"payloadSigs",n)})})}(e),[L(e),z(e)]}(e))}(x({},oe(e),{payloadSigs:r.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(n.map(te(e,t)))).then(function(){})})},function(n){throw console.error("Signatures",n,{ix:e}),n})}();return Promise.resolve(n&&n.then?n.then(function(n){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return i})})})})})})})}catch(e){return Promise.reject(e)}});var ie,ue,ae=function(n,r){void 0===n&&(n=[]),void 0===r&&(r={});try{return Promise.resolve(e().get("sdk.resolve",r.resolve||d(r))).then(function(e){function t(){return Promise.resolve(e(r)(n)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(n))return Promise.resolve(i(u(),n)).then(function(e){n=e})}();return o&&o.then?o.then(t):t()})}catch(e){return Promise.reject(e)}},se=function(e){try{return Promise.resolve(E([I(e)]).then(k))}catch(e){return Promise.reject(e)}},ce=function(e){return e.status>=4},fe=function(e){return e.status>=3},le=function(e){return e.status>=2},de=((ie={})[m]=function(e){try{return Promise.resolve(se(e.self())).then(function(n){ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ie[h]=function(e,n){e.subscribe(n.from),e.send(n.from,p,e.all())},ie[v]=function(e,n){e.unsubscribe(n.from)},ie[y]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ie.POLL=function(e){try{return Promise.resolve(se(e.self())).then(function(n){var r,t;ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(p,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ie),me=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},he=function(e){return P(de,me(e))};function pe(e){function n(n){return g(me(e),he,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return w(e,he)},subscribe:n,onceFinalized:r(le),onceExecuted:r(fe),onceSealed:r(ce)}}pe.isUnknown=function(e){return e.status>=0},pe.isPending=function(e){return e.status>=1},pe.isFinalized=le,pe.isExecuted=fe,pe.isSealed=ce,pe.isExpired=function(e){return 5===e.status};var ve=function(n){try{var r=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},ye=((ue={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(a()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(ve(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(a()).then(function(r){return e.put("hwm",r),Promise.resolve(E([getEvents(e.self(),n.height,r.height-1)]).then(k)).then(function(n){for(var r,t=R(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(ve(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ue[h]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ve(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},ue[v]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ue),ge=function(e){return P(ye,e)};function Pe(e){return{subscribe:function(n){return g(e,ge,n)}}}var we={f_type:"Service",f_vsn:"1.0.0"},be={f_type:"Identity",f_vsn:"1.0.0"},Ee={f_type:"USER",f_vsn:"1.0.0"},ke={f_type:"PollingResponse",f_vsn:"1.0.0"},Ie={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({old:e},we,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function xe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Ae={"back-channel-rpc":xe,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},be,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},be,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:c(e.addr),name:e.name,icon:e.icon}})}},frame:Se};function Re(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function je(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function Ce(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Te(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Ce(e),{method:r,headers:x({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},ke,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:xe(e.authorizationUpdates),local:Se((e.local||[])[0])})}}function Le(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},Ie,{addr:s(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ze="FCL_IFRAME",Oe=function(){},_e=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function De(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return{send:Oe,close:Oe};var t=r.onClose||Oe,o=r.onMessage||Oe,i=r.onReady||Oe;window.addEventListener("message",c);var u=function(e){n(!document.getElementById(ze),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=ze,r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(ze)&&document.getElementById(ze).remove()}]}(Ce(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(_e.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var Fe,Ue={"HTTP/GET":"GET","HTTP/POST":"POST"},Be=function(e){return n(Ue[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Ue[e.method]},Me=function(e,r){try{return r.data=e.data,Promise.resolve(Te(e,{data:r}).then(function(e){return console.info("WAT IS THIS",e),e}).then(Ne)).then(function(r){if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("PENDING"===r.status){var t=!0,o=De(r.local,{onClose:function(){t=!1}}).close;return function e(r,t){void 0===t&&(t=function(){return!0});try{if(n(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(r,{method:Be(r)}).then(Ne)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(r.updates,function(){return t}).then(function(e){return o(),Le(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},He=function(e,n){try{try{return Promise.resolve(Je[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},Je={"HTTP/RPC":Me,"HTTP/POST":Me,"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=S();n.data=e.data,De(e,{onReady:function(r,t){var i=t.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})}catch(e){throw e}},onClose:function(){t("Declined: Externally Halted")},onMessage:function(e,n){var i=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=Ne(e.data.result);switch(u.status){case"APPROVED":r(Le(u.data)),i();break;case"DECLINED":t("Declined: "+(u.reason||"No reason supplied")),i();break;default:t("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function qe(e,n,r){if(!e.s){if(r instanceof Ge){if(!r.s)return void(r.o=qe.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(qe.bind(null,e,n),qe.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ke=function(e){try{return un(),Promise.resolve(Ye()).then(function(n){var r=je(n.services,"authz"),t=je(n.services,"pre-authz");return x({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(He(t,n)).then(cn)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:s(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(He(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ge=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{qe(t,1,i(this.v))}catch(e){qe(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?qe(t,1,n?n(o):o):r?qe(t,1,r(o)):qe(t,2,o)}catch(e){qe(t,2,e)}},t},e}();function Ve(e){return e instanceof Ge&&1&e.s}var Ye=function(){try{return Promise.resolve(new Promise(function(n){try{return un(),Promise.resolve(ln()).then(function(r){return r.loggedIn&&an(r)?n(r):Promise.resolve(e().get("challenge.handshake")).then(function(e){var r,t,o,i=(r={handshake:e,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function e(r){var t=r.data;try{return t.type===en||t.type===$e?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Qe?Promise.resolve():(i(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?c(e.addr):null,e.paddr=e.paddr?c(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=R(e.authorizations);!(r=t()).done;)n.push(x({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(x({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,i=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return Ae[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),u=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,i);return x({},Ee,{addr:c(e.addr),cid:Re(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return b(Ze,Xe,e),Promise.resolve(ln()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ze="CURRENT_USER",We="CURRENT_USER/UPDATED",Xe="SET_CURRENT_USER",$e="FCL::CANCEL",Qe="FCL::CHALLENGE::RESPONSE",en="FCL::CHALLENGE::CANCEL",nn='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',rn=function(e){try{return sessionStorage.setItem(Ze,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},tn=function(){return e().get("persistSession",!0)},on=((Fe={})[m]=function(e){try{return e.merge(JSON.parse(nn)),Promise.resolve(tn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(nn),n=JSON.parse(sessionStorage.getItem(Ze));return null!=n&&e.f_vsn!==n.f_vsn?(sessionStorage.removeItem(Ze),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){an(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Fe[h]=function(e,n){e.subscribe(n.from),e.send(n.from,We,x({},e.all()))},Fe[v]=function(e,n){e.unsubscribe(n.from)},Fe.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Fe[Xe]=function(e,n,r){try{return e.merge(r),Promise.resolve(tn()).then(function(n){n&&rn(e.all()),e.broadcast(We,x({},e.all()))})}catch(e){return Promise.reject(e)}},Fe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(nn)),Promise.resolve(tn()).then(function(n){n&&rn(e.all()),e.broadcast(We,x({},e.all()))})}catch(e){return Promise.reject(e)}},Fe),un=function(){return P(on,Ze)};function an(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function sn(){un(),b(Ze,"DEL_CURRENT_USER")}function cn(e){console.log("rawr(authz)[A]",{authz:e});var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=R(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,u=R(n.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);console.log("rawr(authz)[B]",{authz:e,axs:r,resp:n});var a=r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return He(r,e)},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}});return console.log("rawr(authz)[x]",{authz:e,result:a}),a}function fn(e){un();var n=P(function(n){try{var r;return n.send(Ze,h),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ve(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ve(i)){t=1;break}i=i.s}}var u=new Ge,a=qe.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):qe(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ve(o)&&!o.v)return void qe(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ve(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):qe(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Ze,v),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return b(n,"@EXIT")}}function ln(){return un(),b(Ze,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var dn=function(){return{authenticate:Ye,unauthenticate:sn,authorization:Ke,subscribe:fn,snapshot:ln}},mn=function(){return dn().authenticate()},hn=function(){return dn().unauthenticate()},pn=function(){return dn().unauthenticate(),dn().authenticate()},vn=function(){return dn().authenticate()},yn=function(){return dn().authenticate()},gn=dn().authorization,Pn="0.0.67-alpha.27";export{Pn as VERSION,mn as authenticate,gn as authz,dn as currentUser,Pe as events,yn as logIn,pn as reauthenticate,ae as serialize,vn as signUp,pe as tx,hn as unauthenticate}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as r}from"@onflow/util-invariant";import{isTransaction as n,isScript as t,get as o,pipe as i,interaction as u}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as a}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as s,withPrefix as c}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as f}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as d}from"@onflow/sdk-resolve";import{INIT as m,SUBSCRIBE as h,UPDATED as p,UNSUBSCRIBE as v,SNAPSHOT as y,subscriber as g,spawn as P,snapshoter as w,send as b}from"@onflow/util-actor";import{send as E}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as k}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as I}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as S}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";function x(){return(x=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function A(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function R(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return A(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var j=function(e,r){return Buffer.from(e.padStart(2*r,0),"hex")},C=function(e){return j(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},T=function(e){return l(e).toString("hex")},L=function(e){return _(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(N),(r=e.refBlock,j(r,32)),e.gasLimit,C(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,C(e.payer),e.authorizers.map(C)];var r,n},z=function(e){var r=O(e);return e.payloadSigs.map(function(e){return{signerIndex:r.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,r){return e.signerIndex>r.signerIndex?1:e.signerIndex<r.signerIndex?-1:e.keyId>r.keyId?1:e.keyId<r.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(r=e.sig,Buffer.from(r,"hex"))];var r})},O=function(e){var r=new Map,n=0,t=function(e){r.has(e)||(r.set(e,n),n++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),r},_=function(e){M.forEach(function(r){return K(e,r)}),H.forEach(function(r){return K(e.proposalKey,r,"proposalKey")})},D=function(e){return"number"==typeof e},F=function(e){return"string"==typeof e},U=function(e){return null!==e&&"object"==typeof e},B=function(e){return U(e)&&e instanceof Array},M=[{name:"script",check:F},{name:"arguments",check:B},{name:"refBlock",check:F,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:U},{name:"payer",check:F},{name:"authorizers",check:B}],H=[{name:"address",check:F},{name:"keyId",check:D},{name:"sequenceNum",check:D}],J=[{name:"payloadSigs",check:B}],q=[{name:"address",check:F},{name:"keyId",check:D},{name:"sig",check:F}],K=function(e,r,n,t){var o=r.name,i=r.check,u=r.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw V(o,n,t);if(!i(e[o]))throw Y(o,n,t)},G=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},V=function(e,r,n){return new Error("Missing field "+G(e,r,n))},Y=function(e,r,n){return new Error("Invalid field "+G(e,r,n))},X="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Z(e,r,n){if(!e.s){if(n instanceof W){if(!n.s)return void(n.o=Z.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Z.bind(null,e,r),Z.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var W=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Z(t,1,i(this.v))}catch(e){Z(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Z(t,1,r?r(o):o):n?Z(t,1,n(o)):Z(t,2,o)}catch(e){Z(t,2,e)}},t},e}();function $(e){return e instanceof W&&1&e.s}function Q(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}var ee=function e(n,t,o,i){void 0===i&&(i=3);try{r(i,"Account Resolve Recursion Limit Exceeded",{ix:n,accounts:t}),console.log("resolveAccounts",t,n);var u=function(e,r,n){if("function"==typeof e[X]){var t,o,i,u=e[X]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!$(n))return void n.then(e,i||(i=Z.bind(null,o=new W,2)));n=n.v}o?Z(o,1,n):o=n}catch(e){Z(o||(o=new W),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!$(u))return void u.then(n,o||(o=Z.bind(null,t=new W,2)));u=u.v}t?Z(t,1,u):t=u}catch(e){Z(t||(t=new W),2,e)}}(),t}(s,function(e){return r(s[e])})}(t,function(r){function t(){function t(){u.tempId!=r.tempId&&delete n.accounts[u.tempId]}console.log(">>>",{old:u,ax:r});var o=function(){if(Array.isArray(r))return console.log("RECURSE!!",r),Promise.resolve(e(n,r,u,i-1)).then(function(){});n.accounts[r.tempId]=n.accounts[r.tempId]||r,n.accounts[r.tempId].role.proposer=n.accounts[r.tempId].role.proposer||r.role.proposer,n.accounts[r.tempId].role.payer=n.accounts[r.tempId].role.payer||r.role.payer,n.accounts[r.tempId].role.authorizer=n.accounts[r.tempId].role.authorizer||r.role.authorizer,n.proposer===u.tempId&&(n.proposer=r.tempId),n.payer===u.tempId&&(n.payer=r.tempId),n.authorizations=n.authorizations.map(function(e){return e===u.tempId?r.tempId:e})}();return o&&o.then?o.then(t):t()}var u=o||r,a=function(){if(ne(r.resolve))return Promise.resolve(r.resolve(r,function(e,r){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}catch(e){throw console.error("buildPreSignable",e),e}}(r,n))).then(function(e){r=e})}();return a&&a.then?a.then(t):t()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},re=function(e){return"string"==typeof e},ne=function(e){return"function"==typeof e};function te(e,r){return function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,r,n){try{return{"@type":"Signable","@vsn":"1.0.0",message:r,addr:s(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(function(e){return n.arguments[e].asArgument}),data:{},interaction:n}}catch(e){throw console.error("buildSignable",e),e}}(t,r,e))).then(function(r){e.accounts[n].signature=r.signature})}catch(e){return Promise.reject(e)}}}function oe(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:s(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:s(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(r){return s(e.accounts[r].addr)}).reduce(function(e,r){return e.find(function(e){return e===r})?e:[].concat(e,[r])},[])}}e().put("sdk.resolve",function(i){try{return Promise.resolve(i).then(function(u){return i=u,Promise.resolve(function(i){try{var u=function(){if(n(i)||t(i)){var u=function(){return r(re(a),"Cadence needs to be a string at this point."),Promise.resolve(e().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,r){return e.replace(r[0],r[1])},a)})).then(function(e){i.message.cadence=e})},a=o(i,"ix.cadence");r(ne(a)||re(a),"Cadence needs to be a function or a string.");var s=function(){if(ne(a))return Promise.resolve(a({})).then(function(e){a=e})}();return s&&s.then?s.then(u):u()}}();return Promise.resolve(u&&u.then?u.then(function(){return i}):i)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var o=function(e){return r(null!=typeof e.xform,"No type specified for argument: "+e.value),ne(e.xform)?e.xform(e.value):ne(e.xform.asArgument)?e.xform.asArgument(e.value):void r(!1,"Invalid Argument",e)};if(n(e)||t(e))for(var i=0,u=Object.entries(e.arguments);i<u.length;i++){var a=u[i];e.arguments[a[0]].asArgument=o(a[1])}return Promise.resolve(e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n(e))return Q(function(){return console.log("START",e),console.log("AAA",e.accounts),Promise.resolve(ee(e,Object.values(e.accounts))).then(function(){return console.log("BBB",e.accounts),Promise.resolve(ee(e,Object.values(e.accounts))).then(function(){console.log("CCC",e.accounts),console.log("END",e)})})},function(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e})}();return Promise.resolve(r&&r.then?r.then(function(r){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n(e)&&null==e.message.refBlock)return Promise.resolve(a()).then(function(r){e.message.refBlock=r.id})}();return Promise.resolve(r&&r.then?r.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var t=function(){if(n(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});r(t,"Transactions require a proposer");var o=function(){if(null==t.sequenceNum)return Promise.resolve(f(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[t.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var r=function(){if(n(e))return Q(function(){var r,n=function(e){var r=new Set(e.authorizations);return r.add(e.proposer),r.delete(e.payer),Array.from(r)}(e),t=(r=oe(e),T(L(r)));return Promise.resolve(Promise.all(n.map(te(e,t)))).then(function(){var r=function(e){var r=new Set([e.payer]);return Array.from(r)}(e),t=function(e){return T(function(e){return function(e){J.forEach(function(r){return K(e,r)}),e.payloadSigs.forEach(function(e,r){q.forEach(function(n){return K(e,n,"payloadSigs",r)})})}(e),[L(e),z(e)]}(e))}(x({},oe(e),{payloadSigs:n.map(function(r){return e.accounts[r].signature})}));return Promise.resolve(Promise.all(r.map(te(e,t)))).then(function(){})})},function(r){throw console.error("Signatures",r,{ix:e}),r})}();return Promise.resolve(r&&r.then?r.then(function(r){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return console.log("PRE_SEND IX",i),i})})})})})})})}catch(e){return Promise.reject(e)}});var ie,ue,ae=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e().get("sdk.resolve",n.resolve||d(n))).then(function(e){function t(){return Promise.resolve(e(n)(r)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(r))return Promise.resolve(i(u(),r)).then(function(e){r=e})}();return o&&o.then?o.then(t):t()})}catch(e){return Promise.reject(e)}},se=function(e){try{return Promise.resolve(E([I(e)]).then(k))}catch(e){return Promise.reject(e)}},ce=function(e){return e.status>=4},fe=function(e){return e.status>=3},le=function(e){return e.status>=2},de=((ie={})[m]=function(e){try{return Promise.resolve(se(e.self())).then(function(r){ce(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},ie[h]=function(e,r){e.subscribe(r.from),e.send(r.from,p,e.all())},ie[v]=function(e,r){e.unsubscribe(r.from)},ie[y]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ie.POLL=function(e){try{return Promise.resolve(se(e.self())).then(function(r){var n,t;ce(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(p,r),e.merge(r)})}catch(e){return Promise.reject(e)}},ie),me=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},he=function(e){return P(de,me(e))};function pe(e){function r(r){return g(me(e),he,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return w(e,he)},subscribe:r,onceFinalized:n(le),onceExecuted:n(fe),onceSealed:n(ce)}}pe.isUnknown=function(e){return e.status>=0},pe.isPending=function(e){return e.status>=1},pe.isFinalized=le,pe.isExecuted=fe,pe.isSealed=ce,pe.isExpired=function(e){return 5===e.status};var ve=function(r){try{var n=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},ye=((ue={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(a()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(ve(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(a()).then(function(n){return e.put("hwm",n),Promise.resolve(E([getEvents(e.self(),r.height,n.height-1)]).then(k)).then(function(r){for(var n,t=R(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(ve(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ue[h]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(ve(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},ue[v]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ue),ge=function(e){return P(ye,e)};function Pe(e){return{subscribe:function(r){return g(e,ge,r)}}}var we={f_type:"Service",f_vsn:"1.0.0"},be={f_type:"Identity",f_vsn:"1.0.0"},Ee={f_type:"USER",f_vsn:"1.0.0"},ke={f_type:"PollingResponse",f_vsn:"1.0.0"},Ie={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({old:e},we,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function xe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Ae={"back-channel-rpc":xe,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},be,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},be,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},we,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:c(e.addr),name:e.name,icon:e.icon}})}},frame:Se};function Re(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function je(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function Ce(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,t=Object.entries(e.params||{});n<t.length;n++){var o=t[n];r.searchParams.append(o[0],o[1])}return r}function Ne(e,r){void 0===r&&(r={});var n=r.method||"POST",t="GET"===n?void 0:JSON.stringify(r.data||e.data||{});return fetch(Ce(e),{method:n,headers:x({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Te(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},ke,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:xe(e.authorizationUpdates),local:Se((e.local||[])[0])})}}function Le(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},Ie,{addr:s(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ze="FCL_IFRAME",Oe=function(){},_e=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function De(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return{send:Oe,close:Oe};var t=n.onClose||Oe,o=n.onMessage||Oe,i=n.onReady||Oe;window.addEventListener("message",c);var u=function(e){r(!document.getElementById(ze),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=ze,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(ze)&&document.getElementById(ze).remove()}]}(Ce(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(_e.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}var Fe,Ue={"HTTP/GET":"GET","HTTP/POST":"POST"},Be=function(e){return r(Ue[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Ue[e.method]},Me=function(e,n){try{return n.data=e.data,Promise.resolve(Ne(e,{data:n}).then(Te)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var t=!0,o=De(n.local,{onClose:function(){t=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Ne(n,{method:Be(n)}).then(Te)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,t)})}})}catch(e){return Promise.reject(e)}}(n.updates,function(){return t}).then(function(e){return o(),Le(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},He=function(e,r){try{try{return Promise.resolve(Je[e.method](e,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r}),n}}catch(e){return Promise.reject(e)}},Je={"HTTP/RPC":Me,"HTTP/POST":Me,"IFRAME/RPC":function(e,r){return new Promise(function(n,t){var o=S();r.data=e.data,De(e,{onReady:function(n,t){var i=t.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})}catch(e){throw e}},onClose:function(){t("Declined: Externally Halted")},onMessage:function(e,r){var i=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=Te(e.data.result);switch(u.status){case"APPROVED":n(Le(u.data)),i();break;case"DECLINED":t("Declined: "+(u.reason||"No reason supplied")),i();break;default:t("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function qe(e,r,n){if(!e.s){if(n instanceof Ge){if(!n.s)return void(n.o=qe.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(qe.bind(null,e,r),qe.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Ke=function(e){try{return ir(),Promise.resolve(Ye()).then(function(r){var n=je(r.services,"authz"),t=je(r.services,"pre-authz");return x({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(He(t,r)).then(sr)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:s(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(He(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ge=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{qe(t,1,i(this.v))}catch(e){qe(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?qe(t,1,r?r(o):o):n?qe(t,1,n(o)):qe(t,2,o)}catch(e){qe(t,2,e)}},t},e}();function Ve(e){return e instanceof Ge&&1&e.s}var Ye=function(){try{return Promise.resolve(new Promise(function(r){try{return ir(),Promise.resolve(fr()).then(function(n){return n.loggedIn&&ur(n)?r(n):Promise.resolve(e().get("challenge.handshake")).then(function(e){var n,t,o,i=(n={handshake:e,l6n:window.location.origin},t=n.l6n,(o=new URL(n.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function e(n){var t=n.data;try{return t.type===er||t.type===$e?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Qe?Promise.resolve():(i(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?c(e.addr):null,e.paddr=e.paddr?c(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=R(e.authorizations);!(n=t()).done;)r.push(x({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(x({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,o,i=(t=r,o=n,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(r){return function(e,r){try{return Ae[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),u=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,i);return x({},Ee,{addr:c(e.addr),cid:Re(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return b(Xe,We,e),Promise.resolve(fr()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Xe="CURRENT_USER",Ze="CURRENT_USER/UPDATED",We="SET_CURRENT_USER",$e="FCL::CANCEL",Qe="FCL::CHALLENGE::RESPONSE",er="FCL::CHALLENGE::CANCEL",rr='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',nr=function(e){try{return sessionStorage.setItem(Xe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},tr=function(){return e().get("persistSession",!0)},or=((Fe={})[m]=function(e){try{return e.merge(JSON.parse(rr)),Promise.resolve(tr()).then(function(r){var n=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(rr),r=JSON.parse(sessionStorage.getItem(Xe));return null!=r&&e.f_vsn!==r.f_vsn?(sessionStorage.removeItem(Xe),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){ur(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},Fe[h]=function(e,r){e.subscribe(r.from),e.send(r.from,Ze,x({},e.all()))},Fe[v]=function(e,r){e.unsubscribe(r.from)},Fe.SNAPSHOT=function(e,r){try{return r.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Fe[We]=function(e,r,n){try{return e.merge(n),Promise.resolve(tr()).then(function(r){r&&nr(e.all()),e.broadcast(Ze,x({},e.all()))})}catch(e){return Promise.reject(e)}},Fe.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(rr)),Promise.resolve(tr()).then(function(r){r&&nr(e.all()),e.broadcast(Ze,x({},e.all()))})}catch(e){return Promise.reject(e)}},Fe),ir=function(){return P(or,Xe)};function ur(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function ar(){ir(),b(Xe,"DEL_CURRENT_USER")}function sr(e){console.log("rawr(authz)[A]",{authz:e});var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=r.proposer&&n.push(["PROPOSER",r.proposer]);for(var t,o=R(r.payer||[]);!(t=o()).done;)n.push(["PAYER",t.value]);for(var i,u=R(r.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);console.log("rawr(authz)[B]",{authz:e,axs:n,resp:r});var a=n.map(function(e){var r=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return He(n,e)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}});return console.log("rawr(authz)[x]",{authz:e,result:a}),a}function cr(e){ir();var r=P(function(r){try{var n;return r.send(Xe,h),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(Ve(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!Ve(i)){t=1;break}i=i.s}}var u=new Ge,a=qe.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):qe(u,1,i)})).then(void 0,a),u;function s(r){i=r;do{if(!(o=e())||Ve(o)&&!o.v)return void qe(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ve(i=n())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=n())&&i.then?i.then(s).then(void 0,a):s(i):qe(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(Xe,v),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return b(r,"@EXIT")}}function fr(){return ir(),b(Xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var lr=function(){return{authenticate:Ye,unauthenticate:ar,authorization:Ke,subscribe:cr,snapshot:fr}},dr=function(){return lr().authenticate()},mr=function(){return lr().unauthenticate()},hr=function(){return lr().unauthenticate(),lr().authenticate()},pr=function(){return lr().authenticate()},vr=function(){return lr().authenticate()},yr=lr().authorization,gr="0.0.67-alpha.28";export{gr as VERSION,dr as authenticate,yr as authz,lr as currentUser,Pe as events,vr as logIn,hr as reauthenticate,ae as serialize,pr as signUp,pe as tx,mr as unauthenticate}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/config"),require("@onflow/util-invariant"),require("@onflow/interaction"),require("@onflow/sdk-latest-block"),require("@onflow/util-address"),require("@onflow/sdk-account"),require("@onflow/rlp"),require("@onflow/sdk-resolve"),require("@onflow/util-actor"),require("@onflow/sdk-send"),require("@onflow/sdk-decode"),require("@onflow/sdk-build-transaction-status"),require("@onflow/sdk-build-get-events"),require("@onflow/util-uid"),require("@onflow/util-template"),require("@onflow/sdk-build-transaction"),require("@onflow/sdk-build-script"),require("@onflow/sdk-build-ping"),require("@onflow/sdk-build-get-account"),require("@onflow/sdk-build-get-latest-block"),require("@onflow/sdk-build-get-block-by-id"),require("@onflow/sdk-build-get-block-by-height"),require("@onflow/sdk-build-authorizations"),require("@onflow/sdk-build-arguments"),require("@onflow/sdk-build-proposer"),require("@onflow/sdk-build-payer"),require("@onflow/sdk-build-limit"),require("@onflow/sdk-build-ref"),require("@onflow/sdk-build-params")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/util-invariant","@onflow/interaction","@onflow/sdk-latest-block","@onflow/util-address","@onflow/sdk-account","@onflow/rlp","@onflow/sdk-resolve","@onflow/util-actor","@onflow/sdk-send","@onflow/sdk-decode","@onflow/sdk-build-transaction-status","@onflow/sdk-build-get-events","@onflow/util-uid","@onflow/util-template","@onflow/sdk-build-transaction","@onflow/sdk-build-script","@onflow/sdk-build-ping","@onflow/sdk-build-get-account","@onflow/sdk-build-get-latest-block","@onflow/sdk-build-get-block-by-id","@onflow/sdk-build-get-block-by-height","@onflow/sdk-build-authorizations","@onflow/sdk-build-arguments","@onflow/sdk-build-proposer","@onflow/sdk-build-payer","@onflow/sdk-build-limit","@onflow/sdk-build-ref","@onflow/sdk-build-params"],n):n((e=e||self).fcl={},e.config,e.utilInvariant,e.interaction,e.sdkLatestBlock,e.utilAddress,e.sdkAccount,e.rlp,e.sdkResolve,e.utilActor,e.sdkSend,e.sdkDecode,e.sdkBuildTransactionStatus,e.sdkBuildGetEvents,e.utilUid,e.utilTemplate,e.sdkBuildTransaction,e.sdkBuildScript,e.sdkBuildPing,e.sdkBuildGetAccount,e.sdkBuildGetLatestBlock,e.sdkBuildGetBlockById,e.sdkBuildGetBlockByHeight,e.sdkBuildAuthorizations,e.sdkBuildArguments,e.sdkBuildProposer,e.sdkBuildPayer,e.sdkBuildLimit,e.sdkBuildRef,e.sdkBuildParams)}(this,function(e,n,r,t,o,i,u,a,s,c,l,f,d,p,m,h,v,y,g,b,P,k,w,E,I,S,j,A,O,x){function B(){return(B=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function R(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function T(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return R(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?R(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var C=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},N=function(e){return C(e,8)},L=function(e){return Buffer.from(JSON.stringify(e),"utf8")},z=function(e){return a.encode(e).toString("hex")},U=function(e){return D(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(L),(n=e.refBlock,C(n,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var n,r},q=function(e){var n=_(e);return e.payloadSigs.map(function(e){return{signerIndex:n.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,n){return e.signerIndex>n.signerIndex?1:e.signerIndex<n.signerIndex?-1:e.keyId>n.keyId?1:e.keyId<n.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(n=e.sig,Buffer.from(n,"hex"))];var n})},_=function(e){var n=new Map,r=0,t=function(e){n.has(e)||(n.set(e,r),r++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),n},D=function(e){J.forEach(function(n){return Z(e,n)}),K.forEach(function(n){return Z(e.proposalKey,n,"proposalKey")})},F=function(e){return"number"==typeof e},H=function(e){return"string"==typeof e},M=function(e){return null!==e&&"object"==typeof e},G=function(e){return M(e)&&e instanceof Array},J=[{name:"script",check:H},{name:"arguments",check:G},{name:"refBlock",check:H,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:M},{name:"payer",check:H},{name:"authorizers",check:G}],K=[{name:"address",check:H},{name:"keyId",check:F},{name:"sequenceNum",check:F}],V=[{name:"payloadSigs",check:G}],Y=[{name:"address",check:H},{name:"keyId",check:F},{name:"sig",check:H}],Z=function(e,n,r,t){var o=n.name,i=n.check,u=n.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw X(o,r,t);if(!i(e[o]))throw $(o,r,t)},W=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},X=function(e,n,r){return new Error("Missing field "+W(e,n,r))},$=function(e,n,r){return new Error("Invalid field "+W(e,n,r))},Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ee(e,n,r){if(!e.s){if(r instanceof ne){if(!r.s)return void(r.o=ee.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(ee.bind(null,e,n),ee.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ne=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{ee(t,1,i(this.v))}catch(e){ee(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(t,1,n?n(o):o):r?ee(t,1,r(o)):ee(t,2,o)}catch(e){ee(t,2,e)}},t},e}();function re(e){return e instanceof ne&&1&e.s}function te(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var oe=function e(n,t,o,i){void 0===i&&(i=3);try{r.invariant(i,"Account Resolve Recursion Limit Exceeded",{ix:n,accounts:t}),console.log("resolveAccounts",t,n);var u=function(e,n,r){if("function"==typeof e[Q]){var t,o,i,u=e[Q]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!re(r))return void r.then(e,i||(i=ee.bind(null,o=new ne,2)));r=r.v}o?ee(o,1,r):o=r}catch(e){ee(o||(o=new ne),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,n,r){var t,o,i=-1;return function r(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!re(u))return void u.then(r,o||(o=ee.bind(null,t=new ne,2)));u=u.v}t?ee(t,1,u):t=u}catch(e){ee(t||(t=new ne),2,e)}}(),t}(s,function(e){return n(s[e])})}(t,function(r){function t(){function t(){u.tempId!=r.tempId&&delete n.accounts[u.tempId]}console.log(">>>",{old:u,ax:r});var o=function(){if(Array.isArray(r))return console.log("RECURSE!!",r),Promise.resolve(e(n,r,u,i-1)).then(function(){});n.accounts[r.tempId]=n.accounts[r.tempId]||r,n.accounts[r.tempId].role.proposer=n.accounts[r.tempId].role.proposer||r.role.proposer,n.accounts[r.tempId].role.payer=n.accounts[r.tempId].role.payer||r.role.payer,n.accounts[r.tempId].role.authorizer=n.accounts[r.tempId].role.authorizer||r.role.authorizer,n.proposer===u.tempId&&(n.proposer=r.tempId),n.payer===u.tempId&&(n.payer=r.tempId),n.authorizations=n.authorizations.map(function(e){return e===u.tempId?r.tempId:e})}();return o&&o.then?o.then(t):t()}var u=o||r,a=function(){if(ue(r.resolve))return Promise.resolve(r.resolve(r,function(e,n){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(function(e){return n.arguments[e].asArgument}),data:{},interaction:n}}catch(e){throw console.error("buildPreSignable",e),e}}(r,n))).then(function(e){r=e})}();return a&&a.then?a.then(t):t()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ie=function(e){return"string"==typeof e},ue=function(e){return"function"==typeof e};function ae(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){try{return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:i.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}catch(e){throw console.error("buildSignable",e),e}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function se(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(n){return e.arguments[n].asArgument}),proposalKey:{address:i.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:i.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return i.sansPrefix(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}n.config().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(i){return e=i,Promise.resolve(function(e){try{var o=function(){if(t.isTransaction(e)||t.isScript(e)){var o=function(){return r.invariant(ie(i),"Cadence needs to be a string at this point."),Promise.resolve(n.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},i)})).then(function(n){e.message.cadence=n})},i=t.get(e,"ix.cadence");r.invariant(ue(i)||ie(i),"Cadence needs to be a function or a string.");var u=function(){if(ue(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{if(t.isTransaction(e)||t.isScript(e))for(var n=0,o=Object.entries(e.arguments);n<o.length;n++){var i=o[n];e.arguments[i[0]].asArgument=(r.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),ue(u.xform)?u.xform(u.value):ue(u.xform.asArgument)?u.xform.asArgument(u.value):void r.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e))return te(function(){return console.log("START",e),console.log("AAA",e.accounts),Promise.resolve(oe(e,Object.values(e.accounts))).then(function(){return console.log("BBB",e.accounts),Promise.resolve(oe(e,Object.values(e.accounts))).then(function(){console.log("CCC",e.accounts),console.log("END",e)})})},function(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e})}();return Promise.resolve(n&&n.then?n.then(function(n){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(o.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=Object.values(e.accounts).find(function(e){return e.role.proposer});r.invariant(n,"Transactions require a proposer");var o=function(){if(null==n.sequenceNum)return Promise.resolve(u.account(n.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===n.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[n.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e))return te(function(){var n,r=function(e){var n=new Set(e.authorizations);return n.add(e.proposer),n.delete(e.payer),Array.from(n)}(e),t=(n=se(e),z(U(n)));return Promise.resolve(Promise.all(r.map(ae(e,t)))).then(function(){var n=function(e){var n=new Set([e.payer]);return Array.from(n)}(e),t=function(e){return z(function(e){return function(e){V.forEach(function(n){return Z(e,n)}),e.payloadSigs.forEach(function(e,n){Y.forEach(function(r){return Z(e,r,"payloadSigs",n)})})}(e),[U(e),q(e)]}(e))}(B({},se(e),{payloadSigs:r.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(n.map(ae(e,t)))).then(function(){})})},function(n){throw console.error("Signatures",n,{ix:e}),n})}();return Promise.resolve(n&&n.then?n.then(function(n){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return e})})})})})})})}catch(e){return Promise.reject(e)}});var ce,le,fe=function(e){try{return Promise.resolve(l.send([d.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},de=function(e){return e.status>=4},pe=function(e){return e.status>=3},me=function(e){return e.status>=2},he=((ce={})[c.INIT]=function(e){try{return Promise.resolve(fe(e.self())).then(function(n){de(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ce[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,c.UPDATED,e.all())},ce[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ce[c.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ce.POLL=function(e){try{return Promise.resolve(fe(e.self())).then(function(n){var r,t;de(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(c.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ce),ve=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ye=function(e){return c.spawn(he,ve(e))};function ge(e){function n(n){return c.subscriber(ve(e),ye,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return c.snapshoter(e,ye)},subscribe:n,onceFinalized:r(me),onceExecuted:r(pe),onceSealed:r(de)}}ge.isUnknown=function(e){return e.status>=0},ge.isPending=function(e){return e.status>=1},ge.isFinalized=me,ge.isExecuted=pe,ge.isSealed=de,ge.isExpired=function(e){return 5===e.status};var be=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},Pe=((le={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(o.latestBlock()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(be(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(o.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(l.send([getEvents(e.self(),n.height,r.height-1)]).then(f.decode)).then(function(n){for(var r,t=T(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(be(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},le[c.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(be(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},le[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},le),ke=function(e){return c.spawn(Pe,e)},we={f_type:"Service",f_vsn:"1.0.0"},Ee={f_type:"Identity",f_vsn:"1.0.0"},Ie={f_type:"USER",f_vsn:"1.0.0"},Se={f_type:"PollingResponse",f_vsn:"1.0.0"},je={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Ae(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({old:e},we,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Oe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var xe={"back-channel-rpc":Oe,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:B({},Ee,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:B({},Ee,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({},we,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:Ae};function Be(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Re(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function Te(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Ce(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Te(e),{method:r,headers:B({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({},Se,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:Oe(e.authorizationUpdates),local:Ae((e.local||[])[0])})}}function Le(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return B({},je,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ze="FCL_IFRAME",Ue=function(){},qe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function _e(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return{send:Ue,close:Ue};var t=n.onClose||Ue,o=n.onMessage||Ue,i=n.onReady||Ue;window.addEventListener("message",c);var u=function(e){r.invariant(!document.getElementById(ze),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=ze,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(ze)&&document.getElementById(ze).remove()}]}(Te(e)),a=u[0],s=u[1];return{send:f,close:l};function c(e){try{if("object"!=typeof e.data)return;if(qe.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:f,close:l}),o(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:f,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var De,Fe={"HTTP/GET":"GET","HTTP/POST":"POST"},He=function(e){return r.invariant(Fe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Fe[e.method]},Me=function(e,n){try{return n.data=e.data,Promise.resolve(Ce(e,{data:n}).then(function(e){return console.info("WAT IS THIS",e),e}).then(Ne)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var t=!0,o=_e(n.local,{onClose:function(){t=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Ce(n,{method:He(n)}).then(Ne)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(n.updates,function(){return t}).then(function(e){return o(),Le(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Ge=function(e,n){try{try{return Promise.resolve(Je[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},Je={"HTTP/RPC":Me,"HTTP/POST":Me,"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=m.uid();n.data=e.data,_e(e,{onReady:function(r,t){var i=t.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})}catch(e){throw e}},onClose:function(){t("Declined: Externally Halted")},onMessage:function(e,n){var i=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=Ne(e.data.result);switch(u.status){case"APPROVED":r(Le(u.data)),i();break;case"DECLINED":t("Declined: "+(u.reason||"No reason supplied")),i();break;default:t("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function Ke(e,n,r){if(!e.s){if(r instanceof Ye){if(!r.s)return void(r.o=Ke.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Ke.bind(null,e,n),Ke.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ve=function(e){try{return sn(),Promise.resolve(We()).then(function(n){var r=Re(n.services,"authz"),t=Re(n.services,"pre-authz");return B({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(Ge(t,n)).then(fn)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Ge(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ye=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{Ke(t,1,i(this.v))}catch(e){Ke(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ke(t,1,n?n(o):o):r?Ke(t,1,r(o)):Ke(t,2,o)}catch(e){Ke(t,2,e)}},t},e}();function Ze(e){return e instanceof Ye&&1&e.s}var We=function(){try{return Promise.resolve(new Promise(function(e){try{return sn(),Promise.resolve(pn()).then(function(r){return r.loggedIn&&cn(r)?e(r):Promise.resolve(n.config().get("challenge.handshake")).then(function(n){var r,t,o,u=(r={handshake:n,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function n(r){var t=r.data;try{return t.type===rn||t.type===en?(u(),window.removeEventListener("message",n),Promise.resolve()):t.type!==nn?Promise.resolve():(u(),window.removeEventListener("message",n),Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?i.withPrefix(e.addr):null,e.paddr=e.paddr?i.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=T(e.authorizations);!(r=t()).done;)n.push(B({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(B({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,u=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return xe[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),a=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return B({},Ie,{addr:i.withPrefix(e.addr),cid:Be(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){return c.send(Xe,Qe,n),Promise.resolve(pn()).then(function(n){e(n)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Xe="CURRENT_USER",$e="CURRENT_USER/UPDATED",Qe="SET_CURRENT_USER",en="FCL::CANCEL",nn="FCL::CHALLENGE::RESPONSE",rn="FCL::CHALLENGE::CANCEL",tn='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',on=function(e){try{return sessionStorage.setItem(Xe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},un=function(){return n.config().get("persistSession",!0)},an=((De={})[c.INIT]=function(e){try{return e.merge(JSON.parse(tn)),Promise.resolve(un()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(tn),n=JSON.parse(sessionStorage.getItem(Xe));return null!=n&&e.f_vsn!==n.f_vsn?(sessionStorage.removeItem(Xe),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){cn(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},De[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,$e,B({},e.all()))},De[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},De.SNAPSHOT=function(e,n){try{return n.reply(B({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},De[Qe]=function(e,n,r){try{return e.merge(r),Promise.resolve(un()).then(function(n){n&&on(e.all()),e.broadcast($e,B({},e.all()))})}catch(e){return Promise.reject(e)}},De.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(tn)),Promise.resolve(un()).then(function(n){n&&on(e.all()),e.broadcast($e,B({},e.all()))})}catch(e){return Promise.reject(e)}},De),sn=function(){return c.spawn(an,Xe)};function cn(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function ln(){sn(),c.send(Xe,"DEL_CURRENT_USER")}function fn(e){console.log("rawr(authz)[A]",{authz:e});var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=T(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,u=T(n.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);console.log("rawr(authz)[B]",{authz:e,axs:r,resp:n});var a=r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Ge(r,e)},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}});return console.log("rawr(authz)[x]",{authz:e,result:a}),a}function dn(e){sn();var n=c.spawn(function(n){try{var r;return n.send(Xe,c.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ze(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ze(i)){t=1;break}i=i.s}}var u=new Ye,a=Ke.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Ke(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ze(o)&&!o.v)return void Ke(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ze(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):Ke(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Xe,c.UNSUBSCRIBE),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return c.send(n,"@EXIT")}}function pn(){return sn(),c.send(Xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var mn=function(){return{authenticate:We,unauthenticate:ln,authorization:Ve,subscribe:dn,snapshot:pn}},hn=mn().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return o.latestBlock}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return u.account}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return l.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return p.getEvents}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return v.transaction}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return y.script}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return g.ping}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return b.getAccount}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return k.getBlockById}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return w.getBlockByHeight}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return E.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return E.authorizations}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return I.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return I.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return S.proposer}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return j.payer}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return A.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return O.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return x.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return x.params}}),e.VERSION="0.0.67-alpha.27",e.authenticate=function(){return mn().authenticate()},e.authz=hn,e.currentUser=mn,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,ke,n)}}},e.logIn=function(){return mn().authenticate()},e.reauthenticate=function(){return mn().unauthenticate(),mn().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(n.config().get("sdk.resolve",r.resolve||s.resolve(r))).then(function(n){function o(){return Promise.resolve(n(r)(e)).then(function(e){return JSON.stringify(e,null,2)})}var i=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(n){e=n})}();return i&&i.then?i.then(o):o()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return mn().authenticate()},e.tx=ge,e.unauthenticate=function(){return mn().unauthenticate()}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/config"),require("@onflow/util-invariant"),require("@onflow/interaction"),require("@onflow/sdk-latest-block"),require("@onflow/util-address"),require("@onflow/sdk-account"),require("@onflow/rlp"),require("@onflow/sdk-resolve"),require("@onflow/util-actor"),require("@onflow/sdk-send"),require("@onflow/sdk-decode"),require("@onflow/sdk-build-transaction-status"),require("@onflow/sdk-build-get-events"),require("@onflow/util-uid"),require("@onflow/util-template"),require("@onflow/sdk-build-transaction"),require("@onflow/sdk-build-script"),require("@onflow/sdk-build-ping"),require("@onflow/sdk-build-get-account"),require("@onflow/sdk-build-get-latest-block"),require("@onflow/sdk-build-get-block-by-id"),require("@onflow/sdk-build-get-block-by-height"),require("@onflow/sdk-build-authorizations"),require("@onflow/sdk-build-arguments"),require("@onflow/sdk-build-proposer"),require("@onflow/sdk-build-payer"),require("@onflow/sdk-build-limit"),require("@onflow/sdk-build-ref"),require("@onflow/sdk-build-params")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/util-invariant","@onflow/interaction","@onflow/sdk-latest-block","@onflow/util-address","@onflow/sdk-account","@onflow/rlp","@onflow/sdk-resolve","@onflow/util-actor","@onflow/sdk-send","@onflow/sdk-decode","@onflow/sdk-build-transaction-status","@onflow/sdk-build-get-events","@onflow/util-uid","@onflow/util-template","@onflow/sdk-build-transaction","@onflow/sdk-build-script","@onflow/sdk-build-ping","@onflow/sdk-build-get-account","@onflow/sdk-build-get-latest-block","@onflow/sdk-build-get-block-by-id","@onflow/sdk-build-get-block-by-height","@onflow/sdk-build-authorizations","@onflow/sdk-build-arguments","@onflow/sdk-build-proposer","@onflow/sdk-build-payer","@onflow/sdk-build-limit","@onflow/sdk-build-ref","@onflow/sdk-build-params"],n):n((e=e||self).fcl={},e.config,e.utilInvariant,e.interaction,e.sdkLatestBlock,e.utilAddress,e.sdkAccount,e.rlp,e.sdkResolve,e.utilActor,e.sdkSend,e.sdkDecode,e.sdkBuildTransactionStatus,e.sdkBuildGetEvents,e.utilUid,e.utilTemplate,e.sdkBuildTransaction,e.sdkBuildScript,e.sdkBuildPing,e.sdkBuildGetAccount,e.sdkBuildGetLatestBlock,e.sdkBuildGetBlockById,e.sdkBuildGetBlockByHeight,e.sdkBuildAuthorizations,e.sdkBuildArguments,e.sdkBuildProposer,e.sdkBuildPayer,e.sdkBuildLimit,e.sdkBuildRef,e.sdkBuildParams)}(this,function(e,n,r,t,o,i,u,a,s,c,l,f,d,p,m,h,v,y,g,b,P,k,w,E,I,S,j,A,O,x){function R(){return(R=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function B(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function T(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return B(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?B(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var C=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},N=function(e){return C(e,8)},L=function(e){return Buffer.from(JSON.stringify(e),"utf8")},z=function(e){return a.encode(e).toString("hex")},U=function(e){return D(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(L),(n=e.refBlock,C(n,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var n,r},_=function(e){var n=q(e);return e.payloadSigs.map(function(e){return{signerIndex:n.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,n){return e.signerIndex>n.signerIndex?1:e.signerIndex<n.signerIndex?-1:e.keyId>n.keyId?1:e.keyId<n.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(n=e.sig,Buffer.from(n,"hex"))];var n})},q=function(e){var n=new Map,r=0,t=function(e){n.has(e)||(n.set(e,r),r++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),n},D=function(e){J.forEach(function(n){return X(e,n)}),K.forEach(function(n){return X(e.proposalKey,n,"proposalKey")})},F=function(e){return"number"==typeof e},M=function(e){return"string"==typeof e},H=function(e){return null!==e&&"object"==typeof e},G=function(e){return H(e)&&e instanceof Array},J=[{name:"script",check:M},{name:"arguments",check:G},{name:"refBlock",check:M,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:H},{name:"payer",check:M},{name:"authorizers",check:G}],K=[{name:"address",check:M},{name:"keyId",check:F},{name:"sequenceNum",check:F}],V=[{name:"payloadSigs",check:G}],Y=[{name:"address",check:M},{name:"keyId",check:F},{name:"sig",check:M}],X=function(e,n,r,t){var o=n.name,i=n.check,u=n.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw W(o,r,t);if(!i(e[o]))throw $(o,r,t)},Z=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},W=function(e,n,r){return new Error("Missing field "+Z(e,n,r))},$=function(e,n,r){return new Error("Invalid field "+Z(e,n,r))},Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ee(e,n,r){if(!e.s){if(r instanceof ne){if(!r.s)return void(r.o=ee.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(ee.bind(null,e,n),ee.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ne=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{ee(t,1,i(this.v))}catch(e){ee(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(t,1,n?n(o):o):r?ee(t,1,r(o)):ee(t,2,o)}catch(e){ee(t,2,e)}},t},e}();function re(e){return e instanceof ne&&1&e.s}function te(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var oe=function e(n,t,o,i){void 0===i&&(i=3);try{r.invariant(i,"Account Resolve Recursion Limit Exceeded",{ix:n,accounts:t}),console.log("resolveAccounts",t,n);var u=function(e,n,r){if("function"==typeof e[Q]){var t,o,i,u=e[Q]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!re(r))return void r.then(e,i||(i=ee.bind(null,o=new ne,2)));r=r.v}o?ee(o,1,r):o=r}catch(e){ee(o||(o=new ne),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,n,r){var t,o,i=-1;return function r(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!re(u))return void u.then(r,o||(o=ee.bind(null,t=new ne,2)));u=u.v}t?ee(t,1,u):t=u}catch(e){ee(t||(t=new ne),2,e)}}(),t}(s,function(e){return n(s[e])})}(t,function(r){function t(){function t(){u.tempId!=r.tempId&&delete n.accounts[u.tempId]}console.log(">>>",{old:u,ax:r});var o=function(){if(Array.isArray(r))return console.log("RECURSE!!",r),Promise.resolve(e(n,r,u,i-1)).then(function(){});n.accounts[r.tempId]=n.accounts[r.tempId]||r,n.accounts[r.tempId].role.proposer=n.accounts[r.tempId].role.proposer||r.role.proposer,n.accounts[r.tempId].role.payer=n.accounts[r.tempId].role.payer||r.role.payer,n.accounts[r.tempId].role.authorizer=n.accounts[r.tempId].role.authorizer||r.role.authorizer,n.proposer===u.tempId&&(n.proposer=r.tempId),n.payer===u.tempId&&(n.payer=r.tempId),n.authorizations=n.authorizations.map(function(e){return e===u.tempId?r.tempId:e})}();return o&&o.then?o.then(t):t()}var u=o||r,a=function(){if(ue(r.resolve))return Promise.resolve(r.resolve(r,function(e,n){try{return{"@type":"PreSignable","@vsn":"1.0.0",roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(function(e){return n.arguments[e].asArgument}),data:{},interaction:n}}catch(e){throw console.error("buildPreSignable",e),e}}(r,n))).then(function(e){r=e})}();return a&&a.then?a.then(t):t()});return Promise.resolve(u&&u.then?u.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ie=function(e){return"string"==typeof e},ue=function(e){return"function"==typeof e};function ae(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){try{return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:i.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}catch(e){throw console.error("buildSignable",e),e}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function se(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(n){return e.arguments[n].asArgument}),proposalKey:{address:i.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:i.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return i.sansPrefix(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}n.config().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(i){return e=i,Promise.resolve(function(e){try{var o=function(){if(t.isTransaction(e)||t.isScript(e)){var o=function(){return r.invariant(ie(i),"Cadence needs to be a string at this point."),Promise.resolve(n.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},i)})).then(function(n){e.message.cadence=n})},i=t.get(e,"ix.cadence");r.invariant(ue(i)||ie(i),"Cadence needs to be a function or a string.");var u=function(){if(ue(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{if(t.isTransaction(e)||t.isScript(e))for(var n=0,o=Object.entries(e.arguments);n<o.length;n++){var i=o[n];e.arguments[i[0]].asArgument=(r.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),ue(u.xform)?u.xform(u.value):ue(u.xform.asArgument)?u.xform.asArgument(u.value):void r.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e))return te(function(){return console.log("START",e),console.log("AAA",e.accounts),Promise.resolve(oe(e,Object.values(e.accounts))).then(function(){return console.log("BBB",e.accounts),Promise.resolve(oe(e,Object.values(e.accounts))).then(function(){console.log("CCC",e.accounts),console.log("END",e)})})},function(e){throw console.error("=== SAD PANDA ===\n\n",e,"\n\n=== SAD PANDA ==="),e})}();return Promise.resolve(n&&n.then?n.then(function(n){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(o.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=Object.values(e.accounts).find(function(e){return e.role.proposer});r.invariant(n,"Transactions require a proposer");var o=function(){if(null==n.sequenceNum)return Promise.resolve(u.account(n.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===n.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[n.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e))return te(function(){var n,r=function(e){var n=new Set(e.authorizations);return n.add(e.proposer),n.delete(e.payer),Array.from(n)}(e),t=(n=se(e),z(U(n)));return Promise.resolve(Promise.all(r.map(ae(e,t)))).then(function(){var n=function(e){var n=new Set([e.payer]);return Array.from(n)}(e),t=function(e){return z(function(e){return function(e){V.forEach(function(n){return X(e,n)}),e.payloadSigs.forEach(function(e,n){Y.forEach(function(r){return X(e,r,"payloadSigs",n)})})}(e),[U(e),_(e)]}(e))}(R({},se(e),{payloadSigs:r.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(n.map(ae(e,t)))).then(function(){})})},function(n){throw console.error("Signatures",n,{ix:e}),n})}();return Promise.resolve(n&&n.then?n.then(function(n){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return console.log("PRE_SEND IX",e),e})})})})})})})}catch(e){return Promise.reject(e)}});var ce,le,fe=function(e){try{return Promise.resolve(l.send([d.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},de=function(e){return e.status>=4},pe=function(e){return e.status>=3},me=function(e){return e.status>=2},he=((ce={})[c.INIT]=function(e){try{return Promise.resolve(fe(e.self())).then(function(n){de(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ce[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,c.UPDATED,e.all())},ce[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ce[c.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ce.POLL=function(e){try{return Promise.resolve(fe(e.self())).then(function(n){var r,t;de(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(c.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ce),ve=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ye=function(e){return c.spawn(he,ve(e))};function ge(e){function n(n){return c.subscriber(ve(e),ye,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return c.snapshoter(e,ye)},subscribe:n,onceFinalized:r(me),onceExecuted:r(pe),onceSealed:r(de)}}ge.isUnknown=function(e){return e.status>=0},ge.isPending=function(e){return e.status>=1},ge.isFinalized=me,ge.isExecuted=pe,ge.isSealed=de,ge.isExpired=function(e){return 5===e.status};var be=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},Pe=((le={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(o.latestBlock()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(be(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(o.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(l.send([getEvents(e.self(),n.height,r.height-1)]).then(f.decode)).then(function(n){for(var r,t=T(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(be(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},le[c.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(be(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},le[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},le),ke=function(e){return c.spawn(Pe,e)},we={f_type:"Service",f_vsn:"1.0.0"},Ee={f_type:"Identity",f_vsn:"1.0.0"},Ie={f_type:"USER",f_vsn:"1.0.0"},Se={f_type:"PollingResponse",f_vsn:"1.0.0"},je={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Ae(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({old:e},we,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Oe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var xe={"back-channel-rpc":Oe,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:R({},Ee,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:R({},Ee,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({},we,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:Ae};function Re(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Be(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function Te(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Ce(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Te(e),{method:r,headers:R({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({},Se,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:Oe(e.authorizationUpdates),local:Ae((e.local||[])[0])})}}function Le(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return R({},je,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ze="FCL_IFRAME",Ue=function(){},_e=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function qe(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return{send:Ue,close:Ue};var t=n.onClose||Ue,o=n.onMessage||Ue,i=n.onReady||Ue;window.addEventListener("message",c);var u=function(e){r.invariant(!document.getElementById(ze),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=ze,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(ze)&&document.getElementById(ze).remove()}]}(Te(e)),a=u[0],s=u[1];return{send:f,close:l};function c(e){try{if("object"!=typeof e.data)return;if(_e.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:f,close:l}),o(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:f,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var De,Fe={"HTTP/GET":"GET","HTTP/POST":"POST"},Me=function(e){return r.invariant(Fe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Fe[e.method]},He=function(e,n){try{return n.data=e.data,Promise.resolve(Ce(e,{data:n}).then(Ne)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var t=!0,o=qe(n.local,{onClose:function(){t=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Ce(n,{method:Me(n)}).then(Ne)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(n.updates,function(){return t}).then(function(e){return o(),Le(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Ge=function(e,n){try{try{return Promise.resolve(Je[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},Je={"HTTP/RPC":He,"HTTP/POST":He,"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=m.uid();n.data=e.data,qe(e,{onReady:function(r,t){var i=t.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})}catch(e){throw e}},onClose:function(){t("Declined: Externally Halted")},onMessage:function(e,n){var i=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=Ne(e.data.result);switch(u.status){case"APPROVED":r(Le(u.data)),i();break;case"DECLINED":t("Declined: "+(u.reason||"No reason supplied")),i();break;default:t("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function Ke(e,n,r){if(!e.s){if(r instanceof Ye){if(!r.s)return void(r.o=Ke.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Ke.bind(null,e,n),Ke.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ve=function(e){try{return sn(),Promise.resolve(Ze()).then(function(n){var r=Be(n.services,"authz"),t=Be(n.services,"pre-authz");return R({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(Ge(t,n)).then(fn)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Ge(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ye=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{Ke(t,1,i(this.v))}catch(e){Ke(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ke(t,1,n?n(o):o):r?Ke(t,1,r(o)):Ke(t,2,o)}catch(e){Ke(t,2,e)}},t},e}();function Xe(e){return e instanceof Ye&&1&e.s}var Ze=function(){try{return Promise.resolve(new Promise(function(e){try{return sn(),Promise.resolve(pn()).then(function(r){return r.loggedIn&&cn(r)?e(r):Promise.resolve(n.config().get("challenge.handshake")).then(function(n){var r,t,o,u=(r={handshake:n,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function n(r){var t=r.data;try{return t.type===rn||t.type===en?(u(),window.removeEventListener("message",n),Promise.resolve()):t.type!==nn?Promise.resolve():(u(),window.removeEventListener("message",n),Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?i.withPrefix(e.addr):null,e.paddr=e.paddr?i.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=T(e.authorizations);!(r=t()).done;)n.push(R({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(R({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,u=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return xe[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),a=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return R({},Ie,{addr:i.withPrefix(e.addr),cid:Re(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){return c.send(We,Qe,n),Promise.resolve(pn()).then(function(n){e(n)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},We="CURRENT_USER",$e="CURRENT_USER/UPDATED",Qe="SET_CURRENT_USER",en="FCL::CANCEL",nn="FCL::CHALLENGE::RESPONSE",rn="FCL::CHALLENGE::CANCEL",tn='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',on=function(e){try{return sessionStorage.setItem(We,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},un=function(){return n.config().get("persistSession",!0)},an=((De={})[c.INIT]=function(e){try{return e.merge(JSON.parse(tn)),Promise.resolve(un()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(tn),n=JSON.parse(sessionStorage.getItem(We));return null!=n&&e.f_vsn!==n.f_vsn?(sessionStorage.removeItem(We),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){cn(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},De[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,$e,R({},e.all()))},De[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},De.SNAPSHOT=function(e,n){try{return n.reply(R({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},De[Qe]=function(e,n,r){try{return e.merge(r),Promise.resolve(un()).then(function(n){n&&on(e.all()),e.broadcast($e,R({},e.all()))})}catch(e){return Promise.reject(e)}},De.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(tn)),Promise.resolve(un()).then(function(n){n&&on(e.all()),e.broadcast($e,R({},e.all()))})}catch(e){return Promise.reject(e)}},De),sn=function(){return c.spawn(an,We)};function cn(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function ln(){sn(),c.send(We,"DEL_CURRENT_USER")}function fn(e){console.log("rawr(authz)[A]",{authz:e});var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=T(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,u=T(n.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);console.log("rawr(authz)[B]",{authz:e,axs:r,resp:n});var a=r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Ge(r,e)},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}});return console.log("rawr(authz)[x]",{authz:e,result:a}),a}function dn(e){sn();var n=c.spawn(function(n){try{var r;return n.send(We,c.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Xe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Xe(i)){t=1;break}i=i.s}}var u=new Ye,a=Ke.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Ke(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Xe(o)&&!o.v)return void Ke(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Xe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):Ke(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(We,c.UNSUBSCRIBE),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return c.send(n,"@EXIT")}}function pn(){return sn(),c.send(We,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var mn=function(){return{authenticate:Ze,unauthenticate:ln,authorization:Ve,subscribe:dn,snapshot:pn}},hn=mn().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return o.latestBlock}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return u.account}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return l.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return p.getEvents}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return v.transaction}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return y.script}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return g.ping}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return b.getAccount}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return k.getBlockById}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return w.getBlockByHeight}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return E.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return E.authorizations}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return I.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return I.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return S.proposer}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return j.payer}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return A.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return O.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return x.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return x.params}}),e.VERSION="0.0.67-alpha.28",e.authenticate=function(){return mn().authenticate()},e.authz=hn,e.currentUser=mn,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,ke,n)}}},e.logIn=function(){return mn().authenticate()},e.reauthenticate=function(){return mn().unauthenticate(),mn().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(n.config().get("sdk.resolve",r.resolve||s.resolve(r))).then(function(n){function o(){return Promise.resolve(n(r)(e)).then(function(e){return JSON.stringify(e,null,2)})}var i=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(n){e=n})}();return i&&i.then?i.then(o):o()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return mn().authenticate()},e.tx=ge,e.unauthenticate=function(){return mn().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.67-alpha.27", | ||
"version": "0.0.67-alpha.28", | ||
"description": "Flow Client Library", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
446655
451