From f5ce8518bb5261fbf25d5281c9f31ead99d735fd Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 19 Jul 2023 12:16:06 -0400 Subject: [PATCH] feat: add registry api for use with network registry --- npm-shrinkwrap.json | 35 ++++++++++++++++++++++------------- package.json | 3 ++- src/index.ts | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index c2edc42..ae73f4b 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -10,9 +10,10 @@ "hasInstallScript": true, "dependencies": { "@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/libhyperproxy": "^0.0.2-develop.2", - "@lumeweb/libkernel": "^0.1.0-develop.16", + "@lumeweb/libkernel": "^0.1.0-develop.20", "assert": "^2.0.0", "hsd": "^5.0.1", "p-defer": "^4.0.0" @@ -1693,6 +1694,14 @@ "@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": { "version": "0.0.2-develop.9", "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": { - "version": "0.1.0-develop.16", - "resolved": "https://registry.npmjs.org/@lumeweb/libkernel/-/libkernel-0.1.0-develop.16.tgz", - "integrity": "sha512-wYAgWl/FW8QgMfd9byuvd/DZSIouhGHhOXBay12Koqwf/nxXjYysxagQp9c4WWS2ZDAsUx9jK9bKPlT4t6sSlw==", + "version": "0.1.0-develop.20", + "resolved": "https://registry.npmjs.org/@lumeweb/libkernel/-/libkernel-0.1.0-develop.20.tgz", + "integrity": "sha512-z7yRk6B0P0bxPe+a4Xm5/Bl6eIfkDCB2IJhNK2Gm+o7j4RbWbizRk79+zgBFWMrYzo8bVrpBKK7nGI3iNOgT9g==", "dependencies": { - "@lumeweb/libweb": "0.2.0-develop.22", + "@lumeweb/libweb": "0.2.0-develop.26", "emittery": "^1.0.1" } }, @@ -1737,9 +1746,9 @@ } }, "node_modules/@lumeweb/libportal": { - "version": "0.2.0-develop.12", - "resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.12.tgz", - "integrity": "sha512-FKdMzeOvi8viXwFbKLeD7c4SadLDaz/ZvSLaAumuyXiJCKk0gVM0aPO8mTkibDtJG5JfeFHef0jI9aOSMYWfXw==", + "version": "0.2.0-develop.16", + "resolved": "https://registry.npmjs.org/@lumeweb/libportal/-/libportal-0.2.0-develop.16.tgz", + "integrity": "sha512-wyzza/ttvU6I1gIs4tnYSkcT6s7MIBnUdJSNAbe6k6NsQ1w4bhBVJhEKbBru/lAEASO/PAhHGBwaOCv20rZZfA==", "dependencies": { "@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git", "@noble/curves": "^1.1.0", @@ -1771,13 +1780,13 @@ } }, "node_modules/@lumeweb/libweb": { - "version": "0.2.0-develop.22", - "resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.22.tgz", - "integrity": "sha512-HKh0csOCC82vXqc0Keszymt4Mnu/xgD9GaBjarLclNkCK4mxxBmOuU9OmuOkANndQjl2dhMnmYJHT0bmseBj9Q==", + "version": "0.2.0-develop.26", + "resolved": "https://registry.npmjs.org/@lumeweb/libweb/-/libweb-0.2.0-develop.26.tgz", + "integrity": "sha512-XRIDiqRFqlEbcwjxAfkv7UYnyTflN3Q4rki8YAd9QrLQM2vycslgPLYS53vVJVL9GPH93V5J9z2V4DPQZlOOkQ==", "dependencies": { "@lumeweb/community-portals": "^0.1.0-develop.6", - "@lumeweb/libportal": "^0.2.0-develop.12", - "@lumeweb/node-library-preset": "git+https://git.lumeweb.com/LumeWeb/node-library-preset.git", + "@lumeweb/libportal": "^0.2.0-develop.16", + "@lumeweb/node-library-preset": "0.2.7", "@noble/curves": "^1.1.0", "@noble/hashes": "^1.3.1" } diff --git a/package.json b/package.json index 6e861c9..2f85d5a 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,10 @@ }, "dependencies": { "@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/libhyperproxy": "^0.0.2-develop.2", - "@lumeweb/libkernel": "^0.1.0-develop.16", + "@lumeweb/libkernel": "^0.1.0-develop.20", "assert": "^2.0.0", "hsd": "^5.0.1", "p-defer": "^4.0.0" diff --git a/src/index.ts b/src/index.ts index 78ff260..e44283c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import type { ActiveQuery } 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 { createServer, DummySocket, @@ -13,6 +14,7 @@ import dns from "@i2labs/dns"; import assert from "assert"; const PROTOCOL = "lumeweb.proxy.handshake"; +const TYPES = ["blockchain"]; onmessage = handleMessage; @@ -22,6 +24,7 @@ let moduleLoaded: Promise = new Promise((resolve) => { }); addHandler("presentKey", handlePresentKey); +addHandler("register", handleRegister); addHandler("ready", handleReady); addHandler("query", handleQuery); @@ -29,6 +32,8 @@ let swarm; let proxy: MultiSocketProxy; let node: SPVNode; +const networkRegistry = createNetworkRegistryClient(); + function resolveWithPeers(resolve: Function) { if (!node.pool.peers.head()) { node.pool.on("peer", () => { @@ -61,7 +66,7 @@ function resolveWithPeers(resolve: Function) { } async function handlePresentKey(aq: ActiveQuery) { - swarm = createClient(); + swarm = createSwarmClient(); const peerConnected = defer(); node = new SPVNode({ @@ -188,3 +193,9 @@ async function handleQuery(aq: ActiveQuery) { aq.reject((e as Error).message); } } + +async function handleRegister(aq: ActiveQuery) { + await networkRegistry.registerNetwork(TYPES); + + aq.respond(); +}