@onflow/fcl
Advanced tools
Comparing version 0.0.77-alpha.2 to 0.0.77-alpha.3
@@ -5,2 +5,7 @@ ## Unreleased | ||
## 0.0.77-alpha.3 - 2021-08-04 | ||
- 2021-08-04 -- Adds `execTabRPC` strategy. | ||
- 2021-08-02 -- Adds `WalletUtils.onMessageFromFCL`. Update response types to use `VIEW` and add deprecation warnings for `FRAME`. | ||
## 0.0.77-alpha.2 - 2021-07-30 | ||
@@ -7,0 +12,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),l=u(r),d=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().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","frame");var p=function(e){return function(t){return typeof t===e}},h=function(e){return null!=e},m=p("object"),v=p("string"),y=p("function"),g=p("number");function P(e){return y(e)?e(c.arg,l):[]}var b=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(v(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return c.send([c.script(e.cadence),c.args(P(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}};function E(){return(E=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 w(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 S(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 w(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)?w(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 j={f_type:"Service",f_vsn:"1.0.0"},O={f_type:"Identity",f_vsn:"1.0.0"},x={f_type:"USER",f_vsn:"1.0.0"},R={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return E({old:e},j,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function I(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return E({},j,{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=E({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return E({},j,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var N={"back-channel-rpc":I,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return E({},j,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:E({},O,{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 E({},j,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:E({},O,{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 E({},j,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:C,"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 L(e){return d.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 T(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function U(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(T(e),{method:r,headers:E({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function _(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:E({},e)}),e.f_vsn){case"1.0.0":return e;default:return E({},R,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:I(e.authorizationUpdates),local:C((e.local||[])[0])})}}var B=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(U(r,{method:z(r)}).then(_)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}},F={"HTTP/GET":"GET","HTTP/POST":"POST"},z=function(e){return t.invariant(F[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),F[e.method]},M="FCL_IFRAME";function H(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,function(){document.getElementById(M)&&document.getElementById(M).remove()}]}var q=null,J=null;function V(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 K(e){var t;null==q||null!=(t=q)&&t.closed?q=V(e,"FCL_POP",window,600,600):J!==e?(q=V(e,"FCL_POP",window,600,600)).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,Y={"VIEW/IFRAME":H,"VIEW/POP":K},W=function(e,t,r){try{return t.data=e.data,Promise.resolve(U(e,{data:t}).then(_)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0;return Promise.resolve(function(e,t){void 0===t&&(t={});try{try{return Promise.resolve(Y[e.method](T(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(k(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return B(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)}},Z=function(){},$=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),X=function(){},Q=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ee=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(te[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)}},te={"HTTP/RPC":W,"HTTP/POST":W,"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:Z,close:Z};var r=t.onClose||Z,n=t.onMessage||Z,o=t.onReady||Z,i=t.onResponse||Z;window.addEventListener("message",c);var a=H(T(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if($.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),n(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{s.contentWindow.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:FRAME:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}}),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=_(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=_(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: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=K(T(e)),s=a[0],u=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(Q.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),n(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Popup Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),r()}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(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:FRAME:READY:RESPONSE",body:t,service:r,config:{services:n,app:a}}),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=_(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=_(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")}})})}};function re(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return E({},A,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function ne(e,t,r){if(!e.s){if(r instanceof se){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 oe=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(le(function(){return 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})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(e){return Promise.resolve(b({cadence:""+xe,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)}},ie=function(e){try{return ge(),Promise.resolve(ce()).then(function(r){var n=D(r.services,"user-signature");return t.invariant(n,"Current user must have authorized a signing service."),le(function(){return Promise.resolve(ee({service:n,msg:Oe(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)}},ae=function(e){try{return ge(),Promise.resolve(ce()).then(function(t){var r=D(t.services,"authz"),n=D(t.services,"pre-authz");return E({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(ee({service:n,msg:t})).then(Ee)}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(ee({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(re)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},se=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{ne(n,1,i(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 ue(e){return e instanceof se&&1&e.s}var ce=function(){try{return Promise.resolve(new Promise(function(t,r){try{return ge(),Promise.resolve(Se()).then(function(r){return r.loggedIn&&Pe(r)?t(r):Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(r){return Promise.resolve(e.config.first(["discovery.wallet.method"],"frame")).then(function(e){var i="frame"===e?"IFRAME/RPC":"POP/RPC",a=function(e,t){try{var a=le(function(){return Promise.resolve(ee({service:{endpoint:r,method:i}})).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=S(e.authorizations);!(r=n()).done;)t.push(E({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(E({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 E({},x,{addr:o.withPrefix(e.addr),cid:L(s),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){n.send(de,pe,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return t(!0,e)}return a&&a.then?a.then(t.bind(null,!1),t.bind(null,!0)):t(!1,a)}(0,function(e,r){return Promise.resolve(Se()).then(function(n){if(t(n),e)throw r;return r})});if(a&&a.then)return a.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function le(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var de="CURRENT_USER",fe="CURRENT_USER/UPDATED",pe="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}',me=function(e){try{return sessionStorage.setItem(de,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ve=function(){return e.config().get("persistSession",!0)},ye=((G={})[n.INIT]=function(e){try{return e.merge(JSON.parse(he)),Promise.resolve(ve()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(he),t=JSON.parse(sessionStorage.getItem(de));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(de),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Pe(t)&&e.merge(t)})}();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,fe,E({},e.all()))},G[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},G.SNAPSHOT=function(e,t){try{return t.reply(E({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},G[pe]=function(e,t,r){try{return e.merge(r),Promise.resolve(ve()).then(function(t){t&&me(e.all()),e.broadcast(fe,E({},e.all()))})}catch(e){return Promise.reject(e)}},G.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(he)),Promise.resolve(ve()).then(function(t){t&&me(e.all()),e.broadcast(fe,E({},e.all()))})}catch(e){return Promise.reject(e)}},G),ge=function(){return n.spawn(ye,de)};function Pe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function be(){ge(),n.send(de,"DEL_CURRENT_USER")}function Ee(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=S(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,a=S(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 ee({service:r,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function we(e){ge();var t="@EXIT",r=n.spawn(function(r){try{var o;return r.send(de,n.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(ue(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!ue(i)){n=1;break}i=i.s}}var a=new se,s=ne.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):ne(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||ue(o)&&!o.v)return void ne(a,1,i);if(o.then)return void o.then(c).then(void 0,s);ue(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):ne(a,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===t)return r.send(de,n.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return n.send(r,t)}}function Se(){return ge(),n.send(de,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var je,Oe=function(e){return t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},xe="\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",Re=function(){return{authenticate:ce,unauthenticate:be,authorization:ae,signUserMessage:ie,verifyUserSignatures:oe,subscribe:we,snapshot:Se}},Ae=function(t){try{return Promise.resolve(e.send([e.getTransactionStatus(t)]).then(e.decode))}catch(e){return Promise.reject(e)}},Ce=function(e){return e.status>=4},Ie=function(e){return e.status>=3},ke=function(e){return e.status>=2},Ne=((je={})[n.INIT]=function(e){try{return Promise.resolve(Ae(e.self())).then(function(t){Ce(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},je[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,n.UPDATED,e.all())},je[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},je[n.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},je.POLL=function(e){try{return Promise.resolve(Ae(e.self())).then(function(t){var r,o;Ce(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)}},je),Le=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},De=function(e){return n.spawn(Ne,Le(e))};function Te(e){function t(t){return n.subscriber(Le(e),De,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,De)},subscribe:t,onceFinalized:r(ke),onceExecuted:r(Ie),onceSealed:r(Ce)}}Te.isUnknown=function(e){return e.status>=0},Te.isPending=function(e){return e.status>=1},Te.isFinalized=ke,Te.isExecuted=Ie,Te.isSealed=Ce,Te.isExpired=function(e){return 5===e.status};var Ue,_e=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Be=((Ue={}).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(_e(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=S(e);!(r=n()).done;)t.broadcast("UPDATED",r.value.data);var o=t.put;return Promise.resolve(_e(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)}},Ue[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(_e(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},Ue[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Ue),Fe=function(e){return n.spawn(Be,e)},ze={__proto__:null,sendMsgToFCL:function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(E({},t,{type:e}),"*"):window.opener.postMessage(E({},t,{type:e}),"*")}},Me=Re().authorization,He=l;Object.defineProperty(exports,"TestUtils",{enumerable:!0,get:function(){return e.TestUtils}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return e.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return e.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return e.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return e.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return e.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return e.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return e.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return e.build}}),Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"createSignableVoucher",{enumerable:!0,get:function(){return e.createSignableVoucher}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return e.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return e.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return e.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return e.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return e.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return e.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return e.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return e.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return e.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return e.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return e.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return e.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return e.getTransactionStatus}}),Object.defineProperty(exports,"invariant",{enumerable:!0,get:function(){return e.invariant}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return e.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return e.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return e.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return e.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return e.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return e.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return e.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return e.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return e.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return e.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return e.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return e.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return e.transaction}}),Object.defineProperty(exports,"validator",{enumerable:!0,get:function(){return e.validator}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return s.template}}),exports.VERSION="0.0.77-alpha.2",exports.WalletUtils=ze,exports.authenticate=function(){return Re().authenticate()},exports.authz=Me,exports.currentUser=Re,exports.events=function(e){return{subscribe:function(t){return n.subscriber(e,Fe,t)}}},exports.logIn=function(){return Re().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(m(e),"mutate(opts) -- opts must be an object"),t.invariant(h(e.cadence),"mutate({ cadence }) -- cadence is required"),t.invariant(v(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(c.config().get("fcl.authz",Re().authorization)).then(function(t){return c.send([c.transaction(e.cadence),c.args(P(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=b,exports.reauthenticate=function(){return Re().unauthenticate(),Re().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 Re().authenticate()},exports.t=He,exports.tx=Te,exports.unauthenticate=function(){return Re().unauthenticate()}; | ||
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().put("accessNode.api","http://localhost:8080").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","IFRAME/RPC");var p=function(e){return function(t){return typeof t===e}},h=function(e){return null!=e},m=p("object"),v=p("string"),y=p("function"),g=p("number");function P(e){return y(e)?e(c.arg,d):[]}var E=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(v(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return c.send([c.script(e.cadence),c.args(P(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 C(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 S(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 C(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)?C(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"},O={f_type:"Identity",f_vsn:"1.0.0"},R={f_type:"USER",f_vsn:"1.0.0"},I={f_type:"PollingResponse",f_vsn:"1.0.0"},L={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 b({old:e},w,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},w,{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({},w,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var N={"back-channel-rpc":A,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},w,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},O,{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({},w,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},O,{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({},w,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame: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":x};function F(e){return l.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function k(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function D(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(D(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({},I,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:A(e.authorizationUpdates),local:j((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:V(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)}},B={"HTTP/GET":"GET","HTTP/POST":"POST"},V=function(e){return t.invariant(B[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),B[e.method]},z="FCL_IFRAME";function M(e){t.invariant(!document.getElementById(z),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=z,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(z)&&document.getElementById(z).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 J(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 q=null,K=null;function G(e){var t;null==q||null!=(t=q)&&t.closed?q=window.open(e,"_blank"):K!==e?(q=window.open(e,"_blank")).focus():q.focus(),K=e;var r=setInterval(function(){q&&q.closed&&(clearInterval(r),q=null)},1e3);return[q,function(){q&&!q.closed&&(q.close(),q=null)}]}var Z,$={"VIEW/IFRAME":M,"VIEW/POP":J,"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](D(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=M(D(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}}),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("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=J(D(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}}),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(D(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}}),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")}})})}};function pe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},L,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function he(e,t,r){if(!e.s){if(r instanceof ge){if(!r.s)return void(r.o=he.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(he.bind(null,e,t),he.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var me=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(be(function(){return 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})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(e){return Promise.resolve(E({cadence:""+Ue,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)}},ve=function(e){try{return je(),Promise.resolve(Ee()).then(function(r){var n=k(r.services,"user-signature");return t.invariant(n,"Current user must have authorized a signing service."),be(function(){return Promise.resolve(le({service:n,msg:Te(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return pe(e)}):[pe(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},ye=function(e){try{return je(),Promise.resolve(Ee()).then(function(t){var r=k(t.services,"authz"),n=k(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(pe)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},ge=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{he(n,1,i(this.v))}catch(e){he(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?he(n,1,t?t(o):o):r?he(n,1,r(o)):he(n,2,o)}catch(e){he(n,2,e)}},n},e}();function Pe(e){return e instanceof ge&&1&e.s}var Ee=function(){try{return Promise.resolve(new Promise(function(t,r){try{return je(),Promise.resolve(ke()).then(function(r){return r.loggedIn&&Ae(r)?t(r):Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(r){return Promise.resolve(e.config.first(["discovery.wallet.method"],"IFRAME/RPC")).then(function(e){var i=function(t,i){try{var a=be(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=S(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({},R,{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 a&&a.then?a.then(i.bind(null,!1),i.bind(null,!0)):i(!1,a)}(0,function(e,r){return Promise.resolve(ke()).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 be(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",Se="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}',Re=function(e){try{return sessionStorage.setItem(Ce,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ie=function(){return e.config().get("persistSession",!0)},Le=((Z={})[n.INIT]=function(e){try{return e.merge(JSON.parse(Oe)),Promise.resolve(Ie()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(Oe),t=JSON.parse(sessionStorage.getItem(Ce));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Ce),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Ae(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Z[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,Se,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[we]=function(e,t,r){try{return e.merge(r),Promise.resolve(Ie()).then(function(t){t&&Re(e.all()),e.broadcast(Se,b({},e.all()))})}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(Oe)),Promise.resolve(Ie()).then(function(t){t&&Re(e.all()),e.broadcast(Se,b({},e.all()))})}catch(e){return Promise.reject(e)}},Z),je=function(){return n.spawn(Le,Ce)};function Ae(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function xe(){je(),n.send(Ce,"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=S(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,a=S(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){je();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 ge,s=he.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):he(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||Pe(o)&&!o.v)return void he(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):he(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 ke(){return je(),n.send(Ce,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var De,Te=function(e){return t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Ue="\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",_e=function(){return{authenticate:Ee,unauthenticate:xe,authorization:ye,signUserMessage:ve,verifyUserSignatures:me,subscribe:Fe,snapshot:ke}},Be=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},ze=function(e){return e.status>=3},Me=function(e){return e.status>=2},We=((De={})[n.INIT]=function(e){try{return Promise.resolve(Be(e.self())).then(function(t){Ve(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(Be(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)}},De),He=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ye=function(e){return n.spawn(We,He(e))};function Je(e){function t(t){return n.subscriber(He(e),Ye,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,Ye)},subscribe:t,onceFinalized:r(Me),onceExecuted:r(ze),onceSealed:r(Ve)}}Je.isUnknown=function(e){return e.status>=0},Je.isPending=function(e){return e.status>=1},Je.isFinalized=Me,Je.isExecuted=ze,Je.isSealed=Ve,Je.isExpired=function(e){return 5===e.status};var qe,Ke=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)}},Ge=((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(Ke(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=S(e);!(r=n()).done;)t.broadcast("UPDATED",r.value.data);var o=t.put;return Promise.resolve(Ke(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(Ke(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),Ze=function(e){return n.spawn(Ge,e)},$e={__proto__:null,sendMsgToFCL: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}),"*")},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var r=function(r){"object"==typeof r.data&&r.data.type===e&&(delete r.data.body.interaction,t(r.data))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}}},Xe=_e().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-alpha.3",exports.WalletUtils=$e,exports.authenticate=function(){return _e().authenticate()},exports.authz=Xe,exports.currentUser=_e,exports.events=function(e){return{subscribe:function(t){return n.subscriber(e,Ze,t)}}},exports.logIn=function(){return _e().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(m(e),"mutate(opts) -- opts must be an object"),t.invariant(h(e.cadence),"mutate({ cadence }) -- cadence is required"),t.invariant(v(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(c.config().get("fcl.authz",_e().authorization)).then(function(t){return c.send([c.transaction(e.cadence),c.args(P(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=E,exports.reauthenticate=function(){return _e().unauthenticate(),_e().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 _e().authenticate()},exports.t=Qe,exports.tx=Je,exports.unauthenticate=function(){return _e().unauthenticate()}; | ||
//# 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 u}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 d}from"@onflow/util-invariant";import*as l from"@onflow/types";import{spawn as p,send as f,SUBSCRIBE as y,UNSUBSCRIBE as h,INIT as m,subscriber as g,snapshoter as w,UPDATED as E,SNAPSHOT as v}from"@onflow/util-actor";import{withPrefix as R,sansPrefix as S}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as P from"@onflow/rlp";import{uid as b}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";async function C(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,n])=>[t.replace(e,""),n]))}t().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","frame");const A="0.0.77-alpha.2",I=e=>t=>typeof t===e,k=e=>null!=e,L=I("object"),N=I("string"),O=I("function"),D=I("number");function T(t){return O(t)?t(e.arg,l):[]}async function _(t={}){return await async function(e){d(k(e.cadence),"query({ cadence }) -- cadence is required"),d(N(e.cadence),"query({ cadence }) -- cadence must be a string")}(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 F(){return(F=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"},z={f_type:"Identity",f_vsn:"1.0.0"},U={f_type:"USER",f_vsn:"1.0.0"},M={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({old:e},x,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},x,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function J(e){if(null==e)return null;switch(null==e.method&&(e=F({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return F({},x,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}const $={"back-channel-rpc":B,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:F({},z,{address:R(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:F({},z,{address:R(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},x,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:R(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":J};function K(e){return P.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function V(e=[],t){return e.find(e=>e.type===t)}function G(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 Y(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(G(e),{method:n,headers:F({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function q(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:F({},e)}),e.f_vsn){case"1.0.0":return e;default:return F({},M,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:B(e.authorizationUpdates),local:j((e.local||[])[0])})}}const W={"HTTP/GET":"GET","HTTP/POST":"POST"},Z=e=>(d(W[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),W[e.method]);async function X(e,t=(()=>!0)){if(d(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await Y(e,{method:Z(e)}).then(q);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)),X(n.updates,t)}}const Q="FCL_IFRAME";function ee(e){d(!document.getElementById(Q),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=Q,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,()=>{document.getElementById(Q)&&document.getElementById(Q).remove()}]}let te=null,ne=null;function ae(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 re(e){var t;null==te||null!=(t=te)&&t.closed?te=ae(e,"FCL_POP",window,600,600):ne!==e?(te=ae(e,"FCL_POP",window,600,600),te.focus()):te.focus(),ne=e;var n=setInterval(function(){te&&te.closed&&(clearInterval(n),te=null)},1e3);return[te,()=>{te&&!te.closed&&(te.close(),te=null)}]}const se={"VIEW/IFRAME":ee,"VIEW/POP":re};async function oe(e,t,n={}){t.data=e.data;const a=await Y(e,{data:t}).then(q);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 se[e.method](G(e),t)}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}(J(a.local)),n=()=>{try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return X(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 ie=()=>{},ce=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ue=()=>{},de=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),le={"HTTP/RPC":oe,"HTTP/POST":oe,"IFRAME/RPC":function(e,t,n){return new Promise((a,r)=>{const s=b(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:ie,close:ie};const n=t.onClose||ie,a=t.onMessage||ie,r=t.onReady||ie,s=t.onResponse||ie;window.addEventListener("message",c);const[o,i]=ee(G(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(ce.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:d,close:u}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:d,close:u}),a(e,{send:d,close:u}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&s(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&r(e,{send:d,close:u}),"FCL::CHALLENGE::CANCEL"===e.data.type&&u(),"FCL::CANCEL"===e.data.type&&u()}catch(e){console.error("Frame Callback Error",e),u()}}function u(){try{window.removeEventListener("message",c),i(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{o.contentWindow.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:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await C(/^service\./),app:await C(/^app\.detail\./)}}),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=q(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=q(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=b(),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]=re(G(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(de.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:d,close:u}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:d,close:u}),a(e,{send:d,close:u}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&s(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&r(e,{send:d,close:u}),"FCL::CHALLENGE::CANCEL"===e.data.type&&u(),"FCL::CANCEL"===e.data.type&&u()}catch(e){console.error("Popup Callback Error",e),u()}}function u(){try{window.removeEventListener("message",c),i(),n()}catch(e){console.error("Popup Close Error",e)}}function d(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:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data},config:{services:await C(/^service\./),app:await C(/^app\.detail\./)}}),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=q(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=q(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 pe({service:e,msg:t={},opts:n={}}){try{return le[e.method](e,t,n)}catch(a){throw console.error("execService({service, msg = {}, opts = {}})",a,{service:e,msg:t,opts:n}),a}}function fe(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},H,{addr:S(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const ye="CURRENT_USER",he="CURRENT_USER/UPDATED",me='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ge=async e=>(sessionStorage.setItem(ye,JSON.stringify(e)),e),we=()=>t().get("persistSession",!0),Ee={[m]:async e=>{if(e.merge(JSON.parse(me)),await we()){const t=await(async()=>{const e=JSON.parse(me),t=JSON.parse(sessionStorage.getItem(ye));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(ye),e):t||e})();Re(t)&&e.merge(t)}},[y]:(e,t)=>{e.subscribe(t.from),e.send(t.from,he,F({},e.all()))},[h]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(F({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await we()&&ge(e.all()),e.broadcast(he,F({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(me)),await we()&&ge(e.all()),e.broadcast(he,F({},e.all()))}},ve=()=>p(Ee,ye);function Re(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Se(){return new Promise(async(e,n)=>{ve();const a=await Ae();if(a.loggedIn&&Re(a))return e(a);const r=await t.first(["discovery.wallet","challenge.handshake"]),s="frame"===await t.first(["discovery.wallet.method"],"frame")?"IFRAME/RPC":"POP/RPC";try{const t=await pe({service:{endpoint:r,method:s}});f(ye,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?R(e.addr):null,e.paddr=e.paddr?R(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(F({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(F({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 F({},U,{addr:R(e.addr),cid:K(n),loggedIn:!0,services:t,expiresAt:e.exp})}(t))}catch(e){console.error("Error while authenticating",e)}finally{e(await Ae())}})}function Pe(){ve(),f(ye,"DEL_CURRENT_USER")}async function be(e){ve();const t=await Se(),n=V(t.services,"authz"),a=V(t.services,"pre-authz");return F({},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=>pe({service:t,msg:e}),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await pe({service:a,msg:t}))}:{tempId:"CURRENT_USER",resolve:null,addr:S(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>fe(await pe({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}}))})}function Ce(e){ve();const t="@EXIT",n=p(async n=>{for(n.send(ye,y);;){const a=await n.receive();if(a.tag===t)return void n.send(ye,h);e(a.data)}});return()=>f(n,t)}function Ae(){return ve(),f(ye,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ie=e=>(d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e});async function ke(e){ve();const t=V((await Se()).services,"user-signature");d(t,"Current user must have authorized a signing service.");try{const n=await pe({service:t,msg:Ie(e)});return Array.isArray(n)?n.map(e=>fe(e)):[fe(n)]}catch(e){return e}}async function Le(e,t){d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),d(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[],r=[];const s=await Promise.all(t.map(async e=>{d("string"==typeof e.addr,"addr must be a string"),d("number"==typeof e.keyId,"keyId must be a number"),d("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:"\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",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 Ne=()=>({authenticate:Se,unauthenticate:Pe,authorization:be,signUserMessage:ke,verifyUserSignatures:Le,subscribe:Ce,snapshot:Ae}),Oe=async e=>n([a(e)]).then(r),De=e=>e.status>=4,Te=e=>e.status>=3,_e=e=>e.status>=2,Fe={[m]:async e=>{const t=await Oe(e.self());De(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[y]:(e,t)=>{e.subscribe(t.from),e.send(t.from,E,e.all())},[h]:(e,t)=>{e.unsubscribe(t.from)},[v]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await Oe(e.self());var n,a;De(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(E,t),e.merge(t)}},xe=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},ze=e=>p(Fe,xe(e));function Ue(e){function t(t){return g(xe(e),ze,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,ze)},subscribe:t,onceFinalized:n(_e),onceExecuted:n(Te),onceSealed:n(De)}}async function Me(t={}){try{await async function(e){d(k(e),"mutate(opts) -- opts is required"),d(L(e),"mutate(opts) -- opts must be an object"),d(k(e.cadence),"mutate({ cadence }) -- cadence is required"),d(N(e.cadence),"mutate({ cadence }) -- cadence must be a string")}(t);const n=await e.config().get("fcl.authz",Ne().authorization);return e.send([e.transaction(t.cadence),e.args(T(t.args||[])),t.limit&&D(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}}Ue.isUnknown=e=>e.status>=0,Ue.isPending=e=>e.status>=1,Ue.isFinalized=_e,Ue.isExecuted=Te,Ue.isSealed=De,Ue.isExpired=e=>5===e.status;const He=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)},je=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),Be={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await u()),e.put("tick",await je(e));else{let a=await u();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 je(e))}},[y]:async(e,t)=>{e.hasSubs()||e.put("tick",await je(e)),e.subscribe(t.from)},[h]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},Je=e=>p(Be,e);function $e(e){return{subscribe:t=>g(e,Je,t)}}var Ke={__proto__:null,sendMsgToFCL:(e,t={})=>{window.location!==window.parent.location?window.parent.postMessage(F({},t,{type:e}),"*"):window.opener.postMessage(F({},t,{type:e}),"*")}};const Ve=()=>Ne().authenticate(),Ge=()=>Ne().unauthenticate(),Ye=()=>(Ne().unauthenticate(),Ne().authenticate()),qe=()=>Ne().authenticate(),We=()=>Ne().authenticate(),Ze=Ne().authorization,Xe=l;export{A as VERSION,Ke as WalletUtils,Ve as authenticate,Ze as authz,Ne as currentUser,$e as events,We as logIn,Me as mutate,_ as query,Ye as reauthenticate,He as serialize,qe as signUp,Xe as t,Ue as tx,Ge as unauthenticate}; | ||
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}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 l}from"@onflow/util-invariant";import*as u from"@onflow/types";import{spawn as p,send as y,SUBSCRIBE as f,UNSUBSCRIBE as E,INIT as h,subscriber as m,snapshoter as g,UPDATED as w,SNAPSHOT as C}from"@onflow/util-actor";import{withPrefix as R,sansPrefix as S}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as L from"@onflow/rlp";import{uid as v}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";async function P(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,n])=>[t.replace(e,""),n]))}t().put("accessNode.api","http://localhost:8080").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","IFRAME/RPC");const I="0.0.77-alpha.3",A=e=>t=>typeof t===e,b=e=>null!=e,O=A("object"),F=A("string"),N=A("function"),D=A("number");function k(t){return N(t)?t(e.arg,u):[]}async function T(t={}){return await async function(e){l(b(e.cadence),"query({ cadence }) -- cadence is required"),l(F(e.cadence),"query({ cadence }) -- cadence must be a string")}(t),e.send([e.script(t.cadence),e.args(k(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function _(){return(_=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"},V={f_type:"Identity",f_vsn:"1.0.0"},z={f_type:"USER",f_vsn:"1.0.0"},U={f_type:"PollingResponse",f_vsn:"1.0.0"},W={f_type:"CompositeSignature",f_vsn:"1.0.0"};function M(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({old:e},x,{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 _({},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=_({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return _({},x,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}const Y={"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 _({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},V,{address:R(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},x,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},V,{address:R(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},x,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:R(e.addr),name:e.name,icon:e.icon}})}},frame:M,"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 B(e=[],t){return e.find(e=>e.type===t)}function J(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(J(e),{method:n,headers:_({},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:_({},e)}),e.f_vsn){case"1.0.0":return e;default:return _({},U,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:j(e.authorizationUpdates),local:M((e.local||[])[0])})}}const q={"HTTP/GET":"GET","HTTP/POST":"POST"},Z=e=>(l(q[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),q[e.method]);async function X(e,t=(()=>!0)){if(l(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await K(e,{method:Z(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)),X(n.updates,t)}}const Q="FCL_IFRAME";function ee(e){l(!document.getElementById(Q),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=Q,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(Q)&&document.getElementById(Q).remove()}]}let te=null,ne=null;function ae(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 re(e){var t;null==te||null!=(t=te)&&t.closed?te=ae(e,"FCL_POP",window,640,600):ne!==e?(te=ae(e,"FCL_POP",window,640,600),te.focus()):te.focus(),ne=e;var n=setInterval(function(){te&&te.closed&&(clearInterval(n),te=null)},1e3);return[te,()=>{te&&!te.closed&&(te.close(),te=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=window.open(e,"_blank"),se.focus()):se.focus(),oe=e;var n=setInterval(function(){se&&se.closed&&(clearInterval(n),se=null)},1e3);return[se,()=>{se&&!se.closed&&(se.close(),se=null)}]}const ce={"VIEW/IFRAME":ee,"VIEW/POP":re,"VIEW/TAB":ie};async function de(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 ce[e.method](J(e),t)}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}(H(a.local)),n=()=>{try{t(),r=!1}catch(e){console.error("Frame Close Error",e)}};return X(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 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`),ye=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),fe=()=>{},Ee=e=>"string"==typeof e&&e.toLowerCase(),he=(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"]),ge=()=>{},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,n){return new Promise((a,r)=>{const s=v(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:le,close:le};const n=t.onClose||le,a=t.onMessage||le,r=t.onReady||le,s=t.onResponse||le;window.addEventListener("message",c);const[o,i]=ee(J(e));return{send:l,close:d};function c(e){try{if("object"!=typeof e.data)return;if(ye.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}),a(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(),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 P(/^service\./),app:await P(/^app\.detail\./)}}),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("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=v(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:fe,close:fe};const n=t.onClose||fe,a=t.onMessage||fe,r=t.onReady||fe,s=t.onResponse||fe;window.addEventListener("message",c);const[o,i]=re(J(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}),a(e,{send:l,close:d}),Ee(e.data.type)===Ee("FCL:FRAME:READY")&&(he(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL:FRAME:RESPONSE")&&(he(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL:FRAME:CLOSE")&&(he(e.data.type,"FCL:VIEW:CLOSE"),d()),Ee(e.data.type)===Ee("FCL::CHALLENGE::RESPONSE")&&(he(e.data.type,"FCL:VIEW:RESPONSE"),s(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL::AUTHZ_READY")&&(he(e.data.type,"FCL:VIEW:READY"),r(e,{send:l,close:d})),Ee(e.data.type)===Ee("FCL::CHALLENGE::CANCEL")&&(he(e.data.type,"FCL:VIEW:CLOSE"),d()),Ee(e.data.type)===Ee("FCL::CANCEL")&&(he(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 P(/^service\./),app:await P(/^app\.detail\./)}}),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=v(),o=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t={}){if(null==e)return{send:ge,close:ge};const n=t.onClose||ge,a=t.onMessage||ge,r=t.onReady||ge,s=t.onResponse||ge;window.addEventListener("message",c);const[o,i]=ie(J(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}),a(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(),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 P(/^service\./),app:await P(/^app\.detail\./)}}),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 Se[e.method](e,t,n)}catch(a){throw console.error("execService({service, msg = {}, opts = {}})",a,{service:e,msg:t,opts:n}),a}}function ve(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},W,{addr:S(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const Pe="CURRENT_USER",Ie="CURRENT_USER/UPDATED",Ae='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',be=async e=>(sessionStorage.setItem(Pe,JSON.stringify(e)),e),Oe=()=>t().get("persistSession",!0),Fe={[h]:async e=>{if(e.merge(JSON.parse(Ae)),await Oe()){const t=await(async()=>{const e=JSON.parse(Ae),t=JSON.parse(sessionStorage.getItem(Pe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Pe),e):t||e})();De(t)&&e.merge(t)}},[f]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Ie,_({},e.all()))},[E]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(_({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Oe()&&be(e.all()),e.broadcast(Ie,_({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Ae)),await Oe()&&be(e.all()),e.broadcast(Ie,_({},e.all()))}},Ne=()=>p(Fe,Pe);function De(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function ke(){return new Promise(async(e,n)=>{Ne();const a=await Ve();if(a.loggedIn&&De(a))return e(a);const r=await t.first(["discovery.wallet","challenge.handshake"]),s=await t.first(["discovery.wallet.method"],"IFRAME/RPC");try{const t=await Le({service:{endpoint:r,method:s}});y(Pe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?R(e.addr):null,e.paddr=e.paddr?R(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(_({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(_({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return Y[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 _({},z,{addr:R(e.addr),cid:$(n),loggedIn:!0,services:t,expiresAt:e.exp})}(t))}catch(e){console.error("Error while authenticating",e)}finally{e(await Ve())}})}function Te(){Ne(),y(Pe,"DEL_CURRENT_USER")}async function _e(e){Ne();const t=await ke(),n=B(t.services,"authz"),a=B(t.services,"pre-authz");return _({},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:S(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>ve(await Le({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}}))})}function xe(e){Ne();const t="@EXIT",n=p(async n=>{for(n.send(Pe,f);;){const a=await n.receive();if(a.tag===t)return void n.send(Pe,E);e(a.data)}});return()=>y(n,t)}function Ve(){return Ne(),y(Pe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const ze=e=>(l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e});async function Ue(e){Ne();const t=B((await ke()).services,"user-signature");l(t,"Current user must have authorized a signing service.");try{const n=await Le({service:t,msg:ze(e)});return Array.isArray(n)?n.map(e=>ve(e)):[ve(n)]}catch(e){return e}}async function We(e,t){l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),l(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[],r=[];const s=await Promise.all(t.map(async e=>{l("string"==typeof e.addr,"addr must be a string"),l("number"==typeof e.keyId,"keyId must be a number"),l("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 T({cadence:"\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",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 Me=()=>({authenticate:ke,unauthenticate:Te,authorization:_e,signUserMessage:Ue,verifyUserSignatures:We,subscribe:xe,snapshot:Ve}),je=async e=>n([a(e)]).then(r),He=e=>e.status>=4,Ye=e=>e.status>=3,$e=e=>e.status>=2,Be={[h]:async e=>{const t=await je(e.self());He(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[f]:(e,t)=>{e.subscribe(t.from),e.send(t.from,w,e.all())},[E]:(e,t)=>{e.unsubscribe(t.from)},[C]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await je(e.self());var n,a;He(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(w,t),e.merge(t)}},Je=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ke=e=>p(Be,Je(e));function Ge(e){function t(t){return m(Je(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 g(e,Ke)},subscribe:t,onceFinalized:n($e),onceExecuted:n(Ye),onceSealed:n(He)}}async function qe(t={}){try{await async function(e){l(b(e),"mutate(opts) -- opts is required"),l(O(e),"mutate(opts) -- opts must be an object"),l(b(e.cadence),"mutate({ cadence }) -- cadence is required"),l(F(e.cadence),"mutate({ cadence }) -- cadence must be a string")}(t);const n=await e.config().get("fcl.authz",Me().authorization);return e.send([e.transaction(t.cadence),e.args(k(t.args||[])),t.limit&&D(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=$e,Ge.isExecuted=Ye,Ge.isSealed=He,Ge.isExpired=e=>5===e.status;const Ze=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)},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 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 Xe(e))}},[f]:async(e,t)=>{e.hasSubs()||e.put("tick",await Xe(e)),e.subscribe(t.from)},[E]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},et=e=>p(Qe,e);function tt(e){return{subscribe:t=>m(e,et,t)}}var nt={__proto__:null,sendMsgToFCL:(e,t={})=>{window.location!==window.parent.location?window.parent.postMessage(_({},t,{type:e}),"*"):window.opener.postMessage(_({},t,{type:e}),"*")},onMessageFromFCL:(e,t=(()=>{}))=>{const n=n=>{"object"==typeof n.data&&n.data.type===e&&(delete n.data.body.interaction,t(n.data))};return window.addEventListener("message",n),()=>window.removeEventListener("message",n)}};const at=()=>Me().authenticate(),rt=()=>Me().unauthenticate(),st=()=>(Me().unauthenticate(),Me().authenticate()),ot=()=>Me().authenticate(),it=()=>Me().authenticate(),ct=Me().authorization,dt=u;export{I as VERSION,nt as WalletUtils,at as authenticate,ct as authz,Me as currentUser,tt as events,it as logIn,qe as mutate,T as query,st as reauthenticate,Ze as serialize,ot as signUp,dt as t,Ge as tx,rt as unauthenticate}; | ||
//# 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 i,resolve as a,createSignableVoucher as s,pipe as u,interaction as c,latestBlock 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 d}from"@onflow/util-invariant";import*as f from"@onflow/types";import{INIT as h,SUBSCRIBE as p,UNSUBSCRIBE as m,spawn as v,send as y,UPDATED as g,SNAPSHOT as P,subscriber as E,snapshoter as w}from"@onflow/util-actor";import{withPrefix as b,sansPrefix as S}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as R from"@onflow/rlp";import{uid as A}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";var C=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().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","frame");var I="0.0.77-alpha.2",k=function(e){return function(t){return typeof t===e}},j=function(e){return null!=e},L=k("object"),O=k("string"),N=k("function"),D=k("number");function T(t){return N(t)?t(e.arg,f):[]}var _=function(t){void 0===t&&(t={});try{return Promise.resolve(function(e){try{return d(j(e.cadence),"query({ cadence }) -- cadence is required"),d(O(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}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 F(){return(F=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 z(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 U={f_type:"Service",f_vsn:"1.0.0"},M={f_type:"Identity",f_vsn:"1.0.0"},H={f_type:"USER",f_vsn:"1.0.0"},B={f_type:"PollingResponse",f_vsn:"1.0.0"},J={f_type:"CompositeSignature",f_vsn:"1.0.0"};function K(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({old:e},U,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function V(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function G(e){if(null==e)return null;switch(null==e.method&&(e=F({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var Y={"back-channel-rpc":V,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:F({},M,{address:b(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:F({},M,{address:b(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},U,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:b(e.addr),name:e.name,icon:e.icon}})}},frame:K,"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":G};function q(e){return R.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function W(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function Z(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 $(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(Z(e),{method:r,headers:F({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function X(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:F({},e)}),e.f_vsn){case"1.0.0":return e;default:return F({},B,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:V(e.authorizationUpdates),local:K((e.local||[])[0])})}}var Q=function e(t,r){void 0===r&&(r=function(){return!0});try{if(d(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve($(t,{method:te(t)}).then(X)).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)}},ee={"HTTP/GET":"GET","HTTP/POST":"POST"},te=function(e){return d(ee[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ee[e.method]},re="FCL_IFRAME";function ne(e){d(!document.getElementById(re),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=re,t.allow="usb *; hid *",t.frameBorder="0",t.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(t),[t,function(){document.getElementById(re)&&document.getElementById(re).remove()}]}var oe=null,ie=null;function ae(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 se(e){var t;null==oe||null!=(t=oe)&&t.closed?oe=ae(e,"FCL_POP",window,600,600):ie!==e?(oe=ae(e,"FCL_POP",window,600,600)).focus():oe.focus(),ie=e;var r=setInterval(function(){oe&&oe.closed&&(clearInterval(r),oe=null)},1e3);return[oe,function(){oe&&!oe.closed&&(oe.close(),oe=null)}]}var ue,ce={"VIEW/IFRAME":ne,"VIEW/POP":se},le=function(e,t,r){try{return t.data=e.data,Promise.resolve($(e,{data:t}).then(X)).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(ce[e.method](Z(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(G(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return Q(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)}},de=function(){},fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),he=function(){},pe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),me=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(ve[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)}},ve={"HTTP/RPC":le,"HTTP/POST":le,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var i=A(),a=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:de,close:de};var r=t.onClose||de,n=t.onMessage||de,o=t.onReady||de,i=t.onResponse||de;window.addEventListener("message",c);var a=ne(Z(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;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),n(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{s.contentWindow.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(C(/^service\./)).then(function(n){return Promise.resolve(C(/^app\.detail\./)).then(function(s){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}}),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 r=t.close;try{if("object"!=typeof e.data)return;var i=X(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=X(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(),a=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,i=t.onResponse||he;window.addEventListener("message",c);var a=se(Z(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;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),n(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Popup Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),u(),r()}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(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(C(/^service\./)).then(function(n){return Promise.resolve(C(/^app\.detail\./)).then(function(s){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}}),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 r=t.close;try{if("object"!=typeof e.data)return;var i=X(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=X(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")}})})}};function ye(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return F({},J,{addr:S(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function ge(e,t,r){if(!e.s){if(r instanceof be){if(!r.s)return void(r.o=ge.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ge.bind(null,e,t),ge.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Pe=function(e,t){try{d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),d(Array.isArray(t),"Must include an Array of composite signatures");var n=[],o=[],i=[];return Promise.resolve(Promise.all(t.map(function(e){try{return d("string"==typeof e.addr,"addr must be a string"),d("number"==typeof e.keyId,"keyId must be a number"),d("string"==typeof e.signature,"signature must be a string"),Promise.resolve(Ae(function(){return 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),i.push(e.signature),t.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(_({cadence:""+He,args:function(r,a){return[r(e,a.String),r(t,a.Array([a.String])),r(n,a.Array(a.UFix64)),r(o,a.Array([a.UInt])),r(i,a.Array([a.String]))]}}))})}catch(e){return Promise.reject(e)}},Ee=function(e){try{return De(),Promise.resolve(Re()).then(function(t){var r=W(t.services,"user-signature");return d(r,"Current user must have authorized a signing service."),Ae(function(){return Promise.resolve(me({service:r,msg:Me(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return ye(e)}):[ye(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},we=function(e){try{return De(),Promise.resolve(Re()).then(function(t){var r=W(t.services,"authz"),n=W(t.services,"pre-authz");return F({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(me({service:n,msg:t})).then(Fe)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:S(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(me({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(ye)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},be=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{ge(n,1,i(this.v))}catch(e){ge(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ge(n,1,t?t(o):o):r?ge(n,1,r(o)):ge(n,2,o)}catch(e){ge(n,2,e)}},n},e}();function Se(e){return e instanceof be&&1&e.s}var Re=function(){try{return Promise.resolve(new Promise(function(e,r){try{return De(),Promise.resolve(ze()).then(function(r){return r.loggedIn&&Te(r)?e(r):Promise.resolve(t.first(["discovery.wallet","challenge.handshake"])).then(function(r){return Promise.resolve(t.first(["discovery.wallet.method"],"frame")).then(function(t){var n="frame"===t?"IFRAME/RPC":"POP/RPC",o=function(e,t){try{var o=Ae(function(){return Promise.resolve(me({service:{endpoint:r,method:n}})).then(function(e){return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?b(e.addr):null,e.paddr=e.paddr?b(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=z(e.authorizations);!(r=n()).done;)t.push(F({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(F({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,i=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return function(e,t){try{return Y[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return F({},H,{addr:b(e.addr),cid:q(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){y(Ce,ke,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return t(!0,e)}return o&&o.then?o.then(t.bind(null,!1),t.bind(null,!0)):t(!1,o)}(0,function(t,r){return Promise.resolve(ze()).then(function(n){if(e(n),t)throw r;return r})});if(o&&o.then)return o.then(function(){})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function Ae(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",Ie="CURRENT_USER/UPDATED",ke="SET_CURRENT_USER",je='{\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=function(e){try{return sessionStorage.setItem(Ce,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Oe=function(){return t().get("persistSession",!0)},Ne=((ue={})[h]=function(e){try{return e.merge(JSON.parse(je)),Promise.resolve(Oe()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(je),t=JSON.parse(sessionStorage.getItem(Ce));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Ce),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Te(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},ue[p]=function(e,t){e.subscribe(t.from),e.send(t.from,Ie,F({},e.all()))},ue[m]=function(e,t){e.unsubscribe(t.from)},ue.SNAPSHOT=function(e,t){try{return t.reply(F({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},ue[ke]=function(e,t,r){try{return e.merge(r),Promise.resolve(Oe()).then(function(t){t&&Le(e.all()),e.broadcast(Ie,F({},e.all()))})}catch(e){return Promise.reject(e)}},ue.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(je)),Promise.resolve(Oe()).then(function(t){t&&Le(e.all()),e.broadcast(Ie,F({},e.all()))})}catch(e){return Promise.reject(e)}},ue),De=function(){return v(Ne,Ce)};function Te(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function _e(){De(),y(Ce,"DEL_CURRENT_USER")}function Fe(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=z(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,a=z(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 me({service:r,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function xe(e){De();var t="@EXIT",r=v(function(r){try{var n;return r.send(Ce,p),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(Se(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Se(i)){n=1;break}i=i.s}}var a=new be,s=ge.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):ge(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||Se(o)&&!o.v)return void ge(a,1,i);if(o.then)return void o.then(c).then(void 0,s);Se(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):ge(a,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if(o.tag===t)return r.send(Ce,m),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return y(r,t)}}function ze(){return De(),y(Ce,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ue,Me=function(e){return d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message: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",Be=function(){return{authenticate:Re,unauthenticate:_e,authorization:we,signUserMessage:Ee,verifyUserSignatures:Pe,subscribe:xe,snapshot:ze}},Je=function(e){try{return Promise.resolve(n([o(e)]).then(i))}catch(e){return Promise.reject(e)}},Ke=function(e){return e.status>=4},Ve=function(e){return e.status>=3},Ge=function(e){return e.status>=2},Ye=((Ue={})[h]=function(e){try{return Promise.resolve(Je(e.self())).then(function(t){Ke(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},Ue[p]=function(e,t){e.subscribe(t.from),e.send(t.from,g,e.all())},Ue[m]=function(e,t){e.unsubscribe(t.from)},Ue[P]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Ue.POLL=function(e){try{return Promise.resolve(Je(e.self())).then(function(t){var r,n;Ke(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)}},Ue),qe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},We=function(e){return v(Ye,qe(e))};function Ze(e){function t(t){return E(qe(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 w(e,We)},subscribe:t,onceFinalized:r(Ge),onceExecuted:r(Ve),onceSealed:r(Ke)}}Ze.isUnknown=function(e){return e.status>=0},Ze.isPending=function(e){return e.status>=1},Ze.isFinalized=Ge,Ze.isExecuted=Ve,Ze.isSealed=Ke,Ze.isExpired=function(e){return 5===e.status};var $e,Xe=function(t){void 0===t&&(t={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(e){try{return d(j(e),"mutate(opts) -- opts is required"),d(L(e),"mutate(opts) -- opts must be an object"),d(j(e.cadence),"mutate({ cadence }) -- cadence is required"),d(O(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(t)).then(function(){return Promise.resolve(e.config().get("fcl.authz",Be().authorization)).then(function(r){return e.send([e.transaction(t.cadence),e.args(T(t.args||[])),t.limit&&D(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)}},Qe=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.first(["sdk.resolve"],r.resolve||a)).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)}},et=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)}},tt=(($e={}).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(l()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(et(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(l()).then(function(r){return e.put("hwm",r),Promise.resolve(n([getEvents(e.self(),t.height,r.height-1)]).then(i)).then(function(t){for(var r,n=z(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(et(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)}},$e[p]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(et(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)}},$e[m]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},$e),rt=function(e){return v(tt,e)};function nt(e){return{subscribe:function(t){return E(e,rt,t)}}}var ot={__proto__:null,sendMsgToFCL:function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(F({},t,{type:e}),"*"):window.opener.postMessage(F({},t,{type:e}),"*")}},it=function(){return Be().authenticate()},at=function(){return Be().unauthenticate()},st=function(){return Be().unauthenticate(),Be().authenticate()},ut=function(){return Be().authenticate()},ct=function(){return Be().authenticate()},lt=Be().authorization,dt=f;export{I as VERSION,ot as WalletUtils,it as authenticate,lt as authz,Be as currentUser,nt as events,ct as logIn,Xe as mutate,_ as query,st as reauthenticate,Qe as serialize,ut as signUp,dt as t,Ze as tx,at as unauthenticate}; | ||
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}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 l}from"@onflow/util-invariant";import*as f from"@onflow/types";import{INIT as p,SUBSCRIBE as h,UNSUBSCRIBE as v,spawn as m,send as y,UPDATED as E,SNAPSHOT as P,subscriber as g,snapshoter as C}from"@onflow/util-actor";import{withPrefix as w,sansPrefix as S}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as R from"@onflow/rlp";import{uid as L}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";var b=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().put("accessNode.api","http://localhost:8080").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","IFRAME/RPC");var I="0.0.77-alpha.3",A=function(e){return function(t){return typeof t===e}},O=function(e){return null!=e},F=A("object"),N=A("string"),D=A("function"),j=A("number");function k(t){return D(t)?t(e.arg,f):[]}var T=function(t){void 0===t&&(t={});try{return Promise.resolve(function(e){try{return l(O(e.cadence),"query({ cadence }) -- cadence is required"),l(N(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(t)).then(function(){return e.send([e.script(t.cadence),e.args(k(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function _(){return(_=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function V(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 z={f_type:"Service",f_vsn:"1.0.0"},W={f_type:"Identity",f_vsn:"1.0.0"},M={f_type:"USER",f_vsn:"1.0.0"},U={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Y(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({old:e},z,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},z,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function J(e){if(null==e)return null;switch(null==e.method&&(e=_({},e,{type:"local-view",method:"VIEW/IFRAME"})),e.f_vsn){case"1.0.0":return e;default:return _({},z,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var K={"back-channel-rpc":B,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},z,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},W,{address:w(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 _({},z,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},W,{address:w(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 _({},z,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:w(e.addr),name:e.name,icon:e.icon}})}},frame:Y,"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":J};function G(e){return R.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function q(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function Z(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 $(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(Z(e),{method:r,headers:_({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function X(e){var t;if(null==e)return null;switch((e.addr||e.services)&&(e={status:"APPROVED",data:_({},e)}),e.f_vsn){case"1.0.0":return e;default:return _({},U,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:B(e.authorizationUpdates),local:Y((e.local||[])[0])})}}var Q=function e(t,r){void 0===r&&(r=function(){return!0});try{if(l(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve($(t,{method:te(t)}).then(X)).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)}},ee={"HTTP/GET":"GET","HTTP/POST":"POST"},te=function(e){return l(ee[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ee[e.method]},re="FCL_IFRAME";function ne(e){l(!document.getElementById(re),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=re,t.allow="usb *; hid *",t.frameBorder="0",t.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(t),[t.contentWindow,function(){document.getElementById(re)&&document.getElementById(re).remove()}]}var oe=null,ae=null;function ie(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 se(e){var t;null==oe||null!=(t=oe)&&t.closed?oe=ie(e,"FCL_POP",window,640,600):ae!==e?(oe=ie(e,"FCL_POP",window,640,600)).focus():oe.focus(),ae=e;var r=setInterval(function(){oe&&oe.closed&&(clearInterval(r),oe=null)},1e3);return[oe,function(){oe&&!oe.closed&&(oe.close(),oe=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=window.open(e,"_blank")).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":ne,"VIEW/POP":se,"VIEW/TAB":de},pe=function(e,t,r){try{return t.data=e.data,Promise.resolve($(e,{data:t}).then(X)).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](Z(e),t))}catch(r){throw console.error("execLocal({service, opts = {}})",r,{service:e,opts:t}),r}}catch(e){return Promise.reject(e)}}(J(t.local))).then(function(e){var n=e[1],o=function(){try{n(),r=!1}catch(e){console.error("Frame Close Error",e)}};return Q(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(){},Pe=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")},Ce=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),we=function(){},Se=function(e){return"string"==typeof e&&e.toLowerCase()},Re=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(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":pe,"HTTP/POST":pe,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var a=L(),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=ne(Z(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(b(/^service\./)).then(function(n){return Promise.resolve(b(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}}),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=X(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=X(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=L(),i=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(Z(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;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")&&(ge(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL:FRAME:RESPONSE")&&(ge(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL:FRAME:CLOSE")&&(ge(e.data.type,"FCL:VIEW:CLOSE"),d()),Pe(e.data.type)===Pe("FCL::CHALLENGE::RESPONSE")&&(ge(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL::AUTHZ_READY")&&(ge(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Pe(e.data.type)===Pe("FCL::CHALLENGE::CANCEL")&&(ge(e.data.type,"FCL:VIEW:CLOSE"),d()),Pe(e.data.type)===Pe("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),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(b(/^service\./)).then(function(n){return Promise.resolve(b(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}}),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=X(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=X(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=L(),i=r.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:we,close:we};var r=t.onClose||we,n=t.onMessage||we,o=t.onReady||we,a=t.onResponse||we;window.addEventListener("message",c);var i=de(Z(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")&&(Re(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Se(e.data.type)===Se("FCL:FRAME:RESPONSE")&&(Re(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Se(e.data.type)===Se("FCL:FRAME:CLOSE")&&(Re(e.data.type,"FCL:VIEW:CLOSE"),d()),Se(e.data.type)===Se("FCL::CHALLENGE::RESPONSE")&&(Re(e.data.type,"FCL:VIEW:RESPONSE"),a(e,{send:l,close:d})),Se(e.data.type)===Se("FCL::AUTHZ_READY")&&(Re(e.data.type,"FCL:VIEW:READY"),o(e,{send:l,close:d})),Se(e.data.type)===Se("FCL::CHALLENGE::CANCEL")&&(Re(e.data.type,"FCL:VIEW:CLOSE"),d()),Se(e.data.type)===Se("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),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(b(/^service\./)).then(function(n){return Promise.resolve(b(/^app\.detail\./)).then(function(s){o({type:"FCL:VIEW:READY:RESPONSE",body:t,service:r,config:{services:n,app:s}}),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=X(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=X(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")}})})}};function Ae(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},H,{addr:S(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function Oe(e,t,r){if(!e.s){if(r instanceof je){if(!r.s)return void(r.o=Oe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Oe.bind(null,e,t),Oe.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Fe=function(e,t){try{l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),l(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 l("string"==typeof e.addr,"addr must be a string"),l("number"==typeof e.keyId,"keyId must be a number"),l("string"==typeof e.signature,"signature must be a string"),Promise.resolve(_e(function(){return 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})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(T({cadence:""+Xe,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)}},Ne=function(e){try{return Ye(),Promise.resolve(Te()).then(function(t){var r=q(t.services,"user-signature");return l(r,"Current user must have authorized a signing service."),_e(function(){return Promise.resolve(be({service:r,msg:$e(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Ae(e)}):[Ae(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},De=function(e){try{return Ye(),Promise.resolve(Te()).then(function(t){var r=q(t.services,"authz"),n=q(t.services,"pre-authz");return _({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(be({service:n,msg:t})).then(Ke)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:S(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(be({service:r,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(Ae)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},je=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{Oe(n,1,a(this.v))}catch(e){Oe(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Oe(n,1,t?t(o):o):r?Oe(n,1,r(o)):Oe(n,2,o)}catch(e){Oe(n,2,e)}},n},e}();function ke(e){return e instanceof je&&1&e.s}var Te=function(){try{return Promise.resolve(new Promise(function(e,r){try{return Ye(),Promise.resolve(qe()).then(function(r){return r.loggedIn&&Be(r)?e(r):Promise.resolve(t.first(["discovery.wallet","challenge.handshake"])).then(function(r){return Promise.resolve(t.first(["discovery.wallet.method"],"IFRAME/RPC")).then(function(t){var n=function(e,n){try{var o=_e(function(){return Promise.resolve(be({service:{endpoint:r,method:t}})).then(function(e){return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?w(e.addr):null,e.paddr=e.paddr?w(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=V(e.authorizations);!(r=n()).done;)t.push(_({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(_({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,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 _({},M,{addr:w(e.addr),cid:G(i),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){y(xe,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(qe()).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 _e(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var xe="CURRENT_USER",Ve="CURRENT_USER/UPDATED",ze="SET_CURRENT_USER",We='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Me=function(e){try{return sessionStorage.setItem(xe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ue=function(){return t().get("persistSession",!0)},He=((le={})[p]=function(e){try{return e.merge(JSON.parse(We)),Promise.resolve(Ue()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(We),t=JSON.parse(sessionStorage.getItem(xe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(xe),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Be(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},le[h]=function(e,t){e.subscribe(t.from),e.send(t.from,Ve,_({},e.all()))},le[v]=function(e,t){e.unsubscribe(t.from)},le.SNAPSHOT=function(e,t){try{return t.reply(_({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},le[ze]=function(e,t,r){try{return e.merge(r),Promise.resolve(Ue()).then(function(t){t&&Me(e.all()),e.broadcast(Ve,_({},e.all()))})}catch(e){return Promise.reject(e)}},le.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(We)),Promise.resolve(Ue()).then(function(t){t&&Me(e.all()),e.broadcast(Ve,_({},e.all()))})}catch(e){return Promise.reject(e)}},le),Ye=function(){return m(He,xe)};function Be(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Je(){Ye(),y(xe,"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=V(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var a,i=V(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 Ge(e){Ye();var t="@EXIT",r=m(function(r){try{var n;return r.send(xe,h),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(ke(o)&&(o=o.v),!o)return a;if(o.then){n=0;break}var a=r();if(a&&a.then){if(!ke(a)){n=1;break}a=a.s}}var i=new je,s=Oe.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):Oe(i,1,a)})).then(void 0,s),i;function u(t){a=t;do{if(!(o=e())||ke(o)&&!o.v)return void Oe(i,1,a);if(o.then)return void o.then(c).then(void 0,s);ke(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):Oe(i,1,a)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if(o.tag===t)return r.send(xe,v),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return y(r,t)}}function qe(){return Ye(),y(xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ze,$e=function(e){return l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Xe="\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",Qe=function(){return{authenticate:Te,unauthenticate:Je,authorization:De,signUserMessage:Ne,verifyUserSignatures:Fe,subscribe:Ge,snapshot:qe}},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=((Ze={})[p]=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)}},Ze[h]=function(e,t){e.subscribe(t.from),e.send(t.from,E,e.all())},Ze[v]=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(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(E,t),e.merge(t)})}catch(e){return Promise.reject(e)}},Ze),at=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},it=function(e){return m(ot,at(e))};function st(e){function t(t){return g(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 C(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 ut,ct=function(t){void 0===t&&(t={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(e){try{return l(O(e),"mutate(opts) -- opts is required"),l(F(e),"mutate(opts) -- opts must be an object"),l(O(e.cadence),"mutate({ cadence }) -- cadence is required"),l(N(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}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(k(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(u(c(),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=((ut={}).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=V(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)}},ut[h]=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)}},ut[v]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ut),pt=function(e){return m(ft,e)};function ht(e){return{subscribe:function(t){return g(e,pt,t)}}}var vt={__proto__:null,sendMsgToFCL:function(e,t){void 0===t&&(t={}),window.location!==window.parent.location?window.parent.postMessage(_({},t,{type:e}),"*"):window.opener.postMessage(_({},t,{type:e}),"*")},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var r=function(r){"object"==typeof r.data&&r.data.type===e&&(delete r.data.body.interaction,t(r.data))};return window.addEventListener("message",r),function(){return window.removeEventListener("message",r)}}},mt=function(){return Qe().authenticate()},yt=function(){return Qe().unauthenticate()},Et=function(){return Qe().unauthenticate(),Qe().authenticate()},Pt=function(){return Qe().authenticate()},gt=function(){return Qe().authenticate()},Ct=Qe().authorization,wt=f;export{I as VERSION,vt as WalletUtils,mt as authenticate,Ct as authz,Qe as currentUser,ht as events,gt as logIn,ct as mutate,T as query,Et as reauthenticate,dt as serialize,Pt as signUp,wt as t,st as tx,yt as unauthenticate}; | ||
//# 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,u,s){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().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","frame");var h=function(e){return function(t){return typeof t===e}},m=function(e){return null!=e},v=h("object"),y=h("string"),g=h("function"),P=h("number");function b(e){return g(e)?e(l.arg,d):[]}var E=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(m(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return l.send([l.script(e.cadence),l.args(b(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 j(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 O={f_type:"Service",f_vsn:"1.0.0"},R={f_type:"Identity",f_vsn:"1.0.0"},A={f_type:"USER",f_vsn:"1.0.0"},C={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function k(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return w({old:e},O,{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({},O,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}function L(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({},O,{type:e.type||"local-view",method:e.method,endpoint:e.endpoint,data:e.data||{},params:e.params||{}})}}var T={"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({},O,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},R,{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({},O,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:w({},R,{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({},O,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:k,"open-id":function(e){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":L};function D(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function x(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function U(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 B(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(U(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({},C,{status:e.status,reason:null!=(t=e.reason)?t:null,data:e.compositeSignature||e.data||{},updates:N(e.authorizationUpdates),local:k((e.local||[])[0])})}}var F=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(B(t,{method:M(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)}},z={"HTTP/GET":"GET","HTTP/POST":"POST"},M=function(e){return n.invariant(z[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),z[e.method]},H="FCL_IFRAME";function q(e){n.invariant(!document.getElementById(H),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=H,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,function(){document.getElementById(H)&&document.getElementById(H).remove()}]}var J="FCL_POP",V=null,K=null;function G(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 Y(e){var t;null==V||null!=(t=V)&&t.closed?V=G(e,J,window,600,600):K!==e?(V=G(e,J,window,600,600)).focus():V.focus(),K=e;var n=setInterval(function(){V&&V.closed&&(clearInterval(n),V=null)},1e3);return[V,function(){V&&!V.closed&&(V.close(),V=null)}]}var W,Z={"VIEW/IFRAME":q,"VIEW/POP":Y},$=function(e,t,n){try{return t.data=e.data,Promise.resolve(B(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(Z[e.method](U(e),t))}catch(n){throw console.error("execLocal({service, opts = {}})",n,{service:e,opts:t}),n}}catch(e){return Promise.reject(e)}}(L(t.local))).then(function(e){var r=e[1],o=function(){try{r(),n=!1}catch(e){console.error("Frame Close Error",e)}};return F(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)}},X=function(){},Q=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ee=function(){},te=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]),ne=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(re[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)}},re={"HTTP/RPC":$,"HTTP/POST":$,"IFRAME/RPC":function(e,t,n){return new Promise(function(r,o){var i=u.uid(),a=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:X,close:X};var n=t.onClose||X,r=t.onMessage||X,o=t.onReady||X,i=t.onResponse||X;window.addEventListener("message",c);var a=q(U(e)),u=a[0],s=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(Q.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),s(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{u.contentWindow.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(u){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:n,config:{services:r,app:u}}),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("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=u.uid(),a=n.includeOlderJsonRpcCall;t.data=e.data,function(e,t){if(void 0===t&&(t={}),null==e)return{send:ee,close:ee};var n=t.onClose||ee,r=t.onMessage||ee,o=t.onReady||ee,i=t.onResponse||ee;window.addEventListener("message",c);var a=Y(U(e)),u=a[0],s=a[1];return{send:d,close:l};function c(e){try{if("object"!=typeof e.data)return;if(te.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:d,close:l}),r(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Popup Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),s(),n()}catch(e){console.error("Popup Close Error",e)}}function d(e){try{u.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(u){o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:n,config:{services:r,app:u}}),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")}})})}};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 ie(e,t,n){if(!e.s){if(n instanceof ce){if(!n.s)return void(n.o=ie.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(ie.bind(null,e,t),ie.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var ae=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(fe(function(){return 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})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(E({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)}},ue=function(e){try{return be(),Promise.resolve(de()).then(function(t){var r=x(t.services,"user-signature");return n.invariant(r,"Current user must have authorized a signing service."),fe(function(){return Promise.resolve(ne({service:r,msg:Ae(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)}},se=function(e){try{return be(),Promise.resolve(de()).then(function(t){var n=x(t.services,"authz"),r=x(t.services,"pre-authz");return w({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(ne({service:r,msg:t})).then(Se)}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(ne({service:n,msg:e,opts:{includeOlderJsonRpcCall:!0}})).then(oe)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},ce=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{ie(r,1,i(this.v))}catch(e){ie(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?ie(r,1,t?t(o):o):n?ie(r,1,n(o)):ie(r,2,o)}catch(e){ie(r,2,e)}},r},e}();function le(e){return e instanceof ce&&1&e.s}var de=function(){try{return Promise.resolve(new Promise(function(e,n){try{return be(),Promise.resolve(Oe()).then(function(n){return n.loggedIn&&Ee(n)?e(n):Promise.resolve(t.config.first(["discovery.wallet","challenge.handshake"])).then(function(n){return Promise.resolve(t.config.first(["discovery.wallet.method"],"frame")).then(function(t){var r="frame"===t?"IFRAME/RPC":"POP/RPC",a=function(e,t){try{var a=fe(function(){return Promise.resolve(ne({service:{endpoint:n,method:r}})).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=j(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 T[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),u=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,a);return w({},A,{addr:i.withPrefix(e.addr),cid:D(u),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){o.send(pe,me,e)})})},function(e){console.error("Error while authenticating",e)})}catch(e){return t(!0,e)}return a&&a.then?a.then(t.bind(null,!1),t.bind(null,!0)):t(!1,a)}(0,function(t,n){return Promise.resolve(Oe()).then(function(r){if(e(r),t)throw n;return n})});if(a&&a.then)return a.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 pe="CURRENT_USER",he="CURRENT_USER/UPDATED",me="SET_CURRENT_USER",ve='{\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=function(e){try{return sessionStorage.setItem(pe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ge=function(){return t.config().get("persistSession",!0)},Pe=((W={})[o.INIT]=function(e){try{return e.merge(JSON.parse(ve)),Promise.resolve(ge()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ve),t=JSON.parse(sessionStorage.getItem(pe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(pe),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Ee(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},W[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,he,w({},e.all()))},W[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},W.SNAPSHOT=function(e,t){try{return t.reply(w({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},W[me]=function(e,t,n){try{return e.merge(n),Promise.resolve(ge()).then(function(t){t&&ye(e.all()),e.broadcast(he,w({},e.all()))})}catch(e){return Promise.reject(e)}},W.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ve)),Promise.resolve(ge()).then(function(t){t&&ye(e.all()),e.broadcast(he,w({},e.all()))})}catch(e){return Promise.reject(e)}},W),be=function(){return o.spawn(Pe,pe)};function Ee(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function we(){be(),o.send(pe,"DEL_CURRENT_USER")}function Se(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=j(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,a=j(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 ne({service:n,msg:e})},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function je(e){be();var t="@EXIT",n=o.spawn(function(n){try{var r;return n.send(pe,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 ce,u=ie.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):ie(a,1,i)})).then(void 0,u),a;function s(t){i=t;do{if(!(o=e())||le(o)&&!o.v)return void ie(a,1,i);if(o.then)return void o.then(c).then(void 0,u);le(i=n())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(s).then(void 0,u):s(i):ie(a,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(i){if(i.tag===t)return n.send(pe,o.UNSUBSCRIBE),void(r=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(n,t)}}function Oe(){return be(),o.send(pe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Re,Ae=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message: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",Ie=function(){return{authenticate:de,unauthenticate:we,authorization:se,signUserMessage:ue,verifyUserSignatures:ae,subscribe:je,snapshot:Oe}},ke="POLL",Ne=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},Le=function(e){return e.status>=4},Te=function(e){return e.status>=3},De=function(e){return e.status>=2},xe=((Re={})[o.INIT]=function(e){try{return Promise.resolve(Ne(e.self())).then(function(t){Le(t)||setTimeout(function(){return e.sendSelf(ke)},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},Re[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,o.UPDATED,e.all())},Re[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},Re[o.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Re.POLL=function(e){try{return Promise.resolve(Ne(e.self())).then(function(t){var n,r;Le(t)||setTimeout(function(){return e.sendSelf(ke)},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)}},Re),Ue=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Be=function(e){return o.spawn(xe,Ue(e))};function _e(e){function t(t){return o.subscriber(Ue(e),Be,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,Be)},subscribe:t,onceFinalized:n(De),onceExecuted:n(Te),onceSealed:n(Le)}}_e.isUnknown=function(e){return e.status>=0},_e.isPending=function(e){return e.status>=1},_e.isFinalized=De,_e.isExecuted=Te,_e.isSealed=Le,_e.isExpired=function(e){return 5===e.status};var Fe,ze=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)}},Me=((Fe={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(t.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(ze(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=j(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(ze(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)}},Fe[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(ze(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)}},Fe[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Fe),He=function(e){return o.spawn(Me,e)},qe={__proto__:null,sendMsgToFCL: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}),"*")}},Je=Ie().authorization,Ve=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 s.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return s.template}}),e.VERSION="0.0.77-alpha.2",e.WalletUtils=qe,e.authenticate=function(){return Ie().authenticate()},e.authz=Je,e.currentUser=Ie,e.events=function(e){return{subscribe:function(t){return o.subscriber(e,He,t)}}},e.logIn=function(){return Ie().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(m(e),"mutate(opts) -- opts is required"),n.invariant(v(e),"mutate(opts) -- opts must be an object"),n.invariant(m(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(l.config().get("fcl.authz",Ie().authorization)).then(function(t){return l.send([l.transaction(e.cadence),l.args(b(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=E,e.reauthenticate=function(){return Ie().unauthenticate(),Ie().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 Ie().authenticate()},e.t=Ve,e.tx=_e,e.unauthenticate=function(){return Ie().unauthenticate()}}); | ||
!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().put("accessNode.api","http://localhost:8080").put("discovery.wallet","http://localhost:8701/fcl/authn").put("discovery.wallet.method","IFRAME/RPC");var h=function(e){return function(t){return typeof t===e}},m=function(e){return null!=e},v=h("object"),y=h("string"),g=h("function"),P=h("number");function b(e){return g(e)?e(l.arg,d):[]}var E=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(m(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return l.send([l.script(e.cadence),l.args(b(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 C(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 S(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 C(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)?C(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 R={f_type:"Service",f_vsn:"1.0.0"},O={f_type:"Identity",f_vsn:"1.0.0"},j={f_type:"USER",f_vsn:"1.0.0"},A={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},R,{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({},R,{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({},R,{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({},R,{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({},R,{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({},R,{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 T(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function F(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({},A,{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:M(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)}},z={"HTTP/GET":"GET","HTTP/POST":"POST"},M=function(e){return n.invariant(z[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),z[e.method]},H="FCL_IFRAME";function V(e){n.invariant(!document.getElementById(H),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=H,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(H)&&document.getElementById(H).remove()}]}var J="FCL_POP",W=null,q=null;function Y(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==W||null!=(t=W)&&t.closed?W=Y(e,J,window,640,600):q!==e?(W=Y(e,J,window,640,600)).focus():W.focus(),q=e;var n=setInterval(function(){W&&W.closed&&(clearInterval(n),W=null)},1e3);return[W,function(){W&&!W.closed&&(W.close(),W=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":V,"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"]),me="FCL:VIEW:CLOSE",ve="FCL:VIEW:READY",ye="FCL:VIEW:RESPONSE",ge=function(){},Pe=function(e){return"string"==typeof e&&e.toLowerCase()},be=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"]),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(Ce[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)}},Ce={"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=V(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}}),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("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}}),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(Ee.has(e.data.type))return;Pe(e.data.type)===Pe(me)&&l(),Pe(e.data.type)===Pe(ve)&&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")&&(be(e.data.type,ve),o(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL:FRAME:RESPONSE")&&(be(e.data.type,ye),i(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL:FRAME:CLOSE")&&(be(e.data.type,me),l()),Pe(e.data.type)===Pe("FCL::CHALLENGE::RESPONSE")&&(be(e.data.type,ye),i(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL::AUTHZ_READY")&&(be(e.data.type,ve),o(e,{send:d,close:l})),Pe(e.data.type)===Pe("FCL::CHALLENGE::CANCEL")&&(be(e.data.type,me),l()),Pe(e.data.type)===Pe("FCL::CANCEL")&&(be(e.data.type,me),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}}),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")}})})}};function Se(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 Re(e,t,n){if(!e.s){if(n instanceof Ie){if(!n.s)return void(n.o=Re.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Re.bind(null,e,t),Re.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Oe=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(ke(function(){return 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})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(E({cadence:""+Ke,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)}},je=function(e){try{return ze(),Promise.resolve(Ne()).then(function(t){var r=F(t.services,"user-signature");return n.invariant(r,"Current user must have authorized a signing service."),ke(function(){return Promise.resolve(we({service:r,msg:Ye(e)})).then(function(e){return Array.isArray(e)?e.map(function(e){return Se(e)}):[Se(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},Ae=function(e){try{return ze(),Promise.resolve(Ne()).then(function(t){var n=F(t.services,"authz"),r=F(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(Ve)}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(Se)}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{Re(r,1,i(this.v))}catch(e){Re(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Re(r,1,t?t(o):o):n?Re(r,1,n(o)):Re(r,2,o)}catch(e){Re(r,2,e)}},r},e}();function Le(e){return e instanceof Ie&&1&e.s}var Ne=function(){try{return Promise.resolve(new Promise(function(e,n){try{return ze(),Promise.resolve(We()).then(function(n){return n.loggedIn&&Me(n)?e(n):Promise.resolve(t.config.first(["discovery.wallet","challenge.handshake"])).then(function(n){return Promise.resolve(t.config.first(["discovery.wallet.method"],"IFRAME/RPC")).then(function(t){var r=function(e,r){try{var a=ke(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=S(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({},j,{addr:i.withPrefix(e.addr),cid:T(s),loggedIn:!0,services:a,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){o.send(De,Fe,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(We()).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 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",Te="CURRENT_USER/UPDATED",Fe="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=function(e){try{return sessionStorage.setItem(De,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},_e=function(){return t.config().get("persistSession",!0)},Be=((X={})[o.INIT]=function(e){try{return e.merge(JSON.parse(xe)),Promise.resolve(_e()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(xe),t=JSON.parse(sessionStorage.getItem(De));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(De),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){Me(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,Te,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[Fe]=function(e,t,n){try{return e.merge(n),Promise.resolve(_e()).then(function(t){t&&Ue(e.all()),e.broadcast(Te,w({},e.all()))})}catch(e){return Promise.reject(e)}},X.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(xe)),Promise.resolve(_e()).then(function(t){t&&Ue(e.all()),e.broadcast(Te,w({},e.all()))})}catch(e){return Promise.reject(e)}},X),ze=function(){return o.spawn(Be,De)};function Me(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function He(){ze(),o.send(De,"DEL_CURRENT_USER")}function Ve(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=S(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,a=S(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 Je(e){ze();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=Re.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):Re(a,1,i)})).then(void 0,s),a;function u(t){i=t;do{if(!(o=e())||Le(o)&&!o.v)return void Re(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):Re(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 We(){return ze(),o.send(De,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var qe,Ye=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Ke="\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",Ge=function(){return{authenticate:Ne,unauthenticate:He,authorization:Ae,signUserMessage:je,verifyUserSignatures:Oe,subscribe:Je,snapshot:We}},Ze="POLL",$e=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},Xe=function(e){return e.status>=4},Qe=function(e){return e.status>=3},et=function(e){return e.status>=2},tt=((qe={})[o.INIT]=function(e){try{return Promise.resolve($e(e.self())).then(function(t){Xe(t)||setTimeout(function(){return e.sendSelf(Ze)},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($e(e.self())).then(function(t){var n,r;Xe(t)||setTimeout(function(){return e.sendSelf(Ze)},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),nt=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},rt=function(e){return o.spawn(tt,nt(e))};function ot(e){function t(t){return o.subscriber(nt(e),rt,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,rt)},subscribe:t,onceFinalized:n(et),onceExecuted:n(Qe),onceSealed:n(Xe)}}ot.isUnknown=function(e){return e.status>=0},ot.isPending=function(e){return e.status>=1},ot.isFinalized=et,ot.isExecuted=Qe,ot.isSealed=Xe,ot.isExpired=function(e){return 5===e.status};var it,at=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)}},st=((it={}).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(at(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=S(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(at(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)}},it[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(at(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)}},it[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},it),ut=function(e){return o.spawn(st,e)},ct={__proto__:null,sendMsgToFCL: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}),"*")},onMessageFromFCL:function(e,t){void 0===t&&(t=function(){});var n=function(n){"object"==typeof n.data&&n.data.type===e&&(delete n.data.body.interaction,t(n.data))};return window.addEventListener("message",n),function(){return window.removeEventListener("message",n)}}},lt=Ge().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-alpha.3",e.WalletUtils=ct,e.authenticate=function(){return Ge().authenticate()},e.authz=lt,e.currentUser=Ge,e.events=function(e){return{subscribe:function(t){return o.subscriber(e,ut,t)}}},e.logIn=function(){return Ge().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(m(e),"mutate(opts) -- opts is required"),n.invariant(v(e),"mutate(opts) -- opts must be an object"),n.invariant(m(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(y(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(l.config().get("fcl.authz",Ge().authorization)).then(function(t){return l.send([l.transaction(e.cadence),l.args(b(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=E,e.reauthenticate=function(){return Ge().unauthenticate(),Ge().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 Ge().authenticate()},e.t=dt,e.tx=ot,e.unauthenticate=function(){return Ge().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.77-alpha.2", | ||
"version": "0.0.77-alpha.3", | ||
"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
542084
511