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

@onflow/fcl

Package Overview
Dependencies
Maintainers
8
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.67-alpha.2 to 0.0.67-alpha.3

4

CHANGELOG.md

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

### 0.0.67-alpha.3 - 2020-11-17
- 2020-11-17 -- Fix issue where validation for composite signature for keyId of zero was counted as false
### 0.0.67-alpha.2 - 2020-11-17

@@ -7,0 +11,0 @@

2

dist/fcl.js

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

var e=require("@onflow/config"),r=require("@onflow/util-invariant"),n=require("@onflow/interaction"),t=require("@onflow/sdk-latest-block"),o=require("@onflow/util-address"),i=require("@onflow/sdk-account"),u=require("@onflow/rlp"),s=require("@onflow/sdk-resolve"),a=require("@onflow/util-actor"),c=require("@onflow/sdk-send"),f=require("@onflow/sdk-decode"),l=require("@onflow/sdk-build-transaction-status"),d=require("@onflow/sdk-build-get-events"),p=require("@onflow/util-uid"),h=require("@onflow/util-template"),m=require("@onflow/sdk-build-transaction"),v=require("@onflow/sdk-build-script"),y=require("@onflow/sdk-build-ping"),g=require("@onflow/sdk-build-get-account"),P=require("@onflow/sdk-build-get-latest-block"),b=require("@onflow/sdk-build-get-block-by-id"),w=require("@onflow/sdk-build-get-block-by-height"),S=require("@onflow/sdk-build-authorizations"),k=require("@onflow/sdk-build-arguments"),E=require("@onflow/sdk-build-proposer"),x=require("@onflow/sdk-build-payer"),I=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),O=require("@onflow/sdk-build-params");function T(){return(T=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function A(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function N(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return A(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R=function(e,r){return Buffer.from(e.padStart(2*r,0),"hex")},L=function(e){return R(e,8)},B=function(e){return Buffer.from(JSON.stringify(e),"utf8")},C=function(e){return u.encode(e).toString("hex")},U=function(e){return D(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(B),(r=e.refBlock,R(r,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var r,n},q=function(e){var r=z(e);return e.payloadSigs.map(function(e){return{signerIndex:r.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,r){return e.signerIndex>r.signerIndex?1:e.signerIndex<r.signerIndex?-1:e.keyId>r.keyId?1:e.keyId<r.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(r=e.sig,Buffer.from(r,"hex"))];var r})},z=function(e){var r=new Map,n=0,t=function(e){r.has(e)||(r.set(e,n),n++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),r},D=function(e){M.forEach(function(r){return W(e,r)}),K.forEach(function(r){return W(e.proposalKey,r,"proposalKey")})},F=function(e){return"number"==typeof e},_=function(e){return"string"==typeof e},J=function(e){return null!==e&&"object"==typeof e},H=function(e){return J(e)&&e instanceof Array},M=[{name:"script",check:_},{name:"arguments",check:H},{name:"refBlock",check:_,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:J},{name:"payer",check:_},{name:"authorizers",check:H}],K=[{name:"address",check:_},{name:"keyId",check:F},{name:"sequenceNum",check:F}],V=[{name:"payloadSigs",check:H}],G=[{name:"address",check:_},{name:"keyId",check:F},{name:"sig",check:_}],W=function(e,r,n,t){var o=r.name,i=r.check,u=r.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw Y(o,n,t);if(!i(e[o]))throw Z(o,n,t)},X=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},Y=function(e,r,n){return new Error("Missing field "+X(e,r,n))},Z=function(e,r,n){return new Error("Invalid field "+X(e,r,n))},$="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Q(e,r,n){if(!e.s){if(n instanceof ee){if(!n.s)return void(n.o=Q.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Q.bind(null,e,r),Q.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var ee=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Q(t,1,i(this.v))}catch(e){Q(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Q(t,1,r?r(o):o):n?Q(t,1,n(o)):Q(t,2,o)}catch(e){Q(t,2,e)}},t},e}();function re(e){return e instanceof ee&&1&e.s}var ne=function(e){return"string"==typeof e},te=function(e){return"function"==typeof e};function oe(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:o.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:o.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(r){return o.sansPrefix(e.accounts[r].addr)}).reduce(function(e,r){return e.find(function(e){return e===r})?e:[].concat(e,[r])},[])}}e.config().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(u){function s(){function u(){function u(){function t(){var r=function(){if(n.isTransaction(e)){console.log("RESOLVE SIGNATURES START",e);var r=new Set(e.authorizations);r.add(e.proposer),r.delete(e.payer),r=Array.from(r);var t=new Set([e.payer]);t=Array.from(t),console.log("SIGNATORIES",{insideSigners:r,outsideSigners:t});var i=(u=oe(e),C(U(u)));return Promise.resolve(Promise.all(r.map(function(r){try{var n=e.accounts[r];return null!=n.signature?Promise.resolve():Promise.resolve(n.signingFunction({message:i,addr:o.sansPrefix(n.addr),keyId:n.keyId,roles:n.role,interaction:e})).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}))).then(function(){var n=function(e){return C(function(e){return function(e){V.forEach(function(r){return W(e,r)}),e.payloadSigs.forEach(function(e,r){G.forEach(function(n){return W(e,n,"payloadSigs",r)})})}(e),[U(e),q(e)]}(e))}(T({},oe(e),{payloadSigs:r.map(function(r){return e.accounts[r].signature})}));return Promise.resolve(Promise.all(t.map(function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:n,addr:o.sansPrefix(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}))).then(function(){console.log("RESOLVE SIGNATURES END",e)})})}var u}();return r&&r.then?r.then(function(){return e}):e}var u=function(){if(n.isTransaction(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});r.invariant(t,"Transactions require a proposer");var o=function(){if(null===t.sequenceNum)return Promise.resolve(i.account(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[t.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return u&&u.then?u.then(t):t()}n.isTransaction(e);var s=function(){if(n.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(t.latestBlock()).then(function(r){e.message.refBlock=r.id})}();return s&&s.then?s.then(u):u()}if(n.isTransaction(e)||n.isScript(e))for(var s=0,a=Object.entries(e.arguments);s<a.length;s++){var c=a[s];e.arguments[c[0]].asArgument=(r.invariant(null!=typeof(f=c[1]).xform,"No type specified for argument: "+f.value),te(f.xform)?f.xform(f.value):te(f.xform.asArgument)?f.xform.asArgument(f.value):void r.invariant(!1,"Invalid Argument",f))}var f,l=function(){if(n.isTransaction(e)){var r=function(){e.accounts=t},t={},o=function(e,r,n){if("function"==typeof e[$]){var t,o,i,u=e[$]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!re(n))return void n.then(e,i||(i=Q.bind(null,o=new ee,2)));n=n.v}o?Q(o,1,n):o=n}catch(e){Q(o||(o=new ee),2,e)}}(),u.return){var s=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!re(u))return void u.then(n,o||(o=Q.bind(null,t=new ee,2)));u=u.v}t?Q(t,1,u):t=u}catch(e){Q(t||(t=new ee),2,e)}}(),t}(a,function(e){return r(a[e])})}(Object.entries(e.accounts),function(r){var n=r[0],o=r[1];function i(){t[n]=t[n]||o,t[n].role.proposer=t[n].role.proposer||o.role.proposer,t[n].role.payer=t[n].role.payer||o.role.payer,t[n].role.authorizer=t[n].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=n),e.payer===u&&(e.payer=n),e.authorizations=e.authorizations.map(function(e){return e===u?n:e})}var u=n,s=function(){if(te(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){n=(o=e).tempId})}();return s&&s.then?s.then(i):i()});return o&&o.then?o.then(r):r()}}();return l&&l.then?l.then(u):u()}e=u;var a=function(){if(n.isTransaction(e)||n.isScript(e)){var t=function(){r.invariant(ne(o),"Cadence needs to be a string at this point."),e.message.cadence=o},o=n.get(e,"ix.cadence");r.invariant(te(o)||ne(o),"Cadence needs to be a function or a string.");var i=function(){if(te(o))return Promise.resolve(o({})).then(function(e){o=e})}();return i&&i.then?i.then(t):t()}}();return a&&a.then?a.then(s):s()})}catch(e){return Promise.reject(e)}});var ie,ue,se=function(e){try{return Promise.resolve(c.send([l.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},ae=function(e){return e.status>=4},ce=function(e){return e.status>=3},fe=function(e){return e.status>=2},le=((ie={})[a.INIT]=function(e){try{return Promise.resolve(se(e.self())).then(function(r){ae(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},ie[a.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,a.UPDATED,e.all())},ie[a.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},ie[a.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ie.POLL=function(e){try{return Promise.resolve(se(e.self())).then(function(r){var n,t;ae(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(a.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},ie),de=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},pe=function(e){return a.spawn(le,de(e))};function he(e){function r(r){return a.subscriber(de(e),pe,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return a.snapshoter(e,pe)},subscribe:r,onceFinalized:n(fe),onceExecuted:n(ce),onceSealed:n(ae)}}he.isUnknown=function(e){return e.status>=0},he.isPending=function(e){return e.status>=1},he.isFinalized=fe,he.isExecuted=ce,he.isSealed=ae,he.isExpired=function(e){return 5===e.status};var me=function(r){try{var n=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},ve=((ue={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(t.latestBlock()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(me(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(c.send([getEvents(e.self(),r.height,n.height-1)]).then(f.decode)).then(function(r){for(var n,t=N(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(me(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ue[a.SUBSCRIBE]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(me(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},ue[a.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ue),ye=function(e){return a.spawn(ve,e)};function ge(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()}]}}var Pe={"@type":"Service","@vsn":"1.0.0"},be={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},Se={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},Pe,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function ke(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ee(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function xe(e,r){void 0===r&&(r=!0);var n=new URL(e.endpoint);if(r)for(var t=0,o=Object.entries(e.params||{});t<o.length;t++){var i=o[t];n.searchParams.append(i[0],i[1])}return n}function Ie(e){return ge(xe(e).href)}var je,Oe={"HTTP/GET":"GET","HTTP/POST":"POST"},Te=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},Ae=function(e,r){return"Missing "+Te(e,r)+" in Composite Signature."},Ne=function(e,r){return Te(e,r)+" in Composit Signature did not match the requested "+e+"."},Re={"HTTP/POST":function(e,r){try{var n=function(){},t=null;return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r()}return n&&n.then?n.then(r,r):r()}(function(){return function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){return Promise.resolve(fetch(xe(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0}).then(function(e){return e.json()})).then(function(e){if(console.log("RESP",e),e.local&&e.local.length>0){var r=Ie(e.local[0]);n=r[1]}return Promise.resolve(function e(r){return new Promise(function(n,t){try{return Promise.resolve(fetch(xe(r),{method:Oe[r.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(r){"APPROVED"===r.status?n(r.compositeSignature):"DECLINED"===r.status?t({status:r.status,reason:r.reason}):setTimeout(function(){n(e(r.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})})},function(t){throw n(),Le(e,r,t),t})},function(){return n(),t}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(n,t){try{var o=p.uid(),i=Ie(e),u=i[0],s=i[1],a=function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")};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(),n(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),t({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),t({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}}),new Promise(function(e){window.addEventListener("message",n);var r=setTimeout(function(){window.removeEventListener("message",n),a(),e()},5e3);function n(t){"FCL::AUTHZ_READY"===t.data.type&&(clearTimeout(r),window.removeEventListener("message",n),a(),e())}})}catch(n){Le(e,r,n),t({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function Le(e,r,n){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},n)}function Be(e,r,n){if(!e.s){if(n instanceof Ue){if(!n.s)return void(n.o=Be.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Be.bind(null,e,r),Be.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Ce=function(e){try{return Xe(),Promise.resolve(ze()).then(function(n){Ee(n.services,"authn");var t=Ee(n.services,"authz");return Ee(n.services,"pre-authz"),T({},e,{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(function(e,n){try{return Promise.resolve(Re[e.method](e,n)).then(function(n){return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),n.addr=o.sansPrefix(n.addr),function(e,n){try{var t={compSig:e,authz:n};r.invariant(e.addr,Ae("addr","Address"),t),r.invariant(e.keyId,Ae("keyId"),t),r.invariant(e.signature,Ae("signature"),t),r.invariant(e.keyId===n.identity.keyId,Ne("keyId"),t),r.invariant(o.sansPrefix(e.addr)===o.sansPrefix(n.identity.address),Ne("addr","Address"),t)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(n,e),n})}catch(e){return Promise.reject(e)}}(t,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ue=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Be(t,1,i(this.v))}catch(e){Be(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Be(t,1,r?r(o):o):n?Be(t,1,n(o)):Be(t,2,o)}catch(e){Be(t,2,e)}},t},e}();function qe(e){return e instanceof Ue&&1&e.s}var ze=function(){try{return Promise.resolve(new Promise(function(r){try{return Xe(),Promise.resolve(Qe()).then(function(n){return n.loggedIn&&Ye(n)?r(n):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var n,t,i,u=(t=(n={handshake:e,l6n:window.location.origin}).l6n,(i=new URL(n.handshake)).searchParams.append("l6n",t),ge(i.href))[1];window.addEventListener("message",function e(n){var t=n.data;try{return t.type===Me||t.type===Je?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==He?Promise.resolve():(u(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=N(e.authorizations);!(n=t()).done;)r.push(T({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(T({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,i,u=(t=r,i=n,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(r){return function(e,r){try{var n=Se[e.type](e,r);return console.log(e.type,{normalized:n,service:e}),n}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)});console.log("BUILD USER",u);var s=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,u);return T({},we,{addr:o.withPrefix(e.addr),cid:ke(s),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return a.send(De,_e,e),Promise.resolve(Qe()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},De="CURRENT_USER",Fe="CURRENT_USER/UPDATED",_e="SET_CURRENT_USER",Je="FCL::CANCEL",He="FCL::CHALLENGE::RESPONSE",Me="FCL::CHALLENGE::CANCEL",Ke='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ve=function(e){try{return sessionStorage.setItem(De,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ge=function(){return e.config().get("persistSession",!0)},We=((je={})[a.INIT]=function(e){try{return e.merge(JSON.parse(Ke)),Promise.resolve(Ge()).then(function(r){var n=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(Ke),r=JSON.parse(sessionStorage.getItem(De));return null!=r&&e["@vsn"]!==r["@vsn"]?(sessionStorage.removeItem(De),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){Ye(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},je[a.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,Fe,T({},e.all()))},je[a.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},je.SNAPSHOT=function(e,r){try{return r.reply(T({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},je[_e]=function(e,r,n){try{return e.merge(n),Promise.resolve(Ge()).then(function(r){r&&Ve(e.all()),e.broadcast(Fe,T({},e.all()))})}catch(e){return Promise.reject(e)}},je.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(Ke)),Promise.resolve(Ge()).then(function(r){r&&Ve(e.all()),e.broadcast(Fe,T({},e.all()))})}catch(e){return Promise.reject(e)}},je),Xe=function(){return a.spawn(We,De)};function Ye(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ze(){Xe(),a.send(De,"DEL_CURRENT_USER")}function $e(e){Xe();var r=a.spawn(function(r){try{var n;return r.send(De,a.SUBSCRIBE),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(qe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!qe(i)){t=1;break}i=i.s}}var u=new Ue,s=Be.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Be(u,1,i)})).then(void 0,s),u;function a(r){i=r;do{if(!(o=e())||qe(o)&&!o.v)return void Be(u,1,i);if(o.then)return void o.then(c).then(void 0,s);qe(i=n())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function c(e){e?(i=n())&&i.then?i.then(a).then(void 0,s):a(i):Be(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(De,a.UNSUBSCRIBE),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return a.send(r,"@EXIT")}}function Qe(){return Xe(),a.send(De,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var er=function(){return{authenticate:ze,unauthenticate:Ze,authorization:Ce,subscribe:$e,snapshot:Qe}},rr=er().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return i.account}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return c.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return l.getTransactionStatus}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return d.getEvents}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return m.transaction}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return v.script}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return y.ping}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return g.getAccount}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return b.getBlockById}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return w.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 k.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return k.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return E.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return x.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return I.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return j.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return O.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return O.params}}),exports.VERSION="0.0.67-alpha.2",exports.authenticate=function(){return er().authenticate()},exports.authz=rr,exports.currentUser=er,exports.events=function(e){return{subscribe:function(r){return a.subscriber(e,ye,r)}}},exports.logIn=function(){return er().authenticate()},exports.reauthenticate=function(){er().unauthenticate(),er().authenticate()},exports.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var t=function(){return Promise.resolve(s.resolve(r)(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(r){e=r})}();return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},exports.signUp=function(){return er().authenticate()},exports.tx=he,exports.unauthenticate=function(){return er().unauthenticate()};
var e=require("@onflow/config"),r=require("@onflow/util-invariant"),n=require("@onflow/interaction"),t=require("@onflow/sdk-latest-block"),o=require("@onflow/util-address"),i=require("@onflow/sdk-account"),u=require("@onflow/rlp"),s=require("@onflow/sdk-resolve"),a=require("@onflow/util-actor"),c=require("@onflow/sdk-send"),f=require("@onflow/sdk-decode"),l=require("@onflow/sdk-build-transaction-status"),d=require("@onflow/sdk-build-get-events"),p=require("@onflow/util-uid"),h=require("@onflow/util-template"),m=require("@onflow/sdk-build-transaction"),v=require("@onflow/sdk-build-script"),y=require("@onflow/sdk-build-ping"),g=require("@onflow/sdk-build-get-account"),P=require("@onflow/sdk-build-get-latest-block"),b=require("@onflow/sdk-build-get-block-by-id"),w=require("@onflow/sdk-build-get-block-by-height"),S=require("@onflow/sdk-build-authorizations"),k=require("@onflow/sdk-build-arguments"),E=require("@onflow/sdk-build-proposer"),x=require("@onflow/sdk-build-payer"),I=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),O=require("@onflow/sdk-build-params");function T(){return(T=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function A(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function N(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return A(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R=function(e,r){return Buffer.from(e.padStart(2*r,0),"hex")},L=function(e){return R(e,8)},B=function(e){return Buffer.from(JSON.stringify(e),"utf8")},C=function(e){return u.encode(e).toString("hex")},U=function(e){return D(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(B),(r=e.refBlock,R(r,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var r,n},q=function(e){var r=z(e);return e.payloadSigs.map(function(e){return{signerIndex:r.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,r){return e.signerIndex>r.signerIndex?1:e.signerIndex<r.signerIndex?-1:e.keyId>r.keyId?1:e.keyId<r.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(r=e.sig,Buffer.from(r,"hex"))];var r})},z=function(e){var r=new Map,n=0,t=function(e){r.has(e)||(r.set(e,n),n++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),r},D=function(e){M.forEach(function(r){return W(e,r)}),K.forEach(function(r){return W(e.proposalKey,r,"proposalKey")})},F=function(e){return"number"==typeof e},_=function(e){return"string"==typeof e},J=function(e){return null!==e&&"object"==typeof e},H=function(e){return J(e)&&e instanceof Array},M=[{name:"script",check:_},{name:"arguments",check:H},{name:"refBlock",check:_,defaultVal:"0"},{name:"gasLimit",check:F},{name:"proposalKey",check:J},{name:"payer",check:_},{name:"authorizers",check:H}],K=[{name:"address",check:_},{name:"keyId",check:F},{name:"sequenceNum",check:F}],V=[{name:"payloadSigs",check:H}],G=[{name:"address",check:_},{name:"keyId",check:F},{name:"sig",check:_}],W=function(e,r,n,t){var o=r.name,i=r.check,u=r.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw Y(o,n,t);if(!i(e[o]))throw Z(o,n,t)},X=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},Y=function(e,r,n){return new Error("Missing field "+X(e,r,n))},Z=function(e,r,n){return new Error("Invalid field "+X(e,r,n))},$="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Q(e,r,n){if(!e.s){if(n instanceof ee){if(!n.s)return void(n.o=Q.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Q.bind(null,e,r),Q.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var ee=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Q(t,1,i(this.v))}catch(e){Q(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Q(t,1,r?r(o):o):n?Q(t,1,n(o)):Q(t,2,o)}catch(e){Q(t,2,e)}},t},e}();function re(e){return e instanceof ee&&1&e.s}var ne=function(e){return"string"==typeof e},te=function(e){return"function"==typeof e};function oe(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:o.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:o.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(r){return o.sansPrefix(e.accounts[r].addr)}).reduce(function(e,r){return e.find(function(e){return e===r})?e:[].concat(e,[r])},[])}}e.config().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(u){function s(){function u(){function u(){function t(){var r=function(){if(n.isTransaction(e)){console.log("RESOLVE SIGNATURES START",e);var r=new Set(e.authorizations);r.add(e.proposer),r.delete(e.payer),r=Array.from(r);var t=new Set([e.payer]);t=Array.from(t),console.log("SIGNATORIES",{insideSigners:r,outsideSigners:t});var i=(u=oe(e),C(U(u)));return Promise.resolve(Promise.all(r.map(function(r){try{var n=e.accounts[r];return null!=n.signature?Promise.resolve():Promise.resolve(n.signingFunction({message:i,addr:o.sansPrefix(n.addr),keyId:n.keyId,roles:n.role,interaction:e})).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}))).then(function(){var n=function(e){return C(function(e){return function(e){V.forEach(function(r){return W(e,r)}),e.payloadSigs.forEach(function(e,r){G.forEach(function(n){return W(e,n,"payloadSigs",r)})})}(e),[U(e),q(e)]}(e))}(T({},oe(e),{payloadSigs:r.map(function(r){return e.accounts[r].signature})}));return Promise.resolve(Promise.all(t.map(function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:n,addr:o.sansPrefix(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}))).then(function(){console.log("RESOLVE SIGNATURES END",e)})})}var u}();return r&&r.then?r.then(function(){return e}):e}var u=function(){if(n.isTransaction(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});r.invariant(t,"Transactions require a proposer");var o=function(){if(null===t.sequenceNum)return Promise.resolve(i.account(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[t.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return u&&u.then?u.then(t):t()}n.isTransaction(e);var s=function(){if(n.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(t.latestBlock()).then(function(r){e.message.refBlock=r.id})}();return s&&s.then?s.then(u):u()}if(n.isTransaction(e)||n.isScript(e))for(var s=0,a=Object.entries(e.arguments);s<a.length;s++){var c=a[s];e.arguments[c[0]].asArgument=(r.invariant(null!=typeof(f=c[1]).xform,"No type specified for argument: "+f.value),te(f.xform)?f.xform(f.value):te(f.xform.asArgument)?f.xform.asArgument(f.value):void r.invariant(!1,"Invalid Argument",f))}var f,l=function(){if(n.isTransaction(e)){var r=function(){e.accounts=t},t={},o=function(e,r,n){if("function"==typeof e[$]){var t,o,i,u=e[$]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!re(n))return void n.then(e,i||(i=Q.bind(null,o=new ee,2)));n=n.v}o?Q(o,1,n):o=n}catch(e){Q(o||(o=new ee),2,e)}}(),u.return){var s=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!re(u))return void u.then(n,o||(o=Q.bind(null,t=new ee,2)));u=u.v}t?Q(t,1,u):t=u}catch(e){Q(t||(t=new ee),2,e)}}(),t}(a,function(e){return r(a[e])})}(Object.entries(e.accounts),function(r){var n=r[0],o=r[1];function i(){t[n]=t[n]||o,t[n].role.proposer=t[n].role.proposer||o.role.proposer,t[n].role.payer=t[n].role.payer||o.role.payer,t[n].role.authorizer=t[n].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=n),e.payer===u&&(e.payer=n),e.authorizations=e.authorizations.map(function(e){return e===u?n:e})}var u=n,s=function(){if(te(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){n=(o=e).tempId})}();return s&&s.then?s.then(i):i()});return o&&o.then?o.then(r):r()}}();return l&&l.then?l.then(u):u()}e=u;var a=function(){if(n.isTransaction(e)||n.isScript(e)){var t=function(){r.invariant(ne(o),"Cadence needs to be a string at this point."),e.message.cadence=o},o=n.get(e,"ix.cadence");r.invariant(te(o)||ne(o),"Cadence needs to be a function or a string.");var i=function(){if(te(o))return Promise.resolve(o({})).then(function(e){o=e})}();return i&&i.then?i.then(t):t()}}();return a&&a.then?a.then(s):s()})}catch(e){return Promise.reject(e)}});var ie,ue,se=function(e){try{return Promise.resolve(c.send([l.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},ae=function(e){return e.status>=4},ce=function(e){return e.status>=3},fe=function(e){return e.status>=2},le=((ie={})[a.INIT]=function(e){try{return Promise.resolve(se(e.self())).then(function(r){ae(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},ie[a.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,a.UPDATED,e.all())},ie[a.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},ie[a.SNAPSHOT]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ie.POLL=function(e){try{return Promise.resolve(se(e.self())).then(function(r){var n,t;ae(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(a.UPDATED,r),e.merge(r)})}catch(e){return Promise.reject(e)}},ie),de=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},pe=function(e){return a.spawn(le,de(e))};function he(e){function r(r){return a.subscriber(de(e),pe,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return a.snapshoter(e,pe)},subscribe:r,onceFinalized:n(fe),onceExecuted:n(ce),onceSealed:n(ae)}}he.isUnknown=function(e){return e.status>=0},he.isPending=function(e){return e.status>=1},he.isFinalized=fe,he.isExecuted=ce,he.isSealed=ae,he.isExpired=function(e){return 5===e.status};var me=function(r){try{var n=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},ve=((ue={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(t.latestBlock()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(me(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(c.send([getEvents(e.self(),r.height,n.height-1)]).then(f.decode)).then(function(r){for(var n,t=N(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(me(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ue[a.SUBSCRIBE]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(me(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},ue[a.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ue),ye=function(e){return a.spawn(ve,e)};function ge(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()}]}}var Pe={"@type":"Service","@vsn":"1.0.0"},be={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},Se={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},Pe,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function ke(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ee(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function xe(e,r){void 0===r&&(r=!0);var n=new URL(e.endpoint);if(r)for(var t=0,o=Object.entries(e.params||{});t<o.length;t++){var i=o[t];n.searchParams.append(i[0],i[1])}return n}function Ie(e){return ge(xe(e).href)}var je,Oe={"HTTP/GET":"GET","HTTP/POST":"POST"},Te=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},Ae=function(e,r){return"Missing "+Te(e,r)+" in Composite Signature."},Ne=function(e,r){return Te(e,r)+" in Composit Signature did not match the requested "+e+"."},Re={"HTTP/POST":function(e,r){try{var n=function(){},t=null;return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r()}return n&&n.then?n.then(r,r):r()}(function(){return function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){return Promise.resolve(fetch(xe(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0}).then(function(e){return e.json()})).then(function(e){if(console.log("RESP",e),e.local&&e.local.length>0){var r=Ie(e.local[0]);n=r[1]}return Promise.resolve(function e(r){return new Promise(function(n,t){try{return Promise.resolve(fetch(xe(r),{method:Oe[r.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(r){"APPROVED"===r.status?n(r.compositeSignature):"DECLINED"===r.status?t({status:r.status,reason:r.reason}):setTimeout(function(){n(e(r.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})})},function(t){throw n(),Le(e,r,t),t})},function(){return n(),t}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(n,t){try{var o=p.uid(),i=Ie(e),u=i[0],s=i[1],a=function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")};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(),n(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),t({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),t({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}}),new Promise(function(e){window.addEventListener("message",n);var r=setTimeout(function(){window.removeEventListener("message",n),a(),e()},5e3);function n(t){"FCL::AUTHZ_READY"===t.data.type&&(clearTimeout(r),window.removeEventListener("message",n),a(),e())}})}catch(n){Le(e,r,n),t({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function Le(e,r,n){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},n)}function Be(e,r,n){if(!e.s){if(n instanceof Ue){if(!n.s)return void(n.o=Be.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Be.bind(null,e,r),Be.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Ce=function(e){try{return Xe(),Promise.resolve(ze()).then(function(n){Ee(n.services,"authn");var t=Ee(n.services,"authz");return Ee(n.services,"pre-authz"),T({},e,{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(function(e,n){try{return Promise.resolve(Re[e.method](e,n)).then(function(n){return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),n.addr=o.sansPrefix(n.addr),function(e,n){try{var t={compSig:e,authz:n};r.invariant(e.addr,Ae("addr","Address"),t),r.invariant(null!=e.keyId,Ae("keyId"),t),r.invariant(e.signature,Ae("signature"),t),r.invariant(e.keyId===n.identity.keyId,Ne("keyId"),t),r.invariant(o.sansPrefix(e.addr)===o.sansPrefix(n.identity.address),Ne("addr","Address"),t)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(n,e),n})}catch(e){return Promise.reject(e)}}(t,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Ue=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Be(t,1,i(this.v))}catch(e){Be(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Be(t,1,r?r(o):o):n?Be(t,1,n(o)):Be(t,2,o)}catch(e){Be(t,2,e)}},t},e}();function qe(e){return e instanceof Ue&&1&e.s}var ze=function(){try{return Promise.resolve(new Promise(function(r){try{return Xe(),Promise.resolve(Qe()).then(function(n){return n.loggedIn&&Ye(n)?r(n):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var n,t,i,u=(t=(n={handshake:e,l6n:window.location.origin}).l6n,(i=new URL(n.handshake)).searchParams.append("l6n",t),ge(i.href))[1];window.addEventListener("message",function e(n){var t=n.data;try{return t.type===Me||t.type===Je?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==He?Promise.resolve():(u(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=N(e.authorizations);!(n=t()).done;)r.push(T({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(T({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,i,u=(t=r,i=n,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(r){return function(e,r){try{var n=Se[e.type](e,r);return console.log(e.type,{normalized:n,service:e}),n}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)});console.log("BUILD USER",u);var s=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,u);return T({},we,{addr:o.withPrefix(e.addr),cid:ke(s),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return a.send(De,_e,e),Promise.resolve(Qe()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},De="CURRENT_USER",Fe="CURRENT_USER/UPDATED",_e="SET_CURRENT_USER",Je="FCL::CANCEL",He="FCL::CHALLENGE::RESPONSE",Me="FCL::CHALLENGE::CANCEL",Ke='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ve=function(e){try{return sessionStorage.setItem(De,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ge=function(){return e.config().get("persistSession",!0)},We=((je={})[a.INIT]=function(e){try{return e.merge(JSON.parse(Ke)),Promise.resolve(Ge()).then(function(r){var n=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(Ke),r=JSON.parse(sessionStorage.getItem(De));return null!=r&&e["@vsn"]!==r["@vsn"]?(sessionStorage.removeItem(De),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){Ye(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},je[a.SUBSCRIBE]=function(e,r){e.subscribe(r.from),e.send(r.from,Fe,T({},e.all()))},je[a.UNSUBSCRIBE]=function(e,r){e.unsubscribe(r.from)},je.SNAPSHOT=function(e,r){try{return r.reply(T({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},je[_e]=function(e,r,n){try{return e.merge(n),Promise.resolve(Ge()).then(function(r){r&&Ve(e.all()),e.broadcast(Fe,T({},e.all()))})}catch(e){return Promise.reject(e)}},je.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(Ke)),Promise.resolve(Ge()).then(function(r){r&&Ve(e.all()),e.broadcast(Fe,T({},e.all()))})}catch(e){return Promise.reject(e)}},je),Xe=function(){return a.spawn(We,De)};function Ye(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ze(){Xe(),a.send(De,"DEL_CURRENT_USER")}function $e(e){Xe();var r=a.spawn(function(r){try{var n;return r.send(De,a.SUBSCRIBE),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(qe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!qe(i)){t=1;break}i=i.s}}var u=new Ue,s=Be.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Be(u,1,i)})).then(void 0,s),u;function a(r){i=r;do{if(!(o=e())||qe(o)&&!o.v)return void Be(u,1,i);if(o.then)return void o.then(c).then(void 0,s);qe(i=n())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function c(e){e?(i=n())&&i.then?i.then(a).then(void 0,s):a(i):Be(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(De,a.UNSUBSCRIBE),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return a.send(r,"@EXIT")}}function Qe(){return Xe(),a.send(De,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var er=function(){return{authenticate:ze,unauthenticate:Ze,authorization:Ce,subscribe:$e,snapshot:Qe}},rr=er().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return i.account}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return c.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return l.getTransactionStatus}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return d.getEvents}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return h.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return m.transaction}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return v.script}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return y.ping}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return g.getAccount}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return b.getBlockById}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return w.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 k.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return k.args}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return E.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return x.payer}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return I.limit}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return j.ref}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return O.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return O.params}}),exports.VERSION="0.0.67-alpha.3",exports.authenticate=function(){return er().authenticate()},exports.authz=rr,exports.currentUser=er,exports.events=function(e){return{subscribe:function(r){return a.subscriber(e,ye,r)}}},exports.logIn=function(){return er().authenticate()},exports.reauthenticate=function(){er().unauthenticate(),er().authenticate()},exports.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var t=function(){return Promise.resolve(s.resolve(r)(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(r){e=r})}();return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},exports.signUp=function(){return er().authenticate()},exports.tx=he,exports.unauthenticate=function(){return er().unauthenticate()};
//# sourceMappingURL=fcl.js.map

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

import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as t}from"@onflow/util-invariant";import{isTransaction as n,isScript as r,get as o,pipe as a,interaction as s}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as i}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as u,withPrefix as c}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as d}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as f}from"@onflow/sdk-resolve";import{subscriber as p,spawn as m,snapshoter as y,INIT as g,SUBSCRIBE as h,UPDATED as w,UNSUBSCRIBE as k,SNAPSHOT as E,send as v}from"@onflow/util-actor";import{send as S}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as I}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as b}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as x}from"@onflow/util-uid";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{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";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";function T(){return(T=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var L=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},N=function(e){return L(e,8)},R=function(e){return Buffer.from(JSON.stringify(e),"utf8")},A=function(e){return l(e).toString("hex")},P=function(e){return z(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(R),(t=e.refBlock,L(t,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var t,n},C=function(e){var t=O(e);return e.payloadSigs.map(function(e){return{signerIndex:t.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,t){return e.signerIndex>t.signerIndex?1:e.signerIndex<t.signerIndex?-1:e.keyId>t.keyId?1:e.keyId<t.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(t=e.sig,Buffer.from(t,"hex"))];var t})},O=function(e){var t=new Map,n=0,r=function(e){t.has(e)||(t.set(e,n),n++)};return r(e.proposalKey.address),r(e.payer),e.authorizers.forEach(r),t},z=function(e){j.forEach(function(t){return H(e,t)}),_.forEach(function(t){return H(e.proposalKey,t,"proposalKey")})},U=function(e){return"number"==typeof e},D=function(e){return"string"==typeof e},B=function(e){return null!==e&&"object"==typeof e},F=function(e){return B(e)&&e instanceof Array},j=[{name:"script",check:D},{name:"arguments",check:F},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:U},{name:"proposalKey",check:B},{name:"payer",check:D},{name:"authorizers",check:F}],_=[{name:"address",check:D},{name:"keyId",check:U},{name:"sequenceNum",check:U}],J=[{name:"payloadSigs",check:F}],q=[{name:"address",check:D},{name:"keyId",check:U},{name:"sig",check:D}],H=function(e,t,n,r){var o=t.name,a=t.check,s=t.defaultVal;if(null==e[o]&&null!=s&&(e[o]=s),null==e[o])throw M(o,n,r);if(!a(e[o]))throw G(o,n,r)},K=function(e,t,n){return t?null==n?t+"."+e:t+"."+n+"."+e:e},M=function(e,t,n){return new Error("Missing field "+K(e,t,n))},G=function(e,t,n){return new Error("Invalid field "+K(e,t,n))};const V=e=>"string"==typeof e,$=e=>"function"==typeof e;function W(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(t=>e.arguments[t].asArgument),proposalKey:{address:u(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:u(e.accounts[e.payer].addr),authorizers:e.authorizations.map(t=>u(e.accounts[t].addr)).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[])}}e().put("sdk.resolve",async function(e){if(e=await e,n(e)||r(e)){var a=o(e,"ix.cadence");t($(a)||V(a),"Cadence needs to be a function or a string."),$(a)&&(a=await a({})),t(V(a),"Cadence needs to be a string at this point."),e.message.cadence=a}if(n(e)||r(e)){function s(e){return t(null!=typeof e.xform,"No type specified for argument: "+e.value),$(e.xform)?e.xform(e.value):$(e.xform.asArgument)?e.xform.asArgument(e.value):void t(!1,"Invalid Argument",e)}for(let[t,n]of Object.entries(e.arguments))e.arguments[t].asArgument=s(n)}if(n(e)){var c={};for(let[t,n]of Object.entries(e.accounts)){var l=t;$(n.resolve)&&(n=await n.resolve(n),t=n.tempId),c[t]=c[t]||n,c[t].role.proposer=c[t].role.proposer||n.role.proposer,c[t].role.payer=c[t].role.payer||n.role.payer,c[t].role.authorizer=c[t].role.authorizer||n.role.authorizer,e.proposer===l&&(e.proposer=t),e.payer===l&&(e.payer=t),e.authorizations=e.authorizations.map(e=>e===l?t:e)}e.accounts=c}if(n(e),n(e)&&null==e.message.refBlock&&(e.message.refBlock=(await i()).id),n(e)){var f=Object.values(e.accounts).find(e=>e.role.proposer);t(f,"Transactions require a proposer"),null===f.sequenceNum&&(e.accounts[f.tempId].sequenceNum=await d(f.addr).then(e=>e.keys).then(e=>e.find(e=>e.index===f.keyId)).then(e=>e.sequenceNumber))}if(n(e)){console.log("RESOLVE SIGNATURES START",e);let t=new Set(e.authorizations);t.add(e.proposer),t.delete(e.payer),t=Array.from(t);let n=new Set([e.payer]);n=Array.from(n),console.log("SIGNATORIES",{insideSigners:t,outsideSigners:n});const r=(p=W(e),A(P(p)));await Promise.all(t.map(async t=>{const n=e.accounts[t];if(null!=n.signature)return;const{signature:o}=await n.signingFunction({message:r,addr:u(n.addr),keyId:n.keyId,roles:n.role,interaction:e});e.accounts[t].signature=o}));const o=function(e){return A(function(e){return function(e){J.forEach(function(t){return H(e,t)}),e.payloadSigs.forEach(function(e,t){q.forEach(function(n){return H(e,n,"payloadSigs",t)})})}(e),[P(e),C(e)]}(e))}(T({},W(e),{payloadSigs:t.map(t=>e.accounts[t].signature)}));await Promise.all(n.map(async t=>{const n=e.accounts[t];if(null!=n.signature)return;const{signature:r}=await n.signingFunction({message:o,addr:u(n.addr),keyId:n.keyId,roles:n.role,interaction:e});e.accounts[t].signature=r})),console.log("RESOLVE SIGNATURES END",e)}var p;return e});const X=async(e=[],t={})=>(Array.isArray(e)&&(e=await a(s(),e)),JSON.stringify(await f(t)(e))),Y=async e=>S([b(e)]).then(I),Z=e=>e.status>=4,Q=e=>e.status>=3,ee=e=>e.status>=2,te={[g]:async e=>{const t=await Y(e.self());Z(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,w,e.all())},[k]:(e,t)=>{e.unsubscribe(t.from)},[E]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await Y(e.self());var n,r;Z(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(w,t),e.merge(t)}},ne=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},re=e=>m(te,ne(e));function oe(e){function t(t){return p(ne(e),re,t)}function n(e){return function(n={}){const r=n.suppress||!1;return new Promise((n,o)=>{const a=t(t=>{t.statusCode&&!r?(o(t.errorMessage),a()):e(t)&&(n(t),a())})})}}return{snapshot:function(){return y(e,re)},subscribe:t,onceFinalized:n(ee),onceExecuted:n(Q),onceSealed:n(Z)}}oe.isUnknown=e=>e.status>=0,oe.isPending=e=>e.status>=1,oe.isFinalized=ee,oe.isExecuted=Q,oe.isSealed=Z,oe.isExpired=e=>5===e.status;const ae=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),se={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await ae(e));else{let n=await i();e.put("hwm",n);const r=await S([getEvents(e.self(),t.height,n.height-1)]).then(I);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await ae(e))}},[h]:async(e,t)=>{e.hasSubs()||e.put("tick",await ae(e)),e.subscribe(t.from)},[k]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},ie=e=>m(se,e);function ue(e){return{subscribe:t=>p(e,ie,t)}}function ce(e){if(document.getElementById("FCL_IFRAME"))return;const t=document.createElement("iframe");return t.src=e,t.id="FCL_IFRAME",t.allow="usb *",t.style.position="fixed",t.style.top="0px",t.style.right="0px",t.style.left="0px",t.style.bottom="0px",t.style.height="100vh",t.style.width="100vw",t.style.display="block",t.style.background="rgba(0,0,0,0.25)",t.style.zIndex=2147483647,t.frameBorder="0",t.style.boxSizing="border-box",document.body.append(t),[t,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}const de={"@type":"Service","@vsn":"1.0.0"},le={"@type":"Identity","@vsn":"1.0.0"},fe={"@type":"USER","@vsn":"1.0.0"},pe={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},de,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:c(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},le,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},le,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function me(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function ye(e=[],t){return e.find(e=>e.type===t)}function ge(e,t=!0){const n=new URL(e.endpoint);if(t)for(let[t,r]of Object.entries(e.params||{}))n.searchParams.append(t,r);return n}function he(e){return ce(ge(e).href)}const we={"HTTP/GET":"GET","HTTP/POST":"POST"},ke=e=>new Promise(async(t,n)=>{const r=await fetch(ge(e),{method:we[e.method],headers:{"Content-Type":"application/json"}}).then(e=>e.json());"APPROVED"===r.status?t(r.compositeSignature):"DECLINED"===r.status?n({status:r.status,reason:r.reason}):setTimeout(()=>{t(ke(r.authorizationUpdates))},500)}),Ee=(e,t)=>null==t?`'${e}'`:`'${e}' (${t})`,ve=(e,t)=>`Missing ${Ee(e,t)} in Composite Signature.`,Se=(e,t)=>`${Ee(e,t)} in Composit Signature did not match the requested ${e}.`,Ie={"HTTP/POST":async function(e,t){var n=()=>{},r=null;try{const o=await fetch(ge(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:t?JSON.stringify(t):void 0}).then(e=>e.json());if(console.log("RESP",o),o.local&&o.local.length>0){const[e,t]=he(o.local[0]);n=t}r=await ke(o.authorizationUpdates)}catch(r){throw n(),be(e,t,r),r}finally{return n(),r}},"IFRAME/RPC":async function(e,t){return new Promise((n,r)=>{try{const o=x(),[a,s]=he(e),i=()=>{a.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})),"*")},u=async({data:e})=>{if("object"!=typeof e)return;if("2.0"!==e.jsonrpc)return;if(e.id!==o)return;const t=e.result;"APPROVED"===t.status?(window.removeEventListener("message",u),s(),n(t.compositeSignature)):"DECLINED"===t.status?(window.removeEventListener("message",u),s(),r({status:t.status,reason:t.reason})):(window.removeEventListener("message",u),s(),r({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}))};window.addEventListener("message",u),new Promise(e=>{window.addEventListener("message",n);const t=setTimeout(()=>{window.removeEventListener("message",n),i(),e()},5e3);function n({data:r}){"FCL::AUTHZ_READY"===r.type&&(clearTimeout(t),window.removeEventListener("message",n),i(),e())}})}catch(n){be(e,t,n),r({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}})}};function be(e,t,n){console.error(`[${e.method}] Trouble talking to Wallet Provider`,"\n\n",{authz:e,signable:t},n)}const xe="CURRENT_USER",Te="CURRENT_USER/UPDATED",Le='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ne=async e=>(sessionStorage.setItem(xe,JSON.stringify(e)),e),Re=()=>e().get("persistSession",!0),Ae={[g]:async e=>{if(e.merge(JSON.parse(Le)),await Re()){const t=await(async()=>{const e=JSON.parse(Le),t=JSON.parse(sessionStorage.getItem(xe));return null!=t&&e["@vsn"]!==t["@vsn"]?(sessionStorage.removeItem(xe),e):t||e})();Ce(t)&&e.merge(t)}},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Te,T({},e.all()))},[k]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(T({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Re()&&Ne(e.all()),e.broadcast(Te,T({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Le)),await Re()&&Ne(e.all()),e.broadcast(Te,T({},e.all()))}},Pe=()=>m(Ae,xe);function Ce(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Oe(){return new Promise(async t=>{Pe();const n=await Be();if(n.loggedIn&&Ce(n))return t(n);const[r,o]=function({handshake:e,l6n:t}){var n=new URL(e);return n.searchParams.append("l6n",t),ce(n.href)}({handshake:await e().get("challenge.handshake"),l6n:window.location.origin}),a=async({data:e})=>{if("FCL::CHALLENGE::CANCEL"===e.type||"FCL::CANCEL"===e.type)return o(),void window.removeEventListener("message",a);"FCL::CHALLENGE::RESPONSE"===e.type&&(o(),window.removeEventListener("message",a),v(xe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?c(e.addr):null,e.paddr=e.paddr?c(e.paddr):null,e}(e)).services||[],await async function(e,t){if(null==e||null==t)return[];const n=new URL(e);n.searchParams.append("code",t);const r=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(r))return r;const o=[];if(Array.isArray(r.authorizations))for(let e of r.authorizations)o.push(T({type:"authz",keyId:r.keyId},e));return null!=r.provider&&o.push(T({type:"authn",id:"wallet-provider#authn"},r.provider)),o}(e.hks,e.code)).map(t=>function(e,t){try{var n=pe[e.type](e,t);return console.log(e.type,{normalized:n,service:e}),n}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));console.log("BUILD USER",t);const n=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return T({},fe,{addr:c(e.addr),cid:me(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await Be()))};window.addEventListener("message",a)})}function ze(){Pe(),v(xe,"DEL_CURRENT_USER")}async function Ue(e){Pe();const n=await Oe(),r=(ye(n.services,"authn"),ye(n.services,"authz"));return ye(n.services,"pre-authz"),T({},e,{tempId:"CURRENT_USER",resolve:null,addr:u(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>async function(e,n){const r=await Ie[e.method](e,n);return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=u(r.addr),function(e,n){try{const r={compSig:e,authz:n};t(e.addr,ve("addr","Address"),r),t(e.keyId,ve("keyId"),r),t(e.signature,ve("signature"),r),t(e.keyId===n.identity.keyId,Se("keyId"),r),t(u(e.addr)===u(n.identity.address),Se("addr","Address"),r)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(r,e),r}(r,e)})}function De(e){Pe();const t=m(async t=>{for(t.send(xe,h);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(xe,k);e(n.data)}});return()=>v(t,"@EXIT")}function Be(){return Pe(),v(xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Fe=()=>({authenticate:Oe,unauthenticate:ze,authorization:Ue,subscribe:De,snapshot:Be}),je=()=>Fe().authenticate(),_e=()=>Fe().unauthenticate(),Je=()=>{Fe().unauthenticate(),Fe().authenticate()},qe=()=>Fe().authenticate(),He=()=>Fe().authenticate(),Ke=Fe().authorization,Me="0.0.67-alpha.2";export{Me as VERSION,je as authenticate,Ke as authz,Fe as currentUser,ue as events,He as logIn,Je as reauthenticate,X as serialize,qe as signUp,oe as tx,_e as unauthenticate};
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as t}from"@onflow/util-invariant";import{isTransaction as n,isScript as r,get as o,pipe as a,interaction as s}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as i}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as u,withPrefix as c}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as d}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as f}from"@onflow/sdk-resolve";import{subscriber as p,spawn as m,snapshoter as y,INIT as g,SUBSCRIBE as h,UPDATED as w,UNSUBSCRIBE as k,SNAPSHOT as E,send as v}from"@onflow/util-actor";import{send as S}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as I}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as b}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as x}from"@onflow/util-uid";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{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";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";function T(){return(T=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var L=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},N=function(e){return L(e,8)},R=function(e){return Buffer.from(JSON.stringify(e),"utf8")},A=function(e){return l(e).toString("hex")},P=function(e){return z(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(R),(t=e.refBlock,L(t,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var t,n},C=function(e){var t=O(e);return e.payloadSigs.map(function(e){return{signerIndex:t.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,t){return e.signerIndex>t.signerIndex?1:e.signerIndex<t.signerIndex?-1:e.keyId>t.keyId?1:e.keyId<t.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(t=e.sig,Buffer.from(t,"hex"))];var t})},O=function(e){var t=new Map,n=0,r=function(e){t.has(e)||(t.set(e,n),n++)};return r(e.proposalKey.address),r(e.payer),e.authorizers.forEach(r),t},z=function(e){j.forEach(function(t){return H(e,t)}),_.forEach(function(t){return H(e.proposalKey,t,"proposalKey")})},U=function(e){return"number"==typeof e},D=function(e){return"string"==typeof e},B=function(e){return null!==e&&"object"==typeof e},F=function(e){return B(e)&&e instanceof Array},j=[{name:"script",check:D},{name:"arguments",check:F},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:U},{name:"proposalKey",check:B},{name:"payer",check:D},{name:"authorizers",check:F}],_=[{name:"address",check:D},{name:"keyId",check:U},{name:"sequenceNum",check:U}],J=[{name:"payloadSigs",check:F}],q=[{name:"address",check:D},{name:"keyId",check:U},{name:"sig",check:D}],H=function(e,t,n,r){var o=t.name,a=t.check,s=t.defaultVal;if(null==e[o]&&null!=s&&(e[o]=s),null==e[o])throw M(o,n,r);if(!a(e[o]))throw G(o,n,r)},K=function(e,t,n){return t?null==n?t+"."+e:t+"."+n+"."+e:e},M=function(e,t,n){return new Error("Missing field "+K(e,t,n))},G=function(e,t,n){return new Error("Invalid field "+K(e,t,n))};const V=e=>"string"==typeof e,$=e=>"function"==typeof e;function W(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(t=>e.arguments[t].asArgument),proposalKey:{address:u(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:u(e.accounts[e.payer].addr),authorizers:e.authorizations.map(t=>u(e.accounts[t].addr)).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[])}}e().put("sdk.resolve",async function(e){if(e=await e,n(e)||r(e)){var a=o(e,"ix.cadence");t($(a)||V(a),"Cadence needs to be a function or a string."),$(a)&&(a=await a({})),t(V(a),"Cadence needs to be a string at this point."),e.message.cadence=a}if(n(e)||r(e)){function s(e){return t(null!=typeof e.xform,"No type specified for argument: "+e.value),$(e.xform)?e.xform(e.value):$(e.xform.asArgument)?e.xform.asArgument(e.value):void t(!1,"Invalid Argument",e)}for(let[t,n]of Object.entries(e.arguments))e.arguments[t].asArgument=s(n)}if(n(e)){var c={};for(let[t,n]of Object.entries(e.accounts)){var l=t;$(n.resolve)&&(n=await n.resolve(n),t=n.tempId),c[t]=c[t]||n,c[t].role.proposer=c[t].role.proposer||n.role.proposer,c[t].role.payer=c[t].role.payer||n.role.payer,c[t].role.authorizer=c[t].role.authorizer||n.role.authorizer,e.proposer===l&&(e.proposer=t),e.payer===l&&(e.payer=t),e.authorizations=e.authorizations.map(e=>e===l?t:e)}e.accounts=c}if(n(e),n(e)&&null==e.message.refBlock&&(e.message.refBlock=(await i()).id),n(e)){var f=Object.values(e.accounts).find(e=>e.role.proposer);t(f,"Transactions require a proposer"),null===f.sequenceNum&&(e.accounts[f.tempId].sequenceNum=await d(f.addr).then(e=>e.keys).then(e=>e.find(e=>e.index===f.keyId)).then(e=>e.sequenceNumber))}if(n(e)){console.log("RESOLVE SIGNATURES START",e);let t=new Set(e.authorizations);t.add(e.proposer),t.delete(e.payer),t=Array.from(t);let n=new Set([e.payer]);n=Array.from(n),console.log("SIGNATORIES",{insideSigners:t,outsideSigners:n});const r=(p=W(e),A(P(p)));await Promise.all(t.map(async t=>{const n=e.accounts[t];if(null!=n.signature)return;const{signature:o}=await n.signingFunction({message:r,addr:u(n.addr),keyId:n.keyId,roles:n.role,interaction:e});e.accounts[t].signature=o}));const o=function(e){return A(function(e){return function(e){J.forEach(function(t){return H(e,t)}),e.payloadSigs.forEach(function(e,t){q.forEach(function(n){return H(e,n,"payloadSigs",t)})})}(e),[P(e),C(e)]}(e))}(T({},W(e),{payloadSigs:t.map(t=>e.accounts[t].signature)}));await Promise.all(n.map(async t=>{const n=e.accounts[t];if(null!=n.signature)return;const{signature:r}=await n.signingFunction({message:o,addr:u(n.addr),keyId:n.keyId,roles:n.role,interaction:e});e.accounts[t].signature=r})),console.log("RESOLVE SIGNATURES END",e)}var p;return e});const X=async(e=[],t={})=>(Array.isArray(e)&&(e=await a(s(),e)),JSON.stringify(await f(t)(e))),Y=async e=>S([b(e)]).then(I),Z=e=>e.status>=4,Q=e=>e.status>=3,ee=e=>e.status>=2,te={[g]:async e=>{const t=await Y(e.self());Z(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,w,e.all())},[k]:(e,t)=>{e.unsubscribe(t.from)},[E]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await Y(e.self());var n,r;Z(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(w,t),e.merge(t)}},ne=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},re=e=>m(te,ne(e));function oe(e){function t(t){return p(ne(e),re,t)}function n(e){return function(n={}){const r=n.suppress||!1;return new Promise((n,o)=>{const a=t(t=>{t.statusCode&&!r?(o(t.errorMessage),a()):e(t)&&(n(t),a())})})}}return{snapshot:function(){return y(e,re)},subscribe:t,onceFinalized:n(ee),onceExecuted:n(Q),onceSealed:n(Z)}}oe.isUnknown=e=>e.status>=0,oe.isPending=e=>e.status>=1,oe.isFinalized=ee,oe.isExecuted=Q,oe.isSealed=Z,oe.isExpired=e=>5===e.status;const ae=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),se={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await ae(e));else{let n=await i();e.put("hwm",n);const r=await S([getEvents(e.self(),t.height,n.height-1)]).then(I);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await ae(e))}},[h]:async(e,t)=>{e.hasSubs()||e.put("tick",await ae(e)),e.subscribe(t.from)},[k]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},ie=e=>m(se,e);function ue(e){return{subscribe:t=>p(e,ie,t)}}function ce(e){if(document.getElementById("FCL_IFRAME"))return;const t=document.createElement("iframe");return t.src=e,t.id="FCL_IFRAME",t.allow="usb *",t.style.position="fixed",t.style.top="0px",t.style.right="0px",t.style.left="0px",t.style.bottom="0px",t.style.height="100vh",t.style.width="100vw",t.style.display="block",t.style.background="rgba(0,0,0,0.25)",t.style.zIndex=2147483647,t.frameBorder="0",t.style.boxSizing="border-box",document.body.append(t),[t,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}const de={"@type":"Service","@vsn":"1.0.0"},le={"@type":"Identity","@vsn":"1.0.0"},fe={"@type":"USER","@vsn":"1.0.0"},pe={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},de,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:c(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},le,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return T({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:T({},le,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function me(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function ye(e=[],t){return e.find(e=>e.type===t)}function ge(e,t=!0){const n=new URL(e.endpoint);if(t)for(let[t,r]of Object.entries(e.params||{}))n.searchParams.append(t,r);return n}function he(e){return ce(ge(e).href)}const we={"HTTP/GET":"GET","HTTP/POST":"POST"},ke=e=>new Promise(async(t,n)=>{const r=await fetch(ge(e),{method:we[e.method],headers:{"Content-Type":"application/json"}}).then(e=>e.json());"APPROVED"===r.status?t(r.compositeSignature):"DECLINED"===r.status?n({status:r.status,reason:r.reason}):setTimeout(()=>{t(ke(r.authorizationUpdates))},500)}),Ee=(e,t)=>null==t?`'${e}'`:`'${e}' (${t})`,ve=(e,t)=>`Missing ${Ee(e,t)} in Composite Signature.`,Se=(e,t)=>`${Ee(e,t)} in Composit Signature did not match the requested ${e}.`,Ie={"HTTP/POST":async function(e,t){var n=()=>{},r=null;try{const o=await fetch(ge(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:t?JSON.stringify(t):void 0}).then(e=>e.json());if(console.log("RESP",o),o.local&&o.local.length>0){const[e,t]=he(o.local[0]);n=t}r=await ke(o.authorizationUpdates)}catch(r){throw n(),be(e,t,r),r}finally{return n(),r}},"IFRAME/RPC":async function(e,t){return new Promise((n,r)=>{try{const o=x(),[a,s]=he(e),i=()=>{a.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})),"*")},u=async({data:e})=>{if("object"!=typeof e)return;if("2.0"!==e.jsonrpc)return;if(e.id!==o)return;const t=e.result;"APPROVED"===t.status?(window.removeEventListener("message",u),s(),n(t.compositeSignature)):"DECLINED"===t.status?(window.removeEventListener("message",u),s(),r({status:t.status,reason:t.reason})):(window.removeEventListener("message",u),s(),r({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"}))};window.addEventListener("message",u),new Promise(e=>{window.addEventListener("message",n);const t=setTimeout(()=>{window.removeEventListener("message",n),i(),e()},5e3);function n({data:r}){"FCL::AUTHZ_READY"===r.type&&(clearTimeout(t),window.removeEventListener("message",n),i(),e())}})}catch(n){be(e,t,n),r({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}})}};function be(e,t,n){console.error(`[${e.method}] Trouble talking to Wallet Provider`,"\n\n",{authz:e,signable:t},n)}const xe="CURRENT_USER",Te="CURRENT_USER/UPDATED",Le='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ne=async e=>(sessionStorage.setItem(xe,JSON.stringify(e)),e),Re=()=>e().get("persistSession",!0),Ae={[g]:async e=>{if(e.merge(JSON.parse(Le)),await Re()){const t=await(async()=>{const e=JSON.parse(Le),t=JSON.parse(sessionStorage.getItem(xe));return null!=t&&e["@vsn"]!==t["@vsn"]?(sessionStorage.removeItem(xe),e):t||e})();Ce(t)&&e.merge(t)}},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Te,T({},e.all()))},[k]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(T({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Re()&&Ne(e.all()),e.broadcast(Te,T({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(Le)),await Re()&&Ne(e.all()),e.broadcast(Te,T({},e.all()))}},Pe=()=>m(Ae,xe);function Ce(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function Oe(){return new Promise(async t=>{Pe();const n=await Be();if(n.loggedIn&&Ce(n))return t(n);const[r,o]=function({handshake:e,l6n:t}){var n=new URL(e);return n.searchParams.append("l6n",t),ce(n.href)}({handshake:await e().get("challenge.handshake"),l6n:window.location.origin}),a=async({data:e})=>{if("FCL::CHALLENGE::CANCEL"===e.type||"FCL::CANCEL"===e.type)return o(),void window.removeEventListener("message",a);"FCL::CHALLENGE::RESPONSE"===e.type&&(o(),window.removeEventListener("message",a),v(xe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?c(e.addr):null,e.paddr=e.paddr?c(e.paddr):null,e}(e)).services||[],await async function(e,t){if(null==e||null==t)return[];const n=new URL(e);n.searchParams.append("code",t);const r=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(r))return r;const o=[];if(Array.isArray(r.authorizations))for(let e of r.authorizations)o.push(T({type:"authz",keyId:r.keyId},e));return null!=r.provider&&o.push(T({type:"authn",id:"wallet-provider#authn"},r.provider)),o}(e.hks,e.code)).map(t=>function(e,t){try{var n=pe[e.type](e,t);return console.log(e.type,{normalized:n,service:e}),n}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));console.log("BUILD USER",t);const n=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return T({},fe,{addr:c(e.addr),cid:me(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await Be()))};window.addEventListener("message",a)})}function ze(){Pe(),v(xe,"DEL_CURRENT_USER")}async function Ue(e){Pe();const n=await Oe(),r=(ye(n.services,"authn"),ye(n.services,"authz"));return ye(n.services,"pre-authz"),T({},e,{tempId:"CURRENT_USER",resolve:null,addr:u(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>async function(e,n){const r=await Ie[e.method](e,n);return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=u(r.addr),function(e,n){try{const r={compSig:e,authz:n};t(e.addr,ve("addr","Address"),r),t(null!=e.keyId,ve("keyId"),r),t(e.signature,ve("signature"),r),t(e.keyId===n.identity.keyId,Se("keyId"),r),t(u(e.addr)===u(n.identity.address),Se("addr","Address"),r)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(r,e),r}(r,e)})}function De(e){Pe();const t=m(async t=>{for(t.send(xe,h);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(xe,k);e(n.data)}});return()=>v(t,"@EXIT")}function Be(){return Pe(),v(xe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Fe=()=>({authenticate:Oe,unauthenticate:ze,authorization:Ue,subscribe:De,snapshot:Be}),je=()=>Fe().authenticate(),_e=()=>Fe().unauthenticate(),Je=()=>{Fe().unauthenticate(),Fe().authenticate()},qe=()=>Fe().authenticate(),He=()=>Fe().authenticate(),Ke=Fe().authorization,Me="0.0.67-alpha.3";export{Me as VERSION,je as authenticate,Ke as authz,Fe as currentUser,ue as events,He as logIn,Je as reauthenticate,X as serialize,qe as signUp,oe as tx,_e as unauthenticate};
//# sourceMappingURL=fcl.modern.js.map

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

import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as r}from"@onflow/util-invariant";import{isTransaction as n,isScript as t,get as o,pipe as i,interaction as u}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as s}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as a,withPrefix as c}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as f}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as d}from"@onflow/sdk-resolve";import{INIT as m,SUBSCRIBE as h,UPDATED as p,UNSUBSCRIBE as v,SNAPSHOT as y,subscriber as g,spawn as P,snapshoter as w,send as k}from"@onflow/util-actor";import{send as b}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as E}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as S}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as I}from"@onflow/util-uid";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{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";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";function x(){return(x=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function T(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function A(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return T(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?T(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var j=function(e,r){return Buffer.from(e.padStart(2*r,0),"hex")},L=function(e){return j(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},R=function(e){return l(e).toString("hex")},C=function(e){return U(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(N),(r=e.refBlock,j(r,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var r,n},O=function(e){var r=z(e);return e.payloadSigs.map(function(e){return{signerIndex:r.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,r){return e.signerIndex>r.signerIndex?1:e.signerIndex<r.signerIndex?-1:e.keyId>r.keyId?1:e.keyId<r.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(r=e.sig,Buffer.from(r,"hex"))];var r})},z=function(e){var r=new Map,n=0,t=function(e){r.has(e)||(r.set(e,n),n++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),r},U=function(e){J.forEach(function(r){return K(e,r)}),q.forEach(function(r){return K(e.proposalKey,r,"proposalKey")})},D=function(e){return"number"==typeof e},B=function(e){return"string"==typeof e},F=function(e){return null!==e&&"object"==typeof e},_=function(e){return F(e)&&e instanceof Array},J=[{name:"script",check:B},{name:"arguments",check:_},{name:"refBlock",check:B,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:F},{name:"payer",check:B},{name:"authorizers",check:_}],q=[{name:"address",check:B},{name:"keyId",check:D},{name:"sequenceNum",check:D}],M=[{name:"payloadSigs",check:_}],H=[{name:"address",check:B},{name:"keyId",check:D},{name:"sig",check:B}],K=function(e,r,n,t){var o=r.name,i=r.check,u=r.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw V(o,n,t);if(!i(e[o]))throw W(o,n,t)},G=function(e,r,n){return r?null==n?r+"."+e:r+"."+n+"."+e:e},V=function(e,r,n){return new Error("Missing field "+G(e,r,n))},W=function(e,r,n){return new Error("Invalid field "+G(e,r,n))},X="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Y(e,r,n){if(!e.s){if(n instanceof Z){if(!n.s)return void(n.o=Y.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Y.bind(null,e,r),Y.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Z=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Y(t,1,i(this.v))}catch(e){Y(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Y(t,1,r?r(o):o):n?Y(t,1,n(o)):Y(t,2,o)}catch(e){Y(t,2,e)}},t},e}();function $(e){return e instanceof Z&&1&e.s}var Q=function(e){return"string"==typeof e},ee=function(e){return"function"==typeof e};function re(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:a(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:a(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(r){return a(e.accounts[r].addr)}).reduce(function(e,r){return e.find(function(e){return e===r})?e:[].concat(e,[r])},[])}}e().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(i){function u(){function o(){function t(){function t(){var r=function(){if(n(e)){console.log("RESOLVE SIGNATURES START",e);var r=new Set(e.authorizations);r.add(e.proposer),r.delete(e.payer),r=Array.from(r);var t=new Set([e.payer]);t=Array.from(t),console.log("SIGNATORIES",{insideSigners:r,outsideSigners:t});var o=(i=re(e),R(C(i)));return Promise.resolve(Promise.all(r.map(function(r){try{var n=e.accounts[r];return null!=n.signature?Promise.resolve():Promise.resolve(n.signingFunction({message:o,addr:a(n.addr),keyId:n.keyId,roles:n.role,interaction:e})).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}))).then(function(){var n=function(e){return R(function(e){return function(e){M.forEach(function(r){return K(e,r)}),e.payloadSigs.forEach(function(e,r){H.forEach(function(n){return K(e,n,"payloadSigs",r)})})}(e),[C(e),O(e)]}(e))}(x({},re(e),{payloadSigs:r.map(function(r){return e.accounts[r].signature})}));return Promise.resolve(Promise.all(t.map(function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:n,addr:a(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}))).then(function(){console.log("RESOLVE SIGNATURES END",e)})})}var i}();return r&&r.then?r.then(function(){return e}):e}var o=function(){if(n(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});r(t,"Transactions require a proposer");var o=function(){if(null===t.sequenceNum)return Promise.resolve(f(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(r){e.accounts[t.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return o&&o.then?o.then(t):t()}n(e);var o=function(){if(n(e)&&null==e.message.refBlock)return Promise.resolve(s()).then(function(r){e.message.refBlock=r.id})}();return o&&o.then?o.then(t):t()}if(n(e)||t(e))for(var i=function(e){return r(null!=typeof e.xform,"No type specified for argument: "+e.value),ee(e.xform)?e.xform(e.value):ee(e.xform.asArgument)?e.xform.asArgument(e.value):void r(!1,"Invalid Argument",e)},u=0,c=Object.entries(e.arguments);u<c.length;u++){var l=c[u];e.arguments[l[0]].asArgument=i(l[1])}var d=function(){if(n(e)){var r=function(){e.accounts=t},t={},o=function(e,r,n){if("function"==typeof e[X]){var t,o,i,u=e[X]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!$(n))return void n.then(e,i||(i=Y.bind(null,o=new Z,2)));n=n.v}o?Y(o,1,n):o=n}catch(e){Y(o||(o=new Z),2,e)}}(),u.return){var s=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!$(u))return void u.then(n,o||(o=Y.bind(null,t=new Z,2)));u=u.v}t?Y(t,1,u):t=u}catch(e){Y(t||(t=new Z),2,e)}}(),t}(a,function(e){return r(a[e])})}(Object.entries(e.accounts),function(r){var n=r[0],o=r[1];function i(){t[n]=t[n]||o,t[n].role.proposer=t[n].role.proposer||o.role.proposer,t[n].role.payer=t[n].role.payer||o.role.payer,t[n].role.authorizer=t[n].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=n),e.payer===u&&(e.payer=n),e.authorizations=e.authorizations.map(function(e){return e===u?n:e})}var u=n,s=function(){if(ee(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){n=(o=e).tempId})}();return s&&s.then?s.then(i):i()});return o&&o.then?o.then(r):r()}}();return d&&d.then?d.then(o):o()}e=i;var c=function(){if(n(e)||t(e)){var i=function(){r(Q(u),"Cadence needs to be a string at this point."),e.message.cadence=u},u=o(e,"ix.cadence");r(ee(u)||Q(u),"Cadence needs to be a function or a string.");var s=function(){if(ee(u))return Promise.resolve(u({})).then(function(e){u=e})}();return s&&s.then?s.then(i):i()}}();return c&&c.then?c.then(u):u()})}catch(e){return Promise.reject(e)}});var ne,te,oe=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{var n=function(){return Promise.resolve(d(r)(e)).then(JSON.stringify)},t=function(){if(Array.isArray(e))return Promise.resolve(i(u(),e)).then(function(r){e=r})}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},ie=function(e){try{return Promise.resolve(b([S(e)]).then(E))}catch(e){return Promise.reject(e)}},ue=function(e){return e.status>=4},se=function(e){return e.status>=3},ae=function(e){return e.status>=2},ce=((ne={})[m]=function(e){try{return Promise.resolve(ie(e.self())).then(function(r){ue(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},ne[h]=function(e,r){e.subscribe(r.from),e.send(r.from,p,e.all())},ne[v]=function(e,r){e.unsubscribe(r.from)},ne[y]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ne.POLL=function(e){try{return Promise.resolve(ie(e.self())).then(function(r){var n,t;ue(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),t=r,JSON.stringify(n)!==JSON.stringify(t)&&e.broadcast(p,r),e.merge(r)})}catch(e){return Promise.reject(e)}},ne),fe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},le=function(e){return P(ce,fe(e))};function de(e){function r(r){return g(fe(e),le,r)}function n(e){return function(n){void 0===n&&(n={});var t=n.suppress||!1;return new Promise(function(n,o){var i=r(function(r){r.statusCode&&!t?(o(r.errorMessage),i()):e(r)&&(n(r),i())})})}}return{snapshot:function(){return w(e,le)},subscribe:r,onceFinalized:n(ae),onceExecuted:n(se),onceSealed:n(ue)}}de.isUnknown=function(e){return e.status>=0},de.isPending=function(e){return e.status>=1},de.isFinalized=ae,de.isExecuted=se,de.isSealed=ue,de.isExpired=function(e){return 5===e.status};var me=function(r){try{var n=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return n(function(){return r.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},he=((te={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(s()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(me(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(s()).then(function(n){return e.put("hwm",n),Promise.resolve(b([getEvents(e.self(),r.height,n.height-1)]).then(E)).then(function(r){for(var n,t=A(r);!(n=t()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(me(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},te[h]=function(e,r){try{var n=function(){e.subscribe(r.from)},t=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(me(e)).then(function(n){r.call(e,"tick",n)})}}();return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},te[v]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},te),pe=function(e){return P(he,e)};function ve(e){return{subscribe:function(r){return g(e,pe,r)}}}function ye(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()}]}}var ge={"@type":"Service","@vsn":"1.0.0"},Pe={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},ke={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:c(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},Pe,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},Pe,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function be(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ee(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function Se(e,r){void 0===r&&(r=!0);var n=new URL(e.endpoint);if(r)for(var t=0,o=Object.entries(e.params||{});t<o.length;t++){var i=o[t];n.searchParams.append(i[0],i[1])}return n}function Ie(e){return ye(Se(e).href)}var xe,Te={"HTTP/GET":"GET","HTTP/POST":"POST"},Ae=function(e,r){return null==r?"'"+e+"'":"'"+e+"' ("+r+")"},je=function(e,r){return"Missing "+Ae(e,r)+" in Composite Signature."},Le=function(e,r){return Ae(e,r)+" in Composit Signature did not match the requested "+e+"."},Ne={"HTTP/POST":function(e,r){try{var n=function(){},t=null;return Promise.resolve(function(e,r){try{var n=e()}catch(e){return r()}return n&&n.then?n.then(r,r):r()}(function(){return function(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(function(){return Promise.resolve(fetch(Se(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:r?JSON.stringify(r):void 0}).then(function(e){return e.json()})).then(function(e){if(console.log("RESP",e),e.local&&e.local.length>0){var r=Ie(e.local[0]);n=r[1]}return Promise.resolve(function e(r){return new Promise(function(n,t){try{return Promise.resolve(fetch(Se(r),{method:Te[r.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(r){"APPROVED"===r.status?n(r.compositeSignature):"DECLINED"===r.status?t({status:r.status,reason:r.reason}):setTimeout(function(){n(e(r.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})})},function(t){throw n(),Re(e,r,t),t})},function(){return n(),t}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,r){try{return Promise.resolve(new Promise(function(n,t){try{var o=I(),i=Ie(e),u=i[0],s=i[1],a=function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[r,e.params]})),"*")};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(),n(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),t({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),t({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}}),new Promise(function(e){window.addEventListener("message",n);var r=setTimeout(function(){window.removeEventListener("message",n),a(),e()},5e3);function n(t){"FCL::AUTHZ_READY"===t.data.type&&(clearTimeout(r),window.removeEventListener("message",n),a(),e())}})}catch(n){Re(e,r,n),t({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function Re(e,r,n){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:r},n)}function Ce(e,r,n){if(!e.s){if(n instanceof ze){if(!n.s)return void(n.o=Ce.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(Ce.bind(null,e,r),Ce.bind(null,e,2));e.s=r,e.v=n;var t=e.o;t&&t(e)}}var Oe=function(e){try{return We(),Promise.resolve(De()).then(function(n){Ee(n.services,"authn");var t=Ee(n.services,"authz");return Ee(n.services,"pre-authz"),x({},e,{tempId:"CURRENT_USER",resolve:null,addr:a(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(function(e,n){try{return Promise.resolve(Ne[e.method](e,n)).then(function(n){return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),n.addr=a(n.addr),function(e,n){try{var t={compSig:e,authz:n};r(e.addr,je("addr","Address"),t),r(e.keyId,je("keyId"),t),r(e.signature,je("signature"),t),r(e.keyId===n.identity.keyId,Le("keyId"),t),r(a(e.addr)===a(n.identity.address),Le("addr","Address"),t)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(n,e),n})}catch(e){return Promise.reject(e)}}(t,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},ze=function(){function e(){}return e.prototype.then=function(r,n){var t=new e,o=this.s;if(o){var i=1&o?r:n;if(i){try{Ce(t,1,i(this.v))}catch(e){Ce(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ce(t,1,r?r(o):o):n?Ce(t,1,n(o)):Ce(t,2,o)}catch(e){Ce(t,2,e)}},t},e}();function Ue(e){return e instanceof ze&&1&e.s}var De=function(){try{return Promise.resolve(new Promise(function(r){try{return We(),Promise.resolve($e()).then(function(n){return n.loggedIn&&Xe(n)?r(n):Promise.resolve(e().get("challenge.handshake")).then(function(e){var n,t,o,i=(t=(n={handshake:e,l6n:window.location.origin}).l6n,(o=new URL(n.handshake)).searchParams.append("l6n",t),ye(o.href))[1];window.addEventListener("message",function e(n){var t=n.data;try{return t.type===Me||t.type===Je?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==qe?Promise.resolve():(i(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var r=(e=function(e){return e.addr=e.addr?c(e.addr):null,e.paddr=e.paddr?c(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",r),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var n,t=A(e.authorizations);!(n=t()).done;)r.push(x({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&r.push(x({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var t,o,i=(t=r,o=n,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(r){return function(e,r){try{var n=ke[e.type](e,r);return console.log(e.type,{normalized:n,service:e}),n}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)});console.log("BUILD USER",i);var u=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,i);return x({},we,{addr:c(e.addr),cid:be(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return k(Be,_e,e),Promise.resolve($e()).then(function(e){r(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Be="CURRENT_USER",Fe="CURRENT_USER/UPDATED",_e="SET_CURRENT_USER",Je="FCL::CANCEL",qe="FCL::CHALLENGE::RESPONSE",Me="FCL::CHALLENGE::CANCEL",He='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ke=function(e){try{return sessionStorage.setItem(Be,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ge=function(){return e().get("persistSession",!0)},Ve=((xe={})[m]=function(e){try{return e.merge(JSON.parse(He)),Promise.resolve(Ge()).then(function(r){var n=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(He),r=JSON.parse(sessionStorage.getItem(Be));return null!=r&&e["@vsn"]!==r["@vsn"]?(sessionStorage.removeItem(Be),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){Xe(r)&&e.merge(r)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},xe[h]=function(e,r){e.subscribe(r.from),e.send(r.from,Fe,x({},e.all()))},xe[v]=function(e,r){e.unsubscribe(r.from)},xe.SNAPSHOT=function(e,r){try{return r.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},xe[_e]=function(e,r,n){try{return e.merge(n),Promise.resolve(Ge()).then(function(r){r&&Ke(e.all()),e.broadcast(Fe,x({},e.all()))})}catch(e){return Promise.reject(e)}},xe.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(He)),Promise.resolve(Ge()).then(function(r){r&&Ke(e.all()),e.broadcast(Fe,x({},e.all()))})}catch(e){return Promise.reject(e)}},xe),We=function(){return P(Ve,Be)};function Xe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ye(){We(),k(Be,"DEL_CURRENT_USER")}function Ze(e){We();var r=P(function(r){try{var n;return r.send(Be,h),Promise.resolve(function(e,r,n){for(var t;;){var o=e();if(Ue(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=n();if(i&&i.then){if(!Ue(i)){t=1;break}i=i.s}}var u=new ze,s=Ce.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ce(u,1,i)})).then(void 0,s),u;function a(r){i=r;do{if(!(o=e())||Ue(o)&&!o.v)return void Ce(u,1,i);if(o.then)return void o.then(c).then(void 0,s);Ue(i=n())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function c(e){e?(i=n())&&i.then?i.then(a).then(void 0,s):a(i):Ce(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(r.receive()).then(function(t){if("@EXIT"===t.tag)return r.send(Be,v),void(n=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return k(r,"@EXIT")}}function $e(){return We(),k(Be,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Qe=function(){return{authenticate:De,unauthenticate:Ye,authorization:Oe,subscribe:Ze,snapshot:$e}},er=function(){return Qe().authenticate()},rr=function(){return Qe().unauthenticate()},nr=function(){Qe().unauthenticate(),Qe().authenticate()},tr=function(){return Qe().authenticate()},or=function(){return Qe().authenticate()},ir=Qe().authorization,ur="0.0.67-alpha.2";export{ur as VERSION,er as authenticate,ir as authz,Qe as currentUser,ve as events,or as logIn,nr as reauthenticate,oe as serialize,tr as signUp,de as tx,rr as unauthenticate};
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{invariant as n}from"@onflow/util-invariant";import{isTransaction as r,isScript as t,get as o,pipe as i,interaction as u}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{latestBlock as s}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as a,withPrefix as c}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{account as f}from"@onflow/sdk-account";export{account}from"@onflow/sdk-account";import{encode as l}from"@onflow/rlp";import{resolve as d}from"@onflow/sdk-resolve";import{INIT as m,SUBSCRIBE as h,UPDATED as p,UNSUBSCRIBE as v,SNAPSHOT as y,subscriber as g,spawn as P,snapshoter as w,send as k}from"@onflow/util-actor";import{send as b}from"@onflow/sdk-send";export{send}from"@onflow/sdk-send";import{decode as E}from"@onflow/sdk-decode";export{decode}from"@onflow/sdk-decode";import{getTransactionStatus as S}from"@onflow/sdk-build-transaction-status";export{getTransactionStatus}from"@onflow/sdk-build-transaction-status";export{getEvents}from"@onflow/sdk-build-get-events";import{uid as I}from"@onflow/util-uid";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{getAccount}from"@onflow/sdk-build-get-account";export{getLatestBlock}from"@onflow/sdk-build-get-latest-block";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";function x(){return(x=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function T(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function A(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return T(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?T(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}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)}e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var j=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return j(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},R=function(e){return l(e).toString("hex")},C=function(e){return U(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(N),(n=e.refBlock,j(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},O=function(e){var n=z(e);return e.payloadSigs.map(function(e){return{signerIndex:n.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,n){return e.signerIndex>n.signerIndex?1:e.signerIndex<n.signerIndex?-1:e.keyId>n.keyId?1:e.keyId<n.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(n=e.sig,Buffer.from(n,"hex"))];var n})},z=function(e){var n=new Map,r=0,t=function(e){n.has(e)||(n.set(e,r),r++)};return t(e.proposalKey.address),t(e.payer),e.authorizers.forEach(t),n},U=function(e){J.forEach(function(n){return K(e,n)}),q.forEach(function(n){return K(e.proposalKey,n,"proposalKey")})},D=function(e){return"number"==typeof e},B=function(e){return"string"==typeof e},F=function(e){return null!==e&&"object"==typeof e},_=function(e){return F(e)&&e instanceof Array},J=[{name:"script",check:B},{name:"arguments",check:_},{name:"refBlock",check:B,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:F},{name:"payer",check:B},{name:"authorizers",check:_}],q=[{name:"address",check:B},{name:"keyId",check:D},{name:"sequenceNum",check:D}],M=[{name:"payloadSigs",check:_}],H=[{name:"address",check:B},{name:"keyId",check:D},{name:"sig",check:B}],K=function(e,n,r,t){var o=n.name,i=n.check,u=n.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw V(o,r,t);if(!i(e[o]))throw W(o,r,t)},G=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},V=function(e,n,r){return new Error("Missing field "+G(e,n,r))},W=function(e,n,r){return new Error("Invalid field "+G(e,n,r))},X="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Y(e,n,r){if(!e.s){if(r instanceof Z){if(!r.s)return void(r.o=Y.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Y.bind(null,e,n),Y.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Z=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{Y(t,1,i(this.v))}catch(e){Y(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Y(t,1,n?n(o):o):r?Y(t,1,r(o)):Y(t,2,o)}catch(e){Y(t,2,e)}},t},e}();function $(e){return e instanceof Z&&1&e.s}var Q=function(e){return"string"==typeof e},ee=function(e){return"function"==typeof e};function ne(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(n){return e.arguments[n].asArgument}),proposalKey:{address:a(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:a(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return a(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}e().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(i){function u(){function o(){function t(){function t(){var n=function(){if(r(e)){console.log("RESOLVE SIGNATURES START",e);var n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);var t=new Set([e.payer]);t=Array.from(t),console.log("SIGNATORIES",{insideSigners:n,outsideSigners:t});var o=(i=ne(e),R(C(i)));return Promise.resolve(Promise.all(n.map(function(n){try{var r=e.accounts[n];return null!=r.signature?Promise.resolve():Promise.resolve(r.signingFunction({message:o,addr:a(r.addr),keyId:r.keyId,roles:r.role,interaction:e})).then(function(r){e.accounts[n].signature=r.signature})}catch(e){return Promise.reject(e)}}))).then(function(){var r=function(e){return R(function(e){return function(e){M.forEach(function(n){return K(e,n)}),e.payloadSigs.forEach(function(e,n){H.forEach(function(r){return K(e,r,"payloadSigs",n)})})}(e),[C(e),O(e)]}(e))}(x({},ne(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:r,addr:a(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(r){e.accounts[n].signature=r.signature})}catch(e){return Promise.reject(e)}}))).then(function(){console.log("RESOLVE SIGNATURES END",e)})})}var i}();return n&&n.then?n.then(function(){return e}):e}var o=function(){if(r(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});n(t,"Transactions require a proposer");var o=function(){if(null===t.sequenceNum)return Promise.resolve(f(t.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===t.keyId})}).then(function(e){return e.sequenceNumber})).then(function(n){e.accounts[t.tempId].sequenceNum=n})}();if(o&&o.then)return o.then(function(){})}}();return o&&o.then?o.then(t):t()}r(e);var o=function(){if(r(e)&&null==e.message.refBlock)return Promise.resolve(s()).then(function(n){e.message.refBlock=n.id})}();return o&&o.then?o.then(t):t()}if(r(e)||t(e))for(var i=function(e){return n(null!=typeof e.xform,"No type specified for argument: "+e.value),ee(e.xform)?e.xform(e.value):ee(e.xform.asArgument)?e.xform.asArgument(e.value):void n(!1,"Invalid Argument",e)},u=0,c=Object.entries(e.arguments);u<c.length;u++){var l=c[u];e.arguments[l[0]].asArgument=i(l[1])}var d=function(){if(r(e)){var n=function(){e.accounts=t},t={},o=function(e,n,r){if("function"==typeof e[X]){var t,o,i,u=e[X]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!$(r))return void r.then(e,i||(i=Y.bind(null,o=new Z,2)));r=r.v}o?Y(o,1,r):o=r}catch(e){Y(o||(o=new Z),2,e)}}(),u.return){var s=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,n,r){var t,o,i=-1;return function r(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!$(u))return void u.then(r,o||(o=Y.bind(null,t=new Z,2)));u=u.v}t?Y(t,1,u):t=u}catch(e){Y(t||(t=new Z),2,e)}}(),t}(a,function(e){return n(a[e])})}(Object.entries(e.accounts),function(n){var r=n[0],o=n[1];function i(){t[r]=t[r]||o,t[r].role.proposer=t[r].role.proposer||o.role.proposer,t[r].role.payer=t[r].role.payer||o.role.payer,t[r].role.authorizer=t[r].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=r),e.payer===u&&(e.payer=r),e.authorizations=e.authorizations.map(function(e){return e===u?r:e})}var u=r,s=function(){if(ee(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return s&&s.then?s.then(i):i()});return o&&o.then?o.then(n):n()}}();return d&&d.then?d.then(o):o()}e=i;var c=function(){if(r(e)||t(e)){var i=function(){n(Q(u),"Cadence needs to be a string at this point."),e.message.cadence=u},u=o(e,"ix.cadence");n(ee(u)||Q(u),"Cadence needs to be a function or a string.");var s=function(){if(ee(u))return Promise.resolve(u({})).then(function(e){u=e})}();return s&&s.then?s.then(i):i()}}();return c&&c.then?c.then(u):u()})}catch(e){return Promise.reject(e)}});var re,te,oe=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var r=function(){return Promise.resolve(d(n)(e)).then(JSON.stringify)},t=function(){if(Array.isArray(e))return Promise.resolve(i(u(),e)).then(function(n){e=n})}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},ie=function(e){try{return Promise.resolve(b([S(e)]).then(E))}catch(e){return Promise.reject(e)}},ue=function(e){return e.status>=4},se=function(e){return e.status>=3},ae=function(e){return e.status>=2},ce=((re={})[m]=function(e){try{return Promise.resolve(ie(e.self())).then(function(n){ue(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},re[h]=function(e,n){e.subscribe(n.from),e.send(n.from,p,e.all())},re[v]=function(e,n){e.unsubscribe(n.from)},re[y]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},re.POLL=function(e){try{return Promise.resolve(ie(e.self())).then(function(n){var r,t;ue(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(p,n),e.merge(n)})}catch(e){return Promise.reject(e)}},re),fe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},le=function(e){return P(ce,fe(e))};function de(e){function n(n){return g(fe(e),le,n)}function r(e){return function(r){void 0===r&&(r={});var t=r.suppress||!1;return new Promise(function(r,o){var i=n(function(n){n.statusCode&&!t?(o(n.errorMessage),i()):e(n)&&(r(n),i())})})}}return{snapshot:function(){return w(e,le)},subscribe:n,onceFinalized:r(ae),onceExecuted:r(se),onceSealed:r(ue)}}de.isUnknown=function(e){return e.status>=0},de.isPending=function(e){return e.status>=1},de.isFinalized=ae,de.isExecuted=se,de.isSealed=ue,de.isExpired=function(e){return 5===e.status};var me=function(n){try{var r=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},he=((te={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(s()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(me(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(s()).then(function(r){return e.put("hwm",r),Promise.resolve(b([getEvents(e.self(),n.height,r.height-1)]).then(E)).then(function(n){for(var r,t=A(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(me(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},te[h]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(me(e)).then(function(r){n.call(e,"tick",r)})}}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},te[v]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},te),pe=function(e){return P(he,e)};function ve(e){return{subscribe:function(n){return g(e,pe,n)}}}function ye(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.style.position="fixed",n.style.top="0px",n.style.right="0px",n.style.left="0px",n.style.bottom="0px",n.style.height="100vh",n.style.width="100vw",n.style.display="block",n.style.background="rgba(0,0,0,0.25)",n.style.zIndex=2147483647,n.frameBorder="0",n.style.boxSizing="border-box",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}var ge={"@type":"Service","@vsn":"1.0.0"},Pe={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},ke={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:c(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},Pe,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},Pe,{address:c(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function be(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ee(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function Se(e,n){void 0===n&&(n=!0);var r=new URL(e.endpoint);if(n)for(var t=0,o=Object.entries(e.params||{});t<o.length;t++){var i=o[t];r.searchParams.append(i[0],i[1])}return r}function Ie(e){return ye(Se(e).href)}var xe,Te={"HTTP/GET":"GET","HTTP/POST":"POST"},Ae=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},je=function(e,n){return"Missing "+Ae(e,n)+" in Composite Signature."},Le=function(e,n){return Ae(e,n)+" in Composit Signature did not match the requested "+e+"."},Ne={"HTTP/POST":function(e,n){try{var r=function(){},t=null;return Promise.resolve(function(e,n){try{var r=e()}catch(e){return n()}return r&&r.then?r.then(n,n):n()}(function(){return function(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(function(){return Promise.resolve(fetch(Se(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:n?JSON.stringify(n):void 0}).then(function(e){return e.json()})).then(function(e){if(console.log("RESP",e),e.local&&e.local.length>0){var n=Ie(e.local[0]);r=n[1]}return Promise.resolve(function e(n){return new Promise(function(r,t){try{return Promise.resolve(fetch(Se(n),{method:Te[n.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){"APPROVED"===n.status?r(n.compositeSignature):"DECLINED"===n.status?t({status:n.status,reason:n.reason}):setTimeout(function(){r(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){t=e})})},function(t){throw r(),Re(e,n,t),t})},function(){return r(),t}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){try{return Promise.resolve(new Promise(function(r,t){try{var o=I(),i=Ie(e),u=i[0],s=i[1],a=function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})),"*")};window.addEventListener("message",function e(n){var i=n.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(),r(u.compositeSignature)):"DECLINED"===u.status?(window.removeEventListener("message",e),s(),t({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),t({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}}),new Promise(function(e){window.addEventListener("message",r);var n=setTimeout(function(){window.removeEventListener("message",r),a(),e()},5e3);function r(t){"FCL::AUTHZ_READY"===t.data.type&&(clearTimeout(n),window.removeEventListener("message",r),a(),e())}})}catch(r){Re(e,n,r),t({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function Re(e,n,r){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:n},r)}function Ce(e,n,r){if(!e.s){if(r instanceof ze){if(!r.s)return void(r.o=Ce.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Ce.bind(null,e,n),Ce.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Oe=function(e){try{return We(),Promise.resolve(De()).then(function(r){Ee(r.services,"authn");var t=Ee(r.services,"authz");return Ee(r.services,"pre-authz"),x({},e,{tempId:"CURRENT_USER",resolve:null,addr:a(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(function(e,r){try{return Promise.resolve(Ne[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=a(r.addr),function(e,r){try{var t={compSig:e,authz:r};n(e.addr,je("addr","Address"),t),n(null!=e.keyId,je("keyId"),t),n(e.signature,je("signature"),t),n(e.keyId===r.identity.keyId,Le("keyId"),t),n(a(e.addr)===a(r.identity.address),Le("addr","Address"),t)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(r,e),r})}catch(e){return Promise.reject(e)}}(t,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},ze=function(){function e(){}return e.prototype.then=function(n,r){var t=new e,o=this.s;if(o){var i=1&o?n:r;if(i){try{Ce(t,1,i(this.v))}catch(e){Ce(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ce(t,1,n?n(o):o):r?Ce(t,1,r(o)):Ce(t,2,o)}catch(e){Ce(t,2,e)}},t},e}();function Ue(e){return e instanceof ze&&1&e.s}var De=function(){try{return Promise.resolve(new Promise(function(n){try{return We(),Promise.resolve($e()).then(function(r){return r.loggedIn&&Xe(r)?n(r):Promise.resolve(e().get("challenge.handshake")).then(function(e){var r,t,o,i=(t=(r={handshake:e,l6n:window.location.origin}).l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),ye(o.href))[1];window.addEventListener("message",function e(r){var t=r.data;try{return t.type===Me||t.type===Je?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==qe?Promise.resolve():(i(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?c(e.addr):null,e.paddr=e.paddr?c(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",n),Promise.resolve(fetch(r,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var n=[];if(Array.isArray(e.authorizations))for(var r,t=A(e.authorizations);!(r=t()).done;)n.push(x({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(x({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,o,i=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{var r=ke[e.type](e,n);return console.log(e.type,{normalized:r,service:e}),r}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)});console.log("BUILD USER",i);var u=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,i);return x({},we,{addr:c(e.addr),cid:be(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return k(Be,_e,e),Promise.resolve($e()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Be="CURRENT_USER",Fe="CURRENT_USER/UPDATED",_e="SET_CURRENT_USER",Je="FCL::CANCEL",qe="FCL::CHALLENGE::RESPONSE",Me="FCL::CHALLENGE::CANCEL",He='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ke=function(e){try{return sessionStorage.setItem(Be,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ge=function(){return e().get("persistSession",!0)},Ve=((xe={})[m]=function(e){try{return e.merge(JSON.parse(He)),Promise.resolve(Ge()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(He),n=JSON.parse(sessionStorage.getItem(Be));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Be),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){Xe(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},xe[h]=function(e,n){e.subscribe(n.from),e.send(n.from,Fe,x({},e.all()))},xe[v]=function(e,n){e.unsubscribe(n.from)},xe.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},xe[_e]=function(e,n,r){try{return e.merge(r),Promise.resolve(Ge()).then(function(n){n&&Ke(e.all()),e.broadcast(Fe,x({},e.all()))})}catch(e){return Promise.reject(e)}},xe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(He)),Promise.resolve(Ge()).then(function(n){n&&Ke(e.all()),e.broadcast(Fe,x({},e.all()))})}catch(e){return Promise.reject(e)}},xe),We=function(){return P(Ve,Be)};function Xe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ye(){We(),k(Be,"DEL_CURRENT_USER")}function Ze(e){We();var n=P(function(n){try{var r;return n.send(Be,h),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ue(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ue(i)){t=1;break}i=i.s}}var u=new ze,s=Ce.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ce(u,1,i)})).then(void 0,s),u;function a(n){i=n;do{if(!(o=e())||Ue(o)&&!o.v)return void Ce(u,1,i);if(o.then)return void o.then(c).then(void 0,s);Ue(i=r())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function c(e){e?(i=r())&&i.then?i.then(a).then(void 0,s):a(i):Ce(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Be,v),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return k(n,"@EXIT")}}function $e(){return We(),k(Be,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Qe=function(){return{authenticate:De,unauthenticate:Ye,authorization:Oe,subscribe:Ze,snapshot:$e}},en=function(){return Qe().authenticate()},nn=function(){return Qe().unauthenticate()},rn=function(){Qe().unauthenticate(),Qe().authenticate()},tn=function(){return Qe().authenticate()},on=function(){return Qe().authenticate()},un=Qe().authorization,sn="0.0.67-alpha.3";export{sn as VERSION,en as authenticate,un as authz,Qe as currentUser,ve as events,on as logIn,rn as reauthenticate,oe as serialize,tn as signUp,de as tx,nn as unauthenticate};
//# sourceMappingURL=fcl.module.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/config"),require("@onflow/util-invariant"),require("@onflow/interaction"),require("@onflow/sdk-latest-block"),require("@onflow/util-address"),require("@onflow/sdk-account"),require("@onflow/rlp"),require("@onflow/sdk-resolve"),require("@onflow/util-actor"),require("@onflow/sdk-send"),require("@onflow/sdk-decode"),require("@onflow/sdk-build-transaction-status"),require("@onflow/sdk-build-get-events"),require("@onflow/util-uid"),require("@onflow/util-template"),require("@onflow/sdk-build-transaction"),require("@onflow/sdk-build-script"),require("@onflow/sdk-build-ping"),require("@onflow/sdk-build-get-account"),require("@onflow/sdk-build-get-latest-block"),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/util-invariant","@onflow/interaction","@onflow/sdk-latest-block","@onflow/util-address","@onflow/sdk-account","@onflow/rlp","@onflow/sdk-resolve","@onflow/util-actor","@onflow/sdk-send","@onflow/sdk-decode","@onflow/sdk-build-transaction-status","@onflow/sdk-build-get-events","@onflow/util-uid","@onflow/util-template","@onflow/sdk-build-transaction","@onflow/sdk-build-script","@onflow/sdk-build-ping","@onflow/sdk-build-get-account","@onflow/sdk-build-get-latest-block","@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"],n):n((e=e||self).fcl={},e.config,e.utilInvariant,e.interaction,e.sdkLatestBlock,e.utilAddress,e.sdkAccount,e.rlp,e.sdkResolve,e.utilActor,e.sdkSend,e.sdkDecode,e.sdkBuildTransactionStatus,e.sdkBuildGetEvents,e.utilUid,e.utilTemplate,e.sdkBuildTransaction,e.sdkBuildScript,e.sdkBuildPing,e.sdkBuildGetAccount,e.sdkBuildGetLatestBlock,e.sdkBuildGetBlockById,e.sdkBuildGetBlockByHeight,e.sdkBuildAuthorizations,e.sdkBuildArguments,e.sdkBuildProposer,e.sdkBuildPayer,e.sdkBuildLimit,e.sdkBuildRef,e.sdkBuildParams)}(this,function(e,n,t,r,o,i,u,s,a,c,f,l,d,h,m,p,v,y,g,b,P,k,w,S,E,I,j,O,B,T){function x(){return(x=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function A(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function R(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return A(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(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?A(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var L=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},N=function(e){return L(e,8)},C=function(e){return Buffer.from(JSON.stringify(e),"utf8")},U=function(e){return s.encode(e).toString("hex")},q=function(e){return F(e),[(t=e.script,Buffer.from(t,"utf8")),e.arguments.map(C),(n=e.refBlock,L(n,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var n,t},z=function(e){var n=D(e);return e.payloadSigs.map(function(e){return{signerIndex:n.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,n){return e.signerIndex>n.signerIndex?1:e.signerIndex<n.signerIndex?-1:e.keyId>n.keyId?1:e.keyId<n.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(n=e.sig,Buffer.from(n,"hex"))];var n})},D=function(e){var n=new Map,t=0,r=function(e){n.has(e)||(n.set(e,t),t++)};return r(e.proposalKey.address),r(e.payer),e.authorizers.forEach(r),n},F=function(e){M.forEach(function(n){return X(e,n)}),K.forEach(function(n){return X(e.proposalKey,n,"proposalKey")})},_=function(e){return"number"==typeof e},G=function(e){return"string"==typeof e},H=function(e){return null!==e&&"object"==typeof e},J=function(e){return H(e)&&e instanceof Array},M=[{name:"script",check:G},{name:"arguments",check:J},{name:"refBlock",check:G,defaultVal:"0"},{name:"gasLimit",check:_},{name:"proposalKey",check:H},{name:"payer",check:G},{name:"authorizers",check:J}],K=[{name:"address",check:G},{name:"keyId",check:_},{name:"sequenceNum",check:_}],V=[{name:"payloadSigs",check:J}],W=[{name:"address",check:G},{name:"keyId",check:_},{name:"sig",check:G}],X=function(e,n,t,r){var o=n.name,i=n.check,u=n.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw Z(o,t,r);if(!i(e[o]))throw $(o,t,r)},Y=function(e,n,t){return n?null==t?n+"."+e:n+"."+t+"."+e:e},Z=function(e,n,t){return new Error("Missing field "+Y(e,n,t))},$=function(e,n,t){return new Error("Invalid field "+Y(e,n,t))},Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ee(e,n,t){if(!e.s){if(t instanceof ne){if(!t.s)return void(t.o=ee.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(ee.bind(null,e,n),ee.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var ne=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{ee(r,1,i(this.v))}catch(e){ee(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(r,1,n?n(o):o):t?ee(r,1,t(o)):ee(r,2,o)}catch(e){ee(r,2,e)}},r},e}();function te(e){return e instanceof ne&&1&e.s}var re=function(e){return"string"==typeof e},oe=function(e){return"function"==typeof e};function ie(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(n){return e.arguments[n].asArgument}),proposalKey:{address:i.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:i.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return i.sansPrefix(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}n.config().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(n){function s(){function n(){function n(){function n(){var n=function(){if(r.isTransaction(e)){console.log("RESOLVE SIGNATURES START",e);var n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);var t=new Set([e.payer]);t=Array.from(t),console.log("SIGNATORIES",{insideSigners:n,outsideSigners:t});var o=(u=ie(e),U(q(u)));return Promise.resolve(Promise.all(n.map(function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:o,addr:i.sansPrefix(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(t){e.accounts[n].signature=t.signature})}catch(e){return Promise.reject(e)}}))).then(function(){var r=function(e){return U(function(e){return function(e){V.forEach(function(n){return X(e,n)}),e.payloadSigs.forEach(function(e,n){W.forEach(function(t){return X(e,t,"payloadSigs",n)})})}(e),[q(e),z(e)]}(e))}(x({},ie(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:r,addr:i.sansPrefix(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(t){e.accounts[n].signature=t.signature})}catch(e){return Promise.reject(e)}}))).then(function(){console.log("RESOLVE SIGNATURES END",e)})})}var u}();return n&&n.then?n.then(function(){return e}):e}var o=function(){if(r.isTransaction(e)){var n=Object.values(e.accounts).find(function(e){return e.role.proposer});t.invariant(n,"Transactions require a proposer");var o=function(){if(null===n.sequenceNum)return Promise.resolve(u.account(n.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===n.keyId})}).then(function(e){return e.sequenceNumber})).then(function(t){e.accounts[n.tempId].sequenceNum=t})}();if(o&&o.then)return o.then(function(){})}}();return o&&o.then?o.then(n):n()}r.isTransaction(e);var s=function(){if(r.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(o.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return s&&s.then?s.then(n):n()}if(r.isTransaction(e)||r.isScript(e))for(var s=0,a=Object.entries(e.arguments);s<a.length;s++){var c=a[s];e.arguments[c[0]].asArgument=(t.invariant(null!=typeof(f=c[1]).xform,"No type specified for argument: "+f.value),oe(f.xform)?f.xform(f.value):oe(f.xform.asArgument)?f.xform.asArgument(f.value):void t.invariant(!1,"Invalid Argument",f))}var f,l=function(){if(r.isTransaction(e)){var n=function(){e.accounts=t},t={},o=function(e,n,t){if("function"==typeof e[Q]){var r,o,i,u=e[Q]();if(function e(t){try{for(;!(r=u.next()).done;)if((t=n(r.value))&&t.then){if(!te(t))return void t.then(e,i||(i=ee.bind(null,o=new ne,2)));t=t.v}o?ee(o,1,t):o=t}catch(e){ee(o||(o=new ne),2,e)}}(),u.return){var s=function(e){try{r.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,n,t){var r,o,i=-1;return function t(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!te(u))return void u.then(t,o||(o=ee.bind(null,r=new ne,2)));u=u.v}r?ee(r,1,u):r=u}catch(e){ee(r||(r=new ne),2,e)}}(),r}(a,function(e){return n(a[e])})}(Object.entries(e.accounts),function(n){var r=n[0],o=n[1];function i(){t[r]=t[r]||o,t[r].role.proposer=t[r].role.proposer||o.role.proposer,t[r].role.payer=t[r].role.payer||o.role.payer,t[r].role.authorizer=t[r].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=r),e.payer===u&&(e.payer=r),e.authorizations=e.authorizations.map(function(e){return e===u?r:e})}var u=r,s=function(){if(oe(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return s&&s.then?s.then(i):i()});return o&&o.then?o.then(n):n()}}();return l&&l.then?l.then(n):n()}e=n;var a=function(){if(r.isTransaction(e)||r.isScript(e)){var n=function(){t.invariant(re(o),"Cadence needs to be a string at this point."),e.message.cadence=o},o=r.get(e,"ix.cadence");t.invariant(oe(o)||re(o),"Cadence needs to be a function or a string.");var i=function(){if(oe(o))return Promise.resolve(o({})).then(function(e){o=e})}();return i&&i.then?i.then(n):n()}}();return a&&a.then?a.then(s):s()})}catch(e){return Promise.reject(e)}});var ue,se,ae=function(e){try{return Promise.resolve(f.send([d.getTransactionStatus(e)]).then(l.decode))}catch(e){return Promise.reject(e)}},ce=function(e){return e.status>=4},fe=function(e){return e.status>=3},le=function(e){return e.status>=2},de=((ue={})[c.INIT]=function(e){try{return Promise.resolve(ae(e.self())).then(function(n){ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ue[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,c.UPDATED,e.all())},ue[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ue[c.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ue.POLL=function(e){try{return Promise.resolve(ae(e.self())).then(function(n){var t,r;ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),r=n,JSON.stringify(t)!==JSON.stringify(r)&&e.broadcast(c.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ue),he=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},me=function(e){return c.spawn(de,he(e))};function pe(e){function n(n){return c.subscriber(he(e),me,n)}function t(e){return function(t){void 0===t&&(t={});var r=t.suppress||!1;return new Promise(function(t,o){var i=n(function(n){n.statusCode&&!r?(o(n.errorMessage),i()):e(n)&&(t(n),i())})})}}return{snapshot:function(){return c.snapshoter(e,me)},subscribe:n,onceFinalized:t(le),onceExecuted:t(fe),onceSealed:t(ce)}}pe.isUnknown=function(e){return e.status>=0},pe.isPending=function(e){return e.status>=1},pe.isFinalized=le,pe.isExecuted=fe,pe.isSealed=ce,pe.isExpired=function(e){return 5===e.status};var ve=function(e){try{var t=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return t(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},ye=((se={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),t=function(){if(null==n){var t=e.put;return Promise.resolve(o.latestBlock()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve(ve(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(o.latestBlock()).then(function(t){return e.put("hwm",t),Promise.resolve(f.send([getEvents(e.self(),n.height,t.height-1)]).then(l.decode)).then(function(n){for(var t,r=R(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(ve(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},se[c.SUBSCRIBE]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ve(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},se[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},se),ge=function(e){return c.spawn(ye,e)};function be(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.style.position="fixed",n.style.top="0px",n.style.right="0px",n.style.left="0px",n.style.bottom="0px",n.style.height="100vh",n.style.width="100vw",n.style.display="block",n.style.background="rgba(0,0,0,0.25)",n.style.zIndex=2147483647,n.frameBorder="0",n.style.boxSizing="border-box",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}var Pe={"@type":"Service","@vsn":"1.0.0"},ke={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},Se={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},Pe,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function Ee(e){return s.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ie(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function je(e,n){void 0===n&&(n=!0);var t=new URL(e.endpoint);if(n)for(var r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return t}function Oe(e){return be(je(e).href)}var Be,Te={"HTTP/GET":"GET","HTTP/POST":"POST"},xe=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ae=function(e,n){return"Missing "+xe(e,n)+" in Composite Signature."},Re=function(e,n){return xe(e,n)+" in Composit Signature did not match the requested "+e+"."},Le={"HTTP/POST":function(e,n){try{var t=function(){},r=null;return Promise.resolve(function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(fetch(je(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:n?JSON.stringify(n):void 0}).then(function(e){return e.json()})).then(function(e){if(console.log("RESP",e),e.local&&e.local.length>0){var n=Oe(e.local[0]);t=n[1]}return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(fetch(je(n),{method:Te[n.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){r=e})})},function(r){throw t(),Ne(e,n,r),r})},function(){return t(),r}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){try{return Promise.resolve(new Promise(function(t,r){try{var o=m.uid(),i=Oe(e),u=i[0],s=i[1],a=function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})),"*")};window.addEventListener("message",function e(n){var i=n.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(),r({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),r({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}}),new Promise(function(e){window.addEventListener("message",t);var n=setTimeout(function(){window.removeEventListener("message",t),a(),e()},5e3);function t(r){"FCL::AUTHZ_READY"===r.data.type&&(clearTimeout(n),window.removeEventListener("message",t),a(),e())}})}catch(t){Ne(e,n,t),r({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function Ne(e,n,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:n},t)}function Ce(e,n,t){if(!e.s){if(t instanceof qe){if(!t.s)return void(t.o=Ce.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(Ce.bind(null,e,n),Ce.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var Ue=function(e){try{return Ye(),Promise.resolve(De()).then(function(n){Ie(n.services,"authn");var r=Ie(n.services,"authz");return Ie(n.services,"pre-authz"),x({},e,{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(function(e,n){try{return Promise.resolve(Le[e.method](e,n)).then(function(n){return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),n.addr=i.sansPrefix(n.addr),function(e,n){try{var r={compSig:e,authz:n};t.invariant(e.addr,Ae("addr","Address"),r),t.invariant(e.keyId,Ae("keyId"),r),t.invariant(e.signature,Ae("signature"),r),t.invariant(e.keyId===n.identity.keyId,Re("keyId"),r),t.invariant(i.sansPrefix(e.addr)===i.sansPrefix(n.identity.address),Re("addr","Address"),r)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(n,e),n})}catch(e){return Promise.reject(e)}}(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},qe=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{Ce(r,1,i(this.v))}catch(e){Ce(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ce(r,1,n?n(o):o):t?Ce(r,1,t(o)):Ce(r,2,o)}catch(e){Ce(r,2,e)}},r},e}();function ze(e){return e instanceof qe&&1&e.s}var De=function(){try{return Promise.resolve(new Promise(function(e){try{return Ye(),Promise.resolve(en()).then(function(t){return t.loggedIn&&Ze(t)?e(t):Promise.resolve(n.config().get("challenge.handshake")).then(function(n){var t,r,o,u=(r=(t={handshake:n,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",r),be(o.href))[1];window.addEventListener("message",function n(t){var r=t.data;try{return r.type===Me||r.type===He?(u(),window.removeEventListener("message",n),Promise.resolve()):r.type!==Je?Promise.resolve():(u(),window.removeEventListener("message",n),Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?i.withPrefix(e.addr):null,e.paddr=e.paddr?i.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",n),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 n=[];if(Array.isArray(e.authorizations))for(var t,r=R(e.authorizations);!(t=r()).done;)n.push(x({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&n.push(x({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(t){var r,o,u=(r=n,o=t,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(n){return function(e,n){try{var t=Se[e.type](e,n);return console.log(e.type,{normalized:t,service:e}),t}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)});console.log("BUILD USER",u);var s=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return x({},we,{addr:i.withPrefix(e.addr),cid:Ee(s),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(r)).then(function(n){return c.send(Fe,Ge,n),Promise.resolve(en()).then(function(n){e(n)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Fe="CURRENT_USER",_e="CURRENT_USER/UPDATED",Ge="SET_CURRENT_USER",He="FCL::CANCEL",Je="FCL::CHALLENGE::RESPONSE",Me="FCL::CHALLENGE::CANCEL",Ke='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ve=function(e){try{return sessionStorage.setItem(Fe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},We=function(){return n.config().get("persistSession",!0)},Xe=((Be={})[c.INIT]=function(e){try{return e.merge(JSON.parse(Ke)),Promise.resolve(We()).then(function(n){var t=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(Ke),n=JSON.parse(sessionStorage.getItem(Fe));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Fe),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){Ze(n)&&e.merge(n)})}();if(t&&t.then)return t.then(function(){})})}catch(e){return Promise.reject(e)}},Be[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,_e,x({},e.all()))},Be[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Be.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Be[Ge]=function(e,n,t){try{return e.merge(t),Promise.resolve(We()).then(function(n){n&&Ve(e.all()),e.broadcast(_e,x({},e.all()))})}catch(e){return Promise.reject(e)}},Be.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(Ke)),Promise.resolve(We()).then(function(n){n&&Ve(e.all()),e.broadcast(_e,x({},e.all()))})}catch(e){return Promise.reject(e)}},Be),Ye=function(){return c.spawn(Xe,Fe)};function Ze(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function $e(){Ye(),c.send(Fe,"DEL_CURRENT_USER")}function Qe(e){Ye();var n=c.spawn(function(n){try{var t;return n.send(Fe,c.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(ze(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!ze(i)){r=1;break}i=i.s}}var u=new qe,s=Ce.bind(null,u,2);return(0===r?o.then(c):1===r?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ce(u,1,i)})).then(void 0,s),u;function a(n){i=n;do{if(!(o=e())||ze(o)&&!o.v)return void Ce(u,1,i);if(o.then)return void o.then(c).then(void 0,s);ze(i=t())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function c(e){e?(i=t())&&i.then?i.then(a).then(void 0,s):a(i):Ce(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(Fe,c.UNSUBSCRIBE),void(t=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return c.send(n,"@EXIT")}}function en(){return Ye(),c.send(Fe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var nn=function(){return{authenticate:De,unauthenticate:$e,authorization:Ue,subscribe:Qe,snapshot:en}},tn=nn().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return o.latestBlock}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return u.account}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return f.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return l.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return h.getEvents}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return p.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return p.template}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return v.transaction}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return y.script}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return g.ping}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return b.getAccount}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return k.getBlockById}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return w.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 E.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return E.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return I.proposer}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return j.payer}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return O.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return B.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return T.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return T.params}}),e.VERSION="0.0.67-alpha.2",e.authenticate=function(){return nn().authenticate()},e.authz=tn,e.currentUser=nn,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,ge,n)}}},e.logIn=function(){return nn().authenticate()},e.reauthenticate=function(){nn().unauthenticate(),nn().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var t=function(){return Promise.resolve(a.resolve(n)(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(r.pipe(r.interaction(),e)).then(function(n){e=n})}();return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},e.signUp=function(){return nn().authenticate()},e.tx=pe,e.unauthenticate=function(){return nn().unauthenticate()}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@onflow/config"),require("@onflow/util-invariant"),require("@onflow/interaction"),require("@onflow/sdk-latest-block"),require("@onflow/util-address"),require("@onflow/sdk-account"),require("@onflow/rlp"),require("@onflow/sdk-resolve"),require("@onflow/util-actor"),require("@onflow/sdk-send"),require("@onflow/sdk-decode"),require("@onflow/sdk-build-transaction-status"),require("@onflow/sdk-build-get-events"),require("@onflow/util-uid"),require("@onflow/util-template"),require("@onflow/sdk-build-transaction"),require("@onflow/sdk-build-script"),require("@onflow/sdk-build-ping"),require("@onflow/sdk-build-get-account"),require("@onflow/sdk-build-get-latest-block"),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/util-invariant","@onflow/interaction","@onflow/sdk-latest-block","@onflow/util-address","@onflow/sdk-account","@onflow/rlp","@onflow/sdk-resolve","@onflow/util-actor","@onflow/sdk-send","@onflow/sdk-decode","@onflow/sdk-build-transaction-status","@onflow/sdk-build-get-events","@onflow/util-uid","@onflow/util-template","@onflow/sdk-build-transaction","@onflow/sdk-build-script","@onflow/sdk-build-ping","@onflow/sdk-build-get-account","@onflow/sdk-build-get-latest-block","@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"],n):n((e=e||self).fcl={},e.config,e.utilInvariant,e.interaction,e.sdkLatestBlock,e.utilAddress,e.sdkAccount,e.rlp,e.sdkResolve,e.utilActor,e.sdkSend,e.sdkDecode,e.sdkBuildTransactionStatus,e.sdkBuildGetEvents,e.utilUid,e.utilTemplate,e.sdkBuildTransaction,e.sdkBuildScript,e.sdkBuildPing,e.sdkBuildGetAccount,e.sdkBuildGetLatestBlock,e.sdkBuildGetBlockById,e.sdkBuildGetBlockByHeight,e.sdkBuildAuthorizations,e.sdkBuildArguments,e.sdkBuildProposer,e.sdkBuildPayer,e.sdkBuildLimit,e.sdkBuildRef,e.sdkBuildParams)}(this,function(e,n,t,r,o,i,u,s,a,c,f,l,d,h,m,p,v,y,g,b,P,k,w,S,E,I,j,O,B,T){function x(){return(x=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function A(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function R(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return A(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(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?A(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var L=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},N=function(e){return L(e,8)},C=function(e){return Buffer.from(JSON.stringify(e),"utf8")},U=function(e){return s.encode(e).toString("hex")},q=function(e){return F(e),[(t=e.script,Buffer.from(t,"utf8")),e.arguments.map(C),(n=e.refBlock,L(n,32)),e.gasLimit,N(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,N(e.payer),e.authorizers.map(N)];var n,t},z=function(e){var n=D(e);return e.payloadSigs.map(function(e){return{signerIndex:n.get(e.address),keyId:e.keyId,sig:e.sig}}).sort(function(e,n){return e.signerIndex>n.signerIndex?1:e.signerIndex<n.signerIndex?-1:e.keyId>n.keyId?1:e.keyId<n.keyId?-1:void 0}).map(function(e){return[e.signerIndex,e.keyId,(n=e.sig,Buffer.from(n,"hex"))];var n})},D=function(e){var n=new Map,t=0,r=function(e){n.has(e)||(n.set(e,t),t++)};return r(e.proposalKey.address),r(e.payer),e.authorizers.forEach(r),n},F=function(e){M.forEach(function(n){return X(e,n)}),K.forEach(function(n){return X(e.proposalKey,n,"proposalKey")})},_=function(e){return"number"==typeof e},G=function(e){return"string"==typeof e},H=function(e){return null!==e&&"object"==typeof e},J=function(e){return H(e)&&e instanceof Array},M=[{name:"script",check:G},{name:"arguments",check:J},{name:"refBlock",check:G,defaultVal:"0"},{name:"gasLimit",check:_},{name:"proposalKey",check:H},{name:"payer",check:G},{name:"authorizers",check:J}],K=[{name:"address",check:G},{name:"keyId",check:_},{name:"sequenceNum",check:_}],V=[{name:"payloadSigs",check:J}],W=[{name:"address",check:G},{name:"keyId",check:_},{name:"sig",check:G}],X=function(e,n,t,r){var o=n.name,i=n.check,u=n.defaultVal;if(null==e[o]&&null!=u&&(e[o]=u),null==e[o])throw Z(o,t,r);if(!i(e[o]))throw $(o,t,r)},Y=function(e,n,t){return n?null==t?n+"."+e:n+"."+t+"."+e:e},Z=function(e,n,t){return new Error("Missing field "+Y(e,n,t))},$=function(e,n,t){return new Error("Invalid field "+Y(e,n,t))},Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ee(e,n,t){if(!e.s){if(t instanceof ne){if(!t.s)return void(t.o=ee.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(ee.bind(null,e,n),ee.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var ne=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{ee(r,1,i(this.v))}catch(e){ee(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(r,1,n?n(o):o):t?ee(r,1,t(o)):ee(r,2,o)}catch(e){ee(r,2,e)}},r},e}();function te(e){return e instanceof ne&&1&e.s}var re=function(e){return"string"==typeof e},oe=function(e){return"function"==typeof e};function ie(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(n){return e.arguments[n].asArgument}),proposalKey:{address:i.sansPrefix(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:i.sansPrefix(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return i.sansPrefix(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}n.config().put("sdk.resolve",function(e){try{return Promise.resolve(e).then(function(n){function s(){function n(){function n(){function n(){var n=function(){if(r.isTransaction(e)){console.log("RESOLVE SIGNATURES START",e);var n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);var t=new Set([e.payer]);t=Array.from(t),console.log("SIGNATORIES",{insideSigners:n,outsideSigners:t});var o=(u=ie(e),U(q(u)));return Promise.resolve(Promise.all(n.map(function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:o,addr:i.sansPrefix(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(t){e.accounts[n].signature=t.signature})}catch(e){return Promise.reject(e)}}))).then(function(){var r=function(e){return U(function(e){return function(e){V.forEach(function(n){return X(e,n)}),e.payloadSigs.forEach(function(e,n){W.forEach(function(t){return X(e,t,"payloadSigs",n)})})}(e),[q(e),z(e)]}(e))}(x({},ie(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(function(n){try{var t=e.accounts[n];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction({message:r,addr:i.sansPrefix(t.addr),keyId:t.keyId,roles:t.role,interaction:e})).then(function(t){e.accounts[n].signature=t.signature})}catch(e){return Promise.reject(e)}}))).then(function(){console.log("RESOLVE SIGNATURES END",e)})})}var u}();return n&&n.then?n.then(function(){return e}):e}var o=function(){if(r.isTransaction(e)){var n=Object.values(e.accounts).find(function(e){return e.role.proposer});t.invariant(n,"Transactions require a proposer");var o=function(){if(null===n.sequenceNum)return Promise.resolve(u.account(n.addr).then(function(e){return e.keys}).then(function(e){return e.find(function(e){return e.index===n.keyId})}).then(function(e){return e.sequenceNumber})).then(function(t){e.accounts[n.tempId].sequenceNum=t})}();if(o&&o.then)return o.then(function(){})}}();return o&&o.then?o.then(n):n()}r.isTransaction(e);var s=function(){if(r.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(o.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return s&&s.then?s.then(n):n()}if(r.isTransaction(e)||r.isScript(e))for(var s=0,a=Object.entries(e.arguments);s<a.length;s++){var c=a[s];e.arguments[c[0]].asArgument=(t.invariant(null!=typeof(f=c[1]).xform,"No type specified for argument: "+f.value),oe(f.xform)?f.xform(f.value):oe(f.xform.asArgument)?f.xform.asArgument(f.value):void t.invariant(!1,"Invalid Argument",f))}var f,l=function(){if(r.isTransaction(e)){var n=function(){e.accounts=t},t={},o=function(e,n,t){if("function"==typeof e[Q]){var r,o,i,u=e[Q]();if(function e(t){try{for(;!(r=u.next()).done;)if((t=n(r.value))&&t.then){if(!te(t))return void t.then(e,i||(i=ee.bind(null,o=new ne,2)));t=t.v}o?ee(o,1,t):o=t}catch(e){ee(o||(o=new ne),2,e)}}(),u.return){var s=function(e){try{r.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,n,t){var r,o,i=-1;return function t(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!te(u))return void u.then(t,o||(o=ee.bind(null,r=new ne,2)));u=u.v}r?ee(r,1,u):r=u}catch(e){ee(r||(r=new ne),2,e)}}(),r}(a,function(e){return n(a[e])})}(Object.entries(e.accounts),function(n){var r=n[0],o=n[1];function i(){t[r]=t[r]||o,t[r].role.proposer=t[r].role.proposer||o.role.proposer,t[r].role.payer=t[r].role.payer||o.role.payer,t[r].role.authorizer=t[r].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=r),e.payer===u&&(e.payer=r),e.authorizations=e.authorizations.map(function(e){return e===u?r:e})}var u=r,s=function(){if(oe(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return s&&s.then?s.then(i):i()});return o&&o.then?o.then(n):n()}}();return l&&l.then?l.then(n):n()}e=n;var a=function(){if(r.isTransaction(e)||r.isScript(e)){var n=function(){t.invariant(re(o),"Cadence needs to be a string at this point."),e.message.cadence=o},o=r.get(e,"ix.cadence");t.invariant(oe(o)||re(o),"Cadence needs to be a function or a string.");var i=function(){if(oe(o))return Promise.resolve(o({})).then(function(e){o=e})}();return i&&i.then?i.then(n):n()}}();return a&&a.then?a.then(s):s()})}catch(e){return Promise.reject(e)}});var ue,se,ae=function(e){try{return Promise.resolve(f.send([d.getTransactionStatus(e)]).then(l.decode))}catch(e){return Promise.reject(e)}},ce=function(e){return e.status>=4},fe=function(e){return e.status>=3},le=function(e){return e.status>=2},de=((ue={})[c.INIT]=function(e){try{return Promise.resolve(ae(e.self())).then(function(n){ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ue[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,c.UPDATED,e.all())},ue[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ue[c.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ue.POLL=function(e){try{return Promise.resolve(ae(e.self())).then(function(n){var t,r;ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),r=n,JSON.stringify(t)!==JSON.stringify(r)&&e.broadcast(c.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ue),he=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},me=function(e){return c.spawn(de,he(e))};function pe(e){function n(n){return c.subscriber(he(e),me,n)}function t(e){return function(t){void 0===t&&(t={});var r=t.suppress||!1;return new Promise(function(t,o){var i=n(function(n){n.statusCode&&!r?(o(n.errorMessage),i()):e(n)&&(t(n),i())})})}}return{snapshot:function(){return c.snapshoter(e,me)},subscribe:n,onceFinalized:t(le),onceExecuted:t(fe),onceSealed:t(ce)}}pe.isUnknown=function(e){return e.status>=0},pe.isPending=function(e){return e.status>=1},pe.isFinalized=le,pe.isExecuted=fe,pe.isSealed=ce,pe.isExpired=function(e){return 5===e.status};var ve=function(e){try{var t=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return t(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},ye=((se={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),t=function(){if(null==n){var t=e.put;return Promise.resolve(o.latestBlock()).then(function(n){t.call(e,"hwm",n);var r=e.put;return Promise.resolve(ve(e)).then(function(n){r.call(e,"tick",n)})})}return Promise.resolve(o.latestBlock()).then(function(t){return e.put("hwm",t),Promise.resolve(f.send([getEvents(e.self(),n.height,t.height-1)]).then(l.decode)).then(function(n){for(var t,r=R(n);!(t=r()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(ve(e)).then(function(n){o.call(e,"tick",n)})})})}();return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},se[c.SUBSCRIBE]=function(e,n){try{var t=function(){e.subscribe(n.from)},r=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ve(e)).then(function(t){n.call(e,"tick",t)})}}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},se[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},se),ge=function(e){return c.spawn(ye,e)};function be(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.style.position="fixed",n.style.top="0px",n.style.right="0px",n.style.left="0px",n.style.bottom="0px",n.style.height="100vh",n.style.width="100vw",n.style.display="block",n.style.background="rgba(0,0,0,0.25)",n.style.zIndex=2147483647,n.frameBorder="0",n.style.boxSizing="border-box",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}var Pe={"@type":"Service","@vsn":"1.0.0"},ke={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},Se={authn:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},Pe,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:i.withPrefix(e.addr),name:e.name,icon:e.icon}})}},authz:function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},"pre-authz":function(e){switch(e["@vsn"]){case"1.0.0":return e;default:return x({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:x({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}}};function Ee(e){return s.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Ie(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}function je(e,n){void 0===n&&(n=!0);var t=new URL(e.endpoint);if(n)for(var r=0,o=Object.entries(e.params||{});r<o.length;r++){var i=o[r];t.searchParams.append(i[0],i[1])}return t}function Oe(e){return be(je(e).href)}var Be,Te={"HTTP/GET":"GET","HTTP/POST":"POST"},xe=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ae=function(e,n){return"Missing "+xe(e,n)+" in Composite Signature."},Re=function(e,n){return xe(e,n)+" in Composit Signature did not match the requested "+e+"."},Le={"HTTP/POST":function(e,n){try{var t=function(){},r=null;return Promise.resolve(function(e,n){try{var t=e()}catch(e){return n()}return t&&t.then?t.then(n,n):n()}(function(){return function(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(function(){return Promise.resolve(fetch(je(e,!0),{method:"POST",headers:{"Content-Type":"application/json"},body:n?JSON.stringify(n):void 0}).then(function(e){return e.json()})).then(function(e){if(console.log("RESP",e),e.local&&e.local.length>0){var n=Oe(e.local[0]);t=n[1]}return Promise.resolve(function e(n){return new Promise(function(t,r){try{return Promise.resolve(fetch(je(n),{method:Te[n.method],headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(n){"APPROVED"===n.status?t(n.compositeSignature):"DECLINED"===n.status?r({status:n.status,reason:n.reason}):setTimeout(function(){t(e(n.authorizationUpdates))},500)})}catch(e){return Promise.reject(e)}})}(e.authorizationUpdates)).then(function(e){r=e})})},function(r){throw t(),Ne(e,n,r),r})},function(){return t(),r}))}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){try{return Promise.resolve(new Promise(function(t,r){try{var o=m.uid(),i=Oe(e),u=i[0],s=i[1],a=function(){u.contentWindow.postMessage(JSON.parse(JSON.stringify({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})),"*")};window.addEventListener("message",function e(n){var i=n.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(),r({status:u.status,reason:u.reason})):(window.removeEventListener("message",e),s(),r({status:"DECLINED",reason:"Status was neither APPROVED nor DECLINED"})),Promise.resolve()}catch(e){return Promise.reject(e)}}),new Promise(function(e){window.addEventListener("message",t);var n=setTimeout(function(){window.removeEventListener("message",t),a(),e()},5e3);function t(r){"FCL::AUTHZ_READY"===r.data.type&&(clearTimeout(n),window.removeEventListener("message",t),a(),e())}})}catch(t){Ne(e,n,t),r({status:"DECLINED",reason:"Trouble talking to Wallet Provider"})}}))}catch(e){return Promise.reject(e)}}};function Ne(e,n,t){console.error("["+e.method+"] Trouble talking to Wallet Provider","\n\n",{authz:e,signable:n},t)}function Ce(e,n,t){if(!e.s){if(t instanceof qe){if(!t.s)return void(t.o=Ce.bind(null,e,n));1&n&&(n=t.s),t=t.v}if(t&&t.then)return void t.then(Ce.bind(null,e,n),Ce.bind(null,e,2));e.s=n,e.v=t;var r=e.o;r&&r(e)}}var Ue=function(e){try{return Ye(),Promise.resolve(De()).then(function(n){Ie(n.services,"authn");var r=Ie(n.services,"authz");return Ie(n.services,"pre-authz"),x({},e,{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(function(e,n){try{return Promise.resolve(Le[e.method](e,n)).then(function(n){return null==n.sig&&(n.sig=n.signature),null==n.signature&&(n.signature=n.sig),n.addr=i.sansPrefix(n.addr),function(e,n){try{var r={compSig:e,authz:n};t.invariant(e.addr,Ae("addr","Address"),r),t.invariant(null!=e.keyId,Ae("keyId"),r),t.invariant(e.signature,Ae("signature"),r),t.invariant(e.keyId===n.identity.keyId,Re("keyId"),r),t.invariant(i.sansPrefix(e.addr)===i.sansPrefix(n.identity.address),Re("addr","Address"),r)}catch(e){throw new Error("Composite Signature from Wallet Provider failed Validation/Sanitation.\nReason: "+e.message)}}(n,e),n})}catch(e){return Promise.reject(e)}}(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},qe=function(){function e(){}return e.prototype.then=function(n,t){var r=new e,o=this.s;if(o){var i=1&o?n:t;if(i){try{Ce(r,1,i(this.v))}catch(e){Ce(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Ce(r,1,n?n(o):o):t?Ce(r,1,t(o)):Ce(r,2,o)}catch(e){Ce(r,2,e)}},r},e}();function ze(e){return e instanceof qe&&1&e.s}var De=function(){try{return Promise.resolve(new Promise(function(e){try{return Ye(),Promise.resolve(en()).then(function(t){return t.loggedIn&&Ze(t)?e(t):Promise.resolve(n.config().get("challenge.handshake")).then(function(n){var t,r,o,u=(r=(t={handshake:n,l6n:window.location.origin}).l6n,(o=new URL(t.handshake)).searchParams.append("l6n",r),be(o.href))[1];window.addEventListener("message",function n(t){var r=t.data;try{return r.type===Me||r.type===He?(u(),window.removeEventListener("message",n),Promise.resolve()):r.type!==Je?Promise.resolve():(u(),window.removeEventListener("message",n),Promise.resolve(function(e){try{var n=(e=function(e){return e.addr=e.addr?i.withPrefix(e.addr):null,e.paddr=e.paddr?i.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,n){try{if(null==e||null==n)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",n),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 n=[];if(Array.isArray(e.authorizations))for(var t,r=R(e.authorizations);!(t=r()).done;)n.push(x({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&n.push(x({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(t){var r,o,u=(r=n,o=t,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(n){return function(e,n){try{var t=Se[e.type](e,n);return console.log(e.type,{normalized:t,service:e}),t}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)});console.log("BUILD USER",u);var s=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return x({},we,{addr:i.withPrefix(e.addr),cid:Ee(s),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(r)).then(function(n){return c.send(Fe,Ge,n),Promise.resolve(en()).then(function(n){e(n)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Fe="CURRENT_USER",_e="CURRENT_USER/UPDATED",Ge="SET_CURRENT_USER",He="FCL::CANCEL",Je="FCL::CHALLENGE::RESPONSE",Me="FCL::CHALLENGE::CANCEL",Ke='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Ve=function(e){try{return sessionStorage.setItem(Fe,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},We=function(){return n.config().get("persistSession",!0)},Xe=((Be={})[c.INIT]=function(e){try{return e.merge(JSON.parse(Ke)),Promise.resolve(We()).then(function(n){var t=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(Ke),n=JSON.parse(sessionStorage.getItem(Fe));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Fe),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){Ze(n)&&e.merge(n)})}();if(t&&t.then)return t.then(function(){})})}catch(e){return Promise.reject(e)}},Be[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,_e,x({},e.all()))},Be[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},Be.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Be[Ge]=function(e,n,t){try{return e.merge(t),Promise.resolve(We()).then(function(n){n&&Ve(e.all()),e.broadcast(_e,x({},e.all()))})}catch(e){return Promise.reject(e)}},Be.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(Ke)),Promise.resolve(We()).then(function(n){n&&Ve(e.all()),e.broadcast(_e,x({},e.all()))})}catch(e){return Promise.reject(e)}},Be),Ye=function(){return c.spawn(Xe,Fe)};function Ze(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function $e(){Ye(),c.send(Fe,"DEL_CURRENT_USER")}function Qe(e){Ye();var n=c.spawn(function(n){try{var t;return n.send(Fe,c.SUBSCRIBE),Promise.resolve(function(e,n,t){for(var r;;){var o=e();if(ze(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=t();if(i&&i.then){if(!ze(i)){r=1;break}i=i.s}}var u=new qe,s=Ce.bind(null,u,2);return(0===r?o.then(c):1===r?i.then(a):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):Ce(u,1,i)})).then(void 0,s),u;function a(n){i=n;do{if(!(o=e())||ze(o)&&!o.v)return void Ce(u,1,i);if(o.then)return void o.then(c).then(void 0,s);ze(i=t())&&(i=i.v)}while(!i||!i.then);i.then(a).then(void 0,s)}function c(e){e?(i=t())&&i.then?i.then(a).then(void 0,s):a(i):Ce(u,1,i)}}(function(){return!t&&1},0,function(){return Promise.resolve(n.receive()).then(function(r){if("@EXIT"===r.tag)return n.send(Fe,c.UNSUBSCRIBE),void(t=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return c.send(n,"@EXIT")}}function en(){return Ye(),c.send(Fe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var nn=function(){return{authenticate:De,unauthenticate:$e,authorization:Ue,subscribe:Qe,snapshot:en}},tn=nn().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return o.latestBlock}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return u.account}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return f.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return l.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return h.getEvents}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return p.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return p.template}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return v.transaction}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return y.script}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return g.ping}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return b.getAccount}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return P.getLatestBlock}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return k.getBlockById}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return w.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 E.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return E.args}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return I.proposer}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return j.payer}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return O.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return B.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return T.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return T.params}}),e.VERSION="0.0.67-alpha.3",e.authenticate=function(){return nn().authenticate()},e.authz=tn,e.currentUser=nn,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,ge,n)}}},e.logIn=function(){return nn().authenticate()},e.reauthenticate=function(){nn().unauthenticate(),nn().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var t=function(){return Promise.resolve(a.resolve(n)(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(r.pipe(r.interaction(),e)).then(function(n){e=n})}();return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},e.signUp=function(){return nn().authenticate()},e.tx=pe,e.unauthenticate=function(){return nn().unauthenticate()}});
//# sourceMappingURL=fcl.umd.js.map
{
"name": "@onflow/fcl",
"version": "0.0.67-alpha.2",
"version": "0.0.67-alpha.3",
"description": "Flow Client Library",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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