fix(electron): add BSO name resolvers for desktop board address resolution

Configure desktop PKC RPC with Ethereum-backed BSO resolvers so .bso board addresses resolve correctly.
This commit is contained in:
Tommaso Casaburi
2026-06-18 15:59:15 +07:00
parent 9179988e7f
commit 3a4a0d4130
5 changed files with 57 additions and 4 deletions
+35
View File
@@ -0,0 +1,35 @@
import { BsoResolver } from '@bitsocial/bso-resolver';
export const DEFAULT_ETH_RPC_URL = 'https://ethereum-rpc.publicnode.com';
export const DEFAULT_ETH_RPC_URLS = [
DEFAULT_ETH_RPC_URL,
'https://eth.drpc.org',
'https://ethereum.publicnode.com',
'https://rpc.mevblocker.io',
'https://1rpc.io/eth',
'https://eth-pokt.nodies.app',
];
const getProviderLabel = (provider) => {
try {
return new URL(provider).hostname;
} catch {
return provider;
}
};
export const createBsoNameResolvers = (providers = DEFAULT_ETH_RPC_URLS) =>
providers.map(
(provider) =>
new BsoResolver({
key: `eth-${getProviderLabel(provider)}`,
provider,
}),
);
export const createDefaultPkcOptions = ({ dataPath }) => ({
dataPath,
kuboRpcClientsOptions: [{ url: 'http://localhost:50019/api/v0' }],
httpRoutersOptions: ['https://routing.lol', 'https://peers.pleb.bot', 'https://peers.plebpubsub.xyz', 'https://peers.forumindex.com'],
nameResolvers: createBsoNameResolvers(),
});
+17
View File
@@ -1,6 +1,23 @@
import { describe, expect, it, vi } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
import { createDefaultPkcOptions, DEFAULT_ETH_RPC_URLS } from './pkc-rpc-options.js';
import { startPkcRpcServer } from './start-pkc-rpc-core.js'; import { startPkcRpcServer } from './start-pkc-rpc-core.js';
describe('createDefaultPkcOptions', () => {
it('configures BSO name resolvers for the desktop RPC server', () => {
const options = createDefaultPkcOptions({ dataPath: '/tmp/5chan-pkc' });
expect(options.dataPath).toBe('/tmp/5chan-pkc');
expect(options.kuboRpcClientsOptions).toEqual([{ url: 'http://localhost:50019/api/v0' }]);
expect(options.nameResolvers).toHaveLength(DEFAULT_ETH_RPC_URLS.length);
expect(options.nameResolvers.map((resolver) => resolver.provider)).toEqual(DEFAULT_ETH_RPC_URLS);
expect(options.nameResolvers[0]).toMatchObject({
key: 'eth-ethereum-rpc.publicnode.com',
provider: DEFAULT_ETH_RPC_URLS[0],
});
expect(options.nameResolvers[0].canResolve({ name: 'business-and-finance.bso' })).toBe(true);
});
});
describe('startPkcRpcServer', () => { describe('startPkcRpcServer', () => {
it('passes the Electron data path through pkcOptions', async () => { it('passes the Electron data path through pkcOptions', async () => {
const pkcOptions = { const pkcOptions = {
+3 -4
View File
@@ -6,18 +6,17 @@ import path from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import isDev from 'electron-is-dev'; import isDev from 'electron-is-dev';
import { getPkcDataPath } from './pkc-paths.js'; import { getPkcDataPath } from './pkc-paths.js';
import { createDefaultPkcOptions } from './pkc-rpc-options.js';
import { startPkcRpcServer } from './start-pkc-rpc-core.js'; import { startPkcRpcServer } from './start-pkc-rpc-core.js';
const dirname = path.join(path.dirname(fileURLToPath(import.meta.url))); const dirname = path.join(path.dirname(fileURLToPath(import.meta.url)));
const projectRoot = path.join(dirname, '..'); const projectRoot = path.join(dirname, '..');
// Always run the local PKC RPC server on this port so all desktop clients can reuse it. // Always run the local PKC RPC server on this port so all desktop clients can reuse it.
const port = 9138; const port = 9138;
const defaultPkcOptions = { const defaultPkcOptions = createDefaultPkcOptions({
// find the user's OS data path // find the user's OS data path
dataPath: getPkcDataPath({ isDev, projectRoot }), dataPath: getPkcDataPath({ isDev, projectRoot }),
kuboRpcClientsOptions: [{ url: 'http://localhost:50019/api/v0' }], });
httpRoutersOptions: ['https://routing.lol', 'https://peers.pleb.bot', 'https://peers.plebpubsub.xyz', 'https://peers.forumindex.com'],
};
// Generate the local PKC RPC auth key if it does not exist yet. // Generate the local PKC RPC auth key if it does not exist yet.
const pkcRpcAuthKeyPath = path.join(defaultPkcOptions.dataPath, 'auth-key'); const pkcRpcAuthKeyPath = path.join(defaultPkcOptions.dataPath, 'auth-key');
+1
View File
@@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"@bbob/parser": "4.3.1", "@bbob/parser": "4.3.1",
"@bitsocial/bitsocial-react-hooks": "0.1.17", "@bitsocial/bitsocial-react-hooks": "0.1.17",
"@bitsocial/bso-resolver": "0.0.8",
"@capacitor/app": "7.0.1", "@capacitor/app": "7.0.1",
"@capacitor/browser": "7.0.5", "@capacitor/browser": "7.0.5",
"@capacitor/status-bar": "7.0.1", "@capacitor/status-bar": "7.0.1",
+1
View File
@@ -11,6 +11,7 @@ __metadata:
dependencies: dependencies:
"@bbob/parser": "npm:4.3.1" "@bbob/parser": "npm:4.3.1"
"@bitsocial/bitsocial-react-hooks": "npm:0.1.17" "@bitsocial/bitsocial-react-hooks": "npm:0.1.17"
"@bitsocial/bso-resolver": "npm:0.0.8"
"@capacitor/android": "npm:7.4.5" "@capacitor/android": "npm:7.4.5"
"@capacitor/app": "npm:7.0.1" "@capacitor/app": "npm:7.0.1"
"@capacitor/browser": "npm:7.0.5" "@capacitor/browser": "npm:7.0.5"