Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onflow/fcl

Package Overview
Dependencies
Maintainers
8
Versions
313
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/fcl - npm Package Compare versions

Comparing version 0.0.67-alpha.17 to 0.0.67-alpha.18

4

CHANGELOG.md

@@ -5,2 +5,6 @@ ### Unreleased

### 0.0.67-alpha.18 - 2020-11-26
- 2020-11-23 -- `pre-authz` flatmaps exec-services response
### 0.0.67-alpha.17 - 2020-11-23

@@ -7,0 +11,0 @@

2

dist/fcl.js

@@ -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"),m=require("@onflow/util-template"),h=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"),x=require("@onflow/sdk-build-authorizations"),E=require("@onflow/sdk-build-arguments"),k=require("@onflow/sdk-build-proposer"),S=require("@onflow/sdk-build-payer"),I=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),O=require("@onflow/sdk-build-params");function A(){return(A=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 C(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 C(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)?C(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")},U=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},q=function(e){var r=z(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})},z=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 X(e,r)}),K.forEach(function(r){return X(e.proposalKey,r,"proposalKey")})},F=function(e){return"number"==typeof e},D=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:D},{name:"arguments",check:H},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:M},{name:"payer",check:D},{name:"authorizers",check:H}],K=[{name:"address",check:D},{name:"keyId",check:F},{name:"sequenceNum",check:F}],G=[{name:"payloadSigs",check:H}],V=[{name:"address",check:D},{name:"keyId",check:F},{name:"sig",check:D}],X=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 Z(o,n,t)},Y=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},W=function(e,r,n){return new Error("Missing field "+Y(e,r,n))},Z=function(e,r,n){return new Error("Invalid field "+Y(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(U(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 X(e,r)}),e.payloadSigs.forEach(function(e,r){V.forEach(function(n){return X(e,n,"payloadSigs",r)})})}(e),[U(e),q(e)]}(e))}(A({},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},me=((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),he=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ve=function(e){return s.spawn(me,he(e))};function ye(e){function r(r){return s.subscriber(he(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=R(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"},xe={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"},Se={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Ie(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({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 A({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Oe={"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 A({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},xe,{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 A({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},xe,{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 A({},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:Ie};function Ae(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ce(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function Re(e){var r=new URL(e.endpoint);if(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(Re(e),{method:n,headers:A({},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 A({},ke,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:je(e.authorizationUpdates),local:Ie((e.local||[])[0])})}}function Be(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},Se,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var Le="FCL_IFRAME",Ue=function(){},qe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function ze(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return e;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(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()}]}(Re(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(qe.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,Fe={"HTTP/GET":"GET","HTTP/POST":"POST"},De=function(e){return r.invariant(Fe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Fe[e.method]},Me=function(e,r){try{try{return Promise.resolve(He[e.method](e,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r}),n}}catch(e){return Promise.reject(e)}},He={"HTTP/POST":function(e,n){try{return n.data=e.data,Promise.resolve(Te(e,{data:n}).then(Ne)).then(function(e){var n=!0,t=ze(e.local,{onClose:function(){n=!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:De(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)}}(e.updates,function(){return n}).then(function(e){return t(),Be(e)}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){return new Promise(function(n,t){var o=p.uid();r.data=e.data,ze(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 Je(e,r,n){if(!e.s){if(n instanceof Ge){if(!n.s)return void(n.o=Je.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Je.bind(null,e,r),Je.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(Xe()).then(function(r){var n=Ce(r.services,"authz"),t=Ce(r.services,"pre-authz");return A({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(Me(t,r))}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(Me(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{Je(t,1,i(this.v))}catch(e){Je(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Je(t,1,r?r(o):o):n?Je(t,1,n(o)):Je(t,2,o)}catch(e){Je(t,2,e)}},t},e}();function Ve(e){return e instanceof Ge&&1&e.s}var Xe=function(){try{return Promise.resolve(new Promise(function(r){try{return ir(),Promise.resolve(cr()).then(function(n){return n.loggedIn&&ur(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===er||t.type===$e?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Qe?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=R(e.authorizations);!(n=t()).done;)r.push(A({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(A({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 Oe[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 A({},Ee,{addr:o.withPrefix(e.addr),cid:Ae(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return s.send(Ye,Ze,e),Promise.resolve(cr()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ye="CURRENT_USER",We="CURRENT_USER/UPDATED",Ze="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(Ye,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},tr=function(){return e.config().get("persistSession",!0)},or=((_e={})[s.INIT]=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(Ye));return null!=r&&e.f_vsn!==r.f_vsn?(sessionStorage.removeItem(Ye),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)}},_e[s.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,We,A({},e.all()))},_e[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},_e.SNAPSHOT=function(e,r){try{return r.reply(A({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},_e[Ze]=function(e,r,n){try{return e.merge(n),Promise.resolve(tr()).then(function(r){r&&nr(e.all()),e.broadcast(We,A({},e.all()))})}catch(e){return Promise.reject(e)}},_e.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(We,A({},e.all()))})}catch(e){return Promise.reject(e)}},_e),ir=function(){return s.spawn(or,Ye)};function ur(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function ar(){ir(),s.send(Ye,"DEL_CURRENT_USER")}function sr(e){ir();var r=s.spawn(function(r){try{var n;return r.send(Ye,s.SUBSCRIBE),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=Je.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):Je(u,1,i)})).then(void 0,a),u;function s(r){i=r;do{if(!(o=e())||Ve(o)&&!o.v)return void Je(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):Je(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(Ye,s.UNSUBSCRIBE),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return s.send(r,"@EXIT")}}function cr(){return ir(),s.send(Ye,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var fr=function(){return{authenticate:Xe,unauthenticate:ar,authorization:Ke,subscribe:sr,snapshot:cr}},lr=fr().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 m.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return m.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return h.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 x.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return x.authorizations}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return E.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return E.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return k.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return S.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return I.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return j.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return O.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return O.params}}),exports.VERSION="0.0.67-alpha.17",exports.authenticate=function(){return fr().authenticate()},exports.authz=lr,exports.currentUser=fr,exports.events=function(e){return{subscribe:function(r){return s.subscriber(e,be,r)}}},exports.logIn=function(){return fr().authenticate()},exports.reauthenticate=function(){return fr().unauthenticate(),fr().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 fr().authenticate()},exports.tx=ye,exports.unauthenticate=function(){return fr().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"),m=require("@onflow/util-template"),h=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"),x=require("@onflow/sdk-build-authorizations"),E=require("@onflow/sdk-build-arguments"),k=require("@onflow/sdk-build-proposer"),S=require("@onflow/sdk-build-payer"),I=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),O=require("@onflow/sdk-build-params");function A(){return(A=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")},U=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},z=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")})},F=function(e){return"number"==typeof e},D=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:D},{name:"arguments",check:H},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:M},{name:"payer",check:D},{name:"authorizers",check:H}],K=[{name:"address",check:D},{name:"keyId",check:F},{name:"sequenceNum",check:F}],G=[{name:"payloadSigs",check:H}],V=[{name:"address",check:D},{name:"keyId",check:F},{name:"sig",check:D}],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 X(o,n,t);if(!i(e[o]))throw W(o,n,t)},Z=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},X=function(e,r,n){return new Error("Missing field "+Z(e,r,n))},W=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(U(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),[U(e),z(e)]}(e))}(A({},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},me=((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),he=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ve=function(e){return s.spawn(me,he(e))};function ye(e){function r(r){return s.subscriber(he(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"},xe={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"},Se={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Ie(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({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 A({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Oe={"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 A({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},xe,{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 A({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},xe,{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 A({},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:Ie};function Ae(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(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:A({},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 A({},ke,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:je(e.authorizationUpdates),local:Ie((e.local||[])[0])})}}function Be(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return A({},Se,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var Le="FCL_IFRAME",Ue=function(){},ze=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 e;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(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(ze.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,Fe={"HTTP/GET":"GET","HTTP/POST":"POST"},De=function(e){return r.invariant(Fe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Fe[e.method]},Me=function(e,r){try{try{return Promise.resolve(He[e.method](e,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r}),n}}catch(e){return Promise.reject(e)}},He={"HTTP/POST":function(e,n){try{return n.data=e.data,Promise.resolve(Te(e,{data:n}).then(Ne)).then(function(e){var n=!0,t=qe(e.local,{onClose:function(){n=!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:De(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)}}(e.updates,function(){return n}).then(function(e){return t(),Be(e)}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"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 Je(e,r,n){if(!e.s){if(n instanceof Ge){if(!n.s)return void(n.o=Je.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Je.bind(null,e,r),Je.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=Re(r.services,"authz"),t=Re(r.services,"pre-authz");return A({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(Me(t,r)).then(sr)}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(Me(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{Je(t,1,i(this.v))}catch(e){Je(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Je(t,1,r?r(o):o):n?Je(t,1,n(o)):Je(t,2,o)}catch(e){Je(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.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===er||t.type===$e?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Qe?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(A({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(A({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 Oe[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 A({},Ee,{addr:o.withPrefix(e.addr),cid:Ae(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return s.send(Ze,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)}},Ze="CURRENT_USER",Xe="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(Ze,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},tr=function(){return e.config().get("persistSession",!0)},or=((_e={})[s.INIT]=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(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){ur(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,A({},e.all()))},_e[s.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},_e.SNAPSHOT=function(e,r){try{return r.reply(A({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},_e[We]=function(e,r,n){try{return e.merge(n),Promise.resolve(tr()).then(function(r){r&&nr(e.all()),e.broadcast(Xe,A({},e.all()))})}catch(e){return Promise.reject(e)}},_e.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(Xe,A({},e.all()))})}catch(e){return Promise.reject(e)}},_e),ir=function(){return s.spawn(or,Ze)};function ur(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function ar(){ir(),s.send(Ze,"DEL_CURRENT_USER")}function sr(e){var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:e,payer:[e],authorization:[e]}}(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]);return n.map(function(r){var n=r[0],t=r[1];return{tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:function(r){return Me(e,r)},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}})}function cr(e){ir();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(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=Je.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):Je(u,1,i)})).then(void 0,a),u;function s(r){i=r;do{if(!(o=e())||Ve(o)&&!o.v)return void Je(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):Je(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 fr(){return ir(),s.send(Ze,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var lr=function(){return{authenticate:Ye,unauthenticate:ar,authorization:Ke,subscribe:cr,snapshot:fr}},dr=lr().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 m.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return m.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return h.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 x.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return x.authorizations}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return E.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return E.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return k.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return S.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return I.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return j.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return O.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return O.params}}),exports.VERSION="0.0.67-alpha.18",exports.authenticate=function(){return lr().authenticate()},exports.authz=dr,exports.currentUser=lr,exports.events=function(e){return{subscribe:function(r){return s.subscriber(e,be,r)}}},exports.logIn=function(){return lr().authenticate()},exports.reauthenticate=function(){return lr().unauthenticate(),lr().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 lr().authenticate()},exports.tx=ye,exports.unauthenticate=function(){return lr().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 f}from"@onflow/sdk-resolve";import{subscriber as p,spawn as m,snapshoter as y,INIT as h,SUBSCRIBE as g,UPDATED as w,UNSUBSCRIBE as k,SNAPSHOT as v,send as E}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 C=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},R=function(e){return C(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},L=function(e){return l(e).toString("hex")},T=function(e){return O(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(N),(t=e.refBlock,C(t,32)),e.gasLimit,R(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,R(e.payer),e.authorizers.map(R)];var t,n},P=function(e){var t=_(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})},_=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){D.forEach(function(t){return J(e,t)}),j.forEach(function(t){return J(e.proposalKey,t,"proposalKey")})},z=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},D=[{name:"script",check:F},{name:"arguments",check:B},{name:"refBlock",check:F,defaultVal:"0"},{name:"gasLimit",check:z},{name:"proposalKey",check:U},{name:"payer",check:F},{name:"authorizers",check:B}],j=[{name:"address",check:F},{name:"keyId",check:z},{name:"sequenceNum",check:z}],M=[{name:"payloadSigs",check:B}],H=[{name:"address",check:F},{name:"keyId",check:z},{name:"sig",check:F}],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,X=e=>"function"==typeof e;async function Y(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;X(t.resolve)&&(t=await t.resolve(t,Z(t,e))),console.log(">>>",{old:a,ax:t}),Array.isArray(t)?(console.log("RECURSE!!",t),await Y(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 Z(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(X(s)||V(s),"Cadence needs to be a function or a string."),X(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),X(e.xform)?e.xform(e.value):X(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 Y(e,Object.values(e.accounts)),console.log("BBB",e.accounts),await Y(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),L(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 L(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),P(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||f(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={[h]: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())},[k]:(e,t)=>{e.unsubscribe(t.from)},[v]: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 p(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 y(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)},[k]:(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=>p(e,de,t)}}const fe={f_type:"Service",f_vsn:"1.0.0"},pe={f_type:"Identity",f_vsn:"1.0.0"},me={f_type:"USER",f_vsn:"1.0.0"},ye={f_type:"PollingResponse",f_vsn:"1.0.0"},he={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},fe,{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({},fe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const ke={"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({},fe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},pe,{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({},fe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},pe,{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({},fe,{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 ve(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ee(e=[],t){return e.find(e=>e.type===t)}function be(e){const t=new URL(e.endpoint);if(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({},ye,{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({},he,{addr:c(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const Ae="FCL_IFRAME",Ce=()=>{},Re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ne(e,n={}){if(console.log("FRAME",{service:e,opts:n}),null==e)return e;const r=n.onClose||Ce,o=n.onMessage||Ce,a=n.onReady||Ce;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(Re.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 Le={"HTTP/GET":"GET","HTTP/POST":"POST"},Te=e=>(t(Le[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Le[e.method]),Pe={"HTTP/POST":async function(e,n){n.data=e.data;const r=await Ie(e,{data:n}).then(xe);var o=!0;const{close:a}=Ne(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(e=>(a(),Se(e))).catch(e=>{throw console.error(e),a(),e})},"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const o=S();t.data=e.data,Ne(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 _e(e,t){try{return Pe[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const Oe="CURRENT_USER",ze="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(Oe,JSON.stringify(e)),e),Be=()=>e().get("persistSession",!0),De={[h]:async e=>{if(e.merge(JSON.parse(Fe)),await Be()){const t=await(async()=>{const e=JSON.parse(Fe),t=JSON.parse(sessionStorage.getItem(Oe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Oe),e):t||e})();Me(t)&&e.merge(t)}},[g]:(e,t)=>{e.subscribe(t.from),e.send(t.from,ze,A({},e.all()))},[k]:(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(ze,A({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Fe)),await Be()&&Ue(e.all()),e.broadcast(ze,A({},e.all()))}},je=()=>m(De,Oe);function Me(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function He(){return new Promise(async t=>{je();const n=await Ge();if(n.loggedIn&&Me(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),E(Oe,"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 ke[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:ve(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await Ge()))};window.addEventListener("message",a)})}function Je(){je(),E(Oe,"DEL_CURRENT_USER")}async function qe(e){je();const t=await He(),n=Ee(t.services,"authz"),r=Ee(t.services,"pre-authz");return A({},e,r?{tempId:"CURRENT_USER",resolve:async(e,t)=>_e(r,t)}:{tempId:"CURRENT_USER",resolve:null,addr:c(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>_e(n,e)})}function Ke(e){je();const t=m(async t=>{for(t.send(Oe,g);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(Oe,k);e(n.data)}});return()=>E(t,"@EXIT")}function Ge(){return je(),E(Oe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ve=()=>({authenticate:He,unauthenticate:Je,authorization:qe,subscribe:Ke,snapshot:Ge}),Xe=()=>Ve().authenticate(),Ye=()=>Ve().unauthenticate(),We=()=>(Ve().unauthenticate(),Ve().authenticate()),Ze=()=>Ve().authenticate(),$e=()=>Ve().authenticate(),Qe=Ve().authorization,et="0.0.67-alpha.17";export{et as VERSION,Xe as authenticate,Qe as authz,Ve as currentUser,le as events,$e as logIn,We as reauthenticate,Q as serialize,Ze as signUp,ie as tx,Ye 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 f}from"@onflow/sdk-resolve";import{subscriber as p,spawn as m,snapshoter as y,INIT as h,SUBSCRIBE as g,UPDATED as w,UNSUBSCRIBE as k,SNAPSHOT as E,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)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},P=function(e){return l(e).toString("hex")},T=function(e){return _(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(N),(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=O(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})},O=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},_=function(e){D.forEach(function(t){return J(e,t)}),j.forEach(function(t){return J(e.proposalKey,t,"proposalKey")})},z=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},D=[{name:"script",check:F},{name:"arguments",check:B},{name:"refBlock",check:F,defaultVal:"0"},{name:"gasLimit",check:z},{name:"proposalKey",check:U},{name:"payer",check:F},{name:"authorizers",check:B}],j=[{name:"address",check:F},{name:"keyId",check:z},{name:"sequenceNum",check:z}],M=[{name:"payloadSigs",check:B}],H=[{name:"address",check:F},{name:"keyId",check:z},{name:"sig",check:F}],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,W(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 X(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 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),P(T(t)));await Promise.all(n.map(X(e,r)));let o=function(e){let t=new Set([e.payer]);return Array.from(t)}(e);const a=function(e){return P(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(X(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||f(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={[h]: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())},[k]:(e,t)=>{e.unsubscribe(t.from)},[E]: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 p(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 y(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)},[k]:(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=>p(e,de,t)}}const fe={f_type:"Service",f_vsn:"1.0.0"},pe={f_type:"Identity",f_vsn:"1.0.0"},me={f_type:"USER",f_vsn:"1.0.0"},ye={f_type:"PollingResponse",f_vsn:"1.0.0"},he={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},fe,{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({},fe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const ke={"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({},fe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},pe,{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({},fe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:A({},pe,{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({},fe,{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 Ee(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(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({},ye,{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({},he,{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 Ne(e,n={}){if(console.log("FRAME",{service:e,opts:n}),null==e)return e;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 Pe={"HTTP/GET":"GET","HTTP/POST":"POST"},Te=e=>(t(Pe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Pe[e.method]),Le={"HTTP/POST":async function(e,n){n.data=e.data;const r=await Ie(e,{data:n}).then(xe);var o=!0;const{close:a}=Ne(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(e=>(a(),Se(e))).catch(e=>{throw console.error(e),a(),e})},"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const o=S();t.data=e.data,Ne(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 Le[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const _e="CURRENT_USER",ze="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),De={[h]: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})();Me(t)&&e.merge(t)}},[g]:(e,t)=>{e.subscribe(t.from),e.send(t.from,ze,A({},e.all()))},[k]:(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(ze,A({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Fe)),await Be()&&Ue(e.all()),e.broadcast(ze,A({},e.all()))}},je=()=>m(De,_e);function Me(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function He(){return new Promise(async t=>{je();const n=await Ge();if(n.loggedIn&&Me(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 ke[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:Ee(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await Ge()))};window.addEventListener("message",a)})}function Je(){je(),v(_e,"DEL_CURRENT_USER")}async function qe(e){je();const t=await He(),n=ve(t.services,"authz"),r=ve(t.services,"pre-authz");return A({},e,r?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:e,payer:[e],authorization:[e]}))(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]);return n.map(([t,n])=>({tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:t=>Oe(e,t),role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}))}(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 Ke(e){je();const t=m(async t=>{for(t.send(_e,g);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(_e,k);e(n.data)}});return()=>v(t,"@EXIT")}function Ge(){return je(),v(_e,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ve=()=>({authenticate:He,unauthenticate:Je,authorization:qe,subscribe:Ke,snapshot:Ge}),Ye=()=>Ve().authenticate(),Ze=()=>Ve().unauthenticate(),Xe=()=>(Ve().unauthenticate(),Ve().authenticate()),We=()=>Ve().authenticate(),$e=()=>Ve().authenticate(),Qe=Ve().authorization,et="0.0.67-alpha.18";export{et as VERSION,Ye as authenticate,Qe as authz,Ve as currentUser,le as events,$e as logIn,Xe as reauthenticate,Q as serialize,We 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 b,send as w}from"@onflow/util-actor";import{send as k}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as E}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 j(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 C=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},R=function(e){return C(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},L=function(e){return l(e).toString("hex")},T=function(e){return z(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(N),(n=e.refBlock,C(n,32)),e.gasLimit,R(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,R(e.payer),e.authorizers.map(R)];var n,r},O=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},z=function(e){M.forEach(function(n){return K(e,n)}),H.forEach(function(n){return K(e.proposalKey,n,"proposalKey")})},F=function(e){return"number"==typeof e},U=function(e){return"string"==typeof e},B=function(e){return null!==e&&"object"==typeof e},D=function(e){return B(e)&&e instanceof Array},M=[{name:"script",check:U},{name:"arguments",check:D},{name:"refBlock",check:U,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:B},{name:"payer",check:U},{name:"authorizers",check:D}],H=[{name:"address",check:U},{name:"keyId",check:F},{name:"sequenceNum",check:F}],J=[{name:"payloadSigs",check:D}],q=[{name:"address",check:U},{name:"keyId",check:F},{name:"sig",check:U}],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 X(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))},X=function(e,n,r){return new Error("Invalid field "+G(e,n,r))},Y="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function W(e,n,r){if(!e.s){if(r instanceof Z){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 Z=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 Z&&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[Y]){var t,o,i,u=e[Y]();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 Z,2)));r=r.v}o?W(o,1,r):o=r}catch(e){W(o||(o=new Z),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 Z,2)));u=u.v}t?W(t,1,u):t=u}catch(e){W(t||(t=new Z),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),L(T(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 L(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),[T(e),O(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(k([I(e)]).then(E))}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 b(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(k([getEvents(e.self(),n.height,r.height-1)]).then(E)).then(function(n){for(var r,t=j(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 be={f_type:"Service",f_vsn:"1.0.0"},we={f_type:"Identity",f_vsn:"1.0.0"},ke={f_type:"USER",f_vsn:"1.0.0"},Ee={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},be,{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({},be,{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({},be,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},we,{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({},be,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},we,{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({},be,{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 je(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ce(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function Re(e){var n=new URL(e.endpoint);if(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 Ne(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Re(e),{method:r,headers:x({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Le(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return x({},Ee,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:xe(e.authorizationUpdates),local:Se((e.local||[])[0])})}}function Te(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 Oe="FCL_IFRAME",_e=function(){},ze=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Fe(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return e;var t=r.onClose||_e,o=r.onMessage||_e,i=r.onReady||_e;window.addEventListener("message",c);var u=function(e){n(!document.getElementById(Oe),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=Oe,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(Oe)&&document.getElementById(Oe).remove()}]}(Re(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(ze.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 Ue,Be={"HTTP/GET":"GET","HTTP/POST":"POST"},De=function(e){return n(Be[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Be[e.method]},Me=function(e,n){try{try{return Promise.resolve(He[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},He={"HTTP/POST":function(e,r){try{return r.data=e.data,Promise.resolve(Ne(e,{data:r}).then(Le)).then(function(e){var r=!0,t=Fe(e.local,{onClose:function(){r=!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(Ne(r,{method:De(r)}).then(Le)).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)}}(e.updates,function(){return r}).then(function(e){return t(),Te(e)}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=S();n.data=e.data,Fe(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=Le(e.data.result);switch(u.status){case"APPROVED":r(Te(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 Je(e,n,r){if(!e.s){if(r instanceof Ke){if(!r.s)return void(r.o=Je.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Je.bind(null,e,n),Je.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var qe=function(e){try{return on(),Promise.resolve(Ve()).then(function(n){var r=Ce(n.services,"authz"),t=Ce(n.services,"pre-authz");return x({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(Me(t,n))}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(Me(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ke=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{Je(t,1,i(this.v))}catch(e){Je(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Je(t,1,n?n(o):o):r?Je(t,1,r(o)):Je(t,2,o)}catch(e){Je(t,2,e)}},t},e}();function Ge(e){return e instanceof Ke&&1&e.s}var Ve=function(){try{return Promise.resolve(new Promise(function(n){try{return on(),Promise.resolve(cn()).then(function(r){return r.loggedIn&&un(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===Qe||t.type===Ze?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==$e?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=j(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({},ke,{addr:c(e.addr),cid:je(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return w(Xe,We,e),Promise.resolve(cn()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Xe="CURRENT_USER",Ye="CURRENT_USER/UPDATED",We="SET_CURRENT_USER",Ze="FCL::CANCEL",$e="FCL::CHALLENGE::RESPONSE",Qe="FCL::CHALLENGE::CANCEL",en='{\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}',nn=function(e){try{return sessionStorage.setItem(Xe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},rn=function(){return e().get("persistSession",!0)},tn=((Ue={})[m]=function(e){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(en),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){un(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Ue[h]=function(e,n){e.subscribe(n.from),e.send(n.from,Ye,x({},e.all()))},Ue[v]=function(e,n){e.unsubscribe(n.from)},Ue.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Ue[We]=function(e,n,r){try{return e.merge(r),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Ye,x({},e.all()))})}catch(e){return Promise.reject(e)}},Ue.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Ye,x({},e.all()))})}catch(e){return Promise.reject(e)}},Ue),on=function(){return P(tn,Xe)};function un(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function an(){on(),w(Xe,"DEL_CURRENT_USER")}function sn(e){on();var n=P(function(n){try{var r;return n.send(Xe,h),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ge(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ge(i)){t=1;break}i=i.s}}var u=new Ke,a=Je.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):Je(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ge(o)&&!o.v)return void Je(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ge(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):Je(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,v),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return w(n,"@EXIT")}}function cn(){return on(),w(Xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var fn=function(){return{authenticate:Ve,unauthenticate:an,authorization:qe,subscribe:sn,snapshot:cn}},ln=function(){return fn().authenticate()},dn=function(){return fn().unauthenticate()},mn=function(){return fn().unauthenticate(),fn().authenticate()},hn=function(){return fn().authenticate()},pn=function(){return fn().authenticate()},vn=fn().authorization,yn="0.0.67-alpha.17";export{yn as VERSION,ln as authenticate,vn as authz,fn as currentUser,Pe as events,pn as logIn,mn as reauthenticate,ae as serialize,hn as signUp,pe as tx,dn as unauthenticate};
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 b,send as w}from"@onflow/util-actor";import{send as k}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as E}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},O=function(e){var n=z(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})},z=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")})},F=function(e){return"number"==typeof e},U=function(e){return"string"==typeof e},B=function(e){return null!==e&&"object"==typeof e},D=function(e){return B(e)&&e instanceof Array},M=[{name:"script",check:U},{name:"arguments",check:D},{name:"refBlock",check:U,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:B},{name:"payer",check:U},{name:"authorizers",check:D}],H=[{name:"address",check:U},{name:"keyId",check:F},{name:"sequenceNum",check:F}],J=[{name:"payloadSigs",check:D}],q=[{name:"address",check:U},{name:"keyId",check:F},{name:"sig",check:U}],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 X(e,n,r){if(!e.s){if(r instanceof W){if(!r.s)return void(r.o=X.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(X.bind(null,e,n),X.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var W=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{X(t,1,i(this.v))}catch(e){X(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?X(t,1,n?n(o):o):r?X(t,1,r(o)):X(t,2,o)}catch(e){X(t,2,e)}},t},e}();function $(e){return e instanceof W&&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=X.bind(null,o=new W,2)));r=r.v}o?X(o,1,r):o=r}catch(e){X(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,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=X.bind(null,t=new W,2)));u=u.v}t?X(t,1,u):t=u}catch(e){X(t||(t=new W),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),O(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(k([I(e)]).then(E))}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 b(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(k([getEvents(e.self(),n.height,r.height-1)]).then(E)).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 be={f_type:"Service",f_vsn:"1.0.0"},we={f_type:"Identity",f_vsn:"1.0.0"},ke={f_type:"USER",f_vsn:"1.0.0"},Ee={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},be,{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({},be,{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({},be,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},we,{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({},be,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},we,{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({},be,{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(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({},Ee,{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 Oe="FCL_IFRAME",ze=function(){},_e=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Fe(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return e;var t=r.onClose||ze,o=r.onMessage||ze,i=r.onReady||ze;window.addEventListener("message",c);var u=function(e){n(!document.getElementById(Oe),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=Oe,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(Oe)&&document.getElementById(Oe).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 Ue,Be={"HTTP/GET":"GET","HTTP/POST":"POST"},De=function(e){return n(Be[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Be[e.method]},Me=function(e,n){try{try{return Promise.resolve(He[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},He={"HTTP/POST":function(e,r){try{return r.data=e.data,Promise.resolve(Te(e,{data:r}).then(Ne)).then(function(e){var r=!0,t=Fe(e.local,{onClose:function(){r=!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:De(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)}}(e.updates,function(){return r}).then(function(e){return t(),Le(e)}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=S();n.data=e.data,Fe(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 Je(e,n,r){if(!e.s){if(r instanceof Ke){if(!r.s)return void(r.o=Je.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Je.bind(null,e,n),Je.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var qe=function(e){try{return on(),Promise.resolve(Ve()).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(Me(t,n)).then(sn)}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(Me(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ke=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{Je(t,1,i(this.v))}catch(e){Je(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Je(t,1,n?n(o):o):r?Je(t,1,r(o)):Je(t,2,o)}catch(e){Je(t,2,e)}},t},e}();function Ge(e){return e instanceof Ke&&1&e.s}var Ve=function(){try{return Promise.resolve(new Promise(function(n){try{return on(),Promise.resolve(fn()).then(function(r){return r.loggedIn&&un(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===Qe||t.type===We?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==$e?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({},ke,{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 w(Ye,Xe,e),Promise.resolve(fn()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ye="CURRENT_USER",Ze="CURRENT_USER/UPDATED",Xe="SET_CURRENT_USER",We="FCL::CANCEL",$e="FCL::CHALLENGE::RESPONSE",Qe="FCL::CHALLENGE::CANCEL",en='{\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}',nn=function(e){try{return sessionStorage.setItem(Ye,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},rn=function(){return e().get("persistSession",!0)},tn=((Ue={})[m]=function(e){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(en),n=JSON.parse(sessionStorage.getItem(Ye));return null!=n&&e.f_vsn!==n.f_vsn?(sessionStorage.removeItem(Ye),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){un(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Ue[h]=function(e,n){e.subscribe(n.from),e.send(n.from,Ze,x({},e.all()))},Ue[v]=function(e,n){e.unsubscribe(n.from)},Ue.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Ue[Xe]=function(e,n,r){try{return e.merge(r),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Ze,x({},e.all()))})}catch(e){return Promise.reject(e)}},Ue.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Ze,x({},e.all()))})}catch(e){return Promise.reject(e)}},Ue),on=function(){return P(tn,Ye)};function un(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function an(){on(),w(Ye,"DEL_CURRENT_USER")}function sn(e){var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:e,payer:[e],authorization:[e]}}(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]);return r.map(function(n){var r=n[0],t=n[1];return{tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:function(n){return Me(e,n)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}})}function cn(e){on();var n=P(function(n){try{var r;return n.send(Ye,h),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ge(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ge(i)){t=1;break}i=i.s}}var u=new Ke,a=Je.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):Je(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ge(o)&&!o.v)return void Je(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ge(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):Je(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Ye,v),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return w(n,"@EXIT")}}function fn(){return on(),w(Ye,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ln=function(){return{authenticate:Ve,unauthenticate:an,authorization:qe,subscribe:cn,snapshot:fn}},dn=function(){return ln().authenticate()},mn=function(){return ln().unauthenticate()},hn=function(){return ln().unauthenticate(),ln().authenticate()},pn=function(){return ln().authenticate()},vn=function(){return ln().authenticate()},yn=ln().authorization,gn="0.0.67-alpha.18";export{gn as VERSION,dn as authenticate,yn as authz,ln as currentUser,Pe as events,vn as logIn,hn as reauthenticate,ae as serialize,pn as signUp,pe as tx,mn 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,m,h,p,v,y,g,b,P,k,w,E,S,I,j,A,x,B){function O(){return(O=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 C(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 C(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)?C(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 R=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},N=function(e){return R(e,8)},L=function(e){return Buffer.from(JSON.stringify(e),"utf8")},U=function(e){return a.encode(e).toString("hex")},z=function(e){return F(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(L),(n=e.refBlock,R(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},F=function(e){J.forEach(function(n){return Y(e,n)}),K.forEach(function(n){return Y(e.proposalKey,n,"proposalKey")})},D=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:D},{name:"proposalKey",check:H},{name:"payer",check:M},{name:"authorizers",check:G}],K=[{name:"address",check:M},{name:"keyId",check:D},{name:"sequenceNum",check:D}],V=[{name:"payloadSigs",check:G}],X=[{name:"address",check:M},{name:"keyId",check:D},{name:"sig",check:M}],Y=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 Z(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},Z=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),U(z(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 U(function(e){return function(e){V.forEach(function(n){return Y(e,n)}),e.payloadSigs.forEach(function(e,n){X.forEach(function(r){return Y(e,r,"payloadSigs",n)})})}(e),[z(e),q(e)]}(e))}(O({},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},me=function(e){return e.status>=3},he=function(e){return e.status>=2},pe=((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(pe,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(he),onceExecuted:r(me),onceSealed:r(de)}}ge.isUnknown=function(e){return e.status>=0},ge.isPending=function(e){return e.status>=1},ge.isFinalized=he,ge.isExecuted=me,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"},Se={f_type:"USER",f_vsn:"1.0.0"},Ie={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 O({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 O({},we,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Be={"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 O({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:O({},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 O({},we,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:O({},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 O({},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 Oe(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ce(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(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 Re(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:O({},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 O({},Ie,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:xe(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 O({},je,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var Ue="FCL_IFRAME",ze=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 e;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(Ue),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=Ue,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(Ue)&&document.getElementById(Ue).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 Fe,De={"HTTP/GET":"GET","HTTP/POST":"POST"},Me=function(e){return r.invariant(De[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),De[e.method]},He=function(e,n){try{try{return Promise.resolve(Ge[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},Ge={"HTTP/POST":function(e,n){try{return n.data=e.data,Promise.resolve(Re(e,{data:n}).then(Ne)).then(function(e){var n=!0,t=_e(e.local,{onClose:function(){n=!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(Re(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)}}(e.updates,function(){return n}).then(function(e){return t(),Le(e)}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=h.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 Je(e,n,r){if(!e.s){if(r instanceof Ve){if(!r.s)return void(r.o=Je.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Je.bind(null,e,n),Je.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ke=function(e){try{return an(),Promise.resolve(Ye()).then(function(n){var r=Ce(n.services,"authz"),t=Ce(n.services,"pre-authz");return O({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(He(t,n))}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(He(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ve=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{Je(t,1,i(this.v))}catch(e){Je(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Je(t,1,n?n(o):o):r?Je(t,1,r(o)):Je(t,2,o)}catch(e){Je(t,2,e)}},t},e}();function Xe(e){return e instanceof Ve&&1&e.s}var Ye=function(){try{return Promise.resolve(new Promise(function(e){try{return an(),Promise.resolve(fn()).then(function(r){return r.loggedIn&&sn(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===nn||t.type===Qe?(u(),window.removeEventListener("message",n),Promise.resolve()):t.type!==en?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(O({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(O({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 Be[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 O({},Se,{addr:i.withPrefix(e.addr),cid:Oe(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){return c.send(We,$e,n),Promise.resolve(fn()).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",Ze="CURRENT_USER/UPDATED",$e="SET_CURRENT_USER",Qe="FCL::CANCEL",en="FCL::CHALLENGE::RESPONSE",nn="FCL::CHALLENGE::CANCEL",rn='{\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}',tn=function(e){try{return sessionStorage.setItem(We,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},on=function(){return n.config().get("persistSession",!0)},un=((Fe={})[c.INIT]=function(e){try{return e.merge(JSON.parse(rn)),Promise.resolve(on()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(rn),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){sn(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Fe[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,Ze,O({},e.all()))},Fe[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Fe.SNAPSHOT=function(e,n){try{return n.reply(O({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Fe[$e]=function(e,n,r){try{return e.merge(r),Promise.resolve(on()).then(function(n){n&&tn(e.all()),e.broadcast(Ze,O({},e.all()))})}catch(e){return Promise.reject(e)}},Fe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(rn)),Promise.resolve(on()).then(function(n){n&&tn(e.all()),e.broadcast(Ze,O({},e.all()))})}catch(e){return Promise.reject(e)}},Fe),an=function(){return c.spawn(un,We)};function sn(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function cn(){an(),c.send(We,"DEL_CURRENT_USER")}function ln(e){an();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 Ve,a=Je.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):Je(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Xe(o)&&!o.v)return void Je(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):Je(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 fn(){return an(),c.send(We,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var dn=function(){return{authenticate:Ye,unauthenticate:cn,authorization:Ke,subscribe:ln,snapshot:fn}},mn=dn().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 m.getEvents}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return p.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return p.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 S.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return S.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return I.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 x.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return B.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return B.params}}),e.VERSION="0.0.67-alpha.17",e.authenticate=function(){return dn().authenticate()},e.authz=mn,e.currentUser=dn,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,ke,n)}}},e.logIn=function(){return dn().authenticate()},e.reauthenticate=function(){return dn().unauthenticate(),dn().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 dn().authenticate()},e.tx=ge,e.unauthenticate=function(){return dn().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,f,l,d,m,p,h,v,y,g,b,P,k,w,E,S,I,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")},U=function(e){return a.encode(e).toString("hex")},z=function(e){return F(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},F=function(e){J.forEach(function(n){return Z(e,n)}),K.forEach(function(n){return Z(e.proposalKey,n,"proposalKey")})},D=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:D},{name:"proposalKey",check:H},{name:"payer",check:M},{name:"authorizers",check:G}],K=[{name:"address",check:M},{name:"keyId",check:D},{name:"sequenceNum",check:D}],V=[{name:"payloadSigs",check:G}],Y=[{name:"address",check:M},{name:"keyId",check:D},{name:"sig",check:M}],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 W(o,r,t);if(!i(e[o]))throw $(o,r,t)},X=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},W=function(e,n,r){return new Error("Missing field "+X(e,n,r))},$=function(e,n,r){return new Error("Invalid field "+X(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),U(z(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 U(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),[z(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,fe,le=function(e){try{return Promise.resolve(f.send([d.getTransactionStatus(e)]).then(l.decode))}catch(e){return Promise.reject(e)}},de=function(e){return e.status>=4},me=function(e){return e.status>=3},pe=function(e){return e.status>=2},he=((ce={})[c.INIT]=function(e){try{return Promise.resolve(le(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(le(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(pe),onceExecuted:r(me),onceSealed:r(de)}}ge.isUnknown=function(e){return e.status>=0},ge.isPending=function(e){return e.status>=1},ge.isFinalized=pe,ge.isExecuted=me,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=((fe={}).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(f.send([getEvents(e.self(),n.height,r.height-1)]).then(l.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)}},fe[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)}},fe[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},fe),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"},Se={f_type:"USER",f_vsn:"1.0.0"},Ie={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(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({},Ie,{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 Ue="FCL_IFRAME",ze=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 e;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(Ue),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=Ue,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(Ue)&&document.getElementById(Ue).remove()}]}(Te(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(qe.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,De={"HTTP/GET":"GET","HTTP/POST":"POST"},Me=function(e){return r.invariant(De[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),De[e.method]},He=function(e,n){try{try{return Promise.resolve(Ge[e.method](e,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:n}),r}}catch(e){return Promise.reject(e)}},Ge={"HTTP/POST":function(e,n){try{return n.data=e.data,Promise.resolve(Ce(e,{data:n}).then(Ne)).then(function(e){var n=!0,t=_e(e.local,{onClose:function(){n=!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)}}(e.updates,function(){return n}).then(function(e){return t(),Le(e)}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=p.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 Je(e,n,r){if(!e.s){if(r instanceof Ve){if(!r.s)return void(r.o=Je.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Je.bind(null,e,n),Je.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ke=function(e){try{return an(),Promise.resolve(Ze()).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(He(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(He(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ve=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{Je(t,1,i(this.v))}catch(e){Je(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Je(t,1,n?n(o):o):r?Je(t,1,r(o)):Je(t,2,o)}catch(e){Je(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(e){try{return an(),Promise.resolve(dn()).then(function(r){return r.loggedIn&&sn(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===nn||t.type===Qe?(u(),window.removeEventListener("message",n),Promise.resolve()):t.type!==en?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({},Se,{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,$e,n),Promise.resolve(dn()).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",We="CURRENT_USER/UPDATED",$e="SET_CURRENT_USER",Qe="FCL::CANCEL",en="FCL::CHALLENGE::RESPONSE",nn="FCL::CHALLENGE::CANCEL",rn='{\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}',tn=function(e){try{return sessionStorage.setItem(Xe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},on=function(){return n.config().get("persistSession",!0)},un=((Fe={})[c.INIT]=function(e){try{return e.merge(JSON.parse(rn)),Promise.resolve(on()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(rn),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){sn(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Fe[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,We,B({},e.all()))},Fe[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Fe.SNAPSHOT=function(e,n){try{return n.reply(B({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Fe[$e]=function(e,n,r){try{return e.merge(r),Promise.resolve(on()).then(function(n){n&&tn(e.all()),e.broadcast(We,B({},e.all()))})}catch(e){return Promise.reject(e)}},Fe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(rn)),Promise.resolve(on()).then(function(n){n&&tn(e.all()),e.broadcast(We,B({},e.all()))})}catch(e){return Promise.reject(e)}},Fe),an=function(){return c.spawn(un,Xe)};function sn(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function cn(){an(),c.send(Xe,"DEL_CURRENT_USER")}function fn(e){var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:e,payer:[e],authorization:[e]}}(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]);return r.map(function(n){var r=n[0],t=n[1];return{tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:function(n){return He(e,n)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}})}function ln(e){an();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(Ye(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ye(i)){t=1;break}i=i.s}}var u=new Ve,a=Je.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):Je(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ye(o)&&!o.v)return void Je(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ye(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):Je(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 dn(){return an(),c.send(Xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var mn=function(){return{authenticate:Ze,unauthenticate:cn,authorization:Ke,subscribe:ln,snapshot:dn}},pn=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 f.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return l.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return m.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 S.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return S.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return I.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.18",e.authenticate=function(){return mn().authenticate()},e.authz=pn,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.17",
"version": "0.0.67-alpha.18",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc