refactor: switch to use noble binary utils

This commit is contained in:
Derrick Hammer 2023-07-03 06:41:58 -04:00
parent 1f75489d0d
commit a32dbb117a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 4 additions and 7 deletions

1
npm-shrinkwrap.json generated
View File

@ -12,7 +12,6 @@
"@lumeweb/libpeerdiscovery": "^0.1.0-develop.1", "@lumeweb/libpeerdiscovery": "^0.1.0-develop.1",
"@noble/curves": "^1.1.0", "@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1", "@noble/hashes": "^1.3.1",
"b4a": "^1.6.4",
"json-stringify-deterministic": "^1.0.8" "json-stringify-deterministic": "^1.0.8"
}, },
"devDependencies": { "devDependencies": {

View File

@ -22,7 +22,6 @@
"@lumeweb/libpeerdiscovery": "^0.1.0-develop.1", "@lumeweb/libpeerdiscovery": "^0.1.0-develop.1",
"@noble/curves": "^1.1.0", "@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1", "@noble/hashes": "^1.3.1",
"b4a": "^1.6.4",
"json-stringify-deterministic": "^1.0.8" "json-stringify-deterministic": "^1.0.8"
}, },
"files": [ "files": [

View File

@ -1,11 +1,10 @@
import type { Peer } from "@lumeweb/libpeerdiscovery"; import type { Peer } from "@lumeweb/libpeerdiscovery";
import { IrcClient } from "@ctrl/irc"; import { IrcClient } from "@ctrl/irc";
import jsonStringify from "json-stringify-deterministic"; import jsonStringify from "json-stringify-deterministic";
import b4a from "b4a";
import { ed25519 } from "@noble/curves/ed25519"; import { ed25519 } from "@noble/curves/ed25519";
import { ripemd160 } from "@noble/hashes/ripemd160"; import { ripemd160 } from "@noble/hashes/ripemd160";
import { sha256 } from "@noble/hashes/sha256"; import { sha256 } from "@noble/hashes/sha256";
import { bytesToHex } from "@noble/hashes/utils"; import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
const hash160 = (data: Uint8Array) => ripemd160(sha256(data)); const hash160 = (data: Uint8Array) => ripemd160(sha256(data));
@ -38,7 +37,7 @@ export default async (
client.once("join", resolve); client.once("join", resolve);
}); });
client.say("#lumeweb", b4a.toBuffer(pubkey).toString("hex")); client.say("#lumeweb", bytesToHex(pubkey));
return new Promise<Peer>((resolve, reject) => { return new Promise<Peer>((resolve, reject) => {
client.on("pm", async (from: string, text: string) => { client.on("pm", async (from: string, text: string) => {
@ -58,8 +57,8 @@ export default async (
const verifyPayload = jsonStringify(verifyData); const verifyPayload = jsonStringify(verifyData);
if ( if (
!ed25519.verify( !ed25519.verify(
b4a.from(json.signature, "hex"), hexToBytes(json.signature as string),
b4a.from(verifyPayload), hexToBytes(verifyPayload),
pubkey, pubkey,
) )
) { ) {