@@ -13,7 +13,6 @@ import type {RequestOptions} from 'node:https'
1313import * as openpgp from 'openpgp'
1414import { TransformCallback } from 'stream'
1515import { ethers } from 'ethers'
16- import EthCrypto from 'eth-crypto'
1716import * as Crypto from 'crypto'
1817import IP from 'ip'
1918import { resolve4 } from 'node:dns'
@@ -160,11 +159,8 @@ const encrypt_Message = async (encryptionKeys, message: any) => {
160159}
161160
162161
163- const createSock5ConnectCmd = async ( currentProfile : profile , SaaSnode : nodes_info , requestData : any [ ] ) => {
164- if ( ! currentProfile . pgpKey || ! SaaSnode . armoredPublicKey ) {
165- logger ( Colors . red ( `currentProfile?.pgpKey[${ currentProfile ?. pgpKey } ]|| !SaaSnode?.armoredPublicKey[${ SaaSnode ?. armoredPublicKey } ] Error` ) )
166- return null
167- }
162+ const createSock5ConnectCmd = async ( wallet : ethers . Wallet , SaaSnode : nodes_info , requestData : any [ ] ) => {
163+
168164
169165 if ( ! SaaSnode ?. publicKeyObj ) {
170166 SaaSnode . publicKeyObj = await openpgp . readKey ( { armoredKey : SaaSnode . armoredPublicKey } )
@@ -177,19 +173,18 @@ const createSock5ConnectCmd = async (currentProfile: profile, SaaSnode: nodes_in
177173 algorithm : 'aes-256-cbc' ,
178174 Securitykey : key ,
179175 requestData,
180- walletAddress : currentProfile . keyID . toLowerCase ( )
176+ walletAddress : wallet . address . toLowerCase ( )
181177 }
182178
183179
184180 logger ( Colors . blue ( `createSock5ConnectCmd data = ${ inspect ( requestData , false , 3 , true ) } ` ) )
185181 logger ( Colors . blue ( `createSock5ConnectCmd data length = ${ requestData [ 0 ] . buffer . length } ` ) )
186182
187183 const message = JSON . stringify ( command )
188- const messageHash = ethers . id ( message )
189- const signMessage = EthCrypto . sign ( currentProfile . privateKeyArmor , messageHash )
190-
184+ const signMessage = await wallet . signMessage ( message )
191185
192186 const encryptedCommand = await encrypt_Message ( SaaSnode . publicKeyObj , { message, signMessage} )
187+ logger ( inspect ( { message, signMessage} , false , 3 , true ) )
193188 command . requestData = [ encryptedCommand , '' , key ]
194189 return ( command )
195190}
@@ -297,6 +292,7 @@ export class proxyServer {
297292 public connectHostTimeOut = 1000 * 5
298293 public useGatWay = true
299294 public clientSockets : Set < Net . Socket > = new Set ( )
295+ public currentWallet : ethers . Wallet
300296
301297 private startLocalProxy = async ( ) => {
302298
@@ -363,16 +359,6 @@ export class proxyServer {
363359 this . server . listen ( this . proxyPort , ( ) => {
364360 return logger ( Colors . blue ( `Proxy SERVER success on port : [${ this . proxyPort } ] entry nodes length =[${ this . _egressNodes ?. length } ] SaaS nodes = [${ this . _egressNodes ?. length } ]` ) )
365361 } )
366-
367- if ( ! this . currentProfile ?. keyObj ) {
368- this . currentProfile . keyObj = {
369- privateKeyObj : null ,
370- publicKeyObj : null
371- }
372- }
373- if ( this . currentProfile . pgpKey ?. privateKeyArmor ) {
374- this . currentProfile . keyObj . privateKeyObj = await makePrivateKeyObj ( this . currentProfile . pgpKey . privateKeyArmor )
375- }
376362
377363 }
378364
@@ -387,7 +373,7 @@ export class proxyServer {
387373
388374
389375
390- const cmd = await createSock5ConnectCmd ( this . currentProfile , upChannel_SaaS_node , [ uuuu ] )
376+ const cmd = await createSock5ConnectCmd ( this . currentWallet , upChannel_SaaS_node , [ uuuu ] )
391377 if ( ! cmd ) {
392378 return logger ( Colors . red ( `requestGetWay createSock5Connect return Null Error!` ) )
393379 }
@@ -403,8 +389,8 @@ export class proxyServer {
403389 ConnectToProxyNode ( cmd , upChannel_SaaS_node , entryNode , socket , uuuu , this )
404390 }
405391
406- public restart = ( currentProfile : profile , entryNodes : nodes_info [ ] , egressNodes : nodes_info [ ] ) => {
407- this . currentProfile = currentProfile
392+ public restart = ( privateKey : string , entryNodes : nodes_info [ ] , egressNodes : nodes_info [ ] ) => {
393+ this . privateKey = privateKey
408394 this . _entryNodes = entryNodes
409395 this . _egressNodes = egressNodes
410396 }
@@ -413,7 +399,7 @@ export class proxyServer {
413399 public proxyPort : string , // Proxy server listening port number
414400 private _entryNodes : nodes_info [ ] , // gateway nodes information
415401 private _egressNodes : nodes_info [ ] ,
416- private currentProfile : profile ,
402+ private privateKey : string ,
417403 public debug = false ,
418404 public logStream : string
419405
@@ -422,7 +408,7 @@ export class proxyServer {
422408
423409 logger ( Colors . magenta ( `${ proxyPort } Entry Nodes\n${ _entryNodes . map ( n => [ n . ip_addr , n . region ] ) } ` ) )
424410 logger ( Colors . magenta ( `${ proxyPort } Egress Nodes\n${ _egressNodes . map ( n => [ n . ip_addr , n . region ] ) } ` ) )
425-
411+ this . currentWallet = new ethers . Wallet ( privateKey )
426412 this . startLocalProxy ( )
427413 }
428414
@@ -435,4 +421,4 @@ export class proxyServer {
435421 } )
436422}
437423
438- // curl -v -x http://10 .0.0.252 :3002 "https://www.google.com"
424+ // curl -v -x http://127 .0.0.1 :3002 "https://www.google.com"
0 commit comments