@onflow/fcl
Advanced tools
Comparing version 0.0.77 to 0.0.78-alpha.1
@@ -5,2 +5,6 @@ ## Unreleased | ||
## 0.0.78-alpha.1 - 2021-09-17 | ||
- 2021-09-16 -- Adds redirect option for `POP/RPC` and `TAB/RPC` | ||
## 0.0.77 - 2021-09-17 | ||
@@ -7,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/sdk"),t=require("@onflow/util-invariant"),r=require("@onflow/types"),n=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 t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var c=u(e),d=u(r),l=u(i),f=function(t){try{return Promise.resolve(e.config().where(t)).then(function(e){return Object.fromEntries(Object.entries(e).map(function(e){var r=e[1];return[e[0].replace(t,""),r]}))})}catch(e){return Promise.reject(e)}};e.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,t){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(t)))}catch(e){return Promise.reject(e)}}}});var p=function(e){return function(t){return typeof t===e}},h=function(e){return null!=e},v=p("object"),m=p("string"),y=p("function"),g=p("number");function E(e){return y(e)?e(c.arg,d):[]}var P=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return t.invariant(h(e.cadence),"query({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){t.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(E(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}};function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function C(e,t){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,t){if(e){if("string"==typeof e)return S(e,t);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,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var R={f_type:"Service",f_vsn:"1.0.0"},w={f_type:"Identity",f_vsn:"1.0.0"},O={f_type:"USER",f_vsn:"1.0.0"},L={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({old:e},R,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function x(e){if(null==e)return null;switch(null==e.method&&(e=b({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var N={"back-channel-rpc":j,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{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:A,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":x};function F(e){return l.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function D(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function k(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function T(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(k(e),{method:r,headers:b({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function U(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:b({},e)}),e.f_vsn){case"1.0.0":return e;default:return b({},L,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:j(e.authorizationUpdates),local:A((e.local||[])[0])})}}var _=function e(r,n){void 0===n&&(n=function(){return!0});try{if(t.invariant(r,"Missing Polling Service",{service:r}),!n())throw new Error("Externally Halted");return Promise.resolve(T(r,{method:B(r)}).then(U)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}},V={"HTTP/GET":"GET","HTTP/POST":"POST"},B=function(e){return t.invariant(V[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),V[e.method]},M="FCL_IFRAME";function z(e){t.invariant(!document.getElementById(M),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=M,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(M)&&document.getElementById(M).remove()}]}var W=null,H=null;function Y(e,t,r,n,o){return r.open(e,t,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+n+", height="+o+", top="+(r.top.outerHeight/2+r.top.screenY-o/2)+", left="+(r.top.outerWidth/2+r.top.screenX-n/2))}function q(e){var t;null==W||null!=(t=W)&&t.closed?W=Y(e,"FCL_POP",window,640,600):H!==e?(W=Y(e,"FCL_POP",window,640,600)).focus():W.focus(),H=e;var r=setInterval(function(){W&&W.closed&&(clearInterval(r),W=null)},1e3);return[W,function(){W&&!W.closed&&(W.close(),W=null)}]}var J=null,K=null;function G(e){var t;null==J||null!=(t=J)&&t.closed?J=window.open(e,"_blank"):K!==e?(J=window.open(e,"_blank")).focus():J.focus(),K=e;var r=setInterval(function(){J&&J.closed&&(clearInterval(r),J=null)},1e3);return[J,function(){J&&!J.closed&&(J.close(),J=null)}]}var Z,$={"VIEW/IFRAME":z,"VIEW/POP":q,"VIEW/TAB":G},X=function(e,t,r){try{return t.data=e.data,Promise.resolve(T(e,{data:t}).then(U)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve($[e.method](k(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(x(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return _(t.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:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Q=function(){},ee=function(e){return"string"==typeof e&&e.toLowerCase()},te=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ne=function(){},oe=function(e){return"string"==typeof e&&e.toLowerCase()},ie=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},ae=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),se=function(){},ue=function(e){return"string"==typeof e&&e.toLowerCase()},ce=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},de=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),le=function(e){var t=e.service,r=e.msg,n=void 0===r?{}:r,o=e.opts,i=void 0===o?{}:o;try{try{return Promise.resolve(fe[t.method](t,n,i))}catch(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:n,opts:i}),e}}catch(e){return Promise.reject(e)}},fe={"HTTP/RPC":X,"HTTP/POST":X,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var i=a.uid(),s=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:Q,close:Q};var r=t.onClose||Q,n=t.onMessage||Q,o=t.onReady||Q,i=t.onResponse||Q;window.addEventListener("message",c);var a=z(k(e)),s=a[0],u=a[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(re.has(e.data.type))return;ee(e.data.type)===ee("FCL:VIEW:CLOSE")&&d(),ee(e.data.type)===ee("FCL:VIEW:READY")&&o(e,{send:l,close:d}),ee(e.data.type)===ee("FCL:VIEW:RESPONSE")&&i(e,{send:l,close:d}),n(e,{send:l,close:d}),ee(e.data.type)===ee("FCL:FRAME:READY")&&(te(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ee(e.data.type)===ee("FCL:FRAME:RESPONSE")&&(te(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),ee(e.data.type)===ee("FCL:FRAME:CLOSE")&&(te(e.data.type,"FCL:VIEW:CLOSE"),d()),ee(e.data.type)===ee("FCL::CHALLENGE::RESPONSE")&&(te(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),ee(e.data.type)===ee("FCL::AUTHZ_READY")&&(te(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ee(e.data.type)===ee("FCL::CHALLENGE::CANCEL")&&(te(e.data.type,"FCL:VIEW:CLOSE"),d()),ee(e.data.type)===ee("FCL::CANCEL")&&(te(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}});var u={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),s&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[t,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,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=U(e.data.result);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var i=a.uid(),s=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ne,close:ne};var r=t.onClose||ne,n=t.onMessage||ne,o=t.onReady||ne,i=t.onResponse||ne;window.addEventListener("message",c);var a=q(k(e)),s=a[0],u=a[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(ae.has(e.data.type))return;oe(e.data.type)===oe("FCL:VIEW:CLOSE")&&d(),oe(e.data.type)===oe("FCL:VIEW:READY")&&o(e,{send:l,close:d}),oe(e.data.type)===oe("FCL:VIEW:RESPONSE")&&i(e,{send:l,close:d}),n(e,{send:l,close:d}),oe(e.data.type)===oe("FCL:FRAME:READY")&&(ie(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),oe(e.data.type)===oe("FCL:FRAME:RESPONSE")&&(ie(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),oe(e.data.type)===oe("FCL:FRAME:CLOSE")&&(ie(e.data.type,"FCL:VIEW:CLOSE"),d()),oe(e.data.type)===oe("FCL::CHALLENGE::RESPONSE")&&(ie(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),oe(e.data.type)===oe("FCL::AUTHZ_READY")&&(ie(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),oe(e.data.type)===oe("FCL::CHALLENGE::CANCEL")&&(ie(e.data.type,"FCL:VIEW:CLOSE"),d()),oe(e.data.type)===oe("FCL::CANCEL")&&(ie(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Popup Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Popup Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}});var u={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),s&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=U(e.data.result);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var i=a.uid(),s=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:se,close:se};var r=t.onClose||se,n=t.onMessage||se,o=t.onReady||se,i=t.onResponse||se;window.addEventListener("message",c);var a=G(k(e)),s=a[0],u=a[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(de.has(e.data.type))return;ue(e.data.type)===ue("FCL:VIEW:CLOSE")&&d(),ue(e.data.type)===ue("FCL:VIEW:READY")&&o(e,{send:l,close:d}),ue(e.data.type)===ue("FCL:VIEW:RESPONSE")&&i(e,{send:l,close:d}),n(e,{send:l,close:d}),ue(e.data.type)===ue("FCL:FRAME:READY")&&(ce(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ue(e.data.type)===ue("FCL:FRAME:RESPONSE")&&(ce(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),ue(e.data.type)===ue("FCL:FRAME:CLOSE")&&(ce(e.data.type,"FCL:VIEW:CLOSE"),d()),ue(e.data.type)===ue("FCL::CHALLENGE::RESPONSE")&&(ce(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),ue(e.data.type)===ue("FCL::AUTHZ_READY")&&(ce(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ue(e.data.type)===ue("FCL::CHALLENGE::CANCEL")&&(ce(e.data.type,"FCL:VIEW:CLOSE"),d()),ue(e.data.type)===ue("FCL::CANCEL")&&(ce(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Tab Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Tab Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}});var u={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),s&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=U(e.data.result);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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")}})})}},pe=function(r,n){try{t.invariant(/^[0-9a-f]+$/i.test(r),"Message must be a hex string"),t.invariant(Array.isArray(n),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(n.map(function(r){try{return t.invariant("string"==typeof r.addr,"addr must be a string"),t.invariant("number"==typeof r.keyId,"keyId must be a number"),t.invariant("string"==typeof r.signature,"signature must be a string"),Promise.resolve(function(t,n){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 n(e)}return s&&s.then?s.then(void 0,n):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(e){return Promise.resolve(P({cadence:""+he,args:function(t,n){return[t(r,n.String),t(e,n.Array([n.String])),t(o,n.Array(n.UFix64)),t(i,n.Array([n.UInt])),t(a,n.Array([n.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 ve(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function me(e,t,r){if(!e.s){if(r instanceof Pe){if(!r.s)return void(r.o=me.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(me.bind(null,e,t),me.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ye=function(e,t){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(pe(e,t))}catch(e){return Promise.reject(e)}},ge=function(e){try{return Ae(),Promise.resolve(Se()).then(function(r){var n=D(r.services,"user-signature");return t.invariant(n,"Current user must have authorized a signing service."),Ce(function(){return Promise.resolve(le({service:n,msg:Te(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return ve(e)}):[ve(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},Ee=function(e){try{return Ae(),Promise.resolve(Se()).then(function(t){var r=D(t.services,"authz"),n=D(t.services,"pre-authz");return b({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(le({service:n,msg:t})).then(Ne)}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(le({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(ve)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Pe=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{me(n,1,i(this.v))}catch(e){me(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?me(n,1,t?t(o):o):r?me(n,1,r(o)):me(n,2,o)}catch(e){me(n,2,e)}},n},e}();function be(e){return e instanceof Pe&&1&e.s}var Se=function(){try{return Promise.resolve(new Promise(function(t,r){try{return Ae(),Promise.resolve(De()).then(function(r){return r.loggedIn&&je(r)?t(r):Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(r){try{if(null==r)throw console.warn('Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),new Error('Required config value "discovery.wallet" is not defined')}catch(e){console.error(e)}return Promise.resolve(e.config.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC")).then(function(e){var i=function(t,i){try{var a=Ce(function(){return Promise.resolve(le({service:{endpoint:r,method:e}})).then(function(e){return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var r,n=C(e.authorizations);!(r=n()).done;)t.push(b({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(b({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,i,a=(n=t,i=r,void 0===n&&(n=[]),void 0===i&&(i=[]),[].concat(n,i)).map(function(t){return function(e,t){try{return N[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),s=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return b({},O,{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){n.send(Re,Oe,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return i(!0,e)}return a&&a.then?a.then(i.bind(null,!1),i.bind(null,!0)):i(!1,a)}(0,function(e,r){return Promise.resolve(De()).then(function(n){if(t(n),e)throw r;return r})});if(i&&i.then)return i.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Ce(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Re="CURRENT_USER",we="CURRENT_USER/UPDATED",Oe="SET_CURRENT_USER",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}',Ie=((Z={})[n.INIT]=function(t){try{return t.merge(JSON.parse(Le)),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 t=JSON.parse(Le);return Promise.resolve(e.get(Re)).then(function(r){return null!=r&&t.f_vsn!==r.f_vsn?(e.removeItem(Re),t):r||t})}catch(e){return Promise.reject(e)}}(e)).then(function(e){je(e)&&t.merge(e)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Z[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,we,b({},e.all()))},Z[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},Z.SNAPSHOT=function(e,t){try{return t.reply(b({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[Oe]=function(t,r,n){try{return t.merge(n),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(Re,t.all()),t.broadcast(we,b({},t.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(t,r){try{return t.merge(JSON.parse(Le)),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(Re,t.all()),t.broadcast(we,b({},t.all()))})}catch(e){return Promise.reject(e)}},Z),Ae=function(){return n.spawn(Ie,Re)};function je(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function xe(){Ae(),n.send(Re,"DEL_CURRENT_USER")}function Ne(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=C(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,a=C(t.authorization||[]);!(i=a()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return le({service:r,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Fe(e){Ae();var t="@EXIT",r=n.spawn(function(r){try{var o;return r.send(Re,n.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(be(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!be(i)){n=1;break}i=i.s}}var a=new Pe,s=me.bind(null,a,2);return(0===n?o.then(c):1===n?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):me(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||be(o)&&!o.v)return void me(a,1,i);if(o.then)return void o.then(c).then(void 0,s);be(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):me(a,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===t)return r.send(Re,n.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return n.send(r,t)}}function De(){return Ae(),n.send(Re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ke,Te=function(e){return t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Ue=function(){return{authenticate:Se,unauthenticate:xe,authorization:Ee,signUserMessage:ge,verifyUserSignatures:ye,subscribe:Fe,snapshot:De}};Ue.authenticate=Se,Ue.unauthenticate=xe,Ue.authorization=Ee,Ue.signUserMessage=ge,Ue.verifyUserSignatures=ye,Ue.subscribe=Fe,Ue.snapshot=De;var _e=function(t){try{return Promise.resolve(e.send([e.getTransactionStatus(t)]).then(e.decode))}catch(e){return Promise.reject(e)}},Ve=function(e){return e.status>=4},Be=function(e){return e.status>=3},Me=function(e){return e.status>=2},ze=((ke={})[n.INIT]=function(e){try{return Promise.resolve(_e(e.self())).then(function(t){Ve(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},ke[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,n.UPDATED,e.all())},ke[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},ke[n.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ke.POLL=function(e){try{return Promise.resolve(_e(e.self())).then(function(t){var r,o;Ve(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),o=t,JSON.stringify(r)!==JSON.stringify(o)&&e.broadcast(n.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},ke),We=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},He=function(e){return n.spawn(ze,We(e))};function Ye(e){function t(t){return n.subscriber(We(e),He,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return n.snapshoter(e,He)},subscribe:t,onceFinalized:r(Me),onceExecuted:r(Be),onceSealed:r(Ve)}}Ye.isUnknown=function(e){return e.status>=0},Ye.isPending=function(e){return e.status>=1},Ye.isFinalized=Me,Ye.isExecuted=Be,Ye.isSealed=Ve,Ye.isExpired=function(e){return 5===e.status};var qe,Je=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Ke=((qe={}).TICK=function(t){try{if(!t.hasSubs())return Promise.resolve();var r=t.get("hwm"),n=function(){if(null==r){var n=t.put;return Promise.resolve(e.latestBlock()).then(function(e){n.call(t,"hwm",e);var r=t.put;return Promise.resolve(Je(t)).then(function(e){r.call(t,"tick",e)})})}return Promise.resolve(e.latestBlock()).then(function(n){return t.put("hwm",n),Promise.resolve(e.send([getEvents(t.self(),r.height,n.height-1)]).then(e.decode)).then(function(e){for(var r,n=C(e);!(r=n()).done;)t.broadcast("UPDATED",r.value.data);var o=t.put;return Promise.resolve(Je(t)).then(function(e){o.call(t,"tick",e)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},qe[n.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(Je(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},qe[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},qe),Ge=function(e){return n.spawn(Ke,e)},Ze=function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(b({},t,{type:e}),"*"):window.opener.postMessage(b({},t,{type:e}),"*")},$e={__proto__:null,sendMsgToFCL:Ze,close:function(){Ze("FCL:VIEW:CLOSE")},approve:function(e){Ze("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){Ze("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var r=function(r){var n=r.data;"object"==typeof n&&null!=typeof n&&n.type===e&&t(function(e){var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e}(n))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},encodeMessageFromSignable:e.encodeMessageFromSignable,CompositeSignature:function(e,t,r){this.f_type=I.f_type,this.f_vsn=I.f_vsn,this.addr=o.withPrefix(e),this.keyId=Number(t),this.signature=r}},Xe=Ue().authorization,Qe=d;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="0.0.77",exports.WalletUtils=$e,exports.authenticate=function(){return Ue().authenticate()},exports.authz=Xe,exports.currentUser=Ue,exports.events=function(e){return{subscribe:function(t){return n.subscriber(e,Ge,t)}}},exports.logIn=function(){return Ue().authenticate()},exports.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(e){try{return t.invariant(h(e),"mutate(opts) -- opts is required"),t.invariant(v(e),"mutate(opts) -- opts must be an object"),t.invariant(h(e.cadence),"mutate({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){t.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",Ue().authorization)).then(function(t){return c.send([c.transaction(e.cadence),c.args(E(e.args||[])),e.limit&&g(e.limit)&&c.limit(e.limit),c.proposer(e.proposer||e.authz||t),c.payer(e.payer||e.authz||t),c.authorizations(e.authorizations||[e.authz||t])]).then(c.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},exports.query=P,exports.reauthenticate=function(){return Ue().unauthenticate(),Ue().authenticate()},exports.serialize=function(t,r){void 0===t&&(t=[]),void 0===r&&(r={});try{return Promise.resolve(e.config.first(["sdk.resolve"],r.resolve||e.resolve)).then(function(r){function n(){return Promise.resolve(r(t)).then(function(t){return JSON.stringify(e.createSignableVoucher(t),null,2)})}var o=function(){if(Array.isArray(t))return Promise.resolve(e.pipe(e.interaction(),t)).then(function(e){t=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return Ue().authenticate()},exports.t=Qe,exports.tx=Ye,exports.unauthenticate=function(){return Ue().unauthenticate()},exports.verifyUserSignatures=pe; | ||
var e=require("@onflow/sdk"),t=require("@onflow/util-invariant"),r=require("@onflow/types"),n=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 t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var c=u(e),d=u(r),l=u(i),f=function(t){try{return Promise.resolve(e.config().where(t)).then(function(e){return Object.fromEntries(Object.entries(e).map(function(e){var r=e[1];return[e[0].replace(t,""),r]}))})}catch(e){return Promise.reject(e)}};e.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,t){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(t)))}catch(e){return Promise.reject(e)}}}});var p=function(e){return function(t){return typeof t===e}},h=function(e){return null!=e},v=p("object"),m=p("string"),y=p("function"),g=p("number");function E(e){return y(e)?e(c.arg,d):[]}var P=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return t.invariant(h(e.cadence),"query({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){t.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(E(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}};function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function C(e,t){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,t){if(e){if("string"==typeof e)return S(e,t);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,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var R={f_type:"Service",f_vsn:"1.0.0"},w={f_type:"Identity",f_vsn:"1.0.0"},O={f_type:"USER",f_vsn:"1.0.0"},L={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({old:e},R,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function x(e){if(null==e)return null;switch(null==e.method&&(e=b({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var N={"back-channel-rpc":j,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{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:A,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":x};function F(e){return l.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function D(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function k(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function T(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(k(e),{method:r,headers:b({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function U(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:b({},e)}),e.f_vsn){case"1.0.0":return e;default:return b({},L,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:j(e.authorizationUpdates),local:A((e.local||[])[0])})}}var _=function e(r,n){void 0===n&&(n=function(){return!0});try{if(t.invariant(r,"Missing Polling Service",{service:r}),!n())throw new Error("Externally Halted");return Promise.resolve(T(r,{method:B(r)}).then(U)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}},V={"HTTP/GET":"GET","HTTP/POST":"POST"},B=function(e){return t.invariant(V[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),V[e.method]},M="FCL_IFRAME";function z(e){t.invariant(!document.getElementById(M),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=M,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(M)&&document.getElementById(M).remove()}]}var W=null,H=null;function Y(e){var t,r;null==W||null!=(t=W)&&t.closed?(r=window,W=r.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=600, top="+(r.top.outerHeight/2+r.top.screenY-300)+", left="+(r.top.outerWidth/2+r.top.screenX-320))):H!==e?(W.location.replace(e),W.focus()):W.focus(),H=e;var n=setInterval(function(){W&&W.closed&&(clearInterval(n),W=null)},1e3);return[W,function(){W&&!W.closed&&(W.close(),W=null)}]}var q=null,J=null;function K(e){var t;null==q||null!=(t=q)&&t.closed?q=window.open(e,"_blank"):J!==e?(q.location.replace(e),q.focus()):q.focus(),J=e;var r=setInterval(function(){q&&q.closed&&(clearInterval(r),q=null)},1e3);return[q,function(){q&&!q.closed&&(q.close(),q=null)}]}var G,Z={"VIEW/IFRAME":z,"VIEW/POP":Y,"VIEW/TAB":K},$=function(e,t,r){try{return t.data=e.data,Promise.resolve(T(e,{data:t}).then(U)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve(Z[e.method](k(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(x(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return _(t.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:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},X=function(){},Q=function(e){return"string"==typeof e&&e.toLowerCase()},ee=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},te=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),re=function(){},ne=function(e){return"string"==typeof e&&e.toLowerCase()},oe=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},ie=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ae=function(){},se=function(e){return"string"==typeof e&&e.toLowerCase()},ue=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},ce=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),de=function(e){var t=e.service,r=e.msg,n=void 0===r?{}:r,o=e.opts,i=void 0===o?{}:o;try{try{return Promise.resolve(le[t.method](t,n,i))}catch(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:n,opts:i}),e}}catch(e){return Promise.reject(e)}},le={"HTTP/RPC":$,"HTTP/POST":$,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var i=a.uid(),s=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:X,close:X};var r=t.onClose||X,n=t.onMessage||X,o=t.onReady||X,i=t.onResponse||X;window.addEventListener("message",c);var a=z(k(e)),s=a[0],u=a[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(te.has(e.data.type))return;Q(e.data.type)===Q("FCL:VIEW:CLOSE")&&d(),Q(e.data.type)===Q("FCL:VIEW:READY")&&o(e,{send:l,close:d}),Q(e.data.type)===Q("FCL:VIEW:RESPONSE")&&i(e,{send:l,close:d}),n(e,{send:l,close:d}),Q(e.data.type)===Q("FCL:FRAME:READY")&&(ee(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Q(e.data.type)===Q("FCL:FRAME:RESPONSE")&&(ee(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),Q(e.data.type)===Q("FCL:FRAME:CLOSE")&&(ee(e.data.type,"FCL:VIEW:CLOSE"),d()),Q(e.data.type)===Q("FCL::CHALLENGE::RESPONSE")&&(ee(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),Q(e.data.type)===Q("FCL::AUTHZ_READY")&&(ee(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Q(e.data.type)===Q("FCL::CHALLENGE::CANCEL")&&(ee(e.data.type,"FCL:VIEW:CLOSE"),d()),Q(e.data.type)===Q("FCL::CANCEL")&&(ee(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}});var u={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),s&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[t,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,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=U(e.data.result);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var i=a.uid(),s=r.redir,u=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:re,close:re};var r=t.onClose||re,n=t.onMessage||re,o=t.onReady||re,i=t.onResponse||re;window.addEventListener("message",c);var a=Y(k(e)),s=a[0],u=a[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(ie.has(e.data.type))return;ne(e.data.type)===ne("FCL:VIEW:CLOSE")&&d(),ne(e.data.type)===ne("FCL:VIEW:READY")&&o(e,{send:l,close:d}),ne(e.data.type)===ne("FCL:VIEW:RESPONSE")&&i(e,{send:l,close:d}),n(e,{send:l,close:d}),ne(e.data.type)===ne("FCL:FRAME:READY")&&(oe(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ne(e.data.type)===ne("FCL:FRAME:RESPONSE")&&(oe(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),ne(e.data.type)===ne("FCL:FRAME:CLOSE")&&(oe(e.data.type,"FCL:VIEW:CLOSE"),d()),ne(e.data.type)===ne("FCL::CHALLENGE::RESPONSE")&&(oe(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),ne(e.data.type)===ne("FCL::AUTHZ_READY")&&(oe(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ne(e.data.type)===ne("FCL::CHALLENGE::CANCEL")&&(oe(e.data.type,"FCL:VIEW:CLOSE"),d()),ne(e.data.type)===ne("FCL::CANCEL")&&(oe(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Popup Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Popup Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}});var s={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:s,config:{services:r,app:n},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:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),!s&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=U(e.data.result);switch(a.status){case"APPROVED":n(a.data),!s&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var i=a.uid(),s=r.redir,u=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ae,close:ae};var r=t.onClose||ae,n=t.onMessage||ae,o=t.onReady||ae,i=t.onResponse||ae;window.addEventListener("message",c);var a=K(k(e)),s=a[0],u=a[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(ce.has(e.data.type))return;se(e.data.type)===se("FCL:VIEW:CLOSE")&&d(),se(e.data.type)===se("FCL:VIEW:READY")&&o(e,{send:l,close:d}),se(e.data.type)===se("FCL:VIEW:RESPONSE")&&i(e,{send:l,close:d}),n(e,{send:l,close:d}),se(e.data.type)===se("FCL:FRAME:READY")&&(ue(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),se(e.data.type)===se("FCL:FRAME:RESPONSE")&&(ue(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),se(e.data.type)===se("FCL:FRAME:CLOSE")&&(ue(e.data.type,"FCL:VIEW:CLOSE"),d()),se(e.data.type)===se("FCL::CHALLENGE::RESPONSE")&&(ue(e.data.type,"FCL:VIEW:RESPONSE"),i(e,{send:l,close:d})),se(e.data.type)===se("FCL::AUTHZ_READY")&&(ue(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),se(e.data.type)===se("FCL::CHALLENGE::CANCEL")&&(ue(e.data.type,"FCL:VIEW:CLOSE"),d()),se(e.data.type)===se("FCL::CANCEL")&&(ue(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Tab Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Tab Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(n){return Promise.resolve(f(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}});var s={params:e.params,data:e.data};return Promise.resolve(f(/^service\./)).then(function(r){return Promise.resolve(f(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:s,config:{services:r,app:n},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:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),!s&&r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=U(e.data.result);switch(a.status){case"APPROVED":n(a.data),!s&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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")}})})}},fe=function(r,n){try{t.invariant(/^[0-9a-f]+$/i.test(r),"Message must be a hex string"),t.invariant(Array.isArray(n),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(n.map(function(r){try{return t.invariant("string"==typeof r.addr,"addr must be a string"),t.invariant("number"==typeof r.keyId,"keyId must be a number"),t.invariant("string"==typeof r.signature,"signature must be a string"),Promise.resolve(function(t,n){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 n(e)}return s&&s.then?s.then(void 0,n):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(e){return Promise.resolve(P({cadence:""+pe,args:function(t,n){return[t(r,n.String),t(e,n.Array([n.String])),t(o,n.Array(n.UFix64)),t(i,n.Array([n.UInt])),t(a,n.Array([n.String]))]}}))})}catch(e){return Promise.reject(e)}},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 he(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function ve(e,t,r){if(!e.s){if(r instanceof Ee){if(!r.s)return void(r.o=ve.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ve.bind(null,e,t),ve.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var me=function(e,t){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(fe(e,t))}catch(e){return Promise.reject(e)}},ye=function(e){try{return Ie(),Promise.resolve(be({redir:!0})).then(function(r){var n=D(r.services,"user-signature");return t.invariant(n,"Current user must have authorized a signing service."),Se(function(){return Promise.resolve(de({service:n,msg:ke(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return he(e)}):[he(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},ge=function(e){try{return Ie(),Promise.resolve(be({redir:!0})).then(function(t){var r=D(t.services,"authz"),n=D(t.services,"pre-authz");return b({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(de({service:n,msg:t})).then(xe)}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(de({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(he)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ee=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{ve(n,1,i(this.v))}catch(e){ve(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ve(n,1,t?t(o):o):r?ve(n,1,r(o)):ve(n,2,o)}catch(e){ve(n,2,e)}},n},e}();function Pe(e){return e instanceof Ee&&1&e.s}var be=function(r){void 0===r&&(r={redir:!1});try{return Promise.resolve(new Promise(function(i,a){try{return Ie(),Promise.resolve(Fe()).then(function(a){return a.loggedIn&&Ae(a)?i(a):Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(a){return t.invariant(a,'Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),Promise.resolve(e.config.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC")).then(function(t){return Promise.resolve(e.config.get("fcl.warning.suppress.redir")).then(function(e){r.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 s=function(e,i){try{var s=Se(function(){return Promise.resolve(de({service:{endpoint:a,method:t},opts:r})).then(function(e){return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var r,n=C(e.authorizations);!(r=n()).done;)t.push(b({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(b({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,i,a=(n=t,i=r,void 0===n&&(n=[]),void 0===i&&(i=[]),[].concat(n,i)).map(function(t){return function(e,t){try{return N[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),s=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return b({},O,{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){n.send(Ce,we,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return i(!0,e)}return s&&s.then?s.then(i.bind(null,!1),i.bind(null,!0)):i(!1,s)}(0,function(e,t){return Promise.resolve(Fe()).then(function(r){if(i(r),e)throw t;return t})});if(s&&s.then)return s.then(function(){})})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Se(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Ce="CURRENT_USER",Re="CURRENT_USER/UPDATED",we="SET_CURRENT_USER",Oe='{\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}',Le=((G={})[n.INIT]=function(t){try{return t.merge(JSON.parse(Oe)),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 t=JSON.parse(Oe);return Promise.resolve(e.get(Ce)).then(function(r){return null!=r&&t.f_vsn!==r.f_vsn?(e.removeItem(Ce),t):r||t})}catch(e){return Promise.reject(e)}}(e)).then(function(e){Ae(e)&&t.merge(e)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},G[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,Re,b({},e.all()))},G[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},G.SNAPSHOT=function(e,t){try{return t.reply(b({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},G[we]=function(t,r,n){try{return t.merge(n),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(Ce,t.all()),t.broadcast(Re,b({},t.all()))})}catch(e){return Promise.reject(e)}},G.DEL_CURRENT_USER=function(t,r){try{return t.merge(JSON.parse(Oe)),Promise.resolve(e.config.first(["fcl.storage","fcl.storage.default"])).then(function(e){e.can&&e.put(Ce,t.all()),t.broadcast(Re,b({},t.all()))})}catch(e){return Promise.reject(e)}},G),Ie=function(){return n.spawn(Le,Ce)};function Ae(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function je(){Ie(),n.send(Ce,"DEL_CURRENT_USER")}function xe(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=C(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,a=C(t.authorization||[]);!(i=a()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return de({service:r,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ne(e){Ie();var t="@EXIT",r=n.spawn(function(r){try{var o;return r.send(Ce,n.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(Pe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Pe(i)){n=1;break}i=i.s}}var a=new Ee,s=ve.bind(null,a,2);return(0===n?o.then(c):1===n?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):ve(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||Pe(o)&&!o.v)return void ve(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):ve(a,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===t)return r.send(Ce,n.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return n.send(r,t)}}function Fe(){return Ie(),n.send(Ce,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var De,ke=function(e){return t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Te=function(){return{authenticate:be,unauthenticate:je,authorization:ge,signUserMessage:ye,verifyUserSignatures:me,subscribe:Ne,snapshot:Fe}};Te.authenticate=be,Te.unauthenticate=je,Te.authorization=ge,Te.signUserMessage=ye,Te.verifyUserSignatures=me,Te.subscribe=Ne,Te.snapshot=Fe;var Ue=function(t){try{return Promise.resolve(e.send([e.getTransactionStatus(t)]).then(e.decode))}catch(e){return Promise.reject(e)}},_e=function(e){return e.status>=4},Ve=function(e){return e.status>=3},Be=function(e){return e.status>=2},Me=((De={})[n.INIT]=function(e){try{return Promise.resolve(Ue(e.self())).then(function(t){_e(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},De[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,n.UPDATED,e.all())},De[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},De[n.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},De.POLL=function(e){try{return Promise.resolve(Ue(e.self())).then(function(t){var r,o;_e(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),o=t,JSON.stringify(r)!==JSON.stringify(o)&&e.broadcast(n.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},De),ze=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},We=function(e){return n.spawn(Me,ze(e))};function He(e){function t(t){return n.subscriber(ze(e),We,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return n.snapshoter(e,We)},subscribe:t,onceFinalized:r(Be),onceExecuted:r(Ve),onceSealed:r(_e)}}He.isUnknown=function(e){return e.status>=0},He.isPending=function(e){return e.status>=1},He.isFinalized=Be,He.isExecuted=Ve,He.isSealed=_e,He.isExpired=function(e){return 5===e.status};var Ye,qe=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Je=((Ye={}).TICK=function(t){try{if(!t.hasSubs())return Promise.resolve();var r=t.get("hwm"),n=function(){if(null==r){var n=t.put;return Promise.resolve(e.latestBlock()).then(function(e){n.call(t,"hwm",e);var r=t.put;return Promise.resolve(qe(t)).then(function(e){r.call(t,"tick",e)})})}return Promise.resolve(e.latestBlock()).then(function(n){return t.put("hwm",n),Promise.resolve(e.send([getEvents(t.self(),r.height,n.height-1)]).then(e.decode)).then(function(e){for(var r,n=C(e);!(r=n()).done;)t.broadcast("UPDATED",r.value.data);var o=t.put;return Promise.resolve(qe(t)).then(function(e){o.call(t,"tick",e)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Ye[n.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(qe(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},Ye[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Ye),Ke=function(e){return n.spawn(Je,e)},Ge=function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(b({},t,{type:e}),"*"):window.opener.postMessage(b({},t,{type:e}),"*")},Ze={__proto__:null,sendMsgToFCL:Ge,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})},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var r=function(r){var n=r.data;"object"==typeof n&&null!=typeof n&&n.type===e&&t(function(e){var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e}(n))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},encodeMessageFromSignable:e.encodeMessageFromSignable,CompositeSignature:function(e,t,r){this.f_type=I.f_type,this.f_vsn=I.f_vsn,this.addr=o.withPrefix(e),this.keyId=Number(t),this.signature=r}},$e=Te().authorization,Xe=d;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="0.0.78-alpha.1",exports.WalletUtils=Ze,exports.authenticate=function(){return Te().authenticate()},exports.authz=$e,exports.currentUser=Te,exports.events=function(e){return{subscribe:function(t){return n.subscriber(e,Ke,t)}}},exports.logIn=function(){return Te().authenticate()},exports.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(e){try{return t.invariant(h(e),"mutate(opts) -- opts is required"),t.invariant(v(e),"mutate(opts) -- opts must be an object"),t.invariant(h(e.cadence),"mutate({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(c.config.get("accessNode.api")).then(function(e){t.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",Te().authorization)).then(function(t){return c.send([c.transaction(e.cadence),c.args(E(e.args||[])),e.limit&&g(e.limit)&&c.limit(e.limit),c.proposer(e.proposer||e.authz||t),c.payer(e.payer||e.authz||t),c.authorizations(e.authorizations||[e.authz||t])]).then(c.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},exports.query=P,exports.reauthenticate=function(){return Te().unauthenticate(),Te().authenticate()},exports.serialize=function(t,r){void 0===t&&(t=[]),void 0===r&&(r={});try{return Promise.resolve(e.config.first(["sdk.resolve"],r.resolve||e.resolve)).then(function(r){function n(){return Promise.resolve(r(t)).then(function(t){return JSON.stringify(e.createSignableVoucher(t),null,2)})}var o=function(){if(Array.isArray(t))return Promise.resolve(e.pipe(e.interaction(),t)).then(function(e){t=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return Te().authenticate()},exports.t=Xe,exports.tx=He,exports.unauthenticate=function(){return Te().unauthenticate()},exports.verifyUserSignatures=fe; | ||
//# sourceMappingURL=fcl.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"@onflow/sdk";import{config as t,send as n,getTransactionStatus as a,decode as r,resolve as s,pipe as o,interaction as i,createSignableVoucher as c,latestBlock as d,encodeMessageFromSignable as l}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 u}from"@onflow/util-invariant";import*as p from"@onflow/types";import{spawn as f,send as y,SUBSCRIBE as E,UNSUBSCRIBE as g,INIT as m,subscriber as h,snapshoter as w,UPDATED as C,SNAPSHOT as R}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as v}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as L from"@onflow/rlp";import{uid as P}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";async function A(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":{can:!0,get:async e=>JSON.parse(sessionStorage.getItem(e)),put:async(e,t)=>sessionStorage.setItem(e,JSON.stringify(t))}});const I="0.0.77",b=e=>t=>typeof t===e,F=e=>null!=e,O=b("object"),N=b("string"),D=b("function"),k=b("number");function T(t){return D(t)?t(e.arg,p):[]}async function _(t={}){return await async function(t){u(F(t.cadence),"query({ cadence }) -- cadence is required"),u(N(t.cadence),"query({ cadence }) -- cadence must be a string"),u(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(T(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function V(){return(V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const x={f_type:"Service",f_vsn:"1.0.0"},U={f_type:"Identity",f_vsn:"1.0.0"},W={f_type:"USER",f_vsn:"1.0.0"},M={f_type:"PollingResponse",f_vsn:"1.0.0"},z={f_type:"CompositeSignature",f_vsn:"1.0.0"};function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({old:e},x,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function H(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function Y(e){if(null==e)return null;switch(null==e.method&&(e=V({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}const $={"back-channel-rpc":H,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:j,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":Y};function B(e){return L.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function J(e=[],t){return e.find(e=>e.type===t)}function q(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 K(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(q(e),{method:n,headers:V({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function G(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:V({},e)}),e.f_vsn){case"1.0.0":return e;default:return V({},M,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:H(e.authorizationUpdates),local:j((e.local||[])[0])})}}const Z={"HTTP/GET":"GET","HTTP/POST":"POST"},X=e=>(u(Z[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Z[e.method]);async function Q(e,t=(()=>!0)){if(u(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await K(e,{method:X(e)}).then(G);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)),Q(n.updates,t)}}const ee="FCL_IFRAME";function te(e){u(!document.getElementById(ee),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=ee,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(ee)&&document.getElementById(ee).remove()}]}let ne=null,ae=null;function re(e,t,n,a,r){return n.open(e,t,`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${a}, height=${r}, top=${n.top.outerHeight/2+n.top.screenY-r/2}, left=${n.top.outerWidth/2+n.top.screenX-a/2}`)}function se(e){var t;null==ne||null!=(t=ne)&&t.closed?ne=re(e,"FCL_POP",window,640,600):ae!==e?(ne=re(e,"FCL_POP",window,640,600),ne.focus()):ne.focus(),ae=e;var n=setInterval(function(){ne&&ne.closed&&(clearInterval(n),ne=null)},1e3);return[ne,()=>{ne&&!ne.closed&&(ne.close(),ne=null)}]}let oe=null,ie=null;function ce(e){var t;null==oe||null!=(t=oe)&&t.closed?oe=window.open(e,"_blank"):ie!==e?(oe=window.open(e,"_blank"),oe.focus()):oe.focus(),ie=e;var n=setInterval(function(){oe&&oe.closed&&(clearInterval(n),oe=null)},1e3);return[oe,()=>{oe&&!oe.closed&&(oe.close(),oe=null)}]}const de={"VIEW/IFRAME":te,"VIEW/POP":se,"VIEW/TAB":ce};async function le(e,t,n={}){t.data=e.data;const a=await K(e,{data:t}).then(G);if("APPROVED"===a.status)return a.data;if("DECLINED"===a.status)throw new Error(`Declined: ${a.reason||"No reason supplied."}`);if("PENDING"===a.status){var r=!0;const[e,t]=await async function(e,t={}){try{return de[e.method](q(e),t)}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}(Y(a.local)),n=()=>{try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return Q(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 ue=()=>{},pe=e=>"string"==typeof e&&e.toLowerCase(),fe=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),ye=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Ee=()=>{},ge=e=>"string"==typeof e&&e.toLowerCase(),me=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),he=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),we=()=>{},Ce=e=>"string"==typeof e&&e.toLowerCase(),Re=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),Se=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ve={"HTTP/RPC":le,"HTTP/POST":le,"IFRAME/RPC":function(e,t,n){return new Promise((a,r)=>{const s=P(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:ue,close:ue};const n=t.onClose||ue,a=t.onMessage||ue,r=t.onReady||ue,s=t.onResponse||ue;window.addEventListener("message",c);const[o,i]=te(q(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(ye.has(e.data.type))return;pe(e.data.type)===pe("FCL:VIEW:CLOSE")&&d(),pe(e.data.type)===pe("FCL:VIEW:READY")&&r(e,{send:l,close:d}),pe(e.data.type)===pe("FCL:VIEW:RESPONSE")&&s(e,{send:l,close:d}),a(e,{send:l,close:d}),pe(e.data.type)===pe("FCL:FRAME:READY")&&(fe(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),pe(e.data.type)===pe("FCL:FRAME:RESPONSE")&&(fe(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),pe(e.data.type)===pe("FCL:FRAME:CLOSE")&&(fe(e.data.type,"FCL:VIEW:CLOSE"),d()),pe(e.data.type)===pe("FCL::CHALLENGE::RESPONSE")&&(fe(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),pe(e.data.type)===pe("FCL::AUTHZ_READY")&&(fe(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),pe(e.data.type)===pe("FCL::CHALLENGE::CANCEL")&&(fe(e.data.type,"FCL:VIEW:CLOSE"),d()),pe(e.data.type)===pe("FCL::CANCEL")&&(fe(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),n()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)}}),a({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),o&&a({jsonrpc:"2.0",id:s,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=G(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),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!==s)return;const n=G(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),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=P(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:Ee,close:Ee};const n=t.onClose||Ee,a=t.onMessage||Ee,r=t.onReady||Ee,s=t.onResponse||Ee;window.addEventListener("message",c);const[o,i]=se(q(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(he.has(e.data.type))return;ge(e.data.type)===ge("FCL:VIEW:CLOSE")&&d(),ge(e.data.type)===ge("FCL:VIEW:READY")&&r(e,{send:l,close:d}),ge(e.data.type)===ge("FCL:VIEW:RESPONSE")&&s(e,{send:l,close:d}),a(e,{send:l,close:d}),ge(e.data.type)===ge("FCL:FRAME:READY")&&(me(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),ge(e.data.type)===ge("FCL:FRAME:RESPONSE")&&(me(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),ge(e.data.type)===ge("FCL:FRAME:CLOSE")&&(me(e.data.type,"FCL:VIEW:CLOSE"),d()),ge(e.data.type)===ge("FCL::CHALLENGE::RESPONSE")&&(me(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),ge(e.data.type)===ge("FCL::AUTHZ_READY")&&(me(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),ge(e.data.type)===ge("FCL::CHALLENGE::CANCEL")&&(me(e.data.type,"FCL:VIEW:CLOSE"),d()),ge(e.data.type)===ge("FCL::CANCEL")&&(me(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Popup Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),n()}catch(e){console.error("Popup Close Error",e)}}function l(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)}}),a({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),o&&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=G(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),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=G(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),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=P(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:we,close:we};const n=t.onClose||we,a=t.onMessage||we,r=t.onReady||we,s=t.onResponse||we;window.addEventListener("message",c);const[o,i]=ce(q(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(Se.has(e.data.type))return;Ce(e.data.type)===Ce("FCL:VIEW:CLOSE")&&d(),Ce(e.data.type)===Ce("FCL:VIEW:READY")&&r(e,{send:l,close:d}),Ce(e.data.type)===Ce("FCL:VIEW:RESPONSE")&&s(e,{send:l,close:d}),a(e,{send:l,close:d}),Ce(e.data.type)===Ce("FCL:FRAME:READY")&&(Re(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),Ce(e.data.type)===Ce("FCL:FRAME:RESPONSE")&&(Re(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),Ce(e.data.type)===Ce("FCL:FRAME:CLOSE")&&(Re(e.data.type,"FCL:VIEW:CLOSE"),d()),Ce(e.data.type)===Ce("FCL::CHALLENGE::RESPONSE")&&(Re(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),Ce(e.data.type)===Ce("FCL::AUTHZ_READY")&&(Re(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),Ce(e.data.type)===Ce("FCL::CHALLENGE::CANCEL")&&(Re(e.data.type,"FCL:VIEW:CLOSE"),d()),Ce(e.data.type)===Ce("FCL::CANCEL")&&(Re(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Tab Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),n()}catch(e){console.error("Tab Close Error",e)}}function l(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{async onReady(n,{send:a}){try{a({type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)}}),a({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),o&&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=G(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),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=G(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})}};async function Le({service:e,msg:t={},opts:n={}}){try{return ve[e.method](e,t,n)}catch(a){throw console.error("execService({service, msg = {}, opts = {}})",a,{service:e,msg:t,opts:n}),a}}async function Pe(e,t){u(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),u(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[],r=[];const s=await Promise.all(t.map(async e=>{u("string"==typeof e.addr,"addr must be a string"),u("number"==typeof e.keyId,"keyId must be a number"),u("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 _({cadence:`${Ae}`,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 Ae="\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 Ie(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},z,{addr:v(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const be="CURRENT_USER",Fe="CURRENT_USER/UPDATED",Oe='{\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={[m]:async e=>{e.merge(JSON.parse(Oe));const n=await t.first(["fcl.storage","fcl.storage.default"]);if(n.can){const t=await(async e=>{const t=JSON.parse(Oe),n=await e.get(be);return null!=n&&t.f_vsn!==n.f_vsn?(e.removeItem(be),t):n||t})(n);ke(t)&&e.merge(t)}},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Fe,V({},e.all()))},[g]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(V({},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(be,e.all()),e.broadcast(Fe,V({},e.all()))},DEL_CURRENT_USER:async(e,n)=>{e.merge(JSON.parse(Oe));const a=await t.first(["fcl.storage","fcl.storage.default"]);a.can&&a.put(be,e.all()),e.broadcast(Fe,V({},e.all()))}},De=()=>f(Ne,be);function ke(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Te(){return new Promise(async(e,n)=>{De();const a=await Ue();if(a.loggedIn&&ke(a))return e(a);const r=await t.first(["discovery.wallet","challenge.handshake"]);try{if(null==r)throw console.warn('Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),new Error('Required config value "discovery.wallet" is not defined')}catch(e){console.error(e)}const s=await t.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC");try{const t=await Le({service:{endpoint:r,method:s}});y(be,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(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(V({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(V({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return $[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 V({},W,{addr:S(e.addr),cid:B(n),loggedIn:!0,services:t,expiresAt:e.exp})}(t))}catch(e){console.error("Error while authenticating",e)}finally{e(await Ue())}})}function _e(){De(),y(be,"DEL_CURRENT_USER")}async function Ve(e){De();const t=await Te(),n=J(t.services,"authz"),a=J(t.services,"pre-authz");return V({},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=>Le({service:t,msg:e}),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await Le({service:a,msg:t}))}:{tempId:"CURRENT_USER",resolve:null,addr:v(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>Ie(await Le({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}}))})}function xe(e){De();const t="@EXIT",n=f(async n=>{for(n.send(be,E);;){const a=await n.receive();if(a.tag===t)return void n.send(be,g);e(a.data)}});return()=>y(n,t)}function Ue(){return De(),y(be,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const We=e=>(u(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e});async function Me(e){De();const t=J((await Te()).services,"user-signature");u(t,"Current user must have authorized a signing service.");try{const n=await Le({service:t,msg:We(e)});return Array.isArray(n)?n.map(e=>Ie(e)):[Ie(n)]}catch(e){return e}}async function ze(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;"),Pe(e,t)}let je=()=>({authenticate:Te,unauthenticate:_e,authorization:Ve,signUserMessage:Me,verifyUserSignatures:ze,subscribe:xe,snapshot:Ue});je.authenticate=Te,je.unauthenticate=_e,je.authorization=Ve,je.signUserMessage=Me,je.verifyUserSignatures=ze,je.subscribe=xe,je.snapshot=Ue;const He=async e=>n([a(e)]).then(r),Ye=e=>e.status>=4,$e=e=>e.status>=3,Be=e=>e.status>=2,Je={[m]: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,C,e.all())},[g]:(e,t)=>{e.unsubscribe(t.from)},[R]: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(C,t),e.merge(t)}},qe=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ke=e=>f(Je,qe(e));function Ge(e){function t(t){return h(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 w(e,Ke)},subscribe:t,onceFinalized:n(Be),onceExecuted:n($e),onceSealed:n(Ye)}}async function Ze(t={}){try{await async function(t){u(F(t),"mutate(opts) -- opts is required"),u(O(t),"mutate(opts) -- opts must be an object"),u(F(t.cadence),"mutate({ cadence }) -- cadence is required"),u(N(t.cadence),"mutate({ cadence }) -- cadence must be a string"),u(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 n=await e.config().get("fcl.authz",je().authorization);return e.send([e.transaction(t.cadence),e.args(T(t.args||[])),t.limit&&k(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||n),e.payer(t.payer||t.authz||n),e.authorizations(t.authorizations||[t.authz||n])]).then(e.decode)}catch(e){throw e}}Ge.isUnknown=e=>e.status>=0,Ge.isPending=e=>e.status>=1,Ge.isFinalized=Be,Ge.isExecuted=$e,Ge.isSealed=Ye,Ge.isExpired=e=>5===e.status;const Xe=async(e=[],n={})=>{const a=await t.first(["sdk.resolve"],n.resolve||s);return Array.isArray(e)&&(e=await o(i(),e)),JSON.stringify(c(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 d()),e.put("tick",await Qe(e));else{let a=await d();e.put("hwm",a);const s=await n([getEvents(e.self(),t.height,a.height-1)]).then(r);for(let t of s)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)},[g]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},tt=e=>f(et,e);function nt(e){return{subscribe:t=>h(e,tt,t)}}const at=(e,t={})=>{window.location!==window.parent.location?window.parent.postMessage(V({},t,{type:e}),"*"):window.opener.postMessage(V({},t,{type:e}),"*")};var rt={__proto__:null,sendMsgToFCL:at,close:()=>{at("FCL:VIEW:CLOSE")},approve:e=>{at("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:e=>{at("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:(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)},encodeMessageFromSignable:l,CompositeSignature:function(e,t,n){this.f_type=z.f_type,this.f_vsn=z.f_vsn,this.addr=S(e),this.keyId=Number(t),this.signature=n}};const st=()=>je().authenticate(),ot=()=>je().unauthenticate(),it=()=>(je().unauthenticate(),je().authenticate()),ct=()=>je().authenticate(),dt=()=>je().authenticate(),lt=je().authorization,ut=p;export{I as VERSION,rt as WalletUtils,st as authenticate,lt as authz,je as currentUser,nt as events,dt as logIn,Ze as mutate,_ as query,it as reauthenticate,Xe as serialize,ct as signUp,ut as t,Ge as tx,ot as unauthenticate,Pe as verifyUserSignatures}; | ||
import*as e from"@onflow/sdk";import{config as t,send as a,getTransactionStatus as n,decode as r,resolve as s,pipe as o,interaction as i,createSignableVoucher as c,latestBlock as d,encodeMessageFromSignable as l}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 u}from"@onflow/util-invariant";import*as p from"@onflow/types";import{spawn as f,send as y,SUBSCRIBE as E,UNSUBSCRIBE as g,INIT as m,subscriber as h,snapshoter as w,UPDATED as C,SNAPSHOT as R}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as v}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as L from"@onflow/rlp";import{uid as P}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";async function A(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,a])=>[t.replace(e,""),a]))}t({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:async e=>JSON.parse(sessionStorage.getItem(e)),put:async(e,t)=>sessionStorage.setItem(e,JSON.stringify(t))}});const b="0.0.78-alpha.1",I=e=>t=>typeof t===e,F=e=>null!=e,N=I("object"),O=I("string"),D=I("function"),k=I("number");function T(t){return D(t)?t(e.arg,p):[]}async function _(t={}){return await async function(t){u(F(t.cadence),"query({ cadence }) -- cadence is required"),u(O(t.cadence),"query({ cadence }) -- cadence must be a string"),u(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(T(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function V(){return(V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}const x={f_type:"Service",f_vsn:"1.0.0"},U={f_type:"Identity",f_vsn:"1.0.0"},W={f_type:"USER",f_vsn:"1.0.0"},M={f_type:"PollingResponse",f_vsn:"1.0.0"},z={f_type:"CompositeSignature",f_vsn:"1.0.0"};function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({old:e},x,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Y(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function H(e){if(null==e)return null;switch(null==e.method&&(e=V({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}const B={"back-channel-rpc":Y,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},x,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:j,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":H};function $(e){return L.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function J(e=[],t){return e.find(e=>e.type===t)}function q(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[a,n]of Object.entries(e.params||{}))t.searchParams.append(a,n);return t}function K(e,t={}){const a=t.method||"POST",n="GET"===a?void 0:JSON.stringify(t.data||e.data||{});return fetch(q(e),{method:a,headers:V({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(e=>e.json())}function G(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:V({},e)}),e.f_vsn){case"1.0.0":return e;default:return V({},M,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:Y(e.authorizationUpdates),local:j((e.local||[])[0])})}}const Z={"HTTP/GET":"GET","HTTP/POST":"POST"},X=e=>(u(Z[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Z[e.method]);async function Q(e,t=(()=>!0)){if(u(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const a=await K(e,{method:X(e)}).then(G);switch(a.status){case"APPROVED":return a.data;case"DECLINED":throw new Error(`Declined: ${a.reason||"No reason supplied."}`);default:return await new Promise(e=>setTimeout(e,500)),Q(a.updates,t)}}const ee="FCL_IFRAME";function te(e){u(!document.getElementById(ee),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=ee,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(ee)&&document.getElementById(ee).remove()}]}let ae=null,ne=null;function re(e){var t,a;null==ae||null!=(t=ae)&&t.closed?(a=window,ae=a.open(e,"FCL_POP",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=600, top=${a.top.outerHeight/2+a.top.screenY-300}, left=${a.top.outerWidth/2+a.top.screenX-320}`)):ne!==e?(ae.location.replace(e),ae.focus()):ae.focus(),ne=e;var n=setInterval(function(){ae&&ae.closed&&(clearInterval(n),ae=null)},1e3);return[ae,()=>{ae&&!ae.closed&&(ae.close(),ae=null)}]}let se=null,oe=null;function ie(e){var t;null==se||null!=(t=se)&&t.closed?se=window.open(e,"_blank"):oe!==e?(se.location.replace(e),se.focus()):se.focus(),oe=e;var a=setInterval(function(){se&&se.closed&&(clearInterval(a),se=null)},1e3);return[se,()=>{se&&!se.closed&&(se.close(),se=null)}]}const ce={"VIEW/IFRAME":te,"VIEW/POP":re,"VIEW/TAB":ie};async function de(e,t,a={}){t.data=e.data;const n=await K(e,{data:t}).then(G);if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error(`Declined: ${n.reason||"No reason supplied."}`);if("PENDING"===n.status){var r=!0;const[e,t]=await async function(e,t={}){try{return ce[e.method](q(e),t)}catch(a){throw console.error("execLocal({service, opts = {}})",a,{service:e,opts:t}),a}}(H(n.local)),a=()=>{try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return Q(n.updates,()=>r).then(e=>(a(),e)).catch(e=>{throw console.error(e),a(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")}const le=()=>{},ue=e=>"string"==typeof e&&e.toLowerCase(),pe=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ye=()=>{},Ee=e=>"string"==typeof e&&e.toLowerCase(),ge=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),me=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),he=()=>{},we=e=>"string"==typeof e&&e.toLowerCase(),Ce=(e,t)=>console.warn("DEPRECATION NOTICE",`Received ${e}, please use ${t} for this and future versions of FCL`),Re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Se={"HTTP/RPC":de,"HTTP/POST":de,"IFRAME/RPC":function(e,t,a){return new Promise((n,r)=>{const s=P(),o=a.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:le,close:le};const a=t.onClose||le,n=t.onMessage||le,r=t.onReady||le,s=t.onResponse||le;window.addEventListener("message",c);const[o,i]=te(q(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(fe.has(e.data.type))return;ue(e.data.type)===ue("FCL:VIEW:CLOSE")&&d(),ue(e.data.type)===ue("FCL:VIEW:READY")&&r(e,{send:l,close:d}),ue(e.data.type)===ue("FCL:VIEW:RESPONSE")&&s(e,{send:l,close:d}),n(e,{send:l,close:d}),ue(e.data.type)===ue("FCL:FRAME:READY")&&(pe(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),ue(e.data.type)===ue("FCL:FRAME:RESPONSE")&&(pe(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),ue(e.data.type)===ue("FCL:FRAME:CLOSE")&&(pe(e.data.type,"FCL:VIEW:CLOSE"),d()),ue(e.data.type)===ue("FCL::CHALLENGE::RESPONSE")&&(pe(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),ue(e.data.type)===ue("FCL::AUTHZ_READY")&&(pe(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),ue(e.data.type)===ue("FCL::CHALLENGE::CANCEL")&&(pe(e.data.type,"FCL:VIEW:CLOSE"),d()),ue(e.data.type)===ue("FCL::CANCEL")&&(pe(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),a()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{async onReady(a,{send:n}){try{n({type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)}}),n({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),o&&n({jsonrpc:"2.0",id:s,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 a=G(e.data);switch(a.status){case"APPROVED":n(a.data),t();break;case"DECLINED":r(`Declined: ${a.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC 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 a=G(e.data.result);switch(a.status){case"APPROVED":n(a.data),t();break;case"DECLINED":r(`Declined: ${a.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"POP/RPC":function(e,t,a){return new Promise((n,r)=>{const s=P(),{redir:o,includeOlderJsonRpcCall:i}=a;t.data=e.data,function(e,t={}){if(null==e)return{send:ye,close:ye};const a=t.onClose||ye,n=t.onMessage||ye,r=t.onReady||ye,s=t.onResponse||ye;window.addEventListener("message",c);const[o,i]=re(q(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(me.has(e.data.type))return;Ee(e.data.type)===Ee("FCL:VIEW:CLOSE")&&d(),Ee(e.data.type)===Ee("FCL:VIEW:READY")&&r(e,{send:l,close:d}),Ee(e.data.type)===Ee("FCL:VIEW:RESPONSE")&&s(e,{send:l,close:d}),n(e,{send:l,close:d}),Ee(e.data.type)===Ee("FCL:FRAME:READY")&&(ge(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL:FRAME:RESPONSE")&&(ge(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL:FRAME:CLOSE")&&(ge(e.data.type,"FCL:VIEW:CLOSE"),d()),Ee(e.data.type)===Ee("FCL::CHALLENGE::RESPONSE")&&(ge(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL::AUTHZ_READY")&&(ge(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL::CHALLENGE::CANCEL")&&(ge(e.data.type,"FCL:VIEW:CLOSE"),d()),Ee(e.data.type)===Ee("FCL::CANCEL")&&(ge(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Popup Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),a()}catch(e){console.error("Popup Close Error",e)}}function l(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{async onReady(a,{send:n}){try{n({type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)}}),n({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&n({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 a=G(e.data);switch(a.status){case"APPROVED":n(a.data),!o&&t();break;case"DECLINED":r(`Declined: ${a.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("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 a=G(e.data.result);switch(a.status){case"APPROVED":n(a.data),!o&&t();break;case"DECLINED":r(`Declined: ${a.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})},"TAB/RPC":function(e,t,a){return new Promise((n,r)=>{const s=P(),{redir:o,includeOlderJsonRpcCall:i}=a;t.data=e.data,function(e,t={}){if(null==e)return{send:he,close:he};const a=t.onClose||he,n=t.onMessage||he,r=t.onReady||he,s=t.onResponse||he;window.addEventListener("message",c);const[o,i]=ie(q(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(Re.has(e.data.type))return;we(e.data.type)===we("FCL:VIEW:CLOSE")&&d(),we(e.data.type)===we("FCL:VIEW:READY")&&r(e,{send:l,close:d}),we(e.data.type)===we("FCL:VIEW:RESPONSE")&&s(e,{send:l,close:d}),n(e,{send:l,close:d}),we(e.data.type)===we("FCL:FRAME:READY")&&(Ce(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),we(e.data.type)===we("FCL:FRAME:RESPONSE")&&(Ce(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),we(e.data.type)===we("FCL:FRAME:CLOSE")&&(Ce(e.data.type,"FCL:VIEW:CLOSE"),d()),we(e.data.type)===we("FCL::CHALLENGE::RESPONSE")&&(Ce(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),we(e.data.type)===we("FCL::AUTHZ_READY")&&(Ce(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),we(e.data.type)===we("FCL::CHALLENGE::CANCEL")&&(Ce(e.data.type,"FCL:VIEW:CLOSE"),d()),we(e.data.type)===we("FCL::CANCEL")&&(Ce(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Tab Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),i(),a()}catch(e){console.error("Tab Close Error",e)}}function l(e){try{o.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{async onReady(a,{send:n}){try{n({type:"FCL:VIEW:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)}}),n({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await A(/^service\./),app:await A(/^app\.detail\./)},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&n({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 a=G(e.data);switch(a.status){case"APPROVED":n(a.data),!o&&t();break;case"DECLINED":r(`Declined: ${a.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("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 a=G(e.data.result);switch(a.status){case"APPROVED":n(a.data),!o&&t();break;case"DECLINED":r(`Declined: ${a.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execPopRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})}};async function ve({service:e,msg:t={},opts:a={}}){try{return Se[e.method](e,t,a)}catch(n){throw console.error("execService({service, msg = {}, opts = {}})",n,{service:e,msg:t,opts:a}),n}}async function Le(e,t){u(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),u(Array.isArray(t),"Must include an Array of composite signatures");let a=[],n=[],r=[];const s=await Promise.all(t.map(async e=>{u("string"==typeof e.addr,"addr must be a string"),u("number"==typeof e.keyId,"keyId must be a number"),u("string"==typeof e.signature,"signature must be a string");try{const t=await t(e.addr);return a.push(t.keys[e.keyId].weight.toFixed(1)),n.push(t.keys[e.keyId].signAlgo),r.push(e.signature),t.keys[e.keyId].publicKey}catch(e){throw e}}));return await _({cadence:`${Pe}`,args:(t,o)=>[t(e,o.String),t(s,o.Array([o.String])),t(a,o.Array(o.UFix64)),t(n,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){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},z,{addr:v(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const be="CURRENT_USER",Ie="CURRENT_USER/UPDATED",Fe='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ne={[m]:async e=>{e.merge(JSON.parse(Fe));const a=await t.first(["fcl.storage","fcl.storage.default"]);if(a.can){const t=await(async e=>{const t=JSON.parse(Fe),a=await e.get(be);return null!=a&&t.f_vsn!==a.f_vsn?(e.removeItem(be),t):a||t})(a);De(t)&&e.merge(t)}},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Ie,V({},e.all()))},[g]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(V({},e.all()))},SET_CURRENT_USER:async(e,a,n)=>{e.merge(n);const r=await t.first(["fcl.storage","fcl.storage.default"]);r.can&&r.put(be,e.all()),e.broadcast(Ie,V({},e.all()))},DEL_CURRENT_USER:async(e,a)=>{e.merge(JSON.parse(Fe));const n=await t.first(["fcl.storage","fcl.storage.default"]);n.can&&n.put(be,e.all()),e.broadcast(Ie,V({},e.all()))}},Oe=()=>f(Ne,be);function De(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function ke(e={redir:!1}){return new Promise(async(a,n)=>{Oe();const r=await xe();if(r.loggedIn&&De(r))return a(r);const s=await t.first(["discovery.wallet","challenge.handshake"]);u(s,'Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration');const o=await t.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC"),i=await t.get("fcl.warning.suppress.redir");e.redir&&!i&&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 ve({service:{endpoint:s,method:o},opts:e});y(be,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(e.paddr):null,e}(e)).services||[],await async function(e,t){if(null==e||null==t)return[];const a=new URL(e);a.searchParams.append("code",t);const n=await fetch(a,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(n))return n;const r=[];if(Array.isArray(n.authorizations))for(let e of n.authorizations)r.push(V({type:"authz",keyId:n.keyId},e));return null!=n.provider&&r.push(V({type:"authn",id:"wallet-provider#authn"},n.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return B[e.type](e,t)}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));const a=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return V({},W,{addr:S(e.addr),cid:$(a),loggedIn:!0,services:t,expiresAt:e.exp})}(t))}catch(e){console.error("Error while authenticating",e)}finally{a(await xe())}})}function Te(){Oe(),y(be,"DEL_CURRENT_USER")}async function _e(e){Oe();const t=await ke({redir:!0}),a=J(t.services,"authz"),n=J(t.services,"pre-authz");return V({},e,n?{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),a=[];null!=t.proposer&&a.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])a.push(["PAYER",e]);for(let e of t.authorization||[])a.push(["AUTHORIZER",e]);return a.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>ve({service:t,msg:e}),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await ve({service:n,msg:t}))}:{tempId:"CURRENT_USER",resolve:null,addr:v(a.identity.address),keyId:a.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>Ae(await ve({service:a,msg:e,opts:{includeOlderJsonRpcCall:!0}}))})}function Ve(e){Oe();const t="@EXIT",a=f(async a=>{for(a.send(be,E);;){const n=await a.receive();if(n.tag===t)return void a.send(be,g);e(n.data)}});return()=>y(a,t)}function xe(){return Oe(),y(be,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ue=e=>(u(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e});async function We(e){Oe();const t=J((await ke({redir:!0})).services,"user-signature");u(t,"Current user must have authorized a signing service.");try{const a=await ve({service:t,msg:Ue(e)});return Array.isArray(a)?a.map(e=>Ae(e)):[Ae(a)]}catch(e){return e}}async function Me(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;"),Le(e,t)}let ze=()=>({authenticate:ke,unauthenticate:Te,authorization:_e,signUserMessage:We,verifyUserSignatures:Me,subscribe:Ve,snapshot:xe});ze.authenticate=ke,ze.unauthenticate=Te,ze.authorization=_e,ze.signUserMessage=We,ze.verifyUserSignatures=Me,ze.subscribe=Ve,ze.snapshot=xe;const je=async e=>a([n(e)]).then(r),Ye=e=>e.status>=4,He=e=>e.status>=3,Be=e=>e.status>=2,$e={[m]:async e=>{const t=await je(e.self());Ye(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,C,e.all())},[g]:(e,t)=>{e.unsubscribe(t.from)},[R]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await je(e.self());var a,n;Ye(t)||setTimeout(()=>e.sendSelf("POLL"),2500),a=e.all(),n=t,JSON.stringify(a)!==JSON.stringify(n)&&e.broadcast(C,t),e.merge(t)}},Je=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},qe=e=>f($e,Je(e));function Ke(e){function t(t){return h(Je(e),qe,t)}function a(e){return function(a={}){const n=a.suppress||!1;return new Promise((a,r)=>{const s=t(t=>{t.statusCode&&!n?(r(t.errorMessage),s()):e(t)&&(a(t),s())})})}}return{snapshot:function(){return w(e,qe)},subscribe:t,onceFinalized:a(Be),onceExecuted:a(He),onceSealed:a(Ye)}}async function Ge(t={}){try{await async function(t){u(F(t),"mutate(opts) -- opts is required"),u(N(t),"mutate(opts) -- opts must be an object"),u(F(t.cadence),"mutate({ cadence }) -- cadence is required"),u(O(t.cadence),"mutate({ cadence }) -- cadence must be a string"),u(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 e.send([e.transaction(t.cadence),e.args(T(t.args||[])),t.limit&&k(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)}catch(e){throw e}}Ke.isUnknown=e=>e.status>=0,Ke.isPending=e=>e.status>=1,Ke.isFinalized=Be,Ke.isExecuted=He,Ke.isSealed=Ye,Ke.isExpired=e=>5===e.status;const Ze=async(e=[],a={})=>{const n=await t.first(["sdk.resolve"],a.resolve||s);return Array.isArray(e)&&(e=await o(i(),e)),JSON.stringify(c(await n(e)),null,2)},Xe=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),Qe={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await d()),e.put("tick",await Xe(e));else{let n=await d();e.put("hwm",n);const s=await a([getEvents(e.self(),t.height,n.height-1)]).then(r);for(let t of s)e.broadcast("UPDATED",t.data);e.put("tick",await Xe(e))}},[E]:async(e,t)=>{e.hasSubs()||e.put("tick",await Xe(e)),e.subscribe(t.from)},[g]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},et=e=>f(Qe,e);function tt(e){return{subscribe:t=>h(e,et,t)}}const at=(e,t={})=>{window.location!==window.parent.location?window.parent.postMessage(V({},t,{type:e}),"*"):window.opener.postMessage(V({},t,{type:e}),"*")};var nt={__proto__:null,sendMsgToFCL:at,close:()=>{at("FCL:VIEW:CLOSE")},approve:e=>{at("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:e=>{at("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:(e,t=(()=>{}))=>{const a=a=>{const{data:n}=a;"object"==typeof n&&null!=typeof n&&n.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})(n))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},encodeMessageFromSignable:l,CompositeSignature:function(e,t,a){this.f_type=z.f_type,this.f_vsn=z.f_vsn,this.addr=S(e),this.keyId=Number(t),this.signature=a}};const rt=()=>ze().authenticate(),st=()=>ze().unauthenticate(),ot=()=>(ze().unauthenticate(),ze().authenticate()),it=()=>ze().authenticate(),ct=()=>ze().authenticate(),dt=ze().authorization,lt=p;export{b as VERSION,nt as WalletUtils,rt as authenticate,dt as authz,ze as currentUser,tt as events,ct as logIn,Ge as mutate,_ as query,ot as reauthenticate,Ze as serialize,it as signUp,lt as t,Ke as tx,st as unauthenticate,Le as verifyUserSignatures}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"@onflow/sdk";import{config as t,account as r,send as n,getTransactionStatus as o,decode as a,resolve as i,createSignableVoucher as s,pipe as c,interaction as u,latestBlock as d,encodeMessageFromSignable as l}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 p from"@onflow/types";import{INIT as h,SUBSCRIBE as v,UNSUBSCRIBE as m,spawn as y,send as E,UPDATED as g,SNAPSHOT as P,subscriber as C,snapshoter as R}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as w}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as L from"@onflow/rlp";import{uid as b}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";var A=function(e){try{return Promise.resolve(t().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var r=t[1];return[t[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}};t({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,t){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(t)))}catch(e){return Promise.reject(e)}}}});var I="0.0.77",F=function(e){return function(t){return typeof t===e}},O=function(e){return null!=e},N=F("object"),D=F("string"),k=F("function"),j=F("number");function T(t){return k(t)?t(e.arg,p):[]}var _=function(t){void 0===t&&(t={});try{return Promise.resolve(function(t){try{return f(O(t.cadence),"query({ cadence }) -- cadence is required"),f(D(t.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){f(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)}}(t)).then(function(){return e.send([e.script(t.cadence),e.args(T(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function V(){return(V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function M(e,t){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,t){if(e){if("string"==typeof e)return x(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var W={f_type:"Service",f_vsn:"1.0.0"},U={f_type:"Identity",f_vsn:"1.0.0"},z={f_type:"USER",f_vsn:"1.0.0"},H={f_type:"PollingResponse",f_vsn:"1.0.0"},Y={f_type:"CompositeSignature",f_vsn:"1.0.0"};function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({old:e},W,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function J(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function q(e){if(null==e)return null;switch(null==e.method&&(e=V({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var K={"back-channel-rpc":J,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:B,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":q};function G(e){return L.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Z(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function $(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function X(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch($(e),{method:r,headers:V({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function Q(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:V({},e)}),e.f_vsn){case"1.0.0":return e;default:return V({},H,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:J(e.authorizationUpdates),local:B((e.local||[])[0])})}}var ee=function e(t,r){void 0===r&&(r=function(){return!0});try{if(f(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(X(t,{method:re(t)}).then(Q)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}},te={"HTTP/GET":"GET","HTTP/POST":"POST"},re=function(e){return f(te[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),te[e.method]},ne="FCL_IFRAME";function oe(e){f(!document.getElementById(ne),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=ne,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,function(){document.getElementById(ne)&&document.getElementById(ne).remove()}]}var ae=null,ie=null;function se(e,t,r,n,o){return r.open(e,t,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+n+", height="+o+", top="+(r.top.outerHeight/2+r.top.screenY-o/2)+", left="+(r.top.outerWidth/2+r.top.screenX-n/2))}function ce(e){var t;null==ae||null!=(t=ae)&&t.closed?ae=se(e,"FCL_POP",window,640,600):ie!==e?(ae=se(e,"FCL_POP",window,640,600)).focus():ae.focus(),ie=e;var r=setInterval(function(){ae&&ae.closed&&(clearInterval(r),ae=null)},1e3);return[ae,function(){ae&&!ae.closed&&(ae.close(),ae=null)}]}var ue=null,de=null;function le(e){var t;null==ue||null!=(t=ue)&&t.closed?ue=window.open(e,"_blank"):de!==e?(ue=window.open(e,"_blank")).focus():ue.focus(),de=e;var r=setInterval(function(){ue&&ue.closed&&(clearInterval(r),ue=null)},1e3);return[ue,function(){ue&&!ue.closed&&(ue.close(),ue=null)}]}var fe,pe={"VIEW/IFRAME":oe,"VIEW/POP":ce,"VIEW/TAB":le},he=function(e,t,r){try{return t.data=e.data,Promise.resolve(X(e,{data:t}).then(Q)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve(pe[e.method]($(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(q(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return ee(t.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:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},ve=function(){},me=function(e){return"string"==typeof e&&e.toLowerCase()},ye=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},Ee=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ge=function(){},Pe=function(e){return"string"==typeof e&&e.toLowerCase()},Ce=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},Re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Se=function(){},we=function(e){return"string"==typeof e&&e.toLowerCase()},Le=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},be=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Ae=function(e){var t=e.service,r=e.msg,n=void 0===r?{}:r,o=e.opts,a=void 0===o?{}:o;try{try{return Promise.resolve(Ie[t.method](t,n,a))}catch(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:n,opts:a}),e}}catch(e){return Promise.reject(e)}},Ie={"HTTP/RPC":he,"HTTP/POST":he,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var a=b(),i=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ve,close:ve};var r=t.onClose||ve,n=t.onMessage||ve,o=t.onReady||ve,a=t.onResponse||ve;window.addEventListener("message",u);var i=oe($(e)),s=i[0],c=i[1];return{send:l,close:d};function u(e){try{if("object"!=typeof e.data)return;if(Ee.has(e.data.type))return;me(e.data.type)===me("FCL:VIEW:CLOSE")&&d(),me(e.data.type)===me("FCL:VIEW:READY")&&o(e,{send:l,close:d}),me(e.data.type)===me("FCL:VIEW:RESPONSE")&&a(e,{send:l,close:d}),n(e,{send:l,close:d}),me(e.data.type)===me("FCL:FRAME:READY")&&(ye(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),me(e.data.type)===me("FCL:FRAME:RESPONSE")&&(ye(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),me(e.data.type)===me("FCL:FRAME:CLOSE")&&(ye(e.data.type,"FCL:VIEW:CLOSE"),d()),me(e.data.type)===me("FCL::CHALLENGE::RESPONSE")&&(ye(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),me(e.data.type)===me("FCL::AUTHZ_READY")&&(ye(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),me(e.data.type)===me("FCL::CHALLENGE::CANCEL")&&(ye(e.data.type,"FCL:VIEW:CLOSE"),d()),me(e.data.type)===me("FCL::CANCEL")&&(ye(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",u),c(),r()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(n){return Promise.resolve(A(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}});var c={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(r){return Promise.resolve(A(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:c,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[t,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,t){var r=t.close;try{if("object"!=typeof e.data)return;var a=Q(e.data);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var i=Q(e.data.result);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var a=b(),i=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ge,close:ge};var r=t.onClose||ge,n=t.onMessage||ge,o=t.onReady||ge,a=t.onResponse||ge;window.addEventListener("message",u);var i=ce($(e)),s=i[0],c=i[1];return{send:l,close:d};function u(e){try{if("object"!=typeof e.data)return;if(Re.has(e.data.type))return;Pe(e.data.type)===Pe("FCL:VIEW:CLOSE")&&d(),Pe(e.data.type)===Pe("FCL:VIEW:READY")&&o(e,{send:l,close:d}),Pe(e.data.type)===Pe("FCL:VIEW:RESPONSE")&&a(e,{send:l,close:d}),n(e,{send:l,close:d}),Pe(e.data.type)===Pe("FCL:FRAME:READY")&&(Ce(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL:FRAME:RESPONSE")&&(Ce(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL:FRAME:CLOSE")&&(Ce(e.data.type,"FCL:VIEW:CLOSE"),d()),Pe(e.data.type)===Pe("FCL::CHALLENGE::RESPONSE")&&(Ce(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL::AUTHZ_READY")&&(Ce(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL::CHALLENGE::CANCEL")&&(Ce(e.data.type,"FCL:VIEW:CLOSE"),d()),Pe(e.data.type)===Pe("FCL::CANCEL")&&(Ce(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Popup Callback Error",e),d()}}function d(){try{window.removeEventListener("message",u),c(),r()}catch(e){console.error("Popup Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(n){return Promise.resolve(A(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}});var c={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(r){return Promise.resolve(A(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:c,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var a=Q(e.data);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var i=Q(e.data.result);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var a=b(),i=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:Se,close:Se};var r=t.onClose||Se,n=t.onMessage||Se,o=t.onReady||Se,a=t.onResponse||Se;window.addEventListener("message",u);var i=le($(e)),s=i[0],c=i[1];return{send:l,close:d};function u(e){try{if("object"!=typeof e.data)return;if(be.has(e.data.type))return;we(e.data.type)===we("FCL:VIEW:CLOSE")&&d(),we(e.data.type)===we("FCL:VIEW:READY")&&o(e,{send:l,close:d}),we(e.data.type)===we("FCL:VIEW:RESPONSE")&&a(e,{send:l,close:d}),n(e,{send:l,close:d}),we(e.data.type)===we("FCL:FRAME:READY")&&(Le(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),we(e.data.type)===we("FCL:FRAME:RESPONSE")&&(Le(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),we(e.data.type)===we("FCL:FRAME:CLOSE")&&(Le(e.data.type,"FCL:VIEW:CLOSE"),d()),we(e.data.type)===we("FCL::CHALLENGE::RESPONSE")&&(Le(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),we(e.data.type)===we("FCL::AUTHZ_READY")&&(Le(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),we(e.data.type)===we("FCL::CHALLENGE::CANCEL")&&(Le(e.data.type,"FCL:VIEW:CLOSE"),d()),we(e.data.type)===we("FCL::CANCEL")&&(Le(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Tab Callback Error",e),d()}}function d(){try{window.removeEventListener("message",u),c(),r()}catch(e){console.error("Tab Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(n){return Promise.resolve(A(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}});var c={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(r){return Promise.resolve(A(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:c,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var a=Q(e.data);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var i=Q(e.data.result);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),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")}})})}},Fe=function(e,t){try{f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),f(Array.isArray(t),"Must include an Array of composite signatures");var n=[],o=[],a=[];return Promise.resolve(Promise.all(t.map(function(e){try{return 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"),Promise.resolve(function(t,i){try{var s=Promise.resolve(r(e.addr)).then(function(t){return n.push(t.keys[e.keyId].weight.toFixed(1)),o.push(t.keys[e.keyId].signAlgo),a.push(e.signature),t.keys[e.keyId].publicKey})}catch(e){return i(e)}return s&&s.then?s.then(void 0,i):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(_({cadence:""+Oe,args:function(r,i){return[r(e,i.String),r(t,i.Array([i.String])),r(n,i.Array(i.UFix64)),r(o,i.Array([i.UInt])),r(a,i.Array([i.String]))]}}))})}catch(e){return Promise.reject(e)}},Oe="\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){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},Y,{addr:w(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function De(e,t,r){if(!e.s){if(r instanceof _e){if(!r.s)return void(r.o=De.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(De.bind(null,e,t),De.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ke=function(e,t){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(Fe(e,t))}catch(e){return Promise.reject(e)}},je=function(e){try{return Be(),Promise.resolve(xe()).then(function(t){var r=Z(t.services,"user-signature");return f(r,"Current user must have authorized a signing service."),Me(function(){return Promise.resolve(Ae({service:r,msg:Xe(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)}},Te=function(e){try{return Be(),Promise.resolve(xe()).then(function(t){var r=Z(t.services,"authz"),n=Z(t.services,"pre-authz");return V({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Ae({service:n,msg:t})).then(Ke)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:w(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)}},_e=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var a=1&o?t:r;if(a){try{De(n,1,a(this.v))}catch(e){De(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?De(n,1,t?t(o):o):r?De(n,1,r(o)):De(n,2,o)}catch(e){De(n,2,e)}},n},e}();function Ve(e){return e instanceof _e&&1&e.s}var xe=function(){try{return Promise.resolve(new Promise(function(e,r){try{return Be(),Promise.resolve(Ze()).then(function(r){return r.loggedIn&&Je(r)?e(r):Promise.resolve(t.first(["discovery.wallet","challenge.handshake"])).then(function(r){try{if(null==r)throw console.warn('Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),new Error('Required config value "discovery.wallet" is not defined')}catch(e){console.error(e)}return Promise.resolve(t.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC")).then(function(t){var n=function(e,n){try{var o=Me(function(){return Promise.resolve(Ae({service:{endpoint:r,method:t}})).then(function(e){return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var r,n=M(e.authorizations);!(r=n()).done;)t.push(V({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(V({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,a=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return 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)}),i=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return V({},z,{addr:S(e.addr),cid:G(i),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){E(We,ze,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return n(!0,e)}return o&&o.then?o.then(n.bind(null,!1),n.bind(null,!0)):n(!1,o)}(0,function(t,r){return Promise.resolve(Ze()).then(function(n){if(e(n),t)throw r;return r})});if(n&&n.then)return n.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Me(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var We="CURRENT_USER",Ue="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=((fe={})[h]=function(e){try{return e.merge(JSON.parse(He)),Promise.resolve(t.first(["fcl.storage","fcl.storage.default"])).then(function(t){var r=function(){if(t.can)return Promise.resolve(function(e){try{var t=JSON.parse(He);return Promise.resolve(e.get(We)).then(function(r){return null!=r&&t.f_vsn!==r.f_vsn?(e.removeItem(We),t):r||t})}catch(e){return Promise.reject(e)}}(t)).then(function(t){Je(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},fe[v]=function(e,t){e.subscribe(t.from),e.send(t.from,Ue,V({},e.all()))},fe[m]=function(e,t){e.unsubscribe(t.from)},fe.SNAPSHOT=function(e,t){try{return t.reply(V({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},fe[ze]=function(e,r,n){try{return e.merge(n),Promise.resolve(t.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(We,e.all()),e.broadcast(Ue,V({},e.all()))})}catch(e){return Promise.reject(e)}},fe.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(He)),Promise.resolve(t.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(We,e.all()),e.broadcast(Ue,V({},e.all()))})}catch(e){return Promise.reject(e)}},fe),Be=function(){return y(Ye,We)};function Je(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function qe(){Be(),E(We,"DEL_CURRENT_USER")}function Ke(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=M(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var a,i=M(t.authorization||[]);!(a=i()).done;)r.push(["AUTHORIZER",a.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Ae({service:r,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ge(e){Be();var t="@EXIT",r=y(function(r){try{var n;return r.send(We,v),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(Ve(o)&&(o=o.v),!o)return a;if(o.then){n=0;break}var a=r();if(a&&a.then){if(!Ve(a)){n=1;break}a=a.s}}var i=new _e,s=De.bind(null,i,2);return(0===n?o.then(u):1===n?a.then(c):(void 0).then(function(){(o=e())?o.then?o.then(u).then(void 0,s):u(o):De(i,1,a)})).then(void 0,s),i;function c(t){a=t;do{if(!(o=e())||Ve(o)&&!o.v)return void De(i,1,a);if(o.then)return void o.then(u).then(void 0,s);Ve(a=r())&&(a=a.v)}while(!a||!a.then);a.then(c).then(void 0,s)}function u(e){e?(a=r())&&a.then?a.then(c).then(void 0,s):c(a):De(i,1,a)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if(o.tag===t)return r.send(We,m),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return E(r,t)}}function Ze(){return Be(),E(We,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var $e,Xe=function(e){return f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Qe=function(){return{authenticate:xe,unauthenticate:qe,authorization:Te,signUserMessage:je,verifyUserSignatures:ke,subscribe:Ge,snapshot:Ze}};Qe.authenticate=xe,Qe.unauthenticate=qe,Qe.authorization=Te,Qe.signUserMessage=je,Qe.verifyUserSignatures=ke,Qe.subscribe=Ge,Qe.snapshot=Ze;var et=function(e){try{return Promise.resolve(n([o(e)]).then(a))}catch(e){return Promise.reject(e)}},tt=function(e){return e.status>=4},rt=function(e){return e.status>=3},nt=function(e){return e.status>=2},ot=(($e={})[h]=function(e){try{return Promise.resolve(et(e.self())).then(function(t){tt(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},$e[v]=function(e,t){e.subscribe(t.from),e.send(t.from,g,e.all())},$e[m]=function(e,t){e.unsubscribe(t.from)},$e[P]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},$e.POLL=function(e){try{return Promise.resolve(et(e.self())).then(function(t){var r,n;tt(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(g,t),e.merge(t)})}catch(e){return Promise.reject(e)}},$e),at=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},it=function(e){return y(ot,at(e))};function st(e){function t(t){return C(at(e),it,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var a=t(function(t){t.statusCode&&!n?(o(t.errorMessage),a()):e(t)&&(r(t),a())})})}}return{snapshot:function(){return R(e,it)},subscribe:t,onceFinalized:r(nt),onceExecuted:r(rt),onceSealed:r(tt)}}st.isUnknown=function(e){return e.status>=0},st.isPending=function(e){return e.status>=1},st.isFinalized=nt,st.isExecuted=rt,st.isSealed=tt,st.isExpired=function(e){return 5===e.status};var ct,ut=function(t){void 0===t&&(t={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(t){try{return f(O(t),"mutate(opts) -- opts is required"),f(N(t),"mutate(opts) -- opts must be an object"),f(O(t.cadence),"mutate({ cadence }) -- cadence is required"),f(D(t.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){f(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)}}(t)).then(function(){return Promise.resolve(e.config().get("fcl.authz",Qe().authorization)).then(function(r){return e.send([e.transaction(t.cadence),e.args(T(t.args||[])),t.limit&&j(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||r),e.payer(t.payer||t.authz||r),e.authorizations(t.authorizations||[t.authz||r])]).then(e.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},dt=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.first(["sdk.resolve"],r.resolve||i)).then(function(t){function r(){return Promise.resolve(t(e)).then(function(e){return JSON.stringify(s(e),null,2)})}var n=function(){if(Array.isArray(e))return Promise.resolve(c(u(),e)).then(function(t){e=t})}();return n&&n.then?n.then(r):r()})}catch(e){return Promise.reject(e)}},lt=function(e){try{var r=setTimeout;return Promise.resolve(t().get("fcl.eventPollRate",1e4)).then(function(t){return r(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},ft=((ct={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(d()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(lt(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(d()).then(function(r){return e.put("hwm",r),Promise.resolve(n([getEvents(e.self(),t.height,r.height-1)]).then(a)).then(function(t){for(var r,n=M(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(lt(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ct[v]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(lt(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},ct[m]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ct),pt=function(e){return y(ft,e)};function ht(e){return{subscribe:function(t){return C(e,pt,t)}}}var vt=function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(V({},t,{type:e}),"*"):window.opener.postMessage(V({},t,{type:e}),"*")},mt={__proto__:null,sendMsgToFCL:vt,close:function(){vt("FCL:VIEW:CLOSE")},approve:function(e){vt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){vt("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var r=function(r){var n=r.data;"object"==typeof n&&null!=typeof n&&n.type===e&&t(function(e){var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e}(n))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},encodeMessageFromSignable:l,CompositeSignature:function(e,t,r){this.f_type=Y.f_type,this.f_vsn=Y.f_vsn,this.addr=S(e),this.keyId=Number(t),this.signature=r}},yt=function(){return Qe().authenticate()},Et=function(){return Qe().unauthenticate()},gt=function(){return Qe().unauthenticate(),Qe().authenticate()},Pt=function(){return Qe().authenticate()},Ct=function(){return Qe().authenticate()},Rt=Qe().authorization,St=p;export{I as VERSION,mt as WalletUtils,yt as authenticate,Rt as authz,Qe as currentUser,ht as events,Ct as logIn,ut as mutate,_ as query,gt as reauthenticate,dt as serialize,Pt as signUp,St as t,st as tx,Et as unauthenticate,Fe as verifyUserSignatures}; | ||
import*as e from"@onflow/sdk";import{config as t,account as r,send as n,getTransactionStatus as o,decode as a,resolve as i,createSignableVoucher as s,pipe as u,interaction as c,latestBlock as d,encodeMessageFromSignable as l}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 p from"@onflow/types";import{INIT as h,SUBSCRIBE as v,UNSUBSCRIBE as m,spawn as y,send as E,UPDATED as g,SNAPSHOT as P,subscriber as C,snapshoter as R}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as w}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as L from"@onflow/rlp";import{uid as b}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";var A=function(e){try{return Promise.resolve(t().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var r=t[1];return[t[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}};t({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,t){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(t)))}catch(e){return Promise.reject(e)}}}});var I="0.0.78-alpha.1",F=function(e){return function(t){return typeof t===e}},O=function(e){return null!=e},N=F("object"),D=F("string"),k=F("function"),j=F("number");function T(t){return k(t)?t(e.arg,p):[]}var _=function(t){void 0===t&&(t={});try{return Promise.resolve(function(t){try{return f(O(t.cadence),"query({ cadence }) -- cadence is required"),f(D(t.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){f(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)}}(t)).then(function(){return e.send([e.script(t.cadence),e.args(T(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function V(){return(V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function M(e,t){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,t){if(e){if("string"==typeof e)return x(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var W={f_type:"Service",f_vsn:"1.0.0"},U={f_type:"Identity",f_vsn:"1.0.0"},z={f_type:"USER",f_vsn:"1.0.0"},Y={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({old:e},W,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function J(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function q(e){if(null==e)return null;switch(null==e.method&&(e=V({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var K={"back-channel-rpc":J,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:V({},U,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},W,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:B,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":q};function G(e){return L.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Z(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function $(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function X(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch($(e),{method:r,headers:V({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function Q(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:V({},e)}),e.f_vsn){case"1.0.0":return e;default:return V({},Y,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:J(e.authorizationUpdates),local:B((e.local||[])[0])})}}var ee=function e(t,r){void 0===r&&(r=function(){return!0});try{if(f(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(X(t,{method:re(t)}).then(Q)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}},te={"HTTP/GET":"GET","HTTP/POST":"POST"},re=function(e){return f(te[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),te[e.method]},ne="FCL_IFRAME";function oe(e){f(!document.getElementById(ne),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=ne,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,function(){document.getElementById(ne)&&document.getElementById(ne).remove()}]}var ae=null,ie=null;function se(e){var t,r;null==ae||null!=(t=ae)&&t.closed?(r=window,ae=r.open(e,"FCL_POP","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=600, top="+(r.top.outerHeight/2+r.top.screenY-300)+", left="+(r.top.outerWidth/2+r.top.screenX-320))):ie!==e?(ae.location.replace(e),ae.focus()):ae.focus(),ie=e;var n=setInterval(function(){ae&&ae.closed&&(clearInterval(n),ae=null)},1e3);return[ae,function(){ae&&!ae.closed&&(ae.close(),ae=null)}]}var ue=null,ce=null;function de(e){var t;null==ue||null!=(t=ue)&&t.closed?ue=window.open(e,"_blank"):ce!==e?(ue.location.replace(e),ue.focus()):ue.focus(),ce=e;var r=setInterval(function(){ue&&ue.closed&&(clearInterval(r),ue=null)},1e3);return[ue,function(){ue&&!ue.closed&&(ue.close(),ue=null)}]}var le,fe={"VIEW/IFRAME":oe,"VIEW/POP":se,"VIEW/TAB":de},pe=function(e,t,r){try{return t.data=e.data,Promise.resolve(X(e,{data:t}).then(Q)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve(fe[e.method]($(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(q(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return ee(t.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:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},he=function(){},ve=function(e){return"string"==typeof e&&e.toLowerCase()},me=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},ye=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Ee=function(){},ge=function(e){return"string"==typeof e&&e.toLowerCase()},Pe=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},Ce=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Re=function(){},Se=function(e){return"string"==typeof e&&e.toLowerCase()},we=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},Le=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),be=function(e){var t=e.service,r=e.msg,n=void 0===r?{}:r,o=e.opts,a=void 0===o?{}:o;try{try{return Promise.resolve(Ae[t.method](t,n,a))}catch(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:n,opts:a}),e}}catch(e){return Promise.reject(e)}},Ae={"HTTP/RPC":pe,"HTTP/POST":pe,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var a=b(),i=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:he,close:he};var r=t.onClose||he,n=t.onMessage||he,o=t.onReady||he,a=t.onResponse||he;window.addEventListener("message",c);var i=oe($(e)),s=i[0],u=i[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(ye.has(e.data.type))return;ve(e.data.type)===ve("FCL:VIEW:CLOSE")&&d(),ve(e.data.type)===ve("FCL:VIEW:READY")&&o(e,{send:l,close:d}),ve(e.data.type)===ve("FCL:VIEW:RESPONSE")&&a(e,{send:l,close:d}),n(e,{send:l,close:d}),ve(e.data.type)===ve("FCL:FRAME:READY")&&(me(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ve(e.data.type)===ve("FCL:FRAME:RESPONSE")&&(me(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),ve(e.data.type)===ve("FCL:FRAME:CLOSE")&&(me(e.data.type,"FCL:VIEW:CLOSE"),d()),ve(e.data.type)===ve("FCL::CHALLENGE::RESPONSE")&&(me(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),ve(e.data.type)===ve("FCL::AUTHZ_READY")&&(me(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ve(e.data.type)===ve("FCL::CHALLENGE::CANCEL")&&(me(e.data.type,"FCL:VIEW:CLOSE"),d()),ve(e.data.type)===ve("FCL::CANCEL")&&(me(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(n){return Promise.resolve(A(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}});var u={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(r){return Promise.resolve(A(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),i&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[t,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,t){var r=t.close;try{if("object"!=typeof e.data)return;var a=Q(e.data);switch(a.status){case"APPROVED":n(a.data),r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var i=Q(e.data.result);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var a=b(),i=r.redir,s=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:Ee,close:Ee};var r=t.onClose||Ee,n=t.onMessage||Ee,o=t.onReady||Ee,a=t.onResponse||Ee;window.addEventListener("message",c);var i=se($(e)),s=i[0],u=i[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(Ce.has(e.data.type))return;ge(e.data.type)===ge("FCL:VIEW:CLOSE")&&d(),ge(e.data.type)===ge("FCL:VIEW:READY")&&o(e,{send:l,close:d}),ge(e.data.type)===ge("FCL:VIEW:RESPONSE")&&a(e,{send:l,close:d}),n(e,{send:l,close:d}),ge(e.data.type)===ge("FCL:FRAME:READY")&&(Pe(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ge(e.data.type)===ge("FCL:FRAME:RESPONSE")&&(Pe(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),ge(e.data.type)===ge("FCL:FRAME:CLOSE")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),d()),ge(e.data.type)===ge("FCL::CHALLENGE::RESPONSE")&&(Pe(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),ge(e.data.type)===ge("FCL::AUTHZ_READY")&&(Pe(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),ge(e.data.type)===ge("FCL::CHALLENGE::CANCEL")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),d()),ge(e.data.type)===ge("FCL::CANCEL")&&(Pe(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Popup Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Popup Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(n){return Promise.resolve(A(/^app\.detail\./)).then(function(i){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:i}});var u={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(r){return Promise.resolve(A(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),s&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var a=Q(e.data);switch(a.status){case"APPROVED":n(a.data),!i&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var s=Q(e.data.result);switch(s.status){case"APPROVED":n(s.data),!i&&r();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),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,t,r){return new Promise(function(n,o){var a=b(),i=r.redir,s=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:Re,close:Re};var r=t.onClose||Re,n=t.onMessage||Re,o=t.onReady||Re,a=t.onResponse||Re;window.addEventListener("message",c);var i=de($(e)),s=i[0],u=i[1];return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(Le.has(e.data.type))return;Se(e.data.type)===Se("FCL:VIEW:CLOSE")&&d(),Se(e.data.type)===Se("FCL:VIEW:READY")&&o(e,{send:l,close:d}),Se(e.data.type)===Se("FCL:VIEW:RESPONSE")&&a(e,{send:l,close:d}),n(e,{send:l,close:d}),Se(e.data.type)===Se("FCL:FRAME:READY")&&(we(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Se(e.data.type)===Se("FCL:FRAME:RESPONSE")&&(we(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Se(e.data.type)===Se("FCL:FRAME:CLOSE")&&(we(e.data.type,"FCL:VIEW:CLOSE"),d()),Se(e.data.type)===Se("FCL::CHALLENGE::RESPONSE")&&(we(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Se(e.data.type)===Se("FCL::AUTHZ_READY")&&(we(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Se(e.data.type)===Se("FCL::CHALLENGE::CANCEL")&&(we(e.data.type,"FCL:VIEW:CLOSE"),d()),Se(e.data.type)===Se("FCL::CANCEL")&&(we(e.data.type,"FCL:VIEW:CLOSE"),d())}catch(e){console.error("Tab Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Tab Close Error",e)}}function l(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{onReady:function(r,n){var o=n.send;try{return Promise.resolve(function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){var r={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(n){return Promise.resolve(A(/^app\.detail\./)).then(function(i){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:i}});var u={params:e.params,data:e.data};return Promise.resolve(A(/^service\./)).then(function(r){return Promise.resolve(A(/^app\.detail\./)).then(function(n){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:r,app:n},deprecated:{message:"FCL:FRAME:READY:RESPONSE is deprecated and replaced with type: FCL:VIEW:READY:RESPONSE"}}),s&&o({jsonrpc:"2.0",id:a,method:"fcl:sign",params:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var a=Q(e.data);switch(a.status){case"APPROVED":n(a.data),!i&&r();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==a)return;var s=Q(e.data.result);switch(s.status){case"APPROVED":n(s.data),!i&&r();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),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")}})})}},Ie=function(e,t){try{f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),f(Array.isArray(t),"Must include an Array of composite signatures");var n=[],o=[],a=[];return Promise.resolve(Promise.all(t.map(function(e){try{return 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"),Promise.resolve(function(t,i){try{var s=Promise.resolve(r(e.addr)).then(function(t){return n.push(t.keys[e.keyId].weight.toFixed(1)),o.push(t.keys[e.keyId].signAlgo),a.push(e.signature),t.keys[e.keyId].publicKey})}catch(e){return i(e)}return s&&s.then?s.then(void 0,i):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(_({cadence:""+Fe,args:function(r,i){return[r(e,i.String),r(t,i.Array([i.String])),r(n,i.Array(i.UFix64)),r(o,i.Array([i.UInt])),r(a,i.Array([i.String]))]}}))})}catch(e){return Promise.reject(e)}},Fe="\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 Oe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return V({},H,{addr:w(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function Ne(e,t,r){if(!e.s){if(r instanceof Te){if(!r.s)return void(r.o=Ne.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Ne.bind(null,e,t),Ne.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var De=function(e,t){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(Ie(e,t))}catch(e){return Promise.reject(e)}},ke=function(e){try{return He(),Promise.resolve(Ve({redir:!0})).then(function(t){var r=Z(t.services,"user-signature");return f(r,"Current user must have authorized a signing service."),xe(function(){return Promise.resolve(be({service:r,msg:$e(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Oe(e)}):[Oe(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},je=function(e){try{return He(),Promise.resolve(Ve({redir:!0})).then(function(t){var r=Z(t.services,"authz"),n=Z(t.services,"pre-authz");return V({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(be({service:n,msg:t})).then(qe)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:w(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(be({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(Oe)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Te=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var a=1&o?t:r;if(a){try{Ne(n,1,a(this.v))}catch(e){Ne(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ne(n,1,t?t(o):o):r?Ne(n,1,r(o)):Ne(n,2,o)}catch(e){Ne(n,2,e)}},n},e}();function _e(e){return e instanceof Te&&1&e.s}var Ve=function(e){void 0===e&&(e={redir:!1});try{return Promise.resolve(new Promise(function(r,n){try{return He(),Promise.resolve(Ge()).then(function(n){return n.loggedIn&&Be(n)?r(n):Promise.resolve(t.first(["discovery.wallet","challenge.handshake"])).then(function(n){return f(n,'Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),Promise.resolve(t.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC")).then(function(o){return Promise.resolve(t.get("fcl.warning.suppress.redir")).then(function(t){e.redir&&!t&&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 a=function(t,r){try{var a=xe(function(){return Promise.resolve(be({service:{endpoint:n,method:o},opts:e})).then(function(e){return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var r,n=M(e.authorizations);!(r=n()).done;)t.push(V({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(V({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,a=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return 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)}),i=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return V({},z,{addr:S(e.addr),cid:G(i),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){E(Me,Ue,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return r(!0,e)}return a&&a.then?a.then(r.bind(null,!1),r.bind(null,!0)):r(!1,a)}(0,function(e,t){return Promise.resolve(Ge()).then(function(n){if(r(n),e)throw t;return t})});if(a&&a.then)return a.then(function(){})})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function xe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Me="CURRENT_USER",We="CURRENT_USER/UPDATED",Ue="SET_CURRENT_USER",ze='{\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=((le={})[h]=function(e){try{return e.merge(JSON.parse(ze)),Promise.resolve(t.first(["fcl.storage","fcl.storage.default"])).then(function(t){var r=function(){if(t.can)return Promise.resolve(function(e){try{var t=JSON.parse(ze);return Promise.resolve(e.get(Me)).then(function(r){return null!=r&&t.f_vsn!==r.f_vsn?(e.removeItem(Me),t):r||t})}catch(e){return Promise.reject(e)}}(t)).then(function(t){Be(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},le[v]=function(e,t){e.subscribe(t.from),e.send(t.from,We,V({},e.all()))},le[m]=function(e,t){e.unsubscribe(t.from)},le.SNAPSHOT=function(e,t){try{return t.reply(V({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},le[Ue]=function(e,r,n){try{return e.merge(n),Promise.resolve(t.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(Me,e.all()),e.broadcast(We,V({},e.all()))})}catch(e){return Promise.reject(e)}},le.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(ze)),Promise.resolve(t.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(Me,e.all()),e.broadcast(We,V({},e.all()))})}catch(e){return Promise.reject(e)}},le),He=function(){return y(Ye,Me)};function Be(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Je(){He(),E(Me,"DEL_CURRENT_USER")}function qe(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=M(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var a,i=M(t.authorization||[]);!(a=i()).done;)r.push(["AUTHORIZER",a.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return be({service:r,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ke(e){He();var t="@EXIT",r=y(function(r){try{var n;return r.send(Me,v),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(_e(o)&&(o=o.v),!o)return a;if(o.then){n=0;break}var a=r();if(a&&a.then){if(!_e(a)){n=1;break}a=a.s}}var i=new Te,s=Ne.bind(null,i,2);return(0===n?o.then(c):1===n?a.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ne(i,1,a)})).then(void 0,s),i;function u(t){a=t;do{if(!(o=e())||_e(o)&&!o.v)return void Ne(i,1,a);if(o.then)return void o.then(c).then(void 0,s);_e(a=r())&&(a=a.v)}while(!a||!a.then);a.then(u).then(void 0,s)}function c(e){e?(a=r())&&a.then?a.then(u).then(void 0,s):u(a):Ne(i,1,a)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if(o.tag===t)return r.send(Me,m),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return E(r,t)}}function Ge(){return He(),E(Me,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ze,$e=function(e){return f(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Xe=function(){return{authenticate:Ve,unauthenticate:Je,authorization:je,signUserMessage:ke,verifyUserSignatures:De,subscribe:Ke,snapshot:Ge}};Xe.authenticate=Ve,Xe.unauthenticate=Je,Xe.authorization=je,Xe.signUserMessage=ke,Xe.verifyUserSignatures=De,Xe.subscribe=Ke,Xe.snapshot=Ge;var Qe=function(e){try{return Promise.resolve(n([o(e)]).then(a))}catch(e){return Promise.reject(e)}},et=function(e){return e.status>=4},tt=function(e){return e.status>=3},rt=function(e){return e.status>=2},nt=((Ze={})[h]=function(e){try{return Promise.resolve(Qe(e.self())).then(function(t){et(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},Ze[v]=function(e,t){e.subscribe(t.from),e.send(t.from,g,e.all())},Ze[m]=function(e,t){e.unsubscribe(t.from)},Ze[P]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Ze.POLL=function(e){try{return Promise.resolve(Qe(e.self())).then(function(t){var r,n;et(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(g,t),e.merge(t)})}catch(e){return Promise.reject(e)}},Ze),ot=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},at=function(e){return y(nt,ot(e))};function it(e){function t(t){return C(ot(e),at,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var a=t(function(t){t.statusCode&&!n?(o(t.errorMessage),a()):e(t)&&(r(t),a())})})}}return{snapshot:function(){return R(e,at)},subscribe:t,onceFinalized:r(rt),onceExecuted:r(tt),onceSealed:r(et)}}it.isUnknown=function(e){return e.status>=0},it.isPending=function(e){return e.status>=1},it.isFinalized=rt,it.isExecuted=tt,it.isSealed=et,it.isExpired=function(e){return 5===e.status};var st,ut=function(t){void 0===t&&(t={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(t){try{return f(O(t),"mutate(opts) -- opts is required"),f(N(t),"mutate(opts) -- opts must be an object"),f(O(t.cadence),"mutate({ cadence }) -- cadence is required"),f(D(t.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(e.config.get("accessNode.api")).then(function(e){f(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)}}(t)).then(function(){return Promise.resolve(e.config().get("fcl.authz",Xe().authorization)).then(function(r){return e.send([e.transaction(t.cadence),e.args(T(t.args||[])),t.limit&&j(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||r),e.payer(t.payer||t.authz||r),e.authorizations(t.authorizations||[t.authz||r])]).then(e.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},ct=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.first(["sdk.resolve"],r.resolve||i)).then(function(t){function r(){return Promise.resolve(t(e)).then(function(e){return JSON.stringify(s(e),null,2)})}var n=function(){if(Array.isArray(e))return Promise.resolve(u(c(),e)).then(function(t){e=t})}();return n&&n.then?n.then(r):r()})}catch(e){return Promise.reject(e)}},dt=function(e){try{var r=setTimeout;return Promise.resolve(t().get("fcl.eventPollRate",1e4)).then(function(t){return r(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},lt=((st={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(d()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(dt(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(d()).then(function(r){return e.put("hwm",r),Promise.resolve(n([getEvents(e.self(),t.height,r.height-1)]).then(a)).then(function(t){for(var r,n=M(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(dt(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},st[v]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(dt(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},st[m]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},st),ft=function(e){return y(lt,e)};function pt(e){return{subscribe:function(t){return C(e,ft,t)}}}var ht=function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(V({},t,{type:e}),"*"):window.opener.postMessage(V({},t,{type:e}),"*")},vt={__proto__:null,sendMsgToFCL:ht,close:function(){ht("FCL:VIEW:CLOSE")},approve:function(e){ht("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){ht("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var r=function(r){var n=r.data;"object"==typeof n&&null!=typeof n&&n.type===e&&t(function(e){var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e}(n))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}},encodeMessageFromSignable:l,CompositeSignature:function(e,t,r){this.f_type=H.f_type,this.f_vsn=H.f_vsn,this.addr=S(e),this.keyId=Number(t),this.signature=r}},mt=function(){return Xe().authenticate()},yt=function(){return Xe().unauthenticate()},Et=function(){return Xe().unauthenticate(),Xe().authenticate()},gt=function(){return Xe().authenticate()},Pt=function(){return Xe().authenticate()},Ct=Xe().authorization,Rt=p;export{I as VERSION,vt as WalletUtils,mt as authenticate,Ct as authz,Xe as currentUser,pt as events,Pt as logIn,ut as mutate,_ as query,Et as reauthenticate,ct as serialize,gt as signUp,Rt as t,it as tx,yt as unauthenticate,Ie as verifyUserSignatures}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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"],t):t((e||self).fcl={},e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,o,i,a,s,u){function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var l=c(t),d=c(r),f=c(a),p=function(e){try{return Promise.resolve(t.config().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var n=t[1];return[t[0].replace(e,""),n]}))})}catch(e){return Promise.reject(e)}};t.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,t){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(t)))}catch(e){return Promise.reject(e)}}}});var h=function(e){return function(t){return typeof t===e}},v=function(e){return null!=e},m=h("object"),y=h("string"),g=h("function"),P=h("number");function E(e){return g(e)?e(l.arg,d):[]}var b=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(v(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(l.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 l.send([l.script(e.cadence),l.args(E(e.args||[])),e.limit&&"number"==typeof e.limit&&l.limit(e.limit)]).then(l.decode)})}catch(e){return Promise.reject(e)}};function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function R(e,t){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,t){if(e){if("string"==typeof e)return S(e,t);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,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var C={f_type:"Service",f_vsn:"1.0.0"},O={f_type:"Identity",f_vsn:"1.0.0"},A={f_type:"USER",f_vsn:"1.0.0"},j={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function L(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({old:e},C,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function N(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function k(e){if(null==e)return null;switch(null==e.method&&(e=w({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var D={"back-channel-rpc":N,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},O,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},O,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{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:L,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":k};function F(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function T(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function x(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function U(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(x(e),{method:n,headers:w({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function _(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:w({},e)}),e.f_vsn){case"1.0.0":return e;default:return w({},j,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:N(e.authorizationUpdates),local:L((e.local||[])[0])})}}var B=function e(t,r){void 0===r&&(r=function(){return!0});try{if(n.invariant(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(U(t,{method:z(t)}).then(_)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}},M={"HTTP/GET":"GET","HTTP/POST":"POST"},z=function(e){return n.invariant(M[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),M[e.method]},V="FCL_IFRAME";function H(e){n.invariant(!document.getElementById(V),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=V,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,function(){document.getElementById(V)&&document.getElementById(V).remove()}]}var W="FCL_POP",Y=null,q=null;function J(e,t,n,r,o){return n.open(e,t,"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+r+", height="+o+", top="+(n.top.outerHeight/2+n.top.screenY-o/2)+", left="+(n.top.outerWidth/2+n.top.screenX-r/2))}function K(e){var t;null==Y||null!=(t=Y)&&t.closed?Y=J(e,W,window,640,600):q!==e?(Y=J(e,W,window,640,600)).focus():Y.focus(),q=e;var n=setInterval(function(){Y&&Y.closed&&(clearInterval(n),Y=null)},1e3);return[Y,function(){Y&&!Y.closed&&(Y.close(),Y=null)}]}var G=null,Z=null;function $(e){var t;null==G||null!=(t=G)&&t.closed?G=window.open(e,"_blank"):Z!==e?(G=window.open(e,"_blank")).focus():G.focus(),Z=e;var n=setInterval(function(){G&&G.closed&&(clearInterval(n),G=null)},1e3);return[G,function(){G&&!G.closed&&(G.close(),G=null)}]}var X,Q={"VIEW/IFRAME":H,"VIEW/POP":K,"VIEW/TAB":$},ee=function(e,t,n){try{return t.data=e.data,Promise.resolve(U(e,{data:t}).then(_)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve(Q[e.method](x(e),t))}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}catch(e){return Promise.reject(e)}}(k(t.local))).then(function(e){var r=e[1],o=function(){try{r(),n=!1}catch(e){console.error("Frame Close Error",e)}};return B(t.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:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},te="FCL:VIEW:CLOSE",ne="FCL:VIEW:READY",re="FCL:VIEW:RESPONSE",oe=function(){},ie=function(e){return"string"==typeof e&&e.toLowerCase()},ae=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},se=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ue="FCL:VIEW:CLOSE",ce="FCL:VIEW:READY",le="FCL:VIEW:RESPONSE",de=function(){},fe=function(e){return"string"==typeof e&&e.toLowerCase()},pe=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},he=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ve="FCL:VIEW:CLOSE",me="FCL:VIEW:READY",ye="FCL:VIEW:RESPONSE",ge=function(){},Pe=function(e){return"string"==typeof e&&e.toLowerCase()},Ee=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},be=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),we=function(e){var t=e.service,n=e.msg,r=void 0===n?{}:n,o=e.opts,i=void 0===o?{}:o;try{try{return Promise.resolve(Se[t.method](t,r,i))}catch(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:r,opts:i}),e}}catch(e){return Promise.reject(e)}},Se={"HTTP/RPC":ee,"HTTP/POST":ee,"IFRAME/RPC":function(e,t,n){return new Promise(function(r,o){var i=s.uid(),a=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:oe,close:oe};var n=t.onClose||oe,r=t.onMessage||oe,o=t.onReady||oe,i=t.onResponse||oe;window.addEventListener("message",c);var a=H(x(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(se.has(e.data.type))return;ie(e.data.type)===ie(te)&&l(),ie(e.data.type)===ie(ne)&&o(e,{send:d,close:l}),ie(e.data.type)===ie(re)&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),ie(e.data.type)===ie("FCL:FRAME:READY")&&(ae(e.data.type,ne),o(e,{send:d,close:l})),ie(e.data.type)===ie("FCL:FRAME:RESPONSE")&&(ae(e.data.type,re),i(e,{send:d,close:l})),ie(e.data.type)===ie("FCL:FRAME:CLOSE")&&(ae(e.data.type,te),l()),ie(e.data.type)===ie("FCL::CHALLENGE::RESPONSE")&&(ae(e.data.type,re),i(e,{send:d,close:l})),ie(e.data.type)===ie("FCL::AUTHZ_READY")&&(ae(e.data.type,ne),o(e,{send:d,close:l})),ie(e.data.type)===ie("FCL::CHALLENGE::CANCEL")&&(ae(e.data.type,te),l()),ie(e.data.type)===ie("FCL::CANCEL")&&(ae(e.data.type,te),l())}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{onReady:function(n,r){var o=r.send;try{return Promise.resolve(function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){var n={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:n,config:{services:r,app:s}});var u={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(n){return Promise.resolve(p(/^app\.detail\./)).then(function(r){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:n,app:r},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:[t,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,t){var n=t.close;try{if("object"!=typeof e.data)return;var i=_(e.data);switch(i.status){case"APPROVED":r(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=_(e.data.result);switch(a.status){case"APPROVED":r(a.data),n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,n){return new Promise(function(r,o){var i=s.uid(),a=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:de,close:de};var n=t.onClose||de,r=t.onMessage||de,o=t.onReady||de,i=t.onResponse||de;window.addEventListener("message",c);var a=K(x(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(he.has(e.data.type))return;fe(e.data.type)===fe(ue)&&l(),fe(e.data.type)===fe(ce)&&o(e,{send:d,close:l}),fe(e.data.type)===fe(le)&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),fe(e.data.type)===fe("FCL:FRAME:READY")&&(pe(e.data.type,ce),o(e,{send:d,close:l})),fe(e.data.type)===fe("FCL:FRAME:RESPONSE")&&(pe(e.data.type,le),i(e,{send:d,close:l})),fe(e.data.type)===fe("FCL:FRAME:CLOSE")&&(pe(e.data.type,ue),l()),fe(e.data.type)===fe("FCL::CHALLENGE::RESPONSE")&&(pe(e.data.type,le),i(e,{send:d,close:l})),fe(e.data.type)===fe("FCL::AUTHZ_READY")&&(pe(e.data.type,ce),o(e,{send:d,close:l})),fe(e.data.type)===fe("FCL::CHALLENGE::CANCEL")&&(pe(e.data.type,ue),l()),fe(e.data.type)===fe("FCL::CANCEL")&&(pe(e.data.type,ue),l())}catch(e){console.error("Popup Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),n()}catch(e){console.error("Popup Close Error",e)}}function d(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{onReady:function(n,r){var o=r.send;try{return Promise.resolve(function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){var n={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:n,config:{services:r,app:s}});var u={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(n){return Promise.resolve(p(/^app\.detail\./)).then(function(r){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:n,app:r},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:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;var i=_(e.data);switch(i.status){case"APPROVED":r(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=_(e.data.result);switch(a.status){case"APPROVED":r(a.data),n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,n){return new Promise(function(r,o){var i=s.uid(),a=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ge,close:ge};var n=t.onClose||ge,r=t.onMessage||ge,o=t.onReady||ge,i=t.onResponse||ge;window.addEventListener("message",c);var a=$(x(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(be.has(e.data.type))return;Pe(e.data.type)===Pe(ve)&&l(),Pe(e.data.type)===Pe(me)&&o(e,{send:d,close:l}),Pe(e.data.type)===Pe(ye)&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),Pe(e.data.type)===Pe("FCL:FRAME:READY")&&(Ee(e.data.type,me),o(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL:FRAME:RESPONSE")&&(Ee(e.data.type,ye),i(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL:FRAME:CLOSE")&&(Ee(e.data.type,ve),l()),Pe(e.data.type)===Pe("FCL::CHALLENGE::RESPONSE")&&(Ee(e.data.type,ye),i(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL::AUTHZ_READY")&&(Ee(e.data.type,me),o(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL::CHALLENGE::CANCEL")&&(Ee(e.data.type,ve),l()),Pe(e.data.type)===Pe("FCL::CANCEL")&&(Ee(e.data.type,ve),l())}catch(e){console.error("Tab Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),n()}catch(e){console.error("Tab Close Error",e)}}function d(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{onReady:function(n,r){var o=r.send;try{return Promise.resolve(function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){var n={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:n,config:{services:r,app:s}});var u={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(n){return Promise.resolve(p(/^app\.detail\./)).then(function(r){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:n,app:r},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:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;var i=_(e.data);switch(i.status){case"APPROVED":r(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=_(e.data.result);switch(a.status){case"APPROVED":r(a.data),n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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")}})})}},Re=function(e,r){try{n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),n.invariant(Array.isArray(r),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(r.map(function(e){try{return n.invariant("string"==typeof e.addr,"addr must be a string"),n.invariant("number"==typeof e.keyId,"keyId must be a number"),n.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve(function(n,r){try{var s=Promise.resolve(t.account(e.addr)).then(function(t){return o.push(t.keys[e.keyId].weight.toFixed(1)),i.push(t.keys[e.keyId].signAlgo),a.push(e.signature),t.keys[e.keyId].publicKey})}catch(e){return r(e)}return s&&s.then?s.then(void 0,r):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(b({cadence:""+Ce,args:function(n,r){return[n(e,r.String),n(t,r.Array([r.String])),n(o,r.Array(r.UFix64)),n(i,r.Array([r.UInt])),n(a,r.Array([r.String]))]}}))})}catch(e){return Promise.reject(e)}},Ce="\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 Oe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},I,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function Ae(e,t,n){if(!e.s){if(n instanceof Ne){if(!n.s)return void(n.o=Ae.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Ae.bind(null,e,t),Ae.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var je=function(e,t){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(Re(e,t))}catch(e){return Promise.reject(e)}},Ie=function(e){try{return Me(),Promise.resolve(De()).then(function(t){var r=T(t.services,"user-signature");return n.invariant(r,"Current user must have authorized a signing service."),Fe(function(){return Promise.resolve(we({service:r,msg:Je(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Oe(e)}):[Oe(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},Le=function(e){try{return Me(),Promise.resolve(De()).then(function(t){var n=T(t.services,"authz"),r=T(t.services,"pre-authz");return w({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(we({service:r,msg:t})).then(He)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(we({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(Oe)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ne=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Ae(r,1,i(this.v))}catch(e){Ae(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ae(r,1,t?t(o):o):n?Ae(r,1,n(o)):Ae(r,2,o)}catch(e){Ae(r,2,e)}},r},e}();function ke(e){return e instanceof Ne&&1&e.s}var De=function(){try{return Promise.resolve(new Promise(function(e,n){try{return Me(),Promise.resolve(Ye()).then(function(n){return n.loggedIn&&ze(n)?e(n):Promise.resolve(t.config.first(["discovery.wallet","challenge.handshake"])).then(function(n){try{if(null==n)throw console.warn('Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),new Error('Required config value "discovery.wallet" is not defined')}catch(e){console.error(e)}return Promise.resolve(t.config.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC")).then(function(t){var r=function(e,r){try{var a=Fe(function(){return Promise.resolve(we({service:{endpoint:n,method:t}})).then(function(e){return Promise.resolve(function(e){try{var t=(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,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var n,r=R(e.authorizations);!(n=r()).done;)t.push(w({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(w({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,o,a=(r=t,o=n,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(t){return function(e,t){try{return D[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),s=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return w({},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(Te,Ue,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return r(!0,e)}return a&&a.then?a.then(r.bind(null,!1),r.bind(null,!0)):r(!1,a)}(0,function(t,n){return Promise.resolve(Ye()).then(function(r){if(e(r),t)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 Fe(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Te="CURRENT_USER",xe="CURRENT_USER/UPDATED",Ue="SET_CURRENT_USER",_e='{\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=((X={})[o.INIT]=function(e){try{return e.merge(JSON.parse(_e)),Promise.resolve(t.config.first(["fcl.storage","fcl.storage.default"])).then(function(t){var n=function(){if(t.can)return Promise.resolve(function(e){try{var t=JSON.parse(_e);return Promise.resolve(e.get(Te)).then(function(n){return null!=n&&t.f_vsn!==n.f_vsn?(e.removeItem(Te),t):n||t})}catch(e){return Promise.reject(e)}}(t)).then(function(t){ze(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},X[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,xe,w({},e.all()))},X[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},X.SNAPSHOT=function(e,t){try{return t.reply(w({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},X[Ue]=function(e,n,r){try{return e.merge(r),Promise.resolve(t.config.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(Te,e.all()),e.broadcast(xe,w({},e.all()))})}catch(e){return Promise.reject(e)}},X.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(_e)),Promise.resolve(t.config.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(Te,e.all()),e.broadcast(xe,w({},e.all()))})}catch(e){return Promise.reject(e)}},X),Me=function(){return o.spawn(Be,Te)};function ze(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ve(){Me(),o.send(Te,"DEL_CURRENT_USER")}function He(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=R(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,a=R(t.authorization||[]);!(i=a()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return we({service:n,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function We(e){Me();var t="@EXIT",n=o.spawn(function(n){try{var r;return n.send(Te,o.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(ke(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!ke(i)){r=1;break}i=i.s}}var a=new Ne,s=Ae.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ae(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||ke(o)&&!o.v)return void Ae(a,1,i);if(o.then)return void o.then(c).then(void 0,s);ke(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):Ae(a,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(i){if(i.tag===t)return n.send(Te,o.UNSUBSCRIBE),void(r=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(n,t)}}function Ye(){return Me(),o.send(Te,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var qe,Je=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Ke=function(){return{authenticate:De,unauthenticate:Ve,authorization:Le,signUserMessage:Ie,verifyUserSignatures:je,subscribe:We,snapshot:Ye}};Ke.authenticate=De,Ke.unauthenticate=Ve,Ke.authorization=Le,Ke.signUserMessage=Ie,Ke.verifyUserSignatures=je,Ke.subscribe=We,Ke.snapshot=Ye;var Ge="POLL",Ze=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},$e=function(e){return e.status>=4},Xe=function(e){return e.status>=3},Qe=function(e){return e.status>=2},et=((qe={})[o.INIT]=function(e){try{return Promise.resolve(Ze(e.self())).then(function(t){$e(t)||setTimeout(function(){return e.sendSelf(Ge)},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},qe[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,o.UPDATED,e.all())},qe[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},qe[o.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},qe.POLL=function(e){try{return Promise.resolve(Ze(e.self())).then(function(t){var n,r;$e(t)||setTimeout(function(){return e.sendSelf(Ge)},2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(o.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},qe),tt=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},nt=function(e){return o.spawn(et,tt(e))};function rt(e){function t(t){return o.subscriber(tt(e),nt,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return o.snapshoter(e,nt)},subscribe:t,onceFinalized:n(Qe),onceExecuted:n(Xe),onceSealed:n($e)}}rt.isUnknown=function(e){return e.status>=0},rt.isPending=function(e){return e.status>=1},rt.isFinalized=Qe,rt.isExecuted=Xe,rt.isSealed=$e,rt.isExpired=function(e){return 5===e.status};var ot,it=function(e){try{var n=setTimeout;return Promise.resolve(t.config().get("fcl.eventPollRate",1e4)).then(function(t){return n(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},at=((ot={}).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(t.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(it(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(t.send([getEvents(e.self(),n.height,r.height-1)]).then(t.decode)).then(function(t){for(var n,r=R(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(it(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ot[o.SUBSCRIBE]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(it(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},ot[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ot),st=function(e){return o.spawn(at,e)},ut=function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(w({},t,{type:e}),"*"):window.opener.postMessage(w({},t,{type:e}),"*")},ct={__proto__:null,sendMsgToFCL:ut,close:function(){ut("FCL:VIEW:CLOSE")},approve:function(e){ut("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){ut("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var n=function(n){var r=n.data;"object"==typeof r&&null!=typeof r&&r.type===e&&t(function(e){var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e}(r))};return window.addEventListener("message",n),function(){return window.removeEventListener("message",n)}},encodeMessageFromSignable:t.encodeMessageFromSignable,CompositeSignature:function(e,t,n){this.f_type=I.f_type,this.f_vsn=I.f_vsn,this.addr=i.withPrefix(e),this.keyId=Number(t),this.signature=n}},lt=Ke().authorization,dt=d;Object.defineProperty(e,"TestUtils",{enumerable:!0,get:function(){return t.TestUtils}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"createSignableVoucher",{enumerable:!0,get:function(){return t.createSignableVoucher}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(e,"getCollection",{enumerable:!0,get:function(){return t.getCollection}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"invariant",{enumerable:!0,get:function(){return t.invariant}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"validator",{enumerable:!0,get:function(){return t.validator}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.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="0.0.77",e.WalletUtils=ct,e.authenticate=function(){return Ke().authenticate()},e.authz=lt,e.currentUser=Ke,e.events=function(e){return{subscribe:function(t){return o.subscriber(e,st,t)}}},e.logIn=function(){return Ke().authenticate()},e.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(t,r){try{var o=Promise.resolve(function(e){try{return n.invariant(v(e),"mutate(opts) -- opts is required"),n.invariant(m(e),"mutate(opts) -- opts must be an object"),n.invariant(v(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(l.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(l.config().get("fcl.authz",Ke().authorization)).then(function(t){return l.send([l.transaction(e.cadence),l.args(E(e.args||[])),e.limit&&P(e.limit)&&l.limit(e.limit),l.proposer(e.proposer||e.authz||t),l.payer(e.payer||e.authz||t),l.authorizations(e.authorizations||[e.authz||t])]).then(l.decode)})})}catch(e){return r(e)}return o&&o.then?o.then(void 0,r):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},e.query=b,e.reauthenticate=function(){return Ke().unauthenticate(),Ke().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Promise.resolve(t.config.first(["sdk.resolve"],n.resolve||t.resolve)).then(function(n){function r(){return Promise.resolve(n(e)).then(function(e){return JSON.stringify(t.createSignableVoucher(e),null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(t){e=t})}();return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return Ke().authenticate()},e.t=dt,e.tx=rt,e.unauthenticate=function(){return Ke().unauthenticate()},e.verifyUserSignatures=Re}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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"],t):t((e||self).fcl={},e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,o,i,a,s,u){function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var l=c(t),d=c(r),f=c(a),p=function(e){try{return Promise.resolve(t.config().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var n=t[1];return[t[0].replace(e,""),n]}))})}catch(e){return Promise.reject(e)}};t.config({"discovery.wallet.method.default":"IFRAME/RPC","fcl.storage.default":{can:!0,get:function(e){try{return Promise.resolve(JSON.parse(sessionStorage.getItem(e)))}catch(e){return Promise.reject(e)}},put:function(e,t){try{return Promise.resolve(sessionStorage.setItem(e,JSON.stringify(t)))}catch(e){return Promise.reject(e)}}}});var h=function(e){return function(t){return typeof t===e}},v=function(e){return null!=e},m=h("object"),y=h("string"),g=h("function"),P=h("number");function E(e){return g(e)?e(l.arg,d):[]}var b=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(v(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve(l.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 l.send([l.script(e.cadence),l.args(E(e.args||[])),e.limit&&"number"==typeof e.limit&&l.limit(e.limit)]).then(l.decode)})}catch(e){return Promise.reject(e)}};function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function R(e,t){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,t){if(e){if("string"==typeof e)return S(e,t);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,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var C={f_type:"Service",f_vsn:"1.0.0"},O={f_type:"Identity",f_vsn:"1.0.0"},A={f_type:"USER",f_vsn:"1.0.0"},j={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function L(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({old:e},C,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function N(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function k(e){if(null==e)return null;switch(null==e.method&&(e=w({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var D={"back-channel-rpc":N,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},O,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},O,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},C,{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:L,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}},"local-view":k};function F(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function T(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function x(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function U(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(x(e),{method:n,headers:w({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function _(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:w({},e)}),e.f_vsn){case"1.0.0":return e;default:return w({},j,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:N(e.authorizationUpdates),local:L((e.local||[])[0])})}}var B=function e(t,r){void 0===r&&(r=function(){return!0});try{if(n.invariant(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(U(t,{method:z(t)}).then(_)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}},M={"HTTP/GET":"GET","HTTP/POST":"POST"},z=function(e){return n.invariant(M[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),M[e.method]},V="FCL_IFRAME";function H(e){n.invariant(!document.getElementById(V),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=V,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,function(){document.getElementById(V)&&document.getElementById(V).remove()}]}var Y=null,W=null;function q(e){var t,n;null==Y||null!=(t=Y)&&t.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=600, top="+(n.top.outerHeight/2+n.top.screenY-300)+", left="+(n.top.outerWidth/2+n.top.screenX-320))):W!==e?(Y.location.replace(e),Y.focus()):Y.focus(),W=e;var r=setInterval(function(){Y&&Y.closed&&(clearInterval(r),Y=null)},1e3);return[Y,function(){Y&&!Y.closed&&(Y.close(),Y=null)}]}var J=null,K=null;function G(e){var t;null==J||null!=(t=J)&&t.closed?J=window.open(e,"_blank"):K!==e?(J.location.replace(e),J.focus()):J.focus(),K=e;var n=setInterval(function(){J&&J.closed&&(clearInterval(n),J=null)},1e3);return[J,function(){J&&!J.closed&&(J.close(),J=null)}]}var Z,$={"VIEW/IFRAME":H,"VIEW/POP":q,"VIEW/TAB":G},X=function(e,t,n){try{return t.data=e.data,Promise.resolve(U(e,{data:t}).then(_)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve($[e.method](x(e),t))}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}catch(e){return Promise.reject(e)}}(k(t.local))).then(function(e){var r=e[1],o=function(){try{r(),n=!1}catch(e){console.error("Frame Close Error",e)}};return B(t.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:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Q="FCL:VIEW:CLOSE",ee="FCL:VIEW:READY",te="FCL:VIEW:RESPONSE",ne=function(){},re=function(e){return"string"==typeof e&&e.toLowerCase()},oe=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},ie=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ae="FCL:VIEW:CLOSE",se="FCL:VIEW:READY",ue="FCL:VIEW:RESPONSE",ce=function(){},le=function(e){return"string"==typeof e&&e.toLowerCase()},de=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),pe="FCL:VIEW:CLOSE",he="FCL:VIEW:READY",ve="FCL:VIEW:RESPONSE",me=function(){},ye=function(e){return"string"==typeof e&&e.toLowerCase()},ge=function(e,t){return console.warn("DEPRECATION NOTICE","Received "+e+", please use "+t+" for this and future versions of FCL")},Pe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),Ee=function(e){var t=e.service,n=e.msg,r=void 0===n?{}:n,o=e.opts,i=void 0===o?{}:o;try{try{return Promise.resolve(be[t.method](t,r,i))}catch(e){throw console.error("execService({service, msg = {}, opts = {}})",e,{service:t,msg:r,opts:i}),e}}catch(e){return Promise.reject(e)}},be={"HTTP/RPC":X,"HTTP/POST":X,"IFRAME/RPC":function(e,t,n){return new Promise(function(r,o){var i=s.uid(),a=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ne,close:ne};var n=t.onClose||ne,r=t.onMessage||ne,o=t.onReady||ne,i=t.onResponse||ne;window.addEventListener("message",c);var a=H(x(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(ie.has(e.data.type))return;re(e.data.type)===re(Q)&&l(),re(e.data.type)===re(ee)&&o(e,{send:d,close:l}),re(e.data.type)===re(te)&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),re(e.data.type)===re("FCL:FRAME:READY")&&(oe(e.data.type,ee),o(e,{send:d,close:l})),re(e.data.type)===re("FCL:FRAME:RESPONSE")&&(oe(e.data.type,te),i(e,{send:d,close:l})),re(e.data.type)===re("FCL:FRAME:CLOSE")&&(oe(e.data.type,Q),l()),re(e.data.type)===re("FCL::CHALLENGE::RESPONSE")&&(oe(e.data.type,te),i(e,{send:d,close:l})),re(e.data.type)===re("FCL::AUTHZ_READY")&&(oe(e.data.type,ee),o(e,{send:d,close:l})),re(e.data.type)===re("FCL::CHALLENGE::CANCEL")&&(oe(e.data.type,Q),l()),re(e.data.type)===re("FCL::CANCEL")&&(oe(e.data.type,Q),l())}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}(e,{onReady:function(n,r){var o=r.send;try{return Promise.resolve(function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){var n={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:n,config:{services:r,app:s}});var u={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(n){return Promise.resolve(p(/^app\.detail\./)).then(function(r){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:u,config:{services:n,app:r},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:[t,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,t){var n=t.close;try{if("object"!=typeof e.data)return;var i=_(e.data);switch(i.status){case"APPROVED":r(i.data),n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=_(e.data.result);switch(a.status){case"APPROVED":r(a.data),n();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),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,t,n){return new Promise(function(r,o){var i=s.uid(),a=n.redir,u=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ce,close:ce};var n=t.onClose||ce,r=t.onMessage||ce,o=t.onReady||ce,i=t.onResponse||ce;window.addEventListener("message",c);var a=q(x(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(fe.has(e.data.type))return;le(e.data.type)===le(ae)&&l(),le(e.data.type)===le(se)&&o(e,{send:d,close:l}),le(e.data.type)===le(ue)&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),le(e.data.type)===le("FCL:FRAME:READY")&&(de(e.data.type,se),o(e,{send:d,close:l})),le(e.data.type)===le("FCL:FRAME:RESPONSE")&&(de(e.data.type,ue),i(e,{send:d,close:l})),le(e.data.type)===le("FCL:FRAME:CLOSE")&&(de(e.data.type,ae),l()),le(e.data.type)===le("FCL::CHALLENGE::RESPONSE")&&(de(e.data.type,ue),i(e,{send:d,close:l})),le(e.data.type)===le("FCL::AUTHZ_READY")&&(de(e.data.type,se),o(e,{send:d,close:l})),le(e.data.type)===le("FCL::CHALLENGE::CANCEL")&&(de(e.data.type,ae),l()),le(e.data.type)===le("FCL::CANCEL")&&(de(e.data.type,ae),l())}catch(e){console.error("Popup Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),n()}catch(e){console.error("Popup Close Error",e)}}function d(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Popup Send Error",e,t)}}}(e,{onReady:function(n,r){var o=r.send;try{return Promise.resolve(function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){var n={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:n,config:{services:r,app:a}});var s={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(n){return Promise.resolve(p(/^app\.detail\./)).then(function(r){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:s,config:{services:n,app:r},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:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;var i=_(e.data);switch(i.status){case"APPROVED":r(i.data),!a&&n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var s=_(e.data.result);switch(s.status){case"APPROVED":r(s.data),!a&&n();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),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,t,n){return new Promise(function(r,o){var i=s.uid(),a=n.redir,u=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:me,close:me};var n=t.onClose||me,r=t.onMessage||me,o=t.onReady||me,i=t.onResponse||me;window.addEventListener("message",c);var a=G(x(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(Pe.has(e.data.type))return;ye(e.data.type)===ye(pe)&&l(),ye(e.data.type)===ye(he)&&o(e,{send:d,close:l}),ye(e.data.type)===ye(ve)&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),ye(e.data.type)===ye("FCL:FRAME:READY")&&(ge(e.data.type,he),o(e,{send:d,close:l})),ye(e.data.type)===ye("FCL:FRAME:RESPONSE")&&(ge(e.data.type,ve),i(e,{send:d,close:l})),ye(e.data.type)===ye("FCL:FRAME:CLOSE")&&(ge(e.data.type,pe),l()),ye(e.data.type)===ye("FCL::CHALLENGE::RESPONSE")&&(ge(e.data.type,ve),i(e,{send:d,close:l})),ye(e.data.type)===ye("FCL::AUTHZ_READY")&&(ge(e.data.type,he),o(e,{send:d,close:l})),ye(e.data.type)===ye("FCL::CHALLENGE::CANCEL")&&(ge(e.data.type,pe),l()),ye(e.data.type)===ye("FCL::CANCEL")&&(ge(e.data.type,pe),l())}catch(e){console.error("Tab Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),n()}catch(e){console.error("Tab Close Error",e)}}function d(e){try{s.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Tab Send Error",e,t)}}}(e,{onReady:function(n,r){var o=r.send;try{return Promise.resolve(function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(function(){var n={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(r){return Promise.resolve(p(/^app\.detail\./)).then(function(a){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:n,config:{services:r,app:a}});var s={params:e.params,data:e.data};return Promise.resolve(p(/^service\./)).then(function(n){return Promise.resolve(p(/^app\.detail\./)).then(function(r){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:s,config:{services:n,app:r},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:[t,e.params]})})})})})},function(e){throw e}))}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;var i=_(e.data);switch(i.status){case"APPROVED":r(i.data),!a&&n();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),n();break;default:o("Declined: No reason supplied"),n()}}catch(e){throw console.error("execPopRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var s=_(e.data.result);switch(s.status){case"APPROVED":r(s.data),!a&&n();break;case"DECLINED":o("Declined: "+(s.reason||"No reason supplied")),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")}})})}},we=function(e,r){try{n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),n.invariant(Array.isArray(r),"Must include an Array of composite signatures");var o=[],i=[],a=[];return Promise.resolve(Promise.all(r.map(function(e){try{return n.invariant("string"==typeof e.addr,"addr must be a string"),n.invariant("number"==typeof e.keyId,"keyId must be a number"),n.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve(function(n,r){try{var s=Promise.resolve(t.account(e.addr)).then(function(t){return o.push(t.keys[e.keyId].weight.toFixed(1)),i.push(t.keys[e.keyId].signAlgo),a.push(e.signature),t.keys[e.keyId].publicKey})}catch(e){return r(e)}return s&&s.then?s.then(void 0,r):s}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(b({cadence:""+Se,args:function(n,r){return[n(e,r.String),n(t,r.Array([r.String])),n(o,r.Array(r.UFix64)),n(i,r.Array([r.UInt])),n(a,r.Array([r.String]))]}}))})}catch(e){return Promise.reject(e)}},Se="\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 Re(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({},I,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function Ce(e,t,n){if(!e.s){if(n instanceof Ie){if(!n.s)return void(n.o=Ce.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Ce.bind(null,e,t),Ce.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Oe=function(e,t){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(we(e,t))}catch(e){return Promise.reject(e)}},Ae=function(e){try{return _e(),Promise.resolve(Ne({redir:!0})).then(function(t){var r=T(t.services,"user-signature");return n.invariant(r,"Current user must have authorized a signing service."),ke(function(){return Promise.resolve(Ee({service:r,msg:We(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Re(e)}):[Re(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},je=function(e){try{return _e(),Promise.resolve(Ne({redir:!0})).then(function(t){var n=T(t.services,"authz"),r=T(t.services,"pre-authz");return w({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Ee({service:r,msg:t})).then(ze)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Ee({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(Re)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ie=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Ce(r,1,i(this.v))}catch(e){Ce(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ce(r,1,t?t(o):o):n?Ce(r,1,n(o)):Ce(r,2,o)}catch(e){Ce(r,2,e)}},r},e}();function Le(e){return e instanceof Ie&&1&e.s}var Ne=function(e){void 0===e&&(e={redir:!1});try{return Promise.resolve(new Promise(function(r,a){try{return _e(),Promise.resolve(He()).then(function(a){return a.loggedIn&&Be(a)?r(a):Promise.resolve(t.config.first(["discovery.wallet","challenge.handshake"])).then(function(a){return n.invariant(a,'Required value for "discovery.wallet" not defined in config. See: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/src/exec/query.md#configuration'),Promise.resolve(t.config.first(["discovery.wallet.method","discovery.wallet.method.default"],"IFRAME/RPC")).then(function(n){return Promise.resolve(t.config.get("fcl.warning.suppress.redir")).then(function(t){e.redir&&!t&&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 s=function(t,r){try{var s=ke(function(){return Promise.resolve(Ee({service:{endpoint:a,method:n},opts:e})).then(function(e){return Promise.resolve(function(e){try{var t=(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,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var n,r=R(e.authorizations);!(n=r()).done;)t.push(w({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(w({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,o,a=(r=t,o=n,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(t){return function(e,t){try{return D[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),s=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return w({},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(De,Te,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return r(!0,e)}return s&&s.then?s.then(r.bind(null,!1),r.bind(null,!0)):r(!1,s)}(0,function(e,t){return Promise.resolve(He()).then(function(n){if(r(n),e)throw t;return t})});if(s&&s.then)return s.then(function(){})})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function ke(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var De="CURRENT_USER",Fe="CURRENT_USER/UPDATED",Te="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}',Ue=((Z={})[o.INIT]=function(e){try{return e.merge(JSON.parse(xe)),Promise.resolve(t.config.first(["fcl.storage","fcl.storage.default"])).then(function(t){var n=function(){if(t.can)return Promise.resolve(function(e){try{var t=JSON.parse(xe);return Promise.resolve(e.get(De)).then(function(n){return null!=n&&t.f_vsn!==n.f_vsn?(e.removeItem(De),t):n||t})}catch(e){return Promise.reject(e)}}(t)).then(function(t){Be(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},Z[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,Fe,w({},e.all()))},Z[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},Z.SNAPSHOT=function(e,t){try{return t.reply(w({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[Te]=function(e,n,r){try{return e.merge(r),Promise.resolve(t.config.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(De,e.all()),e.broadcast(Fe,w({},e.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(xe)),Promise.resolve(t.config.first(["fcl.storage","fcl.storage.default"])).then(function(t){t.can&&t.put(De,e.all()),e.broadcast(Fe,w({},e.all()))})}catch(e){return Promise.reject(e)}},Z),_e=function(){return o.spawn(Ue,De)};function Be(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Me(){_e(),o.send(De,"DEL_CURRENT_USER")}function ze(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=R(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,a=R(t.authorization||[]);!(i=a()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return Ee({service:n,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ve(e){_e();var t="@EXIT",n=o.spawn(function(n){try{var r;return n.send(De,o.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(Le(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Le(i)){r=1;break}i=i.s}}var a=new Ie,s=Ce.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ce(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||Le(o)&&!o.v)return void Ce(a,1,i);if(o.then)return void o.then(c).then(void 0,s);Le(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):Ce(a,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(i){if(i.tag===t)return n.send(De,o.UNSUBSCRIBE),void(r=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(n,t)}}function He(){return _e(),o.send(De,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ye,We=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},qe=function(){return{authenticate:Ne,unauthenticate:Me,authorization:je,signUserMessage:Ae,verifyUserSignatures:Oe,subscribe:Ve,snapshot:He}};qe.authenticate=Ne,qe.unauthenticate=Me,qe.authorization=je,qe.signUserMessage=Ae,qe.verifyUserSignatures=Oe,qe.subscribe=Ve,qe.snapshot=He;var Je="POLL",Ke=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},Ge=function(e){return e.status>=4},Ze=function(e){return e.status>=3},$e=function(e){return e.status>=2},Xe=((Ye={})[o.INIT]=function(e){try{return Promise.resolve(Ke(e.self())).then(function(t){Ge(t)||setTimeout(function(){return e.sendSelf(Je)},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},Ye[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,o.UPDATED,e.all())},Ye[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},Ye[o.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Ye.POLL=function(e){try{return Promise.resolve(Ke(e.self())).then(function(t){var n,r;Ge(t)||setTimeout(function(){return e.sendSelf(Je)},2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(o.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},Ye),Qe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},et=function(e){return o.spawn(Xe,Qe(e))};function tt(e){function t(t){return o.subscriber(Qe(e),et,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return o.snapshoter(e,et)},subscribe:t,onceFinalized:n($e),onceExecuted:n(Ze),onceSealed:n(Ge)}}tt.isUnknown=function(e){return e.status>=0},tt.isPending=function(e){return e.status>=1},tt.isFinalized=$e,tt.isExecuted=Ze,tt.isSealed=Ge,tt.isExpired=function(e){return 5===e.status};var nt,rt=function(e){try{var n=setTimeout;return Promise.resolve(t.config().get("fcl.eventPollRate",1e4)).then(function(t){return n(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},ot=((nt={}).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(t.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(rt(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(t.send([getEvents(e.self(),n.height,r.height-1)]).then(t.decode)).then(function(t){for(var n,r=R(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(rt(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},nt[o.SUBSCRIBE]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(rt(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},nt[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},nt),it=function(e){return o.spawn(ot,e)},at=function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(w({},t,{type:e}),"*"):window.opener.postMessage(w({},t,{type:e}),"*")},st={__proto__:null,sendMsgToFCL:at,close:function(){at("FCL:VIEW:CLOSE")},approve:function(e){at("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"APPROVED",reason:null,data:e})},decline:function(e){at("FCL:VIEW:RESPONSE",{f_type:"PollingResponse",f_vsn:"1.0.0",status:"DECLINED",reason:e,data:null})},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var n=function(n){var r=n.data;"object"==typeof r&&null!=typeof r&&r.type===e&&t(function(e){var t;return e.deprecated&&console.warn("DEPRECATION NOTICE",e.deprecated.message),null==e||null==(t=e.body)||delete t.interaction,e}(r))};return window.addEventListener("message",n),function(){return window.removeEventListener("message",n)}},encodeMessageFromSignable:t.encodeMessageFromSignable,CompositeSignature:function(e,t,n){this.f_type=I.f_type,this.f_vsn=I.f_vsn,this.addr=i.withPrefix(e),this.keyId=Number(t),this.signature=n}},ut=qe().authorization,ct=d;Object.defineProperty(e,"TestUtils",{enumerable:!0,get:function(){return t.TestUtils}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"createSignableVoucher",{enumerable:!0,get:function(){return t.createSignableVoucher}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(e,"getCollection",{enumerable:!0,get:function(){return t.getCollection}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"invariant",{enumerable:!0,get:function(){return t.invariant}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"validator",{enumerable:!0,get:function(){return t.validator}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.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="0.0.78-alpha.1",e.WalletUtils=st,e.authenticate=function(){return qe().authenticate()},e.authz=ut,e.currentUser=qe,e.events=function(e){return{subscribe:function(t){return o.subscriber(e,it,t)}}},e.logIn=function(){return qe().authenticate()},e.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(t,r){try{var o=Promise.resolve(function(e){try{return n.invariant(v(e),"mutate(opts) -- opts is required"),n.invariant(m(e),"mutate(opts) -- opts must be an object"),n.invariant(v(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve(l.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(l.config().get("fcl.authz",qe().authorization)).then(function(t){return l.send([l.transaction(e.cadence),l.args(E(e.args||[])),e.limit&&P(e.limit)&&l.limit(e.limit),l.proposer(e.proposer||e.authz||t),l.payer(e.payer||e.authz||t),l.authorizations(e.authorizations||[e.authz||t])]).then(l.decode)})})}catch(e){return r(e)}return o&&o.then?o.then(void 0,r):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},e.query=b,e.reauthenticate=function(){return qe().unauthenticate(),qe().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Promise.resolve(t.config.first(["sdk.resolve"],n.resolve||t.resolve)).then(function(n){function r(){return Promise.resolve(n(e)).then(function(e){return JSON.stringify(t.createSignableVoucher(e),null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(t){e=t})}();return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return qe().authenticate()},e.t=ct,e.tx=tt,e.unauthenticate=function(){return qe().unauthenticate()},e.verifyUserSignatures=we}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.77", | ||
"version": "0.0.78-alpha.1", | ||
"description": "Flow Client Library", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2237288
561