Compare commits

...

45 Commits

Author SHA1 Message Date
semantic-release-bot 129b706490 chore(release): 0.0.2-develop.9 [skip ci]
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-10-13)
2023-10-13 10:55:09 +00:00
Derrick Hammer 2227964e77
Merge remote-tracking branch 'origin/develop' into develop 2023-10-13 06:53:38 -04:00
Derrick Hammer 1397469eaa
dep: update kernel-swarm-client and protomux-rpc-web 2023-10-13 06:53:29 -04:00
semantic-release-bot 72f8a0b135 chore(release): 0.0.2-develop.8 [skip ci]
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-09-04)
2023-09-04 10:31:33 +00:00
Derrick Hammer 6c132fbfd9
Merge remote-tracking branch 'origin/develop' into develop 2023-09-04 06:30:29 -04:00
Derrick Hammer 8303e1549f
dep: update libkernel 2023-09-04 06:30:12 -04:00
Derrick Hammer 685527ca21
dep: update deps 2023-09-03 01:07:36 -04:00
semantic-release-bot 8165b2329e chore(release): 0.0.2-develop.7 [skip ci]
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-09-02)
2023-09-02 14:19:37 +00:00
Derrick Hammer 05103931a7
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 10:18:06 -04:00
Derrick Hammer f8ffa5a59b
dep: update kernel-swarm-client, protomux-rpc-web 2023-09-02 10:18:01 -04:00
semantic-release-bot d29f193d30 chore(release): 0.0.2-develop.6 [skip ci]
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-09-02)
2023-09-02 13:22:23 +00:00
Derrick Hammer 53f6df2259
Merge remote-tracking branch 'origin/develop' into develop 2023-09-02 09:21:03 -04:00
Derrick Hammer cd98198b7c
dep: update kernel-swarm-client,libkernel, protomux-rpc-web 2023-09-02 09:20:58 -04:00
semantic-release-bot 43a0987534 chore(release): 0.0.2-develop.5 [skip ci]
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-29)
2023-07-29 16:28:24 +00:00
Derrick Hammer 920f831eac
Merge remote-tracking branch 'origin/develop' into develop 2023-07-29 12:27:29 -04:00
Derrick Hammer 95a25d0d1c
dep: update protomux-rpc-web and kernel-swarm-client 2023-07-29 12:27:25 -04:00
semantic-release-bot d75634b2b8 chore(release): 0.0.2-develop.4 [skip ci]
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-24)
2023-07-24 17:43:11 +00:00
Derrick Hammer 5b580ce178
Merge remote-tracking branch 'origin/develop' into develop 2023-07-24 13:42:09 -04:00
Derrick Hammer 9506b0da3c
dep: update protomux-rpc-web and kernel-swarm-client 2023-07-24 13:42:03 -04:00
semantic-release-bot ef855ff411 chore(release): 0.0.2-develop.3 [skip ci]
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-23)
2023-07-23 18:47:16 +00:00
Derrick Hammer 0186ea4bcd
Merge remote-tracking branch 'origin/develop' into develop 2023-07-23 14:46:17 -04:00
Derrick Hammer 0f8496f618
dep: update protomux-rpc-web and kernel-swarm-client 2023-07-23 14:46:12 -04:00
semantic-release-bot 1a1f9e5bc5 chore(release): 0.0.2-develop.2 [skip ci]
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-23)
2023-07-23 00:20:34 +00:00
Derrick Hammer 1eb5b1e629
Merge remote-tracking branch 'origin/develop' into develop 2023-07-22 20:19:02 -04:00
Derrick Hammer 3b185faa0b
dep: update protomux-rpc-web 2023-07-22 20:18:57 -04:00
semantic-release-bot c1af787fed chore(release): 0.0.2-develop.1 [skip ci]
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.1...v0.0.2-develop.1) (2023-07-22)

### Bug Fixes

* add endPeerOnError handler ([57f1e40](57f1e40eff))
* presentSeed needs to be presentKey ([a74b2d4](a74b2d416e))

### Reverts

