mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
fix: Sync package-lock.json and fix tests for nostr-tools v2
- 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]>
This commit is contained in:
1 parent
5a5772de3a
commit
ffd8f0e23c
12 files changed
+186
-304
No files matched your search
@@ -9,3 +9,21 @@ export function normalizeHexString(value) {
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user