@onflow/sdk
Advanced tools
Comparing version 0.0.25 to 0.0.26
@@ -5,6 +5,10 @@ ### Unreleased | ||
### 0.0.26 -- 2020-07-09 | ||
- 2020-07-09 -- FIX: resolveSignatures now passes arguments to encoder | ||
### 0.0.25 -- 2020-07-09 | ||
- 2020-07-09 -- FIX: no longer lose signatures sometimes | ||
- 2020-07-07 -- Updates to Readme | ||
- 2020-07-09 -- FIX: no longer lose signatures sometimes | ||
@@ -11,0 +15,0 @@ ### 0.0.24 -- 2020-07-07 |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/interaction"),r=require("@onflow/send"),n=require("@onflow/decode"),t=require("@qvvg/templar"),o=require("@onflow/encode"),i=e.pipe;function u(){return(u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function s(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function a(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return s(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var c={asArgument:function(e){return e},asInjection:function(e){return e}},f={asArgument:function(e){return e},asInjection:function(e){return e}},p=[];const l=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{d(t,1,e(this.v))}catch(e){d(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?d(t,1,r?r(o):o):n?d(t,1,n(o)):d(t,2,o)}catch(e){d(t,2,e)}},t},e}();function d(e,r,n){if(!e.s){if(n instanceof l){if(!n.s)return void(n.o=d.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(d.bind(null,e,r),d.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function m(e){return e instanceof l&&1&e.s}const v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function y(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var g=function(e){return"function"==typeof e},h=function(e){return"number"==typeof e},k=function(e){return"string"==typeof e},b=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},P=function(e){return!(e.role.proposer&&!(k(e.addr)&&h(e.keyId)&&h(e.sequenceNum)&&g(e.signingFunction))||e.role.payer&&!(k(e.addr)&&h(e.keyId)&&g(e.signingFunction))||e.role.authorizer&&!(k(e.addr)&&h(e.keyId)&&g(e.signingFunction)))},x=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},O=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},I=e.pipe([function(r){try{var n=function(){return e.Ok(r)};if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));var t=function(e,r,n){if("function"==typeof e[v]){var t,o,i,u=e[v]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!m(n))return void n.then(e,i||(i=d.bind(null,o=new l,2)));n=n.v}o?d(o,1,n):o=n}catch(e){d(o||(o=new l),2,e)}}(),u.return){var s=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(s,function(e){throw s(e)});s()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],c=0;c<e.length;c++)a.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!m(u))return void u.then(n,o||(o=d.bind(null,t=new l,2)));u=u.v}t?d(t,1,u):t=u}catch(e){d(t||(t=new l),2,e)}}(),t}(a,function(e){return r(a[e])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){b(P(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var i=function(){if(g(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return i&&i.then?i.then(o):o()});return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},function(r){try{if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));for(var n=function(){var e,n,i,s=o[t],a=s.addr+"|"+s.keyId;r.accounts[a]=null!=r.accounts[a]?(e=r.accounts[a],n=u({tempId:a},s),{kind:x([e.kind,n.kind]),tempId:x([e.tempId,n.tempId]),addr:x([e.addr,n.addr]),keyId:(i=[e.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(h)[0]?i.filter(h)[0]:null),sequenceNum:"number"==typeof O([e,n]).sequenceNum?O([e,n]).sequenceNum:e.sequenceNum,signature:x([e.signature,n.signature]),signingFunction:x([e.signingFunction,n.signingFunction]),resolve:x([e.resolve,n.resolve]),role:{proposer:e.role.proposer||n.role.proposer,authorizer:e.role.authorizer||n.role.authorizer,payer:e.role.payer||n.role.payer,param:e.role.param||n.role.param}}):u({tempId:a},s),r.proposer===s.tempId&&(r.proposer=a),r.payer===s.tempId&&(r.payer=a),r.authorizations=r.authorizations.map(function(e){return e===s.tempId?a:e}),delete r.accounts[s.tempId]},t=0,o=Object.values(r.accounts);t<o.length;t++)n();for(var i=0,s=Object.values(r.accounts);i<s.length;i++){var a=s[i];b(P(a),"Account unable to fulfill roles",a)}return Promise.resolve(e.Ok(r))}catch(e){return Promise.reject(e)}}]),S=function(e,r,n){void 0===r&&(r=[]);try{return Promise.all(r.map(function(r){try{return Promise.resolve(e.accounts[r].signingFunction({message:n,addr:e.accounts[r].addr,keyId:e.accounts[r].keyId,roles:e.accounts[r].role,interaction:e})).then(function(n){if(n.cid=r,e.accounts[r].addr!==n.addr)throw new Error(r+" — mismatching address in composite signature");if(e.accounts[r].keyId!==n.keyId)throw new Error(r+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};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,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return r.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(exports,"decodeResponse",{enumerable:!0,get:function(){return n.decodeResponse}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return t.templar}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return t.templar}}),exports.arg=function(e,r){return void 0===r&&(r=f),{value:e,xform:r}},exports.args=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeArgument("function"==typeof r?{resolve:r}:r)}))},exports.authorization=function(e,r,n,t){return{addr:e,signingFunction:r,keyId:n,sequenceNum:t}},exports.authorizations=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeAuthorizer(u({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))},exports.build=function(r){return void 0===r&&(r=[]),e.pipe(e.interaction(),r)},exports.getAccount=function(r){return e.pipe([e.makeGetAccount,function(n){return n.accountAddr=r,e.Ok(n)}])},exports.getEvents=function(r,n,t){return e.pipe([e.makeGetEvents,function(n){return n.events.eventType=r,e.Ok(n)},function(r){return r.events.start=n,e.Ok(r)},function(r){return r.events.end=t,e.Ok(r)}])},exports.getLatestBlock=function(r){return void 0===r&&(r=!1),e.pipe([e.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=r,e.Ok(n)}])},exports.getTransactionStatus=function(r){return e.pipe([e.makeGetTransactionStatus,function(n){return n.transactionId=r,e.Ok(n)}])},exports.invariant=function r(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.length>1){var i=t[0],u=t[1];return r(function(e,r){var n=r.Bad;return i?(0,r.Ok)(e):n(e,u)})}var s=t[0];return function(r){return s(r,{Ok:e.Ok,Bad:e.Bad})}},exports.limit=function(r){return e.pipe([function(n){return n.message.computeLimit=r,e.Ok(n)}])},exports.param=function(e,r,n){return void 0===r&&(r=c),void 0===n&&(n=null),{key:n,value:e,xform:r}},exports.params=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeParam("function"==typeof r?{resolve:r}:r)}))},exports.payer=function(r){return e.makePayer(u({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))},exports.ping=function(){return e.pipe([e.makePing])},exports.proposer=function(r){try{return Promise.resolve(e.makeProposer("function"==typeof r?{resolve:r,role:{proposer:!0}}:u({},r,{role:{proposer:!0}})))}catch(e){return Promise.reject(e)}},exports.ref=function(r){return e.pipe([function(n){return n.message.refBlock=r,e.Ok(n)}])},exports.resolve=i,exports.resolveAccounts=I,exports.resolveArguments=function(r){try{if(!e.isTransaction(r)&&!e.isScript(r))return Promise.resolve(e.Ok(r));var n=Object.values(r.arguments);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return u({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(e){r.arguments[e.tempId]=u({},e,{asArgument:e.xform.asArgument(e.value)})}),e.Ok(r)})}catch(e){return Promise.reject(e)}},exports.resolveParams=function(r){try{var n=function(e){if(t)return e;throw new Error("Invalid Cadence Value")},t=!1;if(!e.isTransaction(r)&&!e.isScript(r))return Promise.resolve(e.Ok(r));var o=e.get(r,"ix.cadence");if("string"==typeof o)return r.message.cadence=o,Promise.resolve(e.Ok(r));var i=function(){if("function"==typeof o){var n=Object.values(r.params);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return u({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(e){r.params[e.tempId]=e}),n=Object.fromEntries(n.filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]})),r.message.cadence=o(n),t=!0,e.Ok(r)})}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}},exports.resolveSignatures=function(r){try{var n,t,i,u,s=function(s){if(c)return s;function f(n){return e.Ok(r)}var p=y(function(){return Promise.resolve(S(r,i,o.encodeTransactionEnvelope({script:r.message.cadence,refBlock:r.message.refBlock||null,gasLimit:r.message.computeLimit,proposalKey:{address:r.accounts[r.proposer].addr,keyId:r.accounts[r.proposer].keyId,sequenceNum:r.accounts[r.proposer].sequenceNum},payer:r.accounts[r.payer].addr,authorizers:r.authorizations.map(function(e){return r.accounts[e].addr}),payloadSigs:t}))).then(function(e){for(var n,t=a(u=e);!(n=t()).done;){var o=n.value;r.accounts[o.cid].signature=o.signature}})},function(e){throw console.error("Fetching of Outside Signatures",e,{ix:r,insideSigners:n,insideSignatures:t,outsideSigners:i,outsideSignatures:u}),e});return p&&p.then?p.then(f):f()},c=!1;if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));try{(n=new Set(r.authorizations)).add(r.proposer),n.delete(r.payer),n=Array.from(n)}catch(e){throw console.error("Inside Signer Discovery",e,{ix:r,insideSigners:n,insideSignatures:t,outsideSigners:i,outsideSignatures:u}),e}try{i=new Set([r.payer]),i=Array.from(i)}catch(e){throw console.error("Outside Signer Discovery",e,{ix:r,insideSigners:n,insideSignatures:t,outsideSigners:i,outsideSignatures:u}),e}var f=y(function(){return Promise.resolve(S(r,n,o.encodeTransactionPayload({script:r.message.cadence,refBlock:r.message.refBlock||null,gasLimit:r.message.computeLimit,proposalKey:{address:r.accounts[r.proposer].addr,keyId:r.accounts[r.proposer].keyId,sequenceNum:r.accounts[r.proposer].sequenceNum},payer:r.accounts[r.payer].addr,authorizers:r.authorizations.map(function(e){return r.accounts[e].addr})}))).then(function(e){for(var n,o=a(t=e);!(n=o()).done;){var i=n.value;r.accounts[i.cid].signature=i.signature}})},function(e){throw console.error("Fetching of Inside Signatures",e,{ix:r,insideSigners:n,insideSignatures:t,outsideSigners:i,outsideSignatures:u}),e});return Promise.resolve(f&&f.then?f.then(s):s(f))}catch(e){return Promise.reject(e)}},exports.resolveValidators=function(r){try{var n=e.get(r,"ix.validators",[]);return Promise.resolve(e.pipe(r,n.map(function(r){return function(n){return r(n,{Ok:e.Ok,Bad:e.Bad})}})))}catch(e){return Promise.reject(e)}},exports.script=function(){return e.pipe([e.makeScript,e.put("ix.cadence",t.templar.apply(void 0,arguments))])},exports.transaction=function(){return e.pipe([e.makeTransaction,e.put("ix.cadence",t.templar.apply(void 0,arguments)),function(r){return r.message.computeLimit=r.message.computeLimit||10,r.message.refBlock=r.message.refBlock||null,r.authorizations=r.authorizations||p,e.Ok(r)}])},exports.validator=function(r){return e.update("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}; | ||
var e=require("@onflow/interaction"),r=require("@onflow/send"),n=require("@onflow/decode"),t=require("@qvvg/templar"),o=require("@onflow/encode"),i=e.pipe;function u(){return(u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function a(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}var c={asArgument:function(e){return e},asInjection:function(e){return e}},s={asArgument:function(e){return e},asInjection:function(e){return e}},f=[];const p=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{l(t,1,e(this.v))}catch(e){l(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?l(t,1,r?r(o):o):n?l(t,1,n(o)):l(t,2,o)}catch(e){l(t,2,e)}},t},e}();function l(e,r,n){if(!e.s){if(n instanceof p){if(!n.s)return void(n.o=l.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(l.bind(null,e,r),l.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function d(e){return e instanceof p&&1&e.s}const m="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var v=function(e){return"function"==typeof e},y=function(e){return"number"==typeof e},g=function(e){return"string"==typeof e},h=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},k=function(e){return!(e.role.proposer&&!(g(e.addr)&&y(e.keyId)&&y(e.sequenceNum)&&v(e.signingFunction))||e.role.payer&&!(g(e.addr)&&y(e.keyId)&&v(e.signingFunction))||e.role.authorizer&&!(g(e.addr)&&y(e.keyId)&&v(e.signingFunction)))},b=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},P=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},x=e.pipe([function(r){try{var n=function(){return e.Ok(r)};if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));var t=function(e,r,n){if("function"==typeof e[m]){var t,o,i,u=e[m]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!d(n))return void n.then(e,i||(i=l.bind(null,o=new p,2)));n=n.v}o?l(o,1,n):o=n}catch(e){l(o||(o=new p),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!d(u))return void u.then(n,o||(o=l.bind(null,t=new p,2)));u=u.v}t?l(t,1,u):t=u}catch(e){l(t||(t=new p),2,e)}}(),t}(c,function(e){return r(c[e])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){h(k(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var i=function(){if(v(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return i&&i.then?i.then(o):o()});return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},function(r){try{if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));for(var n=function(){var e,n,i,a=o[t],c=a.addr+"|"+a.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],n=u({tempId:c},a),{kind:b([e.kind,n.kind]),tempId:b([e.tempId,n.tempId]),addr:b([e.addr,n.addr]),keyId:(i=[e.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(y)[0]?i.filter(y)[0]:null),sequenceNum:"number"==typeof P([e,n]).sequenceNum?P([e,n]).sequenceNum:e.sequenceNum,signature:b([e.signature,n.signature]),signingFunction:b([e.signingFunction,n.signingFunction]),resolve:b([e.resolve,n.resolve]),role:{proposer:e.role.proposer||n.role.proposer,authorizer:e.role.authorizer||n.role.authorizer,payer:e.role.payer||n.role.payer,param:e.role.param||n.role.param}}):u({tempId:c},a),r.proposer===a.tempId&&(r.proposer=c),r.payer===a.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(e){return e===a.tempId?c:e}),delete r.accounts[a.tempId]},t=0,o=Object.values(r.accounts);t<o.length;t++)n();for(var i=0,a=Object.values(r.accounts);i<a.length;i++){var c=a[i];h(k(c),"Account unable to fulfill roles",c)}return Promise.resolve(e.Ok(r))}catch(e){return Promise.reject(e)}}]);function O(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr})}}var I=function(e,r,n){void 0===r&&(r=[]);try{return Promise.all(r.map(function(r){try{return Promise.resolve(e.accounts[r].signingFunction({message:n,addr:e.accounts[r].addr,keyId:e.accounts[r].keyId,roles:e.accounts[r].role,interaction:e})).then(function(n){if(n.cid=r,e.accounts[r].addr!==n.addr)throw new Error(r+" — mismatching address in composite signature");if(e.accounts[r].keyId!==n.keyId)throw new Error(r+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function j(e,r){for(var n,t=function(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return a(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(e,void 0):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(r);!(n=t()).done;){var o=n.value;e.accounts[o.cid].signature=o.signature}return r}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,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return r.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(exports,"decodeResponse",{enumerable:!0,get:function(){return n.decodeResponse}}),Object.defineProperty(exports,"cadence",{enumerable:!0,get:function(){return t.templar}}),Object.defineProperty(exports,"cdc",{enumerable:!0,get:function(){return t.templar}}),exports.arg=function(e,r){return void 0===r&&(r=s),{value:e,xform:r}},exports.args=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeArgument("function"==typeof r?{resolve:r}:r)}))},exports.authorization=function(e,r,n,t){return{addr:e,signingFunction:r,keyId:n,sequenceNum:t}},exports.authorizations=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeAuthorizer(u({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))},exports.build=function(r){return void 0===r&&(r=[]),e.pipe(e.interaction(),r)},exports.getAccount=function(r){return e.pipe([e.makeGetAccount,function(n){return n.accountAddr=r,e.Ok(n)}])},exports.getEvents=function(r,n,t){return e.pipe([e.makeGetEvents,function(n){return n.events.eventType=r,e.Ok(n)},function(r){return r.events.start=n,e.Ok(r)},function(r){return r.events.end=t,e.Ok(r)}])},exports.getLatestBlock=function(r){return void 0===r&&(r=!1),e.pipe([e.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=r,e.Ok(n)}])},exports.getTransactionStatus=function(r){return e.pipe([e.makeGetTransactionStatus,function(n){return n.transactionId=r,e.Ok(n)}])},exports.invariant=function r(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.length>1){var i=t[0],u=t[1];return r(function(e,r){var n=r.Bad;return i?(0,r.Ok)(e):n(e,u)})}var a=t[0];return function(r){return a(r,{Ok:e.Ok,Bad:e.Bad})}},exports.limit=function(r){return e.pipe([function(n){return n.message.computeLimit=r,e.Ok(n)}])},exports.param=function(e,r,n){return void 0===r&&(r=c),void 0===n&&(n=null),{key:n,value:e,xform:r}},exports.params=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeParam("function"==typeof r?{resolve:r}:r)}))},exports.payer=function(r){return e.makePayer(u({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))},exports.ping=function(){return e.pipe([e.makePing])},exports.proposer=function(r){try{return Promise.resolve(e.makeProposer("function"==typeof r?{resolve:r,role:{proposer:!0}}:u({},r,{role:{proposer:!0}})))}catch(e){return Promise.reject(e)}},exports.ref=function(r){return e.pipe([function(n){return n.message.refBlock=r,e.Ok(n)}])},exports.resolve=i,exports.resolveAccounts=x,exports.resolveArguments=function(r){try{if(!e.isTransaction(r)&&!e.isScript(r))return Promise.resolve(e.Ok(r));var n=Object.values(r.arguments);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return u({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(e){r.arguments[e.tempId]=u({},e,{asArgument:e.xform.asArgument(e.value)})}),e.Ok(r)})}catch(e){return Promise.reject(e)}},exports.resolveParams=function(r){try{var n=function(e){if(t)return e;throw new Error("Invalid Cadence Value")},t=!1;if(!e.isTransaction(r)&&!e.isScript(r))return Promise.resolve(e.Ok(r));var o=e.get(r,"ix.cadence");if("string"==typeof o)return r.message.cadence=o,Promise.resolve(e.Ok(r));var i=function(){if("function"==typeof o){var n=Object.values(r.params);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return u({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(e){r.params[e.tempId]=e}),n=Object.fromEntries(n.filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]})),r.message.cadence=o(n),t=!0,e.Ok(r)})}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}},exports.resolveSignatures=function(r){try{if(!e.isTransaction(r))return Promise.resolve(r);var n=function(e){var r=new Set(e.authorizations);r.add(e.proposer),r.delete(e.payer),r=Array.from(r);var n=new Set([e.payer]);return{insideSigners:r,outsideSigners:n=Array.from(n)}}(r),t=n.outsideSigners;return Promise.resolve(I(r,n.insideSigners,o.encodeTransactionPayload(O(r)))).then(function(e){var n=j(r,e);return Promise.resolve(I(r,t,o.encodeTransactionEnvelope(u({},O(r),{payloadSigs:n})))).then(function(e){return j(r,e),r})})}catch(e){return Promise.reject(e)}},exports.resolveValidators=function(r){try{var n=e.get(r,"ix.validators",[]);return Promise.resolve(e.pipe(r,n.map(function(r){return function(n){return r(n,{Ok:e.Ok,Bad:e.Bad})}})))}catch(e){return Promise.reject(e)}},exports.script=function(){return e.pipe([e.makeScript,e.put("ix.cadence",t.templar.apply(void 0,arguments))])},exports.transaction=function(){return e.pipe([e.makeTransaction,e.put("ix.cadence",t.templar.apply(void 0,arguments)),function(r){return r.message.computeLimit=r.message.computeLimit||10,r.message.refBlock=r.message.refBlock||null,r.authorizations=r.authorizations||f,e.Ok(r)}])},exports.validator=function(r){return e.update("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}; | ||
//# sourceMappingURL=sdk.js.map |
@@ -1,2 +0,2 @@ | ||
import{pipe as e,interaction as r,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as i,makeGetLatestBlock as u,makeGetTransactionStatus as c,makeParam as a,makeArgument as s,makeProposer as f,makePayer as l,makePing as d,makeScript as m,put as p,makeTransaction as v,update as y,Bad as h,isTransaction as g,isScript as I,get as b}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{templar as S}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionEnvelope as P,encodeTransactionPayload as k}from"@onflow/encode";function w(n){return void 0===n&&(n=[]),e(r(),n)}var j=e;function A(){return(A=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function x(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function O(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return x(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}function z(r){return void 0===r&&(r=[]),e(r.map(function(e){return n(A({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))}function B(e,r,n,t){return{addr:e,signingFunction:r,keyId:n,sequenceNum:t}}function q(r){return e([t,function(e){return e.accountAddr=r,o(e)}])}function N(r,n,t){return e([i,function(e){return e.events.eventType=r,o(e)},function(e){return e.events.start=n,o(e)},function(e){return e.events.end=t,o(e)}])}function F(r){return void 0===r&&(r=!1),e([u,function(e){return e.latestBlock.isSealed=r,o(e)}])}function E(r){return e([c,function(e){return e.transactionId=r,o(e)}])}function L(r){return e([function(e){return e.message.computeLimit=r,o(e)}])}function T(r){return void 0===r&&(r=[]),e(r.map(function(e){return a("function"==typeof e?{resolve:e}:e)}))}var C={asArgument:function(e){return e},asInjection:function(e){return e}};function D(e,r,n){return void 0===r&&(r=C),void 0===n&&(n=null),{key:n,value:e,xform:r}}function K(r){return void 0===r&&(r=[]),e(r.map(function(e){return s("function"==typeof e?{resolve:e}:e)}))}var R={asArgument:function(e){return e},asInjection:function(e){return e}};function V(e,r){return void 0===r&&(r=R),{value:e,xform:r}}var M=function(e){try{return U(e)?Promise.resolve(f({resolve:e,role:{proposer:!0}})):Promise.resolve(f(A({},e,{role:{proposer:!0}})))}catch(e){return Promise.reject(e)}},U=function(e){return"function"==typeof e};function $(e){return l(A({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))}function G(){return e([d])}function H(r){return e([function(e){return e.message.refBlock=r,o(e)}])}function J(){return e([m,p("ix.cadence",S.apply(void 0,arguments))])}var Q=[];function W(){return e([v,p("ix.cadence",S.apply(void 0,arguments)),function(e){return e.message.computeLimit=e.message.computeLimit||10,e.message.refBlock=e.message.refBlock||null,e.authorizations=e.authorizations||Q,o(e)}])}function X(e){return y("ix.validators",function(r){return Array.isArray(r)?r.push(e):[e]})}function Y(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];if(r.length>1){var t=r[0],i=r[1];return Y(function(e,r){var n=r.Bad;return t?(0,r.Ok)(e):n(e,i)})}var u=r[0];return function(e){return u(e,{Ok:o,Bad:h})}}const Z=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{_(t,1,e(this.v))}catch(e){_(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?_(t,1,r?r(o):o):n?_(t,1,n(o)):_(t,2,o)}catch(e){_(t,2,e)}},t},e}();function _(e,r,n){if(!e.s){if(n instanceof Z){if(!n.s)return void(n.o=_.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(_.bind(null,e,r),_.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function ee(e){return e instanceof Z&&1&e.s}const re="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ne(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var te=function(e){return"function"==typeof e},oe=function(e){return"number"==typeof e},ie=function(e){return"string"==typeof e},ue=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},ce=function(e){return!(e.role.proposer&&!(ie(e.addr)&&oe(e.keyId)&&oe(e.sequenceNum)&&te(e.signingFunction))||e.role.payer&&!(ie(e.addr)&&oe(e.keyId)&&te(e.signingFunction))||e.role.authorizer&&!(ie(e.addr)&&oe(e.keyId)&&te(e.signingFunction)))},ae=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},se=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},fe=e([function(e){try{var r=function(){return o(e)};if(!g(e))return Promise.resolve(o(e));var n=function(e,r,n){if("function"==typeof e[re]){var t,o,i,u=e[re]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!ee(n))return void n.then(e,i||(i=_.bind(null,o=new Z,2)));n=n.v}o?_(o,1,n):o=n}catch(e){_(o||(o=new Z),2,e)}}(),u.return){var c=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(c,function(e){throw c(e)});c()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],s=0;s<e.length;s++)a.push(e[s]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!ee(u))return void u.then(n,o||(o=_.bind(null,t=new Z,2)));u=u.v}t?_(t,1,u):t=u}catch(e){_(t||(t=new Z),2,e)}}(),t}(a,function(e){return r(a[e])})}(Object.entries(e.accounts),function(r){var n=r[0],t=r[1];function o(){ue(ce(e.accounts[n]),"Account unable to fulfill role",e.accounts[n])}var i=function(){if(te(t.resolve))return Promise.resolve(t.resolve(t)).then(function(r){e.accounts[n]=r})}();return i&&i.then?i.then(o):o()});return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},function(e){try{if(!g(e))return Promise.resolve(o(e));for(var r=function(){var r,o,i,u=t[n],c=u.addr+"|"+u.keyId;e.accounts[c]=null!=e.accounts[c]?(r=e.accounts[c],o=A({tempId:c},u),{kind:ae([r.kind,o.kind]),tempId:ae([r.tempId,o.tempId]),addr:ae([r.addr,o.addr]),keyId:(i=[r.keyId,o.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(oe)[0]?i.filter(oe)[0]:null),sequenceNum:"number"==typeof se([r,o]).sequenceNum?se([r,o]).sequenceNum:r.sequenceNum,signature:ae([r.signature,o.signature]),signingFunction:ae([r.signingFunction,o.signingFunction]),resolve:ae([r.resolve,o.resolve]),role:{proposer:r.role.proposer||o.role.proposer,authorizer:r.role.authorizer||o.role.authorizer,payer:r.role.payer||o.role.payer,param:r.role.param||o.role.param}}):A({tempId:c},u),e.proposer===u.tempId&&(e.proposer=c),e.payer===u.tempId&&(e.payer=c),e.authorizations=e.authorizations.map(function(e){return e===u.tempId?c:e}),delete e.accounts[u.tempId]},n=0,t=Object.values(e.accounts);n<t.length;n++)r();for(var i=0,u=Object.values(e.accounts);i<u.length;i++){var c=u[i];ue(ce(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(e))}catch(e){return Promise.reject(e)}}]),le=function(e){try{if(!g(e)&&!I(e))return Promise.resolve(o(e));var r=Object.values(e.arguments);return Promise.resolve(Promise.all(r.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return A({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(r){return r.forEach(function(r){e.arguments[r.tempId]=A({},r,{asArgument:r.xform.asArgument(r.value)})}),o(e)})}catch(e){return Promise.reject(e)}},de=function(e){try{var r=function(e){if(n)return e;throw new Error("Invalid Cadence Value")},n=!1;if(!g(e)&&!I(e))return Promise.resolve(o(e));var t=b(e,"ix.cadence");if("string"==typeof t)return e.message.cadence=t,Promise.resolve(o(e));var i=function(){if("function"==typeof t){var r=Object.values(e.params);return Promise.resolve(Promise.all(r.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return A({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(r){return r.forEach(function(r){e.params[r.tempId]=r}),r=Object.fromEntries(r.filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]})),e.message.cadence=t(r),n=!0,o(e)})}}();return Promise.resolve(i&&i.then?i.then(r):r(i))}catch(e){return Promise.reject(e)}},me=function(e){try{var r,n,t,i,u=function(u){if(c)return u;function a(r){return o(e)}var s=ne(function(){return Promise.resolve(pe(e,t,P({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr}),payloadSigs:n}))).then(function(r){for(var n,t=O(i=r);!(n=t()).done;){var o=n.value;e.accounts[o.cid].signature=o.signature}})},function(o){throw console.error("Fetching of Outside Signatures",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o});return s&&s.then?s.then(a):a()},c=!1;if(!g(e))return Promise.resolve(o(e));try{(r=new Set(e.authorizations)).add(e.proposer),r.delete(e.payer),r=Array.from(r)}catch(o){throw console.error("Inside Signer Discovery",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o}try{t=new Set([e.payer]),t=Array.from(t)}catch(o){throw console.error("Outside Signer Discovery",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o}var a=ne(function(){return Promise.resolve(pe(e,r,k({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr})}))).then(function(r){for(var t,o=O(n=r);!(t=o()).done;){var i=t.value;e.accounts[i.cid].signature=i.signature}})},function(o){throw console.error("Fetching of Inside Signatures",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o});return Promise.resolve(a&&a.then?a.then(u):u(a))}catch(e){return Promise.reject(e)}},pe=function(e,r,n){void 0===r&&(r=[]);try{return Promise.all(r.map(function(r){try{return Promise.resolve(e.accounts[r].signingFunction({message:n,addr:e.accounts[r].addr,keyId:e.accounts[r].keyId,roles:e.accounts[r].role,interaction:e})).then(function(n){if(n.cid=r,e.accounts[r].addr!==n.addr)throw new Error(r+" — mismatching address in composite signature");if(e.accounts[r].keyId!==n.keyId)throw new Error(r+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ve=function(r){try{var n=b(r,"ix.validators",[]);return Promise.resolve(e(r,n.map(function(e){return function(r){return e(r,{Ok:o,Bad:h})}})))}catch(e){return Promise.reject(e)}};export{V as arg,K as args,B as authorization,z as authorizations,w as build,q as getAccount,N as getEvents,F as getLatestBlock,E as getTransactionStatus,Y as invariant,L as limit,D as param,T as params,$ as payer,G as ping,M as proposer,H as ref,j as resolve,fe as resolveAccounts,le as resolveArguments,de as resolveParams,me as resolveSignatures,ve as resolveValidators,J as script,W as transaction,X as validator}; | ||
import{pipe as r,interaction as e,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as i,makeGetLatestBlock as u,makeGetTransactionStatus as c,makeParam as a,makeArgument as s,makeProposer as f,makePayer as l,makePing as m,makeScript as d,put as p,makeTransaction as v,update as y,Bad as h,isTransaction as g,isScript as I,get as b}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{templar as P}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionPayload as k,encodeTransactionEnvelope as w}from"@onflow/encode";function j(n){return void 0===n&&(n=[]),r(e(),n)}var S=r;function A(){return(A=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r}).apply(this,arguments)}function x(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}function O(e){return void 0===e&&(e=[]),r(e.map(function(r){return n(A({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))}function z(r,e,n,t){return{addr:r,signingFunction:e,keyId:n,sequenceNum:t}}function B(e){return r([t,function(r){return r.accountAddr=e,o(r)}])}function q(e,n,t){return r([i,function(r){return r.events.eventType=e,o(r)},function(r){return r.events.start=n,o(r)},function(r){return r.events.end=t,o(r)}])}function N(e){return void 0===e&&(e=!1),r([u,function(r){return r.latestBlock.isSealed=e,o(r)}])}function E(e){return r([c,function(r){return r.transactionId=e,o(r)}])}function F(e){return r([function(r){return r.message.computeLimit=e,o(r)}])}function L(e){return void 0===e&&(e=[]),r(e.map(function(r){return a("function"==typeof r?{resolve:r}:r)}))}var T={asArgument:function(r){return r},asInjection:function(r){return r}};function C(r,e,n){return void 0===e&&(e=T),void 0===n&&(n=null),{key:n,value:r,xform:e}}function R(e){return void 0===e&&(e=[]),r(e.map(function(r){return s("function"==typeof r?{resolve:r}:r)}))}var V={asArgument:function(r){return r},asInjection:function(r){return r}};function K(r,e){return void 0===e&&(e=V),{value:r,xform:e}}var M=function(r){try{return U(r)?Promise.resolve(f({resolve:r,role:{proposer:!0}})):Promise.resolve(f(A({},r,{role:{proposer:!0}})))}catch(r){return Promise.reject(r)}},U=function(r){return"function"==typeof r};function $(r){return l(A({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))}function D(){return r([m])}function G(e){return r([function(r){return r.message.refBlock=e,o(r)}])}function H(){return r([d,p("ix.cadence",P.apply(void 0,arguments))])}var J=[];function Q(){return r([v,p("ix.cadence",P.apply(void 0,arguments)),function(r){return r.message.computeLimit=r.message.computeLimit||10,r.message.refBlock=r.message.refBlock||null,r.authorizations=r.authorizations||J,o(r)}])}function W(r){return y("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}function X(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];if(e.length>1){var t=e[0],i=e[1];return X(function(r,e){var n=e.Bad;return t?(0,e.Ok)(r):n(r,i)})}var u=e[0];return function(r){return u(r,{Ok:o,Bad:h})}}const Y=function(){function r(){}return r.prototype.then=function(e,n){const t=new r,o=this.s;if(o){const r=1&o?e:n;if(r){try{Z(t,1,r(this.v))}catch(r){Z(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?Z(t,1,e?e(o):o):n?Z(t,1,n(o)):Z(t,2,o)}catch(r){Z(t,2,r)}},t},r}();function Z(r,e,n){if(!r.s){if(n instanceof Y){if(!n.s)return void(n.o=Z.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(Z.bind(null,r,e),Z.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function _(r){return r instanceof Y&&1&r.s}const rr="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var er=function(r){return"function"==typeof r},nr=function(r){return"number"==typeof r},tr=function(r){return"string"==typeof r},or=function(r,e){if(!r){var n,t=new Error("INVARIANT "+e);t.stack=t.stack.split("\n").filter(function(r){return!/at invariant/.test(r)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},ir=function(r){return!(r.role.proposer&&!(tr(r.addr)&&nr(r.keyId)&&nr(r.sequenceNum)&&er(r.signingFunction))||r.role.payer&&!(tr(r.addr)&&nr(r.keyId)&&er(r.signingFunction))||r.role.authorizer&&!(tr(r.addr)&&nr(r.keyId)&&er(r.signingFunction)))},ur=function(r){return void 0===r&&(r=[]),r.filter(Boolean)[0]||null},cr=function(r){return void 0===r&&(r=[]),r.find(function(r){return r.role.proposer})||{}},ar=r([function(r){try{var e=function(){return o(r)};if(!g(r))return Promise.resolve(o(r));var n=function(r,e,n){if("function"==typeof r[rr]){var t,o,i,u=r[rr]();if(function r(n){try{for(;!(t=u.next()).done;)if((n=e(t.value))&&n.then){if(!_(n))return void n.then(r,i||(i=Z.bind(null,o=new Y,2)));n=n.v}o?Z(o,1,n):o=n}catch(r){Z(o||(o=new Y),2,r)}}(),u.return){var c=function(r){try{t.done||u.return()}catch(r){}return r};if(o&&o.then)return o.then(c,function(r){throw c(r)});c()}return o}if(!("length"in r))throw new TypeError("Object is not iterable");for(var a=[],s=0;s<r.length;s++)a.push(r[s]);return function(r,e,n){var t,o,i=-1;return function n(u){try{for(;++i<r.length;)if((u=e(i))&&u.then){if(!_(u))return void u.then(n,o||(o=Z.bind(null,t=new Y,2)));u=u.v}t?Z(t,1,u):t=u}catch(r){Z(t||(t=new Y),2,r)}}(),t}(a,function(r){return e(a[r])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){or(ir(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var i=function(){if(er(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return i&&i.then?i.then(o):o()});return Promise.resolve(n&&n.then?n.then(e):e())}catch(r){return Promise.reject(r)}},function(r){try{if(!g(r))return Promise.resolve(o(r));for(var e=function(){var e,o,i,u=t[n],c=u.addr+"|"+u.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],o=A({tempId:c},u),{kind:ur([e.kind,o.kind]),tempId:ur([e.tempId,o.tempId]),addr:ur([e.addr,o.addr]),keyId:(i=[e.keyId,o.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(nr)[0]?i.filter(nr)[0]:null),sequenceNum:"number"==typeof cr([e,o]).sequenceNum?cr([e,o]).sequenceNum:e.sequenceNum,signature:ur([e.signature,o.signature]),signingFunction:ur([e.signingFunction,o.signingFunction]),resolve:ur([e.resolve,o.resolve]),role:{proposer:e.role.proposer||o.role.proposer,authorizer:e.role.authorizer||o.role.authorizer,payer:e.role.payer||o.role.payer,param:e.role.param||o.role.param}}):A({tempId:c},u),r.proposer===u.tempId&&(r.proposer=c),r.payer===u.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(r){return r===u.tempId?c:r}),delete r.accounts[u.tempId]},n=0,t=Object.values(r.accounts);n<t.length;n++)e();for(var i=0,u=Object.values(r.accounts);i<u.length;i++){var c=u[i];or(ir(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}]),sr=function(r){try{if(!g(r)&&!I(r))return Promise.resolve(o(r));var e=Object.values(r.arguments);return Promise.resolve(Promise.all(e.map(function(r){try{var e=!1,n=function(){if("function"==typeof r.resolve)return e=!0,Promise.resolve(r.resolve()).then(function(e){return A({},e,{tempId:r.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return e?n:r}):e?n:r)}catch(r){return Promise.reject(r)}}))).then(function(e){return e.forEach(function(e){r.arguments[e.tempId]=A({},e,{asArgument:e.xform.asArgument(e.value)})}),o(r)})}catch(r){return Promise.reject(r)}},fr=function(r){try{var e=function(r){if(n)return r;throw new Error("Invalid Cadence Value")},n=!1;if(!g(r)&&!I(r))return Promise.resolve(o(r));var t=b(r,"ix.cadence");if("string"==typeof t)return r.message.cadence=t,Promise.resolve(o(r));var i=function(){if("function"==typeof t){var e=Object.values(r.params);return Promise.resolve(Promise.all(e.map(function(r){try{var e=!1,n=function(){if("function"==typeof r.resolve)return e=!0,Promise.resolve(r.resolve()).then(function(e){return A({},e,{tempId:r.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return e?n:r}):e?n:r)}catch(r){return Promise.reject(r)}}))).then(function(e){return e.forEach(function(e){r.params[e.tempId]=e}),e=Object.fromEntries(e.filter(function(r){return null!=r.key}).map(function(r){return[r.key,r.xform.asInjection(r.value)]})),r.message.cadence=t(e),n=!0,o(r)})}}();return Promise.resolve(i&&i.then?i.then(e):e(i))}catch(r){return Promise.reject(r)}};function lr(r){return{script:r.message.cadence,refBlock:r.message.refBlock||null,gasLimit:r.message.computeLimit,arguments:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),proposalKey:{address:r.accounts[r.proposer].addr,keyId:r.accounts[r.proposer].keyId,sequenceNum:r.accounts[r.proposer].sequenceNum},payer:r.accounts[r.payer].addr,authorizers:r.authorizations.map(function(e){return r.accounts[e].addr})}}var mr=function(r){try{if(!g(r))return Promise.resolve(r);var e=function(r){var e=new Set(r.authorizations);e.add(r.proposer),e.delete(r.payer),e=Array.from(e);var n=new Set([r.payer]);return{insideSigners:e,outsideSigners:n=Array.from(n)}}(r),n=e.outsideSigners;return Promise.resolve(dr(r,e.insideSigners,k(lr(r)))).then(function(e){var t=pr(r,e);return Promise.resolve(dr(r,n,w(A({},lr(r),{payloadSigs:t})))).then(function(e){return pr(r,e),r})})}catch(r){return Promise.reject(r)}},dr=function(r,e,n){void 0===e&&(e=[]);try{return Promise.all(e.map(function(e){try{return Promise.resolve(r.accounts[e].signingFunction({message:n,addr:r.accounts[e].addr,keyId:r.accounts[e].keyId,roles:r.accounts[e].role,interaction:r})).then(function(n){if(n.cid=e,r.accounts[e].addr!==n.addr)throw new Error(e+" — mismatching address in composite signature");if(r.accounts[e].keyId!==n.keyId)throw new Error(e+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(r){return Promise.reject(r)}}))}catch(r){return Promise.reject(r)}};function pr(r,e){for(var n,t=function(r,e){var n;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return x(r,void 0);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(r,void 0):void 0}}(r))){n&&(r=n);var t=0;return function(){return t>=r.length?{done:!0}:{done:!1,value:r[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=r[Symbol.iterator]()).next.bind(n)}(e);!(n=t()).done;){var o=n.value;r.accounts[o.cid].signature=o.signature}return e}var vr=function(e){try{var n=b(e,"ix.validators",[]);return Promise.resolve(r(e,n.map(function(r){return function(e){return r(e,{Ok:o,Bad:h})}})))}catch(r){return Promise.reject(r)}};export{K as arg,R as args,z as authorization,O as authorizations,j as build,B as getAccount,q as getEvents,N as getLatestBlock,E as getTransactionStatus,X as invariant,F as limit,C as param,L as params,$ as payer,D as ping,M as proposer,G as ref,S as resolve,ar as resolveAccounts,sr as resolveArguments,fr as resolveParams,mr as resolveSignatures,vr as resolveValidators,H as script,Q as transaction,W as validator}; | ||
//# sourceMappingURL=sdk.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{pipe as e,interaction as r,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as i,makeGetLatestBlock as u,makeGetTransactionStatus as c,makeParam as a,makeArgument as s,makeProposer as f,makePayer as l,makePing as d,makeScript as m,put as p,makeTransaction as v,update as y,Bad as h,isTransaction as g,isScript as I,get as b}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{templar as S}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionEnvelope as P,encodeTransactionPayload as k}from"@onflow/encode";function w(n){return void 0===n&&(n=[]),e(r(),n)}var j=e;function A(){return(A=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function x(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function O(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return x(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}function z(r){return void 0===r&&(r=[]),e(r.map(function(e){return n(A({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))}function B(e,r,n,t){return{addr:e,signingFunction:r,keyId:n,sequenceNum:t}}function q(r){return e([t,function(e){return e.accountAddr=r,o(e)}])}function N(r,n,t){return e([i,function(e){return e.events.eventType=r,o(e)},function(e){return e.events.start=n,o(e)},function(e){return e.events.end=t,o(e)}])}function F(r){return void 0===r&&(r=!1),e([u,function(e){return e.latestBlock.isSealed=r,o(e)}])}function E(r){return e([c,function(e){return e.transactionId=r,o(e)}])}function L(r){return e([function(e){return e.message.computeLimit=r,o(e)}])}function T(r){return void 0===r&&(r=[]),e(r.map(function(e){return a("function"==typeof e?{resolve:e}:e)}))}var C={asArgument:function(e){return e},asInjection:function(e){return e}};function D(e,r,n){return void 0===r&&(r=C),void 0===n&&(n=null),{key:n,value:e,xform:r}}function K(r){return void 0===r&&(r=[]),e(r.map(function(e){return s("function"==typeof e?{resolve:e}:e)}))}var R={asArgument:function(e){return e},asInjection:function(e){return e}};function V(e,r){return void 0===r&&(r=R),{value:e,xform:r}}var M=function(e){try{return U(e)?Promise.resolve(f({resolve:e,role:{proposer:!0}})):Promise.resolve(f(A({},e,{role:{proposer:!0}})))}catch(e){return Promise.reject(e)}},U=function(e){return"function"==typeof e};function $(e){return l(A({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))}function G(){return e([d])}function H(r){return e([function(e){return e.message.refBlock=r,o(e)}])}function J(){return e([m,p("ix.cadence",S.apply(void 0,arguments))])}var Q=[];function W(){return e([v,p("ix.cadence",S.apply(void 0,arguments)),function(e){return e.message.computeLimit=e.message.computeLimit||10,e.message.refBlock=e.message.refBlock||null,e.authorizations=e.authorizations||Q,o(e)}])}function X(e){return y("ix.validators",function(r){return Array.isArray(r)?r.push(e):[e]})}function Y(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];if(r.length>1){var t=r[0],i=r[1];return Y(function(e,r){var n=r.Bad;return t?(0,r.Ok)(e):n(e,i)})}var u=r[0];return function(e){return u(e,{Ok:o,Bad:h})}}const Z=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{_(t,1,e(this.v))}catch(e){_(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?_(t,1,r?r(o):o):n?_(t,1,n(o)):_(t,2,o)}catch(e){_(t,2,e)}},t},e}();function _(e,r,n){if(!e.s){if(n instanceof Z){if(!n.s)return void(n.o=_.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(_.bind(null,e,r),_.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function ee(e){return e instanceof Z&&1&e.s}const re="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function ne(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var te=function(e){return"function"==typeof e},oe=function(e){return"number"==typeof e},ie=function(e){return"string"==typeof e},ue=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},ce=function(e){return!(e.role.proposer&&!(ie(e.addr)&&oe(e.keyId)&&oe(e.sequenceNum)&&te(e.signingFunction))||e.role.payer&&!(ie(e.addr)&&oe(e.keyId)&&te(e.signingFunction))||e.role.authorizer&&!(ie(e.addr)&&oe(e.keyId)&&te(e.signingFunction)))},ae=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},se=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},fe=e([function(e){try{var r=function(){return o(e)};if(!g(e))return Promise.resolve(o(e));var n=function(e,r,n){if("function"==typeof e[re]){var t,o,i,u=e[re]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!ee(n))return void n.then(e,i||(i=_.bind(null,o=new Z,2)));n=n.v}o?_(o,1,n):o=n}catch(e){_(o||(o=new Z),2,e)}}(),u.return){var c=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(c,function(e){throw c(e)});c()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],s=0;s<e.length;s++)a.push(e[s]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!ee(u))return void u.then(n,o||(o=_.bind(null,t=new Z,2)));u=u.v}t?_(t,1,u):t=u}catch(e){_(t||(t=new Z),2,e)}}(),t}(a,function(e){return r(a[e])})}(Object.entries(e.accounts),function(r){var n=r[0],t=r[1];function o(){ue(ce(e.accounts[n]),"Account unable to fulfill role",e.accounts[n])}var i=function(){if(te(t.resolve))return Promise.resolve(t.resolve(t)).then(function(r){e.accounts[n]=r})}();return i&&i.then?i.then(o):o()});return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},function(e){try{if(!g(e))return Promise.resolve(o(e));for(var r=function(){var r,o,i,u=t[n],c=u.addr+"|"+u.keyId;e.accounts[c]=null!=e.accounts[c]?(r=e.accounts[c],o=A({tempId:c},u),{kind:ae([r.kind,o.kind]),tempId:ae([r.tempId,o.tempId]),addr:ae([r.addr,o.addr]),keyId:(i=[r.keyId,o.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(oe)[0]?i.filter(oe)[0]:null),sequenceNum:"number"==typeof se([r,o]).sequenceNum?se([r,o]).sequenceNum:r.sequenceNum,signature:ae([r.signature,o.signature]),signingFunction:ae([r.signingFunction,o.signingFunction]),resolve:ae([r.resolve,o.resolve]),role:{proposer:r.role.proposer||o.role.proposer,authorizer:r.role.authorizer||o.role.authorizer,payer:r.role.payer||o.role.payer,param:r.role.param||o.role.param}}):A({tempId:c},u),e.proposer===u.tempId&&(e.proposer=c),e.payer===u.tempId&&(e.payer=c),e.authorizations=e.authorizations.map(function(e){return e===u.tempId?c:e}),delete e.accounts[u.tempId]},n=0,t=Object.values(e.accounts);n<t.length;n++)r();for(var i=0,u=Object.values(e.accounts);i<u.length;i++){var c=u[i];ue(ce(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(e))}catch(e){return Promise.reject(e)}}]),le=function(e){try{if(!g(e)&&!I(e))return Promise.resolve(o(e));var r=Object.values(e.arguments);return Promise.resolve(Promise.all(r.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return A({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(r){return r.forEach(function(r){e.arguments[r.tempId]=A({},r,{asArgument:r.xform.asArgument(r.value)})}),o(e)})}catch(e){return Promise.reject(e)}},de=function(e){try{var r=function(e){if(n)return e;throw new Error("Invalid Cadence Value")},n=!1;if(!g(e)&&!I(e))return Promise.resolve(o(e));var t=b(e,"ix.cadence");if("string"==typeof t)return e.message.cadence=t,Promise.resolve(o(e));var i=function(){if("function"==typeof t){var r=Object.values(e.params);return Promise.resolve(Promise.all(r.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return A({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(r){return r.forEach(function(r){e.params[r.tempId]=r}),r=Object.fromEntries(r.filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]})),e.message.cadence=t(r),n=!0,o(e)})}}();return Promise.resolve(i&&i.then?i.then(r):r(i))}catch(e){return Promise.reject(e)}},me=function(e){try{var r,n,t,i,u=function(u){if(c)return u;function a(r){return o(e)}var s=ne(function(){return Promise.resolve(pe(e,t,P({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr}),payloadSigs:n}))).then(function(r){for(var n,t=O(i=r);!(n=t()).done;){var o=n.value;e.accounts[o.cid].signature=o.signature}})},function(o){throw console.error("Fetching of Outside Signatures",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o});return s&&s.then?s.then(a):a()},c=!1;if(!g(e))return Promise.resolve(o(e));try{(r=new Set(e.authorizations)).add(e.proposer),r.delete(e.payer),r=Array.from(r)}catch(o){throw console.error("Inside Signer Discovery",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o}try{t=new Set([e.payer]),t=Array.from(t)}catch(o){throw console.error("Outside Signer Discovery",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o}var a=ne(function(){return Promise.resolve(pe(e,r,k({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr})}))).then(function(r){for(var t,o=O(n=r);!(t=o()).done;){var i=t.value;e.accounts[i.cid].signature=i.signature}})},function(o){throw console.error("Fetching of Inside Signatures",o,{ix:e,insideSigners:r,insideSignatures:n,outsideSigners:t,outsideSignatures:i}),o});return Promise.resolve(a&&a.then?a.then(u):u(a))}catch(e){return Promise.reject(e)}},pe=function(e,r,n){void 0===r&&(r=[]);try{return Promise.all(r.map(function(r){try{return Promise.resolve(e.accounts[r].signingFunction({message:n,addr:e.accounts[r].addr,keyId:e.accounts[r].keyId,roles:e.accounts[r].role,interaction:e})).then(function(n){if(n.cid=r,e.accounts[r].addr!==n.addr)throw new Error(r+" — mismatching address in composite signature");if(e.accounts[r].keyId!==n.keyId)throw new Error(r+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}},ve=function(r){try{var n=b(r,"ix.validators",[]);return Promise.resolve(e(r,n.map(function(e){return function(r){return e(r,{Ok:o,Bad:h})}})))}catch(e){return Promise.reject(e)}};export{V as arg,K as args,B as authorization,z as authorizations,w as build,q as getAccount,N as getEvents,F as getLatestBlock,E as getTransactionStatus,Y as invariant,L as limit,D as param,T as params,$ as payer,G as ping,M as proposer,H as ref,j as resolve,fe as resolveAccounts,le as resolveArguments,de as resolveParams,me as resolveSignatures,ve as resolveValidators,J as script,W as transaction,X as validator}; | ||
import{pipe as r,interaction as e,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as i,makeGetLatestBlock as u,makeGetTransactionStatus as c,makeParam as a,makeArgument as s,makeProposer as f,makePayer as l,makePing as m,makeScript as d,put as p,makeTransaction as v,update as y,Bad as h,isTransaction as g,isScript as I,get as b}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{templar as P}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionPayload as k,encodeTransactionEnvelope as w}from"@onflow/encode";function j(n){return void 0===n&&(n=[]),r(e(),n)}var S=r;function A(){return(A=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r}).apply(this,arguments)}function x(r,e){(null==e||e>r.length)&&(e=r.length);for(var n=0,t=new Array(e);n<e;n++)t[n]=r[n];return t}function O(e){return void 0===e&&(e=[]),r(e.map(function(r){return n(A({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))}function z(r,e,n,t){return{addr:r,signingFunction:e,keyId:n,sequenceNum:t}}function B(e){return r([t,function(r){return r.accountAddr=e,o(r)}])}function q(e,n,t){return r([i,function(r){return r.events.eventType=e,o(r)},function(r){return r.events.start=n,o(r)},function(r){return r.events.end=t,o(r)}])}function N(e){return void 0===e&&(e=!1),r([u,function(r){return r.latestBlock.isSealed=e,o(r)}])}function E(e){return r([c,function(r){return r.transactionId=e,o(r)}])}function F(e){return r([function(r){return r.message.computeLimit=e,o(r)}])}function L(e){return void 0===e&&(e=[]),r(e.map(function(r){return a("function"==typeof r?{resolve:r}:r)}))}var T={asArgument:function(r){return r},asInjection:function(r){return r}};function C(r,e,n){return void 0===e&&(e=T),void 0===n&&(n=null),{key:n,value:r,xform:e}}function R(e){return void 0===e&&(e=[]),r(e.map(function(r){return s("function"==typeof r?{resolve:r}:r)}))}var V={asArgument:function(r){return r},asInjection:function(r){return r}};function K(r,e){return void 0===e&&(e=V),{value:r,xform:e}}var M=function(r){try{return U(r)?Promise.resolve(f({resolve:r,role:{proposer:!0}})):Promise.resolve(f(A({},r,{role:{proposer:!0}})))}catch(r){return Promise.reject(r)}},U=function(r){return"function"==typeof r};function $(r){return l(A({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))}function D(){return r([m])}function G(e){return r([function(r){return r.message.refBlock=e,o(r)}])}function H(){return r([d,p("ix.cadence",P.apply(void 0,arguments))])}var J=[];function Q(){return r([v,p("ix.cadence",P.apply(void 0,arguments)),function(r){return r.message.computeLimit=r.message.computeLimit||10,r.message.refBlock=r.message.refBlock||null,r.authorizations=r.authorizations||J,o(r)}])}function W(r){return y("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}function X(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];if(e.length>1){var t=e[0],i=e[1];return X(function(r,e){var n=e.Bad;return t?(0,e.Ok)(r):n(r,i)})}var u=e[0];return function(r){return u(r,{Ok:o,Bad:h})}}const Y=function(){function r(){}return r.prototype.then=function(e,n){const t=new r,o=this.s;if(o){const r=1&o?e:n;if(r){try{Z(t,1,r(this.v))}catch(r){Z(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?Z(t,1,e?e(o):o):n?Z(t,1,n(o)):Z(t,2,o)}catch(r){Z(t,2,r)}},t},r}();function Z(r,e,n){if(!r.s){if(n instanceof Y){if(!n.s)return void(n.o=Z.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(Z.bind(null,r,e),Z.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function _(r){return r instanceof Y&&1&r.s}const rr="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var er=function(r){return"function"==typeof r},nr=function(r){return"number"==typeof r},tr=function(r){return"string"==typeof r},or=function(r,e){if(!r){var n,t=new Error("INVARIANT "+e);t.stack=t.stack.split("\n").filter(function(r){return!/at invariant/.test(r)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},ir=function(r){return!(r.role.proposer&&!(tr(r.addr)&&nr(r.keyId)&&nr(r.sequenceNum)&&er(r.signingFunction))||r.role.payer&&!(tr(r.addr)&&nr(r.keyId)&&er(r.signingFunction))||r.role.authorizer&&!(tr(r.addr)&&nr(r.keyId)&&er(r.signingFunction)))},ur=function(r){return void 0===r&&(r=[]),r.filter(Boolean)[0]||null},cr=function(r){return void 0===r&&(r=[]),r.find(function(r){return r.role.proposer})||{}},ar=r([function(r){try{var e=function(){return o(r)};if(!g(r))return Promise.resolve(o(r));var n=function(r,e,n){if("function"==typeof r[rr]){var t,o,i,u=r[rr]();if(function r(n){try{for(;!(t=u.next()).done;)if((n=e(t.value))&&n.then){if(!_(n))return void n.then(r,i||(i=Z.bind(null,o=new Y,2)));n=n.v}o?Z(o,1,n):o=n}catch(r){Z(o||(o=new Y),2,r)}}(),u.return){var c=function(r){try{t.done||u.return()}catch(r){}return r};if(o&&o.then)return o.then(c,function(r){throw c(r)});c()}return o}if(!("length"in r))throw new TypeError("Object is not iterable");for(var a=[],s=0;s<r.length;s++)a.push(r[s]);return function(r,e,n){var t,o,i=-1;return function n(u){try{for(;++i<r.length;)if((u=e(i))&&u.then){if(!_(u))return void u.then(n,o||(o=Z.bind(null,t=new Y,2)));u=u.v}t?Z(t,1,u):t=u}catch(r){Z(t||(t=new Y),2,r)}}(),t}(a,function(r){return e(a[r])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){or(ir(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var i=function(){if(er(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return i&&i.then?i.then(o):o()});return Promise.resolve(n&&n.then?n.then(e):e())}catch(r){return Promise.reject(r)}},function(r){try{if(!g(r))return Promise.resolve(o(r));for(var e=function(){var e,o,i,u=t[n],c=u.addr+"|"+u.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],o=A({tempId:c},u),{kind:ur([e.kind,o.kind]),tempId:ur([e.tempId,o.tempId]),addr:ur([e.addr,o.addr]),keyId:(i=[e.keyId,o.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(nr)[0]?i.filter(nr)[0]:null),sequenceNum:"number"==typeof cr([e,o]).sequenceNum?cr([e,o]).sequenceNum:e.sequenceNum,signature:ur([e.signature,o.signature]),signingFunction:ur([e.signingFunction,o.signingFunction]),resolve:ur([e.resolve,o.resolve]),role:{proposer:e.role.proposer||o.role.proposer,authorizer:e.role.authorizer||o.role.authorizer,payer:e.role.payer||o.role.payer,param:e.role.param||o.role.param}}):A({tempId:c},u),r.proposer===u.tempId&&(r.proposer=c),r.payer===u.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(r){return r===u.tempId?c:r}),delete r.accounts[u.tempId]},n=0,t=Object.values(r.accounts);n<t.length;n++)e();for(var i=0,u=Object.values(r.accounts);i<u.length;i++){var c=u[i];or(ir(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}]),sr=function(r){try{if(!g(r)&&!I(r))return Promise.resolve(o(r));var e=Object.values(r.arguments);return Promise.resolve(Promise.all(e.map(function(r){try{var e=!1,n=function(){if("function"==typeof r.resolve)return e=!0,Promise.resolve(r.resolve()).then(function(e){return A({},e,{tempId:r.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return e?n:r}):e?n:r)}catch(r){return Promise.reject(r)}}))).then(function(e){return e.forEach(function(e){r.arguments[e.tempId]=A({},e,{asArgument:e.xform.asArgument(e.value)})}),o(r)})}catch(r){return Promise.reject(r)}},fr=function(r){try{var e=function(r){if(n)return r;throw new Error("Invalid Cadence Value")},n=!1;if(!g(r)&&!I(r))return Promise.resolve(o(r));var t=b(r,"ix.cadence");if("string"==typeof t)return r.message.cadence=t,Promise.resolve(o(r));var i=function(){if("function"==typeof t){var e=Object.values(r.params);return Promise.resolve(Promise.all(e.map(function(r){try{var e=!1,n=function(){if("function"==typeof r.resolve)return e=!0,Promise.resolve(r.resolve()).then(function(e){return A({},e,{tempId:r.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return e?n:r}):e?n:r)}catch(r){return Promise.reject(r)}}))).then(function(e){return e.forEach(function(e){r.params[e.tempId]=e}),e=Object.fromEntries(e.filter(function(r){return null!=r.key}).map(function(r){return[r.key,r.xform.asInjection(r.value)]})),r.message.cadence=t(e),n=!0,o(r)})}}();return Promise.resolve(i&&i.then?i.then(e):e(i))}catch(r){return Promise.reject(r)}};function lr(r){return{script:r.message.cadence,refBlock:r.message.refBlock||null,gasLimit:r.message.computeLimit,arguments:r.message.arguments.map(function(e){return r.arguments[e].asArgument}),proposalKey:{address:r.accounts[r.proposer].addr,keyId:r.accounts[r.proposer].keyId,sequenceNum:r.accounts[r.proposer].sequenceNum},payer:r.accounts[r.payer].addr,authorizers:r.authorizations.map(function(e){return r.accounts[e].addr})}}var mr=function(r){try{if(!g(r))return Promise.resolve(r);var e=function(r){var e=new Set(r.authorizations);e.add(r.proposer),e.delete(r.payer),e=Array.from(e);var n=new Set([r.payer]);return{insideSigners:e,outsideSigners:n=Array.from(n)}}(r),n=e.outsideSigners;return Promise.resolve(dr(r,e.insideSigners,k(lr(r)))).then(function(e){var t=pr(r,e);return Promise.resolve(dr(r,n,w(A({},lr(r),{payloadSigs:t})))).then(function(e){return pr(r,e),r})})}catch(r){return Promise.reject(r)}},dr=function(r,e,n){void 0===e&&(e=[]);try{return Promise.all(e.map(function(e){try{return Promise.resolve(r.accounts[e].signingFunction({message:n,addr:r.accounts[e].addr,keyId:r.accounts[e].keyId,roles:r.accounts[e].role,interaction:r})).then(function(n){if(n.cid=e,r.accounts[e].addr!==n.addr)throw new Error(e+" — mismatching address in composite signature");if(r.accounts[e].keyId!==n.keyId)throw new Error(e+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(r){return Promise.reject(r)}}))}catch(r){return Promise.reject(r)}};function pr(r,e){for(var n,t=function(r,e){var n;if("undefined"==typeof Symbol||null==r[Symbol.iterator]){if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return x(r,void 0);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(r,void 0):void 0}}(r))){n&&(r=n);var t=0;return function(){return t>=r.length?{done:!0}:{done:!1,value:r[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=r[Symbol.iterator]()).next.bind(n)}(e);!(n=t()).done;){var o=n.value;r.accounts[o.cid].signature=o.signature}return e}var vr=function(e){try{var n=b(e,"ix.validators",[]);return Promise.resolve(r(e,n.map(function(r){return function(e){return r(e,{Ok:o,Bad:h})}})))}catch(r){return Promise.reject(r)}};export{K as arg,R as args,z as authorization,O as authorizations,j as build,B as getAccount,q as getEvents,N as getLatestBlock,E as getTransactionStatus,X as invariant,F as limit,C as param,L as params,$ as payer,D as ping,M as proposer,G as ref,S as resolve,ar as resolveAccounts,sr as resolveArguments,fr as resolveParams,mr as resolveSignatures,vr as resolveValidators,H as script,Q as transaction,W as validator}; | ||
//# sourceMappingURL=sdk.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@onflow/interaction"),require("@onflow/send"),require("@onflow/decode"),require("@qvvg/templar"),require("@onflow/encode")):"function"==typeof define&&define.amd?define(["exports","@onflow/interaction","@onflow/send","@onflow/decode","@qvvg/templar","@onflow/encode"],r):r((e=e||self).sdk={},e.interaction,e.send,e.decode,e.templar,e.encode)}(this,function(e,r,n,t,o,i){var u=r.pipe;function a(){return(a=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function c(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function s(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return c(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}var f={asArgument:function(e){return e},asInjection:function(e){return e}},d={asArgument:function(e){return e},asInjection:function(e){return e}},l=[];const p=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{m(t,1,e(this.v))}catch(e){m(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?m(t,1,r?r(o):o):n?m(t,1,n(o)):m(t,2,o)}catch(e){m(t,2,e)}},t},e}();function m(e,r,n){if(!e.s){if(n instanceof p){if(!n.s)return void(n.o=m.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(m.bind(null,e,r),m.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function v(e){return e instanceof p&&1&e.s}const y="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function g(e,r){try{var n=e()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var h=function(e){return"function"==typeof e},k=function(e){return"number"==typeof e},b=function(e){return"string"==typeof e},P=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},O=function(e){return!(e.role.proposer&&!(b(e.addr)&&k(e.keyId)&&k(e.sequenceNum)&&h(e.signingFunction))||e.role.payer&&!(b(e.addr)&&k(e.keyId)&&h(e.signingFunction))||e.role.authorizer&&!(b(e.addr)&&k(e.keyId)&&h(e.signingFunction)))},I=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},S=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},w=r.pipe([function(e){try{var n=function(){return r.Ok(e)};if(!r.isTransaction(e))return Promise.resolve(r.Ok(e));var t=function(e,r,n){if("function"==typeof e[y]){var t,o,i,u=e[y]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!v(n))return void n.then(e,i||(i=m.bind(null,o=new p,2)));n=n.v}o?m(o,1,n):o=n}catch(e){m(o||(o=new p),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!v(u))return void u.then(n,o||(o=m.bind(null,t=new p,2)));u=u.v}t?m(t,1,u):t=u}catch(e){m(t||(t=new p),2,e)}}(),t}(c,function(e){return r(c[e])})}(Object.entries(e.accounts),function(r){var n=r[0],t=r[1];function o(){P(O(e.accounts[n]),"Account unable to fulfill role",e.accounts[n])}var i=function(){if(h(t.resolve))return Promise.resolve(t.resolve(t)).then(function(r){e.accounts[n]=r})}();return i&&i.then?i.then(o):o()});return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},function(e){try{if(!r.isTransaction(e))return Promise.resolve(r.Ok(e));for(var n=function(){var r,n,i,u=o[t],c=u.addr+"|"+u.keyId;e.accounts[c]=null!=e.accounts[c]?(r=e.accounts[c],n=a({tempId:c},u),{kind:I([r.kind,n.kind]),tempId:I([r.tempId,n.tempId]),addr:I([r.addr,n.addr]),keyId:(i=[r.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(k)[0]?i.filter(k)[0]:null),sequenceNum:"number"==typeof S([r,n]).sequenceNum?S([r,n]).sequenceNum:r.sequenceNum,signature:I([r.signature,n.signature]),signingFunction:I([r.signingFunction,n.signingFunction]),resolve:I([r.resolve,n.resolve]),role:{proposer:r.role.proposer||n.role.proposer,authorizer:r.role.authorizer||n.role.authorizer,payer:r.role.payer||n.role.payer,param:r.role.param||n.role.param}}):a({tempId:c},u),e.proposer===u.tempId&&(e.proposer=c),e.payer===u.tempId&&(e.payer=c),e.authorizations=e.authorizations.map(function(e){return e===u.tempId?c:e}),delete e.accounts[u.tempId]},t=0,o=Object.values(e.accounts);t<o.length;t++)n();for(var i=0,u=Object.values(e.accounts);i<u.length;i++){var c=u[i];P(O(c),"Account unable to fulfill roles",c)}return Promise.resolve(r.Ok(e))}catch(e){return Promise.reject(e)}}]),j=function(e,r,n){void 0===r&&(r=[]);try{return Promise.all(r.map(function(r){try{return Promise.resolve(e.accounts[r].signingFunction({message:n,addr:e.accounts[r].addr,keyId:e.accounts[r].keyId,roles:e.accounts[r].role,interaction:e})).then(function(n){if(n.cid=r,e.accounts[r].addr!==n.addr)throw new Error(r+" — mismatching address in composite signature");if(e.accounts[r].keyId!==n.keyId)throw new Error(r+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return n.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"decodeResponse",{enumerable:!0,get:function(){return t.decodeResponse}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return o.templar}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return o.templar}}),e.arg=function(e,r){return void 0===r&&(r=d),{value:e,xform:r}},e.args=function(e){return void 0===e&&(e=[]),r.pipe(e.map(function(e){return r.makeArgument("function"==typeof e?{resolve:e}:e)}))},e.authorization=function(e,r,n,t){return{addr:e,signingFunction:r,keyId:n,sequenceNum:t}},e.authorizations=function(e){return void 0===e&&(e=[]),r.pipe(e.map(function(e){return r.makeAuthorizer(a({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))},e.build=function(e){return void 0===e&&(e=[]),r.pipe(r.interaction(),e)},e.getAccount=function(e){return r.pipe([r.makeGetAccount,function(n){return n.accountAddr=e,r.Ok(n)}])},e.getEvents=function(e,n,t){return r.pipe([r.makeGetEvents,function(n){return n.events.eventType=e,r.Ok(n)},function(e){return e.events.start=n,r.Ok(e)},function(e){return e.events.end=t,r.Ok(e)}])},e.getLatestBlock=function(e){return void 0===e&&(e=!1),r.pipe([r.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=e,r.Ok(n)}])},e.getTransactionStatus=function(e){return r.pipe([r.makeGetTransactionStatus,function(n){return n.transactionId=e,r.Ok(n)}])},e.invariant=function e(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.length>1){var i=t[0],u=t[1];return e(function(e,r){var n=r.Bad;return i?(0,r.Ok)(e):n(e,u)})}var a=t[0];return function(e){return a(e,{Ok:r.Ok,Bad:r.Bad})}},e.limit=function(e){return r.pipe([function(n){return n.message.computeLimit=e,r.Ok(n)}])},e.param=function(e,r,n){return void 0===r&&(r=f),void 0===n&&(n=null),{key:n,value:e,xform:r}},e.params=function(e){return void 0===e&&(e=[]),r.pipe(e.map(function(e){return r.makeParam("function"==typeof e?{resolve:e}:e)}))},e.payer=function(e){return r.makePayer(a({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))},e.ping=function(){return r.pipe([r.makePing])},e.proposer=function(e){try{return Promise.resolve(r.makeProposer("function"==typeof e?{resolve:e,role:{proposer:!0}}:a({},e,{role:{proposer:!0}})))}catch(e){return Promise.reject(e)}},e.ref=function(e){return r.pipe([function(n){return n.message.refBlock=e,r.Ok(n)}])},e.resolve=u,e.resolveAccounts=w,e.resolveArguments=function(e){try{if(!r.isTransaction(e)&&!r.isScript(e))return Promise.resolve(r.Ok(e));var n=Object.values(e.arguments);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return a({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(r){e.arguments[r.tempId]=a({},r,{asArgument:r.xform.asArgument(r.value)})}),r.Ok(e)})}catch(e){return Promise.reject(e)}},e.resolveParams=function(e){try{var n=function(e){if(t)return e;throw new Error("Invalid Cadence Value")},t=!1;if(!r.isTransaction(e)&&!r.isScript(e))return Promise.resolve(r.Ok(e));var o=r.get(e,"ix.cadence");if("string"==typeof o)return e.message.cadence=o,Promise.resolve(r.Ok(e));var i=function(){if("function"==typeof o){var n=Object.values(e.params);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return a({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(r){e.params[r.tempId]=r}),n=Object.fromEntries(n.filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]})),e.message.cadence=o(n),t=!0,r.Ok(e)})}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}},e.resolveSignatures=function(e){try{var n,t,o,u,a=function(a){if(c)return a;function f(n){return r.Ok(e)}var d=g(function(){return Promise.resolve(j(e,o,i.encodeTransactionEnvelope({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr}),payloadSigs:t}))).then(function(r){for(var n,t=s(u=r);!(n=t()).done;){var o=n.value;e.accounts[o.cid].signature=o.signature}})},function(r){throw console.error("Fetching of Outside Signatures",r,{ix:e,insideSigners:n,insideSignatures:t,outsideSigners:o,outsideSignatures:u}),r});return d&&d.then?d.then(f):f()},c=!1;if(!r.isTransaction(e))return Promise.resolve(r.Ok(e));try{(n=new Set(e.authorizations)).add(e.proposer),n.delete(e.payer),n=Array.from(n)}catch(r){throw console.error("Inside Signer Discovery",r,{ix:e,insideSigners:n,insideSignatures:t,outsideSigners:o,outsideSignatures:u}),r}try{o=new Set([e.payer]),o=Array.from(o)}catch(r){throw console.error("Outside Signer Discovery",r,{ix:e,insideSigners:n,insideSignatures:t,outsideSigners:o,outsideSignatures:u}),r}var f=g(function(){return Promise.resolve(j(e,n,i.encodeTransactionPayload({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr})}))).then(function(r){for(var n,o=s(t=r);!(n=o()).done;){var i=n.value;e.accounts[i.cid].signature=i.signature}})},function(r){throw console.error("Fetching of Inside Signatures",r,{ix:e,insideSigners:n,insideSignatures:t,outsideSigners:o,outsideSignatures:u}),r});return Promise.resolve(f&&f.then?f.then(a):a(f))}catch(e){return Promise.reject(e)}},e.resolveValidators=function(e){try{var n=r.get(e,"ix.validators",[]);return Promise.resolve(r.pipe(e,n.map(function(e){return function(n){return e(n,{Ok:r.Ok,Bad:r.Bad})}})))}catch(e){return Promise.reject(e)}},e.script=function(){return r.pipe([r.makeScript,r.put("ix.cadence",o.templar.apply(void 0,arguments))])},e.transaction=function(){return r.pipe([r.makeTransaction,r.put("ix.cadence",o.templar.apply(void 0,arguments)),function(e){return e.message.computeLimit=e.message.computeLimit||10,e.message.refBlock=e.message.refBlock||null,e.authorizations=e.authorizations||l,r.Ok(e)}])},e.validator=function(e){return r.update("ix.validators",function(r){return Array.isArray(r)?r.push(e):[e]})}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@onflow/interaction"),require("@onflow/send"),require("@onflow/decode"),require("@qvvg/templar"),require("@onflow/encode")):"function"==typeof define&&define.amd?define(["exports","@onflow/interaction","@onflow/send","@onflow/decode","@qvvg/templar","@onflow/encode"],r):r((e=e||self).sdk={},e.interaction,e.send,e.decode,e.templar,e.encode)}(this,function(e,r,n,t,o,i){var u=r.pipe;function a(){return(a=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}function c(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}var s={asArgument:function(e){return e},asInjection:function(e){return e}},f={asArgument:function(e){return e},asInjection:function(e){return e}},l=[];const p=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{d(t,1,e(this.v))}catch(e){d(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?d(t,1,r?r(o):o):n?d(t,1,n(o)):d(t,2,o)}catch(e){d(t,2,e)}},t},e}();function d(e,r,n){if(!e.s){if(n instanceof p){if(!n.s)return void(n.o=d.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(d.bind(null,e,r),d.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function m(e){return e instanceof p&&1&e.s}const v="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var y=function(e){return"function"==typeof e},g=function(e){return"number"==typeof e},h=function(e){return"string"==typeof e},k=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},b=function(e){return!(e.role.proposer&&!(h(e.addr)&&g(e.keyId)&&g(e.sequenceNum)&&y(e.signingFunction))||e.role.payer&&!(h(e.addr)&&g(e.keyId)&&y(e.signingFunction))||e.role.authorizer&&!(h(e.addr)&&g(e.keyId)&&y(e.signingFunction)))},P=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},O=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},I=r.pipe([function(e){try{var n=function(){return r.Ok(e)};if(!r.isTransaction(e))return Promise.resolve(r.Ok(e));var t=function(e,r,n){if("function"==typeof e[v]){var t,o,i,u=e[v]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!m(n))return void n.then(e,i||(i=d.bind(null,o=new p,2)));n=n.v}o?d(o,1,n):o=n}catch(e){d(o||(o=new p),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!m(u))return void u.then(n,o||(o=d.bind(null,t=new p,2)));u=u.v}t?d(t,1,u):t=u}catch(e){d(t||(t=new p),2,e)}}(),t}(c,function(e){return r(c[e])})}(Object.entries(e.accounts),function(r){var n=r[0],t=r[1];function o(){k(b(e.accounts[n]),"Account unable to fulfill role",e.accounts[n])}var i=function(){if(y(t.resolve))return Promise.resolve(t.resolve(t)).then(function(r){e.accounts[n]=r})}();return i&&i.then?i.then(o):o()});return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},function(e){try{if(!r.isTransaction(e))return Promise.resolve(r.Ok(e));for(var n=function(){var r,n,i,u=o[t],c=u.addr+"|"+u.keyId;e.accounts[c]=null!=e.accounts[c]?(r=e.accounts[c],n=a({tempId:c},u),{kind:P([r.kind,n.kind]),tempId:P([r.tempId,n.tempId]),addr:P([r.addr,n.addr]),keyId:(i=[r.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(g)[0]?i.filter(g)[0]:null),sequenceNum:"number"==typeof O([r,n]).sequenceNum?O([r,n]).sequenceNum:r.sequenceNum,signature:P([r.signature,n.signature]),signingFunction:P([r.signingFunction,n.signingFunction]),resolve:P([r.resolve,n.resolve]),role:{proposer:r.role.proposer||n.role.proposer,authorizer:r.role.authorizer||n.role.authorizer,payer:r.role.payer||n.role.payer,param:r.role.param||n.role.param}}):a({tempId:c},u),e.proposer===u.tempId&&(e.proposer=c),e.payer===u.tempId&&(e.payer=c),e.authorizations=e.authorizations.map(function(e){return e===u.tempId?c:e}),delete e.accounts[u.tempId]},t=0,o=Object.values(e.accounts);t<o.length;t++)n();for(var i=0,u=Object.values(e.accounts);i<u.length;i++){var c=u[i];k(b(c),"Account unable to fulfill roles",c)}return Promise.resolve(r.Ok(e))}catch(e){return Promise.reject(e)}}]);function j(e){return{script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,arguments:e.message.arguments.map(function(r){return e.arguments[r].asArgument}),proposalKey:{address:e.accounts[e.proposer].addr,keyId:e.accounts[e.proposer].keyId,sequenceNum:e.accounts[e.proposer].sequenceNum},payer:e.accounts[e.payer].addr,authorizers:e.authorizations.map(function(r){return e.accounts[r].addr})}}var w=function(e,r,n){void 0===r&&(r=[]);try{return Promise.all(r.map(function(r){try{return Promise.resolve(e.accounts[r].signingFunction({message:n,addr:e.accounts[r].addr,keyId:e.accounts[r].keyId,roles:e.accounts[r].role,interaction:e})).then(function(n){if(n.cid=r,e.accounts[r].addr!==n.addr)throw new Error(r+" — mismatching address in composite signature");if(e.accounts[r].keyId!==n.keyId)throw new Error(r+" — mismatching keyId in composite signature");return n.sig=n.signature,n.address=n.addr,n})}catch(e){return Promise.reject(e)}}))}catch(e){return Promise.reject(e)}};function S(e,r){for(var n,t=function(e,r){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,r){if(e){if("string"==typeof e)return c(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,void 0):void 0}}(e))){n&&(e=n);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=e[Symbol.iterator]()).next.bind(n)}(r);!(n=t()).done;){var o=n.value;e.accounts[o.cid].signature=o.signature}return r}Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return r.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return r.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return r.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return r.why}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return n.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"decodeResponse",{enumerable:!0,get:function(){return t.decodeResponse}}),Object.defineProperty(e,"cadence",{enumerable:!0,get:function(){return o.templar}}),Object.defineProperty(e,"cdc",{enumerable:!0,get:function(){return o.templar}}),e.arg=function(e,r){return void 0===r&&(r=f),{value:e,xform:r}},e.args=function(e){return void 0===e&&(e=[]),r.pipe(e.map(function(e){return r.makeArgument("function"==typeof e?{resolve:e}:e)}))},e.authorization=function(e,r,n,t){return{addr:e,signingFunction:r,keyId:n,sequenceNum:t}},e.authorizations=function(e){return void 0===e&&(e=[]),r.pipe(e.map(function(e){return r.makeAuthorizer(a({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))},e.build=function(e){return void 0===e&&(e=[]),r.pipe(r.interaction(),e)},e.getAccount=function(e){return r.pipe([r.makeGetAccount,function(n){return n.accountAddr=e,r.Ok(n)}])},e.getEvents=function(e,n,t){return r.pipe([r.makeGetEvents,function(n){return n.events.eventType=e,r.Ok(n)},function(e){return e.events.start=n,r.Ok(e)},function(e){return e.events.end=t,r.Ok(e)}])},e.getLatestBlock=function(e){return void 0===e&&(e=!1),r.pipe([r.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=e,r.Ok(n)}])},e.getTransactionStatus=function(e){return r.pipe([r.makeGetTransactionStatus,function(n){return n.transactionId=e,r.Ok(n)}])},e.invariant=function e(){for(var n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];if(t.length>1){var i=t[0],u=t[1];return e(function(e,r){var n=r.Bad;return i?(0,r.Ok)(e):n(e,u)})}var a=t[0];return function(e){return a(e,{Ok:r.Ok,Bad:r.Bad})}},e.limit=function(e){return r.pipe([function(n){return n.message.computeLimit=e,r.Ok(n)}])},e.param=function(e,r,n){return void 0===r&&(r=s),void 0===n&&(n=null),{key:n,value:e,xform:r}},e.params=function(e){return void 0===e&&(e=[]),r.pipe(e.map(function(e){return r.makeParam("function"==typeof e?{resolve:e}:e)}))},e.payer=function(e){return r.makePayer(a({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))},e.ping=function(){return r.pipe([r.makePing])},e.proposer=function(e){try{return Promise.resolve(r.makeProposer("function"==typeof e?{resolve:e,role:{proposer:!0}}:a({},e,{role:{proposer:!0}})))}catch(e){return Promise.reject(e)}},e.ref=function(e){return r.pipe([function(n){return n.message.refBlock=e,r.Ok(n)}])},e.resolve=u,e.resolveAccounts=I,e.resolveArguments=function(e){try{if(!r.isTransaction(e)&&!r.isScript(e))return Promise.resolve(r.Ok(e));var n=Object.values(e.arguments);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return a({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(r){e.arguments[r.tempId]=a({},r,{asArgument:r.xform.asArgument(r.value)})}),r.Ok(e)})}catch(e){return Promise.reject(e)}},e.resolveParams=function(e){try{var n=function(e){if(t)return e;throw new Error("Invalid Cadence Value")},t=!1;if(!r.isTransaction(e)&&!r.isScript(e))return Promise.resolve(r.Ok(e));var o=r.get(e,"ix.cadence");if("string"==typeof o)return e.message.cadence=o,Promise.resolve(r.Ok(e));var i=function(){if("function"==typeof o){var n=Object.values(e.params);return Promise.resolve(Promise.all(n.map(function(e){try{var r=!1,n=function(){if("function"==typeof e.resolve)return r=!0,Promise.resolve(e.resolve()).then(function(r){return a({},r,{tempId:e.tempId})})}();return Promise.resolve(n&&n.then?n.then(function(n){return r?n:e}):r?n:e)}catch(e){return Promise.reject(e)}}))).then(function(n){return n.forEach(function(r){e.params[r.tempId]=r}),n=Object.fromEntries(n.filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]})),e.message.cadence=o(n),t=!0,r.Ok(e)})}}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}},e.resolveSignatures=function(e){try{if(!r.isTransaction(e))return Promise.resolve(e);var n=function(e){var r=new Set(e.authorizations);r.add(e.proposer),r.delete(e.payer),r=Array.from(r);var n=new Set([e.payer]);return{insideSigners:r,outsideSigners:n=Array.from(n)}}(e),t=n.outsideSigners;return Promise.resolve(w(e,n.insideSigners,i.encodeTransactionPayload(j(e)))).then(function(r){var n=S(e,r);return Promise.resolve(w(e,t,i.encodeTransactionEnvelope(a({},j(e),{payloadSigs:n})))).then(function(r){return S(e,r),e})})}catch(e){return Promise.reject(e)}},e.resolveValidators=function(e){try{var n=r.get(e,"ix.validators",[]);return Promise.resolve(r.pipe(e,n.map(function(e){return function(n){return e(n,{Ok:r.Ok,Bad:r.Bad})}})))}catch(e){return Promise.reject(e)}},e.script=function(){return r.pipe([r.makeScript,r.put("ix.cadence",o.templar.apply(void 0,arguments))])},e.transaction=function(){return r.pipe([r.makeTransaction,r.put("ix.cadence",o.templar.apply(void 0,arguments)),function(e){return e.message.computeLimit=e.message.computeLimit||10,e.message.refBlock=e.message.refBlock||null,e.authorizations=e.authorizations||l,r.Ok(e)}])},e.validator=function(e){return r.update("ix.validators",function(r){return Array.isArray(r)?r.push(e):[e]})}}); | ||
//# sourceMappingURL=sdk.umd.js.map |
{ | ||
"name": "@onflow/sdk", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"description": "Flow SDK", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -1,7 +0,23 @@ | ||
import {Ok, isTransaction} from "@onflow/interaction" | ||
import {isTransaction} from "@onflow/interaction" | ||
import { | ||
encodeTransactionPayload, | ||
encodeTransactionEnvelope, | ||
encodeTransactionPayload as encodeInsideMessage, | ||
encodeTransactionEnvelope as encodeOutsideMessage, | ||
} from "@onflow/encode" | ||
function prepForEncoding(ix) { | ||
return { | ||
script: ix.message.cadence, | ||
refBlock: ix.message.refBlock || null, | ||
gasLimit: ix.message.computeLimit, | ||
arguments: ix.message.arguments.map(cid => ix.arguments[cid].asArgument), | ||
proposalKey: { | ||
address: ix.accounts[ix.proposer].addr, | ||
keyId: ix.accounts[ix.proposer].keyId, | ||
sequenceNum: ix.accounts[ix.proposer].sequenceNum, | ||
}, | ||
payer: ix.accounts[ix.payer].addr, | ||
authorizers: ix.authorizations.map(cid => ix.accounts[cid].addr), | ||
} | ||
} | ||
async function fetchSignatures(ix, signers = [], message) { | ||
@@ -31,107 +47,52 @@ return Promise.all( | ||
export async function resolveSignatures(ix) { | ||
if (!isTransaction(ix)) return Ok(ix) | ||
function collateSigners(ix) { | ||
// inside signers are: (authorizers + proposer) - payer | ||
let insideSigners = new Set(ix.authorizations) | ||
insideSigners.add(ix.proposer) | ||
insideSigners.delete(ix.payer) | ||
insideSigners = Array.from(insideSigners) | ||
var insideSigners, insideSignatures, outsideSigners, outsideSignatures | ||
// outside signers are: payer | ||
let outsideSigners = new Set([ix.payer]) | ||
outsideSigners = Array.from(outsideSigners) | ||
// inside signers are: (authorizers + proposer) - payer | ||
try { | ||
insideSigners = new Set(ix.authorizations) | ||
insideSigners.add(ix.proposer) | ||
insideSigners.delete(ix.payer) | ||
insideSigners = Array.from(insideSigners) | ||
} catch (error) { | ||
console.error("Inside Signer Discovery", error, { | ||
ix, | ||
insideSigners, | ||
insideSignatures, | ||
outsideSigners, | ||
outsideSignatures, | ||
}) | ||
throw error | ||
} | ||
return {insideSigners, outsideSigners} | ||
} | ||
// outside signers are: payer | ||
try { | ||
outsideSigners = new Set([ix.payer]) | ||
outsideSigners = Array.from(outsideSigners) | ||
} catch (error) { | ||
console.error("Outside Signer Discovery", error, { | ||
ix, | ||
insideSigners, | ||
insideSignatures, | ||
outsideSigners, | ||
outsideSignatures, | ||
}) | ||
throw error | ||
function mutateAccountsWithSignatures(ix, compSigs) { | ||
for (let {cid, signature} of compSigs) { | ||
ix.accounts[cid].signature = signature | ||
} | ||
return compSigs | ||
} | ||
export async function resolveSignatures(ix) { | ||
if (!isTransaction(ix)) return ix | ||
const {insideSigners, outsideSigners} = collateSigners(ix) | ||
// Get inside composite signatures for inside payload in parallel | ||
try { | ||
insideSignatures = await fetchSignatures( | ||
const insideSignatures = mutateAccountsWithSignatures( | ||
ix, | ||
await fetchSignatures( | ||
ix, | ||
insideSigners, | ||
encodeTransactionPayload({ | ||
script: ix.message.cadence, | ||
refBlock: ix.message.refBlock || null, | ||
gasLimit: ix.message.computeLimit, | ||
proposalKey: { | ||
address: ix.accounts[ix.proposer].addr, | ||
keyId: ix.accounts[ix.proposer].keyId, | ||
sequenceNum: ix.accounts[ix.proposer].sequenceNum, | ||
}, | ||
payer: ix.accounts[ix.payer].addr, | ||
authorizers: ix.authorizations.map(cid => ix.accounts[cid].addr), | ||
}) | ||
encodeInsideMessage(prepForEncoding(ix)) | ||
) | ||
// add signatures to accounts | ||
for (let {cid, signature} of insideSignatures) { | ||
ix.accounts[cid].signature = signature | ||
} | ||
} catch (error) { | ||
console.error("Fetching of Inside Signatures", error, { | ||
ix, | ||
insideSigners, | ||
insideSignatures, | ||
outsideSigners, | ||
outsideSignatures, | ||
}) | ||
throw error | ||
} | ||
) | ||
// Get outside composite signatures for outside payload in parallel | ||
try { | ||
outsideSignatures = await fetchSignatures( | ||
const outsideSignatures = mutateAccountsWithSignatures( | ||
ix, | ||
await fetchSignatures( | ||
ix, | ||
outsideSigners, | ||
encodeTransactionEnvelope({ | ||
script: ix.message.cadence, | ||
refBlock: ix.message.refBlock || null, | ||
gasLimit: ix.message.computeLimit, | ||
proposalKey: { | ||
address: ix.accounts[ix.proposer].addr, | ||
keyId: ix.accounts[ix.proposer].keyId, | ||
sequenceNum: ix.accounts[ix.proposer].sequenceNum, | ||
}, | ||
payer: ix.accounts[ix.payer].addr, | ||
authorizers: ix.authorizations.map(cid => ix.accounts[cid].addr), | ||
encodeOutsideMessage({ | ||
...prepForEncoding(ix), | ||
payloadSigs: insideSignatures, | ||
}) | ||
) | ||
// add signatures to accounts | ||
for (let {cid, signature} of outsideSignatures) { | ||
ix.accounts[cid].signature = signature | ||
} | ||
} catch (error) { | ||
console.error("Fetching of Outside Signatures", error, { | ||
ix, | ||
insideSigners, | ||
insideSignatures, | ||
outsideSigners, | ||
outsideSignatures, | ||
}) | ||
throw error | ||
} | ||
) | ||
return Ok(ix) | ||
return ix | ||
} | ||
@@ -141,3 +102,3 @@ | ||
// | ||
// encodeTransactionPayload({ | ||
// encodeInsideMessage({ | ||
// cadence: ___, | ||
@@ -155,3 +116,3 @@ // refBlock: ___, | ||
// | ||
// encodeTransactionPayload({ | ||
// encodeInsideMessage({ | ||
// ...ix.message, | ||
@@ -163,3 +124,3 @@ // proposer: ix.accounts[ix.proposer], | ||
// | ||
// encodeTransactionEnvelope({ | ||
// encodeOutsideMessage({ | ||
// cadence: ___, | ||
@@ -178,3 +139,3 @@ // refBlock: ___, | ||
// | ||
// encodeTransactionEnvelope({ | ||
// encodeOutsideMessage({ | ||
// ...ix.message, | ||
@@ -181,0 +142,0 @@ // proposer: ix.accounts[ix.proposer], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39
278854
846