@perspect3vism/ad4m-language-context
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -6,3 +6,8 @@ import child_process from "child_process"; | ||
const bootStrapUrl = "https://bootstrap-staging.holo.host" | ||
const kitsuneProxy = "kitsune-proxy://SYVd4CF3BdJ4DS7KwLLgeU3_DbHoZ34Y-qroZ79DOs8/kitsune-quic/h/165.22.32.11/p/5779/--" | ||
function escapeShellArg (arg) { | ||
return arg.replace(" ", "\\\ "); | ||
} | ||
function sleep(ms) { | ||
@@ -13,7 +18,7 @@ return new Promise(resolve => setTimeout(resolve, ms)); | ||
export function createSandbox(hcPath, sbPath) { | ||
return child_process.execSync(`${hcPath} sandbox create --root ${sbPath} network --bootstrap ${bootStrapUrl} quic`).toString(); | ||
return child_process.execSync(`${escapeShellArg(hcPath)} sandbox create --root ${escapeShellArg(sbPath)} network --bootstrap ${bootStrapUrl} quic -p ${kitsuneProxy}`).toString(); | ||
} | ||
export function readSandboxes(hcPath) { | ||
let sb = child_process.execSync(`${hcPath} sandbox list`).toString(); | ||
let sb = child_process.execSync(`${escapeShellArg(hcPath)} sandbox list`).toString(); | ||
let lines = sb.split(/\r\n|\r|\n/); | ||
@@ -25,3 +30,3 @@ if (lines.length == 4) { | ||
lines.slice(2, -2).forEach(val => { | ||
linesOut.push(val.substring(3)); | ||
linesOut.push(escapeShellArg(val.substring(3))); | ||
}); | ||
@@ -33,3 +38,3 @@ return linesOut; | ||
export function stopProcesses(sbPath, hcProcess, lairProcess) { | ||
fs.unlinkSync(`${sbPath}/keystore/pid`) | ||
fs.unlinkSync(`${escapeShellArg(sbPath)}/keystore/pid`) | ||
hcProcess.kill("SIGINT"); | ||
@@ -40,17 +45,17 @@ lairProcess.kill("SIGINT"); | ||
export function unpackDna(hcPath, dnaPath) { | ||
return child_process.execSync(`${hcPath} dna unpack ${dnaPath}`).toString(); | ||
return child_process.execSync(`${escapeShellArg(hcPath)} dna unpack ${escapeShellArg(dnaPath)}`).toString(); | ||
} | ||
export function packDna(hcPath, workdirPath) { | ||
return child_process.execSync(`${hcPath} dna pack ${workdirPath}`).toString(); | ||
return child_process.execSync(`${escapeShellArg(hcPath)} dna pack ${escapeShellArg(workdirPath)}`).toString(); | ||
} | ||
export async function runSandbox(lairPath, hcPath, holochainPath, sbPath, adminPort) { | ||
let lairProcess = child_process.spawn(`${lairPath}`, [], { | ||
let lairProcess = child_process.spawn(`${escapeShellArg(lairPath)}`, [], { | ||
stdio: "inherit", | ||
env: { ...process.env, LAIR_DIR: `${sbPath}/keystore` }, | ||
env: { ...process.env, LAIR_DIR: `${escapeShellArg(sbPath)}/keystore` }, | ||
}); | ||
await sleep(500); | ||
let hcProcess = child_process.spawn(`${hcPath}`, ["sandbox", "-f", adminPort, "--holochain-path", `${holochainPath}`, "run", "-e", sbPath], | ||
let hcProcess = child_process.spawn(`${escapeShellArg(hcPath)}`, ["sandbox", "-f", adminPort, "--holochain-path", `${escapeShellArg(holochainPath)}`, "run", "-e", escapeShellArg(sbPath)], | ||
{ | ||
@@ -65,3 +70,3 @@ stdio: "inherit", | ||
process.on("SIGINT", function () { | ||
fs.unlinkSync(`${sbPath}/keystore/pid`) | ||
fs.unlinkSync(`${escapeShellArg(sbPath)}/keystore/pid`) | ||
hcProcess.kill("SIGINT"); | ||
@@ -77,3 +82,3 @@ lairProcess.kill("SIGINT"); | ||
export function cleanSandboxes(hcPath) { | ||
return child_process.execSync(`${hcPath} sandbox clean`).toString(); | ||
return child_process.execSync(`${escapeShellArg(hcPath)} sandbox clean`).toString(); | ||
} |
@@ -76,6 +76,8 @@ import { AdminWebsocket, AgentPubKey, AppSignalCb, AppWebsocket, CapSecret, AppSignal } from '@holochain/conductor-api' | ||
handleCallback(signal: AppSignal) { | ||
console.log("HolochainService.handleCallback: Got callback", signal, this); | ||
let callbacks = this.signalCallbacks.get(signal.data.cellId[0].toString("base64")) | ||
if (callbacks[0] != undefined) { | ||
callbacks[0](signal); | ||
console.log("GOT CALLBACK FROM HC, checking against language callbacks", this.signalCallbacks); | ||
if (this.signalCallbacks.size != 0) { | ||
let callbacks = this.signalCallbacks.get(signal.data.cellId[1].toString("base64")) | ||
if (callbacks[0] != undefined) { | ||
callbacks[0](signal); | ||
}; | ||
}; | ||
@@ -112,2 +114,7 @@ } | ||
await this.#ready | ||
const pubKey = await this.pubKeyForLanguage(lang); | ||
if (callback != undefined) { | ||
console.log("HolochainService: setting holochains signal callback for language", lang); | ||
this.signalCallbacks.set(pubKey.toString("base64"), [callback, lang]); | ||
}; | ||
@@ -130,3 +137,2 @@ const activeApps = await this.#adminWebsocket.listActiveApps(); | ||
const p = path.join(this.#dataPath, `${lang}-${dna.nick}.dna`); | ||
const pubKey = await this.pubKeyForLanguage(lang); | ||
fs.writeFileSync(p, dna.file); | ||
@@ -136,6 +142,2 @@ const hash = await this.#adminWebsocket.registerDna({ | ||
}) | ||
if (callback != undefined) { | ||
console.log("HolochainService: setting holochains signal callback for language", lang); | ||
this.signalCallbacks.set(hash.toString("base64"), [callback, lang]); | ||
}; | ||
await this.#adminWebsocket.installApp({ | ||
@@ -142,0 +144,0 @@ installed_app_id: lang, agent_key: pubKey, dnas: [{hash: hash, nick: dna.nick}] |
@@ -11,2 +11,6 @@ "use strict"; | ||
const bootStrapUrl = "https://bootstrap-staging.holo.host"; | ||
const kitsuneProxy = "kitsune-proxy://SYVd4CF3BdJ4DS7KwLLgeU3_DbHoZ34Y-qroZ79DOs8/kitsune-quic/h/165.22.32.11/p/5779/--"; | ||
function escapeShellArg(arg) { | ||
return arg.replace(" ", "\\\ "); | ||
} | ||
function sleep(ms) { | ||
@@ -16,7 +20,7 @@ return new Promise(resolve => setTimeout(resolve, ms)); | ||
function createSandbox(hcPath, sbPath) { | ||
return child_process_1.default.execSync(`${hcPath} sandbox create --root ${sbPath} network --bootstrap ${bootStrapUrl} quic`).toString(); | ||
return child_process_1.default.execSync(`${escapeShellArg(hcPath)} sandbox create --root ${escapeShellArg(sbPath)} network --bootstrap ${bootStrapUrl} quic -p ${kitsuneProxy}`).toString(); | ||
} | ||
exports.createSandbox = createSandbox; | ||
function readSandboxes(hcPath) { | ||
let sb = child_process_1.default.execSync(`${hcPath} sandbox list`).toString(); | ||
let sb = child_process_1.default.execSync(`${escapeShellArg(hcPath)} sandbox list`).toString(); | ||
let lines = sb.split(/\r\n|\r|\n/); | ||
@@ -29,3 +33,3 @@ if (lines.length == 4) { | ||
lines.slice(2, -2).forEach(val => { | ||
linesOut.push(val.substring(3)); | ||
linesOut.push(escapeShellArg(val.substring(3))); | ||
}); | ||
@@ -37,3 +41,3 @@ return linesOut; | ||
function stopProcesses(sbPath, hcProcess, lairProcess) { | ||
fs_1.default.unlinkSync(`${sbPath}/keystore/pid`); | ||
fs_1.default.unlinkSync(`${escapeShellArg(sbPath)}/keystore/pid`); | ||
hcProcess.kill("SIGINT"); | ||
@@ -44,16 +48,16 @@ lairProcess.kill("SIGINT"); | ||
function unpackDna(hcPath, dnaPath) { | ||
return child_process_1.default.execSync(`${hcPath} dna unpack ${dnaPath}`).toString(); | ||
return child_process_1.default.execSync(`${escapeShellArg(hcPath)} dna unpack ${escapeShellArg(dnaPath)}`).toString(); | ||
} | ||
exports.unpackDna = unpackDna; | ||
function packDna(hcPath, workdirPath) { | ||
return child_process_1.default.execSync(`${hcPath} dna pack ${workdirPath}`).toString(); | ||
return child_process_1.default.execSync(`${escapeShellArg(hcPath)} dna pack ${escapeShellArg(workdirPath)}`).toString(); | ||
} | ||
exports.packDna = packDna; | ||
async function runSandbox(lairPath, hcPath, holochainPath, sbPath, adminPort) { | ||
let lairProcess = child_process_1.default.spawn(`${lairPath}`, [], { | ||
let lairProcess = child_process_1.default.spawn(`${escapeShellArg(lairPath)}`, [], { | ||
stdio: "inherit", | ||
env: Object.assign(Object.assign({}, process.env), { LAIR_DIR: `${sbPath}/keystore` }), | ||
env: Object.assign(Object.assign({}, process.env), { LAIR_DIR: `${escapeShellArg(sbPath)}/keystore` }), | ||
}); | ||
await sleep(500); | ||
let hcProcess = child_process_1.default.spawn(`${hcPath}`, ["sandbox", "-f", adminPort, "--holochain-path", `${holochainPath}`, "run", "-e", sbPath], { | ||
let hcProcess = child_process_1.default.spawn(`${escapeShellArg(hcPath)}`, ["sandbox", "-f", adminPort, "--holochain-path", `${escapeShellArg(holochainPath)}`, "run", "-e", escapeShellArg(sbPath)], { | ||
stdio: "inherit", | ||
@@ -63,3 +67,3 @@ env: Object.assign(Object.assign({}, process.env), { RUST_LOG: process.env.RUST_LOG ? process.env.RUST_LOG : "info" }), | ||
process.on("SIGINT", function () { | ||
fs_1.default.unlinkSync(`${sbPath}/keystore/pid`); | ||
fs_1.default.unlinkSync(`${escapeShellArg(sbPath)}/keystore/pid`); | ||
hcProcess.kill("SIGINT"); | ||
@@ -74,4 +78,4 @@ lairProcess.kill("SIGINT"); | ||
function cleanSandboxes(hcPath) { | ||
return child_process_1.default.execSync(`${hcPath} sandbox clean`).toString(); | ||
return child_process_1.default.execSync(`${escapeShellArg(hcPath)} sandbox clean`).toString(); | ||
} | ||
exports.cleanSandboxes = cleanSandboxes; |
@@ -90,6 +90,9 @@ "use strict"; | ||
handleCallback(signal) { | ||
console.log("HolochainService.handleCallback: Got callback", signal, this); | ||
let callbacks = this.signalCallbacks.get(signal.data.cellId[0].toString("base64")); | ||
if (callbacks[0] != undefined) { | ||
callbacks[0](signal); | ||
console.log("GOT CALLBACK FROM HC, checking against language callbacks", this.signalCallbacks); | ||
if (this.signalCallbacks.size != 0) { | ||
let callbacks = this.signalCallbacks.get(signal.data.cellId[1].toString("base64")); | ||
if (callbacks[0] != undefined) { | ||
callbacks[0](signal); | ||
} | ||
; | ||
} | ||
@@ -123,2 +126,8 @@ ; | ||
await __classPrivateFieldGet(this, _ready); | ||
const pubKey = await this.pubKeyForLanguage(lang); | ||
if (callback != undefined) { | ||
console.log("HolochainService: setting holochains signal callback for language", lang); | ||
this.signalCallbacks.set(pubKey.toString("base64"), [callback, lang]); | ||
} | ||
; | ||
const activeApps = await __classPrivateFieldGet(this, _adminWebsocket).listActiveApps(); | ||
@@ -138,3 +147,2 @@ //console.log("HolochainService: Found running apps:", activeApps); | ||
const p = path_1.default.join(__classPrivateFieldGet(this, _dataPath), `${lang}-${dna.nick}.dna`); | ||
const pubKey = await this.pubKeyForLanguage(lang); | ||
fs_1.default.writeFileSync(p, dna.file); | ||
@@ -144,7 +152,2 @@ const hash = await __classPrivateFieldGet(this, _adminWebsocket).registerDna({ | ||
}); | ||
if (callback != undefined) { | ||
console.log("HolochainService: setting holochains signal callback for language", lang); | ||
this.signalCallbacks.set(hash.toString("base64"), [callback, lang]); | ||
} | ||
; | ||
await __classPrivateFieldGet(this, _adminWebsocket).installApp({ | ||
@@ -151,0 +154,0 @@ installed_app_id: lang, agent_key: pubKey, dnas: [{ hash: hash, nick: dna.nick }] |
{ | ||
"name": "@perspect3vism/ad4m-language-context", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"LanguageContext.ts", | ||
"Holochain", | ||
"index.ts" | ||
], | ||
"scripts": { | ||
@@ -7,0 +13,0 @@ "build": "tsc", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6
1
33431
14
663