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