refactor: use new sdks and portal

This commit is contained in:
Derrick Hammer 2023-07-02 02:42:43 -04:00
parent 2e5a28a3a9
commit 4c8750bcb2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
11 changed files with 51 additions and 5406 deletions

2
bin/sandbox.d.ts vendored
View File

@ -1,2 +0,0 @@
#!/usr/bin/env node
export {};

View File

@ -1,19 +0,0 @@
#!/usr/bin/env node
// @ts-ignore
import { loadTester, login } from "../dist/index.js";
import puppeteer, { ProtocolError } from "puppeteer";
let browser;
(async () => {
browser = await puppeteer.launch({ headless: false, devtools: true });
const page = (await browser.pages()).pop();
await login(page);
await loadTester(page);
})();
process.on("SIGTERM", async () => {
await browser.close();
});
process.on("uncaughtException", (e) => {
if (!(e instanceof ProtocolError)) {
throw e;
}
});

12
dist/index.d.ts vendored
View File

@ -1,12 +0,0 @@
import { Page } from "puppeteer";
import { errTuple } from "libskynet";
export declare function generateSeedPhrase(): Uint8Array;
export declare function login(page: Page, seed?: Uint8Array): Promise<void>;
export declare function loadTester(page: Page, port?: number): Promise<void>;
declare class Tester {
private page;
constructor(page: Page);
callModule(id: string, method: string, data?: {}): Promise<errTuple>;
}
export declare const tester: (page: Page) => Tester;
export {};

53
dist/index.js vendored
View File

@ -1,53 +0,0 @@
import { bufToHex } from "libskynet";
import * as path from "path";
import * as kernel from "libkernel";
import * as ed from "@noble/ed25519";
// @ts-ignore
import StaticServer from "static-server";
import * as url from "url";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
export function generateSeedPhrase() {
return ed.utils.randomPrivateKey();
}
export async function login(page, seed = generateSeedPhrase()) {
await page.goto("http://kernel.lumeweb.com");
let userSeed = seed;
let seedHex = bufToHex(userSeed);
await page.evaluate((seed) => {
window.localStorage.setItem("v1-key", seed);
}, seedHex);
}
export async function loadTester(page, port = 8081) {
const server = new StaticServer({
rootPath: path.resolve(__dirname, "..", "public"),
port,
host: "localhost",
});
await new Promise((resolve) => {
server.start(resolve);
});
const stop = () => server.stop();
process.on("SIGTERM", stop);
page.browser().on("disconnected", stop);
await page.goto(`http://localhost:${port}/`);
await page.evaluate(() => {
return kernel.init();
});
}
class Tester {
page;
constructor(page) {
this.page = page;
}
async callModule(id, method, data = {}) {
return this.page.evaluate(
async (id, method, data) => {
return kernel.callModule(id, method, data);
},
id,
method,
data
);
}
}
export const tester = (page) => new Tester(page);

View File

