@onflow/sdk
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -5,2 +5,9 @@ ### Unreleased | ||
### 0.0.15 -- 2020-05-05 | ||
- 2020-05-05 -- VSN `@onflow/send` 0.0.8 -> 0.0.9 | ||
- 2020-05-05 -- VSN `@onflow/interaction` 0.0.5 -> 0.0.6 | ||
- 2020-05-05 -- VSN `@onflow/decode` 0.0.5 -> 0.0.6 | ||
- 2020-05-04 **BREAKING** -- Updates sdk according to updated interaction ADT | ||
### 0.0.14 -- 2020-04-20 | ||
@@ -7,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/interaction"),r=require("@onflow/send"),t=require("@onflow/decode"),n=require("@qvvg/templar"),o=require("@onflow/encode"),i=e.pipe;function a(){return(a=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var u={asParam:function(e){return e},asInjection:function(e){return e}};function c(e,r,t){return{addr:e,keyId:r,sequenceNum:t}}var p=[];function s(){return Date.now()}function d(e){return function(r){return null==r?e:r}}function f(e,r,t){return{acct:e,signature:r,keyId:t}}var l=e.pipe([function(r){if(!e.isTransaction(r)&&!e.isScript(r))return e.Ok(r);var t=e.get(r,"ix.code");return r.payload.code="function"==typeof t?t(e.get(r,"ix.params",{})):t,e.Ok(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 t.decode}}),Object.defineProperty(exports,"decodeResponse",{enumerable:!0,get:function(){return t.decodeResponse}}),exports.authorization=function(e,r,t){return{acct:e,signFn:r,keyId:t}},exports.authorizations=function(r){return void 0===r&&(r=[]),e.pipe([e.put("tx.authorizations",r)])},exports.build=function(r){return void 0===r&&(r=[]),e.pipe(e.interaction(),r)},exports.getAccount=function(r){return e.pipe([e.makeGetAccount,function(t){return t.acct=r,e.Ok(t)}])},exports.getEvents=function(r,t,n){return e.pipe([e.makeGetEvents,function(t){return t.eventType=r,e.Ok(t)},function(r){return r.bounds.start=t,e.Ok(r)},function(r){return r.bounds.end=n,e.Ok(r)}])},exports.getLatestBlock=function(r){return void 0===r&&(r=!1),e.pipe([e.makeGetLatestBlock,function(t){return t.isSealed=r,e.Ok(t)}])},exports.getTransactionStatus=function(r){return e.pipe([e.makeGetTransactionStatus,function(t){return t.txId=r,e.Ok(t)}])},exports.limit=function(r){return e.pipe([function(t){return t.payload.limit=r,e.Ok(t)}])},exports.param=function(e,r,t){return void 0===r&&(r=u),void 0===t&&(t=null),{key:t,value:e,xform:r}},exports.params=function(r){return void 0===r&&(r=[]),e.pipe([e.put("ix.params",(t=r,void 0===t&&(t=[]),t.filter(function(e){return null!=e.key}).reduce(function(e,r){var t;return a({},e,((t={})[r.key]=r.value,t))},{})))]);var t},exports.payer=function(r){return e.pipe([e.put("tx.payer",r)])},exports.ping=function(){return e.pipe([e.makePing])},exports.proposer=function(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];try{var o=function(){"object"==typeof t[0]&&(i=t[0]);var r=t[0],n=t[1],o=t[2];return e.pipe([function(t){return t.proposer=i||c(r,n,o),e.Ok(t)}])},i=null,a=function(){if("function"==typeof t[0])return Promise.resolve(t[0]()).then(function(e){i=e})}();return Promise.resolve(a&&a.then?a.then(o):o(a))}catch(e){return Promise.reject(e)}},exports.ref=function(r){return e.pipe([function(t){return t.payload.ref=r,e.Ok(t)}])},exports.resolve=i,exports.resolveAuthorizations=function(r){try{if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));var t=o.encodeTransactionPayload({script:r.payload.code,refBlock:r.payload.ref||null,gasLimit:r.payload.limit,proposalKey:{address:r.proposer.addr,keyId:r.proposer.keyId,sequenceNum:r.proposer.sequenceNum},payer:e.get(r,"tx.payer").acct,authorizers:e.get(r,"tx.authorizations").map(function(e){return e.acct})}),n=e.get(r,"tx.authorizations",[]).map(function(n){try{var o=function(){return n.acct===e.get(r,"tx.payer").acct?f(n.acct,null,n.keyId):Promise.resolve(n.signFn({message:t,addr:n.acct,keyId:n.keyId,roles:{proposer:r.proposer.addr===n.acct,authorizer:!0,payer:e.get(r,"tx.payer").acct===n.acct},interaction:r})).then(function(e){return f(n.acct,e.signature,n.keyId)})},i=function(){if("function"==typeof n)return Promise.resolve(n()).then(function(e){n=e})}();return Promise.resolve(i&&i.then?i.then(o):o())}catch(e){return Promise.reject(e)}});return Promise.resolve(Promise.all(n)).then(function(t){r.authz=t;var n=o.encodeTransactionEnvelope({script:r.payload.code,refBlock:r.payload.ref,gasLimit:r.payload.limit,proposalKey:{address:r.proposer.addr,keyId:r.proposer.keyId,sequenceNum:r.proposer.sequenceNum},payer:e.get(r,"tx.payer").acct,authorizers:e.get(r,"tx.authorizations").map(function(e){return e.acct}),payloadSigs:r.authz.map(function(e){return null===e.signature?null:{address:e.acct,keyId:e.keyId,sig:e.signature}}).filter(function(e){return null!==e})}),i=e.get(r,"tx.payer");return Promise.resolve(i.signFn({message:n,addr:i.acct,keyId:i.keyId,roles:{proposer:r.proposer.addr===i.acct,authorizer:!1,payer:!0},interaction:r})).then(function(t){return r.payer=f(i.acct,t.signature,i.keyId),e.Ok(r)})})}catch(e){return Promise.reject(e)}},exports.resolveParams=l,exports.script=function(){return e.pipe([e.makeScript,e.put("ix.code",n.t7l.apply(void 0,arguments))])},exports.transaction=function(){return e.pipe([e.makeTransaction,e.put("ix.code",n.t7l.apply(void 0,arguments)),function(r){return r.payload.limit=r.payload.limit||10,r.payload.nonce=r.payload.nonce||s(),r.payload.ref=r.payload.ref||null,e.Ok(r)},e.update("tx.authorizations",d(p))])}; | ||
var e=require("@onflow/interaction"),r=require("@onflow/send"),n=require("@onflow/decode"),t=require("@qvvg/templar"),o=require("@onflow/encode"),i=e.pipe;function u(){return(u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}var a={asParam:function(e){return e},asInjection:function(e){return e}},s=function(e){return"function"==typeof e},c=[];const p=function(){function e(){}return e.prototype.then=function(r,n){const t=new e,o=this.s;if(o){const e=1&o?r:n;if(e){try{f(t,1,e(this.v))}catch(e){f(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?f(t,1,r?r(o):o):n?f(t,1,n(o)):f(t,2,o)}catch(e){f(t,2,e)}},t},e}();function f(e,r,n){if(!e.s){if(n instanceof p){if(!n.s)return void(n.o=f.bind(null,e,r));1&r&&(r=n.s),n=n.v}if(n&&n.then)return void n.then(f.bind(null,e,r),f.bind(null,e,2));e.s=r,e.v=n;const t=e.o;t&&t(e)}}function d(e){return e instanceof p&&1&e.s}const l="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var m=function(e){return"function"==typeof e},y=function(e){return"number"==typeof e},v=function(e){return"string"==typeof e},g=function(e,r){if(!e){var n,t=new Error("INVARIANT "+r);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).join("\n");for(var o=arguments.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=arguments[u];throw(n=console).error.apply(n,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},k=function(e){return!(e.role.proposer&&!(v(e.addr)&&y(e.keyId)&&y(e.sequenceNum)&&m(e.signingFunction))||e.role.payer&&!(v(e.addr)&&y(e.keyId)&&m(e.signingFunction))||e.role.authorizer&&!(v(e.addr)&&y(e.keyId)&&m(e.signingFunction)))},h=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},b=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},I=e.pipe([function(r){try{var n=function(){return e.Ok(r)};if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));var t=function(e,r,n){if("function"==typeof e[l]){var t,o,i,u=e[l]();if(function e(n){try{for(;!(t=u.next()).done;)if((n=r(t.value))&&n.then){if(!d(n))return void n.then(e,i||(i=f.bind(null,o=new p,2)));n=n.v}o?f(o,1,n):o=n}catch(e){f(o||(o=new p),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var s=[],c=0;c<e.length;c++)s.push(e[c]);return function(e,r,n){var t,o,i=-1;return function n(u){try{for(;++i<e.length;)if((u=r(i))&&u.then){if(!d(u))return void u.then(n,o||(o=f.bind(null,t=new p,2)));u=u.v}t?f(t,1,u):t=u}catch(e){f(t||(t=new p),2,e)}}(),t}(s,function(e){return r(s[e])})}(Object.entries(r.accounts),function(e){var r=e[1];function n(){g(k(r),"Account unable to fulfill role",r)}var t=function(){if(m(r.resolve))return Promise.resolve(r.resolve(r)).then(function(e){r=e})}();return t&&t.then?t.then(n):n()});return Promise.resolve(t&&t.then?t.then(n):n())}catch(e){return Promise.reject(e)}},function(r){try{if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));for(var n=function(){var e,n,i,a=o[t],s=a.addr+"|"+a.keyId;r.accounts[s]=null!=r.accounts[s]?(e=r.accounts[s],n=u({tempId:s},a),{kind:h([e.kind,n.kind]),tempId:h([e.tempId,n.tempId]),addr:h([e.addr,n.addr]),keyId:(i=[e.keyId,n.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(y)[0]?i.filter(y)[0]:null),sequenceNum:"number"==typeof b([e,n]).sequenceNum?b([e,n]).sequenceNum:e.sequenceNum,signature:h([e.signature,n.signature]),signingFunction:h([e.signingFunction,n.signingFunction]),resolve:h([e.resolve,n.resolve]),role:{proposer:e.role.proposer||n.role.proposer,authorizer:e.role.authorizer||n.role.authorizer,payer:e.role.payer||n.role.payer,param:e.role.param||n.role.param}}):u({tempId:s},a),r.proposer===a.tempId&&(r.proposer=s),r.payer===a.tempId&&(r.payer=s),r.authorizations=r.authorizations.map(function(e){return e===a.tempId?s:e}),delete r.accounts[a.tempId]},t=0,o=Object.values(r.accounts);t<o.length;t++)n();for(var i=0,a=Object.values(r.accounts);i<a.length;i++){var s=a[i];g(k(s),"Account unable to fulfill roles",s)}return Promise.resolve(e.Ok(r))}catch(e){return Promise.reject(e)}}]);Object.defineProperty(exports,"isBad",{enumerable:!0,get:function(){return e.isBad}}),Object.defineProperty(exports,"isOk",{enumerable:!0,get:function(){return e.isOk}}),Object.defineProperty(exports,"pipe",{enumerable:!0,get:function(){return e.pipe}}),Object.defineProperty(exports,"why",{enumerable:!0,get:function(){return e.why}}),Object.defineProperty(exports,"send",{enumerable:!0,get:function(){return r.send}}),Object.defineProperty(exports,"decode",{enumerable:!0,get:function(){return n.decode}}),Object.defineProperty(exports,"decodeResponse",{enumerable:!0,get:function(){return n.decodeResponse}}),exports.authorization=function(e,r,n){return{addr:e,signingFunction:r,keyId:n}},exports.authorizations=function(r){return void 0===r&&(r=[]),e.pipe(r.map(function(r){return e.makeAuthorizer(u({},"function"==typeof r?{resolve:r}:r,{role:{authorizer:!0}}))}))},exports.build=function(r){return void 0===r&&(r=[]),e.pipe(e.interaction(),r)},exports.getAccount=function(r){return e.pipe([e.makeGetAccount,function(n){return n.accountAddr=r,e.Ok(n)}])},exports.getEvents=function(r,n,t){return e.pipe([e.makeGetEvents,function(n){return n.events.eventType=r,e.Ok(n)},function(r){return r.events.start=n,e.Ok(r)},function(r){return r.events.end=t,e.Ok(r)}])},exports.getLatestBlock=function(r){return void 0===r&&(r=!1),e.pipe([e.makeGetLatestBlock,function(n){return n.latestBlock.isSealed=r,e.Ok(n)}])},exports.getTransactionStatus=function(r){return e.pipe([e.makeGetTransactionStatus,function(n){return n.transactionId=r,e.Ok(n)}])},exports.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=a),void 0===n&&(n=null),{key:n,value:e,xform:r}},exports.params=function(r){return void 0===r&&(r=[]),e.pipe(r.map(e.makeParam))},exports.payer=function(r){return e.makePayer(u({},"function"==typeof r?{resolve:r}:r,{role:{payer:!0}}))},exports.ping=function(){return e.pipe([e.makePing])},exports.proposer=function(){try{for(var r=arguments.length,n=new Array(r),t=0;t<r;t++)n[t]=arguments[t];if(s(n[0]))return Promise.resolve(e.makeProposer({resolve:n[0],role:{proposer:!0}}));var o=n[0],i=n[1],u=n[2];return Promise.resolve(e.makeProposer({addr:o,keyId:i,sequenceNum:u,role:{proposer:!0}}))}catch(e){return Promise.reject(e)}},exports.ref=function(r){return e.pipe([function(n){return n.message.refBlock=r,e.Ok(n)}])},exports.resolve=i,exports.resolveAccounts=I,exports.resolveParams=function(r){if(!e.isTransaction(r)&&!e.isScript(r))return e.Ok(r);var n=e.get(r,"ix.cadence");if("string"==typeof n)return r.message.cadence=n,e.Ok(r);if("function"==typeof n){var t=Object.fromEntries(Object.values(r.params).filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]}));return r.message.cadence=n(t),e.Ok(r)}throw new Error("Invalid Cadence Value")},exports.resolveSignatures=function(r){try{if(!e.isTransaction(r))return Promise.resolve(e.Ok(r));var n=r.authorizations.map(function(e){return r.accounts[e]}),t=r.accounts[r.payer],i=r.accounts[r.proposer],a=o.encodeTransactionPayload({script:r.message.cadence,refBlock:r.message.refBlock||null,gasLimit:r.message.computeLimit,proposalKey:{address:i.addr,keyId:i.keyId,sequenceNum:i.sequenceNum},payer:t.addr,authorizers:n.map(function(e){return e.addr})}),s=n.map(function(e){try{return e.addr===t.addr?(r.accounts[e.tempId]=u({},r.accounts[e.tempId],{signature:null}),Promise.resolve()):Promise.resolve(e.signingFunction({message:a,addr:e.addr,keyId:e.keyId,roles:{proposer:i.addr===e.addr,authorizer:!0,payer:t.addr===e.addr},interaction:r})).then(function(n){r.accounts[e.tempId]=u({},r.accounts[e.tempId],{signature:n.signature})})}catch(e){return Promise.reject(e)}});return Promise.resolve(Promise.all(s)).then(function(){n=r.authorizations.map(function(e){return r.accounts[e]});var a=o.encodeTransactionEnvelope({script:r.message.cadence,refBlock:r.message.refBlock||null,gasLimit:r.message.computeLimit,proposalKey:{address:i.addr,keyId:i.keyId,sequenceNum:i.sequenceNum},payer:t.addr,authorizers:n.map(function(e){return e.addr}),payloadSigs:n.map(function(e){return null===e.signature?null:{address:e.addr,keyId:e.keyId,sig:e.signature}}).filter(function(e){return null!==e})});return Promise.resolve(t.signingFunction({message:a,addr:t.addr,keyId:t.keyId,roles:{proposer:i.addr===t.addr,authorizer:!1,payer:!0},interaction:r})).then(function(n){return r.accounts[r.payer]=u({},r.accounts[r.payer],{signature:n.signature}),e.Ok(r)})})}catch(e){return Promise.reject(e)}},exports.script=function(){return e.pipe([e.makeScript,e.put("ix.cadence",t.t7l.apply(void 0,arguments))])},exports.transaction=function(){return e.pipe([e.makeTransaction,e.put("ix.cadence",t.t7l.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||c,e.Ok(r)}])}; | ||
//# sourceMappingURL=sdk.js.map |
@@ -1,2 +0,2 @@ | ||
import{pipe as r,interaction as n,put as e,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as a,makeGetTransactionStatus as i,makePing as c,makeScript as s,makeTransaction as f,update as p,isTransaction as d,get as l,isScript as y}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{t7l as m}from"@qvvg/templar";import{encodeTransactionPayload as v,encodeTransactionEnvelope as h}from"@onflow/encode";function k(e){return void 0===e&&(e=[]),r(n(),e)}var x=r;function g(n){return void 0===n&&(n=[]),r([e("tx.authorizations",n)])}function I(r,n,e){return{acct:r,signFn:n,keyId:e}}function P(n){return r([t,function(r){return r.acct=n,o(r)}])}function z(n,e,t){return r([u,function(r){return r.eventType=n,o(r)},function(r){return r.bounds.start=e,o(r)},function(r){return r.bounds.end=t,o(r)}])}function w(n){return void 0===n&&(n=!1),r([a,function(r){return r.isSealed=n,o(r)}])}function j(n){return r([i,function(r){return r.txId=n,o(r)}])}function q(n){return r([function(r){return r.payload.limit=n,o(r)}])}function b(){return(b=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r}).apply(this,arguments)}function N(n){return void 0===n&&(n=[]),r([e("ix.params",(t=n,void 0===t&&(t=[]),t.filter(function(r){return null!=r.key}).reduce(function(r,n){var e;return b({},r,((e={})[n.key]=n.value,e))},{})))]);var t}var O={asParam:function(r){return r},asInjection:function(r){return r}};function B(r,n,e){return void 0===n&&(n=O),void 0===e&&(e=null),{key:e,value:r,xform:n}}var F=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];try{var u=function(){"object"==typeof e[0]&&(a=e[0]);var n=e[0],t=e[1],u=e[2];return r([function(r){return r.proposer=a||K(n,t,u),o(r)}])},a=null,i=function(){if("function"==typeof e[0])return Promise.resolve(e[0]()).then(function(r){a=r})}();return Promise.resolve(i&&i.then?i.then(u):u(i))}catch(r){return Promise.reject(r)}};function K(r,n,e){return{addr:r,keyId:n,sequenceNum:e}}function L(n){return r([e("tx.payer",n)])}function S(){return r([c])}function A(n){return r([function(r){return r.payload.ref=n,o(r)}])}function D(){return r([s,e("ix.code",m.apply(void 0,arguments))])}var R=[];function T(){return Date.now()}function C(r){return function(n){return null==n?r:n}}function E(){return r([f,e("ix.code",m.apply(void 0,arguments)),function(r){return r.payload.limit=r.payload.limit||10,r.payload.nonce=r.payload.nonce||T(),r.payload.ref=r.payload.ref||null,o(r)},p("tx.authorizations",C(R))])}var G=function(r){try{if(!d(r))return Promise.resolve(o(r));var n=v({script:r.payload.code,refBlock:r.payload.ref||null,gasLimit:r.payload.limit,proposalKey:{address:r.proposer.addr,keyId:r.proposer.keyId,sequenceNum:r.proposer.sequenceNum},payer:l(r,"tx.payer").acct,authorizers:l(r,"tx.authorizations").map(function(r){return r.acct})}),e=l(r,"tx.authorizations",[]).map(function(e){try{var t=function(){return e.acct===l(r,"tx.payer").acct?H(e.acct,null,e.keyId):Promise.resolve(e.signFn({message:n,addr:e.acct,keyId:e.keyId,roles:{proposer:r.proposer.addr===e.acct,authorizer:!0,payer:l(r,"tx.payer").acct===e.acct},interaction:r})).then(function(r){return H(e.acct,r.signature,e.keyId)})},o=function(){if("function"==typeof e)return Promise.resolve(e()).then(function(r){e=r})}();return Promise.resolve(o&&o.then?o.then(t):t())}catch(r){return Promise.reject(r)}});return Promise.resolve(Promise.all(e)).then(function(n){r.authz=n;var e=h({script:r.payload.code,refBlock:r.payload.ref,gasLimit:r.payload.limit,proposalKey:{address:r.proposer.addr,keyId:r.proposer.keyId,sequenceNum:r.proposer.sequenceNum},payer:l(r,"tx.payer").acct,authorizers:l(r,"tx.authorizations").map(function(r){return r.acct}),payloadSigs:r.authz.map(function(r){return null===r.signature?null:{address:r.acct,keyId:r.keyId,sig:r.signature}}).filter(function(r){return null!==r})}),t=l(r,"tx.payer");return Promise.resolve(t.signFn({message:e,addr:t.acct,keyId:t.keyId,roles:{proposer:r.proposer.addr===t.acct,authorizer:!1,payer:!0},interaction:r})).then(function(n){return r.payer=H(t.acct,n.signature,t.keyId),o(r)})})}catch(r){return Promise.reject(r)}};function H(r,n,e){return{acct:r,signature:n,keyId:e}}var J=r([function(r){if(!d(r)&&!y(r))return o(r);var n=l(r,"ix.code");return r.payload.code="function"==typeof n?n(l(r,"ix.params",{})):n,o(r)}]);export{I as authorization,g as authorizations,k as build,P as getAccount,z as getEvents,w as getLatestBlock,j as getTransactionStatus,q as limit,B as param,N as params,L as payer,S as ping,F as proposer,A as ref,x as resolve,G as resolveAuthorizations,J as resolveParams,D as script,E as transaction}; | ||
import{pipe as e,interaction as n,makeAuthorizer as r,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as i,makeGetTransactionStatus as a,makeParam as c,makeProposer as s,makePayer as f,makePing as d,makeScript as l,put as p,makeTransaction as m,isTransaction as y,isScript as v,get as h}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{t7l as g}from"@qvvg/templar";import{encodeTransactionPayload as I,encodeTransactionEnvelope as k}from"@onflow/encode";function b(r){return void 0===r&&(r=[]),e(n(),r)}var w=e;function P(){return(P=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function j(n){return void 0===n&&(n=[]),e(n.map(function(e){return r(P({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))}function z(e,n,r){return{addr:e,signingFunction:n,keyId:r}}function N(n){return e([t,function(e){return e.accountAddr=n,o(e)}])}function S(n,r,t){return e([u,function(e){return e.events.eventType=n,o(e)},function(e){return e.events.start=r,o(e)},function(e){return e.events.end=t,o(e)}])}function q(n){return void 0===n&&(n=!1),e([i,function(e){return e.latestBlock.isSealed=n,o(e)}])}function x(n){return e([a,function(e){return e.transactionId=n,o(e)}])}function B(n){return e([function(e){return e.message.computeLimit=n,o(e)}])}function O(n){return void 0===n&&(n=[]),e(n.map(c))}var F={asParam:function(e){return e},asInjection:function(e){return e}};function A(e,n,r){return void 0===n&&(n=F),void 0===r&&(r=null),{key:r,value:e,xform:n}}var L=function(){try{for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(E(n[0]))return Promise.resolve(s({resolve:n[0],role:{proposer:!0}}));var t=n[0],o=n[1],u=n[2];return Promise.resolve(s({addr:t,keyId:o,sequenceNum:u,role:{proposer:!0}}))}catch(e){return Promise.reject(e)}},E=function(e){return"function"==typeof e};function T(e){return f(P({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))}function K(){return e([d])}function R(n){return e([function(e){return e.message.refBlock=n,o(e)}])}function V(){return e([l,p("ix.cadence",g.apply(void 0,arguments))])}var C=[];function D(){return e([m,p("ix.cadence",g.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||C,o(e)}])}const G=function(){function e(){}return e.prototype.then=function(n,r){const t=new e,o=this.s;if(o){const e=1&o?n:r;if(e){try{H(t,1,e(this.v))}catch(e){H(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?H(t,1,n?n(o):o):r?H(t,1,r(o)):H(t,2,o)}catch(e){H(t,2,e)}},t},e}();function H(e,n,r){if(!e.s){if(r instanceof G){if(!r.s)return void(r.o=H.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(H.bind(null,e,n),H.bind(null,e,2));e.s=n,e.v=r;const t=e.o;t&&t(e)}}function J(e){return e instanceof G&&1&e.s}const M="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var Q=function(e){return"function"==typeof e},U=function(e){return"number"==typeof e},W=function(e){return"string"==typeof e},X=function(e,n){if(!e){var r,t=new Error("INVARIANT "+n);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).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(r=console).error.apply(r,["\n\n---\n\n",t,"\n\n"].concat(u,["\n\n---\n\n"])),t}},Y=function(e){return!(e.role.proposer&&!(W(e.addr)&&U(e.keyId)&&U(e.sequenceNum)&&Q(e.signingFunction))||e.role.payer&&!(W(e.addr)&&U(e.keyId)&&Q(e.signingFunction))||e.role.authorizer&&!(W(e.addr)&&U(e.keyId)&&Q(e.signingFunction)))},Z=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},$=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},_=e([function(e){try{var n=function(){return o(e)};if(!y(e))return Promise.resolve(o(e));var r=function(e,n,r){if("function"==typeof e[M]){var t,o,u,i=e[M]();if(function e(r){try{for(;!(t=i.next()).done;)if((r=n(t.value))&&r.then){if(!J(r))return void r.then(e,u||(u=H.bind(null,o=new G,2)));r=r.v}o?H(o,1,r):o=r}catch(e){H(o||(o=new G),2,e)}}(),i.return){var a=function(e){try{t.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,n,r){var t,o,u=-1;return function r(i){try{for(;++u<e.length;)if((i=n(u))&&i.then){if(!J(i))return void i.then(r,o||(o=H.bind(null,t=new G,2)));i=i.v}t?H(t,1,i):t=i}catch(e){H(t||(t=new G),2,e)}}(),t}(c,function(e){return n(c[e])})}(Object.entries(e.accounts),function(e){var n=e[1];function r(){X(Y(n),"Account unable to fulfill role",n)}var t=function(){if(Q(n.resolve))return Promise.resolve(n.resolve(n)).then(function(e){n=e})}();return t&&t.then?t.then(r):r()});return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},function(e){try{if(!y(e))return Promise.resolve(o(e));for(var n=function(){var n,o,u,i=t[r],a=i.addr+"|"+i.keyId;e.accounts[a]=null!=e.accounts[a]?(n=e.accounts[a],o=P({tempId:a},i),{kind:Z([n.kind,o.kind]),tempId:Z([n.tempId,o.tempId]),addr:Z([n.addr,o.addr]),keyId:(u=[n.keyId,o.keyId],void 0===u&&(u=[]),"number"==typeof u.filter(U)[0]?u.filter(U)[0]:null),sequenceNum:"number"==typeof $([n,o]).sequenceNum?$([n,o]).sequenceNum:n.sequenceNum,signature:Z([n.signature,o.signature]),signingFunction:Z([n.signingFunction,o.signingFunction]),resolve:Z([n.resolve,o.resolve]),role:{proposer:n.role.proposer||o.role.proposer,authorizer:n.role.authorizer||o.role.authorizer,payer:n.role.payer||o.role.payer,param:n.role.param||o.role.param}}):P({tempId:a},i),e.proposer===i.tempId&&(e.proposer=a),e.payer===i.tempId&&(e.payer=a),e.authorizations=e.authorizations.map(function(e){return e===i.tempId?a:e}),delete e.accounts[i.tempId]},r=0,t=Object.values(e.accounts);r<t.length;r++)n();for(var u=0,i=Object.values(e.accounts);u<i.length;u++){var a=i[u];X(Y(a),"Account unable to fulfill roles",a)}return Promise.resolve(o(e))}catch(e){return Promise.reject(e)}}]),ee=function(e){if(!y(e)&&!v(e))return o(e);var n=h(e,"ix.cadence");if("string"==typeof n)return e.message.cadence=n,o(e);if("function"==typeof n){var r=Object.fromEntries(Object.values(e.params).filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]}));return e.message.cadence=n(r),o(e)}throw new Error("Invalid Cadence Value")},ne=function(e){try{if(!y(e))return Promise.resolve(o(e));var n=e.authorizations.map(function(n){return e.accounts[n]}),r=e.accounts[e.payer],t=e.accounts[e.proposer],u=I({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:t.addr,keyId:t.keyId,sequenceNum:t.sequenceNum},payer:r.addr,authorizers:n.map(function(e){return e.addr})}),i=n.map(function(n){try{return n.addr===r.addr?(e.accounts[n.tempId]=P({},e.accounts[n.tempId],{signature:null}),Promise.resolve()):Promise.resolve(n.signingFunction({message:u,addr:n.addr,keyId:n.keyId,roles:{proposer:t.addr===n.addr,authorizer:!0,payer:r.addr===n.addr},interaction:e})).then(function(r){e.accounts[n.tempId]=P({},e.accounts[n.tempId],{signature:r.signature})})}catch(e){return Promise.reject(e)}});return Promise.resolve(Promise.all(i)).then(function(){n=e.authorizations.map(function(n){return e.accounts[n]});var u=k({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:t.addr,keyId:t.keyId,sequenceNum:t.sequenceNum},payer:r.addr,authorizers:n.map(function(e){return e.addr}),payloadSigs:n.map(function(e){return null===e.signature?null:{address:e.addr,keyId:e.keyId,sig:e.signature}}).filter(function(e){return null!==e})});return Promise.resolve(r.signingFunction({message:u,addr:r.addr,keyId:r.keyId,roles:{proposer:t.addr===r.addr,authorizer:!1,payer:!0},interaction:e})).then(function(n){return e.accounts[e.payer]=P({},e.accounts[e.payer],{signature:n.signature}),o(e)})})}catch(e){return Promise.reject(e)}};export{z as authorization,j as authorizations,b as build,N as getAccount,S as getEvents,q as getLatestBlock,x as getTransactionStatus,B as limit,A as param,O as params,T as payer,K as ping,L as proposer,R as ref,w as resolve,_ as resolveAccounts,ee as resolveParams,ne as resolveSignatures,V as script,D as transaction}; | ||
//# sourceMappingURL=sdk.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{pipe as r,interaction as n,put as e,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as a,makeGetTransactionStatus as i,makePing as c,makeScript as s,makeTransaction as f,update as p,isTransaction as d,get as l,isScript as y}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{t7l as m}from"@qvvg/templar";import{encodeTransactionPayload as v,encodeTransactionEnvelope as h}from"@onflow/encode";function k(e){return void 0===e&&(e=[]),r(n(),e)}var x=r;function g(n){return void 0===n&&(n=[]),r([e("tx.authorizations",n)])}function I(r,n,e){return{acct:r,signFn:n,keyId:e}}function P(n){return r([t,function(r){return r.acct=n,o(r)}])}function z(n,e,t){return r([u,function(r){return r.eventType=n,o(r)},function(r){return r.bounds.start=e,o(r)},function(r){return r.bounds.end=t,o(r)}])}function w(n){return void 0===n&&(n=!1),r([a,function(r){return r.isSealed=n,o(r)}])}function j(n){return r([i,function(r){return r.txId=n,o(r)}])}function q(n){return r([function(r){return r.payload.limit=n,o(r)}])}function b(){return(b=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r}).apply(this,arguments)}function N(n){return void 0===n&&(n=[]),r([e("ix.params",(t=n,void 0===t&&(t=[]),t.filter(function(r){return null!=r.key}).reduce(function(r,n){var e;return b({},r,((e={})[n.key]=n.value,e))},{})))]);var t}var O={asParam:function(r){return r},asInjection:function(r){return r}};function B(r,n,e){return void 0===n&&(n=O),void 0===e&&(e=null),{key:e,value:r,xform:n}}var F=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];try{var u=function(){"object"==typeof e[0]&&(a=e[0]);var n=e[0],t=e[1],u=e[2];return r([function(r){return r.proposer=a||K(n,t,u),o(r)}])},a=null,i=function(){if("function"==typeof e[0])return Promise.resolve(e[0]()).then(function(r){a=r})}();return Promise.resolve(i&&i.then?i.then(u):u(i))}catch(r){return Promise.reject(r)}};function K(r,n,e){return{addr:r,keyId:n,sequenceNum:e}}function L(n){return r([e("tx.payer",n)])}function S(){return r([c])}function A(n){return r([function(r){return r.payload.ref=n,o(r)}])}function D(){return r([s,e("ix.code",m.apply(void 0,arguments))])}var R=[];function T(){return Date.now()}function C(r){return function(n){return null==n?r:n}}function E(){return r([f,e("ix.code",m.apply(void 0,arguments)),function(r){return r.payload.limit=r.payload.limit||10,r.payload.nonce=r.payload.nonce||T(),r.payload.ref=r.payload.ref||null,o(r)},p("tx.authorizations",C(R))])}var G=function(r){try{if(!d(r))return Promise.resolve(o(r));var n=v({script:r.payload.code,refBlock:r.payload.ref||null,gasLimit:r.payload.limit,proposalKey:{address:r.proposer.addr,keyId:r.proposer.keyId,sequenceNum:r.proposer.sequenceNum},payer:l(r,"tx.payer").acct,authorizers:l(r,"tx.authorizations").map(function(r){return r.acct})}),e=l(r,"tx.authorizations",[]).map(function(e){try{var t=function(){return e.acct===l(r,"tx.payer").acct?H(e.acct,null,e.keyId):Promise.resolve(e.signFn({message:n,addr:e.acct,keyId:e.keyId,roles:{proposer:r.proposer.addr===e.acct,authorizer:!0,payer:l(r,"tx.payer").acct===e.acct},interaction:r})).then(function(r){return H(e.acct,r.signature,e.keyId)})},o=function(){if("function"==typeof e)return Promise.resolve(e()).then(function(r){e=r})}();return Promise.resolve(o&&o.then?o.then(t):t())}catch(r){return Promise.reject(r)}});return Promise.resolve(Promise.all(e)).then(function(n){r.authz=n;var e=h({script:r.payload.code,refBlock:r.payload.ref,gasLimit:r.payload.limit,proposalKey:{address:r.proposer.addr,keyId:r.proposer.keyId,sequenceNum:r.proposer.sequenceNum},payer:l(r,"tx.payer").acct,authorizers:l(r,"tx.authorizations").map(function(r){return r.acct}),payloadSigs:r.authz.map(function(r){return null===r.signature?null:{address:r.acct,keyId:r.keyId,sig:r.signature}}).filter(function(r){return null!==r})}),t=l(r,"tx.payer");return Promise.resolve(t.signFn({message:e,addr:t.acct,keyId:t.keyId,roles:{proposer:r.proposer.addr===t.acct,authorizer:!1,payer:!0},interaction:r})).then(function(n){return r.payer=H(t.acct,n.signature,t.keyId),o(r)})})}catch(r){return Promise.reject(r)}};function H(r,n,e){return{acct:r,signature:n,keyId:e}}var J=r([function(r){if(!d(r)&&!y(r))return o(r);var n=l(r,"ix.code");return r.payload.code="function"==typeof n?n(l(r,"ix.params",{})):n,o(r)}]);export{I as authorization,g as authorizations,k as build,P as getAccount,z as getEvents,w as getLatestBlock,j as getTransactionStatus,q as limit,B as param,N as params,L as payer,S as ping,F as proposer,A as ref,x as resolve,G as resolveAuthorizations,J as resolveParams,D as script,E as transaction}; | ||
import{pipe as e,interaction as n,makeAuthorizer as r,makeGetAccount as t,Ok as o,makeGetEvents as u,makeGetLatestBlock as i,makeGetTransactionStatus as a,makeParam as c,makeProposer as s,makePayer as f,makePing as d,makeScript as l,put as p,makeTransaction as m,isTransaction as y,isScript as v,get as h}from"@onflow/interaction";export{isBad,isOk,pipe,why}from"@onflow/interaction";export{send}from"@onflow/send";export{decode,decodeResponse}from"@onflow/decode";import{t7l as g}from"@qvvg/templar";import{encodeTransactionPayload as I,encodeTransactionEnvelope as k}from"@onflow/encode";function b(r){return void 0===r&&(r=[]),e(n(),r)}var w=e;function P(){return(P=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}function j(n){return void 0===n&&(n=[]),e(n.map(function(e){return r(P({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))}function z(e,n,r){return{addr:e,signingFunction:n,keyId:r}}function N(n){return e([t,function(e){return e.accountAddr=n,o(e)}])}function S(n,r,t){return e([u,function(e){return e.events.eventType=n,o(e)},function(e){return e.events.start=r,o(e)},function(e){return e.events.end=t,o(e)}])}function q(n){return void 0===n&&(n=!1),e([i,function(e){return e.latestBlock.isSealed=n,o(e)}])}function x(n){return e([a,function(e){return e.transactionId=n,o(e)}])}function B(n){return e([function(e){return e.message.computeLimit=n,o(e)}])}function O(n){return void 0===n&&(n=[]),e(n.map(c))}var F={asParam:function(e){return e},asInjection:function(e){return e}};function A(e,n,r){return void 0===n&&(n=F),void 0===r&&(r=null),{key:r,value:e,xform:n}}var L=function(){try{for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(E(n[0]))return Promise.resolve(s({resolve:n[0],role:{proposer:!0}}));var t=n[0],o=n[1],u=n[2];return Promise.resolve(s({addr:t,keyId:o,sequenceNum:u,role:{proposer:!0}}))}catch(e){return Promise.reject(e)}},E=function(e){return"function"==typeof e};function T(e){return f(P({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))}function K(){return e([d])}function R(n){return e([function(e){return e.message.refBlock=n,o(e)}])}function V(){return e([l,p("ix.cadence",g.apply(void 0,arguments))])}var C=[];function D(){return e([m,p("ix.cadence",g.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||C,o(e)}])}const G=function(){function e(){}return e.prototype.then=function(n,r){const t=new e,o=this.s;if(o){const e=1&o?n:r;if(e){try{H(t,1,e(this.v))}catch(e){H(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?H(t,1,n?n(o):o):r?H(t,1,r(o)):H(t,2,o)}catch(e){H(t,2,e)}},t},e}();function H(e,n,r){if(!e.s){if(r instanceof G){if(!r.s)return void(r.o=H.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(H.bind(null,e,n),H.bind(null,e,2));e.s=n,e.v=r;const t=e.o;t&&t(e)}}function J(e){return e instanceof G&&1&e.s}const M="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var Q=function(e){return"function"==typeof e},U=function(e){return"number"==typeof e},W=function(e){return"string"==typeof e},X=function(e,n){if(!e){var r,t=new Error("INVARIANT "+n);t.stack=t.stack.split("\n").filter(function(e){return!/at invariant/.test(e)}).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(r=console).error.apply(r,["\n\n---\n\n",t,"\n\n"].concat(u,["\n\n---\n\n"])),t}},Y=function(e){return!(e.role.proposer&&!(W(e.addr)&&U(e.keyId)&&U(e.sequenceNum)&&Q(e.signingFunction))||e.role.payer&&!(W(e.addr)&&U(e.keyId)&&Q(e.signingFunction))||e.role.authorizer&&!(W(e.addr)&&U(e.keyId)&&Q(e.signingFunction)))},Z=function(e){return void 0===e&&(e=[]),e.filter(Boolean)[0]||null},$=function(e){return void 0===e&&(e=[]),e.find(function(e){return e.role.proposer})||{}},_=e([function(e){try{var n=function(){return o(e)};if(!y(e))return Promise.resolve(o(e));var r=function(e,n,r){if("function"==typeof e[M]){var t,o,u,i=e[M]();if(function e(r){try{for(;!(t=i.next()).done;)if((r=n(t.value))&&r.then){if(!J(r))return void r.then(e,u||(u=H.bind(null,o=new G,2)));r=r.v}o?H(o,1,r):o=r}catch(e){H(o||(o=new G),2,e)}}(),i.return){var a=function(e){try{t.done||i.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,n,r){var t,o,u=-1;return function r(i){try{for(;++u<e.length;)if((i=n(u))&&i.then){if(!J(i))return void i.then(r,o||(o=H.bind(null,t=new G,2)));i=i.v}t?H(t,1,i):t=i}catch(e){H(t||(t=new G),2,e)}}(),t}(c,function(e){return n(c[e])})}(Object.entries(e.accounts),function(e){var n=e[1];function r(){X(Y(n),"Account unable to fulfill role",n)}var t=function(){if(Q(n.resolve))return Promise.resolve(n.resolve(n)).then(function(e){n=e})}();return t&&t.then?t.then(r):r()});return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},function(e){try{if(!y(e))return Promise.resolve(o(e));for(var n=function(){var n,o,u,i=t[r],a=i.addr+"|"+i.keyId;e.accounts[a]=null!=e.accounts[a]?(n=e.accounts[a],o=P({tempId:a},i),{kind:Z([n.kind,o.kind]),tempId:Z([n.tempId,o.tempId]),addr:Z([n.addr,o.addr]),keyId:(u=[n.keyId,o.keyId],void 0===u&&(u=[]),"number"==typeof u.filter(U)[0]?u.filter(U)[0]:null),sequenceNum:"number"==typeof $([n,o]).sequenceNum?$([n,o]).sequenceNum:n.sequenceNum,signature:Z([n.signature,o.signature]),signingFunction:Z([n.signingFunction,o.signingFunction]),resolve:Z([n.resolve,o.resolve]),role:{proposer:n.role.proposer||o.role.proposer,authorizer:n.role.authorizer||o.role.authorizer,payer:n.role.payer||o.role.payer,param:n.role.param||o.role.param}}):P({tempId:a},i),e.proposer===i.tempId&&(e.proposer=a),e.payer===i.tempId&&(e.payer=a),e.authorizations=e.authorizations.map(function(e){return e===i.tempId?a:e}),delete e.accounts[i.tempId]},r=0,t=Object.values(e.accounts);r<t.length;r++)n();for(var u=0,i=Object.values(e.accounts);u<i.length;u++){var a=i[u];X(Y(a),"Account unable to fulfill roles",a)}return Promise.resolve(o(e))}catch(e){return Promise.reject(e)}}]),ee=function(e){if(!y(e)&&!v(e))return o(e);var n=h(e,"ix.cadence");if("string"==typeof n)return e.message.cadence=n,o(e);if("function"==typeof n){var r=Object.fromEntries(Object.values(e.params).filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]}));return e.message.cadence=n(r),o(e)}throw new Error("Invalid Cadence Value")},ne=function(e){try{if(!y(e))return Promise.resolve(o(e));var n=e.authorizations.map(function(n){return e.accounts[n]}),r=e.accounts[e.payer],t=e.accounts[e.proposer],u=I({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:t.addr,keyId:t.keyId,sequenceNum:t.sequenceNum},payer:r.addr,authorizers:n.map(function(e){return e.addr})}),i=n.map(function(n){try{return n.addr===r.addr?(e.accounts[n.tempId]=P({},e.accounts[n.tempId],{signature:null}),Promise.resolve()):Promise.resolve(n.signingFunction({message:u,addr:n.addr,keyId:n.keyId,roles:{proposer:t.addr===n.addr,authorizer:!0,payer:r.addr===n.addr},interaction:e})).then(function(r){e.accounts[n.tempId]=P({},e.accounts[n.tempId],{signature:r.signature})})}catch(e){return Promise.reject(e)}});return Promise.resolve(Promise.all(i)).then(function(){n=e.authorizations.map(function(n){return e.accounts[n]});var u=k({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:t.addr,keyId:t.keyId,sequenceNum:t.sequenceNum},payer:r.addr,authorizers:n.map(function(e){return e.addr}),payloadSigs:n.map(function(e){return null===e.signature?null:{address:e.addr,keyId:e.keyId,sig:e.signature}}).filter(function(e){return null!==e})});return Promise.resolve(r.signingFunction({message:u,addr:r.addr,keyId:r.keyId,roles:{proposer:t.addr===r.addr,authorizer:!1,payer:!0},interaction:e})).then(function(n){return e.accounts[e.payer]=P({},e.accounts[e.payer],{signature:n.signature}),o(e)})})}catch(e){return Promise.reject(e)}};export{z as authorization,j as authorizations,b as build,N as getAccount,S as getEvents,q as getLatestBlock,x as getTransactionStatus,B as limit,A as param,O as params,T as payer,K as ping,L as proposer,R as ref,w as resolve,_ as resolveAccounts,ee as resolveParams,ne as resolveSignatures,V as script,D as transaction}; | ||
//# sourceMappingURL=sdk.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(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"],n):n((e=e||self).sdk={},e.interaction,e.send,e.decode,e.templar,e.encode)}(this,function(e,n,t,r,o,i){var a=n.pipe;function u(){return(u=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}var c={asParam:function(e){return e},asInjection:function(e){return e}};function p(e,n,t){return{addr:e,keyId:n,sequenceNum:t}}var s=[];function d(){return Date.now()}function f(e){return function(n){return null==n?e:n}}function l(e,n,t){return{acct:e,signature:n,keyId:t}}var y=n.pipe([function(e){if(!n.isTransaction(e)&&!n.isScript(e))return n.Ok(e);var t=n.get(e,"ix.code");return e.payload.code="function"==typeof t?t(n.get(e,"ix.params",{})):t,n.Ok(e)}]);Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return t.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return r.decode}}),Object.defineProperty(e,"decodeResponse",{enumerable:!0,get:function(){return r.decodeResponse}}),e.authorization=function(e,n,t){return{acct:e,signFn:n,keyId:t}},e.authorizations=function(e){return void 0===e&&(e=[]),n.pipe([n.put("tx.authorizations",e)])},e.build=function(e){return void 0===e&&(e=[]),n.pipe(n.interaction(),e)},e.getAccount=function(e){return n.pipe([n.makeGetAccount,function(t){return t.acct=e,n.Ok(t)}])},e.getEvents=function(e,t,r){return n.pipe([n.makeGetEvents,function(t){return t.eventType=e,n.Ok(t)},function(e){return e.bounds.start=t,n.Ok(e)},function(e){return e.bounds.end=r,n.Ok(e)}])},e.getLatestBlock=function(e){return void 0===e&&(e=!1),n.pipe([n.makeGetLatestBlock,function(t){return t.isSealed=e,n.Ok(t)}])},e.getTransactionStatus=function(e){return n.pipe([n.makeGetTransactionStatus,function(t){return t.txId=e,n.Ok(t)}])},e.limit=function(e){return n.pipe([function(t){return t.payload.limit=e,n.Ok(t)}])},e.param=function(e,n,t){return void 0===n&&(n=c),void 0===t&&(t=null),{key:t,value:e,xform:n}},e.params=function(e){return void 0===e&&(e=[]),n.pipe([n.put("ix.params",(t=e,void 0===t&&(t=[]),t.filter(function(e){return null!=e.key}).reduce(function(e,n){var t;return u({},e,((t={})[n.key]=n.value,t))},{})))]);var t},e.payer=function(e){return n.pipe([n.put("tx.payer",e)])},e.ping=function(){return n.pipe([n.makePing])},e.proposer=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];try{var o=function(){"object"==typeof t[0]&&(i=t[0]);var e=t[0],r=t[1],o=t[2];return n.pipe([function(t){return t.proposer=i||p(e,r,o),n.Ok(t)}])},i=null,a=function(){if("function"==typeof t[0])return Promise.resolve(t[0]()).then(function(e){i=e})}();return Promise.resolve(a&&a.then?a.then(o):o(a))}catch(e){return Promise.reject(e)}},e.ref=function(e){return n.pipe([function(t){return t.payload.ref=e,n.Ok(t)}])},e.resolve=a,e.resolveAuthorizations=function(e){try{if(!n.isTransaction(e))return Promise.resolve(n.Ok(e));var t=i.encodeTransactionPayload({script:e.payload.code,refBlock:e.payload.ref||null,gasLimit:e.payload.limit,proposalKey:{address:e.proposer.addr,keyId:e.proposer.keyId,sequenceNum:e.proposer.sequenceNum},payer:n.get(e,"tx.payer").acct,authorizers:n.get(e,"tx.authorizations").map(function(e){return e.acct})}),r=n.get(e,"tx.authorizations",[]).map(function(r){try{var o=function(){return r.acct===n.get(e,"tx.payer").acct?l(r.acct,null,r.keyId):Promise.resolve(r.signFn({message:t,addr:r.acct,keyId:r.keyId,roles:{proposer:e.proposer.addr===r.acct,authorizer:!0,payer:n.get(e,"tx.payer").acct===r.acct},interaction:e})).then(function(e){return l(r.acct,e.signature,r.keyId)})},i=function(){if("function"==typeof r)return Promise.resolve(r()).then(function(e){r=e})}();return Promise.resolve(i&&i.then?i.then(o):o())}catch(e){return Promise.reject(e)}});return Promise.resolve(Promise.all(r)).then(function(t){e.authz=t;var r=i.encodeTransactionEnvelope({script:e.payload.code,refBlock:e.payload.ref,gasLimit:e.payload.limit,proposalKey:{address:e.proposer.addr,keyId:e.proposer.keyId,sequenceNum:e.proposer.sequenceNum},payer:n.get(e,"tx.payer").acct,authorizers:n.get(e,"tx.authorizations").map(function(e){return e.acct}),payloadSigs:e.authz.map(function(e){return null===e.signature?null:{address:e.acct,keyId:e.keyId,sig:e.signature}}).filter(function(e){return null!==e})}),o=n.get(e,"tx.payer");return Promise.resolve(o.signFn({message:r,addr:o.acct,keyId:o.keyId,roles:{proposer:e.proposer.addr===o.acct,authorizer:!1,payer:!0},interaction:e})).then(function(t){return e.payer=l(o.acct,t.signature,o.keyId),n.Ok(e)})})}catch(e){return Promise.reject(e)}},e.resolveParams=y,e.script=function(){return n.pipe([n.makeScript,n.put("ix.code",o.t7l.apply(void 0,arguments))])},e.transaction=function(){return n.pipe([n.makeTransaction,n.put("ix.code",o.t7l.apply(void 0,arguments)),function(e){return e.payload.limit=e.payload.limit||10,e.payload.nonce=e.payload.nonce||d(),e.payload.ref=e.payload.ref||null,n.Ok(e)},n.update("tx.authorizations",f(s))])}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(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"],n):n((e=e||self).sdk={},e.interaction,e.send,e.decode,e.templar,e.encode)}(this,function(e,n,r,t,o,i){var u=n.pipe;function a(){return(a=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}var c={asParam:function(e){return e},asInjection:function(e){return e}},s=function(e){return"function"==typeof e},f=[];const d=function(){function e(){}return e.prototype.then=function(n,r){const t=new e,o=this.s;if(o){const e=1&o?n:r;if(e){try{l(t,1,e(this.v))}catch(e){l(t,2,e)}return t}return this}return this.o=function(e){try{const o=e.v;1&e.s?l(t,1,n?n(o):o):r?l(t,1,r(o)):l(t,2,o)}catch(e){l(t,2,e)}},t},e}();function l(e,n,r){if(!e.s){if(r instanceof d){if(!r.s)return void(r.o=l.bind(null,e,n));1&n&&(n=r.s),r=r.v}if(r&&r.then)return void r.then(l.bind(null,e,n),l.bind(null,e,2));e.s=n,e.v=r;const t=e.o;t&&t(e)}}function p(e){return e instanceof d&&1&e.s}const m="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var y=function(e){return"function"==typeof e},v=function(e){return"number"==typeof e},g=function(e){return"string"==typeof e},k=function(e,n){if(!e){var r,t=new Error("INVARIANT "+n);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(r=console).error.apply(r,["\n\n---\n\n",t,"\n\n"].concat(i,["\n\n---\n\n"])),t}},h=function(e){return!(e.role.proposer&&!(g(e.addr)&&v(e.keyId)&&v(e.sequenceNum)&&y(e.signingFunction))||e.role.payer&&!(g(e.addr)&&v(e.keyId)&&y(e.signingFunction))||e.role.authorizer&&!(g(e.addr)&&v(e.keyId)&&y(e.signingFunction)))},b=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})||{}},O=n.pipe([function(e){try{var r=function(){return n.Ok(e)};if(!n.isTransaction(e))return Promise.resolve(n.Ok(e));var t=function(e,n,r){if("function"==typeof e[m]){var t,o,i,u=e[m]();if(function e(r){try{for(;!(t=u.next()).done;)if((r=n(t.value))&&r.then){if(!p(r))return void r.then(e,i||(i=l.bind(null,o=new d,2)));r=r.v}o?l(o,1,r):o=r}catch(e){l(o||(o=new d),2,e)}}(),u.return){var a=function(e){try{t.done||u.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var c=[],s=0;s<e.length;s++)c.push(e[s]);return function(e,n,r){var t,o,i=-1;return function r(u){try{for(;++i<e.length;)if((u=n(i))&&u.then){if(!p(u))return void u.then(r,o||(o=l.bind(null,t=new d,2)));u=u.v}t?l(t,1,u):t=u}catch(e){l(t||(t=new d),2,e)}}(),t}(c,function(e){return n(c[e])})}(Object.entries(e.accounts),function(e){var n=e[1];function r(){k(h(n),"Account unable to fulfill role",n)}var t=function(){if(y(n.resolve))return Promise.resolve(n.resolve(n)).then(function(e){n=e})}();return t&&t.then?t.then(r):r()});return Promise.resolve(t&&t.then?t.then(r):r())}catch(e){return Promise.reject(e)}},function(e){try{if(!n.isTransaction(e))return Promise.resolve(n.Ok(e));for(var r=function(){var n,r,i,u=o[t],c=u.addr+"|"+u.keyId;e.accounts[c]=null!=e.accounts[c]?(n=e.accounts[c],r=a({tempId:c},u),{kind:b([n.kind,r.kind]),tempId:b([n.tempId,r.tempId]),addr:b([n.addr,r.addr]),keyId:(i=[n.keyId,r.keyId],void 0===i&&(i=[]),"number"==typeof i.filter(v)[0]?i.filter(v)[0]:null),sequenceNum:"number"==typeof I([n,r]).sequenceNum?I([n,r]).sequenceNum:n.sequenceNum,signature:b([n.signature,r.signature]),signingFunction:b([n.signingFunction,r.signingFunction]),resolve:b([n.resolve,r.resolve]),role:{proposer:n.role.proposer||r.role.proposer,authorizer:n.role.authorizer||r.role.authorizer,payer:n.role.payer||r.role.payer,param:n.role.param||r.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++)r();for(var i=0,u=Object.values(e.accounts);i<u.length;i++){var c=u[i];k(h(c),"Account unable to fulfill roles",c)}return Promise.resolve(n.Ok(e))}catch(e){return Promise.reject(e)}}]);Object.defineProperty(e,"isBad",{enumerable:!0,get:function(){return n.isBad}}),Object.defineProperty(e,"isOk",{enumerable:!0,get:function(){return n.isOk}}),Object.defineProperty(e,"pipe",{enumerable:!0,get:function(){return n.pipe}}),Object.defineProperty(e,"why",{enumerable:!0,get:function(){return n.why}}),Object.defineProperty(e,"send",{enumerable:!0,get:function(){return r.send}}),Object.defineProperty(e,"decode",{enumerable:!0,get:function(){return t.decode}}),Object.defineProperty(e,"decodeResponse",{enumerable:!0,get:function(){return t.decodeResponse}}),e.authorization=function(e,n,r){return{addr:e,signingFunction:n,keyId:r}},e.authorizations=function(e){return void 0===e&&(e=[]),n.pipe(e.map(function(e){return n.makeAuthorizer(a({},"function"==typeof e?{resolve:e}:e,{role:{authorizer:!0}}))}))},e.build=function(e){return void 0===e&&(e=[]),n.pipe(n.interaction(),e)},e.getAccount=function(e){return n.pipe([n.makeGetAccount,function(r){return r.accountAddr=e,n.Ok(r)}])},e.getEvents=function(e,r,t){return n.pipe([n.makeGetEvents,function(r){return r.events.eventType=e,n.Ok(r)},function(e){return e.events.start=r,n.Ok(e)},function(e){return e.events.end=t,n.Ok(e)}])},e.getLatestBlock=function(e){return void 0===e&&(e=!1),n.pipe([n.makeGetLatestBlock,function(r){return r.latestBlock.isSealed=e,n.Ok(r)}])},e.getTransactionStatus=function(e){return n.pipe([n.makeGetTransactionStatus,function(r){return r.transactionId=e,n.Ok(r)}])},e.limit=function(e){return n.pipe([function(r){return r.message.computeLimit=e,n.Ok(r)}])},e.param=function(e,n,r){return void 0===n&&(n=c),void 0===r&&(r=null),{key:r,value:e,xform:n}},e.params=function(e){return void 0===e&&(e=[]),n.pipe(e.map(n.makeParam))},e.payer=function(e){return n.makePayer(a({},"function"==typeof e?{resolve:e}:e,{role:{payer:!0}}))},e.ping=function(){return n.pipe([n.makePing])},e.proposer=function(){try{for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];if(s(r[0]))return Promise.resolve(n.makeProposer({resolve:r[0],role:{proposer:!0}}));var o=r[0],i=r[1],u=r[2];return Promise.resolve(n.makeProposer({addr:o,keyId:i,sequenceNum:u,role:{proposer:!0}}))}catch(e){return Promise.reject(e)}},e.ref=function(e){return n.pipe([function(r){return r.message.refBlock=e,n.Ok(r)}])},e.resolve=u,e.resolveAccounts=O,e.resolveParams=function(e){if(!n.isTransaction(e)&&!n.isScript(e))return n.Ok(e);var r=n.get(e,"ix.cadence");if("string"==typeof r)return e.message.cadence=r,n.Ok(e);if("function"==typeof r){var t=Object.fromEntries(Object.values(e.params).filter(function(e){return null!=e.key}).map(function(e){return[e.key,e.xform.asInjection(e.value)]}));return e.message.cadence=r(t),n.Ok(e)}throw new Error("Invalid Cadence Value")},e.resolveSignatures=function(e){try{if(!n.isTransaction(e))return Promise.resolve(n.Ok(e));var r=e.authorizations.map(function(n){return e.accounts[n]}),t=e.accounts[e.payer],o=e.accounts[e.proposer],u=i.encodeTransactionPayload({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:o.addr,keyId:o.keyId,sequenceNum:o.sequenceNum},payer:t.addr,authorizers:r.map(function(e){return e.addr})}),c=r.map(function(n){try{return n.addr===t.addr?(e.accounts[n.tempId]=a({},e.accounts[n.tempId],{signature:null}),Promise.resolve()):Promise.resolve(n.signingFunction({message:u,addr:n.addr,keyId:n.keyId,roles:{proposer:o.addr===n.addr,authorizer:!0,payer:t.addr===n.addr},interaction:e})).then(function(r){e.accounts[n.tempId]=a({},e.accounts[n.tempId],{signature:r.signature})})}catch(e){return Promise.reject(e)}});return Promise.resolve(Promise.all(c)).then(function(){r=e.authorizations.map(function(n){return e.accounts[n]});var u=i.encodeTransactionEnvelope({script:e.message.cadence,refBlock:e.message.refBlock||null,gasLimit:e.message.computeLimit,proposalKey:{address:o.addr,keyId:o.keyId,sequenceNum:o.sequenceNum},payer:t.addr,authorizers:r.map(function(e){return e.addr}),payloadSigs:r.map(function(e){return null===e.signature?null:{address:e.addr,keyId:e.keyId,sig:e.signature}}).filter(function(e){return null!==e})});return Promise.resolve(t.signingFunction({message:u,addr:t.addr,keyId:t.keyId,roles:{proposer:o.addr===t.addr,authorizer:!1,payer:!0},interaction:e})).then(function(r){return e.accounts[e.payer]=a({},e.accounts[e.payer],{signature:r.signature}),n.Ok(e)})})}catch(e){return Promise.reject(e)}},e.script=function(){return n.pipe([n.makeScript,n.put("ix.cadence",o.t7l.apply(void 0,arguments))])},e.transaction=function(){return n.pipe([n.makeTransaction,n.put("ix.cadence",o.t7l.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||f,n.Ok(e)}])}}); | ||
//# sourceMappingURL=sdk.umd.js.map |
{ | ||
"name": "@onflow/sdk", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Flow SDK", | ||
@@ -37,8 +37,8 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@onflow/decode": "0.0.5", | ||
"@onflow/decode": "0.0.6", | ||
"@onflow/encode": "0.0.2", | ||
"@onflow/interaction": "0.0.5", | ||
"@onflow/send": "0.0.8", | ||
"@onflow/interaction": "0.0.6", | ||
"@onflow/send": "0.0.9", | ||
"@qvvg/templar": "0.0.0" | ||
} | ||
} |
166
readme.md
@@ -5,2 +5,10 @@ # @onflow/sdk | ||
# Status | ||
- **Last Updated:** April 21st 2020 | ||
- **Stable:** Yes | ||
- **Risk of Breaking Change:** Medium | ||
This package is working and in active delveopment, breaking changes may happen. | ||
# Install | ||
@@ -14,28 +22,150 @@ | ||
## 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 t from "@onflow/types" | ||
const builtTxIx = await sdk.build([ | ||
sdk.payer(sdk.authorization("01", signingFunction, 0)), | ||
sdk.proposer("01", 0, seqNum), | ||
sdk.transaction`transaction { prepare(acct: AuthAccount) {} execute { log("Hello") } }`, | ||
sdk.authorizations([sdk.authorization("01", signingFunction, 0)]), | ||
]) | ||
``` | ||
const ixBuilt = await sdk.build([ | ||
## Example: Resolving A Transaction Interaction | ||
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 | ||
const resolvedTxIx = await sdk.pipe(builtTxIx, [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]) | ||
) | ||
``` | ||
## 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 | ||
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. | ||
Please reference the provided example project `react-simple` for example code. | ||
### GetAccount | ||
```javascript | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.getAccount(addr) | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
### GetEvents | ||
```javascript | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.getEvents(eventType, startBlock, endBlock), | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
### GetLatestBlock | ||
```javascript | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.getLatestBlock() | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
### GetTransactionStatus | ||
```javascript | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.getTransactionStatus(txId) | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
### Ping | ||
```javascript | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.ping() | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
### Script | ||
```javascript | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.params([sdk.param("foo", "bar")]), | ||
sdk.script` | ||
pub fun main(): UFix64 { | ||
let a = ${p => p.a} | ||
let b = ${p => p.b} | ||
return a + b | ||
pub fun main(): Int { | ||
log("${p => p.foo}") | ||
return 7 | ||
} | ||
`, | ||
sdk.params([sdk.param(5, t.UFix64, "a"), sdk.param(6, t.UFix64, "b")]), | ||
]) | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
const ixResolved = await sdk.resolve(ixBuild, [sdk.resolveParams]) | ||
### Transaction | ||
const response = await sdk.send(ixResolved, { | ||
node: "accessNode url", | ||
}) | ||
```javascript | ||
const acctResponse = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.getAccount("01") | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
const result = await sdk.decodeResponse(response, { | ||
UFix64: v => BigInt(v), | ||
}) | ||
const seqNum = acctResponse.account.keys[0].sequenceNumber | ||
console.log(result === 11n) // true | ||
const response = await sdk.send(await sdk.pipe(await sdk.build([ | ||
sdk.payer(sdk.authorization("01", signingFunction, 0)), | ||
sdk.proposer("01", 0, seqNum), | ||
sdk.transaction`transaction { prepare(acct: AuthAccount) {} execute { log("Hello") } }`, | ||
sdk.authorizations([sdk.authorization("01", signingFunction, 0)]), | ||
]), [ | ||
sdk.resolve([ | ||
sdk.resolveParams, | ||
sdk.resolveAuthorizations, | ||
]), | ||
]), { node: "http://localhost:8080" }) | ||
``` | ||
@@ -68,3 +198,2 @@ | ||
- [`sdk.limit`](./src/build/limit.js) | ||
- [`sdk.nonce`](./src/build/nonce.js) | ||
- [`sdk.params` & `sdk.param`](./src/build/params.js) | ||
@@ -80,2 +209,1 @@ - [`sdk.payer`](./src/build/payer.js) | ||
- [`sdk.resolveParams`](./src/resolve/resolve-params.js) | ||
- [`sdk.resolvePayload`](./src/resolve/resolve-payload.js) |
@@ -1,9 +0,19 @@ | ||
import {pipe, put} from "@onflow/interaction" | ||
import {pipe, makeAuthorizer} from "@onflow/interaction" | ||
const isFn = d => typeof d === "function" | ||
export function authorizations(ax = []) { | ||
return pipe([put("tx.authorizations", ax)]) | ||
return pipe( | ||
ax.map(authorization => { | ||
const a = isFn(authorization) | ||
? { resolve: authorization } | ||
: authorization | ||
return makeAuthorizer({ ...a, role: { authorizer: true }}) | ||
} | ||
)) | ||
} | ||
export function authorization(acct, signFn, keyId) { | ||
return {acct, signFn, keyId} | ||
export function authorization(addr, signingFunction, keyId) { | ||
return {addr, signingFunction, keyId} | ||
} |
import {pipe, makeGetAccount, Ok} from "@onflow/interaction" | ||
export function getAccount(acct) { | ||
export function getAccount(addr) { | ||
return pipe([ | ||
makeGetAccount, | ||
ix => { | ||
ix.acct = acct | ||
ix.accountAddr = addr | ||
return Ok(ix) | ||
@@ -9,0 +9,0 @@ } |
@@ -7,11 +7,11 @@ import {pipe, Ok, makeGetEvents} from "@onflow/interaction" | ||
ix => { | ||
ix.eventType = eventType | ||
ix.events.eventType = eventType | ||
return Ok(ix) | ||
}, | ||
ix => { | ||
ix.bounds.start = start | ||
ix.events.start = start | ||
return Ok(ix) | ||
}, | ||
ix => { | ||
ix.bounds.end = end | ||
ix.events.end = end | ||
return Ok(ix) | ||
@@ -18,0 +18,0 @@ } |
@@ -7,3 +7,3 @@ import {pipe, Ok, makeGetLatestBlock} from "@onflow/interaction" | ||
ix => { | ||
ix.isSealed = isSealed | ||
ix.latestBlock.isSealed = isSealed | ||
return Ok(ix) | ||
@@ -10,0 +10,0 @@ } |
import {pipe, Ok, makeGetTransactionStatus} from "@onflow/interaction" | ||
export function getTransactionStatus(txId) { | ||
export function getTransactionStatus(transactionId) { | ||
return pipe([ | ||
makeGetTransactionStatus, | ||
ix => { | ||
ix.txId = txId | ||
ix.transactionId = transactionId | ||
return Ok(ix) | ||
@@ -9,0 +9,0 @@ } |
import {pipe, Ok} from "@onflow/interaction" | ||
export function limit(limit) { | ||
export function limit(computeLimit) { | ||
return pipe([ | ||
ix => { | ||
ix.payload.limit = limit | ||
ix.message.computeLimit = computeLimit | ||
return Ok(ix) | ||
@@ -8,0 +8,0 @@ } |
@@ -1,11 +0,5 @@ | ||
import {pipe, put} from "@onflow/interaction" | ||
import {pipe, makeParam} from "@onflow/interaction" | ||
function toMap(kv = []) { | ||
return kv | ||
.filter(d => d.key != null) | ||
.reduce((acc, d) => ({...acc, [d.key]: d.value}), {}) | ||
} | ||
export function params(px = []) { | ||
return pipe([put("ix.params", toMap(px))]) | ||
return pipe(px.map(makeParam)) | ||
} | ||
@@ -12,0 +6,0 @@ |
@@ -1,7 +0,11 @@ | ||
import {pipe, put} from "@onflow/interaction" | ||
import {pipe, makePayer} from "@onflow/interaction" | ||
const isFn = d => typeof d === "function" | ||
export function payer(authz) { | ||
return pipe([ | ||
put("tx.payer", authz) | ||
]) | ||
const a = isFn(authz) | ||
? {resolve: authz} | ||
: authz | ||
return makePayer({ ...a, role: { payer: true }}) | ||
} |
@@ -1,18 +0,24 @@ | ||
import {pipe, put, Ok} from "@onflow/interaction" | ||
import {pipe, makeProposer} from "@onflow/interaction" | ||
const isFn = d => typeof d === "function" | ||
export async function proposer(...args) { | ||
let prop = null | ||
if (typeof args[0] === "function") prop = await args[0]() | ||
if (typeof args[0] === "object") prop = args[0] | ||
const [addr, keyId, sequenceNum] = args | ||
return pipe([ | ||
ix => { | ||
ix.proposer = prop || proposalKey(addr, keyId, sequenceNum) | ||
return Ok(ix) | ||
}, | ||
]) | ||
if (isFn(args[0])) { | ||
return makeProposer( | ||
{ | ||
resolve: args[0], | ||
role: {proposer: true}, | ||
} | ||
) | ||
} else { | ||
const [addr, keyId, sequenceNum] = args | ||
return makeProposer( | ||
{ | ||
addr, | ||
keyId, | ||
sequenceNum, | ||
role: {proposer: true}, | ||
} | ||
) | ||
} | ||
} | ||
function proposalKey(addr, keyId, sequenceNum) { | ||
return {addr, keyId, sequenceNum} | ||
} |
import {pipe, Ok} from "@onflow/interaction" | ||
export function ref(ref) { | ||
export function ref(refBlock) { | ||
return pipe([ | ||
ix => { | ||
ix.payload.ref = ref | ||
ix.message.refBlock = refBlock | ||
return Ok(ix) | ||
@@ -8,0 +8,0 @@ } |
@@ -6,4 +6,4 @@ import {pipe, Ok, put, makeScript} from "@onflow/interaction" | ||
return pipe([makeScript, | ||
put("ix.code", t7l(...args)), | ||
put("ix.cadence", t7l(...args)), | ||
]) | ||
} |
@@ -1,2 +0,2 @@ | ||
import {pipe, put, Ok, update, makeTransaction} from "@onflow/interaction" | ||
import {pipe, put, Ok, makeTransaction} from "@onflow/interaction" | ||
import {t7l} from "@qvvg/templar" | ||
@@ -8,26 +8,13 @@ | ||
// NOTE: nonces are changing, this will work for | ||
// the way the current emulator works | ||
function nonce() { | ||
return Date.now() | ||
} | ||
function hammer(fallback) { | ||
return function(value) { | ||
return value == null ? fallback : value | ||
} | ||
} | ||
export function transaction(...args) { | ||
return pipe([ | ||
makeTransaction, | ||
put("ix.code", t7l(...args)), | ||
put("ix.cadence", t7l(...args)), | ||
ix => { | ||
ix.payload.limit = ix.payload.limit || DEFAULT_COMPUTE_LIMIT | ||
ix.payload.nonce = ix.payload.nonce || nonce() | ||
ix.payload.ref = ix.payload.ref || DEFUALT_REF | ||
ix.message.computeLimit = ix.message.computeLimit || DEFAULT_COMPUTE_LIMIT | ||
ix.message.refBlock = ix.message.refBlock || DEFUALT_REF | ||
ix.authorizations = ix.authorizations || DEFAULT_SCRIPT_ACCOUNTS | ||
return Ok(ix) | ||
}, | ||
update("tx.authorizations", hammer(DEFAULT_SCRIPT_ACCOUNTS)) | ||
]) | ||
} |
@@ -31,3 +31,4 @@ import * as root from "./sdk" | ||
limit ref | ||
resolveAuthorizations | ||
resolveAccounts | ||
resolveSignatures | ||
resolveParams | ||
@@ -34,0 +35,0 @@ ` |
@@ -1,14 +0,23 @@ | ||
import {isTransaction, isScript, pipe, get, Ok, update} from "@onflow/interaction" | ||
import {isTransaction, isScript, get, Ok} from "@onflow/interaction" | ||
function isFn(v) { | ||
return typeof v === "function" | ||
} | ||
const isFn = d => typeof d === "function" | ||
const isString = s => typeof s === "string" | ||
export const resolveParams = pipe([ | ||
ix => { | ||
if (!isTransaction(ix) && !isScript(ix)) return Ok(ix) | ||
const code = get(ix, "ix.code") | ||
ix.payload.code = isFn(code) ? code(get(ix, "ix.params", {})) : code | ||
export const resolveParams = (ix) => { | ||
if (!(isTransaction(ix) || isScript(ix))) return Ok(ix) | ||
const cadence = get(ix, 'ix.cadence') | ||
if (isString(cadence)) { | ||
ix.message.cadence = cadence | ||
return Ok(ix) | ||
} | ||
]) | ||
if (isFn(cadence)) { | ||
const params = Object.fromEntries(Object | ||
.values(ix.params) | ||
.filter(param => param.key != null) | ||
.map(param => [param.key, param.xform.asInjection(param.value)])) | ||
ix.message.cadence = cadence(params) | ||
return Ok(ix) | ||
} | ||
throw new Error("Invalid Cadence Value") | ||
} |
@@ -26,3 +26,4 @@ // Base | ||
// resolvers | ||
export {resolveAuthorizations} from "./resolve/resolve-authorizations" | ||
export {resolveAccounts} from "./resolve/resolve-accounts" | ||
export {resolveParams} from "./resolve/resolve-params" | ||
export {resolveSignatures} from "./resolve/resolve-signatures" |
@@ -6,53 +6,26 @@ import assert from "assert" | ||
it("returns the correct limit when building a transaction", async () => { | ||
const one = await resolve(await build([ | ||
transaction``, | ||
limit(156) | ||
])) | ||
const one = await resolve(await build([transaction``, limit(156)])) | ||
const two = await resolve(await build([ | ||
limit(156), | ||
transaction`` | ||
])) | ||
const two = await resolve(await build([limit(156), transaction``])) | ||
assert.equal(one.payload.limit, 156) | ||
assert.equal(two.payload.limit, 156) | ||
assert.deepEqual(one.payload.limit, two.payload.limit) | ||
assert.equal(one.message.computeLimit, 156) | ||
assert.equal(two.message.computeLimit, 156) | ||
assert.deepEqual(one.message.limit, two.message.limit) | ||
}) | ||
it("returns the correct proposer when building a transaction with a known proposer", async () => { | ||
const ix = await resolve(await build([ | ||
transaction``, | ||
proposer("01", 1, 123) | ||
])) | ||
const ix = await resolve( | ||
await build([transaction``, proposer("01", 1, 123)]) | ||
) | ||
const txProposer = ix.proposer | ||
const txProposer = ix.accounts[ix.proposer] | ||
assert.deepEqual(txProposer, {addr: "01", keyId: 1, sequenceNum: 123 }) | ||
assert.deepEqual(txProposer.addr, "01") | ||
assert.deepEqual(txProposer.keyId, 1) | ||
assert.deepEqual(txProposer.sequenceNum, 123) | ||
}) | ||
it("returns the correct proposer when building a transaction with a fetched proposer", async () => { | ||
const asyncProposer = async () => { | ||
return {addr: "01", keyId: 1, sequenceNum: 123} | ||
} | ||
const ix = await resolve(await build([ | ||
transaction``, | ||
proposer(asyncProposer) | ||
])) | ||
const txProposer = ix.proposer | ||
assert.deepEqual(txProposer, {addr: "01", keyId: 1, sequenceNum: 123}) | ||
it("placeholder test", async () => { | ||
expect(1).toBe(1) | ||
}) | ||
it("returns the correct proposer when building a transaction with a given proposalKey", async () => { | ||
const ix = await resolve(await build([ | ||
transaction``, | ||
proposer({addr: "01", keyId: 1, sequenceNum: 123}) | ||
])) | ||
const txProposer = ix.proposer | ||
assert.deepEqual(txProposer, {addr: "01", keyId: 1, sequenceNum: 123 }) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239993
32
639
206
1
+ Added@onflow/decode@0.0.6(transitive)
+ Added@onflow/interaction@0.0.6(transitive)
+ Added@onflow/send@0.0.9(transitive)
- Removed@onflow/decode@0.0.5(transitive)
- Removed@onflow/interaction@0.0.5(transitive)
- Removed@onflow/send@0.0.8(transitive)
Updated@onflow/decode@0.0.6
Updated@onflow/interaction@0.0.6
Updated@onflow/send@0.0.9