mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
- Synced `package-lock.json` with `package.json` to resolve `npm ci` failures. - Updated `nostr-tools` dependencies to resolve conflicts. - Fixed `SyntaxError` in `tests/nostr-login-permissions.test.mjs` caused by duplicate code. - Updated `js/nostr/client.js`, `js/nostr/publishHelpers.js`, `js/nostr/adapters/nsecAdapter.js`, `js/nostr/nip46Client.js` to use `hexToBytes` helper when calling `nostr-tools` functions, as v2+ expects `Uint8Array` instead of hex strings. - Added `hexToBytes` helper in `js/utils/hex.js`. - Updated tests (`tests/nostr/dm-direct-message-flow.test.mjs`, `tests/nostr-send-direct-message.test.mjs`, `tests/nostr-private-key-signer.test.mjs`, `tests/nostr/nip46Client.test.js`) to use `Uint8Array` for keys where required. Co-authored-by: PR0M3TH3AN <[email protected]>
30 lines
865 B
JavaScript
30 lines
865 B
JavaScript
export function normalizeHexString(value) {
|
|
if (typeof value !== "string") {
|
|
return "";
|
|
}
|
|
|
|
const trimmed = value.trim();
|
|
return trimmed ? trimmed.toLowerCase() : "";
|
|
}
|
|
|
|
export const normalizeHexId = normalizeHexString;
|
|
export const normalizeHexPubkey = normalizeHexString;
|
|
|
|
export function hexToBytes(hex) {
|
|
if (typeof hex !== "string") {
|
|
throw new TypeError("hexToBytes: expected string, got " + typeof hex);
|
|
}
|
|
const normalized = hex.trim();
|
|
if (normalized.length % 2) throw new Error("hex string must have even length");
|
|
const array = new Uint8Array(normalized.length / 2);
|
|
for (let i = 0; i < array.length; i++) {
|
|
const j = i * 2;
|
|
const byte = parseInt(normalized.substring(j, j + 2), 16);
|
|
if (Number.isNaN(byte) || byte < 0) {
|
|
throw new Error("Invalid hex string");
|
|
}
|
|
array[i] = byte;
|
|
}
|
|
return array;
|
|
}
|