📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP

@onflow/fcl

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/fcl - npm Package Compare versions

Comparing version

to
0.0.68-alpha.7

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

### 0.0.68-alpha.[1..3] - 2022-02-02
### 0.0.68-alpha.7 - 2021-03-02
- 2022-02-02 -- Adds support for new `GetEvents`, `GetBlockHeader`, `GetBlock`, `GetTransaction` interactions.
- 2021-03-02 -- Authn now uses frame mechanism from Authz flow.
- This is in prep for sending config details to wallet during handshake.
- Enables standardized `FCL:FRAME:CLOSE` message for closing frame
- Introduces a new standardized response `FCL:FRAME:RESPONSE` for wallets to pass the final response back.
- Introduces a new standardized open response `FCL:FRAME:OPEN` for wallets that need to escape the iframe in web browser
- This is backwards compatible with older versions of the FCL wallet spec, but will not be included in V1 release.
- 2021-03-02 -- Introduced new config `discovery.wallet`. This will eventually replace `challenge.handshake`.
- Current implementation will look for `discovery.wallet` first and then fallback onto `challenge.handshake`.
- This is backwards compatible with older version of FCL, but will not be included in V1 release.
New Wallet AUTHN Flow will now look like this:
```
FCL Wallet
| |
|-------[Render Frame]------>|
| |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[OPTIONAL READY FLOW]
|<----[FCL:FRAME:READY]------| // Enables wallet to receive
|----[APP DETAILS/NEEDS]---->| // Application specific details/needs
| [handles details]------*
| |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[OPTIONAL TAB FLOW]
|<----[FCL:FRAME:OPEN]-------| // Some authentication flows cant
|------[Open Tab]----------->| // Be handled in an iframe
| |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[GOLDEN AUTH PATH]
|<----[FCL:FRAME:RESPONSE]---|
*-------[handles auth] |
|-------[Close Frame]---X |
|--------[Close Tab]----X |
| |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[CANCEL AUTH PATH]
|<----[FCL:FRAME:CLOSE]------|
|-------[Close Frame]---X |
|--------[Close Tab]----X |
| |
```
`FCL:FRAME:OPEN` payload needs to look like this:
```json
{
"type": "FCL:FRAME:OPEN",
"endpoint": "https://google.com"
}
```
> The opened tab (web view in something like Unity/iOS?) will not be responsible for sending the Final `FCL:FRAME:RESPONSE` or `FCL:FRAME:CLOSE` messages (this will need to be the frame), but FCL will attempt to close the tab one authn is complete.
### 0.0.68-alpha.[1..6] - 2021-02-02
- 2021-02-02 -- Adds support for new `GetEvents`, `GetBlockHeader`, `GetBlock`, `GetTransaction` interactions.
### 0.0.67 - 2021-01-14

@@ -11,0 +63,0 @@

@@ -1,2 +0,2 @@

