MCPcopy Create free account
hub / github.com/cameri/nostream / addOnion

Function addOnion

src/tor/client.ts:185–216  ·  view source on GitHub ↗
(port: number, host?: string)

Source from the content-addressed store, hash-verified

183}
184
185export const addOnion = async (port: number, host?: string): Promise<string> => {
186 let privateKey = null
187 const path = getPrivateKeyFile()
188
189 try {
190 logger('reading private key from %s', path)
191 const data = await readFile(path, 'utf8')
192 if (data?.length) {
193 privateKey = data
194 logger('privateKey: %o', privateKey)
195 }
196 } catch (error) {
197 logger('error reading private key: %o', error)
198 }
199
200 const client = await getTorClient()
201 if (client) {
202 const hiddenService = await client.addOnion(port, host, privateKey)
203 logger('hidden service: %s:%d', hiddenService.ServiceID, port)
204
205 if (hiddenService?.PrivateKey) {
206 logger.info('saving private key to %s', path)
207
208 await writeFile(path, hiddenService.PrivateKey, 'utf8')
209 return hiddenService.ServiceID!
210 } else {
211 throw new Error(JSON.stringify(hiddenService))
212 }
213 } else {
214 throw new Error('not connect')
215 }
216}

Callers 2

onion.spec.tsFile · 0.90
runMethod · 0.90

Calls 3

getPrivateKeyFileFunction · 0.85
getTorClientFunction · 0.85
addOnionMethod · 0.80

Tested by

no test coverage detected