@onflow/fcl
Advanced tools
Comparing version 0.0.49 to 0.0.50
@@ -5,2 +5,6 @@ ### Unreleased | ||
### 0.0.50 -- 2020-08-14 | ||
- 2020-08-14 -- Fixeds some small bugs due to typos | ||
### 0.0.49 -- 2020-08-13 | ||
@@ -7,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/config"),n=require("@onflow/sdk"),t=require("@onflow/util-actor"),r=require("@onflow/types");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var o,i=function(t){try{return Promise.resolve(e.config().get("accessNode.api")).then(function(e){return n.resolve(t,[n.resolveRefBlockId({node:e}),n.resolveParams,n.resolveArguments,n.resolveAccounts,n.resolveSignatures,n.resolveValidators])})}catch(e){return Promise.reject(e)}},u=function(t,r){void 0===t&&(t=[]),void 0===r&&(r={});try{var o=function(e){return r.node=e,Array.isArray(t)&&(t=n.build(t)),Promise.resolve(i(t)).then(function(e){return n.send(e,r)})},u=r.node;return Promise.resolve(u?o(u):Promise.resolve(e.config().get("accessNode.api")).then(o))}catch(e){return Promise.reject(e)}},c=function(t){try{return Promise.resolve(e.config().where(/^decoder\./)).then(function(e){var r=Object.fromEntries(Object.entries(e).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return n.decodeResponse(t,r)})}catch(e){return Promise.reject(e)}};function s(e,n,t){if(!e.s){if(t instanceof a){if(!t.s)return void(t.o=s.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(s.bind(null,e,n),s.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var a=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{s(r,1,i(this.v))}catch(e){s(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?s(r,1,n?n(o):o):t?s(r,1,t(o)):s(r,2,o)}catch(e){s(r,2,e)}},r},e}();function f(e){return e instanceof a&&1&e.s}var l,d=function(e){try{return Promise.resolve(u([n.getTransactionStatus(e)])).then(c)}catch(e){return Promise.reject(e)}},h=function(e){return 4===e.status},m=function(e){return 3===e.status||h(e)},v=function(e){return 2===e.status||m(e)},p=function(e){return 1===e.status||v(e)},y=((o={})[t.INIT]=function(e){try{return Promise.resolve(d(e.self())).then(function(n){h(n)||setTimeout(function(){return t.send(e.self(),"POLL")},1e3),e.merge(n)})}catch(e){return Promise.reject(e)}},o[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,"TRANSACTION/UPDATED",e.all())},o[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},o.SNAPSHOT=function(e,n){try{return n.replay(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},o.POLL=function(e){try{return Promise.resolve(d(e.self())).then(function(n){h(n)||setTimeout(function(){return t.send(e.self(),"POLL")},1e3),e.merge(n),e.broadcast("TRANSACTION/UPDATED",e.all())})}catch(e){return Promise.reject(e)}},o),P=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return t.spawn(y,e)};function b(e){function n(n){var r=P(e),o=t.spawn(function(e){try{var o;return e.send(r,t.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(f(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!f(i)){r=1;break}i=i.s}}var u=new a,c=s.bind(null,u,2);return(0===r?o.then(d):1===r?i.then(l):(void 0).then(function(){(o=e())?o.then?o.then(d).then(void 0,c):d(o):s(u,1,i)})).then(void 0,c),u;function l(n){i=n;do{if(!(o=e())||f(o)&&!o.v)return void s(u,1,i);if(o.then)return void o.then(d).then(void 0,c);f(i=t())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,c)}function d(e){e?(i=t())&&i.then?i.then(l).then(void 0,c):l(i):s(u,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(e.receive()).then(function(i){if("@EXIT"===i.tag)return e.send(r,t.UNSUBSCRIBE),void(o=1);n(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(o,"@EXIT")}}function r(e){return function(){return new Promise(function(t){var r=n(function(n){e(n)&&(t(n),r())})})}}return{snapshot:function(){var n=P(e);return t.send(n,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:n,oncePending:r(p),onceFinalized:r(v),onceExecuted:r(m),onceSealed:r(h)}}function g(){return(g=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function j(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}b.isUnknown=function(e){return 0===e.status||p(e)},b.isPending=p,b.isFinalized=v,b.isExecuted=m,b.isSealed=h;var S,E=function(){try{return Promise.resolve(u([n.getLatestBlock()])).then(c)}catch(e){return Promise.reject(e)}},x=function(n){try{var t=setTimeout;return Promise.resolve(e.config.get("fcl.eventPollRate",1e4)).then(function(e){return t(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},w=((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(E()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(x(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(E()).then(function(r){return e.put("hwm",r),Promise.resolve(u([n.getEvents(e.self(),t.height,r.height-1)])).then(function(n){return Promise.resolve(c(n)).then(function(n){for(var t,r=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return j(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?j(e,void 0):void 0}}(e)))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(n=e[Symbol.iterator]()).next.bind(n)}(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(x(e)).then(function(n){o.call(e,"tick",n)})})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l[t.SUBSCRIBE]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(x(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},l[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},l),O=function(e){return t.spawn(w,e)},T="FCL_IFRAME_CHALLENGE",I="FCL_IFRAME_AUTHZ",R=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},A={"HTTP/POST":"POST","HTTP/GET":"GET"},U=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:A[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function k(e,n,t){if(!e.s){if(t instanceof C){if(!t.s)return void(t.o=k.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(k.bind(null,e,n),k.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var N=function(){try{return J(),Promise.resolve($()).then(function(e){var t=e.addr;if(null==t)throw new Error("No Flow Address for Current User");return Promise.resolve(u([n.getAccount(t)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},B=function(e){try{return J(),Promise.resolve(_()).then(function(){return Promise.resolve($()).then(function(n){function t(){return g({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve($()).then(function(n){return Promise.resolve(N()).then(function(t){return Promise.resolve(U(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById(I)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=I,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(I)&&document.getElementById(I).remove()}}}(e.local[0]));var t=null;return function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(U(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return n(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(N()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},C=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;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,n?n(o):o):t?k(r,1,t(o)):k(r,2,o)}catch(e){k(r,2,e)}},r},e}();function L(e){return e instanceof C&&1&e.s}var _=function(){try{return Promise.resolve(new Promise(function(n){try{return J(),Promise.resolve($()).then(function(r){return r.loggedIn?n(r):Promise.resolve(e.config().get("challenge.handshake")).then(function(r){return Promise.resolve(e.config().get("challenge.scope")).then(function(e){var o=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(T)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=T,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(T)&&document.getElementById(T).remove()}}}({handshake:r,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var r=e.data;try{if(r.type!==H)return Promise.resolve();o();var i=new URL(r.hks);return i.searchParams.append("code",r.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return t.send(D,F,g({},e,{cid:R(e.provider),loggedIn:!0,verified:!0})),Promise.resolve($()).then(function(e){n(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},D="CURRENT_USER",z="CURRENT_USER/UPDATED",F="SET_CURRENT_USER",H="FCL::CHALLENGE::RESPONSE",G='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',q=new Set(["verified","identity","scoped","provider"]),X=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return q.has(n)&&function(e){console.warn(('\n %cFCL Deprecation Notice\n ========================\n\n Access to field "'+e+'" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n ').replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")}(n),e[n]}})),e},M=((S={})[t.INIT]=function(e){e.merge(JSON.parse(G))},S[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,z,X(e.all()))},S[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},S.SNAPSHOT=function(e,n){try{return n.reply(X(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},S[F]=function(e,n,t){try{return e.merge(t),e.broadcast(z,X(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},S.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(G)),e.broadcast(z,X(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},S.GET_AS_PARAM=function(e,n,t){var o=t.key;try{return n.reply({key:o,value:e.get("addr",null),xform:r.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},S),J=function(){return t.spawn(M,D)};function W(){J(),t.send(D,"DEL_CURRENT_USER")}function K(e){return function(){try{return J(),Promise.resolve(_()).then(function(){return t.send(D,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function V(e){J();var n=t.spawn(function(n){try{var r;return n.send(D,t.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(L(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!L(i)){r=1;break}i=i.s}}var u=new C,c=k.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):k(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||L(o)&&!o.v)return void k(u,1,i);if(o.then)return void o.then(a).then(void 0,c);L(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):k(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(D,t.UNSUBSCRIBE),void(r=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(n,"@EXIT")}}function $(){return J(),t.send(D,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Z=function(){return{authenticate:_,unauthenticate:W,authorization:B,param:K,subscribe:V,snapshot:$}};Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return n.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return n.args}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return n.build}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return n.cadence}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return n.cdc}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),exports.authenticate=function(){return Z().authenticate()},exports.currentUser=Z,exports.decode=c,exports.events=function(e){return{subscribe:function(n){return t.subscriber(e,O,n)}}},exports.resolve=i,exports.send=u,exports.serialize=function(e){void 0===e&&(e=[]);try{var t=function(){return Promise.resolve(i(e)).then(JSON.stringify)},r=function(){if(Array.isArray(e))return Promise.resolve(n.build(e)).then(function(n){e=n})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},exports.tx=b,exports.unauthenticate=function(){return Z().unauthenticate()}; | ||
var e=require("@onflow/config"),n=require("@onflow/sdk"),t=require("@onflow/util-actor"),r=require("@onflow/types");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var o,i=function(t){try{return Promise.resolve(e.config().get("accessNode.api")).then(function(e){return n.resolve(t,[n.resolveRefBlockId({node:e}),n.resolveParams,n.resolveArguments,n.resolveAccounts,n.resolveSignatures,n.resolveValidators])})}catch(e){return Promise.reject(e)}},u=function(t,r){void 0===t&&(t=[]),void 0===r&&(r={});try{var o=function(e){return r.node=e,Array.isArray(t)&&(t=n.build(t)),Promise.resolve(i(t)).then(function(e){return n.send(e,r)})},u=r.node;return Promise.resolve(u?o(u):Promise.resolve(e.config().get("accessNode.api")).then(o))}catch(e){return Promise.reject(e)}},c=function(t){try{return Promise.resolve(e.config().where(/^decoder\./)).then(function(e){var r=Object.fromEntries(Object.entries(e).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return n.decodeResponse(t,r)})}catch(e){return Promise.reject(e)}};function s(e,n,t){if(!e.s){if(t instanceof a){if(!t.s)return void(t.o=s.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(s.bind(null,e,n),s.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var a=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{s(r,1,i(this.v))}catch(e){s(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?s(r,1,n?n(o):o):t?s(r,1,t(o)):s(r,2,o)}catch(e){s(r,2,e)}},r},e}();function f(e){return e instanceof a&&1&e.s}var l,d=function(e){try{return Promise.resolve(u([n.getTransactionStatus(e)])).then(c)}catch(e){return Promise.reject(e)}},h=function(e){return 4===e.status},m=function(e){return 3===e.status||h(e)},v=function(e){return 2===e.status||m(e)},p=function(e){return 1===e.status||v(e)},y=((o={})[t.INIT]=function(e){try{return Promise.resolve(d(e.self())).then(function(n){h(n)||setTimeout(function(){return t.send(e.self(),"POLL")},1e3),e.merge(n)})}catch(e){return Promise.reject(e)}},o[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,"TRANSACTION/UPDATED",e.all())},o[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},o.SNAPSHOT=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},o.POLL=function(e){try{return Promise.resolve(d(e.self())).then(function(n){h(n)||setTimeout(function(){return t.send(e.self(),"POLL")},1e3),e.merge(n),e.broadcast("TRANSACTION/UPDATED",e.all())})}catch(e){return Promise.reject(e)}},o),P=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return t.spawn(y,e)};function b(e){function n(n){var r=P(e),o=t.spawn(function(e){try{var o;return e.send(r,t.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(f(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!f(i)){r=1;break}i=i.s}}var u=new a,c=s.bind(null,u,2);return(0===r?o.then(d):1===r?i.then(l):(void 0).then(function(){(o=e())?o.then?o.then(d).then(void 0,c):d(o):s(u,1,i)})).then(void 0,c),u;function l(n){i=n;do{if(!(o=e())||f(o)&&!o.v)return void s(u,1,i);if(o.then)return void o.then(d).then(void 0,c);f(i=t())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,c)}function d(e){e?(i=t())&&i.then?i.then(l).then(void 0,c):l(i):s(u,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(e.receive()).then(function(i){if("@EXIT"===i.tag)return e.send(r,t.UNSUBSCRIBE),void(o=1);n(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(o,"@EXIT")}}function r(e){return function(){return new Promise(function(t){var r=n(function(n){e(n)&&(t(n),r())})})}}return{snapshot:function(){var n=P(e);return t.send(n,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:n,oncePending:r(p),onceFinalized:r(v),onceExecuted:r(m),onceSealed:r(h)}}function g(){return(g=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function j(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}b.isUnknown=function(e){return 0===e.status||p(e)},b.isPending=p,b.isFinalized=v,b.isExecuted=m,b.isSealed=h;var S,E=function(){try{return Promise.resolve(u([n.getLatestBlock()])).then(c)}catch(e){return Promise.reject(e)}},x=function(n){try{var t=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return t(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},w=((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(E()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(x(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(E()).then(function(r){return e.put("hwm",r),Promise.resolve(u([n.getEvents(e.self(),t.height,r.height-1)])).then(function(n){return Promise.resolve(c(n)).then(function(n){for(var t,r=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return j(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?j(e,void 0):void 0}}(e)))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(n=e[Symbol.iterator]()).next.bind(n)}(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(x(e)).then(function(n){o.call(e,"tick",n)})})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l[t.SUBSCRIBE]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(x(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},l[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},l),O=function(e){return t.spawn(w,e)},T="FCL_IFRAME_CHALLENGE",I="FCL_IFRAME_AUTHZ",R=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},A={"HTTP/POST":"POST","HTTP/GET":"GET"},U=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:A[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function k(e,n,t){if(!e.s){if(t instanceof C){if(!t.s)return void(t.o=k.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(k.bind(null,e,n),k.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var N=function(){try{return J(),Promise.resolve($()).then(function(e){var t=e.addr;if(null==t)throw new Error("No Flow Address for Current User");return Promise.resolve(u([n.getAccount(t)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},B=function(e){try{return J(),Promise.resolve(_()).then(function(){return Promise.resolve($()).then(function(n){function t(){return g({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve($()).then(function(n){return Promise.resolve(N()).then(function(t){return Promise.resolve(U(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById(I)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=I,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(I)&&document.getElementById(I).remove()}}}(e.local[0]));var t=null;return function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(U(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return n(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(N()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},C=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;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,n?n(o):o):t?k(r,1,t(o)):k(r,2,o)}catch(e){k(r,2,e)}},r},e}();function L(e){return e instanceof C&&1&e.s}var _=function(){try{return Promise.resolve(new Promise(function(n){try{return J(),Promise.resolve($()).then(function(r){return r.loggedIn?n(r):Promise.resolve(e.config().get("challenge.handshake")).then(function(r){return Promise.resolve(e.config().get("challenge.scope")).then(function(e){var o=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(T)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=T,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(T)&&document.getElementById(T).remove()}}}({handshake:r,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var r=e.data;try{if(r.type!==H)return Promise.resolve();o();var i=new URL(r.hks);return i.searchParams.append("code",r.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return t.send(D,F,g({},e,{cid:R(e.provider),loggedIn:!0,verified:!0})),Promise.resolve($()).then(function(e){n(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},D="CURRENT_USER",z="CURRENT_USER/UPDATED",F="SET_CURRENT_USER",H="FCL::CHALLENGE::RESPONSE",G='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',q=new Set(["verified","identity","scoped","provider"]),X=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return q.has(n)&&function(e){console.warn(('\n %cFCL Deprecation Notice\n ========================\n\n Access to field "'+e+'" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n ').replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")}(n),e[n]}})),e},M=((S={})[t.INIT]=function(e){e.merge(JSON.parse(G))},S[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,z,X(e.all()))},S[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},S.SNAPSHOT=function(e,n){try{return n.reply(X(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},S[F]=function(e,n,t){try{return e.merge(t),e.broadcast(z,X(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},S.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(G)),e.broadcast(z,X(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},S.GET_AS_PARAM=function(e,n,t){var o=t.key;try{return n.reply({key:o,value:e.get("addr",null),xform:r.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},S),J=function(){return t.spawn(M,D)};function W(){J(),t.send(D,"DEL_CURRENT_USER")}function K(e){return function(){try{return J(),Promise.resolve(_()).then(function(){return t.send(D,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function V(e){J();var n=t.spawn(function(n){try{var r;return n.send(D,t.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(L(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!L(i)){r=1;break}i=i.s}}var u=new C,c=k.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):k(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||L(o)&&!o.v)return void k(u,1,i);if(o.then)return void o.then(a).then(void 0,c);L(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):k(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(D,t.UNSUBSCRIBE),void(r=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(n,"@EXIT")}}function $(){return J(),t.send(D,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Z=function(){return{authenticate:_,unauthenticate:W,authorization:B,param:K,subscribe:V,snapshot:$}};Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return n.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return n.args}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return n.build}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return n.cadence}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return n.cdc}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),exports.authenticate=function(){return Z().authenticate()},exports.currentUser=Z,exports.decode=c,exports.events=function(e){return{subscribe:function(n){return t.subscriber(e,O,n)}}},exports.resolve=i,exports.send=u,exports.serialize=function(e){void 0===e&&(e=[]);try{var t=function(){return Promise.resolve(i(e)).then(JSON.stringify)},r=function(){if(Array.isArray(e))return Promise.resolve(n.build(e)).then(function(n){e=n})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},exports.tx=b,exports.unauthenticate=function(){return Z().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,resolveRefBlockId as n,resolveParams as a,resolveArguments as s,resolveAccounts as o,resolveSignatures as r,resolveValidators as i,build as c,send as l,decodeResponse as u,getTransactionStatus as d,getLatestBlock as p,getEvents as f,getAccount as m}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,pipe,proposer,ref,script,transaction,why}from"@onflow/sdk";import{send as y,spawn as h,SUBSCRIBE as w,UNSUBSCRIBE as g,INIT as E,subscriber as b}from"@onflow/util-actor";import{Identity as T}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const S=async c=>t(c,[n({node:await e().get("accessNode.api")}),a,s,o,r,i]),R=async(t=[],n={})=>(n.node=n.node||await e().get("accessNode.api"),Array.isArray(t)&&(t=c(t)),l(await S(t),n)),P=async(e=[])=>(Array.isArray(e)&&(e=await c(e)),JSON.stringify(await S(e))),k=async t=>{const n=await e().where(/^decoder\./),a=Object.fromEntries(Object.entries(n).map(([e,t])=>[e=`/${e.replace(/^decoder\./,"")}$/`,t]));return u(t,a)},A=async e=>{const t=await R([d(e)]);return k(t)},v=e=>4===e.status,x=e=>3===e.status||v(e),N=e=>2===e.status||x(e),I=e=>1===e.status||N(e),U={[E]:async e=>{const t=await A(e.self());v(t)||setTimeout(()=>y(e.self(),"POLL"),1e3),e.merge(t)},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,"TRANSACTION/UPDATED",e.all())},[g]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.replay(e.all())},POLL:async e=>{const t=await A(e.self());v(t)||setTimeout(()=>y(e.self(),"POLL"),1e3),e.merge(t),e.broadcast("TRANSACTION/UPDATED",e.all())}},L=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return h(U,e)};function C(e){function t(t){const n=L(e),a=h(async e=>{for(e.send(n,w);;){const a=await e.receive();if("@EXIT"===a.tag)return void e.send(n,g);t(a.data)}});return()=>y(a,"@EXIT")}function n(e){return function(){return new Promise(n=>{const a=t(t=>{e(t)&&(n(t),a())})})}}return{snapshot:function(){const t=L(e);return y(t,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:t,oncePending:n(I),onceFinalized:n(N),onceExecuted:n(x),onceSealed:n(v)}}C.isUnknown=e=>0===e.status||I(e),C.isPending=I,C.isFinalized=N,C.isExecuted=x,C.isSealed=v;const O=async()=>k(await R([p()])),_=async t=>setTimeout(()=>t.sendSelf("TICK"),await e.get("fcl.eventPollRate",1e4)),D={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await O()),e.put("tick",await _(e));else{let n=await O();e.put("hwm",n);const a=await R([f(e.self(),t.height,n.height-1)]),s=await k(a);for(let t of s)e.broadcast("UPDATED",t.data);e.put("tick",await _(e))}},[w]:async(e,t)=>{e.hasSubs()||e.put("tick",await _(e)),e.subscribe(t.from)},[g]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},F=e=>h(D,e);function j(e){return{subscribe:t=>b(e,F,t)}}const H="FCL_IFRAME_CHALLENGE",B="FCL_IFRAME_AUTHZ",z=(e={})=>{const t=e.addr,n=e.pid;return null==t||null==n?null:`${t}/${n}`},G={"HTTP/POST":"POST","HTTP/GET":"GET"},X=async(e,t)=>{const n=new URL(e.endpoint);for(let[t,a]of Object.entries(e.params||{}))n.searchParams.append(t,a);return t=t?JSON.stringify(t):void 0,fetch(n,{method:G[e.method],headers:{"Content-Type":"application/json"},body:t}).then(e=>e.json())},$=e=>new Promise(async(t,n)=>{const a=await X(e);"APPROVED"===a.status?t(a.compositeSignature):"DECLINED"===a.status?n({status:a.status,reason:a.reason}):setTimeout(()=>{t($(a.authorizationUpdates))},500)}),J="CURRENT_USER",M="CURRENT_USER/UPDATED",q='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',W=new Set(["verified","identity","scoped","provider"]),K=e=>("undefined"!=typeof Proxy&&(e=new Proxy(e,{get:(e,t)=>(W.has(t)&&(e=>{console.warn(`\n %cFCL Deprecation Notice\n ========================\n\n Access to field "${e}" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n `.replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")})(t),e[t])})),e),V={[E]:e=>{e.merge(JSON.parse(q))},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,M,K(e.all()))},[g]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(K(e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),e.broadcast(M,K(e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(q)),e.broadcast(M,K(e.all()))},GET_AS_PARAM:async(e,t,{key:n})=>{t.reply({key:n,value:e.get("addr",null),xform:T})}},Z=()=>h(V,J);async function Q(){return new Promise(async t=>{Z();const n=await ae();if(n.loggedIn)return t(n);const a=function({handshake:e,scope:t,nonce:n,l6n:a}){if(document.getElementById(H))return;var s=new URL(e);s.searchParams.append("l6n",a),s.searchParams.append("nonce",n),t&&s.searchParams.append("scope",t.split(" ").join("+"));const o=document.createElement("iframe");return o.src=s.href,o.id=H,o.style.height="500px",o.style.maxHeight="90vh",o.style.width="400px",o.style.maxWidth="90vw",o.style.display="block",o.style.background="#fff",o.style.position="fixed",o.style.top="5vh",o.style.right="calc(50vw)",o.style.transform="translateX(50%)",o.style.boxShadow="0 4px 8px -4px black",o.frameBorder="0",document.body.append(o),()=>{document.getElementById(H)&&document.getElementById(H).remove()}}({handshake:await e().get("challenge.handshake"),scope:await e().get("challenge.scope"),nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",async({data:e})=>{if("FCL::CHALLENGE::RESPONSE"!==e.type)return;a();const n=new URL(e.hks);n.searchParams.append("code",e.code);const s=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());y(J,"SET_CURRENT_USER",{...s,cid:z(s.provider),loggedIn:!0,verified:!0}),t(await ae())})})}function Y(){Z(),y(J,"DEL_CURRENT_USER")}async function ee(e){Z(),await Q();const t=await ae();let n;return e.role.proposer&&(n=(await se()).keys.find(e=>e.index===t.keyId).sequenceNumber),{...e,addr:t.addr,keyId:t.keyId,sequenceNum:n,signature:e.signature||null,signingFunction:async e=>{const t=await ae(),n=(await se(),await X(t.authorizations[0],e));let a=()=>{};n.local&&n.local.length>0&&(a=function(e){if(document.getElementById(B))return;var t=new URL(e.endpoint);for(let[n,a]of Object.entries(e.params||{}))t.searchParams.append(n,a);const n=document.createElement("iframe");return n.src=t.href,n.id=B,n.style.height=e.height||"500px",n.style.maxHeight="90vh",n.style.width=e.width||"400px",n.style.maxWidth="90vw",n.style.display="block",n.style.background=e.background||"#fff",n.style.position="fixed",n.style.top="5vh",n.style.right="calc(50vw)",n.style.transform="translateX(50%)",n.style.boxShadow="0 4px 8px -4px black",n.frameBorder="0",document.body.append(n),()=>{document.getElementById(B)&&document.getElementById(B).remove()}}(n.local[0]));let s=null;try{s=await $(n.authorizationUpdates)}catch(e){throw console.error(e),e}finally{return a(),s}},resolve:null,roles:e.roles}}function te(e){return async function(){return Z(),await Q(),y(J,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})}}function ne(e){Z();const t=h(async t=>{for(t.send(J,w);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(J,g);e(n.data)}});return()=>y(t,"@EXIT")}function ae(){return Z(),y(J,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function se(){Z();const{addr:e}=await ae();if(null==e)throw new Error("No Flow Address for Current User");const{account:t}=await R([m(e)]);return t}const oe=()=>({authenticate:Q,unauthenticate:Y,authorization:ee,param:te,subscribe:ne,snapshot:ae}),re=()=>oe().authenticate(),ie=()=>oe().unauthenticate();export{re as authenticate,oe as currentUser,k as decode,j as events,S as resolve,R as send,P as serialize,C as tx,ie as unauthenticate}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,resolveRefBlockId as n,resolveParams as a,resolveArguments as s,resolveAccounts as o,resolveSignatures as r,resolveValidators as i,build as c,send as l,decodeResponse as u,getTransactionStatus as d,getLatestBlock as p,getEvents as f,getAccount as m}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,pipe,proposer,ref,script,transaction,why}from"@onflow/sdk";import{send as y,spawn as h,SUBSCRIBE as w,UNSUBSCRIBE as g,INIT as E,subscriber as b}from"@onflow/util-actor";import{Identity as T}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const S=async c=>t(c,[n({node:await e().get("accessNode.api")}),a,s,o,r,i]),R=async(t=[],n={})=>(n.node=n.node||await e().get("accessNode.api"),Array.isArray(t)&&(t=c(t)),l(await S(t),n)),P=async(e=[])=>(Array.isArray(e)&&(e=await c(e)),JSON.stringify(await S(e))),k=async t=>{const n=await e().where(/^decoder\./),a=Object.fromEntries(Object.entries(n).map(([e,t])=>[e=`/${e.replace(/^decoder\./,"")}$/`,t]));return u(t,a)},A=async e=>{const t=await R([d(e)]);return k(t)},v=e=>4===e.status,x=e=>3===e.status||v(e),N=e=>2===e.status||x(e),I=e=>1===e.status||N(e),U={[E]:async e=>{const t=await A(e.self());v(t)||setTimeout(()=>y(e.self(),"POLL"),1e3),e.merge(t)},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,"TRANSACTION/UPDATED",e.all())},[g]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await A(e.self());v(t)||setTimeout(()=>y(e.self(),"POLL"),1e3),e.merge(t),e.broadcast("TRANSACTION/UPDATED",e.all())}},L=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return h(U,e)};function C(e){function t(t){const n=L(e),a=h(async e=>{for(e.send(n,w);;){const a=await e.receive();if("@EXIT"===a.tag)return void e.send(n,g);t(a.data)}});return()=>y(a,"@EXIT")}function n(e){return function(){return new Promise(n=>{const a=t(t=>{e(t)&&(n(t),a())})})}}return{snapshot:function(){const t=L(e);return y(t,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:t,oncePending:n(I),onceFinalized:n(N),onceExecuted:n(x),onceSealed:n(v)}}C.isUnknown=e=>0===e.status||I(e),C.isPending=I,C.isFinalized=N,C.isExecuted=x,C.isSealed=v;const O=async()=>k(await R([p()])),_=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),D={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await O()),e.put("tick",await _(e));else{let n=await O();e.put("hwm",n);const a=await R([f(e.self(),t.height,n.height-1)]),s=await k(a);for(let t of s)e.broadcast("UPDATED",t.data);e.put("tick",await _(e))}},[w]:async(e,t)=>{e.hasSubs()||e.put("tick",await _(e)),e.subscribe(t.from)},[g]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},F=e=>h(D,e);function j(e){return{subscribe:t=>b(e,F,t)}}const H="FCL_IFRAME_CHALLENGE",B="FCL_IFRAME_AUTHZ",z=(e={})=>{const t=e.addr,n=e.pid;return null==t||null==n?null:`${t}/${n}`},G={"HTTP/POST":"POST","HTTP/GET":"GET"},X=async(e,t)=>{const n=new URL(e.endpoint);for(let[t,a]of Object.entries(e.params||{}))n.searchParams.append(t,a);return t=t?JSON.stringify(t):void 0,fetch(n,{method:G[e.method],headers:{"Content-Type":"application/json"},body:t}).then(e=>e.json())},$=e=>new Promise(async(t,n)=>{const a=await X(e);"APPROVED"===a.status?t(a.compositeSignature):"DECLINED"===a.status?n({status:a.status,reason:a.reason}):setTimeout(()=>{t($(a.authorizationUpdates))},500)}),J="CURRENT_USER",M="CURRENT_USER/UPDATED",q='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',W=new Set(["verified","identity","scoped","provider"]),K=e=>("undefined"!=typeof Proxy&&(e=new Proxy(e,{get:(e,t)=>(W.has(t)&&(e=>{console.warn(`\n %cFCL Deprecation Notice\n ========================\n\n Access to field "${e}" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n `.replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")})(t),e[t])})),e),V={[E]:e=>{e.merge(JSON.parse(q))},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,M,K(e.all()))},[g]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(K(e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),e.broadcast(M,K(e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(q)),e.broadcast(M,K(e.all()))},GET_AS_PARAM:async(e,t,{key:n})=>{t.reply({key:n,value:e.get("addr",null),xform:T})}},Z=()=>h(V,J);async function Q(){return new Promise(async t=>{Z();const n=await ae();if(n.loggedIn)return t(n);const a=function({handshake:e,scope:t,nonce:n,l6n:a}){if(document.getElementById(H))return;var s=new URL(e);s.searchParams.append("l6n",a),s.searchParams.append("nonce",n),t&&s.searchParams.append("scope",t.split(" ").join("+"));const o=document.createElement("iframe");return o.src=s.href,o.id=H,o.style.height="500px",o.style.maxHeight="90vh",o.style.width="400px",o.style.maxWidth="90vw",o.style.display="block",o.style.background="#fff",o.style.position="fixed",o.style.top="5vh",o.style.right="calc(50vw)",o.style.transform="translateX(50%)",o.style.boxShadow="0 4px 8px -4px black",o.frameBorder="0",document.body.append(o),()=>{document.getElementById(H)&&document.getElementById(H).remove()}}({handshake:await e().get("challenge.handshake"),scope:await e().get("challenge.scope"),nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",async({data:e})=>{if("FCL::CHALLENGE::RESPONSE"!==e.type)return;a();const n=new URL(e.hks);n.searchParams.append("code",e.code);const s=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());y(J,"SET_CURRENT_USER",{...s,cid:z(s.provider),loggedIn:!0,verified:!0}),t(await ae())})})}function Y(){Z(),y(J,"DEL_CURRENT_USER")}async function ee(e){Z(),await Q();const t=await ae();let n;return e.role.proposer&&(n=(await se()).keys.find(e=>e.index===t.keyId).sequenceNumber),{...e,addr:t.addr,keyId:t.keyId,sequenceNum:n,signature:e.signature||null,signingFunction:async e=>{const t=await ae(),n=(await se(),await X(t.authorizations[0],e));let a=()=>{};n.local&&n.local.length>0&&(a=function(e){if(document.getElementById(B))return;var t=new URL(e.endpoint);for(let[n,a]of Object.entries(e.params||{}))t.searchParams.append(n,a);const n=document.createElement("iframe");return n.src=t.href,n.id=B,n.style.height=e.height||"500px",n.style.maxHeight="90vh",n.style.width=e.width||"400px",n.style.maxWidth="90vw",n.style.display="block",n.style.background=e.background||"#fff",n.style.position="fixed",n.style.top="5vh",n.style.right="calc(50vw)",n.style.transform="translateX(50%)",n.style.boxShadow="0 4px 8px -4px black",n.frameBorder="0",document.body.append(n),()=>{document.getElementById(B)&&document.getElementById(B).remove()}}(n.local[0]));let s=null;try{s=await $(n.authorizationUpdates)}catch(e){throw console.error(e),e}finally{return a(),s}},resolve:null,roles:e.roles}}function te(e){return async function(){return Z(),await Q(),y(J,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})}}function ne(e){Z();const t=h(async t=>{for(t.send(J,w);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(J,g);e(n.data)}});return()=>y(t,"@EXIT")}function ae(){return Z(),y(J,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function se(){Z();const{addr:e}=await ae();if(null==e)throw new Error("No Flow Address for Current User");const{account:t}=await R([m(e)]);return t}const oe=()=>({authenticate:Q,unauthenticate:Y,authorization:ee,param:te,subscribe:ne,snapshot:ae}),re=()=>oe().authenticate(),ie=()=>oe().unauthenticate();export{re as authenticate,oe as currentUser,k as decode,j as events,S as resolve,R as send,P as serialize,C as tx,ie 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 n,resolveRefBlockId as t,resolveParams as r,resolveArguments as o,resolveAccounts as i,resolveSignatures as u,resolveValidators as c,build as s,send as a,decodeResponse as l,getTransactionStatus as f,getEvents as h,getLatestBlock as d,getAccount as v}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,pipe,proposer,ref,script,transaction,why}from"@onflow/sdk";import{INIT as m,send as p,SUBSCRIBE as y,UNSUBSCRIBE as P,spawn as g,subscriber as b}from"@onflow/util-actor";import{Identity as w}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var E,T=function(s){try{return Promise.resolve(e().get("accessNode.api")).then(function(e){return n(s,[t({node:e}),r,o,i,u,c])})}catch(e){return Promise.reject(e)}},S=function(n,t){void 0===n&&(n=[]),void 0===t&&(t={});try{var r=function(e){return t.node=e,Array.isArray(n)&&(n=s(n)),Promise.resolve(T(n)).then(function(e){return a(e,t)})},o=t.node;return Promise.resolve(o?r(o):Promise.resolve(e().get("accessNode.api")).then(r))}catch(e){return Promise.reject(e)}},j=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(T(e)).then(JSON.stringify)},t=function(){if(Array.isArray(e))return Promise.resolve(s(e)).then(function(n){e=n})}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},A=function(n){try{return Promise.resolve(e().where(/^decoder\./)).then(function(e){var t=Object.fromEntries(Object.entries(e).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return l(n,t)})}catch(e){return Promise.reject(e)}};function k(e,n,t){if(!e.s){if(t instanceof x){if(!t.s)return void(t.o=k.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(k.bind(null,e,n),k.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var x=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;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,n?n(o):o):t?k(r,1,t(o)):k(r,2,o)}catch(e){k(r,2,e)}},r},e}();function R(e){return e instanceof x&&1&e.s}var N,I=function(e){try{return Promise.resolve(S([f(e)])).then(A)}catch(e){return Promise.reject(e)}},O=function(e){return 4===e.status},U=function(e){return 3===e.status||O(e)},L=function(e){return 2===e.status||U(e)},C=function(e){return 1===e.status||L(e)},_=((E={})[m]=function(e){try{return Promise.resolve(I(e.self())).then(function(n){O(n)||setTimeout(function(){return p(e.self(),"POLL")},1e3),e.merge(n)})}catch(e){return Promise.reject(e)}},E[y]=function(e,n){e.subscribe(n.from),e.send(n.from,"TRANSACTION/UPDATED",e.all())},E[P]=function(e,n){e.unsubscribe(n.from)},E.SNAPSHOT=function(e,n){try{return n.replay(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},E.POLL=function(e){try{return Promise.resolve(I(e.self())).then(function(n){O(n)||setTimeout(function(){return p(e.self(),"POLL")},1e3),e.merge(n),e.broadcast("TRANSACTION/UPDATED",e.all())})}catch(e){return Promise.reject(e)}},E),D=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return g(_,e)};function F(e){function n(n){var t=D(e),r=g(function(e){try{var r;return e.send(t,y),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(R(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!R(i)){r=1;break}i=i.s}}var u=new x,c=k.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):k(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||R(o)&&!o.v)return void k(u,1,i);if(o.then)return void o.then(a).then(void 0,c);R(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):k(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(e.receive()).then(function(o){if("@EXIT"===o.tag)return e.send(t,P),void(r=1);n(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return p(r,"@EXIT")}}function t(e){return function(){return new Promise(function(t){var r=n(function(n){e(n)&&(t(n),r())})})}}return{snapshot:function(){var n=D(e);return p(n,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:n,oncePending:t(C),onceFinalized:t(L),onceExecuted:t(U),onceSealed:t(O)}}function H(){return(H=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function B(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}F.isUnknown=function(e){return 0===e.status||C(e)},F.isPending=C,F.isFinalized=L,F.isExecuted=U,F.isSealed=O;var z=function(){try{return Promise.resolve(S([d()])).then(A)}catch(e){return Promise.reject(e)}},G=function(n){try{var t=setTimeout;return Promise.resolve(e.get("fcl.eventPollRate",1e4)).then(function(e){return t(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},X=((N={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),t=function(){if(null==n){var t=e.put;return Promise.resolve(z()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve(G(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(z()).then(function(t){return e.put("hwm",t),Promise.resolve(S([h(e.self(),n.height,t.height-1)])).then(function(n){return Promise.resolve(A(n)).then(function(n){for(var t,r=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return B(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?B(e,void 0):void 0}}(e)))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(n=e[Symbol.iterator]()).next.bind(n)}(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(G(e)).then(function(n){o.call(e,"tick",n)})})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},N[y]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(G(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},N[P]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},N),M=function(e){return g(X,e)};function J(e){return{subscribe:function(n){return b(e,M,n)}}}var q,W="FCL_IFRAME_CHALLENGE",K="FCL_IFRAME_AUTHZ",$=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},V={"HTTP/POST":"POST","HTTP/GET":"GET"},Z=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:V[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function Q(e,n,t){if(!e.s){if(t instanceof ne){if(!t.s)return void(t.o=Q.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(Q.bind(null,e,n),Q.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var Y=function(){try{return he(),Promise.resolve(pe()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(S([v(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},ee=function(e){try{return he(),Promise.resolve(re()).then(function(){return Promise.resolve(pe()).then(function(n){function t(){return H({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(pe()).then(function(n){return Promise.resolve(Y()).then(function(t){return Promise.resolve(Z(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById(K)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=K,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(K)&&document.getElementById(K).remove()}}}(e.local[0]));var t=null;return function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(Z(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return n(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(Y()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},ne=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{Q(r,1,i(this.v))}catch(e){Q(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Q(r,1,n?n(o):o):t?Q(r,1,t(o)):Q(r,2,o)}catch(e){Q(r,2,e)}},r},e}();function te(e){return e instanceof ne&&1&e.s}var re=function(){try{return Promise.resolve(new Promise(function(n){try{return he(),Promise.resolve(pe()).then(function(t){return t.loggedIn?n(t):Promise.resolve(e().get("challenge.handshake")).then(function(t){return Promise.resolve(e().get("challenge.scope")).then(function(e){var r=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(W)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=W,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(W)&&document.getElementById(W).remove()}}}({handshake:t,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var t=e.data;try{if(t.type!==ce)return Promise.resolve();r();var o=new URL(t.hks);return o.searchParams.append("code",t.code),Promise.resolve(fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return p(oe,ue,H({},e,{cid:$(e.provider),loggedIn:!0,verified:!0})),Promise.resolve(pe()).then(function(e){n(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},oe="CURRENT_USER",ie="CURRENT_USER/UPDATED",ue="SET_CURRENT_USER",ce="FCL::CHALLENGE::RESPONSE",se='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',ae=new Set(["verified","identity","scoped","provider"]),le=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return ae.has(n)&&function(e){console.warn(('\n %cFCL Deprecation Notice\n ========================\n\n Access to field "'+e+'" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n ').replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")}(n),e[n]}})),e},fe=((q={})[m]=function(e){e.merge(JSON.parse(se))},q[y]=function(e,n){e.subscribe(n.from),e.send(n.from,ie,le(e.all()))},q[P]=function(e,n){e.unsubscribe(n.from)},q.SNAPSHOT=function(e,n){try{return n.reply(le(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},q[ue]=function(e,n,t){try{return e.merge(t),e.broadcast(ie,le(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},q.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(se)),e.broadcast(ie,le(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},q.GET_AS_PARAM=function(e,n,t){var r=t.key;try{return n.reply({key:r,value:e.get("addr",null),xform:w}),Promise.resolve()}catch(e){return Promise.reject(e)}},q),he=function(){return g(fe,oe)};function de(){he(),p(oe,"DEL_CURRENT_USER")}function ve(e){return function(){try{return he(),Promise.resolve(re()).then(function(){return p(oe,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function me(e){he();var n=g(function(n){try{var t;return n.send(oe,y),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(te(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!te(i)){r=1;break}i=i.s}}var u=new ne,c=Q.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):Q(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||te(o)&&!o.v)return void Q(u,1,i);if(o.then)return void o.then(a).then(void 0,c);te(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):Q(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(oe,P),void(t=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return p(n,"@EXIT")}}function pe(){return he(),p(oe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ye=function(){return{authenticate:re,unauthenticate:de,authorization:ee,param:ve,subscribe:me,snapshot:pe}},Pe=function(){return ye().authenticate()},ge=function(){return ye().unauthenticate()};export{Pe as authenticate,ye as currentUser,A as decode,J as events,T as resolve,S as send,j as serialize,F as tx,ge as unauthenticate}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as n,resolveRefBlockId as t,resolveParams as r,resolveArguments as o,resolveAccounts as i,resolveSignatures as u,resolveValidators as c,build as s,send as a,decodeResponse as l,getTransactionStatus as f,getEvents as h,getLatestBlock as d,getAccount as v}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,pipe,proposer,ref,script,transaction,why}from"@onflow/sdk";import{INIT as m,send as p,SUBSCRIBE as y,UNSUBSCRIBE as P,spawn as g,subscriber as b}from"@onflow/util-actor";import{Identity as w}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var E,T=function(s){try{return Promise.resolve(e().get("accessNode.api")).then(function(e){return n(s,[t({node:e}),r,o,i,u,c])})}catch(e){return Promise.reject(e)}},S=function(n,t){void 0===n&&(n=[]),void 0===t&&(t={});try{var r=function(e){return t.node=e,Array.isArray(n)&&(n=s(n)),Promise.resolve(T(n)).then(function(e){return a(e,t)})},o=t.node;return Promise.resolve(o?r(o):Promise.resolve(e().get("accessNode.api")).then(r))}catch(e){return Promise.reject(e)}},j=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(T(e)).then(JSON.stringify)},t=function(){if(Array.isArray(e))return Promise.resolve(s(e)).then(function(n){e=n})}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},A=function(n){try{return Promise.resolve(e().where(/^decoder\./)).then(function(e){var t=Object.fromEntries(Object.entries(e).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return l(n,t)})}catch(e){return Promise.reject(e)}};function k(e,n,t){if(!e.s){if(t instanceof x){if(!t.s)return void(t.o=k.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(k.bind(null,e,n),k.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var x=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;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,n?n(o):o):t?k(r,1,t(o)):k(r,2,o)}catch(e){k(r,2,e)}},r},e}();function R(e){return e instanceof x&&1&e.s}var N,I=function(e){try{return Promise.resolve(S([f(e)])).then(A)}catch(e){return Promise.reject(e)}},O=function(e){return 4===e.status},U=function(e){return 3===e.status||O(e)},L=function(e){return 2===e.status||U(e)},C=function(e){return 1===e.status||L(e)},_=((E={})[m]=function(e){try{return Promise.resolve(I(e.self())).then(function(n){O(n)||setTimeout(function(){return p(e.self(),"POLL")},1e3),e.merge(n)})}catch(e){return Promise.reject(e)}},E[y]=function(e,n){e.subscribe(n.from),e.send(n.from,"TRANSACTION/UPDATED",e.all())},E[P]=function(e,n){e.unsubscribe(n.from)},E.SNAPSHOT=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},E.POLL=function(e){try{return Promise.resolve(I(e.self())).then(function(n){O(n)||setTimeout(function(){return p(e.self(),"POLL")},1e3),e.merge(n),e.broadcast("TRANSACTION/UPDATED",e.all())})}catch(e){return Promise.reject(e)}},E),D=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return g(_,e)};function F(e){function n(n){var t=D(e),r=g(function(e){try{var r;return e.send(t,y),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(R(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!R(i)){r=1;break}i=i.s}}var u=new x,c=k.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):k(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||R(o)&&!o.v)return void k(u,1,i);if(o.then)return void o.then(a).then(void 0,c);R(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):k(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(e.receive()).then(function(o){if("@EXIT"===o.tag)return e.send(t,P),void(r=1);n(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return p(r,"@EXIT")}}function t(e){return function(){return new Promise(function(t){var r=n(function(n){e(n)&&(t(n),r())})})}}return{snapshot:function(){var n=D(e);return p(n,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:n,oncePending:t(C),onceFinalized:t(L),onceExecuted:t(U),onceSealed:t(O)}}function H(){return(H=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function B(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}F.isUnknown=function(e){return 0===e.status||C(e)},F.isPending=C,F.isFinalized=L,F.isExecuted=U,F.isSealed=O;var z=function(){try{return Promise.resolve(S([d()])).then(A)}catch(e){return Promise.reject(e)}},G=function(n){try{var t=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return t(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},X=((N={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),t=function(){if(null==n){var t=e.put;return Promise.resolve(z()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve(G(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(z()).then(function(t){return e.put("hwm",t),Promise.resolve(S([h(e.self(),n.height,t.height-1)])).then(function(n){return Promise.resolve(A(n)).then(function(n){for(var t,r=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return B(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?B(e,void 0):void 0}}(e)))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(n=e[Symbol.iterator]()).next.bind(n)}(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(G(e)).then(function(n){o.call(e,"tick",n)})})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},N[y]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(G(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},N[P]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},N),M=function(e){return g(X,e)};function J(e){return{subscribe:function(n){return b(e,M,n)}}}var q,W="FCL_IFRAME_CHALLENGE",K="FCL_IFRAME_AUTHZ",$=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},V={"HTTP/POST":"POST","HTTP/GET":"GET"},Z=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:V[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function Q(e,n,t){if(!e.s){if(t instanceof ne){if(!t.s)return void(t.o=Q.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(Q.bind(null,e,n),Q.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var Y=function(){try{return he(),Promise.resolve(pe()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(S([v(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},ee=function(e){try{return he(),Promise.resolve(re()).then(function(){return Promise.resolve(pe()).then(function(n){function t(){return H({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(pe()).then(function(n){return Promise.resolve(Y()).then(function(t){return Promise.resolve(Z(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById(K)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=K,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(K)&&document.getElementById(K).remove()}}}(e.local[0]));var t=null;return function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(Z(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return n(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(Y()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},ne=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{Q(r,1,i(this.v))}catch(e){Q(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Q(r,1,n?n(o):o):t?Q(r,1,t(o)):Q(r,2,o)}catch(e){Q(r,2,e)}},r},e}();function te(e){return e instanceof ne&&1&e.s}var re=function(){try{return Promise.resolve(new Promise(function(n){try{return he(),Promise.resolve(pe()).then(function(t){return t.loggedIn?n(t):Promise.resolve(e().get("challenge.handshake")).then(function(t){return Promise.resolve(e().get("challenge.scope")).then(function(e){var r=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(W)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=W,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(W)&&document.getElementById(W).remove()}}}({handshake:t,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var t=e.data;try{if(t.type!==ce)return Promise.resolve();r();var o=new URL(t.hks);return o.searchParams.append("code",t.code),Promise.resolve(fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return p(oe,ue,H({},e,{cid:$(e.provider),loggedIn:!0,verified:!0})),Promise.resolve(pe()).then(function(e){n(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},oe="CURRENT_USER",ie="CURRENT_USER/UPDATED",ue="SET_CURRENT_USER",ce="FCL::CHALLENGE::RESPONSE",se='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',ae=new Set(["verified","identity","scoped","provider"]),le=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return ae.has(n)&&function(e){console.warn(('\n %cFCL Deprecation Notice\n ========================\n\n Access to field "'+e+'" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n ').replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")}(n),e[n]}})),e},fe=((q={})[m]=function(e){e.merge(JSON.parse(se))},q[y]=function(e,n){e.subscribe(n.from),e.send(n.from,ie,le(e.all()))},q[P]=function(e,n){e.unsubscribe(n.from)},q.SNAPSHOT=function(e,n){try{return n.reply(le(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},q[ue]=function(e,n,t){try{return e.merge(t),e.broadcast(ie,le(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},q.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(se)),e.broadcast(ie,le(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},q.GET_AS_PARAM=function(e,n,t){var r=t.key;try{return n.reply({key:r,value:e.get("addr",null),xform:w}),Promise.resolve()}catch(e){return Promise.reject(e)}},q),he=function(){return g(fe,oe)};function de(){he(),p(oe,"DEL_CURRENT_USER")}function ve(e){return function(){try{return he(),Promise.resolve(re()).then(function(){return p(oe,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function me(e){he();var n=g(function(n){try{var t;return n.send(oe,y),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(te(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!te(i)){r=1;break}i=i.s}}var u=new ne,c=Q.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):Q(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||te(o)&&!o.v)return void Q(u,1,i);if(o.then)return void o.then(a).then(void 0,c);te(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):Q(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(oe,P),void(t=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return p(n,"@EXIT")}}function pe(){return he(),p(oe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ye=function(){return{authenticate:re,unauthenticate:de,authorization:ee,param:ve,subscribe:me,snapshot:pe}},Pe=function(){return ye().authenticate()},ge=function(){return ye().unauthenticate()};export{Pe as authenticate,ye as currentUser,A as decode,J as events,T as resolve,S as send,j as serialize,F as tx,ge as unauthenticate}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/config"),require("@onflow/sdk"),require("@onflow/util-actor"),require("@onflow/types")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/sdk","@onflow/util-actor","@onflow/types"],n):n((e=e||self).fcl={},e.config,e.sdk,e.utilActor,e.types)}(this,function(e,n,t,r,o){n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var i,u=function(e){try{return Promise.resolve(n.config().get("accessNode.api")).then(function(n){return t.resolve(e,[t.resolveRefBlockId({node:n}),t.resolveParams,t.resolveArguments,t.resolveAccounts,t.resolveSignatures,t.resolveValidators])})}catch(e){return Promise.reject(e)}},c=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var o=function(n){return r.node=n,Array.isArray(e)&&(e=t.build(e)),Promise.resolve(u(e)).then(function(e){return t.send(e,r)})},i=r.node;return Promise.resolve(i?o(i):Promise.resolve(n.config().get("accessNode.api")).then(o))}catch(e){return Promise.reject(e)}},s=function(e){try{return Promise.resolve(n.config().where(/^decoder\./)).then(function(n){var r=Object.fromEntries(Object.entries(n).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return t.decodeResponse(e,r)})}catch(e){return Promise.reject(e)}};function a(e,n,t){if(!e.s){if(t instanceof f){if(!t.s)return void(t.o=a.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(a.bind(null,e,n),a.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var f=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{a(r,1,i(this.v))}catch(e){a(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?a(r,1,n?n(o):o):t?a(r,1,t(o)):a(r,2,o)}catch(e){a(r,2,e)}},r},e}();function l(e){return e instanceof f&&1&e.s}var d,h=function(e){try{return Promise.resolve(c([t.getTransactionStatus(e)])).then(s)}catch(e){return Promise.reject(e)}},m=function(e){return 4===e.status},v=function(e){return 3===e.status||m(e)},p=function(e){return 2===e.status||v(e)},y=function(e){return 1===e.status||p(e)},P=((i={})[r.INIT]=function(e){try{return Promise.resolve(h(e.self())).then(function(n){m(n)||setTimeout(function(){return r.send(e.self(),"POLL")},1e3),e.merge(n)})}catch(e){return Promise.reject(e)}},i[r.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,"TRANSACTION/UPDATED",e.all())},i[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},i.SNAPSHOT=function(e,n){try{return n.replay(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},i.POLL=function(e){try{return Promise.resolve(h(e.self())).then(function(n){m(n)||setTimeout(function(){return r.send(e.self(),"POLL")},1e3),e.merge(n),e.broadcast("TRANSACTION/UPDATED",e.all())})}catch(e){return Promise.reject(e)}},i),b=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return r.spawn(P,e)};function g(e){function n(n){var t=b(e),o=r.spawn(function(e){try{var o;return e.send(t,r.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(l(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!l(i)){r=1;break}i=i.s}}var u=new f,c=a.bind(null,u,2);return(0===r?o.then(d):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(d).then(void 0,c):d(o):a(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||l(o)&&!o.v)return void a(u,1,i);if(o.then)return void o.then(d).then(void 0,c);l(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function d(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):a(u,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(e.receive()).then(function(i){if("@EXIT"===i.tag)return e.send(t,r.UNSUBSCRIBE),void(o=1);n(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(o,"@EXIT")}}function t(e){return function(){return new Promise(function(t){var r=n(function(n){e(n)&&(t(n),r())})})}}return{snapshot:function(){var n=b(e);return r.send(n,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:n,oncePending:t(y),onceFinalized:t(p),onceExecuted:t(v),onceSealed:t(m)}}function j(){return(j=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function S(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}g.isUnknown=function(e){return 0===e.status||y(e)},g.isPending=y,g.isFinalized=p,g.isExecuted=v,g.isSealed=m;var w,E=function(){try{return Promise.resolve(c([t.getLatestBlock()])).then(s)}catch(e){return Promise.reject(e)}},O=function(e){try{var t=setTimeout;return Promise.resolve(n.config.get("fcl.eventPollRate",1e4)).then(function(n){return t(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},T=((d={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(E()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(O(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(E()).then(function(r){return e.put("hwm",r),Promise.resolve(c([t.getEvents(e.self(),n.height,r.height-1)])).then(function(n){return Promise.resolve(s(n)).then(function(n){for(var t,r=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return S(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?S(e,void 0):void 0}}(e)))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(n=e[Symbol.iterator]()).next.bind(n)}(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(O(e)).then(function(n){o.call(e,"tick",n)})})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},d[r.SUBSCRIBE]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(O(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},d[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},d),I=function(e){return r.spawn(T,e)},R="FCL_IFRAME_CHALLENGE",A="FCL_IFRAME_AUTHZ",k=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},U={"HTTP/POST":"POST","HTTP/GET":"GET"},N=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:U[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function B(e,n,t){if(!e.s){if(t instanceof L){if(!t.s)return void(t.o=B.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(B.bind(null,e,n),B.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var x=function(){try{return W(),Promise.resolve(Z()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(c([t.getAccount(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},C=function(e){try{return W(),Promise.resolve(D()).then(function(){return Promise.resolve(Z()).then(function(n){function t(){return j({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(Z()).then(function(n){return Promise.resolve(x()).then(function(t){return Promise.resolve(N(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById(A)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=A,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(A)&&document.getElementById(A).remove()}}}(e.local[0]));var t=null;return function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(N(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return n(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(x()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},L=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{B(r,1,i(this.v))}catch(e){B(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?B(r,1,n?n(o):o):t?B(r,1,t(o)):B(r,2,o)}catch(e){B(r,2,e)}},r},e}();function _(e){return e instanceof L&&1&e.s}var D=function(){try{return Promise.resolve(new Promise(function(e){try{return W(),Promise.resolve(Z()).then(function(t){return t.loggedIn?e(t):Promise.resolve(n.config().get("challenge.handshake")).then(function(t){return Promise.resolve(n.config().get("challenge.scope")).then(function(n){var o=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(R)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=R,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(R)&&document.getElementById(R).remove()}}}({handshake:t,scope:n,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var t=n.data;try{if(t.type!==G)return Promise.resolve();o();var i=new URL(t.hks);return i.searchParams.append("code",t.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){return r.send(z,H,j({},n,{cid:k(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(Z()).then(function(n){e(n)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},z="CURRENT_USER",F="CURRENT_USER/UPDATED",H="SET_CURRENT_USER",G="FCL::CHALLENGE::RESPONSE",q='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',X=new Set(["verified","identity","scoped","provider"]),M=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return X.has(n)&&function(e){console.warn(('\n %cFCL Deprecation Notice\n ========================\n\n Access to field "'+e+'" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n ').replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")}(n),e[n]}})),e},J=((w={})[r.INIT]=function(e){e.merge(JSON.parse(q))},w[r.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,F,M(e.all()))},w[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},w.SNAPSHOT=function(e,n){try{return n.reply(M(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},w[H]=function(e,n,t){try{return e.merge(t),e.broadcast(F,M(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},w.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(q)),e.broadcast(F,M(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},w.GET_AS_PARAM=function(e,n,t){var r=t.key;try{return n.reply({key:r,value:e.get("addr",null),xform:o.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},w),W=function(){return r.spawn(J,z)};function K(){W(),r.send(z,"DEL_CURRENT_USER")}function V(e){return function(){try{return W(),Promise.resolve(D()).then(function(){return r.send(z,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function $(e){W();var n=r.spawn(function(n){try{var t;return n.send(z,r.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(_(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!_(i)){r=1;break}i=i.s}}var u=new L,c=B.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):B(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||_(o)&&!o.v)return void B(u,1,i);if(o.then)return void o.then(a).then(void 0,c);_(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):B(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(z,r.UNSUBSCRIBE),void(t=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(n,"@EXIT")}}function Z(){return W(),r.send(z,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Q=function(){return{authenticate:D,unauthenticate:K,authorization:C,param:V,subscribe:$,snapshot:Z}};Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return t.cadence}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return t.cdc}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),e.authenticate=function(){return Q().authenticate()},e.currentUser=Q,e.decode=s,e.events=function(e){return{subscribe:function(n){return r.subscriber(e,I,n)}}},e.resolve=u,e.send=c,e.serialize=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(u(e)).then(JSON.stringify)},r=function(){if(Array.isArray(e))return Promise.resolve(t.build(e)).then(function(n){e=n})}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},e.tx=g,e.unauthenticate=function(){return Q().unauthenticate()}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/config"),require("@onflow/sdk"),require("@onflow/util-actor"),require("@onflow/types")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/sdk","@onflow/util-actor","@onflow/types"],n):n((e=e||self).fcl={},e.config,e.sdk,e.utilActor,e.types)}(this,function(e,n,t,r,o){n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var i,u=function(e){try{return Promise.resolve(n.config().get("accessNode.api")).then(function(n){return t.resolve(e,[t.resolveRefBlockId({node:n}),t.resolveParams,t.resolveArguments,t.resolveAccounts,t.resolveSignatures,t.resolveValidators])})}catch(e){return Promise.reject(e)}},c=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var o=function(n){return r.node=n,Array.isArray(e)&&(e=t.build(e)),Promise.resolve(u(e)).then(function(e){return t.send(e,r)})},i=r.node;return Promise.resolve(i?o(i):Promise.resolve(n.config().get("accessNode.api")).then(o))}catch(e){return Promise.reject(e)}},s=function(e){try{return Promise.resolve(n.config().where(/^decoder\./)).then(function(n){var r=Object.fromEntries(Object.entries(n).map(function(e){var n=e[0],t=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",t]}));return t.decodeResponse(e,r)})}catch(e){return Promise.reject(e)}};function a(e,n,t){if(!e.s){if(t instanceof f){if(!t.s)return void(t.o=a.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(a.bind(null,e,n),a.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var f=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{a(r,1,i(this.v))}catch(e){a(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?a(r,1,n?n(o):o):t?a(r,1,t(o)):a(r,2,o)}catch(e){a(r,2,e)}},r},e}();function l(e){return e instanceof f&&1&e.s}var d,h=function(e){try{return Promise.resolve(c([t.getTransactionStatus(e)])).then(s)}catch(e){return Promise.reject(e)}},m=function(e){return 4===e.status},v=function(e){return 3===e.status||m(e)},p=function(e){return 2===e.status||v(e)},y=function(e){return 1===e.status||p(e)},P=((i={})[r.INIT]=function(e){try{return Promise.resolve(h(e.self())).then(function(n){m(n)||setTimeout(function(){return r.send(e.self(),"POLL")},1e3),e.merge(n)})}catch(e){return Promise.reject(e)}},i[r.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,"TRANSACTION/UPDATED",e.all())},i[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},i.SNAPSHOT=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},i.POLL=function(e){try{return Promise.resolve(h(e.self())).then(function(n){m(n)||setTimeout(function(){return r.send(e.self(),"POLL")},1e3),e.merge(n),e.broadcast("TRANSACTION/UPDATED",e.all())})}catch(e){return Promise.reject(e)}},i),b=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return r.spawn(P,e)};function g(e){function n(n){var t=b(e),o=r.spawn(function(e){try{var o;return e.send(t,r.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(l(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!l(i)){r=1;break}i=i.s}}var u=new f,c=a.bind(null,u,2);return(0===r?o.then(d):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(d).then(void 0,c):d(o):a(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||l(o)&&!o.v)return void a(u,1,i);if(o.then)return void o.then(d).then(void 0,c);l(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function d(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):a(u,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(e.receive()).then(function(i){if("@EXIT"===i.tag)return e.send(t,r.UNSUBSCRIBE),void(o=1);n(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(o,"@EXIT")}}function t(e){return function(){return new Promise(function(t){var r=n(function(n){e(n)&&(t(n),r())})})}}return{snapshot:function(){var n=b(e);return r.send(n,"SNAPSHOT",null,{expectReply:!0,timeout:10})},subscribe:n,oncePending:t(y),onceFinalized:t(p),onceExecuted:t(v),onceSealed:t(m)}}function j(){return(j=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function S(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}g.isUnknown=function(e){return 0===e.status||y(e)},g.isPending=y,g.isFinalized=p,g.isExecuted=v,g.isSealed=m;var w,E=function(){try{return Promise.resolve(c([t.getLatestBlock()])).then(s)}catch(e){return Promise.reject(e)}},O=function(e){try{var t=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return t(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},T=((d={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(E()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(O(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(E()).then(function(r){return e.put("hwm",r),Promise.resolve(c([t.getEvents(e.self(),n.height,r.height-1)])).then(function(n){return Promise.resolve(s(n)).then(function(n){for(var t,r=function(e){var n=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,n){if(e){if("string"==typeof e)return S(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?S(e,void 0):void 0}}(e)))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(n=e[Symbol.iterator]()).next.bind(n)}(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(O(e)).then(function(n){o.call(e,"tick",n)})})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},d[r.SUBSCRIBE]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(O(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},d[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},d),I=function(e){return r.spawn(T,e)},R="FCL_IFRAME_CHALLENGE",A="FCL_IFRAME_AUTHZ",k=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},U={"HTTP/POST":"POST","HTTP/GET":"GET"},N=function(e,n){try{for(var t=new URL(e.endpoint),r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(t,{method:U[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function B(e,n,t){if(!e.s){if(t instanceof L){if(!t.s)return void(t.o=B.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(B.bind(null,e,n),B.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var x=function(){try{return W(),Promise.resolve(Z()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(c([t.getAccount(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},C=function(e){try{return W(),Promise.resolve(D()).then(function(){return Promise.resolve(Z()).then(function(n){function t(){return j({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:r,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(Z()).then(function(n){return Promise.resolve(x()).then(function(t){return Promise.resolve(N(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById(A)){for(var n=new URL(e.endpoint),t=0,r=Object.entries(e.params||{});t<r.length;t++){var o=r[t];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=A,i.style.height=e.height||"500px",i.style.maxHeight="90vh",i.style.width=e.width||"400px",i.style.maxWidth="90vw",i.style.display="block",i.style.background=e.background||"#fff",i.style.position="fixed",i.style.top="5vh",i.style.right="calc(50vw)",i.style.transform="translateX(50%)",i.style.boxShadow="0 4px 8px -4px black",i.frameBorder="0",document.body.append(i),function(){document.getElementById(A)&&document.getElementById(A).remove()}}}(e.local[0]));var t=null;return function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(N(n)).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return n(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var r,o=function(){if(e.role.proposer)return Promise.resolve(x()).then(function(e){var t=e.keys.find(function(e){return e.index===n.keyId});r=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},L=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{B(r,1,i(this.v))}catch(e){B(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?B(r,1,n?n(o):o):t?B(r,1,t(o)):B(r,2,o)}catch(e){B(r,2,e)}},r},e}();function _(e){return e instanceof L&&1&e.s}var D=function(){try{return Promise.resolve(new Promise(function(e){try{return W(),Promise.resolve(Z()).then(function(t){return t.loggedIn?e(t):Promise.resolve(n.config().get("challenge.handshake")).then(function(t){return Promise.resolve(n.config().get("challenge.scope")).then(function(n){var o=function(e){var n=e.handshake,t=e.scope,r=e.nonce,o=e.l6n;if(!document.getElementById(R)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",r),t&&i.searchParams.append("scope",t.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=R,u.style.height="500px",u.style.maxHeight="90vh",u.style.width="400px",u.style.maxWidth="90vw",u.style.display="block",u.style.background="#fff",u.style.position="fixed",u.style.top="5vh",u.style.right="calc(50vw)",u.style.transform="translateX(50%)",u.style.boxShadow="0 4px 8px -4px black",u.frameBorder="0",document.body.append(u),function(){document.getElementById(R)&&document.getElementById(R).remove()}}}({handshake:t,scope:n,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var t=n.data;try{if(t.type!==G)return Promise.resolve();o();var i=new URL(t.hks);return i.searchParams.append("code",t.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){return r.send(z,H,j({},n,{cid:k(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(Z()).then(function(n){e(n)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},z="CURRENT_USER",F="CURRENT_USER/UPDATED",H="SET_CURRENT_USER",G="FCL::CHALLENGE::RESPONSE",q='{\n "cid":null,\n "loggedIn":null,\n "verified":null,\n "identity":{\n "name":null,\n "addr":null,\n "avatar":null,\n "cover":null,\n "color":null,\n "bio":null\n },\n "scoped":{},\n "provider":{\n "addr":null,\n "pid":null,\n "name":null,\n "icon":null\n },\n "authorizations":[]\n}',X=new Set(["verified","identity","scoped","provider"]),M=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return X.has(n)&&function(e){console.warn(('\n %cFCL Deprecation Notice\n ========================\n\n Access to field "'+e+'" on "CurrentUser" is deprecated and will cease to work in future releases of FCL.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/fcl/WARNINGS.md#0001-current-user-data\n\n =======================\n ').replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")}(n),e[n]}})),e},J=((w={})[r.INIT]=function(e){e.merge(JSON.parse(q))},w[r.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,F,M(e.all()))},w[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},w.SNAPSHOT=function(e,n){try{return n.reply(M(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},w[H]=function(e,n,t){try{return e.merge(t),e.broadcast(F,M(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},w.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(q)),e.broadcast(F,M(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},w.GET_AS_PARAM=function(e,n,t){var r=t.key;try{return n.reply({key:r,value:e.get("addr",null),xform:o.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},w),W=function(){return r.spawn(J,z)};function K(){W(),r.send(z,"DEL_CURRENT_USER")}function V(e){return function(){try{return W(),Promise.resolve(D()).then(function(){return r.send(z,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function $(e){W();var n=r.spawn(function(n){try{var t;return n.send(z,r.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(_(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!_(i)){r=1;break}i=i.s}}var u=new L,c=B.bind(null,u,2);return(0===r?o.then(a):1===r?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):B(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||_(o)&&!o.v)return void B(u,1,i);if(o.then)return void o.then(a).then(void 0,c);_(i=t())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=t())&&i.then?i.then(s).then(void 0,c):s(i):B(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(z,r.UNSUBSCRIBE),void(t=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(n,"@EXIT")}}function Z(){return W(),r.send(z,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Q=function(){return{authenticate:D,unauthenticate:K,authorization:C,param:V,subscribe:$,snapshot:Z}};Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return t.cadence}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return t.cdc}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),e.authenticate=function(){return Q().authenticate()},e.currentUser=Q,e.decode=s,e.events=function(e){return{subscribe:function(n){return r.subscriber(e,I,n)}}},e.resolve=u,e.send=c,e.serialize=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(u(e)).then(JSON.stringify)},r=function(){if(Array.isArray(e))return Promise.resolve(t.build(e)).then(function(n){e=n})}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},e.tx=g,e.unauthenticate=function(){return Q().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.49", | ||
"version": "0.0.50", | ||
"description": "Flow Client Library", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
209981