@onflow/fcl
Advanced tools
Comparing version 0.0.68-alpha.21 to 0.0.68-alpha.22
@@ -5,2 +5,6 @@ ## Unreleased | ||
## 0.0.69-alpha.22 - 2021-04-26 | ||
- 2021-04-26 -- Fixed an issue where `config()` was being called as `fcl.config()`, but `fcl` wanst available. | ||
## 0.0.68-alpha.21 - 2021-04-21 | ||
@@ -7,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/config"),t=require("@onflow/sdk"),r=require("@onflow/util-invariant"),n=require("@onflow/types"),o=require("@onflow/util-actor"),i=require("@onflow/util-address"),u=require("@onflow/rlp"),a=require("@onflow/util-uid"),s=require("@onflow/util-template");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e.config().put("sdk.resolve",t.resolve);var c,f,l=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},d=function(e){return e.status>=4},p=function(e){return e.status>=3},h=function(e){return e.status>=2},m=((c={})[o.INIT]=function(e){try{return Promise.resolve(l(e.self())).then(function(t){d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},c[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,o.UPDATED,e.all())},c[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},c[o.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},c.POLL=function(e){try{return Promise.resolve(l(e.self())).then(function(t){var r,n;d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(o.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},c),v=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},y=function(e){return o.spawn(m,v(e))};function g(e){function t(t){return o.subscriber(v(e),y,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return o.snapshoter(e,y)},subscribe:t,onceFinalized:r(h),onceExecuted:r(p),onceSealed:r(d)}}function P(){return(P=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function E(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return b(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)?b(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}g.isUnknown=function(e){return e.status>=0},g.isPending=function(e){return e.status>=1},g.isFinalized=h,g.isExecuted=p,g.isSealed=d,g.isExpired=function(e){return 5===e.status};var x=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},j=((f={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(t.latestBlock()).then(function(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(x(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(t.send([getEvents(e.self(),r.height,n.height-1)]).then(t.decode)).then(function(t){for(var r,n=E(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(x(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},f[o.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(x(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},f[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},f),O=function(e){return o.spawn(j,e)},S={f_type:"Service",f_vsn:"1.0.0"},w={f_type:"Identity",f_vsn:"1.0.0"},R={f_type:"USER",f_vsn:"1.0.0"},I={f_type:"PollingResponse",f_vsn:"1.0.0"},k={f_type:"CompositeSignature",f_vsn:"1.0.0"};function T(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({old:e},S,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var A={"back-channel-rpc":C,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},w,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},w,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{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:T,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function B(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function N(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function U(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function _(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(U(e),{method:r,headers:P({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function L(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},I,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:C(e.authorizationUpdates),local:T((e.local||[])[0])})}}function D(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},k,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var z="FCL_IFRAME",F=function(){},H=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function q(e,t){if(void 0===t&&(t={}),null==e)return{send:F,close:F};var n=t.onClose||F,o=t.onMessage||F,i=t.onReady||F,u=t.onResponse||F;window.addEventListener("message",f);var a=function(e){r.invariant(!document.getElementById(z),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=z,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,function(){document.getElementById(z)&&document.getElementById(z).remove()}]}(U(e)),s=a[0],c=a[1];return{send:d,close:l};function f(e){try{if("object"!=typeof e.data)return;if(H.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:l}),o(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:d,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",f),c(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var M,J={"HTTP/GET":"GET","HTTP/POST":"POST"},G=function(e){return r.invariant(J[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),J[e.method]},V=function(e,t){try{return t.data=e.data,Promise.resolve(_(e,{data:t}).then(L)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,o=q(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(r.invariant(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(_(t,{method:G(t)}).then(L)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return o(),D(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Y=function(e,t){try{try{return Promise.resolve(Z[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},Z={"HTTP/RPC":V,"HTTP/POST":V,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=a.uid();t.data=e.data,q(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=L(e.data.result);switch(u.status){case"APPROVED":r(D(u.data)),i();break;case"DECLINED":n("Declined: "+(u.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function K(e,t,r){if(!e.s){if(r instanceof W){if(!r.s)return void(r.o=K.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(K.bind(null,e,t),K.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var X=function(e){try{return se(),Promise.resolve(Q()).then(function(t){var r=N(t.services,"authz"),n=N(t.services,"pre-authz");return P({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Y(n,t)).then(le)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Y(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},W=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{K(n,1,i(this.v))}catch(e){K(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?K(n,1,t?t(o):o):r?K(n,1,r(o)):K(n,2,o)}catch(e){K(n,2,e)}},n},e}();function $(e){return e instanceof W&&1&e.s}var Q=function(){try{return Promise.resolve(new Promise(function(t,r){try{return se(),Promise.resolve(pe()).then(function(r){return r.loggedIn&&ce(r)?t(r):Promise.resolve(e.config().get("discovery.wallet")).then(function(r){function n(e){q({endpoint:e},{onReady:function(e,t){var r=t.send;try{return Promise.resolve(ee(/^service\./)).then(function(e){return Promise.resolve(ee(/^app\.detail\./)).then(function(t){r({type:"FCL:AUTHN:CONFIG",services:e,app:t})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(pe()).then(function(e){t(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{return Promise.resolve(function(e){try{var t=(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,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=E(e.authorizations);!(r=n()).done;)t.push(P({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(P({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,u=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return function(e,t){try{return A[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,u);return P({},R,{addr:i.withPrefix(e.addr),cid:B(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return o.send(te,ne,e),Promise.resolve(pe()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})}return r?n(r):Promise.resolve(e.config().get("challenge.handshake")).then(n)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ee=function(e){try{return Promise.resolve(fcl.config().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var r=t[1];return[t[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}},te="CURRENT_USER",re="CURRENT_USER/UPDATED",ne="SET_CURRENT_USER",oe='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ie=function(e){try{return sessionStorage.setItem(te,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ue=function(){return e.config().get("persistSession",!0)},ae=((M={})[o.INIT]=function(e){try{return e.merge(JSON.parse(oe)),Promise.resolve(ue()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(oe),t=JSON.parse(sessionStorage.getItem(te));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(te),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){ce(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},M[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,re,P({},e.all()))},M[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},M.SNAPSHOT=function(e,t){try{return t.reply(P({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},M[ne]=function(e,t,r){try{return e.merge(r),Promise.resolve(ue()).then(function(t){t&&ie(e.all()),e.broadcast(re,P({},e.all()))})}catch(e){return Promise.reject(e)}},M.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(oe)),Promise.resolve(ue()).then(function(t){t&&ie(e.all()),e.broadcast(re,P({},e.all()))})}catch(e){return Promise.reject(e)}},M),se=function(){return o.spawn(ae,te)};function ce(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function fe(){se(),o.send(te,"DEL_CURRENT_USER")}function le(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=E(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=E(t.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Y(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function de(e){se();var t=o.spawn(function(t){try{var r;return t.send(te,o.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if($(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!$(i)){n=1;break}i=i.s}}var u=new W,a=K.bind(null,u,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):K(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||$(o)&&!o.v)return void K(u,1,i);if(o.then)return void o.then(c).then(void 0,a);$(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):K(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(t.receive()).then(function(n){if("@EXIT"===n.tag)return t.send(te,o.UNSUBSCRIBE),void(r=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(t,"@EXIT")}}function pe(){return se(),o.send(te,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var he=function(){return{authenticate:Q,unauthenticate:fe,authorization:X,subscribe:de,snapshot:pe}},me=he().authorization,ve=n;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return t.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return s.template}}),exports.VERSION="0.0.68-alpha.21",exports.authenticate=function(){return he().authenticate()},exports.authz=me,exports.currentUser=he,exports.events=function(e){return{subscribe:function(t){return o.subscriber(e,O,t)}}},exports.logIn=function(){return he().authenticate()},exports.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(null!=typeof e.cadence,"query({ cadence }) -- cadence is required"),r.invariant(function(e){return"string"==typeof e}(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return t.send([t.script(e.cadence),t.args((r=e.args||[],"function"==typeof r?r(t.arg,n):[])),e.limit&&"number"==typeof e.limit&&t.limit(e.limit)]).then(t.decode);var r})}catch(e){return Promise.reject(e)}},exports.reauthenticate=function(){return he().unauthenticate(),he().authenticate()},exports.serialize=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e.config().get("sdk.resolve",n.resolve||t.resolve(n))).then(function(e){function n(){return Promise.resolve(e(r)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(r))return Promise.resolve(t.pipe(t.interaction(),r)).then(function(e){r=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return he().authenticate()},exports.t=ve,exports.tx=g,exports.unauthenticate=function(){return he().unauthenticate()}; | ||
var e=require("@onflow/config"),t=require("@onflow/sdk"),r=require("@onflow/util-invariant"),n=require("@onflow/types"),o=require("@onflow/util-actor"),i=require("@onflow/util-address"),u=require("@onflow/rlp"),a=require("@onflow/util-uid"),s=require("@onflow/util-template");e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e.config().put("sdk.resolve",t.resolve);var c,f,l=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},d=function(e){return e.status>=4},p=function(e){return e.status>=3},h=function(e){return e.status>=2},m=((c={})[o.INIT]=function(e){try{return Promise.resolve(l(e.self())).then(function(t){d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},c[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,o.UPDATED,e.all())},c[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},c[o.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},c.POLL=function(e){try{return Promise.resolve(l(e.self())).then(function(t){var r,n;d(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(o.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},c),v=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},y=function(e){return o.spawn(m,v(e))};function g(e){function t(t){return o.subscriber(v(e),y,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return o.snapshoter(e,y)},subscribe:t,onceFinalized:r(h),onceExecuted:r(p),onceSealed:r(d)}}function P(){return(P=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function E(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return b(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)?b(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}g.isUnknown=function(e){return e.status>=0},g.isPending=function(e){return e.status>=1},g.isFinalized=h,g.isExecuted=p,g.isSealed=d,g.isExpired=function(e){return 5===e.status};var x=function(t){try{var r=setTimeout;return Promise.resolve(e.config().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},j=((f={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var r=e.get("hwm"),n=function(){if(null==r){var n=e.put;return Promise.resolve(t.latestBlock()).then(function(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(x(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(n){return e.put("hwm",n),Promise.resolve(t.send([getEvents(e.self(),r.height,n.height-1)]).then(t.decode)).then(function(t){for(var r,n=E(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(x(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},f[o.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(x(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},f[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},f),O=function(e){return o.spawn(j,e)},S={f_type:"Service",f_vsn:"1.0.0"},w={f_type:"Identity",f_vsn:"1.0.0"},R={f_type:"USER",f_vsn:"1.0.0"},I={f_type:"PollingResponse",f_vsn:"1.0.0"},k={f_type:"CompositeSignature",f_vsn:"1.0.0"};function T(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({old:e},S,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var A={"back-channel-rpc":C,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},w,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},w,{address:i.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},S,{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:T,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function B(e){return u.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function N(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function U(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function _(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(U(e),{method:r,headers:P({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function L(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},I,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:C(e.authorizationUpdates),local:T((e.local||[])[0])})}}function D(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},k,{addr:i.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var z="FCL_IFRAME",F=function(){},H=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function q(e,t){if(void 0===t&&(t={}),null==e)return{send:F,close:F};var n=t.onClose||F,o=t.onMessage||F,i=t.onReady||F,u=t.onResponse||F;window.addEventListener("message",f);var a=function(e){r.invariant(!document.getElementById(z),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=z,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,function(){document.getElementById(z)&&document.getElementById(z).remove()}]}(U(e)),s=a[0],c=a[1];return{send:d,close:l};function f(e){try{if("object"!=typeof e.data)return;if(H.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:l}),o(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:d,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",f),c(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var M,J={"HTTP/GET":"GET","HTTP/POST":"POST"},G=function(e){return r.invariant(J[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),J[e.method]},V=function(e,t){try{return t.data=e.data,Promise.resolve(_(e,{data:t}).then(L)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,o=q(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(r.invariant(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(_(t,{method:G(t)}).then(L)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return o(),D(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Y=function(e,t){try{try{return Promise.resolve(Z[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},Z={"HTTP/RPC":V,"HTTP/POST":V,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=a.uid();t.data=e.data,q(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=L(e.data.result);switch(u.status){case"APPROVED":r(D(u.data)),i();break;case"DECLINED":n("Declined: "+(u.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function K(e,t,r){if(!e.s){if(r instanceof W){if(!r.s)return void(r.o=K.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(K.bind(null,e,t),K.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var X=function(e){try{return se(),Promise.resolve(Q()).then(function(t){var r=N(t.services,"authz"),n=N(t.services,"pre-authz");return P({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Y(n,t)).then(le)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:i.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Y(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},W=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{K(n,1,i(this.v))}catch(e){K(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?K(n,1,t?t(o):o):r?K(n,1,r(o)):K(n,2,o)}catch(e){K(n,2,e)}},n},e}();function $(e){return e instanceof W&&1&e.s}var Q=function(){try{return Promise.resolve(new Promise(function(t,r){try{return se(),Promise.resolve(pe()).then(function(r){return r.loggedIn&&ce(r)?t(r):Promise.resolve(e.config().get("discovery.wallet")).then(function(r){function n(e){q({endpoint:e},{onReady:function(e,t){var r=t.send;try{return Promise.resolve(ee(/^service\./)).then(function(e){return Promise.resolve(ee(/^app\.detail\./)).then(function(t){r({type:"FCL:AUTHN:CONFIG",services:e,app:t})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(pe()).then(function(e){t(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{return Promise.resolve(function(e){try{var t=(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,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=E(e.authorizations);!(r=n()).done;)t.push(P({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(P({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,u=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return function(e,t){try{return A[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,u);return P({},R,{addr:i.withPrefix(e.addr),cid:B(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return o.send(te,ne,e),Promise.resolve(pe()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})}return r?n(r):Promise.resolve(e.config().get("challenge.handshake")).then(n)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ee=function(t){try{return Promise.resolve(e.config().where(t)).then(function(e){return Object.fromEntries(Object.entries(e).map(function(e){var r=e[1];return[e[0].replace(t,""),r]}))})}catch(e){return Promise.reject(e)}},te="CURRENT_USER",re="CURRENT_USER/UPDATED",ne="SET_CURRENT_USER",oe='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ie=function(e){try{return sessionStorage.setItem(te,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ue=function(){return e.config().get("persistSession",!0)},ae=((M={})[o.INIT]=function(e){try{return e.merge(JSON.parse(oe)),Promise.resolve(ue()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(oe),t=JSON.parse(sessionStorage.getItem(te));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(te),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){ce(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},M[o.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,re,P({},e.all()))},M[o.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},M.SNAPSHOT=function(e,t){try{return t.reply(P({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},M[ne]=function(e,t,r){try{return e.merge(r),Promise.resolve(ue()).then(function(t){t&&ie(e.all()),e.broadcast(re,P({},e.all()))})}catch(e){return Promise.reject(e)}},M.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(oe)),Promise.resolve(ue()).then(function(t){t&&ie(e.all()),e.broadcast(re,P({},e.all()))})}catch(e){return Promise.reject(e)}},M),se=function(){return o.spawn(ae,te)};function ce(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function fe(){se(),o.send(te,"DEL_CURRENT_USER")}function le(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=E(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=E(t.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return Y(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function de(e){se();var t=o.spawn(function(t){try{var r;return t.send(te,o.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if($(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!$(i)){n=1;break}i=i.s}}var u=new W,a=K.bind(null,u,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):K(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||$(o)&&!o.v)return void K(u,1,i);if(o.then)return void o.then(c).then(void 0,a);$(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):K(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(t.receive()).then(function(n){if("@EXIT"===n.tag)return t.send(te,o.UNSUBSCRIBE),void(r=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return o.send(t,"@EXIT")}}function pe(){return se(),o.send(te,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var he=function(){return{authenticate:Q,unauthenticate:fe,authorization:X,subscribe:de,snapshot:pe}},me=he().authorization,ve=n;Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return t.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return i.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return i.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return i.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return s.template}}),exports.VERSION="0.0.68-alpha.22",exports.authenticate=function(){return he().authenticate()},exports.authz=me,exports.currentUser=he,exports.events=function(e){return{subscribe:function(t){return o.subscriber(e,O,t)}}},exports.logIn=function(){return he().authenticate()},exports.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(null!=typeof e.cadence,"query({ cadence }) -- cadence is required"),r.invariant(function(e){return"string"==typeof e}(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return t.send([t.script(e.cadence),t.args((r=e.args||[],"function"==typeof r?r(t.arg,n):[])),e.limit&&"number"==typeof e.limit&&t.limit(e.limit)]).then(t.decode);var r})}catch(e){return Promise.reject(e)}},exports.reauthenticate=function(){return he().unauthenticate(),he().authenticate()},exports.serialize=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e.config().get("sdk.resolve",n.resolve||t.resolve(n))).then(function(e){function n(){return Promise.resolve(e(r)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(r))return Promise.resolve(t.pipe(t.interaction(),r)).then(function(e){r=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(){return he().authenticate()},exports.t=ve,exports.tx=g,exports.unauthenticate=function(){return he().unauthenticate()}; | ||
//# sourceMappingURL=fcl.js.map |
@@ -1,2 +0,2 @@ | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,send as n,script as a,args as r,limit as s,decode as o,arg as i,pipe as c,interaction as u,getTransactionStatus as d,latestBlock as l}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{invariant as p}from"@onflow/util-invariant";import*as f from"@onflow/types";import{subscriber as y,spawn as h,snapshoter as m,INIT as g,SUBSCRIBE as w,UPDATED as E,UNSUBSCRIBE as v,SNAPSHOT as R,send as S}from"@onflow/util-actor";import{withPrefix as b,sansPrefix as P}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as T}from"@onflow/rlp";import{uid as I}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);const C="0.0.68-alpha.21";async function k(e={}){return await async function(e){p(null!=typeof e.cadence,"query({ cadence }) -- cadence is required"),p((e=>"string"==typeof e)(e.cadence),"query({ cadence }) -- cadence must be a string")}(e),n([a(e.cadence),r((t=e.args||[],"function"==typeof t?t(i,f):[])),e.limit&&"number"==typeof e.limit&&s(e.limit)]).then(o);var t}const A=async(n=[],a={})=>{const r=await e().get("sdk.resolve",a.resolve||t(a));return Array.isArray(n)&&(n=await c(u(),n)),JSON.stringify(await r(n),null,2)},N=async e=>n([d(e)]).then(o),O=e=>e.status>=4,_=e=>e.status>=3,L=e=>e.status>=2,x={[g]:async e=>{const t=await N(e.self());O(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,E,e.all())},[v]:(e,t)=>{e.unsubscribe(t.from)},[R]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await N(e.self());var n,a;O(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(E,t),e.merge(t)}},U=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},D=e=>h(x,U(e));function z(e){function t(t){return y(U(e),D,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,r)=>{const s=t(t=>{t.statusCode&&!a?(r(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return m(e,D)},subscribe:t,onceFinalized:n(L),onceExecuted:n(_),onceSealed:n(O)}}z.isUnknown=e=>e.status>=0,z.isPending=e=>e.status>=1,z.isFinalized=L,z.isExecuted=_,z.isSealed=O,z.isExpired=e=>5===e.status;const F=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),H={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await l()),e.put("tick",await F(e));else{let a=await l();e.put("hwm",a);const r=await n([getEvents(e.self(),t.height,a.height-1)]).then(o);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await F(e))}},[w]:async(e,t)=>{e.hasSubs()||e.put("tick",await F(e)),e.subscribe(t.from)},[v]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},B=e=>h(H,e);function j(e){return{subscribe:t=>y(e,B,t)}}function M(){return(M=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const J={f_type:"Service",f_vsn:"1.0.0"},G={f_type:"Identity",f_vsn:"1.0.0"},q={f_type:"USER",f_vsn:"1.0.0"},Y={f_type:"PollingResponse",f_vsn:"1.0.0"},V={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({old:e},J,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function K(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const X={"back-channel-rpc":K,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},G,{address:b(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},G,{address:b(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:b(e.addr),name:e.name,icon:e.icon}})}},frame:Z,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function W(e){return T([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function $(e=[],t){return e.find(e=>e.type===t)}function Q(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[n,a]of Object.entries(e.params||{}))t.searchParams.append(n,a);return t}function ee(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(Q(e),{method:n,headers:M({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function te(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},Y,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:K(e.authorizationUpdates),local:Z((e.local||[])[0])})}}function ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},V,{addr:P(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const ae="FCL_IFRAME",re=()=>{},se=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function oe(e,t={}){if(null==e)return{send:re,close:re};const n=t.onClose||re,a=t.onMessage||re,r=t.onReady||re,s=t.onResponse||re;window.addEventListener("message",c);const[o,i]=function(e){p(!document.getElementById(ae),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=ae,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(ae)&&document.getElementById(ae).remove()}]}(Q(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(se.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:d,close:u}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:d,close:u}),a(e,{send:d,close:u}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&s(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&r(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(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{o.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const ie={"HTTP/GET":"GET","HTTP/POST":"POST"},ce=e=>(p(ie[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ie[e.method]);async function ue(e,t){t.data=e.data;const n=await ee(e,{data:t}).then(te);if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var a=!0;const{close:e}=oe(n.local,{onClose(){a=!1}});return async function e(t,n=(()=>!0)){if(p(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");const a=await ee(t,{method:ce(t)}).then(te);switch(a.status){case"APPROVED":return a.data;case"DECLINED":throw new Error("Declined: "+(a.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(a.updates,n)}}(n.updates,()=>a).then(t=>(e(),ne(t))).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")}const de={"HTTP/RPC":ue,"HTTP/POST":ue,"IFRAME/RPC":function(e,t){return new Promise((n,a)=>{const r=I();t.data=e.data,oe(e,{onReady(n,{send:a}){try{a({jsonrpc:"2.0",id:r,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose(){a("Declined: Externally Halted")},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==r)return;const s=te(e.data.result);switch(s.status){case"APPROVED":n(ne(s.data)),t();break;case"DECLINED":a("Declined: "+(s.reason||"No reason supplied")),t();break;default:a("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};async function le(e,t){try{return de[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const pe="CURRENT_USER",fe="CURRENT_USER/UPDATED",ye='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',he=async e=>(sessionStorage.setItem(pe,JSON.stringify(e)),e),me=()=>e().get("persistSession",!0),ge={[g]:async e=>{if(e.merge(JSON.parse(ye)),await me()){const t=await(async()=>{const e=JSON.parse(ye),t=JSON.parse(sessionStorage.getItem(pe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(pe),e):t||e})();Ee(t)&&e.merge(t)}},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,fe,M({},e.all()))},[v]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(M({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await me()&&he(e.all()),e.broadcast(fe,M({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(ye)),await me()&&he(e.all()),e.broadcast(fe,M({},e.all()))}},we=()=>h(ge,pe);function Ee(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function ve(e){return Object.fromEntries(Object.entries(await fcl.config().where(e)).map(([t,n])=>[t.replace(e,""),n]))}async function Re(){return new Promise(async(t,n)=>{we();const a=await Te();if(a.loggedIn&&Ee(a))return t(a);oe({endpoint:await e().get("discovery.wallet")||await e().get("challenge.handshake")},{async onReady(e,{send:t}){t({type:"FCL:AUTHN:CONFIG",services:await ve(/^service\./),app:await ve(/^app\.detail\./)})},async onClose(){t(await Te())},async onResponse(e,{close:n}){S(pe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?b(e.addr):null,e.paddr=e.paddr?b(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 a=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(a))return a;const r=[];if(Array.isArray(a.authorizations))for(let e of a.authorizations)r.push(M({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(M({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return X[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 M({},q,{addr:b(e.addr),cid:W(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e.data)),t(await Te()),n()}})})}function Se(){we(),S(pe,"DEL_CURRENT_USER")}async function be(e){we();const t=await Re(),n=$(t.services,"authz"),a=$(t.services,"pre-authz");return M({},e,a?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}))(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])n.push(["PAYER",e]);for(let e of t.authorization||[])n.push(["AUTHORIZER",e]);return n.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>le(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await le(a,t))}:{tempId:"CURRENT_USER",resolve:null,addr:P(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>le(n,e)})}function Pe(e){we();const t=h(async t=>{for(t.send(pe,w);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(pe,v);e(n.data)}});return()=>S(t,"@EXIT")}function Te(){return we(),S(pe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ie=()=>({authenticate:Re,unauthenticate:Se,authorization:be,subscribe:Pe,snapshot:Te}),Ce=()=>Ie().authenticate(),ke=()=>Ie().unauthenticate(),Ae=()=>(Ie().unauthenticate(),Ie().authenticate()),Ne=()=>Ie().authenticate(),Oe=()=>Ie().authenticate(),_e=Ie().authorization,Le=f;export{C as VERSION,Ce as authenticate,_e as authz,Ie as currentUser,j as events,Oe as logIn,k as query,Ae as reauthenticate,A as serialize,Ne as signUp,Le as t,z as tx,ke as unauthenticate}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,send as n,script as a,args as r,limit as s,decode as o,arg as i,pipe as c,interaction as u,getTransactionStatus as d,latestBlock as l}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{invariant as p}from"@onflow/util-invariant";import*as f from"@onflow/types";import{subscriber as y,spawn as h,snapshoter as m,INIT as g,SUBSCRIBE as w,UPDATED as E,UNSUBSCRIBE as v,SNAPSHOT as R,send as S}from"@onflow/util-actor";import{withPrefix as b,sansPrefix as P}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as T}from"@onflow/rlp";import{uid as I}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);const C="0.0.68-alpha.22";async function k(e={}){return await async function(e){p(null!=typeof e.cadence,"query({ cadence }) -- cadence is required"),p((e=>"string"==typeof e)(e.cadence),"query({ cadence }) -- cadence must be a string")}(e),n([a(e.cadence),r((t=e.args||[],"function"==typeof t?t(i,f):[])),e.limit&&"number"==typeof e.limit&&s(e.limit)]).then(o);var t}const A=async(n=[],a={})=>{const r=await e().get("sdk.resolve",a.resolve||t(a));return Array.isArray(n)&&(n=await c(u(),n)),JSON.stringify(await r(n),null,2)},N=async e=>n([d(e)]).then(o),O=e=>e.status>=4,_=e=>e.status>=3,L=e=>e.status>=2,x={[g]:async e=>{const t=await N(e.self());O(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,E,e.all())},[v]:(e,t)=>{e.unsubscribe(t.from)},[R]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await N(e.self());var n,a;O(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(E,t),e.merge(t)}},U=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},D=e=>h(x,U(e));function z(e){function t(t){return y(U(e),D,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,r)=>{const s=t(t=>{t.statusCode&&!a?(r(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return m(e,D)},subscribe:t,onceFinalized:n(L),onceExecuted:n(_),onceSealed:n(O)}}z.isUnknown=e=>e.status>=0,z.isPending=e=>e.status>=1,z.isFinalized=L,z.isExecuted=_,z.isSealed=O,z.isExpired=e=>5===e.status;const F=async t=>setTimeout(()=>t.sendSelf("TICK"),await e().get("fcl.eventPollRate",1e4)),H={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await l()),e.put("tick",await F(e));else{let a=await l();e.put("hwm",a);const r=await n([getEvents(e.self(),t.height,a.height-1)]).then(o);for(let t of r)e.broadcast("UPDATED",t.data);e.put("tick",await F(e))}},[w]:async(e,t)=>{e.hasSubs()||e.put("tick",await F(e)),e.subscribe(t.from)},[v]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},B=e=>h(H,e);function j(e){return{subscribe:t=>y(e,B,t)}}function M(){return(M=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const J={f_type:"Service",f_vsn:"1.0.0"},G={f_type:"Identity",f_vsn:"1.0.0"},q={f_type:"USER",f_vsn:"1.0.0"},Y={f_type:"PollingResponse",f_vsn:"1.0.0"},V={f_type:"CompositeSignature",f_vsn:"1.0.0"};function Z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({old:e},J,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function K(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const X={"back-channel-rpc":K,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},G,{address:b(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},G,{address:b(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},J,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:b(e.addr),name:e.name,icon:e.icon}})}},frame:Z,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function W(e){return T([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function $(e=[],t){return e.find(e=>e.type===t)}function Q(e){const t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(let[n,a]of Object.entries(e.params||{}))t.searchParams.append(n,a);return t}function ee(e,t={}){const n=t.method||"POST",a="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(Q(e),{method:n,headers:M({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function te(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},Y,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:K(e.authorizationUpdates),local:Z((e.local||[])[0])})}}function ne(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},V,{addr:P(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const ae="FCL_IFRAME",re=()=>{},se=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function oe(e,t={}){if(null==e)return{send:re,close:re};const n=t.onClose||re,a=t.onMessage||re,r=t.onReady||re,s=t.onResponse||re;window.addEventListener("message",c);const[o,i]=function(e){p(!document.getElementById(ae),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=ae,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(ae)&&document.getElementById(ae).remove()}]}(Q(e));return{send:d,close:u};function c(e){try{if("object"!=typeof e.data)return;if(se.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:d,close:u}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:d,close:u}),a(e,{send:d,close:u}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&s(e,{send:d,close:u}),"FCL::AUTHZ_READY"===e.data.type&&r(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(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{o.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const ie={"HTTP/GET":"GET","HTTP/POST":"POST"},ce=e=>(p(ie[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),ie[e.method]);async function ue(e,t){t.data=e.data;const n=await ee(e,{data:t}).then(te);if("APPROVED"===n.status)return n.data;if("DECLINED"===n.status)throw new Error("Declined: "+(n.reason||"No reason supplied."));if("PENDING"===n.status){var a=!0;const{close:e}=oe(n.local,{onClose(){a=!1}});return async function e(t,n=(()=>!0)){if(p(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");const a=await ee(t,{method:ce(t)}).then(te);switch(a.status){case"APPROVED":return a.data;case"DECLINED":throw new Error("Declined: "+(a.reason||"No reason supplied."));default:return await new Promise(e=>setTimeout(e,500)),e(a.updates,n)}}(n.updates,()=>a).then(t=>(e(),ne(t))).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:n}),new Error("Auto Decline: Invalid Response")}const de={"HTTP/RPC":ue,"HTTP/POST":ue,"IFRAME/RPC":function(e,t){return new Promise((n,a)=>{const r=I();t.data=e.data,oe(e,{onReady(n,{send:a}){try{a({jsonrpc:"2.0",id:r,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose(){a("Declined: Externally Halted")},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==r)return;const s=te(e.data.result);switch(s.status){case"APPROVED":n(ne(s.data)),t();break;case"DECLINED":a("Declined: "+(s.reason||"No reason supplied")),t();break;default:a("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};async function le(e,t){try{return de[e.method](e,t)}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}const pe="CURRENT_USER",fe="CURRENT_USER/UPDATED",ye='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',he=async e=>(sessionStorage.setItem(pe,JSON.stringify(e)),e),me=()=>e().get("persistSession",!0),ge={[g]:async e=>{if(e.merge(JSON.parse(ye)),await me()){const t=await(async()=>{const e=JSON.parse(ye),t=JSON.parse(sessionStorage.getItem(pe));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(pe),e):t||e})();Ee(t)&&e.merge(t)}},[w]:(e,t)=>{e.subscribe(t.from),e.send(t.from,fe,M({},e.all()))},[v]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(M({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await me()&&he(e.all()),e.broadcast(fe,M({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(ye)),await me()&&he(e.all()),e.broadcast(fe,M({},e.all()))}},we=()=>h(ge,pe);function Ee(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function ve(t){return Object.fromEntries(Object.entries(await e().where(t)).map(([e,n])=>[e.replace(t,""),n]))}async function Re(){return new Promise(async(t,n)=>{we();const a=await Te();if(a.loggedIn&&Ee(a))return t(a);oe({endpoint:await e().get("discovery.wallet")||await e().get("challenge.handshake")},{async onReady(e,{send:t}){t({type:"FCL:AUTHN:CONFIG",services:await ve(/^service\./),app:await ve(/^app\.detail\./)})},async onClose(){t(await Te())},async onResponse(e,{close:n}){S(pe,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?b(e.addr):null,e.paddr=e.paddr?b(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 a=await fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(e=>e.json());if(Array.isArray(a))return a;const r=[];if(Array.isArray(a.authorizations))for(let e of a.authorizations)r.push(M({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(M({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return X[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 M({},q,{addr:b(e.addr),cid:W(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e.data)),t(await Te()),n()}})})}function Se(){we(),S(pe,"DEL_CURRENT_USER")}async function be(e){we();const t=await Re(),n=$(t.services,"authz"),a=$(t.services,"pre-authz");return M({},e,a?{tempId:"CURRENT_USER",resolve:async(e,t)=>function(e){const t=(e=>({f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}))(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(let e of t.payer||[])n.push(["PAYER",e]);for(let e of t.authorization||[])n.push(["AUTHORIZER",e]);return n.map(([e,t])=>({tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:e=>le(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await le(a,t))}:{tempId:"CURRENT_USER",resolve:null,addr:P(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>le(n,e)})}function Pe(e){we();const t=h(async t=>{for(t.send(pe,w);;){const n=await t.receive();if("@EXIT"===n.tag)return void t.send(pe,v);e(n.data)}});return()=>S(t,"@EXIT")}function Te(){return we(),S(pe,"SNAPSHOT",null,{expectReply:!0,timeout:0})}const Ie=()=>({authenticate:Re,unauthenticate:Se,authorization:be,subscribe:Pe,snapshot:Te}),Ce=()=>Ie().authenticate(),ke=()=>Ie().unauthenticate(),Ae=()=>(Ie().unauthenticate(),Ie().authenticate()),Ne=()=>Ie().authenticate(),Oe=()=>Ie().authenticate(),_e=Ie().authorization,Le=f;export{C as VERSION,Ce as authenticate,_e as authz,Ie as currentUser,j as events,Oe as logIn,k as query,Ae as reauthenticate,A as serialize,Ne as signUp,Le as t,z as tx,ke as unauthenticate}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,send as r,script as n,args as o,limit as i,decode as u,arg as a,pipe as s,interaction as c,getTransactionStatus as l,latestBlock as f}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{invariant as d}from"@onflow/util-invariant";import*as h from"@onflow/types";import{INIT as p,SUBSCRIBE as m,UPDATED as v,UNSUBSCRIBE as y,SNAPSHOT as P,subscriber as g,spawn as E,snapshoter as w,send as b}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as R}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as I}from"@onflow/rlp";import{uid as A}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);var T,j,k="0.0.68-alpha.21",C=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return d(O(e.cadence),"query({ cadence }) -- cadence is required"),d(N(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return r([n(e.cadence),o((t=e.args||[],"function"==typeof t?t(a,h):[])),e.limit&&"number"==typeof e.limit&&i(e.limit)]).then(u);var t})}catch(e){return Promise.reject(e)}},O=function(e){return null!=typeof e},N=function(e){return"string"==typeof e},_=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e().get("sdk.resolve",n.resolve||t(n))).then(function(e){function t(){return Promise.resolve(e(r)).then(function(e){return JSON.stringify(e,null,2)})}var n=function(){if(Array.isArray(r))return Promise.resolve(s(c(),r)).then(function(e){r=e})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},x=function(e){try{return Promise.resolve(r([l(e)]).then(u))}catch(e){return Promise.reject(e)}},L=function(e){return e.status>=4},U=function(e){return e.status>=3},D=function(e){return e.status>=2},z=((T={})[p]=function(e){try{return Promise.resolve(x(e.self())).then(function(t){L(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},T[m]=function(e,t){e.subscribe(t.from),e.send(t.from,v,e.all())},T[y]=function(e,t){e.unsubscribe(t.from)},T[P]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},T.POLL=function(e){try{return Promise.resolve(x(e.self())).then(function(t){var r,n;L(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(v,t),e.merge(t)})}catch(e){return Promise.reject(e)}},T),F=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},H=function(e){return E(z,F(e))};function B(e){function t(t){return g(F(e),H,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return w(e,H)},subscribe:t,onceFinalized:r(D),onceExecuted:r(U),onceSealed:r(L)}}function M(){return(M=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function J(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function G(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return J(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)?J(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}B.isUnknown=function(e){return e.status>=0},B.isPending=function(e){return e.status>=1},B.isFinalized=D,B.isExecuted=U,B.isSealed=L,B.isExpired=function(e){return 5===e.status};var q=function(t){try{var r=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Y=((j={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),n=function(){if(null==t){var n=e.put;return Promise.resolve(f()).then(function(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(q(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(f()).then(function(n){return e.put("hwm",n),Promise.resolve(r([getEvents(e.self(),t.height,n.height-1)]).then(u)).then(function(t){for(var r,n=G(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(q(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},j[m]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(q(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},j[y]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},j),V=function(e){return E(Y,e)};function Z(e){return{subscribe:function(t){return g(e,V,t)}}}var K={f_type:"Service",f_vsn:"1.0.0"},X={f_type:"Identity",f_vsn:"1.0.0"},W={f_type:"USER",f_vsn:"1.0.0"},$={f_type:"PollingResponse",f_vsn:"1.0.0"},Q={f_type:"CompositeSignature",f_vsn:"1.0.0"};function ee(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({old:e},K,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function te(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var re={"back-channel-rpc":te,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},X,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},X,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:ee,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function ne(e){return I([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function oe(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function ie(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function ue(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(ie(e),{method:r,headers:M({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function ae(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},$,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:te(e.authorizationUpdates),local:ee((e.local||[])[0])})}}function se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},Q,{addr:R(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ce="FCL_IFRAME",le=function(){},fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function de(e,t){if(void 0===t&&(t={}),null==e)return{send:le,close:le};var r=t.onClose||le,n=t.onMessage||le,o=t.onReady||le,i=t.onResponse||le;window.addEventListener("message",c);var u=function(e){d(!document.getElementById(ce),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=ce,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,function(){document.getElementById(ce)&&document.getElementById(ce).remove()}]}(ie(e)),a=u[0],s=u[1];return{send:f,close:l};function c(e){try{if("object"!=typeof e.data)return;if(fe.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:f,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:f,close:l}),n(e,{send:f,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(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(),r()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var he,pe={"HTTP/GET":"GET","HTTP/POST":"POST"},me=function(e){return d(pe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),pe[e.method]},ve=function(e,t){try{return t.data=e.data,Promise.resolve(ue(e,{data:t}).then(ae)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0,n=de(t.local,{onClose:function(){r=!1}}).close;return function e(t,r){void 0===r&&(r=function(){return!0});try{if(d(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(ue(t,{method:me(t)}).then(ae)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return r}).then(function(e){return n(),se(e)}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},ye=function(e,t){try{try{return Promise.resolve(Pe[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},Pe={"HTTP/RPC":ve,"HTTP/POST":ve,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=A();t.data=e.data,de(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=ae(e.data.result);switch(u.status){case"APPROVED":r(se(u.data)),i();break;case"DECLINED":n("Declined: "+(u.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function ge(e,t,r){if(!e.s){if(r instanceof we){if(!r.s)return void(r.o=ge.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ge.bind(null,e,t),ge.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Ee=function(e){try{return Ne(),Promise.resolve(Se()).then(function(t){var r=oe(t.services,"authz"),n=oe(t.services,"pre-authz");return M({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(ye(n,t)).then(Le)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:R(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(ye(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},we=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{ge(n,1,i(this.v))}catch(e){ge(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ge(n,1,t?t(o):o):r?ge(n,1,r(o)):ge(n,2,o)}catch(e){ge(n,2,e)}},n},e}();function be(e){return e instanceof we&&1&e.s}var Se=function(){try{return Promise.resolve(new Promise(function(t,r){try{return Ne(),Promise.resolve(De()).then(function(r){return r.loggedIn&&_e(r)?t(r):Promise.resolve(e().get("discovery.wallet")).then(function(r){function n(e){de({endpoint:e},{onReady:function(e,t){var r=t.send;try{return Promise.resolve(Re(/^service\./)).then(function(e){return Promise.resolve(Re(/^app\.detail\./)).then(function(t){r({type:"FCL:AUTHN:CONFIG",services:e,app:t})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(De()).then(function(e){t(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=G(e.authorizations);!(r=n()).done;)t.push(M({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(M({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,i=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return function(e,t){try{return re[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),u=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return M({},W,{addr:S(e.addr),cid:ne(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return b(Ie,Te,e),Promise.resolve(De()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})}return r?n(r):Promise.resolve(e().get("challenge.handshake")).then(n)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Re=function(e){try{return Promise.resolve(fcl.config().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var r=t[1];return[t[0].replace(e,""),r]}))})}catch(e){return Promise.reject(e)}},Ie="CURRENT_USER",Ae="CURRENT_USER/UPDATED",Te="SET_CURRENT_USER",je='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ke=function(e){try{return sessionStorage.setItem(Ie,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ce=function(){return e().get("persistSession",!0)},Oe=((he={})[p]=function(e){try{return e.merge(JSON.parse(je)),Promise.resolve(Ce()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(je),t=JSON.parse(sessionStorage.getItem(Ie));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Ie),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){_e(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},he[m]=function(e,t){e.subscribe(t.from),e.send(t.from,Ae,M({},e.all()))},he[y]=function(e,t){e.unsubscribe(t.from)},he.SNAPSHOT=function(e,t){try{return t.reply(M({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},he[Te]=function(e,t,r){try{return e.merge(r),Promise.resolve(Ce()).then(function(t){t&&ke(e.all()),e.broadcast(Ae,M({},e.all()))})}catch(e){return Promise.reject(e)}},he.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(je)),Promise.resolve(Ce()).then(function(t){t&&ke(e.all()),e.broadcast(Ae,M({},e.all()))})}catch(e){return Promise.reject(e)}},he),Ne=function(){return E(Oe,Ie)};function _e(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function xe(){Ne(),b(Ie,"DEL_CURRENT_USER")}function Le(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=G(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=G(t.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return ye(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ue(e){Ne();var t=E(function(t){try{var r;return t.send(Ie,m),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(be(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!be(i)){n=1;break}i=i.s}}var u=new we,a=ge.bind(null,u,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):ge(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||be(o)&&!o.v)return void ge(u,1,i);if(o.then)return void o.then(c).then(void 0,a);be(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):ge(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(t.receive()).then(function(n){if("@EXIT"===n.tag)return t.send(Ie,y),void(r=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return b(t,"@EXIT")}}function De(){return Ne(),b(Ie,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ze=function(){return{authenticate:Se,unauthenticate:xe,authorization:Ee,subscribe:Ue,snapshot:De}},Fe=function(){return ze().authenticate()},He=function(){return ze().unauthenticate()},Be=function(){return ze().unauthenticate(),ze().authenticate()},Me=function(){return ze().authenticate()},Je=function(){return ze().authenticate()},Ge=ze().authorization,qe=h;export{k as VERSION,Fe as authenticate,Ge as authz,ze as currentUser,Z as events,Je as logIn,C as query,Be as reauthenticate,_ as serialize,Me as signUp,qe as t,B as tx,He as unauthenticate}; | ||
import{config as e}from"@onflow/config";export{config}from"@onflow/config";import{resolve as t,send as r,script as n,args as o,limit as i,decode as u,arg as a,pipe as s,interaction as c,getTransactionStatus as l,latestBlock as f}from"@onflow/sdk";export{account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,why}from"@onflow/sdk";import{invariant as d}from"@onflow/util-invariant";import*as h from"@onflow/types";import{INIT as p,SUBSCRIBE as m,UPDATED as v,UNSUBSCRIBE as y,SNAPSHOT as P,subscriber as g,spawn as E,snapshoter as w,send as b}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as R}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import{encode as I}from"@onflow/rlp";import{uid as A}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";e().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),e().put("sdk.resolve",t);var T,j,k="0.0.68-alpha.22",C=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return d(O(e.cadence),"query({ cadence }) -- cadence is required"),d(N(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return r([n(e.cadence),o((t=e.args||[],"function"==typeof t?t(a,h):[])),e.limit&&"number"==typeof e.limit&&i(e.limit)]).then(u);var t})}catch(e){return Promise.reject(e)}},O=function(e){return null!=typeof e},N=function(e){return"string"==typeof e},_=function(r,n){void 0===r&&(r=[]),void 0===n&&(n={});try{return Promise.resolve(e().get("sdk.resolve",n.resolve||t(n))).then(function(e){function t(){return Promise.resolve(e(r)).then(function(e){return JSON.stringify(e,null,2)})}var n=function(){if(Array.isArray(r))return Promise.resolve(s(c(),r)).then(function(e){r=e})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},x=function(e){try{return Promise.resolve(r([l(e)]).then(u))}catch(e){return Promise.reject(e)}},L=function(e){return e.status>=4},U=function(e){return e.status>=3},D=function(e){return e.status>=2},z=((T={})[p]=function(e){try{return Promise.resolve(x(e.self())).then(function(t){L(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},T[m]=function(e,t){e.subscribe(t.from),e.send(t.from,v,e.all())},T[y]=function(e,t){e.unsubscribe(t.from)},T[P]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},T.POLL=function(e){try{return Promise.resolve(x(e.self())).then(function(t){var r,n;L(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),n=t,JSON.stringify(r)!==JSON.stringify(n)&&e.broadcast(v,t),e.merge(t)})}catch(e){return Promise.reject(e)}},T),F=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},H=function(e){return E(z,F(e))};function B(e){function t(t){return g(F(e),H,t)}function r(e){return function(r){void 0===r&&(r={});var n=r.suppress||!1;return new Promise(function(r,o){var i=t(function(t){t.statusCode&&!n?(o(t.errorMessage),i()):e(t)&&(r(t),i())})})}}return{snapshot:function(){return w(e,H)},subscribe:t,onceFinalized:r(D),onceExecuted:r(U),onceSealed:r(L)}}function M(){return(M=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function J(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function G(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return J(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)?J(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}B.isUnknown=function(e){return e.status>=0},B.isPending=function(e){return e.status>=1},B.isFinalized=D,B.isExecuted=U,B.isSealed=L,B.isExpired=function(e){return 5===e.status};var q=function(t){try{var r=setTimeout;return Promise.resolve(e().get("fcl.eventPollRate",1e4)).then(function(e){return r(function(){return t.sendSelf("TICK")},e)})}catch(e){return Promise.reject(e)}},Y=((j={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),n=function(){if(null==t){var n=e.put;return Promise.resolve(f()).then(function(t){n.call(e,"hwm",t);var r=e.put;return Promise.resolve(q(e)).then(function(t){r.call(e,"tick",t)})})}return Promise.resolve(f()).then(function(n){return e.put("hwm",n),Promise.resolve(r([getEvents(e.self(),t.height,n.height-1)]).then(u)).then(function(t){for(var r,n=G(t);!(r=n()).done;)e.broadcast("UPDATED",r.value.data);var o=e.put;return Promise.resolve(q(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},j[m]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(q(e)).then(function(r){t.call(e,"tick",r)})}}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},j[y]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},j),V=function(e){return E(Y,e)};function Z(e){return{subscribe:function(t){return g(e,V,t)}}}var K={f_type:"Service",f_vsn:"1.0.0"},X={f_type:"Identity",f_vsn:"1.0.0"},W={f_type:"USER",f_vsn:"1.0.0"},$={f_type:"PollingResponse",f_vsn:"1.0.0"},Q={f_type:"CompositeSignature",f_vsn:"1.0.0"};function ee(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({old:e},K,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function te(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var re={"back-channel-rpc":te,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},X,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:M({},X,{address:S(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},K,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:ee,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function ne(e){return I([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function oe(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function ie(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var r=0,n=Object.entries(e.params||{});r<n.length;r++){var o=n[r];t.searchParams.append(o[0],o[1])}return t}function ue(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(ie(e),{method:r,headers:M({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function ae(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},$,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:te(e.authorizationUpdates),local:ee((e.local||[])[0])})}}function se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return M({},Q,{addr:R(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var ce="FCL_IFRAME",le=function(){},fe=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function de(e,t){if(void 0===t&&(t={}),null==e)return{send:le,close:le};var r=t.onClose||le,n=t.onMessage||le,o=t.onReady||le,i=t.onResponse||le;window.addEventListener("message",c);var u=function(e){d(!document.getElementById(ce),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=ce,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,function(){document.getElementById(ce)&&document.getElementById(ce).remove()}]}(ie(e)),a=u[0],s=u[1];return{send:f,close:l};function c(e){try{if("object"!=typeof e.data)return;if(fe.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:f,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:f,close:l}),n(e,{send:f,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:f,close:l}),"FCL::AUTHZ_READY"===e.data.type&&o(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(),r()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{a.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var he,pe={"HTTP/GET":"GET","HTTP/POST":"POST"},me=function(e){return d(pe[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),pe[e.method]},ve=function(e,t){try{return t.data=e.data,Promise.resolve(ue(e,{data:t}).then(ae)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var r=!0,n=de(t.local,{onClose:function(){r=!1}}).close;return function e(t,r){void 0===r&&(r=function(){return!0});try{if(d(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(ue(t,{method:me(t)}).then(ae)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,r)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return r}).then(function(e){return n(),se(e)}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},ye=function(e,t){try{try{return Promise.resolve(Pe[e.method](e,t))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t}),r}}catch(e){return Promise.reject(e)}},Pe={"HTTP/RPC":ve,"HTTP/POST":ve,"IFRAME/RPC":function(e,t){return new Promise(function(r,n){var o=A();t.data=e.data,de(e,{onReady:function(r,n){var i=n.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){n("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=ae(e.data.result);switch(u.status){case"APPROVED":r(se(u.data)),i();break;case"DECLINED":n("Declined: "+(u.reason||"No reason supplied")),i();break;default:n("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function ge(e,t,r){if(!e.s){if(r instanceof we){if(!r.s)return void(r.o=ge.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(ge.bind(null,e,t),ge.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Ee=function(e){try{return Ne(),Promise.resolve(Se()).then(function(t){var r=oe(t.services,"authz"),n=oe(t.services,"pre-authz");return M({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(ye(n,t)).then(Le)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:R(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(ye(r,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},we=function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{ge(n,1,i(this.v))}catch(e){ge(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ge(n,1,t?t(o):o):r?ge(n,1,r(o)):ge(n,2,o)}catch(e){ge(n,2,e)}},n},e}();function be(e){return e instanceof we&&1&e.s}var Se=function(){try{return Promise.resolve(new Promise(function(t,r){try{return Ne(),Promise.resolve(De()).then(function(r){return r.loggedIn&&_e(r)?t(r):Promise.resolve(e().get("discovery.wallet")).then(function(r){function n(e){de({endpoint:e},{onReady:function(e,t){var r=t.send;try{return Promise.resolve(Re(/^service\./)).then(function(e){return Promise.resolve(Re(/^app\.detail\./)).then(function(t){r({type:"FCL:AUTHN:CONFIG",services:e,app:t})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(De()).then(function(e){t(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,r){var n=r.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var r=new URL(e);return r.searchParams.append("code",t),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 t=[];if(Array.isArray(e.authorizations))for(var r,n=G(e.authorizations);!(r=n()).done;)t.push(M({type:"authz",keyId:e.keyId},r.value));return null!=e.provider&&t.push(M({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(r){var n,o,i=(n=t,o=r,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(t){return function(e,t){try{return re[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),u=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return M({},W,{addr:S(e.addr),cid:ne(u),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return b(Ie,Te,e),Promise.resolve(De()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})}return r?n(r):Promise.resolve(e().get("challenge.handshake")).then(n)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},Re=function(t){try{return Promise.resolve(e().where(t)).then(function(e){return Object.fromEntries(Object.entries(e).map(function(e){var r=e[1];return[e[0].replace(t,""),r]}))})}catch(e){return Promise.reject(e)}},Ie="CURRENT_USER",Ae="CURRENT_USER/UPDATED",Te="SET_CURRENT_USER",je='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ke=function(e){try{return sessionStorage.setItem(Ie,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Ce=function(){return e().get("persistSession",!0)},Oe=((he={})[p]=function(e){try{return e.merge(JSON.parse(je)),Promise.resolve(Ce()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(je),t=JSON.parse(sessionStorage.getItem(Ie));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(Ie),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){_e(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},he[m]=function(e,t){e.subscribe(t.from),e.send(t.from,Ae,M({},e.all()))},he[y]=function(e,t){e.unsubscribe(t.from)},he.SNAPSHOT=function(e,t){try{return t.reply(M({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},he[Te]=function(e,t,r){try{return e.merge(r),Promise.resolve(Ce()).then(function(t){t&&ke(e.all()),e.broadcast(Ae,M({},e.all()))})}catch(e){return Promise.reject(e)}},he.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(je)),Promise.resolve(Ce()).then(function(t){t&&ke(e.all()),e.broadcast(Ae,M({},e.all()))})}catch(e){return Promise.reject(e)}},he),Ne=function(){return E(Oe,Ie)};function _e(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function xe(){Ne(),b(Ie,"DEL_CURRENT_USER")}function Le(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=G(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=G(t.authorization||[]);!(i=u()).done;)r.push(["AUTHORIZER",i.value]);return r.map(function(e){var t=e[0],r=e[1];return{tempId:[r.identity.address,r.identity.keyId].join("|"),addr:r.identity.address,keyId:r.identity.keyId,signingFunction:function(e){return ye(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function Ue(e){Ne();var t=E(function(t){try{var r;return t.send(Ie,m),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(be(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!be(i)){n=1;break}i=i.s}}var u=new we,a=ge.bind(null,u,2);return(0===n?o.then(c):1===n?i.then(s):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,a):c(o):ge(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||be(o)&&!o.v)return void ge(u,1,i);if(o.then)return void o.then(c).then(void 0,a);be(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):ge(u,1,i)}}(function(){return!r&&1},0,function(){return Promise.resolve(t.receive()).then(function(n){if("@EXIT"===n.tag)return t.send(Ie,y),void(r=1);e(n.data)})}))}catch(e){return Promise.reject(e)}});return function(){return b(t,"@EXIT")}}function De(){return Ne(),b(Ie,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ze=function(){return{authenticate:Se,unauthenticate:xe,authorization:Ee,subscribe:Ue,snapshot:De}},Fe=function(){return ze().authenticate()},He=function(){return ze().unauthenticate()},Be=function(){return ze().unauthenticate(),ze().authenticate()},Me=function(){return ze().authenticate()},Je=function(){return ze().authenticate()},Ge=ze().authorization,qe=h;export{k as VERSION,Fe as authenticate,Ge as authz,ze as currentUser,Z as events,Je as logIn,C as query,Be as reauthenticate,_ as serialize,Me as signUp,qe as t,B as tx,He as unauthenticate}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/config"),require("@onflow/sdk"),require("@onflow/util-invariant"),require("@onflow/types"),require("@onflow/util-actor"),require("@onflow/util-address"),require("@onflow/rlp"),require("@onflow/util-uid"),require("@onflow/util-template")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/sdk","@onflow/util-invariant","@onflow/types","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-uid","@onflow/util-template"],t):t((e=e||self).fcl={},e.config,e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,o,i,u,a,c,s){t.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),t.config().put("sdk.resolve",n.resolve);var f,l,d=function(e){try{return Promise.resolve(n.send([n.getTransactionStatus(e)]).then(n.decode))}catch(e){return Promise.reject(e)}},p=function(e){return e.status>=4},h=function(e){return e.status>=3},m=function(e){return e.status>=2},v=((f={})[i.INIT]=function(e){try{return Promise.resolve(d(e.self())).then(function(t){p(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},f[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,i.UPDATED,e.all())},f[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},f[i.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},f.POLL=function(e){try{return Promise.resolve(d(e.self())).then(function(t){var n,r;p(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(i.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},f),y=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},g=function(e){return i.spawn(v,y(e))};function P(e){function t(t){return i.subscriber(y(e),g,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return i.snapshoter(e,g)},subscribe:t,onceFinalized:n(m),onceExecuted:n(h),onceSealed:n(p)}}function b(){return(b=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)}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return E(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?E(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}P.isUnknown=function(e){return e.status>=0},P.isPending=function(e){return e.status>=1},P.isFinalized=m,P.isExecuted=h,P.isSealed=p,P.isExpired=function(e){return 5===e.status};var w=function(e){try{var n=setTimeout;return Promise.resolve(t.config().get("fcl.eventPollRate",1e4)).then(function(t){return n(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},O=((l={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(n.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(w(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(n.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(n.send([getEvents(e.self(),t.height,r.height-1)]).then(n.decode)).then(function(t){for(var n,r=j(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(w(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l[i.SUBSCRIBE]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(w(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},l[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},l),S=function(e){return i.spawn(O,e)},I={f_type:"Service",f_vsn:"1.0.0"},R={f_type:"Identity",f_vsn:"1.0.0"},k={f_type:"USER",f_vsn:"1.0.0"},T={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({old:e},I,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var N={"back-channel-rpc":B,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},R,{address:u.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},R,{address:u.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:u.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:C,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function U(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function x(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function _(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function L(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(_(e),{method:n,headers:b({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function D(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},T,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:B(e.authorizationUpdates),local:C((e.local||[])[0])})}}function z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},A,{addr:u.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var F="FCL_IFRAME",H=function(){},q=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function M(e,t){if(void 0===t&&(t={}),null==e)return{send:H,close:H};var n=t.onClose||H,o=t.onMessage||H,i=t.onReady||H,u=t.onResponse||H;window.addEventListener("message",f);var a=function(e){r.invariant(!document.getElementById(F),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=F,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,function(){document.getElementById(F)&&document.getElementById(F).remove()}]}(_(e)),c=a[0],s=a[1];return{send:d,close:l};function f(e){try{if("object"!=typeof e.data)return;if(q.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:l}),o(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:d,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",f),s(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{c.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var J,G={"HTTP/GET":"GET","HTTP/POST":"POST"},V=function(e){return r.invariant(G[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),G[e.method]},Y=function(e,t){try{return t.data=e.data,Promise.resolve(L(e,{data:t}).then(D)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,o=M(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(r.invariant(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(L(t,{method:V(t)}).then(D)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return o(),z(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Z=function(e,t){try{try{return Promise.resolve(K[e.method](e,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}catch(e){return Promise.reject(e)}},K={"HTTP/RPC":Y,"HTTP/POST":Y,"IFRAME/RPC":function(e,t){return new Promise(function(n,r){var o=c.uid();t.data=e.data,M(e,{onReady:function(n,r){var i=r.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){r("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=D(e.data.result);switch(u.status){case"APPROVED":n(z(u.data)),i();break;case"DECLINED":r("Declined: "+(u.reason||"No reason supplied")),i();break;default:r("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function X(e,t,n){if(!e.s){if(n instanceof W){if(!n.s)return void(n.o=X.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(X.bind(null,e,t),X.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var $=function(e){try{return se(),Promise.resolve(ee()).then(function(t){var n=x(t.services,"authz"),r=x(t.services,"pre-authz");return b({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Z(r,t)).then(de)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:u.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Z(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},W=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{X(r,1,i(this.v))}catch(e){X(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?X(r,1,t?t(o):o):n?X(r,1,n(o)):X(r,2,o)}catch(e){X(r,2,e)}},r},e}();function Q(e){return e instanceof W&&1&e.s}var ee=function(){try{return Promise.resolve(new Promise(function(e,n){try{return se(),Promise.resolve(he()).then(function(n){return n.loggedIn&&fe(n)?e(n):Promise.resolve(t.config().get("discovery.wallet")).then(function(n){function r(t){M({endpoint:t},{onReady:function(e,t){var n=t.send;try{return Promise.resolve(te(/^service\./)).then(function(e){return Promise.resolve(te(/^app\.detail\./)).then(function(t){n({type:"FCL:AUTHN:CONFIG",services:e,app:t})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(he()).then(function(t){e(t)})}catch(e){return Promise.reject(e)}},onResponse:function(t,n){var r=n.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?u.withPrefix(e.addr):null,e.paddr=e.paddr?u.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var n,r=j(e.authorizations);!(n=r()).done;)t.push(b({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(b({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,o,i=(r=t,o=n,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(t){return function(e,t){try{return N[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return b({},k,{addr:u.withPrefix(e.addr),cid:U(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t.data)).then(function(t){return i.send(ne,oe,t),Promise.resolve(he()).then(function(t){e(t),r()})})}catch(t){return Promise.reject(t)}}})}return n?r(n):Promise.resolve(t.config().get("challenge.handshake")).then(r)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},te=function(e){try{return Promise.resolve(fcl.config().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var n=t[1];return[t[0].replace(e,""),n]}))})}catch(e){return Promise.reject(e)}},ne="CURRENT_USER",re="CURRENT_USER/UPDATED",oe="SET_CURRENT_USER",ie='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ue=function(e){try{return sessionStorage.setItem(ne,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ae=function(){return t.config().get("persistSession",!0)},ce=((J={})[i.INIT]=function(e){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(ne));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(ne),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){fe(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},J[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,re,b({},e.all()))},J[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},J.SNAPSHOT=function(e,t){try{return t.reply(b({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},J[oe]=function(e,t,n){try{return e.merge(n),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(re,b({},e.all()))})}catch(e){return Promise.reject(e)}},J.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(re,b({},e.all()))})}catch(e){return Promise.reject(e)}},J),se=function(){return i.spawn(ce,ne)};function fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function le(){se(),i.send(ne,"DEL_CURRENT_USER")}function de(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=j(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,u=j(t.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return Z(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function pe(e){se();var t=i.spawn(function(t){try{var n;return t.send(ne,i.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(Q(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Q(i)){r=1;break}i=i.s}}var u=new W,a=X.bind(null,u,2);return(0===r?o.then(s):1===r?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(s).then(void 0,a):s(o):X(u,1,i)})).then(void 0,a),u;function c(t){i=t;do{if(!(o=e())||Q(o)&&!o.v)return void X(u,1,i);if(o.then)return void o.then(s).then(void 0,a);Q(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function s(e){e?(i=n())&&i.then?i.then(c).then(void 0,a):c(i):X(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(r){if("@EXIT"===r.tag)return t.send(ne,i.UNSUBSCRIBE),void(n=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return i.send(t,"@EXIT")}}function he(){return se(),i.send(ne,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var me=function(){return{authenticate:ee,unauthenticate:le,authorization:$,subscribe:pe,snapshot:he}},ve=me().authorization,ye=o;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return n.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return n.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return n.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return n.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return n.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return n.build}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return n.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return n.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return n.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return n.getBlockHeader}}),Object.defineProperty(e,"getCollection",{enumerable:!0,get:function(){return n.getCollection}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return n.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return n.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return n.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return n.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return n.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return u.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return u.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return u.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return s.template}}),e.VERSION="0.0.68-alpha.21",e.authenticate=function(){return me().authenticate()},e.authz=ve,e.currentUser=me,e.events=function(e){return{subscribe:function(t){return i.subscriber(e,S,t)}}},e.logIn=function(){return me().authenticate()},e.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(null!=typeof e.cadence,"query({ cadence }) -- cadence is required"),r.invariant(function(e){return"string"==typeof e}(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return n.send([n.script(e.cadence),n.args((t=e.args||[],"function"==typeof t?t(n.arg,o):[])),e.limit&&"number"==typeof e.limit&&n.limit(e.limit)]).then(n.decode);var t})}catch(e){return Promise.reject(e)}},e.reauthenticate=function(){return me().unauthenticate(),me().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.config().get("sdk.resolve",r.resolve||n.resolve(r))).then(function(t){function r(){return Promise.resolve(t(e)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(t){e=t})}();return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return me().authenticate()},e.t=ye,e.tx=P,e.unauthenticate=function(){return me().unauthenticate()}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/config"),require("@onflow/sdk"),require("@onflow/util-invariant"),require("@onflow/types"),require("@onflow/util-actor"),require("@onflow/util-address"),require("@onflow/rlp"),require("@onflow/util-uid"),require("@onflow/util-template")):"function"==typeof define&&define.amd?define(["exports","@onflow/config","@onflow/sdk","@onflow/util-invariant","@onflow/types","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-uid","@onflow/util-template"],t):t((e=e||self).fcl={},e.config,e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,o,i,u,a,c,s){t.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate"),t.config().put("sdk.resolve",n.resolve);var f,l,d=function(e){try{return Promise.resolve(n.send([n.getTransactionStatus(e)]).then(n.decode))}catch(e){return Promise.reject(e)}},p=function(e){return e.status>=4},h=function(e){return e.status>=3},m=function(e){return e.status>=2},v=((f={})[i.INIT]=function(e){try{return Promise.resolve(d(e.self())).then(function(t){p(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},f[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,i.UPDATED,e.all())},f[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},f[i.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},f.POLL=function(e){try{return Promise.resolve(d(e.self())).then(function(t){var n,r;p(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),n=e.all(),r=t,JSON.stringify(n)!==JSON.stringify(r)&&e.broadcast(i.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},f),y=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},g=function(e){return i.spawn(v,y(e))};function P(e){function t(t){return i.subscriber(y(e),g,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,o){var i=t(function(t){t.statusCode&&!r?(o(t.errorMessage),i()):e(t)&&(n(t),i())})})}}return{snapshot:function(){return i.snapshoter(e,g)},subscribe:t,onceFinalized:n(m),onceExecuted:n(h),onceSealed:n(p)}}function b(){return(b=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)}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return E(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?E(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}P.isUnknown=function(e){return e.status>=0},P.isPending=function(e){return e.status>=1},P.isFinalized=m,P.isExecuted=h,P.isSealed=p,P.isExpired=function(e){return 5===e.status};var w=function(e){try{var n=setTimeout;return Promise.resolve(t.config().get("fcl.eventPollRate",1e4)).then(function(t){return n(function(){return e.sendSelf("TICK")},t)})}catch(e){return Promise.reject(e)}},O=((l={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var t=e.get("hwm"),r=function(){if(null==t){var r=e.put;return Promise.resolve(n.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(w(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(n.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(n.send([getEvents(e.self(),t.height,r.height-1)]).then(n.decode)).then(function(t){for(var n,r=j(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var o=e.put;return Promise.resolve(w(e)).then(function(t){o.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},l[i.SUBSCRIBE]=function(e,t){try{var n=function(){e.subscribe(t.from)},r=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(w(e)).then(function(n){t.call(e,"tick",n)})}}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},l[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},l),S=function(e){return i.spawn(O,e)},I={f_type:"Service",f_vsn:"1.0.0"},R={f_type:"Identity",f_vsn:"1.0.0"},k={f_type:"USER",f_vsn:"1.0.0"},T={f_type:"PollingResponse",f_vsn:"1.0.0"},A={f_type:"CompositeSignature",f_vsn:"1.0.0"};function C(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({old:e},I,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var N={"back-channel-rpc":B,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},R,{address:u.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authz:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},R,{address:u.withPrefix(e.addr),keyId:e.keyId}),params:e.params,data:e.data})}},authn:function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:u.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:C,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}}};function U(e){return a.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function x(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function _(e){var t=new URL(e.endpoint);if(t.searchParams.append("l6n",window.location.origin),null!=e.params)for(var n=0,r=Object.entries(e.params||{});n<r.length;n++){var o=r[n];t.searchParams.append(o[0],o[1])}return t}function L(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(_(e),{method:n,headers:b({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function D(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},T,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:B(e.authorizationUpdates),local:C((e.local||[])[0])})}}function z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},A,{addr:u.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}var F="FCL_IFRAME",H=function(){},q=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function M(e,t){if(void 0===t&&(t={}),null==e)return{send:H,close:H};var n=t.onClose||H,o=t.onMessage||H,i=t.onReady||H,u=t.onResponse||H;window.addEventListener("message",f);var a=function(e){r.invariant(!document.getElementById(F),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=F,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,function(){document.getElementById(F)&&document.getElementById(F).remove()}]}(_(e)),c=a[0],s=a[1];return{send:d,close:l};function f(e){try{if("object"!=typeof e.data)return;if(q.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&l(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:d,close:l}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:l}),o(e,{send:d,close:l}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:l}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:d,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",f),s(),n()}catch(e){console.error("Frame Close Error",e)}}function d(e){try{c.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}var J,G={"HTTP/GET":"GET","HTTP/POST":"POST"},V=function(e){return r.invariant(G[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),G[e.method]},Y=function(e,t){try{return t.data=e.data,Promise.resolve(L(e,{data:t}).then(D)).then(function(t){if("APPROVED"===t.status)return t.data;if("DECLINED"===t.status)throw new Error("Declined: "+(t.reason||"No reason supplied."));if("PENDING"===t.status){var n=!0,o=M(t.local,{onClose:function(){n=!1}}).close;return function e(t,n){void 0===n&&(n=function(){return!0});try{if(r.invariant(t,"Missing Polling Service",{service:t}),!n())throw new Error("Externally Halted");return Promise.resolve(L(t,{method:V(t)}).then(D)).then(function(t){switch(t.status){case"APPROVED":return t.data;case"DECLINED":throw new Error("Declined: "+(t.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(t.updates,n)})}})}catch(e){return Promise.reject(e)}}(t.updates,function(){return n}).then(function(e){return o(),z(e)}).catch(function(e){throw console.error(e),o(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},Z=function(e,t){try{try{return Promise.resolve(K[e.method](e,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t}),n}}catch(e){return Promise.reject(e)}},K={"HTTP/RPC":Y,"HTTP/POST":Y,"IFRAME/RPC":function(e,t){return new Promise(function(n,r){var o=c.uid();t.data=e.data,M(e,{onReady:function(n,r){var i=r.send;try{i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onClose:function(){r("Declined: Externally Halted")},onMessage:function(e,t){var i=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=D(e.data.result);switch(u.status){case"APPROVED":n(z(u.data)),i();break;case"DECLINED":r("Declined: "+(u.reason||"No reason supplied")),i();break;default:r("Declined: No reason supplied"),i()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}}})})}};function X(e,t,n){if(!e.s){if(n instanceof W){if(!n.s)return void(n.o=X.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(X.bind(null,e,t),X.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var $=function(e){try{return se(),Promise.resolve(ee()).then(function(t){var n=x(t.services,"authz"),r=x(t.services,"pre-authz");return b({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(Z(r,t)).then(de)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:u.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(Z(n,e))}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},W=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{X(r,1,i(this.v))}catch(e){X(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?X(r,1,t?t(o):o):n?X(r,1,n(o)):X(r,2,o)}catch(e){X(r,2,e)}},r},e}();function Q(e){return e instanceof W&&1&e.s}var ee=function(){try{return Promise.resolve(new Promise(function(e,n){try{return se(),Promise.resolve(he()).then(function(n){return n.loggedIn&&fe(n)?e(n):Promise.resolve(t.config().get("discovery.wallet")).then(function(n){function r(t){M({endpoint:t},{onReady:function(e,t){var n=t.send;try{return Promise.resolve(te(/^service\./)).then(function(e){return Promise.resolve(te(/^app\.detail\./)).then(function(t){n({type:"FCL:AUTHN:CONFIG",services:e,app:t})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(he()).then(function(t){e(t)})}catch(e){return Promise.reject(e)}},onResponse:function(t,n){var r=n.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?u.withPrefix(e.addr):null,e.paddr=e.paddr?u.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,t){try{if(null==e||null==t)return Promise.resolve([]);var n=new URL(e);return n.searchParams.append("code",t),Promise.resolve(fetch(n,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var t=[];if(Array.isArray(e.authorizations))for(var n,r=j(e.authorizations);!(n=r()).done;)t.push(b({type:"authz",keyId:e.keyId},n.value));return null!=e.provider&&t.push(b({type:"authn",id:"wallet-provider#authn"},e.provider)),t})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(n){var r,o,i=(r=t,o=n,void 0===r&&(r=[]),void 0===o&&(o=[]),[].concat(r,o)).map(function(t){return function(e,t){try{return N[e.type](e,t)}catch(t){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,t),e}}(t,e)}),a=function(e,t){return t.find(function(e){return"authn"===e.type})}(0,i);return b({},k,{addr:u.withPrefix(e.addr),cid:U(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(t.data)).then(function(t){return i.send(ne,oe,t),Promise.resolve(he()).then(function(t){e(t),r()})})}catch(t){return Promise.reject(t)}}})}return n?r(n):Promise.resolve(t.config().get("challenge.handshake")).then(r)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},te=function(e){try{return Promise.resolve(t.config().where(e)).then(function(t){return Object.fromEntries(Object.entries(t).map(function(t){var n=t[1];return[t[0].replace(e,""),n]}))})}catch(e){return Promise.reject(e)}},ne="CURRENT_USER",re="CURRENT_USER/UPDATED",oe="SET_CURRENT_USER",ie='{\n "f_type": "User",\n "f_vsn": "1.0.0",\n "addr":null,\n "cid":null,\n "loggedIn":null,\n "expiresAt":null,\n "services":[]\n}',ue=function(e){try{return sessionStorage.setItem(ne,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ae=function(){return t.config().get("persistSession",!0)},ce=((J={})[i.INIT]=function(e){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(ne));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(ne),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){fe(t)&&e.merge(t)})}();if(n&&n.then)return n.then(function(){})})}catch(e){return Promise.reject(e)}},J[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,re,b({},e.all()))},J[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},J.SNAPSHOT=function(e,t){try{return t.reply(b({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},J[oe]=function(e,t,n){try{return e.merge(n),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(re,b({},e.all()))})}catch(e){return Promise.reject(e)}},J.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(re,b({},e.all()))})}catch(e){return Promise.reject(e)}},J),se=function(){return i.spawn(ce,ne)};function fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function le(){se(),i.send(ne,"DEL_CURRENT_USER")}function de(e){var t=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),n=[];null!=t.proposer&&n.push(["PROPOSER",t.proposer]);for(var r,o=j(t.payer||[]);!(r=o()).done;)n.push(["PAYER",r.value]);for(var i,u=j(t.authorization||[]);!(i=u()).done;)n.push(["AUTHORIZER",i.value]);return n.map(function(e){var t=e[0],n=e[1];return{tempId:[n.identity.address,n.identity.keyId].join("|"),addr:n.identity.address,keyId:n.identity.keyId,signingFunction:function(e){return Z(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function pe(e){se();var t=i.spawn(function(t){try{var n;return t.send(ne,i.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(Q(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Q(i)){r=1;break}i=i.s}}var u=new W,a=X.bind(null,u,2);return(0===r?o.then(s):1===r?i.then(c):(void 0).then(function(){(o=e())?o.then?o.then(s).then(void 0,a):s(o):X(u,1,i)})).then(void 0,a),u;function c(t){i=t;do{if(!(o=e())||Q(o)&&!o.v)return void X(u,1,i);if(o.then)return void o.then(s).then(void 0,a);Q(i=n())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,a)}function s(e){e?(i=n())&&i.then?i.then(c).then(void 0,a):c(i):X(u,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(r){if("@EXIT"===r.tag)return t.send(ne,i.UNSUBSCRIBE),void(n=1);e(r.data)})}))}catch(e){return Promise.reject(e)}});return function(){return i.send(t,"@EXIT")}}function he(){return se(),i.send(ne,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var me=function(){return{authenticate:ee,unauthenticate:le,authorization:$,subscribe:pe,snapshot:he}},ve=me().authorization,ye=o;Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return n.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return n.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return n.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return n.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return n.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return n.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return n.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return n.build}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return n.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return n.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return n.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return n.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return n.getBlockHeader}}),Object.defineProperty(e,"getCollection",{enumerable:!0,get:function(){return n.getCollection}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return n.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return n.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return n.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return n.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return n.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return n.getTransactionStatus}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return n.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return n.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return n.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return n.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return n.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return n.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return n.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return n.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return n.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return n.transaction}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return u.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return u.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return u.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return s.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return s.template}}),e.VERSION="0.0.68-alpha.22",e.authenticate=function(){return me().authenticate()},e.authz=ve,e.currentUser=me,e.events=function(e){return{subscribe:function(t){return i.subscriber(e,S,t)}}},e.logIn=function(){return me().authenticate()},e.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return r.invariant(null!=typeof e.cadence,"query({ cadence }) -- cadence is required"),r.invariant(function(e){return"string"==typeof e}(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return n.send([n.script(e.cadence),n.args((t=e.args||[],"function"==typeof t?t(n.arg,o):[])),e.limit&&"number"==typeof e.limit&&n.limit(e.limit)]).then(n.decode);var t})}catch(e){return Promise.reject(e)}},e.reauthenticate=function(){return me().unauthenticate(),me().authenticate()},e.serialize=function(e,r){void 0===e&&(e=[]),void 0===r&&(r={});try{return Promise.resolve(t.config().get("sdk.resolve",r.resolve||n.resolve(r))).then(function(t){function r(){return Promise.resolve(t(e)).then(function(e){return JSON.stringify(e,null,2)})}var o=function(){if(Array.isArray(e))return Promise.resolve(n.pipe(n.interaction(),e)).then(function(t){e=t})}();return o&&o.then?o.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(){return me().authenticate()},e.t=ye,e.tx=P,e.unauthenticate=function(){return me().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.68-alpha.21", | ||
"version": "0.0.68-alpha.22", | ||
"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
326403