@onflow/sdk
Advanced tools
Comparing version 0.0.30 to 0.0.31
@@ -5,2 +5,11 @@ ### Unreleased | ||
### 0.0.31 -- 2020-08-25 | ||
- 2020-08-25 -- VSN `@onflow/send` 0.0.17 -> 0.0.20 | ||
- 2020-08-25 -- VSN `@onflow/interaction` 0.0.9 -> 0.0.10 | ||
- 2020-08-25 -- VSN `@onflow/decode` 0.0.6 -> 0.0.7 | ||
- 2020-08-24 -- Implements GetBlockByHeight and GetBlockById interaction builders. | ||
- 2020-08-13 -- Updates Readme with an overview of the JS-SDK | ||
- 2020-08-10 -- Updates Readme | ||
### 0.0.30 -- 2020-7-27 | ||
@@ -7,0 +16,0 @@ |
@@ -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");function i(r){return void 0===r&&(r=[]),e.pipe(e.interaction(),r)}var u=e.pipe;function s(){return(s=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 a(r){return e.pipe([e.makeGetAccount,function(n){return n.accountAddr=r,e.Ok(n)}])}function f(r){return void 0===r&&(r=!1),e.pipe([e.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=r,e.Ok(n)}])}var p={asArgument:function(e){return e},asInjection:function(e){return e}},l={asArgument:function(e){return e},asInjection:function(e){return e}},d=[];const m=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{v(t,1,e(this.v))}catch(e){v(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?v(t,1,r?r(o):o):n?v(t,1,n(o)):v(t,2,o)}catch(e){v(t,2,e)}},t},e}();function v(e,r,n){if(!e.s){if(n instanceof m){if(!n.s)return void(n.o=v.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(v.bind(null,e,r),v.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function y(e){return e instanceof m&&1&e.s}const h="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var g=function(e){return"function"==typeof e},k=function(e){return"number"==typeof e},P=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}},O=function(e){return!(e.role.proposer&&!(P(e.addr)&&k(e.keyId)&&k(e.sequenceNum)&&g(e.signingFunction))||e.role.payer&&!(P(e.addr)&&k(e.keyId)&&g(e.signingFunction))||e.role.authorizer&&!(P(e.addr)&&k(e.keyId)&&g(e.signingFunction)))},x=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},I=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},j=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[h]){var t,o,i,u=e[h]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!y(n))return void n.then(e,i||(i=v.bind(null,o=new m,2)));n=n.v}o?v(o,1,n):o=n}catch(e){v(o||(o=new m),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 c=[],a=0;a<e.length;a++)c.push(e[a]);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(!y(u))return void u.then(n,o||(o=v.bind(null,t=new m,2)));u=u.v}t?v(t,1,u):t=u}catch(e){v(t||(t=new m),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(){b(O(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,u=o[t],c=u.addr+"|"+u.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],n=s({tempId:c},u),{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(k)[0]?i.filter(k)[0]:null),sequenceNum:"number"==typeof I([e,n]).sequenceNum?I([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}}):s({tempId:c},u),r.proposer===u.tempId&&(r.proposer=c),r.payer===u.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(e){return e===u.tempId?c:e}),delete r.accounts[u.tempId]},t=0,o=Object.values(r.accounts);t<o.length;t++)n();for(var i=0,u=Object.values(r.accounts);i<u.length;i++){var c=u[i];b(O(c),"Account unable to fulfill roles",c)}return Promise.resolve(e.Ok(r))}catch(e){return Promise.reject(e)}}]);function S(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 A(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(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=l),{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(s({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))},exports.build=i,exports.getAccount=a,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=f,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=p),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(s({},"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}}:s({},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=u,exports.resolveAccounts=j,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 s({},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]=s({},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 s({},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.resolveProposerSequenceNumber=function(t){var o=t.node;return function(t){try{return e.isTransaction(t)?t.accounts[t.proposer].sequenceNum?Promise.resolve(e.Ok(t)):Promise.resolve(i([a(t.accounts[t.proposer].addr)])).then(function(i){return Promise.resolve(r.send(i,{node:o})).then(function(r){return Promise.resolve(n.decodeResponse(r)).then(function(r){return t.accounts[t.proposer].sequenceNum=r.keys[t.accounts[t.proposer].keyId].sequenceNumber,e.Ok(t)})})}):Promise.resolve(e.Ok(t))}catch(e){return Promise.reject(e)}}},exports.resolveRefBlockId=function(t){var o=t.node;return function(t){try{return e.isTransaction(t)?t.message.refBlock?Promise.resolve(e.Ok(t)):Promise.resolve(i([f()])).then(function(i){return Promise.resolve(r.send(i,{node:o})).then(function(r){return Promise.resolve(n.decodeResponse(r)).then(function(r){return t.message.refBlock=r.id,e.Ok(t)})})}):Promise.resolve(e.Ok(t))}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(w(r,n.insideSigners,o.encodeTransactionPayload(S(r)))).then(function(e){var n=A(r,e);return Promise.resolve(w(r,t,o.encodeTransactionEnvelope(s({},S(r),{payloadSigs:n})))).then(function(e){return A(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||d,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");function i(r){return void 0===r&&(r=[]),e.pipe(e.interaction(),r)}var u=e.pipe;function s(){return(s=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 a(r){return e.pipe([e.makeGetAccount,function(n){return n.accountAddr=r,e.Ok(n)}])}function f(r){return void 0===r&&(r=!1),e.pipe([e.makeGetLatestBlock,function(n){return n.block.isSealed=r,e.Ok(n)}])}var p={asArgument:function(e){return e},asInjection:function(e){return e}},l={asArgument:function(e){return e},asInjection:function(e){return e}},d=[];const m=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{v(t,1,e(this.v))}catch(e){v(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?v(t,1,r?r(o):o):n?v(t,1,n(o)):v(t,2,o)}catch(e){v(t,2,e)}},t},e}();function v(e,r,n){if(!e.s){if(n instanceof m){if(!n.s)return void(n.o=v.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(v.bind(null,e,r),v.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function y(e){return e instanceof m&&1&e.s}const h="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var g=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)&&g(e.signingFunction))||e.role.payer&&!(b(e.addr)&&k(e.keyId)&&g(e.signingFunction))||e.role.authorizer&&!(b(e.addr)&&k(e.keyId)&&g(e.signingFunction)))},x=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},I=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},j=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[h]){var t,o,i,u=e[h]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!y(n))return void n.then(e,i||(i=v.bind(null,o=new m,2)));n=n.v}o?v(o,1,n):o=n}catch(e){v(o||(o=new m),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 c=[],a=0;a<e.length;a++)c.push(e[a]);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(!y(u))return void u.then(n,o||(o=v.bind(null,t=new m,2)));u=u.v}t?v(t,1,u):t=u}catch(e){v(t||(t=new m),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(){P(O(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,u=o[t],c=u.addr+"|"+u.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],n=s({tempId:c},u),{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(k)[0]?i.filter(k)[0]:null),sequenceNum:"number"==typeof I([e,n]).sequenceNum?I([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}}):s({tempId:c},u),r.proposer===u.tempId&&(r.proposer=c),r.payer===u.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(e){return e===u.tempId?c:e}),delete r.accounts[u.tempId]},t=0,o=Object.values(r.accounts);t<o.length;t++)n();for(var i=0,u=Object.values(r.accounts);i<u.length;i++){var c=u[i];P(O(c),"Account unable to fulfill roles",c)}return Promise.resolve(e.Ok(r))}catch(e){return Promise.reject(e)}}]);function S(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 A(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(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=l),{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(s({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))},exports.build=i,exports.getAccount=a,exports.getBlockByHeight=function(r){return e.pipe([e.makeGetBlockByHeight,function(n){return n.block.height=r,e.Ok(n)}])},exports.getBlockById=function(r){return e.pipe([e.makeGetBlockById,function(n){return n.block.id=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=f,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=p),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(s({},"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}}:s({},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=u,exports.resolveAccounts=j,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 s({},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]=s({},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 s({},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.resolveProposerSequenceNumber=function(t){var o=t.node;return function(t){try{return e.isTransaction(t)?t.accounts[t.proposer].sequenceNum?Promise.resolve(e.Ok(t)):Promise.resolve(i([a(t.accounts[t.proposer].addr)])).then(function(i){return Promise.resolve(r.send(i,{node:o})).then(function(r){return Promise.resolve(n.decodeResponse(r)).then(function(r){return t.accounts[t.proposer].sequenceNum=r.keys[t.accounts[t.proposer].keyId].sequenceNumber,e.Ok(t)})})}):Promise.resolve(e.Ok(t))}catch(e){return Promise.reject(e)}}},exports.resolveRefBlockId=function(t){var o=t.node;return function(t){try{return e.isTransaction(t)?t.message.refBlock?Promise.resolve(e.Ok(t)):Promise.resolve(i([f()])).then(function(i){return Promise.resolve(r.send(i,{node:o})).then(function(r){return Promise.resolve(n.decodeResponse(r)).then(function(r){return t.message.refBlock=r.id,e.Ok(t)})})}):Promise.resolve(e.Ok(t))}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(w(r,n.insideSigners,o.encodeTransactionPayload(S(r)))).then(function(e){var n=A(r,e);return Promise.resolve(w(r,t,o.encodeTransactionEnvelope(s({},S(r),{payloadSigs:n})))).then(function(e){return A(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||d,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 r,interaction as e,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as i,makeGetTransactionStatus as c,makeParam as s,makeArgument as a,makeProposer as f,makePayer as l,makePing as m,makeScript as d,put as v,makeTransaction as p,update as y,Bad as h,isTransaction as g,isScript as P,get as I}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as b}from"@onflow/send";export{send}from"@onflow/send";import{decodeResponse as k}from"@onflow/decode";export{decode,decodeResponse}from"@onflow/decode";import{templar as w}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionPayload as j,encodeTransactionEnvelope as S}from"@onflow/encode";function A(n){return void 0===n&&(n=[]),r(e(),n)}var x=r;function O(){return(O=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 q(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 B(e){return void 0===e&&(e=[]),r(e.map(function(r){return n(O({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))}function N(r,e,n,t){return{addr:r,signingFunction:e,keyId:n,sequenceNum:t}}function z(e){return r([t,function(r){return r.accountAddr=e,o(r)}])}function E(e,n,t){return r([u,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 F(e){return void 0===e&&(e=!1),r([i,function(r){return r.latestBlock.isSealed=e,o(r)}])}function L(e){return r([c,function(r){return r.transactionId=e,o(r)}])}function T(e){return r([function(r){return r.message.computeLimit=e,o(r)}])}function C(e){return void 0===e&&(e=[]),r(e.map(function(r){return s("function"==typeof r?{resolve:r}:r)}))}var R={asArgument:function(r){return r},asInjection:function(r){return r}};function V(r,e,n){return void 0===e&&(e=R),void 0===n&&(n=null),{key:n,value:r,xform:e}}function K(e){return void 0===e&&(e=[]),r(e.map(function(r){return a("function"==typeof r?{resolve:r}:r)}))}var M={asArgument:function(r){return r},asInjection:function(r){return r}};function U(r,e){return void 0===e&&(e=M),{value:r,xform:e}}var $=function(r){try{return D(r)?Promise.resolve(f({resolve:r,role:{proposer:!0}})):Promise.resolve(f(O({},r,{role:{proposer:!0}})))}catch(r){return Promise.reject(r)}},D=function(r){return"function"==typeof r};function G(r){return l(O({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))}function H(){return r([m])}function J(e){return r([function(r){return r.message.refBlock=e,o(r)}])}function Q(){return r([d,v("ix.cadence",w.apply(void 0,arguments))])}var W=[];function X(){return r([p,v("ix.cadence",w.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||W,o(r)}])}function Y(r){return y("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}function Z(){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],u=e[1];return Z(function(r,e){var n=e.Bad;return t?(0,e.Ok)(r):n(r,u)})}var i=e[0];return function(r){return i(r,{Ok:o,Bad:h})}}const _=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{rr(t,1,r(this.v))}catch(r){rr(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?rr(t,1,e?e(o):o):n?rr(t,1,n(o)):rr(t,2,o)}catch(r){rr(t,2,r)}},t},r}();function rr(r,e,n){if(!r.s){if(n instanceof _){if(!n.s)return void(n.o=rr.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(rr.bind(null,r,e),rr.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function er(r){return r instanceof _&&1&r.s}const nr="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var tr=function(r){return"function"==typeof r},or=function(r){return"number"==typeof r},ur=function(r){return"string"==typeof r},ir=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,u=new Array(o>2?o-2:0),i=2;i<o;i++)u[i-2]=arguments[i];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(u,["\n\n---\n\n"])),t}},cr=function(r){return!(r.role.proposer&&!(ur(r.addr)&&or(r.keyId)&&or(r.sequenceNum)&&tr(r.signingFunction))||r.role.payer&&!(ur(r.addr)&&or(r.keyId)&&tr(r.signingFunction))||r.role.authorizer&&!(ur(r.addr)&&or(r.keyId)&&tr(r.signingFunction)))},sr=function(r){return void 0===r&&(r=[]),r.filter(Boolean)[0]||null},ar=function(r){return void 0===r&&(r=[]),r.find(function(r){return r.role.proposer})||{}},fr=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[nr]){var t,o,u,i=r[nr]();if(function r(n){try{for(;!(t=i.next()).done;)if((n=e(t.value))&&n.then){if(!er(n))return void n.then(r,u||(u=rr.bind(null,o=new _,2)));n=n.v}o?rr(o,1,n):o=n}catch(r){rr(o||(o=new _),2,r)}}(),i.return){var c=function(r){try{t.done||i.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 s=[],a=0;a<r.length;a++)s.push(r[a]);return function(r,e,n){var t,o,u=-1;return function n(i){try{for(;++u<r.length;)if((i=e(u))&&i.then){if(!er(i))return void i.then(n,o||(o=rr.bind(null,t=new _,2)));i=i.v}t?rr(t,1,i):t=i}catch(r){rr(t||(t=new _),2,r)}}(),t}(s,function(r){return e(s[r])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){ir(cr(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var u=function(){if(tr(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return u&&u.then?u.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,u,i=t[n],c=i.addr+"|"+i.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],o=O({tempId:c},i),{kind:sr([e.kind,o.kind]),tempId:sr([e.tempId,o.tempId]),addr:sr([e.addr,o.addr]),keyId:(u=[e.keyId,o.keyId],void 0===u&&(u=[]),"number"==typeof u.filter(or)[0]?u.filter(or)[0]:null),sequenceNum:"number"==typeof ar([e,o]).sequenceNum?ar([e,o]).sequenceNum:e.sequenceNum,signature:sr([e.signature,o.signature]),signingFunction:sr([e.signingFunction,o.signingFunction]),resolve:sr([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}}):O({tempId:c},i),r.proposer===i.tempId&&(r.proposer=c),r.payer===i.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(r){return r===i.tempId?c:r}),delete r.accounts[i.tempId]},n=0,t=Object.values(r.accounts);n<t.length;n++)e();for(var u=0,i=Object.values(r.accounts);u<i.length;u++){var c=i[u];ir(cr(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}]),lr=function(r){try{if(!g(r)&&!P(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 O({},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]=O({},e,{asArgument:e.xform.asArgument(e.value)})}),o(r)})}catch(r){return Promise.reject(r)}},mr=function(r){try{var e=function(r){if(n)return r;throw new Error("Invalid Cadence Value")},n=!1;if(!g(r)&&!P(r))return Promise.resolve(o(r));var t=I(r,"ix.cadence");if("string"==typeof t)return r.message.cadence=t,Promise.resolve(o(r));var u=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 O({},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(u&&u.then?u.then(e):e(u))}catch(r){return Promise.reject(r)}};function dr(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 vr=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(pr(r,e.insideSigners,j(dr(r)))).then(function(e){var t=yr(r,e);return Promise.resolve(pr(r,n,S(O({},dr(r),{payloadSigs:t})))).then(function(e){return yr(r,e),r})})}catch(r){return Promise.reject(r)}},pr=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 yr(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 q(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)?q(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 hr=function(e){try{var n=I(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)}},gr=function(r){var e=r.node;return function(r){try{return g(r)?r.accounts[r.proposer].sequenceNum?Promise.resolve(o(r)):Promise.resolve(A([z(r.accounts[r.proposer].addr)])).then(function(n){return Promise.resolve(b(n,{node:e})).then(function(e){return Promise.resolve(k(e)).then(function(e){return r.accounts[r.proposer].sequenceNum=e.keys[r.accounts[r.proposer].keyId].sequenceNumber,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}},Pr=function(r){var e=r.node;return function(r){try{return g(r)?r.message.refBlock?Promise.resolve(o(r)):Promise.resolve(A([F()])).then(function(n){return Promise.resolve(b(n,{node:e})).then(function(e){return Promise.resolve(k(e)).then(function(e){return r.message.refBlock=e.id,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}};export{U as arg,K as args,N as authorization,B as authorizations,A as build,z as getAccount,E as getEvents,F as getLatestBlock,L as getTransactionStatus,Z as invariant,T as limit,V as param,C as params,G as payer,H as ping,$ as proposer,J as ref,x as resolve,fr as resolveAccounts,lr as resolveArguments,mr as resolveParams,gr as resolveProposerSequenceNumber,Pr as resolveRefBlockId,vr as resolveSignatures,hr as resolveValidators,Q as script,X as transaction,Y as validator}; | ||
import{pipe as r,interaction as e,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as i,makeGetBlockById as c,makeGetBlockByHeight as s,makeGetTransactionStatus as a,makeParam as f,makeArgument as l,makeProposer as m,makePayer as d,makePing as v,makeScript as p,put as y,makeTransaction as h,update as g,Bad as P,isTransaction as b,isScript as I,get as k}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as w}from"@onflow/send";export{send}from"@onflow/send";import{decodeResponse as j}from"@onflow/decode";export{decode,decodeResponse}from"@onflow/decode";import{templar as S}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionPayload as A,encodeTransactionEnvelope as x}from"@onflow/encode";function O(n){return void 0===n&&(n=[]),r(e(),n)}var q=r;function N(){return(N=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 z(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 B(e){return void 0===e&&(e=[]),r(e.map(function(r){return n(N({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))}function E(r,e,n,t){return{addr:r,signingFunction:e,keyId:n,sequenceNum:t}}function F(e){return r([t,function(r){return r.accountAddr=e,o(r)}])}function L(e,n,t){return r([u,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 T(e){return void 0===e&&(e=!1),r([i,function(r){return r.block.isSealed=e,o(r)}])}function C(e){return r([c,function(r){return r.block.id=e,o(r)}])}function R(e){return r([s,function(r){return r.block.height=e,o(r)}])}function V(e){return r([a,function(r){return r.transactionId=e,o(r)}])}function K(e){return r([function(r){return r.message.computeLimit=e,o(r)}])}function M(e){return void 0===e&&(e=[]),r(e.map(function(r){return f("function"==typeof r?{resolve:r}:r)}))}var U={asArgument:function(r){return r},asInjection:function(r){return r}};function $(r,e,n){return void 0===e&&(e=U),void 0===n&&(n=null),{key:n,value:r,xform:e}}function D(e){return void 0===e&&(e=[]),r(e.map(function(r){return l("function"==typeof r?{resolve:r}:r)}))}var G={asArgument:function(r){return r},asInjection:function(r){return r}};function H(r,e){return void 0===e&&(e=G),{value:r,xform:e}}var J=function(r){try{return Q(r)?Promise.resolve(m({resolve:r,role:{proposer:!0}})):Promise.resolve(m(N({},r,{role:{proposer:!0}})))}catch(r){return Promise.reject(r)}},Q=function(r){return"function"==typeof r};function W(r){return d(N({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))}function X(){return r([v])}function Y(e){return r([function(r){return r.message.refBlock=e,o(r)}])}function Z(){return r([p,y("ix.cadence",S.apply(void 0,arguments))])}var _=[];function rr(){return r([h,y("ix.cadence",S.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||_,o(r)}])}function er(r){return g("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}function nr(){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],u=e[1];return nr(function(r,e){var n=e.Bad;return t?(0,e.Ok)(r):n(r,u)})}var i=e[0];return function(r){return i(r,{Ok:o,Bad:P})}}const tr=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{or(t,1,r(this.v))}catch(r){or(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?or(t,1,e?e(o):o):n?or(t,1,n(o)):or(t,2,o)}catch(r){or(t,2,r)}},t},r}();function or(r,e,n){if(!r.s){if(n instanceof tr){if(!n.s)return void(n.o=or.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(or.bind(null,r,e),or.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function ur(r){return r instanceof tr&&1&r.s}const ir="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var cr=function(r){return"function"==typeof r},sr=function(r){return"number"==typeof r},ar=function(r){return"string"==typeof r},fr=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,u=new Array(o>2?o-2:0),i=2;i<o;i++)u[i-2]=arguments[i];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(u,["\n\n---\n\n"])),t}},lr=function(r){return!(r.role.proposer&&!(ar(r.addr)&&sr(r.keyId)&&sr(r.sequenceNum)&&cr(r.signingFunction))||r.role.payer&&!(ar(r.addr)&&sr(r.keyId)&&cr(r.signingFunction))||r.role.authorizer&&!(ar(r.addr)&&sr(r.keyId)&&cr(r.signingFunction)))},mr=function(r){return void 0===r&&(r=[]),r.filter(Boolean)[0]||null},dr=function(r){return void 0===r&&(r=[]),r.find(function(r){return r.role.proposer})||{}},vr=r([function(r){try{var e=function(){return o(r)};if(!b(r))return Promise.resolve(o(r));var n=function(r,e,n){if("function"==typeof r[ir]){var t,o,u,i=r[ir]();if(function r(n){try{for(;!(t=i.next()).done;)if((n=e(t.value))&&n.then){if(!ur(n))return void n.then(r,u||(u=or.bind(null,o=new tr,2)));n=n.v}o?or(o,1,n):o=n}catch(r){or(o||(o=new tr),2,r)}}(),i.return){var c=function(r){try{t.done||i.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 s=[],a=0;a<r.length;a++)s.push(r[a]);return function(r,e,n){var t,o,u=-1;return function n(i){try{for(;++u<r.length;)if((i=e(u))&&i.then){if(!ur(i))return void i.then(n,o||(o=or.bind(null,t=new tr,2)));i=i.v}t?or(t,1,i):t=i}catch(r){or(t||(t=new tr),2,r)}}(),t}(s,function(r){return e(s[r])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){fr(lr(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var u=function(){if(cr(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return u&&u.then?u.then(o):o()});return Promise.resolve(n&&n.then?n.then(e):e())}catch(r){return Promise.reject(r)}},function(r){try{if(!b(r))return Promise.resolve(o(r));for(var e=function(){var e,o,u,i=t[n],c=i.addr+"|"+i.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],o=N({tempId:c},i),{kind:mr([e.kind,o.kind]),tempId:mr([e.tempId,o.tempId]),addr:mr([e.addr,o.addr]),keyId:(u=[e.keyId,o.keyId],void 0===u&&(u=[]),"number"==typeof u.filter(sr)[0]?u.filter(sr)[0]:null),sequenceNum:"number"==typeof dr([e,o]).sequenceNum?dr([e,o]).sequenceNum:e.sequenceNum,signature:mr([e.signature,o.signature]),signingFunction:mr([e.signingFunction,o.signingFunction]),resolve:mr([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}}):N({tempId:c},i),r.proposer===i.tempId&&(r.proposer=c),r.payer===i.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(r){return r===i.tempId?c:r}),delete r.accounts[i.tempId]},n=0,t=Object.values(r.accounts);n<t.length;n++)e();for(var u=0,i=Object.values(r.accounts);u<i.length;u++){var c=i[u];fr(lr(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}]),pr=function(r){try{if(!b(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 N({},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]=N({},e,{asArgument:e.xform.asArgument(e.value)})}),o(r)})}catch(r){return Promise.reject(r)}},yr=function(r){try{var e=function(r){if(n)return r;throw new Error("Invalid Cadence Value")},n=!1;if(!b(r)&&!I(r))return Promise.resolve(o(r));var t=k(r,"ix.cadence");if("string"==typeof t)return r.message.cadence=t,Promise.resolve(o(r));var u=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 N({},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(u&&u.then?u.then(e):e(u))}catch(r){return Promise.reject(r)}};function hr(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 gr=function(r){try{if(!b(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(Pr(r,e.insideSigners,A(hr(r)))).then(function(e){var t=br(r,e);return Promise.resolve(Pr(r,n,x(N({},hr(r),{payloadSigs:t})))).then(function(e){return br(r,e),r})})}catch(r){return Promise.reject(r)}},Pr=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 br(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 z(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)?z(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 Ir=function(e){try{var n=k(e,"ix.validators",[]);return Promise.resolve(r(e,n.map(function(r){return function(e){return r(e,{Ok:o,Bad:P})}})))}catch(r){return Promise.reject(r)}},kr=function(r){var e=r.node;return function(r){try{return b(r)?r.accounts[r.proposer].sequenceNum?Promise.resolve(o(r)):Promise.resolve(O([F(r.accounts[r.proposer].addr)])).then(function(n){return Promise.resolve(w(n,{node:e})).then(function(e){return Promise.resolve(j(e)).then(function(e){return r.accounts[r.proposer].sequenceNum=e.keys[r.accounts[r.proposer].keyId].sequenceNumber,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}},wr=function(r){var e=r.node;return function(r){try{return b(r)?r.message.refBlock?Promise.resolve(o(r)):Promise.resolve(O([T()])).then(function(n){return Promise.resolve(w(n,{node:e})).then(function(e){return Promise.resolve(j(e)).then(function(e){return r.message.refBlock=e.id,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}};export{H as arg,D as args,E as authorization,B as authorizations,O as build,F as getAccount,R as getBlockByHeight,C as getBlockById,L as getEvents,T as getLatestBlock,V as getTransactionStatus,nr as invariant,K as limit,$ as param,M as params,W as payer,X as ping,J as proposer,Y as ref,q as resolve,vr as resolveAccounts,pr as resolveArguments,yr as resolveParams,kr as resolveProposerSequenceNumber,wr as resolveRefBlockId,gr as resolveSignatures,Ir as resolveValidators,Z as script,rr as transaction,er as validator}; | ||
//# sourceMappingURL=sdk.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{pipe as r,interaction as e,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as i,makeGetTransactionStatus as c,makeParam as s,makeArgument as a,makeProposer as f,makePayer as l,makePing as m,makeScript as d,put as v,makeTransaction as p,update as y,Bad as h,isTransaction as g,isScript as P,get as I}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as b}from"@onflow/send";export{send}from"@onflow/send";import{decodeResponse as k}from"@onflow/decode";export{decode,decodeResponse}from"@onflow/decode";import{templar as w}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionPayload as j,encodeTransactionEnvelope as S}from"@onflow/encode";function A(n){return void 0===n&&(n=[]),r(e(),n)}var x=r;function O(){return(O=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 q(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 B(e){return void 0===e&&(e=[]),r(e.map(function(r){return n(O({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))}function N(r,e,n,t){return{addr:r,signingFunction:e,keyId:n,sequenceNum:t}}function z(e){return r([t,function(r){return r.accountAddr=e,o(r)}])}function E(e,n,t){return r([u,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 F(e){return void 0===e&&(e=!1),r([i,function(r){return r.latestBlock.isSealed=e,o(r)}])}function L(e){return r([c,function(r){return r.transactionId=e,o(r)}])}function T(e){return r([function(r){return r.message.computeLimit=e,o(r)}])}function C(e){return void 0===e&&(e=[]),r(e.map(function(r){return s("function"==typeof r?{resolve:r}:r)}))}var R={asArgument:function(r){return r},asInjection:function(r){return r}};function V(r,e,n){return void 0===e&&(e=R),void 0===n&&(n=null),{key:n,value:r,xform:e}}function K(e){return void 0===e&&(e=[]),r(e.map(function(r){return a("function"==typeof r?{resolve:r}:r)}))}var M={asArgument:function(r){return r},asInjection:function(r){return r}};function U(r,e){return void 0===e&&(e=M),{value:r,xform:e}}var $=function(r){try{return D(r)?Promise.resolve(f({resolve:r,role:{proposer:!0}})):Promise.resolve(f(O({},r,{role:{proposer:!0}})))}catch(r){return Promise.reject(r)}},D=function(r){return"function"==typeof r};function G(r){return l(O({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))}function H(){return r([m])}function J(e){return r([function(r){return r.message.refBlock=e,o(r)}])}function Q(){return r([d,v("ix.cadence",w.apply(void 0,arguments))])}var W=[];function X(){return r([p,v("ix.cadence",w.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||W,o(r)}])}function Y(r){return y("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}function Z(){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],u=e[1];return Z(function(r,e){var n=e.Bad;return t?(0,e.Ok)(r):n(r,u)})}var i=e[0];return function(r){return i(r,{Ok:o,Bad:h})}}const _=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{rr(t,1,r(this.v))}catch(r){rr(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?rr(t,1,e?e(o):o):n?rr(t,1,n(o)):rr(t,2,o)}catch(r){rr(t,2,r)}},t},r}();function rr(r,e,n){if(!r.s){if(n instanceof _){if(!n.s)return void(n.o=rr.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(rr.bind(null,r,e),rr.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function er(r){return r instanceof _&&1&r.s}const nr="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var tr=function(r){return"function"==typeof r},or=function(r){return"number"==typeof r},ur=function(r){return"string"==typeof r},ir=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,u=new Array(o>2?o-2:0),i=2;i<o;i++)u[i-2]=arguments[i];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(u,["\n\n---\n\n"])),t}},cr=function(r){return!(r.role.proposer&&!(ur(r.addr)&&or(r.keyId)&&or(r.sequenceNum)&&tr(r.signingFunction))||r.role.payer&&!(ur(r.addr)&&or(r.keyId)&&tr(r.signingFunction))||r.role.authorizer&&!(ur(r.addr)&&or(r.keyId)&&tr(r.signingFunction)))},sr=function(r){return void 0===r&&(r=[]),r.filter(Boolean)[0]||null},ar=function(r){return void 0===r&&(r=[]),r.find(function(r){return r.role.proposer})||{}},fr=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[nr]){var t,o,u,i=r[nr]();if(function r(n){try{for(;!(t=i.next()).done;)if((n=e(t.value))&&n.then){if(!er(n))return void n.then(r,u||(u=rr.bind(null,o=new _,2)));n=n.v}o?rr(o,1,n):o=n}catch(r){rr(o||(o=new _),2,r)}}(),i.return){var c=function(r){try{t.done||i.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 s=[],a=0;a<r.length;a++)s.push(r[a]);return function(r,e,n){var t,o,u=-1;return function n(i){try{for(;++u<r.length;)if((i=e(u))&&i.then){if(!er(i))return void i.then(n,o||(o=rr.bind(null,t=new _,2)));i=i.v}t?rr(t,1,i):t=i}catch(r){rr(t||(t=new _),2,r)}}(),t}(s,function(r){return e(s[r])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){ir(cr(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var u=function(){if(tr(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return u&&u.then?u.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,u,i=t[n],c=i.addr+"|"+i.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],o=O({tempId:c},i),{kind:sr([e.kind,o.kind]),tempId:sr([e.tempId,o.tempId]),addr:sr([e.addr,o.addr]),keyId:(u=[e.keyId,o.keyId],void 0===u&&(u=[]),"number"==typeof u.filter(or)[0]?u.filter(or)[0]:null),sequenceNum:"number"==typeof ar([e,o]).sequenceNum?ar([e,o]).sequenceNum:e.sequenceNum,signature:sr([e.signature,o.signature]),signingFunction:sr([e.signingFunction,o.signingFunction]),resolve:sr([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}}):O({tempId:c},i),r.proposer===i.tempId&&(r.proposer=c),r.payer===i.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(r){return r===i.tempId?c:r}),delete r.accounts[i.tempId]},n=0,t=Object.values(r.accounts);n<t.length;n++)e();for(var u=0,i=Object.values(r.accounts);u<i.length;u++){var c=i[u];ir(cr(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}]),lr=function(r){try{if(!g(r)&&!P(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 O({},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]=O({},e,{asArgument:e.xform.asArgument(e.value)})}),o(r)})}catch(r){return Promise.reject(r)}},mr=function(r){try{var e=function(r){if(n)return r;throw new Error("Invalid Cadence Value")},n=!1;if(!g(r)&&!P(r))return Promise.resolve(o(r));var t=I(r,"ix.cadence");if("string"==typeof t)return r.message.cadence=t,Promise.resolve(o(r));var u=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 O({},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(u&&u.then?u.then(e):e(u))}catch(r){return Promise.reject(r)}};function dr(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 vr=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(pr(r,e.insideSigners,j(dr(r)))).then(function(e){var t=yr(r,e);return Promise.resolve(pr(r,n,S(O({},dr(r),{payloadSigs:t})))).then(function(e){return yr(r,e),r})})}catch(r){return Promise.reject(r)}},pr=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 yr(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 q(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)?q(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 hr=function(e){try{var n=I(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)}},gr=function(r){var e=r.node;return function(r){try{return g(r)?r.accounts[r.proposer].sequenceNum?Promise.resolve(o(r)):Promise.resolve(A([z(r.accounts[r.proposer].addr)])).then(function(n){return Promise.resolve(b(n,{node:e})).then(function(e){return Promise.resolve(k(e)).then(function(e){return r.accounts[r.proposer].sequenceNum=e.keys[r.accounts[r.proposer].keyId].sequenceNumber,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}},Pr=function(r){var e=r.node;return function(r){try{return g(r)?r.message.refBlock?Promise.resolve(o(r)):Promise.resolve(A([F()])).then(function(n){return Promise.resolve(b(n,{node:e})).then(function(e){return Promise.resolve(k(e)).then(function(e){return r.message.refBlock=e.id,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}};export{U as arg,K as args,N as authorization,B as authorizations,A as build,z as getAccount,E as getEvents,F as getLatestBlock,L as getTransactionStatus,Z as invariant,T as limit,V as param,C as params,G as payer,H as ping,$ as proposer,J as ref,x as resolve,fr as resolveAccounts,lr as resolveArguments,mr as resolveParams,gr as resolveProposerSequenceNumber,Pr as resolveRefBlockId,vr as resolveSignatures,hr as resolveValidators,Q as script,X as transaction,Y as validator}; | ||
import{pipe as r,interaction as e,makeAuthorizer as n,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as i,makeGetBlockById as c,makeGetBlockByHeight as s,makeGetTransactionStatus as a,makeParam as f,makeArgument as l,makeProposer as m,makePayer as d,makePing as v,makeScript as p,put as y,makeTransaction as h,update as g,Bad as P,isTransaction as b,isScript as I,get as k}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";import{send as w}from"@onflow/send";export{send}from"@onflow/send";import{decodeResponse as j}from"@onflow/decode";export{decode,decodeResponse}from"@onflow/decode";import{templar as S}from"@qvvg/templar";export{templar as cadence,templar as cdc}from"@qvvg/templar";import{encodeTransactionPayload as A,encodeTransactionEnvelope as x}from"@onflow/encode";function O(n){return void 0===n&&(n=[]),r(e(),n)}var q=r;function N(){return(N=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 z(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 B(e){return void 0===e&&(e=[]),r(e.map(function(r){return n(N({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))}function E(r,e,n,t){return{addr:r,signingFunction:e,keyId:n,sequenceNum:t}}function F(e){return r([t,function(r){return r.accountAddr=e,o(r)}])}function L(e,n,t){return r([u,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 T(e){return void 0===e&&(e=!1),r([i,function(r){return r.block.isSealed=e,o(r)}])}function C(e){return r([c,function(r){return r.block.id=e,o(r)}])}function R(e){return r([s,function(r){return r.block.height=e,o(r)}])}function V(e){return r([a,function(r){return r.transactionId=e,o(r)}])}function K(e){return r([function(r){return r.message.computeLimit=e,o(r)}])}function M(e){return void 0===e&&(e=[]),r(e.map(function(r){return f("function"==typeof r?{resolve:r}:r)}))}var U={asArgument:function(r){return r},asInjection:function(r){return r}};function $(r,e,n){return void 0===e&&(e=U),void 0===n&&(n=null),{key:n,value:r,xform:e}}function D(e){return void 0===e&&(e=[]),r(e.map(function(r){return l("function"==typeof r?{resolve:r}:r)}))}var G={asArgument:function(r){return r},asInjection:function(r){return r}};function H(r,e){return void 0===e&&(e=G),{value:r,xform:e}}var J=function(r){try{return Q(r)?Promise.resolve(m({resolve:r,role:{proposer:!0}})):Promise.resolve(m(N({},r,{role:{proposer:!0}})))}catch(r){return Promise.reject(r)}},Q=function(r){return"function"==typeof r};function W(r){return d(N({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))}function X(){return r([v])}function Y(e){return r([function(r){return r.message.refBlock=e,o(r)}])}function Z(){return r([p,y("ix.cadence",S.apply(void 0,arguments))])}var _=[];function rr(){return r([h,y("ix.cadence",S.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||_,o(r)}])}function er(r){return g("ix.validators",function(e){return Array.isArray(e)?e.push(r):[r]})}function nr(){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],u=e[1];return nr(function(r,e){var n=e.Bad;return t?(0,e.Ok)(r):n(r,u)})}var i=e[0];return function(r){return i(r,{Ok:o,Bad:P})}}const tr=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{or(t,1,r(this.v))}catch(r){or(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?or(t,1,e?e(o):o):n?or(t,1,n(o)):or(t,2,o)}catch(r){or(t,2,r)}},t},r}();function or(r,e,n){if(!r.s){if(n instanceof tr){if(!n.s)return void(n.o=or.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(or.bind(null,r,e),or.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function ur(r){return r instanceof tr&&1&r.s}const ir="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var cr=function(r){return"function"==typeof r},sr=function(r){return"number"==typeof r},ar=function(r){return"string"==typeof r},fr=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,u=new Array(o>2?o-2:0),i=2;i<o;i++)u[i-2]=arguments[i];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(u,["\n\n---\n\n"])),t}},lr=function(r){return!(r.role.proposer&&!(ar(r.addr)&&sr(r.keyId)&&sr(r.sequenceNum)&&cr(r.signingFunction))||r.role.payer&&!(ar(r.addr)&&sr(r.keyId)&&cr(r.signingFunction))||r.role.authorizer&&!(ar(r.addr)&&sr(r.keyId)&&cr(r.signingFunction)))},mr=function(r){return void 0===r&&(r=[]),r.filter(Boolean)[0]||null},dr=function(r){return void 0===r&&(r=[]),r.find(function(r){return r.role.proposer})||{}},vr=r([function(r){try{var e=function(){return o(r)};if(!b(r))return Promise.resolve(o(r));var n=function(r,e,n){if("function"==typeof r[ir]){var t,o,u,i=r[ir]();if(function r(n){try{for(;!(t=i.next()).done;)if((n=e(t.value))&&n.then){if(!ur(n))return void n.then(r,u||(u=or.bind(null,o=new tr,2)));n=n.v}o?or(o,1,n):o=n}catch(r){or(o||(o=new tr),2,r)}}(),i.return){var c=function(r){try{t.done||i.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 s=[],a=0;a<r.length;a++)s.push(r[a]);return function(r,e,n){var t,o,u=-1;return function n(i){try{for(;++u<r.length;)if((i=e(u))&&i.then){if(!ur(i))return void i.then(n,o||(o=or.bind(null,t=new tr,2)));i=i.v}t?or(t,1,i):t=i}catch(r){or(t||(t=new tr),2,r)}}(),t}(s,function(r){return e(s[r])})}(Object.entries(r.accounts),function(e){var n=e[0],t=e[1];function o(){fr(lr(r.accounts[n]),"Account unable to fulfill role",r.accounts[n])}var u=function(){if(cr(t.resolve))return Promise.resolve(t.resolve(t)).then(function(e){r.accounts[n]=e})}();return u&&u.then?u.then(o):o()});return Promise.resolve(n&&n.then?n.then(e):e())}catch(r){return Promise.reject(r)}},function(r){try{if(!b(r))return Promise.resolve(o(r));for(var e=function(){var e,o,u,i=t[n],c=i.addr+"|"+i.keyId;r.accounts[c]=null!=r.accounts[c]?(e=r.accounts[c],o=N({tempId:c},i),{kind:mr([e.kind,o.kind]),tempId:mr([e.tempId,o.tempId]),addr:mr([e.addr,o.addr]),keyId:(u=[e.keyId,o.keyId],void 0===u&&(u=[]),"number"==typeof u.filter(sr)[0]?u.filter(sr)[0]:null),sequenceNum:"number"==typeof dr([e,o]).sequenceNum?dr([e,o]).sequenceNum:e.sequenceNum,signature:mr([e.signature,o.signature]),signingFunction:mr([e.signingFunction,o.signingFunction]),resolve:mr([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}}):N({tempId:c},i),r.proposer===i.tempId&&(r.proposer=c),r.payer===i.tempId&&(r.payer=c),r.authorizations=r.authorizations.map(function(r){return r===i.tempId?c:r}),delete r.accounts[i.tempId]},n=0,t=Object.values(r.accounts);n<t.length;n++)e();for(var u=0,i=Object.values(r.accounts);u<i.length;u++){var c=i[u];fr(lr(c),"Account unable to fulfill roles",c)}return Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}]),pr=function(r){try{if(!b(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 N({},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]=N({},e,{asArgument:e.xform.asArgument(e.value)})}),o(r)})}catch(r){return Promise.reject(r)}},yr=function(r){try{var e=function(r){if(n)return r;throw new Error("Invalid Cadence Value")},n=!1;if(!b(r)&&!I(r))return Promise.resolve(o(r));var t=k(r,"ix.cadence");if("string"==typeof t)return r.message.cadence=t,Promise.resolve(o(r));var u=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 N({},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(u&&u.then?u.then(e):e(u))}catch(r){return Promise.reject(r)}};function hr(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 gr=function(r){try{if(!b(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(Pr(r,e.insideSigners,A(hr(r)))).then(function(e){var t=br(r,e);return Promise.resolve(Pr(r,n,x(N({},hr(r),{payloadSigs:t})))).then(function(e){return br(r,e),r})})}catch(r){return Promise.reject(r)}},Pr=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 br(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 z(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)?z(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 Ir=function(e){try{var n=k(e,"ix.validators",[]);return Promise.resolve(r(e,n.map(function(r){return function(e){return r(e,{Ok:o,Bad:P})}})))}catch(r){return Promise.reject(r)}},kr=function(r){var e=r.node;return function(r){try{return b(r)?r.accounts[r.proposer].sequenceNum?Promise.resolve(o(r)):Promise.resolve(O([F(r.accounts[r.proposer].addr)])).then(function(n){return Promise.resolve(w(n,{node:e})).then(function(e){return Promise.resolve(j(e)).then(function(e){return r.accounts[r.proposer].sequenceNum=e.keys[r.accounts[r.proposer].keyId].sequenceNumber,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}},wr=function(r){var e=r.node;return function(r){try{return b(r)?r.message.refBlock?Promise.resolve(o(r)):Promise.resolve(O([T()])).then(function(n){return Promise.resolve(w(n,{node:e})).then(function(e){return Promise.resolve(j(e)).then(function(e){return r.message.refBlock=e.id,o(r)})})}):Promise.resolve(o(r))}catch(r){return Promise.reject(r)}}};export{H as arg,D as args,E as authorization,B as authorizations,O as build,F as getAccount,R as getBlockByHeight,C as getBlockById,L as getEvents,T as getLatestBlock,V as getTransactionStatus,nr as invariant,K as limit,$ as param,M as params,W as payer,X as ping,J as proposer,Y as ref,q as resolve,vr as resolveAccounts,pr as resolveArguments,yr as resolveParams,kr as resolveProposerSequenceNumber,wr as resolveRefBlockId,gr as resolveSignatures,Ir as resolveValidators,Z as script,rr as transaction,er 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){function u(e){return void 0===e&&(e=[]),r.pipe(r.interaction(),e)}var c=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 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 f(e){return r.pipe([r.makeGetAccount,function(n){return n.accountAddr=e,r.Ok(n)}])}function l(e){return void 0===e&&(e=!1),r.pipe([r.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=e,r.Ok(n)}])}var d={asArgument:function(e){return e},asInjection:function(e){return e}},p={asArgument:function(e){return e},asInjection:function(e){return e}},m=[];const v=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{y(t,1,e(this.v))}catch(e){y(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?y(t,1,r?r(o):o):n?y(t,1,n(o)):y(t,2,o)}catch(e){y(t,2,e)}},t},e}();function y(e,r,n){if(!e.s){if(n instanceof v){if(!n.s)return void(n.o=y.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(y.bind(null,e,r),y.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function h(e){return e instanceof v&&1&e.s}const g="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var k=function(e){return"function"==typeof e},P=function(e){return"number"==typeof e},b=function(e){return"string"==typeof e},O=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}},I=function(e){return!(e.role.proposer&&!(b(e.addr)&&P(e.keyId)&&P(e.sequenceNum)&&k(e.signingFunction))||e.role.payer&&!(b(e.addr)&&P(e.keyId)&&k(e.signingFunction))||e.role.authorizer&&!(b(e.addr)&&P(e.keyId)&&k(e.signingFunction)))},j=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},w=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},S=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[g]){var t,o,i,u=e[g]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!h(n))return void n.then(e,i||(i=y.bind(null,o=new v,2)));n=n.v}o?y(o,1,n):o=n}catch(e){y(o||(o=new v),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(!h(u))return void u.then(n,o||(o=y.bind(null,t=new v,2)));u=u.v}t?y(t,1,u):t=u}catch(e){y(t||(t=new v),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(){O(I(e.accounts[n]),"Account unable to fulfill role",e.accounts[n])}var i=function(){if(k(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:j([r.kind,n.kind]),tempId:j([r.tempId,n.tempId]),addr:j([r.addr,n.addr]),keyId:(i=[r.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(P)[0]?i.filter(P)[0]:null),sequenceNum:"number"==typeof w([r,n]).sequenceNum?w([r,n]).sequenceNum:r.sequenceNum,signature:j([r.signature,n.signature]),signingFunction:j([r.signingFunction,n.signingFunction]),resolve:j([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];O(I(c),"Account unable to fulfill roles",c)}return Promise.resolve(r.Ok(e))}catch(e){return Promise.reject(e)}}]);function A(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 q=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 B(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 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))){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=p),{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=u,e.getAccount=f,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=l,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 c=t[0];return function(e){return c(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=d),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=c,e.resolveAccounts=S,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.resolveProposerSequenceNumber=function(e){var o=e.node;return function(e){try{return r.isTransaction(e)?e.accounts[e.proposer].sequenceNum?Promise.resolve(r.Ok(e)):Promise.resolve(u([f(e.accounts[e.proposer].addr)])).then(function(i){return Promise.resolve(n.send(i,{node:o})).then(function(n){return Promise.resolve(t.decodeResponse(n)).then(function(n){return e.accounts[e.proposer].sequenceNum=n.keys[e.accounts[e.proposer].keyId].sequenceNumber,r.Ok(e)})})}):Promise.resolve(r.Ok(e))}catch(e){return Promise.reject(e)}}},e.resolveRefBlockId=function(e){var o=e.node;return function(e){try{return r.isTransaction(e)?e.message.refBlock?Promise.resolve(r.Ok(e)):Promise.resolve(u([l()])).then(function(i){return Promise.resolve(n.send(i,{node:o})).then(function(n){return Promise.resolve(t.decodeResponse(n)).then(function(n){return e.message.refBlock=n.id,r.Ok(e)})})}):Promise.resolve(r.Ok(e))}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(q(e,n.insideSigners,i.encodeTransactionPayload(A(e)))).then(function(r){var n=B(e,r);return Promise.resolve(q(e,t,i.encodeTransactionEnvelope(a({},A(e),{payloadSigs:n})))).then(function(r){return B(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||m,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){function u(e){return void 0===e&&(e=[]),r.pipe(r.interaction(),e)}var c=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 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 f(e){return r.pipe([r.makeGetAccount,function(n){return n.accountAddr=e,r.Ok(n)}])}function l(e){return void 0===e&&(e=!1),r.pipe([r.makeGetLatestBlock,function(n){return n.block.isSealed=e,r.Ok(n)}])}var d={asArgument:function(e){return e},asInjection:function(e){return e}},p={asArgument:function(e){return e},asInjection:function(e){return e}},m=[];const v=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{y(t,1,e(this.v))}catch(e){y(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?y(t,1,r?r(o):o):n?y(t,1,n(o)):y(t,2,o)}catch(e){y(t,2,e)}},t},e}();function y(e,r,n){if(!e.s){if(n instanceof v){if(!n.s)return void(n.o=y.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(y.bind(null,e,r),y.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function h(e){return e instanceof v&&1&e.s}const g="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var k=function(e){return"function"==typeof e},b=function(e){return"number"==typeof e},P=function(e){return"string"==typeof e},O=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}},I=function(e){return!(e.role.proposer&&!(P(e.addr)&&b(e.keyId)&&b(e.sequenceNum)&&k(e.signingFunction))||e.role.payer&&!(P(e.addr)&&b(e.keyId)&&k(e.signingFunction))||e.role.authorizer&&!(P(e.addr)&&b(e.keyId)&&k(e.signingFunction)))},j=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},w=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},S=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[g]){var t,o,i,u=e[g]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!h(n))return void n.then(e,i||(i=y.bind(null,o=new v,2)));n=n.v}o?y(o,1,n):o=n}catch(e){y(o||(o=new v),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(!h(u))return void u.then(n,o||(o=y.bind(null,t=new v,2)));u=u.v}t?y(t,1,u):t=u}catch(e){y(t||(t=new v),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(){O(I(e.accounts[n]),"Account unable to fulfill role",e.accounts[n])}var i=function(){if(k(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:j([r.kind,n.kind]),tempId:j([r.tempId,n.tempId]),addr:j([r.addr,n.addr]),keyId:(i=[r.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(b)[0]?i.filter(b)[0]:null),sequenceNum:"number"==typeof w([r,n]).sequenceNum?w([r,n]).sequenceNum:r.sequenceNum,signature:j([r.signature,n.signature]),signingFunction:j([r.signingFunction,n.signingFunction]),resolve:j([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];O(I(c),"Account unable to fulfill roles",c)}return Promise.resolve(r.Ok(e))}catch(e){return Promise.reject(e)}}]);function A(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 B=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 q(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 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))){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=p),{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=u,e.getAccount=f,e.getBlockByHeight=function(e){return r.pipe([r.makeGetBlockByHeight,function(n){return n.block.height=e,r.Ok(n)}])},e.getBlockById=function(e){return r.pipe([r.makeGetBlockById,function(n){return n.block.id=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=l,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 c=t[0];return function(e){return c(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=d),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=c,e.resolveAccounts=S,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.resolveProposerSequenceNumber=function(e){var o=e.node;return function(e){try{return r.isTransaction(e)?e.accounts[e.proposer].sequenceNum?Promise.resolve(r.Ok(e)):Promise.resolve(u([f(e.accounts[e.proposer].addr)])).then(function(i){return Promise.resolve(n.send(i,{node:o})).then(function(n){return Promise.resolve(t.decodeResponse(n)).then(function(n){return e.accounts[e.proposer].sequenceNum=n.keys[e.accounts[e.proposer].keyId].sequenceNumber,r.Ok(e)})})}):Promise.resolve(r.Ok(e))}catch(e){return Promise.reject(e)}}},e.resolveRefBlockId=function(e){var o=e.node;return function(e){try{return r.isTransaction(e)?e.message.refBlock?Promise.resolve(r.Ok(e)):Promise.resolve(u([l()])).then(function(i){return Promise.resolve(n.send(i,{node:o})).then(function(n){return Promise.resolve(t.decodeResponse(n)).then(function(n){return e.message.refBlock=n.id,r.Ok(e)})})}):Promise.resolve(r.Ok(e))}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(B(e,n.insideSigners,i.encodeTransactionPayload(A(e)))).then(function(r){var n=q(e,r);return Promise.resolve(B(e,t,i.encodeTransactionEnvelope(a({},A(e),{payloadSigs:n})))).then(function(r){return q(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||m,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.30", | ||
"version": "0.0.31", | ||
"description": "Flow SDK", | ||
@@ -37,8 +37,8 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@onflow/decode": "0.0.6", | ||
"@onflow/decode": "0.0.7", | ||
"@onflow/encode": "0.0.4", | ||
"@onflow/interaction": "0.0.8", | ||
"@onflow/send": "0.0.17", | ||
"@onflow/interaction": "0.0.10", | ||
"@onflow/send": "0.0.20", | ||
"@qvvg/templar": "0.0.1" | ||
} | ||
} |
363
readme.md
@@ -7,7 +7,7 @@ # @onflow/sdk | ||
- **Last Updated:** July 7th 2020 | ||
- **Last Updated:** August 13th 2020 | ||
- **Stable:** Yes | ||
- **Risk of Breaking Change:** Medium | ||
This package is working and in active delveopment, breaking changes may happen. | ||
This package is working and in active development, breaking changes may happen. | ||
@@ -20,13 +20,302 @@ # Install | ||
# Usage | ||
# Flow JS-SDK | ||
## Example: Building A Transaction Interaction | ||
#### Introduction | ||
Welcome, we're glad you're here. | ||
The Flow JS-SDK is a relatively low-level suite of tools that allow JavaScript applications to interact with the Flow Blockchain. | ||
In doing so, the Flow JS-SDK employs several concepts which empower developers to create, and operate upon what we call _Interactions_ that can be sent to the Flow Blockchain, and what we call _Responses_ that are returned from the Flow Blockchain. | ||
Interactions have a Type, which tells the Flow JS-SDK itself how to react to preparing, operating upon and sending this specific interaction. Types of Interactions include, Get Account, Execute Script, Execute Transaction, Get Events, Get Latest Block and Get Transaction Status. | ||
Futher in this document we will outline how to create such Interactions for use in your JavaScript applications, and how to deal with the Responses that the Flow Blockchain returns. | ||
## Phases | ||
Conceptually, there are four phases to the Flow JS-SDK. | ||
Build -> Resolve -> Send -> Decode | ||
We will walk through each phase to exaplain how it is relevant for your applications and how you use the Flow JS-SDK. | ||
## Build | ||
Build is the phase of your use of the Flow JS-SDK where you _Build_ up a specific interaction. During this phase you specify upon an interaction what information you currently know. This may include the specific Cadence code for a Script you wish to execute, or the address for the Account of which you wish to get. As you specify information, the type of the interaction you are composing becomes clear. For example, if you Build an interaction and specify that you want to get an account for a specific address, you are composing an interaction of type Get Account. | ||
The Flow JS-SDK exposes what we call a _build_ function, and a suite of _builder_ functions. The build function consumes as its argument an array of builder functions within it. Each builder function consumes information that you know, and that you want to place into the interaction. | ||
Example 1 | ||
: Building an Execute Script Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const interaction = await sdk.build([ | ||
sdk.script` | ||
pub fun main(): Int { | ||
return 721 | ||
} | ||
` | ||
]) | ||
``` | ||
In Example 1, we're composing an Execute Script Interaction, because we have built an interaction and specified a Script Cadence code within it using the sdk.script builder. | ||
Example 2 | ||
: Building an Execute Get Account Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const interaction = await sdk.build([ | ||
sdk.getAccount("123ABC456DEF") | ||
]) | ||
``` | ||
In Example 2, we're composing a Get Account Interaction, because we have built an interaction and specified an address within it using the sdk.getAccount builder. | ||
## Build - Transactions | ||
On Flow, you can also execute transactions. Transaction Interactions can be built as well using the Flow JS-SDK. Transaction Interactions require a few pieces of information when they're being built. They require, the Cadence Code for the Transaction, any arguments that the Transaction Requires, a Proposer for the Transaction, a Payer for the Transaction and a list of Authorizers for the transaction. | ||
The Proposer of the transaction represents the Account on Flow for which one of it's keys will have its sequence number incremented by the transaction. | ||
The Payer of the transaction represents the Account on Flow for which will pay for the transaction. | ||
Each Authorizer of the transaction represents an Account on Flow which consents to have it's state modified by this transaction. | ||
The builders for the Proposer, Payer and each Authorizer consume an _authorization_ which is built using its own builder function. An authorization is a data structure which is constructed by providing an Address, Signing Function and a keyId, and optionally a sequence number (more on this later). | ||
The Address for an Authorization corresponds to the address for the Flow Account this authorization represents. The Signing Function is a function which can produce a Signature for a transaction on behalf of the specified account. The keyId represents the id of the key on the Account which needs to be used to produce the Signature for a transaction. An Authorization also optionlly takes a sequence number, which is the sequence number for the key corresponding to the keyId of the Flow Account this authorization represents, if this authroization is for a proposer. (Again, more on this later. Observe how we choose not to provide this piece of information in Example 3, this decision will be explained later). | ||
Example 3 | ||
: Building a Transaction Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const signingFunction = (...) => { | ||
... | ||
return signature | ||
} | ||
const interaction = await sdk.build([ | ||
sdk.transaction`transaction() { prepare(acct: AuthAccount) {} execute { log("Hello, Flow!") } }`, | ||
sdk.payer(sdk.authorization("f8d6e0586b0a20c7", signingFunction, 0)), | ||
sdk.proposer(sdk.authorization("f8d6e0586b0a20c7", signingFunction, 0)), | ||
sdk.authorizations([sdk.authorization("f8d6e0586b0a20c7", signingFunction, 0)]), | ||
]) | ||
``` | ||
In Example 3, we build a Transaction Interaction by building an interaction and specifying transaction code, a payer, proposer and list of authorizers using their corresponding builder functions. Inside the payer, proposer and each authorizer, we call the authorization builder function and provide the required address, signing function and keyId that will be used in that authorization. | ||
## Resolve | ||
After Build, the next phase of use of the JS-SDK is the Resolve phase. During Build, we specified onto the the Interaction we're building the information that we currently know. Things like the Cadence Code we wish to have executed for a Script Interaction or Transaction Interaction, or the authroizations for a payer or proposer, or the address of the account we wish for get for a Get Account Interaction. | ||
Some things, however, we don't know. For example, when developing your dApp, you don't know the signature that will be produced when a user signs a transaction. You don't know the specific encoding that your Interaction needs to be in, or maybe you don't yet know the sequence number for a transactions proposer authorization. All of these things need to be discovered, produced or conceptually _resolved_ before your Interaction can be sent to the Flow Blockchain. | ||
This is where the _Resolve_ phase comes in. Resolves takes your built interaction containing all the information you do know and does it's best to get it into a position where it can be sent to the Flow Blockchain. The Flow JS-SDK comes with several _resolver_ functions that your dApp can use to do just this. | ||
Example 4 | ||
: Building an Execute Script Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const builtInteraction = await sdk.build([ | ||
sdk.script` | ||
pub fun main(msg: String): String { | ||
return "Hello, Flow!" | ||
} | ||
`, | ||
sdk.args([ sdk.arg("Hello, Flow", types.String) ]) | ||
]) | ||
const resolvedInteraction = await sdk.pipe(builtInteraction, [ | ||
sdk.resolveParams, | ||
sdk.resolveArguments, | ||
]) | ||
``` | ||
In Example 4 we Build an Execute Script Interaction by using the script builder to specify a Cadence script and the args and arg builders to specify some arguments to pass into the Cadence Script. To Resolve this built interaction, we pipe'd the built interaction through an array of resolvers. The resolveParams resolver encoded the Cadence script into a format the Flow Blockchain accepts, and the resolveArguments resolver prepared the arguments into the correct encoding that the Flow Blockchain accepts. | ||
Example 5 | ||
: Building an Execute Script Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const signingFunction = (...) => { | ||
... | ||
return signature | ||
} | ||
const builtInteraction = await sdk.build([ | ||
sdk.transaction`transaction(msg: String) { prepare(acct: AuthAccount) {} execute { log(msg) } }`, | ||
sdk.args([sdk.arg("Hello, Flow!", types.String)]), | ||
sdk.payer(sdk.authorization("f8d6e0586b0a20c7", signingFunction, 0)), | ||
sdk.proposer(sdk.authorization("f8d6e0586b0a20c7", signingFunction, 0)), | ||
sdk.authorizations([sdk.authorization("f8d6e0586b0a20c7", signingFunction, 0)]), | ||
]) | ||
const resolvedInteraction = await sdk.pipe(builtInteraction, [ | ||
sdk.resolveArguments, | ||
sdk.resolveParams, | ||
sdk.resolveAccounts, | ||
sdk.resolveRefBlockId({ node: "http://localhost:8080" }), | ||
sdk.resolveProposerSequenceNumber({ node: "http://localhost:8080" }), | ||
sdk.resolveSignatures, | ||
]) | ||
``` | ||
In Example 5 we build a Transaction Interaction by building an interaction and calling the transaction builder with a piece of transaction Cadence code, and then specify an authorization for the payer, proposer and one authorizer. | ||
After the Transaction Interaction is built, we pipe it through a series of resolvers. We resolve the reference block id to execute this transaction against by calling the resolveRefBlockId resovler. We resolve the sequence number for the proposer authorization for this transaction by calling the resolveProposerSequenceNumber resolver. Then we resolve the arguments and params for the transaction by calling the resolveArguments and resolveParams resolvers. We then call the resolveAccounts resolver to prepare each specified authorization into a format that they could be used to produce their correct signature(s) for the transaction. Finally, at the end, we call the resolveSignatures resolver which will asyncronously using the signingFunction available for the specified authorizations to retrieve a signature for each. | ||
## Send | ||
Once an Interaction has been _Built_ and, if necessary, _Resolved_ it can then be _Sent_ to the Flow Blockchain. Fortunately, sending to the Flow Blockchain is simple. The Flow JS-SDK exposes a Send function which consumes an Interaction and some configuration, and returns a data structure called a _Response_ (more on this later). | ||
Example 6 | ||
: Sending an Execute Script Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const builtInteraction = await sdk.build([ | ||
sdk.script` | ||
pub fun main(msg: String): String { | ||
return "Hello, Flow!" | ||
} | ||
`, | ||
sdk.args([ sdk.arg("Hello, Flow", types.String) ]) | ||
]) | ||
const resolvedInteraction = await sdk.pipe(builtInteraction, [ | ||
sdk.resolveParams, | ||
sdk.resolveArguments, | ||
]) | ||
const response = await sdk.send(resolvedInteraction, { node: "my-access-node-url" }) | ||
``` | ||
In Example 6 we use the Flow JS-SDK send function to send an Interaction to the Flow Blockchain, and receive back a Response. Notice how the send function consumes both the resolved interaction as well as an object of configuration. The key value pair `node: "my-access-node-url"` on this configuration object tells the send function where to send this interaction to. The node here must point to the Flow access node of your choice, be that for the Flow main-net, testnet, emulator or elsewhere. | ||
## Decode | ||
The Flow JS-SDK send function returns a response. This Response is a Data Structure that must be _decoded_ into a format that you intuitively want. For example, if you send an Execute Script Interaction to the Flow Blockchain and inside that Interaction was a Cadence script that when executed returns the Integer 1, then the response you intuitively want is the integer 1 represented as a the JavaScript number 1. If you send a Get Account Interaction to the Flow Blockchain, then the response you intuitively want is a JavaScript object containing information of that Flow Account, not the entire content of the Response Data Structure itself. | ||
This is where the decode phase comes in. The Flow JS-SDK exposes a function `decode` that consumes a response and returns back what you intuitively expect. | ||
For the available Interaction types, decoding responses for them produces values like such: | ||
- Decoding a Transaction Interaction returns the Transaction ID for the submitted Transaction Interaction | ||
- Decoding an Execute Script Interaction returns the JavaScript equivalently typed values for the value returned by the Cadence Script that was Executed. | ||
- Decoding a Get Account Interaction returns a JavaScript object containing the information for the account. | ||
- Decoding a Get Events Interaction returns a JavaScript array of JavaScript objects each containing the relevant information for each Event. | ||
- Decoding a Get Transaction Status interaction returns a JavaScript object of relevant information about the status of a transcation. | ||
- Decoding a Get Latest Block interaction returns a JavaScript object of relevant information of the Latest Block. | ||
Example 7 | ||
: Decoding an Execute Script Interaction | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const builtInteraction = await sdk.build([ | ||
sdk.script` | ||
pub fun main(int1: Int, int2: Int): Int { | ||
return int1 + int2 | ||
} | ||
`, | ||
sdk.args([ sdk.arg(1, types.Int), sdk.arg(2, types.Int) ]) | ||
]) | ||
const resolvedInteraction = await sdk.pipe(builtInteraction, [ | ||
sdk.resolveParams, | ||
sdk.resolveArguments, | ||
]) | ||
const response = await sdk.send(resolvedInteraction, { node: "my-access-node-url" }) | ||
const decoded = await sdk.decode(response) | ||
assert(3 === decoded) | ||
assert(typeof decoded === "number") | ||
``` | ||
In Example 7 we illustrate how intuitively the decoded value returned from calling decode on the response returned from this Execute Script interaction must be the JavaScript number 3. This is because the Execute Script interaction contains Cadence code, which when executed with the included script arguements, adds the Cadence Integer 1 and Cadence Integer 2 together to return the Cadence Integer 3. Since there is no native concept of a Cadence Integer of value 3 in JavaScript, when this response is decoded, we intuitively expect the decoded value to be the JavaScript number 3. | ||
Decode does several things under the hood to take your response into something you'd like to consume in your JS Applications. At a high level, it returns the relevant information from the response data structure, and if there are any Cadence values, decodes those Cadence values into conceptually equivalent JavaScript values and types. | ||
## Custom Decoders | ||
Custom Decoders are a concept available in the Flow JS-SDK which allows developers to, when decoding a response, exchange any Cadence typed values into their desired JavaScript value. | ||
Custom Decoders are declared by passing a configuration object of key value pairs into the decode function. The keys included in this object correspond to the Cadence type you wish to provide a custom decoder for, and the value must be an asyncronous function which returns your desired JavaScript value for the type. The keys in this object can optionally be regex values declared by writing a regular expression between two forward slashes (ie: "/my-regex-exp/"). | ||
Example 8 | ||
: Using a Custom Decoder to decode an Execute Script interaction. | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const builtInteraction = await sdk.build([ | ||
sdk.script` | ||
pub struct Point { | ||
pub var x: Int | ||
pub var y: Int | ||
init(x: Int, y: Int) { | ||
self.x = x | ||
self.y = y | ||
} | ||
} | ||
pub fun main(x: Int, y: Int): Point { | ||
return Point(x: x, y: y) | ||
} | ||
`, | ||
sdk.args([ sdk.arg(123, types.Int), sdk.arg(456, types.Int) ]) | ||
]) | ||
const resolvedInteraction = await sdk.pipe(builtInteraction, [ | ||
sdk.resolveParams, | ||
sdk.resolveArguments, | ||
]) | ||
const response = await sdk.send(resolvedInteraction, { node: "my-access-node-url" }) | ||
class Point { | ||
constructor({ x, y }) { | ||
this.x = x | ||
this.y = y | ||
this.created_at = Date.now() | ||
} | ||
} | ||
const decoded = await sdk.decode(response, { | ||
"/Point/": async point => new Point(point) | ||
}) | ||
assert(3 === decoded) | ||
assert(typeof decoded === "number") | ||
``` | ||
In Example 8 we declare an Execute Script interaction with Cadence code that returns a Point Cadence struct. If no custom decoders were declared, the returned Cadence Point struct would by default be decoded into a JavaScript object with key value pairs for it's x and y variables. However, in this example we declare a custom decoder onto the call to decode which includes a regular expression that will match to the Point struct and return a new instance of the Point class that is declared just above. | ||
## Flow JS-SDK Usage | ||
### Example: Building A Transaction Interaction | ||
Building a interaction produces an unresolved interaction. For example, to build a transaction interaction you must call `sdk.build([...])`, and pass in the sequence of builders you want to use to compose that transaction interaction. The example below highlights one way to build a transaction interaction: | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const builtTxIx = await sdk.build([ | ||
sdk.transaction`transaction(msg: String) { prepare(acct: AuthAccount) {} execute { log(msg) } }`, | ||
sdk.args([sdk.arg("Hello, Flow!", types.String)]), | ||
sdk.payer(sdk.authorization("01", signingFunction, 0)), | ||
sdk.proposer(sdk.authorization("01", signingFunction, 0, seqNum)), | ||
sdk.transaction`transaction { prepare(acct: AuthAccount) {} execute { log("Hello") } }`, | ||
sdk.authorizations([sdk.authorization("01", signingFunction, 0)]), | ||
@@ -36,3 +325,3 @@ ]) | ||
## Example: Resolving A Transaction Interaction | ||
### Example: Resolving A Transaction Interaction | ||
@@ -42,5 +331,10 @@ Once a transaction interaction is built, it's still not quite ready to be sent to the Access Node. To further prepare it to be ready to be sent to the Access Node, you must resolve it by piping it through a series of resolvers. Resolvers are functions that consume an interaction and attempt to fill in or prepare any missing pieces of it to get it ready to be sent to the Access API. The example below highlights one way to resolve a transaction interaction: | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const resolvedTxIx = await sdk.pipe(builtTxIx, [ | ||
sdk.resolve([ | ||
sdk.resolveArguments, | ||
sdk.resolveParams, | ||
sdk.resolveAccounts, | ||
sdk.resolveProposerSequenceNumber({ node: "http://localhost:8080" }), | ||
sdk.resolveRefBlockId({ node: "http://localhost:8080" }), | ||
sdk.resolveSignatures | ||
@@ -50,12 +344,12 @@ ]) | ||
``` | ||
## Example: Sending A Transaction Interaction | ||
### Example: Sending A Transaction Interaction | ||
Now that your transction interaction is resolved, it can be sent to an Access Node! To send it to an Access Node, you must call `sdk.send(...)` with that interaction, and a configuration object. To specify which Access Node to send your request to, you specify it in the _node_ parameter of the config object. For example, the code below shows how to send your transaction interaction to the Flow Emulator running on _localhost:8080_: | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const response = await sdk.send(resolvedTxIx, { node: "http://localhost:8080" }) | ||
``` | ||
## Using the rest of the SDK | ||
The SDK additionally supplies builders to construct interactions of many different types to interact with the Access Node's various APIs. | ||
@@ -65,5 +359,6 @@ | ||
### GetAccount | ||
### GetAccount Usage | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const response = await sdk.send(await sdk.build([ | ||
@@ -74,5 +369,6 @@ sdk.getAccount(addr) | ||
### GetEvents | ||
### GetEvents Usage | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const response = await sdk.send(await sdk.build([ | ||
@@ -83,5 +379,6 @@ sdk.getEvents(eventType, startBlock, endBlock), | ||
### GetLatestBlock | ||
### GetLatestBlock Usage | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const response = await sdk.send(await sdk.build([ | ||
@@ -92,5 +389,6 @@ sdk.getLatestBlock() | ||
### GetTransactionStatus | ||
### GetTransactionStatus Usage | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const response = await sdk.send(await sdk.build([ | ||
@@ -101,5 +399,6 @@ sdk.getTransactionStatus(txId) | ||
### Ping | ||
### Ping Usage | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
const response = await sdk.send(await sdk.build([ | ||
@@ -110,10 +409,12 @@ sdk.ping() | ||
### Script | ||
### Script Usage | ||
```javascript | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.params([sdk.param("foo", "bar")]), | ||
sdk.args([sdk.arg("Hello Flow!", types.String)]), | ||
sdk.script` | ||
pub fun main(): Int { | ||
log("${p => p.foo}") | ||
pub fun main(msg: String): Int { | ||
log(msg) | ||
return 7 | ||
@@ -124,2 +425,3 @@ } | ||
sdk.resolve([ | ||
sdk.resolveArguments, | ||
sdk.resolveParams, | ||
@@ -130,19 +432,20 @@ ]), | ||
### Transaction | ||
### Transaction Usage | ||
```javascript | ||
const acctResponse = await sdk.send(await sdk.build([ | ||
sdk.getAccount("01") | ||
]), { node: "http://localhost:8080" }) | ||
const seqNum = acctResponse.account.keys[0].sequenceNumber | ||
import * as sdk from "@onflow/sdk" | ||
import * as types from "@onflow/types" | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.transaction`transaction(msg: String) { prepare(acct: AuthAccount) {} execute { log(msg) } }`, | ||
sdk.args([sdk.arg("Hello, Flow!", types.String)]), | ||
sdk.payer(sdk.authorization("01", signingFunction, 0)), | ||
sdk.proposer(sdk.authorization("01", signingFunction, 0, seqNum)), | ||
sdk.transaction`transaction { prepare(acct: AuthAccount) {} execute { log("Hello") } }`, | ||
sdk.proposer(sdk.authorization("01", signingFunction, 0)), | ||
sdk.authorizations([sdk.authorization("01", signingFunction, 0)]), | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveArguments, | ||
sdk.resolveParams, | ||
sdk.resolveAccounts, | ||
sdk.resolveProposerSequenceNumber({ node: "http://localhost:8080" }), | ||
sdk.resolveRefBlockId({ node: "http://localhost:8080" }), | ||
sdk.resolveSignatures | ||
@@ -153,3 +456,3 @@ ]), | ||
# Exposes | ||
## Flow JS-SDK Exposes | ||
@@ -190,1 +493,5 @@ - [Top Level](./) | ||
- [`sdk.resolveSignatures`](./src/resolve/resolve-signatures.js) | ||
- [`sdk.resolveArguments`](./src/resolve/resolve-arguments.js) | ||
- [`sdk.resolveProposerSequenceNumber`](./src/resolve/resolve-proposer-sequence-number.js) | ||
- [`sdk.resolveRefBlockId`](./src/resolve/resolve-ref-block-id.js) | ||
- [`sdk.resolveValidators`](./src/resolve/resolve-validators.js) |
@@ -7,3 +7,3 @@ import {pipe, Ok, makeGetLatestBlock} from "@onflow/interaction" | ||
ix => { | ||
ix.latestBlock.isSealed = isSealed | ||
ix.block.isSealed = isSealed | ||
return Ok(ix) | ||
@@ -10,0 +10,0 @@ } |
@@ -17,2 +17,4 @@ // Base | ||
export {getLatestBlock} from "./build/get-latest-block" | ||
export {getBlockById} from "./build/get-block-by-id" | ||
export {getBlockByHeight} from "./build/get-block-by-height" | ||
export {getTransactionStatus} from "./build/get-transaction-status" | ||
@@ -19,0 +21,0 @@ export {limit} from "./build/limit" |
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
319248
44
917
483
+ Added@onflow/decode@0.0.7(transitive)
+ Added@onflow/interaction@0.0.10(transitive)
+ Added@onflow/send@0.0.20(transitive)
- Removed@onflow/decode@0.0.6(transitive)
- Removed@onflow/interaction@0.0.70.0.8(transitive)
- Removed@onflow/send@0.0.17(transitive)
Updated@onflow/decode@0.0.7
Updated@onflow/interaction@0.0.10
Updated@onflow/send@0.0.20