@truebit/cli 1.120.0-beta.317 → 1.120.0-beta.318

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.
Files changed (2) hide show
  1. package/build/index.mjs +1 -1
  2. package/package.json +2 -2
package/build/index.mjs CHANGED
@@ -502,7 +502,7 @@ Opening Truebit Web UI...`)),console.log(oh.white("URL: ")+oh.yellow(d)),await n
502
502
  Browser opened successfully.`)):(console.log(oh.yellow(`
503
503
  Could not open browser automatically.`)),console.log(oh.white("Copy and paste the URL above into your browser."))),console.log(oh.gray(`
504
504
  This login expires in 30 days.
505
- `))}function rpa(e){switch(e){case"local":case"testnet":return"http://localhost:5173";case"staging":return"https://dashboard-staging.truebit.network";default:return"https://dashboard.truebit.network"}}function npa(e){return new Promise(t=>{let r;switch(tpa()){case"darwin":r=`open "${e}"`;break;case"win32":r=`start "" "${e}"`;break;default:r=`xdg-open "${e}"`;break}epa(r,n=>{t(!n)})})}hs();async function lDt(e){try{console.log("Fetching execution status...");let r=await(await sl()).get(`api/execution/${e}`).catch(e0);if(r.data.message)throw r.data.message;console.log("Task execution status: ",r.data.status),r.data.output&&console.log("Task execution output: ",r.data.output)}catch(t){console.error(`Couldn't fetch execution status for executionId ${e}: ${t}`)}}import pDt from"chalk";import{ethers as opa}from"ethers";hs();import*as fZ from"crypto";import apa from"axios";import Qxe from"chalk";function dDt(e){if(apa.isAxiosError(e)&&e.response?.data){let t=e.response.data;return console.log(Qxe.red(t.message)),typeof t=="string"?t:t.message||JSON.stringify(t)}return e instanceof Error?e.message:String(e)}async function ipa(e,t){try{let r=t0({namespace:t});return(await e.post("getkey",r)).data}catch(r){return dDt(r),console.error(Qxe.red("Failed to retrieve encryption key from Hub-TEE-KMS. Please try again")),null}}function spa(e,t){try{let r=Buffer.from(t,"base64"),n=fZ.randomBytes(16),a=fZ.createCipheriv("aes-256-cbc",r,n),i=Buffer.concat([a.update(e,"utf8"),a.final()]);return r.fill(0),{encrypted_authString:i.toString("base64"),iv:n.toString("base64")}}catch{return null}}async function cDt(e,t,r){try{let n=await ipa(e,r);if(!n)return null;let a=spa(t,n.plaintext_key);return a?{encrypted_authString:a.encrypted_authString,encrypted_data_key:n.encryption_key,iv:a.iv}:null}catch(n){return dDt(n),console.error(Qxe.red("Failed to encrypt credentials. Please try again.")),null}}async function mDt(e,t,r,n,a,i,s){console.log("Deploying the API Authentication Credentials");try{if(!z$t(i))throw"Invalid private key provided";if(!opa.isAddress(s))throw"Invalid address provided";if(ste(n,a),!n8(e))throw"Invalid taskId";let o=await ZWe();console.log("Encrypting credentials...");let u=await cDt(o,a,t);if(!u)return;let l=t0({taskId:e,namespace:t,taskName:r,method:n,encrypted_authString:u.encrypted_authString,encrypted_data_key:u.encrypted_data_key,iv:u.iv});await o.post("credentials",l).catch(e0),console.log("The encrypted credentials were deployed "+pDt.green("Successfully"))}catch(o){let u=o instanceof Error?o.message:String(o);console.error(pDt.red(u));return}}import Qc from"colors";hs();var fpa=3e4,uZ=null;async function hDt(){if(uZ&&uZ.expiresAt>Date.now())return uZ.chains;let r=(await(await Qy()).get("chains")).data??[];return uZ={chains:r,expiresAt:Date.now()+fpa},r}async function yDt(){let e;try{e=await hDt()}catch(a){console.error(Qc.red(`Failed to fetch supported chains: ${a instanceof Error?a.message:String(a)}`)),process.exit(1)}if(e.length===0){console.log(Qc.yellow("No chains configured on this deployment."));return}let t=e.map(a=>({chainId:String(a.chainId),name:a.displayName,symbol:a.symbol,network:a.isTestnet?"testnet":"mainnet"})).sort((a,i)=>a.name.localeCompare(i.name)),r={chainId:Math.max(8,...t.map(a=>a.chainId.length)),name:Math.max(4,...t.map(a=>a.name.length)),symbol:Math.max(6,...t.map(a=>a.symbol.length)),network:Math.max(7,...t.map(a=>a.network.length))},n=(a,i)=>a+" ".repeat(Math.max(0,i-a.length));console.log(Qc.cyan(n("chainId",r.chainId)+" "+n("name",r.name)+" "+n("symbol",r.symbol)+" network")),console.log(Qc.gray("-".repeat(r.chainId)+" "+"-".repeat(r.name)+" "+"-".repeat(r.symbol)+" "+"-".repeat(r.network)));for(let a of t)console.log(Qc.yellow(n(a.chainId,r.chainId))+" "+Qc.white(n(a.name,r.name))+" "+Qc.gray(n(a.symbol,r.symbol))+" "+(a.network==="mainnet"?Qc.green(a.network):Qc.gray(a.network)))}import{inspect as Zma}from"util";import ts from"ora";import{v4 as Xma}from"uuid";import{ethers as wZ}from"ethers";var bDt={name:"@truebit/cli",version:"1.120.0-beta.317",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.16.1",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.3",ethers:"6.16.0",figlet:"1.11.0","form-data":"4.0.5","openapi-enforcer":"1.23.0",ora:"9.4.0","public-ip":"8.0.0","ts-retry":"6.0.0",uuid:"14.0.0"},bin:{truebit:"build/index.mjs"},files:["build"],devDependencies:{"@types/figlet":"1.7.0","@vitest/coverage-v8":"4.1.6",esbuild:"0.28.0",typescript:"5.9.3",vitest:"4.1.6"},engines:{node:">=22.13.0"}};vi();hs();zo();vi();import{createInterface as hpa}from"node:readline/promises";import ep from"chalk";hs();import Vw from"axios";import{ethers as a8}from"ethers";import{randomBytes as lpa}from"crypto";import{v4 as dpa}from"uuid";vi();import{ethers as lZ}from"ethers";async function vDt(e){sh(e);let t=$i(),r=en(t,St.AVAX),n=lZ.keccak256(lZ.toUtf8Bytes(e));return await r.authorization.registerAuthorization(n),n}async function eEe(e,t,r=Jt("address")){sh(e);let n=$i(),a=en(n,St.AVAX),i=await a.authorization.getEIP712Domain(),s=await a.authorization.nonces(r),o=Math.floor(Date.now()/1e3)+3600,u={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},l=lZ.keccak256(lZ.toUtf8Bytes(e)),d={user:r,apiKeyHash:l,nonce:Number(s),deadline:o};if(!a.utils)throw new Error("Private key is required for signing operations");let c=await a.utils.signMeta(i,u,d);return(await G$t(r,l,o,c,t)).status==201?l:null}vi();zo();import{isTooManyTries as gDt,retryAsync as _Dt}from"ts-retry";var xDt="0x0000000000000000000000000000000000000000";async function EDt(e){let t=!0;return e===""?(t=!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(e)?await cpa(e)&&(t=!1,console.log("The provided email address is already in use. Please enter a different email address.")):(t=!1,console.log("The email address provided is not valid. Please try again.")),t}function fh(e){return e==="Y"||e==="N"}function wDt(e){return!a8.isAddress(e)||e.length!==42||!e.startsWith("0x")}async function SDt(){let e=$i(),t=en(e,St.AVAX),r=Jt("address"),n=await mpa(),a=await ppa();sh(a);let i=a8.keccak256(a8.toUtf8Bytes(a)),s=Math.floor(Date.now()/1e3)+3600,o=await t.taskRegistry.getEIP712Domain(),u=await t.authorization.getEIP712Domain(),l={RegisterTaskNamespaceMeta:[{name:"user",type:"address"},{name:"namespace",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},d={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},c=BigInt(await t.taskRegistry.nonces(r)),v=await t.authorization.nonces(r),m={user:a8.getAddress(r),namespace:n,nonce:c,deadline:s},p={user:r,apiKeyHash:i,nonce:Number(v),deadline:s};if(!t.utils)throw new Error("Private key is required for signing operations");let y=await t.utils.signMeta(o,l,m),b=await t.utils.signMeta(u,d,p),g={user:r,namespace:n,apiKeyHash:i,namespaceSignature:y,apiKeySignature:b,namespaceDeadline:s,apiKeyDeadline:s};try{let x=await K$t(g);if(x.status!==201)throw new Error("Registration failed with unexpected status");if(!x.data.namespaceRegistration.success)throw new Error("Namespace registration failed");if(!x.data.apiKeyRegistration.success)throw new Error("API key registration failed");return{namespace:n,apiKey:a,hashedApiKey:i}}catch(x){let E=x.message;throw new Error(`Combined registration failed: ${E}`)}}async function cpa(e){let t=await ms();try{return(await t.get(`userexistence/${e}`)).data===!0}catch(r){if(Vw.isAxiosError(r)&&r.response?.status===404&&typeof r.response?.data?.message=="string"&&r.response.data.message.includes("User not found"))return!1;throw r}}async function dZ(e,t){try{let r={message:"I am a Truebit User"};if(!t)throw Error("Secret.json does not exists");let n=t.privateKey,a=t.address,i=Sa.createSignedBody(r,n,a);return(await(await ms()).get(`user/${e}`,{headers:{"truebit-auth":JSON.stringify(i)}})).data}catch(r){if(Vw.isAxiosError(r)&&r.response?.status===401&&r.response?.data.message.includes("Entitlement Validation Error")||Vw.isAxiosError(r)&&r.response?.status==404&&r.response?.data.message&&r.response?.data.message.includes("User not found"))return null;throw Vw.isAxiosError(r)?r.response?Error(`The server responding with an error -> ${r.response.data.message||r.response.status+" - "+r.response.statusText}`):r.request?Error(`The server is not responding -> ${r.message}`):Error(`There was an error in the communication with the server -> ${r.message}`):Error(typeof r=="string"?`There was an error in the communication with the server -> ${r}`:"There was an error in the communication with the server.")}}async function TDt(e){try{return await(await ms()).post("user/register",e)}catch(t){throw Vw.isAxiosError(t)?t.response?Error(`The server responding with an error -> ${t.response.data.message||t.response.status+" - "+t.response.statusText}`):t.request?Error(`The server is not responding -> ${t.message}`):Error(`There was an error in the communication with the server -> ${t.message}`):Error(typeof t=="string"?`There was an error in the communication with the server -> ${t}`:"There was an error in the communication with the server.")}}async function ppa(){let e=$i(),t=en(e,St.AVAX),r="";try{await _Dt(async()=>{r=dpa();let n=a8.keccak256(a8.toUtf8Bytes(r));return await t.authorization.getPayerAddress(n)===xDt},{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw gDt(n)?Error("Attempts to generate unique Api Key for the user exhausted."):n}return r}async function mpa(){let e=$i(),t=en(e,St.AVAX),r="";try{await _Dt(async()=>(r=lpa(4).toString("hex"),await t.taskRegistry.getNamespaceOwner(r)===xDt),{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw gDt(n)?Error("Attempts to generate unique namespace for the user exhausted."):n}return r}function ADt(e){e.fullNameAnswer="",e.emailAddressAnswer="",e.companyNameAnswer="",e.jobPositionAnswer="",e.eulaAnswer="",e.confirmRegistration=""}zo();kp();import ypa from"ora";import*as cZ from"os";async function IDt(e,t,r){let n=ys(),a=n!==null,i=0,s,o=hpa({input:process.stdin,output:process.stdout,terminal:!0});switch(a&&(wDt(n.address)?i=1:(s=await dZ(n.address,n),s?i=2:i=3)),i){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(dn.SETUP_STEP1_SCENARIO1_P2(s));break;case 3:{console.log(dn.SETUP_STEP2_SCENARIO3_P1),console.log();let u={user_ip:e,date_time:ua(),os_version:cZ.type+"_"+cZ.release,node_version:process.version,cli_version:t};await r.sendEventToMixpanel("user_registration_begin",u);let l={confirmRegistration:"",fullNameAnswer:"",emailAddressAnswer:"",companyNameAnswer:"",jobPositionAnswer:"",eulaAnswer:""};try{for(;l.confirmRegistration!="Y";){for(l.fullNameAnswer=(await o.question(ep.bold(" 1. Full Name: "))).trim();l.fullNameAnswer==="";)console.log("Your full name is required. Please provide your first and last name to proceed."),l.fullNameAnswer=(await o.question(ep.bold(" 1. Full Name: "))).trim();for(l.emailAddressAnswer=(await o.question(ep.bold(" 2. Email Address: "))).trim();!await EDt(l.emailAddressAnswer);)l.emailAddressAnswer=(await o.question(ep.bold(" 2. Email Address: "))).trim();for(l.companyNameAnswer=(await o.question(ep.bold(" 3. Company Name: "))).trim(),l.jobPositionAnswer=(await o.question(ep.bold(" 4. Job Position: "))).trim();!fh(l.eulaAnswer);)l.eulaAnswer=(await o.question(ep.bold(` 5. Accept EULA? [Y|N] (${dn.EULA_TERMS_LINK}): `))).toUpperCase();if(l.eulaAnswer=="N"){console.log(dn.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!fh(l.confirmRegistration);)console.log(`
505
+ `))}function rpa(e){switch(e){case"local":case"testnet":return"http://localhost:5173";case"staging":return"https://dashboard-staging.truebit.network";default:return"https://dashboard.truebit.network"}}function npa(e){return new Promise(t=>{let r;switch(tpa()){case"darwin":r=`open "${e}"`;break;case"win32":r=`start "" "${e}"`;break;default:r=`xdg-open "${e}"`;break}epa(r,n=>{t(!n)})})}hs();async function lDt(e){try{console.log("Fetching execution status...");let r=await(await sl()).get(`api/execution/${e}`).catch(e0);if(r.data.message)throw r.data.message;console.log("Task execution status: ",r.data.status),r.data.output&&console.log("Task execution output: ",r.data.output)}catch(t){console.error(`Couldn't fetch execution status for executionId ${e}: ${t}`)}}import pDt from"chalk";import{ethers as opa}from"ethers";hs();import*as fZ from"crypto";import apa from"axios";import Qxe from"chalk";function dDt(e){if(apa.isAxiosError(e)&&e.response?.data){let t=e.response.data;return console.log(Qxe.red(t.message)),typeof t=="string"?t:t.message||JSON.stringify(t)}return e instanceof Error?e.message:String(e)}async function ipa(e,t){try{let r=t0({namespace:t});return(await e.post("getkey",r)).data}catch(r){return dDt(r),console.error(Qxe.red("Failed to retrieve encryption key from Hub-TEE-KMS. Please try again")),null}}function spa(e,t){try{let r=Buffer.from(t,"base64"),n=fZ.randomBytes(16),a=fZ.createCipheriv("aes-256-cbc",r,n),i=Buffer.concat([a.update(e,"utf8"),a.final()]);return r.fill(0),{encrypted_authString:i.toString("base64"),iv:n.toString("base64")}}catch{return null}}async function cDt(e,t,r){try{let n=await ipa(e,r);if(!n)return null;let a=spa(t,n.plaintext_key);return a?{encrypted_authString:a.encrypted_authString,encrypted_data_key:n.encryption_key,iv:a.iv}:null}catch(n){return dDt(n),console.error(Qxe.red("Failed to encrypt credentials. Please try again.")),null}}async function mDt(e,t,r,n,a,i,s){console.log("Deploying the API Authentication Credentials");try{if(!z$t(i))throw"Invalid private key provided";if(!opa.isAddress(s))throw"Invalid address provided";if(ste(n,a),!n8(e))throw"Invalid taskId";let o=await ZWe();console.log("Encrypting credentials...");let u=await cDt(o,a,t);if(!u)return;let l=t0({taskId:e,namespace:t,taskName:r,method:n,encrypted_authString:u.encrypted_authString,encrypted_data_key:u.encrypted_data_key,iv:u.iv});await o.post("credentials",l).catch(e0),console.log("The encrypted credentials were deployed "+pDt.green("Successfully"))}catch(o){let u=o instanceof Error?o.message:String(o);console.error(pDt.red(u));return}}import Qc from"colors";hs();var fpa=3e4,uZ=null;async function hDt(){if(uZ&&uZ.expiresAt>Date.now())return uZ.chains;let r=(await(await Qy()).get("chains")).data??[];return uZ={chains:r,expiresAt:Date.now()+fpa},r}async function yDt(){let e;try{e=await hDt()}catch(a){console.error(Qc.red(`Failed to fetch supported chains: ${a instanceof Error?a.message:String(a)}`)),process.exit(1)}if(e.length===0){console.log(Qc.yellow("No chains configured on this deployment."));return}let t=e.map(a=>({chainId:String(a.chainId),name:a.displayName,symbol:a.symbol,network:a.isTestnet?"testnet":"mainnet"})).sort((a,i)=>a.name.localeCompare(i.name)),r={chainId:Math.max(8,...t.map(a=>a.chainId.length)),name:Math.max(4,...t.map(a=>a.name.length)),symbol:Math.max(6,...t.map(a=>a.symbol.length)),network:Math.max(7,...t.map(a=>a.network.length))},n=(a,i)=>a+" ".repeat(Math.max(0,i-a.length));console.log(Qc.cyan(n("chainId",r.chainId)+" "+n("name",r.name)+" "+n("symbol",r.symbol)+" network")),console.log(Qc.gray("-".repeat(r.chainId)+" "+"-".repeat(r.name)+" "+"-".repeat(r.symbol)+" "+"-".repeat(r.network)));for(let a of t)console.log(Qc.yellow(n(a.chainId,r.chainId))+" "+Qc.white(n(a.name,r.name))+" "+Qc.gray(n(a.symbol,r.symbol))+" "+(a.network==="mainnet"?Qc.green(a.network):Qc.gray(a.network)))}import{inspect as Zma}from"util";import ts from"ora";import{v4 as Xma}from"uuid";import{ethers as wZ}from"ethers";var bDt={name:"@truebit/cli",version:"1.120.0-beta.318",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.16.1",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.3",ethers:"6.16.0",figlet:"1.11.0","form-data":"4.0.5","openapi-enforcer":"1.23.0",ora:"9.4.0","public-ip":"8.0.0","ts-retry":"6.0.0",uuid:"14.0.0"},bin:{truebit:"build/index.mjs"},files:["build"],devDependencies:{"@types/figlet":"1.7.0","@vitest/coverage-v8":"4.1.6",esbuild:"0.28.0",typescript:"5.9.3",vitest:"4.1.6"},engines:{node:">=22.13.0"}};vi();hs();zo();vi();import{createInterface as hpa}from"node:readline/promises";import ep from"chalk";hs();import Vw from"axios";import{ethers as a8}from"ethers";import{randomBytes as lpa}from"crypto";import{v4 as dpa}from"uuid";vi();import{ethers as lZ}from"ethers";async function vDt(e){sh(e);let t=$i(),r=en(t,St.AVAX),n=lZ.keccak256(lZ.toUtf8Bytes(e));return await r.authorization.registerAuthorization(n),n}async function eEe(e,t,r=Jt("address")){sh(e);let n=$i(),a=en(n,St.AVAX),i=await a.authorization.getEIP712Domain(),s=await a.authorization.nonces(r),o=Math.floor(Date.now()/1e3)+3600,u={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},l=lZ.keccak256(lZ.toUtf8Bytes(e)),d={user:r,apiKeyHash:l,nonce:Number(s),deadline:o};if(!a.utils)throw new Error("Private key is required for signing operations");let c=await a.utils.signMeta(i,u,d);return(await G$t(r,l,o,c,t)).status==201?l:null}vi();zo();import{isTooManyTries as gDt,retryAsync as _Dt}from"ts-retry";var xDt="0x0000000000000000000000000000000000000000";async function EDt(e){let t=!0;return e===""?(t=!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(e)?await cpa(e)&&(t=!1,console.log("The provided email address is already in use. Please enter a different email address.")):(t=!1,console.log("The email address provided is not valid. Please try again.")),t}function fh(e){return e==="Y"||e==="N"}function wDt(e){return!a8.isAddress(e)||e.length!==42||!e.startsWith("0x")}async function SDt(){let e=$i(),t=en(e,St.AVAX),r=Jt("address"),n=await mpa(),a=await ppa();sh(a);let i=a8.keccak256(a8.toUtf8Bytes(a)),s=Math.floor(Date.now()/1e3)+3600,o=await t.taskRegistry.getEIP712Domain(),u=await t.authorization.getEIP712Domain(),l={RegisterTaskNamespaceMeta:[{name:"user",type:"address"},{name:"namespace",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},d={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},c=BigInt(await t.taskRegistry.nonces(r)),v=await t.authorization.nonces(r),m={user:a8.getAddress(r),namespace:n,nonce:c,deadline:s},p={user:r,apiKeyHash:i,nonce:Number(v),deadline:s};if(!t.utils)throw new Error("Private key is required for signing operations");let y=await t.utils.signMeta(o,l,m),b=await t.utils.signMeta(u,d,p),g={user:r,namespace:n,apiKeyHash:i,namespaceSignature:y,apiKeySignature:b,namespaceDeadline:s,apiKeyDeadline:s};try{let x=await K$t(g);if(x.status!==201)throw new Error("Registration failed with unexpected status");if(!x.data.namespaceRegistration.success)throw new Error("Namespace registration failed");if(!x.data.apiKeyRegistration.success)throw new Error("API key registration failed");return{namespace:n,apiKey:a,hashedApiKey:i}}catch(x){let E=x.message;throw new Error(`Combined registration failed: ${E}`)}}async function cpa(e){let t=await ms();try{return(await t.get(`userexistence/${e}`)).data===!0}catch(r){if(Vw.isAxiosError(r)&&r.response?.status===404&&typeof r.response?.data?.message=="string"&&r.response.data.message.includes("User not found"))return!1;throw r}}async function dZ(e,t){try{let r={message:"I am a Truebit User"};if(!t)throw Error("Secret.json does not exists");let n=t.privateKey,a=t.address,i=Sa.createSignedBody(r,n,a);return(await(await ms()).get(`user/${e}`,{headers:{"truebit-auth":JSON.stringify(i)}})).data}catch(r){if(Vw.isAxiosError(r)&&r.response?.status===401&&r.response?.data.message.includes("Entitlement Validation Error")||Vw.isAxiosError(r)&&r.response?.status==404&&r.response?.data.message&&r.response?.data.message.includes("User not found"))return null;throw Vw.isAxiosError(r)?r.response?Error(`The server responding with an error -> ${r.response.data.message||r.response.status+" - "+r.response.statusText}`):r.request?Error(`The server is not responding -> ${r.message}`):Error(`There was an error in the communication with the server -> ${r.message}`):Error(typeof r=="string"?`There was an error in the communication with the server -> ${r}`:"There was an error in the communication with the server.")}}async function TDt(e){try{return await(await ms()).post("user/register",e)}catch(t){throw Vw.isAxiosError(t)?t.response?Error(`The server responding with an error -> ${t.response.data.message||t.response.status+" - "+t.response.statusText}`):t.request?Error(`The server is not responding -> ${t.message}`):Error(`There was an error in the communication with the server -> ${t.message}`):Error(typeof t=="string"?`There was an error in the communication with the server -> ${t}`:"There was an error in the communication with the server.")}}async function ppa(){let e=$i(),t=en(e,St.AVAX),r="";try{await _Dt(async()=>{r=dpa();let n=a8.keccak256(a8.toUtf8Bytes(r));return await t.authorization.getPayerAddress(n)===xDt},{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw gDt(n)?Error("Attempts to generate unique Api Key for the user exhausted."):n}return r}async function mpa(){let e=$i(),t=en(e,St.AVAX),r="";try{await _Dt(async()=>(r=lpa(4).toString("hex"),await t.taskRegistry.getNamespaceOwner(r)===xDt),{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw gDt(n)?Error("Attempts to generate unique namespace for the user exhausted."):n}return r}function ADt(e){e.fullNameAnswer="",e.emailAddressAnswer="",e.companyNameAnswer="",e.jobPositionAnswer="",e.eulaAnswer="",e.confirmRegistration=""}zo();kp();import ypa from"ora";import*as cZ from"os";async function IDt(e,t,r){let n=ys(),a=n!==null,i=0,s,o=hpa({input:process.stdin,output:process.stdout,terminal:!0});switch(a&&(wDt(n.address)?i=1:(s=await dZ(n.address,n),s?i=2:i=3)),i){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(dn.SETUP_STEP1_SCENARIO1_P2(s));break;case 3:{console.log(dn.SETUP_STEP2_SCENARIO3_P1),console.log();let u={user_ip:e,date_time:ua(),os_version:cZ.type+"_"+cZ.release,node_version:process.version,cli_version:t};await r.sendEventToMixpanel("user_registration_begin",u);let l={confirmRegistration:"",fullNameAnswer:"",emailAddressAnswer:"",companyNameAnswer:"",jobPositionAnswer:"",eulaAnswer:""};try{for(;l.confirmRegistration!="Y";){for(l.fullNameAnswer=(await o.question(ep.bold(" 1. Full Name: "))).trim();l.fullNameAnswer==="";)console.log("Your full name is required. Please provide your first and last name to proceed."),l.fullNameAnswer=(await o.question(ep.bold(" 1. Full Name: "))).trim();for(l.emailAddressAnswer=(await o.question(ep.bold(" 2. Email Address: "))).trim();!await EDt(l.emailAddressAnswer);)l.emailAddressAnswer=(await o.question(ep.bold(" 2. Email Address: "))).trim();for(l.companyNameAnswer=(await o.question(ep.bold(" 3. Company Name: "))).trim(),l.jobPositionAnswer=(await o.question(ep.bold(" 4. Job Position: "))).trim();!fh(l.eulaAnswer);)l.eulaAnswer=(await o.question(ep.bold(` 5. Accept EULA? [Y|N] (${dn.EULA_TERMS_LINK}): `))).toUpperCase();if(l.eulaAnswer=="N"){console.log(dn.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!fh(l.confirmRegistration);)console.log(`
506
506
  Is the information provided above correct?`),l.confirmRegistration=(await o.question(ep.bold("Press [Y] to confirm or [N] to edit: "))).toUpperCase();l.confirmRegistration=="N"&&(console.log(`
507
507
  Please provide the following information:`),ADt(l))}}catch(v){if(v.name==="AbortError"||v.message.includes("Ctrl+C")){let m=v.message,p=u;p.error_details=m,p.date_time=ua();let y={fullname:l.fullNameAnswer,email:l.emailAddressAnswer,company:l.companyNameAnswer,role:l.jobPositionAnswer};p.user_info=JSON.stringify(y),await r.sendEventToMixpanel("user_registration_failed",p),process.exit(0)}}if(l.eulaAnswer=="N")break;let d=u;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 c=ypa({text:ep.bold("... registering your account."),stream:process.stdout}).start();try{let{namespace:v,apiKey:m}=await SDt(),p={name:l.fullNameAnswer,email:l.emailAddressAnswer,walletAddress:n?.address,company:l.companyNameAnswer,jobDescription:l.jobPositionAnswer,EULA:Sa.createSignedBody({ip:await OO(),date:new Date().toISOString()},n.privateKey),defaultNamespace:v,defaultApiKey:m};await TDt(p),c.stop(),console.log(dn.SETUP_STEP2_SCENARIO3_P2(l,n.address,v,m)),d.distinct_id=p.walletAddress,d.date_time=ua(),d.fullname=p.name,d.email=p.email,d.company=p.company,d.role=p.jobDescription,d.namespace=p.defaultNamespace,d.api_key=m,d.wallet_address=p.walletAddress,await r.sendEventToMixpanel("user_registration_success",d),await r.registerUserMixpanel(d.wallet_address,bpa(d))}catch(v){c.stop();let m=v.message,p=u;p.error_details=m,p.date_time=ua();let y={fullname:l.fullNameAnswer,email:l.emailAddressAnswer,company:l.companyNameAnswer,role:l.jobPositionAnswer};p.user_info=JSON.stringify(y),await r.sendEventToMixpanel("user_registration_failed",p);let b=m?m.match(/CreateUserValidation - (.*?.*)/)?.[1]:null;if(b)throw Error(b);if(m.includes("Sender doesn't have enough funds to send tx"))throw Error("We are currently experiencing technical difficulties. Please try again later.");console.error(dn.SETUP_STEP2_UNHANDLED_ERROR),process.exit(1)}finally{c.clear()}break}default:throw Error("An unexpected error occurred.")}o.close()}function bpa(e){return{apiKey:e.api_key,name:e.fullname,email:e.email,ip:e.user_ip,company:e.company,role:e.role,namespace:e.namespace,walletAddress:e.wallet_address}}import{setDefaultAutoSelectFamily as Qma}from"node:net";import vpa from"chalk";vi();kp();import{createInterface as gpa}from"node:readline/promises";import*as pZ from"os";async function ODt(e,t,r){let n=ys(),a=n!==null,i;switch(a?a&&!n.eula?i=2:i=3:i=1,i){case 1:case 2:{let s=gpa({input:process.stdin,output:process.stdout,terminal:!0}),o="",u={user_ip:e,date_time:ua(),os_version:pZ.type+"_"+pZ.release,node_version:process.version,cli_version:t};for(console.log(dn.EULA_INSTALLATION);!fh(o);)o=(await s.question(vpa.bold(`
508
508
  Have you read, and do you accept the Terms of Use? [Y|N]: `))).toUpperCase(),await r.sendEventToMixpanel("TOS_shown",u);if(o=="N")throw u.date_time=ua(),await r.sendEventToMixpanel("TOS_rejected",u),dn.EULA_INSTALLATION_NO_ACCEPTED;u.date_time=ua(),await r.sendEventToMixpanel("TOS_accepted",u);let l=Math.round(new Date().getTime()).toString();if(i===1){let d={...Poe(),eula:l};tGe(d)}else i===2&&y9({eula:l});s.close()}break;default:break}}vi();kp();async function es(e=!1){let t=ys(),r=t!==null,n=null,a;switch(r?r&&(!t.privateKey||!t.address)?a=2:(n=await dZ(t.address,t),n?a=4:a=3):a=1,a){case 1:case 2:case 3:console.log(dn.USER_NO_REGISTERED),process.exit(1);break;case 4:e&&console.log(`You are logged in as: ${n?.name} - ${n?.email}`);break}}import{createInterface as _pa}from"node:readline/promises";kp();vi();import xpa from"chalk";async function qDt(){console.log(xpa.bold(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truebit/cli",
3
- "version": "1.120.0-beta.317",
3
+ "version": "1.120.0-beta.318",
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": {
@@ -55,5 +55,5 @@
55
55
  "engines": {
56
56
  "node": ">=22.13.0"
57
57
  },
58
- "gitHead": "077afc6dd1c2f9a918ad5b75493e7f69cde8a07e"
58
+ "gitHead": "cd814d9d0202b99b63335551d75d6104cb5c72cc"
59
59
  }