* Revert "*Use swarm start, not swarm ready" ([c155a4e](c155a4ea1c))
2023-07-22 14:31:38 +00:00
Derrick Hammer 57f1e40eff
fix: add endPeerOnError handler 2023-07-22 10:28:31 -04:00
Derrick Hammer 1bb59e1079
dep: update deps 2023-07-22 10:28:27 -04:00
Derrick Hammer 71b0d64074
dep: update protomux-rpc-web 2023-07-22 07:25:20 -04:00
Derrick Hammer aaa808fd56
dep: update protomux-rpc-web 2023-07-22 06:25:50 -04:00
Derrick Hammer 821d4cd075
dep: update protomux-rpc-web 2023-07-21 22:00:40 -04:00
Derrick Hammer 1a8b68153a
dep: update protomux-rpc-web 2023-07-21 20:47:16 -04:00
Derrick Hammer d4b9b2834a
dep: update deps 2023-07-12 06:53:07 -04:00
Derrick Hammer 4d0dd268aa
dep: update deps 2023-07-12 06:50:35 -04:00
Derrick Hammer b77f0d2993
dep: update presetter-kernel-module-preset 2023-07-11 07:17:46 -04:00
Derrick Hammer 44ce08c40d
dep: update kernel-swarm-client and protomux-rpc-web 2023-07-08 07:49:15 -04:00
Derrick Hammer cc00a0fe7d
refactor: move to vite bundler 2023-07-08 04:59:38 -04:00
Derrick Hammer 00a83a5f84
dep: update protomux-rpc-web and kernel-swarm-client 2023-07-08 04:19:36 -04:00
Derrick Hammer 6543c04a1c
dep: update protomux-rpc-web and kernel-swarm-client 2023-07-04 23:21:21 -04:00
Derrick Hammer fe59475d59
dep: update @lumeweb/protomux-rpc-web 2023-07-04 11:56:29 -04:00
Derrick Hammer b39bbb8735
ci: customize build to override hyperswarm, protomux-rpc and timers 2023-07-04 10:19:56 -04:00
Derrick Hammer 293c1bbacc
dep: update/add deps 2023-07-04 10:19:22 -04:00
Derrick Hammer a74b2d416e
fix: presentSeed needs to be presentKey 2023-07-04 05:45:40 -04:00
Derrick Hammer 4e7ff8774d
ci: setup 2023-07-04 05:16:33 -04:00
Derrick Hammer 81c24fe7ec
refactor: move to new sdks and portal 2023-07-04 05:16:23 -04:00
11 changed files with 20128 additions and 333 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

18
.presetterrc.json Normal file
View File

@ -0,0 +1,18 @@
{
"preset": [
"@lumeweb/presetter-kernel-module-preset"
],
"config": {
"vite": {
"resolve": {
"alias": {
"timers": "timers-browserify",
"protomux-rpc": "@lumeweb/protomux-rpc-web"
}
},
"optimize": {
"hyperswarm": "export default {}"
}
}
}
}

28
CHANGELOG.md Normal file
View File

