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