feat: add registry api for use with network registry
This commit is contained in:
parent
0a7ceecd9c
commit
f5ce8518bb
|
@ -10,9 +10,10 @@
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@i2labs/dns": "^1.0.1",
|
"@i2labs/dns": "^1.0.1",
|
||||||
|
"@lumeweb/kernel-network-registry-client": "^0.1.0-develop.2",
|
||||||
"@lumeweb/kernel-swarm-client": "^0.0.2-develop.9",
|
"@lumeweb/kernel-swarm-client": "^0.0.2-develop.9",
|
||||||
"@lumeweb/libhyperproxy": "^0.0.2-develop.2",
|
"@lumeweb/libhyperproxy": "^0.0.2-develop.2",
|
||||||
"@lumeweb/libkernel": "^0.1.0-develop.16",
|
"@lumeweb/libkernel": "^0.1.0-develop.20",
|
||||||
"assert": "^2.0.0",
|
"assert": "^2.0.0",
|
||||||
"hsd": "^5.0.1",
|
"hsd": "^5.0.1",
|
||||||
"p-defer": "^4.0.0"
|
"p-defer": "^4.0.0"
|
||||||
|
@ -1693,6 +1694,14 @@
|
||||||
"@lumeweb/libweb": "^0.2.0-develop.19"
|
"@lumeweb/libweb": "^0.2.0-develop.19"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@lumeweb/kernel-network-registry-client": {
|
||||||
|
"version": "0.1.0-develop.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@lumeweb/kernel-network-registry-client/-/kernel-network-registry-client-0.1.0-develop.2.tgz",
|
||||||
|
"integrity": "sha512-e2iJylhabt+T++lcVJ2o+hoR6DNXtyTWeodROyJ+f1VPhS9rgzAGflDOKyd7Zpi4DDHzpRY2gJtiL18FHOmMrw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@lumeweb/libkernel": "^0.1.0-develop.20"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@lumeweb/kernel-swarm-client": {
|
"node_modules/@lumeweb/kernel-swarm-client": {
|
||||||
"version": "0.0.2-develop.9",
|
"version": "0.0.2-develop.9",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/kernel-swarm-client/-/kernel-swarm-client-0.0.2-develop.9.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/kernel-swarm-client/-/kernel-swarm-client-0.0.2-develop.9.tgz",
|
||||||
|
@ -1717,11 +1726,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/libkernel": {
|
"node_modules/@lumeweb/libkernel": {
|
||||||
"version": "0.1.0-develop.16",
|
"version": "0.1.0-develop.20",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/libkernel/-/libkernel-0.1.0-develop.16.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/libkernel/-/libkernel-0.1.0-develop.20.tgz",
|
||||||
"integrity": "sha512-wYAgWl/FW8QgMfd9byuvd/DZSIouhGHhOXBay12Koqwf/nxXjYysxagQp9c4WWS2ZDAsUx9jK9bKPlT4t6sSlw==",
|
"integrity": "sha512-z7yRk6B0P0bxPe+a4Xm5/Bl6eIfkDCB2IJhNK2Gm+o7j4RbWbizRk79+zgBFWMrYzo8bVrpBKK7nGI3iNOgT9g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/libweb": "0.2.0-develop.22",
|
"@lumeweb/libweb": "0.2.0-develop.26",
|
||||||
"emittery": "^1.0.1"
|
"emittery": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1737,9 +1746,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/libportal": {
|
"node_modules/@lumeweb/libportal": {
|
||||||
"version": "0.2.0-develop.12",
|
"version": "0.2.0-develop.16",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.12.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.16.tgz",
|
||||||
"integrity": "sha512-FKdMzeOvi8viXwFbKLeD7c4SadLDaz/ZvSLaAumuyXiJCKk0gVM0aPO8mTkibDtJG5JfeFHef0jI9aOSMYWfXw==",
|
"integrity": "sha512-wyzza/ttvU6I1gIs4tnYSkcT6s7MIBnUdJSNAbe6k6NsQ1w4bhBVJhEKbBru/lAEASO/PAhHGBwaOCv20rZZfA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git",
|
"@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git",
|
||||||
"@noble/curves": "^1.1.0",
|
"@noble/curves": "^1.1.0",
|
||||||
|
@ -1771,13 +1780,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/libweb": {
|
"node_modules/@lumeweb/libweb": {
|
||||||
"version": "0.2.0-develop.22",
|
"version": "0.2.0-develop.26",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.22.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.26.tgz",
|
||||||
"integrity": "sha512-HKh0csOCC82vXqc0Keszymt4Mnu/xgD9GaBjarLclNkCK4mxxBmOuU9OmuOkANndQjl2dhMnmYJHT0bmseBj9Q==",
|
"integrity": "sha512-XRIDiqRFqlEbcwjxAfkv7UYnyTflN3Q4rki8YAd9QrLQM2vycslgPLYS53vVJVL9GPH93V5J9z2V4DPQZlOOkQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/community-portals": "^0.1.0-develop.6",
|
"@lumeweb/community-portals": "^0.1.0-develop.6",
|
||||||
"@lumeweb/libportal": "^0.2.0-develop.12",
|
"@lumeweb/libportal": "^0.2.0-develop.16",
|
||||||
"@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git",
|
"@lumeweb/node-library-preset": "0.2.7",
|
||||||
"@noble/curves": "^1.1.0",
|
"@noble/curves": "^1.1.0",
|
||||||
"@noble/hashes": "^1.3.1"
|
"@noble/hashes": "^1.3.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,10 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@i2labs/dns": "^1.0.1",
|
"@i2labs/dns": "^1.0.1",
|
||||||
|
"@lumeweb/kernel-network-registry-client": "^0.1.0-develop.2",
|
||||||
"@lumeweb/kernel-swarm-client": "^0.0.2-develop.9",
|
"@lumeweb/kernel-swarm-client": "^0.0.2-develop.9",
|
||||||
"@lumeweb/libhyperproxy": "^0.0.2-develop.2",
|
"@lumeweb/libhyperproxy": "^0.0.2-develop.2",
|
||||||
"@lumeweb/libkernel": "^0.1.0-develop.16",
|
"@lumeweb/libkernel": "^0.1.0-develop.20",
|
||||||
"assert": "^2.0.0",
|
"assert": "^2.0.0",
|
||||||
"hsd": "^5.0.1",
|
"hsd": "^5.0.1",
|
||||||
"p-defer": "^4.0.0"
|
"p-defer": "^4.0.0"
|
||||||
|
|
15
src/index.ts
15
src/index.ts
|
@ -1,6 +1,7 @@
|
||||||
import type { ActiveQuery } from "@lumeweb/libkernel/module";
|
import type { ActiveQuery } from "@lumeweb/libkernel/module";
|
||||||
import { addHandler, handleMessage } from "@lumeweb/libkernel/module";
|
import { addHandler, handleMessage } from "@lumeweb/libkernel/module";
|
||||||
import { createClient } from "@lumeweb/kernel-swarm-client";
|
import { createClient as createSwarmClient } from "@lumeweb/kernel-swarm-client";
|
||||||
|
import { createClient as createNetworkRegistryClient } from "@lumeweb/kernel-network-registry-client";
|
||||||
import {
|
import {
|
||||||
createServer,
|
createServer,
|
||||||
DummySocket,
|
DummySocket,
|
||||||
|
@ -13,6 +14,7 @@ import dns from "@i2labs/dns";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
const PROTOCOL = "lumeweb.proxy.handshake";
|
const PROTOCOL = "lumeweb.proxy.handshake";
|
||||||
|
const TYPES = ["blockchain"];
|
||||||
|
|
||||||
onmessage = handleMessage;
|
onmessage = handleMessage;
|
||||||
|
|
||||||
|
@ -22,6 +24,7 @@ let moduleLoaded: Promise<void> = new Promise((resolve) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
addHandler("presentKey", handlePresentKey);
|
addHandler("presentKey", handlePresentKey);
|
||||||
|
addHandler("register", handleRegister);
|
||||||
addHandler("ready", handleReady);
|
addHandler("ready", handleReady);
|
||||||
addHandler("query", handleQuery);
|
addHandler("query", handleQuery);
|
||||||
|
|
||||||
|
@ -29,6 +32,8 @@ let swarm;
|
||||||
let proxy: MultiSocketProxy;
|
let proxy: MultiSocketProxy;
|
||||||
let node: SPVNode;
|
let node: SPVNode;
|
||||||
|
|
||||||
|
const networkRegistry = createNetworkRegistryClient();
|
||||||
|
|
||||||
function resolveWithPeers(resolve: Function) {
|
function resolveWithPeers(resolve: Function) {
|
||||||
if (!node.pool.peers.head()) {
|
if (!node.pool.peers.head()) {
|
||||||
node.pool.on("peer", () => {
|
node.pool.on("peer", () => {
|
||||||
|
@ -61,7 +66,7 @@ function resolveWithPeers(resolve: Function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handlePresentKey(aq: ActiveQuery) {
|
async function handlePresentKey(aq: ActiveQuery) {
|
||||||
swarm = createClient();
|
swarm = createSwarmClient();
|
||||||
|
|
||||||
const peerConnected = defer();
|
const peerConnected = defer();
|
||||||
node = new SPVNode({
|
node = new SPVNode({
|
||||||
|
@ -188,3 +193,9 @@ async function handleQuery(aq: ActiveQuery) {
|
||||||
aq.reject((e as Error).message);
|
aq.reject((e as Error).message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleRegister(aq: ActiveQuery) {
|
||||||
|
await networkRegistry.registerNetwork(TYPES);
|
||||||
|
|
||||||
|
aq.respond();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue