@onflow/fcl
Advanced tools
Comparing version 0.0.54 to 0.0.55
@@ -5,2 +5,6 @@ ### Unreleased | ||
### 0.0.55 -- 2020-09-04 | ||
- 2020-09-04 -- Wallet Provider Services | ||
### 0.0.54 -- 2020-09-03 | ||
@@ -7,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
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},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),h=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},p=function(e){return t.spawn(m,h(e))};function v(e){function r(r){return t.subscriber(h(e),p,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,p)},subscribe:r,onceFinalized:n(d),onceExecuted:n(f),onceSealed:n(l)}}function y(){return(y=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 P(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}v.isUnknown=function(e){return e.status>=0},v.isPending=function(e){return e.status>=1},v.isFinalized=d,v.isExecuted=f,v.isSealed=l,v.isExpired=function(e){return 5===e.status};var b=function(){try{return Promise.resolve(c([r.getLatestBlock()])).then(s)}catch(e){return Promise.reject(e)}},g=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)}},j=((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(b()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(g(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(b()).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 P(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)?P(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(g(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(g(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),S=function(e){return t.spawn(j,e)};function x(e){return null==e?null:e.replace(/^0x/,"")}var E,O="FCL_IFRAME_CHALLENGE",w="FCL_IFRAME_AUTHZ",I=function(e){void 0===e&&(e={});var r=e.addr,t=e.pid;return null==r||null==t?null:r+"/"+t},R={"HTTP/POST":"POST","HTTP/GET":"GET"},T=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:R[e.method],headers:{"Content-Type":"application/json"},body:r}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function N(e,r,t){if(!e.s){if(t instanceof U){if(!t.s)return void(t.o=N.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(N.bind(null,e,r),N.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var k=function(){try{return M(),Promise.resolve($()).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)}},B=function(e){try{return M(),Promise.resolve(C()).then(function(){return Promise.resolve($()).then(function(r){function t(){return y({},e,{addr:r.addr,keyId:r.keyId,sequenceNum:n,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve($()).then(function(r){return Promise.resolve(k()).then(function(t){return Promise.resolve(T(r.authorizations[0],e)).then(function(e){var r=function(){};e.local&&e.local.length>0&&(r=function(e){if(!document.getElementById(w)){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=w,i.allow="usb",i.style.position="fixed",i.style.top="0px",i.style.right="0px",i.style.left="0px",i.style.bottom="0px",i.style.height="100vh",i.style.width="100vw",i.style.display="block",i.style.background="rgba(0,0,0,0.25)",i.frameBorder="0",i.style.boxSizing="border-box",i.style.border="1px solid white",document.body.append(i),function(){document.getElementById(w)&&document.getElementById(w).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(T(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)}},U=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{N(n,1,i(this.v))}catch(e){N(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?N(n,1,r?r(o):o):t?N(n,1,t(o)):N(n,2,o)}catch(e){N(n,2,e)}},n},e}();function A(e){return e instanceof U&&1&e.s}var C=function(){try{return Promise.resolve(new Promise(function(r){try{return M(),Promise.resolve($()).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(O)){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=O,u.allow="usb",u.style.position="fixed",u.style.top="0px",u.style.right="0px",u.style.left="0px",u.style.bottom="0px",u.style.height="100vh",u.style.width="100vw",u.style.display="block",u.style.background="rgba(0,0,0,0.25)",u.frameBorder="0",u.style.boxSizing="border-box",u.style.border="1px solid white",document.body.append(u),function(){document.getElementById(O)&&document.getElementById(O).remove()}}}({handshake:n,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var n=e.data;try{if(n.type!==D)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,z,y({},e,{cid:I(e.provider),loggedIn:!0,verified:!0})),Promise.resolve($()).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",z="SET_CURRENT_USER",D="FCL::CHALLENGE::RESPONSE",F='{\n "VERSION": "0.1.1",\n "addr":null,\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.error(('\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},J=function(e){try{return localStorage.setItem(L,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},q=((E={})[t.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(F),r=JSON.parse(localStorage.getItem(L));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(L),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(t){r.call(e,t)})}catch(e){return Promise.reject(e)}},E[t.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,_,G(e.all()))},E[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},E.SNAPSHOT=function(e,r){try{return r.reply(G(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},E[z]=function(e,r,t){try{return e.merge(t),J(e.all()),e.broadcast(_,G(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},E.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(F)),J(e.all()),e.broadcast(_,G(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},E.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)}},E),M=function(){return t.spawn(q,L)};function V(){M(),t.send(L,"DEL_CURRENT_USER")}function K(e){return function(){try{return M(),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 X(e){M();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(A(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!A(i)){n=1;break}i=i.s}}var u=new U,c=N.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):N(u,1,i)})).then(void 0,c),u;function s(r){i=r;do{if(!(o=e())||A(o)&&!o.v)return void N(u,1,i);if(o.then)return void o.then(a).then(void 0,c);A(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):N(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 $(){return M(),t.send(L,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var W=function(){return{authenticate:C,unauthenticate:V,authorization:B,param:K,subscribe:X,snapshot:$}};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,"getBlockByHeight",{enumerable:!0,get:function(){return r.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return r.getBlockById}}),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.VERSION="0.0.51",exports.authenticate=function(){return W().authenticate()},exports.currentUser=W,exports.decode=s,exports.events=function(e){return{subscribe:function(r){return t.subscriber(e,S,r)}}},exports.resolve=u,exports.sansPrefix=x,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=v,exports.unauthenticate=function(){return W().unauthenticate()},exports.withPrefix=function(e){return null==e?null:"0x"+x(e)}; | ||
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)}},s=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)}},c=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(s([r.getTransactionStatus(e)])).then(c)}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},h=((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),m=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},p=function(e){return t.spawn(h,m(e))};function v(e){function r(r){return t.subscriber(m(e),p,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,p)},subscribe:r,onceFinalized:n(d),onceExecuted:n(f),onceSealed:n(l)}}function y(){return(y=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 P(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}function g(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 P(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)?P(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)}v.isUnknown=function(e){return e.status>=0},v.isPending=function(e){return e.status>=1},v.isFinalized=d,v.isExecuted=f,v.isSealed=l,v.isExpired=function(e){return 5===e.status};var b=function(){try{return Promise.resolve(s([r.getLatestBlock()])).then(c)}catch(e){return Promise.reject(e)}},E=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(b()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(E(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(b()).then(function(n){return e.put("hwm",n),Promise.resolve(s([r.getEvents(e.self(),t.height,n.height-1)])).then(function(r){return Promise.resolve(c(r)).then(function(r){for(var t,n=g(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(E(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(E(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),j=function(e){return t.spawn(S,e)};function x(e){return null==e?null:e.replace(/^0x/,"")}var w="FCL_IFRAME_CHALLENGE";function O(e,r){void 0===r&&(r=!0);var t=new URL(e.endpoint);if(r)for(var n=0,o=Object.entries(e.params||{});n<o.length;n++){var i=o[n];t.searchParams.append(i[0],i[1])}return t}var I="FCL_IFRAME_AUTHZ";function T(e){if(!document.getElementById(I)){var r=O(e),t=document.createElement("iframe");return t.src=r.href,t.id=I,t.allow="usb",t.style.position="fixed",t.style.top="0px",t.style.right="0px",t.style.left="0px",t.style.bottom="0px",t.style.height="100vh",t.style.width="100vw",t.style.display="block",t.style.background="rgba(0,0,0,0.25)",t.frameBorder="0",t.style.boxSizing="border-box",t.style.border="1px solid white",document.body.append(t),[t,function(){document.getElementById(I)&&document.getElementById(I).remove()}]}}var R,A={"HTTP/GET":"GET","HTTP/POST":"POST"},k="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",N=k.length,B={"HTTP/POST":function(e,r){try{var t=function(){},n=null;return Promise.resolve(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(fetch(O(e),{method:"POST",headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0}).then(function(e){return e.json()})).then(function(e){if(e.local&&e.local.length>0){var r=T(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(O(r),{method:A[r.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).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){n=e})})},function(e){throw t(),console.error(e),e})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){var o=function(){for(var e="",r=32;r--;)e+=k[Math.random()*N|0];return e}();T(e)[0].contentWindow.postMessage({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]},"*"),window.addListener("message",function(e){var r=e.data;try{if("object"!=typeof r)return Promise.resolve();if("2.0"!==r.jsonrpc)return Promise.resolve();if(r.id!==o)return Promise.resolve();var i=r.result;return"APPROVED"===i.status?t(i.compositeSignature):n("DECLINED"===i.status?{status:i.status,reason:i.reason}:{status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}),Promise.resolve()}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}}},U=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},C=function(e,r){return"Missing "+U(e,r)+" in Composite Signature."},L=function(e,r){return U(e,r)+" in Composit Signature did not match the requested "+e+"."};function D(e,r,t){if(!e.s){if(t instanceof _){if(!t.s)return void(t.o=D.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(D.bind(null,e,r),D.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var z=function(e){try{return X(),Promise.resolve(F()).then(function(t){function n(){return y({},e,{addr:u.addr,keyId:u.keyId,sequenceNum:i,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(function(e,r){try{return Promise.resolve(B[e.method](e,r))}catch(e){return Promise.reject(e)}}(u,e)).then(function(e){return function(e,r){try{if(null==e.addr)throw new Error(C("addr","Address"));if(null==e.keyId)throw new Error(C("keyId"));if(null==e.sig)throw new Error(C("sig","Signature"));if(e.addr!==r.addr)throw new Error(L("addr","Address"));if(e.keyId!==r.keyId)throw new Error(L("keyId"))}catch(t){throw console.error(t,"\n\n",{"Composite Signature":e,"Authz Service":r}),new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+t.message)}}(e,u),e})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var o,i,u=(void 0===(o=t.services)&&(o=[]),o.find(function(e){return"authz"===e.type})),c=function(){if(e.role.proposer)return Promise.resolve(function(){try{return X(),Promise.resolve(Y()).then(function(e){var t=e.addr;if(null==t)throw new Error("No Flow Address for Current User");return Promise.resolve(s([r.getAccount(t)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}}()).then(function(e){var r=e.keys.find(function(e){return e.index===u.keyId});i=r.sequenceNumber})}();return c&&c.then?c.then(n):n()})}catch(e){return Promise.reject(e)}},_=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{D(n,1,i(this.v))}catch(e){D(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?D(n,1,r?r(o):o):t?D(n,1,t(o)):D(n,2,o)}catch(e){D(n,2,e)}},n},e}();function H(e){return e instanceof _&&1&e.s}var F=function(){try{return Promise.resolve(new Promise(function(r){try{return X(),Promise.resolve(Y()).then(function(n){return n.loggedIn?r(n):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var n=function(e){var r=e.handshake,t=e.l6n;if(!document.getElementById(w)){var n=new URL(r);n.searchParams.append("l6n",t);var o=document.createElement("iframe");return o.src=n.href,o.id=w,o.allow="usb",o.style.position="fixed",o.style.top="0px",o.style.right="0px",o.style.left="0px",o.style.bottom="0px",o.style.height="100vh",o.style.width="100vw",o.style.display="block",o.style.background="rgba(0,0,0,0.25)",o.frameBorder="0",o.style.boxSizing="border-box",o.style.border="1px solid white",document.body.append(o),function(){document.getElementById(w)&&document.getElementById(w).remove()}}}({handshake:e,l6n:window.location.origin});window.addEventListener("message",function(e){var o=e.data;try{if(o.type!==J)return Promise.resolve();n();var i="did:fcl:"+o.addr,u=o.addr,s=o.services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",r),Promise.resolve(fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var t,n=g(e.authorizations);!(t=n()).done;)r.push(y({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(y({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(o.hks,o.code)).then(function(e){var n,o,c={addr:u,cid:i,loggedIn:!0,services:(n=s,o=e,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o))};return t.send(M,q,c),Promise.resolve(Y()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},M="CURRENT_USER",V="CURRENT_USER/UPDATED",q="SET_CURRENT_USER",J="FCL::CHALLENGE::RESPONSE",G='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',K=function(e){try{return localStorage.setItem(M,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},W=((R={})[t.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(G),r=JSON.parse(localStorage.getItem(M));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(M),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(t){r.call(e,t)})}catch(e){return Promise.reject(e)}},R[t.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,V,e.all())},R[t.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},R.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},R[q]=function(e,r,t){try{return e.merge(t),K(e.all()),e.broadcast(V,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},R.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(G)),K(e.all()),e.broadcast(V,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},R.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)}},R),X=function(){return t.spawn(W,M)};function Z(){X(),t.send(M,"DEL_CURRENT_USER")}function $(e){return function(){try{return X(),Promise.resolve(F()).then(function(){return t.send(M,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Q(e){X();var r=t.spawn(function(r){try{var n;return r.send(M,t.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(H(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!H(i)){n=1;break}i=i.s}}var u=new _,s=D.bind(null,u,2);return(0===n?o.then(a):1===n?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,s):a(o):D(u,1,i)})).then(void 0,s),u;function c(r){i=r;do{if(!(o=e())||H(o)&&!o.v)return void D(u,1,i);if(o.then)return void o.then(a).then(void 0,s);H(i=t())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,s)}function a(e){e?(i=t())&&i.then?i.then(c).then(void 0,s):c(i):D(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if("@EXIT"===o.tag)return r.send(M,t.UNSUBSCRIBE),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(r,"@EXIT")}}function Y(){return X(),t.send(M,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ee=function(){return{authenticate:F,unauthenticate:Z,authorization:z,param:$,subscribe:Q,snapshot:Y}};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,"getBlockByHeight",{enumerable:!0,get:function(){return r.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return r.getBlockById}}),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.VERSION="0.0.51",exports.authenticate=function(){return ee().authenticate()},exports.currentUser=ee,exports.decode=c,exports.events=function(e){return{subscribe:function(r){return t.subscriber(e,j,r)}}},exports.resolve=u,exports.sansPrefix=x,exports.send=s,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=v,exports.unauthenticate=function(){return ee().unauthenticate()},exports.withPrefix=function(e){return null==e?null:"0x"+x(e)}; | ||
//# 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 o,resolveAccounts as s,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 y}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getBlockByHeight,getBlockById,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,pipe,proposer,ref,script,transaction,why}from"@onflow/sdk";import{subscriber as m,spawn as h,snapshoter as w,INIT as g,SUBSCRIBE as b,UPDATED as E,UNSUBSCRIBE as S,SNAPSHOT as T,send as R}from"@onflow/util-actor";import{Identity as N}from"@onflow/types";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const k=async c=>t(c,[n({node:await e().get("accessNode.api")}),a,o,s,r,i]),x=async(t=[],n={})=>(n.node=n.node||await e().get("accessNode.api"),Array.isArray(t)&&(t=c(t)),l(await k(t),n)),P=async(e=[])=>(Array.isArray(e)&&(e=await c(e)),JSON.stringify(await k(e))),I=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)},v=async e=>{const t=await x([d(e)]);return I(t)},A=e=>e.status>=4,O=e=>e.status>=3,U=e=>e.status>=2,L={[g]:async e=>{const t=await v(e.self());A(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[b]:(e,t)=>{e.subscribe(t.from),e.send(t.from,E,e.all())},[S]:(e,t)=>{e.unsubscribe(t.from)},[T]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await v(e.self());var n,a;A(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(E,t),e.merge(t)}},C=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},_=e=>h(L,C(e));function B(e){function t(t){return m(C(e),_,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,o)=>{const s=t(t=>{t.statusCode&&!a?(o(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return w(e,_)},subscribe:t,onceFinalized:n(U),onceExecuted:n(O),onceSealed:n(A)}}B.isUnknown=e=>e.status>=0,B.isPending=e=>e.status>=1,B.isFinalized=U,B.isExecuted=O,B.isSealed=A,B.isExpired=e=>5===e.status;const D=async()=>I(await x([p()])),F=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),j={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await D()),e.put("tick",await F(e));else{let n=await D();e.put("hwm",n);const a=await x([f(e.self(),t.height,n.height-1)]),o=await I(a);for(let t of o)e.broadcast("UPDATED",t.data);e.put("tick",await F(e))}},[b]:async(e,t)=>{e.hasSubs()||e.put("tick",await F(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(j,e);function H(e){return{subscribe:t=>m(e,z,t)}}function G(e){return null==e?null:e.replace(/^0x/,"")}function J(e){return null==e?null:"0x"+G(e)}const M="FCL_IFRAME_CHALLENGE",$="FCL_IFRAME_AUTHZ",V=(e={})=>{const t=e.addr,n=e.pid;return null==t||null==n?null:`${t}/${n}`},q={"HTTP/POST":"POST","HTTP/GET":"GET"},K=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:q[e.method],headers:{"Content-Type":"application/json"},body:t}).then(e=>e.json())},X=e=>new Promise(async(t,n)=>{const a=await K(e);"APPROVED"===a.status?t(a.compositeSignature):"DECLINED"===a.status?n({status:a.status,reason:a.reason}):setTimeout(()=>{t(X(a.authorizationUpdates))},500)}),W="CURRENT_USER",Z="CURRENT_USER/UPDATED",Q='{\n "VERSION": "0.1.1",\n "addr":null,\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}',Y=new Set(["verified","identity","scoped","provider"]),ee=e=>("undefined"!=typeof Proxy&&(e=new Proxy(e,{get:(e,t)=>(Y.has(t)&&(e=>{console.error(`\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),te=async e=>(localStorage.setItem(W,JSON.stringify(e)),e),ne={[g]:async e=>{e.merge(await(async()=>{const e=JSON.parse(Q),t=JSON.parse(localStorage.getItem(W));return null!=t&&e.VERSION!==t.VERSION?(localStorage.removeItem(W),e):t||e})())},[b]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Z,ee(e.all()))},[S]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(ee(e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),te(e.all()),e.broadcast(Z,ee(e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Q)),te(e.all()),e.broadcast(Z,ee(e.all()))},GET_AS_PARAM:async(e,t,{key:n})=>{t.reply({key:n,value:e.get("addr",null),xform:N})}},ae=()=>h(ne,W);async function oe(){return new Promise(async t=>{ae();const n=await le();if(n.loggedIn)return t(n);const a=function({handshake:e,scope:t,nonce:n,l6n:a}){if(document.getElementById(M))return;var o=new URL(e);o.searchParams.append("l6n",a),o.searchParams.append("nonce",n),t&&o.searchParams.append("scope",t.split(" ").join("+"));const s=document.createElement("iframe");return s.src=o.href,s.id=M,s.allow="usb",s.style.position="fixed",s.style.top="0px",s.style.right="0px",s.style.left="0px",s.style.bottom="0px",s.style.height="100vh",s.style.width="100vw",s.style.display="block",s.style.background="rgba(0,0,0,0.25)",s.frameBorder="0",s.style.boxSizing="border-box",s.style.border="1px solid white",document.body.append(s),()=>{document.getElementById(M)&&document.getElementById(M).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 o=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());R(W,"SET_CURRENT_USER",{...o,cid:V(o.provider),loggedIn:!0,verified:!0}),t(await le())})})}function se(){ae(),R(W,"DEL_CURRENT_USER")}async function re(e){ae(),await oe();const t=await le();let n;return e.role.proposer&&(n=(await ue()).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 le(),n=(await ue(),await K(t.authorizations[0],e));let a=()=>{};n.local&&n.local.length>0&&(a=function(e){if(document.getElementById($))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=$,n.allow="usb",n.style.position="fixed",n.style.top="0px",n.style.right="0px",n.style.left="0px",n.style.bottom="0px",n.style.height="100vh",n.style.width="100vw",n.style.display="block",n.style.background="rgba(0,0,0,0.25)",n.frameBorder="0",n.style.boxSizing="border-box",n.style.border="1px solid white",document.body.append(n),()=>{document.getElementById($)&&document.getElementById($).remove()}}(n.local[0]));let o=null;try{o=await X(n.authorizationUpdates)}catch(e){throw console.error(e),e}finally{return a(),o}},resolve:null,roles:e.roles}}function ie(e){return async function(){return ae(),await oe(),R(W,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})}}function ce(e){ae();const t=h(async t=>{for(t.send(W,b);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(W,S);e(n.data)}});return()=>R(t,"@EXIT")}function le(){return ae(),R(W,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function ue(){ae();const{addr:e}=await le();if(null==e)throw new Error("No Flow Address for Current User");const{account:t}=await x([y(e)]);return t}const de=()=>({authenticate:oe,unauthenticate:se,authorization:re,param:ie,subscribe:ce,snapshot:le}),pe=()=>de().authenticate(),fe=()=>de().unauthenticate(),ye="0.0.51";export{ye as VERSION,pe as authenticate,de as currentUser,I as decode,H as events,k as resolve,G as sansPrefix,x as send,P as serialize,B as tx,fe as unauthenticate,J as withPrefix}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,resolveRefBlockId as n,resolveParams as a,resolveArguments as r,resolveAccounts as s,resolveSignatures as o,resolveValidators as i,build as c,send as u,decodeResponse as l,getTransactionStatus as d,getLatestBlock as f,getEvents as y,getAccount as p}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getBlockByHeight,getBlockById,getEvents,getLatestBlock,getTransactionStatus,isBad,isOk,limit,param,params,payer,ping,pipe,proposer,ref,script,transaction,why}from"@onflow/sdk";import{subscriber as h,spawn as m,snapshoter as w,INIT as g,SUBSCRIBE as E,UPDATED as S,UNSUBSCRIBE as b,SNAPSHOT as T,send as I}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 P=async c=>t(c,[n({node:await e().get("accessNode.api")}),a,r,s,o,i]),k=async(t=[],n={})=>(n.node=n.node||await e().get("accessNode.api"),Array.isArray(t)&&(t=c(t)),u(await P(t),n)),A=async(e=[])=>(Array.isArray(e)&&(e=await c(e)),JSON.stringify(await P(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 l(t,a)},v=async e=>{const t=await k([d(e)]);return N(t)},x=e=>e.status>=4,O=e=>e.status>=3,C=e=>e.status>=2,L={[g]:async e=>{const t=await v(e.self());x(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,S,e.all())},[b]:(e,t)=>{e.unsubscribe(t.from)},[T]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await v(e.self());var n,a;x(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(S,t),e.merge(t)}},U=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},D=e=>m(L,U(e));function _(e){function t(t){return h(U(e),D,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,r)=>{const s=t(t=>{t.statusCode&&!a?(r(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return w(e,D)},subscribe:t,onceFinalized:n(C),onceExecuted:n(O),onceSealed:n(x)}}_.isUnknown=e=>e.status>=0,_.isPending=e=>e.status>=1,_.isFinalized=C,_.isExecuted=O,_.isSealed=x,_.isExpired=e=>5===e.status;const z=async()=>N(await k([f()])),B=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),j={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await z()),e.put("tick",await B(e));else{let n=await z();e.put("hwm",n);const a=await k([y(e.self(),t.height,n.height-1)]),r=await N(a);for(let t of r)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)},[b]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},F=e=>m(j,e);function H(e){return{subscribe:t=>h(e,F,t)}}function M(e){return null==e?null:e.replace(/^0x/,"")}function J(e){return null==e?null:"0x"+M(e)}const G="FCL_IFRAME_CHALLENGE";async function V(e,t){if(null==e||null==t)return[];const n=new URL(e);n.searchParams.append("code",t);const a=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(a))return a;const r=[];if(Array.isArray(a.authorizations))for(let e of a.authorizations)r.push({type:"authz",keyId:a.keyId,...e});return null!=a.provider&&r.push({type:"authn",id:"wallet-provider#authn",...a.provider}),r}function $(e=[],t=[]){return[...e,...t]}function q(e,t=!0){const n=new URL(e.endpoint);if(t)for(let[t,a]of Object.entries(e.params||{}))n.searchParams.append(t,a);return n}const K="FCL_IFRAME_AUTHZ";function W(e){if(document.getElementById(K))return;var t=q(e);const n=document.createElement("iframe");return n.src=t.href,n.id=K,n.allow="usb",n.style.position="fixed",n.style.top="0px",n.style.right="0px",n.style.left="0px",n.style.bottom="0px",n.style.height="100vh",n.style.width="100vw",n.style.display="block",n.style.background="rgba(0,0,0,0.25)",n.frameBorder="0",n.style.boxSizing="border-box",n.style.border="1px solid white",document.body.append(n),[n,()=>{document.getElementById(K)&&document.getElementById(K).remove()}]}const X={"HTTP/GET":"GET","HTTP/POST":"POST"},Z=e=>new Promise(async(t,n)=>{const a=await fetch(q(e),{method:X[e.method],headers:{"Content-Type":"application/json"}}).then(e=>e.json());"APPROVED"===a.status?t(a.compositeSignature):"DECLINED"===a.status?n({status:a.status,reason:a.reason}):setTimeout(()=>{t(Z(a.authorizationUpdates))},500)});var Q="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",Y=Q.length;const ee={"HTTP/POST":async function(e,t){var n=()=>{},a=null;try{const r=await fetch(q(e),{method:"POST",headers:{"Content-Type":"application/json"},body:t?JSON.stringify(t):void 0}).then(e=>e.json());if(r.local&&r.local.length>0){const[e,t]=W(r.local[0]);n=t}a=await Z(r.authorizationUpdates)}catch(e){throw n(),console.error(e),e}finally{return n(),a}},"IFRAME/RPC":async function(e,t){return new Promise((n,a)=>{const r=function(){for(var e="",t=32;t--;)e+=Q[Math.random()*Y|0];return e}(),[s,o]=W(e);s.contentWindow.postMessage({jsonrpc:"2.0",id:r,method:"fcl:sign",params:[t,e.params]},"*"),window.addListener("message",async({data:e})=>{if("object"!=typeof e)return;if("2.0"!==e.jsonrpc)return;if(e.id!==r)return;const t=e.result;"APPROVED"===t.status?n(t.compositeSignature):a("DECLINED"===t.status?{status:t.status,reason:t.reason}:{status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})})})}},te=(e,t)=>null==t?`'${e}'`:`'${e}' (${t})`,ne=(e,t)=>`Missing ${te(e,t)} in Composite Signature.`,ae=(e,t)=>`${te(e,t)} in Composit Signature did not match the requested ${e}.`,re="CURRENT_USER",se="CURRENT_USER/UPDATED",oe='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',ie=async e=>(localStorage.setItem(re,JSON.stringify(e)),e),ce={[g]:async e=>{e.merge(await(async()=>{const e=JSON.parse(oe),t=JSON.parse(localStorage.getItem(re));return null!=t&&e.VERSION!==t.VERSION?(localStorage.removeItem(re),e):t||e})())},[E]:(e,t)=>{e.subscribe(t.from),e.send(t.from,se,e.all())},[b]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(e.all())},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),ie(e.all()),e.broadcast(se,e.all())},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(oe)),ie(e.all()),e.broadcast(se,e.all())},GET_AS_PARAM:async(e,t,{key:n})=>{t.reply({key:n,value:e.get("addr",null),xform:R})}},ue=()=>m(ce,re);async function le(){return new Promise(async t=>{ue();const n=await he();if(n.loggedIn)return t(n);const a=function({handshake:e,l6n:t}){if(document.getElementById(G))return;var n=new URL(e);n.searchParams.append("l6n",t);const a=document.createElement("iframe");return a.src=n.href,a.id=G,a.allow="usb",a.style.position="fixed",a.style.top="0px",a.style.right="0px",a.style.left="0px",a.style.bottom="0px",a.style.height="100vh",a.style.width="100vw",a.style.display="block",a.style.background="rgba(0,0,0,0.25)",a.frameBorder="0",a.style.boxSizing="border-box",a.style.border="1px solid white",document.body.append(a),()=>{document.getElementById(G)&&document.getElementById(G).remove()}}({handshake:await e().get("challenge.handshake"),l6n:window.location.origin});window.addEventListener("message",async({data:e})=>{if("FCL::CHALLENGE::RESPONSE"!==e.type)return;a();const n={addr:e.addr,cid:"did:fcl:"+e.addr,loggedIn:!0,services:$(e.services||[],await V(e.hks,e.code))};I(re,"SET_CURRENT_USER",n),t(await he())})})}function de(){ue(),I(re,"DEL_CURRENT_USER")}async function fe(e){ue();const t=function(e=[],t){return e.find(e=>e.type===t)}((await le()).services,"authz");let n;return e.role.proposer&&(n=(await async function(){ue();const{addr:e}=await he();if(null==e)throw new Error("No Flow Address for Current User");const{account:t}=await k([p(e)]);return t}()).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 n=await async function(e,t){return ee[e.method](e,t)}(t,e);return function(e,t){try{if(null==e.addr)throw new Error(ne("addr","Address"));if(null==e.keyId)throw new Error(ne("keyId"));if(null==e.sig)throw new Error(ne("sig","Signature"));if(e.addr!==t.addr)throw new Error(ae("addr","Address"));if(e.keyId!==t.keyId)throw new Error(ae("keyId"))}catch(n){throw console.error(n,"\n\n",{"Composite Signature":e,"Authz Service":t}),new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+n.message)}}(n,t),n},resolve:null,roles:e.roles}}function ye(e){return async function(){return ue(),await le(),I(re,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})}}function pe(e){ue();const t=m(async t=>{for(t.send(re,E);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(re,b);e(n.data)}});return()=>I(t,"@EXIT")}function he(){return ue(),I(re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const me=()=>({authenticate:le,unauthenticate:de,authorization:fe,param:ye,subscribe:pe,snapshot:he}),we=()=>me().authenticate(),ge=()=>me().unauthenticate(),Ee="0.0.51";export{Ee as VERSION,we as authenticate,me as currentUser,N as decode,H as events,P as resolve,M as sansPrefix,k as send,A as serialize,_ as tx,ge as unauthenticate,J as withPrefix}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as r,resolveRefBlockId as n,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,getBlockByHeight,getBlockById,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 E,snapshoter as w,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 r(s,[n({node:e}),t,o,i,u,c])})}catch(e){return Promise.reject(e)}},A=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{var t=function(e){return n.node=e,Array.isArray(r)&&(r=s(r)),Promise.resolve(x(r)).then(function(e){return a(e,n)})},o=n.node;return Promise.resolve(o?t(o):Promise.resolve(e().get("accessNode.api")).then(t))}catch(e){return Promise.reject(e)}},I=function(e){void 0===e&&(e=[]);try{var r=function(){return Promise.resolve(x(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(s(e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},N=function(r){try{return Promise.resolve(e().where(/^decoder\./)).then(function(e){var n=Object.fromEntries(Object.entries(e).map(function(e){var r=e[0],n=e[1];return[r="/"+r.replace(/^decoder\./,"")+"$/",n]}));return l(r,n)})}catch(e){return Promise.reject(e)}},R=function(e){try{return Promise.resolve(A([f(e)])).then(N)}catch(e){return Promise.reject(e)}},O=function(e){return e.status>=4},L=function(e){return e.status>=3},U=function(e){return e.status>=2},C=((T={})[v]=function(e){try{return Promise.resolve(R(e.self())).then(function(r){O(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},T[p]=function(e,r){e.subscribe(r.from),e.send(r.from,y,e.all())},T[P]=function(e,r){e.unsubscribe(r.from)},T[g]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},T.POLL=function(e){try{return Promise.resolve(R(e.self())).then(function(r){var n,t;O(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(y,r),e.merge(r)})}catch(e){return Promise.reject(e)}},T),_=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},B=function(e){return E(C,_(e))};function D(e){function r(r){return b(_(e),B,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return w(e,B)},subscribe:r,onceFinalized:n(U),onceExecuted:n(L),onceSealed:n(O)}}function F(){return(F=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function z(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}D.isUnknown=function(e){return e.status>=0},D.isPending=function(e){return e.status>=1},D.isFinalized=U,D.isExecuted=L,D.isSealed=O,D.isExpired=function(e){return 5===e.status};var H=function(){try{return Promise.resolve(A([d()])).then(N)}catch(e){return Promise.reject(e)}},G=function(r){try{var n=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},J=((k={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(H()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(G(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(H()).then(function(n){return e.put("hwm",n),Promise.resolve(A([h(e.self(),r.height,n.height-1)])).then(function(r){return Promise.resolve(N(r)).then(function(r){for(var n,t=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 z(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?z(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);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(G(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)}},k[p]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(G(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},k[P]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},k),M=function(e){return E(J,e)};function V(e){return{subscribe:function(r){return b(e,M,r)}}}function q(e){return null==e?null:e.replace(/^0x/,"")}function K(e){return null==e?null:"0x"+q(e)}var X,$="FCL_IFRAME_CHALLENGE",W="FCL_IFRAME_AUTHZ",Z=function(e){void 0===e&&(e={});var r=e.addr,n=e.pid;return null==r||null==n?null:r+"/"+n},Q={"HTTP/POST":"POST","HTTP/GET":"GET"},Y=function(e,r){try{for(var n=new URL(e.endpoint),t=0,o=Object.entries(e.params||{});t<o.length;t++){var i=o[t];n.searchParams.append(i[0],i[1])}return r=r?JSON.stringify(r):void 0,Promise.resolve(fetch(n,{method:Q[e.method],headers:{"Content-Type":"application/json"},body:r}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function ee(e,r,n){if(!e.s){if(n instanceof te){if(!n.s)return void(n.o=ee.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(ee.bind(null,e,r),ee.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var re=function(){try{return ve(),Promise.resolve(ge()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(A([m(r)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},ne=function(e){try{return ve(),Promise.resolve(ie()).then(function(){return Promise.resolve(ge()).then(function(r){function n(){return F({},e,{addr:r.addr,keyId:r.keyId,sequenceNum:t,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(ge()).then(function(r){return Promise.resolve(re()).then(function(n){return Promise.resolve(Y(r.authorizations[0],e)).then(function(e){var r=function(){};e.local&&e.local.length>0&&(r=function(e){if(!document.getElementById(W)){for(var r=new URL(e.endpoint),n=0,t=Object.entries(e.params||{});n<t.length;n++){var o=t[n];r.searchParams.append(o[0],o[1])}var i=document.createElement("iframe");return i.src=r.href,i.id=W,i.allow="usb",i.style.position="fixed",i.style.top="0px",i.style.right="0px",i.style.left="0px",i.style.bottom="0px",i.style.height="100vh",i.style.width="100vw",i.style.display="block",i.style.background="rgba(0,0,0,0.25)",i.frameBorder="0",i.style.boxSizing="border-box",i.style.border="1px solid white",document.body.append(i),function(){document.getElementById(W)&&document.getElementById(W).remove()}}}(e.local[0]));var n=null;return function(e,r){try{var n=e()}catch(e){return r()}return n&&n.then?n.then(r,r):r()}(function(){return function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){return Promise.resolve(function e(r){return new Promise(function(n,t){try{return Promise.resolve(Y(r)).then(function(r){"APPROVED"===r.status?n(r.compositeSignature):"DECLINED"===r.status?t({status:r.status,reason:r.reason}):setTimeout(function(){n(e(r.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){n=e})},function(e){throw console.error(e),e})},function(){return r(),n})})})})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var t,o=function(){if(e.role.proposer)return Promise.resolve(re()).then(function(e){var n=e.keys.find(function(e){return e.index===r.keyId});t=n.sequenceNumber})}();return o&&o.then?o.then(n):n()})})}catch(e){return Promise.reject(e)}},te=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{ee(t,1,i(this.v))}catch(e){ee(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(t,1,r?r(o):o):n?ee(t,1,n(o)):ee(t,2,o)}catch(e){ee(t,2,e)}},t},e}();function oe(e){return e instanceof te&&1&e.s}var ie=function(){try{return Promise.resolve(new Promise(function(r){try{return ve(),Promise.resolve(ge()).then(function(n){return n.loggedIn?r(n):Promise.resolve(e().get("challenge.handshake")).then(function(n){return Promise.resolve(e().get("challenge.scope")).then(function(e){var t=function(e){var r=e.handshake,n=e.scope,t=e.nonce,o=e.l6n;if(!document.getElementById($)){var i=new URL(r);i.searchParams.append("l6n",o),i.searchParams.append("nonce",t),n&&i.searchParams.append("scope",n.split(" ").join("+"));var u=document.createElement("iframe");return u.src=i.href,u.id=$,u.allow="usb",u.style.position="fixed",u.style.top="0px",u.style.right="0px",u.style.left="0px",u.style.bottom="0px",u.style.height="100vh",u.style.width="100vw",u.style.display="block",u.style.background="rgba(0,0,0,0.25)",u.frameBorder="0",u.style.boxSizing="border-box",u.style.border="1px solid white",document.body.append(u),function(){document.getElementById($)&&document.getElementById($).remove()}}}({handshake:n,scope:e,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(e){var n=e.data;try{if(n.type!==ae)return Promise.resolve();t();var o=new URL(n.hks);return o.searchParams.append("code",n.code),Promise.resolve(fetch(o,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){return S(ue,se,F({},e,{cid:Z(e.provider),loggedIn:!0,verified:!0})),Promise.resolve(ge()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ue="CURRENT_USER",ce="CURRENT_USER/UPDATED",se="SET_CURRENT_USER",ae="FCL::CHALLENGE::RESPONSE",le='{\n "VERSION": "0.1.1",\n "addr":null,\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}',fe=new Set(["verified","identity","scoped","provider"]),he=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,r){return fe.has(r)&&function(e){console.error(('\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},de=function(e){try{return localStorage.setItem(ue,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},me=((X={})[v]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(le),r=JSON.parse(localStorage.getItem(ue));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(ue),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(n){r.call(e,n)})}catch(e){return Promise.reject(e)}},X[p]=function(e,r){e.subscribe(r.from),e.send(r.from,ce,he(e.all()))},X[P]=function(e,r){e.unsubscribe(r.from)},X.SNAPSHOT=function(e,r){try{return r.reply(he(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},X[se]=function(e,r,n){try{return e.merge(n),de(e.all()),e.broadcast(ce,he(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},X.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(le)),de(e.all()),e.broadcast(ce,he(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},X.GET_AS_PARAM=function(e,r,n){var t=n.key;try{return r.reply({key:t,value:e.get("addr",null),xform:j}),Promise.resolve()}catch(e){return Promise.reject(e)}},X),ve=function(){return E(me,ue)};function pe(){ve(),S(ue,"DEL_CURRENT_USER")}function ye(e){return function(){try{return ve(),Promise.resolve(ie()).then(function(){return S(ue,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Pe(e){ve();var r=E(function(r){try{var n;return r.send(ue,p),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(oe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!oe(i)){t=1;break}i=i.s}}var u=new te,c=ee.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):ee(u,1,i)})).then(void 0,c),u;function s(r){i=r;do{if(!(o=e())||oe(o)&&!o.v)return void ee(u,1,i);if(o.then)return void o.then(a).then(void 0,c);oe(i=n())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,c)}function a(e){e?(i=n())&&i.then?i.then(s).then(void 0,c):s(i):ee(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(ue,P),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return S(r,"@EXIT")}}function ge(){return ve(),S(ue,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var be=function(){return{authenticate:ie,unauthenticate:pe,authorization:ne,param:ye,subscribe:Pe,snapshot:ge}},Ee=function(){return be().authenticate()},we=function(){return be().unauthenticate()},Se="0.0.51";export{Se as VERSION,Ee as authenticate,be as currentUser,N as decode,V as events,x as resolve,q as sansPrefix,A as send,I as serialize,D as tx,we as unauthenticate,K as withPrefix}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as r,resolveRefBlockId as t,resolveParams as n,resolveArguments as o,resolveAccounts as i,resolveSignatures as u,resolveValidators as s,build as c,send as a,decodeResponse as l,getTransactionStatus as f,getEvents as d,getLatestBlock as h,getAccount as m}from"@onflow/sdk";export{arg,args,authorization,authorizations,build,cadence,cdc,getAccount,getBlockByHeight,getBlockById,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 y,UPDATED as P,UNSUBSCRIBE as p,SNAPSHOT as g,subscriber as b,spawn as E,snapshoter as w,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 I,T,A=function(c){try{return Promise.resolve(e().get("accessNode.api")).then(function(e){return r(c,[t({node:e}),n,o,i,u,s])})}catch(e){return Promise.reject(e)}},k=function(r,t){void 0===r&&(r=[]),void 0===t&&(t={});try{var n=function(e){return t.node=e,Array.isArray(r)&&(r=c(r)),Promise.resolve(A(r)).then(function(e){return a(e,t)})},o=t.node;return Promise.resolve(o?n(o):Promise.resolve(e().get("accessNode.api")).then(n))}catch(e){return Promise.reject(e)}},R=function(e){void 0===e&&(e=[]);try{var r=function(){return Promise.resolve(A(e)).then(JSON.stringify)},t=function(){if(Array.isArray(e))return Promise.resolve(c(e)).then(function(r){e=r})}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},O=function(r){try{return Promise.resolve(e().where(/^decoder\./)).then(function(e){var t=Object.fromEntries(Object.entries(e).map(function(e){var r=e[0],t=e[1];return[r="/"+r.replace(/^decoder\./,"")+"$/",t]}));return l(r,t)})}catch(e){return Promise.reject(e)}},N=function(e){try{return Promise.resolve(k([f(e)])).then(O)}catch(e){return Promise.reject(e)}},x=function(e){return e.status>=4},C=function(e){return e.status>=3},L=function(e){return e.status>=2},U=((I={})[v]=function(e){try{return Promise.resolve(N(e.self())).then(function(r){x(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},I[y]=function(e,r){e.subscribe(r.from),e.send(r.from,P,e.all())},I[p]=function(e,r){e.unsubscribe(r.from)},I[g]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},I.POLL=function(e){try{return Promise.resolve(N(e.self())).then(function(r){var t,n;x(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(P,r),e.merge(r)})}catch(e){return Promise.reject(e)}},I),D=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},_=function(e){return E(U,D(e))};function z(e){function r(r){return b(D(e),_,r)}function t(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 w(e,_)},subscribe:r,onceFinalized:t(L),onceExecuted:t(C),onceSealed:t(x)}}function B(){return(B=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 F(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}function H(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 F(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)?F(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)}z.isUnknown=function(e){return e.status>=0},z.isPending=function(e){return e.status>=1},z.isFinalized=L,z.isExecuted=C,z.isSealed=x,z.isExpired=function(e){return 5===e.status};var M=function(){try{return Promise.resolve(k([h()])).then(O)}catch(e){return Promise.reject(e)}},J=function(r){try{var t=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return t(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},G=((T={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),t=function(){if(null==r){var t=e.put;return Promise.resolve(M()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve(J(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(M()).then(function(t){return e.put("hwm",t),Promise.resolve(k([d(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(O(r)).then(function(r){for(var t,n=H(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(J(e)).then(function(r){o.call(e,"tick",r)})})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},T[y]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(J(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)}},T[p]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},T),V=function(e){return E(G,e)};function q(e){return{subscribe:function(r){return b(e,V,r)}}}function K(e){return null==e?null:e.replace(/^0x/,"")}function W(e){return null==e?null:"0x"+K(e)}var X="FCL_IFRAME_CHALLENGE";function Z(e,r){void 0===r&&(r=!0);var t=new URL(e.endpoint);if(r)for(var n=0,o=Object.entries(e.params||{});n<o.length;n++){var i=o[n];t.searchParams.append(i[0],i[1])}return t}var $="FCL_IFRAME_AUTHZ";function Q(e){if(!document.getElementById($)){var r=Z(e),t=document.createElement("iframe");return t.src=r.href,t.id=$,t.allow="usb",t.style.position="fixed",t.style.top="0px",t.style.right="0px",t.style.left="0px",t.style.bottom="0px",t.style.height="100vh",t.style.width="100vw",t.style.display="block",t.style.background="rgba(0,0,0,0.25)",t.frameBorder="0",t.style.boxSizing="border-box",t.style.border="1px solid white",document.body.append(t),[t,function(){document.getElementById($)&&document.getElementById($).remove()}]}}var Y,ee={"HTTP/GET":"GET","HTTP/POST":"POST"},re="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",te=re.length,ne={"HTTP/POST":function(e,r){try{var t=function(){},n=null;return Promise.resolve(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(fetch(Z(e),{method:"POST",headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0}).then(function(e){return e.json()})).then(function(e){if(e.local&&e.local.length>0){var r=Q(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(Z(r),{method:ee[r.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).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){n=e})})},function(e){throw t(),console.error(e),e})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){var o=function(){for(var e="",r=32;r--;)e+=re[Math.random()*te|0];return e}();Q(e)[0].contentWindow.postMessage({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]},"*"),window.addListener("message",function(e){var r=e.data;try{if("object"!=typeof r)return Promise.resolve();if("2.0"!==r.jsonrpc)return Promise.resolve();if(r.id!==o)return Promise.resolve();var i=r.result;return"APPROVED"===i.status?t(i.compositeSignature):n("DECLINED"===i.status?{status:i.status,reason:i.reason}:{status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}),Promise.resolve()}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}}},oe=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},ie=function(e,r){return"Missing "+oe(e,r)+" in Composite Signature."},ue=function(e,r){return oe(e,r)+" in Composit Signature did not match the requested "+e+"."};function se(e,r,t){if(!e.s){if(t instanceof ae){if(!t.s)return void(t.o=se.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(se.bind(null,e,r),se.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var ce=function(e){try{return ge(),Promise.resolve(fe()).then(function(r){function t(){return B({},e,{addr:i.addr,keyId:i.keyId,sequenceNum:o,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(function(e,r){try{return Promise.resolve(ne[e.method](e,r))}catch(e){return Promise.reject(e)}}(i,e)).then(function(e){return function(e,r){try{if(null==e.addr)throw new Error(ie("addr","Address"));if(null==e.keyId)throw new Error(ie("keyId"));if(null==e.sig)throw new Error(ie("sig","Signature"));if(e.addr!==r.addr)throw new Error(ue("addr","Address"));if(e.keyId!==r.keyId)throw new Error(ue("keyId"))}catch(t){throw console.error(t,"\n\n",{"Composite Signature":e,"Authz Service":r}),new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+t.message)}}(e,i),e})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var n,o,i=(void 0===(n=r.services)&&(n=[]),n.find(function(e){return"authz"===e.type})),u=function(){if(e.role.proposer)return Promise.resolve(function(){try{return ge(),Promise.resolve(Se()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(k([m(r)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}}()).then(function(e){var r=e.keys.find(function(e){return e.index===i.keyId});o=r.sequenceNumber})}();return u&&u.then?u.then(t):t()})}catch(e){return Promise.reject(e)}},ae=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{se(n,1,i(this.v))}catch(e){se(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?se(n,1,r?r(o):o):t?se(n,1,t(o)):se(n,2,o)}catch(e){se(n,2,e)}},n},e}();function le(e){return e instanceof ae&&1&e.s}var fe=function(){try{return Promise.resolve(new Promise(function(r){try{return ge(),Promise.resolve(Se()).then(function(t){return t.loggedIn?r(t):Promise.resolve(e().get("challenge.handshake")).then(function(e){var t=function(e){var r=e.handshake,t=e.l6n;if(!document.getElementById(X)){var n=new URL(r);n.searchParams.append("l6n",t);var o=document.createElement("iframe");return o.src=n.href,o.id=X,o.allow="usb",o.style.position="fixed",o.style.top="0px",o.style.right="0px",o.style.left="0px",o.style.bottom="0px",o.style.height="100vh",o.style.width="100vw",o.style.display="block",o.style.background="rgba(0,0,0,0.25)",o.frameBorder="0",o.style.boxSizing="border-box",o.style.border="1px solid white",document.body.append(o),function(){document.getElementById(X)&&document.getElementById(X).remove()}}}({handshake:e,l6n:window.location.origin});window.addEventListener("message",function(e){var n=e.data;try{if(n.type!==ve)return Promise.resolve();t();var o="did:fcl:"+n.addr,i=n.addr,u=n.services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",r),Promise.resolve(fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var t,n=H(e.authorizations);!(t=n()).done;)r.push(B({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(B({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(n.hks,n.code)).then(function(e){var t,n,s={addr:i,cid:o,loggedIn:!0,services:(t=u,n=e,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return S(de,me,s),Promise.resolve(Se()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},de="CURRENT_USER",he="CURRENT_USER/UPDATED",me="SET_CURRENT_USER",ve="FCL::CHALLENGE::RESPONSE",ye='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',Pe=function(e){try{return localStorage.setItem(de,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},pe=((Y={})[v]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(ye),r=JSON.parse(localStorage.getItem(de));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(de),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(t){r.call(e,t)})}catch(e){return Promise.reject(e)}},Y[y]=function(e,r){e.subscribe(r.from),e.send(r.from,he,e.all())},Y[p]=function(e,r){e.unsubscribe(r.from)},Y.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Y[me]=function(e,r,t){try{return e.merge(t),Pe(e.all()),e.broadcast(he,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Y.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(ye)),Pe(e.all()),e.broadcast(he,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Y.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:j}),Promise.resolve()}catch(e){return Promise.reject(e)}},Y),ge=function(){return E(pe,de)};function be(){ge(),S(de,"DEL_CURRENT_USER")}function Ee(e){return function(){try{return ge(),Promise.resolve(fe()).then(function(){return S(de,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function we(e){ge();var r=E(function(r){try{var t;return r.send(de,y),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(le(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!le(i)){n=1;break}i=i.s}}var u=new ae,s=se.bind(null,u,2);return(0===n?o.then(a):1===n?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(a).then(void 0,s):a(o):se(u,1,i)})).then(void 0,s),u;function c(r){i=r;do{if(!(o=e())||le(o)&&!o.v)return void se(u,1,i);if(o.then)return void o.then(a).then(void 0,s);le(i=t())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,s)}function a(e){e?(i=t())&&i.then?i.then(c).then(void 0,s):c(i):se(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(de,p),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return S(r,"@EXIT")}}function Se(){return ge(),S(de,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var je=function(){return{authenticate:fe,unauthenticate:be,authorization:ce,param:Ee,subscribe:we,snapshot:Se}},Ie=function(){return je().authenticate()},Te=function(){return je().unauthenticate()},Ae="0.0.51";export{Ae as VERSION,Ie as authenticate,je as currentUser,O as decode,q as events,A as resolve,K as sansPrefix,k as send,R as serialize,z as tx,Te as unauthenticate,W as withPrefix}; | ||
//# 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,r,t,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 r.resolve(e,[r.resolveRefBlockId({node:n}),r.resolveParams,r.resolveArguments,r.resolveAccounts,r.resolveSignatures,r.resolveValidators])})}catch(e){return Promise.reject(e)}},s=function(e,t){void 0===e&&(e=[]),void 0===t&&(t={});try{var o=function(n){return t.node=n,Array.isArray(e)&&(e=r.build(e)),Promise.resolve(c(e)).then(function(e){return r.send(e,t)})},i=t.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 t=Object.fromEntries(Object.entries(n).map(function(e){var n=e[0],r=e[1];return[n="/"+n.replace(/^decoder\./,"")+"$/",r]}));return r.decodeResponse(e,t)})}catch(e){return Promise.reject(e)}},l=function(e){try{return Promise.resolve(s([r.getTransactionStatus(e)])).then(a)}catch(e){return Promise.reject(e)}},f=function(e){return e.status>=4},d=function(e){return e.status>=3},m=function(e){return e.status>=2},h=((i={})[t.INIT]=function(e){try{return Promise.resolve(l(e.self())).then(function(n){f(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},i[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,t.UPDATED,e.all())},i[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},i[t.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(l(e.self())).then(function(n){var r,o;f(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),o=n,JSON.stringify(r)!==JSON.stringify(o)&&e.broadcast(t.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},i),v=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},p=function(e){return t.spawn(h,v(e))};function y(e){function n(n){return t.subscriber(v(e),p,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 t.snapshoter(e,p)},subscribe:n,onceFinalized:r(m),onceExecuted:r(d),onceSealed:r(f)}}function P(){return(P=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 g(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}y.isUnknown=function(e){return e.status>=0},y.isPending=function(e){return e.status>=1},y.isFinalized=m,y.isExecuted=d,y.isSealed=f,y.isExpired=function(e){return 5===e.status};var b=function(){try{return Promise.resolve(s([r.getLatestBlock()])).then(a)}catch(e){return Promise.reject(e)}},j=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},S=((u={}).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(b()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve(j(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(b()).then(function(t){return e.put("hwm",t),Promise.resolve(s([r.getEvents(e.self(),n.height,t.height-1)])).then(function(n){return Promise.resolve(a(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 g(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)?g(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(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},u[t.SUBSCRIBE]=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)}},u[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},u),E=function(e){return t.spawn(S,e)};function w(e){return null==e?null:e.replace(/^0x/,"")}var O,I="FCL_IFRAME_CHALLENGE",R="FCL_IFRAME_AUTHZ",T=function(e){void 0===e&&(e={});var n=e.addr,r=e.pid;return null==n||null==r?null:n+"/"+r},k={"HTTP/POST":"POST","HTTP/GET":"GET"},N=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:k[e.method],headers:{"Content-Type":"application/json"},body:n}).then(function(e){return e.json()}))}catch(e){return Promise.reject(e)}};function A(e,n,r){if(!e.s){if(r instanceof x){if(!r.s)return void(r.o=A.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(A.bind(null,e,n),A.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var B=function(){try{return V(),Promise.resolve(W()).then(function(e){var n=e.addr;if(null==n)throw new Error("No Flow Address for Current User");return Promise.resolve(s([r.getAccount(n)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}},U=function(e){try{return V(),Promise.resolve(L()).then(function(){return Promise.resolve(W()).then(function(n){function r(){return P({},e,{addr:n.addr,keyId:n.keyId,sequenceNum:t,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(W()).then(function(n){return Promise.resolve(B()).then(function(r){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(R)){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=R,i.allow="usb",i.style.position="fixed",i.style.top="0px",i.style.right="0px",i.style.left="0px",i.style.bottom="0px",i.style.height="100vh",i.style.width="100vw",i.style.display="block",i.style.background="rgba(0,0,0,0.25)",i.frameBorder="0",i.style.boxSizing="border-box",i.style.border="1px solid white",document.body.append(i),function(){document.getElementById(R)&&document.getElementById(R).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(N(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(B()).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)}},x=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{A(t,1,i(this.v))}catch(e){A(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?A(t,1,n?n(o):o):r?A(t,1,r(o)):A(t,2,o)}catch(e){A(t,2,e)}},t},e}();function C(e){return e instanceof x&&1&e.s}var L=function(){try{return Promise.resolve(new Promise(function(e){try{return V(),Promise.resolve(W()).then(function(r){return r.loggedIn?e(r):Promise.resolve(n.config().get("challenge.handshake")).then(function(r){return Promise.resolve(n.config().get("challenge.scope")).then(function(n){var o=function(e){var n=e.handshake,r=e.scope,t=e.nonce,o=e.l6n;if(!document.getElementById(I)){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=I,u.allow="usb",u.style.position="fixed",u.style.top="0px",u.style.right="0px",u.style.left="0px",u.style.bottom="0px",u.style.height="100vh",u.style.width="100vw",u.style.display="block",u.style.background="rgba(0,0,0,0.25)",u.frameBorder="0",u.style.boxSizing="border-box",u.style.border="1px solid white",document.body.append(u),function(){document.getElementById(I)&&document.getElementById(I).remove()}}}({handshake:r,scope:n,nonce:"asdf",l6n:window.location.origin});window.addEventListener("message",function(n){var r=n.data;try{if(r.type!==F)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(n){return t.send(_,D,P({},n,{cid:T(n.provider),loggedIn:!0,verified:!0})),Promise.resolve(W()).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",z="CURRENT_USER/UPDATED",D="SET_CURRENT_USER",F="FCL::CHALLENGE::RESPONSE",H='{\n "VERSION": "0.1.1",\n "addr":null,\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"]),J=function(e){return"undefined"!=typeof Proxy&&(e=new Proxy(e,{get:function(e,n){return G.has(n)&&function(e){console.error(('\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},q=function(e){try{return localStorage.setItem(_,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},M=((O={})[t.INIT]=function(e){try{var n=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(H),n=JSON.parse(localStorage.getItem(_));return null!=n&&e.VERSION!==n.VERSION?(localStorage.removeItem(_),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(r){n.call(e,r)})}catch(e){return Promise.reject(e)}},O[t.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,z,J(e.all()))},O[t.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},O.SNAPSHOT=function(e,n){try{return n.reply(J(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},O[D]=function(e,n,r){try{return e.merge(r),q(e.all()),e.broadcast(z,J(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},O.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(H)),q(e.all()),e.broadcast(z,J(e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},O.GET_AS_PARAM=function(e,n,r){var t=r.key;try{return n.reply({key:t,value:e.get("addr",null),xform:o.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},O),V=function(){return t.spawn(M,_)};function K(){V(),t.send(_,"DEL_CURRENT_USER")}function X(e){return function(){try{return V(),Promise.resolve(L()).then(function(){return t.send(_,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function $(e){V();var n=t.spawn(function(n){try{var r;return n.send(_,t.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(C(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!C(i)){t=1;break}i=i.s}}var u=new x,c=A.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):A(u,1,i)})).then(void 0,c),u;function s(n){i=n;do{if(!(o=e())||C(o)&&!o.v)return void A(u,1,i);if(o.then)return void o.then(a).then(void 0,c);C(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):A(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if("@EXIT"===o.tag)return n.send(_,t.UNSUBSCRIBE),void(r=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return t.send(n,"@EXIT")}}function W(){return V(),t.send(_,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Z=function(){return{authenticate:L,unauthenticate:K,authorization:U,param:X,subscribe:$,snapshot:W}};Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return r.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return r.args}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return r.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return r.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return r.build}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return r.cadence}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return r.cdc}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return r.getAccount}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return r.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return r.getBlockById}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return r.getEvents}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return r.getLatestBlock}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return r.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return r.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return r.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return r.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return r.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return r.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return r.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return r.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return r.script}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return r.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return r.why}}),e.VERSION="0.0.51",e.authenticate=function(){return Z().authenticate()},e.currentUser=Z,e.decode=a,e.events=function(e){return{subscribe:function(n){return t.subscriber(e,E,n)}}},e.resolve=c,e.sansPrefix=w,e.send=s,e.serialize=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(c(e)).then(JSON.stringify)},t=function(){if(Array.isArray(e))return Promise.resolve(r.build(e)).then(function(n){e=n})}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},e.tx=y,e.unauthenticate=function(){return Z().unauthenticate()},e.withPrefix=function(e){return null==e?null:"0x"+w(e)}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(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"],r):r((e=e||self).fcl={},e.config,e.sdk,e.utilActor,e.types)}(this,function(e,r,t,n,o){r.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var i,u,c=function(e){try{return Promise.resolve(r.config().get("accessNode.api")).then(function(r){return t.resolve(e,[t.resolveRefBlockId({node:r}),t.resolveParams,t.resolveArguments,t.resolveAccounts,t.resolveSignatures,t.resolveValidators])})}catch(e){return Promise.reject(e)}},s=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var o=function(r){return n.node=r,Array.isArray(e)&&(e=t.build(e)),Promise.resolve(c(e)).then(function(e){return t.send(e,n)})},i=n.node;return Promise.resolve(i?o(i):Promise.resolve(r.config().get("accessNode.api")).then(o))}catch(e){return Promise.reject(e)}},a=function(e){try{return Promise.resolve(r.config().where(/^decoder\./)).then(function(r){var n=Object.fromEntries(Object.entries(r).map(function(e){var r=e[0],t=e[1];return[r="/"+r.replace(/^decoder\./,"")+"$/",t]}));return t.decodeResponse(e,n)})}catch(e){return Promise.reject(e)}},l=function(e){try{return Promise.resolve(s([t.getTransactionStatus(e)])).then(a)}catch(e){return Promise.reject(e)}},f=function(e){return e.status>=4},d=function(e){return e.status>=3},m=function(e){return e.status>=2},h=((i={})[n.INIT]=function(e){try{return Promise.resolve(l(e.self())).then(function(r){f(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},i[n.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,n.UPDATED,e.all())},i[n.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},i[n.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},i.POLL=function(e){try{return Promise.resolve(l(e.self())).then(function(r){var t,o;f(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),o=r,JSON.stringify(t)!==JSON.stringify(o)&&e.broadcast(n.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},i),v=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},y=function(e){return n.spawn(h,v(e))};function p(e){function r(r){return n.subscriber(v(e),y,r)}function t(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 n.snapshoter(e,y)},subscribe:r,onceFinalized:t(m),onceExecuted:t(d),onceSealed:t(f)}}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 g(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}function b(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 g(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)?g(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)}p.isUnknown=function(e){return e.status>=0},p.isPending=function(e){return e.status>=1},p.isFinalized=m,p.isExecuted=d,p.isSealed=f,p.isExpired=function(e){return 5===e.status};var E=function(){try{return Promise.resolve(s([t.getLatestBlock()])).then(a)}catch(e){return Promise.reject(e)}},S=function(e){try{var t=setTimeout;return Promise.resolve(r.config().get("fcl.eventPollRate",1e4)).then(function(r){return t(function(){return e.sendSelf("TICK")},r)})}catch(e){return Promise.reject(e)}},j=((u={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(E()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(S(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(E()).then(function(n){return e.put("hwm",n),Promise.resolve(s([t.getEvents(e.self(),r.height,n.height-1)])).then(function(r){return Promise.resolve(a(r)).then(function(r){for(var t,n=b(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(S(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)}},u[n.SUBSCRIBE]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(S(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)}},u[n.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},u),w=function(e){return n.spawn(j,e)};function O(e){return null==e?null:e.replace(/^0x/,"")}var I="FCL_IFRAME_CHALLENGE";function T(e,r){void 0===r&&(r=!0);var t=new URL(e.endpoint);if(r)for(var n=0,o=Object.entries(e.params||{});n<o.length;n++){var i=o[n];t.searchParams.append(i[0],i[1])}return t}var A="FCL_IFRAME_AUTHZ";function R(e){if(!document.getElementById(A)){var r=T(e),t=document.createElement("iframe");return t.src=r.href,t.id=A,t.allow="usb",t.style.position="fixed",t.style.top="0px",t.style.right="0px",t.style.left="0px",t.style.bottom="0px",t.style.height="100vh",t.style.width="100vw",t.style.display="block",t.style.background="rgba(0,0,0,0.25)",t.frameBorder="0",t.style.boxSizing="border-box",t.style.border="1px solid white",document.body.append(t),[t,function(){document.getElementById(A)&&document.getElementById(A).remove()}]}}var k,N={"HTTP/GET":"GET","HTTP/POST":"POST"},B="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",U=B.length,C={"HTTP/POST":function(e,r){try{var t=function(){},n=null;return Promise.resolve(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(fetch(T(e),{method:"POST",headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0}).then(function(e){return e.json()})).then(function(e){if(e.local&&e.local.length>0){var r=R(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(T(r),{method:N[r.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).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){n=e})})},function(e){throw t(),console.error(e),e})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){var o=function(){for(var e="",r=32;r--;)e+=B[Math.random()*U|0];return e}();R(e)[0].contentWindow.postMessage({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]},"*"),window.addListener("message",function(e){var r=e.data;try{if("object"!=typeof r)return Promise.resolve();if("2.0"!==r.jsonrpc)return Promise.resolve();if(r.id!==o)return Promise.resolve();var i=r.result;return"APPROVED"===i.status?t(i.compositeSignature):n("DECLINED"===i.status?{status:i.status,reason:i.reason}:{status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}),Promise.resolve()}catch(e){return Promise.reject(e)}})}))}catch(e){return Promise.reject(e)}}},x=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},L=function(e,r){return"Missing "+x(e,r)+" in Composite Signature."},D=function(e,r){return x(e,r)+" in Composit Signature did not match the requested "+e+"."};function z(e,r,t){if(!e.s){if(t instanceof H){if(!t.s)return void(t.o=z.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(z.bind(null,e,r),z.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var _=function(e){try{return Z(),Promise.resolve(M()).then(function(r){function n(){return P({},e,{addr:u.addr,keyId:u.keyId,sequenceNum:i,signature:e.signature||null,signingFunction:function(e){try{return Promise.resolve(function(e,r){try{return Promise.resolve(C[e.method](e,r))}catch(e){return Promise.reject(e)}}(u,e)).then(function(e){return function(e,r){try{if(null==e.addr)throw new Error(L("addr","Address"));if(null==e.keyId)throw new Error(L("keyId"));if(null==e.sig)throw new Error(L("sig","Signature"));if(e.addr!==r.addr)throw new Error(D("addr","Address"));if(e.keyId!==r.keyId)throw new Error(D("keyId"))}catch(t){throw console.error(t,"\n\n",{"Composite Signature":e,"Authz Service":r}),new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+t.message)}}(e,u),e})}catch(e){return Promise.reject(e)}},resolve:null,roles:e.roles})}var o,i,u=(void 0===(o=r.services)&&(o=[]),o.find(function(e){return"authz"===e.type})),c=function(){if(e.role.proposer)return Promise.resolve(function(){try{return Z(),Promise.resolve(ee()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(s([t.getAccount(r)])).then(function(e){return e.account})})}catch(e){return Promise.reject(e)}}()).then(function(e){var r=e.keys.find(function(e){return e.index===u.keyId});i=r.sequenceNumber})}();return c&&c.then?c.then(n):n()})}catch(e){return Promise.reject(e)}},H=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{z(n,1,i(this.v))}catch(e){z(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?z(n,1,r?r(o):o):t?z(n,1,t(o)):z(n,2,o)}catch(e){z(n,2,e)}},n},e}();function F(e){return e instanceof H&&1&e.s}var M=function(){try{return Promise.resolve(new Promise(function(e){try{return Z(),Promise.resolve(ee()).then(function(t){return t.loggedIn?e(t):Promise.resolve(r.config().get("challenge.handshake")).then(function(r){var t=function(e){var r=e.handshake,t=e.l6n;if(!document.getElementById(I)){var n=new URL(r);n.searchParams.append("l6n",t);var o=document.createElement("iframe");return o.src=n.href,o.id=I,o.allow="usb",o.style.position="fixed",o.style.top="0px",o.style.right="0px",o.style.left="0px",o.style.bottom="0px",o.style.height="100vh",o.style.width="100vw",o.style.display="block",o.style.background="rgba(0,0,0,0.25)",o.frameBorder="0",o.style.boxSizing="border-box",o.style.border="1px solid white",document.body.append(o),function(){document.getElementById(I)&&document.getElementById(I).remove()}}}({handshake:r,l6n:window.location.origin});window.addEventListener("message",function(r){var o=r.data;try{if(o.type!==G)return Promise.resolve();t();var i="did:fcl:"+o.addr,u=o.addr,c=o.services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",r),Promise.resolve(fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var t,n=b(e.authorizations);!(t=n()).done;)r.push(P({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(P({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(o.hks,o.code)).then(function(r){var t,o,s={addr:u,cid:i,loggedIn:!0,services:(t=c,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o))};return n.send(V,J,s),Promise.resolve(ee()).then(function(r){e(r)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},V="CURRENT_USER",q="CURRENT_USER/UPDATED",J="SET_CURRENT_USER",G="FCL::CHALLENGE::RESPONSE",K='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',W=function(e){try{return localStorage.setItem(V,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},X=((k={})[n.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(K),r=JSON.parse(localStorage.getItem(V));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(V),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(t){r.call(e,t)})}catch(e){return Promise.reject(e)}},k[n.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,q,e.all())},k[n.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},k.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},k[J]=function(e,r,t){try{return e.merge(t),W(e.all()),e.broadcast(q,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},k.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(K)),W(e.all()),e.broadcast(q,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},k.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:o.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},k),Z=function(){return n.spawn(X,V)};function $(){Z(),n.send(V,"DEL_CURRENT_USER")}function Q(e){return function(){try{return Z(),Promise.resolve(M()).then(function(){return n.send(V,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Y(e){Z();var r=n.spawn(function(r){try{var t;return r.send(V,n.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(F(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!F(i)){n=1;break}i=i.s}}var u=new H,c=z.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):z(u,1,i)})).then(void 0,c),u;function s(r){i=r;do{if(!(o=e())||F(o)&&!o.v)return void z(u,1,i);if(o.then)return void o.then(a).then(void 0,c);F(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):z(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(o){if("@EXIT"===o.tag)return r.send(V,n.UNSUBSCRIBE),void(t=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return n.send(r,"@EXIT")}}function ee(){return Z(),n.send(V,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var re=function(){return{authenticate:M,unauthenticate:$,authorization:_,param:Q,subscribe:Y,snapshot:ee}};Object.defineProperty(e,"config",{enumerable:!0,get:function(){return r.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,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),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.VERSION="0.0.51",e.authenticate=function(){return re().authenticate()},e.currentUser=re,e.decode=a,e.events=function(e){return{subscribe:function(r){return n.subscriber(e,w,r)}}},e.resolve=c,e.sansPrefix=O,e.send=s,e.serialize=function(e){void 0===e&&(e=[]);try{var r=function(){return Promise.resolve(c(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(t.build(e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},e.tx=p,e.unauthenticate=function(){return re().unauthenticate()},e.withPrefix=function(e){return null==e?null:"0x"+O(e)}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.54", | ||
"version": "0.0.55", | ||
"description": "Flow Client Library", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -538,3 +538,3 @@ # @onflow/fcl | ||
Describing the specifics of how to compose Flow transactions is beyond the scope of this guide. For more information about how to build Flow transactions you can read the [https://docs.onflow.org/docs/cadence#transactions](docs). | ||
Describing the specifics of how to compose Flow transactions is beyond the scope of this guide. For more information about how to build Flow transactions you can read the [docs here](https://docs.onflow.org/docs/cadence#transactions). | ||
@@ -541,0 +541,0 @@ ### Simple Transaction |
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
229760
239
13