@onflow/fcl
Advanced tools
Comparing version 0.0.74-alpha.1 to 0.0.74-alpha.2
@@ -5,2 +5,7 @@ ## Unreleased | ||
## 0.0.74-alpha.2 | ||
- 2021-07-15 -- Update `verifyUserSignature` to pass publicKey signingAlgos into Cadence script. Allows for successfull verification of supported algorithms ECDSA_P256 and ECDSA_secp256k1 | ||
- 2021-07-14 -- Updates `fcl.serialize` to use new `config.first` | ||
## 0.0.74-alpha.1 | ||
@@ -7,0 +12,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/sdk"),t=require("@onflow/util-invariant"),r=require("@onflow/types"),n=require("@onflow/util-actor"),o=require("@onflow/util-address"),i=require("@onflow/rlp"),u=require("@onflow/util-uid"),a=require("@onflow/util-template");function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var c=s(e),l=s(r),f=s(i);e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var d=function(e){return function(t){return typeof t===e}},p=function(e){return null!=e},h=d("object"),m=d("string"),v=d("function"),y=d("number");function g(e){return v(e)?e(c.arg,l):[]}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 j(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return b(e,t);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,t):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.")}var E={f_type:"Service",f_vsn:"1.0.0"},x={f_type:"Identity",f_vsn:"1.0.0"},S={f_type:"USER",f_vsn:"1.0.0"},O={f_type:"PollingResponse",f_vsn:"1.0.0"},w={f_type:"CompositeSignature",f_vsn:"1.0.0"};function R(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({old:e},E,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function I(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},E,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var k={"back-channel-rpc":I,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},E,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},x,{address:o.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({},E,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},x,{address:o.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({},E,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:R,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function A(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function C(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function T(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 N(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(T(e),{method:r,headers:P({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function U(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},O,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:I(e.authorizationUpdates),local:R((e.local||[])[0])})}}var B="FCL_IFRAME",D=function(){},L=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function _(e,r){if(void 0===r&&(r={}),null==e)return{send:D,close:D};var n=r.onClose||D,o=r.onMessage||D,i=r.onReady||D,u=r.onResponse||D;window.addEventListener("message",l);var a=function(e){t.invariant(!document.getElementById(B),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=B,r.allow="usb *; hid *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(B)&&document.getElementById(B).remove()}]}(T(e)),s=a[0],c=a[1];return{send:d,close:f};function l(e){try{if("object"!=typeof e.data)return;if(L.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:d,close:f}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:f}),o(e,{send:d,close:f}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:d,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",l),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 z,F=function e(r,n){void 0===n&&(n=function(){return!0});try{if(t.invariant(r,"Missing Polling Service",{service:r}),!n())throw new Error("Externally Halted");return Promise.resolve(N(r,{method:M(r)}).then(U)).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)}},H={"HTTP/GET":"GET","HTTP/POST":"POST"},M=function(e){return t.invariant(H[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),H[e.method]},q=function(e,t,r){try{return t.data=e.data,Promise.resolve(N(e,{data:t}).then(U)).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=_(t.local,{onClose:function(){r=!1}}).close;return F(t.updates,function(){return r}).then(function(e){return n(),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)}},J=function(e,t,r){void 0===r&&(r={});try{try{return Promise.resolve(K[e.method](e,t,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t,opts:r}),n}}catch(e){return Promise.reject(e)}},K={"HTTP/RPC":q,"HTTP/POST":q,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var i=u.uid(),a=r.includeOlderJsonRpcCall;t.data=e.data,_(e,{onReady:function(r,n){var o=n.send;try{o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=U(e.data);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var u=U(e.data.result);switch(u.status){case"APPROVED":n(u.data),r();break;case"DECLINED":o("Declined: "+(u.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})}};function G(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},w,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function V(e,t,r){if(!e.s){if(r instanceof X){if(!r.s)return void(r.o=V.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(V.bind(null,e,t),V.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}function Y(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Z=function(e,r){try{t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),t.invariant(Array.isArray(r),"Must include an Array of composite signatures");var n=[],o=[];return Promise.resolve(Promise.all(r.map(function(e){try{return t.invariant("string"==typeof e.addr,"addr must be a string"),t.invariant("number"==typeof e.keyId,"keyId must be a number"),t.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve(Y(function(){return Promise.resolve(fcl.account(e.addr)).then(function(t){return n.push(t.keys[e.keyId].weight.toFixed(1)),o.push(e.signature),t.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(fcl.query({cadence:""+ye,args:function(r,i){return[r(e,i.String),r(t,i.Array([i.String])),r(n,i.Array(i.UFix64)),r(o,i.Array([i.String]))]}}))})}catch(e){return Promise.reject(e)}},$=function(e,r){void 0===r&&(r={});try{return ce(),Promise.resolve(ee(r)).then(function(r){var n=C(r.services,"user-signature");return t.invariant(n,"Current user must have authorized a signing service."),Y(function(){return Promise.resolve(J(n,ve(e))).then(function(e){return Array.isArray(e)?e.map(function(e){return G(e)}):[G(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},W=function(e){try{return ce(),Promise.resolve(ee()).then(function(t){var r=C(t.services,"authz"),n=C(t.services,"pre-authz");return P({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(J(n,t)).then(de)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(J(r,e,{includeOlderJsonRpcCall:!0})).then(G)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},X=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{V(n,1,i(this.v))}catch(e){V(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?V(n,1,t?t(o):o):r?V(n,1,r(o)):V(n,2,o)}catch(e){V(n,2,e)}},n},e}();function Q(e){return e instanceof X&&1&e.s}var ee=function(t){void 0===t&&(t={});try{return Promise.resolve(new Promise(function(r,i){try{return ce(),Promise.resolve(he()).then(function(i){if(i.loggedIn&&le(i))return r(i);var u=t.serviceStrategy||_;return Promise.resolve(e.config().get("discovery.wallet")).then(function(t){function i(e){u({endpoint:e},{onReady:function(e,t){var r=t.send;try{return Promise.resolve(te(/^service\./)).then(function(e){return Promise.resolve(te(/^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(he()).then(function(e){r(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var i=t.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,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=j(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,i,u=(n=t,i=r,void 0===n&&(n=[]),void 0===i&&(i=[]),[].concat(n,i)).map(function(t){return function(e,t){try{return k[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({},S,{addr:o.withPrefix(e.addr),cid:A(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return n.send(re,oe,e),Promise.resolve(he()).then(function(e){r(e),i()})})}catch(e){return Promise.reject(e)}}})}return t?i(t):Promise.resolve(e.config().get("challenge.handshake")).then(i)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},te=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)}},re="CURRENT_USER",ne="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(re,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ae=function(){return e.config().get("persistSession",!0)},se=((z={})[n.INIT]=function(e){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(re));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(re),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){le(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},z[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,ne,P({},e.all()))},z[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},z.SNAPSHOT=function(e,t){try{return t.reply(P({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},z[oe]=function(e,t,r){try{return e.merge(r),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(ne,P({},e.all()))})}catch(e){return Promise.reject(e)}},z.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(ne,P({},e.all()))})}catch(e){return Promise.reject(e)}},z),ce=function(){return n.spawn(se,re)};function le(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function fe(){ce(),n.send(re,"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),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=j(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=j(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 J(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function pe(e){ce();var t="@EXIT",r=n.spawn(function(r){try{var o;return r.send(re,n.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(Q(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Q(i)){n=1;break}i=i.s}}var u=new X,a=V.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):V(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||Q(o)&&!o.v)return void V(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Q(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):V(u,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===t)return r.send(re,n.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return n.send(r,t)}}function he(){return ce(),n.send(re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var me,ve=function(e){return t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},ye="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: SignatureAlgorithm.ECDSA_P256\n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",ge=function(){return{authenticate:ee,unauthenticate:fe,authorization:W,signUserMessage:$,verifyUserSignatures:Z,subscribe:pe,snapshot:he}},Pe=function(t){try{return Promise.resolve(e.send([e.getTransactionStatus(t)]).then(e.decode))}catch(e){return Promise.reject(e)}},be=function(e){return e.status>=4},je=function(e){return e.status>=3},Ee=function(e){return e.status>=2},xe=((me={})[n.INIT]=function(e){try{return Promise.resolve(Pe(e.self())).then(function(t){be(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},me[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,n.UPDATED,e.all())},me[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},me[n.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},me.POLL=function(e){try{return Promise.resolve(Pe(e.self())).then(function(t){var r,o;be(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),o=t,JSON.stringify(r)!==JSON.stringify(o)&&e.broadcast(n.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},me),Se=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Oe=function(e){return n.spawn(xe,Se(e))};function we(e){function t(t){return n.subscriber(Se(e),Oe,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 n.snapshoter(e,Oe)},subscribe:t,onceFinalized:r(Ee),onceExecuted:r(je),onceSealed:r(be)}}we.isUnknown=function(e){return e.status>=0},we.isPending=function(e){return e.status>=1},we.isFinalized=Ee,we.isExecuted=je,we.isSealed=be,we.isExpired=function(e){return 5===e.status};var Re,Ie=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)}},ke=((Re={}).TICK=function(t){try{if(!t.hasSubs())return Promise.resolve();var r=t.get("hwm"),n=function(){if(null==r){var n=t.put;return Promise.resolve(e.latestBlock()).then(function(e){n.call(t,"hwm",e);var r=t.put;return Promise.resolve(Ie(t)).then(function(e){r.call(t,"tick",e)})})}return Promise.resolve(e.latestBlock()).then(function(n){return t.put("hwm",n),Promise.resolve(e.send([getEvents(t.self(),r.height,n.height-1)]).then(e.decode)).then(function(e){for(var r,n=j(e);!(r=n()).done;)t.broadcast("UPDATED",r.value.data);var o=t.put;return Promise.resolve(Ie(t)).then(function(e){o.call(t,"tick",e)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Re[n.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(Ie(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)}},Re[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Re),Ae=function(e){return n.spawn(ke,e)},Ce=ge().authorization,Te=l;Object.defineProperty(exports,"TestUtils",{enumerable:!0,get:function(){return e.TestUtils}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return e.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return e.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return e.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return e.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return e.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return e.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return e.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return e.build}}),Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"createSignableVoucher",{enumerable:!0,get:function(){return e.createSignableVoucher}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return e.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return e.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return e.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return e.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return e.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return e.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return e.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return e.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return e.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return e.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return e.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return e.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return e.getTransactionStatus}}),Object.defineProperty(exports,"invariant",{enumerable:!0,get:function(){return e.invariant}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return e.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return e.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return e.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return e.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return e.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return e.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return e.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return e.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return e.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return e.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return e.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return e.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return e.transaction}}),Object.defineProperty(exports,"validator",{enumerable:!0,get:function(){return e.validator}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return a.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return a.template}}),exports.VERSION="0.0.74-alpha.1",exports.authenticate=function(e){return ge().authenticate(e)},exports.authz=Ce,exports.currentUser=ge,exports.events=function(e){return{subscribe:function(t){return n.subscriber(e,Ae,t)}}},exports.logIn=function(e){return ge().authenticate()},exports.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(e){try{return t.invariant(p(e),"mutate(opts) -- opts is required"),t.invariant(h(e),"mutate(opts) -- opts must be an object"),t.invariant(p(e.cadence),"mutate({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(c.config().get("fcl.authz",ge().authorization)).then(function(t){return c.send([c.transaction(e.cadence),c.args(g(e.args||[])),e.limit&&y(e.limit)&&c.limit(e.limit),c.proposer(e.proposer||e.authz||t),c.payer(e.payer||e.authz||t),c.authorizations(e.authorizations||[e.authz||t])]).then(c.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},exports.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return t.invariant(p(e.cadence),"query({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return c.send([c.script(e.cadence),c.args(g(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}},exports.reauthenticate=function(){return ge().unauthenticate(),ge().authenticate()},exports.serialize=function(t,r){void 0===t&&(t=[]),void 0===r&&(r={});try{return Promise.resolve(e.config().get("sdk.resolve",r.resolve||e.resolve)).then(function(r){function n(){return Promise.resolve(r(t)).then(function(t){return JSON.stringify(e.createSignableVoucher(t),null,2)})}var o=function(){if(Array.isArray(t))return Promise.resolve(e.pipe(e.interaction(),t)).then(function(e){t=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(e){return ge().authenticate()},exports.t=Te,exports.tx=we,exports.unauthenticate=function(){return ge().unauthenticate()}; | ||
var e=require("@onflow/sdk"),t=require("@onflow/util-invariant"),r=require("@onflow/types"),n=require("@onflow/util-actor"),o=require("@onflow/util-address"),i=require("@onflow/rlp"),u=require("@onflow/util-uid"),a=require("@onflow/util-template");function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var c=s(e),l=s(r),f=s(i);e.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var d=function(e){return function(t){return typeof t===e}},p=function(e){return null!=e},h=d("object"),m=d("string"),v=d("function"),y=d("number");function g(e){return v(e)?e(c.arg,l):[]}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 j(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return b(e,t);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,t):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.")}var E={f_type:"Service",f_vsn:"1.0.0"},S={f_type:"Identity",f_vsn:"1.0.0"},x={f_type:"USER",f_vsn:"1.0.0"},O={f_type:"PollingResponse",f_vsn:"1.0.0"},w={f_type:"CompositeSignature",f_vsn:"1.0.0"};function I(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({old:e},E,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function R(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},E,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var A={"back-channel-rpc":R,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},E,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},S,{address:o.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({},E,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:P({},S,{address:o.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({},E,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:I,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function k(e){return f.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function C(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function T(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 U(e,t){void 0===t&&(t={});var r=t.method||"POST",n="GET"===r?void 0:JSON.stringify(t.data||e.data||{});return fetch(T(e),{method:r,headers:P({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function N(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},O,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:R(e.authorizationUpdates),local:I((e.local||[])[0])})}}var B="FCL_IFRAME",D=function(){},L=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function _(e,r){if(void 0===r&&(r={}),null==e)return{send:D,close:D};var n=r.onClose||D,o=r.onMessage||D,i=r.onReady||D,u=r.onResponse||D;window.addEventListener("message",l);var a=function(e){t.invariant(!document.getElementById(B),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=B,r.allow="usb *; hid *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById(B)&&document.getElementById(B).remove()}]}(T(e)),s=a[0],c=a[1];return{send:d,close:f};function l(e){try{if("object"!=typeof e.data)return;if(L.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&i(e,{send:d,close:f}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:f}),o(e,{send:d,close:f}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:f}),"FCL::AUTHZ_READY"===e.data.type&&i(e,{send:d,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",l),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 z,F=function e(r,n){void 0===n&&(n=function(){return!0});try{if(t.invariant(r,"Missing Polling Service",{service:r}),!n())throw new Error("Externally Halted");return Promise.resolve(U(r,{method:M(r)}).then(N)).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)}},H={"HTTP/GET":"GET","HTTP/POST":"POST"},M=function(e){return t.invariant(H[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),H[e.method]},q=function(e,t,r){try{return t.data=e.data,Promise.resolve(U(e,{data:t}).then(N)).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=_(t.local,{onClose:function(){r=!1}}).close;return F(t.updates,function(){return r}).then(function(e){return n(),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)}},J=function(e,t,r){void 0===r&&(r={});try{try{return Promise.resolve(K[e.method](e,t,r))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:t,opts:r}),n}}catch(e){return Promise.reject(e)}},K={"HTTP/RPC":q,"HTTP/POST":q,"IFRAME/RPC":function(e,t,r){return new Promise(function(n,o){var i=u.uid(),a=r.includeOlderJsonRpcCall;t.data=e.data,_(e,{onReady:function(r,n){var o=n.send;try{o({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;var i=N(e.data);switch(i.status){case"APPROVED":n(i.data),r();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var r=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var u=N(e.data.result);switch(u.status){case"APPROVED":n(u.data),r();break;case"DECLINED":o("Declined: "+(u.reason||"No reason supplied")),r();break;default:o("Declined: No reason supplied"),r()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})}};function G(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return P({},w,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function V(e,t,r){if(!e.s){if(r instanceof X){if(!r.s)return void(r.o=V.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(V.bind(null,e,t),V.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}function Y(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var Z=function(e,r){try{t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),t.invariant(Array.isArray(r),"Must include an Array of composite signatures");var n=[],o=[],i=[];return Promise.resolve(Promise.all(r.map(function(e){try{return t.invariant("string"==typeof e.addr,"addr must be a string"),t.invariant("number"==typeof e.keyId,"keyId must be a number"),t.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve(Y(function(){return Promise.resolve(fcl.account(e.addr)).then(function(t){return n.push(t.keys[e.keyId].weight.toFixed(1)),o.push(t.keys[e.keyId].signAlgo),i.push(e.signature),t.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(fcl.query({cadence:""+ye,args:function(r,u){return[r(e,u.String),r(t,u.Array([u.String])),r(n,u.Array(u.UFix64)),r(o,u.Array([u.UInt])),r(i,u.Array([u.String]))]}}))})}catch(e){return Promise.reject(e)}},$=function(e,r){void 0===r&&(r={});try{return ce(),Promise.resolve(ee(r)).then(function(r){var n=C(r.services,"user-signature");return t.invariant(n,"Current user must have authorized a signing service."),Y(function(){return Promise.resolve(J(n,ve(e))).then(function(e){return Array.isArray(e)?e.map(function(e){return G(e)}):[G(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},W=function(e){try{return ce(),Promise.resolve(ee()).then(function(t){var r=C(t.services,"authz"),n=C(t.services,"pre-authz");return P({},e,n?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(J(n,t)).then(de)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(r.identity.address),keyId:r.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(J(r,e,{includeOlderJsonRpcCall:!0})).then(G)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},X=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{V(n,1,i(this.v))}catch(e){V(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?V(n,1,t?t(o):o):r?V(n,1,r(o)):V(n,2,o)}catch(e){V(n,2,e)}},n},e}();function Q(e){return e instanceof X&&1&e.s}var ee=function(t){void 0===t&&(t={});try{return Promise.resolve(new Promise(function(r,i){try{return ce(),Promise.resolve(he()).then(function(i){if(i.loggedIn&&le(i))return r(i);var u=t.serviceStrategy||_;return Promise.resolve(e.config.first(["discovery.wallet","challenge.handshake"])).then(function(e){u({endpoint:e},{onReady:function(e,t){var r=t.send;try{return Promise.resolve(te(/^service\./)).then(function(e){return Promise.resolve(te(/^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(he()).then(function(e){r(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var i=t.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,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=j(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,i,u=(n=t,i=r,void 0===n&&(n=[]),void 0===i&&(i=[]),[].concat(n,i)).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({},x,{addr:o.withPrefix(e.addr),cid:k(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return n.send(re,oe,e),Promise.resolve(he()).then(function(e){r(e),i()})})}catch(e){return Promise.reject(e)}}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},te=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)}},re="CURRENT_USER",ne="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(re,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ae=function(){return e.config().get("persistSession",!0)},se=((z={})[n.INIT]=function(e){try{return e.merge(JSON.parse(ie)),Promise.resolve(ae()).then(function(t){var r=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ie),t=JSON.parse(sessionStorage.getItem(re));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(re),Promise.resolve(e)):Promise.resolve(t||e)}catch(e){return Promise.reject(e)}}()).then(function(t){le(t)&&e.merge(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},z[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,ne,P({},e.all()))},z[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},z.SNAPSHOT=function(e,t){try{return t.reply(P({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},z[oe]=function(e,t,r){try{return e.merge(r),Promise.resolve(ae()).then(function(t){t&&ue(e.all()),e.broadcast(ne,P({},e.all()))})}catch(e){return Promise.reject(e)}},z.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(ne,P({},e.all()))})}catch(e){return Promise.reject(e)}},z),ce=function(){return n.spawn(se,re)};function le(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function fe(){ce(),n.send(re,"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),r=[];null!=t.proposer&&r.push(["PROPOSER",t.proposer]);for(var n,o=j(t.payer||[]);!(n=o()).done;)r.push(["PAYER",n.value]);for(var i,u=j(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 J(r,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function pe(e){ce();var t="@EXIT",r=n.spawn(function(r){try{var o;return r.send(re,n.SUBSCRIBE),Promise.resolve(function(e,t,r){for(var n;;){var o=e();if(Q(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Q(i)){n=1;break}i=i.s}}var u=new X,a=V.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):V(u,1,i)})).then(void 0,a),u;function s(t){i=t;do{if(!(o=e())||Q(o)&&!o.v)return void V(u,1,i);if(o.then)return void o.then(c).then(void 0,a);Q(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):V(u,1,i)}}(function(){return!o&&1},0,function(){return Promise.resolve(r.receive()).then(function(i){if(i.tag===t)return r.send(re,n.UNSUBSCRIBE),void(o=1);e(i.data)})}))}catch(e){return Promise.reject(e)}});return function(){return n.send(r,t)}}function he(){return ce(),n.send(re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var me,ve=function(e){return t.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},ye="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",ge=function(){return{authenticate:ee,unauthenticate:fe,authorization:W,signUserMessage:$,verifyUserSignatures:Z,subscribe:pe,snapshot:he}},Pe=function(t){try{return Promise.resolve(e.send([e.getTransactionStatus(t)]).then(e.decode))}catch(e){return Promise.reject(e)}},be=function(e){return e.status>=4},je=function(e){return e.status>=3},Ee=function(e){return e.status>=2},Se=((me={})[n.INIT]=function(e){try{return Promise.resolve(Pe(e.self())).then(function(t){be(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},me[n.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,n.UPDATED,e.all())},me[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},me[n.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},me.POLL=function(e){try{return Promise.resolve(Pe(e.self())).then(function(t){var r,o;be(t)||setTimeout(function(){return e.sendSelf("POLL")},2500),r=e.all(),o=t,JSON.stringify(r)!==JSON.stringify(o)&&e.broadcast(n.UPDATED,t),e.merge(t)})}catch(e){return Promise.reject(e)}},me),xe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Oe=function(e){return n.spawn(Se,xe(e))};function we(e){function t(t){return n.subscriber(xe(e),Oe,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 n.snapshoter(e,Oe)},subscribe:t,onceFinalized:r(Ee),onceExecuted:r(je),onceSealed:r(be)}}we.isUnknown=function(e){return e.status>=0},we.isPending=function(e){return e.status>=1},we.isFinalized=Ee,we.isExecuted=je,we.isSealed=be,we.isExpired=function(e){return 5===e.status};var Ie,Re=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)}},Ae=((Ie={}).TICK=function(t){try{if(!t.hasSubs())return Promise.resolve();var r=t.get("hwm"),n=function(){if(null==r){var n=t.put;return Promise.resolve(e.latestBlock()).then(function(e){n.call(t,"hwm",e);var r=t.put;return Promise.resolve(Re(t)).then(function(e){r.call(t,"tick",e)})})}return Promise.resolve(e.latestBlock()).then(function(n){return t.put("hwm",n),Promise.resolve(e.send([getEvents(t.self(),r.height,n.height-1)]).then(e.decode)).then(function(e){for(var r,n=j(e);!(r=n()).done;)t.broadcast("UPDATED",r.value.data);var o=t.put;return Promise.resolve(Re(t)).then(function(e){o.call(t,"tick",e)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Ie[n.SUBSCRIBE]=function(e,t){try{var r=function(){e.subscribe(t.from)},n=function(){if(!e.hasSubs()){var t=e.put;return Promise.resolve(Re(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)}},Ie[n.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Ie),ke=function(e){return n.spawn(Ae,e)},Ce=ge().authorization,Te=l;Object.defineProperty(exports,"TestUtils",{enumerable:!0,get:function(){return e.TestUtils}}),Object.defineProperty(exports,"account",{enumerable:!0,get:function(){return e.account}}),Object.defineProperty(exports,"arg",{enumerable:!0,get:function(){return e.arg}}),Object.defineProperty(exports,"args",{enumerable:!0,get:function(){return e.args}}),Object.defineProperty(exports,"atBlockHeight",{enumerable:!0,get:function(){return e.atBlockHeight}}),Object.defineProperty(exports,"atBlockId",{enumerable:!0,get:function(){return e.atBlockId}}),Object.defineProperty(exports,"authorization",{enumerable:!0,get:function(){return e.authorization}}),Object.defineProperty(exports,"authorizations",{enumerable:!0,get:function(){return e.authorizations}}),Object.defineProperty(exports,"build",{enumerable:!0,get:function(){return e.build}}),Object.defineProperty(exports,"config",{enumerable:!0,get:function(){return e.config}}),Object.defineProperty(exports,"createSignableVoucher",{enumerable:!0,get:function(){return e.createSignableVoucher}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return e.decode}}),Object.defineProperty(exports,"getAccount",{enumerable:!0,get:function(){return e.getAccount}}),Object.defineProperty(exports,"getBlock",{enumerable:!0,get:function(){return e.getBlock}}),Object.defineProperty(exports,"getBlockByHeight",{enumerable:!0,get:function(){return e.getBlockByHeight}}),Object.defineProperty(exports,"getBlockById",{enumerable:!0,get:function(){return e.getBlockById}}),Object.defineProperty(exports,"getBlockHeader",{enumerable:!0,get:function(){return e.getBlockHeader}}),Object.defineProperty(exports,"getCollection",{enumerable:!0,get:function(){return e.getCollection}}),Object.defineProperty(exports,"getEvents",{enumerable:!0,get:function(){return e.getEvents}}),Object.defineProperty(exports,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return e.getEventsAtBlockHeightRange}}),Object.defineProperty(exports,"getEventsAtBlockIds",{enumerable:!0,get:function(){return e.getEventsAtBlockIds}}),Object.defineProperty(exports,"getLatestBlock",{enumerable:!0,get:function(){return e.getLatestBlock}}),Object.defineProperty(exports,"getTransaction",{enumerable:!0,get:function(){return e.getTransaction}}),Object.defineProperty(exports,"getTransactionStatus",{enumerable:!0,get:function(){return e.getTransactionStatus}}),Object.defineProperty(exports,"invariant",{enumerable:!0,get:function(){return e.invariant}}),Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return e.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return e.isOk}}),Object.defineProperty(exports,"latestBlock",{enumerable:!0,get:function(){return e.latestBlock}}),Object.defineProperty(exports,"limit",{enumerable:!0,get:function(){return e.limit}}),Object.defineProperty(exports,"param",{enumerable:!0,get:function(){return e.param}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return e.params}}),Object.defineProperty(exports,"payer",{enumerable:!0,get:function(){return e.payer}}),Object.defineProperty(exports,"ping",{enumerable:!0,get:function(){return e.ping}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"proposer",{enumerable:!0,get:function(){return e.proposer}}),Object.defineProperty(exports,"ref",{enumerable:!0,get:function(){return e.ref}}),Object.defineProperty(exports,"script",{enumerable:!0,get:function(){return e.script}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return e.send}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return e.transaction}}),Object.defineProperty(exports,"validator",{enumerable:!0,get:function(){return e.validator}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(exports,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(exports,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return a.template}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return a.template}}),exports.VERSION="0.0.74-alpha.2",exports.authenticate=function(e){return ge().authenticate(e)},exports.authz=Ce,exports.currentUser=ge,exports.events=function(e){return{subscribe:function(t){return n.subscriber(e,ke,t)}}},exports.logIn=function(e){return ge().authenticate()},exports.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(function(e){try{return t.invariant(p(e),"mutate(opts) -- opts is required"),t.invariant(h(e),"mutate(opts) -- opts must be an object"),t.invariant(p(e.cadence),"mutate({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(c.config().get("fcl.authz",ge().authorization)).then(function(t){return c.send([c.transaction(e.cadence),c.args(g(e.args||[])),e.limit&&y(e.limit)&&c.limit(e.limit),c.proposer(e.proposer||e.authz||t),c.payer(e.payer||e.authz||t),c.authorizations(e.authorizations||[e.authz||t])]).then(c.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},exports.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return t.invariant(p(e.cadence),"query({ cadence }) -- cadence is required"),t.invariant(m(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return c.send([c.script(e.cadence),c.args(g(e.args||[])),e.limit&&"number"==typeof e.limit&&c.limit(e.limit)]).then(c.decode)})}catch(e){return Promise.reject(e)}},exports.reauthenticate=function(){return ge().unauthenticate(),ge().authenticate()},exports.serialize=function(t,r){void 0===t&&(t=[]),void 0===r&&(r={});try{return Promise.resolve(e.config.first(["sdk.resolve"],r.resolve||e.resolve)).then(function(r){function n(){return Promise.resolve(r(t)).then(function(t){return JSON.stringify(e.createSignableVoucher(t),null,2)})}var o=function(){if(Array.isArray(t))return Promise.resolve(e.pipe(e.interaction(),t)).then(function(e){t=e})}();return o&&o.then?o.then(n):n()})}catch(e){return Promise.reject(e)}},exports.signUp=function(e){return ge().authenticate()},exports.t=Te,exports.tx=we,exports.unauthenticate=function(){return ge().unauthenticate()}; | ||
//# sourceMappingURL=fcl.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"@onflow/sdk";import{config as t,send as n,getTransactionStatus as a,decode as r,resolve as s,pipe as i,interaction as o,createSignableVoucher as c,latestBlock as u}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as d}from"@onflow/util-invariant";import*as l from"@onflow/types";import{spawn as p,send as f,SUBSCRIBE as y,UNSUBSCRIBE as h,INIT as m,subscriber as g,snapshoter as w,UPDATED as E,SNAPSHOT as v}from"@onflow/util-actor";import{withPrefix as S,sansPrefix as b}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as R from"@onflow/rlp";import{uid as P}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";t().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const A="0.0.74-alpha.1",k=e=>t=>typeof t===e,C=e=>null!=e,I=k("object"),T=k("string"),N=k("function"),O=k("number");function x(t){return N(t)?t(e.arg,l):[]}async function L(t={}){return await async function(e){d(C(e.cadence),"query({ cadence }) -- cadence is required"),d(T(e.cadence),"query({ cadence }) -- cadence must be a string")}(t),e.send([e.script(t.cadence),e.args(x(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function _(){return(_=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 D={f_type:"Service",f_vsn:"1.0.0"},U={f_type:"Identity",f_vsn:"1.0.0"},z={f_type:"USER",f_vsn:"1.0.0"},F={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({old:e},D,{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 _({},D,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const M={"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 _({},D,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},U,{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 _({},D,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:_({},U,{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 _({},D,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:S(e.addr),name:e.name,icon:e.icon}})}},frame:j,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function J(e){return R.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function K(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 G(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:_({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function $(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},F,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:B(e.authorizationUpdates),local:j((e.local||[])[0])})}}const V="FCL_IFRAME",Y=()=>{},Z=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function W(e,t={}){if(null==e)return{send:Y,close:Y};const n=t.onClose||Y,a=t.onMessage||Y,r=t.onReady||Y,s=t.onResponse||Y;window.addEventListener("message",c);const[i,o]=function(e){d(!document.getElementById(V),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=V,t.allow="usb *; hid *",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(V)&&document.getElementById(V).remove()}]}(q(e));return{send:l,close:u};function c(e){try{if("object"!=typeof e.data)return;if(Z.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:l,close:u}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:l,close:u}),a(e,{send:l,close:u}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&s(e,{send:l,close:u}),"FCL::AUTHZ_READY"===e.data.type&&r(e,{send:l,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),o(),n()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{i.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const X={"HTTP/GET":"GET","HTTP/POST":"POST"},Q=e=>(d(X[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),X[e.method]);async function ee(e,t=(()=>!0)){if(d(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await G(e,{method:Q(e)}).then($);switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error(`Declined: ${n.reason||"No reason supplied."}`);default:return await new Promise(e=>setTimeout(e,500)),ee(n.updates,t)}}async function te(e,t,n){t.data=e.data;const a=await G(e,{data:t}).then($);if("APPROVED"===a.status)return a.data;if("DECLINED"===a.status)throw new Error(`Declined: ${a.reason||"No reason supplied."}`);if("PENDING"===a.status){var r=!0;const{close:e}=W(a.local,{onClose(){r=!1}});return ee(a.updates,()=>r).then(t=>(e(),t)).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:a}),new Error("Auto Decline: Invalid Response")}const ne={"HTTP/RPC":te,"HTTP/POST":te,"IFRAME/RPC":function(e,t,n){return new Promise((a,r)=>{const s=P(),i=n.includeOlderJsonRpcCall;t.data=e.data,W(e,{onReady(n,{send:a}){try{a({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data}}),i&&a({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=$(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;const n=$(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})}};async function ae(e,t,n={}){try{return ne[e.method](e,t,n)}catch(a){throw console.error("execService(service, msg)",a,{service:e,msg:t,opts:n}),a}}function re(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return _({},H,{addr:b(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const se="CURRENT_USER",ie="CURRENT_USER/UPDATED",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}',ce=async e=>(sessionStorage.setItem(se,JSON.stringify(e)),e),ue=()=>t().get("persistSession",!0),de={[m]:async e=>{if(e.merge(JSON.parse(oe)),await ue()){const t=await(async()=>{const e=JSON.parse(oe),t=JSON.parse(sessionStorage.getItem(se));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(se),e):t||e})();pe(t)&&e.merge(t)}},[y]:(e,t)=>{e.subscribe(t.from),e.send(t.from,ie,_({},e.all()))},[h]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(_({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await ue()&&ce(e.all()),e.broadcast(ie,_({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(oe)),await ue()&&ce(e.all()),e.broadcast(ie,_({},e.all()))}},le=()=>p(de,se);function pe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function fe(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,n])=>[t.replace(e,""),n]))}async function ye(e={}){return new Promise(async(n,a)=>{le();const r=await we();if(r.loggedIn&&pe(r))return n(r);(e.serviceStrategy||W)({endpoint:await t().get("discovery.wallet")||await t().get("challenge.handshake")},{async onReady(e,{send:t}){t({type:"FCL:AUTHN:CONFIG",services:await fe(/^service\./),app:await fe(/^app\.detail\./)})},async onClose(){n(await we())},async onResponse(e,{close:t}){f(se,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?S(e.addr):null,e.paddr=e.paddr?S(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(_({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(_({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return M[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 _({},z,{addr:S(e.addr),cid:J(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e.data)),n(await we()),t()}})})}function he(){le(),f(se,"DEL_CURRENT_USER")}async function me(e){le();const t=await ye(),n=K(t.services,"authz"),a=K(t.services,"pre-authz");return _({},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=>ae(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await ae(a,t))}:{tempId:"CURRENT_USER",resolve:null,addr:b(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>re(await ae(n,e,{includeOlderJsonRpcCall:!0}))})}function ge(e){le();const t="@EXIT",n=p(async n=>{for(n.send(se,y);;){const a=await n.receive();if(a.tag===t)return void n.send(se,h);e(a.data)}});return()=>f(n,t)}function we(){return le(),f(se,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function Ee(e,t={}){le();const n=K((await ye(t)).services,"user-signature");d(n,"Current user must have authorized a signing service.");try{const t=await ae(n,(e=>(d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}))(e));return Array.isArray(t)?t.map(e=>re(e)):[re(t)]}catch(e){return e}}async function ve(e,t){d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),d(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[];const r=await Promise.all(t.map(async e=>{d("string"==typeof e.addr,"addr must be a string"),d("number"==typeof e.keyId,"keyId must be a number"),d("string"==typeof e.signature,"signature must be a string");try{const t=await fcl.account(e.addr);return n.push(t.keys[e.keyId].weight.toFixed(1)),a.push(e.signature),t.keys[e.keyId].publicKey}catch(e){throw e}}));return await fcl.query({cadence:"\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: SignatureAlgorithm.ECDSA_P256\n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",args:(t,s)=>[t(e,s.String),t(r,s.Array([s.String])),t(n,s.Array(s.UFix64)),t(a,s.Array([s.String]))]})}const Se=()=>({authenticate:ye,unauthenticate:he,authorization:me,signUserMessage:Ee,verifyUserSignatures:ve,subscribe:ge,snapshot:we}),be=async e=>n([a(e)]).then(r),Re=e=>e.status>=4,Pe=e=>e.status>=3,Ae=e=>e.status>=2,ke={[m]:async e=>{const t=await be(e.self());Re(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[y]:(e,t)=>{e.subscribe(t.from),e.send(t.from,E,e.all())},[h]:(e,t)=>{e.unsubscribe(t.from)},[v]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await be(e.self());var n,a;Re(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(E,t),e.merge(t)}},Ce=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ie=e=>p(ke,Ce(e));function Te(e){function t(t){return g(Ce(e),Ie,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,r)=>{const s=t(t=>{t.statusCode&&!a?(r(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return w(e,Ie)},subscribe:t,onceFinalized:n(Ae),onceExecuted:n(Pe),onceSealed:n(Re)}}async function Ne(t={}){try{await async function(e){d(C(e),"mutate(opts) -- opts is required"),d(I(e),"mutate(opts) -- opts must be an object"),d(C(e.cadence),"mutate({ cadence }) -- cadence is required"),d(T(e.cadence),"mutate({ cadence }) -- cadence must be a string")}(t);const n=await e.config().get("fcl.authz",Se().authorization);return e.send([e.transaction(t.cadence),e.args(x(t.args||[])),t.limit&&O(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||n),e.payer(t.payer||t.authz||n),e.authorizations(t.authorizations||[t.authz||n])]).then(e.decode)}catch(e){throw e}}Te.isUnknown=e=>e.status>=0,Te.isPending=e=>e.status>=1,Te.isFinalized=Ae,Te.isExecuted=Pe,Te.isSealed=Re,Te.isExpired=e=>5===e.status;const Oe=async(e=[],n={})=>{const a=await t().get("sdk.resolve",n.resolve||s);return Array.isArray(e)&&(e=await i(o(),e)),JSON.stringify(c(await a(e)),null,2)},xe=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),Le={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await u()),e.put("tick",await xe(e));else{let a=await u();e.put("hwm",a);const s=await n([getEvents(e.self(),t.height,a.height-1)]).then(r);for(let t of s)e.broadcast("UPDATED",t.data);e.put("tick",await xe(e))}},[y]:async(e,t)=>{e.hasSubs()||e.put("tick",await xe(e)),e.subscribe(t.from)},[h]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},_e=e=>p(Le,e);function De(e){return{subscribe:t=>g(e,_e,t)}}const Ue=e=>Se().authenticate(e),ze=()=>Se().unauthenticate(),Fe=()=>(Se().unauthenticate(),Se().authenticate()),He=e=>Se().authenticate(),je=e=>Se().authenticate(),Be=Se().authorization,Me=l;export{A as VERSION,Ue as authenticate,Be as authz,Se as currentUser,De as events,je as logIn,Ne as mutate,L as query,Fe as reauthenticate,Oe as serialize,He as signUp,Me as t,Te as tx,ze as unauthenticate}; | ||
import*as e from"@onflow/sdk";import{config as t,send as n,getTransactionStatus as a,decode as r,resolve as s,pipe as i,interaction as o,createSignableVoucher as c,latestBlock as u}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as d}from"@onflow/util-invariant";import*as l from"@onflow/types";import{spawn as p,send as f,SUBSCRIBE as y,UNSUBSCRIBE as h,INIT as m,subscriber as g,snapshoter as w,UPDATED as E,SNAPSHOT as S}from"@onflow/util-actor";import{withPrefix as v,sansPrefix as b}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as R from"@onflow/rlp";import{uid as A}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";t().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");const P="0.0.74-alpha.2",k=e=>t=>typeof t===e,I=e=>null!=e,C=k("object"),T=k("string"),N=k("function"),O=k("number");function _(t){return N(t)?t(e.arg,l):[]}async function x(t={}){return await async function(e){d(I(e.cadence),"query({ cadence }) -- cadence is required"),d(T(e.cadence),"query({ cadence }) -- cadence must be a string")}(t),e.send([e.script(t.cadence),e.args(_(t.args||[])),t.limit&&"number"==typeof t.limit&&e.limit(t.limit)]).then(e.decode)}function L(){return(L=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 D={f_type:"Service",f_vsn:"1.0.0"},U={f_type:"Identity",f_vsn:"1.0.0"},z={f_type:"USER",f_vsn:"1.0.0"},F={f_type:"PollingResponse",f_vsn:"1.0.0"},H={f_type:"CompositeSignature",f_vsn:"1.0.0"};function j(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({old:e},D,{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 L({},D,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}const M={"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 L({},D,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:L({},U,{address:v(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 L({},D,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:L({},U,{address:v(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 L({},D,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:v(e.addr),name:e.name,icon:e.icon}})}},frame:j,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function J(e){return R.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function K(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 G(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:L({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:a}).then(e=>e.json())}function $(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},F,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:B(e.authorizationUpdates),local:j((e.local||[])[0])})}}const V="FCL_IFRAME",Y=()=>{},Z=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function W(e,t={}){if(null==e)return{send:Y,close:Y};const n=t.onClose||Y,a=t.onMessage||Y,r=t.onReady||Y,s=t.onResponse||Y;window.addEventListener("message",c);const[i,o]=function(e){d(!document.getElementById(V),"Attempt at triggering multiple Frames",{src:e});const t=document.createElement("iframe");return t.src=e,t.id=V,t.allow="usb *; hid *",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(V)&&document.getElementById(V).remove()}]}(q(e));return{send:l,close:u};function c(e){try{if("object"!=typeof e.data)return;if(Z.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&u(),"FCL:FRAME:READY"===e.data.type&&r(e,{send:l,close:u}),"FCL:FRAME:RESPONSE"===e.data.type&&s(e,{send:l,close:u}),a(e,{send:l,close:u}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&s(e,{send:l,close:u}),"FCL::AUTHZ_READY"===e.data.type&&r(e,{send:l,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),o(),n()}catch(e){console.error("Frame Close Error",e)}}function l(e){try{i.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(t){console.error("Frame Send Error",e,t)}}}const X={"HTTP/GET":"GET","HTTP/POST":"POST"},Q=e=>(d(X[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),X[e.method]);async function ee(e,t=(()=>!0)){if(d(e,"Missing Polling Service",{service:e}),!t())throw new Error("Externally Halted");const n=await G(e,{method:Q(e)}).then($);switch(n.status){case"APPROVED":return n.data;case"DECLINED":throw new Error(`Declined: ${n.reason||"No reason supplied."}`);default:return await new Promise(e=>setTimeout(e,500)),ee(n.updates,t)}}async function te(e,t,n){t.data=e.data;const a=await G(e,{data:t}).then($);if("APPROVED"===a.status)return a.data;if("DECLINED"===a.status)throw new Error(`Declined: ${a.reason||"No reason supplied."}`);if("PENDING"===a.status){var r=!0;const{close:e}=W(a.local,{onClose(){r=!1}});return ee(a.updates,()=>r).then(t=>(e(),t)).catch(t=>{throw console.error(t),e(),t})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:a}),new Error("Auto Decline: Invalid Response")}const ne={"HTTP/RPC":te,"HTTP/POST":te,"IFRAME/RPC":function(e,t,n){return new Promise((a,r)=>{const s=A(),i=n.includeOlderJsonRpcCall;t.data=e.data,W(e,{onReady(n,{send:a}){try{a({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data}}),i&&a({jsonrpc:"2.0",id:s,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse(e,{close:t}){try{if("object"!=typeof e.data)return;const n=$(e.data);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage(e,{close:t}){try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==s)return;const n=$(e.data.result);switch(n.status){case"APPROVED":a(n.data),t();break;case"DECLINED":r(`Declined: ${n.reason||"No reason supplied"}`),t();break;default:r("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose(){r("Declined: Externally Halted")}})})}};async function ae(e,t,n={}){try{return ne[e.method](e,t,n)}catch(a){throw console.error("execService(service, msg)",a,{service:e,msg:t,opts:n}),a}}function re(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},H,{addr:b(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}const se="CURRENT_USER",ie="CURRENT_USER/UPDATED",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}',ce=async e=>(sessionStorage.setItem(se,JSON.stringify(e)),e),ue=()=>t().get("persistSession",!0),de={[m]:async e=>{if(e.merge(JSON.parse(oe)),await ue()){const t=await(async()=>{const e=JSON.parse(oe),t=JSON.parse(sessionStorage.getItem(se));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(se),e):t||e})();pe(t)&&e.merge(t)}},[y]:(e,t)=>{e.subscribe(t.from),e.send(t.from,ie,L({},e.all()))},[h]:(e,t)=>{e.unsubscribe(t.from)},SNAPSHOT:async(e,t)=>{t.reply(L({},e.all()))},SET_CURRENT_USER:async(e,t,n)=>{e.merge(n),await ue()&&ce(e.all()),e.broadcast(ie,L({},e.all()))},DEL_CURRENT_USER:async(e,t)=>{e.merge(JSON.parse(oe)),await ue()&&ce(e.all()),e.broadcast(ie,L({},e.all()))}},le=()=>p(de,se);function pe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}async function fe(e){return Object.fromEntries(Object.entries(await t().where(e)).map(([t,n])=>[t.replace(e,""),n]))}async function ye(e={}){return new Promise(async(n,a)=>{le();const r=await we();if(r.loggedIn&&pe(r))return n(r);(e.serviceStrategy||W)({endpoint:await t.first(["discovery.wallet","challenge.handshake"])},{async onReady(e,{send:t}){t({type:"FCL:AUTHN:CONFIG",services:await fe(/^service\./),app:await fe(/^app\.detail\./)})},async onClose(){n(await we())},async onResponse(e,{close:t}){f(se,"SET_CURRENT_USER",await async function(e){var t=function(e=[],t=[]){return[...e,...t]}((e=function(e){return e.addr=e.addr?v(e.addr):null,e.paddr=e.paddr?v(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(L({type:"authz",keyId:a.keyId},e));return null!=a.provider&&r.push(L({type:"authn",id:"wallet-provider#authn"},a.provider)),r}(e.hks,e.code)).map(t=>function(e,t){try{return M[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 L({},z,{addr:v(e.addr),cid:J(n),loggedIn:!0,services:t,expiresAt:e.exp})}(e.data)),n(await we()),t()}})})}function he(){le(),f(se,"DEL_CURRENT_USER")}async function me(e){le();const t=await ye(),n=K(t.services,"authz"),a=K(t.services,"pre-authz");return L({},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=>ae(t,e),role:{proposer:"PROPOSER"===e,payer:"PAYER"===e,authorizer:"AUTHORIZER"===e}}))}(await ae(a,t))}:{tempId:"CURRENT_USER",resolve:null,addr:b(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:async e=>re(await ae(n,e,{includeOlderJsonRpcCall:!0}))})}function ge(e){le();const t="@EXIT",n=p(async n=>{for(n.send(se,y);;){const a=await n.receive();if(a.tag===t)return void n.send(se,h);e(a.data)}});return()=>f(n,t)}function we(){return le(),f(se,"SNAPSHOT",null,{expectReply:!0,timeout:0})}async function Ee(e,t={}){le();const n=K((await ye(t)).services,"user-signature");d(n,"Current user must have authorized a signing service.");try{const t=await ae(n,(e=>(d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}))(e));return Array.isArray(t)?t.map(e=>re(e)):[re(t)]}catch(e){return e}}async function Se(e,t){d(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),d(Array.isArray(t),"Must include an Array of composite signatures");let n=[],a=[],r=[];const s=await Promise.all(t.map(async e=>{d("string"==typeof e.addr,"addr must be a string"),d("number"==typeof e.keyId,"keyId must be a number"),d("string"==typeof e.signature,"signature must be a string");try{const t=await fcl.account(e.addr);return n.push(t.keys[e.keyId].weight.toFixed(1)),a.push(t.keys[e.keyId].signAlgo),r.push(e.signature),t.keys[e.keyId].publicKey}catch(e){throw e}}));return await fcl.query({cadence:"\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",args:(t,i)=>[t(e,i.String),t(s,i.Array([i.String])),t(n,i.Array(i.UFix64)),t(a,i.Array([i.UInt])),t(r,i.Array([i.String]))]})}const ve=()=>({authenticate:ye,unauthenticate:he,authorization:me,signUserMessage:Ee,verifyUserSignatures:Se,subscribe:ge,snapshot:we}),be=async e=>n([a(e)]).then(r),Re=e=>e.status>=4,Ae=e=>e.status>=3,Pe=e=>e.status>=2,ke={[m]:async e=>{const t=await be(e.self());Re(t)||setTimeout(()=>e.sendSelf("POLL"),2500),e.merge(t)},[y]:(e,t)=>{e.subscribe(t.from),e.send(t.from,E,e.all())},[h]:(e,t)=>{e.unsubscribe(t.from)},[S]:async(e,t)=>{t.reply(e.all())},POLL:async e=>{const t=await be(e.self());var n,a;Re(t)||setTimeout(()=>e.sendSelf("POLL"),2500),n=e.all(),a=t,JSON.stringify(n)!==JSON.stringify(a)&&e.broadcast(E,t),e.merge(t)}},Ie=e=>{if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ce=e=>p(ke,Ie(e));function Te(e){function t(t){return g(Ie(e),Ce,t)}function n(e){return function(n={}){const a=n.suppress||!1;return new Promise((n,r)=>{const s=t(t=>{t.statusCode&&!a?(r(t.errorMessage),s()):e(t)&&(n(t),s())})})}}return{snapshot:function(){return w(e,Ce)},subscribe:t,onceFinalized:n(Pe),onceExecuted:n(Ae),onceSealed:n(Re)}}async function Ne(t={}){try{await async function(e){d(I(e),"mutate(opts) -- opts is required"),d(C(e),"mutate(opts) -- opts must be an object"),d(I(e.cadence),"mutate({ cadence }) -- cadence is required"),d(T(e.cadence),"mutate({ cadence }) -- cadence must be a string")}(t);const n=await e.config().get("fcl.authz",ve().authorization);return e.send([e.transaction(t.cadence),e.args(_(t.args||[])),t.limit&&O(t.limit)&&e.limit(t.limit),e.proposer(t.proposer||t.authz||n),e.payer(t.payer||t.authz||n),e.authorizations(t.authorizations||[t.authz||n])]).then(e.decode)}catch(e){throw e}}Te.isUnknown=e=>e.status>=0,Te.isPending=e=>e.status>=1,Te.isFinalized=Pe,Te.isExecuted=Ae,Te.isSealed=Re,Te.isExpired=e=>5===e.status;const Oe=async(e=[],n={})=>{const a=await t.first(["sdk.resolve"],n.resolve||s);return Array.isArray(e)&&(e=await i(o(),e)),JSON.stringify(c(await a(e)),null,2)},_e=async e=>setTimeout(()=>e.sendSelf("TICK"),await t().get("fcl.eventPollRate",1e4)),xe={TICK:async e=>{if(!e.hasSubs())return;let t=e.get("hwm");if(null==t)e.put("hwm",await u()),e.put("tick",await _e(e));else{let a=await u();e.put("hwm",a);const s=await n([getEvents(e.self(),t.height,a.height-1)]).then(r);for(let t of s)e.broadcast("UPDATED",t.data);e.put("tick",await _e(e))}},[y]:async(e,t)=>{e.hasSubs()||e.put("tick",await _e(e)),e.subscribe(t.from)},[h]:(e,t)=>{e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))}},Le=e=>p(xe,e);function De(e){return{subscribe:t=>g(e,Le,t)}}const Ue=e=>ve().authenticate(e),ze=()=>ve().unauthenticate(),Fe=()=>(ve().unauthenticate(),ve().authenticate()),He=e=>ve().authenticate(),je=e=>ve().authenticate(),Be=ve().authorization,Me=l;export{P as VERSION,Ue as authenticate,Be as authz,ve as currentUser,De as events,je as logIn,Ne as mutate,x as query,Fe as reauthenticate,Oe as serialize,He as signUp,Me as t,Te as tx,ze as unauthenticate}; | ||
//# sourceMappingURL=fcl.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import*as e from"@onflow/sdk";import{config as r,send as t,getTransactionStatus as n,decode as o,resolve as i,createSignableVoucher as a,pipe as s,interaction as u,latestBlock as c}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as l}from"@onflow/util-invariant";import*as d from"@onflow/types";import{INIT as f,SUBSCRIBE as h,UNSUBSCRIBE as m,spawn as p,send as v,UPDATED as y,SNAPSHOT as g,subscriber as P,snapshoter as E}from"@onflow/util-actor";import{withPrefix as b,sansPrefix as S}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as w from"@onflow/rlp";import{uid as R}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";r().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var A="0.0.74-alpha.1",j=function(e){return function(r){return typeof r===e}},I=function(e){return null!=e},k=j("object"),C=j("string"),T=j("function"),O=j("number");function N(r){return T(r)?r(e.arg,d):[]}var x=function(r){void 0===r&&(r={});try{return Promise.resolve(function(e){try{return l(I(e.cadence),"query({ cadence }) -- cadence is required"),l(C(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(r)).then(function(){return e.send([e.script(r.cadence),e.args(N(r.args||[])),r.limit&&"number"==typeof r.limit&&e.limit(r.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function L(){return(L=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function D(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return D(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?D(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);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.")}var U={f_type:"Service",f_vsn:"1.0.0"},z={f_type:"Identity",f_vsn:"1.0.0"},F={f_type:"USER",f_vsn:"1.0.0"},H={f_type:"PollingResponse",f_vsn:"1.0.0"},B={f_type:"CompositeSignature",f_vsn:"1.0.0"};function M(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({old:e},U,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function J(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},U,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var K={"back-channel-rpc":J,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:L({},z,{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 L({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:L({},z,{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 L({},U,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:b(e.addr),name:e.name,icon:e.icon}})}},frame:M,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function q(e){return w.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function G(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function V(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var t=0,n=Object.entries(e.params||{});t<n.length;t++){var o=n[t];r.searchParams.append(o[0],o[1])}return r}function Y(e,r){void 0===r&&(r={});var t=r.method||"POST",n="GET"===t?void 0:JSON.stringify(r.data||e.data||{});return fetch(V(e),{method:t,headers:L({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function Z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},H,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:J(e.authorizationUpdates),local:M((e.local||[])[0])})}}var $="FCL_IFRAME",W=function(){},X=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Q(e,r){if(void 0===r&&(r={}),null==e)return{send:W,close:W};var t=r.onClose||W,n=r.onMessage||W,o=r.onReady||W,i=r.onResponse||W;window.addEventListener("message",c);var a=function(e){l(!document.getElementById($),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=$,r.allow="usb *; hid *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById($)&&document.getElementById($).remove()}]}(V(e)),s=a[0],u=a[1];return{send:f,close:d};function c(e){try{if("object"!=typeof e.data)return;if(X.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&d(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:f,close:d}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:f,close:d}),n(e,{send:f,close:d}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:f,close:d}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:f,close:d}),"FCL::CHALLENGE::CANCEL"===e.data.type&&d(),"FCL::CANCEL"===e.data.type&&d()}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),t()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}var ee,re=function e(r,t){void 0===t&&(t=function(){return!0});try{if(l(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(Y(r,{method:ne(r)}).then(Z)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,t)})}})}catch(e){return Promise.reject(e)}},te={"HTTP/GET":"GET","HTTP/POST":"POST"},ne=function(e){return l(te[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),te[e.method]},oe=function(e,r,t){try{return r.data=e.data,Promise.resolve(Y(e,{data:r}).then(Z)).then(function(r){if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("PENDING"===r.status){var t=!0,n=Q(r.local,{onClose:function(){t=!1}}).close;return re(r.updates,function(){return t}).then(function(e){return n(),e}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},ie=function(e,r,t){void 0===t&&(t={});try{try{return Promise.resolve(ae[e.method](e,r,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r,opts:t}),n}}catch(e){return Promise.reject(e)}},ae={"HTTP/RPC":oe,"HTTP/POST":oe,"IFRAME/RPC":function(e,r,t){return new Promise(function(n,o){var i=R(),a=t.includeOlderJsonRpcCall;r.data=e.data,Q(e,{onReady:function(t,n){var o=n.send;try{o({type:"FCL:FRAME:READY:RESPONSE",body:r,service:{params:e.params,data:e.data}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[r,e.params]})}catch(e){throw e}},onResponse:function(e,r){var t=r.close;try{if("object"!=typeof e.data)return;var i=Z(e.data);switch(i.status){case"APPROVED":n(i.data),t();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),t();break;default:o("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,r){var t=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=Z(e.data.result);switch(a.status){case"APPROVED":n(a.data),t();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),t();break;default:o("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})}};function se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},B,{addr:S(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function ue(e,r,t){if(!e.s){if(t instanceof he){if(!t.s)return void(t.o=ue.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(ue.bind(null,e,r),ue.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}function ce(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var le=function(e,r){try{l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),l(Array.isArray(r),"Must include an Array of composite signatures");var t=[],n=[];return Promise.resolve(Promise.all(r.map(function(e){try{return l("string"==typeof e.addr,"addr must be a string"),l("number"==typeof e.keyId,"keyId must be a number"),l("string"==typeof e.signature,"signature must be a string"),Promise.resolve(ce(function(){return Promise.resolve(fcl.account(e.addr)).then(function(r){return t.push(r.keys[e.keyId].weight.toFixed(1)),n.push(e.signature),r.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(r){return Promise.resolve(fcl.query({cadence:""+Ne,args:function(o,i){return[o(e,i.String),o(r,i.Array([i.String])),o(t,i.Array(i.UFix64)),o(n,i.Array([i.String]))]}}))})}catch(e){return Promise.reject(e)}},de=function(e,r){void 0===r&&(r={});try{return Re(),Promise.resolve(pe(r)).then(function(r){var t=G(r.services,"user-signature");return l(t,"Current user must have authorized a signing service."),ce(function(){return Promise.resolve(ie(t,Oe(e))).then(function(e){return Array.isArray(e)?e.map(function(e){return se(e)}):[se(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},fe=function(e){try{return Re(),Promise.resolve(pe()).then(function(r){var t=G(r.services,"authz"),n=G(r.services,"pre-authz");return L({},e,n?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(ie(n,r)).then(Ie)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:S(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(ie(t,e,{includeOlderJsonRpcCall:!0})).then(se)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},he=function(){function e(){}return e.prototype.then=function(r,t){var n=new e,o=this.s;if(o){var i=1&o?r:t;if(i){try{ue(n,1,i(this.v))}catch(e){ue(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ue(n,1,r?r(o):o):t?ue(n,1,t(o)):ue(n,2,o)}catch(e){ue(n,2,e)}},n},e}();function me(e){return e instanceof he&&1&e.s}var pe=function(e){void 0===e&&(e={});try{return Promise.resolve(new Promise(function(t,n){try{return Re(),Promise.resolve(Ce()).then(function(n){if(n.loggedIn&&Ae(n))return t(n);var o=e.serviceStrategy||Q;return Promise.resolve(r().get("discovery.wallet")).then(function(e){function n(e){o({endpoint:e},{onReady:function(e,r){var t=r.send;try{return Promise.resolve(ve(/^service\./)).then(function(e){return Promise.resolve(ve(/^app\.detail\./)).then(function(r){t({type:"FCL:AUTHN:CONFIG",services:e,app:r})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(Ce()).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 r=(e=function(e){return e.addr=e.addr?b(e.addr):null,e.paddr=e.paddr?b(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",r),Promise.resolve(fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var t,n=_(e.authorizations);!(t=n()).done;)r.push(L({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(L({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(t){var n,o,i=(n=r,o=t,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(r){return function(e,r){try{return K[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),a=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,i);return L({},F,{addr:b(e.addr),cid:q(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return v(ye,Pe,e),Promise.resolve(Ce()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})}return e?n(e):Promise.resolve(r().get("challenge.handshake")).then(n)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ve=function(e){try{return Promise.resolve(r().where(e)).then(function(r){return Object.fromEntries(Object.entries(r).map(function(r){var t=r[1];return[r[0].replace(e,""),t]}))})}catch(e){return Promise.reject(e)}},ye="CURRENT_USER",ge="CURRENT_USER/UPDATED",Pe="SET_CURRENT_USER",Ee='{\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}',be=function(e){try{return sessionStorage.setItem(ye,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Se=function(){return r().get("persistSession",!0)},we=((ee={})[f]=function(e){try{return e.merge(JSON.parse(Ee)),Promise.resolve(Se()).then(function(r){var t=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(Ee),r=JSON.parse(sessionStorage.getItem(ye));return null!=r&&e.f_vsn!==r.f_vsn?(sessionStorage.removeItem(ye),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){Ae(r)&&e.merge(r)})}();if(t&&t.then)return t.then(function(){})})}catch(e){return Promise.reject(e)}},ee[h]=function(e,r){e.subscribe(r.from),e.send(r.from,ge,L({},e.all()))},ee[m]=function(e,r){e.unsubscribe(r.from)},ee.SNAPSHOT=function(e,r){try{return r.reply(L({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},ee[Pe]=function(e,r,t){try{return e.merge(t),Promise.resolve(Se()).then(function(r){r&&be(e.all()),e.broadcast(ge,L({},e.all()))})}catch(e){return Promise.reject(e)}},ee.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(Ee)),Promise.resolve(Se()).then(function(r){r&&be(e.all()),e.broadcast(ge,L({},e.all()))})}catch(e){return Promise.reject(e)}},ee),Re=function(){return p(we,ye)};function Ae(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function je(){Re(),v(ye,"DEL_CURRENT_USER")}function Ie(e){var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),t=[];null!=r.proposer&&t.push(["PROPOSER",r.proposer]);for(var n,o=_(r.payer||[]);!(n=o()).done;)t.push(["PAYER",n.value]);for(var i,a=_(r.authorization||[]);!(i=a()).done;)t.push(["AUTHORIZER",i.value]);return t.map(function(e){var r=e[0],t=e[1];return{tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:function(e){return ie(t,e)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}})}function ke(e){Re();var r="@EXIT",t=p(function(t){try{var n;return t.send(ye,h),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(me(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!me(i)){n=1;break}i=i.s}}var a=new he,s=ue.bind(null,a,2);return(0===n?o.then(c):1===n?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):ue(a,1,i)})).then(void 0,s),a;function u(r){i=r;do{if(!(o=e())||me(o)&&!o.v)return void ue(a,1,i);if(o.then)return void o.then(c).then(void 0,s);me(i=t())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=t())&&i.then?i.then(u).then(void 0,s):u(i):ue(a,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(o){if(o.tag===r)return t.send(ye,m),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(t,r)}}function Ce(){return Re(),v(ye,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Te,Oe=function(e){return l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Ne="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: SignatureAlgorithm.ECDSA_P256\n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",xe=function(){return{authenticate:pe,unauthenticate:je,authorization:fe,signUserMessage:de,verifyUserSignatures:le,subscribe:ke,snapshot:Ce}},Le=function(e){try{return Promise.resolve(t([n(e)]).then(o))}catch(e){return Promise.reject(e)}},De=function(e){return e.status>=4},_e=function(e){return e.status>=3},Ue=function(e){return e.status>=2},ze=((Te={})[f]=function(e){try{return Promise.resolve(Le(e.self())).then(function(r){De(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},Te[h]=function(e,r){e.subscribe(r.from),e.send(r.from,y,e.all())},Te[m]=function(e,r){e.unsubscribe(r.from)},Te[g]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Te.POLL=function(e){try{return Promise.resolve(Le(e.self())).then(function(r){var t,n;De(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(y,r),e.merge(r)})}catch(e){return Promise.reject(e)}},Te),Fe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},He=function(e){return p(ze,Fe(e))};function Be(e){function r(r){return P(Fe(e),He,r)}function t(e){return function(t){void 0===t&&(t={});var n=t.suppress||!1;return new Promise(function(t,o){var i=r(function(r){r.statusCode&&!n?(o(r.errorMessage),i()):e(r)&&(t(r),i())})})}}return{snapshot:function(){return E(e,He)},subscribe:r,onceFinalized:t(Ue),onceExecuted:t(_e),onceSealed:t(De)}}Be.isUnknown=function(e){return e.status>=0},Be.isPending=function(e){return e.status>=1},Be.isFinalized=Ue,Be.isExecuted=_e,Be.isSealed=De,Be.isExpired=function(e){return 5===e.status};var Me,Je=function(r){void 0===r&&(r={});try{return Promise.resolve(function(t,n){try{var o=Promise.resolve(function(e){try{return l(I(e),"mutate(opts) -- opts is required"),l(k(e),"mutate(opts) -- opts must be an object"),l(I(e.cadence),"mutate({ cadence }) -- cadence is required"),l(C(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(r)).then(function(){return Promise.resolve(e.config().get("fcl.authz",xe().authorization)).then(function(t){return e.send([e.transaction(r.cadence),e.args(N(r.args||[])),r.limit&&O(r.limit)&&e.limit(r.limit),e.proposer(r.proposer||r.authz||t),e.payer(r.payer||r.authz||t),e.authorizations(r.authorizations||[r.authz||t])]).then(e.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},Ke=function(e,t){void 0===e&&(e=[]),void 0===t&&(t={});try{return Promise.resolve(r().get("sdk.resolve",t.resolve||i)).then(function(r){function t(){return Promise.resolve(r(e)).then(function(e){return JSON.stringify(a(e),null,2)})}var n=function(){if(Array.isArray(e))return Promise.resolve(s(u(),e)).then(function(r){e=r})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},qe=function(e){try{var t=setTimeout;return Promise.resolve(r().get("fcl.eventPollRate",1e4)).then(function(r){return t(function(){return e.sendSelf("TICK")},r)})}catch(e){return Promise.reject(e)}},Ge=((Me={}).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(c()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(qe(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(c()).then(function(n){return e.put("hwm",n),Promise.resolve(t([getEvents(e.self(),r.height,n.height-1)]).then(o)).then(function(r){for(var t,n=_(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(qe(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Me[h]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(qe(e)).then(function(t){r.call(e,"tick",t)})}}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},Me[m]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Me),Ve=function(e){return p(Ge,e)};function Ye(e){return{subscribe:function(r){return P(e,Ve,r)}}}var Ze=function(e){return xe().authenticate(e)},$e=function(){return xe().unauthenticate()},We=function(){return xe().unauthenticate(),xe().authenticate()},Xe=function(e){return xe().authenticate()},Qe=function(e){return xe().authenticate()},er=xe().authorization,rr=d;export{A as VERSION,Ze as authenticate,er as authz,xe as currentUser,Ye as events,Qe as logIn,Je as mutate,x as query,We as reauthenticate,Ke as serialize,Xe as signUp,rr as t,Be as tx,$e as unauthenticate}; | ||
import*as e from"@onflow/sdk";import{config as r,send as t,getTransactionStatus as n,decode as o,resolve as i,createSignableVoucher as a,pipe as s,interaction as u,latestBlock as c}from"@onflow/sdk";export{TestUtils,account,arg,args,atBlockHeight,atBlockId,authorization,authorizations,build,config,createSignableVoucher,decode,getAccount,getBlock,getBlockByHeight,getBlockById,getBlockHeader,getCollection,getEvents,getEventsAtBlockHeightRange,getEventsAtBlockIds,getLatestBlock,getTransaction,getTransactionStatus,invariant,isBad,isOk,latestBlock,limit,param,params,payer,ping,pipe,proposer,ref,script,send,transaction,validator,why}from"@onflow/sdk";import{invariant as l}from"@onflow/util-invariant";import*as d from"@onflow/types";import{INIT as f,SUBSCRIBE as h,UNSUBSCRIBE as m,spawn as p,send as v,UPDATED as y,SNAPSHOT as g,subscriber as P,snapshoter as E}from"@onflow/util-actor";import{withPrefix as b,sansPrefix as S}from"@onflow/util-address";export{display,sansPrefix,withPrefix}from"@onflow/util-address";import*as w from"@onflow/rlp";import{uid as A}from"@onflow/util-uid";export{template as cadence,template as cdc}from"@onflow/util-template";r().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var R="0.0.74-alpha.2",I=function(e){return function(r){return typeof r===e}},k=function(e){return null!=e},j=I("object"),C=I("string"),T=I("function"),O=I("number");function N(r){return T(r)?r(e.arg,d):[]}var x=function(r){void 0===r&&(r={});try{return Promise.resolve(function(e){try{return l(k(e.cadence),"query({ cadence }) -- cadence is required"),l(C(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(r)).then(function(){return e.send([e.script(r.cadence),e.args(N(r.args||[])),r.limit&&"number"==typeof r.limit&&e.limit(r.limit)]).then(e.decode)})}catch(e){return Promise.reject(e)}};function L(){return(L=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function D(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return D(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?D(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);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.")}var U={f_type:"Service",f_vsn:"1.0.0"},z={f_type:"Identity",f_vsn:"1.0.0"},F={f_type:"USER",f_vsn:"1.0.0"},H={f_type:"PollingResponse",f_vsn:"1.0.0"},B={f_type:"CompositeSignature",f_vsn:"1.0.0"};function M(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({old:e},U,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function J(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},U,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var K={"back-channel-rpc":J,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:L({},z,{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 L({},U,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:L({},z,{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 L({},U,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:b(e.addr),name:e.name,icon:e.icon}})}},frame:M,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function q(e){return w.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function G(e,r){return void 0===e&&(e=[]),e.find(function(e){return e.type===r})}function V(e){var r=new URL(e.endpoint);if(r.searchParams.append("l6n",window.location.origin),null!=e.params)for(var t=0,n=Object.entries(e.params||{});t<n.length;t++){var o=n[t];r.searchParams.append(o[0],o[1])}return r}function Y(e,r){void 0===r&&(r={});var t=r.method||"POST",n="GET"===t?void 0:JSON.stringify(r.data||e.data||{});return fetch(V(e),{method:t,headers:L({},e.headers||{},r.headers||{},{"Content-Type":"application/json"}),body:n}).then(function(e){return e.json()})}function Z(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},H,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:J(e.authorizationUpdates),local:M((e.local||[])[0])})}}var $="FCL_IFRAME",W=function(){},X=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function Q(e,r){if(void 0===r&&(r={}),null==e)return{send:W,close:W};var t=r.onClose||W,n=r.onMessage||W,o=r.onReady||W,i=r.onResponse||W;window.addEventListener("message",c);var a=function(e){l(!document.getElementById($),"Attempt at triggering multiple Frames",{src:e});var r=document.createElement("iframe");return r.src=e,r.id=$,r.allow="usb *; hid *",r.frameBorder="0",r.style.cssText="\n position:fixed;\n top: 0px;\n right: 0px;\n bottom: 0px;\n left: 0px;\n height: 100vh;\n width: 100vw;\n display:block;\n background:rgba(0,0,0,0.25);\n z-index: 2147483647;\n box-sizing: border-box;\n",document.body.append(r),[r,function(){document.getElementById($)&&document.getElementById($).remove()}]}(V(e)),s=a[0],u=a[1];return{send:f,close:d};function c(e){try{if("object"!=typeof e.data)return;if(X.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&d(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:f,close:d}),"FCL:FRAME:RESPONSE"===e.data.type&&i(e,{send:f,close:d}),n(e,{send:f,close:d}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&i(e,{send:f,close:d}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:f,close:d}),"FCL::CHALLENGE::CANCEL"===e.data.type&&d(),"FCL::CANCEL"===e.data.type&&d()}catch(e){console.error("Frame Callback Error",e),d()}}function d(){try{window.removeEventListener("message",c),u(),t()}catch(e){console.error("Frame Close Error",e)}}function f(e){try{s.contentWindow.postMessage(JSON.parse(JSON.stringify(e||{})),"*")}catch(r){console.error("Frame Send Error",e,r)}}}var ee,re=function e(r,t){void 0===t&&(t=function(){return!0});try{if(l(r,"Missing Polling Service",{service:r}),!t())throw new Error("Externally Halted");return Promise.resolve(Y(r,{method:ne(r)}).then(Z)).then(function(r){switch(r.status){case"APPROVED":return r.data;case"DECLINED":throw new Error("Declined: "+(r.reason||"No reason supplied."));default:return Promise.resolve(new Promise(function(e){return setTimeout(e,500)})).then(function(){return e(r.updates,t)})}})}catch(e){return Promise.reject(e)}},te={"HTTP/GET":"GET","HTTP/POST":"POST"},ne=function(e){return l(te[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),te[e.method]},oe=function(e,r,t){try{return r.data=e.data,Promise.resolve(Y(e,{data:r}).then(Z)).then(function(r){if("APPROVED"===r.status)return r.data;if("DECLINED"===r.status)throw new Error("Declined: "+(r.reason||"No reason supplied."));if("PENDING"===r.status){var t=!0,n=Q(r.local,{onClose:function(){t=!1}}).close;return re(r.updates,function(){return t}).then(function(e){return n(),e}).catch(function(e){throw console.error(e),n(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:r}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},ie=function(e,r,t){void 0===t&&(t={});try{try{return Promise.resolve(ae[e.method](e,r,t))}catch(n){throw console.error("execService(service, msg)",n,{service:e,msg:r,opts:t}),n}}catch(e){return Promise.reject(e)}},ae={"HTTP/RPC":oe,"HTTP/POST":oe,"IFRAME/RPC":function(e,r,t){return new Promise(function(n,o){var i=A(),a=t.includeOlderJsonRpcCall;r.data=e.data,Q(e,{onReady:function(t,n){var o=n.send;try{o({type:"FCL:FRAME:READY:RESPONSE",body:r,service:{params:e.params,data:e.data}}),a&&o({jsonrpc:"2.0",id:i,method:"fcl:sign",params:[r,e.params]})}catch(e){throw e}},onResponse:function(e,r){var t=r.close;try{if("object"!=typeof e.data)return;var i=Z(e.data);switch(i.status){case"APPROVED":n(i.data),t();break;case"DECLINED":o("Declined: "+(i.reason||"No reason supplied")),t();break;default:o("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,r){var t=r.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==i)return;var a=Z(e.data.result);switch(a.status){case"APPROVED":n(a.data),t();break;case"DECLINED":o("Declined: "+(a.reason||"No reason supplied")),t();break;default:o("Declined: No reason supplied"),t()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){o("Declined: Externally Halted")}})})}};function se(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return L({},B,{addr:S(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function ue(e,r,t){if(!e.s){if(t instanceof he){if(!t.s)return void(t.o=ue.bind(null,e,r));1&r&&(r=t.s),t=t.v}if(t&&t.then)return void t.then(ue.bind(null,e,r),ue.bind(null,e,2));e.s=r,e.v=t;var n=e.o;n&&n(e)}}function ce(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var le=function(e,r){try{l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),l(Array.isArray(r),"Must include an Array of composite signatures");var t=[],n=[],o=[];return Promise.resolve(Promise.all(r.map(function(e){try{return l("string"==typeof e.addr,"addr must be a string"),l("number"==typeof e.keyId,"keyId must be a number"),l("string"==typeof e.signature,"signature must be a string"),Promise.resolve(ce(function(){return Promise.resolve(fcl.account(e.addr)).then(function(r){return t.push(r.keys[e.keyId].weight.toFixed(1)),n.push(r.keys[e.keyId].signAlgo),o.push(e.signature),r.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(r){return Promise.resolve(fcl.query({cadence:""+Ne,args:function(i,a){return[i(e,a.String),i(r,a.Array([a.String])),i(t,a.Array(a.UFix64)),i(n,a.Array([a.UInt])),i(o,a.Array([a.String]))]}}))})}catch(e){return Promise.reject(e)}},de=function(e,r){void 0===r&&(r={});try{return Ae(),Promise.resolve(pe(r)).then(function(r){var t=G(r.services,"user-signature");return l(t,"Current user must have authorized a signing service."),ce(function(){return Promise.resolve(ie(t,Oe(e))).then(function(e){return Array.isArray(e)?e.map(function(e){return se(e)}):[se(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},fe=function(e){try{return Ae(),Promise.resolve(pe()).then(function(r){var t=G(r.services,"authz"),n=G(r.services,"pre-authz");return L({},e,n?{tempId:"CURRENT_USER",resolve:function(e,r){try{return Promise.resolve(ie(n,r)).then(ke)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:S(t.identity.address),keyId:t.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(ie(t,e,{includeOlderJsonRpcCall:!0})).then(se)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},he=function(){function e(){}return e.prototype.then=function(r,t){var n=new e,o=this.s;if(o){var i=1&o?r:t;if(i){try{ue(n,1,i(this.v))}catch(e){ue(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?ue(n,1,r?r(o):o):t?ue(n,1,t(o)):ue(n,2,o)}catch(e){ue(n,2,e)}},n},e}();function me(e){return e instanceof he&&1&e.s}var pe=function(e){void 0===e&&(e={});try{return Promise.resolve(new Promise(function(t,n){try{return Ae(),Promise.resolve(Ce()).then(function(n){if(n.loggedIn&&Re(n))return t(n);var o=e.serviceStrategy||Q;return Promise.resolve(r.first(["discovery.wallet","challenge.handshake"])).then(function(e){o({endpoint:e},{onReady:function(e,r){var t=r.send;try{return Promise.resolve(ve(/^service\./)).then(function(e){return Promise.resolve(ve(/^app\.detail\./)).then(function(r){t({type:"FCL:AUTHN:CONFIG",services:e,app:r})})})}catch(e){return Promise.reject(e)}},onClose:function(){try{return Promise.resolve(Ce()).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 r=(e=function(e){return e.addr=e.addr?b(e.addr):null,e.paddr=e.paddr?b(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,r){try{if(null==e||null==r)return Promise.resolve([]);var t=new URL(e);return t.searchParams.append("code",r),Promise.resolve(fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}}).then(function(e){return e.json()})).then(function(e){if(Array.isArray(e))return e;var r=[];if(Array.isArray(e.authorizations))for(var t,n=_(e.authorizations);!(t=n()).done;)r.push(L({type:"authz",keyId:e.keyId},t.value));return null!=e.provider&&r.push(L({type:"authn",id:"wallet-provider#authn"},e.provider)),r})}catch(e){return Promise.reject(e)}}(e.hks,e.code)).then(function(t){var n,o,i=(n=r,o=t,void 0===n&&(n=[]),void 0===o&&(o=[]),[].concat(n,o)).map(function(r){return function(e,r){try{return K[e.type](e,r)}catch(r){return console.error("Unrecognized FCL Service Type ["+e.type+"]",e,r),e}}(r,e)}),a=function(e,r){return r.find(function(e){return"authn"===e.type})}(0,i);return L({},F,{addr:b(e.addr),cid:q(a),loggedIn:!0,services:i,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return v(ye,Pe,e),Promise.resolve(Ce()).then(function(e){t(e),n()})})}catch(e){return Promise.reject(e)}}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ve=function(e){try{return Promise.resolve(r().where(e)).then(function(r){return Object.fromEntries(Object.entries(r).map(function(r){var t=r[1];return[r[0].replace(e,""),t]}))})}catch(e){return Promise.reject(e)}},ye="CURRENT_USER",ge="CURRENT_USER/UPDATED",Pe="SET_CURRENT_USER",Ee='{\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}',be=function(e){try{return sessionStorage.setItem(ye,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},Se=function(){return r().get("persistSession",!0)},we=((ee={})[f]=function(e){try{return e.merge(JSON.parse(Ee)),Promise.resolve(Se()).then(function(r){var t=function(){if(r)return Promise.resolve(function(){try{var e=JSON.parse(Ee),r=JSON.parse(sessionStorage.getItem(ye));return null!=r&&e.f_vsn!==r.f_vsn?(sessionStorage.removeItem(ye),Promise.resolve(e)):Promise.resolve(r||e)}catch(e){return Promise.reject(e)}}()).then(function(r){Re(r)&&e.merge(r)})}();if(t&&t.then)return t.then(function(){})})}catch(e){return Promise.reject(e)}},ee[h]=function(e,r){e.subscribe(r.from),e.send(r.from,ge,L({},e.all()))},ee[m]=function(e,r){e.unsubscribe(r.from)},ee.SNAPSHOT=function(e,r){try{return r.reply(L({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},ee[Pe]=function(e,r,t){try{return e.merge(t),Promise.resolve(Se()).then(function(r){r&&be(e.all()),e.broadcast(ge,L({},e.all()))})}catch(e){return Promise.reject(e)}},ee.DEL_CURRENT_USER=function(e,r){try{return e.merge(JSON.parse(Ee)),Promise.resolve(Se()).then(function(r){r&&be(e.all()),e.broadcast(ge,L({},e.all()))})}catch(e){return Promise.reject(e)}},ee),Ae=function(){return p(we,ye)};function Re(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function Ie(){Ae(),v(ye,"DEL_CURRENT_USER")}function ke(e){var r=function(e){return{f_type:"PreAuthzResponse",f_vsn:"1.0.0",proposer:(e||{}).proposer,payer:(e||{}).payer||[],authorization:(e||{}).authorization||[]}}(e),t=[];null!=r.proposer&&t.push(["PROPOSER",r.proposer]);for(var n,o=_(r.payer||[]);!(n=o()).done;)t.push(["PAYER",n.value]);for(var i,a=_(r.authorization||[]);!(i=a()).done;)t.push(["AUTHORIZER",i.value]);return t.map(function(e){var r=e[0],t=e[1];return{tempId:[t.identity.address,t.identity.keyId].join("|"),addr:t.identity.address,keyId:t.identity.keyId,signingFunction:function(e){return ie(t,e)},role:{proposer:"PROPOSER"===r,payer:"PAYER"===r,authorizer:"AUTHORIZER"===r}}})}function je(e){Ae();var r="@EXIT",t=p(function(t){try{var n;return t.send(ye,h),Promise.resolve(function(e,r,t){for(var n;;){var o=e();if(me(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=t();if(i&&i.then){if(!me(i)){n=1;break}i=i.s}}var a=new he,s=ue.bind(null,a,2);return(0===n?o.then(c):1===n?i.then(u):(void 0).then(function(){(o=e())?o.then?o.then(c).then(void 0,s):c(o):ue(a,1,i)})).then(void 0,s),a;function u(r){i=r;do{if(!(o=e())||me(o)&&!o.v)return void ue(a,1,i);if(o.then)return void o.then(c).then(void 0,s);me(i=t())&&(i=i.v)}while(!i||!i.then);i.then(u).then(void 0,s)}function c(e){e?(i=t())&&i.then?i.then(u).then(void 0,s):u(i):ue(a,1,i)}}(function(){return!n&&1},0,function(){return Promise.resolve(t.receive()).then(function(o){if(o.tag===r)return t.send(ye,m),void(n=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return v(t,r)}}function Ce(){return Ae(),v(ye,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var Te,Oe=function(e){return l(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},Ne="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",xe=function(){return{authenticate:pe,unauthenticate:Ie,authorization:fe,signUserMessage:de,verifyUserSignatures:le,subscribe:je,snapshot:Ce}},Le=function(e){try{return Promise.resolve(t([n(e)]).then(o))}catch(e){return Promise.reject(e)}},De=function(e){return e.status>=4},_e=function(e){return e.status>=3},Ue=function(e){return e.status>=2},ze=((Te={})[f]=function(e){try{return Promise.resolve(Le(e.self())).then(function(r){De(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),e.merge(r)})}catch(e){return Promise.reject(e)}},Te[h]=function(e,r){e.subscribe(r.from),e.send(r.from,y,e.all())},Te[m]=function(e,r){e.unsubscribe(r.from)},Te[g]=function(e,r){try{return r.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},Te.POLL=function(e){try{return Promise.resolve(Le(e.self())).then(function(r){var t,n;De(r)||setTimeout(function(){return e.sendSelf("POLL")},2500),t=e.all(),n=r,JSON.stringify(t)!==JSON.stringify(n)&&e.broadcast(y,r),e.merge(r)})}catch(e){return Promise.reject(e)}},Te),Fe=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},He=function(e){return p(ze,Fe(e))};function Be(e){function r(r){return P(Fe(e),He,r)}function t(e){return function(t){void 0===t&&(t={});var n=t.suppress||!1;return new Promise(function(t,o){var i=r(function(r){r.statusCode&&!n?(o(r.errorMessage),i()):e(r)&&(t(r),i())})})}}return{snapshot:function(){return E(e,He)},subscribe:r,onceFinalized:t(Ue),onceExecuted:t(_e),onceSealed:t(De)}}Be.isUnknown=function(e){return e.status>=0},Be.isPending=function(e){return e.status>=1},Be.isFinalized=Ue,Be.isExecuted=_e,Be.isSealed=De,Be.isExpired=function(e){return 5===e.status};var Me,Je=function(r){void 0===r&&(r={});try{return Promise.resolve(function(t,n){try{var o=Promise.resolve(function(e){try{return l(k(e),"mutate(opts) -- opts is required"),l(j(e),"mutate(opts) -- opts must be an object"),l(k(e.cadence),"mutate({ cadence }) -- cadence is required"),l(C(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(r)).then(function(){return Promise.resolve(e.config().get("fcl.authz",xe().authorization)).then(function(t){return e.send([e.transaction(r.cadence),e.args(N(r.args||[])),r.limit&&O(r.limit)&&e.limit(r.limit),e.proposer(r.proposer||r.authz||t),e.payer(r.payer||r.authz||t),e.authorizations(r.authorizations||[r.authz||t])]).then(e.decode)})})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},Ke=function(e,t){void 0===e&&(e=[]),void 0===t&&(t={});try{return Promise.resolve(r.first(["sdk.resolve"],t.resolve||i)).then(function(r){function t(){return Promise.resolve(r(e)).then(function(e){return JSON.stringify(a(e),null,2)})}var n=function(){if(Array.isArray(e))return Promise.resolve(s(u(),e)).then(function(r){e=r})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},qe=function(e){try{var t=setTimeout;return Promise.resolve(r().get("fcl.eventPollRate",1e4)).then(function(r){return t(function(){return e.sendSelf("TICK")},r)})}catch(e){return Promise.reject(e)}},Ge=((Me={}).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(c()).then(function(r){n.call(e,"hwm",r);var t=e.put;return Promise.resolve(qe(e)).then(function(r){t.call(e,"tick",r)})})}return Promise.resolve(c()).then(function(n){return e.put("hwm",n),Promise.resolve(t([getEvents(e.self(),r.height,n.height-1)]).then(o)).then(function(r){for(var t,n=_(r);!(t=n()).done;)e.broadcast("UPDATED",t.value.data);var o=e.put;return Promise.resolve(qe(e)).then(function(r){o.call(e,"tick",r)})})})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Me[h]=function(e,r){try{var t=function(){e.subscribe(r.from)},n=function(){if(!e.hasSubs()){var r=e.put;return Promise.resolve(qe(e)).then(function(t){r.call(e,"tick",t)})}}();return Promise.resolve(n&&n.then?n.then(t):t())}catch(e){return Promise.reject(e)}},Me[m]=function(e,r){e.unsubscribe(r.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Me),Ve=function(e){return p(Ge,e)};function Ye(e){return{subscribe:function(r){return P(e,Ve,r)}}}var Ze=function(e){return xe().authenticate(e)},$e=function(){return xe().unauthenticate()},We=function(){return xe().unauthenticate(),xe().authenticate()},Xe=function(e){return xe().authenticate()},Qe=function(e){return xe().authenticate()},er=xe().authorization,rr=d;export{R as VERSION,Ze as authenticate,er as authz,xe as currentUser,Ye as events,Qe as logIn,Je as mutate,x as query,We as reauthenticate,Ke as serialize,Xe as signUp,rr as t,Be as tx,$e as unauthenticate}; | ||
//# sourceMappingURL=fcl.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,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/sdk","@onflow/util-invariant","@onflow/types","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-uid","@onflow/util-template"],t):t((e||self).fcl={},e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,i,o,u,a,c){function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var l=s(t),f=s(r),d=s(u);t.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var p=function(e){return function(t){return typeof t===e}},h=function(e){return null!=e},m=p("object"),v=p("string"),y=p("function"),g=p("number");function P(e){return y(e)?e(l.arg,f):[]}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 j(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 E(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return j(e,t);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)?j(e,t):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.")}var S={f_type:"Service",f_vsn:"1.0.0"},w={f_type:"Identity",f_vsn:"1.0.0"},O={f_type:"USER",f_vsn:"1.0.0"},R={f_type:"PollingResponse",f_vsn:"1.0.0"},I={f_type:"CompositeSignature",f_vsn:"1.0.0"};function k(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({old:e},S,{type:"frame",endpoint:e.endpoint,params:e.params||{},data:e.data||{}})}}function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},S,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var C={"back-channel-rpc":A,"pre-authz":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.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({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.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({},S,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:k,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function T(e){return d.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 n=0,r=Object.entries(e.params||{});n<r.length;n++){var i=r[n];t.searchParams.append(i[0],i[1])}return t}function x(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(U(e),{method:n,headers:b({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:A(e.authorizationUpdates),local:k((e.local||[])[0])})}}var D="FCL_IFRAME",_=function(){},L=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function z(e,t){if(void 0===t&&(t={}),null==e)return{send:_,close:_};var r=t.onClose||_,i=t.onMessage||_,o=t.onReady||_,u=t.onResponse||_;window.addEventListener("message",l);var a=function(e){n.invariant(!document.getElementById(D),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=D,t.allow="usb *; hid *",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(D)&&document.getElementById(D).remove()}]}(U(e)),c=a[0],s=a[1];return{send:d,close:f};function l(e){try{if("object"!=typeof e.data)return;if(L.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:f}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:f}),i(e,{send:d,close:f}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:f}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",l),s(),r()}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 F,H=function e(t,r){void 0===r&&(r=function(){return!0});try{if(n.invariant(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(x(t,{method:q(t)}).then(B)).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)}},M={"HTTP/GET":"GET","HTTP/POST":"POST"},q=function(e){return n.invariant(M[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),M[e.method]},J=function(e,t,n){try{return t.data=e.data,Promise.resolve(x(e,{data:t}).then(B)).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,r=z(t.local,{onClose:function(){n=!1}}).close;return H(t.updates,function(){return n}).then(function(e){return r(),e}).catch(function(e){throw console.error(e),r(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},K=function(e,t,n){void 0===n&&(n={});try{try{return Promise.resolve(G[e.method](e,t,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t,opts:n}),r}}catch(e){return Promise.reject(e)}},G={"HTTP/RPC":J,"HTTP/POST":J,"IFRAME/RPC":function(e,t,n){return new Promise(function(r,i){var o=a.uid(),u=n.includeOlderJsonRpcCall;t.data=e.data,z(e,{onReady:function(n,r){var i=r.send;try{i({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data}}),u&&i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;var o=B(e.data);switch(o.status){case"APPROVED":r(o.data),n();break;case"DECLINED":i("Declined: "+(o.reason||"No reason supplied")),n();break;default:i("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=B(e.data.result);switch(u.status){case"APPROVED":r(u.data),n();break;case"DECLINED":i("Declined: "+(u.reason||"No reason supplied")),n();break;default:i("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){i("Declined: Externally Halted")}})})}};function V(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function Y(e,t,n){if(!e.s){if(n instanceof Q){if(!n.s)return void(n.o=Y.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Y.bind(null,e,t),Y.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}function $(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Z=function(e,t){try{n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),n.invariant(Array.isArray(t),"Must include an Array of composite signatures");var r=[],i=[];return Promise.resolve(Promise.all(t.map(function(e){try{return n.invariant("string"==typeof e.addr,"addr must be a string"),n.invariant("number"==typeof e.keyId,"keyId must be a number"),n.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve($(function(){return Promise.resolve(fcl.account(e.addr)).then(function(t){return r.push(t.keys[e.keyId].weight.toFixed(1)),i.push(e.signature),t.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(fcl.query({cadence:""+ge,args:function(n,o){return[n(e,o.String),n(t,o.Array([o.String])),n(r,o.Array(o.UFix64)),n(i,o.Array([o.String]))]}}))})}catch(e){return Promise.reject(e)}},W=function(e,t){void 0===t&&(t={});try{return le(),Promise.resolve(te(t)).then(function(t){var r=N(t.services,"user-signature");return n.invariant(r,"Current user must have authorized a signing service."),$(function(){return Promise.resolve(K(r,ye(e))).then(function(e){return Array.isArray(e)?e.map(function(e){return V(e)}):[V(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},X=function(e){try{return le(),Promise.resolve(te()).then(function(t){var n=N(t.services,"authz"),r=N(t.services,"pre-authz");return b({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(K(r,t)).then(pe)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(K(n,e,{includeOlderJsonRpcCall:!0})).then(V)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Q=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{Y(r,1,o(this.v))}catch(e){Y(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?Y(r,1,t?t(i):i):n?Y(r,1,n(i)):Y(r,2,i)}catch(e){Y(r,2,e)}},r},e}();function ee(e){return e instanceof Q&&1&e.s}var te=function(e){void 0===e&&(e={});try{return Promise.resolve(new Promise(function(n,r){try{return le(),Promise.resolve(me()).then(function(r){if(r.loggedIn&&fe(r))return n(r);var u=e.serviceStrategy||z;return Promise.resolve(t.config().get("discovery.wallet")).then(function(e){function r(e){u({endpoint:e},{onReady:function(e,t){var n=t.send;try{return Promise.resolve(ne(/^service\./)).then(function(e){return Promise.resolve(ne(/^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(me()).then(function(e){n(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,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=E(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,i,u=(r=t,i=n,void 0===r&&(r=[]),void 0===i&&(i=[]),[].concat(r,i)).map(function(t){return function(e,t){try{return C[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 b({},O,{addr:o.withPrefix(e.addr),cid:T(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return i.send(re,oe,e),Promise.resolve(me()).then(function(e){n(e),r()})})}catch(e){return Promise.reject(e)}}})}return e?r(e):Promise.resolve(t.config().get("challenge.handshake")).then(r)})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ne=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)}},re="CURRENT_USER",ie="CURRENT_USER/UPDATED",oe="SET_CURRENT_USER",ue='{\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}',ae=function(e){try{return sessionStorage.setItem(re,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},ce=function(){return t.config().get("persistSession",!0)},se=((F={})[i.INIT]=function(e){try{return e.merge(JSON.parse(ue)),Promise.resolve(ce()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ue),t=JSON.parse(sessionStorage.getItem(re));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(re),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)}},F[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,ie,b({},e.all()))},F[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},F.SNAPSHOT=function(e,t){try{return t.reply(b({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},F[oe]=function(e,t,n){try{return e.merge(n),Promise.resolve(ce()).then(function(t){t&&ae(e.all()),e.broadcast(ie,b({},e.all()))})}catch(e){return Promise.reject(e)}},F.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ue)),Promise.resolve(ce()).then(function(t){t&&ae(e.all()),e.broadcast(ie,b({},e.all()))})}catch(e){return Promise.reject(e)}},F),le=function(){return i.spawn(se,re)};function fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function de(){le(),i.send(re,"DEL_CURRENT_USER")}function pe(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,i=E(t.payer||[]);!(r=i()).done;)n.push(["PAYER",r.value]);for(var o,u=E(t.authorization||[]);!(o=u()).done;)n.push(["AUTHORIZER",o.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 K(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function he(e){le();var t="@EXIT",n=i.spawn(function(n){try{var r;return n.send(re,i.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var i=e();if(ee(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!ee(o)){r=1;break}o=o.s}}var u=new Q,a=Y.bind(null,u,2);return(0===r?i.then(s):1===r?o.then(c):(void 0).then(function(){(i=e())?i.then?i.then(s).then(void 0,a):s(i):Y(u,1,o)})).then(void 0,a),u;function c(t){o=t;do{if(!(i=e())||ee(i)&&!i.v)return void Y(u,1,o);if(i.then)return void i.then(s).then(void 0,a);ee(o=n())&&(o=o.v)}while(!o||!o.then);o.then(c).then(void 0,a)}function s(e){e?(o=n())&&o.then?o.then(c).then(void 0,a):c(o):Y(u,1,o)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if(o.tag===t)return n.send(re,i.UNSUBSCRIBE),void(r=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return i.send(n,t)}}function me(){return le(),i.send(re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ve,ye=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},ge="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: SignatureAlgorithm.ECDSA_P256\n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",Pe=function(){return{authenticate:te,unauthenticate:de,authorization:X,signUserMessage:W,verifyUserSignatures:Z,subscribe:he,snapshot:me}},be="POLL",je=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},Ee=function(e){return e.status>=4},Se=function(e){return e.status>=3},we=function(e){return e.status>=2},Oe=((ve={})[i.INIT]=function(e){try{return Promise.resolve(je(e.self())).then(function(t){Ee(t)||setTimeout(function(){return e.sendSelf(be)},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},ve[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,i.UPDATED,e.all())},ve[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},ve[i.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ve.POLL=function(e){try{return Promise.resolve(je(e.self())).then(function(t){var n,r;Ee(t)||setTimeout(function(){return e.sendSelf(be)},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)}},ve),Re=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Ie=function(e){return i.spawn(Oe,Re(e))};function ke(e){function t(t){return i.subscriber(Re(e),Ie,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,i){var o=t(function(t){t.statusCode&&!r?(i(t.errorMessage),o()):e(t)&&(n(t),o())})})}}return{snapshot:function(){return i.snapshoter(e,Ie)},subscribe:t,onceFinalized:n(we),onceExecuted:n(Se),onceSealed:n(Ee)}}ke.isUnknown=function(e){return e.status>=0},ke.isPending=function(e){return e.status>=1},ke.isFinalized=we,ke.isExecuted=Se,ke.isSealed=Ee,ke.isExpired=function(e){return 5===e.status};var Ae,Ce=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)}},Te=((Ae={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(t.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(Ce(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(t.send([getEvents(e.self(),n.height,r.height-1)]).then(t.decode)).then(function(t){for(var n,r=E(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var i=e.put;return Promise.resolve(Ce(e)).then(function(t){i.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Ae[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(Ce(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)}},Ae[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},Ae),Ne=function(e){return i.spawn(Te,e)},Ue=Pe().authorization,xe=f;Object.defineProperty(e,"TestUtils",{enumerable:!0,get:function(){return t.TestUtils}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"createSignableVoucher",{enumerable:!0,get:function(){return t.createSignableVoucher}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(e,"getCollection",{enumerable:!0,get:function(){return t.getCollection}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"invariant",{enumerable:!0,get:function(){return t.invariant}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"validator",{enumerable:!0,get:function(){return t.validator}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return o.withPrefix}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return c.template}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return c.template}}),e.VERSION="0.0.74-alpha.1",e.authenticate=function(e){return Pe().authenticate(e)},e.authz=Ue,e.currentUser=Pe,e.events=function(e){return{subscribe:function(t){return i.subscriber(e,Ne,t)}}},e.logIn=function(e){return Pe().authenticate()},e.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(t,r){try{var i=Promise.resolve(function(e){try{return n.invariant(h(e),"mutate(opts) -- opts is required"),n.invariant(m(e),"mutate(opts) -- opts must be an object"),n.invariant(h(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(v(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(l.config().get("fcl.authz",Pe().authorization)).then(function(t){return l.send([l.transaction(e.cadence),l.args(P(e.args||[])),e.limit&&g(e.limit)&&l.limit(e.limit),l.proposer(e.proposer||e.authz||t),l.payer(e.payer||e.authz||t),l.authorizations(e.authorizations||[e.authz||t])]).then(l.decode)})})}catch(e){return r(e)}return i&&i.then?i.then(void 0,r):i}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},e.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(h(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(v(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return l.send([l.script(e.cadence),l.args(P(e.args||[])),e.limit&&"number"==typeof e.limit&&l.limit(e.limit)]).then(l.decode)})}catch(e){return Promise.reject(e)}},e.reauthenticate=function(){return Pe().unauthenticate(),Pe().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Promise.resolve(t.config().get("sdk.resolve",n.resolve||t.resolve)).then(function(n){function r(){return Promise.resolve(n(e)).then(function(e){return JSON.stringify(t.createSignableVoucher(e),null,2)})}var i=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(t){e=t})}();return i&&i.then?i.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(e){return Pe().authenticate()},e.t=xe,e.tx=ke,e.unauthenticate=function(){return Pe().unauthenticate()}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,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/sdk","@onflow/util-invariant","@onflow/types","@onflow/util-actor","@onflow/util-address","@onflow/rlp","@onflow/util-uid","@onflow/util-template"],t):t((e||self).fcl={},e.sdk,e.utilInvariant,e.t$1,e.utilActor,e.utilAddress,e.rlp,e.utilUid,e.utilTemplate)}(this,function(e,t,n,r,i,o,u,a,s){function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,t}var l=c(t),f=c(r),d=c(u);t.config().put("accessNode.api","http://localhost:8080").put("challenge.handshake","http://localhost:8700/authenticate");var p=function(e){return function(t){return typeof t===e}},h=function(e){return null!=e},m=p("object"),v=p("string"),y=p("function"),g=p("number");function P(e){return y(e)?e(l.arg,f):[]}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 j(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 E(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return j(e,t);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)?j(e,t):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.")}var S={f_type:"Service",f_vsn:"1.0.0"},w={f_type:"Identity",f_vsn:"1.0.0"},O={f_type:"USER",f_vsn:"1.0.0"},I={f_type:"PollingResponse",f_vsn:"1.0.0"},R={f_type:"CompositeSignature",f_vsn:"1.0.0"};function A(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({old:e},S,{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 b({},S,{type:"back-channel-rpc",endpoint:e.endpoint,method:e.method,params:e.params||{},data:e.data||{}})}}var C={"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 b({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.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({},S,{type:e.type,uid:e.id,endpoint:e.endpoint,method:e.method,identity:b({},w,{address:o.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({},S,{type:e.type,uid:e.id,endpoint:e.authn,id:e.pid,provider:{address:o.withPrefix(e.addr),name:e.name,icon:e.icon}})}},frame:A,"open-id":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return null}},"user-signature":function(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:throw new Error("Invalid user-signature service")}}};function T(e){return d.encode([e.provider.address||e.provider.name||"UNSPECIFIED",e.id]).toString("hex")}function U(e,t){return void 0===e&&(e=[]),e.find(function(e){return e.type===t})}function N(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 i=r[n];t.searchParams.append(i[0],i[1])}return t}function x(e,t){void 0===t&&(t={});var n=t.method||"POST",r="GET"===n?void 0:JSON.stringify(t.data||e.data||{});return fetch(N(e),{method:n,headers:b({},e.headers||{},t.headers||{},{"Content-Type":"application/json"}),body:r}).then(function(e){return e.json()})}function B(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},I,{status:e.status,reason:e.reason,data:e.compositeSignature||e.data||{},updates:k(e.authorizationUpdates),local:A((e.local||[])[0])})}}var D="FCL_IFRAME",_=function(){},L=new Set(["monetizationstart","monetizationpending","monetizationprogress","monetizationstop"]);function z(e,t){if(void 0===t&&(t={}),null==e)return{send:_,close:_};var r=t.onClose||_,i=t.onMessage||_,o=t.onReady||_,u=t.onResponse||_;window.addEventListener("message",l);var a=function(e){n.invariant(!document.getElementById(D),"Attempt at triggering multiple Frames",{src:e});var t=document.createElement("iframe");return t.src=e,t.id=D,t.allow="usb *; hid *",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(D)&&document.getElementById(D).remove()}]}(N(e)),s=a[0],c=a[1];return{send:d,close:f};function l(e){try{if("object"!=typeof e.data)return;if(L.has(e.data.type))return;"FCL:FRAME:CLOSE"===e.data.type&&f(),"FCL:FRAME:READY"===e.data.type&&o(e,{send:d,close:f}),"FCL:FRAME:RESPONSE"===e.data.type&&u(e,{send:d,close:f}),i(e,{send:d,close:f}),"FCL::CHALLENGE::RESPONSE"===e.data.type&&u(e,{send:d,close:f}),"FCL::AUTHZ_READY"===e.data.type&&o(e,{send:d,close:f}),"FCL::CHALLENGE::CANCEL"===e.data.type&&f(),"FCL::CANCEL"===e.data.type&&f()}catch(e){console.error("Frame Callback Error",e),f()}}function f(){try{window.removeEventListener("message",l),c(),r()}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 F,H=function e(t,r){void 0===r&&(r=function(){return!0});try{if(n.invariant(t,"Missing Polling Service",{service:t}),!r())throw new Error("Externally Halted");return Promise.resolve(x(t,{method:q(t)}).then(B)).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)}},M={"HTTP/GET":"GET","HTTP/POST":"POST"},q=function(e){return n.invariant(M[e.method],"Invalid Service Method for type back-channel-rpc",{service:e}),M[e.method]},J=function(e,t,n){try{return t.data=e.data,Promise.resolve(x(e,{data:t}).then(B)).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,r=z(t.local,{onClose:function(){n=!1}}).close;return H(t.updates,function(){return n}).then(function(e){return r(),e}).catch(function(e){throw console.error(e),r(),e})}throw console.error("Auto Decline: Invalid Response",{service:e,resp:t}),new Error("Auto Decline: Invalid Response")})}catch(e){return Promise.reject(e)}},K=function(e,t,n){void 0===n&&(n={});try{try{return Promise.resolve(G[e.method](e,t,n))}catch(r){throw console.error("execService(service, msg)",r,{service:e,msg:t,opts:n}),r}}catch(e){return Promise.reject(e)}},G={"HTTP/RPC":J,"HTTP/POST":J,"IFRAME/RPC":function(e,t,n){return new Promise(function(r,i){var o=a.uid(),u=n.includeOlderJsonRpcCall;t.data=e.data,z(e,{onReady:function(n,r){var i=r.send;try{i({type:"FCL:FRAME:READY:RESPONSE",body:t,service:{params:e.params,data:e.data}}),u&&i({jsonrpc:"2.0",id:o,method:"fcl:sign",params:[t,e.params]})}catch(e){throw e}},onResponse:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;var o=B(e.data);switch(o.status){case"APPROVED":r(o.data),n();break;case"DECLINED":i("Declined: "+(o.reason||"No reason supplied")),n();break;default:i("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onResponse error",e),e}},onMessage:function(e,t){var n=t.close;try{if("object"!=typeof e.data)return;if("2.0"!==e.data.jsonrpc)return;if(e.data.id!==o)return;var u=B(e.data.result);switch(u.status){case"APPROVED":r(u.data),n();break;case"DECLINED":i("Declined: "+(u.reason||"No reason supplied")),n();break;default:i("Declined: No reason supplied"),n()}}catch(e){throw console.error("execIframeRPC onMessage error",e),e}},onClose:function(){i("Declined: Externally Halted")}})})}};function V(e){if(null==e)return null;switch(e.f_vsn){case"1.0.0":return e;default:return b({},R,{addr:o.sansPrefix(e.addr||e.address),signature:e.signature||e.sig,keyId:e.keyId})}}function Y(e,t,n){if(!e.s){if(n instanceof Q){if(!n.s)return void(n.o=Y.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Y.bind(null,e,t),Y.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}function $(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var Z=function(e,t){try{n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),n.invariant(Array.isArray(t),"Must include an Array of composite signatures");var r=[],i=[],o=[];return Promise.resolve(Promise.all(t.map(function(e){try{return n.invariant("string"==typeof e.addr,"addr must be a string"),n.invariant("number"==typeof e.keyId,"keyId must be a number"),n.invariant("string"==typeof e.signature,"signature must be a string"),Promise.resolve($(function(){return Promise.resolve(fcl.account(e.addr)).then(function(t){return r.push(t.keys[e.keyId].weight.toFixed(1)),i.push(t.keys[e.keyId].signAlgo),o.push(e.signature),t.keys[e.keyId].publicKey})},function(e){throw e}))}catch(e){return Promise.reject(e)}}))).then(function(t){return Promise.resolve(fcl.query({cadence:""+ge,args:function(n,u){return[n(e,u.String),n(t,u.Array([u.String])),n(r,u.Array(u.UFix64)),n(i,u.Array([u.UInt])),n(o,u.Array([u.String]))]}}))})}catch(e){return Promise.reject(e)}},W=function(e,t){void 0===t&&(t={});try{return le(),Promise.resolve(te(t)).then(function(t){var r=U(t.services,"user-signature");return n.invariant(r,"Current user must have authorized a signing service."),$(function(){return Promise.resolve(K(r,ye(e))).then(function(e){return Array.isArray(e)?e.map(function(e){return V(e)}):[V(e)]})},function(e){return e})})}catch(e){return Promise.reject(e)}},X=function(e){try{return le(),Promise.resolve(te()).then(function(t){var n=U(t.services,"authz"),r=U(t.services,"pre-authz");return b({},e,r?{tempId:"CURRENT_USER",resolve:function(e,t){try{return Promise.resolve(K(r,t)).then(pe)}catch(e){return Promise.reject(e)}}}:{tempId:"CURRENT_USER",resolve:null,addr:o.sansPrefix(n.identity.address),keyId:n.identity.keyId,sequenceNum:null,signature:null,signingFunction:function(e){try{return Promise.resolve(K(n,e,{includeOlderJsonRpcCall:!0})).then(V)}catch(e){return Promise.reject(e)}}})})}catch(e){return Promise.reject(e)}},Q=function(){function e(){}return e.prototype.then=function(t,n){var r=new e,i=this.s;if(i){var o=1&i?t:n;if(o){try{Y(r,1,o(this.v))}catch(e){Y(r,2,e)}return r}return this}return this.o=function(e){try{var i=e.v;1&e.s?Y(r,1,t?t(i):i):n?Y(r,1,n(i)):Y(r,2,i)}catch(e){Y(r,2,e)}},r},e}();function ee(e){return e instanceof Q&&1&e.s}var te=function(e){void 0===e&&(e={});try{return Promise.resolve(new Promise(function(n,r){try{return le(),Promise.resolve(me()).then(function(r){if(r.loggedIn&&fe(r))return n(r);var u=e.serviceStrategy||z;return Promise.resolve(t.config.first(["discovery.wallet","challenge.handshake"])).then(function(e){u({endpoint:e},{onReady:function(e,t){var n=t.send;try{return Promise.resolve(ne(/^service\./)).then(function(e){return Promise.resolve(ne(/^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(me()).then(function(e){n(e)})}catch(e){return Promise.reject(e)}},onResponse:function(e,t){var r=t.close;try{return Promise.resolve(function(e){try{var t=(e=function(e){return e.addr=e.addr?o.withPrefix(e.addr):null,e.paddr=e.paddr?o.withPrefix(e.paddr):null,e}(e)).services||[];return Promise.resolve(function(e,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=E(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,i,u=(r=t,i=n,void 0===r&&(r=[]),void 0===i&&(i=[]),[].concat(r,i)).map(function(t){return function(e,t){try{return C[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 b({},O,{addr:o.withPrefix(e.addr),cid:T(a),loggedIn:!0,services:u,expiresAt:e.exp})})}catch(e){return Promise.reject(e)}}(e.data)).then(function(e){return i.send(re,oe,e),Promise.resolve(me()).then(function(e){n(e),r()})})}catch(e){return Promise.reject(e)}}})})})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ne=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)}},re="CURRENT_USER",ie="CURRENT_USER/UPDATED",oe="SET_CURRENT_USER",ue='{\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}',ae=function(e){try{return sessionStorage.setItem(re,JSON.stringify(e)),Promise.resolve(e)}catch(e){return Promise.reject(e)}},se=function(){return t.config().get("persistSession",!0)},ce=((F={})[i.INIT]=function(e){try{return e.merge(JSON.parse(ue)),Promise.resolve(se()).then(function(t){var n=function(){if(t)return Promise.resolve(function(){try{var e=JSON.parse(ue),t=JSON.parse(sessionStorage.getItem(re));return null!=t&&e.f_vsn!==t.f_vsn?(sessionStorage.removeItem(re),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)}},F[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,ie,b({},e.all()))},F[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},F.SNAPSHOT=function(e,t){try{return t.reply(b({},e.all())),Promise.resolve()}catch(e){return Promise.reject(e)}},F[oe]=function(e,t,n){try{return e.merge(n),Promise.resolve(se()).then(function(t){t&&ae(e.all()),e.broadcast(ie,b({},e.all()))})}catch(e){return Promise.reject(e)}},F.DEL_CURRENT_USER=function(e,t){try{return e.merge(JSON.parse(ue)),Promise.resolve(se()).then(function(t){t&&ae(e.all()),e.broadcast(ie,b({},e.all()))})}catch(e){return Promise.reject(e)}},F),le=function(){return i.spawn(ce,re)};function fe(e){return null==e.expiresAt||0===e.expiresAt||e.expiresAt>Date.now()}function de(){le(),i.send(re,"DEL_CURRENT_USER")}function pe(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,i=E(t.payer||[]);!(r=i()).done;)n.push(["PAYER",r.value]);for(var o,u=E(t.authorization||[]);!(o=u()).done;)n.push(["AUTHORIZER",o.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 K(n,e)},role:{proposer:"PROPOSER"===t,payer:"PAYER"===t,authorizer:"AUTHORIZER"===t}}})}function he(e){le();var t="@EXIT",n=i.spawn(function(n){try{var r;return n.send(re,i.SUBSCRIBE),Promise.resolve(function(e,t,n){for(var r;;){var i=e();if(ee(i)&&(i=i.v),!i)return o;if(i.then){r=0;break}var o=n();if(o&&o.then){if(!ee(o)){r=1;break}o=o.s}}var u=new Q,a=Y.bind(null,u,2);return(0===r?i.then(c):1===r?o.then(s):(void 0).then(function(){(i=e())?i.then?i.then(c).then(void 0,a):c(i):Y(u,1,o)})).then(void 0,a),u;function s(t){o=t;do{if(!(i=e())||ee(i)&&!i.v)return void Y(u,1,o);if(i.then)return void i.then(c).then(void 0,a);ee(o=n())&&(o=o.v)}while(!o||!o.then);o.then(s).then(void 0,a)}function c(e){e?(o=n())&&o.then?o.then(s).then(void 0,a):s(o):Y(u,1,o)}}(function(){return!r&&1},0,function(){return Promise.resolve(n.receive()).then(function(o){if(o.tag===t)return n.send(re,i.UNSUBSCRIBE),void(r=1);e(o.data)})}))}catch(e){return Promise.reject(e)}});return function(){return i.send(n,t)}}function me(){return le(),i.send(re,"SNAPSHOT",null,{expectReply:!0,timeout:0})}var ve,ye=function(e){return n.invariant(/^[0-9a-f]+$/i.test(e),"Message must be a hex string"),{message:e}},ge="\nimport Crypto\n \npub fun main(\n message: String,\n rawPublicKeys: [String],\n weights: [UFix64],\n signAlgos: [UInt],\n signatures: [String],\n): Bool {\n\n let keyList = Crypto.KeyList()\n \n var i = 0\n for rawPublicKey in rawPublicKeys {\n keyList.add(\n PublicKey(\n publicKey: rawPublicKey.decodeHex(),\n signatureAlgorithm: signAlgos[i] == 2 ? SignatureAlgorithm.ECDSA_P256 : SignatureAlgorithm.ECDSA_secp256k1 \n ),\n hashAlgorithm: HashAlgorithm.SHA3_256,\n weight: weights[i],\n )\n i = i + 1\n }\n\n let signatureSet: [Crypto.KeyListSignature] = []\n\n var j = 0\n for signature in signatures {\n signatureSet.append(\n Crypto.KeyListSignature(\n keyIndex: j,\n signature: signature.decodeHex()\n )\n )\n j = j + 1\n }\n \n let signedData = message.decodeHex()\n \n return keyList.verify(\n signatureSet: signatureSet,\n signedData: signedData\n )\n}\n",Pe=function(){return{authenticate:te,unauthenticate:de,authorization:X,signUserMessage:W,verifyUserSignatures:Z,subscribe:he,snapshot:me}},be="POLL",je=function(e){try{return Promise.resolve(t.send([t.getTransactionStatus(e)]).then(t.decode))}catch(e){return Promise.reject(e)}},Ee=function(e){return e.status>=4},Se=function(e){return e.status>=3},we=function(e){return e.status>=2},Oe=((ve={})[i.INIT]=function(e){try{return Promise.resolve(je(e.self())).then(function(t){Ee(t)||setTimeout(function(){return e.sendSelf(be)},2500),e.merge(t)})}catch(e){return Promise.reject(e)}},ve[i.SUBSCRIBE]=function(e,t){e.subscribe(t.from),e.send(t.from,i.UPDATED,e.all())},ve[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from)},ve[i.SNAPSHOT]=function(e,t){try{return t.reply(e.all()),Promise.resolve()}catch(e){return Promise.reject(e)}},ve.POLL=function(e){try{return Promise.resolve(je(e.self())).then(function(t){var n,r;Ee(t)||setTimeout(function(){return e.sendSelf(be)},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)}},ve),Ie=function(e){if("object"==typeof e&&(e=e.transactionId),null==e)throw new Error("transactionId required");return e},Re=function(e){return i.spawn(Oe,Ie(e))};function Ae(e){function t(t){return i.subscriber(Ie(e),Re,t)}function n(e){return function(n){void 0===n&&(n={});var r=n.suppress||!1;return new Promise(function(n,i){var o=t(function(t){t.statusCode&&!r?(i(t.errorMessage),o()):e(t)&&(n(t),o())})})}}return{snapshot:function(){return i.snapshoter(e,Re)},subscribe:t,onceFinalized:n(we),onceExecuted:n(Se),onceSealed:n(Ee)}}Ae.isUnknown=function(e){return e.status>=0},Ae.isPending=function(e){return e.status>=1},Ae.isFinalized=we,Ae.isExecuted=Se,Ae.isSealed=Ee,Ae.isExpired=function(e){return 5===e.status};var ke,Ce=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)}},Te=((ke={}).TICK=function(e){try{if(!e.hasSubs())return Promise.resolve();var n=e.get("hwm"),r=function(){if(null==n){var r=e.put;return Promise.resolve(t.latestBlock()).then(function(t){r.call(e,"hwm",t);var n=e.put;return Promise.resolve(Ce(e)).then(function(t){n.call(e,"tick",t)})})}return Promise.resolve(t.latestBlock()).then(function(r){return e.put("hwm",r),Promise.resolve(t.send([getEvents(e.self(),n.height,r.height-1)]).then(t.decode)).then(function(t){for(var n,r=E(t);!(n=r()).done;)e.broadcast("UPDATED",n.value.data);var i=e.put;return Promise.resolve(Ce(e)).then(function(t){i.call(e,"tick",t)})})})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},ke[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(Ce(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)}},ke[i.UNSUBSCRIBE]=function(e,t){e.unsubscribe(t.from),e.hasSubs()||(clearTimeout(e.get("tick")),e.delete("tick"),e.delete("hwm"))},ke),Ue=function(e){return i.spawn(Te,e)},Ne=Pe().authorization,xe=f;Object.defineProperty(e,"TestUtils",{enumerable:!0,get:function(){return t.TestUtils}}),Object.defineProperty(e,"account",{enumerable:!0,get:function(){return t.account}}),Object.defineProperty(e,"arg",{enumerable:!0,get:function(){return t.arg}}),Object.defineProperty(e,"args",{enumerable:!0,get:function(){return t.args}}),Object.defineProperty(e,"atBlockHeight",{enumerable:!0,get:function(){return t.atBlockHeight}}),Object.defineProperty(e,"atBlockId",{enumerable:!0,get:function(){return t.atBlockId}}),Object.defineProperty(e,"authorization",{enumerable:!0,get:function(){return t.authorization}}),Object.defineProperty(e,"authorizations",{enumerable:!0,get:function(){return t.authorizations}}),Object.defineProperty(e,"build",{enumerable:!0,get:function(){return t.build}}),Object.defineProperty(e,"config",{enumerable:!0,get:function(){return t.config}}),Object.defineProperty(e,"createSignableVoucher",{enumerable:!0,get:function(){return t.createSignableVoucher}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"getAccount",{enumerable:!0,get:function(){return t.getAccount}}),Object.defineProperty(e,"getBlock",{enumerable:!0,get:function(){return t.getBlock}}),Object.defineProperty(e,"getBlockByHeight",{enumerable:!0,get:function(){return t.getBlockByHeight}}),Object.defineProperty(e,"getBlockById",{enumerable:!0,get:function(){return t.getBlockById}}),Object.defineProperty(e,"getBlockHeader",{enumerable:!0,get:function(){return t.getBlockHeader}}),Object.defineProperty(e,"getCollection",{enumerable:!0,get:function(){return t.getCollection}}),Object.defineProperty(e,"getEvents",{enumerable:!0,get:function(){return t.getEvents}}),Object.defineProperty(e,"getEventsAtBlockHeightRange",{enumerable:!0,get:function(){return t.getEventsAtBlockHeightRange}}),Object.defineProperty(e,"getEventsAtBlockIds",{enumerable:!0,get:function(){return t.getEventsAtBlockIds}}),Object.defineProperty(e,"getLatestBlock",{enumerable:!0,get:function(){return t.getLatestBlock}}),Object.defineProperty(e,"getTransaction",{enumerable:!0,get:function(){return t.getTransaction}}),Object.defineProperty(e,"getTransactionStatus",{enumerable:!0,get:function(){return t.getTransactionStatus}}),Object.defineProperty(e,"invariant",{enumerable:!0,get:function(){return t.invariant}}),Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return t.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return t.isOk}}),Object.defineProperty(e,"latestBlock",{enumerable:!0,get:function(){return t.latestBlock}}),Object.defineProperty(e,"limit",{enumerable:!0,get:function(){return t.limit}}),Object.defineProperty(e,"param",{enumerable:!0,get:function(){return t.param}}),Object.defineProperty(e,"params",{enumerable:!0,get:function(){return t.params}}),Object.defineProperty(e,"payer",{enumerable:!0,get:function(){return t.payer}}),Object.defineProperty(e,"ping",{enumerable:!0,get:function(){return t.ping}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return t.pipe}}),Object.defineProperty(e,"proposer",{enumerable:!0,get:function(){return t.proposer}}),Object.defineProperty(e,"ref",{enumerable:!0,get:function(){return t.ref}}),Object.defineProperty(e,"script",{enumerable:!0,get:function(){return t.script}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(e,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(e,"validator",{enumerable:!0,get:function(){return t.validator}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return t.why}}),Object.defineProperty(e,"display",{enumerable:!0,get:function(){return o.display}}),Object.defineProperty(e,"sansPrefix",{enumerable:!0,get:function(){return o.sansPrefix}}),Object.defineProperty(e,"withPrefix",{enumerable:!0,get:function(){return o.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.74-alpha.2",e.authenticate=function(e){return Pe().authenticate(e)},e.authz=Ne,e.currentUser=Pe,e.events=function(e){return{subscribe:function(t){return i.subscriber(e,Ue,t)}}},e.logIn=function(e){return Pe().authenticate()},e.mutate=function(e){void 0===e&&(e={});try{return Promise.resolve(function(t,r){try{var i=Promise.resolve(function(e){try{return n.invariant(h(e),"mutate(opts) -- opts is required"),n.invariant(m(e),"mutate(opts) -- opts must be an object"),n.invariant(h(e.cadence),"mutate({ cadence }) -- cadence is required"),n.invariant(v(e.cadence),"mutate({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return Promise.resolve(l.config().get("fcl.authz",Pe().authorization)).then(function(t){return l.send([l.transaction(e.cadence),l.args(P(e.args||[])),e.limit&&g(e.limit)&&l.limit(e.limit),l.proposer(e.proposer||e.authz||t),l.payer(e.payer||e.authz||t),l.authorizations(e.authorizations||[e.authz||t])]).then(l.decode)})})}catch(e){return r(e)}return i&&i.then?i.then(void 0,r):i}(0,function(e){throw e}))}catch(e){return Promise.reject(e)}},e.query=function(e){void 0===e&&(e={});try{return Promise.resolve(function(e){try{return n.invariant(h(e.cadence),"query({ cadence }) -- cadence is required"),n.invariant(v(e.cadence),"query({ cadence }) -- cadence must be a string"),Promise.resolve()}catch(e){return Promise.reject(e)}}(e)).then(function(){return l.send([l.script(e.cadence),l.args(P(e.args||[])),e.limit&&"number"==typeof e.limit&&l.limit(e.limit)]).then(l.decode)})}catch(e){return Promise.reject(e)}},e.reauthenticate=function(){return Pe().unauthenticate(),Pe().authenticate()},e.serialize=function(e,n){void 0===e&&(e=[]),void 0===n&&(n={});try{return Promise.resolve(t.config.first(["sdk.resolve"],n.resolve||t.resolve)).then(function(n){function r(){return Promise.resolve(n(e)).then(function(e){return JSON.stringify(t.createSignableVoucher(e),null,2)})}var i=function(){if(Array.isArray(e))return Promise.resolve(t.pipe(t.interaction(),e)).then(function(t){e=t})}();return i&&i.then?i.then(r):r()})}catch(e){return Promise.reject(e)}},e.signUp=function(e){return Pe().authenticate()},e.t=xe,e.tx=Ae,e.unauthenticate=function(){return Pe().unauthenticate()}}); | ||
//# sourceMappingURL=fcl.umd.js.map |
{ | ||
"name": "@onflow/fcl", | ||
"version": "0.0.74-alpha.1", | ||
"version": "0.0.74-alpha.2", | ||
"description": "Flow Client Library", | ||
@@ -21,3 +21,3 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"jest": "^27.0.4", | ||
"jest": "^27.0.6", | ||
"jest-esm-transformer": "1.0.0", | ||
@@ -41,3 +41,3 @@ "microbundle": "^0.13.3" | ||
"@onflow/rlp": "0.0.3", | ||
"@onflow/sdk": "0.0.51-alpha.1", | ||
"@onflow/sdk": "^0.0.51-alpha.2", | ||
"@onflow/types": "^0.0.4", | ||
@@ -44,0 +44,0 @@ "@onflow/util-actor": "0.0.2", |
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
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
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
397949
372
+ Added@onflow/sdk@0.0.51(transitive)
- Removed@onflow/sdk@0.0.51-alpha.1(transitive)
Updated@onflow/sdk@^0.0.51-alpha.2