Refactor handle registry updates and improve key decoding
Removed 'healing' logic and authoritative update propagation from handle registry and gossip code, simplifying handle upserts to only update on strictly newer timestamps. Enhanced sodium-chat key handling with robust base64 decoding and key repair logic. Added scripts for key inspection and crypto testing. Deleted unused healing module.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
|
||||
import 'dotenv/config';
|
||||
import { db } from '@/db';
|
||||
import { handleRegistry } from '@/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
const TARGET_DID = 'did:synapsis:75aea1b8630142f59e3cd893ec1d88e5'; // The one that failed
|
||||
|
||||
async function main() {
|
||||
console.log('--- Inspecting Remote Key ---');
|
||||
|
||||
const entry = await db.query.handleRegistry.findFirst({
|
||||
where: eq(handleRegistry.did, TARGET_DID),
|
||||
});
|
||||
|
||||
if (!entry) {
|
||||
console.log('Registry entry not found!');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Registry: ${entry.handle} @ ${entry.nodeDomain}`);
|
||||
|
||||
// Try keys endpoint
|
||||
const keysUrl = `https://${entry.nodeDomain}/api/chat/keys?did=${encodeURIComponent(TARGET_DID)}`;
|
||||
console.log('Fetching:', keysUrl);
|
||||
|
||||
try {
|
||||
const res = await fetch(keysUrl);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
console.log('Key Data:', data);
|
||||
|
||||
const key = data.publicKey;
|
||||
console.log('Key:', key);
|
||||
console.log('Length:', key.length);
|
||||
|
||||
// Checks
|
||||
const isBase64 = /^[A-Za-z0-9+/]*={0,2}$/.test(key);
|
||||
const isHex = /^[0-9a-fA-F]+$/.test(key);
|
||||
console.log('Is Base64-ish:', isBase64);
|
||||
console.log('Is Hex-ish:', isHex);
|
||||
} else {
|
||||
console.log('Fetch failed:', res.status, await res.text());
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error).then(() => process.exit(0));
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
const sodium = require('libsodium-wrappers-sumo');
|
||||
|
||||
const BAD_KEY_B64 = "z+X63kLk1GoV0gJvPtqNisWuZ3XmlTbfMh9gW0xqcmg=";
|
||||
|
||||
async function main() {
|
||||
console.log('--- Initializing Sodium ---');
|
||||
await sodium.ready;
|
||||
console.log('Sodium Ready. Variants:', sodium.base64_variants);
|
||||
|
||||
const variants = [
|
||||
{ name: 'Default (undefined)', val: undefined },
|
||||
{ name: 'ORIGINAL', val: sodium.base64_variants.ORIGINAL },
|
||||
{ name: 'ORIGINAL_NO_PADDING', val: sodium.base64_variants.ORIGINAL_NO_PADDING },
|
||||
{ name: 'URLSAFE', val: sodium.base64_variants.URLSAFE },
|
||||
{ name: 'URLSAFE_NO_PADDING', val: sodium.base64_variants.URLSAFE_NO_PADDING },
|
||||
];
|
||||
|
||||
for (const v of variants) {
|
||||
process.stdout.write(`Testing: ${v.name}... `);
|
||||
try {
|
||||
// If checking NO_PADDING, manually strip padding for fairness
|
||||
let keyStr = BAD_KEY_B64;
|
||||
if (v.name.includes('NO_PADDING')) keyStr = keyStr.replace(/=/g, '');
|
||||
|
||||
const buf = sodium.from_base64(keyStr, v.val);
|
||||
console.log(`SUCCESS! Length: ${buf.length}`);
|
||||
} catch (e) {
|
||||
console.log(`FAILED.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user