diff --git a/.vscode/settings.json b/.vscode/settings.json index 877f8724..77ecbcc0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,5 +19,8 @@ "typescript.preferences.autoImportFileExcludePatterns": [ "next/router.d.ts", "next/dist/client/router.d.ts" - ] + ], + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff" + } } diff --git a/apps/nextjs/src/app/.well-known/did.json/route.ts b/apps/nextjs/src/app/.well-known/did.json/route.ts index 56725249..373eaec2 100644 --- a/apps/nextjs/src/app/.well-known/did.json/route.ts +++ b/apps/nextjs/src/app/.well-known/did.json/route.ts @@ -1,9 +1,19 @@ import { NextResponse } from "next/server"; +const SERVICE_DID = "did:web:graysky.app"; + export function GET() { return NextResponse.json({ "@context": ["https://www.w3.org/ns/did/v1"], - id: "did:web:graysky.app", + id: SERVICE_DID, + verificationMethod: [ + { + id: "did:web:api.bsky.app#atproto", + type: "Multikey", + controller: SERVICE_DID, + publicKeyMultibase: "zQ3shS9xdF5BahagdsLPznAU9L3YrZ6qenrNaV2kq6RjvZ4d1", + }, + ], service: [ { id: "#bsky_notif", diff --git a/cryptography/keyGen.py b/cryptography/keyGen.py new file mode 100644 index 00000000..07b5caa9 --- /dev/null +++ b/cryptography/keyGen.py @@ -0,0 +1,29 @@ +from ecdsa import SECP256k1, SigningKey + +from multiformats.multibase import Multibase + +# Generate a private key +sk = SigningKey.generate(curve=SECP256k1) +print(f"Signing Key: {sk.to_string().hex()}") +print(f"Verifying Key: {sk.verifying_key.to_string().hex()}") +print(f"Verifying Key (compressed): {sk.verifying_key.to_string('compressed').hex()}") + + +# Encoding to multibase + +# When encoding public keys as strings, the preferred representation uses multibase (with base58btc specifically) and a multicode prefix to indicate the specific key type. By embedding metadata about the type of key in the encoding itself, they can be parsed unambiguously. The process for encoding a public key in this format is: +# +# Encode the public key curve "point" as bytes. Be sure to use the smaller "compact" or "compressed" representation. This is usually easy for k256, but might require a special argument or configuration for p256 keys +# Prepend the appropriate curve multicodec value, as varint-encoded bytes, in front of the key bytes: +# p256 (compressed, 33 byte key length): p256-pub, code 0x1200, varint-encoded bytes: [0x80, 0x24] +# k256 (compressed, 33 byte key length): secp256k1-pub, code 0xE7, varint bytes: [0xE7, 0x01] +# Encode the combined bytes with with base58btc, and prefix with a z character, yielding a multibase-encoded string + +multibase = Multibase( + name="base58btc", + code="z", +) + +encoded = multibase.encode(b"\xE7\x01" + sk.verifying_key.to_string("compressed")) + +print(f"Encoded: {encoded}")