Skip to content

Commit b1ebf31

Browse files
committed
chore: apply changes for .env
1 parent dc95e1c commit b1ebf31

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

infrastructure/eid-wallet/src/env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ declare namespace App {}
55
declare module "$env/static/public" {
66
export const PUBLIC_REGISTRY_URL: string;
77
export const PUBLIC_PROVISIONER_URL: string;
8-
export const EID_WALLET_TOKEN: string;
8+
export const PUBLIC_EID_WALLET_TOKEN: string;
99
}

infrastructure/eid-wallet/src/lib/global/controllers/evault.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PUBLIC_REGISTRY_URL, PUBLIC_PROVISIONER_URL, EID_WALLET_TOKEN } from "$env/static/public";
1+
import { PUBLIC_REGISTRY_URL, PUBLIC_PROVISIONER_URL, PUBLIC_EID_WALLET_TOKEN } from "$env/static/public";
22
import type { Store } from "@tauri-apps/plugin-store";
33
import axios from "axios";
44
import { GraphQLClient } from "graphql-request";
@@ -141,9 +141,9 @@ export class VaultController {
141141
}
142142

143143
// Get authentication token from environment variable
144-
const authToken = EID_WALLET_TOKEN || null;
144+
const authToken = PUBLIC_EID_WALLET_TOKEN || null;
145145
if (!authToken) {
146-
console.warn("EID_WALLET_TOKEN not set, request may fail authentication");
146+
console.warn("PUBLIC_EID_WALLET_TOKEN not set, request may fail authentication");
147147
}
148148

149149
// Call PATCH /public-key to save the public key
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Script to generate a test JWT token for evault-core authentication
5+
*
6+
* Usage:
7+
* REGISTRY_ENTROPY_KEY_JWK='{"kty":"EC",...}' node generate-test-token.js
8+
*
9+
* Or set the environment variable in a .env file
10+
*
11+
* You can also use tsx to run it:
12+
* REGISTRY_ENTROPY_KEY_JWK='...' npx tsx generate-test-token.js
13+
*/
14+
15+
const { importJWK, SignJWT } = require("jose");
16+
const dotenv = require("dotenv");
17+
const path = require("path");
18+
19+
// Load .env file if it exists (try both root and current directory)
20+
dotenv.config({ path: path.resolve(__dirname, "../../../.env") });
21+
dotenv.config({ path: path.resolve(__dirname, ".env") });
22+
23+
async function generateTestToken() {
24+
const jwkString = '{"kty":"EC","use":"sig","alg":"ES256","kid":"entropy-key-1","crv":"P-256","x":"POWUVJwOulAW0gheTVUHF4nXUenMCg0jxhGKI8M1LLU","y":"Cb4GC8Tt0gW7zMr-DhsDJisGVNgWttwjnyQl1HyU7hg","d":"FWqvWBzoiZcD0hh4JAMdJ7foxFRGqyV2Ei_eWvr1Si4"}';
25+
26+
if (!jwkString) {
27+
console.error("Error: REGISTRY_ENTROPY_KEY_JWK environment variable is required");
28+
console.error("\nUsage:");
29+
console.error(" REGISTRY_ENTROPY_KEY_JWK='<your-jwk-json>' node generate-test-token.js");
30+
console.error("\nOr set it in your .env file");
31+
process.exit(1);
32+
}
33+
34+
try {
35+
const jwk = JSON.parse(jwkString);
36+
const privateKey = await importJWK(jwk, "ES256");
37+
38+
// Generate token valid for 1 year
39+
const token = await new SignJWT({
40+
// Add any custom claims you want
41+
platform: "eid-wallet",
42+
purpose: "public-key-sync",
43+
})
44+
.setProtectedHeader({
45+
alg: "ES256",
46+
kid: jwk.kid || "entropy-key-1",
47+
})
48+
.setIssuedAt()
49+
.setExpirationTime("1y") // Valid for 1 year
50+
.sign(privateKey);
51+
52+
console.log("\n✅ Generated JWT Token (valid for 1 year):\n");
53+
console.log(token);
54+
console.log("\n📋 Use this token in the Authorization header:");
55+
console.log(` Authorization: Bearer ${token}\n`);
56+
57+
return token;
58+
} catch (error) {
59+
console.error("Error generating token:", error.message);
60+
if (error.message.includes("JSON")) {
61+
console.error("\nMake sure REGISTRY_ENTROPY_KEY_JWK is valid JSON");
62+
}
63+
process.exit(1);
64+
}
65+
}
66+
67+
generateTestToken();
68+

0 commit comments

Comments
 (0)