@onflow/fcl
Advanced tools
Comparing version 0.0.50 to 0.0.51
@@ -5,2 +5,7 @@ ### Unreleased | ||
### 0.0.51 -- 2020-08-14 | ||
- 2020-08-14 -- `fcl.tx(resp).once*` throw errors when statusCode is non-zero, errors can be suppressed (previous behaviour) py passing `{suppress: true}` to the `.once*` function. | ||
- 2020-08-14 -- `fcl.tx(resp).subscribe(callback)` callback will only be called when the status is different to what it was before. | ||
### 0.0.50 -- 2020-08-14 | ||
@@ -7,0 +12,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.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()}; | ||
var e=require("@onflow/config"),r=require("@onflow/sdk"),t=require("@onflow/util-actor"),n=require("@onflow/types");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var o,i,u=function(t){try{return Promise.resolve(e.config().get("accessNode.api")).then(function(e){return r.resolve(t,[r.resolveRefBlockId({node:e}),r.resolveParams,r.resolveArguments,r.resolveAccounts,r.resolveSignatures,r.resolveValidators])})}catch(e){return Promise.reject(e)}},c=function(t,n){void 0===t&&(t=[]),void 0===n&&(n={});try{var o=function(e){return n.node=e,Array.isArray(t)&&(t=r.build(t)),Promise.resolve(u(t)).then(function(e){return r.send(e,n)})},i=n.node;return Promise.resolve(i?o(i):Promise.resolve(e.config().get("accessNode.api")).then(o))}catch(e){return Promise.reject(e)}},s=function(t){try{return Promise.resolve(e.config().where(/^decoder\./)).then(function(e){var n=Object.fromEntries(Object.entries(e).map(function(e){var r=e[0],t=e[1];return[r="/"+r.replace(/^decoder\./,"")+"$/",t]}));return r.decodeResponse(t,n)})}catch(e){return Promise.reject(e)}},a=function(e){try{return Promise.resolve(c([r.getTransactionStatus(e)])).then(s)}catch(e){return Promise.reject(e)}},l=function(e){return e.status>=4},f=function(e){return e.status>=3},d=function(e){return e.status>=2||f(e)},h=function(e){return e.status>=1||d(e)},m=((o={})[t.INIT]=function(e){try{return Promise.resolve(a(e.self())).then(function(r){l(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},o[t.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,t.UPDATED,e.all())},o[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},o[t.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},o.POLL=function(e){try{return Promise.resolve(a(e.self())).then(function(r){var n,o;l(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),o=r,JSON.stringify(n)!==JSON.stringify(o)&&e.broadcast(t.UPDATED,r),e.merge(r)})}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 e},v=function(e){return t.spawn(m,p(e))};function y(e){function r(r){return t.subscriber(p(e),v,r)}function n(e){return function(t){void 0===t&&(t={});var n=t.suppress||!1;return new Promise(function(t,o){var i=r(function(r){r.statusCode&&!n?(o(r.errorMessage),i()):e(r)&&(t(r),i())})})}}return{snapshot:function(){return t.snapshoter(e,v)},subscribe:r,onceFinalized:n(d),onceExecuted:n(f),onceSealed:n(l)}}function P(){return(P=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function b(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}y.isUnknown=function(e){return e.status>=0||h(e)},y.isPending=h,y.isFinalized=d,y.isExecuted=f,y.isSealed=l,y.isExpired=function(e){return 5===e.status};var g,j=function(){try{return Promise.resolve(c([r.getLatestBlock()])).then(s)}catch(e){return Promise.reject(e)}},x=function(r){try{var t=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return t(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},S=((i={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),n=function(){if(null==t){var n=e.put;return Promise.resolve(j()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(x(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(j()).then(function(n){return e.put("hwm",n),Promise.resolve(c([r.getEvents(e.self(),t.height,n.height-1)])).then(function(r){return Promise.resolve(s(r)).then(function(r){for(var t,n=function(e){var r=0;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(e=function(e,r){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 r>=e.length?{done:!0}:{done:!1,value:e[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(x(e)).then(function(r){o.call(e,"tick",r)})})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i[t.SUBSCRIBE]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(x(e)).then(function(t){r.call(e,"tick",t)})}}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},i[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},i),E=function(e){return t.spawn(S,e)},w="FCL_IFRAME_CHALLENGE",O="FCL_IFRAME_AUTHZ",T=function(e){void 0===e&&(e={});var r=e.addr,t=e.pid;return null==r||null==t?null:r+"/"+t},I={"HTTP/POST":"POST","HTTP/GET":"GET"},R=function(e,r){try{for(var t=new URL(e.endpoint),n=0,o=Object.entries(e.params||{});n<o.length;n++){var i=o[n];t.searchParams.append(i[0],i[1])}return r=r?JSON.stringify(r):void 0,Promise.resolve(fetch(t,{method:I[e.method],headers:{"Content-Type":"application/json"},body:r}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function U(e,r,t){if(!e.s){if(t instanceof N){if(!t.s)return void(t.o=U.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(U.bind(null,e,r),U.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var k=function(){try{return J(),Promise.resolve(K()).then(function(e){var t=e.addr;if(null==t)throw new Error("No Flow Address for Current User");return Promise.resolve(c([r.getAccount(t)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},A=function(e){try{return J(),Promise.resolve(C()).then(function(){return Promise.resolve(K()).then(function(r){function t(){return P({},e,{addr:r.addr,keyId:r.keyId,sequenceNum:n,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(K()).then(function(r){return Promise.resolve(k()).then(function(t){return Promise.resolve(R(r.authorizations[0],e)).then(function(e){var r=function(){};e.local&&e.local.length>0&&(r=function(e){if(!document.getElementById(O)){for(var r=new URL(e.endpoint),t=0,n=Object.entries(e.params||{});t<n.length;t++){var o=n[t];r.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=r.href,i.id=O,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(O)&&document.getElementById(O).remove()}}}(e.local[0]));var t=null;return function(e,r){try{var t=e()}catch(e){return r()}return t&&t.then?t.then(r,r):r()}(function(){return function(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(function(){return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(R(r)).then(function(r){"APPROVED"===r.status?t(r.compositeSignature):"DECLINED"===r.status?n({status:r.status,reason:r.reason}):setTimeout(function(){t(e(r.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})},function(e){throw console.error(e),e})},function(){return r(),t})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var n,o=function(){if(e.role.proposer)return Promise.resolve(k()).then(function(e){var t=e.keys.find(function(e){return e.index===r.keyId});n=t.sequenceNumber})}();return o&&o.then?o.then(t):t()})})}catch(e){return Promise.reject(e)}},N=function(){function e(){}return e.prototype.then=function(r,t){var n=new e,o=this.s;if(o){var i=1&o?r:t;if(i){try{U(n,1,i(this.v))}catch(e){U(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?U(n,1,r?r(o):o):t?U(n,1,t(o)):U(n,2,o)}catch(e){U(n,2,e)}},n},e}();function B(e){return e instanceof N&&1&e.s}var C=function(){try{return Promise.resolve(new Promise(function(r){try{return J(),Promise.resolve(K()).then(function(n){return n.loggedIn?r(n):Promise.resolve(e.config().get("challenge.handshake")).then(function(n){return Promise.resolve(e.config().get("challenge.scope")).then(function(e){var o=function(e){var r=e.handshake,t=e.scope,n=e.nonce,o=e.l6n;if(!document.getElementById(w)){var i=new URL(r);i.searchParams.append("l6n",o),i.searchParams.append("nonce",n),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:n,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var n=e.data;try{if(n.type!==z)return Promise.resolve();o();var i=new URL(n.hks);return i.searchParams.append("code",n.code),Promise.resolve(fetch(i,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return t.send(L,D,P({},e,{cid:T(e.provider),loggedIn:!0,verified:!0})),Promise.resolve(K()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},L="CURRENT_USER",_="CURRENT_USER/UPDATED",D="SET_CURRENT_USER",z="FCL::CHALLENGE::RESPONSE",F='{\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}',H=new Set(["verified","identity","scoped","provider"]),G=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,r){return H.has(r)&&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;")}(r),e[r]}})),e},q=((g={})[t.INIT]=function(e){e.merge(JSON.parse(F))},g[t.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,_,G(e.all()))},g[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},g.SNAPSHOT=function(e,r){try{return r.reply(G(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},g[D]=function(e,r,t){try{return e.merge(t),e.broadcast(_,G(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},g.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(F)),e.broadcast(_,G(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},g.GET_AS_PARAM=function(e,r,t){var o=t.key;try{return r.reply({key:o,value:e.get("addr",null),xform:n.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},g),J=function(){return t.spawn(q,L)};function M(){J(),t.send(L,"DEL_CURRENT_USER")}function X(e){return function(){try{return J(),Promise.resolve(C()).then(function(){return t.send(L,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function W(e){J();var r=t.spawn(function(r){try{var n;return r.send(L,t.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(B(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!B(i)){n=1;break}i=i.s}}var u=new N,c=U.bind(null,u,2);return(0===n?o.then(a):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):U(u,1,i)})).then(void 0,c),u;function s(r){i=r;do{if(!(o=e())||B(o)&&!o.v)return void U(u,1,i);if(o.then)return void o.then(a).then(void 0,c);B(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):U(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if("@EXIT"===o.tag)return r.send(L,t.UNSUBSCRIBE),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(r,"@EXIT")}}function K(){return J(),t.send(L,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var V=function(){return{authenticate:C,unauthenticate:M,authorization:A,param:X,subscribe:W,snapshot:K}};Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return r.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return r.args}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return r.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return r.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return r.build}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return r.cadence}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return r.cdc}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return r.getAccount}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return r.getEvents}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return r.getLatestBlock}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return r.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return r.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return r.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return r.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return r.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return r.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return r.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return r.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return r.script}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return r.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return r.why}}),exports.authenticate=function(){return V().authenticate()},exports.currentUser=V,exports.decode=s,exports.events=function(e){return{subscribe:function(r){return t.subscriber(e,E,r)}}},exports.resolve=u,exports.send=c,exports.serialize=function(e){void 0===e&&(e=[]);try{var t=function(){return Promise.resolve(u(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(r.build(e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},exports.tx=y,exports.unauthenticate=function(){return V().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.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}; | ||
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{subscriber as y,spawn as h,snapshoter as w,INIT as g,SUBSCRIBE as E,UPDATED as b,UNSUBSCRIBE as S,SNAPSHOT as T,send as k}from"@onflow/util-actor";import{Identity as R}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const x=async c=>t(c,[n({node:await e().get("accessNode.api")}),a,s,o,r,i]),P=async(t=[],n={})=>(n.node=n.node||await e().get("accessNode.api"),Array.isArray(t)&&(t=c(t)),l(await x(t),n)),v=async(e=[])=>(Array.isArray(e)&&(e=await c(e)),JSON.stringify(await x(e))),N=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 P([d(e)]);return N(t)},U=e=>e.status>=4,L=e=>e.status>=3,I=e=>e.status>=2||L(e),C=e=>e.status>=1||I(e),O={[g]:async e=>{const t=await A(e.self());U(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,b,e.all())},[S]:(e,t)=>{e.unsubscribe(t.from)},[T]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await A(e.self());var n,a;U(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(b,t),e.merge(t)}},_=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},D=e=>h(O,_(e));function F(e){function t(t){return y(_(e),D,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,s)=>{const o=t(t=>{t.statusCode&&!a?(s(t.errorMessage),o()):e(t)&&(n(t),o())})})}}return{snapshot:function(){return w(e,D)},subscribe:t,onceFinalized:n(I),onceExecuted:n(L),onceSealed:n(U)}}F.isUnknown=e=>e.status>=0||C(e),F.isPending=C,F.isFinalized=I,F.isExecuted=L,F.isSealed=U,F.isExpired=e=>5===e.status;const j=async()=>N(await P([p()])),B=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),H={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await j()),e.put("tick",await B(e));else{let n=await j();e.put("hwm",n);const a=await P([f(e.self(),t.height,n.height-1)]),s=await N(a);for(let t of s)e.broadcast("UPDATED",t.data);e.put("tick",await B(e))}},[E]:async(e,t)=>{e.hasSubs()||e.put("tick",await B(e)),e.subscribe(t.from)},[S]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},z=e=>h(H,e);function G(e){return{subscribe:t=>y(e,z,t)}}const J="FCL_IFRAME_CHALLENGE",M="FCL_IFRAME_AUTHZ",$=(e={})=>{const t=e.addr,n=e.pid;return null==t||null==n?null:`${t}/${n}`},X={"HTTP/POST":"POST","HTTP/GET":"GET"},q=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:X[e.method],headers:{"Content-Type":"application/json"},body:t}).then(e=>e.json())},W=e=>new Promise(async(t,n)=>{const a=await q(e);"APPROVED"===a.status?t(a.compositeSignature):"DECLINED"===a.status?n({status:a.status,reason:a.reason}):setTimeout(()=>{t(W(a.authorizationUpdates))},500)}),K="CURRENT_USER",V="CURRENT_USER/UPDATED",Z='{\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"]),Y=e=>("undefined"!=typeof Proxy&&(e=new Proxy(e,{get:(e,t)=>(Q.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),ee={[g]:e=>{e.merge(JSON.parse(Z))},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,V,Y(e.all()))},[S]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(Y(e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),e.broadcast(V,Y(e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Z)),e.broadcast(V,Y(e.all()))},GET_AS_PARAM:async(e,t,{key:n})=>{t.reply({key:n,value:e.get("addr",null),xform:R})}},te=()=>h(ee,K);async function ne(){return new Promise(async t=>{te();const n=await ie();if(n.loggedIn)return t(n);const a=function({handshake:e,scope:t,nonce:n,l6n:a}){if(document.getElementById(J))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=J,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(J)&&document.getElementById(J).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());k(K,"SET_CURRENT_USER",{...s,cid:$(s.provider),loggedIn:!0,verified:!0}),t(await ie())})})}function ae(){te(),k(K,"DEL_CURRENT_USER")}async function se(e){te(),await ne();const t=await ie();let n;return e.role.proposer&&(n=(await ce()).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 ie(),n=(await ce(),await q(t.authorizations[0],e));let a=()=>{};n.local&&n.local.length>0&&(a=function(e){if(document.getElementById(M))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=M,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(M)&&document.getElementById(M).remove()}}(n.local[0]));let s=null;try{s=await W(n.authorizationUpdates)}catch(e){throw console.error(e),e}finally{return a(),s}},resolve:null,roles:e.roles}}function oe(e){return async function(){return te(),await ne(),k(K,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})}}function re(e){te();const t=h(async t=>{for(t.send(K,E);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(K,S);e(n.data)}});return()=>k(t,"@EXIT")}function ie(){return te(),k(K,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function ce(){te();const{addr:e}=await ie();if(null==e)throw new Error("No Flow Address for Current User");const{account:t}=await P([m(e)]);return t}const le=()=>({authenticate:ne,unauthenticate:ae,authorization:se,param:oe,subscribe:re,snapshot:ie}),ue=()=>le().authenticate(),de=()=>le().unauthenticate();export{ue as authenticate,le as currentUser,N as decode,G as events,x as resolve,P as send,v as serialize,F as tx,de 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.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}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as n,resolveRefBlockId as r,resolveParams as t,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 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{INIT as v,SUBSCRIBE as p,UPDATED as y,UNSUBSCRIBE as P,SNAPSHOT as g,subscriber as b,spawn as w,snapshoter as E,send as S}from"@onflow/util-actor";import{Identity as j}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T,k,x=function(s){try{return Promise.resolve(e().get("accessNode.api")).then(function(e){return n(s,[r({node:e}),t,o,i,u,c])})}catch(e){return Promise.reject(e)}},A=function(n,r){void 0===n&&(n=[]),void 0===r&&(r={});try{var t=function(e){return r.node=e,Array.isArray(n)&&(n=s(n)),Promise.resolve(x(n)).then(function(e){return a(e,r)})},o=r.node;return Promise.resolve(o?t(o):Promise.resolve(e().get("accessNode.api")).then(t))}catch(e){return Promise.reject(e)}},R=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(x(e)).then(JSON.stringify)},r=function(){if(Array.isArray(e))return Promise.resolve(s(e)).then(function(n){e=n})}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},N=function(n){try{return Promise.resolve(e().where(/^decoder\./)).then(function(e){var r=Object.fromEntries(Object.entries(e).map(function(e){var n=e[0],r=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",r]}));return l(n,r)})}catch(e){return Promise.reject(e)}},O=function(e){try{return Promise.resolve(A([f(e)])).then(N)}catch(e){return Promise.reject(e)}},I=function(e){return e.status>=4},L=function(e){return e.status>=3},U=function(e){return e.status>=2||L(e)},C=function(e){return e.status>=1||U(e)},_=((T={})[v]=function(e){try{return Promise.resolve(O(e.self())).then(function(n){I(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},T[p]=function(e,n){e.subscribe(n.from),e.send(n.from,y,e.all())},T[P]=function(e,n){e.unsubscribe(n.from)},T[g]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},T.POLL=function(e){try{return Promise.resolve(O(e.self())).then(function(n){var r,t;I(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(y,n),e.merge(n)})}catch(e){return Promise.reject(e)}},T),D=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},F=function(e){return w(_,D(e))};function B(e){function n(n){return b(D(e),F,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return E(e,F)},subscribe:n,onceFinalized:r(U),onceExecuted:r(L),onceSealed:r(I)}}function H(){return(H=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function z(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}B.isUnknown=function(e){return e.status>=0||C(e)},B.isPending=C,B.isFinalized=U,B.isExecuted=L,B.isSealed=I,B.isExpired=function(e){return 5===e.status};var G=function(){try{return Promise.resolve(A([d()])).then(N)}catch(e){return Promise.reject(e)}},J=function(n){try{var r=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},M=((k={}).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(G()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(J(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(G()).then(function(r){return e.put("hwm",r),Promise.resolve(A([h(e.self(),n.height,r.height-1)])).then(function(n){return Promise.resolve(N(n)).then(function(n){for(var r,t=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 z(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?z(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);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(J(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)}},k[p]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(J(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},k[P]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},k),X=function(e){return w(M,e)};function q(e){return{subscribe:function(n){return b(e,X,n)}}}var W,K="FCL_IFRAME_CHALLENGE",$="FCL_IFRAME_AUTHZ",V=function(e){void 0===e&&(e={});var n=e.addr,r=e.pid;return null==n||null==r?null:n+"/"+r},Z={"HTTP/POST":"POST","HTTP/GET":"GET"},Q=function(e,n){try{for(var r=new URL(e.endpoint),t=0,o=Object.entries(e.params||{});t<o.length;t++){var i=o[t];r.searchParams.append(i[0],i[1])}return n=n?JSON.stringify(n):void 0,Promise.resolve(fetch(r,{method:Z[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function Y(e,n,r){if(!e.s){if(r instanceof re){if(!r.s)return void(r.o=Y.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Y.bind(null,e,n),Y.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ee=function(){try{return de(),Promise.resolve(ye()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(A([m(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},ne=function(e){try{return de(),Promise.resolve(oe()).then(function(){return Promise.resolve(ye()).then(function(n){function r(){return H({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:t,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(ye()).then(function(n){return Promise.resolve(ee()).then(function(r){return Promise.resolve(Q(n.authorizations[0],e)).then(function(e){var n=function(){};e.local&&e.local.length>0&&(n=function(e){if(!document.getElementById($)){for(var n=new URL(e.endpoint),r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=n.href,i.id=$,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($)&&document.getElementById($).remove()}}}(e.local[0]));var r=null;return function(e,n){try{var r=e()}catch(e){return n()}return r&&r.then?r.then(n,n):n()}(function(){return function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){return Promise.resolve(function e(n){return new Promise(function(r,t){try{return Promise.resolve(Q(n)).then(function(n){"APPROVED"===n.status?r(n.compositeSignature):"DECLINED"===n.status?t({status:n.status,reason:n.reason}):setTimeout(function(){r(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){r=e})},function(e){throw console.error(e),e})},function(){return n(),r})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var t,o=function(){if(e.role.proposer)return Promise.resolve(ee()).then(function(e){var r=e.keys.find(function(e){return e.index===n.keyId});t=r.sequenceNumber})}();return o&&o.then?o.then(r):r()})})}catch(e){return Promise.reject(e)}},re=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{Y(t,1,i(this.v))}catch(e){Y(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Y(t,1,n?n(o):o):r?Y(t,1,r(o)):Y(t,2,o)}catch(e){Y(t,2,e)}},t},e}();function te(e){return e instanceof re&&1&e.s}var oe=function(){try{return Promise.resolve(new Promise(function(n){try{return de(),Promise.resolve(ye()).then(function(r){return r.loggedIn?n(r):Promise.resolve(e().get("challenge.handshake")).then(function(r){return Promise.resolve(e().get("challenge.scope")).then(function(e){var t=function(e){var n=e.handshake,r=e.scope,t=e.nonce,o=e.l6n;if(!document.getElementById(K)){var i=new URL(n);i.searchParams.append("l6n",o),i.searchParams.append("nonce",t),r&&i.searchParams.append("scope",r.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=K,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(K)&&document.getElementById(K).remove()}}}({handshake:r,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var r=e.data;try{if(r.type!==se)return Promise.resolve();t();var o=new URL(r.hks);return o.searchParams.append("code",r.code),Promise.resolve(fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return S(ie,ce,H({},e,{cid:V(e.provider),loggedIn:!0,verified:!0})),Promise.resolve(ye()).then(function(e){n(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ie="CURRENT_USER",ue="CURRENT_USER/UPDATED",ce="SET_CURRENT_USER",se="FCL::CHALLENGE::RESPONSE",ae='{\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}',le=new Set(["verified","identity","scoped","provider"]),fe=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return le.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},he=((W={})[v]=function(e){e.merge(JSON.parse(ae))},W[p]=function(e,n){e.subscribe(n.from),e.send(n.from,ue,fe(e.all()))},W[P]=function(e,n){e.unsubscribe(n.from)},W.SNAPSHOT=function(e,n){try{return n.reply(fe(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},W[ce]=function(e,n,r){try{return e.merge(r),e.broadcast(ue,fe(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},W.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(ae)),e.broadcast(ue,fe(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},W.GET_AS_PARAM=function(e,n,r){var t=r.key;try{return n.reply({key:t,value:e.get("addr",null),xform:j}),Promise.resolve()}catch(e){return Promise.reject(e)}},W),de=function(){return w(he,ie)};function me(){de(),S(ie,"DEL_CURRENT_USER")}function ve(e){return function(){try{return de(),Promise.resolve(oe()).then(function(){return S(ie,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function pe(e){de();var n=w(function(n){try{var r;return n.send(ie,p),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(te(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!te(i)){t=1;break}i=i.s}}var u=new re,c=Y.bind(null,u,2);return(0===t?o.then(a):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,c):a(o):Y(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||te(o)&&!o.v)return void Y(u,1,i);if(o.then)return void o.then(a).then(void 0,c);te(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=r())&&i.then?i.then(s).then(void 0,c):s(i):Y(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(ie,P),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return S(n,"@EXIT")}}function ye(){return de(),S(ie,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Pe=function(){return{authenticate:oe,unauthenticate:me,authorization:ne,param:ve,subscribe:pe,snapshot:ye}},ge=function(){return Pe().authenticate()},be=function(){return Pe().unauthenticate()};export{ge as authenticate,Pe as currentUser,N as decode,q as events,x as resolve,A as send,R as serialize,B as tx,be 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.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()}}); | ||
!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,c=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)}},s=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(c(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)}},a=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)}},f=function(e){try{return Promise.resolve(s([t.getTransactionStatus(e)])).then(a)}catch(e){return Promise.reject(e)}},l=function(e){return e.status>=4},d=function(e){return e.status>=3},h=function(e){return e.status>=2||d(e)},m=function(e){return e.status>=1||h(e)},v=((i={})[r.INIT]=function(e){try{return Promise.resolve(f(e.self())).then(function(n){l(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},i[r.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,r.UPDATED,e.all())},i[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},i[r.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(f(e.self())).then(function(n){var t,o;l(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),o=n,JSON.stringify(t)!==JSON.stringify(o)&&e.broadcast(r.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},i),p=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},y=function(e){return r.spawn(v,p(e))};function P(e){function n(n){return r.subscriber(p(e),y,n)}function t(e){return function(t){void 0===t&&(t={});var r=t.suppress||!1;return new Promise(function(t,o){var i=n(function(n){n.statusCode&&!r?(o(n.errorMessage),i()):e(n)&&(t(n),i())})})}}return{snapshot:function(){return r.snapshoter(e,y)},subscribe:n,onceFinalized:t(h),onceExecuted:t(d),onceSealed:t(l)}}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 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}P.isUnknown=function(e){return e.status>=0||m(e)},P.isPending=m,P.isFinalized=h,P.isExecuted=d,P.isSealed=l,P.isExpired=function(e){return 5===e.status};var j,S=function(){try{return Promise.resolve(s([t.getLatestBlock()])).then(a)}catch(e){return Promise.reject(e)}},E=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)}},w=((u={}).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(S()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(E(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(S()).then(function(r){return e.put("hwm",r),Promise.resolve(s([t.getEvents(e.self(),n.height,r.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(E(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)}},u[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(E(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)}},u[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},u),O=function(e){return r.spawn(w,e)},T="FCL_IFRAME_CHALLENGE",k="FCL_IFRAME_AUTHZ",I=function(e){void 0===e&&(e={});var n=e.addr,t=e.pid;return null==n||null==t?null:n+"/"+t},R={"HTTP/POST":"POST","HTTP/GET":"GET"},A=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:R[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function U(e,n,t){if(!e.s){if(t instanceof B){if(!t.s)return void(t.o=U.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(U.bind(null,e,n),U.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var N=function(){try{return M(),Promise.resolve(V()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(s([t.getAccount(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},x=function(e){try{return M(),Promise.resolve(L()).then(function(){return Promise.resolve(V()).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(V()).then(function(n){return Promise.resolve(N()).then(function(t){return Promise.resolve(A(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(A(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)}},B=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{U(r,1,i(this.v))}catch(e){U(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?U(r,1,n?n(o):o):t?U(r,1,t(o)):U(r,2,o)}catch(e){U(r,2,e)}},r},e}();function C(e){return e instanceof B&&1&e.s}var L=function(){try{return Promise.resolve(new Promise(function(e){try{return M(),Promise.resolve(V()).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(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:t,scope:n,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var t=n.data;try{if(t.type!==F)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,g({},n,{cid:I(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(V()).then(function(n){e(n)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},_="CURRENT_USER",D="CURRENT_USER/UPDATED",z="SET_CURRENT_USER",F="FCL::CHALLENGE::RESPONSE",H='{\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}',G=new Set(["verified","identity","scoped","provider"]),q=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return G.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=((j={})[r.INIT]=function(e){e.merge(JSON.parse(H))},j[r.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,D,q(e.all()))},j[r.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},j.SNAPSHOT=function(e,n){try{return n.reply(q(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},j[z]=function(e,n,t){try{return e.merge(t),e.broadcast(D,q(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},j.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(H)),e.broadcast(D,q(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},j.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)}},j),M=function(){return r.spawn(J,_)};function X(){M(),r.send(_,"DEL_CURRENT_USER")}function W(e){return function(){try{return M(),Promise.resolve(L()).then(function(){return r.send(_,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function K(e){M();var n=r.spawn(function(n){try{var t;return n.send(_,r.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(C(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!C(i)){r=1;break}i=i.s}}var u=new B,c=U.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):U(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||C(o)&&!o.v)return void U(u,1,i);if(o.then)return void o.then(a).then(void 0,c);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):U(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(_,r.UNSUBSCRIBE),void(t=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return r.send(n,"@EXIT")}}function V(){return M(),r.send(_,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var $=function(){return{authenticate:L,unauthenticate:X,authorization:x,param:W,subscribe:K,snapshot:V}};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 $().authenticate()},e.currentUser=$,e.decode=a,e.events=function(e){return{subscribe:function(n){return r.subscriber(e,O,n)}}},e.resolve=c,e.send=s,e.serialize=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(c(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=P,e.unauthenticate=function(){return $().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.50", | ||
"version": "0.0.51", | ||
"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
201090
215