Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onflow/fcl

Package Overview
Dependencies
Maintainers
7
Versions
313
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/fcl - npm Package Compare versions

Comparing version 0.0.61-alpha.1 to 0.0.61-alpha.2

5

CHANGELOG.md

@@ -5,2 +5,7 @@ ### Unreleased

### 0.0.61-alpha.2 - 2020-10-07
- 2020-10-07 -- VSN `@onflow/sdk-resolve-signatures` 0.0.0 -> 0.0.1
- 2020-10-07 -- VSN `@onflow/sdk` 0.0.35 -> 0.0.37
### 0.0.61-alpha.1 - 2020-10-07

@@ -7,0 +12,0 @@

2

dist/fcl.js

@@ -1,2 +0,2 @@

var e=require("@onflow/config"),r=require("@onflow/interaction"),t=require("@onflow/send"),n=require("@onflow/sdk"),o=require("@onflow/sdk-resolve-cadence"),i=require("@onflow/sdk-resolve-arguments"),u=require("@onflow/sdk-resolve-accounts"),s=require("@onflow/sdk-resolve-signatures"),c=require("@onflow/sdk-resolve-validators"),a=require("@onflow/decode"),l=require("@onflow/util-actor"),f=require("@onflow/sdk-build-transaction-status"),d=require("@onflow/sdk-build-get-events"),m=require("@onflow/sdk-build-get-latest-block"),h=require("@onflow/sdk-build-get-account"),p=require("@onflow/types"),v=require("@onflow/util-address"),P=require("@onflow/util-template"),y=require("@onflow/sdk-build-transaction"),g=require("@onflow/sdk-build-script"),b=require("@onflow/sdk-build-ping"),w=require("@onflow/sdk-build-get-block-by-id"),E=require("@onflow/sdk-build-get-block-by-height"),S=require("@onflow/sdk-build-authorizations"),j=require("@onflow/sdk-build-arguments"),O=require("@onflow/sdk-build-proposer"),k=require("@onflow/sdk-build-payer"),x=require("@onflow/sdk-build-limit"),I=require("@onflow/sdk-build-ref"),T=require("@onflow/sdk-build-params");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R,A,C=function(t){try{return Promise.resolve(e.config().get("accessNode.api")).then(function(e){return r.pipe(t,[o.resolveCadence,i.resolveArguments,u.resolveAccounts,n.resolveRefBlockId({node:e}),s.resolveSignatures,c.resolveValidators])})}catch(e){return Promise.reject(e)}},N=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Array.isArray(e)&&(e=r.pipe(r.interaction(),e)),Promise.resolve(C(e)).then(function(e){return t.send(e,n)})}catch(e){return Promise.reject(e)}},L=function(r){try{return Promise.resolve(e.config().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 a.decodeResponse(r,t)})}catch(e){return Promise.reject(e)}},U=function(e){try{return Promise.resolve(N([getTransactionStatus(e)])).then(L)}catch(e){return Promise.reject(e)}},q=function(e){return e.status>=4},B=function(e){return e.status>=3},D=function(e){return e.status>=2},z=((R={})[l.INIT]=function(e){try{return Promise.resolve(U(e.self())).then(function(r){q(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},R[l.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,l.UPDATED,e.all())},R[l.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},R[l.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},R.POLL=function(e){try{return Promise.resolve(U(e.self())).then(function(r){var t,n;q(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(l.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},R),F=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},_=function(e){return l.spawn(z,F(e))};function M(e){function r(r){return l.subscriber(F(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 l.snapshoter(e,_)},subscribe:r,onceFinalized:t(D),onceExecuted:t(B),onceSealed:t(q)}}function H(){return(H=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 J(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 V(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 J(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?J(e,void 0):void 0}}(e)))return function(){return 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)}M.isUnknown=function(e){return e.status>=0},M.isPending=function(e){return e.status>=1},M.isFinalized=D,M.isExecuted=B,M.isSealed=q,M.isExpired=function(e){return 5===e.status};var G=function(){try{return Promise.resolve(N([getLatestBlock()])).then(L)}catch(e){return Promise.reject(e)}},W=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)}},K=((A={}).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(G()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve(W(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(G()).then(function(t){return e.put("hwm",t),Promise.resolve(N([getEvents(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(L(r)).then(function(r){for(var t,n=V(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(W(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)}},A[l.SUBSCRIBE]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(W(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)}},A[l.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},A),X=function(e){return l.spawn(K,e)};function $(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.style.position="fixed",r.style.top="0px",r.style.right="0px",r.style.left="0px",r.style.bottom="0px",r.style.height="100vh",r.style.width="100vw",r.style.display="block",r.style.background="rgba(0,0,0,0.25)",r.style.zIndex=2147483647,r.frameBorder="0",r.style.boxSizing="border-box",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}function Q(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}function Y(e){return $(Q(e).href)}var Z,ee={"HTTP/GET":"GET","HTTP/POST":"POST"},re=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},te=function(e,r){return"Missing "+re(e,r)+" in Composite Signature."},ne=function(e,r){return re(e,r)+" in Composit Signature did not match the requested "+e+"."},oe="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",ie=oe.length,ue={"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(Q(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=Y(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(Q(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(n){throw t(),se(e,r,n),n})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){try{var o=function(){for(var e="",r=32;r--;)e+=oe[Math.random()*ie|0];return e}(),i=Y(e),u=i[0],s=i[1];setTimeout(function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")},500),window.addEventListener("message",function e(r){var i=r.data;try{if("object"!=typeof i)return Promise.resolve();if("2.0"!==i.jsonrpc)return Promise.resolve();if(i.id!==o)return Promise.resolve();var u=i.result;return"APPROVED"===u.status?(window.removeEventListener("message",e),s(),t(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),n({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),n({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}})}catch(t){se(e,r,t),n({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function se(e,r,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},t)}function ce(e,r,t){if(!e.s){if(t instanceof le){if(!t.s)return void(t.o=ce.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(ce.bind(null,e,r),ce.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var ae=function(e){try{return we(),Promise.resolve(de()).then(function(r){function t(){return H({},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(ue[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),function(e,r){try{if(null==e.addr)throw new Error(te("addr","Address"));if(null==e.keyId)throw new Error(te("keyId"));if(null==e.signature)throw new Error(te("signature"));if(e.addr!==r.addr)throw new Error(ne("addr","Address"));if(e.keyId!==r.keyId)throw new Error(ne("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)}}(r,e),r})}catch(e){return Promise.reject(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 we(),Promise.resolve(Oe()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(N([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===i.keyId});o=r.sequenceNumber})}();return u&&u.then?u.then(t):t()})}catch(e){return Promise.reject(e)}},le=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{ce(n,1,i(this.v))}catch(e){ce(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ce(n,1,r?r(o):o):t?ce(n,1,t(o)):ce(n,2,o)}catch(e){ce(n,2,e)}},n},e}();function fe(e){return e instanceof le&&1&e.s}var de=function(){try{return Promise.resolve(new Promise(function(r){try{return we(),Promise.resolve(Oe()).then(function(t){return t.loggedIn?r(t):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var t,n,o,i=(n=(t={handshake:e,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",n),$(o.href))[1];window.addEventListener("message",function e(t){var n=t.data;try{if(n.type===Pe)return i(),window.removeEventListener("message",e),Promise.resolve();if(n.type!==ve)return Promise.resolve();i(),window.removeEventListener("message",e);var o="did:fcl:"+n.addr,u=n.addr,s=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=V(e.authorizations);!(t=n()).done;)r.push(H({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(H({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,i={addr:u,cid:o,loggedIn:!0,services:(t=s,n=e,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return l.send(me,pe,i),Promise.resolve(Oe()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},me="CURRENT_USER",he="CURRENT_USER/UPDATED",pe="SET_CURRENT_USER",ve="FCL::CHALLENGE::RESPONSE",Pe="FCL::CHALLENGE::CANCEL",ye='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',ge=function(e){try{return localStorage.setItem(me,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},be=((Z={})[l.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(ye),r=JSON.parse(localStorage.getItem(me));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(me),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)}},Z[l.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,he,e.all())},Z[l.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},Z.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[pe]=function(e,r,t){try{return e.merge(t),ge(e.all()),e.broadcast(he,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(ye)),ge(e.all()),e.broadcast(he,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Z.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:p.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},Z),we=function(){return l.spawn(be,me)};function Ee(){we(),l.send(me,"DEL_CURRENT_USER")}function Se(e){return function(){try{return we(),Promise.resolve(de()).then(function(){return l.send(me,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function je(e){we();var r=l.spawn(function(r){try{var t;return r.send(me,l.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(fe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!fe(i)){n=1;break}i=i.s}}var u=new le,s=ce.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):ce(u,1,i)})).then(void 0,s),u;function c(r){i=r;do{if(!(o=e())||fe(o)&&!o.v)return void ce(u,1,i);if(o.then)return void o.then(a).then(void 0,s);fe(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):ce(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(me,l.UNSUBSCRIBE),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return l.send(r,"@EXIT")}}function Oe(){return we(),l.send(me,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ke=function(){return{authenticate:de,unauthenticate:Ee,authorization:ae,param:Se,subscribe:je,snapshot:Oe}};Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),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,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return f.getTransactionStatus}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return d.getEvents}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return m.getLatestBlock}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return h.getAccount}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return v.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return v.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return v.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return P.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return P.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return y.transaction}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return g.script}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return b.ping}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return w.getBlockById}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return E.getBlockByHeight}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return S.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return S.authorizations}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return j.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return j.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return O.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return k.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return x.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return I.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return T.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return T.params}}),exports.VERSION="0.0.61-alpha.1",exports.authenticate=function(){return ke().authenticate()},exports.currentUser=ke,exports.decode=L,exports.events=function(e){return{subscribe:function(r){return l.subscriber(e,X,r)}}},exports.resolve=C,exports.send=N,exports.serialize=function(e){void 0===e&&(e=[]);try{var t=function(){return Promise.resolve(C(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(r.pipe(r.interaction(),e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},exports.tx=M,exports.unauthenticate=function(){return ke().unauthenticate()};
var e=require("@onflow/config"),r=require("@onflow/interaction"),t=require("@onflow/send"),n=require("@onflow/sdk"),o=require("@onflow/sdk-resolve-cadence"),i=require("@onflow/sdk-resolve-arguments"),u=require("@onflow/sdk-resolve-accounts"),s=require("@onflow/sdk-resolve-signatures"),c=require("@onflow/sdk-resolve-validators"),a=require("@onflow/decode"),l=require("@onflow/util-actor"),f=require("@onflow/sdk-build-transaction-status"),d=require("@onflow/sdk-build-get-events"),m=require("@onflow/sdk-build-get-latest-block"),h=require("@onflow/sdk-build-get-account"),p=require("@onflow/types"),v=require("@onflow/util-address"),P=require("@onflow/util-template"),y=require("@onflow/sdk-build-transaction"),g=require("@onflow/sdk-build-script"),b=require("@onflow/sdk-build-ping"),w=require("@onflow/sdk-build-get-block-by-id"),E=require("@onflow/sdk-build-get-block-by-height"),S=require("@onflow/sdk-build-authorizations"),j=require("@onflow/sdk-build-arguments"),O=require("@onflow/sdk-build-proposer"),k=require("@onflow/sdk-build-payer"),x=require("@onflow/sdk-build-limit"),I=require("@onflow/sdk-build-ref"),T=require("@onflow/sdk-build-params");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R,A,C=function(t){try{return Promise.resolve(e.config().get("accessNode.api")).then(function(e){return r.pipe(t,[o.resolveCadence,i.resolveArguments,u.resolveAccounts,n.resolveRefBlockId({node:e}),s.resolveSignatures,c.resolveValidators])})}catch(e){return Promise.reject(e)}},N=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Array.isArray(e)&&(e=r.pipe(r.interaction(),e)),Promise.resolve(C(e)).then(function(e){return t.send(e,n)})}catch(e){return Promise.reject(e)}},L=function(r){try{return Promise.resolve(e.config().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 a.decodeResponse(r,t)})}catch(e){return Promise.reject(e)}},U=function(e){try{return Promise.resolve(N([getTransactionStatus(e)])).then(L)}catch(e){return Promise.reject(e)}},q=function(e){return e.status>=4},B=function(e){return e.status>=3},D=function(e){return e.status>=2},z=((R={})[l.INIT]=function(e){try{return Promise.resolve(U(e.self())).then(function(r){q(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},R[l.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,l.UPDATED,e.all())},R[l.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},R[l.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},R.POLL=function(e){try{return Promise.resolve(U(e.self())).then(function(r){var t,n;q(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(l.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},R),F=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},_=function(e){return l.spawn(z,F(e))};function M(e){function r(r){return l.subscriber(F(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 l.snapshoter(e,_)},subscribe:r,onceFinalized:t(D),onceExecuted:t(B),onceSealed:t(q)}}function H(){return(H=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 J(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 V(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 J(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?J(e,void 0):void 0}}(e)))return function(){return 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)}M.isUnknown=function(e){return e.status>=0},M.isPending=function(e){return e.status>=1},M.isFinalized=D,M.isExecuted=B,M.isSealed=q,M.isExpired=function(e){return 5===e.status};var G=function(){try{return Promise.resolve(N([getLatestBlock()])).then(L)}catch(e){return Promise.reject(e)}},W=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)}},K=((A={}).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(G()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve(W(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(G()).then(function(t){return e.put("hwm",t),Promise.resolve(N([getEvents(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(L(r)).then(function(r){for(var t,n=V(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(W(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)}},A[l.SUBSCRIBE]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(W(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)}},A[l.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},A),X=function(e){return l.spawn(K,e)};function $(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.style.position="fixed",r.style.top="0px",r.style.right="0px",r.style.left="0px",r.style.bottom="0px",r.style.height="100vh",r.style.width="100vw",r.style.display="block",r.style.background="rgba(0,0,0,0.25)",r.style.zIndex=2147483647,r.frameBorder="0",r.style.boxSizing="border-box",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}function Q(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}function Y(e){return $(Q(e).href)}var Z,ee={"HTTP/GET":"GET","HTTP/POST":"POST"},re=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},te=function(e,r){return"Missing "+re(e,r)+" in Composite Signature."},ne=function(e,r){return re(e,r)+" in Composit Signature did not match the requested "+e+"."},oe="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",ie=oe.length,ue={"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(Q(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=Y(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(Q(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(n){throw t(),se(e,r,n),n})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){try{var o=function(){for(var e="",r=32;r--;)e+=oe[Math.random()*ie|0];return e}(),i=Y(e),u=i[0],s=i[1];setTimeout(function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")},500),window.addEventListener("message",function e(r){var i=r.data;try{if("object"!=typeof i)return Promise.resolve();if("2.0"!==i.jsonrpc)return Promise.resolve();if(i.id!==o)return Promise.resolve();var u=i.result;return"APPROVED"===u.status?(window.removeEventListener("message",e),s(),t(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),n({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),n({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}})}catch(t){se(e,r,t),n({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function se(e,r,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},t)}function ce(e,r,t){if(!e.s){if(t instanceof le){if(!t.s)return void(t.o=ce.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(ce.bind(null,e,r),ce.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var ae=function(e){try{return we(),Promise.resolve(de()).then(function(r){function t(){return H({},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(ue[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),function(e,r){try{if(null==e.addr)throw new Error(te("addr","Address"));if(null==e.keyId)throw new Error(te("keyId"));if(null==e.signature)throw new Error(te("signature"));if(e.addr!==r.addr)throw new Error(ne("addr","Address"));if(e.keyId!==r.keyId)throw new Error(ne("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)}}(r,e),r})}catch(e){return Promise.reject(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 we(),Promise.resolve(Oe()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(N([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===i.keyId});o=r.sequenceNumber})}();return u&&u.then?u.then(t):t()})}catch(e){return Promise.reject(e)}},le=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{ce(n,1,i(this.v))}catch(e){ce(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ce(n,1,r?r(o):o):t?ce(n,1,t(o)):ce(n,2,o)}catch(e){ce(n,2,e)}},n},e}();function fe(e){return e instanceof le&&1&e.s}var de=function(){try{return Promise.resolve(new Promise(function(r){try{return we(),Promise.resolve(Oe()).then(function(t){return t.loggedIn?r(t):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var t,n,o,i=(n=(t={handshake:e,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",n),$(o.href))[1];window.addEventListener("message",function e(t){var n=t.data;try{if(n.type===Pe)return i(),window.removeEventListener("message",e),Promise.resolve();if(n.type!==ve)return Promise.resolve();i(),window.removeEventListener("message",e);var o="did:fcl:"+n.addr,u=n.addr,s=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=V(e.authorizations);!(t=n()).done;)r.push(H({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(H({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,i={addr:u,cid:o,loggedIn:!0,services:(t=s,n=e,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return l.send(me,pe,i),Promise.resolve(Oe()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},me="CURRENT_USER",he="CURRENT_USER/UPDATED",pe="SET_CURRENT_USER",ve="FCL::CHALLENGE::RESPONSE",Pe="FCL::CHALLENGE::CANCEL",ye='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',ge=function(e){try{return localStorage.setItem(me,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},be=((Z={})[l.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(ye),r=JSON.parse(localStorage.getItem(me));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(me),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)}},Z[l.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,he,e.all())},Z[l.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},Z.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Z[pe]=function(e,r,t){try{return e.merge(t),ge(e.all()),e.broadcast(he,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Z.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(ye)),ge(e.all()),e.broadcast(he,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Z.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:p.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},Z),we=function(){return l.spawn(be,me)};function Ee(){we(),l.send(me,"DEL_CURRENT_USER")}function Se(e){return function(){try{return we(),Promise.resolve(de()).then(function(){return l.send(me,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function je(e){we();var r=l.spawn(function(r){try{var t;return r.send(me,l.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(fe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!fe(i)){n=1;break}i=i.s}}var u=new le,s=ce.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):ce(u,1,i)})).then(void 0,s),u;function c(r){i=r;do{if(!(o=e())||fe(o)&&!o.v)return void ce(u,1,i);if(o.then)return void o.then(a).then(void 0,s);fe(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):ce(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(me,l.UNSUBSCRIBE),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return l.send(r,"@EXIT")}}function Oe(){return we(),l.send(me,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ke=function(){return{authenticate:de,unauthenticate:Ee,authorization:ae,param:Se,subscribe:je,snapshot:Oe}};Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),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,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return f.getTransactionStatus}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return d.getEvents}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return m.getLatestBlock}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return h.getAccount}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return v.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return v.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return v.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return P.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return P.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return y.transaction}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return g.script}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return b.ping}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return w.getBlockById}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return E.getBlockByHeight}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return S.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return S.authorizations}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return j.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return j.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return O.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return k.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return x.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return I.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return T.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return T.params}}),exports.VERSION="0.0.61-alpha.2",exports.authenticate=function(){return ke().authenticate()},exports.currentUser=ke,exports.decode=L,exports.events=function(e){return{subscribe:function(r){return l.subscriber(e,X,r)}}},exports.resolve=C,exports.send=N,exports.serialize=function(e){void 0===e&&(e=[]);try{var t=function(){return Promise.resolve(C(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(r.pipe(r.interaction(),e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},exports.tx=M,exports.unauthenticate=function(){return ke().unauthenticate()};
//# sourceMappingURL=fcl.js.map

@@ -1,2 +0,2 @@

import{config as t}from"@onflow/config";export{config}from"@onflow/config";import{pipe as e,interaction as n}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as o}from"@onflow/send";import{resolveRefBlockId as r}from"@onflow/sdk";import{resolveCadence as a}from"@onflow/sdk-resolve-cadence";import{resolveArguments as s}from"@onflow/sdk-resolve-arguments";import{resolveAccounts as i}from"@onflow/sdk-resolve-accounts";import{resolveSignatures as l}from"@onflow/sdk-resolve-signatures";import{resolveValidators as c}from"@onflow/sdk-resolve-validators";import{decodeResponse as u}from"@onflow/decode";import{subscriber as d,spawn as f,snapshoter as p,INIT as m,SUBSCRIBE as w,UPDATED as y,UNSUBSCRIBE as g,SNAPSHOT as h,send as E}from"@onflow/util-actor";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getAccount}from"@onflow/sdk-build-get-account";import{Identity as b}from"@onflow/types";export{display,sansPrefix,withPrefix}from"@onflow/util-address";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";t().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const k=async n=>e(n,[a,s,i,r({node:await t().get("accessNode.api")}),l,c]),S=async(t=[],r={})=>(Array.isArray(t)&&(t=e(n(),t)),o(await k(t),r)),v=async(t=[])=>(Array.isArray(t)&&(t=await e(n(),t)),JSON.stringify(await k(t))),T=async e=>{const n=await t().where(/^decoder\./),o=Object.fromEntries(Object.entries(n).map(([t,e])=>[t=`/${t.replace(/^decoder\./,"")}$/`,e]));return u(e,o)},P=async t=>{const e=await S([getTransactionStatus(t)]);return T(e)},I=t=>t.status>=4,R=t=>t.status>=3,x=t=>t.status>=2,A={[m]:async t=>{const e=await P(t.self());I(e)||setTimeout(()=>t.sendSelf("POLL"),2500),t.merge(e)},[w]:(t,e)=>{t.subscribe(e.from),t.send(e.from,y,t.all())},[g]:(t,e)=>{t.unsubscribe(e.from)},[h]:async(t,e)=>{e.reply(t.all())},POLL:async t=>{const e=await P(t.self());var n,o;I(e)||setTimeout(()=>t.sendSelf("POLL"),2500),n=t.all(),o=e,JSON.stringify(n)!==JSON.stringify(o)&&t.broadcast(y,e),t.merge(e)}},L=t=>{if("object"==typeof t&&(t=t.transactionId),null==t)throw new Error("transactionId required");return t},N=t=>f(A,L(t));function O(t){function e(e){return d(L(t),N,e)}function n(t){return function(n={}){const o=n.suppress||!1;return new Promise((n,r)=>{const a=e(e=>{e.statusCode&&!o?(r(e.errorMessage),a()):t(e)&&(n(e),a())})})}}return{snapshot:function(){return p(t,N)},subscribe:e,onceFinalized:n(x),onceExecuted:n(R),onceSealed:n(I)}}O.isUnknown=t=>t.status>=0,O.isPending=t=>t.status>=1,O.isFinalized=x,O.isExecuted=R,O.isSealed=I,O.isExpired=t=>5===t.status;const C=async()=>T(await S([getLatestBlock()])),U=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),D={TICK:async t=>{if(!t.hasSubs())return;let e=t.get("hwm");if(null==e)t.put("hwm",await C()),t.put("tick",await U(t));else{let n=await C();t.put("hwm",n);const o=await S([getEvents(t.self(),e.height,n.height-1)]),r=await T(o);for(let e of r)t.broadcast("UPDATED",e.data);t.put("tick",await U(t))}},[w]:async(t,e)=>{t.hasSubs()||t.put("tick",await U(t)),t.subscribe(e.from)},[g]:(t,e)=>{t.unsubscribe(e.from),t.hasSubs()||(clearTimeout(t.get("tick")),t.delete("tick"),t.delete("hwm"))}},_=t=>f(D,t);function z(t){return{subscribe:e=>d(t,_,e)}}function j(){return(j=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}function F(t){if(document.getElementById("FCL_IFRAME"))return;const e=document.createElement("iframe");return e.src=t,e.id="FCL_IFRAME",e.allow="usb *",e.style.position="fixed",e.style.top="0px",e.style.right="0px",e.style.left="0px",e.style.bottom="0px",e.style.height="100vh",e.style.width="100vw",e.style.display="block",e.style.background="rgba(0,0,0,0.25)",e.style.zIndex=2147483647,e.frameBorder="0",e.style.boxSizing="border-box",document.body.append(e),[e,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}async function B(t,e){if(null==t||null==e)return[];const n=new URL(t);n.searchParams.append("code",e);const o=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(t=>t.json());if(Array.isArray(o))return o;const r=[];if(Array.isArray(o.authorizations))for(let t of o.authorizations)r.push(j({type:"authz",keyId:o.keyId},t));return null!=o.provider&&r.push(j({type:"authn",id:"wallet-provider#authn"},o.provider)),r}function M(t=[],e=[]){return[...t,...e]}function J(t,e=!0){const n=new URL(t.endpoint);if(e)for(let[e,o]of Object.entries(t.params||{}))n.searchParams.append(e,o);return n}function H(t){return F(J(t).href)}const $={"HTTP/GET":"GET","HTTP/POST":"POST"},G=t=>new Promise(async(e,n)=>{const o=await fetch(J(t),{method:$[t.method],headers:{"Content-Type":"application/json"}}).then(t=>t.json());"APPROVED"===o.status?e(o.compositeSignature):"DECLINED"===o.status?n({status:o.status,reason:o.reason}):setTimeout(()=>{e(G(o.authorizationUpdates))},500)}),V=(t,e)=>null==e?`'${t}'`:`'${t}' (${e})`,q=(t,e)=>`Missing ${V(t,e)} in Composite Signature.`,W=(t,e)=>`${V(t,e)} in Composit Signature did not match the requested ${t}.`;var K="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",X=K.length;const Q={"HTTP/POST":async function(t,e){var n=()=>{},o=null;try{const r=await fetch(J(t),{method:"POST",headers:{"Content-Type":"application/json"},body:e?JSON.stringify(e):void 0}).then(t=>t.json());if(r.local&&r.local.length>0){const[t,e]=H(r.local[0]);n=e}o=await G(r.authorizationUpdates)}catch(o){throw n(),Y(t,e,o),o}finally{return n(),o}},"IFRAME/RPC":async function(t,e){return new Promise((n,o)=>{try{const r=function(){for(var t="",e=32;e--;)t+=K[Math.random()*X|0];return t}(),[a,s]=H(t);setTimeout(()=>{a.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:r,method:"fcl:sign",params:[e,t.params]})),"*")},500);const i=async({data:t})=>{if("object"!=typeof t)return;if("2.0"!==t.jsonrpc)return;if(t.id!==r)return;const e=t.result;"APPROVED"===e.status?(window.removeEventListener("message",i),s(),n(e.compositeSignature)):"DECLINED"===e.status?(window.removeEventListener("message",i),s(),o({status:e.status,reason:e.reason})):(window.removeEventListener("message",i),s(),o({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}))};window.addEventListener("message",i)}catch(n){Y(t,e,n),o({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}})}};function Y(t,e,n){console.error(`[${t.method}] Trouble talking to Wallet Provider`,"\n\n",{authz:t,signable:e},n)}const Z="CURRENT_USER",tt="CURRENT_USER/UPDATED",et='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',nt=async t=>(localStorage.setItem(Z,JSON.stringify(t)),t),ot={[m]:async t=>{t.merge(await(async()=>{const t=JSON.parse(et),e=JSON.parse(localStorage.getItem(Z));return null!=e&&t.VERSION!==e.VERSION?(localStorage.removeItem(Z),t):e||t})())},[w]:(t,e)=>{t.subscribe(e.from),t.send(e.from,tt,t.all())},[g]:(t,e)=>{t.unsubscribe(e.from)},SNAPSHOT:async(t,e)=>{e.reply(t.all())},SET_CURRENT_USER:async(t,e,n)=>{t.merge(n),nt(t.all()),t.broadcast(tt,t.all())},DEL_CURRENT_USER:async(t,e)=>{t.merge(JSON.parse(et)),nt(t.all()),t.broadcast(tt,t.all())},GET_AS_PARAM:async(t,e,{key:n})=>{e.reply({key:n,value:t.get("addr",null),xform:b})}},rt=()=>f(ot,Z);async function at(){return new Promise(async e=>{rt();const n=await ut();if(n.loggedIn)return e(n);const[o,r]=function({handshake:t,l6n:e}){var n=new URL(t);return n.searchParams.append("l6n",e),F(n.href)}({handshake:await t().get("challenge.handshake"),l6n:window.location.origin}),a=async({data:t})=>{if("FCL::CHALLENGE::CANCEL"===t.type)return r(),void window.removeEventListener("message",a);if("FCL::CHALLENGE::RESPONSE"!==t.type)return;r(),window.removeEventListener("message",a);const n={addr:t.addr,cid:"did:fcl:"+t.addr,loggedIn:!0,services:M(t.services||[],await B(t.hks,t.code))};E(Z,"SET_CURRENT_USER",n),e(await ut())};window.addEventListener("message",a)})}function st(){rt(),E(Z,"DEL_CURRENT_USER")}async function it(t){rt();const e=function(t=[],e){return t.find(t=>t.type===e)}((await at()).services,"authz");let n;return t.role.proposer&&(n=(await async function(){rt();const{addr:t}=await ut();if(null==t)throw new Error("No Flow Address for Current User");const{account:e}=await S([getAccount(t)]);return e}()).keys.find(t=>t.index===e.keyId).sequenceNumber),j({},t,{addr:e.addr,keyId:e.keyId,sequenceNum:n,signature:t.signature||null,signingFunction:async t=>async function(t,e){const n=await Q[t.method](t,e);return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),function(t,e){try{if(null==t.addr)throw new Error(q("addr","Address"));if(null==t.keyId)throw new Error(q("keyId"));if(null==t.signature)throw new Error(q("signature"));if(t.addr!==e.addr)throw new Error(W("addr","Address"));if(t.keyId!==e.keyId)throw new Error(W("keyId"))}catch(n){throw console.error(n,"\n\n",{"Composite Signature":t,"Authz Service":e}),new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+n.message)}}(n,t),n}(e,t),resolve:null,roles:t.roles})}function lt(t){return async function(){return rt(),await at(),E(Z,"GET_AS_PARAM",{key:t},{expectReply:!0,timeout:10})}}function ct(t){rt();const e=f(async e=>{for(e.send(Z,w);;){const n=await e.receive();if("@EXIT"===n.tag)return void e.send(Z,g);t(n.data)}});return()=>E(e,"@EXIT")}function ut(){return rt(),E(Z,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const dt=()=>({authenticate:at,unauthenticate:st,authorization:it,param:lt,subscribe:ct,snapshot:ut}),ft=()=>dt().authenticate(),pt=()=>dt().unauthenticate(),mt="0.0.61-alpha.1";export{mt as VERSION,ft as authenticate,dt as currentUser,T as decode,z as events,k as resolve,S as send,v as serialize,O as tx,pt as unauthenticate};
import{config as t}from"@onflow/config";export{config}from"@onflow/config";import{pipe as e,interaction as n}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as o}from"@onflow/send";import{resolveRefBlockId as r}from"@onflow/sdk";import{resolveCadence as a}from"@onflow/sdk-resolve-cadence";import{resolveArguments as s}from"@onflow/sdk-resolve-arguments";import{resolveAccounts as i}from"@onflow/sdk-resolve-accounts";import{resolveSignatures as l}from"@onflow/sdk-resolve-signatures";import{resolveValidators as c}from"@onflow/sdk-resolve-validators";import{decodeResponse as u}from"@onflow/decode";import{subscriber as d,spawn as f,snapshoter as p,INIT as m,SUBSCRIBE as w,UPDATED as y,UNSUBSCRIBE as g,SNAPSHOT as h,send as E}from"@onflow/util-actor";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getAccount}from"@onflow/sdk-build-get-account";import{Identity as b}from"@onflow/types";export{display,sansPrefix,withPrefix}from"@onflow/util-address";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";t().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const k=async n=>e(n,[a,s,i,r({node:await t().get("accessNode.api")}),l,c]),S=async(t=[],r={})=>(Array.isArray(t)&&(t=e(n(),t)),o(await k(t),r)),v=async(t=[])=>(Array.isArray(t)&&(t=await e(n(),t)),JSON.stringify(await k(t))),T=async e=>{const n=await t().where(/^decoder\./),o=Object.fromEntries(Object.entries(n).map(([t,e])=>[t=`/${t.replace(/^decoder\./,"")}$/`,e]));return u(e,o)},P=async t=>{const e=await S([getTransactionStatus(t)]);return T(e)},I=t=>t.status>=4,R=t=>t.status>=3,x=t=>t.status>=2,A={[m]:async t=>{const e=await P(t.self());I(e)||setTimeout(()=>t.sendSelf("POLL"),2500),t.merge(e)},[w]:(t,e)=>{t.subscribe(e.from),t.send(e.from,y,t.all())},[g]:(t,e)=>{t.unsubscribe(e.from)},[h]:async(t,e)=>{e.reply(t.all())},POLL:async t=>{const e=await P(t.self());var n,o;I(e)||setTimeout(()=>t.sendSelf("POLL"),2500),n=t.all(),o=e,JSON.stringify(n)!==JSON.stringify(o)&&t.broadcast(y,e),t.merge(e)}},L=t=>{if("object"==typeof t&&(t=t.transactionId),null==t)throw new Error("transactionId required");return t},N=t=>f(A,L(t));function O(t){function e(e){return d(L(t),N,e)}function n(t){return function(n={}){const o=n.suppress||!1;return new Promise((n,r)=>{const a=e(e=>{e.statusCode&&!o?(r(e.errorMessage),a()):t(e)&&(n(e),a())})})}}return{snapshot:function(){return p(t,N)},subscribe:e,onceFinalized:n(x),onceExecuted:n(R),onceSealed:n(I)}}O.isUnknown=t=>t.status>=0,O.isPending=t=>t.status>=1,O.isFinalized=x,O.isExecuted=R,O.isSealed=I,O.isExpired=t=>5===t.status;const C=async()=>T(await S([getLatestBlock()])),U=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),D={TICK:async t=>{if(!t.hasSubs())return;let e=t.get("hwm");if(null==e)t.put("hwm",await C()),t.put("tick",await U(t));else{let n=await C();t.put("hwm",n);const o=await S([getEvents(t.self(),e.height,n.height-1)]),r=await T(o);for(let e of r)t.broadcast("UPDATED",e.data);t.put("tick",await U(t))}},[w]:async(t,e)=>{t.hasSubs()||t.put("tick",await U(t)),t.subscribe(e.from)},[g]:(t,e)=>{t.unsubscribe(e.from),t.hasSubs()||(clearTimeout(t.get("tick")),t.delete("tick"),t.delete("hwm"))}},_=t=>f(D,t);function z(t){return{subscribe:e=>d(t,_,e)}}function j(){return(j=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}function F(t){if(document.getElementById("FCL_IFRAME"))return;const e=document.createElement("iframe");return e.src=t,e.id="FCL_IFRAME",e.allow="usb *",e.style.position="fixed",e.style.top="0px",e.style.right="0px",e.style.left="0px",e.style.bottom="0px",e.style.height="100vh",e.style.width="100vw",e.style.display="block",e.style.background="rgba(0,0,0,0.25)",e.style.zIndex=2147483647,e.frameBorder="0",e.style.boxSizing="border-box",document.body.append(e),[e,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}async function B(t,e){if(null==t||null==e)return[];const n=new URL(t);n.searchParams.append("code",e);const o=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(t=>t.json());if(Array.isArray(o))return o;const r=[];if(Array.isArray(o.authorizations))for(let t of o.authorizations)r.push(j({type:"authz",keyId:o.keyId},t));return null!=o.provider&&r.push(j({type:"authn",id:"wallet-provider#authn"},o.provider)),r}function M(t=[],e=[]){return[...t,...e]}function J(t,e=!0){const n=new URL(t.endpoint);if(e)for(let[e,o]of Object.entries(t.params||{}))n.searchParams.append(e,o);return n}function H(t){return F(J(t).href)}const $={"HTTP/GET":"GET","HTTP/POST":"POST"},G=t=>new Promise(async(e,n)=>{const o=await fetch(J(t),{method:$[t.method],headers:{"Content-Type":"application/json"}}).then(t=>t.json());"APPROVED"===o.status?e(o.compositeSignature):"DECLINED"===o.status?n({status:o.status,reason:o.reason}):setTimeout(()=>{e(G(o.authorizationUpdates))},500)}),V=(t,e)=>null==e?`'${t}'`:`'${t}' (${e})`,q=(t,e)=>`Missing ${V(t,e)} in Composite Signature.`,W=(t,e)=>`${V(t,e)} in Composit Signature did not match the requested ${t}.`;var K="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",X=K.length;const Q={"HTTP/POST":async function(t,e){var n=()=>{},o=null;try{const r=await fetch(J(t),{method:"POST",headers:{"Content-Type":"application/json"},body:e?JSON.stringify(e):void 0}).then(t=>t.json());if(r.local&&r.local.length>0){const[t,e]=H(r.local[0]);n=e}o=await G(r.authorizationUpdates)}catch(o){throw n(),Y(t,e,o),o}finally{return n(),o}},"IFRAME/RPC":async function(t,e){return new Promise((n,o)=>{try{const r=function(){for(var t="",e=32;e--;)t+=K[Math.random()*X|0];return t}(),[a,s]=H(t);setTimeout(()=>{a.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:r,method:"fcl:sign",params:[e,t.params]})),"*")},500);const i=async({data:t})=>{if("object"!=typeof t)return;if("2.0"!==t.jsonrpc)return;if(t.id!==r)return;const e=t.result;"APPROVED"===e.status?(window.removeEventListener("message",i),s(),n(e.compositeSignature)):"DECLINED"===e.status?(window.removeEventListener("message",i),s(),o({status:e.status,reason:e.reason})):(window.removeEventListener("message",i),s(),o({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}))};window.addEventListener("message",i)}catch(n){Y(t,e,n),o({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}})}};function Y(t,e,n){console.error(`[${t.method}] Trouble talking to Wallet Provider`,"\n\n",{authz:t,signable:e},n)}const Z="CURRENT_USER",tt="CURRENT_USER/UPDATED",et='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',nt=async t=>(localStorage.setItem(Z,JSON.stringify(t)),t),ot={[m]:async t=>{t.merge(await(async()=>{const t=JSON.parse(et),e=JSON.parse(localStorage.getItem(Z));return null!=e&&t.VERSION!==e.VERSION?(localStorage.removeItem(Z),t):e||t})())},[w]:(t,e)=>{t.subscribe(e.from),t.send(e.from,tt,t.all())},[g]:(t,e)=>{t.unsubscribe(e.from)},SNAPSHOT:async(t,e)=>{e.reply(t.all())},SET_CURRENT_USER:async(t,e,n)=>{t.merge(n),nt(t.all()),t.broadcast(tt,t.all())},DEL_CURRENT_USER:async(t,e)=>{t.merge(JSON.parse(et)),nt(t.all()),t.broadcast(tt,t.all())},GET_AS_PARAM:async(t,e,{key:n})=>{e.reply({key:n,value:t.get("addr",null),xform:b})}},rt=()=>f(ot,Z);async function at(){return new Promise(async e=>{rt();const n=await ut();if(n.loggedIn)return e(n);const[o,r]=function({handshake:t,l6n:e}){var n=new URL(t);return n.searchParams.append("l6n",e),F(n.href)}({handshake:await t().get("challenge.handshake"),l6n:window.location.origin}),a=async({data:t})=>{if("FCL::CHALLENGE::CANCEL"===t.type)return r(),void window.removeEventListener("message",a);if("FCL::CHALLENGE::RESPONSE"!==t.type)return;r(),window.removeEventListener("message",a);const n={addr:t.addr,cid:"did:fcl:"+t.addr,loggedIn:!0,services:M(t.services||[],await B(t.hks,t.code))};E(Z,"SET_CURRENT_USER",n),e(await ut())};window.addEventListener("message",a)})}function st(){rt(),E(Z,"DEL_CURRENT_USER")}async function it(t){rt();const e=function(t=[],e){return t.find(t=>t.type===e)}((await at()).services,"authz");let n;return t.role.proposer&&(n=(await async function(){rt();const{addr:t}=await ut();if(null==t)throw new Error("No Flow Address for Current User");const{account:e}=await S([getAccount(t)]);return e}()).keys.find(t=>t.index===e.keyId).sequenceNumber),j({},t,{addr:e.addr,keyId:e.keyId,sequenceNum:n,signature:t.signature||null,signingFunction:async t=>async function(t,e){const n=await Q[t.method](t,e);return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),function(t,e){try{if(null==t.addr)throw new Error(q("addr","Address"));if(null==t.keyId)throw new Error(q("keyId"));if(null==t.signature)throw new Error(q("signature"));if(t.addr!==e.addr)throw new Error(W("addr","Address"));if(t.keyId!==e.keyId)throw new Error(W("keyId"))}catch(n){throw console.error(n,"\n\n",{"Composite Signature":t,"Authz Service":e}),new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+n.message)}}(n,t),n}(e,t),resolve:null,roles:t.roles})}function lt(t){return async function(){return rt(),await at(),E(Z,"GET_AS_PARAM",{key:t},{expectReply:!0,timeout:10})}}function ct(t){rt();const e=f(async e=>{for(e.send(Z,w);;){const n=await e.receive();if("@EXIT"===n.tag)return void e.send(Z,g);t(n.data)}});return()=>E(e,"@EXIT")}function ut(){return rt(),E(Z,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const dt=()=>({authenticate:at,unauthenticate:st,authorization:it,param:lt,subscribe:ct,snapshot:ut}),ft=()=>dt().authenticate(),pt=()=>dt().unauthenticate(),mt="0.0.61-alpha.2";export{mt as VERSION,ft as authenticate,dt as currentUser,T as decode,z as events,k as resolve,S as send,v as serialize,O as tx,pt as unauthenticate};
//# sourceMappingURL=fcl.modern.js.map

@@ -1,2 +0,2 @@

import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{pipe as r,interaction as t}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as n}from"@onflow/send";import{resolveRefBlockId as o}from"@onflow/sdk";import{resolveCadence as i}from"@onflow/sdk-resolve-cadence";import{resolveArguments as s}from"@onflow/sdk-resolve-arguments";import{resolveAccounts as u}from"@onflow/sdk-resolve-accounts";import{resolveSignatures as a}from"@onflow/sdk-resolve-signatures";import{resolveValidators as c}from"@onflow/sdk-resolve-validators";import{decodeResponse as l}from"@onflow/decode";import{INIT as f,SUBSCRIBE as d,UPDATED as m,UNSUBSCRIBE as h,SNAPSHOT as v,subscriber as p,spawn as P,snapshoter as y,send as g}from"@onflow/util-actor";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getAccount}from"@onflow/sdk-build-get-account";import{Identity as w}from"@onflow/types";export{display,sansPrefix,withPrefix}from"@onflow/util-address";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var b,E,S=function(t){try{return Promise.resolve(e().get("accessNode.api")).then(function(e){return r(t,[i,s,u,o({node:e}),a,c])})}catch(e){return Promise.reject(e)}},k=function(e,o){void 0===e&&(e=[]),void 0===o&&(o={});try{return Array.isArray(e)&&(e=r(t(),e)),Promise.resolve(S(e)).then(function(e){return n(e,o)})}catch(e){return Promise.reject(e)}},j=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(S(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(r(t(),e)).then(function(r){e=r})}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}},T=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)}},A=function(e){try{return Promise.resolve(k([getTransactionStatus(e)])).then(T)}catch(e){return Promise.reject(e)}},I=function(e){return e.status>=4},x=function(e){return e.status>=3},R=function(e){return e.status>=2},L=((b={})[f]=function(e){try{return Promise.resolve(A(e.self())).then(function(r){I(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},b[d]=function(e,r){e.subscribe(r.from),e.send(r.from,m,e.all())},b[h]=function(e,r){e.unsubscribe(r.from)},b[v]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},b.POLL=function(e){try{return Promise.resolve(A(e.self())).then(function(r){var t,n;I(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(m,r),e.merge(r)})}catch(e){return Promise.reject(e)}},b),O=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},N=function(e){return P(L,O(e))};function C(e){function r(r){return p(O(e),N,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 y(e,N)},subscribe:r,onceFinalized:t(R),onceExecuted:t(x),onceSealed:t(I)}}function D(){return(D=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 U(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 z(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 U(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)?U(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)}C.isUnknown=function(e){return e.status>=0},C.isPending=function(e){return e.status>=1},C.isFinalized=R,C.isExecuted=x,C.isSealed=I,C.isExpired=function(e){return 5===e.status};var F=function(){try{return Promise.resolve(k([getLatestBlock()])).then(T)}catch(e){return Promise.reject(e)}},_=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)}},M=((E={}).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(F()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve(_(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(F()).then(function(t){return e.put("hwm",t),Promise.resolve(k([getEvents(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(T(r)).then(function(r){for(var t,n=z(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(_(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)}},E[d]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(_(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)}},E[h]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},E),B=function(e){return P(M,e)};function J(e){return{subscribe:function(r){return p(e,B,r)}}}function H(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.style.position="fixed",r.style.top="0px",r.style.right="0px",r.style.left="0px",r.style.bottom="0px",r.style.height="100vh",r.style.width="100vw",r.style.display="block",r.style.background="rgba(0,0,0,0.25)",r.style.zIndex=2147483647,r.frameBorder="0",r.style.boxSizing="border-box",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}function G(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}function V(e){return H(G(e).href)}var q,W={"HTTP/GET":"GET","HTTP/POST":"POST"},K=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},X=function(e,r){return"Missing "+K(e,r)+" in Composite Signature."},$=function(e,r){return K(e,r)+" in Composit Signature did not match the requested "+e+"."},Q="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",Y=Q.length,Z={"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(G(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=V(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(G(r),{method:W[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(n){throw t(),ee(e,r,n),n})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){try{var o=function(){for(var e="",r=32;r--;)e+=Q[Math.random()*Y|0];return e}(),i=V(e),s=i[0],u=i[1];setTimeout(function(){s.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")},500),window.addEventListener("message",function e(r){var i=r.data;try{if("object"!=typeof i)return Promise.resolve();if("2.0"!==i.jsonrpc)return Promise.resolve();if(i.id!==o)return Promise.resolve();var s=i.result;return"APPROVED"===s.status?(window.removeEventListener("message",e),u(),t(s.compositeSignature)):"DECLINED"===s.status?(window.removeEventListener("message",e),u(),n({status:s.status,reason:s.reason})):(window.removeEventListener("message",e),u(),n({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}})}catch(t){ee(e,r,t),n({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function ee(e,r,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},t)}function re(e,r,t){if(!e.s){if(t instanceof ne){if(!t.s)return void(t.o=re.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(re.bind(null,e,r),re.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var te=function(e){try{return he(),Promise.resolve(ie()).then(function(r){function t(){return D({},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(Z[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),function(e,r){try{if(null==e.addr)throw new Error(X("addr","Address"));if(null==e.keyId)throw new Error(X("keyId"));if(null==e.signature)throw new Error(X("signature"));if(e.addr!==r.addr)throw new Error($("addr","Address"));if(e.keyId!==r.keyId)throw new Error($("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)}}(r,e),r})}catch(e){return Promise.reject(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})),s=function(){if(e.role.proposer)return Promise.resolve(function(){try{return he(),Promise.resolve(ye()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(k([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===i.keyId});o=r.sequenceNumber})}();return s&&s.then?s.then(t):t()})}catch(e){return Promise.reject(e)}},ne=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{re(n,1,i(this.v))}catch(e){re(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?re(n,1,r?r(o):o):t?re(n,1,t(o)):re(n,2,o)}catch(e){re(n,2,e)}},n},e}();function oe(e){return e instanceof ne&&1&e.s}var ie=function(){try{return Promise.resolve(new Promise(function(r){try{return he(),Promise.resolve(ye()).then(function(t){return t.loggedIn?r(t):Promise.resolve(e().get("challenge.handshake")).then(function(e){var t,n,o,i=(n=(t={handshake:e,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",n),H(o.href))[1];window.addEventListener("message",function e(t){var n=t.data;try{if(n.type===le)return i(),window.removeEventListener("message",e),Promise.resolve();if(n.type!==ce)return Promise.resolve();i(),window.removeEventListener("message",e);var o="did:fcl:"+n.addr,s=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=z(e.authorizations);!(t=n()).done;)r.push(D({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(D({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,i={addr:s,cid:o,loggedIn:!0,services:(t=u,n=e,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return g(se,ae,i),Promise.resolve(ye()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},se="CURRENT_USER",ue="CURRENT_USER/UPDATED",ae="SET_CURRENT_USER",ce="FCL::CHALLENGE::RESPONSE",le="FCL::CHALLENGE::CANCEL",fe='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',de=function(e){try{return localStorage.setItem(se,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},me=((q={})[f]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(fe),r=JSON.parse(localStorage.getItem(se));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(se),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)}},q[d]=function(e,r){e.subscribe(r.from),e.send(r.from,ue,e.all())},q[h]=function(e,r){e.unsubscribe(r.from)},q.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},q[ae]=function(e,r,t){try{return e.merge(t),de(e.all()),e.broadcast(ue,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},q.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(fe)),de(e.all()),e.broadcast(ue,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},q.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:w}),Promise.resolve()}catch(e){return Promise.reject(e)}},q),he=function(){return P(me,se)};function ve(){he(),g(se,"DEL_CURRENT_USER")}function pe(e){return function(){try{return he(),Promise.resolve(ie()).then(function(){return g(se,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Pe(e){he();var r=P(function(r){try{var t;return r.send(se,d),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(oe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!oe(i)){n=1;break}i=i.s}}var s=new ne,u=re.bind(null,s,2);return(0===n?o.then(c):1===n?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):re(s,1,i)})).then(void 0,u),s;function a(r){i=r;do{if(!(o=e())||oe(o)&&!o.v)return void re(s,1,i);if(o.then)return void o.then(c).then(void 0,u);oe(i=t())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,u)}function c(e){e?(i=t())&&i.then?i.then(a).then(void 0,u):a(i):re(s,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(se,h),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return g(r,"@EXIT")}}function ye(){return he(),g(se,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ge=function(){return{authenticate:ie,unauthenticate:ve,authorization:te,param:pe,subscribe:Pe,snapshot:ye}},we=function(){return ge().authenticate()},be=function(){return ge().unauthenticate()},Ee="0.0.61-alpha.1";export{Ee as VERSION,we as authenticate,ge as currentUser,T as decode,J as events,S as resolve,k as send,j as serialize,C as tx,be as unauthenticate};
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{pipe as r,interaction as t}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as n}from"@onflow/send";import{resolveRefBlockId as o}from"@onflow/sdk";import{resolveCadence as i}from"@onflow/sdk-resolve-cadence";import{resolveArguments as s}from"@onflow/sdk-resolve-arguments";import{resolveAccounts as u}from"@onflow/sdk-resolve-accounts";import{resolveSignatures as a}from"@onflow/sdk-resolve-signatures";import{resolveValidators as c}from"@onflow/sdk-resolve-validators";import{decodeResponse as l}from"@onflow/decode";import{INIT as f,SUBSCRIBE as d,UPDATED as m,UNSUBSCRIBE as h,SNAPSHOT as v,subscriber as p,spawn as P,snapshoter as y,send as g}from"@onflow/util-actor";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";export{getAccount}from"@onflow/sdk-build-get-account";import{Identity as w}from"@onflow/types";export{display,sansPrefix,withPrefix}from"@onflow/util-address";export{template as cadence,template as cdc}from"@onflow/util-template";export{transaction}from"@onflow/sdk-build-transaction";export{script}from"@onflow/sdk-build-script";export{ping}from"@onflow/sdk-build-ping";export{getBlockById}from"@onflow/sdk-build-get-block-by-id";export{getBlockByHeight}from"@onflow/sdk-build-get-block-by-height";export{authorization,authorizations}from"@onflow/sdk-build-authorizations";export{arg,args}from"@onflow/sdk-build-arguments";export{proposer}from"@onflow/sdk-build-proposer";export{payer}from"@onflow/sdk-build-payer";export{limit}from"@onflow/sdk-build-limit";export{ref}from"@onflow/sdk-build-ref";export{param,params}from"@onflow/sdk-build-params";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var b,E,S=function(t){try{return Promise.resolve(e().get("accessNode.api")).then(function(e){return r(t,[i,s,u,o({node:e}),a,c])})}catch(e){return Promise.reject(e)}},k=function(e,o){void 0===e&&(e=[]),void 0===o&&(o={});try{return Array.isArray(e)&&(e=r(t(),e)),Promise.resolve(S(e)).then(function(e){return n(e,o)})}catch(e){return Promise.reject(e)}},j=function(e){void 0===e&&(e=[]);try{var n=function(){return Promise.resolve(S(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(r(t(),e)).then(function(r){e=r})}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}},T=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)}},A=function(e){try{return Promise.resolve(k([getTransactionStatus(e)])).then(T)}catch(e){return Promise.reject(e)}},I=function(e){return e.status>=4},x=function(e){return e.status>=3},R=function(e){return e.status>=2},L=((b={})[f]=function(e){try{return Promise.resolve(A(e.self())).then(function(r){I(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},b[d]=function(e,r){e.subscribe(r.from),e.send(r.from,m,e.all())},b[h]=function(e,r){e.unsubscribe(r.from)},b[v]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},b.POLL=function(e){try{return Promise.resolve(A(e.self())).then(function(r){var t,n;I(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(m,r),e.merge(r)})}catch(e){return Promise.reject(e)}},b),O=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},N=function(e){return P(L,O(e))};function C(e){function r(r){return p(O(e),N,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 y(e,N)},subscribe:r,onceFinalized:t(R),onceExecuted:t(x),onceSealed:t(I)}}function D(){return(D=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 U(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 z(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 U(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)?U(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)}C.isUnknown=function(e){return e.status>=0},C.isPending=function(e){return e.status>=1},C.isFinalized=R,C.isExecuted=x,C.isSealed=I,C.isExpired=function(e){return 5===e.status};var F=function(){try{return Promise.resolve(k([getLatestBlock()])).then(T)}catch(e){return Promise.reject(e)}},_=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)}},M=((E={}).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(F()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve(_(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(F()).then(function(t){return e.put("hwm",t),Promise.resolve(k([getEvents(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(T(r)).then(function(r){for(var t,n=z(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(_(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)}},E[d]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(_(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)}},E[h]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},E),B=function(e){return P(M,e)};function J(e){return{subscribe:function(r){return p(e,B,r)}}}function H(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.style.position="fixed",r.style.top="0px",r.style.right="0px",r.style.left="0px",r.style.bottom="0px",r.style.height="100vh",r.style.width="100vw",r.style.display="block",r.style.background="rgba(0,0,0,0.25)",r.style.zIndex=2147483647,r.frameBorder="0",r.style.boxSizing="border-box",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}function G(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}function V(e){return H(G(e).href)}var q,W={"HTTP/GET":"GET","HTTP/POST":"POST"},K=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},X=function(e,r){return"Missing "+K(e,r)+" in Composite Signature."},$=function(e,r){return K(e,r)+" in Composit Signature did not match the requested "+e+"."},Q="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",Y=Q.length,Z={"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(G(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=V(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(G(r),{method:W[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(n){throw t(),ee(e,r,n),n})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){try{var o=function(){for(var e="",r=32;r--;)e+=Q[Math.random()*Y|0];return e}(),i=V(e),s=i[0],u=i[1];setTimeout(function(){s.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")},500),window.addEventListener("message",function e(r){var i=r.data;try{if("object"!=typeof i)return Promise.resolve();if("2.0"!==i.jsonrpc)return Promise.resolve();if(i.id!==o)return Promise.resolve();var s=i.result;return"APPROVED"===s.status?(window.removeEventListener("message",e),u(),t(s.compositeSignature)):"DECLINED"===s.status?(window.removeEventListener("message",e),u(),n({status:s.status,reason:s.reason})):(window.removeEventListener("message",e),u(),n({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}})}catch(t){ee(e,r,t),n({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function ee(e,r,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},t)}function re(e,r,t){if(!e.s){if(t instanceof ne){if(!t.s)return void(t.o=re.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(re.bind(null,e,r),re.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var te=function(e){try{return he(),Promise.resolve(ie()).then(function(r){function t(){return D({},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(Z[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),function(e,r){try{if(null==e.addr)throw new Error(X("addr","Address"));if(null==e.keyId)throw new Error(X("keyId"));if(null==e.signature)throw new Error(X("signature"));if(e.addr!==r.addr)throw new Error($("addr","Address"));if(e.keyId!==r.keyId)throw new Error($("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)}}(r,e),r})}catch(e){return Promise.reject(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})),s=function(){if(e.role.proposer)return Promise.resolve(function(){try{return he(),Promise.resolve(ye()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(k([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===i.keyId});o=r.sequenceNumber})}();return s&&s.then?s.then(t):t()})}catch(e){return Promise.reject(e)}},ne=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{re(n,1,i(this.v))}catch(e){re(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?re(n,1,r?r(o):o):t?re(n,1,t(o)):re(n,2,o)}catch(e){re(n,2,e)}},n},e}();function oe(e){return e instanceof ne&&1&e.s}var ie=function(){try{return Promise.resolve(new Promise(function(r){try{return he(),Promise.resolve(ye()).then(function(t){return t.loggedIn?r(t):Promise.resolve(e().get("challenge.handshake")).then(function(e){var t,n,o,i=(n=(t={handshake:e,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",n),H(o.href))[1];window.addEventListener("message",function e(t){var n=t.data;try{if(n.type===le)return i(),window.removeEventListener("message",e),Promise.resolve();if(n.type!==ce)return Promise.resolve();i(),window.removeEventListener("message",e);var o="did:fcl:"+n.addr,s=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=z(e.authorizations);!(t=n()).done;)r.push(D({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(D({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,i={addr:s,cid:o,loggedIn:!0,services:(t=u,n=e,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return g(se,ae,i),Promise.resolve(ye()).then(function(e){r(e)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},se="CURRENT_USER",ue="CURRENT_USER/UPDATED",ae="SET_CURRENT_USER",ce="FCL::CHALLENGE::RESPONSE",le="FCL::CHALLENGE::CANCEL",fe='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',de=function(e){try{return localStorage.setItem(se,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},me=((q={})[f]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(fe),r=JSON.parse(localStorage.getItem(se));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(se),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)}},q[d]=function(e,r){e.subscribe(r.from),e.send(r.from,ue,e.all())},q[h]=function(e,r){e.unsubscribe(r.from)},q.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},q[ae]=function(e,r,t){try{return e.merge(t),de(e.all()),e.broadcast(ue,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},q.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(fe)),de(e.all()),e.broadcast(ue,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},q.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:w}),Promise.resolve()}catch(e){return Promise.reject(e)}},q),he=function(){return P(me,se)};function ve(){he(),g(se,"DEL_CURRENT_USER")}function pe(e){return function(){try{return he(),Promise.resolve(ie()).then(function(){return g(se,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function Pe(e){he();var r=P(function(r){try{var t;return r.send(se,d),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(oe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!oe(i)){n=1;break}i=i.s}}var s=new ne,u=re.bind(null,s,2);return(0===n?o.then(c):1===n?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):re(s,1,i)})).then(void 0,u),s;function a(r){i=r;do{if(!(o=e())||oe(o)&&!o.v)return void re(s,1,i);if(o.then)return void o.then(c).then(void 0,u);oe(i=t())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,u)}function c(e){e?(i=t())&&i.then?i.then(a).then(void 0,u):a(i):re(s,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(se,h),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return g(r,"@EXIT")}}function ye(){return he(),g(se,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ge=function(){return{authenticate:ie,unauthenticate:ve,authorization:te,param:pe,subscribe:Pe,snapshot:ye}},we=function(){return ge().authenticate()},be=function(){return ge().unauthenticate()},Ee="0.0.61-alpha.2";export{Ee as VERSION,we as authenticate,ge as currentUser,T as decode,J as events,S as resolve,k as send,j as serialize,C as tx,be as unauthenticate};
//# sourceMappingURL=fcl.module.js.map

@@ -1,2 +0,2 @@

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@onflow/config"),require("@onflow/interaction"),require("@onflow/send"),require("@onflow/sdk"),require("@onflow/sdk-resolve-cadence"),require("@onflow/sdk-resolve-arguments"),require("@onflow/sdk-resolve-accounts"),require("@onflow/sdk-resolve-signatures"),require("@onflow/sdk-resolve-validators"),require("@onflow/decode"),require("@onflow/util-actor"),require("@onflow/sdk-build-transaction-status"),require("@onflow/sdk-build-get-events"),require("@onflow/sdk-build-get-latest-block"),require("@onflow/sdk-build-get-account"),require("@onflow/types"),require("@onflow/util-address"),require("@onflow/util-template"),require("@onflow/sdk-build-transaction"),require("@onflow/sdk-build-script"),require("@onflow/sdk-build-ping"),require("@onflow/sdk-build-get-block-by-id"),require("@onflow/sdk-build-get-block-by-height"),require("@onflow/sdk-build-authorizations"),require("@onflow/sdk-build-arguments"),require("@onflow/sdk-build-proposer"),require("@onflow/sdk-build-payer"),require("@onflow/sdk-build-limit"),require("@onflow/sdk-build-ref"),require("@onflow/sdk-build-params")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/interaction","@onflow/send","@onflow/sdk","@onflow/sdk-resolve-cadence","@onflow/sdk-resolve-arguments","@onflow/sdk-resolve-accounts","@onflow/sdk-resolve-signatures","@onflow/sdk-resolve-validators","@onflow/decode","@onflow/util-actor","@onflow/sdk-build-transaction-status","@onflow/sdk-build-get-events","@onflow/sdk-build-get-latest-block","@onflow/sdk-build-get-account","@onflow/types","@onflow/util-address","@onflow/util-template","@onflow/sdk-build-transaction","@onflow/sdk-build-script","@onflow/sdk-build-ping","@onflow/sdk-build-get-block-by-id","@onflow/sdk-build-get-block-by-height","@onflow/sdk-build-authorizations","@onflow/sdk-build-arguments","@onflow/sdk-build-proposer","@onflow/sdk-build-payer","@onflow/sdk-build-limit","@onflow/sdk-build-ref","@onflow/sdk-build-params"],r):r((e=e||self).fcl={},e.config,e.interaction,e.send$1,e.sdk,e.sdkResolveCadence,e.sdkResolveArguments,e.sdkResolveAccounts,e.sdkResolveSignatures,e.sdkResolveValidators,e.decode$1,e.utilActor,e.sdkBuildTransactionStatus,e.sdkBuildGetEvents,e.sdkBuildGetLatestBlock,e.sdkBuildGetAccount,e.types,e.utilAddress,e.utilTemplate,e.sdkBuildTransaction,e.sdkBuildScript,e.sdkBuildPing,e.sdkBuildGetBlockById,e.sdkBuildGetBlockByHeight,e.sdkBuildAuthorizations,e.sdkBuildArguments,e.sdkBuildProposer,e.sdkBuildPayer,e.sdkBuildLimit,e.sdkBuildRef,e.sdkBuildParams)}(this,function(e,r,t,n,o,i,u,s,c,a,l,f,d,m,h,v,p,g,y,b,P,w,k,E,S,j,O,I,B,A,R){r.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T,C,N=function(e){try{return Promise.resolve(r.config().get("accessNode.api")).then(function(r){return t.pipe(e,[i.resolveCadence,u.resolveArguments,s.resolveAccounts,o.resolveRefBlockId({node:r}),c.resolveSignatures,a.resolveValidators])})}catch(e){return Promise.reject(e)}},L=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Array.isArray(e)&&(e=t.pipe(t.interaction(),e)),Promise.resolve(N(e)).then(function(e){return n.send(e,r)})}catch(e){return Promise.reject(e)}},U=function(e){try{return Promise.resolve(r.config().where(/^decoder\./)).then(function(r){var t=Object.fromEntries(Object.entries(r).map(function(e){var r=e[0],t=e[1];return[r="/"+r.replace(/^decoder\./,"")+"$/",t]}));return l.decodeResponse(e,t)})}catch(e){return Promise.reject(e)}},q=function(e){try{return Promise.resolve(L([getTransactionStatus(e)])).then(U)}catch(e){return Promise.reject(e)}},x=function(e){return e.status>=4},D=function(e){return e.status>=3},z=function(e){return e.status>=2},F=((T={})[f.INIT]=function(e){try{return Promise.resolve(q(e.self())).then(function(r){x(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},T[f.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,f.UPDATED,e.all())},T[f.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},T[f.SNAPSHOT]=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(q(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(f.UPDATED,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},G=function(e){return f.spawn(F,_(e))};function M(e){function r(r){return f.subscriber(_(e),G,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 f.snapshoter(e,G)},subscribe:r,onceFinalized:t(z),onceExecuted:t(D),onceSealed:t(x)}}function H(){return(H=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 J(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 V(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 J(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?J(e,void 0):void 0}}(e)))return function(){return 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)}M.isUnknown=function(e){return e.status>=0},M.isPending=function(e){return e.status>=1},M.isFinalized=z,M.isExecuted=D,M.isSealed=x,M.isExpired=function(e){return 5===e.status};var W=function(){try{return Promise.resolve(L([getLatestBlock()])).then(U)}catch(e){return Promise.reject(e)}},$=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)}},K=((C={}).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(W()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve($(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(W()).then(function(t){return e.put("hwm",t),Promise.resolve(L([getEvents(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(U(r)).then(function(r){for(var t,n=V(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve($(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)}},C[f.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)).then(function(t){r.call(e,"tick",t)})}}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},C[f.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},C),X=function(e){return f.spawn(K,e)};function Q(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.style.position="fixed",r.style.top="0px",r.style.right="0px",r.style.left="0px",r.style.bottom="0px",r.style.height="100vh",r.style.width="100vw",r.style.display="block",r.style.background="rgba(0,0,0,0.25)",r.style.zIndex=2147483647,r.frameBorder="0",r.style.boxSizing="border-box",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}function Y(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}function Z(e){return Q(Y(e).href)}var ee,re={"HTTP/GET":"GET","HTTP/POST":"POST"},te=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},ne=function(e,r){return"Missing "+te(e,r)+" in Composite Signature."},oe=function(e,r){return te(e,r)+" in Composit Signature did not match the requested "+e+"."},ie="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",ue=ie.length,se={"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(Y(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=Z(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(Y(r),{method:re[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(n){throw t(),ce(e,r,n),n})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){try{var o=function(){for(var e="",r=32;r--;)e+=ie[Math.random()*ue|0];return e}(),i=Z(e),u=i[0],s=i[1];setTimeout(function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")},500),window.addEventListener("message",function e(r){var i=r.data;try{if("object"!=typeof i)return Promise.resolve();if("2.0"!==i.jsonrpc)return Promise.resolve();if(i.id!==o)return Promise.resolve();var u=i.result;return"APPROVED"===u.status?(window.removeEventListener("message",e),s(),t(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),n({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),n({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}})}catch(t){ce(e,r,t),n({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function ce(e,r,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},t)}function ae(e,r,t){if(!e.s){if(t instanceof fe){if(!t.s)return void(t.o=ae.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(ae.bind(null,e,r),ae.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var le=function(e){try{return ke(),Promise.resolve(me()).then(function(r){function t(){return H({},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(se[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),function(e,r){try{if(null==e.addr)throw new Error(ne("addr","Address"));if(null==e.keyId)throw new Error(ne("keyId"));if(null==e.signature)throw new Error(ne("signature"));if(e.addr!==r.addr)throw new Error(oe("addr","Address"));if(e.keyId!==r.keyId)throw new Error(oe("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)}}(r,e),r})}catch(e){return Promise.reject(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 ke(),Promise.resolve(Oe()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(L([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===i.keyId});o=r.sequenceNumber})}();return u&&u.then?u.then(t):t()})}catch(e){return Promise.reject(e)}},fe=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{ae(n,1,i(this.v))}catch(e){ae(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ae(n,1,r?r(o):o):t?ae(n,1,t(o)):ae(n,2,o)}catch(e){ae(n,2,e)}},n},e}();function de(e){return e instanceof fe&&1&e.s}var me=function(){try{return Promise.resolve(new Promise(function(e){try{return ke(),Promise.resolve(Oe()).then(function(t){return t.loggedIn?e(t):Promise.resolve(r.config().get("challenge.handshake")).then(function(r){var t,n,o,i=(n=(t={handshake:r,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",n),Q(o.href))[1];window.addEventListener("message",function r(t){var n=t.data;try{if(n.type===ye)return i(),window.removeEventListener("message",r),Promise.resolve();if(n.type!==ge)return Promise.resolve();i(),window.removeEventListener("message",r);var o="did:fcl:"+n.addr,u=n.addr,s=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=V(e.authorizations);!(t=n()).done;)r.push(H({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(H({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(n.hks,n.code)).then(function(r){var t,n,i={addr:u,cid:o,loggedIn:!0,services:(t=s,n=r,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return f.send(he,pe,i),Promise.resolve(Oe()).then(function(r){e(r)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},he="CURRENT_USER",ve="CURRENT_USER/UPDATED",pe="SET_CURRENT_USER",ge="FCL::CHALLENGE::RESPONSE",ye="FCL::CHALLENGE::CANCEL",be='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',Pe=function(e){try{return localStorage.setItem(he,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},we=((ee={})[f.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(be),r=JSON.parse(localStorage.getItem(he));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(he),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)}},ee[f.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,ve,e.all())},ee[f.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},ee.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ee[pe]=function(e,r,t){try{return e.merge(t),Pe(e.all()),e.broadcast(ve,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ee.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(be)),Pe(e.all()),e.broadcast(ve,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ee.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:p.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},ee),ke=function(){return f.spawn(we,he)};function Ee(){ke(),f.send(he,"DEL_CURRENT_USER")}function Se(e){return function(){try{return ke(),Promise.resolve(me()).then(function(){return f.send(he,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function je(e){ke();var r=f.spawn(function(r){try{var t;return r.send(he,f.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(de(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!de(i)){n=1;break}i=i.s}}var u=new fe,s=ae.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):ae(u,1,i)})).then(void 0,s),u;function c(r){i=r;do{if(!(o=e())||de(o)&&!o.v)return void ae(u,1,i);if(o.then)return void o.then(a).then(void 0,s);de(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):ae(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(he,f.UNSUBSCRIBE),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return f.send(r,"@EXIT")}}function Oe(){return ke(),f.send(he,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ie=function(){return{authenticate:me,unauthenticate:Ee,authorization:le,param:Se,subscribe:je,snapshot:Oe}};Object.defineProperty(e,"config",{enumerable:!0,get:function(){return r.config}}),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,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return m.getEvents}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return h.getLatestBlock}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return v.getAccount}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return g.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return g.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return g.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return y.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return y.template}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return b.transaction}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return P.script}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return w.ping}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return k.getBlockById}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return E.getBlockByHeight}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return S.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return S.authorizations}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return j.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return j.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return O.proposer}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return I.payer}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return B.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return A.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return R.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return R.params}}),e.VERSION="0.0.61-alpha.1",e.authenticate=function(){return Ie().authenticate()},e.currentUser=Ie,e.decode=U,e.events=function(e){return{subscribe:function(r){return f.subscriber(e,X,r)}}},e.resolve=N,e.send=L,e.serialize=function(e){void 0===e&&(e=[]);try{var r=function(){return Promise.resolve(N(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},e.tx=M,e.unauthenticate=function(){return Ie().unauthenticate()}});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@onflow/config"),require("@onflow/interaction"),require("@onflow/send"),require("@onflow/sdk"),require("@onflow/sdk-resolve-cadence"),require("@onflow/sdk-resolve-arguments"),require("@onflow/sdk-resolve-accounts"),require("@onflow/sdk-resolve-signatures"),require("@onflow/sdk-resolve-validators"),require("@onflow/decode"),require("@onflow/util-actor"),require("@onflow/sdk-build-transaction-status"),require("@onflow/sdk-build-get-events"),require("@onflow/sdk-build-get-latest-block"),require("@onflow/sdk-build-get-account"),require("@onflow/types"),require("@onflow/util-address"),require("@onflow/util-template"),require("@onflow/sdk-build-transaction"),require("@onflow/sdk-build-script"),require("@onflow/sdk-build-ping"),require("@onflow/sdk-build-get-block-by-id"),require("@onflow/sdk-build-get-block-by-height"),require("@onflow/sdk-build-authorizations"),require("@onflow/sdk-build-arguments"),require("@onflow/sdk-build-proposer"),require("@onflow/sdk-build-payer"),require("@onflow/sdk-build-limit"),require("@onflow/sdk-build-ref"),require("@onflow/sdk-build-params")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/interaction","@onflow/send","@onflow/sdk","@onflow/sdk-resolve-cadence","@onflow/sdk-resolve-arguments","@onflow/sdk-resolve-accounts","@onflow/sdk-resolve-signatures","@onflow/sdk-resolve-validators","@onflow/decode","@onflow/util-actor","@onflow/sdk-build-transaction-status","@onflow/sdk-build-get-events","@onflow/sdk-build-get-latest-block","@onflow/sdk-build-get-account","@onflow/types","@onflow/util-address","@onflow/util-template","@onflow/sdk-build-transaction","@onflow/sdk-build-script","@onflow/sdk-build-ping","@onflow/sdk-build-get-block-by-id","@onflow/sdk-build-get-block-by-height","@onflow/sdk-build-authorizations","@onflow/sdk-build-arguments","@onflow/sdk-build-proposer","@onflow/sdk-build-payer","@onflow/sdk-build-limit","@onflow/sdk-build-ref","@onflow/sdk-build-params"],r):r((e=e||self).fcl={},e.config,e.interaction,e.send$1,e.sdk,e.sdkResolveCadence,e.sdkResolveArguments,e.sdkResolveAccounts,e.sdkResolveSignatures,e.sdkResolveValidators,e.decode$1,e.utilActor,e.sdkBuildTransactionStatus,e.sdkBuildGetEvents,e.sdkBuildGetLatestBlock,e.sdkBuildGetAccount,e.types,e.utilAddress,e.utilTemplate,e.sdkBuildTransaction,e.sdkBuildScript,e.sdkBuildPing,e.sdkBuildGetBlockById,e.sdkBuildGetBlockByHeight,e.sdkBuildAuthorizations,e.sdkBuildArguments,e.sdkBuildProposer,e.sdkBuildPayer,e.sdkBuildLimit,e.sdkBuildRef,e.sdkBuildParams)}(this,function(e,r,t,n,o,i,u,s,c,a,l,f,d,m,h,v,p,g,y,b,P,w,k,E,S,j,O,I,B,A,R){r.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T,C,N=function(e){try{return Promise.resolve(r.config().get("accessNode.api")).then(function(r){return t.pipe(e,[i.resolveCadence,u.resolveArguments,s.resolveAccounts,o.resolveRefBlockId({node:r}),c.resolveSignatures,a.resolveValidators])})}catch(e){return Promise.reject(e)}},L=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Array.isArray(e)&&(e=t.pipe(t.interaction(),e)),Promise.resolve(N(e)).then(function(e){return n.send(e,r)})}catch(e){return Promise.reject(e)}},U=function(e){try{return Promise.resolve(r.config().where(/^decoder\./)).then(function(r){var t=Object.fromEntries(Object.entries(r).map(function(e){var r=e[0],t=e[1];return[r="/"+r.replace(/^decoder\./,"")+"$/",t]}));return l.decodeResponse(e,t)})}catch(e){return Promise.reject(e)}},q=function(e){try{return Promise.resolve(L([getTransactionStatus(e)])).then(U)}catch(e){return Promise.reject(e)}},x=function(e){return e.status>=4},D=function(e){return e.status>=3},z=function(e){return e.status>=2},F=((T={})[f.INIT]=function(e){try{return Promise.resolve(q(e.self())).then(function(r){x(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},T[f.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,f.UPDATED,e.all())},T[f.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},T[f.SNAPSHOT]=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(q(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(f.UPDATED,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},G=function(e){return f.spawn(F,_(e))};function M(e){function r(r){return f.subscriber(_(e),G,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 f.snapshoter(e,G)},subscribe:r,onceFinalized:t(z),onceExecuted:t(D),onceSealed:t(x)}}function H(){return(H=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 J(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 V(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 J(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?J(e,void 0):void 0}}(e)))return function(){return 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)}M.isUnknown=function(e){return e.status>=0},M.isPending=function(e){return e.status>=1},M.isFinalized=z,M.isExecuted=D,M.isSealed=x,M.isExpired=function(e){return 5===e.status};var W=function(){try{return Promise.resolve(L([getLatestBlock()])).then(U)}catch(e){return Promise.reject(e)}},$=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)}},K=((C={}).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(W()).then(function(r){t.call(e,"hwm",r);var n=e.put;return Promise.resolve($(e)).then(function(r){n.call(e,"tick",r)})})}return Promise.resolve(W()).then(function(t){return e.put("hwm",t),Promise.resolve(L([getEvents(e.self(),r.height,t.height-1)])).then(function(r){return Promise.resolve(U(r)).then(function(r){for(var t,n=V(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve($(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)}},C[f.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)).then(function(t){r.call(e,"tick",t)})}}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},C[f.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},C),X=function(e){return f.spawn(K,e)};function Q(e){if(!document.getElementById("FCL_IFRAME")){var r=document.createElement("iframe");return r.src=e,r.id="FCL_IFRAME",r.allow="usb *",r.style.position="fixed",r.style.top="0px",r.style.right="0px",r.style.left="0px",r.style.bottom="0px",r.style.height="100vh",r.style.width="100vw",r.style.display="block",r.style.background="rgba(0,0,0,0.25)",r.style.zIndex=2147483647,r.frameBorder="0",r.style.boxSizing="border-box",document.body.append(r),[r,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}function Y(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}function Z(e){return Q(Y(e).href)}var ee,re={"HTTP/GET":"GET","HTTP/POST":"POST"},te=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},ne=function(e,r){return"Missing "+te(e,r)+" in Composite Signature."},oe=function(e,r){return te(e,r)+" in Composit Signature did not match the requested "+e+"."},ie="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",ue=ie.length,se={"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(Y(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=Z(e.local[0]);t=r[1]}return Promise.resolve(function e(r){return new Promise(function(t,n){try{return Promise.resolve(fetch(Y(r),{method:re[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(n){throw t(),ce(e,r,n),n})},function(){return t(),n}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(t,n){try{var o=function(){for(var e="",r=32;r--;)e+=ie[Math.random()*ue|0];return e}(),i=Z(e),u=i[0],s=i[1];setTimeout(function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")},500),window.addEventListener("message",function e(r){var i=r.data;try{if("object"!=typeof i)return Promise.resolve();if("2.0"!==i.jsonrpc)return Promise.resolve();if(i.id!==o)return Promise.resolve();var u=i.result;return"APPROVED"===u.status?(window.removeEventListener("message",e),s(),t(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),n({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),n({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}})}catch(t){ce(e,r,t),n({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function ce(e,r,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},t)}function ae(e,r,t){if(!e.s){if(t instanceof fe){if(!t.s)return void(t.o=ae.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(ae.bind(null,e,r),ae.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}var le=function(e){try{return ke(),Promise.resolve(me()).then(function(r){function t(){return H({},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(se[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),function(e,r){try{if(null==e.addr)throw new Error(ne("addr","Address"));if(null==e.keyId)throw new Error(ne("keyId"));if(null==e.signature)throw new Error(ne("signature"));if(e.addr!==r.addr)throw new Error(oe("addr","Address"));if(e.keyId!==r.keyId)throw new Error(oe("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)}}(r,e),r})}catch(e){return Promise.reject(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 ke(),Promise.resolve(Oe()).then(function(e){var r=e.addr;if(null==r)throw new Error("No Flow Address for Current User");return Promise.resolve(L([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===i.keyId});o=r.sequenceNumber})}();return u&&u.then?u.then(t):t()})}catch(e){return Promise.reject(e)}},fe=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{ae(n,1,i(this.v))}catch(e){ae(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ae(n,1,r?r(o):o):t?ae(n,1,t(o)):ae(n,2,o)}catch(e){ae(n,2,e)}},n},e}();function de(e){return e instanceof fe&&1&e.s}var me=function(){try{return Promise.resolve(new Promise(function(e){try{return ke(),Promise.resolve(Oe()).then(function(t){return t.loggedIn?e(t):Promise.resolve(r.config().get("challenge.handshake")).then(function(r){var t,n,o,i=(n=(t={handshake:r,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",n),Q(o.href))[1];window.addEventListener("message",function r(t){var n=t.data;try{if(n.type===ye)return i(),window.removeEventListener("message",r),Promise.resolve();if(n.type!==ge)return Promise.resolve();i(),window.removeEventListener("message",r);var o="did:fcl:"+n.addr,u=n.addr,s=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=V(e.authorizations);!(t=n()).done;)r.push(H({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(H({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(n.hks,n.code)).then(function(r){var t,n,i={addr:u,cid:o,loggedIn:!0,services:(t=s,n=r,void 0===t&&(t=[]),void 0===n&&(n=[]),[].concat(t,n))};return f.send(he,pe,i),Promise.resolve(Oe()).then(function(r){e(r)})})}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},he="CURRENT_USER",ve="CURRENT_USER/UPDATED",pe="SET_CURRENT_USER",ge="FCL::CHALLENGE::RESPONSE",ye="FCL::CHALLENGE::CANCEL",be='{\n "VERSION": "0.2.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "services":[]\n}',Pe=function(e){try{return localStorage.setItem(he,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},we=((ee={})[f.INIT]=function(e){try{var r=e.merge;return Promise.resolve(function(){try{var e=JSON.parse(be),r=JSON.parse(localStorage.getItem(he));return null!=r&&e.VERSION!==r.VERSION?(localStorage.removeItem(he),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)}},ee[f.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,ve,e.all())},ee[f.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},ee.SNAPSHOT=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ee[pe]=function(e,r,t){try{return e.merge(t),Pe(e.all()),e.broadcast(ve,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ee.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(be)),Pe(e.all()),e.broadcast(ve,e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ee.GET_AS_PARAM=function(e,r,t){var n=t.key;try{return r.reply({key:n,value:e.get("addr",null),xform:p.Identity}),Promise.resolve()}catch(e){return Promise.reject(e)}},ee),ke=function(){return f.spawn(we,he)};function Ee(){ke(),f.send(he,"DEL_CURRENT_USER")}function Se(e){return function(){try{return ke(),Promise.resolve(me()).then(function(){return f.send(he,"GET_AS_PARAM",{key:e},{expectReply:!0,timeout:10})})}catch(e){return Promise.reject(e)}}}function je(e){ke();var r=f.spawn(function(r){try{var t;return r.send(he,f.SUBSCRIBE),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(de(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!de(i)){n=1;break}i=i.s}}var u=new fe,s=ae.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):ae(u,1,i)})).then(void 0,s),u;function c(r){i=r;do{if(!(o=e())||de(o)&&!o.v)return void ae(u,1,i);if(o.then)return void o.then(a).then(void 0,s);de(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):ae(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(r.receive()).then(function(n){if("@EXIT"===n.tag)return r.send(he,f.UNSUBSCRIBE),void(t=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return f.send(r,"@EXIT")}}function Oe(){return ke(),f.send(he,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Ie=function(){return{authenticate:me,unauthenticate:Ee,authorization:le,param:Se,subscribe:je,snapshot:Oe}};Object.defineProperty(e,"config",{enumerable:!0,get:function(){return r.config}}),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,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return m.getEvents}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return h.getLatestBlock}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return v.getAccount}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return g.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return g.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return g.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return y.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return y.template}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return b.transaction}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return P.script}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return w.ping}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return k.getBlockById}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return E.getBlockByHeight}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return S.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return S.authorizations}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return j.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return j.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return O.proposer}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return I.payer}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return B.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return A.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return R.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return R.params}}),e.VERSION="0.0.61-alpha.2",e.authenticate=function(){return Ie().authenticate()},e.currentUser=Ie,e.decode=U,e.events=function(e){return{subscribe:function(r){return f.subscriber(e,X,r)}}},e.resolve=N,e.send=L,e.serialize=function(e){void 0===e&&(e=[]);try{var r=function(){return Promise.resolve(N(e)).then(JSON.stringify)},n=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(r){e=r})}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},e.tx=M,e.unauthenticate=function(){return Ie().unauthenticate()}});
//# sourceMappingURL=fcl.umd.js.map
{
"name": "@onflow/fcl",
"version": "0.0.61-alpha.1",
"version": "0.0.61-alpha.2",
"description": "Flow Client Library",

@@ -40,3 +40,3 @@ "license": "Apache-2.0",

"@onflow/interaction": "0.0.10",
"@onflow/sdk": "0.0.35",
"@onflow/sdk": "0.0.37",
"@onflow/sdk-build-arguments": "0.0.0",

@@ -63,3 +63,3 @@ "@onflow/sdk-build-authorizations": "0.0.0",

"@onflow/sdk-resolve-cadence": "0.0.0",
"@onflow/sdk-resolve-signatures": "0.0.0",
"@onflow/sdk-resolve-signatures": "0.0.1",
"@onflow/sdk-resolve-validators": "0.0.0",

@@ -66,0 +66,0 @@ "@onflow/send": "0.0.22",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc