@truebit/cli 1.120.0-beta.265 → 1.120.0-beta.266

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
@@ -513,7 +513,7 @@ ${r.data.payload.instrumentedTaskId}`);else throw"Malformed instrumentation serv
513
513
  `+Fi.cyan("=".repeat(60))),console.log(Fi.cyan.bold(" Quota Status")),console.log(Fi.cyan("=".repeat(60))+`
514
514
  `),console.log(Fi.white("Wallet Address: ")+Fi.yellow(e)),console.log(Fi.white("Subscription Tier: ")+Fi.green(s.userSubscription.toUpperCase())),s.maxSolutions!==void 0&&console.log(Fi.white("Max Solutions: ")+Fi.green(`${s.maxSolutions}`)),s.quotaMax===0)console.log(Fi.white("Monthly Quota: ")+Fi.green("UNLIMITED")),s.currentUsage!==void 0&&console.log(Fi.white("Current Usage: ")+Fi.yellow(`${s.currentUsage} executions`));else{if(console.log(Fi.white("Monthly Quota: ")+Fi.green(`${s.quotaMax} executions`)),s.currentUsage!==void 0&&(console.log(Fi.white("Current Usage: ")+Fi.yellow(`${s.currentUsage} executions`)),s.remaining!==void 0)){let c=s.remaining===0?Fi.red:s.remaining<s.quotaMax*.2?Fi.yellow:Fi.green;console.log(Fi.white("Remaining: ")+c(`${s.remaining} executions`))}console.log(Fi.white("Quota Resets On: ")+Fi.yellow(f))}console.log(`
515
515
  `+Fi.cyan("=".repeat(60))+`
516
- `)}catch(t){throw t instanceof Error?console.error(Fi.red("Error fetching quota status: ")+t.message):console.error(Fi.red("Error fetching quota status: ")+String(t)),t}}HKe();El();async function c_r(t){try{console.log("Fetching execution status...");let r=await(await Lh()).get(`api/execution/${t}`).catch(Ac);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(e){console.error(`Couldn't fetch execution status for executionId ${t}: ${e}`)}}var d_r=cr(bV(),1),Ok=class{tokens=[];authInputs;parse(e,r){let n=this.parseKeyValuePairs(r);if(e.length==0){this.authInputs=n;return}let i=Object.keys(n);if(e.every(a=>i.includes(a))){let a={};for(let s of e)a[s]=n[s];this.authInputs=a}else throw new Error(`Invalid authString: ${e} are required`)}parseKeyValuePairs(e){try{let r=e.split(","),n={};for(let i of r){let[a,s]=i.split(":");n[a.trim()]=s.trim()}return n}catch{throw new Error("Invalid auth string")}}},Rpe=class extends Ok{tokens=["accessKey","secretKey"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return d_r.default.sign(e,{accessKeyId:this.authInputs.accessKey,secretAccessKey:this.authInputs.secretKey}).headers||{}}},qpe=class extends Ok{tokens=["username","password"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return{Authorization:`Basic ${btoa(`${this.authInputs.username}:${this.authInputs.password}`)}`}}},Npe=class extends Ok{tokens=[];constructor(e){super(),this.parse([],e)}authHeaders(e){return{...this.authInputs}}};var F1;(function(t){t.AWS_SIGNATURE="aws-signature",t.BASIC_AUTH="basic-auth",t.CUSTOM_HEADER="custom-header"})(F1||(F1={}));var zKe=(t,e)=>{switch(t){case F1.AWS_SIGNATURE:return new Rpe(e);case F1.BASIC_AUTH:return new qpe(e);case F1.CUSTOM_HEADER:return new Npe(e);default:throw new Error(`Invalid authentication method specified. Should be one of <${Object.values(F1)}>`)}};import m_r from"chalk";import{ethers as u0a}from"ethers";El();import*as Dpe from"crypto";import a0a from"axios";import WKe from"chalk";function p_r(t){if(a0a.isAxiosError(t)&&t.response?.data){let e=t.response.data;return console.log(WKe.red(e.message)),typeof e=="string"?e:e.message||JSON.stringify(e)}return t instanceof Error?t.message:String(t)}async function s0a(t,e){try{let r=xc({namespace:e});return(await t.post("getkey",r)).data}catch(r){return p_r(r),console.error(WKe.red("Failed to retrieve encryption key from Hub-TEE-KMS. Please try again")),null}}function o0a(t,e){try{let r=Buffer.from(e,"base64"),n=Dpe.randomBytes(16),i=Dpe.createCipheriv("aes-256-cbc",r,n),a=Buffer.concat([i.update(t,"utf8"),i.final()]);return r.fill(0),{encrypted_authString:a.toString("base64"),iv:n.toString("base64")}}catch{return null}}async function h_r(t,e,r){try{let n=await s0a(t,r);if(!n)return null;let i=o0a(e,n.plaintext_key);return i?{encrypted_authString:i.encrypted_authString,encrypted_data_key:n.encryption_key,iv:i.iv}:null}catch(n){return p_r(n),console.error(WKe.red("Failed to encrypt credentials. Please try again.")),null}}async function y_r(t,e,r,n,i,a,s){console.log("Deploying the API Authentication Credentials");try{if(!Gvr(a))throw"Invalid private key provided";if(!u0a.isAddress(s))throw"Invalid address provided";if(zKe(n,i),!dT(t))throw"Invalid taskId";let o=await zCt();console.log("Encrypting credentials...");let u=await h_r(o,i,e);if(!u)return;let f=xc({taskId:t,namespace:e,taskName:r,method:n,encrypted_authString:u.encrypted_authString,encrypted_data_key:u.encrypted_data_key,iv:u.iv});await o.post("credentials",f).catch(Ac),console.log("The encrypted credentials were deployed "+m_r.green("Successfully"))}catch(o){let u=o instanceof Error?o.message:String(o);console.error(m_r.red(u));return}}import{inspect as Zfa}from"util";import Ju from"ora";import{v4 as Xfa}from"uuid";import{ethers as Ype}from"ethers";var b_r={name:"@truebit/cli",version:"1.120.0-beta.265",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.3",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.2",ethers:"6.16.0",figlet:"1.10.0","form-data":"4.0.5","openapi-enforcer":"1.23.0",ora:"9.1.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":"4.0.18",esbuild:"0.27.2",typescript:"5.9.3",vitest:"4.0.18"},engines:{node:">=22.13.0"}};A0();El();f6();A0();import{createInterface as m0a}from"node:readline/promises";import x2 from"chalk";El();import Ck from"axios";import{ethers as pT}from"ethers";import{randomBytes as l0a}from"crypto";import{v4 as c0a}from"uuid";A0();import{ethers as kpe}from"ethers";async function g_r(t){i8(t);let e=gi(Ru(),Vt.AVAX),r=kpe.keccak256(kpe.toUtf8Bytes(t));return await e.authorization.registerAuthorization(r),r}async function GKe(t,e,r=Dn("address")){i8(t);let n=gi(Ru(),Vt.AVAX),i=await n.authorization.getEIP712Domain(),a=await n.authorization.nonces(r),s=Math.floor(Date.now()/1e3)+3600,o={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},u=kpe.keccak256(kpe.toUtf8Bytes(t)),f={user:r,apiKeyHash:u,nonce:Number(a),deadline:s};if(!n.utils)throw new Error("Private key is required for signing operations");let c=await n.utils.signMeta(i,o,f);return(await Yvr(r,u,s,c,e)).status==201?u:null}A0();f6();import{isTooManyTries as v_r,retryAsync as __r}from"ts-retry";var E_r="0x0000000000000000000000000000000000000000";async function S_r(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 d0a(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 a8(t){return t==="Y"||t==="N"}function w_r(t){return!pT.isAddress(t)||t.length!==42||!t.startsWith("0x")}async function A_r(){let t=Ru(),e=gi(t,Vt.AVAX),r=Dn("address"),n=await h0a(),i=await p0a();i8(i);let a=pT.keccak256(pT.toUtf8Bytes(i)),s=Math.floor(Date.now()/1e3)+3600,o=await e.taskRegistry.getEIP712Domain(),u=await e.authorization.getEIP712Domain(),f={RegisterTaskNamespaceMeta:[{name:"user",type:"address"},{name:"namespace",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},c={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},d=BigInt(await e.taskRegistry.nonces(r)),h=await e.authorization.nonces(r),p={user:pT.getAddress(r),namespace:n,nonce:d,deadline:s},m={user:r,apiKeyHash:a,nonce:Number(h),deadline:s};if(!e.utils)throw new Error("Private key is required for signing operations");let y=await e.utils.signMeta(o,f,p),b=await e.utils.signMeta(u,c,m),v={user:r,namespace:n,apiKeyHash:a,namespaceSignature:y,apiKeySignature:b,namespaceDeadline:s,apiKeyDeadline:s};try{let E=await Jvr(v);if(E.status!==201)throw new Error("Registration failed with unexpected status");if(!E.data.namespaceRegistration.success)throw new Error("Namespace registration failed");if(!E.data.apiKeyRegistration.success)throw new Error("API key registration failed");return{namespace:n,apiKey:i,hashedApiKey:a}}catch(E){let x=E.message;throw new Error(`Combined registration failed: ${x}`)}}async function d0a(t){let e=await S0();try{return(await e.get(`userexistence/${t}`)).data===!0}catch(r){if(Ck.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 $pe(t,e){try{let r={message:"I am a Truebit User"};if(!e)throw Error("Secret.json does not exists");let n=e.privateKey,i=e.address,a=Zf.createSignedBody(r,n,i);return(await(await S0()).get(`user/${t}`,{headers:{"truebit-auth":JSON.stringify(a)}})).data}catch(r){if(Ck.isAxiosError(r)&&r.response?.status===401&&r.response?.data.message.includes("Entitlement Validation Error")||Ck.isAxiosError(r)&&r.response?.status==404&&r.response?.data.message&&r.response?.data.message.includes("User not found"))return null;throw Ck.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 x_r(t){try{return await(await S0()).post("user/register",t)}catch(e){throw Ck.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 p0a(){let t=Ru(),e=gi(t,Vt.AVAX),r="";try{await __r(async()=>{r=c0a();let n=pT.keccak256(pT.toUtf8Bytes(r));return await e.authorization.getPayerAddress(n)===E_r},{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw v_r(n)?Error("Attempts to generate unique Api Key for the user exhausted."):n}return r}async function h0a(){let t=Ru(),e=gi(t,Vt.AVAX),r="";try{await __r(async()=>(r=l0a(4).toString("hex"),await e.taskRegistry.getNamespaceOwner(r)===E_r),{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw v_r(n)?Error("Attempts to generate unique namespace for the user exhausted."):n}return r}function T_r(t){t.fullNameAnswer="",t.emailAddressAnswer="",t.companyNameAnswer="",t.jobPositionAnswer="",t.eulaAnswer="",t.confirmRegistration=""}f6();ig();import y0a from"ora";import*as Bpe from"os";async function O_r(t,e,r){let n=w0(),i=n!==null,a=0,s,o=m0a({input:process.stdin,output:process.stdout,terminal:!0});switch(i&&(w_r(n.address)?a=1:(s=await $pe(n.address,n),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(Ri.SETUP_STEP1_SCENARIO1_P2(s));break;case 3:{console.log(Ri.SETUP_STEP2_SCENARIO3_P1),console.log();let u={user_ip:t,date_time:us(),os_version:Bpe.type+"_"+Bpe.release,node_version:process.version,cli_version:e};await r.sendEventToMixpanel("user_registration_begin",u);let f={confirmRegistration:"",fullNameAnswer:"",emailAddressAnswer:"",companyNameAnswer:"",jobPositionAnswer:"",eulaAnswer:""};try{for(;f.confirmRegistration!="Y";){for(f.fullNameAnswer=(await o.question(x2.bold(" 1. Full Name: "))).trim();f.fullNameAnswer==="";)console.log("Your full name is required. Please provide your first and last name to proceed."),f.fullNameAnswer=(await o.question(x2.bold(" 1. Full Name: "))).trim();for(f.emailAddressAnswer=(await o.question(x2.bold(" 2. Email Address: "))).trim();!await S_r(f.emailAddressAnswer);)f.emailAddressAnswer=(await o.question(x2.bold(" 2. Email Address: "))).trim();for(f.companyNameAnswer=(await o.question(x2.bold(" 3. Company Name: "))).trim(),f.jobPositionAnswer=(await o.question(x2.bold(" 4. Job Position: "))).trim();!a8(f.eulaAnswer);)f.eulaAnswer=(await o.question(x2.bold(` 5. Accept EULA? [Y|N] (${Ri.EULA_TERMS_LINK}): `))).toUpperCase();if(f.eulaAnswer=="N"){console.log(Ri.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!a8(f.confirmRegistration);)console.log(`
516
+ `)}catch(t){throw t instanceof Error?console.error(Fi.red("Error fetching quota status: ")+t.message):console.error(Fi.red("Error fetching quota status: ")+String(t)),t}}HKe();El();async function c_r(t){try{console.log("Fetching execution status...");let r=await(await Lh()).get(`api/execution/${t}`).catch(Ac);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(e){console.error(`Couldn't fetch execution status for executionId ${t}: ${e}`)}}var d_r=cr(bV(),1),Ok=class{tokens=[];authInputs;parse(e,r){let n=this.parseKeyValuePairs(r);if(e.length==0){this.authInputs=n;return}let i=Object.keys(n);if(e.every(a=>i.includes(a))){let a={};for(let s of e)a[s]=n[s];this.authInputs=a}else throw new Error(`Invalid authString: ${e} are required`)}parseKeyValuePairs(e){try{let r=e.split(","),n={};for(let i of r){let[a,s]=i.split(":");n[a.trim()]=s.trim()}return n}catch{throw new Error("Invalid auth string")}}},Rpe=class extends Ok{tokens=["accessKey","secretKey"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return d_r.default.sign(e,{accessKeyId:this.authInputs.accessKey,secretAccessKey:this.authInputs.secretKey}).headers||{}}},qpe=class extends Ok{tokens=["username","password"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return{Authorization:`Basic ${btoa(`${this.authInputs.username}:${this.authInputs.password}`)}`}}},Npe=class extends Ok{tokens=[];constructor(e){super(),this.parse([],e)}authHeaders(e){return{...this.authInputs}}};var F1;(function(t){t.AWS_SIGNATURE="aws-signature",t.BASIC_AUTH="basic-auth",t.CUSTOM_HEADER="custom-header"})(F1||(F1={}));var zKe=(t,e)=>{switch(t){case F1.AWS_SIGNATURE:return new Rpe(e);case F1.BASIC_AUTH:return new qpe(e);case F1.CUSTOM_HEADER:return new Npe(e);default:throw new Error(`Invalid authentication method specified. Should be one of <${Object.values(F1)}>`)}};import m_r from"chalk";import{ethers as u0a}from"ethers";El();import*as Dpe from"crypto";import a0a from"axios";import WKe from"chalk";function p_r(t){if(a0a.isAxiosError(t)&&t.response?.data){let e=t.response.data;return console.log(WKe.red(e.message)),typeof e=="string"?e:e.message||JSON.stringify(e)}return t instanceof Error?t.message:String(t)}async function s0a(t,e){try{let r=xc({namespace:e});return(await t.post("getkey",r)).data}catch(r){return p_r(r),console.error(WKe.red("Failed to retrieve encryption key from Hub-TEE-KMS. Please try again")),null}}function o0a(t,e){try{let r=Buffer.from(e,"base64"),n=Dpe.randomBytes(16),i=Dpe.createCipheriv("aes-256-cbc",r,n),a=Buffer.concat([i.update(t,"utf8"),i.final()]);return r.fill(0),{encrypted_authString:a.toString("base64"),iv:n.toString("base64")}}catch{return null}}async function h_r(t,e,r){try{let n=await s0a(t,r);if(!n)return null;let i=o0a(e,n.plaintext_key);return i?{encrypted_authString:i.encrypted_authString,encrypted_data_key:n.encryption_key,iv:i.iv}:null}catch(n){return p_r(n),console.error(WKe.red("Failed to encrypt credentials. Please try again.")),null}}async function y_r(t,e,r,n,i,a,s){console.log("Deploying the API Authentication Credentials");try{if(!Gvr(a))throw"Invalid private key provided";if(!u0a.isAddress(s))throw"Invalid address provided";if(zKe(n,i),!dT(t))throw"Invalid taskId";let o=await zCt();console.log("Encrypting credentials...");let u=await h_r(o,i,e);if(!u)return;let f=xc({taskId:t,namespace:e,taskName:r,method:n,encrypted_authString:u.encrypted_authString,encrypted_data_key:u.encrypted_data_key,iv:u.iv});await o.post("credentials",f).catch(Ac),console.log("The encrypted credentials were deployed "+m_r.green("Successfully"))}catch(o){let u=o instanceof Error?o.message:String(o);console.error(m_r.red(u));return}}import{inspect as Zfa}from"util";import Ju from"ora";import{v4 as Xfa}from"uuid";import{ethers as Ype}from"ethers";var b_r={name:"@truebit/cli",version:"1.120.0-beta.266",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.3",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.2",ethers:"6.16.0",figlet:"1.10.0","form-data":"4.0.5","openapi-enforcer":"1.23.0",ora:"9.1.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":"4.0.18",esbuild:"0.27.2",typescript:"5.9.3",vitest:"4.0.18"},engines:{node:">=22.13.0"}};A0();El();f6();A0();import{createInterface as m0a}from"node:readline/promises";import x2 from"chalk";El();import Ck from"axios";import{ethers as pT}from"ethers";import{randomBytes as l0a}from"crypto";import{v4 as c0a}from"uuid";A0();import{ethers as kpe}from"ethers";async function g_r(t){i8(t);let e=gi(Ru(),Vt.AVAX),r=kpe.keccak256(kpe.toUtf8Bytes(t));return await e.authorization.registerAuthorization(r),r}async function GKe(t,e,r=Dn("address")){i8(t);let n=gi(Ru(),Vt.AVAX),i=await n.authorization.getEIP712Domain(),a=await n.authorization.nonces(r),s=Math.floor(Date.now()/1e3)+3600,o={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},u=kpe.keccak256(kpe.toUtf8Bytes(t)),f={user:r,apiKeyHash:u,nonce:Number(a),deadline:s};if(!n.utils)throw new Error("Private key is required for signing operations");let c=await n.utils.signMeta(i,o,f);return(await Yvr(r,u,s,c,e)).status==201?u:null}A0();f6();import{isTooManyTries as v_r,retryAsync as __r}from"ts-retry";var E_r="0x0000000000000000000000000000000000000000";async function S_r(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 d0a(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 a8(t){return t==="Y"||t==="N"}function w_r(t){return!pT.isAddress(t)||t.length!==42||!t.startsWith("0x")}async function A_r(){let t=Ru(),e=gi(t,Vt.AVAX),r=Dn("address"),n=await h0a(),i=await p0a();i8(i);let a=pT.keccak256(pT.toUtf8Bytes(i)),s=Math.floor(Date.now()/1e3)+3600,o=await e.taskRegistry.getEIP712Domain(),u=await e.authorization.getEIP712Domain(),f={RegisterTaskNamespaceMeta:[{name:"user",type:"address"},{name:"namespace",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},c={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},d=BigInt(await e.taskRegistry.nonces(r)),h=await e.authorization.nonces(r),p={user:pT.getAddress(r),namespace:n,nonce:d,deadline:s},m={user:r,apiKeyHash:a,nonce:Number(h),deadline:s};if(!e.utils)throw new Error("Private key is required for signing operations");let y=await e.utils.signMeta(o,f,p),b=await e.utils.signMeta(u,c,m),v={user:r,namespace:n,apiKeyHash:a,namespaceSignature:y,apiKeySignature:b,namespaceDeadline:s,apiKeyDeadline:s};try{let E=await Jvr(v);if(E.status!==201)throw new Error("Registration failed with unexpected status");if(!E.data.namespaceRegistration.success)throw new Error("Namespace registration failed");if(!E.data.apiKeyRegistration.success)throw new Error("API key registration failed");return{namespace:n,apiKey:i,hashedApiKey:a}}catch(E){let x=E.message;throw new Error(`Combined registration failed: ${x}`)}}async function d0a(t){let e=await S0();try{return(await e.get(`userexistence/${t}`)).data===!0}catch(r){if(Ck.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 $pe(t,e){try{let r={message:"I am a Truebit User"};if(!e)throw Error("Secret.json does not exists");let n=e.privateKey,i=e.address,a=Zf.createSignedBody(r,n,i);return(await(await S0()).get(`user/${t}`,{headers:{"truebit-auth":JSON.stringify(a)}})).data}catch(r){if(Ck.isAxiosError(r)&&r.response?.status===401&&r.response?.data.message.includes("Entitlement Validation Error")||Ck.isAxiosError(r)&&r.response?.status==404&&r.response?.data.message&&r.response?.data.message.includes("User not found"))return null;throw Ck.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 x_r(t){try{return await(await S0()).post("user/register",t)}catch(e){throw Ck.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 p0a(){let t=Ru(),e=gi(t,Vt.AVAX),r="";try{await __r(async()=>{r=c0a();let n=pT.keccak256(pT.toUtf8Bytes(r));return await e.authorization.getPayerAddress(n)===E_r},{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw v_r(n)?Error("Attempts to generate unique Api Key for the user exhausted."):n}return r}async function h0a(){let t=Ru(),e=gi(t,Vt.AVAX),r="";try{await __r(async()=>(r=l0a(4).toString("hex"),await e.taskRegistry.getNamespaceOwner(r)===E_r),{delay:500,maxTry:5,until:n=>n===!0})}catch(n){throw v_r(n)?Error("Attempts to generate unique namespace for the user exhausted."):n}return r}function T_r(t){t.fullNameAnswer="",t.emailAddressAnswer="",t.companyNameAnswer="",t.jobPositionAnswer="",t.eulaAnswer="",t.confirmRegistration=""}f6();ig();import y0a from"ora";import*as Bpe from"os";async function O_r(t,e,r){let n=w0(),i=n!==null,a=0,s,o=m0a({input:process.stdin,output:process.stdout,terminal:!0});switch(i&&(w_r(n.address)?a=1:(s=await $pe(n.address,n),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(Ri.SETUP_STEP1_SCENARIO1_P2(s));break;case 3:{console.log(Ri.SETUP_STEP2_SCENARIO3_P1),console.log();let u={user_ip:t,date_time:us(),os_version:Bpe.type+"_"+Bpe.release,node_version:process.version,cli_version:e};await r.sendEventToMixpanel("user_registration_begin",u);let f={confirmRegistration:"",fullNameAnswer:"",emailAddressAnswer:"",companyNameAnswer:"",jobPositionAnswer:"",eulaAnswer:""};try{for(;f.confirmRegistration!="Y";){for(f.fullNameAnswer=(await o.question(x2.bold(" 1. Full Name: "))).trim();f.fullNameAnswer==="";)console.log("Your full name is required. Please provide your first and last name to proceed."),f.fullNameAnswer=(await o.question(x2.bold(" 1. Full Name: "))).trim();for(f.emailAddressAnswer=(await o.question(x2.bold(" 2. Email Address: "))).trim();!await S_r(f.emailAddressAnswer);)f.emailAddressAnswer=(await o.question(x2.bold(" 2. Email Address: "))).trim();for(f.companyNameAnswer=(await o.question(x2.bold(" 3. Company Name: "))).trim(),f.jobPositionAnswer=(await o.question(x2.bold(" 4. Job Position: "))).trim();!a8(f.eulaAnswer);)f.eulaAnswer=(await o.question(x2.bold(` 5. Accept EULA? [Y|N] (${Ri.EULA_TERMS_LINK}): `))).toUpperCase();if(f.eulaAnswer=="N"){console.log(Ri.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!a8(f.confirmRegistration);)console.log(`
517
517
  Is the information provided above correct?`),f.confirmRegistration=(await o.question(x2.bold("Press [Y] to confirm or [N] to edit: "))).toUpperCase();f.confirmRegistration=="N"&&(console.log(`
518
518
  Please provide the following information:`),T_r(f))}}catch(h){if(h.name==="AbortError"||h.message.includes("Ctrl+C")){let p=h.message,m=u;m.error_details=p,m.date_time=us();let y={fullname:f.fullNameAnswer,email:f.emailAddressAnswer,company:f.companyNameAnswer,role:f.jobPositionAnswer};m.user_info=JSON.stringify(y),await r.sendEventToMixpanel("user_registration_failed",m),process.exit(0)}}if(f.eulaAnswer=="N")break;let c=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 d=y0a({text:x2.bold("... registering your account."),stream:process.stdout}).start();try{let{namespace:h,apiKey:p}=await A_r(),m={name:f.fullNameAnswer,email:f.emailAddressAnswer,walletAddress:n?.address,company:f.companyNameAnswer,jobDescription:f.jobPositionAnswer,EULA:Zf.createSignedBody({ip:await GG(),date:new Date().toISOString()},n.privateKey),defaultNamespace:h,defaultApiKey:p};await x_r(m),d.stop(),console.log(Ri.SETUP_STEP2_SCENARIO3_P2(f,n.address,h,p)),c.distinct_id=m.walletAddress,c.date_time=us(),c.fullname=m.name,c.email=m.email,c.company=m.company,c.role=m.jobDescription,c.namespace=m.defaultNamespace,c.api_key=p,c.wallet_address=m.walletAddress,await r.sendEventToMixpanel("user_registration_success",c),await r.registerUserMixpanel(c.wallet_address,b0a(c))}catch(h){d.stop();let p=h.message,m=u;m.error_details=p,m.date_time=us();let y={fullname:f.fullNameAnswer,email:f.emailAddressAnswer,company:f.companyNameAnswer,role:f.jobPositionAnswer};m.user_info=JSON.stringify(y),await r.sendEventToMixpanel("user_registration_failed",m);let b=p?p.match(/CreateUserValidation - (.*?.*)/)?.[1]:null;if(b)throw Error(b);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(Ri.SETUP_STEP2_UNHANDLED_ERROR),process.exit(1)}finally{d.clear()}break}default:throw Error("An unexpected error occurred.")}o.close()}function b0a(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 Qfa}from"node:net";import g0a from"chalk";A0();ig();import{createInterface as v0a}from"node:readline/promises";import*as Fpe from"os";async function C_r(t,e,r){let n=w0(),i=n!==null,a=0;switch(i?i&&!n.eula?a=2:a=3:a=1,a){case 1:case 2:{let s=v0a({input:process.stdin,output:process.stdout,terminal:!0}),o="",u={user_ip:t,date_time:us(),os_version:Fpe.type+"_"+Fpe.release,node_version:process.version,cli_version:e};for(console.log(Ri.EULA_INSTALLATION);!a8(o);)o=(await s.question(g0a.bold(`
519
519
  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=us(),await r.sendEventToMixpanel("TOS_rejected",u),Ri.EULA_INSTALLATION_NO_ACCEPTED;u.date_time=us(),await r.sendEventToMixpanel("TOS_accepted",u);let f=Math.round(new Date().getTime()).toString();if(a===1){let c={...MTe(),eula:f};YCt(c)}else a===2&&cq({eula:f});s.close()}break;default:break}}A0();ig();async function Hc(t=!1){let e=w0(),r=e!==null,n=null,i=0;switch(r?r&&(!e.privateKey||!e.address)?i=2:(n=await $pe(e.address,e),n?i=4:i=3):i=1,i){case 1:case 2:case 3:console.log(Ri.USER_NO_REGISTERED),process.exit(1);break;case 4:t&&console.log(`You are logged in as: ${n?.name} - ${n?.email}`);break}}import{createInterface as _0a}from"node:readline/promises";ig();A0();import E0a from"chalk";async function I_r(){console.log(E0a.bold(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truebit/cli",
3
- "version": "1.120.0-beta.265",
3
+ "version": "1.120.0-beta.266",
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": "394a30cece4235a78c951aba2bca3f9abad80893"
58
+ "gitHead": "dbd9650e21d42b181311c86e18989f26533c58ca"
59
59
  }