var e=require("@onflow/config"),t=require("@onflow/sdk"),r=require("@onflow/util-actor"),n=require("@onflow/util-address"),o=require("@onflow/rlp"),i=require("@onflow/util-invariant"),u=require("@onflow/util-uid"),a=require("@onflow/util-template");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e.config().put("sdk.resolve",t.resolve);var s,c,f=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},l=function(e){return e.status>=4},d=function(e){return e.status>=3},p=function(e){return e.status>=2},h=((s={})[r.INIT]=function(e){try{return Promise.resolve(f(e.self())).then(function(t){l(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},s[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,r.UPDATED,e.all())},s[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},s[r.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},s.POLL=function(e){try{return Promise.resolve(f(e.self())).then(function(t){var n,o;l(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),o=t,JSON.stringify(n)!==JSON.stringify(o)&&e.broadcast(r.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},s),m=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},v=function(e){return r.spawn(h,m(e))};function y(e){function t(t){return r.subscriber(m(e),v,t)}function n(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return r.snapshoter(e,v)},subscribe:t,onceFinalized:n(p),onceExecuted:n(d),onceSealed:n(l)}}function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function b(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return P(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)?P(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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)}y.isUnknown=function(e){return e.status>=0},y.isPending=function(e){return e.status>=1},y.isFinalized=p,y.isExecuted=d,y.isSealed=l,y.isExpired=function(e){return 5===e.status};var E=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},x=((c={}).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(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(E(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(t.send([getEvents(e.self(),r.height,n.height-1)]).then(t.decode)).then(function(t){for(var r,n=b(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(E(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},c[r.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(E(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},c[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},c),w=function(e){return r.spawn(x,e)},S={f_type:"Service",f_vsn:"1.0.0"},j={f_type:"Identity",f_vsn:"1.0.0"},O={f_type:"USER",f_vsn:"1.0.0"},I={f_type:"PollingResponse",f_vsn:"1.0.0"},R={f_type:"CompositeSignature",f_vsn:"1.0.0"};function k(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({old:e},S,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},S,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var C={"back-channel-rpc":A,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:g({},j,{address:n.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 g({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:g({},j,{address:n.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 g({},S,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:n.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:k};function T(e){return o.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function B(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function N(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function L(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(N(e),{method:r,headers:g({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function U(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},I,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:A(e.authorizationUpdates),local:k((e.local||[])[0])})}}function _(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},R,{addr:n.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var z="FCL_IFRAME",D=function(){},F=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function H(e,t){if(void 0===t&&(t={}),console.log("FRAME",{service:e,opts:t}),null==e)return{send:D,close:D};var r=t.onClose||D,n=t.onMessage||D,o=t.onReady||D;window.addEventListener("message",c);var u=function(e){i.invariant(!document.getElementById(z),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=z,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,function(){document.getElementById(z)&&document.getElementById(z).remove()}]}(N(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(F.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:l,close:f}),n(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&o(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(),r()}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(t){console.error("Frame Send Error",e,t)}}}var M,J={"HTTP/GET":"GET","HTTP/POST":"POST"},q=function(e){return i.invariant(J[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),J[e.method]},G=function(e,t){try{return t.data=e.data,Promise.resolve(L(e,{data:t}).then(U)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0,n=H(t.local,{onClose:function(){r=!1}}).close;return function e(t,r){void 0===r&&(r=function(){return!0});try{if(i.invariant(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(L(t,{method:q(t)}).then(U)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return r}).then(function(e){return n(),_(e)}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},V=function(e,t){try{try{return Promise.resolve(Y[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},Y={"HTTP/RPC":G,"HTTP/POST":G,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=u.uid();t.data=e.data,H(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=U(e.data.result);switch(u.status){case"APPROVED":r(_(u.data)),i();break;case"DECLINED":n("Declined: "+(u.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function Z(e,t,r){if(!e.s){if(r instanceof X){if(!r.s)return void(r.o=Z.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Z.bind(null,e,t),Z.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var K=function(e){try{return ce(),Promise.resolve($()).then(function(t){var r=B(t.services,"authz"),o=B(t.services,"pre-authz");return g({},e,o?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(V(o,t)).then(de)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:n.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(V(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},X=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Z(n,1,i(this.v))}catch(e){Z(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Z(n,1,t?t(o):o):r?Z(n,1,r(o)):Z(n,2,o)}catch(e){Z(n,2,e)}},n},e}();function W(e){return e instanceof X&&1&e.s}var $=function(){try{return Promise.resolve(new Promise(function(t){try{return ce(),Promise.resolve(he()).then(function(o){return o.loggedIn&&fe(o)?t(o):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var o,i,u,a=(o={handshake:e,l6n:window.location.origin},i=o.l6n,(u=new URL(o.handshake)).searchParams.append("l6n",i),function(e){if(!document.getElementById("FCL_IFRAME")){var 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,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(u.href))[1];window.addEventListener("message",function e(o){var i=o.data;try{return i.type===oe||i.type===re?(a(),window.removeEventListener("message",e),Promise.resolve()):i.type!==ne?Promise.resolve():(a(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?n.withPrefix(e.addr):null,e.paddr=e.paddr?n.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=b(e.authorizations);!(r=n()).done;)t.push(g({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(g({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var o,i,u=(o=t,i=r,void 0===o&&(o=[]),void 0===i&&(i=[]),[].concat(o,i)).map(function(t){return function(e,t){try{return C[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,u);return g({},O,{addr:n.withPrefix(e.addr),cid:T(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(i)).then(function(e){return r.send(Q,te,e),Promise.resolve(he()).then(function(e){t(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Q="CURRENT_USER",ee="CURRENT_USER/UPDATED",te="SET_CURRENT_USER",re="FCL::CANCEL",ne="FCL::CHALLENGE::RESPONSE",oe="FCL::CHALLENGE::CANCEL",ie='{\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=function(e){try{return sessionStorage.setItem(Q,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ae=function(){return e.config().get("persistSession",!0)},se=((M={})[r.INIT]=function(e){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(Q));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Q),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){fe(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},M[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,ee,g({},e.all()))},M[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},M.SNAPSHOT=function(e,t){try{return t.reply(g({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},M[te]=function(e,t,r){try{return e.merge(r),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(ee,g({},e.all()))})}catch(e){return Promise.reject(e)}},M.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(ee,g({},e.all()))})}catch(e){return Promise.reject(e)}},M),ce=function(){return r.spawn(se,Q)};function fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function le(){ce(),r.send(Q,"DEL_CURRENT_USER")}function de(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=b(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=b(t.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return V(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function pe(e){ce();var t=r.spawn(function(t){try{var n;return t.send(Q,r.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(W(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!W(i)){n=1;break}i=i.s}}var u=new X,a=Z.bind(null,u,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Z(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||W(o)&&!o.v)return void Z(u,1,i);if(o.then)return void o.then(c).then(void 0,a);W(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):Z(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(o){if("@EXIT"===o.tag)return t.send(Q,r.UNSUBSCRIBE),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(t,"@EXIT")}}function he(){return ce(),r.send(Q,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var me=function(){return{authenticate:$,unauthenticate:le,authorization:K,subscribe:pe,snapshot:he}},ve=me().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return n.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return n.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return n.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return a.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return a.template}}),exports.VERSION="0.0.68-alpha.6",exports.authenticate=function(){return me().authenticate()},exports.authz=ve,exports.currentUser=me,exports.events=function(e){return{subscribe:function(t){return r.subscriber(e,w,t)}}},exports.logIn=function(){return me().authenticate()},exports.reauthenticate=function(){return me().unauthenticate(),me().authenticate()},exports.serialize=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e.config().get("sdk.resolve",n.resolve||t.resolve(n))).then(function(e){function n(){return Promise.resolve(e(r)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(r))return Promise.resolve(t.pipe(t.interaction(),r)).then(function(e){r=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return me().authenticate()},exports.tx=y,exports.unauthenticate=function(){return me().unauthenticate()};
var e=require("@onflow/config"),t=require("@onflow/sdk"),r=require("@onflow/util-actor"),n=require("@onflow/util-address"),o=require("@onflow/rlp"),i=require("@onflow/util-invariant"),u=require("@onflow/util-uid"),a=require("@onflow/util-template");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e.config().put("sdk.resolve",t.resolve);var s,c,f=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},l=function(e){return e.status>=4},d=function(e){return e.status>=3},p=function(e){return e.status>=2},h=((s={})[r.INIT]=function(e){try{return Promise.resolve(f(e.self())).then(function(t){l(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},s[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,r.UPDATED,e.all())},s[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},s[r.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},s.POLL=function(e){try{return Promise.resolve(f(e.self())).then(function(t){var n,o;l(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),o=t,JSON.stringify(n)!==JSON.stringify(o)&&e.broadcast(r.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},s),m=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},v=function(e){return r.spawn(h,m(e))};function y(e){function t(t){return r.subscriber(m(e),v,t)}function n(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return r.snapshoter(e,v)},subscribe:t,onceFinalized:n(p),onceExecuted:n(d),onceSealed:n(l)}}function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function b(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return P(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)?P(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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)}y.isUnknown=function(e){return e.status>=0},y.isPending=function(e){return e.status>=1},y.isFinalized=p,y.isExecuted=d,y.isSealed=l,y.isExpired=function(e){return 5===e.status};var E=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},x=((c={}).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(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(E(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(t.send([getEvents(e.self(),r.height,n.height-1)]).then(t.decode)).then(function(t){for(var r,n=b(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(E(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},c[r.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(E(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},c[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},c),S=function(e){return r.spawn(x,e)},O={f_type:"Service",f_vsn:"1.0.0"},j={f_type:"Identity",f_vsn:"1.0.0"},w={f_type:"USER",f_vsn:"1.0.0"},R={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function k(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({old:e},O,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},O,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var T={"back-channel-rpc":A,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},O,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:g({},j,{address:n.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 g({},O,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:g({},j,{address:n.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 g({},O,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:n.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:k};function C(e){return o.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function B(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function N(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function U(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(N(e),{method:r,headers:g({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function _(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},R,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:A(e.authorizationUpdates),local:k((e.local||[])[0])})}}function D(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return g({},I,{addr:n.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var L="FCL_IFRAME",z=function(){},F=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function H(e,t){if(void 0===t&&(t={}),console.log("FRAME",{service:e,opts:t}),null==e)return{send:z,close:z};var r=t.onClose||z,n=t.onMessage||z,o=t.onReady||z,u=t.onResponse||z;window.addEventListener("message",f);var a=function(e){i.invariant(!document.getElementById(L),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=L,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,function(){document.getElementById(L)&&document.getElementById(L).remove()}]}(N(e)),s=a[0],c=a[1];return{send:d,close:l};function f(e){try{if("object"!=typeof e.data)return;if(F.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:l}),n(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&(console.log("BOOP"),u(e,{send:d,close:l})),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,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",f),c(),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)}}}var M,J={"HTTP/GET":"GET","HTTP/POST":"POST"},q=function(e){return i.invariant(J[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),J[e.method]},G=function(e,t){try{return t.data=e.data,Promise.resolve(U(e,{data:t}).then(_)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0,n=H(t.local,{onClose:function(){r=!1}}).close;return function e(t,r){void 0===r&&(r=function(){return!0});try{if(i.invariant(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(U(t,{method:q(t)}).then(_)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return r}).then(function(e){return n(),D(e)}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Y=function(e,t){try{try{return Promise.resolve(V[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},V={"HTTP/RPC":G,"HTTP/POST":G,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=u.uid();t.data=e.data,H(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=_(e.data.result);switch(u.status){case"APPROVED":r(D(u.data)),i();break;case"DECLINED":n("Declined: "+(u.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function Z(e,t,r){if(!e.s){if(r instanceof X){if(!r.s)return void(r.o=Z.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Z.bind(null,e,t),Z.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var K=function(e){try{return ue(),Promise.resolve($()).then(function(t){var r=B(t.services,"authz"),o=B(t.services,"pre-authz");return g({},e,o?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Y(o,t)).then(ce)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:n.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Y(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},X=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Z(n,1,i(this.v))}catch(e){Z(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Z(n,1,t?t(o):o):r?Z(n,1,r(o)):Z(n,2,o)}catch(e){Z(n,2,e)}},n},e}();function W(e){return e instanceof X&&1&e.s}var $=function(){try{return Promise.resolve(new Promise(function(t,o){try{return ue(),Promise.resolve(le()).then(function(o){return o.loggedIn&&ae(o)?t(o):Promise.resolve(e.config().get("discovery.wallet")).then(function(o){function i(e){H({endpoint:e},{onReady:function(e,t){console.log("ON READY",e)},onClose:function(){try{return Promise.resolve(le()).then(function(e){t(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,o){var i=o.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?n.withPrefix(e.addr):null,e.paddr=e.paddr?n.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=b(e.authorizations);!(r=n()).done;)t.push(g({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(g({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var o,i,u=(o=t,i=r,void 0===o&&(o=[]),void 0===i&&(i=[]),[].concat(o,i)).map(function(t){return function(e,t){try{return T[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,u);return g({},w,{addr:n.withPrefix(e.addr),cid:C(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return r.send(Q,te,e),Promise.resolve(le()).then(function(e){t(e),i()})})}catch(e){return Promise.reject(e)}}})}return o?i(o):Promise.resolve(e.config().get("challenge.handshake")).then(i)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Q="CURRENT_USER",ee="CURRENT_USER/UPDATED",te="SET_CURRENT_USER",re='{\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}',ne=function(e){try{return sessionStorage.setItem(Q,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},oe=function(){return e.config().get("persistSession",!0)},ie=((M={})[r.INIT]=function(e){try{return e.merge(JSON.parse(re)),Promise.resolve(oe()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(re),t=JSON.parse(sessionStorage.getItem(Q));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Q),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){ae(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},M[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,ee,g({},e.all()))},M[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},M.SNAPSHOT=function(e,t){try{return t.reply(g({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},M[te]=function(e,t,r){try{return e.merge(r),Promise.resolve(oe()).then(function(t){t&&ne(e.all()),e.broadcast(ee,g({},e.all()))})}catch(e){return Promise.reject(e)}},M.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(re)),Promise.resolve(oe()).then(function(t){t&&ne(e.all()),e.broadcast(ee,g({},e.all()))})}catch(e){return Promise.reject(e)}},M),ue=function(){return r.spawn(ie,Q)};function ae(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function se(){ue(),r.send(Q,"DEL_CURRENT_USER")}function ce(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=b(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=b(t.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Y(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function fe(e){ue();var t=r.spawn(function(t){try{var n;return t.send(Q,r.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(W(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!W(i)){n=1;break}i=i.s}}var u=new X,a=Z.bind(null,u,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):Z(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||W(o)&&!o.v)return void Z(u,1,i);if(o.then)return void o.then(c).then(void 0,a);W(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):Z(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(o){if("@EXIT"===o.tag)return t.send(Q,r.UNSUBSCRIBE),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(t,"@EXIT")}}function le(){return ue(),r.send(Q,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var de=function(){return{authenticate:$,unauthenticate:se,authorization:K,subscribe:fe,snapshot:le}},pe=de().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return n.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return n.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return n.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return a.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return a.template}}),exports.VERSION="0.0.68-alpha.7",exports.authenticate=function(){return de().authenticate()},exports.authz=pe,exports.currentUser=de,exports.events=function(e){return{subscribe:function(t){return r.subscriber(e,S,t)}}},exports.logIn=function(){return de().authenticate()},exports.reauthenticate=function(){return de().unauthenticate(),de().authenticate()},exports.serialize=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e.config().get("sdk.resolve",n.resolve||t.resolve(n))).then(function(e){function n(){return Promise.resolve(e(r)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(r))return Promise.resolve(t.pipe(t.interaction(),r)).then(function(e){r=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return de().authenticate()},exports.tx=y,exports.unauthenticate=function(){return de().unauthenticate()};
//# sourceMappingURL=fcl.js.map

@@ -1,2 +0,2 @@

import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,pipe as n,interaction as r,send as a,getTransactionStatus as o,decode as s,latestBlock as i}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{subscriber as c,spawn as d,snapshoter as u,INIT as l,SUBSCRIBE as p,UPDATED as f,UNSUBSCRIBE as h,SNAPSHOT as m,send as y}from"@onflow/util-actor";import{withPrefix as g,sansPrefix as E}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as w}from"@onflow/rlp";import{invariant as v}from"@onflow/util-invariant";import{uid as R}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);const S=async(a=[],o={})=>{const s=await e().get("sdk.resolve",o.resolve||t(o));return Array.isArray(a)&&(a=await n(r(),a)),JSON.stringify(await s(a),null,2)},b=async e=>a([o(e)]).then(s),I=e=>e.status>=4,C=e=>e.status>=3,P=e=>e.status>=2,T={[l]:async e=>{const t=await b(e.self());I(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[p]:(e,t)=>{e.subscribe(t.from),e.send(t.from,f,e.all())},[h]:(e,t)=>{e.unsubscribe(t.from)},[m]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await b(e.self());var n,r;I(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(f,t),e.merge(t)}},A=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},k=e=>d(T,A(e));function L(e){function t(t){return c(A(e),k,t)}function n(e){return function(n={}){const r=n.suppress||!1;return new Promise((n,a)=>{const o=t(t=>{t.statusCode&&!r?(a(t.errorMessage),o()):e(t)&&(n(t),o())})})}}return{snapshot:function(){return u(e,k)},subscribe:t,onceFinalized:n(P),onceExecuted:n(C),onceSealed:n(I)}}L.isUnknown=e=>e.status>=0,L.isPending=e=>e.status>=1,L.isFinalized=P,L.isExecuted=C,L.isSealed=I,L.isExpired=e=>5===e.status;const N=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),x={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await N(e));else{let n=await i();e.put("hwm",n);const r=await a([getEvents(e.self(),t.height,n.height-1)]).then(s);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await N(e))}},[p]:async(e,t)=>{e.hasSubs()||e.put("tick",await N(e)),e.subscribe(t.from)},[h]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},_=e=>d(x,e);function O(e){return{subscribe:t=>c(e,_,t)}}function F(){return(F=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)}const U={f_type:"Service",f_vsn:"1.0.0"},D={f_type:"Identity",f_vsn:"1.0.0"},z={f_type:"USER",f_vsn:"1.0.0"},B={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function M(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({old:e},U,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const J={"back-channel-rpc":j,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:F({},D,{address:g(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 F({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:F({},D,{address:g(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 F({},U,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:g(e.addr),name:e.name,icon:e.icon}})}},frame:M};function G(e){return w([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Y(e=[],t){return e.find(e=>e.type===t)}function V(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[n,r]of Object.entries(e.params||{}))t.searchParams.append(n,r);return t}function Z(e,t={}){const n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(V(e),{method:n,headers:F({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(e=>e.json())}function q(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},B,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:j(e.authorizationUpdates),local:M((e.local||[])[0])})}}function K(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},H,{addr:E(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const X="FCL_IFRAME",W=()=>{},$=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Q(e,t={}){if(console.log("FRAME",{service:e,opts:t}),null==e)return{send:W,close:W};const n=t.onClose||W,r=t.onMessage||W,a=t.onReady||W;window.addEventListener("message",i);const[o,s]=function(e){v(!document.getElementById(X),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=X,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(X)&&document.getElementById(X).remove()}]}(V(e));return{send:d,close:c};function i(e){try{if("object"!=typeof e.data)return;if($.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&c(),"FCL:FRAME:READY"===e.data.type&&a(e,{send:d,close:c}),r(e,{send:d,close:c}),"FCL::AUTHZ_READY"===e.data.type&&a(e,{send:d,close:c}),"FCL::CHALLENGE::CANCEL"===e.data.type&&c(),"FCL::CANCEL"===e.data.type&&c()}catch(e){console.error("Frame Callback Error",e),c()}}function c(){try{window.removeEventListener("message",i),s(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),o.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const ee={"HTTP/GET":"GET","HTTP/POST":"POST"},te=e=>(v(ee[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ee[e.method]);async function ne(e,t){t.data=e.data;const n=await Z(e,{data:t}).then(q);if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var r=!0;const{close:e}=Q(n.local,{onClose(){r=!1}});return async function e(t,n=(()=>!0)){if(v(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");const r=await Z(t,{method:te(t)}).then(q);switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(r.updates,n)}}(n.updates,()=>r).then(t=>(e(),K(t))).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")}const re={"HTTP/RPC":ne,"HTTP/POST":ne,"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const a=R();t.data=e.data,Q(e,{onReady(n,{send:r}){try{r({jsonrpc:"2.0",id:a,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!==a)return;const o=q(e.data.result);switch(o.status){case"APPROVED":n(K(o.data)),t();break;case"DECLINED":r("Declined: "+(o.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 ae(e,t){try{return re[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const oe="CURRENT_USER",se="CURRENT_USER/UPDATED",ie='{\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}',ce=async e=>(sessionStorage.setItem(oe,JSON.stringify(e)),e),de=()=>e().get("persistSession",!0),ue={[l]:async e=>{if(e.merge(JSON.parse(ie)),await de()){const t=await(async()=>{const e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(oe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(oe),e):t||e})();pe(t)&&e.merge(t)}},[p]:(e,t)=>{e.subscribe(t.from),e.send(t.from,se,F({},e.all()))},[h]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(F({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await de()&&ce(e.all()),e.broadcast(se,F({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(ie)),await de()&&ce(e.all()),e.broadcast(se,F({},e.all()))}},le=()=>d(ue,oe);function pe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function fe(){return new Promise(async t=>{le();const n=await ge();if(n.loggedIn&&pe(n))return t(n);const[r,a]=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}),o=async({data:e})=>{if("FCL::CHALLENGE::CANCEL"===e.type||"FCL::CANCEL"===e.type)return a(),void window.removeEventListener("message",o);"FCL::CHALLENGE::RESPONSE"===e.type&&(a(),window.removeEventListener("message",o),y(oe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?g(e.addr):null,e.paddr=e.paddr?g(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 a=[];if(Array.isArray(r.authorizations))for(let e of r.authorizations)a.push(F({type:"authz",keyId:r.keyId},e));return null!=r.provider&&a.push(F({type:"authn",id:"wallet-provider#authn"},r.provider)),a}(e.hks,e.code)).map(t=>function(e,t){try{return J[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 F({},z,{addr:g(e.addr),cid:G(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await ge()))};window.addEventListener("message",o)})}function he(){le(),y(oe,"DEL_CURRENT_USER")}async function me(e){le();const t=await fe(),n=Y(t.services,"authz"),r=Y(t.services,"pre-authz");return F({},e,r?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}))(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])n.push(["PAYER",e]);for(let e of t.authorization||[])n.push(["AUTHORIZER",e]);return n.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>ae(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await ae(r,t))}:{tempId:"CURRENT_USER",resolve:null,addr:E(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>ae(n,e)})}function ye(e){le();const t=d(async t=>{for(t.send(oe,p);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(oe,h);e(n.data)}});return()=>y(t,"@EXIT")}function ge(){return le(),y(oe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ee=()=>({authenticate:fe,unauthenticate:he,authorization:me,subscribe:ye,snapshot:ge}),we=()=>Ee().authenticate(),ve=()=>Ee().unauthenticate(),Re=()=>(Ee().unauthenticate(),Ee().authenticate()),Se=()=>Ee().authenticate(),be=()=>Ee().authenticate(),Ie=Ee().authorization,Ce="0.0.68-alpha.6";export{Ce as VERSION,we as authenticate,Ie as authz,Ee as currentUser,O as events,be as logIn,Re as reauthenticate,S as serialize,Se as signUp,L as tx,ve as unauthenticate};
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,pipe as n,interaction as a,send as r,getTransactionStatus as s,decode as o,latestBlock as i}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{subscriber as c,spawn as d,snapshoter as u,INIT as l,SUBSCRIBE as p,UPDATED as f,UNSUBSCRIBE as h,SNAPSHOT as y,send as m}from"@onflow/util-actor";import{withPrefix as g,sansPrefix as w}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as E}from"@onflow/rlp";import{invariant as v}from"@onflow/util-invariant";import{uid as R}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);const S=async(r=[],s={})=>{const o=await e().get("sdk.resolve",s.resolve||t(s));return Array.isArray(r)&&(r=await n(a(),r)),JSON.stringify(await o(r),null,2)},P=async e=>r([s(e)]).then(o),T=e=>e.status>=4,I=e=>e.status>=3,b=e=>e.status>=2,k={[l]:async e=>{const t=await P(e.self());T(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[p]:(e,t)=>{e.subscribe(t.from),e.send(t.from,f,e.all())},[h]:(e,t)=>{e.unsubscribe(t.from)},[y]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await P(e.self());var n,a;T(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(f,t),e.merge(t)}},A=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},C=e=>d(k,A(e));function N(e){function t(t){return c(A(e),C,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,r)=>{const s=t(t=>{t.statusCode&&!a?(r(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return u(e,C)},subscribe:t,onceFinalized:n(b),onceExecuted:n(I),onceSealed:n(T)}}N.isUnknown=e=>e.status>=0,N.isPending=e=>e.status>=1,N.isFinalized=b,N.isExecuted=I,N.isSealed=T,N.isExpired=e=>5===e.status;const O=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),_={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await O(e));else{let n=await i();e.put("hwm",n);const a=await r([getEvents(e.self(),t.height,n.height-1)]).then(o);for(let t of a)e.broadcast("UPDATED",t.data);e.put("tick",await O(e))}},[p]:async(e,t)=>{e.hasSubs()||e.put("tick",await O(e)),e.subscribe(t.from)},[h]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},x=e=>d(_,e);function L(e){return{subscribe:t=>c(e,x,t)}}function D(){return(D=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const U={f_type:"Service",f_vsn:"1.0.0"},z={f_type:"Identity",f_vsn:"1.0.0"},F={f_type:"USER",f_vsn:"1.0.0"},B={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return D({old:e},U,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function M(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return D({},U,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const J={"back-channel-rpc":M,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return D({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:D({},z,{address:g(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 D({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:D({},z,{address:g(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 D({},U,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:g(e.addr),name:e.name,icon:e.icon}})}},frame:j};function G(e){return E([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Y(e=[],t){return e.find(e=>e.type===t)}function V(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[n,a]of Object.entries(e.params||{}))t.searchParams.append(n,a);return t}function Z(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(V(e),{method:n,headers:D({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function q(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return D({},B,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:M(e.authorizationUpdates),local:j((e.local||[])[0])})}}function K(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return D({},H,{addr:w(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const X="FCL_IFRAME",W=()=>{},$=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Q(e,t={}){if(console.log("FRAME",{service:e,opts:t}),null==e)return{send:W,close:W};const n=t.onClose||W,a=t.onMessage||W,r=t.onReady||W,s=t.onResponse||W;window.addEventListener("message",c);const[o,i]=function(e){v(!document.getElementById(X),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=X,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(X)&&document.getElementById(X).remove()}]}(V(e));return{send:u,close:d};function c(e){try{if("object"!=typeof e.data)return;if($.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&d(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:u,close:d}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:u,close:d}),a(e,{send:u,close:d}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&(console.log("BOOP"),s(e,{send:u,close:d})),"FCL::AUTHZ_READY"===e.data.type&&r(e,{send:u,close:d}),"FCL::CHALLENGE::CANCEL"===e.data.type&&d(),"FCL::CANCEL"===e.data.type&&d()}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),n()}catch(e){console.error("Frame Close Error",e)}}function u(e){try{console.log("SEND",e),o.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const ee={"HTTP/GET":"GET","HTTP/POST":"POST"},te=e=>(v(ee[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ee[e.method]);async function ne(e,t){t.data=e.data;const n=await Z(e,{data:t}).then(q);if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var a=!0;const{close:e}=Q(n.local,{onClose(){a=!1}});return async function e(t,n=(()=>!0)){if(v(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");const a=await Z(t,{method:te(t)}).then(q);switch(a.status){case"APPROVED":return a.data;case"DECLINED":throw new Error("Declined: "+(a.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(a.updates,n)}}(n.updates,()=>a).then(t=>(e(),K(t))).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")}const ae={"HTTP/RPC":ne,"HTTP/POST":ne,"IFRAME/RPC":function(e,t){return new Promise((n,a)=>{const r=R();t.data=e.data,Q(e,{onReady(n,{send:a}){try{a({jsonrpc:"2.0",id:r,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose(){a("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!==r)return;const s=q(e.data.result);switch(s.status){case"APPROVED":n(K(s.data)),t();break;case"DECLINED":a("Declined: "+(s.reason||"No reason supplied")),t();break;default:a("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};async function re(e,t){try{return ae[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const se="CURRENT_USER",oe="CURRENT_USER/UPDATED",ie='{\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}',ce=async e=>(sessionStorage.setItem(se,JSON.stringify(e)),e),de=()=>e().get("persistSession",!0),ue={[l]:async e=>{if(e.merge(JSON.parse(ie)),await de()){const t=await(async()=>{const e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(se));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(se),e):t||e})();pe(t)&&e.merge(t)}},[p]:(e,t)=>{e.subscribe(t.from),e.send(t.from,oe,D({},e.all()))},[h]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(D({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await de()&&ce(e.all()),e.broadcast(oe,D({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(ie)),await de()&&ce(e.all()),e.broadcast(oe,D({},e.all()))}},le=()=>d(ue,se);function pe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function fe(){return new Promise(async(t,n)=>{le();const a=await ge();if(a.loggedIn&&pe(a))return t(a);Q({endpoint:await e().get("discovery.wallet")||await e().get("challenge.handshake")},{onReady(e,{}){console.log("ON READY",e)},async onClose(){t(await ge())},async onResponse(e,{close:n}){m(se,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?g(e.addr):null,e.paddr=e.paddr?g(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 a=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(a))return a;const r=[];if(Array.isArray(a.authorizations))for(let e of a.authorizations)r.push(D({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(D({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return J[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 D({},F,{addr:g(e.addr),cid:G(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e.data)),t(await ge()),n()}})})}function he(){le(),m(se,"DEL_CURRENT_USER")}async function ye(e){le();const t=await fe(),n=Y(t.services,"authz"),a=Y(t.services,"pre-authz");return D({},e,a?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}))(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])n.push(["PAYER",e]);for(let e of t.authorization||[])n.push(["AUTHORIZER",e]);return n.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>re(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await re(a,t))}:{tempId:"CURRENT_USER",resolve:null,addr:w(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>re(n,e)})}function me(e){le();const t=d(async t=>{for(t.send(se,p);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(se,h);e(n.data)}});return()=>m(t,"@EXIT")}function ge(){return le(),m(se,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const we=()=>({authenticate:fe,unauthenticate:he,authorization:ye,subscribe:me,snapshot:ge}),Ee=()=>we().authenticate(),ve=()=>we().unauthenticate(),Re=()=>(we().unauthenticate(),we().authenticate()),Se=()=>we().authenticate(),Pe=()=>we().authenticate(),Te=we().authorization,Ie="0.0.68-alpha.7";export{Ie as VERSION,Ee as authenticate,Te as authz,we as currentUser,L as events,Pe as logIn,Re as reauthenticate,S as serialize,Se as signUp,N as tx,ve as unauthenticate};
//# sourceMappingURL=fcl.modern.js.map

@@ -1,2 +0,2 @@

import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,pipe as n,interaction as r,send as o,getTransactionStatus as i,decode as a,latestBlock as s}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{INIT as u,SUBSCRIBE as c,UPDATED as l,UNSUBSCRIBE as d,SNAPSHOT as f,subscriber as h,spawn as p,snapshoter as m,send as v}from"@onflow/util-actor";import{withPrefix as y,sansPrefix as P}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as g}from"@onflow/rlp";import{invariant as E}from"@onflow/util-invariant";import{uid as w}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);var b,S,R=function(o,i){void 0===o&&(o=[]),void 0===i&&(i={});try{return Promise.resolve(e().get("sdk.resolve",i.resolve||t(i))).then(function(e){function t(){return Promise.resolve(e(o)).then(function(e){return JSON.stringify(e,null,2)})}var i=function(){if(Array.isArray(o))return Promise.resolve(n(r(),o)).then(function(e){o=e})}();return i&&i.then?i.then(t):t()})}catch(e){return Promise.reject(e)}},I=function(e){try{return Promise.resolve(o([i(e)]).then(a))}catch(e){return Promise.reject(e)}},A=function(e){return e.status>=4},C=function(e){return e.status>=3},k=function(e){return e.status>=2},T=((b={})[u]=function(e){try{return Promise.resolve(I(e.self())).then(function(t){A(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},b[c]=function(e,t){e.subscribe(t.from),e.send(t.from,l,e.all())},b[d]=function(e,t){e.unsubscribe(t.from)},b[f]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},b.POLL=function(e){try{return Promise.resolve(I(e.self())).then(function(t){var n,r;A(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(l,t),e.merge(t)})}catch(e){return Promise.reject(e)}},b),L=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},j=function(e){return p(T,L(e))};function x(e){function t(t){return h(L(e),j,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return m(e,j)},subscribe:t,onceFinalized:n(k),onceExecuted:n(C),onceSealed:n(A)}}function N(){return(N=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)}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function _(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return O(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)?O(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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)}x.isUnknown=function(e){return e.status>=0},x.isPending=function(e){return e.status>=1},x.isFinalized=k,x.isExecuted=C,x.isSealed=A,x.isExpired=function(e){return 5===e.status};var F=function(t){try{var n=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},D=((S={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),n=function(){if(null==t){var n=e.put;return Promise.resolve(s()).then(function(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(F(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(s()).then(function(n){return e.put("hwm",n),Promise.resolve(o([getEvents(e.self(),t.height,n.height-1)]).then(a)).then(function(t){for(var n,r=_(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(F(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},S[c]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(F(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},S[d]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},S),U=function(e){return p(D,e)};function z(e){return{subscribe:function(t){return h(e,U,t)}}}var B={f_type:"Service",f_vsn:"1.0.0"},H={f_type:"Identity",f_vsn:"1.0.0"},M={f_type:"USER",f_vsn:"1.0.0"},J={f_type:"PollingResponse",f_vsn:"1.0.0"},G={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Y(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return N({old:e},B,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function V(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return N({},B,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Z={"back-channel-rpc":V,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return N({},B,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:N({},H,{address:y(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 N({},B,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:N({},H,{address:y(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 N({},B,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:y(e.addr),name:e.name,icon:e.icon}})}},frame:Y};function q(e){return g([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function K(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function X(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function W(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(X(e),{method:n,headers:N({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function $(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return N({},J,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:V(e.authorizationUpdates),local:Y((e.local||[])[0])})}}function Q(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return N({},G,{addr:P(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ee="FCL_IFRAME",te=function(){},ne=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function re(e,t){if(void 0===t&&(t={}),console.log("FRAME",{service:e,opts:t}),null==e)return{send:te,close:te};var n=t.onClose||te,r=t.onMessage||te,o=t.onReady||te;window.addEventListener("message",u);var i=function(e){E(!document.getElementById(ee),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=ee,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,function(){document.getElementById(ee)&&document.getElementById(ee).remove()}]}(X(e)),a=i[0],s=i[1];return{send:l,close:c};function u(e){try{if("object"!=typeof e.data)return;if(ne.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&c(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:l,close:c}),r(e,{send:l,close:c}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:l,close:c}),"FCL::CHALLENGE::CANCEL"===e.data.type&&c(),"FCL::CANCEL"===e.data.type&&c()}catch(e){console.error("Frame Callback Error",e),c()}}function c(){try{window.removeEventListener("message",u),s(),n()}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(t){console.error("Frame Send Error",e,t)}}}var oe,ie={"HTTP/GET":"GET","HTTP/POST":"POST"},ae=function(e){return E(ie[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ie[e.method]},se=function(e,t){try{return t.data=e.data,Promise.resolve(W(e,{data:t}).then($)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,r=re(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(E(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(W(t,{method:ae(t)}).then($)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return r(),Q(e)}).catch(function(e){throw console.error(e),r(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},ue=function(e,t){try{try{return Promise.resolve(ce[e.method](e,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}catch(e){return Promise.reject(e)}},ce={"HTTP/RPC":se,"HTTP/POST":se,"IFRAME/RPC":function(e,t){return new Promise(function(n,r){var o=w();t.data=e.data,re(e,{onReady:function(n,r){var i=r.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){r("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var a=$(e.data.result);switch(a.status){case"APPROVED":n(Q(a.data)),i();break;case"DECLINED":r("Declined: "+(a.reason||"No reason supplied")),i();break;default:r("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function le(e,t,n){if(!e.s){if(n instanceof fe){if(!n.s)return void(n.o=le.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(le.bind(null,e,t),le.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var de=function(e){try{return Ie(),Promise.resolve(pe()).then(function(t){var n=K(t.services,"authz"),r=K(t.services,"pre-authz");return N({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(ue(r,t)).then(ke)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:P(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(ue(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},fe=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{le(r,1,i(this.v))}catch(e){le(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?le(r,1,t?t(o):o):n?le(r,1,n(o)):le(r,2,o)}catch(e){le(r,2,e)}},r},e}();function he(e){return e instanceof fe&&1&e.s}var pe=function(){try{return Promise.resolve(new Promise(function(t){try{return Ie(),Promise.resolve(Le()).then(function(n){return n.loggedIn&&Ae(n)?t(n):Promise.resolve(e().get("challenge.handshake")).then(function(e){var n,r,o,i=(n={handshake:e,l6n:window.location.origin},r=n.l6n,(o=new URL(n.handshake)).searchParams.append("l6n",r),function(e){if(!document.getElementById("FCL_IFRAME")){var 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,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function e(n){var r=n.data;try{return r.type===Ee||r.type===Pe?(i(),window.removeEventListener("message",e),Promise.resolve()):r.type!==ge?Promise.resolve():(i(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?y(e.addr):null,e.paddr=e.paddr?y(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var n,r=_(e.authorizations);!(n=r()).done;)t.push(N({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(N({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,o,i=(r=t,o=n,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(t){return function(e,t){try{return Z[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return N({},M,{addr:y(e.addr),cid:q(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(r)).then(function(e){return v(me,ye,e),Promise.resolve(Le()).then(function(e){t(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},me="CURRENT_USER",ve="CURRENT_USER/UPDATED",ye="SET_CURRENT_USER",Pe="FCL::CANCEL",ge="FCL::CHALLENGE::RESPONSE",Ee="FCL::CHALLENGE::CANCEL",we='{\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}',be=function(e){try{return sessionStorage.setItem(me,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Se=function(){return e().get("persistSession",!0)},Re=((oe={})[u]=function(e){try{return e.merge(JSON.parse(we)),Promise.resolve(Se()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(we),t=JSON.parse(sessionStorage.getItem(me));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(me),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Ae(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},oe[c]=function(e,t){e.subscribe(t.from),e.send(t.from,ve,N({},e.all()))},oe[d]=function(e,t){e.unsubscribe(t.from)},oe.SNAPSHOT=function(e,t){try{return t.reply(N({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},oe[ye]=function(e,t,n){try{return e.merge(n),Promise.resolve(Se()).then(function(t){t&&be(e.all()),e.broadcast(ve,N({},e.all()))})}catch(e){return Promise.reject(e)}},oe.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(we)),Promise.resolve(Se()).then(function(t){t&&be(e.all()),e.broadcast(ve,N({},e.all()))})}catch(e){return Promise.reject(e)}},oe),Ie=function(){return p(Re,me)};function Ae(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ce(){Ie(),v(me,"DEL_CURRENT_USER")}function ke(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=_(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,a=_(t.authorization||[]);!(i=a()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return ue(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Te(e){Ie();var t=p(function(t){try{var n;return t.send(me,c),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(he(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!he(i)){r=1;break}i=i.s}}var a=new fe,s=le.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):le(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||he(o)&&!o.v)return void le(a,1,i);if(o.then)return void o.then(c).then(void 0,s);he(i=n())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=n())&&i.then?i.then(u).then(void 0,s):u(i):le(a,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(r){if("@EXIT"===r.tag)return t.send(me,d),void(n=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(t,"@EXIT")}}function Le(){return Ie(),v(me,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var je=function(){return{authenticate:pe,unauthenticate:Ce,authorization:de,subscribe:Te,snapshot:Le}},xe=function(){return je().authenticate()},Ne=function(){return je().unauthenticate()},Oe=function(){return je().unauthenticate(),je().authenticate()},_e=function(){return je().authenticate()},Fe=function(){return je().authenticate()},De=je().authorization,Ue="0.0.68-alpha.6";export{Ue as VERSION,xe as authenticate,De as authz,je as currentUser,z as events,Fe as logIn,Oe as reauthenticate,R as serialize,_e as signUp,x as tx,Ne as unauthenticate};
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,pipe as r,interaction as n,send as o,getTransactionStatus as i,decode as a,latestBlock as u}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{INIT as s,SUBSCRIBE as c,UPDATED as l,UNSUBSCRIBE as d,SNAPSHOT as f,subscriber as h,spawn as p,snapshoter as m,send as v}from"@onflow/util-actor";import{withPrefix as y,sansPrefix as P}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as g}from"@onflow/rlp";import{invariant as E}from"@onflow/util-invariant";import{uid as w}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);var S,b,R=function(o,i){void 0===o&&(o=[]),void 0===i&&(i={});try{return Promise.resolve(e().get("sdk.resolve",i.resolve||t(i))).then(function(e){function t(){return Promise.resolve(e(o)).then(function(e){return JSON.stringify(e,null,2)})}var i=function(){if(Array.isArray(o))return Promise.resolve(r(n(),o)).then(function(e){o=e})}();return i&&i.then?i.then(t):t()})}catch(e){return Promise.reject(e)}},I=function(e){try{return Promise.resolve(o([i(e)]).then(a))}catch(e){return Promise.reject(e)}},A=function(e){return e.status>=4},T=function(e){return e.status>=3},k=function(e){return e.status>=2},j=((S={})[s]=function(e){try{return Promise.resolve(I(e.self())).then(function(t){A(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},S[c]=function(e,t){e.subscribe(t.from),e.send(t.from,l,e.all())},S[d]=function(e,t){e.unsubscribe(t.from)},S[f]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},S.POLL=function(e){try{return Promise.resolve(I(e.self())).then(function(t){var r,n;A(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(l,t),e.merge(t)})}catch(e){return Promise.reject(e)}},S),C=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},O=function(e){return p(j,C(e))};function N(e){function t(t){return h(C(e),O,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return m(e,O)},subscribe:t,onceFinalized:r(k),onceExecuted:r(T),onceSealed:r(A)}}function _(){return(_=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function L(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return x(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)?x(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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.isUnknown=function(e){return e.status>=0},N.isPending=function(e){return e.status>=1},N.isFinalized=k,N.isExecuted=T,N.isSealed=A,N.isExpired=function(e){return 5===e.status};var D=function(t){try{var r=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},U=((b={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(u()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(D(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(u()).then(function(r){return e.put("hwm",r),Promise.resolve(o([getEvents(e.self(),t.height,r.height-1)]).then(a)).then(function(t){for(var r,n=L(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(D(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},b[c]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(D(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},b[d]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},b),z=function(e){return p(U,e)};function F(e){return{subscribe:function(t){return h(e,z,t)}}}var B={f_type:"Service",f_vsn:"1.0.0"},H={f_type:"Identity",f_vsn:"1.0.0"},M={f_type:"USER",f_vsn:"1.0.0"},J={f_type:"PollingResponse",f_vsn:"1.0.0"},G={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Y(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({old:e},B,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function V(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},B,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Z={"back-channel-rpc":V,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},B,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},H,{address:y(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,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},H,{address:y(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,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:y(e.addr),name:e.name,icon:e.icon}})}},frame:Y};function q(e){return g([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function K(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function X(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function W(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(X(e),{method:r,headers:_({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function $(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},J,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:V(e.authorizationUpdates),local:Y((e.local||[])[0])})}}function Q(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},G,{addr:P(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ee="FCL_IFRAME",te=function(){},re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function ne(e,t){if(void 0===t&&(t={}),console.log("FRAME",{service:e,opts:t}),null==e)return{send:te,close:te};var r=t.onClose||te,n=t.onMessage||te,o=t.onReady||te,i=t.onResponse||te;window.addEventListener("message",c);var a=function(e){E(!document.getElementById(ee),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=ee,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,function(){document.getElementById(ee)&&document.getElementById(ee).remove()}]}(X(e)),u=a[0],s=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(re.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),n(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&(console.log("BOOP"),i(e,{send:d,close:l})),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,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(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),u.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var oe,ie={"HTTP/GET":"GET","HTTP/POST":"POST"},ae=function(e){return E(ie[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ie[e.method]},ue=function(e,t){try{return t.data=e.data,Promise.resolve(W(e,{data:t}).then($)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0,n=ne(t.local,{onClose:function(){r=!1}}).close;return function e(t,r){void 0===r&&(r=function(){return!0});try{if(E(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(W(t,{method:ae(t)}).then($)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return r}).then(function(e){return n(),Q(e)}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},se=function(e,t){try{try{return Promise.resolve(ce[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},ce={"HTTP/RPC":ue,"HTTP/POST":ue,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=w();t.data=e.data,ne(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var a=$(e.data.result);switch(a.status){case"APPROVED":r(Q(a.data)),i();break;case"DECLINED":n("Declined: "+(a.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function le(e,t,r){if(!e.s){if(r instanceof fe){if(!r.s)return void(r.o=le.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(le.bind(null,e,t),le.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var de=function(e){try{return Se(),Promise.resolve(pe()).then(function(t){var r=K(t.services,"authz"),n=K(t.services,"pre-authz");return _({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(se(n,t)).then(Ie)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:P(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(se(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},fe=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{le(n,1,i(this.v))}catch(e){le(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?le(n,1,t?t(o):o):r?le(n,1,r(o)):le(n,2,o)}catch(e){le(n,2,e)}},n},e}();function he(e){return e instanceof fe&&1&e.s}var pe=function(){try{return Promise.resolve(new Promise(function(t,r){try{return Se(),Promise.resolve(Te()).then(function(r){return r.loggedIn&&be(r)?t(r):Promise.resolve(e().get("discovery.wallet")).then(function(r){function n(e){ne({endpoint:e},{onReady:function(e,t){console.log("ON READY",e)},onClose:function(){try{return Promise.resolve(Te()).then(function(e){t(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?y(e.addr):null,e.paddr=e.paddr?y(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=L(e.authorizations);!(r=n()).done;)t.push(_({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(_({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,i=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return function(e,t){try{return Z[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return _({},M,{addr:y(e.addr),cid:q(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return v(me,ye,e),Promise.resolve(Te()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})}return r?n(r):Promise.resolve(e().get("challenge.handshake")).then(n)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},me="CURRENT_USER",ve="CURRENT_USER/UPDATED",ye="SET_CURRENT_USER",Pe='{\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}',ge=function(e){try{return sessionStorage.setItem(me,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ee=function(){return e().get("persistSession",!0)},we=((oe={})[s]=function(e){try{return e.merge(JSON.parse(Pe)),Promise.resolve(Ee()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(Pe),t=JSON.parse(sessionStorage.getItem(me));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(me),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){be(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},oe[c]=function(e,t){e.subscribe(t.from),e.send(t.from,ve,_({},e.all()))},oe[d]=function(e,t){e.unsubscribe(t.from)},oe.SNAPSHOT=function(e,t){try{return t.reply(_({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},oe[ye]=function(e,t,r){try{return e.merge(r),Promise.resolve(Ee()).then(function(t){t&&ge(e.all()),e.broadcast(ve,_({},e.all()))})}catch(e){return Promise.reject(e)}},oe.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(Pe)),Promise.resolve(Ee()).then(function(t){t&&ge(e.all()),e.broadcast(ve,_({},e.all()))})}catch(e){return Promise.reject(e)}},oe),Se=function(){return p(we,me)};function be(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Re(){Se(),v(me,"DEL_CURRENT_USER")}function Ie(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=L(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,a=L(t.authorization||[]);!(i=a()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return se(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ae(e){Se();var t=p(function(t){try{var r;return t.send(me,c),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(he(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!he(i)){n=1;break}i=i.s}}var a=new fe,u=le.bind(null,a,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):le(a,1,i)})).then(void 0,u),a;function s(t){i=t;do{if(!(o=e())||he(o)&&!o.v)return void le(a,1,i);if(o.then)return void o.then(c).then(void 0,u);he(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,u)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,u):s(i):le(a,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(t.receive()).then(function(n){if("@EXIT"===n.tag)return t.send(me,d),void(r=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(t,"@EXIT")}}function Te(){return Se(),v(me,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ke=function(){return{authenticate:pe,unauthenticate:Re,authorization:de,subscribe:Ae,snapshot:Te}},je=function(){return ke().authenticate()},Ce=function(){return ke().unauthenticate()},Oe=function(){return ke().unauthenticate(),ke().authenticate()},Ne=function(){return ke().authenticate()},_e=function(){return ke().authenticate()},xe=ke().authorization,Le="0.0.68-alpha.7";export{Le as VERSION,je as authenticate,xe as authz,ke as currentUser,F as events,_e as logIn,Oe as reauthenticate,R as serialize,Ne as signUp,N as tx,Ce as unauthenticate};
//# sourceMappingURL=fcl.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/config"),require("@onflow/sdk"),require("@onflow/util-actor"),require("@onflow/util-address"),require("@onflow/rlp"),require("@onflow/util-invariant"),require("@onflow/util-uid"),require("@onflow/util-template")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/sdk","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-invariant","@onflow/util-uid","@onflow/util-template"],t):t((e=e||self).fcl={},e.config,e.sdk,e.utilActor,e.utilAddress,e.rlp,e.utilInvariant,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,o,i,u,a,c){t.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),t.config().put("sdk.resolve",n.resolve);var s,l,f=function(e){try{return Promise.resolve(n.send([n.getTransactionStatus(e)]).then(n.decode))}catch(e){return Promise.reject(e)}},d=function(e){return e.status>=4},p=function(e){return e.status>=3},h=function(e){return e.status>=2},m=((s={})[r.INIT]=function(e){try{return Promise.resolve(f(e.self())).then(function(t){d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},s[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,r.UPDATED,e.all())},s[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},s[r.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},s.POLL=function(e){try{return Promise.resolve(f(e.self())).then(function(t){var n,o;d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),o=t,JSON.stringify(n)!==JSON.stringify(o)&&e.broadcast(r.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},s),v=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},y=function(e){return r.spawn(m,v(e))};function g(e){function t(t){return r.subscriber(v(e),y,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return r.snapshoter(e,y)},subscribe:t,onceFinalized:n(h),onceExecuted:n(p),onceSealed:n(d)}}function P(){return(P=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)}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function E(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return b(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)?b(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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)}g.isUnknown=function(e){return e.status>=0},g.isPending=function(e){return e.status>=1},g.isFinalized=h,g.isExecuted=p,g.isSealed=d,g.isExpired=function(e){return 5===e.status};var w=function(e){try{var n=setTimeout;return Promise.resolve(t.config().get("fcl.eventPollRate",1e4)).then(function(t){return n(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},S=((l={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(n.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(w(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(n.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(n.send([getEvents(e.self(),t.height,r.height-1)]).then(n.decode)).then(function(t){for(var n,r=E(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(w(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l[r.SUBSCRIBE]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(w(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},l[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},l),j=function(e){return r.spawn(S,e)},O={f_type:"Service",f_vsn:"1.0.0"},I={f_type:"Identity",f_vsn:"1.0.0"},R={f_type:"USER",f_vsn:"1.0.0"},k={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({old:e},O,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function T(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},O,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var B={"back-channel-rpc":T,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},O,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},I,{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 P({},O,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},I,{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 P({},O,{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:C};function x(e){return i.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function N(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function L(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function U(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(L(e),{method:n,headers:P({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function _(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},k,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:T(e.authorizationUpdates),local:C((e.local||[])[0])})}}function z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},A,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var D="FCL_IFRAME",F=function(){},H=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function M(e,t){if(void 0===t&&(t={}),console.log("FRAME",{service:e,opts:t}),null==e)return{send:F,close:F};var n=t.onClose||F,r=t.onMessage||F,o=t.onReady||F;window.addEventListener("message",s);var i=function(e){u.invariant(!document.getElementById(D),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=D,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,function(){document.getElementById(D)&&document.getElementById(D).remove()}]}(L(e)),a=i[0],c=i[1];return{send:f,close:l};function s(e){try{if("object"!=typeof e.data)return;if(H.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:f,close:l}),r(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(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",s),c(),n()}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(t){console.error("Frame Send Error",e,t)}}}var J,q={"HTTP/GET":"GET","HTTP/POST":"POST"},G=function(e){return u.invariant(q[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),q[e.method]},V=function(e,t){try{return t.data=e.data,Promise.resolve(U(e,{data:t}).then(_)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,r=M(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(u.invariant(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(U(t,{method:G(t)}).then(_)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return r(),z(e)}).catch(function(e){throw console.error(e),r(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Y=function(e,t){try{try{return Promise.resolve(Z[e.method](e,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}catch(e){return Promise.reject(e)}},Z={"HTTP/RPC":V,"HTTP/POST":V,"IFRAME/RPC":function(e,t){return new Promise(function(n,r){var o=a.uid();t.data=e.data,M(e,{onReady:function(n,r){var i=r.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){r("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=_(e.data.result);switch(u.status){case"APPROVED":n(z(u.data)),i();break;case"DECLINED":r("Declined: "+(u.reason||"No reason supplied")),i();break;default:r("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function K(e,t,n){if(!e.s){if(n instanceof W){if(!n.s)return void(n.o=K.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(K.bind(null,e,t),K.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var X=function(e){try{return le(),Promise.resolve(Q()).then(function(t){var n=N(t.services,"authz"),r=N(t.services,"pre-authz");return P({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Y(r,t)).then(pe)}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(Y(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},W=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{K(r,1,i(this.v))}catch(e){K(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?K(r,1,t?t(o):o):n?K(r,1,n(o)):K(r,2,o)}catch(e){K(r,2,e)}},r},e}();function $(e){return e instanceof W&&1&e.s}var Q=function(){try{return Promise.resolve(new Promise(function(e){try{return le(),Promise.resolve(me()).then(function(n){return n.loggedIn&&fe(n)?e(n):Promise.resolve(t.config().get("challenge.handshake")).then(function(t){var n,i,u,a=(n={handshake:t,l6n:window.location.origin},i=n.l6n,(u=new URL(n.handshake)).searchParams.append("l6n",i),function(e){if(!document.getElementById("FCL_IFRAME")){var 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,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(u.href))[1];window.addEventListener("message",function t(n){var i=n.data;try{return i.type===ie||i.type===re?(a(),window.removeEventListener("message",t),Promise.resolve()):i.type!==oe?Promise.resolve():(a(),window.removeEventListener("message",t),Promise.resolve(function(e){try{var t=(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,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var n,r=E(e.authorizations);!(n=r()).done;)t.push(P({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(P({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,i,u=(r=t,i=n,void 0===r&&(r=[]),void 0===i&&(i=[]),[].concat(r,i)).map(function(t){return function(e,t){try{return B[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,u);return P({},R,{addr:o.withPrefix(e.addr),cid:x(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(i)).then(function(t){return r.send(ee,ne,t),Promise.resolve(me()).then(function(t){e(t)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ee="CURRENT_USER",te="CURRENT_USER/UPDATED",ne="SET_CURRENT_USER",re="FCL::CANCEL",oe="FCL::CHALLENGE::RESPONSE",ie="FCL::CHALLENGE::CANCEL",ue='{\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}',ae=function(e){try{return sessionStorage.setItem(ee,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ce=function(){return t.config().get("persistSession",!0)},se=((J={})[r.INIT]=function(e){try{return e.merge(JSON.parse(ue)),Promise.resolve(ce()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ue),t=JSON.parse(sessionStorage.getItem(ee));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(ee),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){fe(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},J[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,te,P({},e.all()))},J[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},J.SNAPSHOT=function(e,t){try{return t.reply(P({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},J[ne]=function(e,t,n){try{return e.merge(n),Promise.resolve(ce()).then(function(t){t&&ae(e.all()),e.broadcast(te,P({},e.all()))})}catch(e){return Promise.reject(e)}},J.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ue)),Promise.resolve(ce()).then(function(t){t&&ae(e.all()),e.broadcast(te,P({},e.all()))})}catch(e){return Promise.reject(e)}},J),le=function(){return r.spawn(se,ee)};function fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function de(){le(),r.send(ee,"DEL_CURRENT_USER")}function pe(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=E(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,u=E(t.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return Y(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function he(e){le();var t=r.spawn(function(t){try{var n;return t.send(ee,r.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if($(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!$(i)){r=1;break}i=i.s}}var u=new W,a=K.bind(null,u,2);return(0===r?o.then(s):1===r?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(s).then(void 0,a):s(o):K(u,1,i)})).then(void 0,a),u;function c(t){i=t;do{if(!(o=e())||$(o)&&!o.v)return void K(u,1,i);if(o.then)return void o.then(s).then(void 0,a);$(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function s(e){e?(i=n())&&i.then?i.then(c).then(void 0,a):c(i):K(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(o){if("@EXIT"===o.tag)return t.send(ee,r.UNSUBSCRIBE),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(t,"@EXIT")}}function me(){return le(),r.send(ee,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ve=function(){return{authenticate:Q,unauthenticate:de,authorization:X,subscribe:he,snapshot:me}},ye=ve().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return n.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return n.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return n.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return n.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return n.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return n.build}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return n.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return n.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return n.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return n.getBlockHeader}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return n.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return n.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return n.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return n.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return n.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return c.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return c.template}}),e.VERSION="0.0.68-alpha.6",e.authenticate=function(){return ve().authenticate()},e.authz=ye,e.currentUser=ve,e.events=function(e){return{subscribe:function(t){return r.subscriber(e,j,t)}}},e.logIn=function(){return ve().authenticate()},e.reauthenticate=function(){return ve().unauthenticate(),ve().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.config().get("sdk.resolve",r.resolve||n.resolve(r))).then(function(t){function r(){return Promise.resolve(t(e)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(t){e=t})}();return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return ve().authenticate()},e.tx=g,e.unauthenticate=function(){return ve().unauthenticate()}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/config"),require("@onflow/sdk"),require("@onflow/util-actor"),require("@onflow/util-address"),require("@onflow/rlp"),require("@onflow/util-invariant"),require("@onflow/util-uid"),require("@onflow/util-template")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/sdk","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-invariant","@onflow/util-uid","@onflow/util-template"],t):t((e=e||self).fcl={},e.config,e.sdk,e.utilActor,e.utilAddress,e.rlp,e.utilInvariant,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,o,i,u,a,c){t.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),t.config().put("sdk.resolve",n.resolve);var s,l,f=function(e){try{return Promise.resolve(n.send([n.getTransactionStatus(e)]).then(n.decode))}catch(e){return Promise.reject(e)}},d=function(e){return e.status>=4},p=function(e){return e.status>=3},h=function(e){return e.status>=2},m=((s={})[r.INIT]=function(e){try{return Promise.resolve(f(e.self())).then(function(t){d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},s[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,r.UPDATED,e.all())},s[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},s[r.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},s.POLL=function(e){try{return Promise.resolve(f(e.self())).then(function(t){var n,o;d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),o=t,JSON.stringify(n)!==JSON.stringify(o)&&e.broadcast(r.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},s),v=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},y=function(e){return r.spawn(m,v(e))};function g(e){function t(t){return r.subscriber(v(e),y,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return r.snapshoter(e,y)},subscribe:t,onceFinalized:n(h),onceExecuted:n(p),onceSealed:n(d)}}function P(){return(P=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)}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function E(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return b(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)?b(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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)}g.isUnknown=function(e){return e.status>=0},g.isPending=function(e){return e.status>=1},g.isFinalized=h,g.isExecuted=p,g.isSealed=d,g.isExpired=function(e){return 5===e.status};var S=function(e){try{var n=setTimeout;return Promise.resolve(t.config().get("fcl.eventPollRate",1e4)).then(function(t){return n(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},O=((l={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(n.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(S(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(n.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(n.send([getEvents(e.self(),t.height,r.height-1)]).then(n.decode)).then(function(t){for(var n,r=E(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(S(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l[r.SUBSCRIBE]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(S(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},l[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},l),j=function(e){return r.spawn(O,e)},w={f_type:"Service",f_vsn:"1.0.0"},R={f_type:"Identity",f_vsn:"1.0.0"},I={f_type:"USER",f_vsn:"1.0.0"},k={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function T(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({old:e},w,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},w,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var B={"back-channel-rpc":C,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},w,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},R,{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 P({},w,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},R,{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 P({},w,{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:T};function N(e){return i.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function U(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function x(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function _(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(x(e),{method:n,headers:P({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function D(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},k,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:C(e.authorizationUpdates),local:T((e.local||[])[0])})}}function L(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},A,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var z="FCL_IFRAME",F=function(){},H=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function M(e,t){if(void 0===t&&(t={}),console.log("FRAME",{service:e,opts:t}),null==e)return{send:F,close:F};var n=t.onClose||F,r=t.onMessage||F,o=t.onReady||F,i=t.onResponse||F;window.addEventListener("message",l);var a=function(e){u.invariant(!document.getElementById(z),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=z,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,function(){document.getElementById(z)&&document.getElementById(z).remove()}]}(x(e)),c=a[0],s=a[1];return{send:d,close:f};function l(e){try{if("object"!=typeof e.data)return;if(H.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:f}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:f}),r(e,{send:d,close:f}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&(console.log("BOOP"),i(e,{send:d,close:f})),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,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",l),s(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),c.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var J,q={"HTTP/GET":"GET","HTTP/POST":"POST"},G=function(e){return u.invariant(q[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),q[e.method]},Y=function(e,t){try{return t.data=e.data,Promise.resolve(_(e,{data:t}).then(D)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,r=M(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(u.invariant(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(_(t,{method:G(t)}).then(D)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return r(),L(e)}).catch(function(e){throw console.error(e),r(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},V=function(e,t){try{try{return Promise.resolve(Z[e.method](e,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}catch(e){return Promise.reject(e)}},Z={"HTTP/RPC":Y,"HTTP/POST":Y,"IFRAME/RPC":function(e,t){return new Promise(function(n,r){var o=a.uid();t.data=e.data,M(e,{onReady:function(n,r){var i=r.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){r("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=D(e.data.result);switch(u.status){case"APPROVED":n(L(u.data)),i();break;case"DECLINED":r("Declined: "+(u.reason||"No reason supplied")),i();break;default:r("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function K(e,t,n){if(!e.s){if(n instanceof W){if(!n.s)return void(n.o=K.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(K.bind(null,e,t),K.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var X=function(e){try{return ae(),Promise.resolve(Q()).then(function(t){var n=U(t.services,"authz"),r=U(t.services,"pre-authz");return P({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(V(r,t)).then(le)}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(V(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},W=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{K(r,1,i(this.v))}catch(e){K(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?K(r,1,t?t(o):o):n?K(r,1,n(o)):K(r,2,o)}catch(e){K(r,2,e)}},r},e}();function $(e){return e instanceof W&&1&e.s}var Q=function(){try{return Promise.resolve(new Promise(function(e,n){try{return ae(),Promise.resolve(de()).then(function(n){return n.loggedIn&&ce(n)?e(n):Promise.resolve(t.config().get("discovery.wallet")).then(function(n){function i(t){M({endpoint:t},{onReady:function(e,t){console.log("ON READY",e)},onClose:function(){try{return Promise.resolve(de()).then(function(t){e(t)})}catch(e){return Promise.reject(e)}},onResponse:function(t,n){var i=n.close;try{return Promise.resolve(function(e){try{var t=(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,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var n,r=E(e.authorizations);!(n=r()).done;)t.push(P({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(P({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,i,u=(r=t,i=n,void 0===r&&(r=[]),void 0===i&&(i=[]),[].concat(r,i)).map(function(t){return function(e,t){try{return B[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,u);return P({},I,{addr:o.withPrefix(e.addr),cid:N(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t.data)).then(function(t){return r.send(ee,ne,t),Promise.resolve(de()).then(function(t){e(t),i()})})}catch(t){return Promise.reject(t)}}})}return n?i(n):Promise.resolve(t.config().get("challenge.handshake")).then(i)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ee="CURRENT_USER",te="CURRENT_USER/UPDATED",ne="SET_CURRENT_USER",re='{\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}',oe=function(e){try{return sessionStorage.setItem(ee,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ie=function(){return t.config().get("persistSession",!0)},ue=((J={})[r.INIT]=function(e){try{return e.merge(JSON.parse(re)),Promise.resolve(ie()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(re),t=JSON.parse(sessionStorage.getItem(ee));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(ee),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){ce(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},J[r.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,te,P({},e.all()))},J[r.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},J.SNAPSHOT=function(e,t){try{return t.reply(P({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},J[ne]=function(e,t,n){try{return e.merge(n),Promise.resolve(ie()).then(function(t){t&&oe(e.all()),e.broadcast(te,P({},e.all()))})}catch(e){return Promise.reject(e)}},J.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(re)),Promise.resolve(ie()).then(function(t){t&&oe(e.all()),e.broadcast(te,P({},e.all()))})}catch(e){return Promise.reject(e)}},J),ae=function(){return r.spawn(ue,ee)};function ce(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function se(){ae(),r.send(ee,"DEL_CURRENT_USER")}function le(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=E(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,u=E(t.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return V(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function fe(e){ae();var t=r.spawn(function(t){try{var n;return t.send(ee,r.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if($(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!$(i)){r=1;break}i=i.s}}var u=new W,a=K.bind(null,u,2);return(0===r?o.then(s):1===r?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(s).then(void 0,a):s(o):K(u,1,i)})).then(void 0,a),u;function c(t){i=t;do{if(!(o=e())||$(o)&&!o.v)return void K(u,1,i);if(o.then)return void o.then(s).then(void 0,a);$(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function s(e){e?(i=n())&&i.then?i.then(c).then(void 0,a):c(i):K(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(o){if("@EXIT"===o.tag)return t.send(ee,r.UNSUBSCRIBE),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(t,"@EXIT")}}function de(){return ae(),r.send(ee,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var pe=function(){return{authenticate:Q,unauthenticate:se,authorization:X,subscribe:fe,snapshot:de}},he=pe().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return n.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return n.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return n.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return n.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return n.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return n.build}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return n.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return n.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return n.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return n.getBlockHeader}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return n.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return n.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return n.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return n.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return n.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return c.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return c.template}}),e.VERSION="0.0.68-alpha.7",e.authenticate=function(){return pe().authenticate()},e.authz=he,e.currentUser=pe,e.events=function(e){return{subscribe:function(t){return r.subscriber(e,j,t)}}},e.logIn=function(){return pe().authenticate()},e.reauthenticate=function(){return pe().unauthenticate(),pe().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.config().get("sdk.resolve",r.resolve||n.resolve(r))).then(function(t){function r(){return Promise.resolve(t(e)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(t){e=t})}();return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return pe().authenticate()},e.tx=g,e.unauthenticate=function(){return pe().unauthenticate()}});
//# sourceMappingURL=fcl.umd.js.map
{
"name": "@onflow/fcl",
"version": "0.0.68-alpha.6",
"version": "0.0.68-alpha.7",
"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