Compare commits
77 Commits
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | c6f6001c8c | |
Derrick Hammer | a92ee9cb13 | |
Derrick Hammer | 699e3ea7ff | |
semantic-release-bot | a182295c90 | |
Derrick Hammer | b9550f6215 | |
Derrick Hammer | 491f1b4a6b | |
semantic-release-bot | 4388760387 | |
Derrick Hammer | fc422be3ca | |
Derrick Hammer | beef5eff8b | |
semantic-release-bot | d98c65be9f | |
Derrick Hammer | ccd27270fc | |
Derrick Hammer | 5b8c2caa48 | |
semantic-release-bot | 5130a1f9d6 | |
Derrick Hammer | 161de281ad | |
Derrick Hammer | 7b43129169 | |
Derrick Hammer | 9201763ef6 | |
semantic-release-bot | 900eafc5d8 | |
Derrick Hammer | e775a171f3 | |
Derrick Hammer | 1664c23d75 | |
semantic-release-bot | 96c8b52cfe | |
Derrick Hammer | fcee2b00c6 | |
Derrick Hammer | cabbfe343d | |
semantic-release-bot | 74f5c83487 | |
Derrick Hammer | 0ed4449161 | |
Derrick Hammer | dcad699ae1 | |
Derrick Hammer | 12cb3a3b5e | |
Derrick Hammer | 873bc3da52 | |
semantic-release-bot | 7971dca7b6 | |
Derrick Hammer | 5117f381f6 | |
Derrick Hammer | ac5877385b | |
semantic-release-bot | c2eb45d485 | |
Derrick Hammer | 3dd34a9af2 | |
Derrick Hammer | ad4511c385 | |
semantic-release-bot | 3c1aed2f2f | |
Derrick Hammer | d312d1704d | |
Derrick Hammer | 296acba3b4 | |
Derrick Hammer | e56cbecbcf | |
Derrick Hammer | 39a91144de | |
semantic-release-bot | f96d4c319f | |
Derrick Hammer | 9d2b64d510 | |
Derrick Hammer | 04c7292e44 | |
semantic-release-bot | 6a5a6346bb | |
Derrick Hammer | aa3153e4f8 | |
Derrick Hammer | e779cae293 | |
semantic-release-bot | 54af6c5c1b | |
Derrick Hammer | 37dcb39466 | |
Derrick Hammer | 99f1c7c799 | |
semantic-release-bot | b955e19e72 | |
Derrick Hammer | 27e3452074 | |
Derrick Hammer | 928cff2a08 | |
semantic-release-bot | b7f7235fe0 | |
Derrick Hammer | 8008bfe98d | |
Derrick Hammer | 10170bd673 | |
Derrick Hammer | cb3421b662 | |
semantic-release-bot | 18cf0fd19c | |
Derrick Hammer | af224e742a | |
Derrick Hammer | 3a4cfd45a6 | |
semantic-release-bot | 09438cf112 | |
Derrick Hammer | 411d35154f | |
Derrick Hammer | 57496da5cc | |
Derrick Hammer | 9b2387b517 | |
Derrick Hammer | bf32cebe93 | |
Derrick Hammer | 9958b7cfc2 | |
Derrick Hammer | 1b9e656e86 | |
Derrick Hammer | 3b2cf557dc | |
Derrick Hammer | 5816ab308a | |
Derrick Hammer | 2f92782995 | |
Derrick Hammer | 2e86ce5ffa | |
Derrick Hammer | a0ba6dd6c7 | |
Derrick Hammer | 1a9f593a7c | |
semantic-release-bot | 66ab8412a2 | |
Derrick Hammer | 3fe82e33a0 | |
semantic-release-bot | da0616ac45 | |
Derrick Hammer | 99b355f7a1 | |
semantic-release-bot | 0379757dcd | |
Derrick Hammer | 8a80ba9ac5 | |
Derrick Hammer | cc929a903a |
|
@ -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
|
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"preset": [
|
||||||
|
"@lumeweb/presetter-kernel-module-preset"
|
||||||
|
],
|
||||||
|
"config": {
|
||||||
|
"vite": {
|
||||||
|
"resolve": {
|
||||||
|
"alias": {
|
||||||
|
"sodium-universal": "@screamingvoid/sodium-universal"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-10-13)
|
||||||
|
|
||||||
|
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-09-04)
|
||||||
|
|
||||||
|
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-09-03)
|
||||||
|
|
||||||
|
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-09-03)
|
||||||
|
|
||||||
|
# [0.1.0-develop.7](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.6...v0.1.0-develop.7) (2023-09-02)
|
||||||
|
|
||||||
|
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-09-02)
|
||||||
|
|
||||||
|
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-07-29)
|
||||||
|
|
||||||
|
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-07-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* on swarmInstance init, add every relay as an explicit peer ([873bc3d](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/873bc3da52d206635d7dea5f8090e1a05ccf6828))
|
||||||
|
* patch dht-relay handshake logic to prevent duplicate processing ([12cb3a3](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/12cb3a3b5ee16bbda03458627a0ea67f89d7576b))
|
||||||
|
* patch protomux to use the buffers arraybuffer byteLength ([dcad699](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/dcad699ae1f5f14e3ffe3844607028a6cd53130e))
|
||||||
|
|
||||||
|
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-07-23)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add socketSetKeepAlive api method ([ac58773](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/ac5877385b96b7162a646cadc9b9512759f21bbb))
|
||||||
|
|
||||||
|
# [0.1.0-develop.2](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.1.0-develop.1...v0.1.0-develop.2) (2023-07-23)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove unneeded mutex call ([ad4511c](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/ad4511c3853d6cd3fc5c3f0490012ca34f5c66ce))
|
||||||
|
|
||||||
|
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.10...v0.1.0-develop.1) (2023-07-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add socketListeners api call ([e56cbec](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/e56cbecbcf6641ea12059868829b9428a3c327c2))
|
||||||
|
* track what modules are listening on a socket connection by their module id ([39a9114](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/39a91144de1641ec17ba02888409009310aca67a))
|
||||||
|
|
||||||
|
## [0.0.2-develop.10](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.9...v0.0.2-develop.10) (2023-07-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove mutex and don't make cb async to prevent race condition ([04c7292](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/04c7292e44a9ad272543ff241dad72af4ce5ccaa))
|
||||||
|
|
||||||
|
## [0.0.2-develop.9](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.8...v0.0.2-develop.9) (2023-07-12)
|
||||||
|
|
||||||
|
## [0.0.2-develop.8](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.7...v0.0.2-develop.8) (2023-07-11)
|
||||||
|
|
||||||
|
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-07-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* pin buffer version ([928cff2](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/928cff2a083e5282d15882b6be05ab42d6e2cab2))
|
||||||
|
|
||||||
|
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* need to patch our own sdk for bundling so we don't need to put the hack in directly ([10170bd](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/10170bd673ccd4070c2ab9e0b444cba81080311d))
|
||||||
|
|
||||||
|
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* need to loop over all protomux message args and await any promises ([3a4cfd4](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/3a4cfd45a6515fac5a4205d0c2503864efbd33bf))
|
||||||
|
|
||||||
|
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add patch-package to postinstall ([5816ab3](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/5816ab308ada8f489d4f01d6110bf2dd14092412))
|
||||||
|
* keypair needs to be a private extended key ([57496da](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/57496da5cc4c0aa4c0fd941d45d32ae4ed798d36))
|
||||||
|
* need to add browser flag to .presetterrc.json ([2f92782](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/2f92782995af6a15719325e482a077e87a7b6b6e))
|
||||||
|
* we need to use the wasm libsodium @screamingvoid/sodium-universal ([411d351](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/411d35154f6a3176a9ee8c2033ac3ea2877d6be9))
|
||||||
|
|
||||||
|
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-01)
|
||||||
|
|
||||||
|
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* rename var nextId ([99b355f](https://git.lumeweb.com/LumeWeb/kernel-swarm/commit/99b355f7a1e8711d7d475d88cbd09338de0e8f1f))
|
||||||
|
|
||||||
|
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/kernel-swarm/compare/v0.0.1...v0.0.2-develop.1) (2023-07-01)
|
14
build.js
14
build.js
|
@ -1,14 +0,0 @@
|
||||||
import esbuild from "esbuild";
|
|
||||||
|
|
||||||
esbuild.buildSync({
|
|
||||||
entryPoints: ["src/index.ts"],
|
|
||||||
outfile: "dist/index.js",
|
|
||||||
format: "iife",
|
|
||||||
bundle: true,
|
|
||||||
legalComments: "external",
|
|
||||||
// minify: true
|
|
||||||
define: {
|
|
||||||
global: "self",
|
|
||||||
},
|
|
||||||
inject: ["process.js", "polyfill.js"],
|
|
||||||
});
|
|
File diff suppressed because it is too large
Load Diff
73
package.json
73
package.json
|
@ -4,64 +4,43 @@
|
||||||
"name": "Hammer Technologies LLC",
|
"name": "Hammer Technologies LLC",
|
||||||
"email": "contact@lumeweb.com"
|
"email": "contact@lumeweb.com"
|
||||||
},
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "gitea@git.lumeweb.com:LumeWeb/kernel-swarm.git"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"prepare": "presetter bootstrap",
|
||||||
"format": "prettier -w src",
|
"build": "run build",
|
||||||
"build-script": "tsc --project tsconfig.build.json && mv dist-build/build.js dist-build/build.mjs",
|
"semantic-release": "semantic-release",
|
||||||
"compile": "npm run build-script && node build.js",
|
"postinstall": "patch-package"
|
||||||
"build": "npm run compile && node ./dist-build/build.mjs dev"
|
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/hyperswarm-web": "git+https://git.lumeweb.com/LumeWeb/hyperswarm-web.git",
|
"@lumeweb/hyperswarm-web": "0.0.2-develop.13",
|
||||||
"@lumeweb/rpc": "git+https://git.lumeweb.com/LumeWeb/rpc.git",
|
"@lumeweb/libkernel": "^0.1.0-develop.44",
|
||||||
"@noble/ed25519": "^1.7.3",
|
"@lumeweb/rpc": "0.0.2-develop.1",
|
||||||
"@peculiar/webcrypto": "git+https://git.lumeweb.com/LumeWeb/webcrypto.git",
|
"@noble/curves": "^1.1.0",
|
||||||
|
"@peculiar/webcrypto": "^1.4.3",
|
||||||
|
"@screamingvoid/sodium-universal": "^0.1.1",
|
||||||
"async-mutex": "^0.4.0",
|
"async-mutex": "^0.4.0",
|
||||||
"b4a": "^1.6.3",
|
"b4a": "^1.6.4",
|
||||||
"eventemitter2": "^6.4.9",
|
"eventemitter2": "^6.4.9",
|
||||||
"hyperswarm": "^4.4.0",
|
"hyperswarm": "^4.5.1",
|
||||||
"libkmodule": "^0.2.53",
|
"noise-handshake": "^3.0.3",
|
||||||
"libskynet": "^0.0.62",
|
|
||||||
"noise-handshake": "^3.0.2",
|
|
||||||
"p-defer": "^4.0.0",
|
"p-defer": "^4.0.0",
|
||||||
"protomux": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux.git",
|
"protomux": "^3.5.0"
|
||||||
"randombytes": "github:LumeWeb/randombytes-browser"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-commonjs": "^22.0.2",
|
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.41",
|
||||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
"@rollup/plugin-alias": "^5.0.0",
|
||||||
"@rollup/plugin-typescript": "^8.5.0",
|
|
||||||
"@screamingvoid/sodium-universal": "^0.1.1",
|
|
||||||
"@scure/bip39": "^1.2.0",
|
|
||||||
"@skynetlabs/skynet-nodejs": "^2.9.0",
|
|
||||||
"@types/b4a": "^1.6.0",
|
"@types/b4a": "^1.6.0",
|
||||||
"@types/jest": "^28.1.8",
|
|
||||||
"@types/read": "^0.0.29",
|
|
||||||
"buffer": "^6.0.3",
|
|
||||||
"cli-progress": "^3.12.0",
|
|
||||||
"crypto-browserify": "^3.12.0",
|
"crypto-browserify": "^3.12.0",
|
||||||
"esbuild": "^0.14.54",
|
"patch-package": "^7.0.0",
|
||||||
"inspectpack": "^4.7.1",
|
"presetter": "*"
|
||||||
"jest": "^28.1.3",
|
|
||||||
"jest-puppeteer": "^6.2.0",
|
|
||||||
"libskynetnode": "^0.1.4",
|
|
||||||
"prettier": "^2.8.7",
|
|
||||||
"process": "^0.11.10",
|
|
||||||
"puppeteer": "^15.5.0",
|
|
||||||
"random-number-csprng": "^1.0.2",
|
|
||||||
"read": "^1.0.7",
|
|
||||||
"rollup": "^2.79.1",
|
|
||||||
"rollup-plugin-polyfill-node": "^0.9.0",
|
|
||||||
"stream-browserify": "^3.0.0",
|
|
||||||
"ts-loader": "^9.4.2",
|
|
||||||
"typescript": "^4.9.5",
|
|
||||||
"webpack": "^5.79.0",
|
|
||||||
"webpack-cli": "^4.10.0"
|
|
||||||
},
|
},
|
||||||
"browser": {
|
"version": "0.1.0-develop.11",
|
||||||
"sodium-universal": "@screamingvoid/sodium-universal",
|
"readme": "ERROR: No README data found!",
|
||||||
"crypto": "crypto-browserify",
|
"overrides": {
|
||||||
"stream": "stream-browserify"
|
"buffer": "^6.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
diff --git a/node_modules/@hyperswarm/dht-relay/lib/node.js b/node_modules/@hyperswarm/dht-relay/lib/node.js
|
||||||
|
index 9ee8ef9..8a37655 100644
|
||||||
|
--- a/node_modules/@hyperswarm/dht-relay/lib/node.js
|
||||||
|
+++ b/node_modules/@hyperswarm/dht-relay/lib/node.js
|
||||||
|
@@ -407,7 +407,7 @@ function onNoiseReceive (message) {
|
||||||
|
if (message.isInitiator) {
|
||||||
|
const handshake = this._handshakes.get(message.id)
|
||||||
|
|
||||||
|
- if (handshake) {
|
||||||
|
+ if (handshake && !handshake.complete) {
|
||||||
|
handshake._onNoiseReceive(message)
|
||||||
|
}
|
||||||
|
} else {
|
|
@ -0,0 +1,54 @@
|
||||||
|
diff --git a/node_modules/protomux/index.js b/node_modules/protomux/index.js
|
||||||
|
index 07bf0ad..ef91c72 100644
|
||||||
|
--- a/node_modules/protomux/index.js
|
||||||
|
+++ b/node_modules/protomux/index.js
|
||||||
|
@@ -195,34 +195,34 @@ class Channel {
|
||||||
|
type,
|
||||||
|
encoding,
|
||||||
|
onmessage,
|
||||||
|
- recv (state, session) {
|
||||||
|
+ async recv (state, session) {
|
||||||
|
session._track(m.onmessage(encoding.decode(state), session))
|
||||||
|
},
|
||||||
|
- send (m, session = s) {
|
||||||
|
+ async send (m, session = s) {
|
||||||
|
if (session.closed === true) return false
|
||||||
|
|
||||||
|
const mux = session._mux
|
||||||
|
const state = { buffer: null, start: 0, end: typeLen }
|
||||||
|
|
||||||
|
if (mux._batch !== null) {
|
||||||
|
- encoding.preencode(state, m)
|
||||||
|
+ await encoding.preencode(state, m)
|
||||||
|
state.buffer = mux._alloc(state.end)
|
||||||
|
|
||||||
|
c.uint.encode(state, type)
|
||||||
|
- encoding.encode(state, m)
|
||||||
|
+ await encoding.encode(state, m)
|
||||||
|
|
||||||
|
mux._pushBatch(session._localId, state.buffer)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
c.uint.preencode(state, session._localId)
|
||||||
|
- encoding.preencode(state, m)
|
||||||
|
+ await encoding.preencode(state, m)
|
||||||
|
|
||||||
|
state.buffer = mux._alloc(state.end)
|
||||||
|
|
||||||
|
c.uint.encode(state, session._localId)
|
||||||
|
c.uint.encode(state, type)
|
||||||
|
- encoding.encode(state, m)
|
||||||
|
+ await encoding.encode(state, m)
|
||||||
|
|
||||||
|
mux.drained = mux.stream.write(state.buffer)
|
||||||
|
|
||||||
|
@@ -417,7 +417,7 @@ module.exports = class Protomux {
|
||||||
|
|
||||||
|
_ondata (buffer) {
|
||||||
|
try {
|
||||||
|
- const state = { buffer, start: 0, end: buffer.byteLength }
|
||||||
|
+ const state = { buffer, start: 0, end: buffer.buffer.byteLength }
|
||||||
|
this._decode(c.uint.decode(state), state)
|
||||||
|
} catch (err) {
|
||||||
|
this._safeDestroy(err)
|
11
polyfill.js
11
polyfill.js
|
@ -1,11 +0,0 @@
|
||||||
import { Crypto } from "@peculiar/webcrypto";
|
|
||||||
|
|
||||||
let globalCrypto = self.crypto;
|
|
||||||
if (!globalCrypto.subtle) {
|
|
||||||
let subtleCrypto = new Crypto().subtle;
|
|
||||||
Object.defineProperty(globalCrypto, "subtle", {
|
|
||||||
get() {
|
|
||||||
return subtleCrypto;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
export const process = require('process');
|
|
||||||
|
|
||||||
|
|
|
@ -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 kernel:", 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("");
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ export function pubKeyToIpv6(publicKey: Uint8Array) {
|
||||||
addr[prefix.length] = ones;
|
addr[prefix.length] = ones;
|
||||||
addr.set(nodeId, prefix.length + 1);
|
addr.set(nodeId, prefix.length + 1);
|
||||||
|
|
||||||
const result = [];
|
const result: string[] = [];
|
||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
const num1 = addr[i * 2].toString(16).padStart(2, "0");
|
const num1 = addr[i * 2].toString(16).padStart(2, "0");
|
||||||
const num2 = addr[i * 2 + 1].toString(16).padStart(2, "0");
|
const num2 = addr[i * 2 + 1].toString(16).padStart(2, "0");
|
||||||
|
@ -46,7 +46,7 @@ function getLeadingOnes(buf: Uint8Array) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTruncatedNodeID(buf: Uint8Array) {
|
function getTruncatedNodeID(buf: Uint8Array) {
|
||||||
const result = [];
|
const result: number[] = [];
|
||||||
let done = false;
|
let done = false;
|
||||||
let bits = 0;
|
let bits = 0;
|
||||||
let nBits = 0;
|
let nBits = 0;
|
||||||
|
|
133
src/index.ts
133
src/index.ts
|
@ -1,17 +1,22 @@
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Hyperswarm from "@lumeweb/hyperswarm-web";
|
import Hyperswarm from "@lumeweb/hyperswarm-web";
|
||||||
import type { ActiveQuery } from "libkmodule";
|
import type { ActiveQuery } from "@lumeweb/libkernel/module";
|
||||||
import { addHandler, getSeed, handleMessage } from "libkmodule";
|
import {
|
||||||
import { handlePresentSeed as handlePresentSeedModule } from "libkmodule/dist/seed.js";
|
addHandler,
|
||||||
|
getKey,
|
||||||
|
handleMessage,
|
||||||
|
handlePresentKey as handlePresentKeyModule,
|
||||||
|
logErr,
|
||||||
|
} from "@lumeweb/libkernel/module";
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
import * as ed from "@noble/ed25519";
|
import { ed25519 } from "@noble/curves/ed25519";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import { pubKeyToIpv6 } from "./addr.js";
|
import { pubKeyToIpv6 } from "./addr.js";
|
||||||
import { EventEmitter2 as EventEmitter } from "eventemitter2";
|
import { EventEmitter2 as EventEmitter } from "eventemitter2";
|
||||||
import { logErr } from "libkmodule/dist";
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Protomux from "protomux";
|
import Protomux from "protomux";
|
||||||
import defer, { DeferredPromise } from "p-defer";
|
import defer, { DeferredPromise } from "p-defer";
|
||||||
|
import { concatBytes, hexToBytes } from "@lumeweb/libweb";
|
||||||
|
|
||||||
const MAX_PEER_LISTENERS = 20;
|
const MAX_PEER_LISTENERS = 20;
|
||||||
|
|
||||||
|
@ -19,6 +24,7 @@ interface SwarmConnection {
|
||||||
swarm: number;
|
swarm: number;
|
||||||
conn: any;
|
conn: any;
|
||||||
channels: Map<number, Protomux>;
|
channels: Map<number, Protomux>;
|
||||||
|
listeners: Map<string, number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SwarmEvents {
|
interface SwarmEvents {
|
||||||
|
@ -43,9 +49,9 @@ function idFactory(start = 1) {
|
||||||
let id = start;
|
let id = start;
|
||||||
|
|
||||||
return function nextId() {
|
return function nextId() {
|
||||||
const nextId = id;
|
const _nextId = id;
|
||||||
id += 1;
|
id += 1;
|
||||||
return nextId;
|
return _nextId;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +60,7 @@ const getSocketId = idFactory();
|
||||||
const getChannelId = idFactory();
|
const getChannelId = idFactory();
|
||||||
const getMessageId = idFactory();
|
const getMessageId = idFactory();
|
||||||
|
|
||||||
addHandler("presentSeed", handlePresentSeed);
|
addHandler("presentKey", handlePresentKey);
|
||||||
addHandler("join", handleJoin);
|
addHandler("join", handleJoin);
|
||||||
addHandler("getPeerByPubkey", handleGetPeerByPubkey);
|
addHandler("getPeerByPubkey", handleGetPeerByPubkey);
|
||||||
|
|
||||||
|
@ -73,8 +79,10 @@ addHandler("socketExists", handleSocketExists);
|
||||||
addHandler("socketListenEvent", handleSocketListenEvent, {
|
addHandler("socketListenEvent", handleSocketListenEvent, {
|
||||||
receiveUpdates: true,
|
receiveUpdates: true,
|
||||||
});
|
});
|
||||||
|
addHandler("socketListeners", handleSocketListenersEvent);
|
||||||
addHandler("socketWrite", handleWriteSocketEvent);
|
addHandler("socketWrite", handleWriteSocketEvent);
|
||||||
addHandler("socketClose", handleCloseSocketEvent);
|
addHandler("socketClose", handleCloseSocketEvent);
|
||||||
|
addHandler("socketSetKeepAlive", handleSocketSetKeepAliveEvent);
|
||||||
addHandler("createProtomuxChannel", handleCreateProtomuxChannel, {
|
addHandler("createProtomuxChannel", handleCreateProtomuxChannel, {
|
||||||
receiveUpdates: true,
|
receiveUpdates: true,
|
||||||
});
|
});
|
||||||
|
@ -83,14 +91,10 @@ addHandler("createProtomuxMessage", handleCreateProtomuxMessage, {
|
||||||
});
|
});
|
||||||
addHandler("createSwarm", handleCreateSwarm);
|
addHandler("createSwarm", handleCreateSwarm);
|
||||||
|
|
||||||
async function handlePresentSeed(aq: ActiveQuery) {
|
async function handlePresentKey(aq: ActiveQuery) {
|
||||||
const pubkey = await ed.getPublicKey(aq.callerInput.rootKey);
|
handlePresentKeyModule({
|
||||||
handlePresentSeedModule({
|
|
||||||
callerInput: {
|
callerInput: {
|
||||||
seed: {
|
key: aq.callerInput.rootKey,
|
||||||
publicKey: await ed.getPublicKey(aq.callerInput.rootKey),
|
|
||||||
secretKey: b4a.concat([aq.callerInput.rootKey, pubkey]),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
} as ActiveQuery);
|
} as ActiveQuery);
|
||||||
|
|
||||||
|
@ -101,7 +105,13 @@ async function handlePresentSeed(aq: ActiveQuery) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createSwarm(): Promise<number> {
|
async function createSwarm(): Promise<number> {
|
||||||
const swarmInstance = new Hyperswarm({ keyPair: await getSeed() });
|
const privateKey = await getKey();
|
||||||
|
const swarmInstance = new Hyperswarm({
|
||||||
|
keyPair: {
|
||||||
|
publicKey: ed25519.getPublicKey(privateKey),
|
||||||
|
secretKey: concatBytes(privateKey, ed25519.getPublicKey(privateKey)),
|
||||||
|
},
|
||||||
|
});
|
||||||
const id = getSwarmId();
|
const id = getSwarmId();
|
||||||
swarmInstances.set(id, swarmInstance);
|
swarmInstances.set(id, swarmInstance);
|
||||||
|
|
||||||
|
@ -115,6 +125,7 @@ async function createSwarm(): Promise<number> {
|
||||||
swarm: id,
|
swarm: id,
|
||||||
conn: peer,
|
conn: peer,
|
||||||
channels: new Map<number, Protomux>(),
|
channels: new Map<number, Protomux>(),
|
||||||
|
listeners: new Map<string, number>(),
|
||||||
});
|
});
|
||||||
|
|
||||||
peer.once("close", () => {
|
peer.once("close", () => {
|
||||||
|
@ -123,6 +134,9 @@ async function createSwarm(): Promise<number> {
|
||||||
|
|
||||||
swarmInstanceEvents.emit("connection", peer);
|
swarmInstanceEvents.emit("connection", peer);
|
||||||
});
|
});
|
||||||
|
swarmInstance.relays.forEach((relay) => {
|
||||||
|
swarmInstance.activeRelay.joinPeer(hexToBytes(relay));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
swarmInstance.onSelf("close", (...args) => {
|
swarmInstance.onSelf("close", (...args) => {
|
||||||
|
@ -148,6 +162,8 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const conn = connections.get(aq.callerInput.id) as SwarmConnection;
|
||||||
|
|
||||||
let responded = false;
|
let responded = false;
|
||||||
const respond = () => {
|
const respond = () => {
|
||||||
if (responded) {
|
if (responded) {
|
||||||
|
@ -155,11 +171,19 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
}
|
}
|
||||||
|
|
||||||
responded = true;
|
responded = true;
|
||||||
|
let count = conn.listeners.get(aq.domain) as number;
|
||||||
|
count--;
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
conn.listeners.set(aq.domain, count);
|
||||||
|
} else {
|
||||||
|
conn.listeners.delete(aq.domain);
|
||||||
|
}
|
||||||
|
|
||||||
aq.respond();
|
aq.respond();
|
||||||
};
|
};
|
||||||
|
|
||||||
const cb = async (data: Buffer) => {
|
const cb = (data: Buffer) => {
|
||||||
await socket.mutex?.waitForUnlock();
|
|
||||||
if (responded) {
|
if (responded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +200,30 @@ function handleSocketListenEvent(aq: ActiveQuery) {
|
||||||
socket.off(event, cb);
|
socket.off(event, cb);
|
||||||
respond();
|
respond();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!conn.listeners.has(aq.domain)) {
|
||||||
|
conn.listeners.set(aq.domain, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.listeners.set(aq.domain, (conn.listeners.get(aq.domain) as number) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSocketListenersEvent(aq: ActiveQuery) {
|
||||||
|
const socket = validateConnection(aq);
|
||||||
|
|
||||||
|
if (!socket) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const conn = connections.get(aq.callerInput.id) as SwarmConnection;
|
||||||
|
|
||||||
|
aq.respond(
|
||||||
|
[...conn.listeners.entries()]
|
||||||
|
.filter((item) => {
|
||||||
|
return item[1] > 0;
|
||||||
|
})
|
||||||
|
.map((item) => item[0]),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSocketExists(aq: ActiveQuery) {
|
async function handleSocketExists(aq: ActiveQuery) {
|
||||||
|
@ -196,6 +244,25 @@ function handleCloseSocketEvent(aq: ActiveQuery) {
|
||||||
aq.respond();
|
aq.respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSocketSetKeepAliveEvent(aq: ActiveQuery) {
|
||||||
|
const socket = validateConnection(aq);
|
||||||
|
|
||||||
|
if (!socket) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { alive = null } = aq.callerInput;
|
||||||
|
|
||||||
|
if (!alive) {
|
||||||
|
aq.reject("alive required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.setKeepAlive(aq.callerInput.alive);
|
||||||
|
|
||||||
|
aq.respond();
|
||||||
|
}
|
||||||
|
|
||||||
async function handleWriteSocketEvent(aq: ActiveQuery) {
|
async function handleWriteSocketEvent(aq: ActiveQuery) {
|
||||||
const socket = validateConnection(aq);
|
const socket = validateConnection(aq);
|
||||||
|
|
||||||
|
@ -206,11 +273,9 @@ async function handleWriteSocketEvent(aq: ActiveQuery) {
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
aq.reject("empty message");
|
aq.reject("empty message");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await socket.mutex?.waitForUnlock();
|
|
||||||
|
|
||||||
socket.write(message);
|
socket.write(message);
|
||||||
|
|
||||||
aq.respond();
|
aq.respond();
|
||||||
|
@ -375,7 +440,8 @@ async function handleListenConnections(aq: ActiveQuery) {
|
||||||
const swarmEvent = swarmEvents.get(swarmId as number)?.events;
|
const swarmEvent = swarmEvents.get(swarmId as number)?.events;
|
||||||
|
|
||||||
if (!swarmEvent) {
|
if (!swarmEvent) {
|
||||||
logErr("swarm event object is missing");
|
aq.reject("swarm event object is missing");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
swarmEvent?.on("connection", listener);
|
swarmEvent?.on("connection", listener);
|
||||||
|
@ -447,7 +513,7 @@ async function handleCreateProtomuxChannel(aq: ActiveQuery) {
|
||||||
}
|
}
|
||||||
return (...args: any) => {
|
return (...args: any) => {
|
||||||
args = args.filter(
|
args = args.filter(
|
||||||
(item: any) => item?.constructor.name.toLowerCase() !== "channel"
|
(item: any) => item?.constructor.name.toLowerCase() !== "channel",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (name === "destroy") {
|
if (name === "destroy") {
|
||||||
|
@ -559,7 +625,7 @@ async function handleCreateProtomuxMessage(aq: ActiveQuery) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
aq.setReceiveUpdate?.((data) => {
|
aq.setReceiveUpdate?.((data: any) => {
|
||||||
if (data.action === "send") {
|
if (data.action === "send") {
|
||||||
message.send(...data.args);
|
message.send(...data.args);
|
||||||
}
|
}
|
||||||
|
@ -569,10 +635,17 @@ async function handleCreateProtomuxMessage(aq: ActiveQuery) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.onmessage) {
|
if (data.onmessage) {
|
||||||
data.onmessage = (...args: any) => {
|
data.onmessage = async (...args: any) => {
|
||||||
|
for (let i = 0; i < args.length; i++) {
|
||||||
|
if (isPromise(args[i])) {
|
||||||
|
args[i] = await args[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
args = args.filter(
|
args = args.filter(
|
||||||
(item: any) => item?.constructor.name.toLowerCase() !== "channel"
|
(item: any) => item?.constructor.name.toLowerCase() !== "channel",
|
||||||
);
|
);
|
||||||
|
|
||||||
aq.sendUpdate({
|
aq.sendUpdate({
|
||||||
action: "onmessage",
|
action: "onmessage",
|
||||||
args,
|
args,
|
||||||
|
@ -615,3 +688,11 @@ function getSwarmToSwarmId(swarm: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
|
function isPromise(obj: Promise<any>) {
|
||||||
|
return (
|
||||||
|
!!obj &&
|
||||||
|
(typeof obj === "object" || typeof obj === "function") &&
|
||||||
|
typeof obj.then === "function"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -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__/*"]
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "esnext",
|
|
||||||
"declaration": true,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"outDir": "./build",
|
|
||||||
"strict": true,
|
|
||||||
"allowSyntheticDefaultImports": true
|
|
||||||
},
|
|
||||||
"include": ["src"],
|
|
||||||
"exclude": ["node_modules", "**/__tests__/*"]
|
|
||||||
}
|
|
Loading…
Reference in New Issue