@truebit/cli 1.120.0-beta.225 → 1.120.0-beta.226
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/build/index.mjs +1 -1
- package/package.json +2 -2
package/build/index.mjs
CHANGED
|
@@ -242,7 +242,7 @@ ${n.data.payload.instrumentedTaskId}`);else throw"Malformed instrumentation serv
|
|
|
242
242
|
`+kr.cyan("=".repeat(60))+`
|
|
243
243
|
`)}catch(t){throw t instanceof Error?console.error(kr.red("Error fetching quota status: ")+t.message):console.error(kr.red("Error fetching quota status: ")+String(t)),t}}import*as Mke from"readline";import{ethers as aHt}from"ethers";async function Pke(){let t=Ro(),e=t!==null,n=Mke.createInterface({input:process.stdin,output:process.stdout}),r=a=>new Promise(s=>n.question(a,s)),i=0;if(e&&t.privateKey&&t.address)i=1;else if(e)switch(console.log(rr.SETUP_STEP1),(await r("Press [Y] to proceed or [N] to skip: ")).trim().toUpperCase()){case"Y":i=2;break;case"N":i=3;break;default:console.log("Invalid input. Please enter Y or N."),n.close();return}switch(i){case 1:lM(),console.log(rr.SETUP_STEP1_SCENARIO1_P1);break;case 2:{lM();let a=aHt.Wallet.createRandom(),s=a.privateKey,o=a.address;g_({privateKey:s,address:o}),console.log(`
|
|
244
244
|
Setting up your new wallet...`),console.log(rr.SETUP_STEP1_SCENARIO2(o));break}case 3:lM(),console.log(rr.SETUP_STEP1_SCENARIO3),process.exit(1);break;default:console.log("An unexpected error occurred.");break}n.close()}async function Rke(t){try{console.log("Fetching execution status...");let n=await(await kl()).get(`api/execution/${t}`).catch(of);if(n.data.message)throw n.data.message;console.log("Task execution status: ",n.data.status),n.data.output&&console.log("Task execution output: ",n.data.output)}catch(e){console.error(`Couldn't fetch execution status for executionId ${t}: ${e}`)}}var Dke=Rt(FS(),1),T_=class{tokens=[];authInputs;parse(e,n){let r=this.parseKeyValuePairs(n);if(e.length==0){this.authInputs=r;return}let i=Object.keys(r);if(e.every(a=>i.includes(a))){let a={};for(let s of e)a[s]=r[s];this.authInputs=a}else throw new Error(`Invalid authString: ${e} are required`)}parseKeyValuePairs(e){try{let n=e.split(","),r={};for(let i of n){let[a,s]=i.split(":");r[a.trim()]=s.trim()}return r}catch{throw new Error("Invalid auth string")}}},TM=class extends T_{tokens=["accessKey","secretKey"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return Dke.default.sign(e,{accessKeyId:this.authInputs.accessKey,secretAccessKey:this.authInputs.secretKey}).headers||{}}},CM=class extends T_{tokens=["username","password"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return{Authorization:`Basic ${btoa(`${this.authInputs.username}:${this.authInputs.password}`)}`}}},OM=class extends T_{tokens=[];constructor(e){super(),this.parse([],e)}authHeaders(e){return{...this.authInputs}}};var Oc;(function(t){t.AWS_SIGNATURE="aws-signature",t.BASIC_AUTH="basic-auth",t.CUSTOM_HEADER="custom-header"})(Oc||(Oc={}));var tJ=(t,e)=>{switch(t){case Oc.AWS_SIGNATURE:return new TM(e);case Oc.BASIC_AUTH:return new CM(e);case Oc.CUSTOM_HEADER:return new OM(e);default:throw new Error(`Invalid authentication method specified. Should be one of <${Object.values(Oc)}>`)}};import uHt from"chalk";import{ethers as cHt}from"ethers";import*as IM from"crypto";async function oHt(t){try{return(await t.get("/getkey")).data}catch(e){throw new Error(`Failed to get encryption key: ${e}`)}}function fHt(t,e){try{let n=Buffer.from(e,"base64"),r=IM.randomBytes(16),i=IM.createCipheriv("aes-256-cbc",n,r),a=Buffer.concat([i.update(t,"utf8"),i.final()]);return n.fill(0),{encrypted_authString:a.toString("base64"),iv:r.toString("base64")}}catch(n){throw n instanceof Error?new Error(`Failed to encrypt credentials: ${n.message}`):new Error(`Failed to encrypt credentials: ${n}`)}}async function kke(t,e){let n=await oHt(t),r=fHt(e,n.plaintext_key);return{encrypted_authString:r.encrypted_authString,encrypted_data_key:n.encrypted_key,iv:r.iv}}async function Nke(t,e,n,r,i,a,s){console.log("Deploying the API Authentication Credentials");try{if(!mke(a))throw"Invalid private key provided";if(!cHt.isAddress(s))throw"Invalid address provided";if(tJ(r,i),!Db(t))throw"Invalid taskId";let o=await CDe();console.log("Encrypting credentials...");let f=await kke(o,i);await o.post("credentials",{taskId:t,namespace:e,taskName:n,method:r,encrypted_authString:f.encrypted_authString,encrypted_data_key:f.encrypted_data_key,iv:f.iv}).catch(of),console.log("The encrypted credentials were deployed "+uHt.green("Successfully"))}catch(o){throw console.log(o),`There was an Error deploying credentials:
|
|
245
|
-
Couldn't push api credentials to remote server: ${o}`}}import{inspect as lWt}from"util";import ds from"ora";import{v4 as dWt}from"uuid";import{ethers as LM}from"ethers";var $ke={name:"@truebit/cli",version:"1.120.0-beta.
|
|
245
|
+
Couldn't push api credentials to remote server: ${o}`}}import{inspect as lWt}from"util";import ds from"ora";import{v4 as dWt}from"uuid";import{ethers as LM}from"ethers";var $ke={name:"@truebit/cli",version:"1.120.0-beta.226",private:!1,description:"truebit-cli is a basic command line that allows interaction between users and truebit nextgen node.",author:{name:"Truebit Co.",url:"https://truebit.io/"},license:"https://truebit.io/terms/",repository:{type:"git",url:"https://github.com/TruebitProtocol"},homepage:"https://truebit.io/",main:"build/index.mjs",module:"build/index.mjs",types:"build/types/index.d.ts",type:"module",scripts:{prebuild:"rimraf build logs","prebuild:dev":"rimraf build logs","build:dev":"tsc && chmod +x build/index.mjs",build:"NODE_ENV=production node esbuild.config.mjs && chmod +x build/index.mjs",dev:"export NODE_ENV=development && npx nodemon",test:"vitest run --passWithNoTests tests/"},dependencies:{axios:"1.13.1",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.2",ethers:"6.15.0",figlet:"1.9.3","openapi-enforcer":"1.23.0",ora:"9.0.0","public-ip":"8.0.0","ts-retry":"6.0.0",uuid:"13.0.0"},bin:{truebit:"build/index.mjs"},files:["build"],devDependencies:{"@types/figlet":"1.7.0","@vitest/coverage-v8":"3.2.4",esbuild:"^0.25.11",typescript:"5.9.3",vitest:"3.2.4"},engines:{node:">=22.13.0"}};import{createInterface as bHt}from"node:readline/promises";import L1 from"chalk";import C_ from"axios";import{ethers as nJ}from"ethers";import{randomBytes as dHt}from"crypto";import{v4 as pHt}from"uuid";import{ethers as MM}from"ethers";async function Bke(t,e=Gt("blockchainEnv")){x_(t);let n=Dr(e,Mt.AVAX),r=MM.keccak256(MM.toUtf8Bytes(t));return await n.authorization.registerAuthorization(r),r}async function PM(t,e,n=Gt("blockchainEnv"),r=Gt("address")){x_(t);let i=Dr(n,Mt.AVAX),a=await i.authorization.getEIP712Domain(),s=await i.authorization.nonces(r),o=Math.floor(Date.now()/1e3)+3600,f={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},u=MM.keccak256(MM.toUtf8Bytes(t)),c={user:r,apiKeyHash:u,nonce:Number(s),deadline:o},l=await i.utils.signMeta(a,f,c);return(await bke(r,u,o,l,e)).status==201?u:null}import{isTooManyTries as Fke,retryAsync as Lke}from"ts-retry";var qke="0x0000000000000000000000000000000000000000";async function Uke(t){let e=!0;return t===""?(e=!1,console.log("An email address is required. Please provide your email address to proceed.")):new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(t)?await hHt(t)&&(e=!1,console.log("The provided email address is already in use. Please enter a different email address.")):(e=!1,console.log("The email address provided is not valid. Please try again.")),e}function Rm(t){return t==="Y"||t==="N"}function jke(t){return!nJ.isAddress(t)||t.length!==42||!t.startsWith("0x")}async function Vke(){let t=await mHt();try{if(!await PM(t,!0))throw Error("The API key could not been registered.")}catch(e){let n=e.message;if(n)throw Error(`There was an error registering the API key -> ${n}`)}return t}async function zke(){let t=await yHt();try{if(!await SM(t,!0))throw Error("The namespace could not been registered.")}catch(e){let n=e.message,r=n?n.match(/execution reverted: "(.*?)" /)?.[1]:null;if(r)throw Error(`There was an error registering the namespace -> ${r}`);if(n)throw Error(`There was an error registering the namespace -> ${n}`)}return t}async function hHt(t){let e=await Dl();try{return(await e.get(`userexistence/${t}`)).data===!0}catch(n){if(C_.isAxiosError(n)&&n.response?.status===404&&typeof n.response?.data?.message=="string"&&n.response.data.message.includes("User not found"))return!1;throw n}}async function RM(t,e){try{let n={message:"I am a Truebit User"};if(!e)throw Error("Secret.json does not exists");let r=e.privateKey,i=e.address,a=M0.createSignedBody(n,r,i);return(await(await Dl()).get(`user/${t}`,{headers:{"truebit-auth":JSON.stringify(a)}})).data}catch(n){if(C_.isAxiosError(n)&&n.response?.status===401&&n.response?.data.message.includes("Entitlement Validation Error")||C_.isAxiosError(n)&&n.response?.status==404&&n.response?.data.message&&n.response?.data.message.includes("User not found"))return null;throw C_.isAxiosError(n)?n.response?Error(`The server responding with an error -> ${n.response.data.message||n.response.status+" - "+n.response.statusText}`):n.request?Error(`The server is not responding -> ${n.message}`):Error(`There was an error in the communication with the server -> ${n.message}`):Error(typeof n=="string"?`There was an error in the communication with the server -> ${n}`:"There was an error in the communication with the server.")}}async function Hke(t){try{return await(await Dl()).post("user/register",t)}catch(e){throw C_.isAxiosError(e)?e.response?Error(`The server responding with an error -> ${e.response.data.message||e.response.status+" - "+e.response.statusText}`):e.request?Error(`The server is not responding -> ${e.message}`):Error(`There was an error in the communication with the server -> ${e.message}`):Error(typeof e=="string"?`There was an error in the communication with the server -> ${e}`:"There was an error in the communication with the server.")}}async function mHt(){let t=Gt("blockchainEnv"),e=Dr(t,Mt.AVAX),n="";try{await Lke(async()=>{n=pHt();let r=nJ.keccak256(nJ.toUtf8Bytes(n));return await e.authorization.getPayerAddress(r)===qke},{delay:500,maxTry:5,until:r=>r===!0})}catch(r){throw Fke(r)?Error("Attempts to generate unique Api Key for the user exhausted."):r}return n}async function yHt(){let t=Gt("blockchainEnv"),e=Dr(t,Mt.AVAX),n="";try{await Lke(async()=>(n=dHt(4).toString("hex"),await e.taskRegistry.getNamespaceOwner(n)===qke),{delay:500,maxTry:5,until:r=>r===!0})}catch(r){throw Fke(r)?Error("Attempts to generate unique namespace for the user exhausted."):r}return n}function Wke(t){t.fullNameAnswer="",t.emailAddressAnswer="",t.companyNameAnswer="",t.jobPositionAnswer="",t.eulaAnswer="",t.confirmRegistration=""}import gHt from"ora";import*as DM from"os";async function Gke(t,e,n){let r=Ro(),i=r!==null,a=0,s,o=bHt({input:process.stdin,output:process.stdout,terminal:!0});switch(i&&(jke(r.address)?a=1:(s=await RM(r.address,r),s?a=2:a=3)),a){case 1:console.log("The wallet set in the configuration must be a valid ethereum address. (ENS not supported yet)");break;case 2:console.log(rr.SETUP_STEP1_SCENARIO1_P2(s));break;case 3:{console.log(rr.SETUP_STEP2_SCENARIO3_P1),console.log();let f={user_ip:t,date_time:Ri(),os_version:DM.type+"_"+DM.release,node_version:process.version,cli_version:e};await n.sendEventToMixpanel("user_registration_begin",f);let u={confirmRegistration:"",fullNameAnswer:"",emailAddressAnswer:"",companyNameAnswer:"",jobPositionAnswer:"",eulaAnswer:""};try{for(;u.confirmRegistration!="Y";){for(u.fullNameAnswer=(await o.question(L1.bold(" 1. Full Name: "))).trim();u.fullNameAnswer==="";)console.log("Your full name is required. Please provide your first and last name to proceed."),u.fullNameAnswer=(await o.question(L1.bold(" 1. Full Name: "))).trim();for(u.emailAddressAnswer=(await o.question(L1.bold(" 2. Email Address: "))).trim();!await Uke(u.emailAddressAnswer);)u.emailAddressAnswer=(await o.question(L1.bold(" 2. Email Address: "))).trim();for(u.companyNameAnswer=(await o.question(L1.bold(" 3. Company Name: "))).trim(),u.jobPositionAnswer=(await o.question(L1.bold(" 4. Job Position: "))).trim();!Rm(u.eulaAnswer);)u.eulaAnswer=(await o.question(L1.bold(` 5. Accept EULA? [Y|N] (${rr.EULA_TERMS_LINK}): `))).toUpperCase();if(u.eulaAnswer=="N"){console.log(rr.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!Rm(u.confirmRegistration);)console.log(`
|
|
246
246
|
Is the information provided above correct?`),u.confirmRegistration=(await o.question(L1.bold("Press [Y] to confirm or [N] to edit: "))).toUpperCase();u.confirmRegistration=="N"&&(console.log(`
|
|
247
247
|
Please provide the following information:`),Wke(u))}}catch(d){if(d.name==="AbortError"||d.message.includes("Ctrl+C")){let p=d.message,h=f;h.error_details=p,h.date_time=Ri();let g={fullname:u.fullNameAnswer,email:u.emailAddressAnswer,company:u.companyNameAnswer,role:u.jobPositionAnswer};h.user_info=JSON.stringify(g),await n.sendEventToMixpanel("user_registration_failed",h),process.exit(0)}}if(u.eulaAnswer=="N")break;let c=f;console.log(),console.log("By completing registration, you'll be automatically subscribed to our newsletter."),console.log("To opt-out, please follow the steps described in our documentation portal."),console.log();let l=gHt({text:L1.bold("... registering your account."),stream:process.stdout}).start();try{let d=await zke(),p=await Vke(),h={name:u.fullNameAnswer,email:u.emailAddressAnswer,walletAddress:r?.address,company:u.companyNameAnswer,jobDescription:u.jobPositionAnswer,EULA:M0.createSignedBody({ip:await mM(),date:new Date().toISOString()},r.privateKey),defaultNamespace:d,defaultApiKey:p};await Hke(h),l.stop(),console.log(rr.SETUP_STEP2_SCENARIO3_P2(u,r.address,d,p)),c.distinct_id=h.walletAddress,c.date_time=Ri(),c.fullname=h.name,c.email=h.email,c.company=h.company,c.role=h.jobDescription,c.namespace=h.defaultNamespace,c.api_key=p,c.wallet_address=h.walletAddress,await n.sendEventToMixpanel("user_registration_success",c),await n.registerUserMixpanel(c.wallet_address,_Ht(c))}catch(d){l.stop();let p=d.message,h=f;h.error_details=p,h.date_time=Ri();let g={fullname:u.fullNameAnswer,email:u.emailAddressAnswer,company:u.companyNameAnswer,role:u.jobPositionAnswer};h.user_info=JSON.stringify(g),await n.sendEventToMixpanel("user_registration_failed",h);let x=p?p.match(/CreateUserValidation - (.*?.*)/)?.[1]:null;if(x)throw Error(x);if(p.includes("Sender doesn't have enough funds to send tx"))throw Error("We are currently experiencing technical difficulties. Please try again later.");console.error(rr.SETUP_STEP2_UNHANDLED_ERROR),process.exit(1)}finally{l.clear()}break}default:throw Error("An unexpected error occurred.")}o.close()}function _Ht(t){return{apiKey:t.api_key,name:t.fullname,email:t.email,ip:t.user_ip,company:t.company,role:t.role,namespace:t.namespace,walletAddress:t.wallet_address}}import{setDefaultAutoSelectFamily as pWt}from"node:net";import vHt from"chalk";import{createInterface as AHt}from"node:readline/promises";import*as kM from"os";async function Kke(t,e,n){let r=Ro(),i=r!==null,a=0;switch(i?i&&!r.eula?a=2:a=3:a=1,a){case 1:case 2:{let s=AHt({input:process.stdin,output:process.stdout,terminal:!0}),o="",f={user_ip:t,date_time:Ri(),os_version:kM.type+"_"+kM.release,node_version:process.version,cli_version:e};for(console.log(rr.EULA_INSTALLATION);!Rm(o);)o=(await s.question(vHt.bold(`
|
|
248
248
|
Have you read, and do you accept the Terms of Use? [Y|N]: `))).toUpperCase(),await n.sendEventToMixpanel("TOS_shown",f);if(o=="N")throw f.date_time=Ri(),await n.sendEventToMixpanel("TOS_rejected",f),rr.EULA_INSTALLATION_NO_ACCEPTED;f.date_time=Ri(),await n.sendEventToMixpanel("TOS_accepted",f);let u=Math.round(new Date().getTime()).toString();if(a===1){let c={...wb(),eula:u};xDe(c)}else a===2&&g_({eula:u});s.close()}break;case 3:default:break}}async function uf(t=!1){let e=Ro(),n=e!==null,r=null,i=0;switch(n?n&&(!e.privateKey||!e.address)?i=2:(r=await RM(e.address,e),r?i=4:i=3):i=1,i){case 1:case 2:case 3:console.log(rr.USER_NO_REGISTERED),process.exit(1);break;case 4:t&&console.log(`You are logged in as: ${r?.name} - ${r?.email}`);break}}import{createInterface as wHt}from"node:readline/promises";import EHt from"chalk";async function Yke(){console.log(EHt.bold(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truebit/cli",
|
|
3
|
-
"version": "1.120.0-beta.
|
|
3
|
+
"version": "1.120.0-beta.226",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "truebit-cli is a basic command line that allows interaction between users and truebit nextgen node.",
|
|
6
6
|
"author": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=22.13.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9f183faa7f00c3dcc1f1c6f2ce7e86de3711d18f"
|
|
58
58
|
}
|