@onflow/fcl
Advanced tools
Comparing version 0.0.67-alpha.8 to 0.0.67-alpha.9
@@ -5,3 +5,3 @@ ### Unreleased | ||
### 0.0.67-alpha.[7,8] - 2020-11-19 | ||
### 0.0.67-alpha.[7-9] - 2020-11-19 | ||
@@ -8,0 +8,0 @@ - 2020-11-19 -- Experimental IFRAME/RPC strategy |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/config"),n=require("@onflow/util-invariant"),r=require("@onflow/interaction"),t=require("@onflow/sdk-latest-block"),o=require("@onflow/util-address"),i=require("@onflow/sdk-account"),u=require("@onflow/rlp"),a=require("@onflow/sdk-resolve"),s=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"),m=require("@onflow/util-template"),h=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"),E=require("@onflow/sdk-build-get-block-by-height"),w=require("@onflow/sdk-build-authorizations"),k=require("@onflow/sdk-build-arguments"),x=require("@onflow/sdk-build-proposer"),S=require("@onflow/sdk-build-payer"),I=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),O=require("@onflow/sdk-build-params");function C(){return(C=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 A(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 R(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 A(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)?A(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.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return T(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},B=function(e){return u.encode(e).toString("hex")},F=function(e){return z(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(N),(n=e.refBlock,T(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},U=function(e){var n=q(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})},q=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},z=function(e){J.forEach(function(n){return W(e,n)}),K.forEach(function(n){return W(e.proposalKey,n,"proposalKey")})},M=function(e){return"number"==typeof e},D=function(e){return"string"==typeof e},_=function(e){return null!==e&&"object"==typeof e},H=function(e){return _(e)&&e instanceof Array},J=[{name:"script",check:D},{name:"arguments",check:H},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:M},{name:"proposalKey",check:_},{name:"payer",check:D},{name:"authorizers",check:H}],K=[{name:"address",check:D},{name:"keyId",check:M},{name:"sequenceNum",check:M}],G=[{name:"payloadSigs",check:H}],V=[{name:"address",check:D},{name:"keyId",check:M},{name:"sig",check:D}],W=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 Y(o,r,t);if(!i(e[o]))throw Z(o,r,t)},X=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},Y=function(e,n,r){return new Error("Missing field "+X(e,n,r))},Z=function(e,n,r){return new Error("Invalid field "+X(e,n,r))},$="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Q(e,n,r){if(!e.s){if(r instanceof ee){if(!r.s)return void(r.o=Q.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Q.bind(null,e,n),Q.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ee=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{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,n?n(o):o):r?Q(t,1,r(o)):Q(t,2,o)}catch(e){Q(t,2,e)}},t},e}();function ne(e){return e instanceof ee&&1&e.s}var re=function(e){return"string"==typeof e},te=function(e){return"function"==typeof e};function oe(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:o.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(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: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(n){return o.sansPrefix(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}e.config().put("sdk.resolve",function(o){try{return Promise.resolve(o).then(function(u){return o=u,Promise.resolve(function(t){try{var o=function(){if(r.isTransaction(t)||r.isScript(t)){var o=function(){return n.invariant(re(i),"Cadence needs to be a string at this point."),Promise.resolve(e.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},i)})).then(function(e){t.message.cadence=e})},i=r.get(t,"ix.cadence");n.invariant(te(i)||re(i),"Cadence needs to be a function or a string.");var u=function(){if(te(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return t}):t)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{if(r.isTransaction(e)||r.isScript(e))for(var t=0,o=Object.entries(e.arguments);t<o.length;t++){var i=o[t];e.arguments[i[0]].asArgument=(n.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),te(u.xform)?u.xform(u.value):te(u.xform.asArgument)?u.xform.asArgument(u.value):void n.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(o)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r.isTransaction(e)){var n=function(){e.accounts=t},t={},o=function(e,n,r){if("function"==typeof e[$]){var t,o,i,u=e[$]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!ne(r))return void r.then(e,i||(i=Q.bind(null,o=new ee,2)));r=r.v}o?Q(o,1,r):o=r}catch(e){Q(o||(o=new ee),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.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(!ne(u))return void u.then(r,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}(s,function(e){return n(s[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,a=function(){if(te(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return a&&a.then?a.then(i):i()});return o&&o.then?o.then(n):n()}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(t.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var t=function(){if(r.isTransaction(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});n.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(n){e.accounts[t.tempId].sequenceNum=n})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r.isTransaction(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);var o=(i=ie(e),B(F(i)));return Promise.resolve(Promise.all(n.map(oe(e,o)))).then(function(){var r=function(e){return B(function(e){return function(e){G.forEach(function(n){return W(e,n)}),e.payloadSigs.forEach(function(e,n){V.forEach(function(r){return W(e,r,"payloadSigs",n)})})}(e),[F(e),U(e)]}(e))}(C({},ie(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(oe(e,r)))).then(function(){})})}var i}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return o})})})})})})})}catch(e){return Promise.reject(e)}});var ue,ae,se=function(e){try{return Promise.resolve(c.send([l.getTransactionStatus(e)]).then(f.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={})[s.INIT]=function(e){try{return Promise.resolve(se(e.self())).then(function(n){ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ue[s.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,s.UPDATED,e.all())},ue[s.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ue[s.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(se(e.self())).then(function(n){var r,t;ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(s.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ue),pe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},me=function(e){return s.spawn(de,pe(e))};function he(e){function n(n){return s.subscriber(pe(e),me,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 s.snapshoter(e,me)},subscribe:n,onceFinalized:r(le),onceExecuted:r(fe),onceSealed:r(ce)}}he.isUnknown=function(e){return e.status>=0},he.isPending=function(e){return e.status>=1},he.isFinalized=le,he.isExecuted=fe,he.isSealed=ce,he.isExpired=function(e){return 5===e.status};var ve=function(n){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},ye=((ae={}).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(t.latestBlock()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(ve(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(t.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(c.send([getEvents(e.self(),n.height,r.height-1)]).then(f.decode)).then(function(n){for(var r,t=R(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(ve(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)}},ae[s.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ve(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)}},ae[s.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ae),ge=function(e){return s.spawn(ye,e)},Pe={"@type":"Service","@vsn":"1.0.0"},be={"@type":"Identity","@vsn":"1.0.0"},Ee={"@type":"USER","@vsn":"1.0.0"},we={"@type":"PollingResponse","@vsn":"1.0.0"};function ke(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({old:e},Pe,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function xe(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Se={"back-channel-rpc":xe,"pre-authz":function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},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}})}},frame:ke};function Ie(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function je(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}var Oe=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ce=function(e,n){return"Missing "+Oe(e,n)+" in Composite Signature."},Ae=function(e,n){return Oe(e,n)+" in Composit Signature did not match the requested "+e+"."};function Re(e){var n=new URL(e.endpoint);if(null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Te(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Re(e),{method:r,headers:C({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Le(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},we,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:xe(e.authorizationUpdates),local:ke((e.local||[])[0])})}}var Ne="FCL_IFRAME",Be=function(){},Fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ue(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return e;var t=r.onClose||Be,o=r.onMessage||Be,i=r.onReady||Be;window.addEventListener("message",c);var u=function(e){n.invariant(!document.getElementById(Ne),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=Ne,r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(Ne)&&document.getElementById(Ne).remove()}]}(Re(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(Fe.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e)),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var qe,ze={"HTTP/GET":"GET","HTTP/POST":"POST"},Me=function(e){return n.invariant(ze[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ze[e.method]},De={"HTTP/POST":function(e,r){try{return r.data=e.data,Promise.resolve(Te(e,{data:r}).then(Le)).then(function(e){var r=!0,t=Ue(e.local,{onClose:function(){r=!1}}).close;return function e(r,t){void 0===t&&(t=function(){return!0});try{if(n.invariant(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(r,{method:Me(r)}).then(Le)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(e.updates,function(){return r}).then(function(e){return t(),e}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=p.uid();n.data=e.data,Ue(e,{onReady:function(r,t){var i=t.send;console.log("FCL[IFRAME/RPC] onReady"),i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})},onMessage:function(e,n){var i=n.close;if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"===e.data.jsonrpc&&e.data.id===o){console.log("FCL[IFRAME/RPC] A",data.result);var u=Le(data.result);switch(console.log("FCL[IFRAME/RPC] B",u),u.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",u.data),r(u.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",u),t("Declined: "+(u.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",u),t("Declined: No reason supplied")}i()}}})})}};function _e(e,n,r){if(!e.s){if(r instanceof Je){if(!r.s)return void(r.o=_e.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(_e.bind(null,e,n),_e.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var He=function(e){try{return tn(),Promise.resolve(Ge()).then(function(r){je(r.services,"authn");var t=je(r.services,"authz");return je(r.services,"pre-authz"),C({},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 console.log("Signable",e),Promise.resolve(function(e,r){try{return Promise.resolve(De[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=o.sansPrefix(r.addr),function(e,r){try{var t={compSig:e,authz:r};n.invariant(e.addr,Ce("addr","Address"),t),n.invariant(null!=e.keyId,Ce("keyId"),t),n.invariant(e.signature,Ce("signature"),t),n.invariant(e.keyId===r.identity.keyId,Ae("keyId"),t),n.invariant(o.sansPrefix(e.addr)===o.sansPrefix(r.identity.address),Ae("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)}},Je=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{_e(t,1,i(this.v))}catch(e){_e(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?_e(t,1,n?n(o):o):r?_e(t,1,r(o)):_e(t,2,o)}catch(e){_e(t,2,e)}},t},e}();function Ke(e){return e instanceof Je&&1&e.s}var Ge=function(){try{return Promise.resolve(new Promise(function(n){try{return tn(),Promise.resolve(sn()).then(function(r){return r.loggedIn&&on(r)?n(r):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var r,t,i,u=(r={handshake:e,l6n:window.location.origin},t=r.l6n,(i=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(i.href))[1];window.addEventListener("message",function e(r){var t=r.data;try{return t.type===$e||t.type===Ye?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Ze?Promise.resolve():(u(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var n=(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,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=R(e.authorizations);!(r=t()).done;)n.push(C({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(C({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,i,u=(t=n,i=r,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(n){return function(e,n){try{return Se[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),a=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return C({},Ee,{addr:o.withPrefix(e.addr),cid:Ie(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return s.send(Ve,Xe,e),Promise.resolve(sn()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ve="CURRENT_USER",We="CURRENT_USER/UPDATED",Xe="SET_CURRENT_USER",Ye="FCL::CANCEL",Ze="FCL::CHALLENGE::RESPONSE",$e="FCL::CHALLENGE::CANCEL",Qe='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',en=function(e){try{return sessionStorage.setItem(Ve,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},nn=function(){return e.config().get("persistSession",!0)},rn=((qe={})[s.INIT]=function(e){try{return e.merge(JSON.parse(Qe)),Promise.resolve(nn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(Qe),n=JSON.parse(sessionStorage.getItem(Ve));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Ve),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){on(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},qe[s.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,We,C({},e.all()))},qe[s.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},qe.SNAPSHOT=function(e,n){try{return n.reply(C({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},qe[Xe]=function(e,n,r){try{return e.merge(r),Promise.resolve(nn()).then(function(n){n&&en(e.all()),e.broadcast(We,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(Qe)),Promise.resolve(nn()).then(function(n){n&&en(e.all()),e.broadcast(We,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe),tn=function(){return s.spawn(rn,Ve)};function on(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function un(){tn(),s.send(Ve,"DEL_CURRENT_USER")}function an(e){tn();var n=s.spawn(function(n){try{var r;return n.send(Ve,s.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ke(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ke(i)){t=1;break}i=i.s}}var u=new Je,a=_e.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):_e(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ke(o)&&!o.v)return void _e(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ke(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):_e(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Ve,s.UNSUBSCRIBE),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return s.send(n,"@EXIT")}}function sn(){return tn(),s.send(Ve,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var cn=function(){return{authenticate:Ge,unauthenticate:un,authorization:He,subscribe:an,snapshot:sn}},fn=cn().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(exports,"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 m.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return m.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return h.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 E.getBlockByHeight}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return w.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return w.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 x.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return S.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.8",exports.authenticate=function(){return cn().authenticate()},exports.authz=fn,exports.currentUser=cn,exports.events=function(e){return{subscribe:function(n){return s.subscriber(e,ge,n)}}},exports.logIn=function(){return cn().authenticate()},exports.reauthenticate=function(){cn().unauthenticate(),cn().authenticate()},exports.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)}},exports.signUp=function(){return cn().authenticate()},exports.tx=he,exports.unauthenticate=function(){return cn().unauthenticate()}; | ||
var e=require("@onflow/config"),n=require("@onflow/util-invariant"),r=require("@onflow/interaction"),t=require("@onflow/sdk-latest-block"),o=require("@onflow/util-address"),i=require("@onflow/sdk-account"),u=require("@onflow/rlp"),a=require("@onflow/sdk-resolve"),s=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"),m=require("@onflow/util-template"),h=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"),E=require("@onflow/sdk-build-get-block-by-height"),w=require("@onflow/sdk-build-authorizations"),k=require("@onflow/sdk-build-arguments"),x=require("@onflow/sdk-build-proposer"),S=require("@onflow/sdk-build-payer"),I=require("@onflow/sdk-build-limit"),j=require("@onflow/sdk-build-ref"),O=require("@onflow/sdk-build-params");function C(){return(C=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 A(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 R(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 A(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)?A(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.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return T(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},B=function(e){return u.encode(e).toString("hex")},F=function(e){return z(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(N),(n=e.refBlock,T(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},U=function(e){var n=q(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})},q=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},z=function(e){J.forEach(function(n){return W(e,n)}),K.forEach(function(n){return W(e.proposalKey,n,"proposalKey")})},M=function(e){return"number"==typeof e},D=function(e){return"string"==typeof e},_=function(e){return null!==e&&"object"==typeof e},H=function(e){return _(e)&&e instanceof Array},J=[{name:"script",check:D},{name:"arguments",check:H},{name:"refBlock",check:D,defaultVal:"0"},{name:"gasLimit",check:M},{name:"proposalKey",check:_},{name:"payer",check:D},{name:"authorizers",check:H}],K=[{name:"address",check:D},{name:"keyId",check:M},{name:"sequenceNum",check:M}],G=[{name:"payloadSigs",check:H}],V=[{name:"address",check:D},{name:"keyId",check:M},{name:"sig",check:D}],W=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 Y(o,r,t);if(!i(e[o]))throw Z(o,r,t)},X=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},Y=function(e,n,r){return new Error("Missing field "+X(e,n,r))},Z=function(e,n,r){return new Error("Invalid field "+X(e,n,r))},$="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Q(e,n,r){if(!e.s){if(r instanceof ee){if(!r.s)return void(r.o=Q.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(Q.bind(null,e,n),Q.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ee=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{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,n?n(o):o):r?Q(t,1,r(o)):Q(t,2,o)}catch(e){Q(t,2,e)}},t},e}();function ne(e){return e instanceof ee&&1&e.s}var re=function(e){return"string"==typeof e},te=function(e){return"function"==typeof e};function oe(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:o.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(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: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(n){return o.sansPrefix(e.accounts[n].addr)}).reduce(function(e,n){return e.find(function(e){return e===n})?e:[].concat(e,[n])},[])}}e.config().put("sdk.resolve",function(o){try{return Promise.resolve(o).then(function(u){return o=u,Promise.resolve(function(t){try{var o=function(){if(r.isTransaction(t)||r.isScript(t)){var o=function(){return n.invariant(re(i),"Cadence needs to be a string at this point."),Promise.resolve(e.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},i)})).then(function(e){t.message.cadence=e})},i=r.get(t,"ix.cadence");n.invariant(te(i)||re(i),"Cadence needs to be a function or a string.");var u=function(){if(te(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return t}):t)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{if(r.isTransaction(e)||r.isScript(e))for(var t=0,o=Object.entries(e.arguments);t<o.length;t++){var i=o[t];e.arguments[i[0]].asArgument=(n.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),te(u.xform)?u.xform(u.value):te(u.xform.asArgument)?u.xform.asArgument(u.value):void n.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(o)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r.isTransaction(e)){var n=function(){e.accounts=t},t={},o=function(e,n,r){if("function"==typeof e[$]){var t,o,i,u=e[$]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!ne(r))return void r.then(e,i||(i=Q.bind(null,o=new ee,2)));r=r.v}o?Q(o,1,r):o=r}catch(e){Q(o||(o=new ee),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.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(!ne(u))return void u.then(r,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}(s,function(e){return n(s[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,a=function(){if(te(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return a&&a.then?a.then(i):i()});return o&&o.then?o.then(n):n()}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(t.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var t=function(){if(r.isTransaction(e)){var t=Object.values(e.accounts).find(function(e){return e.role.proposer});n.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(n){e.accounts[t.tempId].sequenceNum=n})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r.isTransaction(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);var o=(i=ie(e),B(F(i)));return Promise.resolve(Promise.all(n.map(oe(e,o)))).then(function(){var r=function(e){return B(function(e){return function(e){G.forEach(function(n){return W(e,n)}),e.payloadSigs.forEach(function(e,n){V.forEach(function(r){return W(e,r,"payloadSigs",n)})})}(e),[F(e),U(e)]}(e))}(C({},ie(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(oe(e,r)))).then(function(){})})}var i}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(o)).then(function(){return o})})})})})})})}catch(e){return Promise.reject(e)}});var ue,ae,se=function(e){try{return Promise.resolve(c.send([l.getTransactionStatus(e)]).then(f.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={})[s.INIT]=function(e){try{return Promise.resolve(se(e.self())).then(function(n){ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ue[s.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,s.UPDATED,e.all())},ue[s.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ue[s.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(se(e.self())).then(function(n){var r,t;ce(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(s.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ue),pe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},me=function(e){return s.spawn(de,pe(e))};function he(e){function n(n){return s.subscriber(pe(e),me,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 s.snapshoter(e,me)},subscribe:n,onceFinalized:r(le),onceExecuted:r(fe),onceSealed:r(ce)}}he.isUnknown=function(e){return e.status>=0},he.isPending=function(e){return e.status>=1},he.isFinalized=le,he.isExecuted=fe,he.isSealed=ce,he.isExpired=function(e){return 5===e.status};var ve=function(n){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return n.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},ye=((ae={}).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(t.latestBlock()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(ve(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(t.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(c.send([getEvents(e.self(),n.height,r.height-1)]).then(f.decode)).then(function(n){for(var r,t=R(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(ve(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)}},ae[s.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ve(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)}},ae[s.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ae),ge=function(e){return s.spawn(ye,e)},Pe={"@type":"Service","@vsn":"1.0.0"},be={"@type":"Identity","@vsn":"1.0.0"},Ee={"@type":"USER","@vsn":"1.0.0"},we={"@type":"PollingResponse","@vsn":"1.0.0"};function ke(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({old:e},Pe,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function xe(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Se={"back-channel-rpc":xe,"pre-authz":function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},be,{address:o.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},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}})}},frame:ke};function Ie(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function je(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}var Oe=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ce=function(e,n){return"Missing "+Oe(e,n)+" in Composite Signature."},Ae=function(e,n){return Oe(e,n)+" in Composit Signature did not match the requested "+e+"."};function Re(e){var n=new URL(e.endpoint);if(null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Te(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Re(e),{method:r,headers:C({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Le(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},we,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:xe(e.authorizationUpdates),local:ke((e.local||[])[0])})}}var Ne="FCL_IFRAME",Be=function(){},Fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ue(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return e;var t=r.onClose||Be,o=r.onMessage||Be,i=r.onReady||Be;window.addEventListener("message",c);var u=function(e){n.invariant(!document.getElementById(Ne),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=Ne,r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(Ne)&&document.getElementById(Ne).remove()}]}(Re(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if(Fe.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var qe,ze={"HTTP/GET":"GET","HTTP/POST":"POST"},Me=function(e){return n.invariant(ze[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ze[e.method]},De={"HTTP/POST":function(e,r){try{return r.data=e.data,Promise.resolve(Te(e,{data:r}).then(Le)).then(function(e){var r=!0,t=Ue(e.local,{onClose:function(){r=!1}}).close;return function e(r,t){void 0===t&&(t=function(){return!0});try{if(n.invariant(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(r,{method:Me(r)}).then(Le)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(e.updates,function(){return r}).then(function(e){return t(),e}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=p.uid();n.data=e.data,Ue(e,{onReady:function(r,t){var i=t.send;console.log("FCL[IFRAME/RPC] onReady"),i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})},onMessage:function(e,n){var i=n.close;if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"===e.data.jsonrpc&&e.data.id===o){console.log("FCL[IFRAME/RPC] A",data.result);var u=Le(data.result);switch(console.log("FCL[IFRAME/RPC] B",u),u.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",u.data),r(u.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",u),t("Declined: "+(u.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",u),t("Declined: No reason supplied")}i()}}})})}};function _e(e,n,r){if(!e.s){if(r instanceof Je){if(!r.s)return void(r.o=_e.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(_e.bind(null,e,n),_e.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var He=function(e){try{return tn(),Promise.resolve(Ge()).then(function(r){je(r.services,"authn");var t=je(r.services,"authz");return je(r.services,"pre-authz"),C({},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 console.log("Signable",e),Promise.resolve(function(e,r){try{return Promise.resolve(De[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=o.sansPrefix(r.addr),function(e,r){try{var t={compSig:e,authz:r};n.invariant(e.addr,Ce("addr","Address"),t),n.invariant(null!=e.keyId,Ce("keyId"),t),n.invariant(e.signature,Ce("signature"),t),n.invariant(e.keyId===r.identity.keyId,Ae("keyId"),t),n.invariant(o.sansPrefix(e.addr)===o.sansPrefix(r.identity.address),Ae("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)}},Je=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{_e(t,1,i(this.v))}catch(e){_e(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?_e(t,1,n?n(o):o):r?_e(t,1,r(o)):_e(t,2,o)}catch(e){_e(t,2,e)}},t},e}();function Ke(e){return e instanceof Je&&1&e.s}var Ge=function(){try{return Promise.resolve(new Promise(function(n){try{return tn(),Promise.resolve(sn()).then(function(r){return r.loggedIn&&on(r)?n(r):Promise.resolve(e.config().get("challenge.handshake")).then(function(e){var r,t,i,u=(r={handshake:e,l6n:window.location.origin},t=r.l6n,(i=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(i.href))[1];window.addEventListener("message",function e(r){var t=r.data;try{return t.type===$e||t.type===Ye?(u(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Ze?Promise.resolve():(u(),window.removeEventListener("message",e),Promise.resolve(function(e){try{var n=(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,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=R(e.authorizations);!(r=t()).done;)n.push(C({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(C({type:"authn",id:"wallet-provider#authn"},e.provider)),n})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var t,i,u=(t=n,i=r,void 0===t&&(t=[]),void 0===i&&(i=[]),[].concat(t,i)).map(function(n){return function(e,n){try{return Se[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),a=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return C({},Ee,{addr:o.withPrefix(e.addr),cid:Ie(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return s.send(Ve,Xe,e),Promise.resolve(sn()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ve="CURRENT_USER",We="CURRENT_USER/UPDATED",Xe="SET_CURRENT_USER",Ye="FCL::CANCEL",Ze="FCL::CHALLENGE::RESPONSE",$e="FCL::CHALLENGE::CANCEL",Qe='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',en=function(e){try{return sessionStorage.setItem(Ve,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},nn=function(){return e.config().get("persistSession",!0)},rn=((qe={})[s.INIT]=function(e){try{return e.merge(JSON.parse(Qe)),Promise.resolve(nn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(Qe),n=JSON.parse(sessionStorage.getItem(Ve));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Ve),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){on(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},qe[s.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,We,C({},e.all()))},qe[s.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},qe.SNAPSHOT=function(e,n){try{return n.reply(C({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},qe[Xe]=function(e,n,r){try{return e.merge(r),Promise.resolve(nn()).then(function(n){n&&en(e.all()),e.broadcast(We,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(Qe)),Promise.resolve(nn()).then(function(n){n&&en(e.all()),e.broadcast(We,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe),tn=function(){return s.spawn(rn,Ve)};function on(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function un(){tn(),s.send(Ve,"DEL_CURRENT_USER")}function an(e){tn();var n=s.spawn(function(n){try{var r;return n.send(Ve,s.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ke(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ke(i)){t=1;break}i=i.s}}var u=new Je,a=_e.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):_e(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ke(o)&&!o.v)return void _e(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ke(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):_e(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Ve,s.UNSUBSCRIBE),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return s.send(n,"@EXIT")}}function sn(){return tn(),s.send(Ve,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var cn=function(){return{authenticate:Ge,unauthenticate:un,authorization:He,subscribe:an,snapshot:sn}},fn=cn().authorization;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(exports,"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 m.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return m.template}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return h.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 E.getBlockByHeight}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return w.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return w.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 x.proposer}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return S.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.9",exports.authenticate=function(){return cn().authenticate()},exports.authz=fn,exports.currentUser=cn,exports.events=function(e){return{subscribe:function(n){return s.subscriber(e,ge,n)}}},exports.logIn=function(){return cn().authenticate()},exports.reauthenticate=function(){cn().unauthenticate(),cn().authenticate()},exports.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)}},exports.signUp=function(){return cn().authenticate()},exports.tx=he,exports.unauthenticate=function(){return cn().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 c,withPrefix as u}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 b}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 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 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 C(){return(C=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 R=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},A=function(e){return R(e,8)},L=function(e){return Buffer.from(JSON.stringify(e),"utf8")},P=function(e){return l(e).toString("hex")},N=function(e){return z(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(L),(t=e.refBlock,R(t,32)),e.gasLimit,A(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,A(e.payer),e.authorizers.map(A)];var t,n},F=function(e){var t=T(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})},T=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){D.forEach(function(t){return J(e,t)}),_.forEach(function(t){return J(e.proposalKey,t,"proposalKey")})},O=function(e){return"number"==typeof e},M=function(e){return"string"==typeof e},U=function(e){return null!==e&&"object"==typeof e},B=function(e){return U(e)&&e instanceof Array},D=[{name:"script",check:M},{name:"arguments",check:B},{name:"refBlock",check:M,defaultVal:"0"},{name:"gasLimit",check:O},{name:"proposalKey",check:U},{name:"payer",check:M},{name:"authorizers",check:B}],_=[{name:"address",check:M},{name:"keyId",check:O},{name:"sequenceNum",check:O}],j=[{name:"payloadSigs",check:B}],H=[{name:"address",check:M},{name:"keyId",check:O},{name:"sig",check:M}],J=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 K(o,n,r);if(!a(e[o]))throw G(o,n,r)},q=function(e,t,n){return t?null==n?t+"."+e:t+"."+n+"."+e:e},K=function(e,t,n){return new Error("Missing field "+q(e,t,n))},G=function(e,t,n){return new Error("Invalid field "+q(e,t,n))};const $=e=>"string"==typeof e,V=e=>"function"==typeof e;function W(e,t){return async function(n){const r=e.accounts[n];if(null!=r.signature)return;const{signature:o}=await r.signingFunction(function(e,t,n){return{"@type":"Signable","@vsn":"1.0.0",message:t,addr:c(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(e=>n.arguments[e].asArgument),data:{},interaction:n}}(r,t,e));e.accounts[n].signature=o}}function X(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:c(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:c(e.accounts[e.payer].addr),authorizers:e.authorizations.map(t=>c(e.accounts[t].addr)).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[])}}e().put("sdk.resolve",async function(a){return a=await a,await async function(a){if(n(a)||r(a)){var s=o(a,"ix.cadence");t(V(s)||$(s),"Cadence needs to be a function or a string."),V(s)&&(s=await s({})),t($(s),"Cadence needs to be a string at this point."),a.message.cadence=await e().where(/^0x/).then(e=>Object.entries(e).reduce((e,[t,n])=>e.replace(t,n),s))}return a}(a),await async function(e){function o(e){return t(null!=typeof e.xform,"No type specified for argument: "+e.value),V(e.xform)?e.xform(e.value):V(e.xform.asArgument)?e.xform.asArgument(e.value):void t(!1,"Invalid Argument",e)}if(n(e)||r(e))for(let[t,n]of Object.entries(e.arguments))e.arguments[t].asArgument=o(n);return e}(a),await async function(e){if(n(e)){var t={};for(let[n,o]of Object.entries(e.accounts)){var r=n;V(o.resolve)&&(o=await o.resolve(o),n=o.tempId),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===r&&(e.proposer=n),e.payer===r&&(e.payer=n),e.authorizations=e.authorizations.map(e=>e===r?n:e)}e.accounts=t}return e}(a),await async function(e){return n(e)&&null==e.message.refBlock&&(e.message.refBlock=(await i()).id),e}(a),await async function(e){if(n(e)){var r=Object.values(e.accounts).find(e=>e.role.proposer);t(r,"Transactions require a proposer"),null===r.sequenceNum&&(e.accounts[r.tempId].sequenceNum=await d(r.addr).then(e=>e.keys).then(e=>e.find(e=>e.index===r.keyId)).then(e=>e.sequenceNumber))}return e}(a),await async function(e){if(n(e)){let n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);let r=new Set([e.payer]);r=Array.from(r);const o=(t=X(e),P(N(t)));await Promise.all(n.map(W(e,o)));const a=function(e){return P(function(e){return function(e){j.forEach(function(t){return J(e,t)}),e.payloadSigs.forEach(function(e,t){H.forEach(function(n){return J(e,n,"payloadSigs",t)})})}(e),[N(e),F(e)]}(e))}(C({},X(e),{payloadSigs:n.map(t=>e.accounts[t].signature)}));await Promise.all(r.map(W(e,a)))}var t;return e}(a),a});const Y=async(e=[],t={})=>(Array.isArray(e)&&(e=await a(s(),e)),JSON.stringify(await f(t)(e))),Z=async e=>b([S(e)]).then(I),Q=e=>e.status>=4,ee=e=>e.status>=3,te=e=>e.status>=2,ne={[g]:async e=>{const t=await Z(e.self());Q(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 Z(e.self());var n,r;Q(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(w,t),e.merge(t)}},re=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},oe=e=>m(ne,re(e));function ae(e){function t(t){return p(re(e),oe,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,oe)},subscribe:t,onceFinalized:n(te),onceExecuted:n(ee),onceSealed:n(Q)}}ae.isUnknown=e=>e.status>=0,ae.isPending=e=>e.status>=1,ae.isFinalized=te,ae.isExecuted=ee,ae.isSealed=Q,ae.isExpired=e=>5===e.status;const se=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),ie={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await se(e));else{let n=await i();e.put("hwm",n);const r=await b([getEvents(e.self(),t.height,n.height-1)]).then(I);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await se(e))}},[h]:async(e,t)=>{e.hasSubs()||e.put("tick",await se(e)),e.subscribe(t.from)},[k]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},ce=e=>m(ie,e);function ue(e){return{subscribe:t=>p(e,ce,t)}}const de={"@type":"Service","@vsn":"1.0.0"},le={"@type":"Identity","@vsn":"1.0.0"},fe={"@type":"USER","@vsn":"1.0.0"},pe={"@type":"PollingResponse","@vsn":"1.0.0"};function me(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({old:e},de,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function ye(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const ge={"back-channel-rpc":ye,"pre-authz":function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},le,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},le,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:u(e.addr),name:e.name,icon:e.icon}})}},frame:me};function he(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function we(e=[],t){return e.find(e=>e.type===t)}const ke=(e,t)=>null==t?`'${e}'`:`'${e}' (${t})`,Ee=(e,t)=>`Missing ${ke(e,t)} in Composite Signature.`,ve=(e,t)=>`${ke(e,t)} in Composit Signature did not match the requested ${e}.`;function be(e){const t=new URL(e.endpoint);if(null!=e.params)for(let[n,r]of Object.entries(e.params||{}))t.searchParams.append(n,r);return t}function Ie(e,t={}){const n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(be(e),{method:n,headers:C({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(e=>e.json())}function Se(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},pe,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:ye(e.authorizationUpdates),local:me((e.local||[])[0])})}}const xe="FCL_IFRAME",Ce=()=>{},Re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ae(e,n={}){if(console.log("FRAME",{service:e,opts:n}),null==e)return e;const r=n.onClose||Ce,o=n.onMessage||Ce,a=n.onReady||Ce;window.addEventListener("message",c);const[s,i]=function(e){t(!document.getElementById(xe),"Attempt at triggering multiple Frames",{src:e});const n=document.createElement("iframe");return n.src=e,n.id=xe,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,()=>{document.getElementById(xe)&&document.getElementById(xe).remove()}]}(be(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(Re.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&a(e,{send:d,close:u}),o(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&a(e,{send:d,close:u}),"FCL::CHALLENGE::CANCEL"===e.data.type&&u(),"FCL::CANCEL"===e.data.type&&u()}catch(e){console.error("Frame Callback Error",e),u()}}function u(){try{window.removeEventListener("message",c),i(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),s.contentWindow.postMessage(JSON.parse(JSON.stringify(e)),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const Le={"HTTP/GET":"GET","HTTP/POST":"POST"},Pe=e=>(t(Le[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Le[e.method]),Ne={"HTTP/POST":async function(e,n){n.data=e.data;const r=await Ie(e,{data:n}).then(Se);var o=!0;const{close:a}=Ae(r.local,{onClose:()=>{o=!1}});return async function e(n,r=(()=>!0)){if(t(n,"Missing Polling Service",{service:n}),!r())throw new Error("Externally Halted");const o=await Ie(n,{method:Pe(n)}).then(Se);switch(o.status){case"APPROVED":return o.data;case"DECLINED":throw new Error("Declined: "+(o.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(o.updates,r)}}(r.updates,()=>o).then(e=>(a(),e)).catch(e=>{throw console.error(e),a(),e})},"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const o=x();t.data=e.data,Ae(e,{onReady(n,{send:r}){console.log("FCL[IFRAME/RPC] onReady"),r({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})},onMessage(e,{close:t}){if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;console.log("FCL[IFRAME/RPC] A",data.result);const a=Se(data.result);switch(console.log("FCL[IFRAME/RPC] B",a),a.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",a.data),n(a.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",a),r("Declined: "+(a.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",a),r("Declined: No reason supplied")}t()}})})}},Fe="CURRENT_USER",Te="CURRENT_USER/UPDATED",ze='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Oe=async e=>(sessionStorage.setItem(Fe,JSON.stringify(e)),e),Me=()=>e().get("persistSession",!0),Ue={[g]:async e=>{if(e.merge(JSON.parse(ze)),await Me()){const t=await(async()=>{const e=JSON.parse(ze),t=JSON.parse(sessionStorage.getItem(Fe));return null!=t&&e["@vsn"]!==t["@vsn"]?(sessionStorage.removeItem(Fe),e):t||e})();De(t)&&e.merge(t)}},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Te,C({},e.all()))},[k]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(C({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Me()&&Oe(e.all()),e.broadcast(Te,C({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(ze)),await Me()&&Oe(e.all()),e.broadcast(Te,C({},e.all()))}},Be=()=>m(Ue,Fe);function De(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function _e(){return new Promise(async t=>{Be();const n=await qe();if(n.loggedIn&&De(n))return t(n);const[r,o]=function({handshake:e,l6n:t}){var n=new URL(e);return n.searchParams.append("l6n",t),function(e){if(document.getElementById("FCL_IFRAME"))return;const t=document.createElement("iframe");return t.src=e,t.id="FCL_IFRAME",t.allow="usb *",t.frameBorder="0",t.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(t),[t,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}(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(Fe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?u(e.addr):null,e.paddr=e.paddr?u(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(C({type:"authz",keyId:r.keyId},e));return null!=r.provider&&o.push(C({type:"authn",id:"wallet-provider#authn"},r.provider)),o}(e.hks,e.code)).map(t=>function(e,t){try{return ge[e.type](e,t)}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));const n=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return C({},fe,{addr:u(e.addr),cid:he(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await qe()))};window.addEventListener("message",a)})}function je(){Be(),v(Fe,"DEL_CURRENT_USER")}async function He(e){Be();const n=await _e(),r=(we(n.services,"authn"),we(n.services,"authz"));return we(n.services,"pre-authz"),C({},e,{tempId:"CURRENT_USER",resolve:null,addr:c(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>(console.log("Signable",e),async function(e,n){const r=await Ne[e.method](e,n);return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=c(r.addr),function(e,n){try{const r={compSig:e,authz:n};t(e.addr,Ee("addr","Address"),r),t(null!=e.keyId,Ee("keyId"),r),t(e.signature,Ee("signature"),r),t(e.keyId===n.identity.keyId,ve("keyId"),r),t(c(e.addr)===c(n.identity.address),ve("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 Je(e){Be();const t=m(async t=>{for(t.send(Fe,h);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(Fe,k);e(n.data)}});return()=>v(t,"@EXIT")}function qe(){return Be(),v(Fe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ke=()=>({authenticate:_e,unauthenticate:je,authorization:He,subscribe:Je,snapshot:qe}),Ge=()=>Ke().authenticate(),$e=()=>Ke().unauthenticate(),Ve=()=>{Ke().unauthenticate(),Ke().authenticate()},We=()=>Ke().authenticate(),Xe=()=>Ke().authenticate(),Ye=Ke().authorization,Ze="0.0.67-alpha.8";export{Ze as VERSION,Ge as authenticate,Ye as authz,Ke as currentUser,ue as events,Xe as logIn,Ve as reauthenticate,Y as serialize,We as signUp,ae 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 c,withPrefix as u}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 p}from"@onflow/sdk-resolve";import{subscriber as f,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 b}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 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 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 C(){return(C=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 R=function(e,t){return Buffer.from(e.padStart(2*t,0),"hex")},A=function(e){return R(e,8)},L=function(e){return Buffer.from(JSON.stringify(e),"utf8")},P=function(e){return l(e).toString("hex")},N=function(e){return z(e),[(n=e.script,Buffer.from(n,"utf8")),e.arguments.map(L),(t=e.refBlock,R(t,32)),e.gasLimit,A(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,A(e.payer),e.authorizers.map(A)];var t,n},F=function(e){var t=T(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})},T=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){D.forEach(function(t){return J(e,t)}),_.forEach(function(t){return J(e.proposalKey,t,"proposalKey")})},O=function(e){return"number"==typeof e},M=function(e){return"string"==typeof e},U=function(e){return null!==e&&"object"==typeof e},B=function(e){return U(e)&&e instanceof Array},D=[{name:"script",check:M},{name:"arguments",check:B},{name:"refBlock",check:M,defaultVal:"0"},{name:"gasLimit",check:O},{name:"proposalKey",check:U},{name:"payer",check:M},{name:"authorizers",check:B}],_=[{name:"address",check:M},{name:"keyId",check:O},{name:"sequenceNum",check:O}],j=[{name:"payloadSigs",check:B}],H=[{name:"address",check:M},{name:"keyId",check:O},{name:"sig",check:M}],J=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 K(o,n,r);if(!a(e[o]))throw G(o,n,r)},q=function(e,t,n){return t?null==n?t+"."+e:t+"."+n+"."+e:e},K=function(e,t,n){return new Error("Missing field "+q(e,t,n))},G=function(e,t,n){return new Error("Invalid field "+q(e,t,n))};const $=e=>"string"==typeof e,V=e=>"function"==typeof e;function W(e,t){return async function(n){const r=e.accounts[n];if(null!=r.signature)return;const{signature:o}=await r.signingFunction(function(e,t,n){return{"@type":"Signable","@vsn":"1.0.0",message:t,addr:c(e.addr),keyId:e.keyId,roles:e.role,cadence:n.message.cadence,args:n.message.arguments.map(e=>n.arguments[e].asArgument),data:{},interaction:n}}(r,t,e));e.accounts[n].signature=o}}function X(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:c(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:c(e.accounts[e.payer].addr),authorizers:e.authorizations.map(t=>c(e.accounts[t].addr)).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[])}}e().put("sdk.resolve",async function(a){return a=await a,await async function(a){if(n(a)||r(a)){var s=o(a,"ix.cadence");t(V(s)||$(s),"Cadence needs to be a function or a string."),V(s)&&(s=await s({})),t($(s),"Cadence needs to be a string at this point."),a.message.cadence=await e().where(/^0x/).then(e=>Object.entries(e).reduce((e,[t,n])=>e.replace(t,n),s))}return a}(a),await async function(e){function o(e){return t(null!=typeof e.xform,"No type specified for argument: "+e.value),V(e.xform)?e.xform(e.value):V(e.xform.asArgument)?e.xform.asArgument(e.value):void t(!1,"Invalid Argument",e)}if(n(e)||r(e))for(let[t,n]of Object.entries(e.arguments))e.arguments[t].asArgument=o(n);return e}(a),await async function(e){if(n(e)){var t={};for(let[n,o]of Object.entries(e.accounts)){var r=n;V(o.resolve)&&(o=await o.resolve(o),n=o.tempId),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===r&&(e.proposer=n),e.payer===r&&(e.payer=n),e.authorizations=e.authorizations.map(e=>e===r?n:e)}e.accounts=t}return e}(a),await async function(e){return n(e)&&null==e.message.refBlock&&(e.message.refBlock=(await i()).id),e}(a),await async function(e){if(n(e)){var r=Object.values(e.accounts).find(e=>e.role.proposer);t(r,"Transactions require a proposer"),null===r.sequenceNum&&(e.accounts[r.tempId].sequenceNum=await d(r.addr).then(e=>e.keys).then(e=>e.find(e=>e.index===r.keyId)).then(e=>e.sequenceNumber))}return e}(a),await async function(e){if(n(e)){let n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);let r=new Set([e.payer]);r=Array.from(r);const o=(t=X(e),P(N(t)));await Promise.all(n.map(W(e,o)));const a=function(e){return P(function(e){return function(e){j.forEach(function(t){return J(e,t)}),e.payloadSigs.forEach(function(e,t){H.forEach(function(n){return J(e,n,"payloadSigs",t)})})}(e),[N(e),F(e)]}(e))}(C({},X(e),{payloadSigs:n.map(t=>e.accounts[t].signature)}));await Promise.all(r.map(W(e,a)))}var t;return e}(a),a});const Y=async(e=[],t={})=>(Array.isArray(e)&&(e=await a(s(),e)),JSON.stringify(await p(t)(e))),Z=async e=>b([S(e)]).then(I),Q=e=>e.status>=4,ee=e=>e.status>=3,te=e=>e.status>=2,ne={[g]:async e=>{const t=await Z(e.self());Q(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 Z(e.self());var n,r;Q(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(w,t),e.merge(t)}},re=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},oe=e=>m(ne,re(e));function ae(e){function t(t){return f(re(e),oe,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,oe)},subscribe:t,onceFinalized:n(te),onceExecuted:n(ee),onceSealed:n(Q)}}ae.isUnknown=e=>e.status>=0,ae.isPending=e=>e.status>=1,ae.isFinalized=te,ae.isExecuted=ee,ae.isSealed=Q,ae.isExpired=e=>5===e.status;const se=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),ie={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await i()),e.put("tick",await se(e));else{let n=await i();e.put("hwm",n);const r=await b([getEvents(e.self(),t.height,n.height-1)]).then(I);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await se(e))}},[h]:async(e,t)=>{e.hasSubs()||e.put("tick",await se(e)),e.subscribe(t.from)},[k]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},ce=e=>m(ie,e);function ue(e){return{subscribe:t=>f(e,ce,t)}}const de={"@type":"Service","@vsn":"1.0.0"},le={"@type":"Identity","@vsn":"1.0.0"},pe={"@type":"USER","@vsn":"1.0.0"},fe={"@type":"PollingResponse","@vsn":"1.0.0"};function me(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({old:e},de,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function ye(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const ge={"back-channel-rpc":ye,"pre-authz":function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},le,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},le,{address:u(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},de,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:u(e.addr),name:e.name,icon:e.icon}})}},frame:me};function he(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function we(e=[],t){return e.find(e=>e.type===t)}const ke=(e,t)=>null==t?`'${e}'`:`'${e}' (${t})`,Ee=(e,t)=>`Missing ${ke(e,t)} in Composite Signature.`,ve=(e,t)=>`${ke(e,t)} in Composit Signature did not match the requested ${e}.`;function be(e){const t=new URL(e.endpoint);if(null!=e.params)for(let[n,r]of Object.entries(e.params||{}))t.searchParams.append(n,r);return t}function Ie(e,t={}){const n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(be(e),{method:n,headers:C({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(e=>e.json())}function Se(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},fe,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:ye(e.authorizationUpdates),local:me((e.local||[])[0])})}}const xe="FCL_IFRAME",Ce=()=>{},Re=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ae(e,n={}){if(console.log("FRAME",{service:e,opts:n}),null==e)return e;const r=n.onClose||Ce,o=n.onMessage||Ce,a=n.onReady||Ce;window.addEventListener("message",c);const[s,i]=function(e){t(!document.getElementById(xe),"Attempt at triggering multiple Frames",{src:e});const n=document.createElement("iframe");return n.src=e,n.id=xe,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,()=>{document.getElementById(xe)&&document.getElementById(xe).remove()}]}(be(e));return{send:d,close:u};function c(e){try{if(Re.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&a(e,{send:d,close:u}),o(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&a(e,{send:d,close:u}),"FCL::CHALLENGE::CANCEL"===e.data.type&&u(),"FCL::CANCEL"===e.data.type&&u()}catch(e){console.error("Frame Callback Error",e),u()}}function u(){try{window.removeEventListener("message",c),i(),r()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{console.log("SEND",e),s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const Le={"HTTP/GET":"GET","HTTP/POST":"POST"},Pe=e=>(t(Le[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Le[e.method]),Ne={"HTTP/POST":async function(e,n){n.data=e.data;const r=await Ie(e,{data:n}).then(Se);var o=!0;const{close:a}=Ae(r.local,{onClose:()=>{o=!1}});return async function e(n,r=(()=>!0)){if(t(n,"Missing Polling Service",{service:n}),!r())throw new Error("Externally Halted");const o=await Ie(n,{method:Pe(n)}).then(Se);switch(o.status){case"APPROVED":return o.data;case"DECLINED":throw new Error("Declined: "+(o.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(o.updates,r)}}(r.updates,()=>o).then(e=>(a(),e)).catch(e=>{throw console.error(e),a(),e})},"IFRAME/RPC":function(e,t){return new Promise((n,r)=>{const o=x();t.data=e.data,Ae(e,{onReady(n,{send:r}){console.log("FCL[IFRAME/RPC] onReady"),r({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})},onMessage(e,{close:t}){if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;console.log("FCL[IFRAME/RPC] A",data.result);const a=Se(data.result);switch(console.log("FCL[IFRAME/RPC] B",a),a.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",a.data),n(a.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",a),r("Declined: "+(a.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",a),r("Declined: No reason supplied")}t()}})})}},Fe="CURRENT_USER",Te="CURRENT_USER/UPDATED",ze='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Oe=async e=>(sessionStorage.setItem(Fe,JSON.stringify(e)),e),Me=()=>e().get("persistSession",!0),Ue={[g]:async e=>{if(e.merge(JSON.parse(ze)),await Me()){const t=await(async()=>{const e=JSON.parse(ze),t=JSON.parse(sessionStorage.getItem(Fe));return null!=t&&e["@vsn"]!==t["@vsn"]?(sessionStorage.removeItem(Fe),e):t||e})();De(t)&&e.merge(t)}},[h]:(e,t)=>{e.subscribe(t.from),e.send(t.from,Te,C({},e.all()))},[k]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(C({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await Me()&&Oe(e.all()),e.broadcast(Te,C({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(ze)),await Me()&&Oe(e.all()),e.broadcast(Te,C({},e.all()))}},Be=()=>m(Ue,Fe);function De(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function _e(){return new Promise(async t=>{Be();const n=await qe();if(n.loggedIn&&De(n))return t(n);const[r,o]=function({handshake:e,l6n:t}){var n=new URL(e);return n.searchParams.append("l6n",t),function(e){if(document.getElementById("FCL_IFRAME"))return;const t=document.createElement("iframe");return t.src=e,t.id="FCL_IFRAME",t.allow="usb *",t.frameBorder="0",t.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(t),[t,()=>{document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}(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(Fe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?u(e.addr):null,e.paddr=e.paddr?u(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(C({type:"authz",keyId:r.keyId},e));return null!=r.provider&&o.push(C({type:"authn",id:"wallet-provider#authn"},r.provider)),o}(e.hks,e.code)).map(t=>function(e,t){try{return ge[e.type](e,t)}catch(t){return console.error(`Unrecognized FCL Service Type [${e.type}]`,e,t),e}}(t,e));const n=function(e,t){return t.find(e=>"authn"===e.type)}(0,t);return C({},pe,{addr:u(e.addr),cid:he(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e)),t(await qe()))};window.addEventListener("message",a)})}function je(){Be(),v(Fe,"DEL_CURRENT_USER")}async function He(e){Be();const n=await _e(),r=(we(n.services,"authn"),we(n.services,"authz"));return we(n.services,"pre-authz"),C({},e,{tempId:"CURRENT_USER",resolve:null,addr:c(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>(console.log("Signable",e),async function(e,n){const r=await Ne[e.method](e,n);return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=c(r.addr),function(e,n){try{const r={compSig:e,authz:n};t(e.addr,Ee("addr","Address"),r),t(null!=e.keyId,Ee("keyId"),r),t(e.signature,Ee("signature"),r),t(e.keyId===n.identity.keyId,ve("keyId"),r),t(c(e.addr)===c(n.identity.address),ve("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 Je(e){Be();const t=m(async t=>{for(t.send(Fe,h);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(Fe,k);e(n.data)}});return()=>v(t,"@EXIT")}function qe(){return Be(),v(Fe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ke=()=>({authenticate:_e,unauthenticate:je,authorization:He,subscribe:Je,snapshot:qe}),Ge=()=>Ke().authenticate(),$e=()=>Ke().unauthenticate(),Ve=()=>{Ke().unauthenticate(),Ke().authenticate()},We=()=>Ke().authenticate(),Xe=()=>Ke().authenticate(),Ye=Ke().authorization,Ze="0.0.67-alpha.9";export{Ze as VERSION,Ge as authenticate,Ye as authz,Ke as currentUser,ue as events,Xe as logIn,Ve as reauthenticate,Y as serialize,We as signUp,ae 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 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 a}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as s,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 b,send as w}from"@onflow/util-actor";import{send as k}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 A(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 C(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 A(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)?A(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 R=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return R(e,8)},j=function(e){return Buffer.from(JSON.stringify(e),"utf8")},N=function(e){return l(e).toString("hex")},F=function(e){return z(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(j),(n=e.refBlock,R(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},T=function(e){var n=O(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})},O=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},z=function(e){_.forEach(function(n){return K(e,n)}),H.forEach(function(n){return K(e.proposalKey,n,"proposalKey")})},M=function(e){return"number"==typeof e},B=function(e){return"string"==typeof e},U=function(e){return null!==e&&"object"==typeof e},D=function(e){return U(e)&&e instanceof Array},_=[{name:"script",check:B},{name:"arguments",check:D},{name:"refBlock",check:B,defaultVal:"0"},{name:"gasLimit",check:M},{name:"proposalKey",check:U},{name:"payer",check:B},{name:"authorizers",check:D}],H=[{name:"address",check:B},{name:"keyId",check:M},{name:"sequenceNum",check:M}],J=[{name:"payloadSigs",check:D}],q=[{name:"address",check:B},{name:"keyId",check:M},{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,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:s(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function re(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:s(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:s(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return s(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(i){try{return Promise.resolve(i).then(function(u){return i=u,Promise.resolve(function(i){try{var u=function(){if(r(i)||t(i)){var u=function(){return n(Q(a),"Cadence needs to be a string at this point."),Promise.resolve(e().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},a)})).then(function(e){i.message.cadence=e})},a=o(i,"ix.cadence");n(ee(a)||Q(a),"Cadence needs to be a function or a string.");var s=function(){if(ee(a))return Promise.resolve(a({})).then(function(e){a=e})}();return s&&s.then?s.then(u):u()}}();return Promise.resolve(u&&u.then?u.then(function(){return i}):i)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var o=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)};if(r(e)||t(e))for(var i=0,u=Object.entries(e.arguments);i<u.length;i++){var a=u[i];e.arguments[a[0]].asArgument=o(a[1])}return Promise.resolve(e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=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 a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.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}(s,function(e){return n(s[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,a=function(){if(ee(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return a&&a.then?a.then(i):i()});return o&&o.then?o.then(n):n()}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(e)&&null==e.message.refBlock)return Promise.resolve(a()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var t=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 Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(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);var o=(i=re(e),N(F(i)));return Promise.resolve(Promise.all(n.map(ne(e,o)))).then(function(){var r=function(e){return N(function(e){return function(e){J.forEach(function(n){return K(e,n)}),e.payloadSigs.forEach(function(e,n){q.forEach(function(r){return K(e,r,"payloadSigs",n)})})}(e),[F(e),T(e)]}(e))}(x({},re(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(ne(e,r)))).then(function(){})})}var i}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return i})})})})})})})}catch(e){return Promise.reject(e)}});var te,oe,ie=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)}},ue=function(e){try{return Promise.resolve(k([S(e)]).then(E))}catch(e){return Promise.reject(e)}},ae=function(e){return e.status>=4},se=function(e){return e.status>=3},ce=function(e){return e.status>=2},fe=((te={})[m]=function(e){try{return Promise.resolve(ue(e.self())).then(function(n){ae(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},te[h]=function(e,n){e.subscribe(n.from),e.send(n.from,p,e.all())},te[v]=function(e,n){e.unsubscribe(n.from)},te[y]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},te.POLL=function(e){try{return Promise.resolve(ue(e.self())).then(function(n){var r,t;ae(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)}},te),le=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},de=function(e){return P(fe,le(e))};function me(e){function n(n){return g(le(e),de,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 b(e,de)},subscribe:n,onceFinalized:r(ce),onceExecuted:r(se),onceSealed:r(ae)}}me.isUnknown=function(e){return e.status>=0},me.isPending=function(e){return e.status>=1},me.isFinalized=ce,me.isExecuted=se,me.isSealed=ae,me.isExpired=function(e){return 5===e.status};var he=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)}},pe=((oe={}).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(a()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(he(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(a()).then(function(r){return e.put("hwm",r),Promise.resolve(k([getEvents(e.self(),n.height,r.height-1)]).then(E)).then(function(n){for(var r,t=C(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(he(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)}},oe[h]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(he(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)}},oe[v]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},oe),ve=function(e){return P(pe,e)};function ye(e){return{subscribe:function(n){return g(e,ve,n)}}}var ge={"@type":"Service","@vsn":"1.0.0"},Pe={"@type":"Identity","@vsn":"1.0.0"},be={"@type":"USER","@vsn":"1.0.0"},we={"@type":"PollingResponse","@vsn":"1.0.0"};function ke(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return x({old:e},ge,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Ee(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Se={"back-channel-rpc":Ee,"pre-authz":function(e){if(null==e)return null;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})}},authz:function(e){if(null==e)return null;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})}},authn:function(e){if(null==e)return null;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}})}},frame:ke};function Ie(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function xe(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}var Ae=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ce=function(e,n){return"Missing "+Ae(e,n)+" in Composite Signature."},Re=function(e,n){return Ae(e,n)+" in Composit Signature did not match the requested "+e+"."};function Le(e){var n=new URL(e.endpoint);if(null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function je(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Le(e),{method:r,headers:x({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return x({},we,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:Ee(e.authorizationUpdates),local:ke((e.local||[])[0])})}}var Fe="FCL_IFRAME",Te=function(){},Oe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function ze(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return e;var t=r.onClose||Te,o=r.onMessage||Te,i=r.onReady||Te;window.addEventListener("message",c);var u=function(e){n(!document.getElementById(Fe),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=Fe,r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(Fe)&&document.getElementById(Fe).remove()}]}(Le(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if("object"!=typeof e.data)return;if(Oe.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e)),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var Me,Be={"HTTP/GET":"GET","HTTP/POST":"POST"},Ue=function(e){return n(Be[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Be[e.method]},De={"HTTP/POST":function(e,r){try{return r.data=e.data,Promise.resolve(je(e,{data:r}).then(Ne)).then(function(e){var r=!0,t=ze(e.local,{onClose:function(){r=!1}}).close;return function e(r,t){void 0===t&&(t=function(){return!0});try{if(n(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(je(r,{method:Ue(r)}).then(Ne)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(e.updates,function(){return r}).then(function(e){return t(),e}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=I();n.data=e.data,ze(e,{onReady:function(r,t){var i=t.send;console.log("FCL[IFRAME/RPC] onReady"),i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})},onMessage:function(e,n){var i=n.close;if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"===e.data.jsonrpc&&e.data.id===o){console.log("FCL[IFRAME/RPC] A",data.result);var u=Ne(data.result);switch(console.log("FCL[IFRAME/RPC] B",u),u.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",u.data),r(u.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",u),t("Declined: "+(u.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",u),t("Declined: No reason supplied")}i()}}})})}};function _e(e,n,r){if(!e.s){if(r instanceof Je){if(!r.s)return void(r.o=_e.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(_e.bind(null,e,n),_e.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var He=function(e){try{return rn(),Promise.resolve(Ke()).then(function(r){xe(r.services,"authn");var t=xe(r.services,"authz");return xe(r.services,"pre-authz"),x({},e,{tempId:"CURRENT_USER",resolve:null,addr:s(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return console.log("Signable",e),Promise.resolve(function(e,r){try{return Promise.resolve(De[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=s(r.addr),function(e,r){try{var t={compSig:e,authz:r};n(e.addr,Ce("addr","Address"),t),n(null!=e.keyId,Ce("keyId"),t),n(e.signature,Ce("signature"),t),n(e.keyId===r.identity.keyId,Re("keyId"),t),n(s(e.addr)===s(r.identity.address),Re("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)}},Je=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{_e(t,1,i(this.v))}catch(e){_e(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?_e(t,1,n?n(o):o):r?_e(t,1,r(o)):_e(t,2,o)}catch(e){_e(t,2,e)}},t},e}();function qe(e){return e instanceof Je&&1&e.s}var Ke=function(){try{return Promise.resolve(new Promise(function(n){try{return rn(),Promise.resolve(an()).then(function(r){return r.loggedIn&&tn(r)?n(r):Promise.resolve(e().get("challenge.handshake")).then(function(e){var r,t,o,i=(r={handshake:e,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function e(r){var t=r.data;try{return t.type===Ze||t.type===Xe?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Ye?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=C(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{return Se[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),u=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,i);return x({},be,{addr:c(e.addr),cid:Ie(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return w(Ge,We,e),Promise.resolve(an()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ge="CURRENT_USER",Ve="CURRENT_USER/UPDATED",We="SET_CURRENT_USER",Xe="FCL::CANCEL",Ye="FCL::CHALLENGE::RESPONSE",Ze="FCL::CHALLENGE::CANCEL",$e='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Qe=function(e){try{return sessionStorage.setItem(Ge,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},en=function(){return e().get("persistSession",!0)},nn=((Me={})[m]=function(e){try{return e.merge(JSON.parse($e)),Promise.resolve(en()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse($e),n=JSON.parse(sessionStorage.getItem(Ge));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Ge),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){tn(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Me[h]=function(e,n){e.subscribe(n.from),e.send(n.from,Ve,x({},e.all()))},Me[v]=function(e,n){e.unsubscribe(n.from)},Me.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Me[We]=function(e,n,r){try{return e.merge(r),Promise.resolve(en()).then(function(n){n&&Qe(e.all()),e.broadcast(Ve,x({},e.all()))})}catch(e){return Promise.reject(e)}},Me.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse($e)),Promise.resolve(en()).then(function(n){n&&Qe(e.all()),e.broadcast(Ve,x({},e.all()))})}catch(e){return Promise.reject(e)}},Me),rn=function(){return P(nn,Ge)};function tn(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function on(){rn(),w(Ge,"DEL_CURRENT_USER")}function un(e){rn();var n=P(function(n){try{var r;return n.send(Ge,h),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(qe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!qe(i)){t=1;break}i=i.s}}var u=new Je,a=_e.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):_e(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||qe(o)&&!o.v)return void _e(u,1,i);if(o.then)return void o.then(c).then(void 0,a);qe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):_e(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Ge,v),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return w(n,"@EXIT")}}function an(){return rn(),w(Ge,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var sn=function(){return{authenticate:Ke,unauthenticate:on,authorization:He,subscribe:un,snapshot:an}},cn=function(){return sn().authenticate()},fn=function(){return sn().unauthenticate()},ln=function(){sn().unauthenticate(),sn().authenticate()},dn=function(){return sn().authenticate()},mn=function(){return sn().authenticate()},hn=sn().authorization,pn="0.0.67-alpha.8";export{pn as VERSION,cn as authenticate,hn as authz,sn as currentUser,ye as events,mn as logIn,ln as reauthenticate,ie as serialize,dn as signUp,me as tx,fn 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 a}from"@onflow/sdk-latest-block";export{latestBlock}from"@onflow/sdk-latest-block";import{sansPrefix as s,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 b,send as w}from"@onflow/util-actor";import{send as k}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 A(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 C(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 A(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)?A(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 R=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return R(e,8)},j=function(e){return Buffer.from(JSON.stringify(e),"utf8")},N=function(e){return l(e).toString("hex")},F=function(e){return z(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(j),(n=e.refBlock,R(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},T=function(e){var n=O(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})},O=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},z=function(e){_.forEach(function(n){return K(e,n)}),H.forEach(function(n){return K(e.proposalKey,n,"proposalKey")})},M=function(e){return"number"==typeof e},B=function(e){return"string"==typeof e},U=function(e){return null!==e&&"object"==typeof e},D=function(e){return U(e)&&e instanceof Array},_=[{name:"script",check:B},{name:"arguments",check:D},{name:"refBlock",check:B,defaultVal:"0"},{name:"gasLimit",check:M},{name:"proposalKey",check:U},{name:"payer",check:B},{name:"authorizers",check:D}],H=[{name:"address",check:B},{name:"keyId",check:M},{name:"sequenceNum",check:M}],J=[{name:"payloadSigs",check:D}],q=[{name:"address",check:B},{name:"keyId",check:M},{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,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:s(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function re(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:s(e.accounts[e.proposer].addr),keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:s(e.accounts[e.payer].addr),authorizers:e.authorizations.map(function(n){return s(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(i){try{return Promise.resolve(i).then(function(u){return i=u,Promise.resolve(function(i){try{var u=function(){if(r(i)||t(i)){var u=function(){return n(Q(a),"Cadence needs to be a string at this point."),Promise.resolve(e().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},a)})).then(function(e){i.message.cadence=e})},a=o(i,"ix.cadence");n(ee(a)||Q(a),"Cadence needs to be a function or a string.");var s=function(){if(ee(a))return Promise.resolve(a({})).then(function(e){a=e})}();return s&&s.then?s.then(u):u()}}();return Promise.resolve(u&&u.then?u.then(function(){return i}):i)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var o=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)};if(r(e)||t(e))for(var i=0,u=Object.entries(e.arguments);i<u.length;i++){var a=u[i];e.arguments[a[0]].asArgument=o(a[1])}return Promise.resolve(e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=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 a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.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}(s,function(e){return n(s[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,a=function(){if(ee(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){r=(o=e).tempId})}();return a&&a.then?a.then(i):i()});return o&&o.then?o.then(n):n()}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(e)&&null==e.message.refBlock)return Promise.resolve(a()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var t=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 Promise.resolve(t&&t.then?t.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(r(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);var o=(i=re(e),N(F(i)));return Promise.resolve(Promise.all(n.map(ne(e,o)))).then(function(){var r=function(e){return N(function(e){return function(e){J.forEach(function(n){return K(e,n)}),e.payloadSigs.forEach(function(e,n){q.forEach(function(r){return K(e,r,"payloadSigs",n)})})}(e),[F(e),T(e)]}(e))}(x({},re(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(t.map(ne(e,r)))).then(function(){})})}var i}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(i)).then(function(){return i})})})})})})})}catch(e){return Promise.reject(e)}});var te,oe,ie=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)}},ue=function(e){try{return Promise.resolve(k([S(e)]).then(E))}catch(e){return Promise.reject(e)}},ae=function(e){return e.status>=4},se=function(e){return e.status>=3},ce=function(e){return e.status>=2},fe=((te={})[m]=function(e){try{return Promise.resolve(ue(e.self())).then(function(n){ae(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},te[h]=function(e,n){e.subscribe(n.from),e.send(n.from,p,e.all())},te[v]=function(e,n){e.unsubscribe(n.from)},te[y]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},te.POLL=function(e){try{return Promise.resolve(ue(e.self())).then(function(n){var r,t;ae(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)}},te),le=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},de=function(e){return P(fe,le(e))};function me(e){function n(n){return g(le(e),de,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 b(e,de)},subscribe:n,onceFinalized:r(ce),onceExecuted:r(se),onceSealed:r(ae)}}me.isUnknown=function(e){return e.status>=0},me.isPending=function(e){return e.status>=1},me.isFinalized=ce,me.isExecuted=se,me.isSealed=ae,me.isExpired=function(e){return 5===e.status};var he=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)}},pe=((oe={}).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(a()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(he(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(a()).then(function(r){return e.put("hwm",r),Promise.resolve(k([getEvents(e.self(),n.height,r.height-1)]).then(E)).then(function(n){for(var r,t=C(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(he(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)}},oe[h]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(he(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)}},oe[v]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},oe),ve=function(e){return P(pe,e)};function ye(e){return{subscribe:function(n){return g(e,ve,n)}}}var ge={"@type":"Service","@vsn":"1.0.0"},Pe={"@type":"Identity","@vsn":"1.0.0"},be={"@type":"USER","@vsn":"1.0.0"},we={"@type":"PollingResponse","@vsn":"1.0.0"};function ke(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return x({old:e},ge,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Ee(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return x({},ge,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var Se={"back-channel-rpc":Ee,"pre-authz":function(e){if(null==e)return null;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})}},authz:function(e){if(null==e)return null;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})}},authn:function(e){if(null==e)return null;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}})}},frame:ke};function Ie(e){return l([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function xe(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}var Ae=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ce=function(e,n){return"Missing "+Ae(e,n)+" in Composite Signature."},Re=function(e,n){return Ae(e,n)+" in Composit Signature did not match the requested "+e+"."};function Le(e){var n=new URL(e.endpoint);if(null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function je(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(Le(e),{method:r,headers:x({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Ne(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return x({},we,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:Ee(e.authorizationUpdates),local:ke((e.local||[])[0])})}}var Fe="FCL_IFRAME",Te=function(){},Oe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function ze(e,r){if(void 0===r&&(r={}),console.log("FRAME",{service:e,opts:r}),null==e)return e;var t=r.onClose||Te,o=r.onMessage||Te,i=r.onReady||Te;window.addEventListener("message",c);var u=function(e){n(!document.getElementById(Fe),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=Fe,r.allow="usb *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(Fe)&&document.getElementById(Fe).remove()}]}(Le(e)),a=u[0],s=u[1];return{send:l,close:f};function c(e){try{if(Oe.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:l,close:f}),o(e,{send:l,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:l,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var Me,Be={"HTTP/GET":"GET","HTTP/POST":"POST"},Ue=function(e){return n(Be[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Be[e.method]},De={"HTTP/POST":function(e,r){try{return r.data=e.data,Promise.resolve(je(e,{data:r}).then(Ne)).then(function(e){var r=!0,t=ze(e.local,{onClose:function(){r=!1}}).close;return function e(r,t){void 0===t&&(t=function(){return!0});try{if(n(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(je(r,{method:Ue(r)}).then(Ne)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(e.updates,function(){return r}).then(function(e){return t(),e}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=I();n.data=e.data,ze(e,{onReady:function(r,t){var i=t.send;console.log("FCL[IFRAME/RPC] onReady"),i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})},onMessage:function(e,n){var i=n.close;if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"===e.data.jsonrpc&&e.data.id===o){console.log("FCL[IFRAME/RPC] A",data.result);var u=Ne(data.result);switch(console.log("FCL[IFRAME/RPC] B",u),u.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",u.data),r(u.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",u),t("Declined: "+(u.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",u),t("Declined: No reason supplied")}i()}}})})}};function _e(e,n,r){if(!e.s){if(r instanceof Je){if(!r.s)return void(r.o=_e.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(_e.bind(null,e,n),_e.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var He=function(e){try{return rn(),Promise.resolve(Ke()).then(function(r){xe(r.services,"authn");var t=xe(r.services,"authz");return xe(r.services,"pre-authz"),x({},e,{tempId:"CURRENT_USER",resolve:null,addr:s(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return console.log("Signable",e),Promise.resolve(function(e,r){try{return Promise.resolve(De[e.method](e,r)).then(function(r){return null==r.sig&&(r.sig=r.signature),null==r.signature&&(r.signature=r.sig),r.addr=s(r.addr),function(e,r){try{var t={compSig:e,authz:r};n(e.addr,Ce("addr","Address"),t),n(null!=e.keyId,Ce("keyId"),t),n(e.signature,Ce("signature"),t),n(e.keyId===r.identity.keyId,Re("keyId"),t),n(s(e.addr)===s(r.identity.address),Re("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)}},Je=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{_e(t,1,i(this.v))}catch(e){_e(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?_e(t,1,n?n(o):o):r?_e(t,1,r(o)):_e(t,2,o)}catch(e){_e(t,2,e)}},t},e}();function qe(e){return e instanceof Je&&1&e.s}var Ke=function(){try{return Promise.resolve(new Promise(function(n){try{return rn(),Promise.resolve(an()).then(function(r){return r.loggedIn&&tn(r)?n(r):Promise.resolve(e().get("challenge.handshake")).then(function(e){var r,t,o,i=(r={handshake:e,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function e(r){var t=r.data;try{return t.type===Ze||t.type===Xe?(i(),window.removeEventListener("message",e),Promise.resolve()):t.type!==Ye?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=C(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{return Se[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),u=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,i);return x({},be,{addr:c(e.addr),cid:Ie(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(e){return w(Ge,We,e),Promise.resolve(an()).then(function(e){n(e)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Ge="CURRENT_USER",Ve="CURRENT_USER/UPDATED",We="SET_CURRENT_USER",Xe="FCL::CANCEL",Ye="FCL::CHALLENGE::RESPONSE",Ze="FCL::CHALLENGE::CANCEL",$e='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',Qe=function(e){try{return sessionStorage.setItem(Ge,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},en=function(){return e().get("persistSession",!0)},nn=((Me={})[m]=function(e){try{return e.merge(JSON.parse($e)),Promise.resolve(en()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse($e),n=JSON.parse(sessionStorage.getItem(Ge));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(Ge),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){tn(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},Me[h]=function(e,n){e.subscribe(n.from),e.send(n.from,Ve,x({},e.all()))},Me[v]=function(e,n){e.unsubscribe(n.from)},Me.SNAPSHOT=function(e,n){try{return n.reply(x({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},Me[We]=function(e,n,r){try{return e.merge(r),Promise.resolve(en()).then(function(n){n&&Qe(e.all()),e.broadcast(Ve,x({},e.all()))})}catch(e){return Promise.reject(e)}},Me.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse($e)),Promise.resolve(en()).then(function(n){n&&Qe(e.all()),e.broadcast(Ve,x({},e.all()))})}catch(e){return Promise.reject(e)}},Me),rn=function(){return P(nn,Ge)};function tn(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function on(){rn(),w(Ge,"DEL_CURRENT_USER")}function un(e){rn();var n=P(function(n){try{var r;return n.send(Ge,h),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(qe(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!qe(i)){t=1;break}i=i.s}}var u=new Je,a=_e.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):_e(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||qe(o)&&!o.v)return void _e(u,1,i);if(o.then)return void o.then(c).then(void 0,a);qe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):_e(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(Ge,v),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return w(n,"@EXIT")}}function an(){return rn(),w(Ge,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var sn=function(){return{authenticate:Ke,unauthenticate:on,authorization:He,subscribe:un,snapshot:an}},cn=function(){return sn().authenticate()},fn=function(){return sn().unauthenticate()},ln=function(){sn().unauthenticate(),sn().authenticate()},dn=function(){return sn().authenticate()},mn=function(){return sn().authenticate()},hn=sn().authorization,pn="0.0.67-alpha.9";export{pn as VERSION,cn as authenticate,hn as authz,sn as currentUser,ye as events,mn as logIn,ln as reauthenticate,ie as serialize,dn as signUp,me as tx,fn 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,r,t,o,i,u,a,s,c,l,f,d,m,h,p,v,y,g,b,P,k,w,E,S,I,j,A,B,O){function C(){return(C=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 R(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 x(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 R(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)?R(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)}n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return T(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},F=function(e){return a.encode(e).toString("hex")},z=function(e){return M(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(N),(n=e.refBlock,T(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},U=function(e){var n=q(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})},q=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},M=function(e){J.forEach(function(n){return X(e,n)}),K.forEach(function(n){return X(e.proposalKey,n,"proposalKey")})},D=function(e){return"number"==typeof e},_=function(e){return"string"==typeof e},H=function(e){return null!==e&&"object"==typeof e},G=function(e){return H(e)&&e instanceof Array},J=[{name:"script",check:_},{name:"arguments",check:G},{name:"refBlock",check:_,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:H},{name:"payer",check:_},{name:"authorizers",check:G}],K=[{name:"address",check:_},{name:"keyId",check:D},{name:"sequenceNum",check:D}],V=[{name:"payloadSigs",check:G}],W=[{name:"address",check:_},{name:"keyId",check:D},{name:"sig",check:_}],X=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 Z(o,r,t);if(!i(e[o]))throw $(o,r,t)},Y=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},Z=function(e,n,r){return new Error("Missing field "+Y(e,n,r))},$=function(e,n,r){return new Error("Invalid field "+Y(e,n,r))},Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ee(e,n,r){if(!e.s){if(r instanceof ne){if(!r.s)return void(r.o=ee.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(ee.bind(null,e,n),ee.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ne=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{ee(t,1,i(this.v))}catch(e){ee(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(t,1,n?n(o):o):r?ee(t,1,r(o)):ee(t,2,o)}catch(e){ee(t,2,e)}},t},e}();function re(e){return e instanceof ne&&1&e.s}var te=function(e){return"string"==typeof e},oe=function(e){return"function"==typeof e};function ie(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:i.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function ue(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(i){return e=i,Promise.resolve(function(e){try{var o=function(){if(t.isTransaction(e)||t.isScript(e)){var o=function(){return r.invariant(te(i),"Cadence needs to be a string at this point."),Promise.resolve(n.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},i)})).then(function(n){e.message.cadence=n})},i=t.get(e,"ix.cadence");r.invariant(oe(i)||te(i),"Cadence needs to be a function or a string.");var u=function(){if(oe(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{if(t.isTransaction(e)||t.isScript(e))for(var n=0,o=Object.entries(e.arguments);n<o.length;n++){var i=o[n];e.arguments[i[0]].asArgument=(r.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),oe(u.xform)?u.xform(u.value):oe(u.xform.asArgument)?u.xform.asArgument(u.value):void r.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=function(){e.accounts=r},r={},o=function(e,n,r){if("function"==typeof e[Q]){var t,o,i,u=e[Q]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!re(r))return void r.then(e,i||(i=ee.bind(null,o=new ne,2)));r=r.v}o?ee(o,1,r):o=r}catch(e){ee(o||(o=new ne),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.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(!re(u))return void u.then(r,o||(o=ee.bind(null,t=new ne,2)));u=u.v}t?ee(t,1,u):t=u}catch(e){ee(t||(t=new ne),2,e)}}(),t}(s,function(e){return n(s[e])})}(Object.entries(e.accounts),function(n){var t=n[0],o=n[1];function i(){r[t]=r[t]||o,r[t].role.proposer=r[t].role.proposer||o.role.proposer,r[t].role.payer=r[t].role.payer||o.role.payer,r[t].role.authorizer=r[t].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=t),e.payer===u&&(e.payer=t),e.authorizations=e.authorizations.map(function(e){return e===u?t:e})}var u=t,a=function(){if(oe(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){t=(o=e).tempId})}();return a&&a.then?a.then(i):i()});return o&&o.then?o.then(n):n()}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(o.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=Object.values(e.accounts).find(function(e){return e.role.proposer});r.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(r){e.accounts[n.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);var r=new Set([e.payer]);r=Array.from(r);var o=(i=ue(e),F(z(i)));return Promise.resolve(Promise.all(n.map(ie(e,o)))).then(function(){var t=function(e){return F(function(e){return function(e){V.forEach(function(n){return X(e,n)}),e.payloadSigs.forEach(function(e,n){W.forEach(function(r){return X(e,r,"payloadSigs",n)})})}(e),[z(e),U(e)]}(e))}(C({},ue(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(r.map(ie(e,t)))).then(function(){})})}var i}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return e})})})})})})})}catch(e){return Promise.reject(e)}});var ae,se,ce=function(e){try{return Promise.resolve(l.send([d.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},le=function(e){return e.status>=4},fe=function(e){return e.status>=3},de=function(e){return e.status>=2},me=((ae={})[c.INIT]=function(e){try{return Promise.resolve(ce(e.self())).then(function(n){le(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ae[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,c.UPDATED,e.all())},ae[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ae[c.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ae.POLL=function(e){try{return Promise.resolve(ce(e.self())).then(function(n){var r,t;le(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(c.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ae),he=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},pe=function(e){return c.spawn(me,he(e))};function ve(e){function n(n){return c.subscriber(he(e),pe,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 c.snapshoter(e,pe)},subscribe:n,onceFinalized:r(de),onceExecuted:r(fe),onceSealed:r(le)}}ve.isUnknown=function(e){return e.status>=0},ve.isPending=function(e){return e.status>=1},ve.isFinalized=de,ve.isExecuted=fe,ve.isSealed=le,ve.isExpired=function(e){return 5===e.status};var ye=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},ge=((se={}).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(o.latestBlock()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(ye(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(o.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(l.send([getEvents(e.self(),n.height,r.height-1)]).then(f.decode)).then(function(n){for(var r,t=x(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(ye(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)}},se[c.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ye(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)}},se[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},se),be=function(e){return c.spawn(ge,e)},Pe={"@type":"Service","@vsn":"1.0.0"},ke={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},Ee={"@type":"PollingResponse","@vsn":"1.0.0"};function Se(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({old:e},Pe,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Ie(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var je={"back-channel-rpc":Ie,"pre-authz":function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},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}})}},frame:Se};function Ae(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Be(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}var Oe=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ce=function(e,n){return"Missing "+Oe(e,n)+" in Composite Signature."},Re=function(e,n){return Oe(e,n)+" in Composit Signature did not match the requested "+e+"."};function xe(e){var n=new URL(e.endpoint);if(null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Te(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(xe(e),{method:r,headers:C({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Le(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Ee,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:Ie(e.authorizationUpdates),local:Se((e.local||[])[0])})}}var Ne="FCL_IFRAME",Fe=function(){},ze=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ue(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return e;var t=n.onClose||Fe,o=n.onMessage||Fe,i=n.onReady||Fe;window.addEventListener("message",c);var u=function(e){r.invariant(!document.getElementById(Ne),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=Ne,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(Ne)&&document.getElementById(Ne).remove()}]}(xe(e)),a=u[0],s=u[1];return{send:f,close:l};function c(e){try{if("object"!=typeof e.data)return;if(ze.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:f,close:l}),o(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:f,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e)),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var qe,Me={"HTTP/GET":"GET","HTTP/POST":"POST"},De=function(e){return r.invariant(Me[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Me[e.method]},_e={"HTTP/POST":function(e,n){try{return n.data=e.data,Promise.resolve(Te(e,{data:n}).then(Le)).then(function(e){var n=!0,t=Ue(e.local,{onClose:function(){n=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(n,{method:De(n)}).then(Le)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(e.updates,function(){return n}).then(function(e){return t(),e}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=h.uid();n.data=e.data,Ue(e,{onReady:function(r,t){var i=t.send;console.log("FCL[IFRAME/RPC] onReady"),i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})},onMessage:function(e,n){var i=n.close;if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"===e.data.jsonrpc&&e.data.id===o){console.log("FCL[IFRAME/RPC] A",data.result);var u=Le(data.result);switch(console.log("FCL[IFRAME/RPC] B",u),u.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",u.data),r(u.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",u),t("Declined: "+(u.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",u),t("Declined: No reason supplied")}i()}}})})}};function He(e,n,r){if(!e.s){if(r instanceof Je){if(!r.s)return void(r.o=He.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(He.bind(null,e,n),He.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ge=function(e){try{return on(),Promise.resolve(Ve()).then(function(n){Be(n.services,"authn");var t=Be(n.services,"authz");return Be(n.services,"pre-authz"),C({},e,{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return console.log("Signable",e),Promise.resolve(function(e,n){try{return Promise.resolve(_e[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 t={compSig:e,authz:n};r.invariant(e.addr,Ce("addr","Address"),t),r.invariant(null!=e.keyId,Ce("keyId"),t),r.invariant(e.signature,Ce("signature"),t),r.invariant(e.keyId===n.identity.keyId,Re("keyId"),t),r.invariant(i.sansPrefix(e.addr)===i.sansPrefix(n.identity.address),Re("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)}},Je=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{He(t,1,i(this.v))}catch(e){He(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?He(t,1,n?n(o):o):r?He(t,1,r(o)):He(t,2,o)}catch(e){He(t,2,e)}},t},e}();function Ke(e){return e instanceof Je&&1&e.s}var Ve=function(){try{return Promise.resolve(new Promise(function(e){try{return on(),Promise.resolve(cn()).then(function(r){return r.loggedIn&&un(r)?e(r):Promise.resolve(n.config().get("challenge.handshake")).then(function(n){var r,t,o,u=(r={handshake:n,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function n(r){var t=r.data;try{return t.type===Qe||t.type===Ze?(u(),window.removeEventListener("message",n),Promise.resolve()):t.type!==$e?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 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=x(e.authorizations);!(r=t()).done;)n.push(C({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(C({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,u=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return je[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),a=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return C({},we,{addr:i.withPrefix(e.addr),cid:Ae(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){return c.send(We,Ye,n),Promise.resolve(cn()).then(function(n){e(n)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},We="CURRENT_USER",Xe="CURRENT_USER/UPDATED",Ye="SET_CURRENT_USER",Ze="FCL::CANCEL",$e="FCL::CHALLENGE::RESPONSE",Qe="FCL::CHALLENGE::CANCEL",en='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',nn=function(e){try{return sessionStorage.setItem(We,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},rn=function(){return n.config().get("persistSession",!0)},tn=((qe={})[c.INIT]=function(e){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(en),n=JSON.parse(sessionStorage.getItem(We));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(We),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){un(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},qe[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,Xe,C({},e.all()))},qe[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},qe.SNAPSHOT=function(e,n){try{return n.reply(C({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},qe[Ye]=function(e,n,r){try{return e.merge(r),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Xe,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Xe,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe),on=function(){return c.spawn(tn,We)};function un(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function an(){on(),c.send(We,"DEL_CURRENT_USER")}function sn(e){on();var n=c.spawn(function(n){try{var r;return n.send(We,c.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ke(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ke(i)){t=1;break}i=i.s}}var u=new Je,a=He.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):He(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ke(o)&&!o.v)return void He(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ke(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):He(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(We,c.UNSUBSCRIBE),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return c.send(n,"@EXIT")}}function cn(){return on(),c.send(We,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ln=function(){return{authenticate:Ve,unauthenticate:an,authorization:Ge,subscribe:sn,snapshot:cn}},fn=ln().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"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 l.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return m.getEvents}}),Object.defineProperty(e,"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 E.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return E.authorizations}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return S.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return S.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 A.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return B.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return O.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return O.params}}),e.VERSION="0.0.67-alpha.8",e.authenticate=function(){return ln().authenticate()},e.authz=fn,e.currentUser=ln,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,be,n)}}},e.logIn=function(){return ln().authenticate()},e.reauthenticate=function(){ln().unauthenticate(),ln().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var r=function(){return Promise.resolve(s.resolve(n)(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(n){e=n})}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}},e.signUp=function(){return ln().authenticate()},e.tx=ve,e.unauthenticate=function(){return ln().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,r,t,o,i,u,a,s,c,l,f,d,m,h,p,v,y,g,b,P,k,w,E,S,I,j,A,B,O){function C(){return(C=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 R(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 x(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 R(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)?R(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)}n.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var T=function(e,n){return Buffer.from(e.padStart(2*n,0),"hex")},L=function(e){return T(e,8)},N=function(e){return Buffer.from(JSON.stringify(e),"utf8")},F=function(e){return a.encode(e).toString("hex")},z=function(e){return M(e),[(r=e.script,Buffer.from(r,"utf8")),e.arguments.map(N),(n=e.refBlock,T(n,32)),e.gasLimit,L(e.proposalKey.address),e.proposalKey.keyId,e.proposalKey.sequenceNum,L(e.payer),e.authorizers.map(L)];var n,r},U=function(e){var n=q(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})},q=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},M=function(e){J.forEach(function(n){return X(e,n)}),K.forEach(function(n){return X(e.proposalKey,n,"proposalKey")})},D=function(e){return"number"==typeof e},_=function(e){return"string"==typeof e},H=function(e){return null!==e&&"object"==typeof e},G=function(e){return H(e)&&e instanceof Array},J=[{name:"script",check:_},{name:"arguments",check:G},{name:"refBlock",check:_,defaultVal:"0"},{name:"gasLimit",check:D},{name:"proposalKey",check:H},{name:"payer",check:_},{name:"authorizers",check:G}],K=[{name:"address",check:_},{name:"keyId",check:D},{name:"sequenceNum",check:D}],V=[{name:"payloadSigs",check:G}],W=[{name:"address",check:_},{name:"keyId",check:D},{name:"sig",check:_}],X=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 Z(o,r,t);if(!i(e[o]))throw $(o,r,t)},Y=function(e,n,r){return n?null==r?n+"."+e:n+"."+r+"."+e:e},Z=function(e,n,r){return new Error("Missing field "+Y(e,n,r))},$=function(e,n,r){return new Error("Invalid field "+Y(e,n,r))},Q="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ee(e,n,r){if(!e.s){if(r instanceof ne){if(!r.s)return void(r.o=ee.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(ee.bind(null,e,n),ee.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var ne=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{ee(t,1,i(this.v))}catch(e){ee(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?ee(t,1,n?n(o):o):r?ee(t,1,r(o)):ee(t,2,o)}catch(e){ee(t,2,e)}},t},e}();function re(e){return e instanceof ne&&1&e.s}var te=function(e){return"string"==typeof e},oe=function(e){return"function"==typeof e};function ie(e,n){return function(r){try{var t=e.accounts[r];return null!=t.signature?Promise.resolve():Promise.resolve(t.signingFunction(function(e,n,r){return{"@type":"Signable","@vsn":"1.0.0",message:n,addr:i.sansPrefix(e.addr),keyId:e.keyId,roles:e.role,cadence:r.message.cadence,args:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),data:{},interaction:r}}(t,n,e))).then(function(n){e.accounts[r].signature=n.signature})}catch(e){return Promise.reject(e)}}}function ue(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(i){return e=i,Promise.resolve(function(e){try{var o=function(){if(t.isTransaction(e)||t.isScript(e)){var o=function(){return r.invariant(te(i),"Cadence needs to be a string at this point."),Promise.resolve(n.config().where(/^0x/).then(function(e){return Object.entries(e).reduce(function(e,n){return e.replace(n[0],n[1])},i)})).then(function(n){e.message.cadence=n})},i=t.get(e,"ix.cadence");r.invariant(oe(i)||te(i),"Cadence needs to be a function or a string.");var u=function(){if(oe(i))return Promise.resolve(i({})).then(function(e){i=e})}();return u&&u.then?u.then(o):o()}}();return Promise.resolve(o&&o.then?o.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{if(t.isTransaction(e)||t.isScript(e))for(var n=0,o=Object.entries(e.arguments);n<o.length;n++){var i=o[n];e.arguments[i[0]].asArgument=(r.invariant(null!=typeof(u=i[1]).xform,"No type specified for argument: "+u.value),oe(u.xform)?u.xform(u.value):oe(u.xform.asArgument)?u.xform.asArgument(u.value):void r.invariant(!1,"Invalid Argument",u))}return Promise.resolve(e)}catch(e){return Promise.reject(e)}var u}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=function(){e.accounts=r},r={},o=function(e,n,r){if("function"==typeof e[Q]){var t,o,i,u=e[Q]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!re(r))return void r.then(e,i||(i=ee.bind(null,o=new ne,2)));r=r.v}o?ee(o,1,r):o=r}catch(e){ee(o||(o=new ne),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.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(!re(u))return void u.then(r,o||(o=ee.bind(null,t=new ne,2)));u=u.v}t?ee(t,1,u):t=u}catch(e){ee(t||(t=new ne),2,e)}}(),t}(s,function(e){return n(s[e])})}(Object.entries(e.accounts),function(n){var t=n[0],o=n[1];function i(){r[t]=r[t]||o,r[t].role.proposer=r[t].role.proposer||o.role.proposer,r[t].role.payer=r[t].role.payer||o.role.payer,r[t].role.authorizer=r[t].role.authorizer||o.role.authorizer,e.proposer===u&&(e.proposer=t),e.payer===u&&(e.payer=t),e.authorizations=e.authorizations.map(function(e){return e===u?t:e})}var u=t,a=function(){if(oe(o.resolve))return Promise.resolve(o.resolve(o)).then(function(e){t=(o=e).tempId})}();return a&&a.then?a.then(i):i()});return o&&o.then?o.then(n):n()}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)&&null==e.message.refBlock)return Promise.resolve(o.latestBlock()).then(function(n){e.message.refBlock=n.id})}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=Object.values(e.accounts).find(function(e){return e.role.proposer});r.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(r){e.accounts[n.tempId].sequenceNum=r})}();if(o&&o.then)return o.then(function(){})}}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(function(e){try{var n=function(){if(t.isTransaction(e)){var n=new Set(e.authorizations);n.add(e.proposer),n.delete(e.payer),n=Array.from(n);var r=new Set([e.payer]);r=Array.from(r);var o=(i=ue(e),F(z(i)));return Promise.resolve(Promise.all(n.map(ie(e,o)))).then(function(){var t=function(e){return F(function(e){return function(e){V.forEach(function(n){return X(e,n)}),e.payloadSigs.forEach(function(e,n){W.forEach(function(r){return X(e,r,"payloadSigs",n)})})}(e),[z(e),U(e)]}(e))}(C({},ue(e),{payloadSigs:n.map(function(n){return e.accounts[n].signature})}));return Promise.resolve(Promise.all(r.map(ie(e,t)))).then(function(){})})}var i}();return Promise.resolve(n&&n.then?n.then(function(){return e}):e)}catch(e){return Promise.reject(e)}}(e)).then(function(){return e})})})})})})})}catch(e){return Promise.reject(e)}});var ae,se,ce=function(e){try{return Promise.resolve(l.send([d.getTransactionStatus(e)]).then(f.decode))}catch(e){return Promise.reject(e)}},le=function(e){return e.status>=4},fe=function(e){return e.status>=3},de=function(e){return e.status>=2},me=((ae={})[c.INIT]=function(e){try{return Promise.resolve(ce(e.self())).then(function(n){le(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(n)})}catch(e){return Promise.reject(e)}},ae[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,c.UPDATED,e.all())},ae[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},ae[c.SNAPSHOT]=function(e,n){try{return n.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ae.POLL=function(e){try{return Promise.resolve(ce(e.self())).then(function(n){var r,t;le(n)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),t=n,JSON.stringify(r)!==JSON.stringify(t)&&e.broadcast(c.UPDATED,n),e.merge(n)})}catch(e){return Promise.reject(e)}},ae),he=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},pe=function(e){return c.spawn(me,he(e))};function ve(e){function n(n){return c.subscriber(he(e),pe,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 c.snapshoter(e,pe)},subscribe:n,onceFinalized:r(de),onceExecuted:r(fe),onceSealed:r(le)}}ve.isUnknown=function(e){return e.status>=0},ve.isPending=function(e){return e.status>=1},ve.isFinalized=de,ve.isExecuted=fe,ve.isSealed=le,ve.isExpired=function(e){return 5===e.status};var ye=function(e){try{var r=setTimeout;return Promise.resolve(n.config().get("fcl.eventPollRate",1e4)).then(function(n){return r(function(){return e.sendSelf("TICK")},n)})}catch(e){return Promise.reject(e)}},ge=((se={}).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(o.latestBlock()).then(function(n){r.call(e,"hwm",n);var t=e.put;return Promise.resolve(ye(e)).then(function(n){t.call(e,"tick",n)})})}return Promise.resolve(o.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(l.send([getEvents(e.self(),n.height,r.height-1)]).then(f.decode)).then(function(n){for(var r,t=x(n);!(r=t()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(ye(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)}},se[c.SUBSCRIBE]=function(e,n){try{var r=function(){e.subscribe(n.from)},t=function(){if(!e.hasSubs()){var n=e.put;return Promise.resolve(ye(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)}},se[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},se),be=function(e){return c.spawn(ge,e)},Pe={"@type":"Service","@vsn":"1.0.0"},ke={"@type":"Identity","@vsn":"1.0.0"},we={"@type":"USER","@vsn":"1.0.0"},Ee={"@type":"PollingResponse","@vsn":"1.0.0"};function Se(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({old:e},Pe,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function Ie(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var je={"back-channel-rpc":Ie,"pre-authz":function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Pe,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:C({},ke,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},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}})}},frame:Se};function Ae(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function Be(e,n){return void 0===e&&(e=[]),e.find(function(e){return e.type===n})}var Oe=function(e,n){return null==n?"'"+e+"'":"'"+e+"' ("+n+")"},Ce=function(e,n){return"Missing "+Oe(e,n)+" in Composite Signature."},Re=function(e,n){return Oe(e,n)+" in Composit Signature did not match the requested "+e+"."};function xe(e){var n=new URL(e.endpoint);if(null!=e.params)for(var r=0,t=Object.entries(e.params||{});r<t.length;r++){var o=t[r];n.searchParams.append(o[0],o[1])}return n}function Te(e,n){void 0===n&&(n={});var r=n.method||"POST",t="GET"===r?void 0:JSON.stringify(n.data||e.data||{});return fetch(xe(e),{method:r,headers:C({},e.headers||{},n.headers||{},{"Content-Type":"application/json"}),body:t}).then(function(e){return e.json()})}function Le(e){if(null==e)return null;switch(e["@vsn"]){case"1.0.0":return e;default:return C({},Ee,{status:e.status,reason:e.reason,data:e.compositeSignature||{},updates:Ie(e.authorizationUpdates),local:Se((e.local||[])[0])})}}var Ne="FCL_IFRAME",Fe=function(){},ze=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Ue(e,n){if(void 0===n&&(n={}),console.log("FRAME",{service:e,opts:n}),null==e)return e;var t=n.onClose||Fe,o=n.onMessage||Fe,i=n.onReady||Fe;window.addEventListener("message",c);var u=function(e){r.invariant(!document.getElementById(Ne),"Attempt at triggering multiple Frames",{src:e});var n=document.createElement("iframe");return n.src=e,n.id=Ne,n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(n),[n,function(){document.getElementById(Ne)&&document.getElementById(Ne).remove()}]}(xe(e)),a=u[0],s=u[1];return{send:f,close:l};function c(e){try{if(ze.has(e.data.type))return;console.log("FRAME MESSAGE!!",e),"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:f,close:l}),o(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:f,close:l}),"FCL::CHALLENGE::CANCEL"===e.data.type&&l(),"FCL::CANCEL"===e.data.type&&l()}catch(e){console.error("Frame Callback Error",e),l()}}function l(){try{window.removeEventListener("message",c),s(),t()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{console.log("SEND",e),a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(n){console.error("Frame Send Error",e,n)}}}var qe,Me={"HTTP/GET":"GET","HTTP/POST":"POST"},De=function(e){return r.invariant(Me[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),Me[e.method]},_e={"HTTP/POST":function(e,n){try{return n.data=e.data,Promise.resolve(Te(e,{data:n}).then(Le)).then(function(e){var n=!0,t=Ue(e.local,{onClose:function(){n=!1}}).close;return function e(n,t){void 0===t&&(t=function(){return!0});try{if(r.invariant(n,"Missing Polling Service",{service:n}),!t())throw new Error("Externally Halted");return Promise.resolve(Te(n,{method:De(n)}).then(Le)).then(function(n){switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error("Declined: "+(n.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(n.updates,t)})}})}catch(e){return Promise.reject(e)}}(e.updates,function(){return n}).then(function(e){return t(),e}).catch(function(e){throw console.error(e),t(),e})})}catch(e){return Promise.reject(e)}},"IFRAME/RPC":function(e,n){return new Promise(function(r,t){var o=h.uid();n.data=e.data,Ue(e,{onReady:function(r,t){var i=t.send;console.log("FCL[IFRAME/RPC] onReady"),i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[n,e.params]})},onMessage:function(e,n){var i=n.close;if(console.log("FCL[IFRAME/RPC] onMessage",e),"2.0"===e.data.jsonrpc&&e.data.id===o){console.log("FCL[IFRAME/RPC] A",data.result);var u=Le(data.result);switch(console.log("FCL[IFRAME/RPC] B",u),u.status){case"APPROVED":console.log("FCL[IFRAME/RPC] APPROVED",u.data),r(u.data);break;case"DECLINED":console.log("FCL[IFRAME/RPC] DECLINED",u),t("Declined: "+(u.reason||"No reason supplied"));break;default:console.error("Invalid IFRAME/RPC Response Status",u),t("Declined: No reason supplied")}i()}}})})}};function He(e,n,r){if(!e.s){if(r instanceof Je){if(!r.s)return void(r.o=He.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(He.bind(null,e,n),He.bind(null,e,2));e.s=n,e.v=r;var t=e.o;t&&t(e)}}var Ge=function(e){try{return on(),Promise.resolve(Ve()).then(function(n){Be(n.services,"authn");var t=Be(n.services,"authz");return Be(n.services,"pre-authz"),C({},e,{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return console.log("Signable",e),Promise.resolve(function(e,n){try{return Promise.resolve(_e[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 t={compSig:e,authz:n};r.invariant(e.addr,Ce("addr","Address"),t),r.invariant(null!=e.keyId,Ce("keyId"),t),r.invariant(e.signature,Ce("signature"),t),r.invariant(e.keyId===n.identity.keyId,Re("keyId"),t),r.invariant(i.sansPrefix(e.addr)===i.sansPrefix(n.identity.address),Re("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)}},Je=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{He(t,1,i(this.v))}catch(e){He(t,2,e)}return t}return this}return this.o=function(e){try{var o=e.v;1&e.s?He(t,1,n?n(o):o):r?He(t,1,r(o)):He(t,2,o)}catch(e){He(t,2,e)}},t},e}();function Ke(e){return e instanceof Je&&1&e.s}var Ve=function(){try{return Promise.resolve(new Promise(function(e){try{return on(),Promise.resolve(cn()).then(function(r){return r.loggedIn&&un(r)?e(r):Promise.resolve(n.config().get("challenge.handshake")).then(function(n){var r,t,o,u=(r={handshake:n,l6n:window.location.origin},t=r.l6n,(o=new URL(r.handshake)).searchParams.append("l6n",t),function(e){if(!document.getElementById("FCL_IFRAME")){var n=document.createElement("iframe");return n.src=e,n.id="FCL_IFRAME",n.allow="usb *",n.frameBorder="0",n.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n ",document.body.append(n),[n,function(){document.getElementById("FCL_IFRAME")&&document.getElementById("FCL_IFRAME").remove()}]}}(o.href))[1];window.addEventListener("message",function n(r){var t=r.data;try{return t.type===Qe||t.type===Ze?(u(),window.removeEventListener("message",n),Promise.resolve()):t.type!==$e?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 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=x(e.authorizations);!(r=t()).done;)n.push(C({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&n.push(C({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,u=(t=n,o=r,void 0===t&&(t=[]),void 0===o&&(o=[]),[].concat(t,o)).map(function(n){return function(e,n){try{return je[e.type](e,n)}catch(n){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,n),e}}(n,e)}),a=function(e,n){return n.find(function(e){return"authn"===e.type})}(0,u);return C({},we,{addr:i.withPrefix(e.addr),cid:Ae(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t)).then(function(n){return c.send(We,Ye,n),Promise.resolve(cn()).then(function(n){e(n)})}))}catch(e){return Promise.reject(e)}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},We="CURRENT_USER",Xe="CURRENT_USER/UPDATED",Ye="SET_CURRENT_USER",Ze="FCL::CANCEL",$e="FCL::CHALLENGE::RESPONSE",Qe="FCL::CHALLENGE::CANCEL",en='{\n "@type": "User",\n "@vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',nn=function(e){try{return sessionStorage.setItem(We,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},rn=function(){return n.config().get("persistSession",!0)},tn=((qe={})[c.INIT]=function(e){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){var r=function(){if(n)return Promise.resolve(function(){try{var e=JSON.parse(en),n=JSON.parse(sessionStorage.getItem(We));return null!=n&&e["@vsn"]!==n["@vsn"]?(sessionStorage.removeItem(We),Promise.resolve(e)):Promise.resolve(n||e)}catch(e){return Promise.reject(e)}}()).then(function(n){un(n)&&e.merge(n)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},qe[c.SUBSCRIBE]=function(e,n){e.subscribe(n.from),e.send(n.from,Xe,C({},e.all()))},qe[c.UNSUBSCRIBE]=function(e,n){e.unsubscribe(n.from)},qe.SNAPSHOT=function(e,n){try{return n.reply(C({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},qe[Ye]=function(e,n,r){try{return e.merge(r),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Xe,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe.DEL_CURRENT_USER=function(e,n){try{return e.merge(JSON.parse(en)),Promise.resolve(rn()).then(function(n){n&&nn(e.all()),e.broadcast(Xe,C({},e.all()))})}catch(e){return Promise.reject(e)}},qe),on=function(){return c.spawn(tn,We)};function un(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function an(){on(),c.send(We,"DEL_CURRENT_USER")}function sn(e){on();var n=c.spawn(function(n){try{var r;return n.send(We,c.SUBSCRIBE),Promise.resolve(function(e,n,r){for(var t;;){var o=e();if(Ke(o)&&(o=o.v),!o)return i;if(o.then){t=0;break}var i=r();if(i&&i.then){if(!Ke(i)){t=1;break}i=i.s}}var u=new Je,a=He.bind(null,u,2);return(0===t?o.then(c):1===t?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):He(u,1,i)})).then(void 0,a),u;function s(n){i=n;do{if(!(o=e())||Ke(o)&&!o.v)return void He(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Ke(i=r())&&(i=i.v)}while(!i||!i.then);i.then(s).then(void 0,a)}function c(e){e?(i=r())&&i.then?i.then(s).then(void 0,a):s(i):He(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(t){if("@EXIT"===t.tag)return n.send(We,c.UNSUBSCRIBE),void(r=1);e(t.data)})}))}catch(e){return Promise.reject(e)}});return function(){return c.send(n,"@EXIT")}}function cn(){return on(),c.send(We,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ln=function(){return{authenticate:Ve,unauthenticate:an,authorization:Ge,subscribe:sn,snapshot:cn}},fn=ln().authorization;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return n.config}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"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 l.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return f.decode}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return d.getTransactionStatus}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return m.getEvents}}),Object.defineProperty(e,"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 E.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return E.authorizations}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return S.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return S.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 A.limit}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return B.ref}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return O.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return O.params}}),e.VERSION="0.0.67-alpha.9",e.authenticate=function(){return ln().authenticate()},e.authz=fn,e.currentUser=ln,e.events=function(e){return{subscribe:function(n){return c.subscriber(e,be,n)}}},e.logIn=function(){return ln().authenticate()},e.reauthenticate=function(){ln().unauthenticate(),ln().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{var r=function(){return Promise.resolve(s.resolve(n)(e)).then(JSON.stringify)},o=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(n){e=n})}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}},e.signUp=function(){return ln().authenticate()},e.tx=ve,e.unauthenticate=function(){return ln().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.67-alpha.8", | ||
"version": "0.0.67-alpha.9", | ||
"description": "Flow Client Library", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
424942