Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,955 changes: 1,618 additions & 337 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ authors = ["World Contributors"]

[workspace.dependencies]
# World ID protocol types
world-id-primitives = { version = "0.6.0", default-features = false }
world-id-primitives = { version = "0.11.0", default-features = false }

# Serialization
serde = { version = "1.0", features = ["derive"] }
Expand Down Expand Up @@ -60,9 +60,6 @@ alloy-sol-types = "0.8.0"
alloy-primitives = "1.5.7"
ruint = "1.11.1"

# OPRF types
taceo-oprf = { version = "0.8", default-features = false, features = ["types"] }

# UniFFI
uniffi = "0.31"

Expand Down
37 changes: 35 additions & 2 deletions js/examples/nextjs/app/api/rp-signature/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,54 @@ import { signRequest } from "@worldcoin/idkit/signing";

// export const runtime = "nodejs";

type SignatureType = "request" | "create_session" | "session";

function isSignatureType(value: unknown): value is SignatureType {
return (
value === "request" || value === "create_session" || value === "session"
);
}

export async function POST(request: Request): Promise<Response> {
try {
const body = (await request.json()) as {
action: string;
signature_type?: SignatureType;
action?: string;
ttl?: number;
};

const signatureType = body.signature_type ?? "request";
if (!isSignatureType(signatureType)) {
return NextResponse.json(
{ error: "Invalid signature_type" },
{ status: 400 },
);
}

if (body.action !== undefined && typeof body.action !== "string") {
return NextResponse.json(
{ error: "action must be a string" },
{ status: 400 },
);
}

const action = body.action?.trim() || undefined;
Comment thread
Takaros999 marked this conversation as resolved.
if (signatureType !== "request" && action) {
return NextResponse.json(
{ error: "Session signatures must not include action" },
{ status: 400 },
);
}

const signingKey = process.env.RP_SIGNING_KEY;
const { sig, nonce, createdAt, expiresAt } = signRequest({
action: body.action,
...(signatureType === "request" && action ? { action } : {}),
signingKeyHex: signingKey!,
ttl: body.ttl,
});

console.log("Generated RP signature:", {
signatureType,
sig,
nonce,
createdAt,
Expand Down
Loading
Loading