@ -0,0 +1,28 @@
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-10-13)
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-09-04)
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-09-02)
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-09-02)
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-29)
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-24)
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-23)
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-23)
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/kernel-rpc/compare/v0.0.1...v0.0.2-develop.1) (2023-07-22)
### Bug Fixes
* add endPeerOnError handler ([57f1e40](https://git.lumeweb.com/LumeWeb/kernel-rpc/commit/57f1e40eff0c5bc2d0d8edeeccdf883594781b53))
* presentSeed needs to be presentKey ([a74b2d4](https://git.lumeweb.com/LumeWeb/kernel-rpc/commit/a74b2d416e6ec8d97e725942265792b96ed185f7))
### Reverts
* Revert "*Use swarm start, not swarm ready" ([c155a4e](https://git.lumeweb.com/LumeWeb/kernel-rpc/commit/c155a4ea1c108ac7ef66d884996362a0dd2d9333))

View File

@ -1,14 +0,0 @@
import esbuild from "esbuild";
esbuild.buildSync({
entryPoints: ["src/index.ts"],
outfile: "dist/index.js",
format: "esm",
bundle: true,
legalComments: "external",
// minify: true
define: {
global: "self",
},
external: ["libkernel"],
});

20033
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +1,28 @@
{
"name": "@lumeweb/kernel-rpc",
"version": "0.1.0",
"version": "0.0.2-develop.9",
"type": "module",
"scripts": {
"test": "jest",
"build-script": "tsc --project tsconfig.build.json && mv dist-build/build.js dist-build/build.mjs",
"compile": "npm run build-script && rimraf node_modules/@lumeweb/dht-rpc-client/node_modules node_modules/@lumeweb/kernel-dht-client/node_modules/libkmodule && node build.js",
"build": "npm run compile && node ./dist-build/build.mjs dev"
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/kernel-rpc.git"
},
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"readme": "ERROR: No README data found!",
"dependencies": {
"@lumeweb/interface-relay": "git+https://git.lumeweb.com/LumeWeb/interface-relay.git",
"@lumeweb/kernel-swarm-client": "git+https://git.lumeweb.com/LumeWeb/kernel-swarm-client.git",
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
"@lumeweb/protomux-rpc-web": "git+https://git.lumeweb.com/LumeWeb/protomux-rpc-web.git",
"@lumeweb/rpc-client": "git+https://git.lumeweb.com/LumeWeb/rpc-client.git",
"b4a": "^1.6.3",
"libkmodule": "^0.2.53",
"p-defer": "^4.0.0"
"@lumeweb/kernel-swarm-client": "^0.1.0-develop.11",
"@lumeweb/libkernel": "^0.1.0-develop.44",
"@lumeweb/protomux-rpc-web": "^0.0.2-develop.20",
"@lumeweb/rpc-client": "^0.0.2-develop.5"
},
"devDependencies": {
"@scure/bip39": "^1.2.0",
"@skynetlabs/skynet-nodejs": "^2.9.0",
"@types/b4a": "^1.6.0",
"@types/node": "^18.15.11",
"@types/read": "^0.0.29",
"cli-progress": "^3.12.0",
"esbuild": "^0.17.17",
"read": "^2.1.0",
"timers-browserify": "^2.0.12",
"typescript": "^5.0.4"
},
"browser": {
"timers": "timers-browserify",
"protomux-rpc": "@lumeweb/protomux-rpc-web"
},
"pnpm": {
"patchedDependencies": {
"b4a@1.6.3": "patches/b4a@1.6.3.patch"
}
"@lumeweb/interface-relay": "^0.0.2-develop.3",
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.43",
"@rollup/plugin-alias": "^5.0.0",
"presetter": "^4.0.1",
"timers-browserify": "^2.0.12"
}
}

View File

@ -1,36 +0,0 @@
diff --git a/browser.js b/browser.js
index e07f78d17b7b4a2963e4f0062047cc96e6025f9e..a9f266a2644f3f8ebd0f6684b3e11a7519059851 100644
--- a/browser.js
+++ b/browser.js
@@ -3,6 +3,7 @@ const base64 = require('./lib/base64')
const hex = require('./lib/hex')
const utf8 = require('./lib/utf8')
const utf16le = require('./lib/utf16le')
+const Buffer = require('buffer').Buffer
const LE = new Uint8Array(Uint16Array.of(0xff).buffer)[0] === 0xff
diff --git a/index.js b/index.js
index a751d6b4d27c7dd903efbfdc87a98f61044a62b8..8bd32640afdcfbc475168d458c51f8b9162d1656 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,5 @@
+const Buffer = require('buffer').Buffer
+
function isBuffer (value) {
return Buffer.isBuffer(value) || value instanceof Uint8Array
}
diff --git a/package.json b/package.json
index eb0f792709b27e66f26658054781b4099507b5ed..69c4ff39c48b0bdd5f0bc7ebbade517e7c5d76e4 100644
--- a/package.json
+++ b/package.json
@@ -8,9 +8,6 @@
"index.js",
"lib"
],
- "browser": {
- "./index.js": "./browser.js"
- },
"scripts": {
"test": "standard && brittle test/*.mjs"
},

View File

@ -1,218 +0,0 @@
// This is the standard build script for a kernel module.
import * as fs from "fs";
import read from "read";
import * as bip39 from "@scure/bip39";
import { wordlist } from "@scure/bip39/wordlists/english.js";
//@ts-ignore
import { SkynetClient } from "@skynetlabs/skynet-nodejs";
// Helper variables to make it easier to return empty values alongside errors.
const nu8 = new Uint8Array(0);
const nkp = {
publicKey: nu8,
secretKey: nu8,
};
// readFile is a wrapper for fs.readFileSync that handles the try-catch for the
// caller.
function readFile(fileName: string): [string, string | null] {
try {
let data = fs.readFileSync(fileName, "utf8");
return [data, null];
} catch (err) {
return ["", "unable to read file: " + JSON.stringify(err)];
}
}
// readFileBinary is a wrapper for fs.readFileSync that handles the try-catch
// for the caller.
function readFileBinary(fileName: string): [Uint8Array, string | null] {
try {
let data = fs.readFileSync(fileName, null);
return [data, null];
} catch (err) {
return [nu8, "unable to read file: " + JSON.stringify(err)];
}
}
// writeFile is a wrapper for fs.writeFileSync which handles the try-catch in a
// non-exception way.
function writeFile(fileName: string, fileData: string): string | null {
try {
fs.writeFileSync(fileName, fileData);
return null;
} catch (err) {
return "unable to write file: " + JSON.stringify(err);
}
}
// handlePass handles all portions of the script that occur after the password
// has been requested. If no password needs to be requested, handlePass will be
// called with a null input. We need to structure the code this way because the
// password reader is async and we can only access the password when using a
// callback.
function handlePass(password: string) {
try {
// If we are running prod and the seed file does not exist, we
// need to confirm the password and also warn the user to use a
// secure password.
if (!fs.existsSync(seedFile) && process.argv[2] === "prod") {
// The file does not exist, we need to confirm the
// password.
console.log();
console.log(
"No production entry found for module. Creating new production module..."
);
console.log(
"If someone can guess the password, they can push arbitrary changes to your module."
);
console.log("Please use a secure password.");
console.log();
read(
{ prompt: "Confirm Password: ", silent: true },
function (err: any, confirmPassword: string) {
if (err) {
console.error("unable to fetch password:", err);
process.exit(1);
}
if (password !== confirmPassword) {
console.error("passwords do not match");
process.exit(1);
}
handlePassConfirm(moduleSalt, password);
}
);
} else {
// If the seed file does exist, or if we are using dev,
// there's no need to confirm the password but we do
// need to pass the logic off to the handlePassConfirm
// callback.
handlePassConfirm(moduleSalt, password);
}
} catch (err) {
console.error("Unable to read seedFile:", err);
process.exit(1);
}
}
// handlePassConfirm handles the full script after the confirmation password
// has been provided. If not confirmation password is needed, this function
// will be called anyway using the unconfirmed password as input.
function handlePassConfirm(seed: string, password: string) {
// Create the seedFile if it does not exist. For dev we just save the
// seed to disk outright, because this is a dev build and therefore not
// security sensitive. Also the dev seed does not get pushed to the
// github repo.
//
// For prod, we use the seed to create a new seed (called the shield)
// which allows us to verify that the developer has provided the right
// password when deploying the module. The shield does get pushed to
// the github repo so that the production module is the same on all
// devices.
if (!fs.existsSync(seedFile) && process.argv[2] !== "prod") {
// Generate the seed phrase and write it to the file.
let seedPhrase = bip39.generateMnemonic(wordlist);
let errWF = writeFile(seedFile, seedPhrase);
if (errWF !== null) {
console.error("unable to write file:", errWF);
process.exit(1);
}
} else if (!fs.existsSync(seedFile) && process.argv[2] === "prod") {
// Generate the seed phrase.
let seedPhrase = bip39.generateMnemonic(wordlist);
// Write the registry link to the file.
}
// Load or verify the seed. If this is prod, the password is used to
// create and verify the seed. If this is dev, we just load the seed
// with no password.
let seedPhrase: string;
let registryLink: string;
if (process.argv[2] === "prod") {
// Generate the seed phrase from the password.
seedPhrase = bip39.generateMnemonic(wordlist);
} else {
let [sp, errRF] = readFile(seedFile);
if (errRF !== null) {
console.error("unable to read seed phrase for dev command from disk");
process.exit(1);
}
seedPhrase = sp;
}
let metadata = {
Filename: "index.js",
};
const client = new SkynetClient("https://web3portal.com");
client
.uploadFile("dist/index.js")
.then((result: any) => {
console.log("Immutable Link for module:", result);
})
.catch((err: any) => {
console.error("unable to upload file", err);
process.exit(1);
});
}
// Add a newline for readability.
console.log();
// Check for a 'dev' or 'prod' input to the script.
if (process.argv.length !== 3) {
console.error("need to provide either 'dev' or 'prod' as an input");
process.exit(1);
}
// Create the build folder if it does not exist.
if (!fs.existsSync("build")) {
fs.mkdirSync("build");
}
// Determine the seed file.
let seedFile: string;
if (process.argv[2] === "prod") {
seedFile = "module-skylink";
} else if (process.argv[2] === "dev") {
seedFile = "build/dev-seed";
} else {
console.error("need to provide either 'dev' or 'prod' as an input");
process.exit(1);
}
// If doing a prod deployment, check whether the salt file exists. If it does
// not, create it.
let moduleSalt: string;
if (!fs.existsSync(".module-salt")) {
moduleSalt = bip39.generateMnemonic(wordlist);
let errWF = writeFile(".module-salt", moduleSalt);
if (errWF !== null) {
console.error("unable to write module salt file:", errWF);
process.exit(1);
}
} else {
let [ms, errRF] = readFile(".module-salt");
if (errRF !== null) {
console.error("unable to read moduleSalt");
process.exit(1);
}
ms = ms.replace(/\n$/, "");
moduleSalt = ms;
}
// Need to get a password if this is a prod build.
if (process.argv[2] === "prod") {
read(
{ prompt: "Password: ", silent: true },
function (err: any, password: string) {
if (err) {
console.error("unable to fetch password:", err);
process.exit(1);
}
handlePass(password);
}
);
} else {
handlePass("");
}

View File

@ -1,6 +1,10 @@
import { addHandler, handleMessage } from "libkmodule";
import type { ActiveQuery } from "libkmodule";
import { createClient, SwarmClient } from "@lumeweb/kernel-swarm-client";
import { addHandler, handleMessage } from "@lumeweb/libkernel/module";
import type { ActiveQuery } from "@lumeweb/libkernel/module";
import {
createClient,
Socket,
SwarmClient,
} from "@lumeweb/kernel-swarm-client";
import { RpcNetwork, RpcQueryOptions, setupStream } from "@lumeweb/rpc-client";
import type { RPCRequest, RPCResponse } from "@lumeweb/interface-relay";
@ -27,12 +31,12 @@ let moduleReady: Promise<void> = new Promise((resolve) => {
const networkInstances = new Map<number, RpcNetwork>();
addHandler("presentSeed", handlePresentSeed);
addHandler("presentKey", handlePresentKey);
addHandler("createNetwork", handleCreateNetwork);
addHandler("simpleQuery", handleSimpleQuery);
addHandler("ready", handleReady);
async function handlePresentSeed() {
async function handlePresentKey() {
if (!defaultNetwork) {
defaultNetwork = networkInstances.get(await createNetwork()) as RpcNetwork;
}
@ -42,6 +46,7 @@ async function handlePresentSeed() {
async function handleCreateNetwork(aq: ActiveQuery) {
aq.respond(await createNetwork(false));
}
async function handleSimpleQuery(aq: ActiveQuery) {
const {
query = undefined,
@ -93,6 +98,7 @@ async function handleReady(aq: ActiveQuery) {
).readyWithRelays;
aq.respond();
}
async function createNetwork(def = true): Promise<number> {
const dhtInstance = new RpcNetwork(createClient(def));
const id = nextId();
@ -100,6 +106,12 @@ async function createNetwork(def = true): Promise<number> {
dhtInstance.swarm.on("setup", async (peer: any) => setupStream(peer));
dhtInstance.endPeerOnError = async (peer: Socket) => {
const listeners = (await peer.getListeners()) as string[];
return listeners.length <= 1;
};
return id;
}

View File

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

View File

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