diff --git a/scripts/setup.js b/scripts/setup.js index 180b1a2..44809d0 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -338,6 +338,31 @@ async function registerWithPlc(plcUrl, did, operation) { return true } +// === PDS INITIALIZATION === + +async function initializePds(pdsUrl, did, privateKeyHex, handle) { + const url = `${pdsUrl}/init?did=${encodeURIComponent(did)}` + + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + did, + privateKey: privateKeyHex, + handle + }) + }) + + if (!response.ok) { + const text = await response.text() + throw new Error(`PDS initialization failed: ${response.status} ${text}`) + } + + return response.json() +} + // === MAIN === async function main() { @@ -375,7 +400,13 @@ async function main() { console.log(' Registered successfully!') console.log('') - // TODO: Initialize PDS + // Step 4: Initialize PDS + console.log(`Initializing PDS at ${opts.pds}...`) + const privateKeyHex = bytesToHex(keyPair.privateKey) + await initializePds(opts.pds, did, privateKeyHex, fullHandle) + console.log(' PDS initialized!') + console.log('') + // TODO: Notify relay }