@ -2,30 +2,25 @@
"name": "@lumeweb/kernel-tester",
"version": "0.1.0",
"scripts": {
"build": "tsc && rollup -c && mv dist/tester* public && mkdir -p bin && mv build/sandbox* bin/ && mv build/index* dist && rm -f dist/tester.js && rm -rf build/"
"prepare": "presetter bootstrap",
"build": "run build build:bin",
"build:bin": "mv build/tester* public && mkdir -p bin && mv build/sandbox* bin/"
},
"main": "dist/index.js",
"type": "module",
"dependencies": {
"@noble/ed25519": "^1.7.1",
"libkernel": "^0.1.41",
"libskynet": "^0.0.48",
"libskynetnode": "^0.1.3",
"puppeteer": "^15.4.0",
"static-server": "^2.2.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/node": "^18.0.0",
"@types/ws": "^8.5.3",
"prettier": "^2.7.1",
"rollup": "^2.75.7",
"rollup-plugin-polyfill-node": "^0.9.0",
"typescript": "^4.5"
},
"bin": {
"kernel-sandbox": "bin/sandbox.js"
},
"devDependencies": {
"@lumeweb/presetter-preset-rollup": "^4.0.2-develop.12",
"@rollup/plugin-wasm": "^6.1.3",
"presetter": "*"
},
"readme": "ERROR: No README data found!",
"_id": "@lumeweb/kernel-tester@0.1.0",
"dependencies": {
"@lumeweb/libkernel": "^0.1.0-develop.10",
"puppeteer": "^20.7.4",
"static-server": "^2.2.1"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
export default [
{
input: "build/tester.js",
output: {
file: "dist/tester.js",
format: "iife",
},
plugins: [resolve(), commonjs(), json()],
inlineDynamicImports: true,
},
];

View File

@ -1,52 +1,42 @@
import {
b64ToBuf,
bufToHex,
deriveChildSeed,
dictionary,
seedPhraseToSeed,
taggedRegistryEntryKeys,
} from "libskynet";
import * as path from "path";
import { overwriteRegistryEntry } from "libskynetnode";
import * as kernel from "libkernel";
import { webcrypto } from "crypto";
import * as ed from "@noble/ed25519";
// @ts-ignore
import StaticServer from "static-server";
import { Page } from "puppeteer";
import { errTuple } from "libskynet";
import * as path from 'path';
import * as kernel from '@lumeweb/libkernel/kernel';
// @ts-ignore
import StaticServer from 'static-server';
import { Page } from 'puppeteer';
import { bufToHex, ed25519, ErrTuple } from '@lumeweb/libkernel';
import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
import * as url from "url";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
export function generateSeedPhrase() {
return ed.utils.randomPrivateKey();
return ed25519.utils.randomPrivateKey();
}
export async function login(page: Page, seed = generateSeedPhrase()) {
await page.goto("http://kernel.lumeweb.com");
await page.goto('http://kernel.lumeweb.com');
let userSeed = seed;
let seedHex = bufToHex(userSeed);
let seedHex = bufToHex(seed);
await page.evaluate((seed: string) => {
window.localStorage.setItem("v1-key", seed);
window.localStorage.setItem('v1-key', seed);
}, seedHex);
}
export async function loadTester(page: Page, port = 8080) {
const server = new StaticServer({
rootPath: path.resolve(__dirname, "..", "public"),
rootPath: path.resolve(__dirname, '..', 'public'),
port,
host: "localhost",
host: 'localhost',
});
await new Promise((resolve) => {
server.start(resolve);
});
const stop = () => server.stop();
process.on("SIGTERM", stop);
page.browser().on("disconnected", stop);
process.on('SIGTERM', stop);
page.browser().on('disconnected', stop);
await page.goto(`http://localhost:${port}/`);
await page.evaluate(() => {
@ -61,14 +51,14 @@ class Tester {
this.page = page;
}
async callModule(id: string, method: string, data = {}): Promise<errTuple> {
async callModule(id: string, method: string, data = {}): Promise<ErrTuple> {
return this.page.evaluate(
async (id, method, data) => {
return kernel.callModule(id, method, data);
},
id,
method,
data
data,
);
}
}

View File

@ -1,8 +1,8 @@
#!/usr/bin/env node
// @ts-ignore
import { loadTester, login } from "../dist/index.js";
import { loadTester, login } from '../build/index.js';
import puppeteer, { Browser, Page, ProtocolError } from "puppeteer";
import puppeteer, { Browser, Page, ProtocolError } from 'puppeteer';
let browser: Browser;
@ -14,10 +14,10 @@ let browser: Browser;
await loadTester(page);
})();
process.on("SIGTERM", async () => {
process.on('SIGTERM', async () => {
await browser.close();
});
process.on("uncaughtException", (e) => {
process.on('uncaughtException', (e) => {
if (!(e instanceof ProtocolError)) {
throw e;
}

View File

@ -1,10 +1,7 @@
import * as kernel from "libkernel";
import * as skynet from "libskynet";
import * as kernel from "@lumeweb/libkernel";
// @ts-ignore
window.kernel = kernel;
// @ts-ignore
window.skynet = skynet;
window.addEventListener("message", (event) => {
const data = event.data?.data;

View File

@ -1,15 +0,0 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"declaration": true,
"moduleResolution": "node",
"outDir": "./build",
"strict": true,
"allowSyntheticDefaultImports": true
},
"include": [
"src",
],
"exclude": ["node_modules", "**/__tests__/*"]
}