stxer 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/README.md +236 -55
- package/dist/ast.d.ts +1 -1
- package/dist/bitcoin.d.ts +121 -0
- package/dist/index.d.ts +2 -0
- package/dist/simulation-api.d.ts +52 -3
- package/dist/simulation.d.ts +70 -3
- package/dist/stxer.cjs.development.js +904 -101
- package/dist/stxer.cjs.development.js.map +1 -1
- package/dist/stxer.cjs.production.min.js +1 -1
- package/dist/stxer.cjs.production.min.js.map +1 -1
- package/dist/stxer.esm.js +885 -104
- package/dist/stxer.esm.js.map +1 -1
- package/dist/transaction.d.ts +71 -0
- package/dist/types.d.ts +246 -24
- package/package.json +6 -4
- package/src/ast.ts +1 -1
- package/src/bitcoin.ts +391 -0
- package/src/index.ts +2 -0
- package/src/simulation-api.ts +109 -12
- package/src/simulation.ts +245 -46
- package/src/transaction.ts +141 -0
- package/src/types.ts +253 -26
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@stacks/transactions"),t=require("ts-clarity"),n=require("@stacks/network"),r=require("c32check");function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t,n,r,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function a(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var a=e.apply(t,n);function s(e){o(a,r,i,s,c,"next",e)}function c(e){o(a,r,i,s,c,"throw",e)}s(void 0)})}}function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.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)?i(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(null,arguments)}function u(){var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function o(n,r,i,o){var c=Object.create((r&&r.prototype instanceof s?r:s).prototype);return l(c,"_invoke",function(n,r,i){var o,s,c,u=0,l=i||[],p=!1,d={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(t,n){return o=t,s=0,c=e,d.n=n,a}};function h(n,r){for(s=n,c=r,t=0;!p&&u&&!i&&t<l.length;t++){var i,o=l[t],h=d.p,f=o[2];n>3?(i=f===r)&&(c=o[(s=o[4])?5:(s=3,3)],o[4]=o[5]=e):o[0]<=h&&((i=n<2&&h<o[1])?(s=0,d.v=r,d.n=o[1]):h<f&&(i=n<3||o[0]>r||r>f)&&(o[4]=n,o[5]=r,d.n=f,s=0))}if(i||n>1)return a;throw p=!0,r}return function(i,l,f){if(u>1)throw TypeError("Generator is already running");for(p&&1===l&&h(l,f),s=l,c=f;(t=s<2?e:c)||!p;){o||(s?s<3?(s>1&&(d.n=-1),h(s,c)):d.n=c:d.v=c);try{if(u=2,o){if(s||(i="next"),t=o[i]){if(!(t=t.call(o,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,s<2&&(s=0)}else 1===s&&(t=o.return)&&t.call(o),s<2&&(c=TypeError("The iterator does not provide a '"+i+"' method"),s=1);o=e}else if((t=(p=d.n<0)?c:n.call(r,d))!==a)break}catch(t){o=e,s=1,c=t}finally{u=1}}return{value:t,done:p}}}(n,i,o),!0),c}var a={};function s(){}function c(){}function p(){}t=Object.getPrototypeOf;var d=[][r]?t(t([][r]())):(l(t={},r,function(){return this}),t),h=p.prototype=s.prototype=Object.create(d);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,l(e,i,"GeneratorFunction")),e.prototype=Object.create(h),e}return c.prototype=p,l(h,"constructor",p),l(p,"constructor",c),c.displayName="GeneratorFunction",l(p,i,"GeneratorFunction"),l(h),l(h,i,"Generator"),l(h,r,function(){return this}),l(h,"toString",function(){return"[object Generator]"}),(u=function(){return{w:o,m:f}})()}function l(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}l=function(e,t,n,r){function o(t,n){l(e,t,function(e){return this._invoke(t,n,e)})}t?i?i(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(o("next",0),o("throw",1),o("return",2))},l(e,t,n,r)}var p="https://api.stxer.xyz",d="https://testnet-api.stxer.xyz",h=p;function f(){return(f=a(u().m(function e(t){var n,r,i,o;return u().w(function(e){for(;;)switch(e.n){case 0:return r=(null!=(n=t.stxerApi)?n:h)+"/contracts/"+t.contractId,e.n=1,fetch(r,{method:"GET",headers:{Accept:"application/json"}});case 1:if((i=e.v).ok){e.n=2;break}throw new Error("Failed to fetch contract AST: "+i.status+" "+i.statusText);case 2:return e.n=3,i.text();case 3:if((o=e.v).startsWith("{")){e.n=4;break}throw new Error("Invalid response from contracts endpoint: "+o);case 4:return e.a(2,JSON.parse(o))}},e)}))).apply(this,arguments)}function v(){return(v=a(u().m(function e(t){var n,r,i,o,a;return u().w(function(e){for(;;)switch(e.n){case 0:return r=(null!=(n=t.stxerApi)?n:h)+"/contracts:parse",i={contract_id:t.contractId,source_code:t.sourceCode},void 0!==t.clarityVersion&&(i.clarity_version=t.clarityVersion),void 0!==t.epoch&&(i.epoch=t.epoch),e.n=1,fetch(r,{method:"POST",body:JSON.stringify(i),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=2;break}throw new Error("Failed to parse contract: "+o.status+" "+o.statusText);case 2:return e.n=3,o.text();case 3:if((a=e.v).startsWith("{")){e.n=4;break}throw new Error("Invalid response from contract parse endpoint: "+a);case 4:return e.a(2,JSON.parse(a))}},e)}))).apply(this,arguments)}function y(t){for(var n,r=[],i=s(null!=t?t:[]);!(n=i()).done;){var o=n.value;r.push("Ok"in o?e.deserializeCV(o.Ok):new Error(o.Err))}return r}function m(e,t){return b.apply(this,arguments)}function b(){return(b=a(u().m(function t(n,r){var i,o,a,c,l,p,d,h,f,v,m,b,w,k,g,x;return u().w(function(t){for(;;)switch(t.n){case 0:if(void 0===r&&(r={}),o=null==n.index_block_hash?void 0:n.index_block_hash.startsWith("0x")?n.index_block_hash.substring(2):n.index_block_hash,a={vars:[],maps:[],readonly:[],tip:o},null!=n.variables)for(c=s(n.variables);!(l=c()).done;)a.vars.push([e.serializeCV((p=l.value).contract),p.variableName]);if(null!=n.maps)for(d=s(n.maps);!(h=d()).done;)a.maps.push([e.serializeCV((f=h.value).contract),f.mapName,e.serializeCV(f.mapKey)]);if(null!=n.readonly)for(v=s(n.readonly);!(m=v()).done;)a.readonly.push([e.serializeCV((b=m.value).contract),b.functionName].concat(b.functionArgs.map(function(t){return e.serializeCV(t)})));return w=(null!=(i=r.stxerApi)?i:"https://api.stxer.xyz")+"/sidecar/v2/batch",t.n=1,fetch(w,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"}});case 1:return k=t.v,t.n=2,k.text();case 2:if((g=t.v).includes("Ok")||g.includes("Err")){t.n=3;break}throw new Error("Requesting batch reads failed: "+g+", url: "+w+", payload: "+JSON.stringify(a));case 3:return x=JSON.parse(g),t.a(2,{index_block_hash:x.index_block_hash,vars:y(x.vars),maps:y(x.maps),readonly:y(x.readonly)})}},t)}))).apply(this,arguments)}var w=new(function(){function t(e){var t;this.queues=new Map,this.timeoutIds=new Map,this.stxerAPIEndpoint=void 0,this.batchDelayMs=void 0,this.stxerAPIEndpoint=null!=(t=e.stxerAPIEndpoint)?t:"https://api.stxer.xyz",this.batchDelayMs=e.batchDelayMs}var n=t.prototype;return n.getQueueKey=function(e){return null!=e?e:"_undefined"},n.read=function(e){var t=this;return new Promise(function(n,r){t.enqueue({request:e,resolve:n,reject:r})})},n.enqueue=function(e){var t,n=this,r=this.getQueueKey(e.tip),i=null!=(t=this.queues.get(r))?t:[];if(this.queues.has(r)||this.queues.set(r,i),i.push(e),!this.timeoutIds.has(r)){var o=setTimeout(function(){return n.processBatch(r)},this.batchDelayMs);this.timeoutIds.set(r,o)}},n.processBatch=function(){var t=a(u().m(function t(n){var r,i,o,a,c,l,p,d,h,f,v,y,b,w,k,g,x,S,_,A,T,E,N,C,P,j,I;return u().w(function(t){for(;;)switch(t.p=t.n){case 0:if(i=null!=(r=this.queues.get(n))?r:[],this.queues.delete(n),(o=this.timeoutIds.get(n))&&(clearTimeout(o),this.timeoutIds.delete(n)),0!==i.length){t.n=1;break}return t.a(2);case 1:return t.p=1,a=i.filter(function(e){return"readonly"===e.request.mode}),c=i.filter(function(e){return"mapEntry"===e.request.mode}),l=i.filter(function(e){return"variable"===e.request.mode}),p="_undefined"===n?void 0:n,d={readonly:a.map(function(t){var n=t.request;return{contract:e.contractPrincipalCV(n.contractAddress,n.contractName),functionName:n.functionName,functionArgs:n.functionArgs}}),maps:c.map(function(t){var n=t.request;return{contract:e.contractPrincipalCV(n.contractAddress,n.contractName),mapName:n.mapName,mapKey:n.mapKey}}),variables:l.map(function(t){var n=t.request;return{contract:e.contractPrincipalCV(n.contractAddress,n.contractName),variableName:n.variableName}}),index_block_hash:p},t.n=2,m(d,{stxerApi:this.stxerAPIEndpoint});case 2:for(f=s((h=t.v).readonly.entries());!(v=f()).done;)b=(y=v.value)[0],(w=y[1])instanceof Error?a[b].reject(w):a[b].resolve(w);for(k=s(h.vars.entries());!(g=k()).done;)S=(x=g.value)[0],(_=x[1])instanceof Error?l[S].reject(_):l[S].resolve(_);for(A=s(h.maps.entries());!(T=A()).done;)N=(E=T.value)[0],(C=E[1])instanceof Error?c[N].reject(C):c[N].resolve(C);t.n=4;break;case 3:for(t.p=3,I=t.v,P=s(i);!(j=P()).done;)j.value.reject(I);case 4:return t.a(2)}},t,this,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),t}())({batchDelayMs:100});function k(){return(k=a(u().m(function e(n){var r,i,o,a,c,l,p,d,h,f,v,y;return u().w(function(e){for(;;)switch(e.n){case 0:if(i=null!=(r=n.batchProcessor)?r:w,o=n.contract.split(".",2),a=o[0],c=o[1],l=String(n.functionName),p=n.abi.find(function(e){return e.name===n.functionName})){e.n=1;break}throw new Error("failed to find function definition for "+n.functionName);case 1:for(d=n.args,h=[],f=s(p.args);!(v=f()).done;)h.push(t.encodeAbi((y=v.value).type,d[y.name]));return e.a(2,new Promise(function(e,r){i.enqueue({request:{mode:"readonly",contractAddress:a,contractName:c,functionName:l,functionArgs:h},tip:n.indexBlockHash,resolve:function(n){try{var i=t.decodeAbi(p.outputs.type,n);e(i)}catch(e){r(e)}},reject:r})}))}},e)}))).apply(this,arguments)}function g(){return(g=a(u().m(function n(r){var i,o,a,s,c,l,p;return u().w(function(n){for(;;)switch(n.n){case 0:if(o=null!=(i=r.batchProcessor)?i:w,a=r.contract.split(".",2),s=a[0],c=a[1],l=r.abi.find(function(e){return e.name===r.mapName})){n.n=1;break}throw new Error("failed to find map definition for "+r.mapName);case 1:return p=t.encodeAbi(l.key,r.key),n.a(2,new Promise(function(n,i){o.enqueue({request:{mode:"mapEntry",contractAddress:s,contractName:c,mapName:r.mapName,mapKey:p},tip:r.indexBlockHash,resolve:function(r){try{if(r.type===e.ClarityType.OptionalNone)return void n(null);if(r.type!==e.ClarityType.OptionalSome)throw new Error("unexpected map value: "+r);var o=t.decodeAbi(l.value,r.value);n(o)}catch(e){i(e)}},reject:i})}))}},n)}))).apply(this,arguments)}function x(){return(x=a(u().m(function e(n){var r,i,o,a,s,c;return u().w(function(e){for(;;)switch(e.n){case 0:if(i=null!=(r=n.batchProcessor)?r:w,o=n.contract.split(".",2),a=o[0],s=o[1],c=n.abi.find(function(e){return e.name===n.variableName})){e.n=1;break}throw new Error("failed to find variable definition for "+n.variableName);case 1:return e.a(2,new Promise(function(e,r){i.enqueue({request:{mode:"variable",contractAddress:a,contractName:s,variableName:n.variableName},tip:n.indexBlockHash,resolve:function(n){try{var i=t.decodeAbi(c.type,n);e(i)}catch(e){r(e)}},reject:r})}))}},e)}))).apply(this,arguments)}function S(){return(S=a(u().m(function e(t,n){var r,i,o;return u().w(function(e){for(;;)switch(e.n){case 0:return void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:h,e.n=1,fetch(i+"/devtools/v2/simulations:instant",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=3;break}return e.n=2,o.text();case 2:throw new Error("Instant simulation failed: "+e.v);case 3:return e.a(2,o.json())}},e)}))).apply(this,arguments)}function _(e,t){return A.apply(this,arguments)}function A(){return(A=a(u().m(function e(t,n){var r,i,o;return u().w(function(e){for(;;)switch(e.n){case 0:return void 0===t&&(t={}),void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:h,e.n=1,fetch(i+"/devtools/v2/simulations",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=3;break}return e.n=2,o.text();case 2:throw new Error("Failed to create simulation session: "+e.v);case 3:return e.n=4,o.json();case 4:return e.a(2,e.v.id)}},e)}))).apply(this,arguments)}function T(e,t,n){return E.apply(this,arguments)}function E(){return(E=a(u().m(function e(t,n,r){var i,o,a;return u().w(function(e){for(;;)switch(e.n){case 0:return void 0===r&&(r={}),o=null!=(i=r.stxerApi)?i:h,e.n=1,fetch(o+"/devtools/v2/simulations/"+t,{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((a=e.v).ok){e.n=3;break}return e.n=2,a.text();case 2:throw new Error("Failed to submit simulation steps: "+e.v);case 3:return e.a(2,a.json())}},e)}))).apply(this,arguments)}function N(){return(N=a(u().m(function e(t,n){var r,i,o;return u().w(function(e){for(;;)switch(e.n){case 0:return void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:h,e.n=1,fetch(i+"/devtools/v2/simulations/"+t,{method:"GET",headers:{Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=3;break}return e.n=2,o.text();case 2:throw new Error("Failed to get simulation result: "+e.v);case 3:return e.a(2,o.json())}},e)}))).apply(this,arguments)}function C(){return(C=a(u().m(function e(t,n,r){var i,o,a;return u().w(function(e){for(;;)switch(e.n){case 0:return void 0===r&&(r={}),o=null!=(i=r.stxerApi)?i:h,e.n=1,fetch(o+"/devtools/v2/simulations/"+t+"/reads",{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((a=e.v).ok){e.n=3;break}return e.n=2,a.text();case 2:throw new Error("Failed to batch reads from simulation: "+e.v);case 3:return e.a(2,a.json())}},e)}))).apply(this,arguments)}function P(t,i){var o=r.c32addressDecode(i),a=o[1];switch(o[0]){case n.AddressVersion.MainnetSingleSig:case n.AddressVersion.TestnetSingleSig:t.auth.spendingCondition.hashMode=e.AddressHashMode.P2PKH,t.auth.spendingCondition.signer=a;break;case n.AddressVersion.MainnetMultiSig:case n.AddressVersion.TestnetMultiSig:var s=t.auth.spendingCondition;t.auth.spendingCondition={hashMode:e.AddressHashMode.P2SH,signer:a,fields:[],signaturesRequired:0,nonce:s.nonce,fee:s.fee}}return t}var j=function(){function r(e){var t,n,r,i;void 0===e&&(e={}),this.apiEndpoint=void 0,this.stacksNodeAPI=void 0,this.network=void 0,this.skipTracing=void 0,this.block=NaN,this.sender="",this.steps=[],this.network=null!=(t=e.network)?t:"mainnet";var o="testnet"===this.network;this.apiEndpoint=null!=(n=e.apiEndpoint)?n:o?d:p,this.stacksNodeAPI=null!=(r=e.stacksNodeAPI)?r:o?"https://api.testnet.hiro.so":"https://api.hiro.so",this.skipTracing=null!=(i=e.skipTracing)&&i}r.new=function(e){return new r(e)};var i=r.prototype;return i.useBlockHeight=function(e){return this.block=e,this},i.withSender=function(e){return this.sender=e,this},i.inlineSimulation=function(e){return this.steps.push({simulationId:e}),this},i.addSTXTransfer=function(e){var t,n;if(null==e.sender&&""===this.sender)throw new Error("Please specify a sender with useSender or adding a sender paramenter");return this.steps.push(c({},e,{sender:null!=(t=e.sender)?t:this.sender,fee:null!=(n=e.fee)?n:0})),this},i.addContractCall=function(e){var t,n;if(null==e.sender&&""===this.sender)throw new Error("Please specify a sender with useSender or adding a sender paramenter");return this.steps.push(c({},e,{sender:null!=(t=e.sender)?t:this.sender,fee:null!=(n=e.fee)?n:0})),this},i.addContractDeploy=function(t){var n,r,i;if(null==t.deployer&&""===this.sender)throw new Error("Please specify a deployer with useSender or adding a deployer paramenter");return this.steps.push(c({},t,{deployer:null!=(n=t.deployer)?n:this.sender,fee:null!=(r=t.fee)?r:0,clarity_version:null!=(i=t.clarity_version)?i:e.ClarityVersion.Clarity4})),this},i.addEvalCode=function(e,t){return this.steps.push({contract_id:e,code:t}),this},i.addMapRead=function(e,t,n){return this.steps.push({contract_id:e,code:"(map-get "+t+" "+n+")"}),this},i.addVarRead=function(e,t){return this.steps.push({contract_id:e,code:"(var-get "+t+")"}),this},i.addSetContractCode=function(t){var n;return this.steps.push({type:"SetContractCode",contract_id:t.contract_id,source_code:t.source_code,clarity_version:null!=(n=t.clarity_version)?n:e.ClarityVersion.Clarity4}),this},i.addReads=function(e){return this.steps.push({type:"Reads",reads:e}),this},i.addTenureExtend=function(){return this.steps.push({type:"TenureExtend"}),this},i.getBlockInfo=function(){var e=a(u().m(function e(){var n;return u().w(function(e){for(;;)switch(e.n){case 0:if(!Number.isNaN(this.block)){e.n=2;break}return e.n=1,t.getNodeInfo({stacksEndpoint:this.stacksNodeAPI});case 1:this.block=e.v.stacks_tip_height;case 2:return e.n=3,t.richFetch(this.stacksNodeAPI+"/extended/v1/block/by_height/"+this.block+"?unanchored=true").then(function(e){return e.json()});case 3:if((n=e.v).height===this.block&&"string"==typeof n.hash&&n.hash.startsWith("0x")){e.n=4;break}throw new Error("failed to get block info for block height "+this.block);case 4:return e.a(2,{block_height:this.block,block_hash:n.hash.substring(2),index_block_hash:n.index_block_hash.substring(2)})}},e,this)}));return function(){return e.apply(this,arguments)}}(),i.run=function(){var r=a(u().m(function r(){var i,o,l,p,d,h,f,v,y,m,b,w,k,g,x,S,A,E,N=this;return u().w(function(r){for(;;)switch(r.n){case 0:return console.log("--------------------------------\nThis product can never exist without your support!\n\nWe receive sponsorship funds with:\nSP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER\n\nFeedbacks and feature requests are welcome.\nTo get in touch: contact@stxer.xyz\n--------------------------------"),r.n=1,this.getBlockInfo();case 1:i=r.v,console.log("Using block height "+i.block_height+" hash 0x"+i.block_hash+" to run simulation."),o=[],l=new Map,p=function(){var e=a(u().m(function e(n){var r,o,a;return u().w(function(e){for(;;)switch(e.n){case 0:if(null!=(r=l.get(n))){e.n=2;break}return o=N.stacksNodeAPI+"/v2/accounts/"+n+"?proof="+!1+"&tip="+i.index_block_hash,e.n=1,t.richFetch(o).then(function(e){return e.json()});case 1:return l.set(n,(a=e.v).nonce+1),e.a(2,a.nonce);case 2:return l.set(n,r+1),e.a(2,r)}},e)}));return function(t){return e.apply(this,arguments)}}(),d="mainnet"===this.network?n.STACKS_MAINNET:n.STACKS_TESTNET,this.stacksNodeAPI&&(d=c({},d,{client:c({},d.client,{baseUrl:this.stacksNodeAPI})})),h=s(this.steps);case 2:if((f=h()).done){r.n=14;break}if(!("simulationId"in(v=f.value))){r.n=3;break}throw new Error("inlineSimulation is not yet supported in V2 API. Please run simulations from scratch.");case 3:if(!("sender"in v)||!("function_name"in v)){r.n=6;break}return r.n=4,p(v.sender);case 4:return m=r.v,r.n=5,e.makeUnsignedContractCall({contractAddress:v.contract_id.split(".")[0],contractName:v.contract_id.split(".")[1],functionName:v.function_name,functionArgs:null!=(y=v.function_args)?y:[],nonce:m,network:d,publicKey:"",postConditionMode:e.PostConditionMode.Allow,fee:v.fee});case 5:P(b=r.v,v.sender),o.push({Transaction:I(b.serializeBytes())}),r.n=13;break;case 6:if(!("sender"in v)||!("recipient"in v)){r.n=9;break}return r.n=7,p(v.sender);case 7:return w=r.v,r.n=8,e.makeUnsignedSTXTokenTransfer({recipient:v.recipient,amount:v.amount,nonce:w,network:d,publicKey:"",fee:v.fee});case 8:P(k=r.v,v.sender),o.push({Transaction:I(k.serializeBytes())}),r.n=13;break;case 9:if(!("deployer"in v)){r.n=12;break}return r.n=10,p(v.deployer);case 10:return g=r.v,r.n=11,e.makeUnsignedContractDeploy({contractName:v.contract_name,codeBody:v.source_code,nonce:g,network:d,publicKey:"",postConditionMode:e.PostConditionMode.Allow,fee:v.fee,clarityVersion:v.clarity_version});case 11:P(x=r.v,v.deployer),o.push({Transaction:I(x.serializeBytes())}),r.n=13;break;case 12:"code"in v?(S=v.contract_id.split("."),A=S[0],o.push({Eval:[this.sender||A,"",A+"."+S[1],v.code]})):"SetContractCode"===v.type?o.push({SetContractCode:[v.contract_id,v.source_code,O(v.clarity_version)]}):"Reads"===v.type?o.push({Reads:v.reads}):"TenureExtend"===v.type?o.push({TenureExtend:[]}):console.log("Invalid simulation step: "+v);case 13:r.n=2;break;case 14:return r.n=15,_({block_height:i.block_height,block_hash:i.block_hash,skip_tracing:this.skipTracing},{stxerApi:this.apiEndpoint});case 15:return E=r.v,r.n=16,T(E,{steps:o},{stxerApi:this.apiEndpoint});case 16:return console.log("Simulation will be available at: https://stxer.xyz/simulations/"+this.network+"/"+E),r.a(2,E)}},r,this)}));return function(){return r.apply(this,arguments)}}(),i.pipe=function(e){return e(this)},r}();function I(e){return Array.from(e).map(function(e){return e.toString(16).padStart(2,"0")}).join("")}function O(t){switch(t){case e.ClarityVersion.Clarity1:return 1;case e.ClarityVersion.Clarity2:return 2;case e.ClarityVersion.Clarity3:return 3;default:return 4}}function q(){return(q=a(u().m(function e(t){var n,r,i,o;return u().w(function(e){for(;;)switch(e.n){case 0:return void 0===t&&(t={}),r=(null!=(n=t.stxerApi)?n:h)+"/sidecar/tip",e.n=1,fetch(r,{method:"GET",headers:{Accept:"application/json"}});case 1:if((i=e.v).ok){e.n=2;break}throw new Error("Failed to fetch tip: "+i.status+" "+i.statusText);case 2:return e.n=3,i.text();case 3:if((o=e.v).startsWith("{")){e.n=4;break}throw new Error("Invalid response from tip endpoint: "+o);case 4:return e.a(2,JSON.parse(o))}},e)}))).apply(this,arguments)}exports.DEFAULT_STXER_API=h,exports.STXER_API_MAINNET=p,exports.STXER_API_TESTNET=d,exports.SimulationBuilder=j,exports.batchRead=m,exports.callReadonly=function(e){return k.apply(this,arguments)},exports.createSimulationSession=_,exports.getContractAST=function(e){return f.apply(this,arguments)},exports.getSimulationResult=function(e,t){return N.apply(this,arguments)},exports.getTip=function(e){return q.apply(this,arguments)},exports.instantSimulation=function(e,t){return S.apply(this,arguments)},exports.parseContract=function(e){return v.apply(this,arguments)},exports.parseSimulationEvent=function(e){return JSON.parse(e)},exports.readMap=function(e){return g.apply(this,arguments)},exports.readVariable=function(e){return x.apply(this,arguments)},exports.simulationBatchReads=function(e,t,n){return C.apply(this,arguments)},exports.submitSimulationSteps=T;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@stacks/transactions"),t=require("@noble/hashes/sha2.js"),n=require("ts-clarity"),r=require("@stacks/network"),i=require("c32check");function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e,t,n,r,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function s(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function s(e){a(o,r,i,s,c,"next",e)}function c(e){a(o,r,i,s,c,"throw",e)}s(void 0)})}}function c(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return o(e,t);var n={}.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)?o(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(null,arguments)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function p(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(p=function(){return!!e})()}function f(){var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function o(n,r,i,o){var c=Object.create((r&&r.prototype instanceof s?r:s).prototype);return h(c,"_invoke",function(n,r,i){var o,s,c,u=0,l=i||[],p=!1,f={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(t,n){return o=t,s=0,c=e,f.n=n,a}};function h(n,r){for(s=n,c=r,t=0;!p&&u&&!i&&t<l.length;t++){var i,o=l[t],h=f.p,d=o[2];n>3?(i=d===r)&&(c=o[(s=o[4])?5:(s=3,3)],o[4]=o[5]=e):o[0]<=h&&((i=n<2&&h<o[1])?(s=0,f.v=r,f.n=o[1]):h<d&&(i=n<3||o[0]>r||r>d)&&(o[4]=n,o[5]=r,f.n=d,s=0))}if(i||n>1)return a;throw p=!0,r}return function(i,l,d){if(u>1)throw TypeError("Generator is already running");for(p&&1===l&&h(l,d),s=l,c=d;(t=s<2?e:c)||!p;){o||(s?s<3?(s>1&&(f.n=-1),h(s,c)):f.n=c:f.v=c);try{if(u=2,o){if(s||(i="next"),t=o[i]){if(!(t=t.call(o,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,s<2&&(s=0)}else 1===s&&(t=o.return)&&t.call(o),s<2&&(c=TypeError("The iterator does not provide a '"+i+"' method"),s=1);o=e}else if((t=(p=f.n<0)?c:n.call(r,f))!==a)break}catch(t){o=e,s=1,c=t}finally{u=1}}return{value:t,done:p}}}(n,i,o),!0),c}var a={};function s(){}function c(){}function u(){}t=Object.getPrototypeOf;var l=[][r]?t(t([][r]())):(h(t={},r,function(){return this}),t),p=u.prototype=s.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,h(e,i,"GeneratorFunction")),e.prototype=Object.create(p),e}return c.prototype=u,h(p,"constructor",u),h(u,"constructor",c),c.displayName="GeneratorFunction",h(u,i,"GeneratorFunction"),h(p),h(p,i,"Generator"),h(p,r,function(){return this}),h(p,"toString",function(){return"[object Generator]"}),(f=function(){return{w:o,m:d}})()}function h(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}h=function(e,t,n,r){function o(t,n){h(e,t,function(e){return this._invoke(t,n,e)})}t?i?i(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(o("next",0),o("throw",1),o("return",2))},h(e,t,n,r)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function v(e){var t="function"==typeof Map?new Map:void 0;return v=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(p())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&d(i,n.prototype),i}(e,arguments,l(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),d(n,e)},v(e)}var y="https://api.stxer.xyz",m="https://testnet-api.stxer.xyz",b=y;function w(){return(w=s(f().m(function e(t){var n,r,i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return r=(null!=(n=t.stxerApi)?n:b)+"/contracts/"+t.contractId,e.n=1,fetch(r,{method:"GET",headers:{Accept:"application/json"}});case 1:if((i=e.v).ok){e.n=2;break}throw new Error("Failed to fetch contract AST: "+i.status+" "+i.statusText);case 2:return e.n=3,i.text();case 3:if((o=e.v).startsWith("{")){e.n=4;break}throw new Error("Invalid response from contracts endpoint: "+o);case 4:return e.a(2,JSON.parse(o))}},e)}))).apply(this,arguments)}function g(){return(g=s(f().m(function e(t){var n,r,i,o,a;return f().w(function(e){for(;;)switch(e.n){case 0:return r=(null!=(n=t.stxerApi)?n:b)+"/contracts:parse",i={contract_id:t.contractId,source_code:t.sourceCode},void 0!==t.clarityVersion&&(i.clarity_version=t.clarityVersion),void 0!==t.epoch&&(i.epoch=t.epoch),e.n=1,fetch(r,{method:"POST",body:JSON.stringify(i),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=2;break}throw new Error("Failed to parse contract: "+o.status+" "+o.statusText);case 2:return e.n=3,o.text();case 3:if((a=e.v).startsWith("{")){e.n=4;break}throw new Error("Invalid response from contract parse endpoint: "+a);case 4:return e.a(2,JSON.parse(a))}},e)}))).apply(this,arguments)}function k(t){for(var n,r=[],i=c(null!=t?t:[]);!(n=i()).done;){var o=n.value;r.push("Ok"in o?e.deserializeCV(o.Ok):new Error(o.Err))}return r}function x(e,t){return A.apply(this,arguments)}function A(){return(A=s(f().m(function t(n,r){var i,o,a,s,u,l,p,h,d,v,y,m,b,w,g,x;return f().w(function(t){for(;;)switch(t.n){case 0:if(void 0===r&&(r={}),o=null==n.index_block_hash?void 0:n.index_block_hash.startsWith("0x")?n.index_block_hash.substring(2):n.index_block_hash,a={vars:[],maps:[],readonly:[],tip:o},null!=n.variables)for(s=c(n.variables);!(u=s()).done;)a.vars.push([e.serializeCV((l=u.value).contract),l.variableName]);if(null!=n.maps)for(p=c(n.maps);!(h=p()).done;)a.maps.push([e.serializeCV((d=h.value).contract),d.mapName,e.serializeCV(d.mapKey)]);if(null!=n.readonly)for(v=c(n.readonly);!(y=v()).done;)a.readonly.push([e.serializeCV((m=y.value).contract),m.functionName].concat(m.functionArgs.map(function(t){return e.serializeCV(t)})));return b=(null!=(i=r.stxerApi)?i:"https://api.stxer.xyz")+"/sidecar/v2/batch",t.n=1,fetch(b,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"}});case 1:return w=t.v,t.n=2,w.text();case 2:if((g=t.v).includes("Ok")||g.includes("Err")){t.n=3;break}throw new Error("Requesting batch reads failed: "+g+", url: "+b+", payload: "+JSON.stringify(a));case 3:return x=JSON.parse(g),t.a(2,{index_block_hash:x.index_block_hash,vars:k(x.vars),maps:k(x.maps),readonly:k(x.readonly)})}},t)}))).apply(this,arguments)}function S(e){return t.sha256(e)}function T(e){return S(S(e))}function _(e){return Array.from(e).map(function(e){return e.toString(16).padStart(2,"0")}).join("")}function E(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e[e.length-1-n];return t}function N(e,t){var n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n}var C=new(function(){function t(e){var t;this.queues=new Map,this.timeoutIds=new Map,this.stxerAPIEndpoint=void 0,this.batchDelayMs=void 0,this.stxerAPIEndpoint=null!=(t=e.stxerAPIEndpoint)?t:"https://api.stxer.xyz",this.batchDelayMs=e.batchDelayMs}var n=t.prototype;return n.getQueueKey=function(e){return null!=e?e:"_undefined"},n.read=function(e){var t=this;return new Promise(function(n,r){t.enqueue({request:e,resolve:n,reject:r})})},n.enqueue=function(e){var t,n=this,r=this.getQueueKey(e.tip),i=null!=(t=this.queues.get(r))?t:[];if(this.queues.has(r)||this.queues.set(r,i),i.push(e),!this.timeoutIds.has(r)){var o=setTimeout(function(){return n.processBatch(r)},this.batchDelayMs);this.timeoutIds.set(r,o)}},n.processBatch=function(){var t=s(f().m(function t(n){var r,i,o,a,s,u,l,p,h,d,v,y,m,b,w,g,k,A,S,T,_,E,N,C,P,O,j;return f().w(function(t){for(;;)switch(t.p=t.n){case 0:if(i=null!=(r=this.queues.get(n))?r:[],this.queues.delete(n),(o=this.timeoutIds.get(n))&&(clearTimeout(o),this.timeoutIds.delete(n)),0!==i.length){t.n=1;break}return t.a(2);case 1:return t.p=1,a=i.filter(function(e){return"readonly"===e.request.mode}),s=i.filter(function(e){return"mapEntry"===e.request.mode}),u=i.filter(function(e){return"variable"===e.request.mode}),l="_undefined"===n?void 0:n,p={readonly:a.map(function(t){var n=t.request;return{contract:e.contractPrincipalCV(n.contractAddress,n.contractName),functionName:n.functionName,functionArgs:n.functionArgs}}),maps:s.map(function(t){var n=t.request;return{contract:e.contractPrincipalCV(n.contractAddress,n.contractName),mapName:n.mapName,mapKey:n.mapKey}}),variables:u.map(function(t){var n=t.request;return{contract:e.contractPrincipalCV(n.contractAddress,n.contractName),variableName:n.variableName}}),index_block_hash:l},t.n=2,x(p,{stxerApi:this.stxerAPIEndpoint});case 2:for(d=c((h=t.v).readonly.entries());!(v=d()).done;)m=(y=v.value)[0],(b=y[1])instanceof Error?a[m].reject(b):a[m].resolve(b);for(w=c(h.vars.entries());!(g=w()).done;)A=(k=g.value)[0],(S=k[1])instanceof Error?u[A].reject(S):u[A].resolve(S);for(T=c(h.maps.entries());!(_=T()).done;)N=(E=_.value)[0],(C=E[1])instanceof Error?s[N].reject(C):s[N].resolve(C);t.n=4;break;case 3:for(t.p=3,j=t.v,P=c(i);!(O=P()).done;)O.value.reject(j);case 4:return t.a(2)}},t,this,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),t}())({batchDelayMs:100});function P(){return(P=s(f().m(function e(t){var r,i,o,a,s,u,l,p,h,d,v,y;return f().w(function(e){for(;;)switch(e.n){case 0:if(i=null!=(r=t.batchProcessor)?r:C,o=t.contract.split(".",2),a=o[0],s=o[1],u=String(t.functionName),l=t.abi.find(function(e){return e.name===t.functionName})){e.n=1;break}throw new Error("failed to find function definition for "+t.functionName);case 1:for(p=t.args,h=[],d=c(l.args);!(v=d()).done;)h.push(n.encodeAbi((y=v.value).type,p[y.name]));return e.a(2,new Promise(function(e,r){i.enqueue({request:{mode:"readonly",contractAddress:a,contractName:s,functionName:u,functionArgs:h},tip:t.indexBlockHash,resolve:function(t){try{var i=n.decodeAbi(l.outputs.type,t);e(i)}catch(e){r(e)}},reject:r})}))}},e)}))).apply(this,arguments)}function O(){return(O=s(f().m(function t(r){var i,o,a,s,c,u,l;return f().w(function(t){for(;;)switch(t.n){case 0:if(o=null!=(i=r.batchProcessor)?i:C,a=r.contract.split(".",2),s=a[0],c=a[1],u=r.abi.find(function(e){return e.name===r.mapName})){t.n=1;break}throw new Error("failed to find map definition for "+r.mapName);case 1:return l=n.encodeAbi(u.key,r.key),t.a(2,new Promise(function(t,i){o.enqueue({request:{mode:"mapEntry",contractAddress:s,contractName:c,mapName:r.mapName,mapKey:l},tip:r.indexBlockHash,resolve:function(r){try{if(r.type===e.ClarityType.OptionalNone)return void t(null);if(r.type!==e.ClarityType.OptionalSome)throw new Error("unexpected map value: "+r);var o=n.decodeAbi(u.value,r.value);t(o)}catch(e){i(e)}},reject:i})}))}},t)}))).apply(this,arguments)}function j(){return(j=s(f().m(function e(t){var r,i,o,a,s,c;return f().w(function(e){for(;;)switch(e.n){case 0:if(i=null!=(r=t.batchProcessor)?r:C,o=t.contract.split(".",2),a=o[0],s=o[1],c=t.abi.find(function(e){return e.name===t.variableName})){e.n=1;break}throw new Error("failed to find variable definition for "+t.variableName);case 1:return e.a(2,new Promise(function(e,r){i.enqueue({request:{mode:"variable",contractAddress:a,contractName:s,variableName:t.variableName},tip:t.indexBlockHash,resolve:function(t){try{var i=n.decodeAbi(c.type,t);e(i)}catch(e){r(e)}},reject:r})}))}},e)}))).apply(this,arguments)}var I=function(e){function t(t,n,r){var i,o=function(e){return e.includes("simulation_busy:")?"simulation_busy":e.includes("simulation_outdated:")?"simulation_outdated":null}(r);return(i=e.call(this,t+" (HTTP "+n+"): "+r)||this).status=void 0,i.marker=void 0,i.body=void 0,i.name="SimulationError",i.status=n,i.marker=o,i.body=r,i}var n,r;return r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,d(n,r),t}(v(Error));function U(e,t){return M.apply(this,arguments)}function M(){return(M=s(f().m(function e(t,n){return f().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,n.text();case 1:throw new I(t,n.status,e.v);case 2:return e.a(2)}},e)}))).apply(this,arguments)}function V(){return(V=s(f().m(function e(t,n){var r,i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:b,e.n=1,fetch(i+"/devtools/v2/simulations:instant",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=2;break}return e.n=2,U("Instant simulation failed",o);case 2:return e.a(2,o.json())}},e)}))).apply(this,arguments)}function q(e,t){return B.apply(this,arguments)}function B(){return(B=s(f().m(function e(t,n){var r,i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===t&&(t={}),void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:b,e.n=1,fetch(i+"/devtools/v2/simulations",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=2;break}return e.n=2,U("Failed to create simulation session",o);case 2:return e.n=3,o.json();case 3:return e.a(2,e.v.id)}},e)}))).apply(this,arguments)}function R(e,t,n){return z.apply(this,arguments)}function z(){return(z=s(f().m(function e(t,n,r){var i,o,a;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===r&&(r={}),o=null!=(i=r.stxerApi)?i:b,e.n=1,fetch(o+"/devtools/v2/simulations/"+t,{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((a=e.v).ok){e.n=2;break}return e.n=2,U("Failed to submit simulation steps",a);case 2:return e.a(2,a.json())}},e)}))).apply(this,arguments)}function K(){return(K=s(f().m(function e(t,n){var r,i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:b,e.n=1,fetch(i+"/devtools/v2/simulations/"+t,{method:"GET",headers:{Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=2;break}return e.n=2,U("Failed to get simulation result",o);case 2:return e.a(2,o.json())}},e)}))).apply(this,arguments)}function H(){return(H=s(f().m(function e(t,n){var r,i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===n&&(n={}),i=null!=(r=n.stxerApi)?r:b,e.n=1,fetch(i+"/devtools/v2/simulations/"+t+"/tip",{method:"GET",headers:{Accept:"application/json"}});case 1:if((o=e.v).ok){e.n=2;break}return e.n=2,U("Failed to get simulation tip",o);case 2:return e.a(2,o.json())}},e)}))).apply(this,arguments)}function D(e,t,n){return F.apply(this,arguments)}function F(){return(F=s(f().m(function e(t,n,r){var i,o,a;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===r&&(r={}),o=null!=(i=r.stxerApi)?i:b,e.n=1,fetch(o+"/devtools/v2/simulations/"+t+"/reads",{method:"POST",body:JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}});case 1:if((a=e.v).ok){e.n=2;break}return e.n=2,U("Failed to batch reads from simulation",a);case 2:return e.a(2,a.json())}},e)}))).apply(this,arguments)}function J(t,n){var o=i.c32addressDecode(n),a=o[0],s=o[1];switch(a){case r.AddressVersion.MainnetSingleSig:case r.AddressVersion.TestnetSingleSig:t.auth.spendingCondition.hashMode=e.AddressHashMode.P2PKH,t.auth.spendingCondition.signer=s;break;case r.AddressVersion.MainnetMultiSig:case r.AddressVersion.TestnetMultiSig:var c=t.auth.spendingCondition;t.auth.spendingCondition={hashMode:e.AddressHashMode.P2SH,signer:s,fields:[],signaturesRequired:0,nonce:c.nonce,fee:c.fee};break;default:throw new Error("unsupported address version: "+a)}return t}function G(e){return W.apply(this,arguments)}function W(){return(W=s(f().m(function t(n){var r,i,o,a,s,c,u;return f().w(function(t){for(;;)switch(t.n){case 0:if(a=n.contract.split("."),s=a[0],c=a[1]){t.n=1;break}throw new Error('bad contract id "'+n.contract+'" — expected SP….name');case 1:return t.n=2,e.makeUnsignedContractCall({contractAddress:s,contractName:c,functionName:n.functionName,functionArgs:n.functionArgs,fee:null!=(r=n.fee)?r:1e3,nonce:n.nonce,publicKey:"0".repeat(66),network:null!=(i=n.network)?i:"mainnet",postConditionMode:null!=(o=n.postConditionMode)?o:e.PostConditionMode.Allow});case 2:return J(u=t.v,n.sender),t.a(2,e.serializeTransaction(u))}},t)}))).apply(this,arguments)}var X=function(){function t(e){var t,n,r,i;void 0===e&&(e={}),this.apiEndpoint=void 0,this.stacksNodeAPI=void 0,this.network=void 0,this.skipTracing=void 0,this.block=Number.NaN,this.sender="",this.steps=[],this.network=null!=(t=e.network)?t:"mainnet";var o="testnet"===this.network;this.apiEndpoint=null!=(n=e.apiEndpoint)?n:o?m:y,this.stacksNodeAPI=null!=(r=e.stacksNodeAPI)?r:o?"https://api.testnet.hiro.so":"https://api.hiro.so",this.skipTracing=null!=(i=e.skipTracing)&&i}t.new=function(e){return new t(e)};var i=t.prototype;return i.useBlockHeight=function(e){return this.block=e,this},i.withSender=function(e){return this.sender=e,this},i.inlineSimulation=function(e){return this.steps.push({simulationId:e}),this},i.addSTXTransfer=function(e){var t,n;if(null==e.sender&&""===this.sender)throw new Error("Please specify a sender with useSender or adding a sender paramenter");return this.steps.push(u({},e,{sender:null!=(t=e.sender)?t:this.sender,fee:null!=(n=e.fee)?n:0})),this},i.addContractCall=function(e){var t,n;if(null==e.sender&&""===this.sender)throw new Error("Please specify a sender with useSender or adding a sender paramenter");return this.steps.push(u({},e,{sender:null!=(t=e.sender)?t:this.sender,fee:null!=(n=e.fee)?n:0})),this},i.addContractDeploy=function(t){var n,r,i;if(null==t.deployer&&""===this.sender)throw new Error("Please specify a deployer with useSender or adding a deployer paramenter");return this.steps.push(u({},t,{deployer:null!=(n=t.deployer)?n:this.sender,fee:null!=(r=t.fee)?r:0,clarity_version:null!=(i=t.clarity_version)?i:e.ClarityVersion.Clarity5})),this},i.addEvalCode=function(e,t){return this.steps.push({contract_id:e,code:t}),this},i.addMapRead=function(e,t,n){return this.steps.push({contract_id:e,code:"(map-get "+t+" "+n+")"}),this},i.addVarRead=function(e,t){return this.steps.push({contract_id:e,code:"(var-get "+t+")"}),this},i.addSetContractCode=function(t){var n;return this.steps.push({type:"SetContractCode",contract_id:t.contract_id,source_code:t.source_code,clarity_version:null!=(n=t.clarity_version)?n:e.ClarityVersion.Clarity5}),this},i.addReads=function(e){return this.steps.push({type:"Reads",reads:e}),this},i.addTenureExtend=function(e){return void 0===e&&(e="Extended"),this.steps.push({type:"TenureExtend",cause:e}),this},i.addAdvanceBlocks=function(e){return this.steps.push({type:"AdvanceBlocks",request:e}),this},i.getBlockInfo=function(){var e=s(f().m(function e(){var t;return f().w(function(e){for(;;)switch(e.n){case 0:if(!Number.isNaN(this.block)){e.n=2;break}return e.n=1,n.getNodeInfo({stacksEndpoint:this.stacksNodeAPI});case 1:this.block=e.v.stacks_tip_height;case 2:return e.n=3,n.richFetch(this.stacksNodeAPI+"/extended/v1/block/by_height/"+this.block+"?unanchored=true").then(function(e){return e.json()});case 3:if((t=e.v).height===this.block&&"string"==typeof t.hash&&t.hash.startsWith("0x")){e.n=4;break}throw new Error("failed to get block info for block height "+this.block);case 4:return e.a(2,{block_height:this.block,block_hash:t.hash.substring(2),index_block_hash:t.index_block_hash.substring(2)})}},e,this)}));return function(){return e.apply(this,arguments)}}(),i.run=function(){var t=s(f().m(function t(){var i,o,a,l,p,h,d,v,y,m,b,w,g,k,x,A,S,T,E=this;return f().w(function(t){for(;;)switch(t.n){case 0:return console.log("--------------------------------\nThis product can never exist without your support!\n\nWe receive sponsorship funds with:\nSP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER\n\nFeedbacks and feature requests are welcome.\nTo get in touch: contact@stxer.xyz\n--------------------------------"),t.n=1,this.getBlockInfo();case 1:i=t.v,console.log("Using block height "+i.block_height+" hash 0x"+i.block_hash+" to run simulation."),o=[],a=new Map,l=function(){var e=s(f().m(function e(t){var r,o,s;return f().w(function(e){for(;;)switch(e.n){case 0:if(null!=(r=a.get(t))){e.n=2;break}return o=E.stacksNodeAPI+"/v2/accounts/"+t+"?proof="+!1+"&tip="+i.index_block_hash,e.n=1,n.richFetch(o).then(function(e){return e.json()});case 1:return a.set(t,(s=e.v).nonce+1),e.a(2,s.nonce);case 2:return a.set(t,r+1),e.a(2,r)}},e)}));return function(t){return e.apply(this,arguments)}}(),p="mainnet"===this.network?r.STACKS_MAINNET:r.STACKS_TESTNET,this.stacksNodeAPI&&(p=u({},p,{client:u({},p.client,{baseUrl:this.stacksNodeAPI})})),h=c(this.steps);case 2:if((d=h()).done){t.n=14;break}if(!("simulationId"in(v=d.value))){t.n=3;break}throw new Error("inlineSimulation is not yet supported in V2 API. Please run simulations from scratch.");case 3:if(!("sender"in v)||!("function_name"in v)){t.n=6;break}return t.n=4,l(v.sender);case 4:return m=t.v,t.n=5,e.makeUnsignedContractCall({contractAddress:v.contract_id.split(".")[0],contractName:v.contract_id.split(".")[1],functionName:v.function_name,functionArgs:null!=(y=v.function_args)?y:[],nonce:m,network:p,publicKey:"",postConditionMode:e.PostConditionMode.Allow,fee:v.fee});case 5:J(b=t.v,v.sender),o.push({Transaction:_(b.serializeBytes())}),t.n=13;break;case 6:if(!("sender"in v)||!("recipient"in v)){t.n=9;break}return t.n=7,l(v.sender);case 7:return w=t.v,t.n=8,e.makeUnsignedSTXTokenTransfer({recipient:v.recipient,amount:v.amount,nonce:w,network:p,publicKey:"",fee:v.fee});case 8:J(g=t.v,v.sender),o.push({Transaction:_(g.serializeBytes())}),t.n=13;break;case 9:if(!("deployer"in v)){t.n=12;break}return t.n=10,l(v.deployer);case 10:return k=t.v,t.n=11,e.makeUnsignedContractDeploy({contractName:v.contract_name,codeBody:v.source_code,nonce:k,network:p,publicKey:"",postConditionMode:e.PostConditionMode.Allow,fee:v.fee,clarityVersion:v.clarity_version});case 11:J(x=t.v,v.deployer),o.push({Transaction:_(x.serializeBytes())}),t.n=13;break;case 12:"code"in v?(A=v.contract_id.split("."),S=A[0],o.push({Eval:[this.sender||S,"",S+"."+A[1],v.code]})):"SetContractCode"===v.type?o.push({SetContractCode:[v.contract_id,v.source_code,Y(v.clarity_version)]}):"Reads"===v.type?o.push({Reads:v.reads}):"TenureExtend"===v.type?o.push({TenureExtend:{cause:v.cause}}):"AdvanceBlocks"===v.type?o.push({AdvanceBlocks:v.request}):console.log("Invalid simulation step: "+v);case 13:t.n=2;break;case 14:return t.n=15,q({block_height:i.block_height,block_hash:i.block_hash,skip_tracing:this.skipTracing},{stxerApi:this.apiEndpoint});case 15:return T=t.v,t.n=16,R(T,{steps:o},{stxerApi:this.apiEndpoint});case 16:return console.log("Simulation will be available at: https://stxer.xyz/simulations/"+this.network+"/"+T),t.a(2,T)}},t,this)}));return function(){return t.apply(this,arguments)}}(),i.pipe=function(e){return e(this)},t}();function Y(t){switch(t){case e.ClarityVersion.Clarity1:return 1;case e.ClarityVersion.Clarity2:return 2;case e.ClarityVersion.Clarity3:return 3;case e.ClarityVersion.Clarity4:return 4;default:return 5}}function L(){return(L=s(f().m(function t(n,r,i){var o,a,s,c,l,p,h;return f().w(function(t){for(;;)switch(t.n){case 0:if(void 0===i&&(i={}),null==(o=r.nonce)){t.n=1;break}p=o,t.n=3;break;case 1:return h=Number,t.n=2,Z(n,r.sender,i);case 2:p=h(t.v);case 3:return a=p,t.n=4,G(u({},r,{nonce:a}));case 4:return s=t.v,t.n=5,R(n,{steps:[{Transaction:s}]},i);case 5:if("Transaction"in(c=t.v.steps[0])){t.n=6;break}throw new Error("expected Transaction step, got "+JSON.stringify(c).slice(0,200));case 6:if(!("Err"in c.Transaction)){t.n=7;break}throw new Error("Transaction Err: "+c.Transaction.Err);case 7:return t.a(2,{result:e.cvToString(e.deserializeCV((l=c.Transaction.Ok).result)),resultHex:l.result,vmError:l.vm_error,pcAborted:l.post_condition_aborted,receipt:l})}},t)}))).apply(this,arguments)}function Q(){return(Q=s(f().m(function t(n,r,i,o){var a,s,c;return f().w(function(t){for(;;)switch(t.n){case 0:return void 0===o&&(o={}),t.n=1,D(n,{readonly:[[r,"get-balance",e.serializeCV(e.Cl.principal(i))]]},o);case 1:if((s=null==(a=t.v.readonly)?void 0:a[0])&&"Ok"in s){t.n=2;break}throw new Error("get-balance("+r+") failed: "+JSON.stringify(s));case 2:if((c=e.deserializeCV(s.Ok)).type!==e.ClarityType.ResponseErr){t.n=3;break}return t.a(2,0n);case 3:if(c.type===e.ClarityType.ResponseOk){t.n=4;break}throw new Error("unexpected get-balance shape: "+e.cvToString(c));case 4:if(c.value.type===e.ClarityType.UInt){t.n=5;break}throw new Error("expected uint inside (ok …), got "+c.value.type);case 5:return t.a(2,BigInt(c.value.value))}},t)}))).apply(this,arguments)}function $(){return($=s(f().m(function e(t,n,r){var i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===r&&(r={}),e.n=1,D(t,{stx:[n]},r);case 1:if((o=null==(i=e.v.stx)?void 0:i[0])&&"Ok"in o){e.n=2;break}throw new Error("stx balance read for "+n+" failed");case 2:return e.a(2,BigInt(o.Ok))}},e)}))).apply(this,arguments)}function Z(e,t,n){return ee.apply(this,arguments)}function ee(){return(ee=s(f().m(function e(t,n,r){var i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===r&&(r={}),e.n=1,D(t,{nonces:[n]},r);case 1:if((o=null==(i=e.v.nonces)?void 0:i[0])&&"Ok"in o){e.n=2;break}return e.a(2,0n);case 2:return e.a(2,BigInt(o.Ok))}},e)}))).apply(this,arguments)}function te(){return(te=s(f().m(function t(n,r,i,o){var a,s;return f().w(function(t){for(;;)switch(t.n){case 0:return void 0===o&&(o={}),t.n=1,D(n,{vars:[[r,i]]},o);case 1:if((s=null==(a=t.v.vars)?void 0:a[0])&&"Ok"in s){t.n=2;break}throw new Error("var-get "+r+" "+i+" failed: "+JSON.stringify(s));case 2:return t.a(2,e.deserializeCV(s.Ok))}},t)}))).apply(this,arguments)}function ne(){return(ne=s(f().m(function e(t){var n,r,i,o;return f().w(function(e){for(;;)switch(e.n){case 0:return void 0===t&&(t={}),r=(null!=(n=t.stxerApi)?n:b)+"/sidecar/tip",e.n=1,fetch(r,{method:"GET",headers:{Accept:"application/json"}});case 1:if((i=e.v).ok){e.n=2;break}throw new Error("Failed to fetch tip: "+i.status+" "+i.statusText);case 2:return e.n=3,i.text();case 3:if((o=e.v).startsWith("{")){e.n=4;break}throw new Error("Invalid response from tip endpoint: "+o);case 4:return e.a(2,JSON.parse(o))}},e)}))).apply(this,arguments)}exports.DEFAULT_STXER_API=b,exports.STXER_API_MAINNET=y,exports.STXER_API_TESTNET=m,exports.SimulationBuilder=X,exports.SimulationError=I,exports.batchRead=x,exports.buildBitcoinHeader=function(e){var t,n,r,i,o,a=new Uint8Array(80),s=new DataView(a.buffer);s.setUint32(0,null!=(t=e.version)?t:536870912,!0),a.set(null!=(n=e.prevHash)?n:new Uint8Array(32),4),a.set(e.merkleRoot,36),s.setUint32(68,null!=(r=e.timestamp)?r:Math.floor(Date.now()/1e3),!0),s.setUint32(72,null!=(i=e.bits)?i:486604799,!0),s.setUint32(76,null!=(o=e.nonce)?o:0,!0);var c=T(a);return{header:a,hash:E(c),rawHash:c}},exports.buildUnsignedContractCallHex=G,exports.bytesToHex=_,exports.callContract=function(e,t,n){return L.apply(this,arguments)},exports.callReadonly=function(e){return P.apply(this,arguments)},exports.createSimulationSession=q,exports.forgeBitcoinTx=function(e){var t,n,r=[],i=function(e){var t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e>>>0,!0),t},o=function(e){var t=new Uint8Array(8),n=new DataView(t.buffer);return n.setUint32(0,Number(0xffffffffn&e),!0),n.setUint32(4,Number(e>>32n&0xffffffffn),!0),t},a=function(e){if(e<253)return new Uint8Array([e]);if(e<=65535){var t=new Uint8Array(3);return t[0]=253,new DataView(t.buffer).setUint16(1,e,!0),t}if(e<=4294967295){var n=new Uint8Array(5);return n[0]=254,new DataView(n.buffer).setUint32(1,e,!0),n}throw new Error("varint too large: "+e)};r.push(i(null!=(t=e.version)?t:2)),r.push(a(e.inputs.length));for(var s,u=c(e.inputs);!(s=u()).done;){var l,p=s.value;if(32!==p.prevTxid.length)throw new Error("prevTxid must be 32 bytes");r.push(p.prevTxid),r.push(i(p.prevVout)),r.push(a(p.scriptSig.length)),r.push(p.scriptSig),r.push(i(null!=(l=p.sequence)?l:4294967293))}r.push(a(e.outputs.length));for(var f,h=c(e.outputs);!(f=h()).done;){var d=f.value;r.push(o(d.value)),r.push(a(d.scriptPubKey.length)),r.push(d.scriptPubKey)}r.push(i(null!=(n=e.locktime)?n:0));for(var v=r.reduce(function(e,t){return e+t.length},0),y=new Uint8Array(v),m=0,b=0,w=r;b<w.length;b++){var g=w[b];y.set(g,m),m+=g.length}var k=T(y);return{bytes:y,txid:k,txidDisplay:E(k)}},exports.ftPrincipal=function(t){var n=t.split("."),r=n[0],i=n[1];if(!i)throw new Error('bad contract id "'+t+'" — expected SP….name');return e.Cl.contractPrincipal(r,i)},exports.getContractAST=function(e){return w.apply(this,arguments)},exports.getFtBalance=function(e,t,n,r){return Q.apply(this,arguments)},exports.getNonce=Z,exports.getSimulationResult=function(e,t){return K.apply(this,arguments)},exports.getSimulationTip=function(e,t){return H.apply(this,arguments)},exports.getStxBalance=function(e,t,n){return $.apply(this,arguments)},exports.getTip=function(e){return ne.apply(this,arguments)},exports.hexToBytes=function(e){var t=e.toLowerCase().replace(/^0x/,"");if(t.length%2!=0)throw new Error("odd-length hex");for(var n=new Uint8Array(t.length/2),r=0;r<n.length;r++)n[r]=Number.parseInt(t.slice(2*r,2*r+2),16);return n},exports.instantSimulation=function(e,t){return V.apply(this,arguments)},exports.merkleProof=function(e,t){if(t<0||t>=e.length)throw new Error("merkleProof: index "+t+" out of range "+e.length);for(var n=e.map(function(e){return new Uint8Array(e)}),r=[],i=t;n.length>1;){n.length%2==1&&n.push(n[n.length-1]),r.push(n[1^i]);for(var o=[],a=0;a<n.length;a+=2)o.push(T(N(n[a],n[a+1])));n=o,i=Math.floor(i/2)}return{proof:r,root:n[0]}},exports.opReturnScript=function(e){if(e.length>75)throw new Error("OP_RETURN data too long: "+e.length);var t=new Uint8Array(2+e.length);return t[0]=106,t[1]=e.length,t.set(e,2),t},exports.p2pkhScript=function(e){if(20!==e.length)throw new Error("pubKeyHash must be 20 bytes");var t=new Uint8Array(25);return t[0]=118,t[1]=169,t[2]=20,t.set(e,3),t[23]=136,t[24]=172,t},exports.p2wpkhScript=function(e){if(20!==e.length)throw new Error("pubKeyHash must be 20 bytes");var t=new Uint8Array(22);return t[0]=0,t[1]=20,t.set(e,2),t},exports.parseContract=function(e){return g.apply(this,arguments)},exports.parseSimulationEvent=function(e){return JSON.parse(e)},exports.readDataVar=function(e,t,n,r){return te.apply(this,arguments)},exports.readMap=function(e){return O.apply(this,arguments)},exports.readVariable=function(e){return j.apply(this,arguments)},exports.setSender=J,exports.sha256=S,exports.sha256d=T,exports.simulationBatchReads=D,exports.singleTxMerkleRoot=function(e){return new Uint8Array(e)},exports.submitSimulationSteps=R,exports.verifyMerkleProof=function(e,t,n,r){for(var i,o=new Uint8Array(e),a=t,s=c(n);!(i=s()).done;){var u=i.value;o=T(1&a?N(u,o):N(o,u)),a=Math.floor(a/2)}return function(e,t){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(o,r)};
|
|
2
2
|
//# sourceMappingURL=stxer.cjs.production.min.js.map
|