Compare commits
20 Commits
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | d86e749e72 | |
Derrick Hammer | 14c5892ab5 | |
Derrick Hammer | 26576d809e | |
semantic-release-bot | 85d81b4d6f | |
Derrick Hammer | e44b63b63e | |
Derrick Hammer | 780573aa7d | |
semantic-release-bot | d9ef28532f | |
Derrick Hammer | 1ddcf5be81 | |
Derrick Hammer | 00560a64a7 | |
semantic-release-bot | de08d8ab3a | |
Derrick Hammer | 71267ae892 | |
Derrick Hammer | ac4aaceb73 | |
semantic-release-bot | 33da202f99 | |
Derrick Hammer | 17b9af7e71 | |
Derrick Hammer | a6ec4d6bed | |
semantic-release-bot | 2ec10660e5 | |
Derrick Hammer | a32dbb117a | |
semantic-release-bot | 1f75489d0d | |
Derrick Hammer | 6b6278813a | |
Derrick Hammer | 8bd5ae948a |
|
@ -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,5 @@
|
|||
{
|
||||
"preset": [
|
||||
"@lumeweb/node-library-preset"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-10-13)
|
||||
|
||||
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* increase timeout to 3 seconds ([780573a](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/commit/780573aa7d025590dfc8dbedf9aa380d4888bc8a))
|
||||
|
||||
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add reject reason for logging ([00560a6](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/commit/00560a64a7fc6ee280fc8496c96a74a6d272a730))
|
||||
|
||||
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add 1 second timeout to auto-reject and close the connection ([ac4aace](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/commit/ac4aaceb73f434a5b832c597973c9cba1c4cc1cd))
|
||||
|
||||
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* use utf8ToBytes ([a6ec4d6](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/commit/a6ec4d6bedb660c80b2cfd13cddf71e913f4347e))
|
||||
|
||||
## [0.0.2-develop.2](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.2-develop.1...v0.0.2-develop.2) (2023-07-03)
|
||||
|
||||
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/peer-discovery-irc/compare/v0.0.1...v0.0.2-develop.1) (2023-07-01)
|
|
@ -1,6 +0,0 @@
|
|||
/// <reference types="node" resolution-mode="require"/>
|
||||
import type { Peer } from "@lumeweb/peer-discovery";
|
||||
declare const _default: (pubkey: Buffer, options?: {
|
||||
host: string;
|
||||
}) => Promise<boolean | Peer>;
|
||||
export default _default;
|
|
@ -1,46 +0,0 @@
|
|||
import { IrcClient } from "@ctrl/irc";
|
||||
import jsonStringify from "json-stringify-deterministic";
|
||||
import b4a from "b4a";
|
||||
import * as ed from "@noble/ed25519";
|
||||
import { ripemd160 } from "@noble/hashes/ripemd160";
|
||||
import { sha256 } from "@noble/hashes/sha256";
|
||||
import { bytesToHex } from "@noble/hashes/utils";
|
||||
const hash160 = (data) => ripemd160(sha256(data));
|
||||
export default async (pubkey, options = { host: "irc.liberta.casa" }) => {
|
||||
let ircPubKey = await ed.getPublicKey(ed.utils.randomPrivateKey());
|
||||
let client = new IrcClient(undefined, bytesToHex(hash160(ircPubKey)).substring(0, 15), {
|
||||
host: options.host,
|
||||
port: 6697,
|
||||
secure: true,
|
||||
channels: ["#lumeweb"],
|
||||
realName: "lumeweb-client",
|
||||
});
|
||||
client.connect();
|
||||
await new Promise((resolve) => {
|
||||
client.once("join", resolve);
|
||||
});
|
||||
client.say("#lumeweb", b4a.toBuffer(pubkey).toString("hex"));
|
||||
return new Promise((resolve, reject) => {
|
||||
client.on("pm", async (from, text) => {
|
||||
let json;
|
||||
try {
|
||||
json = JSON.parse(text);
|
||||
}
|
||||
catch {
|
||||
return;
|
||||
}
|
||||
const verifyData = {
|
||||
host: json.host,
|
||||
port: json.port,
|
||||
timestamp: json.timestamp,
|
||||
};
|
||||
const verifyPayload = jsonStringify(verifyData);
|
||||
if (!(await ed.verify(b4a.from(json.signature, "hex"), b4a.from(verifyPayload), pubkey))) {
|
||||
return;
|
||||
}
|
||||
client.end();
|
||||
resolve({ host: json.host, port: json.port });
|
||||
});
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
|
@ -1,20 +1,33 @@
|
|||
{
|
||||
"name": "@lumeweb/peer-discovery-irc",
|
||||
"version": "0.1.0",
|
||||
"main": "dist/index.js",
|
||||
"version": "0.0.2-develop.7",
|
||||
"main": "lib/index.js",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "gitea@git.lumeweb.com:LumeWeb/peer-discovery-irc.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/b4a": "^1.6.0",
|
||||
"@types/node": "^18.11.17",
|
||||
"prettier": "^2.8.3",
|
||||
"typescript": "^4.9.4"
|
||||
"@lumeweb/node-library-preset": "^0.2.7",
|
||||
"presetter": "*"
|
||||
},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"scripts": {
|
||||
"prepare": "presetter bootstrap",
|
||||
"build": "run build",
|
||||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ctrl/irc": "^2.1.0",
|
||||
"@lumeweb/peer-discovery": "git+https://git.lumeweb.com/LumeWeb/peer-discovery.git",
|
||||
"@noble/ed25519": "^1.7.1",
|
||||
"@noble/hashes": "^1.1.5",
|
||||
"b4a": "^1.6.1",
|
||||
"@ctrl/irc": "^2.1.1",
|
||||
"@lumeweb/libpeerdiscovery": "^0.1.0-develop.1",
|
||||
"@noble/curves": "^1.1.0",
|
||||
"@noble/hashes": "^1.3.1",
|
||||
"json-stringify-deterministic": "^1.0.8"
|
||||
},
|
||||
"files": [
|
||||
"lib/**"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
|
|
128
pnpm-lock.yaml
128
pnpm-lock.yaml
|
@ -1,128 +0,0 @@
|
|||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
'@ctrl/irc': ^2.1.0
|
||||
'@lumeweb/peer-discovery': git+https://git.lumeweb.com/LumeWeb/peer-discovery.git
|
||||
'@noble/ed25519': ^1.7.1
|
||||
'@noble/hashes': ^1.1.5
|
||||
'@types/b4a': ^1.6.0
|
||||
'@types/node': ^18.11.17
|
||||
b4a: ^1.6.1
|
||||
json-stringify-deterministic: ^1.0.8
|
||||
prettier: ^2.8.3
|
||||
typescript: ^4.9.4
|
||||
|
||||
dependencies:
|
||||
'@ctrl/irc': 2.1.0
|
||||
'@lumeweb/peer-discovery': git.lumeweb.com/LumeWeb/peer-discovery/abdb430c273301f7652feb8f9026c89a78f58d7a
|
||||
'@noble/ed25519': 1.7.1
|
||||
'@noble/hashes': 1.1.5
|
||||
b4a: 1.6.1
|
||||
json-stringify-deterministic: 1.0.8
|
||||
|
||||
devDependencies:
|
||||
'@types/b4a': 1.6.0
|
||||
'@types/node': 18.11.18
|
||||
prettier: 2.8.3
|
||||
typescript: 4.9.4
|
||||
|
||||
packages:
|
||||
|
||||
/@ctrl/irc/2.1.0:
|
||||
resolution: {integrity: sha512-cVCXsKZVZ0seciCdTmwF9PUt+t/QCjJl6HYUPhkMrOTh6voQ9lqipUxF0/fLksBl2hrRiITgBXvTjpNYLdkbJQ==}
|
||||
engines: {node: '>=14.16'}
|
||||
dependencies:
|
||||
chardet: 1.5.1
|
||||
debug: 4.3.4
|
||||
iconv-lite: 0.6.3
|
||||
lodash.defaultsdeep: 4.6.1
|
||||
tiny-typed-emitter: 2.1.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/@noble/ed25519/1.7.1:
|
||||
resolution: {integrity: sha512-Rk4SkJFaXZiznFyC/t77Q0NKS4FL7TLJJsVG2V2oiEq3kJVeTdxysEe/yRWSpnWMe808XRDJ+VFh5pt/FN5plw==}
|
||||
dev: false
|
||||
|
||||
/@noble/hashes/1.1.5:
|
||||
resolution: {integrity: sha512-LTMZiiLc+V4v1Yi16TD6aX2gmtKszNye0pQgbaLqkvhIqP7nVsSaJsWloGQjJfJ8offaoP5GtX3yY5swbcJxxQ==}
|
||||
dev: false
|
||||
|
||||
/@types/b4a/1.6.0:
|
||||
resolution: {integrity: sha512-rYU2r5nSUPyKyufWijxgTjsFp2kLCwydj2TmKU4StJeGPHS/Fs5KHgP89DNF0jddyeAbN5mdjNDqIrjIHca60g==}
|
||||
dependencies:
|
||||
'@types/node': 18.11.18
|
||||
dev: true
|
||||
|
||||
/@types/node/18.11.18:
|
||||
resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==}
|
||||
dev: true
|
||||
|
||||
/b4a/1.6.1:
|
||||
resolution: {integrity: sha512-AsKjNhz72yxteo/0EtQEiwkMUgk/tGmycXlbG4g3Ard2/ULtNLUykGOkeK0egmN27h0xMAhb76jYccW+XTBExA==}
|
||||
dev: false
|
||||
|
||||
/chardet/1.5.1:
|
||||
resolution: {integrity: sha512-0XMOtA52igKDOIfvJZJ6v0+J9yMF3IuYyEa5oFUxBXA01G6mwCNKpul3bgbFf7lmZuqwN/oyg/zQ1cGS7NyJkQ==}
|
||||
dev: false
|
||||
|
||||
/debug/4.3.4:
|
||||
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
|
||||
engines: {node: '>=6.0'}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.1.2
|
||||
dev: false
|
||||
|
||||
/iconv-lite/0.6.3:
|
||||
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
dev: false
|
||||
|
||||
/json-stringify-deterministic/1.0.8:
|
||||
resolution: {integrity: sha512-rkJID3qeigo3VCrEcxX1333fTBBxW89YrdYcZexMnL/WdB8u0zctyG63e/DpahRJyrWCDhh7IQhiR7u2XEDQ4Q==}
|
||||
engines: {node: '>= 4'}
|
||||
dev: false
|
||||
|
||||
/lodash.defaultsdeep/4.6.1:
|
||||
resolution: {integrity: sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==}
|
||||
dev: false
|
||||
|
||||
/ms/2.1.2:
|
||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||
dev: false
|
||||
|
||||
/prettier/2.8.3:
|
||||
resolution: {integrity: sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/safer-buffer/2.1.2:
|
||||
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
|
||||
dev: false
|
||||
|
||||
/tiny-typed-emitter/2.1.0:
|
||||
resolution: {integrity: sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==}
|
||||
dev: false
|
||||
|
||||
/typescript/4.9.4:
|
||||
resolution: {integrity: sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==}
|
||||
engines: {node: '>=4.2.0'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
git.lumeweb.com/LumeWeb/peer-discovery/abdb430c273301f7652feb8f9026c89a78f58d7a:
|
||||
resolution: {commit: abdb430c273301f7652feb8f9026c89a78f58d7a, repo: https://git.lumeweb.com/LumeWeb/peer-discovery.git, type: git}
|
||||
name: '@lumeweb/peer-discovery'
|
||||
version: 0.1.0
|
||||
dependencies:
|
||||
b4a: 1.6.1
|
||||
dev: false
|
39
src/index.ts
39
src/index.ts
|
@ -1,11 +1,10 @@
|
|||
import type { Peer } from "@lumeweb/peer-discovery";
|
||||
import type { Peer } from "@lumeweb/libpeerdiscovery";
|
||||
import { IrcClient } from "@ctrl/irc";
|
||||
import jsonStringify from "json-stringify-deterministic";
|
||||
import b4a from "b4a";
|
||||
import * as ed from "@noble/ed25519";
|
||||
import { ed25519 } from "@noble/curves/ed25519";
|
||||
import { ripemd160 } from "@noble/hashes/ripemd160";
|
||||
import { sha256 } from "@noble/hashes/sha256";
|
||||
import { bytesToHex } from "@noble/hashes/utils";
|
||||
import { bytesToHex, hexToBytes, utf8ToBytes } from "@noble/hashes/utils";
|
||||
|
||||
const hash160 = (data: Uint8Array) => ripemd160(sha256(data));
|
||||
|
||||
|
@ -16,12 +15,17 @@ interface SignedPeerResponse extends Peer {
|
|||
|
||||
export default async (
|
||||
pubkey: Buffer,
|
||||
options = { host: "irc.liberta.casa" }
|
||||
options = { host: "irc.liberta.casa" },
|
||||
): Promise<boolean | Peer> => {
|
||||
let ircPubKey = await ed.getPublicKey(ed.utils.randomPrivateKey());
|
||||
return {
|
||||
host: "relay1.lumeweb.com",
|
||||
port: 8080,
|
||||
};
|
||||
/*
|
||||
let ircPubKey = ed25519.getPublicKey(ed25519.utils.randomPrivateKey());
|
||||
|
||||
let client = new IrcClient(
|
||||
undefined,
|
||||
undefined as any,
|
||||
bytesToHex(hash160(ircPubKey)).substring(0, 15),
|
||||
{
|
||||
host: options.host,
|
||||
|
@ -29,7 +33,7 @@ export default async (
|
|||
secure: true,
|
||||
channels: ["#lumeweb"],
|
||||
realName: "lumeweb-client",
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
client.connect();
|
||||
|
@ -38,7 +42,7 @@ export default async (
|
|||
client.once("join", resolve);
|
||||
});
|
||||
|
||||
client.say("#lumeweb", b4a.toBuffer(pubkey).toString("hex"));
|
||||
client.say("#lumeweb", bytesToHex(pubkey));
|
||||
|
||||
return new Promise<Peer>((resolve, reject) => {
|
||||
client.on("pm", async (from: string, text: string) => {
|
||||
|
@ -57,11 +61,11 @@ export default async (
|
|||
|
||||
const verifyPayload = jsonStringify(verifyData);
|
||||
if (
|
||||
!(await ed.verify(
|
||||
b4a.from(json.signature, "hex"),
|
||||
b4a.from(verifyPayload),
|
||||
pubkey
|
||||
))
|
||||
!ed25519.verify(
|
||||
hexToBytes(json.signature as string),
|
||||
utf8ToBytes(verifyPayload),
|
||||
pubkey,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -69,5 +73,10 @@ export default async (
|
|||
client.end();
|
||||
resolve({ host: json.host, port: json.port });
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
client.end();
|
||||
reject("irc discovery response timed out");
|
||||
}, 3000);
|
||||
});*/
|
||||
};
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"outDir": "dist",
|
||||
"declaration": true,
|
||||
"moduleResolution": "nodenext"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue