BYOK Personal Data Server (PDS) written in Go
ipfs vow atproto pds go
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: add missing js function

+74 -1
+74 -1
server/templates/account.html
··· 234 234 </div> 235 235 </main> 236 236 237 - <script> 237 + <script type="module"> 238 + import { p256 } from 'https://esm.sh/@noble/curves@1.2.0/p256'; 239 + 238 240 // --------------------------------------------------------------------------- 239 241 // Utilities 240 242 // --------------------------------------------------------------------------- ··· 259 261 out[i] = raw.charCodeAt(i); 260 262 } 261 263 return out; 264 + } 265 + 266 + async function deriveSigningKey(prfOutput) { 267 + const keyMaterial = await window.crypto.subtle.importKey( 268 + "raw", 269 + prfOutput, 270 + "HKDF", 271 + false, 272 + ["deriveBits"] 273 + ); 274 + 275 + const derivedBits = await window.crypto.subtle.deriveBits( 276 + { 277 + name: "HKDF", 278 + hash: "SHA-256", 279 + salt: new TextEncoder().encode("Vow PDS Signing Key"), 280 + info: new TextEncoder().encode("P-256") 281 + }, 282 + keyMaterial, 283 + 256 284 + ); 285 + 286 + const privateKeyBytes = new Uint8Array(derivedBits); 287 + 288 + // Use noble-curves to derive public key from private scalar 289 + const pubPoint = p256.getPublicKey(privateKeyBytes, false); 290 + const xBytes = pubPoint.slice(1, 33); 291 + const yBytes = pubPoint.slice(33, 65); 292 + 293 + // Build JWK for import 294 + const jwk = { 295 + kty: "EC", 296 + crv: "P-256", 297 + d: bytesToBase64url(privateKeyBytes), 298 + x: bytesToBase64url(xBytes), 299 + y: bytesToBase64url(yBytes), 300 + ext: true 301 + }; 302 + 303 + const privateKey = await window.crypto.subtle.importKey( 304 + "jwk", 305 + jwk, 306 + { name: "ECDSA", namedCurve: "P-256" }, 307 + true, 308 + ["sign"] 309 + ); 310 + 311 + const rawPublicKey = new Uint8Array(65); 312 + rawPublicKey[0] = 0x04; 313 + rawPublicKey.set(xBytes, 1); 314 + rawPublicKey.set(yBytes, 33); 315 + 316 + const publicKey = await window.crypto.subtle.importKey( 317 + "raw", 318 + rawPublicKey, 319 + { name: "ECDSA", namedCurve: "P-256" }, 320 + true, 321 + ["verify"] 322 + ); 323 + 324 + return { privateKey, publicKey }; 325 + } 326 + 327 + function compressRawPublicKey(rawKey) { 328 + if (rawKey.length !== 65) { 329 + throw new Error("Expected 65-byte uncompressed public key"); 330 + } 331 + const compressed = new Uint8Array(33); 332 + compressed[0] = rawKey[64] % 2 === 0 ? 0x02 : 0x03; 333 + compressed.set(rawKey.slice(1, 33), 1); 334 + return compressed; 262 335 } 263 336 264 337 // ---------------------------------------------------------------------------