@onflow/fcl
Advanced tools
Comparing version 0.0.78-alpha.6 to 0.0.78-alpha.7
@@ -5,2 +5,60 @@ ## Unreleased | ||
## 0.0.78-alpha.7 - 2021-11-12 | ||
- 2021-11-10 -- Allow configurable Discovery in FCL via `fcl.discovery` with current support for authn services. | ||
An app developer will now be able to list services for authentication ("authn") in their application and authenticate without having to point directly at a single wallet or `"discovery.wallet"` which is a pre-constructed UI for Flow services. | ||
To use this, first set in the config the API endpoint for fetching Flow services. | ||
```javascript | ||
import { config } from "@onflow/fcl" | ||
config({ | ||
"discovery.authn.endpoint": "https://fcl-discovery.onflow.org/api/testnet/authn" | ||
}) | ||
// On mainnet, you can use https://fcl-discovery.onflow.org/api/authn | ||
``` | ||
Then in an application you can get services with the following: | ||
```javascript | ||
import * as fcl from "@onflow/fcl" | ||
fcl.discovery.authn.subscribe(callback) | ||
// OR | ||
fcl.discovery.authn.snapshot() | ||
``` | ||
This will return a list a services which you can then authenticate with the following: | ||
```javascript | ||
fcl.authenticate({ service }) | ||
``` | ||
An example React component could then wind up looking like this: | ||
```javascript | ||
import "./config" | ||
import { useState, useEffect } from "react" | ||
import * as fcl from "@onflow/fcl" | ||
function Component() { | ||
const [services, setServices] = useState([]) | ||
useEffect(() => fcl.discovery.authn.subscribe(res => setServices(res.results)), []) | ||
return ( | ||
<div> | ||
{services.map(service => <button key={service.id} onClick={() => fcl.authenticate({ service })}>Login with {service.provider.name}</button>)} | ||
</div> | ||
) | ||
} | ||
``` | ||
- 2021-11-10 -- Updates pop/tab to reject on force window close | ||
- 2021-10-29 -- Removes default `config.fcl.appDomainTag` and updates docs. | ||
## 0.0.78-alpha.6 - 2021-10-25 | ||
@@ -7,0 +65,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/sdk"),r=require("@onflow/util-invariant"),n=require("@onflow/types"),t=require("@onflow/util-actor"),o=require("@onflow/util-address"),i=require("@onflow/rlp"),a=require("@onflow/util-uid"),s=require("@onflow/util-template");function u(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}}),r.default=e,r}var c=u(e),l=u(n),d=u(i),f=function(r){try{return Promise.resolve(e.config().where(r)).then(function(e){return Object.fromEntries(Object.entries(e).map(function(e){var n=e[1];return[e[0].replace(r,""),n]}))})}catch(e){return Promise.reject(e)}},p={can:!("undefined"==typeof window),get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,r){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(r)))}catch(e){return Promise.reject(e)}}};e.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":p,"fcl.appDomainTag.default":"APP-V0.0-user"});var v="0.0.78-alpha.6",h=function(e){return function(r){return typeof r===e}},m=function(e){return null!=e},y=h("object"),g=h("string"),P=h("function"),E=h("number");function b(e){return P(e)?e(c.arg,l):[]}var R=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(m(e.cadence),"query({ cadence }) -- cadence is required"),r.invariant(g(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){r.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return c.send([c.script(e.cadence),c.args(b(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}};function w(){return w=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},w.apply(this,arguments)}function S(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function x(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return S(e,r);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)?S(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var C={f_type:"Service",f_vsn:"1.0.0"},O={f_type:"Identity",f_vsn:"1.0.0"},I={f_type:"USER",f_vsn:"1.0.0"},j={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function D(e){return null==e?null:"1.0.0"===e.f_vsn?e:w({old:e},C,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function N(e){return null==e?null:"1.0.0"===e.f_vsn?e:w({},C,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function k(e){return null==e?null:(null==e.method&&(e=w({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:w({},C,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}var L={"back-channel-rpc":N,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:w({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},O,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:w({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},O,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:w({},C,{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:D,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":k,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function F(e){return d.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function T(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function _(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,t=Object.entries(e.params||{});n<t.length;n++){var o=t[n];r.searchParams.append(o[0],o[1])}return r}function U(e,r){void 0===r&&(r={});var n=r.method||"POST",t="GET"===n?void 0:JSON.stringify(r.data||e.data||{});return fetch(_(e),{method:n,headers:w({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function B(e){var r,n;return null==e?null:"1.0.0"===e.f_vsn?e:w({},j,{status:null!=(r=e.status)?r:"APPROVED",reason:null!=(n=e.reason)?n:null,data:e.compositeSignature||e.data||w({},e)||{},updates:N(e.authorizationUpdates),local:D((e.local||[])[0])})}var M=function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(U(n,{method:z(n)}).then(B)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,t)})}})}catch(e){return Promise.reject(e)}},V={"HTTP/GET":"GET","HTTP/POST":"POST"},z=function(e){return r.invariant(V[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),V[e.method]},W="FCL_IFRAME";function H(e){r.invariant(!document.getElementById(W),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=W,n.allow="usb *; hid *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n.contentWindow,function(){document.getElementById(W)&&document.getElementById(W).remove()}]}var Y=null,q=null;function J(e){var r,n;null==Y||null!=(r=Y)&&r.closed?(n=window,Y=n.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top="+(n.top.outerHeight/2+n.top.screenY-385)+", left="+(n.top.outerWidth/2+n.top.screenX-320))):q!==e?(Y.location.replace(e),Y.focus()):Y.focus(),q=e;var t=setInterval(function(){Y&&Y.closed&&(clearInterval(t),Y=null)},1e3);return[Y,function(){Y&&!Y.closed&&(Y.close(),Y=null)}]}var K=null,G=null;function X(e){var r;null==K||null!=(r=K)&&r.closed?K=window.open(e,"_blank"):G!==e?(K.location.replace(e),K.focus()):K.focus(),G=e;var n=setInterval(function(){K&&K.closed&&(clearInterval(n),K=null)},1e3);return[K,function(){K&&!K.closed&&(K.close(),K=null)}]}var Z,$={"VIEW/IFRAME":H,"VIEW/POP":J,"VIEW/TAB":X},Q=function(e,r,n){try{var t={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(o){return Promise.resolve(U(e,{data:w({fclVersion:v,service:t,config:{services:n,app:o}},r)}).then(B)).then(function(r){if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("REDIRECT"===r.status)return r;if("PENDING"===r.status){var n=!0;return Promise.resolve(function(e,r){void 0===r&&(r={});try{try{return Promise.resolve($[e.method](_(e),r))}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:r}),n}}catch(e){return Promise.reject(e)}}(k(r.local))).then(function(e){var t=e[1],o=function(){try{t(),n=!1}catch(e){console.error("Frame Close Error",e)}};return M(r.updates,function(){return n}).then(function(e){return o(),e}).catch(function(e){throw console.error(e),o(),e})})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")})})})}catch(e){return Promise.reject(e)}},ee=function(e){return"string"==typeof e&&e.toLowerCase()},re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ne=function(e,r){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+r+" for this and future versions of FCL")},te=function(e){var r=e.close,n=e.send,t=e.onReady,o=e.onResponse,i=e.onMessage;return function(e){try{if("object"!=typeof e.data)return;if(re.has(e.data.type))return;ee(e.data.type)===ee("FCL:VIEW:CLOSE")&&r(),ee(e.data.type)===ee("FCL:VIEW:READY")&&t(e,{send:n,close:r}),ee(e.data.type)===ee("FCL:VIEW:RESPONSE")&&o(e,{send:n,close:r}),i(e,{send:n,close:r}),ee(e.data.type)===ee("FCL:FRAME:READY")&&(ne(e.data.type,"FCL:VIEW:READY"),t(e,{send:n,close:r})),ee(e.data.type)===ee("FCL:FRAME:RESPONSE")&&(ne(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:n,close:r})),ee(e.data.type)===ee("FCL:FRAME:CLOSE")&&(ne(e.data.type,"FCL:VIEW:CLOSE"),r()),ee(e.data.type)===ee("FCL::CHALLENGE::RESPONSE")&&(ne(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:n,close:r})),ee(e.data.type)===ee("FCL::AUTHZ_READY")&&(ne(e.data.type,"FCL:VIEW:READY"),t(e,{send:n,close:r})),ee(e.data.type)===ee("FCL::CHALLENGE::CANCEL")&&(ne(e.data.type,"FCL:VIEW:CLOSE"),r()),ee(e.data.type)===ee("FCL::CANCEL")&&(ne(e.data.type,"FCL:VIEW:CLOSE"),r())}catch(e){console.error("Frame Callback Error",e),r()}}},oe=function(){},ie=function(){},ae=function(){},se=function(){},ue=function e(n){var t=n.service,o=n.msg,i=void 0===o?{}:o,a=n.opts,s=void 0===a?{}:a;try{return Promise.resolve(function(n,o){try{var a=Promise.resolve(ce[t.method](t,i,s)).then(function(n){return"REDIRECT"===n.status?(r.invariant(t.type===n.data.type,"Cannot shift recursive service type in execService"),t=n.data,Promise.resolve(e({service:t,msg:i,opts:s}))):n})}catch(e){return o(e)}return a&&a.then?a.then(void 0,o):a}(0,function(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:i,opts:s}),e}))}catch(e){return Promise.reject(e)}},ce={"HTTP/RPC":Q,"HTTP/POST":Q,"IFRAME/RPC":function(e,r,n){return new Promise(function(t,o){var i,s=a.uid(),u=n.includeOlderJsonRpcCall;r.data=null!=(i=e.data)?i:null,function(e,r){if(void 0===r&&(r={}),null==e)return{send:oe,close:oe};var n=r.onClose||oe;window.addEventListener("message",te({close:a,send:s,onReady:r.onReady||oe,onResponse:r.onResponse||oe,onMessage:r.onMessage||oe}));var t=H(_(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",te),i(),n()}catch(e){console.error("Frame Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(t){return Promise.resolve(f(/^app\.detail\./)).then(function(i){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:t,app:i}});var a={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:FRAME:READY:RESPONSE",body:r,service:a,config:{services:n,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[r,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":t(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;var i=B(e.data.result);switch(i.status){case"APPROVED":t(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"POP/RPC":function(e,r,n){return new Promise(function(t,o){var i=a.uid(),s=n.redir,u=n.includeOlderJsonRpcCall;r.data=e.data,function(e,r){if(void 0===r&&(r={}),null==e)return{send:ie,close:ie};var n=r.onClose||ie;window.addEventListener("message",te({close:a,send:s,onReady:r.onReady||ie,onResponse:r.onResponse||ie,onMessage:r.onMessage||ie}));var t=J(_(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",te),i(),n()}catch(e){console.error("Popup Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Popup Send Error",e,r)}}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(t){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:FRAME:READY:RESPONSE",body:r,service:s,config:{services:n,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[r,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=B(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),n();break;case"REDIRECT":t(a),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"TAB/RPC":function(e,r,n){return new Promise(function(t,o){var i=a.uid(),s=n.redir,u=n.includeOlderJsonRpcCall;r.data=e.data,function(e,r){if(void 0===r&&(r={}),null==e)return{send:ae,close:ae};var n=r.onClose||ae;window.addEventListener("message",te({close:a,send:s,onReady:r.onReady||ae,onResponse:r.onResponse||ae,onMessage:r.onMessage||ae}));var t=X(_(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",te),i(),n()}catch(e){console.error("Tab Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Tab Send Error",e,r)}}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(t){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:FRAME:READY:RESPONSE",body:r,service:s,config:{services:n,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[r,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=B(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),n();break;case"REDIRECT":t(a),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"EXT/RPC":function(e,r,n){return new Promise(function(n,t){!function(e,r){void 0===r&&(r={});try{var n,t=function(){try{window.removeEventListener("message",te),a()}catch(e){console.error("Extension Close Error",e)}},o=function(e){try{var r;null==(r=window[i])||r.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(r){console.error("Extension Send Error",e,r)}};if(null==e)return Promise.resolve({send:se,close:se});var i=e.endpoint,a=r.onClose||se;window.addEventListener("message",te({close:t,send:o,onReady:r.onReady||se,onResponse:r.onResponse||se,onMessage:r.onMessage||se})),Promise.resolve(null==(n=window[i])?void 0:n.flow.enable()).then(function(){return{send:o,close:t}})}catch(e){return Promise.reject(e)}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(e){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:e,app:t}})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var o=r.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":n(i.data),o();break;case"DECLINED":t("Declined: "+(i.reason||"No reason supplied")),o();break;case"REDIRECT":n(i),o();break;default:t("Declined: No reason supplied"),o()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose:function(){t("Declined: Externally Halted")}})})}},le=function(n,t){try{r.invariant(/^[0-9a-f]+$/i.test(n),"Message must be a hex string"),r.invariant(Array.isArray(t),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(t.map(function(n){try{return r.invariant("string"==typeof n.addr,"addr must be a string"),r.invariant("number"==typeof n.keyId,"keyId must be a number"),r.invariant("string"==typeof n.signature,"signature must be a string"),Promise.resolve(function(r,t){try{var s=Promise.resolve(e.account(n.addr)).then(function(e){return o.push(e.keys[n.keyId].weight.toFixed(1)),i.push(e.keys[n.keyId].signAlgo),a.push(n.signature),e.keys[n.keyId].publicKey})}catch(e){return t(e)}return s&&s.then?s.then(void 0,t):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(e){return Promise.resolve(R({cadence:""+de,args:function(r,t){return[r(n,t.String),r(e,t.Array([t.String])),r(o,t.Array(t.UFix64)),r(i,t.Array([t.UInt])),r(a,t.Array([t.String]))]}}))})}catch(e){return Promise.reject(e)}},de="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function fe(e){return null==e?null:"1.0.0"===e.f_vsn?e:w({},A,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}function pe(e,r,n){if(!e.s){if(n instanceof ge){if(!n.s)return void(n.o=pe.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(pe.bind(null,e,r),pe.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var ve=function(e,r){try{return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Promise.resolve(le(e,r))}catch(e){return Promise.reject(e)}},he=function(e){try{return Oe(),Promise.resolve(Ee({redir:!0})).then(function(n){var t=T(n.services,"user-signature");return r.invariant(t,"Current user must have authorized a signing service."),be(function(){return Promise.resolve(ue({service:t,msg:Le(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return fe(e)}):[fe(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},me=function(){try{return Promise.resolve(Ee()).then(function(r){return e.arg(o.withPrefix(r.addr),l.Address)})}catch(e){return Promise.reject(e)}},ye=function(e){try{return Oe(),Promise.resolve(Ee({redir:!0})).then(function(r){var n=T(r.services,"authz"),t=T(r.services,"pre-authz");return w({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(ue({service:t,msg:r})).then(Ae)}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(ue({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(fe)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},ge=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{pe(t,1,i(this.v))}catch(e){pe(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?pe(t,1,r?r(o):o):n?pe(t,1,n(o)):pe(t,2,o)}catch(e){pe(t,2,e)}},t},e}();function Pe(e){return e instanceof ge&&1&e.s}var Ee=function(n){void 0===n&&(n={redir:!1});try{return Promise.resolve(new Promise(function(i,a){try{return Oe(),Promise.resolve(Ne()).then(function(a){return a.loggedIn&&Ie(a)?i(a):Promise.resolve(function(){try{return Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(n){return Promise.resolve(e.config.first(["discovery.wallet.method","discovery.wallet.method.default"])).then(function(t){return Promise.resolve(e.config.first(["fcl.appDomainTag","fcl.appDomainTag.default"])).then(function(e){return r.invariant(null!=n,'\n Required value for discovery.wallet not defined in config.\n See: "https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration"\n '),{discoveryWallet:n,discoveryWalletMethod:t,appDomainTag:e}})})})}catch(e){return Promise.reject(e)}}()).then(function(r){var a=r.discoveryWallet,s=r.discoveryWalletMethod,u=r.appDomainTag;return Promise.resolve(e.config.get("fcl.warning.suppress.redir")).then(function(e){n.redir&&!e&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");var r=function(e,r){try{var i=be(function(){return Promise.resolve(ue({service:{type:"authn",endpoint:a,method:s},msg:{timestamp:Date.now(),appDomainTag:u,extensions:window.fcl_extensions||[]},opts:n})).then(function(e){return Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=x(e.authorizations);!(n=t()).done;)r.push(w({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(w({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,i,a=(t=r,i=n,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(r){return function(e,r){try{return L[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),s=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,a);return w({},I,{addr:o.withPrefix(e.addr),cid:F(s),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){t.send(Re,Se,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return r(!0,e)}return i&&i.then?i.then(r.bind(null,!1),r.bind(null,!0)):r(!1,i)}(0,function(e,r){return Promise.resolve(Ne()).then(function(n){if(i(n),e)throw r;return r})});if(r&&r.then)return r.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function be(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}var Re="CURRENT_USER",we="CURRENT_USER/UPDATED",Se="SET_CURRENT_USER",xe='{\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=((Z={})[t.INIT]=function(r){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),r.merge(JSON.parse(xe)),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){var n=function(){if(e.can)return Promise.resolve(function(e){try{var r=JSON.parse(xe);return Promise.resolve(e.get(Re)).then(function(n){return null!=n&&r.f_vsn!==n.f_vsn?(e.removeItem(Re),r):n||r})}catch(e){return Promise.reject(e)}}(e)).then(function(e){Ie(e)&&r.merge(e)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},Z[t.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,we,w({},e.all()))},Z[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},Z.SNAPSHOT=function(e,r){try{return r.reply(w({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[Se]=function(r,n,t){try{return r.merge(t),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(Re,r.all()),r.broadcast(we,w({},r.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(r,n){try{return r.merge(JSON.parse(xe)),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(Re,r.all()),r.broadcast(we,w({},r.all()))})}catch(e){return Promise.reject(e)}},Z),Oe=function(){return t.spawn(Ce,Re)};function Ie(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function je(){Oe(),t.send(Re,"DEL_CURRENT_USER")}function Ae(e){var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=r.proposer&&n.push(["PROPOSER",r.proposer]);for(var t,o=x(r.payer||[]);!(t=o()).done;)n.push(["PAYER",t.value]);for(var i,a=x(r.authorization||[]);!(i=a()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var r=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return ue({service:n,msg:e})},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}})}function De(e){Oe();var r="@EXIT",n=t.spawn(function(n){try{var o;return n.send(Re,t.SUBSCRIBE),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(Pe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!Pe(i)){t=1;break}i=i.s}}var a=new ge,s=pe.bind(null,a,2);return(0===t?o.then(c):1===t?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):pe(a,1,i)})).then(void 0,s),a;function u(r){i=r;do{if(!(o=e())||Pe(o)&&!o.v)return void pe(a,1,i);if(o.then)return void o.then(c).then(void 0,s);Pe(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):pe(a,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(n.receive()).then(function(i){if(i.tag===r)return n.send(Re,t.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(n,r)}}function Ne(){return Oe(),t.send(Re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ke,Le=function(e){return r.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Fe=function(){return{authenticate:Ee,unauthenticate:je,authorization:ye,signUserMessage:he,verifyUserSignatures:ve,subscribe:De,snapshot:Ne,resolveArgument:me}};Fe.authenticate=Ee,Fe.unauthenticate=je,Fe.authorization=ye,Fe.signUserMessage=he,Fe.verifyUserSignatures=ve,Fe.subscribe=De,Fe.snapshot=Ne,Fe.resolveArgument=me;var Te=function(r){try{return Promise.resolve(e.send([e.getTransactionStatus(r)]).then(e.decode))}catch(e){return Promise.reject(e)}},_e=function(e){return e.status>=4},Ue=function(e){return e.status>=3},Be=function(e){return e.status>=2},Me=((ke={})[t.INIT]=function(e){try{return Promise.resolve(Te(e.self())).then(function(r){_e(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},ke[t.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,t.UPDATED,e.all())},ke[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},ke[t.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ke.POLL=function(e){try{return Promise.resolve(Te(e.self())).then(function(r){var n,o;_e(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),o=r,JSON.stringify(n)!==JSON.stringify(o)&&e.broadcast(t.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},ke),Ve=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ze=function(e){return t.spawn(Me,Ve(e))};function We(e){function r(r){return t.subscriber(Ve(e),ze,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return t.snapshoter(e,ze)},subscribe:r,onceFinalized:n(Be),onceExecuted:n(Ue),onceSealed:n(_e)}}We.isUnknown=function(e){return e.status>=0},We.isPending=function(e){return e.status>=1},We.isFinalized=Be,We.isExecuted=Ue,We.isSealed=_e,We.isExpired=function(e){return 5===e.status};var He,Ye=function(r){try{var n=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},qe=((He={}).TICK=function(r){try{if(!r.hasSubs())return Promise.resolve();var n=r.get("hwm"),t=function(){if(null==n){var t=r.put;return Promise.resolve(e.latestBlock()).then(function(e){t.call(r,"hwm",e);var n=r.put;return Promise.resolve(Ye(r)).then(function(e){n.call(r,"tick",e)})})}return Promise.resolve(e.latestBlock()).then(function(t){return r.put("hwm",t),Promise.resolve(e.send([e.getEvents(r.self(),n.height,t.height-1)]).then(e.decode)).then(function(e){for(var n,t=x(e);!(n=t()).done;)r.broadcast("UPDATED",n.value.data);var o=r.put;return Promise.resolve(Ye(r)).then(function(e){o.call(r,"tick",e)})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},He[t.SUBSCRIBE]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(Ye(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},He[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},He),Je=function(e){return t.spawn(qe,e)},Ke=function(e,r){void 0===r&&(r=function(){});var n=function(n){var t=n.data;"object"==typeof t&&null!=typeof t&&t.type===e&&r(function(e){var r;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(r=e.body)||delete r.interaction,e}(t))};return window.addEventListener("message",n),function(){return window.removeEventListener("message",n)}},Ge=function(e,r){void 0===r&&(r={}),window.location!==window.parent.location?window.parent.postMessage(w({},r,{type:e}),"*"):window.opener.postMessage(w({},r,{type:e}),"*")},Xe=function(e,r){return Buffer.from(e.padEnd(2*r,0),"hex")},Ze={__proto__:null,sendMsgToFCL:Ge,ready:function(e,r){Ke("FCL:VIEW:READY:RESPONSE",e),Ge("FCL:VIEW:READY")},close:function(){Ge("FCL:VIEW:CLOSE")},approve:function(e){Ge("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){Ge("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:function(e){Ge("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:Ke,encodeMessageFromSignable:e.encodeMessageFromSignable,CompositeSignature:function(e,r,n){this.f_type=A.f_type,this.f_vsn=A.f_vsn,this.addr=o.withPrefix(e),this.keyId=Number(r),this.signature=n},encodeMessageForProvableAuthnSigning:function(e,n,t){void 0===t&&(t=""),r.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),r.invariant(n,"Encode Message From Provable Authn Error: timestamp must be defined");var a=Xe(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),s=Xe(Buffer.from(t).toString("hex"),32).toString("hex");return a+(t?i.encode([s,o.withPrefix(e),n]).toString("hex"):i.encode([o.withPrefix(e),n]).toString("hex"))},encodeMessageForProvableAuthnVerifying:function(e,n,t){void 0===t&&(t=""),r.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),r.invariant(n,"Encode Message From Provable Authn Error: timestamp must be defined");var a,s=t?(a=Buffer.from(t).toString("hex"),Buffer.from(a.padEnd(64,0),"hex")).toString("hex"):null;return t?i.encode([s,o.withPrefix(e),n]).toString("hex"):i.encode([o.withPrefix(e),n]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}},$e=Fe().authorization,Qe=l;Object.defineProperty(exports,"TestUtils",{enumerable:!0,get:function(){return e.TestUtils}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return e.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return e.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return e.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return e.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return e.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return e.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return e.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return e.build}}),Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"createSignableVoucher",{enumerable:!0,get:function(){return e.createSignableVoucher}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return e.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return e.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return e.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return e.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return e.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return e.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return e.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return e.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return e.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return e.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return e.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return e.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return e.getTransactionStatus}}),Object.defineProperty(exports,"invariant",{enumerable:!0,get:function(){return e.invariant}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return e.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return e.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return e.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return e.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return e.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return e.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return e.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return e.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return e.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return e.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return e.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return e.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return e.transaction}}),Object.defineProperty(exports,"validator",{enumerable:!0,get:function(){return e.validator}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return s.template}}),exports.VERSION=v,exports.WalletUtils=Ze,exports.authenticate=function(){return Fe().authenticate()},exports.authz=$e,exports.currentUser=Fe,exports.events=function(e){return{subscribe:function(r){return t.subscriber(e,Je,r)}}},exports.logIn=function(){return Fe().authenticate()},exports.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(n,t){try{var o=Promise.resolve(function(e){try{return r.invariant(m(e),"mutate(opts) -- opts is required"),r.invariant(y(e),"mutate(opts) -- opts must be an object"),r.invariant(m(e.cadence),"mutate({ cadence }) -- cadence is required"),r.invariant(g(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){r.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(c.config().get("fcl.authz",Fe().authorization)).then(function(r){return c.send([c.transaction(e.cadence),c.args(b(e.args||[])),e.limit&&E(e.limit)&&c.limit(e.limit),c.proposer(e.proposer||e.authz||r),c.payer(e.payer||e.authz||r),c.authorizations(e.authorizations||[e.authz||r])]).then(c.decode)})})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},exports.query=R,exports.reauthenticate=function(){return Fe().unauthenticate(),Fe().authenticate()},exports.serialize=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e.config.first(["sdk.resolve"],n.resolve||e.resolve)).then(function(n){function t(){return Promise.resolve(n(r)).then(function(r){return JSON.stringify(e.createSignableVoucher(r),null,2)})}var o=function(){if(Array.isArray(r))return Promise.resolve(e.pipe(e.interaction(),r)).then(function(e){r=e})}();return o&&o.then?o.then(t):t()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return Fe().authenticate()},exports.t=Qe,exports.tx=We,exports.unauthenticate=function(){return Fe().unauthenticate()},exports.verifyUserSignatures=le; | ||
var e=require("@onflow/sdk"),n=require("@onflow/util-invariant"),r=require("@onflow/types"),t=require("@onflow/util-actor"),o=require("@onflow/util-address"),i=require("@onflow/rlp"),a=require("@onflow/util-uid"),s=require("@onflow/util-template");function u(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var c=u(e),l=u(r),d=u(i),f=function(n){try{return Promise.resolve(e.config().where(n)).then(function(e){return Object.fromEntries(Object.entries(e).map(function(e){var r=e[1];return[e[0].replace(n,""),r]}))})}catch(e){return Promise.reject(e)}},p={can:!("undefined"==typeof window),get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,n){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(n)))}catch(e){return Promise.reject(e)}}};e.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":p});var v="0.0.78-alpha.7",h=function(e){return function(n){return typeof n===e}},m=function(e){return null!=e},y=h("object"),g=h("string"),P=h("function"),E=h("number");function b(e){return P(e)?e(c.arg,l):[]}var w=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(m(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(g(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){n.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return c.send([c.script(e.cadence),c.args(b(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}};function R(){return R=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},R.apply(this,arguments)}function S(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function x(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return S(e,n);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)?S(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var C={f_type:"Service",f_vsn:"1.0.0"},O={f_type:"Identity",f_vsn:"1.0.0"},I={f_type:"USER",f_vsn:"1.0.0"},j={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function D(e){return null==e?null:"1.0.0"===e.f_vsn?e:R({old:e},C,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function N(e){return null==e?null:"1.0.0"===e.f_vsn?e:R({},C,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function L(e){return null==e?null:(null==e.method&&(e=R({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:R({},C,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}var k={"back-channel-rpc":N,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:R({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:R({},O,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:R({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:R({},O,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:R({},C,{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:D,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":L,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function F(e){return d.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function T(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function U(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function _(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(U(e),{method:r,headers:R({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function B(e){var n,r;return null==e?null:"1.0.0"===e.f_vsn?e:R({},j,{status:null!=(n=e.status)?n:"APPROVED",reason:null!=(r=e.reason)?r:null,data:e.compositeSignature||e.data||R({},e)||{},updates:N(e.authorizationUpdates),local:D((e.local||[])[0])})}var M=function e(r,t){void 0===t&&(t=function(){return!0});try{if(n.invariant(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(_(r,{method:z(r)}).then(B)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}},V={"HTTP/GET":"GET","HTTP/POST":"POST"},z=function(e){return n.invariant(V[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),V[e.method]},W="FCL_IFRAME";function H(e){n.invariant(!document.getElementById(W),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=W,r.allow="usb *; hid *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r.contentWindow,function(){document.getElementById(W)&&document.getElementById(W).remove()}]}var Y=null,q=null;function J(e){var n,r;return null==Y||null!=(n=Y)&&n.closed?(r=window,Y=r.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top="+(r.top.outerHeight/2+r.top.screenY-385)+", left="+(r.top.outerWidth/2+r.top.screenX-320))):q!==e?(Y.location.replace(e),Y.focus()):Y.focus(),q=e,[Y,function(){Y&&!Y.closed&&Y.close(),Y=null}]}var K=null,G=null;function X(e){var n;return null==K||null!=(n=K)&&n.closed?K=window.open(e,"_blank"):G!==e?(K.location.replace(e),K.focus()):K.focus(),G=e,[K,function(){K&&!K.closed&&K.close(),K=null}]}var Z,$={"VIEW/IFRAME":H,"VIEW/POP":J,"VIEW/TAB":X},Q=function(e,n,r){try{var t={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(o){return Promise.resolve(_(e,{data:R({fclVersion:v,service:t,config:{services:r,app:o}},n)}).then(B)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("REDIRECT"===n.status)return n;if("PENDING"===n.status){var r=!0;return Promise.resolve(function(e,n){void 0===n&&(n={});try{try{return Promise.resolve($[e.method](U(e),n))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:n}),r}}catch(e){return Promise.reject(e)}}(L(n.local))).then(function(e){var t=e[1],o=function(){try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return M(n.updates,function(){return r}).then(function(e){return o(),e}).catch(function(e){throw console.error(e),o(),e})})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})})})}catch(e){return Promise.reject(e)}},ee=function(e){return"string"==typeof e&&e.toLowerCase()},ne=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),re=function(e,n){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+n+" for this and future versions of FCL")},te=function(e){var n=e.close,r=e.send,t=e.onReady,o=e.onResponse,i=e.onMessage;return function(e){try{if("object"!=typeof e.data)return;if(ne.has(e.data.type))return;ee(e.data.type)===ee("FCL:VIEW:CLOSE")&&n(),ee(e.data.type)===ee("FCL:VIEW:READY")&&t(e,{send:r,close:n}),ee(e.data.type)===ee("FCL:VIEW:RESPONSE")&&o(e,{send:r,close:n}),i(e,{send:r,close:n}),ee(e.data.type)===ee("FCL:FRAME:READY")&&(re(e.data.type,"FCL:VIEW:READY"),t(e,{send:r,close:n})),ee(e.data.type)===ee("FCL:FRAME:RESPONSE")&&(re(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:r,close:n})),ee(e.data.type)===ee("FCL:FRAME:CLOSE")&&(re(e.data.type,"FCL:VIEW:CLOSE"),n()),ee(e.data.type)===ee("FCL::CHALLENGE::RESPONSE")&&(re(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:r,close:n})),ee(e.data.type)===ee("FCL::AUTHZ_READY")&&(re(e.data.type,"FCL:VIEW:READY"),t(e,{send:r,close:n})),ee(e.data.type)===ee("FCL::CHALLENGE::CANCEL")&&(re(e.data.type,"FCL:VIEW:CLOSE"),n()),ee(e.data.type)===ee("FCL::CANCEL")&&(re(e.data.type,"FCL:VIEW:CLOSE"),n())}catch(e){console.error("Frame Callback Error",e),n()}}},oe=function(){},ie=function(){},ae=function(){},se=function(){},ue=function e(r){var t=r.service,o=r.msg,i=void 0===o?{}:o,a=r.opts,s=void 0===a?{}:a;try{return Promise.resolve(function(r,o){try{var a=Promise.resolve(ce[t.method](t,i,s)).then(function(r){return"REDIRECT"===r.status?(n.invariant(t.type===r.data.type,"Cannot shift recursive service type in execService"),t=r.data,Promise.resolve(e({service:t,msg:i,opts:s}))):r})}catch(e){return o(e)}return a&&a.then?a.then(void 0,o):a}(0,function(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:i,opts:s}),e}))}catch(e){return Promise.reject(e)}},ce={"HTTP/RPC":Q,"HTTP/POST":Q,"IFRAME/RPC":function(e,n,r){return new Promise(function(t,o){var i,s=a.uid(),u=r.includeOlderJsonRpcCall;n.data=null!=(i=e.data)?i:null,function(e,n){if(void 0===n&&(n={}),null==e)return{send:oe,close:oe};var r=n.onClose||oe;window.addEventListener("message",te({close:a,send:s,onReady:n.onReady||oe,onResponse:n.onResponse||oe,onMessage:n.onMessage||oe}));var t=H(U(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",te),i(),r()}catch(e){console.error("Frame Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(t){return Promise.resolve(f(/^app\.detail\./)).then(function(i){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:i}});var a={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:FRAME:READY:RESPONSE",body:n,service:a,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[n,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;var i=B(e.data.result);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"POP/RPC":function(e,n,r){return new Promise(function(t,o){var i=a.uid(),s=r.redir,u=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:ie,close:ie};var r=n.onClose||ie;window.addEventListener("message",te({close:s,send:u,onReady:n.onReady||ie,onResponse:n.onResponse||ie,onMessage:n.onMessage||ie}));var t=J(U(e)),o=t[0],i=t[1],a=setInterval(function(){o&&o.closed&&s()},500);return{send:u,close:s};function s(){try{window.removeEventListener("message",te),clearInterval(a),i(),r()}catch(e){console.error("Popup Close Error",e)}}function u(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Popup Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(t){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=B(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;case"REDIRECT":t(a),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"TAB/RPC":function(e,n,r){return new Promise(function(t,o){var i=a.uid(),s=r.redir,u=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:ae,close:ae};var r=n.onClose||ae;window.addEventListener("message",te({close:s,send:u,onReady:n.onReady||ae,onResponse:n.onResponse||ae,onMessage:n.onMessage||ae}));var t=X(U(e)),o=t[0],i=t[1],a=setInterval(function(){o&&o.closed&&s()},500);return{send:u,close:s};function s(){try{window.removeEventListener("message",te),clearInterval(a),i(),r()}catch(e){console.error("Tab Close Error",e)}}function u(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Tab Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(t){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=B(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;case"REDIRECT":t(a),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"EXT/RPC":function(e,n,r){return new Promise(function(r,t){!function(e,n){void 0===n&&(n={});try{var r,t=function(){try{window.removeEventListener("message",te),a()}catch(e){console.error("Extension Close Error",e)}},o=function(e){try{var n;null==(n=window[i])||n.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(n){console.error("Extension Send Error",e,n)}};if(null==e)return Promise.resolve({send:se,close:se});var i=e.endpoint,a=n.onClose||se;window.addEventListener("message",te({close:t,send:o,onReady:n.onReady||se,onResponse:n.onResponse||se,onMessage:n.onMessage||se})),Promise.resolve(null==(r=window[i])?void 0:r.flow.enable()).then(function(){return{send:o,close:t}})}catch(e){return Promise.reject(e)}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(f(/^service\./)).then(function(e){return Promise.resolve(f(/^app\.detail\./)).then(function(t){o({fclVersion:v,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:e,app:t}})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var o=n.close;try{if("object"!=typeof e.data)return;var i=B(e.data);switch(i.status){case"APPROVED":r(i.data),o();break;case"DECLINED":t("Declined: "+(i.reason||"No reason supplied")),o();break;case"REDIRECT":r(i),o();break;default:t("Declined: No reason supplied"),o()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose:function(){t("Declined: Externally Halted")}})})}},le=function(r,t){try{n.invariant(/^[0-9a-f]+$/i.test(r),"Message must be a hex string"),n.invariant(Array.isArray(t),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(t.map(function(r){try{return n.invariant("string"==typeof r.addr,"addr must be a string"),n.invariant("number"==typeof r.keyId,"keyId must be a number"),n.invariant("string"==typeof r.signature,"signature must be a string"),Promise.resolve(function(n,t){try{var s=Promise.resolve(e.account(r.addr)).then(function(e){return o.push(e.keys[r.keyId].weight.toFixed(1)),i.push(e.keys[r.keyId].signAlgo),a.push(r.signature),e.keys[r.keyId].publicKey})}catch(e){return t(e)}return s&&s.then?s.then(void 0,t):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(e){return Promise.resolve(w({cadence:""+de,args:function(n,t){return[n(r,t.String),n(e,t.Array([t.String])),n(o,t.Array(t.UFix64)),n(i,t.Array([t.UInt])),n(a,t.Array([t.String]))]}}))})}catch(e){return Promise.reject(e)}},de="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function fe(e){return null==e?null:"1.0.0"===e.f_vsn?e:R({},A,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}function pe(e,n,r){if(!e.s){if(r instanceof ge){if(!r.s)return void(r.o=pe.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(pe.bind(null,e,n),pe.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ve=function(e,n){try{return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Promise.resolve(le(e,n))}catch(e){return Promise.reject(e)}},he=function(e){try{return Oe(),Promise.resolve(Ee({redir:!0})).then(function(r){var t=T(r.services,"user-signature");return n.invariant(t,"Current user must have authorized a signing service."),be(function(){return Promise.resolve(ue({service:t,msg:ke(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return fe(e)}):[fe(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},me=function(){try{return Promise.resolve(Ee()).then(function(n){return e.arg(o.withPrefix(n.addr),l.Address)})}catch(e){return Promise.reject(e)}},ye=function(e){try{return Oe(),Promise.resolve(Ee({redir:!0})).then(function(n){var r=T(n.services,"authz"),t=T(n.services,"pre-authz");return R({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(ue({service:t,msg:n})).then(Ae)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(ue({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(fe)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},ge=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{pe(t,1,i(this.v))}catch(e){pe(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?pe(t,1,n?n(o):o):r?pe(t,1,r(o)):pe(t,2,o)}catch(e){pe(t,2,e)}},t},e}();function Pe(e){return e instanceof ge&&1&e.s}var Ee=function(r){var i=r.service,a=r.redir,s=void 0!==a&&a;try{return Promise.resolve(new Promise(function(r,a){try{return Oe(),Promise.resolve(Ne()).then(function(a){return a.loggedIn&&Ie(a)?r(a):Promise.resolve(function(){try{return Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(n){return Promise.resolve(e.config.first(["discovery.wallet.method","discovery.wallet.method.default"])).then(function(r){return Promise.resolve(e.config.get("fcl.appDomainTag")).then(function(e){return{discoveryWallet:n,discoveryWalletMethod:r,appDomainTag:e}})})})}catch(e){return Promise.reject(e)}}()).then(function(a){var u=a.discoveryWallet,c=a.discoveryWalletMethod,l=a.appDomainTag;return n.invariant(i||u,'\n If no service passed to "authenticate," then "discovery.wallet" must be defined in config.\n See: "https://docs.onflow.org/fcl/reference/api/#setting-configuration-values"\n '),Promise.resolve(e.config.get("fcl.warning.suppress.redir")).then(function(e){s&&!e&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");var n=function(e,n){try{var r=be(function(){return Promise.resolve(ue({service:i||{type:"authn",endpoint:u,method:c},msg:{timestamp:Date.now(),appDomainTag:l,extensions:window.fcl_extensions||[]},opts:{redir:s}})).then(function(e){return Promise.resolve(function(e){try{var n=(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,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=x(e.authorizations);!(r=t()).done;)n.push(R({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(R({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,i,a=(t=n,i=r,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(n){return function(e,n){try{return k[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),s=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,a);return R({},I,{addr:o.withPrefix(e.addr),cid:F(s),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){t.send(we,Se,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return n(!0,e)}return r&&r.then?r.then(n.bind(null,!1),n.bind(null,!0)):n(!1,r)}(0,function(e,n){return Promise.resolve(Ne()).then(function(t){if(r(t),e)throw n;return n})});if(n&&n.then)return n.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function be(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var we="CURRENT_USER",Re="CURRENT_USER/UPDATED",Se="SET_CURRENT_USER",xe='{\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=((Z={})[t.INIT]=function(n){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),n.merge(JSON.parse(xe)),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){var r=function(){if(e.can)return Promise.resolve(function(e){try{var n=JSON.parse(xe);return Promise.resolve(e.get(we)).then(function(r){return null!=r&&n.f_vsn!==r.f_vsn?(e.removeItem(we),n):r||n})}catch(e){return Promise.reject(e)}}(e)).then(function(e){Ie(e)&&n.merge(e)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Z[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,Re,R({},e.all()))},Z[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Z.SNAPSHOT=function(e,n){try{return n.reply(R({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[Se]=function(n,r,t){try{return n.merge(t),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(we,n.all()),n.broadcast(Re,R({},n.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(n,r){try{return n.merge(JSON.parse(xe)),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(we,n.all()),n.broadcast(Re,R({},n.all()))})}catch(e){return Promise.reject(e)}},Z),Oe=function(){return t.spawn(Ce,we)};function Ie(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function je(){Oe(),t.send(we,"DEL_CURRENT_USER")}function Ae(e){var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=x(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,a=x(n.authorization||[]);!(i=a()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return ue({service:r,msg:e})},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}})}function De(e){Oe();var n="@EXIT",r=t.spawn(function(r){try{var o;return r.send(we,t.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Pe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Pe(i)){t=1;break}i=i.s}}var a=new ge,s=pe.bind(null,a,2);return(0===t?o.then(c):1===t?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):pe(a,1,i)})).then(void 0,s),a;function u(n){i=n;do{if(!(o=e())||Pe(o)&&!o.v)return void pe(a,1,i);if(o.then)return void o.then(c).then(void 0,s);Pe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=r())&&i.then?i.then(u).then(void 0,s):u(i):pe(a,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===n)return r.send(we,t.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(r,n)}}function Ne(){return Oe(),t.send(we,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Le,ke=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Fe=function(){return{authenticate:Ee,unauthenticate:je,authorization:ye,signUserMessage:he,verifyUserSignatures:ve,subscribe:De,snapshot:Ne,resolveArgument:me}};Fe.authenticate=Ee,Fe.unauthenticate=je,Fe.authorization=ye,Fe.signUserMessage=he,Fe.verifyUserSignatures=ve,Fe.subscribe=De,Fe.snapshot=Ne,Fe.resolveArgument=me;var Te=function(n){try{return Promise.resolve(e.send([e.getTransactionStatus(n)]).then(e.decode))}catch(e){return Promise.reject(e)}},Ue=function(e){return e.status>=4},_e=function(e){return e.status>=3},Be=function(e){return e.status>=2},Me=((Le={})[t.INIT]=function(e){try{return Promise.resolve(Te(e.self())).then(function(n){Ue(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},Le[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,t.UPDATED,e.all())},Le[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Le[t.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Le.POLL=function(e){try{return Promise.resolve(Te(e.self())).then(function(n){var r,o;Ue(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),o=n,JSON.stringify(r)!==JSON.stringify(o)&&e.broadcast(t.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},Le),Ve=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ze=function(e){return t.spawn(Me,Ve(e))};function We(e){function n(n){return t.subscriber(Ve(e),ze,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return t.snapshoter(e,ze)},subscribe:n,onceFinalized:r(Be),onceExecuted:r(_e),onceSealed:r(Ue)}}We.isUnknown=function(e){return e.status>=0},We.isPending=function(e){return e.status>=1},We.isFinalized=Be,We.isExecuted=_e,We.isSealed=Ue,We.isExpired=function(e){return 5===e.status};var He,Ye=function(n){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},qe=((He={}).TICK=function(n){try{if(!n.hasSubs())return Promise.resolve();var r=n.get("hwm"),t=function(){if(null==r){var t=n.put;return Promise.resolve(e.latestBlock()).then(function(e){t.call(n,"hwm",e);var r=n.put;return Promise.resolve(Ye(n)).then(function(e){r.call(n,"tick",e)})})}return Promise.resolve(e.latestBlock()).then(function(t){return n.put("hwm",t),Promise.resolve(e.send([e.getEvents(n.self(),r.height,t.height-1)]).then(e.decode)).then(function(e){for(var r,t=x(e);!(r=t()).done;)n.broadcast("UPDATED",r.value.data);var o=n.put;return Promise.resolve(Ye(n)).then(function(e){o.call(n,"tick",e)})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},He[t.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(Ye(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},He[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},He),Je=function(e){return t.spawn(qe,e)},Ke=function(r){void 0===r&&(r=[]);try{return Promise.resolve(e.config.get("discovery.authn.endpoint")).then(function(e){n.invariant(Boolean(e),'"discovery.authn.endpoint" in config must be defined.');var t=new URL(e);return fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()}).then(function(e){return[].concat(r,e)})})}catch(e){return Promise.reject(e)}};function Ge(e){void 0===e&&(e=[]);var n=window.fcl_extensions||[];return[].concat(n,e)}var Xe,Ze=((Xe={})[t.INIT]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "fcl.discovery" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),Promise.resolve((n={type:"authn"},r=n.type,function(){var e=arguments;return function(n){return[].slice.call(e).reduce(function(e,n){return e.then(n)},Promise.resolve(n))}}(Ke,Ge,function(e){return function(e,n){return void 0===e&&(e=[]),e.filter(function(e){return e.type===n})}(e,r)})([]))).then(function(n){e.put("results",n)})}catch(e){return Promise.reject(e)}var n,r},Xe[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,"UPDATED",R({},e.all()))},Xe[t.UNSUBSCRIBE]=function(e,n){return e.unsubscribe(n.from)},Xe.SNAPSHOT=function(e,n){try{return Promise.resolve(n.reply(R({},e.all())))}catch(e){return Promise.reject(e)}},Xe),$e=function(){return t.spawn(Ze,"authn")},Qe={authn:{subscribe:function(e){return t.subscriber("authn",$e,e)},snapshot:function(){return t.snapshoter("authn",$e)}}},en=function(e,n){void 0===n&&(n=function(){});var r=function(r){var t=r.data;"object"==typeof t&&null!=typeof t&&t.type===e&&n(function(e){var n;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(n=e.body)||delete n.interaction,e}(t))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},nn=function(e,n){void 0===n&&(n={}),window.location!==window.parent.location?window.parent.postMessage(R({},n,{type:e}),"*"):window.opener.postMessage(R({},n,{type:e}),"*")},rn=function(e,n){return Buffer.from(e.padEnd(2*n,0),"hex")},tn={__proto__:null,sendMsgToFCL:nn,ready:function(e,n){en("FCL:VIEW:READY:RESPONSE",e),nn("FCL:VIEW:READY")},close:function(){nn("FCL:VIEW:CLOSE")},approve:function(e){nn("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){nn("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:function(e){nn("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:en,encodeMessageFromSignable:e.encodeMessageFromSignable,CompositeSignature:function(e,n,r){this.f_type=A.f_type,this.f_vsn=A.f_vsn,this.addr=o.withPrefix(e),this.keyId=Number(n),this.signature=r},encodeMessageForProvableAuthnSigning:function(e,r,t){void 0===t&&(t=""),n.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),n.invariant(r,"Encode Message From Provable Authn Error: timestamp must be defined");var a=rn(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),s=rn(Buffer.from(t).toString("hex"),32).toString("hex");return a+(t?i.encode([s,o.withPrefix(e),r]).toString("hex"):i.encode([o.withPrefix(e),r]).toString("hex"))},encodeMessageForProvableAuthnVerifying:function(e,r,t){void 0===t&&(t=""),n.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),n.invariant(r,"Encode Message From Provable Authn Error: timestamp must be defined");var a,s=t?(a=Buffer.from(t).toString("hex"),Buffer.from(a.padEnd(64,0),"hex")).toString("hex"):null;return t?i.encode([s,o.withPrefix(e),r]).toString("hex"):i.encode([o.withPrefix(e),r]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}},on=Fe().authorization,an=l;Object.defineProperty(exports,"TestUtils",{enumerable:!0,get:function(){return e.TestUtils}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return e.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return e.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return e.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return e.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return e.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return e.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return e.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return e.build}}),Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"createSignableVoucher",{enumerable:!0,get:function(){return e.createSignableVoucher}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return e.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return e.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return e.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return e.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return e.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return e.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return e.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return e.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return e.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return e.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return e.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return e.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return e.getTransactionStatus}}),Object.defineProperty(exports,"invariant",{enumerable:!0,get:function(){return e.invariant}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return e.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return e.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return e.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return e.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return e.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return e.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return e.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return e.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return e.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return e.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return e.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return e.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return e.transaction}}),Object.defineProperty(exports,"validator",{enumerable:!0,get:function(){return e.validator}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return s.template}}),exports.VERSION=v,exports.WalletUtils=tn,exports.authenticate=function(e){return void 0===e&&(e={}),Fe().authenticate(e)},exports.authz=on,exports.currentUser=Fe,exports.discovery=Qe,exports.events=function(e){return{subscribe:function(n){return t.subscriber(e,Je,n)}}},exports.logIn=function(e){return void 0===e&&(e={}),Fe().authenticate(e)},exports.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(r,t){try{var o=Promise.resolve(function(e){try{return n.invariant(m(e),"mutate(opts) -- opts is required"),n.invariant(y(e),"mutate(opts) -- opts must be an object"),n.invariant(m(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(g(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){n.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(c.config().get("fcl.authz",Fe().authorization)).then(function(n){return c.send([c.transaction(e.cadence),c.args(b(e.args||[])),e.limit&&E(e.limit)&&c.limit(e.limit),c.proposer(e.proposer||e.authz||n),c.payer(e.payer||e.authz||n),c.authorizations(e.authorizations||[e.authz||n])]).then(c.decode)})})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},exports.query=w,exports.reauthenticate=function(e){return void 0===e&&(e={}),Fe().unauthenticate(),Fe().authenticate(e)},exports.serialize=function(n,r){void 0===n&&(n=[]),void 0===r&&(r={});try{return Promise.resolve(e.config.first(["sdk.resolve"],r.resolve||e.resolve)).then(function(r){function t(){return Promise.resolve(r(n)).then(function(n){return JSON.stringify(e.createSignableVoucher(n),null,2)})}var o=function(){if(Array.isArray(n))return Promise.resolve(e.pipe(e.interaction(),n)).then(function(e){n=e})}();return o&&o.then?o.then(t):t()})}catch(e){return Promise.reject(e)}},exports.signUp=function(e){return void 0===e&&(e={}),Fe().authenticate(e)},exports.t=an,exports.tx=We,exports.unauthenticate=function(){return Fe().unauthenticate()},exports.verifyUserSignatures=le; | ||
//# sourceMappingURL=fcl.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"@onflow/sdk";import{config as t,arg as n,send as a,getTransactionStatus as r,decode as s,resolve as o,pipe as i,interaction as c,createSignableVoucher as d,latestBlock as l,getEvents as u,encodeMessageFromSignable as p}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as f}from"@onflow/util-invariant";import*as y from"@onflow/types";import{spawn as g,send as m,SUBSCRIBE as E,UNSUBSCRIBE as h,INIT as w,subscriber as R,snapshoter as v,UPDATED as S,SNAPSHOT as b}from"@onflow/util-actor";import{withPrefix as C,sansPrefix as P}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as A from"@onflow/rlp";import{encode as I}from"@onflow/rlp";import{uid as D}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";const L={can:!("undefined"==typeof window),get:async e=>JSON.parse(sessionStorage.getItem(e)),put:async(e,t)=>sessionStorage.setItem(e,JSON.stringify(t))};async function N(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,n])=>[t.replace(e,""),n]))}t({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":L,"fcl.appDomainTag.default":"APP-V0.0-user"});const O="0.0.78-alpha.6",k=e=>t=>typeof t===e,F=e=>null!=e,x=k("object"),T=k("string"),_=k("function"),M=k("number");function V(t){return _(t)?t(e.arg,y):[]}async function U(t={}){return await async function(t){f(F(t.cadence),"query({ cadence }) -- cadence is required"),f(T(t.cadence),"query({ cadence }) -- cadence must be a string"),f(await e.config.get("accessNode.api"),'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')}(t),e.send([e.script(t.cadence),e.args(V(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function j(){return j=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},j.apply(this,arguments)}const W={f_type:"Service",f_vsn:"1.0.0"},z={f_type:"Identity",f_vsn:"1.0.0"},H={f_type:"USER",f_vsn:"1.0.0"},Y={f_type:"PollingResponse",f_vsn:"1.0.0"},B={f_type:"CompositeSignature",f_vsn:"1.0.0"};function J(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({old:e},W,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function $(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function q(e){return null==e?null:(null==e.method&&(e=j({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:j({},W,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}const K={"back-channel-rpc":$,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:j({},z,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:j({},z,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:C(e.addr),name:e.name,icon:e.icon}})},frame:J,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":q,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function G(e){return A.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function X(e=[],t){return e.find(e=>e.type===t)}function Z(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 Q(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(Z(e),{method:n,headers:j({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function ee(e){var t,n;return null==e?null:"1.0.0"===e.f_vsn?e:j({},Y,{status:null!=(t=e.status)?t:"APPROVED",reason:null!=(n=e.reason)?n:null,data:e.compositeSignature||e.data||j({},e)||{},updates:$(e.authorizationUpdates),local:J((e.local||[])[0])})}const te={"HTTP/GET":"GET","HTTP/POST":"POST"},ne=e=>(f(te[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),te[e.method]);async function ae(e,t=(()=>!0)){if(f(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await Q(e,{method:ne(e)}).then(ee);switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error(`Declined: ${n.reason||"No reason supplied."}`);default:return await new Promise(e=>setTimeout(e,500)),ae(n.updates,t)}}const re="FCL_IFRAME";function se(e){f(!document.getElementById(re),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=re,t.allow="usb *; hid *",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.contentWindow,()=>{document.getElementById(re)&&document.getElementById(re).remove()}]}let oe=null,ie=null;function ce(e){var t,n;null==oe||null!=(t=oe)&&t.closed?(n=window,oe=n.open(e,"FCL_POP",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top=${n.top.outerHeight/2+n.top.screenY-385}, left=${n.top.outerWidth/2+n.top.screenX-320}`)):ie!==e?(oe.location.replace(e),oe.focus()):oe.focus(),ie=e;var a=setInterval(function(){oe&&oe.closed&&(clearInterval(a),oe=null)},1e3);return[oe,()=>{oe&&!oe.closed&&(oe.close(),oe=null)}]}let de=null,le=null;function ue(e){var t;null==de||null!=(t=de)&&t.closed?de=window.open(e,"_blank"):le!==e?(de.location.replace(e),de.focus()):de.focus(),le=e;var n=setInterval(function(){de&&de.closed&&(clearInterval(n),de=null)},1e3);return[de,()=>{de&&!de.closed&&(de.close(),de=null)}]}const pe={"VIEW/IFRAME":se,"VIEW/POP":ce,"VIEW/TAB":ue};async function fe(e,t,n={}){const a=await Q(e,{data:j({fclVersion:O,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}},t)}).then(ee);if("APPROVED"===a.status)return a.data;if("DECLINED"===a.status)throw new Error(`Declined: ${a.reason||"No reason supplied."}`);if("REDIRECT"===a.status)return a;if("PENDING"===a.status){var r=!0;const[e,t]=await async function(e,t={}){try{return pe[e.method](Z(e),t)}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}(q(a.local)),n=()=>{try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return ae(a.updates,()=>r).then(e=>(n(),e)).catch(e=>{throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:a}),new Error("Auto Decline: Invalid Response")}const ye=e=>"string"==typeof e&&e.toLowerCase(),ge=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),me=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),Ee=({close:e,send:t,onReady:n,onResponse:a,onMessage:r})=>s=>{try{if("object"!=typeof s.data)return;if(ge.has(s.data.type))return;ye(s.data.type)===ye("FCL:VIEW:CLOSE")&&e(),ye(s.data.type)===ye("FCL:VIEW:READY")&&n(s,{send:t,close:e}),ye(s.data.type)===ye("FCL:VIEW:RESPONSE")&&a(s,{send:t,close:e}),r(s,{send:t,close:e}),ye(s.data.type)===ye("FCL:FRAME:READY")&&(me(s.data.type,"FCL:VIEW:READY"),n(s,{send:t,close:e})),ye(s.data.type)===ye("FCL:FRAME:RESPONSE")&&(me(s.data.type,"FCL:VIEW:RESPONSE"),a(s,{send:t,close:e})),ye(s.data.type)===ye("FCL:FRAME:CLOSE")&&(me(s.data.type,"FCL:VIEW:CLOSE"),e()),ye(s.data.type)===ye("FCL::CHALLENGE::RESPONSE")&&(me(s.data.type,"FCL:VIEW:RESPONSE"),a(s,{send:t,close:e})),ye(s.data.type)===ye("FCL::AUTHZ_READY")&&(me(s.data.type,"FCL:VIEW:READY"),n(s,{send:t,close:e})),ye(s.data.type)===ye("FCL::CHALLENGE::CANCEL")&&(me(s.data.type,"FCL:VIEW:CLOSE"),e()),ye(s.data.type)===ye("FCL::CANCEL")&&(me(s.data.type,"FCL:VIEW:CLOSE"),e())}catch(t){console.error("Frame Callback Error",t),e()}},he=()=>{},we=()=>{},Re=()=>{},ve=()=>{},Se={"HTTP/RPC":fe,"HTTP/POST":fe,"IFRAME/RPC":function(e,t,n){return new Promise((a,r)=>{var s;const o=D(),i=n.includeOlderJsonRpcCall;t.data=null!=(s=e.data)?s:null,function(e,t={}){if(null==e)return{send:he,close:he};const n=t.onClose||he;window.addEventListener("message",Ee({close:s,send:o,onReady:t.onReady||he,onResponse:t.onResponse||he,onMessage:t.onMessage||he}));const[a,r]=se(Z(e));return{send:o,close:s};function s(){try{window.removeEventListener("message",Ee),r(),n()}catch(e){console.error("Frame Close Error",e)}}function o(e){try{a.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}}),a({fclVersion:O,type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&a({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=ee(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;const n=ee(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"POP/RPC":function(e,t,n){return new Promise((a,r)=>{const s=D(),{redir:o,includeOlderJsonRpcCall:i}=n;t.data=e.data,function(e,t={}){if(null==e)return{send:we,close:we};const n=t.onClose||we;window.addEventListener("message",Ee({close:s,send:o,onReady:t.onReady||we,onResponse:t.onResponse||we,onMessage:t.onMessage||we}));const[a,r]=ce(Z(e));return{send:o,close:s};function s(){try{window.removeEventListener("message",Ee),r(),n()}catch(e){console.error("Popup Close Error",e)}}function o(e){try{a.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}}),a({fclVersion:O,type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&a({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=ee(e.data);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;const n=ee(e.data.result);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"TAB/RPC":function(e,t,n){return new Promise((a,r)=>{const s=D(),{redir:o,includeOlderJsonRpcCall:i}=n;t.data=e.data,function(e,t={}){if(null==e)return{send:Re,close:Re};const n=t.onClose||Re;window.addEventListener("message",Ee({close:s,send:o,onReady:t.onReady||Re,onResponse:t.onResponse||Re,onMessage:t.onMessage||Re}));const[a,r]=ue(Z(e));return{send:o,close:s};function s(){try{window.removeEventListener("message",Ee),r(),n()}catch(e){console.error("Tab Close Error",e)}}function o(e){try{a.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}}),a({fclVersion:O,type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&a({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=ee(e.data);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;const n=ee(e.data.result);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"EXT/RPC":function(e,t,n){return new Promise((n,a)=>{!async function(e,t={}){var n;if(null==e)return{send:ve,close:ve};const{endpoint:a}=e,r=t.onClose||ve;window.addEventListener("message",Ee({close:function(){try{window.removeEventListener("message",Ee),r()}catch(e){console.error("Extension Close Error",e)}},send:function(e){try{var t;null==(t=window[a])||t.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(t){console.error("Extension Send Error",e,t)}},onReady:t.onReady||ve,onResponse:t.onResponse||ve,onMessage:t.onMessage||ve})),await(null==(n=window[a])?void 0:n.flow.enable())}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const r=ee(e.data);switch(r.status){case"APPROVED":n(r.data),t();break;case"DECLINED":a(`Declined: ${r.reason||"No reason supplied"}`),t();break;case"REDIRECT":n(r),t();break;default:a("Declined: No reason supplied"),t()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose(){a("Declined: Externally Halted")}})})}};async function be({service:e,msg:t={},opts:n={}}){try{const a=await Se[e.method](e,t,n);return"REDIRECT"===a.status?(f(e.type===a.data.type,"Cannot shift recursive service type in execService"),e=a.data,await be({service:e,msg:t,opts:n})):a}catch(a){throw console.error("execService({service, msg = {}, opts = {}})",a,{service:e,msg:t,opts:n}),a}}async function Ce(e,t){f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),f(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[],r=[];const s=await Promise.all(t.map(async e=>{f("string"==typeof e.addr,"addr must be a string"),f("number"==typeof e.keyId,"keyId must be a number"),f("string"==typeof e.signature,"signature must be a string");try{const t=await t(e.addr);return n.push(t.keys[e.keyId].weight.toFixed(1)),a.push(t.keys[e.keyId].signAlgo),r.push(e.signature),t.keys[e.keyId].publicKey}catch(e){throw e}}));return await U({cadence:`${Pe}`,args:(t,o)=>[t(e,o.String),t(s,o.Array([o.String])),t(n,o.Array(o.UFix64)),t(a,o.Array([o.UInt])),t(r,o.Array([o.String]))]})}const Pe="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function Ae(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},B,{addr:P(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}const Ie="CURRENT_USER",De="CURRENT_USER/UPDATED",Le='{\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={[w]:async e=>{"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),e.merge(JSON.parse(Le));const n=await t.first(["fcl.storage","fcl.storage.default"]);if(n.can){const t=await(async e=>{const t=JSON.parse(Le),n=await e.get(Ie);return null!=n&&t.f_vsn!==n.f_vsn?(e.removeItem(Ie),t):n||t})(n);ke(t)&&e.merge(t)}},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,De,j({},e.all()))},[h]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(j({},e.all()))},SET_CURRENT_USER:async(e,n,a)=>{e.merge(a);const r=await t.first(["fcl.storage","fcl.storage.default"]);r.can&&r.put(Ie,e.all()),e.broadcast(De,j({},e.all()))},DEL_CURRENT_USER:async(e,n)=>{e.merge(JSON.parse(Le));const a=await t.first(["fcl.storage","fcl.storage.default"]);a.can&&a.put(Ie,e.all()),e.broadcast(De,j({},e.all()))}},Oe=()=>g(Ne,Ie);function ke(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Fe(e={redir:!1}){return new Promise(async(n,a)=>{Oe();const r=await Me();if(r.loggedIn&&ke(r))return n(r);const{discoveryWallet:s,discoveryWalletMethod:o,appDomainTag:i}=await async function(){const e=await t.first(["discovery.wallet","challenge.handshake"]),n=await t.first(["discovery.wallet.method","discovery.wallet.method.default"]),a=await t.first(["fcl.appDomainTag","fcl.appDomainTag.default"]);return f(null!=e,'\n Required value for discovery.wallet not defined in config.\n See: "https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration"\n '),{discoveryWallet:e,discoveryWalletMethod:n,appDomainTag:a}}(),c=await t.get("fcl.warning.suppress.redir");e.redir&&!c&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");try{const t=await be({service:{type:"authn",endpoint:s,method:o},msg:{timestamp:Date.now(),appDomainTag:i,extensions:window.fcl_extensions||[]},opts:e});m(Ie,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?C(e.addr):null,e.paddr=e.paddr?C(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(j({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(j({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return K[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 j({},H,{addr:C(e.addr),cid:G(n),loggedIn:!0,services:t,expiresAt:e.exp})}(t))}catch(e){console.error("Error while authenticating",e)}finally{n(await Me())}})}function xe(){Oe(),m(Ie,"DEL_CURRENT_USER")}async function Te(e){Oe();const t=await Fe({redir:!0}),n=X(t.services,"authz"),a=X(t.services,"pre-authz");return j({},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=>be({service:t,msg:e}),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await be({service:a,msg:t}))}:{tempId:"CURRENT_USER",resolve:null,addr:P(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>Ae(await be({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}}))})}function _e(e){Oe();const t="@EXIT",n=g(async n=>{for(n.send(Ie,E);;){const a=await n.receive();if(a.tag===t)return void n.send(Ie,h);e(a.data)}});return()=>m(n,t)}function Me(){return Oe(),m(Ie,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function Ve(){const{addr:e}=await Fe();return n(C(e),y.Address)}const Ue=e=>(f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e});async function je(e){Oe();const t=X((await Fe({redir:!0})).services,"user-signature");f(t,"Current user must have authorized a signing service.");try{const n=await be({service:t,msg:Ue(e)});return Array.isArray(n)?n.map(e=>Ae(e)):[Ae(n)]}catch(e){return e}}async function We(e,t){return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Ce(e,t)}let ze=()=>({authenticate:Fe,unauthenticate:xe,authorization:Te,signUserMessage:je,verifyUserSignatures:We,subscribe:_e,snapshot:Me,resolveArgument:Ve});ze.authenticate=Fe,ze.unauthenticate=xe,ze.authorization=Te,ze.signUserMessage=je,ze.verifyUserSignatures=We,ze.subscribe=_e,ze.snapshot=Me,ze.resolveArgument=Ve;const He=async e=>a([r(e)]).then(s),Ye=e=>e.status>=4,Be=e=>e.status>=3,Je=e=>e.status>=2,$e={[w]:async e=>{const t=await He(e.self());Ye(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,S,e.all())},[h]:(e,t)=>{e.unsubscribe(t.from)},[b]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await He(e.self());var n,a;Ye(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(S,t),e.merge(t)}},qe=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ke=e=>g($e,qe(e));function Ge(e){function t(t){return R(qe(e),Ke,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 v(e,Ke)},subscribe:t,onceFinalized:n(Je),onceExecuted:n(Be),onceSealed:n(Ye)}}async function Xe(t={}){var n;try{await async function(t){f(F(t),"mutate(opts) -- opts is required"),f(x(t),"mutate(opts) -- opts must be an object"),f(F(t.cadence),"mutate({ cadence }) -- cadence is required"),f(T(t.cadence),"mutate({ cadence }) -- cadence must be a string"),f(await e.config.get("accessNode.api"),'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')}(t);const a=await e.config().get("fcl.authz",ze().authorization);return n=e.send([e.transaction(t.cadence),e.args(V(t.args||[])),t.limit&&M(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||a),e.payer(t.payer||t.authz||a),e.authorizations(t.authorizations||[t.authz||a])]).then(e.decode),n}catch(e){throw e}}Ge.isUnknown=e=>e.status>=0,Ge.isPending=e=>e.status>=1,Ge.isFinalized=Je,Ge.isExecuted=Be,Ge.isSealed=Ye,Ge.isExpired=e=>5===e.status;const Ze=async(e=[],n={})=>{const a=await t.first(["sdk.resolve"],n.resolve||o);return Array.isArray(e)&&(e=await i(c(),e)),JSON.stringify(d(await a(e)),null,2)},Qe=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),et={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await l()),e.put("tick",await Qe(e));else{let n=await l();e.put("hwm",n);const r=await a([u(e.self(),t.height,n.height-1)]).then(s);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await Qe(e))}},[E]:async(e,t)=>{e.hasSubs()||e.put("tick",await Qe(e)),e.subscribe(t.from)},[h]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},tt=e=>g(et,e);function nt(e){return{subscribe:t=>R(e,tt,t)}}const at=(e,t=(()=>{}))=>{const n=n=>{const{data:a}=n;"object"==typeof a&&null!=typeof a&&a.type===e&&t((e=>{var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e})(a))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},rt=(e,t={})=>{window.location!==window.parent.location?window.parent.postMessage(j({},t,{type:e}),"*"):window.opener.postMessage(j({},t,{type:e}),"*")},st=(e,t)=>Buffer.from(e.padEnd(2*t,0),"hex");var ot={__proto__:null,sendMsgToFCL:rt,ready:(e,t={})=>{at("FCL:VIEW:READY:RESPONSE",e),rt("FCL:VIEW:READY")},close:()=>{rt("FCL:VIEW:CLOSE")},approve:e=>{rt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:e=>{rt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:e=>{rt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:at,encodeMessageFromSignable:p,CompositeSignature:function(e,t,n){this.f_type=B.f_type,this.f_vsn=B.f_vsn,this.addr=C(e),this.keyId=Number(t),this.signature=n},encodeMessageForProvableAuthnSigning:(e,t,n="")=>{f(e,"Encode Message From Provable Authn Error: address must be defined"),f(t,"Encode Message From Provable Authn Error: timestamp must be defined");const a=st(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),r=st(Buffer.from(n).toString("hex"),32).toString("hex");return a+(n?I([r,C(e),t]).toString("hex"):I([C(e),t]).toString("hex"))},encodeMessageForProvableAuthnVerifying:(e,t,n="")=>{f(e,"Encode Message From Provable Authn Error: address must be defined"),f(t,"Encode Message From Provable Authn Error: timestamp must be defined");const a=n?(r=Buffer.from(n).toString("hex"),Buffer.from(r.padEnd(64,0),"hex")).toString("hex"):null;var r;return n?I([a,C(e),t]).toString("hex"):I([C(e),t]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}};const it=()=>ze().authenticate(),ct=()=>ze().unauthenticate(),dt=()=>(ze().unauthenticate(),ze().authenticate()),lt=()=>ze().authenticate(),ut=()=>ze().authenticate(),pt=ze().authorization,ft=y;export{O as VERSION,ot as WalletUtils,it as authenticate,pt as authz,ze as currentUser,nt as events,ut as logIn,Xe as mutate,U as query,dt as reauthenticate,Ze as serialize,lt as signUp,ft as t,Ge as tx,ct as unauthenticate,Ce as verifyUserSignatures}; | ||
import*as e from"@onflow/sdk";import{config as t,arg as n,send as a,getTransactionStatus as r,decode as s,resolve as o,pipe as i,interaction as c,createSignableVoucher as d,latestBlock as l,getEvents as u,encodeMessageFromSignable as p}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as f}from"@onflow/util-invariant";import*as y from"@onflow/types";import{spawn as g,send as m,SUBSCRIBE as h,UNSUBSCRIBE as E,INIT as w,subscriber as v,snapshoter as R,UPDATED as S,SNAPSHOT as b}from"@onflow/util-actor";import{withPrefix as C,sansPrefix as P}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as A from"@onflow/rlp";import{encode as I}from"@onflow/rlp";import{uid as D}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";const L={can:!("undefined"==typeof window),get:async e=>JSON.parse(sessionStorage.getItem(e)),put:async(e,t)=>sessionStorage.setItem(e,JSON.stringify(t))};async function N(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,n])=>[t.replace(e,""),n]))}t({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":L});const O="0.0.78-alpha.7",F=e=>t=>typeof t===e,k=e=>null!=e,T=F("object"),x=F("string"),_=F("function"),M=F("number");function V(t){return _(t)?t(e.arg,y):[]}async function U(t={}){return await async function(t){f(k(t.cadence),"query({ cadence }) -- cadence is required"),f(x(t.cadence),"query({ cadence }) -- cadence must be a string"),f(await e.config.get("accessNode.api"),'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')}(t),e.send([e.script(t.cadence),e.args(V(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function j(){return j=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},j.apply(this,arguments)}const W={f_type:"Service",f_vsn:"1.0.0"},z={f_type:"Identity",f_vsn:"1.0.0"},H={f_type:"USER",f_vsn:"1.0.0"},B={f_type:"PollingResponse",f_vsn:"1.0.0"},Y={f_type:"CompositeSignature",f_vsn:"1.0.0"};function J(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({old:e},W,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function $(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function K(e){return null==e?null:(null==e.method&&(e=j({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:j({},W,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}const q={"back-channel-rpc":$,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:j({},z,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:j({},z,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},W,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:C(e.addr),name:e.name,icon:e.icon}})},frame:J,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":K,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function G(e){return A.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function X(e=[],t){return e.find(e=>e.type===t)}function Z(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 Q(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(Z(e),{method:n,headers:j({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function ee(e){var t,n;return null==e?null:"1.0.0"===e.f_vsn?e:j({},B,{status:null!=(t=e.status)?t:"APPROVED",reason:null!=(n=e.reason)?n:null,data:e.compositeSignature||e.data||j({},e)||{},updates:$(e.authorizationUpdates),local:J((e.local||[])[0])})}const te={"HTTP/GET":"GET","HTTP/POST":"POST"},ne=e=>(f(te[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),te[e.method]);async function ae(e,t=(()=>!0)){if(f(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await Q(e,{method:ne(e)}).then(ee);switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error(`Declined: ${n.reason||"No reason supplied."}`);default:return await new Promise(e=>setTimeout(e,500)),ae(n.updates,t)}}const re="FCL_IFRAME";function se(e){f(!document.getElementById(re),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=re,t.allow="usb *; hid *",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.contentWindow,()=>{document.getElementById(re)&&document.getElementById(re).remove()}]}let oe=null,ie=null;function ce(e){var t,n;return null==oe||null!=(t=oe)&&t.closed?(n=window,oe=n.open(e,"FCL_POP",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top=${n.top.outerHeight/2+n.top.screenY-385}, left=${n.top.outerWidth/2+n.top.screenX-320}`)):ie!==e?(oe.location.replace(e),oe.focus()):oe.focus(),ie=e,[oe,()=>{oe&&!oe.closed&&oe.close(),oe=null}]}let de=null,le=null;function ue(e){var t;return null==de||null!=(t=de)&&t.closed?de=window.open(e,"_blank"):le!==e?(de.location.replace(e),de.focus()):de.focus(),le=e,[de,()=>{de&&!de.closed&&de.close(),de=null}]}const pe={"VIEW/IFRAME":se,"VIEW/POP":ce,"VIEW/TAB":ue};async function fe(e,t,n={}){const a=await Q(e,{data:j({fclVersion:O,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}},t)}).then(ee);if("APPROVED"===a.status)return a.data;if("DECLINED"===a.status)throw new Error(`Declined: ${a.reason||"No reason supplied."}`);if("REDIRECT"===a.status)return a;if("PENDING"===a.status){var r=!0;const[e,t]=await async function(e,t={}){try{return pe[e.method](Z(e),t)}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}(K(a.local)),n=()=>{try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return ae(a.updates,()=>r).then(e=>(n(),e)).catch(e=>{throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:a}),new Error("Auto Decline: Invalid Response")}const ye=e=>"string"==typeof e&&e.toLowerCase(),ge=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),me=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),he=({close:e,send:t,onReady:n,onResponse:a,onMessage:r})=>s=>{try{if("object"!=typeof s.data)return;if(ge.has(s.data.type))return;ye(s.data.type)===ye("FCL:VIEW:CLOSE")&&e(),ye(s.data.type)===ye("FCL:VIEW:READY")&&n(s,{send:t,close:e}),ye(s.data.type)===ye("FCL:VIEW:RESPONSE")&&a(s,{send:t,close:e}),r(s,{send:t,close:e}),ye(s.data.type)===ye("FCL:FRAME:READY")&&(me(s.data.type,"FCL:VIEW:READY"),n(s,{send:t,close:e})),ye(s.data.type)===ye("FCL:FRAME:RESPONSE")&&(me(s.data.type,"FCL:VIEW:RESPONSE"),a(s,{send:t,close:e})),ye(s.data.type)===ye("FCL:FRAME:CLOSE")&&(me(s.data.type,"FCL:VIEW:CLOSE"),e()),ye(s.data.type)===ye("FCL::CHALLENGE::RESPONSE")&&(me(s.data.type,"FCL:VIEW:RESPONSE"),a(s,{send:t,close:e})),ye(s.data.type)===ye("FCL::AUTHZ_READY")&&(me(s.data.type,"FCL:VIEW:READY"),n(s,{send:t,close:e})),ye(s.data.type)===ye("FCL::CHALLENGE::CANCEL")&&(me(s.data.type,"FCL:VIEW:CLOSE"),e()),ye(s.data.type)===ye("FCL::CANCEL")&&(me(s.data.type,"FCL:VIEW:CLOSE"),e())}catch(t){console.error("Frame Callback Error",t),e()}},Ee=()=>{},we=()=>{},ve=()=>{},Re=()=>{},Se={"HTTP/RPC":fe,"HTTP/POST":fe,"IFRAME/RPC":function(e,t,n){return new Promise((a,r)=>{var s;const o=D(),i=n.includeOlderJsonRpcCall;t.data=null!=(s=e.data)?s:null,function(e,t={}){if(null==e)return{send:Ee,close:Ee};const n=t.onClose||Ee;window.addEventListener("message",he({close:s,send:o,onReady:t.onReady||Ee,onResponse:t.onResponse||Ee,onMessage:t.onMessage||Ee}));const[a,r]=se(Z(e));return{send:o,close:s};function s(){try{window.removeEventListener("message",he),r(),n()}catch(e){console.error("Frame Close Error",e)}}function o(e){try{a.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}}),a({fclVersion:O,type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&a({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=ee(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;const n=ee(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"POP/RPC":function(e,t,n){return new Promise((a,r)=>{const s=D(),{redir:o,includeOlderJsonRpcCall:i}=n;t.data=e.data,function(e,t={}){if(null==e)return{send:we,close:we};const n=t.onClose||we;window.addEventListener("message",he({close:o,send:i,onReady:t.onReady||we,onResponse:t.onResponse||we,onMessage:t.onMessage||we}));const[a,r]=ce(Z(e)),s=setInterval(function(){a&&a.closed&&o()},500);return{send:i,close:o};function o(){try{window.removeEventListener("message",he),clearInterval(s),r(),n()}catch(e){console.error("Popup Close Error",e)}}function i(e){try{a.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}}),a({fclVersion:O,type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&a({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=ee(e.data);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;const n=ee(e.data.result);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"TAB/RPC":function(e,t,n){return new Promise((a,r)=>{const s=D(),{redir:o,includeOlderJsonRpcCall:i}=n;t.data=e.data,function(e,t={}){if(null==e)return{send:ve,close:ve};const n=t.onClose||ve;window.addEventListener("message",he({close:o,send:i,onReady:t.onReady||ve,onResponse:t.onResponse||ve,onMessage:t.onMessage||ve}));const[a,r]=ue(Z(e)),s=setInterval(function(){a&&a.closed&&o()},500);return{send:i,close:o};function o(){try{window.removeEventListener("message",he),clearInterval(s),r(),n()}catch(e){console.error("Tab Close Error",e)}}function i(e){try{a.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}}),a({fclVersion:O,type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&a({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=ee(e.data);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;const n=ee(e.data.result);switch(n.status){case"APPROVED":a(n.data),!o&&t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;case"REDIRECT":a(n),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"EXT/RPC":function(e,t,n){return new Promise((n,a)=>{!async function(e,t={}){var n;if(null==e)return{send:Re,close:Re};const{endpoint:a}=e,r=t.onClose||Re;window.addEventListener("message",he({close:function(){try{window.removeEventListener("message",he),r()}catch(e){console.error("Extension Close Error",e)}},send:function(e){try{var t;null==(t=window[a])||t.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(t){console.error("Extension Send Error",e,t)}},onReady:t.onReady||Re,onResponse:t.onResponse||Re,onMessage:t.onMessage||Re})),await(null==(n=window[a])?void 0:n.flow.enable())}(e,{async onReady(n,{send:a}){try{a({fclVersion:O,type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data,type:e.type},config:{services:await N(/^service\./),app:await N(/^app\.detail\./)}})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const r=ee(e.data);switch(r.status){case"APPROVED":n(r.data),t();break;case"DECLINED":a(`Declined: ${r.reason||"No reason supplied"}`),t();break;case"REDIRECT":n(r),t();break;default:a("Declined: No reason supplied"),t()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose(){a("Declined: Externally Halted")}})})}};async function be({service:e,msg:t={},opts:n={}}){try{const a=await Se[e.method](e,t,n);return"REDIRECT"===a.status?(f(e.type===a.data.type,"Cannot shift recursive service type in execService"),e=a.data,await be({service:e,msg:t,opts:n})):a}catch(a){throw console.error("execService({service, msg = {}, opts = {}})",a,{service:e,msg:t,opts:n}),a}}async function Ce(e,t){f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),f(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[],r=[];const s=await Promise.all(t.map(async e=>{f("string"==typeof e.addr,"addr must be a string"),f("number"==typeof e.keyId,"keyId must be a number"),f("string"==typeof e.signature,"signature must be a string");try{const t=await t(e.addr);return n.push(t.keys[e.keyId].weight.toFixed(1)),a.push(t.keys[e.keyId].signAlgo),r.push(e.signature),t.keys[e.keyId].publicKey}catch(e){throw e}}));return await U({cadence:`${Pe}`,args:(t,o)=>[t(e,o.String),t(s,o.Array([o.String])),t(n,o.Array(o.UFix64)),t(a,o.Array([o.UInt])),t(r,o.Array([o.String]))]})}const Pe="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function Ae(e){return null==e?null:"1.0.0"===e.f_vsn?e:j({},Y,{addr:P(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}const Ie="CURRENT_USER",De="CURRENT_USER/UPDATED",Le='{\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={[w]:async e=>{"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),e.merge(JSON.parse(Le));const n=await t.first(["fcl.storage","fcl.storage.default"]);if(n.can){const t=await(async e=>{const t=JSON.parse(Le),n=await e.get(Ie);return null!=n&&t.f_vsn!==n.f_vsn?(e.removeItem(Ie),t):n||t})(n);Fe(t)&&e.merge(t)}},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,De,j({},e.all()))},[E]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(j({},e.all()))},SET_CURRENT_USER:async(e,n,a)=>{e.merge(a);const r=await t.first(["fcl.storage","fcl.storage.default"]);r.can&&r.put(Ie,e.all()),e.broadcast(De,j({},e.all()))},DEL_CURRENT_USER:async(e,n)=>{e.merge(JSON.parse(Le));const a=await t.first(["fcl.storage","fcl.storage.default"]);a.can&&a.put(Ie,e.all()),e.broadcast(De,j({},e.all()))}},Oe=()=>g(Ne,Ie);function Fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function ke({service:e,redir:n=!1}){return new Promise(async(a,r)=>{Oe();const s=await Me();if(s.loggedIn&&Fe(s))return a(s);const{discoveryWallet:o,discoveryWalletMethod:i,appDomainTag:c}=await async function(){return{discoveryWallet:await t.first(["discovery.wallet","challenge.handshake"]),discoveryWalletMethod:await t.first(["discovery.wallet.method","discovery.wallet.method.default"]),appDomainTag:await t.get("fcl.appDomainTag")}}();f(e||o,'\n If no service passed to "authenticate," then "discovery.wallet" must be defined in config.\n See: "https://docs.onflow.org/fcl/reference/api/#setting-configuration-values"\n ');const d=await t.get("fcl.warning.suppress.redir");n&&!d&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");try{const t=await be({service:e||{type:"authn",endpoint:o,method:i},msg:{timestamp:Date.now(),appDomainTag:c,extensions:window.fcl_extensions||[]},opts:{redir:n}});m(Ie,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?C(e.addr):null,e.paddr=e.paddr?C(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(j({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(j({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return q[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 j({},H,{addr:C(e.addr),cid:G(n),loggedIn:!0,services:t,expiresAt:e.exp})}(t))}catch(e){console.error("Error while authenticating",e)}finally{a(await Me())}})}function Te(){Oe(),m(Ie,"DEL_CURRENT_USER")}async function xe(e){Oe();const t=await ke({redir:!0}),n=X(t.services,"authz"),a=X(t.services,"pre-authz");return j({},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=>be({service:t,msg:e}),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await be({service:a,msg:t}))}:{tempId:"CURRENT_USER",resolve:null,addr:P(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>Ae(await be({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}}))})}function _e(e){Oe();const t="@EXIT",n=g(async n=>{for(n.send(Ie,h);;){const a=await n.receive();if(a.tag===t)return void n.send(Ie,E);e(a.data)}});return()=>m(n,t)}function Me(){return Oe(),m(Ie,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function Ve(){const{addr:e}=await ke();return n(C(e),y.Address)}const Ue=e=>(f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e});async function je(e){Oe();const t=X((await ke({redir:!0})).services,"user-signature");f(t,"Current user must have authorized a signing service.");try{const n=await be({service:t,msg:Ue(e)});return Array.isArray(n)?n.map(e=>Ae(e)):[Ae(n)]}catch(e){return e}}async function We(e,t){return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Ce(e,t)}let ze=()=>({authenticate:ke,unauthenticate:Te,authorization:xe,signUserMessage:je,verifyUserSignatures:We,subscribe:_e,snapshot:Me,resolveArgument:Ve});ze.authenticate=ke,ze.unauthenticate=Te,ze.authorization=xe,ze.signUserMessage=je,ze.verifyUserSignatures=We,ze.subscribe=_e,ze.snapshot=Me,ze.resolveArgument=Ve;const He=async e=>a([r(e)]).then(s),Be=e=>e.status>=4,Ye=e=>e.status>=3,Je=e=>e.status>=2,$e={[w]:async e=>{const t=await He(e.self());Be(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,S,e.all())},[E]:(e,t)=>{e.unsubscribe(t.from)},[b]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await He(e.self());var n,a;Be(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(S,t),e.merge(t)}},Ke=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},qe=e=>g($e,Ke(e));function Ge(e){function t(t){return v(Ke(e),qe,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 R(e,qe)},subscribe:t,onceFinalized:n(Je),onceExecuted:n(Ye),onceSealed:n(Be)}}async function Xe(t={}){var n;try{await async function(t){f(k(t),"mutate(opts) -- opts is required"),f(T(t),"mutate(opts) -- opts must be an object"),f(k(t.cadence),"mutate({ cadence }) -- cadence is required"),f(x(t.cadence),"mutate({ cadence }) -- cadence must be a string"),f(await e.config.get("accessNode.api"),'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')}(t);const a=await e.config().get("fcl.authz",ze().authorization);return n=e.send([e.transaction(t.cadence),e.args(V(t.args||[])),t.limit&&M(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||a),e.payer(t.payer||t.authz||a),e.authorizations(t.authorizations||[t.authz||a])]).then(e.decode),n}catch(e){throw e}}Ge.isUnknown=e=>e.status>=0,Ge.isPending=e=>e.status>=1,Ge.isFinalized=Je,Ge.isExecuted=Ye,Ge.isSealed=Be,Ge.isExpired=e=>5===e.status;const Ze=async(e=[],n={})=>{const a=await t.first(["sdk.resolve"],n.resolve||o);return Array.isArray(e)&&(e=await i(c(),e)),JSON.stringify(d(await a(e)),null,2)},Qe=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),et={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await l()),e.put("tick",await Qe(e));else{let n=await l();e.put("hwm",n);const r=await a([u(e.self(),t.height,n.height-1)]).then(s);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await Qe(e))}},[h]:async(e,t)=>{e.hasSubs()||e.put("tick",await Qe(e)),e.subscribe(t.from)},[E]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},tt=e=>g(et,e);function nt(e){return{subscribe:t=>v(e,tt,t)}}async function at(e=[]){const n=await t.get("discovery.authn.endpoint");f(Boolean(n),'"discovery.authn.endpoint" in config must be defined.');const a=new URL(n);return fetch(a,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(t=>[...e,...t])}function rt(e=[]){return[...window.fcl_extensions||[],...e]}const st={[w]:async e=>{"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "fcl.discovery" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;");const t=await(({type:e})=>((...e)=>t=>e.reduce((e,t)=>e.then(t),Promise.resolve(t)))(at,rt,t=>function(e=[],t){return e.filter(e=>e.type===t)}(t,e))([]))({type:"authn"});e.put("results",t)},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,"UPDATED",j({},e.all()))},[E]:(e,t)=>e.unsubscribe(t.from),SNAPSHOT:async(e,t)=>t.reply(j({},e.all()))},ot=()=>g(st,"authn"),it={authn:{subscribe:e=>v("authn",ot,e),snapshot:()=>R("authn",ot)}},ct=(e,t=(()=>{}))=>{const n=n=>{const{data:a}=n;"object"==typeof a&&null!=typeof a&&a.type===e&&t((e=>{var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e})(a))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)},dt=(e,t={})=>{window.location!==window.parent.location?window.parent.postMessage(j({},t,{type:e}),"*"):window.opener.postMessage(j({},t,{type:e}),"*")},lt=(e,t)=>Buffer.from(e.padEnd(2*t,0),"hex");var ut={__proto__:null,sendMsgToFCL:dt,ready:(e,t={})=>{ct("FCL:VIEW:READY:RESPONSE",e),dt("FCL:VIEW:READY")},close:()=>{dt("FCL:VIEW:CLOSE")},approve:e=>{dt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:e=>{dt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:e=>{dt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:ct,encodeMessageFromSignable:p,CompositeSignature:function(e,t,n){this.f_type=Y.f_type,this.f_vsn=Y.f_vsn,this.addr=C(e),this.keyId=Number(t),this.signature=n},encodeMessageForProvableAuthnSigning:(e,t,n="")=>{f(e,"Encode Message From Provable Authn Error: address must be defined"),f(t,"Encode Message From Provable Authn Error: timestamp must be defined");const a=lt(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),r=lt(Buffer.from(n).toString("hex"),32).toString("hex");return a+(n?I([r,C(e),t]).toString("hex"):I([C(e),t]).toString("hex"))},encodeMessageForProvableAuthnVerifying:(e,t,n="")=>{f(e,"Encode Message From Provable Authn Error: address must be defined"),f(t,"Encode Message From Provable Authn Error: timestamp must be defined");const a=n?(r=Buffer.from(n).toString("hex"),Buffer.from(r.padEnd(64,0),"hex")).toString("hex"):null;var r;return n?I([a,C(e),t]).toString("hex"):I([C(e),t]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}};const pt=(e={})=>ze().authenticate(e),ft=()=>ze().unauthenticate(),yt=(e={})=>(ze().unauthenticate(),ze().authenticate(e)),gt=(e={})=>ze().authenticate(e),mt=(e={})=>ze().authenticate(e),ht=ze().authorization,Et=y;export{O as VERSION,ut as WalletUtils,pt as authenticate,ht as authz,ze as currentUser,it as discovery,nt as events,mt as logIn,Xe as mutate,U as query,yt as reauthenticate,Ze as serialize,gt as signUp,Et as t,Ge as tx,ft as unauthenticate,Ce as verifyUserSignatures}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"@onflow/sdk";import{config as r,account as n,arg as t,send as o,getTransactionStatus as i,decode as s,resolve as a,createSignableVoucher as c,pipe as u,interaction as l,latestBlock as d,getEvents as f,encodeMessageFromSignable as p}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as v}from"@onflow/util-invariant";import*as h from"@onflow/types";import{INIT as m,SUBSCRIBE as y,UNSUBSCRIBE as g,spawn as E,send as P,UPDATED as R,SNAPSHOT as w,subscriber as b,snapshoter as S}from"@onflow/util-actor";import{withPrefix as C,sansPrefix as A}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as I from"@onflow/rlp";import{encode as D}from"@onflow/rlp";import{uid as L}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";var N=function(e){try{return Promise.resolve(r().where(e)).then(function(r){return Object.fromEntries(Object.entries(r).map(function(r){var n=r[1];return[r[0].replace(e,""),n]}))})}catch(e){return Promise.reject(e)}},O={can:!("undefined"==typeof window),get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,r){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(r)))}catch(e){return Promise.reject(e)}}};r({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":O,"fcl.appDomainTag.default":"APP-V0.0-user"});var k="0.0.78-alpha.6",j=function(e){return function(r){return typeof r===e}},F=function(e){return null!=e},x=j("object"),T=j("string"),_=j("function"),M=j("number");function V(r){return _(r)?r(e.arg,h):[]}var U=function(r){void 0===r&&(r={});try{return Promise.resolve(function(r){try{return v(F(r.cadence),"query({ cadence }) -- cadence is required"),v(T(r.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){v(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(r)).then(function(){return e.send([e.script(r.cadence),e.args(V(r.args||[])),r.limit&&"number"==typeof r.limit&&e.limit(r.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function W(){return W=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},W.apply(this,arguments)}function z(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function H(e,r){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return z(e,r);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)?z(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var Y={f_type:"Service",f_vsn:"1.0.0"},B={f_type:"Identity",f_vsn:"1.0.0"},J={f_type:"USER",f_vsn:"1.0.0"},q={f_type:"PollingResponse",f_vsn:"1.0.0"},K={f_type:"CompositeSignature",f_vsn:"1.0.0"};function G(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({old:e},Y,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function X(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},Y,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function Z(e){return null==e?null:(null==e.method&&(e=W({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:W({},Y,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}var $={"back-channel-rpc":X,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},Y,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:W({},B,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},Y,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:W({},B,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},Y,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:C(e.addr),name:e.name,icon:e.icon}})},frame:G,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":Z,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function Q(e){return I.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function ee(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function re(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,t=Object.entries(e.params||{});n<t.length;n++){var o=t[n];r.searchParams.append(o[0],o[1])}return r}function ne(e,r){void 0===r&&(r={});var n=r.method||"POST",t="GET"===n?void 0:JSON.stringify(r.data||e.data||{});return fetch(re(e),{method:n,headers:W({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function te(e){var r,n;return null==e?null:"1.0.0"===e.f_vsn?e:W({},q,{status:null!=(r=e.status)?r:"APPROVED",reason:null!=(n=e.reason)?n:null,data:e.compositeSignature||e.data||W({},e)||{},updates:X(e.authorizationUpdates),local:G((e.local||[])[0])})}var oe=function e(r,n){void 0===n&&(n=function(){return!0});try{if(v(r,"Missing Polling Service",{service:r}),!n())throw new Error("Externally Halted");return Promise.resolve(ne(r,{method:se(r)}).then(te)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,n)})}})}catch(e){return Promise.reject(e)}},ie={"HTTP/GET":"GET","HTTP/POST":"POST"},se=function(e){return v(ie[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ie[e.method]},ae="FCL_IFRAME";function ce(e){v(!document.getElementById(ae),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=ae,r.allow="usb *; hid *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r.contentWindow,function(){document.getElementById(ae)&&document.getElementById(ae).remove()}]}var ue=null,le=null;function de(e){var r,n;null==ue||null!=(r=ue)&&r.closed?(n=window,ue=n.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top="+(n.top.outerHeight/2+n.top.screenY-385)+", left="+(n.top.outerWidth/2+n.top.screenX-320))):le!==e?(ue.location.replace(e),ue.focus()):ue.focus(),le=e;var t=setInterval(function(){ue&&ue.closed&&(clearInterval(t),ue=null)},1e3);return[ue,function(){ue&&!ue.closed&&(ue.close(),ue=null)}]}var fe=null,pe=null;function ve(e){var r;null==fe||null!=(r=fe)&&r.closed?fe=window.open(e,"_blank"):pe!==e?(fe.location.replace(e),fe.focus()):fe.focus(),pe=e;var n=setInterval(function(){fe&&fe.closed&&(clearInterval(n),fe=null)},1e3);return[fe,function(){fe&&!fe.closed&&(fe.close(),fe=null)}]}var he,me={"VIEW/IFRAME":ce,"VIEW/POP":de,"VIEW/TAB":ve},ye=function(e,r,n){try{var t={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(n){return Promise.resolve(N(/^app\.detail\./)).then(function(o){return Promise.resolve(ne(e,{data:W({fclVersion:k,service:t,config:{services:n,app:o}},r)}).then(te)).then(function(r){if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("REDIRECT"===r.status)return r;if("PENDING"===r.status){var n=!0;return Promise.resolve(function(e,r){void 0===r&&(r={});try{try{return Promise.resolve(me[e.method](re(e),r))}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:r}),n}}catch(e){return Promise.reject(e)}}(Z(r.local))).then(function(e){var t=e[1],o=function(){try{t(),n=!1}catch(e){console.error("Frame Close Error",e)}};return oe(r.updates,function(){return n}).then(function(e){return o(),e}).catch(function(e){throw console.error(e),o(),e})})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")})})})}catch(e){return Promise.reject(e)}},ge=function(e){return"string"==typeof e&&e.toLowerCase()},Ee=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Pe=function(e,r){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+r+" for this and future versions of FCL")},Re=function(e){var r=e.close,n=e.send,t=e.onReady,o=e.onResponse,i=e.onMessage;return function(e){try{if("object"!=typeof e.data)return;if(Ee.has(e.data.type))return;ge(e.data.type)===ge("FCL:VIEW:CLOSE")&&r(),ge(e.data.type)===ge("FCL:VIEW:READY")&&t(e,{send:n,close:r}),ge(e.data.type)===ge("FCL:VIEW:RESPONSE")&&o(e,{send:n,close:r}),i(e,{send:n,close:r}),ge(e.data.type)===ge("FCL:FRAME:READY")&&(Pe(e.data.type,"FCL:VIEW:READY"),t(e,{send:n,close:r})),ge(e.data.type)===ge("FCL:FRAME:RESPONSE")&&(Pe(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:n,close:r})),ge(e.data.type)===ge("FCL:FRAME:CLOSE")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),r()),ge(e.data.type)===ge("FCL::CHALLENGE::RESPONSE")&&(Pe(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:n,close:r})),ge(e.data.type)===ge("FCL::AUTHZ_READY")&&(Pe(e.data.type,"FCL:VIEW:READY"),t(e,{send:n,close:r})),ge(e.data.type)===ge("FCL::CHALLENGE::CANCEL")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),r()),ge(e.data.type)===ge("FCL::CANCEL")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),r())}catch(e){console.error("Frame Callback Error",e),r()}}},we=function(){},be=function(){},Se=function(){},Ce=function(){},Ae=function e(r){var n=r.service,t=r.msg,o=void 0===t?{}:t,i=r.opts,s=void 0===i?{}:i;try{return Promise.resolve(function(r,t){try{var i=Promise.resolve(Ie[n.method](n,o,s)).then(function(r){return"REDIRECT"===r.status?(v(n.type===r.data.type,"Cannot shift recursive service type in execService"),n=r.data,Promise.resolve(e({service:n,msg:o,opts:s}))):r})}catch(e){return t(e)}return i&&i.then?i.then(void 0,t):i}(0,function(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:n,msg:o,opts:s}),e}))}catch(e){return Promise.reject(e)}},Ie={"HTTP/RPC":ye,"HTTP/POST":ye,"IFRAME/RPC":function(e,r,n){return new Promise(function(t,o){var i,s=L(),a=n.includeOlderJsonRpcCall;r.data=null!=(i=e.data)?i:null,function(e,r){if(void 0===r&&(r={}),null==e)return{send:we,close:we};var n=r.onClose||we;window.addEventListener("message",Re({close:s,send:a,onReady:r.onReady||we,onResponse:r.onResponse||we,onMessage:r.onMessage||we}));var t=ce(re(e)),o=t[0],i=t[1];return{send:a,close:s};function s(){try{window.removeEventListener("message",Re),i(),n()}catch(e){console.error("Frame Close Error",e)}}function a(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(t){return Promise.resolve(N(/^app\.detail\./)).then(function(i){o({fclVersion:k,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:t,app:i}});var c={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(n){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:k,type:"FCL:FRAME:READY:RESPONSE",body:r,service:c,config:{services:n,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),a&&o({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[r,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":t(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;var i=te(e.data.result);switch(i.status){case"APPROVED":t(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"POP/RPC":function(e,r,n){return new Promise(function(t,o){var i=L(),s=n.redir,a=n.includeOlderJsonRpcCall;r.data=e.data,function(e,r){if(void 0===r&&(r={}),null==e)return{send:be,close:be};var n=r.onClose||be;window.addEventListener("message",Re({close:s,send:a,onReady:r.onReady||be,onResponse:r.onResponse||be,onMessage:r.onMessage||be}));var t=de(re(e)),o=t[0],i=t[1];return{send:a,close:s};function s(){try{window.removeEventListener("message",Re),i(),n()}catch(e){console.error("Popup Close Error",e)}}function a(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Popup Send Error",e,r)}}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(t){return Promise.resolve(N(/^app\.detail\./)).then(function(s){o({fclVersion:k,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:t,app:s}});var c={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(n){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:k,type:"FCL:FRAME:READY:RESPONSE",body:r,service:c,config:{services:n,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[r,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=te(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),n();break;case"REDIRECT":t(a),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"TAB/RPC":function(e,r,n){return new Promise(function(t,o){var i=L(),s=n.redir,a=n.includeOlderJsonRpcCall;r.data=e.data,function(e,r){if(void 0===r&&(r={}),null==e)return{send:Se,close:Se};var n=r.onClose||Se;window.addEventListener("message",Re({close:s,send:a,onReady:r.onReady||Se,onResponse:r.onResponse||Se,onMessage:r.onMessage||Se}));var t=ve(re(e)),o=t[0],i=t[1];return{send:a,close:s};function s(){try{window.removeEventListener("message",Re),i(),n()}catch(e){console.error("Tab Close Error",e)}}function a(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Tab Send Error",e,r)}}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(t){return Promise.resolve(N(/^app\.detail\./)).then(function(s){o({fclVersion:k,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:t,app:s}});var c={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(n){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:k,type:"FCL:FRAME:READY:RESPONSE",body:r,service:c,config:{services:n,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[r,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;case"REDIRECT":t(i),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,r){var n=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=te(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),n();break;case"REDIRECT":t(a),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"EXT/RPC":function(e,r,n){return new Promise(function(n,t){!function(e,r){void 0===r&&(r={});try{var n,t=function(){try{window.removeEventListener("message",Re),s()}catch(e){console.error("Extension Close Error",e)}},o=function(e){try{var r;null==(r=window[i])||r.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(r){console.error("Extension Send Error",e,r)}};if(null==e)return Promise.resolve({send:Ce,close:Ce});var i=e.endpoint,s=r.onClose||Ce;window.addEventListener("message",Re({close:t,send:o,onReady:r.onReady||Ce,onResponse:r.onResponse||Ce,onMessage:r.onMessage||Ce})),Promise.resolve(null==(n=window[i])?void 0:n.flow.enable()).then(function(){return{send:o,close:t}})}catch(e){return Promise.reject(e)}}(e,{onReady:function(n,t){var o=t.send;try{return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){var n={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(e){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:k,type:"FCL:VIEW:READY:RESPONSE",body:r,service:n,config:{services:e,app:t}})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var o=r.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":n(i.data),o();break;case"DECLINED":t("Declined: "+(i.reason||"No reason supplied")),o();break;case"REDIRECT":n(i),o();break;default:t("Declined: No reason supplied"),o()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose:function(){t("Declined: Externally Halted")}})})}},De=function(e,r){try{v(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),v(Array.isArray(r),"Must include an Array of composite signatures");var t=[],o=[],i=[];return Promise.resolve(Promise.all(r.map(function(e){try{return v("string"==typeof e.addr,"addr must be a string"),v("number"==typeof e.keyId,"keyId must be a number"),v("string"==typeof e.signature,"signature must be a string"),Promise.resolve(function(r,s){try{var a=Promise.resolve(n(e.addr)).then(function(r){return t.push(r.keys[e.keyId].weight.toFixed(1)),o.push(r.keys[e.keyId].signAlgo),i.push(e.signature),r.keys[e.keyId].publicKey})}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(r){return Promise.resolve(U({cadence:""+Le,args:function(n,s){return[n(e,s.String),n(r,s.Array([s.String])),n(t,s.Array(s.UFix64)),n(o,s.Array([s.UInt])),n(i,s.Array([s.String]))]}}))})}catch(e){return Promise.reject(e)}},Le="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function Ne(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},K,{addr:A(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}function Oe(e,r,n){if(!e.s){if(n instanceof Te){if(!n.s)return void(n.o=Oe.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Oe.bind(null,e,r),Oe.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var ke=function(e,r){try{return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Promise.resolve(De(e,r))}catch(e){return Promise.reject(e)}},je=function(e){try{return Be(),Promise.resolve(Me({redir:!0})).then(function(r){var n=ee(r.services,"user-signature");return v(n,"Current user must have authorized a signing service."),Ve(function(){return Promise.resolve(Ae({service:n,msg:$e(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Ne(e)}):[Ne(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},Fe=function(){try{return Promise.resolve(Me()).then(function(e){return t(C(e.addr),h.Address)})}catch(e){return Promise.reject(e)}},xe=function(e){try{return Be(),Promise.resolve(Me({redir:!0})).then(function(r){var n=ee(r.services,"authz"),t=ee(r.services,"pre-authz");return W({},e,t?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(Ae({service:t,msg:r})).then(Ke)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:A(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Ae({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(Ne)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Te=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Oe(t,1,i(this.v))}catch(e){Oe(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Oe(t,1,r?r(o):o):n?Oe(t,1,n(o)):Oe(t,2,o)}catch(e){Oe(t,2,e)}},t},e}();function _e(e){return e instanceof Te&&1&e.s}var Me=function(e){void 0===e&&(e={redir:!1});try{return Promise.resolve(new Promise(function(n,t){try{return Be(),Promise.resolve(Xe()).then(function(t){return t.loggedIn&&Je(t)?n(t):Promise.resolve(function(){try{return Promise.resolve(r.first(["discovery.wallet","challenge.handshake"])).then(function(e){return Promise.resolve(r.first(["discovery.wallet.method","discovery.wallet.method.default"])).then(function(n){return Promise.resolve(r.first(["fcl.appDomainTag","fcl.appDomainTag.default"])).then(function(r){return v(null!=e,'\n Required value for discovery.wallet not defined in config.\n See: "https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration"\n '),{discoveryWallet:e,discoveryWalletMethod:n,appDomainTag:r}})})})}catch(e){return Promise.reject(e)}}()).then(function(t){var o=t.discoveryWallet,i=t.discoveryWalletMethod,s=t.appDomainTag;return Promise.resolve(r.get("fcl.warning.suppress.redir")).then(function(r){e.redir&&!r&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");var t=function(r,n){try{var t=Ve(function(){return Promise.resolve(Ae({service:{type:"authn",endpoint:o,method:i},msg:{timestamp:Date.now(),appDomainTag:s,extensions:window.fcl_extensions||[]},opts:e})).then(function(e){return Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?C(e.addr):null,e.paddr=e.paddr?C(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=H(e.authorizations);!(n=t()).done;)r.push(W({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(W({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,o,i=(t=r,o=n,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(r){return function(e,r){try{return $[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),s=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,i);return W({},J,{addr:C(e.addr),cid:Q(s),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){P(Ue,ze,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return n(!0,e)}return t&&t.then?t.then(n.bind(null,!1),n.bind(null,!0)):n(!1,t)}(0,function(e,r){return Promise.resolve(Xe()).then(function(t){if(n(t),e)throw r;return r})});if(t&&t.then)return t.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Ve(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}var Ue="CURRENT_USER",We="CURRENT_USER/UPDATED",ze="SET_CURRENT_USER",He='{\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}',Ye=((he={})[m]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),e.merge(JSON.parse(He)),Promise.resolve(r.first(["fcl.storage","fcl.storage.default"])).then(function(r){var n=function(){if(r.can)return Promise.resolve(function(e){try{var r=JSON.parse(He);return Promise.resolve(e.get(Ue)).then(function(n){return null!=n&&r.f_vsn!==n.f_vsn?(e.removeItem(Ue),r):n||r})}catch(e){return Promise.reject(e)}}(r)).then(function(r){Je(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},he[y]=function(e,r){e.subscribe(r.from),e.send(r.from,We,W({},e.all()))},he[g]=function(e,r){e.unsubscribe(r.from)},he.SNAPSHOT=function(e,r){try{return r.reply(W({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},he[ze]=function(e,n,t){try{return e.merge(t),Promise.resolve(r.first(["fcl.storage","fcl.storage.default"])).then(function(r){r.can&&r.put(Ue,e.all()),e.broadcast(We,W({},e.all()))})}catch(e){return Promise.reject(e)}},he.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(He)),Promise.resolve(r.first(["fcl.storage","fcl.storage.default"])).then(function(r){r.can&&r.put(Ue,e.all()),e.broadcast(We,W({},e.all()))})}catch(e){return Promise.reject(e)}},he),Be=function(){return E(Ye,Ue)};function Je(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function qe(){Be(),P(Ue,"DEL_CURRENT_USER")}function Ke(e){var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=r.proposer&&n.push(["PROPOSER",r.proposer]);for(var t,o=H(r.payer||[]);!(t=o()).done;)n.push(["PAYER",t.value]);for(var i,s=H(r.authorization||[]);!(i=s()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var r=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return Ae({service:n,msg:e})},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}})}function Ge(e){Be();var r="@EXIT",n=E(function(n){try{var t;return n.send(Ue,y),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(_e(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!_e(i)){t=1;break}i=i.s}}var s=new Te,a=Oe.bind(null,s,2);return(0===t?o.then(u):1===t?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(u).then(void 0,a):u(o):Oe(s,1,i)})).then(void 0,a),s;function c(r){i=r;do{if(!(o=e())||_e(o)&&!o.v)return void Oe(s,1,i);if(o.then)return void o.then(u).then(void 0,a);_e(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function u(e){e?(i=n())&&i.then?i.then(c).then(void 0,a):c(i):Oe(s,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if(o.tag===r)return n.send(Ue,g),void(t=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return P(n,r)}}function Xe(){return Be(),P(Ue,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ze,$e=function(e){return v(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Qe=function(){return{authenticate:Me,unauthenticate:qe,authorization:xe,signUserMessage:je,verifyUserSignatures:ke,subscribe:Ge,snapshot:Xe,resolveArgument:Fe}};Qe.authenticate=Me,Qe.unauthenticate=qe,Qe.authorization=xe,Qe.signUserMessage=je,Qe.verifyUserSignatures=ke,Qe.subscribe=Ge,Qe.snapshot=Xe,Qe.resolveArgument=Fe;var er=function(e){try{return Promise.resolve(o([i(e)]).then(s))}catch(e){return Promise.reject(e)}},rr=function(e){return e.status>=4},nr=function(e){return e.status>=3},tr=function(e){return e.status>=2},or=((Ze={})[m]=function(e){try{return Promise.resolve(er(e.self())).then(function(r){rr(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},Ze[y]=function(e,r){e.subscribe(r.from),e.send(r.from,R,e.all())},Ze[g]=function(e,r){e.unsubscribe(r.from)},Ze[w]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Ze.POLL=function(e){try{return Promise.resolve(er(e.self())).then(function(r){var n,t;rr(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(R,r),e.merge(r)})}catch(e){return Promise.reject(e)}},Ze),ir=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},sr=function(e){return E(or,ir(e))};function ar(e){function r(r){return b(ir(e),sr,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return S(e,sr)},subscribe:r,onceFinalized:n(tr),onceExecuted:n(nr),onceSealed:n(rr)}}ar.isUnknown=function(e){return e.status>=0},ar.isPending=function(e){return e.status>=1},ar.isFinalized=tr,ar.isExecuted=nr,ar.isSealed=rr,ar.isExpired=function(e){return 5===e.status};var cr,ur=function(r){void 0===r&&(r={});try{return Promise.resolve(function(n,t){try{var o=Promise.resolve(function(r){try{return v(F(r),"mutate(opts) -- opts is required"),v(x(r),"mutate(opts) -- opts must be an object"),v(F(r.cadence),"mutate({ cadence }) -- cadence is required"),v(T(r.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){v(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(r)).then(function(){return Promise.resolve(e.config().get("fcl.authz",Qe().authorization)).then(function(n){return e.send([e.transaction(r.cadence),e.args(V(r.args||[])),r.limit&&M(r.limit)&&e.limit(r.limit),e.proposer(r.proposer||r.authz||n),e.payer(r.payer||r.authz||n),e.authorizations(r.authorizations||[r.authz||n])]).then(e.decode)})})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},lr=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Promise.resolve(r.first(["sdk.resolve"],n.resolve||a)).then(function(r){function n(){return Promise.resolve(r(e)).then(function(e){return JSON.stringify(c(e),null,2)})}var t=function(){if(Array.isArray(e))return Promise.resolve(u(l(),e)).then(function(r){e=r})}();return t&&t.then?t.then(n):n()})}catch(e){return Promise.reject(e)}},dr=function(e){try{var n=setTimeout;return Promise.resolve(r().get("fcl.eventPollRate",1e4)).then(function(r){return n(function(){return e.sendSelf("TICK")},r)})}catch(e){return Promise.reject(e)}},fr=((cr={}).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(d()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(dr(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(d()).then(function(n){return e.put("hwm",n),Promise.resolve(o([f(e.self(),r.height,n.height-1)]).then(s)).then(function(r){for(var n,t=H(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(dr(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},cr[y]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(dr(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},cr[g]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},cr),pr=function(e){return E(fr,e)};function vr(e){return{subscribe:function(r){return b(e,pr,r)}}}var hr=function(e,r){void 0===r&&(r=function(){});var n=function(n){var t=n.data;"object"==typeof t&&null!=typeof t&&t.type===e&&r(function(e){var r;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(r=e.body)||delete r.interaction,e}(t))};return window.addEventListener("message",n),function(){return window.removeEventListener("message",n)}},mr=function(e,r){void 0===r&&(r={}),window.location!==window.parent.location?window.parent.postMessage(W({},r,{type:e}),"*"):window.opener.postMessage(W({},r,{type:e}),"*")},yr=function(e,r){return Buffer.from(e.padEnd(2*r,0),"hex")},gr={__proto__:null,sendMsgToFCL:mr,ready:function(e,r){hr("FCL:VIEW:READY:RESPONSE",e),mr("FCL:VIEW:READY")},close:function(){mr("FCL:VIEW:CLOSE")},approve:function(e){mr("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){mr("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:function(e){mr("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:hr,encodeMessageFromSignable:p,CompositeSignature:function(e,r,n){this.f_type=K.f_type,this.f_vsn=K.f_vsn,this.addr=C(e),this.keyId=Number(r),this.signature=n},encodeMessageForProvableAuthnSigning:function(e,r,n){void 0===n&&(n=""),v(e,"Encode Message From Provable Authn Error: address must be defined"),v(r,"Encode Message From Provable Authn Error: timestamp must be defined");var t=yr(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),o=yr(Buffer.from(n).toString("hex"),32).toString("hex");return t+(n?D([o,C(e),r]).toString("hex"):D([C(e),r]).toString("hex"))},encodeMessageForProvableAuthnVerifying:function(e,r,n){void 0===n&&(n=""),v(e,"Encode Message From Provable Authn Error: address must be defined"),v(r,"Encode Message From Provable Authn Error: timestamp must be defined");var t,o=n?(t=Buffer.from(n).toString("hex"),Buffer.from(t.padEnd(64,0),"hex")).toString("hex"):null;return n?D([o,C(e),r]).toString("hex"):D([C(e),r]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}},Er=function(){return Qe().authenticate()},Pr=function(){return Qe().unauthenticate()},Rr=function(){return Qe().unauthenticate(),Qe().authenticate()},wr=function(){return Qe().authenticate()},br=function(){return Qe().authenticate()},Sr=Qe().authorization,Cr=h;export{k as VERSION,gr as WalletUtils,Er as authenticate,Sr as authz,Qe as currentUser,vr as events,br as logIn,ur as mutate,U as query,Rr as reauthenticate,lr as serialize,wr as signUp,Cr as t,ar as tx,Pr as unauthenticate,De as verifyUserSignatures}; | ||
import*as e from"@onflow/sdk";import{config as n,account as r,arg as t,send as o,getTransactionStatus as i,decode as s,resolve as a,createSignableVoucher as c,pipe as u,interaction as l,latestBlock as d,getEvents as f,encodeMessageFromSignable as p}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as v}from"@onflow/util-invariant";import*as h from"@onflow/types";import{INIT as m,SUBSCRIBE as y,UNSUBSCRIBE as g,spawn as E,send as P,UPDATED as w,SNAPSHOT as R,subscriber as b,snapshoter as S}from"@onflow/util-actor";import{withPrefix as C,sansPrefix as A}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as I from"@onflow/rlp";import{encode as D}from"@onflow/rlp";import{uid as L}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";var N=function(e){try{return Promise.resolve(n().where(e)).then(function(n){return Object.fromEntries(Object.entries(n).map(function(n){var r=n[1];return[n[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}},O={can:!("undefined"==typeof window),get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,n){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(n)))}catch(e){return Promise.reject(e)}}};n({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":O});var j="0.0.78-alpha.7",k=function(e){return function(n){return typeof n===e}},F=function(e){return null!=e},x=k("object"),T=k("string"),_=k("function"),M=k("number");function V(n){return _(n)?n(e.arg,h):[]}var U=function(n){void 0===n&&(n={});try{return Promise.resolve(function(n){try{return v(F(n.cadence),"query({ cadence }) -- cadence is required"),v(T(n.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){v(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(n)).then(function(){return e.send([e.script(n.cadence),e.args(V(n.args||[])),n.limit&&"number"==typeof n.limit&&e.limit(n.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function W(){return W=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},W.apply(this,arguments)}function z(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function H(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return z(e,n);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)?z(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var B={f_type:"Service",f_vsn:"1.0.0"},Y={f_type:"Identity",f_vsn:"1.0.0"},J={f_type:"USER",f_vsn:"1.0.0"},K={f_type:"PollingResponse",f_vsn:"1.0.0"},q={f_type:"CompositeSignature",f_vsn:"1.0.0"};function G(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({old:e},B,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function X(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},B,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function Z(e){return null==e?null:(null==e.method&&(e=W({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:W({},B,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}var $={"back-channel-rpc":X,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},B,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:W({},Y,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},B,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:W({},Y,{address:C(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},B,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:C(e.addr),name:e.name,icon:e.icon}})},frame:G,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":Z,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function Q(e){return I.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function ee(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function ne(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function re(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(ne(e),{method:r,headers:W({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function te(e){var n,r;return null==e?null:"1.0.0"===e.f_vsn?e:W({},K,{status:null!=(n=e.status)?n:"APPROVED",reason:null!=(r=e.reason)?r:null,data:e.compositeSignature||e.data||W({},e)||{},updates:X(e.authorizationUpdates),local:G((e.local||[])[0])})}var oe=function e(n,r){void 0===r&&(r=function(){return!0});try{if(v(n,"Missing Polling Service",{service:n}),!r())throw new Error("Externally Halted");return Promise.resolve(re(n,{method:se(n)}).then(te)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,r)})}})}catch(e){return Promise.reject(e)}},ie={"HTTP/GET":"GET","HTTP/POST":"POST"},se=function(e){return v(ie[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ie[e.method]},ae="FCL_IFRAME";function ce(e){v(!document.getElementById(ae),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=ae,n.allow="usb *; hid *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n.contentWindow,function(){document.getElementById(ae)&&document.getElementById(ae).remove()}]}var ue=null,le=null;function de(e){var n,r;return null==ue||null!=(n=ue)&&n.closed?(r=window,ue=r.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top="+(r.top.outerHeight/2+r.top.screenY-385)+", left="+(r.top.outerWidth/2+r.top.screenX-320))):le!==e?(ue.location.replace(e),ue.focus()):ue.focus(),le=e,[ue,function(){ue&&!ue.closed&&ue.close(),ue=null}]}var fe=null,pe=null;function ve(e){var n;return null==fe||null!=(n=fe)&&n.closed?fe=window.open(e,"_blank"):pe!==e?(fe.location.replace(e),fe.focus()):fe.focus(),pe=e,[fe,function(){fe&&!fe.closed&&fe.close(),fe=null}]}var he,me={"VIEW/IFRAME":ce,"VIEW/POP":de,"VIEW/TAB":ve},ye=function(e,n,r){try{var t={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(r){return Promise.resolve(N(/^app\.detail\./)).then(function(o){return Promise.resolve(re(e,{data:W({fclVersion:j,service:t,config:{services:r,app:o}},n)}).then(te)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("REDIRECT"===n.status)return n;if("PENDING"===n.status){var r=!0;return Promise.resolve(function(e,n){void 0===n&&(n={});try{try{return Promise.resolve(me[e.method](ne(e),n))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:n}),r}}catch(e){return Promise.reject(e)}}(Z(n.local))).then(function(e){var t=e[1],o=function(){try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return oe(n.updates,function(){return r}).then(function(e){return o(),e}).catch(function(e){throw console.error(e),o(),e})})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})})})}catch(e){return Promise.reject(e)}},ge=function(e){return"string"==typeof e&&e.toLowerCase()},Ee=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Pe=function(e,n){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+n+" for this and future versions of FCL")},we=function(e){var n=e.close,r=e.send,t=e.onReady,o=e.onResponse,i=e.onMessage;return function(e){try{if("object"!=typeof e.data)return;if(Ee.has(e.data.type))return;ge(e.data.type)===ge("FCL:VIEW:CLOSE")&&n(),ge(e.data.type)===ge("FCL:VIEW:READY")&&t(e,{send:r,close:n}),ge(e.data.type)===ge("FCL:VIEW:RESPONSE")&&o(e,{send:r,close:n}),i(e,{send:r,close:n}),ge(e.data.type)===ge("FCL:FRAME:READY")&&(Pe(e.data.type,"FCL:VIEW:READY"),t(e,{send:r,close:n})),ge(e.data.type)===ge("FCL:FRAME:RESPONSE")&&(Pe(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:r,close:n})),ge(e.data.type)===ge("FCL:FRAME:CLOSE")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),n()),ge(e.data.type)===ge("FCL::CHALLENGE::RESPONSE")&&(Pe(e.data.type,"FCL:VIEW:RESPONSE"),o(e,{send:r,close:n})),ge(e.data.type)===ge("FCL::AUTHZ_READY")&&(Pe(e.data.type,"FCL:VIEW:READY"),t(e,{send:r,close:n})),ge(e.data.type)===ge("FCL::CHALLENGE::CANCEL")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),n()),ge(e.data.type)===ge("FCL::CANCEL")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),n())}catch(e){console.error("Frame Callback Error",e),n()}}},Re=function(){},be=function(){},Se=function(){},Ce=function(){},Ae=function e(n){var r=n.service,t=n.msg,o=void 0===t?{}:t,i=n.opts,s=void 0===i?{}:i;try{return Promise.resolve(function(n,t){try{var i=Promise.resolve(Ie[r.method](r,o,s)).then(function(n){return"REDIRECT"===n.status?(v(r.type===n.data.type,"Cannot shift recursive service type in execService"),r=n.data,Promise.resolve(e({service:r,msg:o,opts:s}))):n})}catch(e){return t(e)}return i&&i.then?i.then(void 0,t):i}(0,function(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:r,msg:o,opts:s}),e}))}catch(e){return Promise.reject(e)}},Ie={"HTTP/RPC":ye,"HTTP/POST":ye,"IFRAME/RPC":function(e,n,r){return new Promise(function(t,o){var i,s=L(),a=r.includeOlderJsonRpcCall;n.data=null!=(i=e.data)?i:null,function(e,n){if(void 0===n&&(n={}),null==e)return{send:Re,close:Re};var r=n.onClose||Re;window.addEventListener("message",we({close:s,send:a,onReady:n.onReady||Re,onResponse:n.onResponse||Re,onMessage:n.onMessage||Re}));var t=ce(ne(e)),o=t[0],i=t[1];return{send:a,close:s};function s(){try{window.removeEventListener("message",we),i(),r()}catch(e){console.error("Frame Close Error",e)}}function a(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(t){return Promise.resolve(N(/^app\.detail\./)).then(function(i){o({fclVersion:j,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:i}});var c={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(r){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:j,type:"FCL:FRAME:READY:RESPONSE",body:n,service:c,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),a&&o({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[n,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;var i=te(e.data.result);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"POP/RPC":function(e,n,r){return new Promise(function(t,o){var i=L(),s=r.redir,a=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:be,close:be};var r=n.onClose||be;window.addEventListener("message",we({close:a,send:c,onReady:n.onReady||be,onResponse:n.onResponse||be,onMessage:n.onMessage||be}));var t=de(ne(e)),o=t[0],i=t[1],s=setInterval(function(){o&&o.closed&&a()},500);return{send:c,close:a};function a(){try{window.removeEventListener("message",we),clearInterval(s),i(),r()}catch(e){console.error("Popup Close Error",e)}}function c(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Popup Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(t){return Promise.resolve(N(/^app\.detail\./)).then(function(s){o({fclVersion:j,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:s}});var c={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(r){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:j,type:"FCL:FRAME:READY:RESPONSE",body:n,service:c,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=te(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;case"REDIRECT":t(a),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"TAB/RPC":function(e,n,r){return new Promise(function(t,o){var i=L(),s=r.redir,a=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:Se,close:Se};var r=n.onClose||Se;window.addEventListener("message",we({close:a,send:c,onReady:n.onReady||Se,onResponse:n.onResponse||Se,onMessage:n.onMessage||Se}));var t=ve(ne(e)),o=t[0],i=t[1],s=setInterval(function(){o&&o.closed&&a()},500);return{send:c,close:a};function a(){try{window.removeEventListener("message",we),clearInterval(s),i(),r()}catch(e){console.error("Tab Close Error",e)}}function c(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Tab Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(t){return Promise.resolve(N(/^app\.detail\./)).then(function(s){o({fclVersion:j,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:s}});var c={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(r){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:j,type:"FCL:FRAME:READY:RESPONSE",body:n,service:c,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":t(i.data),!s&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=te(e.data.result);switch(a.status){case"APPROVED":t(a.data),!s&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;case"REDIRECT":t(a),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"EXT/RPC":function(e,n,r){return new Promise(function(r,t){!function(e,n){void 0===n&&(n={});try{var r,t=function(){try{window.removeEventListener("message",we),s()}catch(e){console.error("Extension Close Error",e)}},o=function(e){try{var n;null==(n=window[i])||n.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(n){console.error("Extension Send Error",e,n)}};if(null==e)return Promise.resolve({send:Ce,close:Ce});var i=e.endpoint,s=n.onClose||Ce;window.addEventListener("message",we({close:t,send:o,onReady:n.onReady||Ce,onResponse:n.onResponse||Ce,onMessage:n.onMessage||Ce})),Promise.resolve(null==(r=window[i])?void 0:r.flow.enable()).then(function(){return{send:o,close:t}})}catch(e){return Promise.reject(e)}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(N(/^service\./)).then(function(e){return Promise.resolve(N(/^app\.detail\./)).then(function(t){o({fclVersion:j,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:e,app:t}})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var o=n.close;try{if("object"!=typeof e.data)return;var i=te(e.data);switch(i.status){case"APPROVED":r(i.data),o();break;case"DECLINED":t("Declined: "+(i.reason||"No reason supplied")),o();break;case"REDIRECT":r(i),o();break;default:t("Declined: No reason supplied"),o()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose:function(){t("Declined: Externally Halted")}})})}},De=function(e,n){try{v(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),v(Array.isArray(n),"Must include an Array of composite signatures");var t=[],o=[],i=[];return Promise.resolve(Promise.all(n.map(function(e){try{return v("string"==typeof e.addr,"addr must be a string"),v("number"==typeof e.keyId,"keyId must be a number"),v("string"==typeof e.signature,"signature must be a string"),Promise.resolve(function(n,s){try{var a=Promise.resolve(r(e.addr)).then(function(n){return t.push(n.keys[e.keyId].weight.toFixed(1)),o.push(n.keys[e.keyId].signAlgo),i.push(e.signature),n.keys[e.keyId].publicKey})}catch(e){return s(e)}return a&&a.then?a.then(void 0,s):a}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(n){return Promise.resolve(U({cadence:""+Le,args:function(r,s){return[r(e,s.String),r(n,s.Array([s.String])),r(t,s.Array(s.UFix64)),r(o,s.Array([s.UInt])),r(i,s.Array([s.String]))]}}))})}catch(e){return Promise.reject(e)}},Le="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function Ne(e){return null==e?null:"1.0.0"===e.f_vsn?e:W({},q,{addr:A(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}function Oe(e,n,r){if(!e.s){if(r instanceof Te){if(!r.s)return void(r.o=Oe.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Oe.bind(null,e,n),Oe.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var je=function(e,n){try{return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Promise.resolve(De(e,n))}catch(e){return Promise.reject(e)}},ke=function(e){try{return Ye(),Promise.resolve(Me({redir:!0})).then(function(n){var r=ee(n.services,"user-signature");return v(r,"Current user must have authorized a signing service."),Ve(function(){return Promise.resolve(Ae({service:r,msg:$e(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Ne(e)}):[Ne(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},Fe=function(){try{return Promise.resolve(Me()).then(function(e){return t(C(e.addr),h.Address)})}catch(e){return Promise.reject(e)}},xe=function(e){try{return Ye(),Promise.resolve(Me({redir:!0})).then(function(n){var r=ee(n.services,"authz"),t=ee(n.services,"pre-authz");return W({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(Ae({service:t,msg:n})).then(qe)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:A(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Ae({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(Ne)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Te=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{Oe(t,1,i(this.v))}catch(e){Oe(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Oe(t,1,n?n(o):o):r?Oe(t,1,r(o)):Oe(t,2,o)}catch(e){Oe(t,2,e)}},t},e}();function _e(e){return e instanceof Te&&1&e.s}var Me=function(e){var r=e.service,t=e.redir,o=void 0!==t&&t;try{return Promise.resolve(new Promise(function(e,t){try{return Ye(),Promise.resolve(Xe()).then(function(t){return t.loggedIn&&Je(t)?e(t):Promise.resolve(function(){try{return Promise.resolve(n.first(["discovery.wallet","challenge.handshake"])).then(function(e){return Promise.resolve(n.first(["discovery.wallet.method","discovery.wallet.method.default"])).then(function(r){return Promise.resolve(n.get("fcl.appDomainTag")).then(function(n){return{discoveryWallet:e,discoveryWalletMethod:r,appDomainTag:n}})})})}catch(e){return Promise.reject(e)}}()).then(function(t){var i=t.discoveryWallet,s=t.discoveryWalletMethod,a=t.appDomainTag;return v(r||i,'\n If no service passed to "authenticate," then "discovery.wallet" must be defined in config.\n See: "https://docs.onflow.org/fcl/reference/api/#setting-configuration-values"\n '),Promise.resolve(n.get("fcl.warning.suppress.redir")).then(function(n){o&&!n&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");var t=function(e,n){try{var t=Ve(function(){return Promise.resolve(Ae({service:r||{type:"authn",endpoint:i,method:s},msg:{timestamp:Date.now(),appDomainTag:a,extensions:window.fcl_extensions||[]},opts:{redir:o}})).then(function(e){return Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?C(e.addr):null,e.paddr=e.paddr?C(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=H(e.authorizations);!(r=t()).done;)n.push(W({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(W({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,i=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return $[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),s=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,i);return W({},J,{addr:C(e.addr),cid:Q(s),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){P(Ue,ze,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return n(!0,e)}return t&&t.then?t.then(n.bind(null,!1),n.bind(null,!0)):n(!1,t)}(0,function(n,r){return Promise.resolve(Xe()).then(function(t){if(e(t),n)throw r;return r})});if(t&&t.then)return t.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Ve(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var Ue="CURRENT_USER",We="CURRENT_USER/UPDATED",ze="SET_CURRENT_USER",He='{\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=((he={})[m]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),e.merge(JSON.parse(He)),Promise.resolve(n.first(["fcl.storage","fcl.storage.default"])).then(function(n){var r=function(){if(n.can)return Promise.resolve(function(e){try{var n=JSON.parse(He);return Promise.resolve(e.get(Ue)).then(function(r){return null!=r&&n.f_vsn!==r.f_vsn?(e.removeItem(Ue),n):r||n})}catch(e){return Promise.reject(e)}}(n)).then(function(n){Je(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},he[y]=function(e,n){e.subscribe(n.from),e.send(n.from,We,W({},e.all()))},he[g]=function(e,n){e.unsubscribe(n.from)},he.SNAPSHOT=function(e,n){try{return n.reply(W({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},he[ze]=function(e,r,t){try{return e.merge(t),Promise.resolve(n.first(["fcl.storage","fcl.storage.default"])).then(function(n){n.can&&n.put(Ue,e.all()),e.broadcast(We,W({},e.all()))})}catch(e){return Promise.reject(e)}},he.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(He)),Promise.resolve(n.first(["fcl.storage","fcl.storage.default"])).then(function(n){n.can&&n.put(Ue,e.all()),e.broadcast(We,W({},e.all()))})}catch(e){return Promise.reject(e)}},he),Ye=function(){return E(Be,Ue)};function Je(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ke(){Ye(),P(Ue,"DEL_CURRENT_USER")}function qe(e){var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=H(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,s=H(n.authorization||[]);!(i=s()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Ae({service:r,msg:e})},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}})}function Ge(e){Ye();var n="@EXIT",r=E(function(r){try{var t;return r.send(Ue,y),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(_e(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!_e(i)){t=1;break}i=i.s}}var s=new Te,a=Oe.bind(null,s,2);return(0===t?o.then(u):1===t?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(u).then(void 0,a):u(o):Oe(s,1,i)})).then(void 0,a),s;function c(n){i=n;do{if(!(o=e())||_e(o)&&!o.v)return void Oe(s,1,i);if(o.then)return void o.then(u).then(void 0,a);_e(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function u(e){e?(i=r())&&i.then?i.then(c).then(void 0,a):c(i):Oe(s,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if(o.tag===n)return r.send(Ue,g),void(t=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return P(r,n)}}function Xe(){return Ye(),P(Ue,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ze,$e=function(e){return v(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Qe=function(){return{authenticate:Me,unauthenticate:Ke,authorization:xe,signUserMessage:ke,verifyUserSignatures:je,subscribe:Ge,snapshot:Xe,resolveArgument:Fe}};Qe.authenticate=Me,Qe.unauthenticate=Ke,Qe.authorization=xe,Qe.signUserMessage=ke,Qe.verifyUserSignatures=je,Qe.subscribe=Ge,Qe.snapshot=Xe,Qe.resolveArgument=Fe;var en=function(e){try{return Promise.resolve(o([i(e)]).then(s))}catch(e){return Promise.reject(e)}},nn=function(e){return e.status>=4},rn=function(e){return e.status>=3},tn=function(e){return e.status>=2},on=((Ze={})[m]=function(e){try{return Promise.resolve(en(e.self())).then(function(n){nn(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},Ze[y]=function(e,n){e.subscribe(n.from),e.send(n.from,w,e.all())},Ze[g]=function(e,n){e.unsubscribe(n.from)},Ze[R]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Ze.POLL=function(e){try{return Promise.resolve(en(e.self())).then(function(n){var r,t;nn(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(w,n),e.merge(n)})}catch(e){return Promise.reject(e)}},Ze),sn=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},an=function(e){return E(on,sn(e))};function cn(e){function n(n){return b(sn(e),an,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return S(e,an)},subscribe:n,onceFinalized:r(tn),onceExecuted:r(rn),onceSealed:r(nn)}}cn.isUnknown=function(e){return e.status>=0},cn.isPending=function(e){return e.status>=1},cn.isFinalized=tn,cn.isExecuted=rn,cn.isSealed=nn,cn.isExpired=function(e){return 5===e.status};var un,ln=function(n){void 0===n&&(n={});try{return Promise.resolve(function(r,t){try{var o=Promise.resolve(function(n){try{return v(F(n),"mutate(opts) -- opts is required"),v(x(n),"mutate(opts) -- opts must be an object"),v(F(n.cadence),"mutate({ cadence }) -- cadence is required"),v(T(n.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){v(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(n)).then(function(){return Promise.resolve(e.config().get("fcl.authz",Qe().authorization)).then(function(r){return e.send([e.transaction(n.cadence),e.args(V(n.args||[])),n.limit&&M(n.limit)&&e.limit(n.limit),e.proposer(n.proposer||n.authz||r),e.payer(n.payer||n.authz||r),e.authorizations(n.authorizations||[n.authz||r])]).then(e.decode)})})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},dn=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(n.first(["sdk.resolve"],r.resolve||a)).then(function(n){function r(){return Promise.resolve(n(e)).then(function(e){return JSON.stringify(c(e),null,2)})}var t=function(){if(Array.isArray(e))return Promise.resolve(u(l(),e)).then(function(n){e=n})}();return t&&t.then?t.then(r):r()})}catch(e){return Promise.reject(e)}},fn=function(e){try{var r=setTimeout;return Promise.resolve(n().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},pn=((un={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(d()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(fn(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(d()).then(function(r){return e.put("hwm",r),Promise.resolve(o([f(e.self(),n.height,r.height-1)]).then(s)).then(function(n){for(var r,t=H(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(fn(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},un[y]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(fn(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},un[g]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},un),vn=function(e){return E(pn,e)};function hn(e){return{subscribe:function(n){return b(e,vn,n)}}}var mn=function(e){void 0===e&&(e=[]);try{return Promise.resolve(n.get("discovery.authn.endpoint")).then(function(n){v(Boolean(n),'"discovery.authn.endpoint" in config must be defined.');var r=new URL(n);return fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()}).then(function(n){return[].concat(e,n)})})}catch(e){return Promise.reject(e)}};function yn(e){void 0===e&&(e=[]);var n=window.fcl_extensions||[];return[].concat(n,e)}var gn,En=((gn={})[m]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "fcl.discovery" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),Promise.resolve((n={type:"authn"},r=n.type,function(){var e=arguments;return function(n){return[].slice.call(e).reduce(function(e,n){return e.then(n)},Promise.resolve(n))}}(mn,yn,function(e){return function(e,n){return void 0===e&&(e=[]),e.filter(function(e){return e.type===n})}(e,r)})([]))).then(function(n){e.put("results",n)})}catch(e){return Promise.reject(e)}var n,r},gn[y]=function(e,n){e.subscribe(n.from),e.send(n.from,"UPDATED",W({},e.all()))},gn[g]=function(e,n){return e.unsubscribe(n.from)},gn.SNAPSHOT=function(e,n){try{return Promise.resolve(n.reply(W({},e.all())))}catch(e){return Promise.reject(e)}},gn),Pn=function(){return E(En,"authn")},wn={authn:{subscribe:function(e){return b("authn",Pn,e)},snapshot:function(){return S("authn",Pn)}}},Rn=function(e,n){void 0===n&&(n=function(){});var r=function(r){var t=r.data;"object"==typeof t&&null!=typeof t&&t.type===e&&n(function(e){var n;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(n=e.body)||delete n.interaction,e}(t))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},bn=function(e,n){void 0===n&&(n={}),window.location!==window.parent.location?window.parent.postMessage(W({},n,{type:e}),"*"):window.opener.postMessage(W({},n,{type:e}),"*")},Sn=function(e,n){return Buffer.from(e.padEnd(2*n,0),"hex")},Cn={__proto__:null,sendMsgToFCL:bn,ready:function(e,n){Rn("FCL:VIEW:READY:RESPONSE",e),bn("FCL:VIEW:READY")},close:function(){bn("FCL:VIEW:CLOSE")},approve:function(e){bn("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){bn("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:function(e){bn("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:Rn,encodeMessageFromSignable:p,CompositeSignature:function(e,n,r){this.f_type=q.f_type,this.f_vsn=q.f_vsn,this.addr=C(e),this.keyId=Number(n),this.signature=r},encodeMessageForProvableAuthnSigning:function(e,n,r){void 0===r&&(r=""),v(e,"Encode Message From Provable Authn Error: address must be defined"),v(n,"Encode Message From Provable Authn Error: timestamp must be defined");var t=Sn(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),o=Sn(Buffer.from(r).toString("hex"),32).toString("hex");return t+(r?D([o,C(e),n]).toString("hex"):D([C(e),n]).toString("hex"))},encodeMessageForProvableAuthnVerifying:function(e,n,r){void 0===r&&(r=""),v(e,"Encode Message From Provable Authn Error: address must be defined"),v(n,"Encode Message From Provable Authn Error: timestamp must be defined");var t,o=r?(t=Buffer.from(r).toString("hex"),Buffer.from(t.padEnd(64,0),"hex")).toString("hex"):null;return r?D([o,C(e),n]).toString("hex"):D([C(e),n]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}},An=function(e){return void 0===e&&(e={}),Qe().authenticate(e)},In=function(){return Qe().unauthenticate()},Dn=function(e){return void 0===e&&(e={}),Qe().unauthenticate(),Qe().authenticate(e)},Ln=function(e){return void 0===e&&(e={}),Qe().authenticate(e)},Nn=function(e){return void 0===e&&(e={}),Qe().authenticate(e)},On=Qe().authorization,jn=h;export{j as VERSION,Cn as WalletUtils,An as authenticate,On as authz,Qe as currentUser,wn as discovery,hn as events,Nn as logIn,ln as mutate,U as query,Dn as reauthenticate,dn as serialize,Ln as signUp,jn as t,cn as tx,In as unauthenticate,De as verifyUserSignatures}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/sdk"),require("@onflow/util-invariant"),require("@onflow/types"),require("@onflow/util-actor"),require("@onflow/util-address"),require("@onflow/rlp"),require("@onflow/util-uid"),require("@onflow/util-template")):"function"==typeof define&&define.amd?define(["exports","@onflow/sdk","@onflow/util-invariant","@onflow/types","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-uid","@onflow/util-template"],n):n((e||self).fcl={},e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,n,r,t,o,i,a,s,u){function c(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var l=c(n),d=c(t),f=c(a),p=function(e){try{return Promise.resolve(n.config().where(e)).then(function(n){return Object.fromEntries(Object.entries(n).map(function(n){var r=n[1];return[n[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}},v={can:!("undefined"==typeof window),get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,n){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(n)))}catch(e){return Promise.reject(e)}}};n.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":v,"fcl.appDomainTag.default":"APP-V0.0-user"});var h="0.0.78-alpha.6",m=function(e){return function(n){return typeof n===e}},y=function(e){return null!=e},g=m("object"),P=m("string"),E=m("function"),b=m("number");function w(e){return E(e)?e(l.arg,d):[]}var R=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(y(e.cadence),"query({ cadence }) -- cadence is required"),r.invariant(P(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(l.config.get("accessNode.api")).then(function(e){r.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return l.send([l.script(e.cadence),l.args(w(e.args||[])),e.limit&&"number"==typeof e.limit&&l.limit(e.limit)]).then(l.decode)})}catch(e){return Promise.reject(e)}};function S(){return S=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},S.apply(this,arguments)}function O(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function C(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return O(e,n);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)?O(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var j={f_type:"Service",f_vsn:"1.0.0"},I={f_type:"Identity",f_vsn:"1.0.0"},A={f_type:"USER",f_vsn:"1.0.0"},D={f_type:"PollingResponse",f_vsn:"1.0.0"},k={f_type:"CompositeSignature",f_vsn:"1.0.0"};function N(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({old:e},j,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function x(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function L(e){return null==e?null:(null==e.method&&(e=S({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:S({},j,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}var T={"back-channel-rpc":x,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:S({},I,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:S({},I,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})},frame:N,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":L,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function F(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function _(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function U(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function B(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(U(e),{method:r,headers:S({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function M(e){var n,r;return null==e?null:"1.0.0"===e.f_vsn?e:S({},D,{status:null!=(n=e.status)?n:"APPROVED",reason:null!=(r=e.reason)?r:null,data:e.compositeSignature||e.data||S({},e)||{},updates:x(e.authorizationUpdates),local:N((e.local||[])[0])})}var V=function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(B(n,{method:H(n)}).then(M)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}},z={"HTTP/GET":"GET","HTTP/POST":"POST"},H=function(e){return r.invariant(z[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),z[e.method]},W="FCL_IFRAME";function Y(e){r.invariant(!document.getElementById(W),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=W,n.allow="usb *; hid *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n.contentWindow,function(){document.getElementById(W)&&document.getElementById(W).remove()}]}var q=null,J=null;function K(e){var n,r;null==q||null!=(n=q)&&n.closed?(r=window,q=r.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top="+(r.top.outerHeight/2+r.top.screenY-385)+", left="+(r.top.outerWidth/2+r.top.screenX-320))):J!==e?(q.location.replace(e),q.focus()):q.focus(),J=e;var t=setInterval(function(){q&&q.closed&&(clearInterval(t),q=null)},1e3);return[q,function(){q&&!q.closed&&(q.close(),q=null)}]}var G=null,$=null;function X(e){var n;null==G||null!=(n=G)&&n.closed?G=window.open(e,"_blank"):$!==e?(G.location.replace(e),G.focus()):G.focus(),$=e;var r=setInterval(function(){G&&G.closed&&(clearInterval(r),G=null)},1e3);return[G,function(){G&&!G.closed&&(G.close(),G=null)}]}var Z,Q={"VIEW/IFRAME":Y,"VIEW/POP":K,"VIEW/TAB":X},ee=function(e,n,r){try{var t={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(o){return Promise.resolve(B(e,{data:S({fclVersion:h,service:t,config:{services:r,app:o}},n)}).then(M)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("REDIRECT"===n.status)return n;if("PENDING"===n.status){var r=!0;return Promise.resolve(function(e,n){void 0===n&&(n={});try{try{return Promise.resolve(Q[e.method](U(e),n))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:n}),r}}catch(e){return Promise.reject(e)}}(L(n.local))).then(function(e){var t=e[1],o=function(){try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return V(n.updates,function(){return r}).then(function(e){return o(),e}).catch(function(e){throw console.error(e),o(),e})})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})})})}catch(e){return Promise.reject(e)}},ne="FCL:VIEW:CLOSE",re="FCL:VIEW:READY",te="FCL:VIEW:RESPONSE",oe=function(e){return"string"==typeof e&&e.toLowerCase()},ie=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ae=function(e,n){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+n+" for this and future versions of FCL")},se=function(e){var n=e.close,r=e.send,t=e.onReady,o=e.onResponse,i=e.onMessage;return function(e){try{if("object"!=typeof e.data)return;if(ie.has(e.data.type))return;oe(e.data.type)===oe(ne)&&n(),oe(e.data.type)===oe(re)&&t(e,{send:r,close:n}),oe(e.data.type)===oe(te)&&o(e,{send:r,close:n}),i(e,{send:r,close:n}),oe(e.data.type)===oe("FCL:FRAME:READY")&&(ae(e.data.type,re),t(e,{send:r,close:n})),oe(e.data.type)===oe("FCL:FRAME:RESPONSE")&&(ae(e.data.type,te),o(e,{send:r,close:n})),oe(e.data.type)===oe("FCL:FRAME:CLOSE")&&(ae(e.data.type,ne),n()),oe(e.data.type)===oe("FCL::CHALLENGE::RESPONSE")&&(ae(e.data.type,te),o(e,{send:r,close:n})),oe(e.data.type)===oe("FCL::AUTHZ_READY")&&(ae(e.data.type,re),t(e,{send:r,close:n})),oe(e.data.type)===oe("FCL::CHALLENGE::CANCEL")&&(ae(e.data.type,ne),n()),oe(e.data.type)===oe("FCL::CANCEL")&&(ae(e.data.type,ne),n())}catch(e){console.error("Frame Callback Error",e),n()}}},ue=function(){},ce=function(){},le=function(){},de=function(){},fe=function e(n){var t=n.service,o=n.msg,i=void 0===o?{}:o,a=n.opts,s=void 0===a?{}:a;try{return Promise.resolve(function(n,o){try{var a=Promise.resolve(pe[t.method](t,i,s)).then(function(n){return"REDIRECT"===n.status?(r.invariant(t.type===n.data.type,"Cannot shift recursive service type in execService"),t=n.data,Promise.resolve(e({service:t,msg:i,opts:s}))):n})}catch(e){return o(e)}return a&&a.then?a.then(void 0,o):a}(0,function(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:i,opts:s}),e}))}catch(e){return Promise.reject(e)}},pe={"HTTP/RPC":ee,"HTTP/POST":ee,"IFRAME/RPC":function(e,n,r){return new Promise(function(t,o){var i,a=s.uid(),u=r.includeOlderJsonRpcCall;n.data=null!=(i=e.data)?i:null,function(e,n){if(void 0===n&&(n={}),null==e)return{send:ue,close:ue};var r=n.onClose||ue;window.addEventListener("message",se({close:a,send:s,onReady:n.onReady||ue,onResponse:n.onResponse||ue,onMessage:n.onMessage||ue}));var t=Y(U(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",se),i(),r()}catch(e){console.error("Frame Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(t){return Promise.resolve(p(/^app\.detail\./)).then(function(i){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:i}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[n,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var i=M(e.data.result);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"POP/RPC":function(e,n,r){return new Promise(function(t,o){var i=s.uid(),a=r.redir,u=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:ce,close:ce};var r=n.onClose||ce;window.addEventListener("message",se({close:a,send:s,onReady:n.onReady||ce,onResponse:n.onResponse||ce,onMessage:n.onMessage||ce}));var t=K(U(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",se),i(),r()}catch(e){console.error("Popup Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Popup Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(t){return Promise.resolve(p(/^app\.detail\./)).then(function(a){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":t(i.data),!a&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var s=M(e.data.result);switch(s.status){case"APPROVED":t(s.data),!a&&r();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),r();break;case"REDIRECT":t(s),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"TAB/RPC":function(e,n,r){return new Promise(function(t,o){var i=s.uid(),a=r.redir,u=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:le,close:le};var r=n.onClose||le;window.addEventListener("message",se({close:a,send:s,onReady:n.onReady||le,onResponse:n.onResponse||le,onMessage:n.onMessage||le}));var t=X(U(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",se),i(),r()}catch(e){console.error("Tab Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Tab Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(t){return Promise.resolve(p(/^app\.detail\./)).then(function(a){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":t(i.data),!a&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var s=M(e.data.result);switch(s.status){case"APPROVED":t(s.data),!a&&r();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),r();break;case"REDIRECT":t(s),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"EXT/RPC":function(e,n,r){return new Promise(function(r,t){!function(e,n){void 0===n&&(n={});try{var r,t=function(){try{window.removeEventListener("message",se),a()}catch(e){console.error("Extension Close Error",e)}},o=function(e){try{var n;null==(n=window[i])||n.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(n){console.error("Extension Send Error",e,n)}};if(null==e)return Promise.resolve({send:de,close:de});var i=e.endpoint,a=n.onClose||de;window.addEventListener("message",se({close:t,send:o,onReady:n.onReady||de,onResponse:n.onResponse||de,onMessage:n.onMessage||de})),Promise.resolve(null==(r=window[i])?void 0:r.flow.enable()).then(function(){return{send:o,close:t}})}catch(e){return Promise.reject(e)}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(e){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:e,app:t}})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var o=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":r(i.data),o();break;case"DECLINED":t("Declined: "+(i.reason||"No reason supplied")),o();break;case"REDIRECT":r(i),o();break;default:t("Declined: No reason supplied"),o()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose:function(){t("Declined: Externally Halted")}})})}},ve=function(e,t){try{r.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),r.invariant(Array.isArray(t),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(t.map(function(e){try{return r.invariant("string"==typeof e.addr,"addr must be a string"),r.invariant("number"==typeof e.keyId,"keyId must be a number"),r.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve(function(r,t){try{var s=Promise.resolve(n.account(e.addr)).then(function(n){return o.push(n.keys[e.keyId].weight.toFixed(1)),i.push(n.keys[e.keyId].signAlgo),a.push(e.signature),n.keys[e.keyId].publicKey})}catch(e){return t(e)}return s&&s.then?s.then(void 0,t):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(n){return Promise.resolve(R({cadence:""+he,args:function(r,t){return[r(e,t.String),r(n,t.Array([t.String])),r(o,t.Array(t.UFix64)),r(i,t.Array([t.UInt])),r(a,t.Array([t.String]))]}}))})}catch(e){return Promise.reject(e)}},he="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function me(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},k,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}function ye(e,n,r){if(!e.s){if(r instanceof we){if(!r.s)return void(r.o=ye.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(ye.bind(null,e,n),ye.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ge=function(e,n){try{return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Promise.resolve(ve(e,n))}catch(e){return Promise.reject(e)}},Pe=function(e){try{return ke(),Promise.resolve(Se({redir:!0})).then(function(n){var t=_(n.services,"user-signature");return r.invariant(t,"Current user must have authorized a signing service."),Oe(function(){return Promise.resolve(fe({service:t,msg:Ue(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return me(e)}):[me(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},Ee=function(){try{return Promise.resolve(Se()).then(function(e){return n.arg(i.withPrefix(e.addr),d.Address)})}catch(e){return Promise.reject(e)}},be=function(e){try{return ke(),Promise.resolve(Se({redir:!0})).then(function(n){var r=_(n.services,"authz"),t=_(n.services,"pre-authz");return S({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(fe({service:t,msg:n})).then(Le)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(fe({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(me)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},we=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{ye(t,1,i(this.v))}catch(e){ye(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ye(t,1,n?n(o):o):r?ye(t,1,r(o)):ye(t,2,o)}catch(e){ye(t,2,e)}},t},e}();function Re(e){return e instanceof we&&1&e.s}var Se=function(e){void 0===e&&(e={redir:!1});try{return Promise.resolve(new Promise(function(t,a){try{return ke(),Promise.resolve(Fe()).then(function(a){return a.loggedIn&&Ne(a)?t(a):Promise.resolve(function(){try{return Promise.resolve(n.config.first(["discovery.wallet","challenge.handshake"])).then(function(e){return Promise.resolve(n.config.first(["discovery.wallet.method","discovery.wallet.method.default"])).then(function(t){return Promise.resolve(n.config.first(["fcl.appDomainTag","fcl.appDomainTag.default"])).then(function(n){return r.invariant(null!=e,'\n Required value for discovery.wallet not defined in config.\n See: "https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration"\n '),{discoveryWallet:e,discoveryWalletMethod:t,appDomainTag:n}})})})}catch(e){return Promise.reject(e)}}()).then(function(r){var a=r.discoveryWallet,s=r.discoveryWalletMethod,u=r.appDomainTag;return Promise.resolve(n.config.get("fcl.warning.suppress.redir")).then(function(n){e.redir&&!n&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");var r=function(n,r){try{var t=Oe(function(){return Promise.resolve(fe({service:{type:"authn",endpoint:a,method:s},msg:{timestamp:Date.now(),appDomainTag:u,extensions:window.fcl_extensions||[]},opts:e})).then(function(e){return Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?i.withPrefix(e.addr):null,e.paddr=e.paddr?i.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=C(e.authorizations);!(r=t()).done;)n.push(S({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(S({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,a=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return T[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),s=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,a);return S({},A,{addr:i.withPrefix(e.addr),cid:F(s),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){o.send(Ce,Ie,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return r(!0,e)}return t&&t.then?t.then(r.bind(null,!1),r.bind(null,!0)):r(!1,t)}(0,function(e,n){return Promise.resolve(Fe()).then(function(r){if(t(r),e)throw n;return n})});if(r&&r.then)return r.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Oe(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var Ce="CURRENT_USER",je="CURRENT_USER/UPDATED",Ie="SET_CURRENT_USER",Ae='{\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}',De=((Z={})[o.INIT]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),e.merge(JSON.parse(Ae)),Promise.resolve(n.config.first(["fcl.storage","fcl.storage.default"])).then(function(n){var r=function(){if(n.can)return Promise.resolve(function(e){try{var n=JSON.parse(Ae);return Promise.resolve(e.get(Ce)).then(function(r){return null!=r&&n.f_vsn!==r.f_vsn?(e.removeItem(Ce),n):r||n})}catch(e){return Promise.reject(e)}}(n)).then(function(n){Ne(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Z[o.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,je,S({},e.all()))},Z[o.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Z.SNAPSHOT=function(e,n){try{return n.reply(S({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[Ie]=function(e,r,t){try{return e.merge(t),Promise.resolve(n.config.first(["fcl.storage","fcl.storage.default"])).then(function(n){n.can&&n.put(Ce,e.all()),e.broadcast(je,S({},e.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(Ae)),Promise.resolve(n.config.first(["fcl.storage","fcl.storage.default"])).then(function(n){n.can&&n.put(Ce,e.all()),e.broadcast(je,S({},e.all()))})}catch(e){return Promise.reject(e)}},Z),ke=function(){return o.spawn(De,Ce)};function Ne(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function xe(){ke(),o.send(Ce,"DEL_CURRENT_USER")}function Le(e){var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=C(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,a=C(n.authorization||[]);!(i=a()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return fe({service:r,msg:e})},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}})}function Te(e){ke();var n="@EXIT",r=o.spawn(function(r){try{var t;return r.send(Ce,o.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Re(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Re(i)){t=1;break}i=i.s}}var a=new we,s=ye.bind(null,a,2);return(0===t?o.then(c):1===t?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):ye(a,1,i)})).then(void 0,s),a;function u(n){i=n;do{if(!(o=e())||Re(o)&&!o.v)return void ye(a,1,i);if(o.then)return void o.then(c).then(void 0,s);Re(i=r())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=r())&&i.then?i.then(u).then(void 0,s):u(i):ye(a,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===n)return r.send(Ce,o.UNSUBSCRIBE),void(t=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(r,n)}}function Fe(){return ke(),o.send(Ce,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var _e,Ue=function(e){return r.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Be=function(){return{authenticate:Se,unauthenticate:xe,authorization:be,signUserMessage:Pe,verifyUserSignatures:ge,subscribe:Te,snapshot:Fe,resolveArgument:Ee}};Be.authenticate=Se,Be.unauthenticate=xe,Be.authorization=be,Be.signUserMessage=Pe,Be.verifyUserSignatures=ge,Be.subscribe=Te,Be.snapshot=Fe,Be.resolveArgument=Ee;var Me="POLL",Ve=function(e){try{return Promise.resolve(n.send([n.getTransactionStatus(e)]).then(n.decode))}catch(e){return Promise.reject(e)}},ze=function(e){return e.status>=4},He=function(e){return e.status>=3},We=function(e){return e.status>=2},Ye=((_e={})[o.INIT]=function(e){try{return Promise.resolve(Ve(e.self())).then(function(n){ze(n)||setTimeout(function(){return e.sendSelf(Me)},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},_e[o.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,o.UPDATED,e.all())},_e[o.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},_e[o.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},_e.POLL=function(e){try{return Promise.resolve(Ve(e.self())).then(function(n){var r,t;ze(n)||setTimeout(function(){return e.sendSelf(Me)},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(o.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},_e),qe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Je=function(e){return o.spawn(Ye,qe(e))};function Ke(e){function n(n){return o.subscriber(qe(e),Je,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return o.snapshoter(e,Je)},subscribe:n,onceFinalized:r(We),onceExecuted:r(He),onceSealed:r(ze)}}Ke.isUnknown=function(e){return e.status>=0},Ke.isPending=function(e){return e.status>=1},Ke.isFinalized=We,Ke.isExecuted=He,Ke.isSealed=ze,Ke.isExpired=function(e){return 5===e.status};var Ge,$e=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},Xe=((Ge={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),t=function(){if(null==r){var t=e.put;return Promise.resolve(n.latestBlock()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve($e(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(n.latestBlock()).then(function(t){return e.put("hwm",t),Promise.resolve(n.send([n.getEvents(e.self(),r.height,t.height-1)]).then(n.decode)).then(function(n){for(var r,t=C(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve($e(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Ge[o.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve($e(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},Ge[o.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Ge),Ze=function(e){return o.spawn(Xe,e)},Qe=function(e,n){void 0===n&&(n=function(){});var r=function(r){var t=r.data;"object"==typeof t&&null!=typeof t&&t.type===e&&n(function(e){var n;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(n=e.body)||delete n.interaction,e}(t))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},en=function(e,n){void 0===n&&(n={}),window.location!==window.parent.location?window.parent.postMessage(S({},n,{type:e}),"*"):window.opener.postMessage(S({},n,{type:e}),"*")},nn=function(e,n){return Buffer.from(e.padEnd(2*n,0),"hex")},rn={__proto__:null,sendMsgToFCL:en,ready:function(e,n){Qe("FCL:VIEW:READY:RESPONSE",e),en("FCL:VIEW:READY")},close:function(){en("FCL:VIEW:CLOSE")},approve:function(e){en("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){en("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:function(e){en("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:Qe,encodeMessageFromSignable:n.encodeMessageFromSignable,CompositeSignature:function(e,n,r){this.f_type=k.f_type,this.f_vsn=k.f_vsn,this.addr=i.withPrefix(e),this.keyId=Number(n),this.signature=r},encodeMessageForProvableAuthnSigning:function(e,n,t){void 0===t&&(t=""),r.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),r.invariant(n,"Encode Message From Provable Authn Error: timestamp must be defined");var o=nn(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),s=nn(Buffer.from(t).toString("hex"),32).toString("hex");return o+(t?a.encode([s,i.withPrefix(e),n]).toString("hex"):a.encode([i.withPrefix(e),n]).toString("hex"))},encodeMessageForProvableAuthnVerifying:function(e,n,t){void 0===t&&(t=""),r.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),r.invariant(n,"Encode Message From Provable Authn Error: timestamp must be defined");var o,s=t?(o=Buffer.from(t).toString("hex"),Buffer.from(o.padEnd(64,0),"hex")).toString("hex"):null;return t?a.encode([s,i.withPrefix(e),n]).toString("hex"):a.encode([i.withPrefix(e),n]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}},tn=Be().authorization,on=d;Object.defineProperty(e,"TestUtils",{enumerable:!0,get:function(){return n.TestUtils}}),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,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"createSignableVoucher",{enumerable:!0,get:function(){return n.createSignableVoucher}}),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,"getCollection",{enumerable:!0,get:function(){return n.getCollection}}),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,"invariant",{enumerable:!0,get:function(){return n.invariant}}),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,"validator",{enumerable:!0,get:function(){return n.validator}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return u.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return u.template}}),e.VERSION=h,e.WalletUtils=rn,e.authenticate=function(){return Be().authenticate()},e.authz=tn,e.currentUser=Be,e.events=function(e){return{subscribe:function(n){return o.subscriber(e,Ze,n)}}},e.logIn=function(){return Be().authenticate()},e.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(n,t){try{var o=Promise.resolve(function(e){try{return r.invariant(y(e),"mutate(opts) -- opts is required"),r.invariant(g(e),"mutate(opts) -- opts must be an object"),r.invariant(y(e.cadence),"mutate({ cadence }) -- cadence is required"),r.invariant(P(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(l.config.get("accessNode.api")).then(function(e){r.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(l.config().get("fcl.authz",Be().authorization)).then(function(n){return l.send([l.transaction(e.cadence),l.args(w(e.args||[])),e.limit&&b(e.limit)&&l.limit(e.limit),l.proposer(e.proposer||e.authz||n),l.payer(e.payer||e.authz||n),l.authorizations(e.authorizations||[e.authz||n])]).then(l.decode)})})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},e.query=R,e.reauthenticate=function(){return Be().unauthenticate(),Be().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(n.config.first(["sdk.resolve"],r.resolve||n.resolve)).then(function(r){function t(){return Promise.resolve(r(e)).then(function(e){return JSON.stringify(n.createSignableVoucher(e),null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(n){e=n})}();return o&&o.then?o.then(t):t()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return Be().authenticate()},e.t=on,e.tx=Ke,e.unauthenticate=function(){return Be().unauthenticate()},e.verifyUserSignatures=ve}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/sdk"),require("@onflow/util-invariant"),require("@onflow/types"),require("@onflow/util-actor"),require("@onflow/util-address"),require("@onflow/rlp"),require("@onflow/util-uid"),require("@onflow/util-template")):"function"==typeof define&&define.amd?define(["exports","@onflow/sdk","@onflow/util-invariant","@onflow/types","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-uid","@onflow/util-template"],n):n((e||self).fcl={},e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,n,r,t,o,i,a,s,u){function c(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var l=c(n),d=c(t),f=c(a),p=function(e){try{return Promise.resolve(n.config().where(e)).then(function(n){return Object.fromEntries(Object.entries(n).map(function(n){var r=n[1];return[n[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}},v={can:!("undefined"==typeof window),get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,n){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(n)))}catch(e){return Promise.reject(e)}}};n.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":v});var h="0.0.78-alpha.7",m=function(e){return function(n){return typeof n===e}},y=function(e){return null!=e},g=m("object"),P=m("string"),b=m("function"),E=m("number");function w(e){return b(e)?e(l.arg,d):[]}var R=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(y(e.cadence),"query({ cadence }) -- cadence is required"),r.invariant(P(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(l.config.get("accessNode.api")).then(function(e){r.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return l.send([l.script(e.cadence),l.args(w(e.args||[])),e.limit&&"number"==typeof e.limit&&l.limit(e.limit)]).then(l.decode)})}catch(e){return Promise.reject(e)}};function S(){return S=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},S.apply(this,arguments)}function O(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function C(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return O(e,n);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)?O(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var j={f_type:"Service",f_vsn:"1.0.0"},I={f_type:"Identity",f_vsn:"1.0.0"},A={f_type:"USER",f_vsn:"1.0.0"},D={f_type:"PollingResponse",f_vsn:"1.0.0"},N={f_type:"CompositeSignature",f_vsn:"1.0.0"};function k(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({old:e},j,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}function x(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}function L(e){return null==e?null:(null==e.method&&(e=S({},e,{type:"local-view",method:"VIEW/IFRAME"})),"1.0.0"===e.f_vsn?e:S({},j,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}}))}var T={"back-channel-rpc":x,"pre-authz":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:S({},I,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authz:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:S({},I,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})},authn:function(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},j,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})},frame:k,"open-id":function(e){return null==e?null:"1.0.0"===e.f_vsn?e:null},"user-signature":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid user-signature service")},"local-view":L,"account-proof":function(e){if(null==e)return null;if("1.0.0"===e.f_vsn)return e;throw new Error("Invalid account-proof service")}};function F(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function U(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function _(e){var n=new URL(e.endpoint);if(n.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function B(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(_(e),{method:r,headers:S({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function M(e){var n,r;return null==e?null:"1.0.0"===e.f_vsn?e:S({},D,{status:null!=(n=e.status)?n:"APPROVED",reason:null!=(r=e.reason)?r:null,data:e.compositeSignature||e.data||S({},e)||{},updates:x(e.authorizationUpdates),local:k((e.local||[])[0])})}var V=function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(B(n,{method:H(n)}).then(M)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}},z={"HTTP/GET":"GET","HTTP/POST":"POST"},H=function(e){return r.invariant(z[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),z[e.method]},W="FCL_IFRAME";function Y(e){r.invariant(!document.getElementById(W),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=W,n.allow="usb *; hid *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n.contentWindow,function(){document.getElementById(W)&&document.getElementById(W).remove()}]}var q=null,J=null;function K(e){var n,r;return null==q||null!=(n=q)&&n.closed?(r=window,q=r.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=770, top="+(r.top.outerHeight/2+r.top.screenY-385)+", left="+(r.top.outerWidth/2+r.top.screenX-320))):J!==e?(q.location.replace(e),q.focus()):q.focus(),J=e,[q,function(){q&&!q.closed&&q.close(),q=null}]}var G=null,$=null;function X(e){var n;return null==G||null!=(n=G)&&n.closed?G=window.open(e,"_blank"):$!==e?(G.location.replace(e),G.focus()):G.focus(),$=e,[G,function(){G&&!G.closed&&G.close(),G=null}]}var Z,Q={"VIEW/IFRAME":Y,"VIEW/POP":K,"VIEW/TAB":X},ee=function(e,n,r){try{var t={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(o){return Promise.resolve(B(e,{data:S({fclVersion:h,service:t,config:{services:r,app:o}},n)}).then(M)).then(function(n){if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("REDIRECT"===n.status)return n;if("PENDING"===n.status){var r=!0;return Promise.resolve(function(e,n){void 0===n&&(n={});try{try{return Promise.resolve(Q[e.method](_(e),n))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:n}),r}}catch(e){return Promise.reject(e)}}(L(n.local))).then(function(e){var t=e[1],o=function(){try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return V(n.updates,function(){return r}).then(function(e){return o(),e}).catch(function(e){throw console.error(e),o(),e})})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")})})})}catch(e){return Promise.reject(e)}},ne="FCL:VIEW:CLOSE",re="FCL:VIEW:READY",te="FCL:VIEW:RESPONSE",oe=function(e){return"string"==typeof e&&e.toLowerCase()},ie=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ae=function(e,n){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+n+" for this and future versions of FCL")},se=function(e){var n=e.close,r=e.send,t=e.onReady,o=e.onResponse,i=e.onMessage;return function(e){try{if("object"!=typeof e.data)return;if(ie.has(e.data.type))return;oe(e.data.type)===oe(ne)&&n(),oe(e.data.type)===oe(re)&&t(e,{send:r,close:n}),oe(e.data.type)===oe(te)&&o(e,{send:r,close:n}),i(e,{send:r,close:n}),oe(e.data.type)===oe("FCL:FRAME:READY")&&(ae(e.data.type,re),t(e,{send:r,close:n})),oe(e.data.type)===oe("FCL:FRAME:RESPONSE")&&(ae(e.data.type,te),o(e,{send:r,close:n})),oe(e.data.type)===oe("FCL:FRAME:CLOSE")&&(ae(e.data.type,ne),n()),oe(e.data.type)===oe("FCL::CHALLENGE::RESPONSE")&&(ae(e.data.type,te),o(e,{send:r,close:n})),oe(e.data.type)===oe("FCL::AUTHZ_READY")&&(ae(e.data.type,re),t(e,{send:r,close:n})),oe(e.data.type)===oe("FCL::CHALLENGE::CANCEL")&&(ae(e.data.type,ne),n()),oe(e.data.type)===oe("FCL::CANCEL")&&(ae(e.data.type,ne),n())}catch(e){console.error("Frame Callback Error",e),n()}}},ue=function(){},ce=function(){},le=function(){},de=function(){},fe=function e(n){var t=n.service,o=n.msg,i=void 0===o?{}:o,a=n.opts,s=void 0===a?{}:a;try{return Promise.resolve(function(n,o){try{var a=Promise.resolve(pe[t.method](t,i,s)).then(function(n){return"REDIRECT"===n.status?(r.invariant(t.type===n.data.type,"Cannot shift recursive service type in execService"),t=n.data,Promise.resolve(e({service:t,msg:i,opts:s}))):n})}catch(e){return o(e)}return a&&a.then?a.then(void 0,o):a}(0,function(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:i,opts:s}),e}))}catch(e){return Promise.reject(e)}},pe={"HTTP/RPC":ee,"HTTP/POST":ee,"IFRAME/RPC":function(e,n,r){return new Promise(function(t,o){var i,a=s.uid(),u=r.includeOlderJsonRpcCall;n.data=null!=(i=e.data)?i:null,function(e,n){if(void 0===n&&(n={}),null==e)return{send:ue,close:ue};var r=n.onClose||ue;window.addEventListener("message",se({close:a,send:s,onReady:n.onReady||ue,onResponse:n.onResponse||ue,onMessage:n.onMessage||ue}));var t=Y(_(e)),o=t[0],i=t[1];return{send:s,close:a};function a(){try{window.removeEventListener("message",se),i(),r()}catch(e){console.error("Frame Close Error",e)}}function s(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(t){return Promise.resolve(p(/^app\.detail\./)).then(function(i){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:i}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[n,e.params],deprecated:{message:"jsonrpc is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var i=M(e.data.result);switch(i.status){case"APPROVED":t(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"POP/RPC":function(e,n,r){return new Promise(function(t,o){var i=s.uid(),a=r.redir,u=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:ce,close:ce};var r=n.onClose||ce;window.addEventListener("message",se({close:s,send:u,onReady:n.onReady||ce,onResponse:n.onResponse||ce,onMessage:n.onMessage||ce}));var t=K(_(e)),o=t[0],i=t[1],a=setInterval(function(){o&&o.closed&&s()},500);return{send:u,close:s};function s(){try{window.removeEventListener("message",se),clearInterval(a),i(),r()}catch(e){console.error("Popup Close Error",e)}}function u(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Popup Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(t){return Promise.resolve(p(/^app\.detail\./)).then(function(a){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":t(i.data),!a&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var s=M(e.data.result);switch(s.status){case"APPROVED":t(s.data),!a&&r();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),r();break;case"REDIRECT":t(s),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"TAB/RPC":function(e,n,r){return new Promise(function(t,o){var i=s.uid(),a=r.redir,u=r.includeOlderJsonRpcCall;n.data=e.data,function(e,n){if(void 0===n&&(n={}),null==e)return{send:le,close:le};var r=n.onClose||le;window.addEventListener("message",se({close:s,send:u,onReady:n.onReady||le,onResponse:n.onResponse||le,onMessage:n.onMessage||le}));var t=X(_(e)),o=t[0],i=t[1],a=setInterval(function(){o&&o.closed&&s()},500);return{send:u,close:s};function s(){try{window.removeEventListener("message",se),clearInterval(a),i(),r()}catch(e){console.error("Tab Close Error",e)}}function u(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Tab Send Error",e,n)}}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(t){return Promise.resolve(p(/^app\.detail\./)).then(function(a){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:t,app:a}});var s={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:FRAME:READY:RESPONSE",body:n,service:s,config:{services:r,app:t},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),u&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[n,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":t(i.data),!a&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;case"REDIRECT":t(i),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,n){var r=n.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var s=M(e.data.result);switch(s.status){case"APPROVED":t(s.data),!a&&r();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),r();break;case"REDIRECT":t(s),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})},"EXT/RPC":function(e,n,r){return new Promise(function(r,t){!function(e,n){void 0===n&&(n={});try{var r,t=function(){try{window.removeEventListener("message",se),a()}catch(e){console.error("Extension Close Error",e)}},o=function(e){try{var n;null==(n=window[i])||n.flow.send(JSON.parse(JSON.stringify(e||{})))}catch(n){console.error("Extension Send Error",e,n)}};if(null==e)return Promise.resolve({send:de,close:de});var i=e.endpoint,a=n.onClose||de;window.addEventListener("message",se({close:t,send:o,onReady:n.onReady||de,onResponse:n.onResponse||de,onMessage:n.onMessage||de})),Promise.resolve(null==(r=window[i])?void 0:r.flow.enable()).then(function(){return{send:o,close:t}})}catch(e){return Promise.reject(e)}}(e,{onReady:function(r,t){var o=t.send;try{return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){var r={params:e.params,data:e.data,type:e.type};return Promise.resolve(p(/^service\./)).then(function(e){return Promise.resolve(p(/^app\.detail\./)).then(function(t){o({fclVersion:h,type:"FCL:VIEW:READY:RESPONSE",body:n,service:r,config:{services:e,app:t}})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,n){var o=n.close;try{if("object"!=typeof e.data)return;var i=M(e.data);switch(i.status){case"APPROVED":r(i.data),o();break;case"DECLINED":t("Declined: "+(i.reason||"No reason supplied")),o();break;case"REDIRECT":r(i),o();break;default:t("Declined: No reason supplied"),o()}}catch(e){throw console.error("execExtRPC onResponse error",e),e}},onClose:function(){t("Declined: Externally Halted")}})})}},ve=function(e,t){try{r.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),r.invariant(Array.isArray(t),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(t.map(function(e){try{return r.invariant("string"==typeof e.addr,"addr must be a string"),r.invariant("number"==typeof e.keyId,"keyId must be a number"),r.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve(function(r,t){try{var s=Promise.resolve(n.account(e.addr)).then(function(n){return o.push(n.keys[e.keyId].weight.toFixed(1)),i.push(n.keys[e.keyId].signAlgo),a.push(e.signature),n.keys[e.keyId].publicKey})}catch(e){return t(e)}return s&&s.then?s.then(void 0,t):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(n){return Promise.resolve(R({cadence:""+he,args:function(r,t){return[r(e,t.String),r(n,t.Array([t.String])),r(o,t.Array(t.UFix64)),r(i,t.Array([t.UInt])),r(a,t.Array([t.String]))]}}))})}catch(e){return Promise.reject(e)}},he="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n";function me(e){return null==e?null:"1.0.0"===e.f_vsn?e:S({},N,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}function ye(e,n,r){if(!e.s){if(r instanceof we){if(!r.s)return void(r.o=ye.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(ye.bind(null,e,n),ye.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ge=function(e,n){try{return console.warn("\n %cFCL/SDK Deprecation Notice\n ============================\n verifyUserSignatures is no longer exported as fcl.currentUser().verifyUserSignatures\n and is now available as fcl.verifyUserSignatures\n ============================\n ","font-weight:bold;font-family:monospace;"),Promise.resolve(ve(e,n))}catch(e){return Promise.reject(e)}},Pe=function(e){try{return Ne(),Promise.resolve(Se({redir:!0})).then(function(n){var t=U(n.services,"user-signature");return r.invariant(t,"Current user must have authorized a signing service."),Oe(function(){return Promise.resolve(fe({service:t,msg:_e(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return me(e)}):[me(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},be=function(){try{return Promise.resolve(Se()).then(function(e){return n.arg(i.withPrefix(e.addr),d.Address)})}catch(e){return Promise.reject(e)}},Ee=function(e){try{return Ne(),Promise.resolve(Se({redir:!0})).then(function(n){var r=U(n.services,"authz"),t=U(n.services,"pre-authz");return S({},e,t?{tempId:"CURRENT_USER",resolve:function(e,n){try{return Promise.resolve(fe({service:t,msg:n})).then(Le)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(fe({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(me)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},we=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{ye(t,1,i(this.v))}catch(e){ye(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ye(t,1,n?n(o):o):r?ye(t,1,r(o)):ye(t,2,o)}catch(e){ye(t,2,e)}},t},e}();function Re(e){return e instanceof we&&1&e.s}var Se=function(e){var t=e.service,a=e.redir,s=void 0!==a&&a;try{return Promise.resolve(new Promise(function(e,a){try{return Ne(),Promise.resolve(Fe()).then(function(a){return a.loggedIn&&ke(a)?e(a):Promise.resolve(function(){try{return Promise.resolve(n.config.first(["discovery.wallet","challenge.handshake"])).then(function(e){return Promise.resolve(n.config.first(["discovery.wallet.method","discovery.wallet.method.default"])).then(function(r){return Promise.resolve(n.config.get("fcl.appDomainTag")).then(function(n){return{discoveryWallet:e,discoveryWalletMethod:r,appDomainTag:n}})})})}catch(e){return Promise.reject(e)}}()).then(function(a){var u=a.discoveryWallet,c=a.discoveryWalletMethod,l=a.appDomainTag;return r.invariant(t||u,'\n If no service passed to "authenticate," then "discovery.wallet" must be defined in config.\n See: "https://docs.onflow.org/fcl/reference/api/#setting-configuration-values"\n '),Promise.resolve(n.config.get("fcl.warning.suppress.redir")).then(function(n){s&&!n&&console.warn("You are manually enabling a very experimental feature that is not yet standard, use at your own risk.\n You can disable this warning by setting fcl.warning.suppress.redir to true in your config");var r=function(e,n){try{var r=Oe(function(){return Promise.resolve(fe({service:t||{type:"authn",endpoint:u,method:c},msg:{timestamp:Date.now(),appDomainTag:l,extensions:window.fcl_extensions||[]},opts:{redir:s}})).then(function(e){return Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?i.withPrefix(e.addr):null,e.paddr=e.paddr?i.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=C(e.authorizations);!(r=t()).done;)n.push(S({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(S({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,a=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return T[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),s=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,a);return S({},A,{addr:i.withPrefix(e.addr),cid:F(s),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){o.send(Ce,Ie,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return n(!0,e)}return r&&r.then?r.then(n.bind(null,!1),n.bind(null,!0)):n(!1,r)}(0,function(n,r){return Promise.resolve(Fe()).then(function(t){if(e(t),n)throw r;return r})});if(r&&r.then)return r.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Oe(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var Ce="CURRENT_USER",je="CURRENT_USER/UPDATED",Ie="SET_CURRENT_USER",Ae='{\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}',De=((Z={})[o.INIT]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "currentUser" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),e.merge(JSON.parse(Ae)),Promise.resolve(n.config.first(["fcl.storage","fcl.storage.default"])).then(function(n){var r=function(){if(n.can)return Promise.resolve(function(e){try{var n=JSON.parse(Ae);return Promise.resolve(e.get(Ce)).then(function(r){return null!=r&&n.f_vsn!==r.f_vsn?(e.removeItem(Ce),n):r||n})}catch(e){return Promise.reject(e)}}(n)).then(function(n){ke(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Z[o.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,je,S({},e.all()))},Z[o.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Z.SNAPSHOT=function(e,n){try{return n.reply(S({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[Ie]=function(e,r,t){try{return e.merge(t),Promise.resolve(n.config.first(["fcl.storage","fcl.storage.default"])).then(function(n){n.can&&n.put(Ce,e.all()),e.broadcast(je,S({},e.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(Ae)),Promise.resolve(n.config.first(["fcl.storage","fcl.storage.default"])).then(function(n){n.can&&n.put(Ce,e.all()),e.broadcast(je,S({},e.all()))})}catch(e){return Promise.reject(e)}},Z),Ne=function(){return o.spawn(De,Ce)};function ke(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function xe(){Ne(),o.send(Ce,"DEL_CURRENT_USER")}function Le(e){var n=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=n.proposer&&r.push(["PROPOSER",n.proposer]);for(var t,o=C(n.payer||[]);!(t=o()).done;)r.push(["PAYER",t.value]);for(var i,a=C(n.authorization||[]);!(i=a()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var n=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return fe({service:r,msg:e})},role:{proposer:"PROPOSER"===n,payer:"PAYER"===n,authorizer:"AUTHORIZER"===n}}})}function Te(e){Ne();var n="@EXIT",r=o.spawn(function(r){try{var t;return r.send(Ce,o.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Re(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Re(i)){t=1;break}i=i.s}}var a=new we,s=ye.bind(null,a,2);return(0===t?o.then(c):1===t?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):ye(a,1,i)})).then(void 0,s),a;function u(n){i=n;do{if(!(o=e())||Re(o)&&!o.v)return void ye(a,1,i);if(o.then)return void o.then(c).then(void 0,s);Re(i=r())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=r())&&i.then?i.then(u).then(void 0,s):u(i):ye(a,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===n)return r.send(Ce,o.UNSUBSCRIBE),void(t=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(r,n)}}function Fe(){return Ne(),o.send(Ce,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ue,_e=function(e){return r.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Be=function(){return{authenticate:Se,unauthenticate:xe,authorization:Ee,signUserMessage:Pe,verifyUserSignatures:ge,subscribe:Te,snapshot:Fe,resolveArgument:be}};Be.authenticate=Se,Be.unauthenticate=xe,Be.authorization=Ee,Be.signUserMessage=Pe,Be.verifyUserSignatures=ge,Be.subscribe=Te,Be.snapshot=Fe,Be.resolveArgument=be;var Me="POLL",Ve=function(e){try{return Promise.resolve(n.send([n.getTransactionStatus(e)]).then(n.decode))}catch(e){return Promise.reject(e)}},ze=function(e){return e.status>=4},He=function(e){return e.status>=3},We=function(e){return e.status>=2},Ye=((Ue={})[o.INIT]=function(e){try{return Promise.resolve(Ve(e.self())).then(function(n){ze(n)||setTimeout(function(){return e.sendSelf(Me)},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},Ue[o.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,o.UPDATED,e.all())},Ue[o.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Ue[o.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Ue.POLL=function(e){try{return Promise.resolve(Ve(e.self())).then(function(n){var r,t;ze(n)||setTimeout(function(){return e.sendSelf(Me)},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(o.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},Ue),qe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Je=function(e){return o.spawn(Ye,qe(e))};function Ke(e){function n(n){return o.subscriber(qe(e),Je,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return o.snapshoter(e,Je)},subscribe:n,onceFinalized:r(We),onceExecuted:r(He),onceSealed:r(ze)}}Ke.isUnknown=function(e){return e.status>=0},Ke.isPending=function(e){return e.status>=1},Ke.isFinalized=We,Ke.isExecuted=He,Ke.isSealed=ze,Ke.isExpired=function(e){return 5===e.status};var Ge,$e=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},Xe=((Ge={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),t=function(){if(null==r){var t=e.put;return Promise.resolve(n.latestBlock()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve($e(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(n.latestBlock()).then(function(t){return e.put("hwm",t),Promise.resolve(n.send([n.getEvents(e.self(),r.height,t.height-1)]).then(n.decode)).then(function(n){for(var r,t=C(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve($e(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Ge[o.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve($e(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},Ge[o.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Ge),Ze=function(e){return o.spawn(Xe,e)},Qe=function(e){void 0===e&&(e=[]);try{return Promise.resolve(n.config.get("discovery.authn.endpoint")).then(function(n){r.invariant(Boolean(n),'"discovery.authn.endpoint" in config must be defined.');var t=new URL(n);return fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()}).then(function(n){return[].concat(e,n)})})}catch(e){return Promise.reject(e)}};function en(e){void 0===e&&(e=[]);var n=window.fcl_extensions||[];return[].concat(n,e)}var nn,rn="authn",tn=((nn={})[o.INIT]=function(e){try{return"undefined"==typeof window&&console.warn('\n %cFCL Warning\n ============================\n "fcl.discovery" is only available in the browser.\n For more info, please see the docs: https://docs.onflow.org/fcl/\n ============================\n ',"font-weight:bold;font-family:monospace;"),Promise.resolve((n={type:rn},r=n.type,function(){var e=arguments;return function(n){return[].slice.call(e).reduce(function(e,n){return e.then(n)},Promise.resolve(n))}}(Qe,en,function(e){return function(e,n){return void 0===e&&(e=[]),e.filter(function(e){return e.type===n})}(e,r)})([]))).then(function(n){e.put("results",n)})}catch(e){return Promise.reject(e)}var n,r},nn[o.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,"UPDATED",S({},e.all()))},nn[o.UNSUBSCRIBE]=function(e,n){return e.unsubscribe(n.from)},nn.SNAPSHOT=function(e,n){try{return Promise.resolve(n.reply(S({},e.all())))}catch(e){return Promise.reject(e)}},nn),on=function(){return o.spawn(tn,rn)},an={authn:{subscribe:function(e){return o.subscriber(rn,on,e)},snapshot:function(){return o.snapshoter(rn,on)}}},sn=function(e,n){void 0===n&&(n=function(){});var r=function(r){var t=r.data;"object"==typeof t&&null!=typeof t&&t.type===e&&n(function(e){var n;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(n=e.body)||delete n.interaction,e}(t))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},un=function(e,n){void 0===n&&(n={}),window.location!==window.parent.location?window.parent.postMessage(S({},n,{type:e}),"*"):window.opener.postMessage(S({},n,{type:e}),"*")},cn=function(e,n){return Buffer.from(e.padEnd(2*n,0),"hex")},ln={__proto__:null,sendMsgToFCL:un,ready:function(e,n){sn("FCL:VIEW:READY:RESPONSE",e),un("FCL:VIEW:READY")},close:function(){un("FCL:VIEW:CLOSE")},approve:function(e){un("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){un("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},redirect:function(e){un("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"REDIRECT",reason:null,data:e})},onMessageFromFCL:sn,encodeMessageFromSignable:n.encodeMessageFromSignable,CompositeSignature:function(e,n,r){this.f_type=N.f_type,this.f_vsn=N.f_vsn,this.addr=i.withPrefix(e),this.keyId=Number(n),this.signature=r},encodeMessageForProvableAuthnSigning:function(e,n,t){void 0===t&&(t=""),r.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),r.invariant(n,"Encode Message From Provable Authn Error: timestamp must be defined");var o=cn(Buffer.from("FLOW-V0.0-user").toString("hex"),32).toString("hex"),s=cn(Buffer.from(t).toString("hex"),32).toString("hex");return o+(t?a.encode([s,i.withPrefix(e),n]).toString("hex"):a.encode([i.withPrefix(e),n]).toString("hex"))},encodeMessageForProvableAuthnVerifying:function(e,n,t){void 0===t&&(t=""),r.invariant(e,"Encode Message From Provable Authn Error: address must be defined"),r.invariant(n,"Encode Message From Provable Authn Error: timestamp must be defined");var o,s=t?(o=Buffer.from(t).toString("hex"),Buffer.from(o.padEnd(64,0),"hex")).toString("hex"):null;return t?a.encode([s,i.withPrefix(e),n]).toString("hex"):a.encode([i.withPrefix(e),n]).toString("hex")},injectExtService:function(e){"authn"===e.type&&null!=e.endpoint?(Array.isArray(window.fcl_extensions)||(window.fcl_extensions=[]),window.fcl_extensions.push(e)):console.warn("Authn service is required")}},dn=Be().authorization,fn=d;Object.defineProperty(e,"TestUtils",{enumerable:!0,get:function(){return n.TestUtils}}),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,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"createSignableVoucher",{enumerable:!0,get:function(){return n.createSignableVoucher}}),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,"getCollection",{enumerable:!0,get:function(){return n.getCollection}}),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,"invariant",{enumerable:!0,get:function(){return n.invariant}}),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,"validator",{enumerable:!0,get:function(){return n.validator}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return u.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return u.template}}),e.VERSION=h,e.WalletUtils=ln,e.authenticate=function(e){return void 0===e&&(e={}),Be().authenticate(e)},e.authz=dn,e.currentUser=Be,e.discovery=an,e.events=function(e){return{subscribe:function(n){return o.subscriber(e,Ze,n)}}},e.logIn=function(e){return void 0===e&&(e={}),Be().authenticate(e)},e.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(n,t){try{var o=Promise.resolve(function(e){try{return r.invariant(y(e),"mutate(opts) -- opts is required"),r.invariant(g(e),"mutate(opts) -- opts must be an object"),r.invariant(y(e.cadence),"mutate({ cadence }) -- cadence is required"),r.invariant(P(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(l.config.get("accessNode.api")).then(function(e){r.invariant(e,'Required value for "accessNode.api" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration')})}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(l.config().get("fcl.authz",Be().authorization)).then(function(n){return l.send([l.transaction(e.cadence),l.args(w(e.args||[])),e.limit&&E(e.limit)&&l.limit(e.limit),l.proposer(e.proposer||e.authz||n),l.payer(e.payer||e.authz||n),l.authorizations(e.authorizations||[e.authz||n])]).then(l.decode)})})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},e.query=R,e.reauthenticate=function(e){return void 0===e&&(e={}),Be().unauthenticate(),Be().authenticate(e)},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(n.config.first(["sdk.resolve"],r.resolve||n.resolve)).then(function(r){function t(){return Promise.resolve(r(e)).then(function(e){return JSON.stringify(n.createSignableVoucher(e),null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(n){e=n})}();return o&&o.then?o.then(t):t()})}catch(e){return Promise.reject(e)}},e.signUp=function(e){return void 0===e&&(e={}),Be().authenticate(e)},e.t=fn,e.tx=Ke,e.unauthenticate=function(){return Be().unauthenticate()},e.verifyUserSignatures=ve}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.78-alpha.6", | ||
"version": "0.0.78-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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2302255
18855
616
6
13
1
14