@darkauth/client 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dek.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { compactDecrypt, importJWK } from "jose";
2
- import { deriveDek, unwrapPrivateKey } from "./crypto";
3
- import { getHooks } from "./hooks";
2
+ import { deriveDek, unwrapPrivateKey } from "./crypto.js";
3
+ import { getHooks } from "./hooks.js";
4
4
  let cachedPrivKey = null;
5
5
  let cachedPrivKeyPromise = null;
6
6
  async function getUserEncPrivateKey(drk) {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./crypto";
2
- export * from "./dek";
3
- export { setHooks } from "./hooks";
1
+ export * from "./crypto.js";
2
+ export * from "./dek.js";
3
+ export { setHooks } from "./hooks.js";
4
4
  type Config = {
5
5
  issuer: string;
6
6
  clientId: string;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { compactDecrypt } from "jose";
2
- export * from "./crypto";
3
- export * from "./dek";
4
- export { setHooks } from "./hooks";
2
+ export * from "./crypto.js";
3
+ export * from "./dek.js";
4
+ export { setHooks } from "./hooks.js";
5
5
  function viteEnvGet(key) {
6
6
  try {
7
7
  const im = import.meta || undefined;
@@ -25,7 +25,6 @@ let cfg = {
25
25
  (typeof window !== "undefined"
26
26
  ? `${window.location.origin}/callback`
27
27
  : "http://localhost:5173/callback"),
28
- zk: true,
29
28
  };
30
29
  const OBFUSCATION_KEY = "DarkAuth-Storage-Protection-2025";
31
30
  export function setConfig(next) {
@@ -93,14 +92,18 @@ export function isTokenValid(token) {
93
92
  return claims.exp * 1000 > Date.now() + 5000;
94
93
  }
95
94
  export async function initiateLogin() {
96
- const keyPair = await crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, [
97
- "deriveKey",
98
- "deriveBits",
99
- ]);
100
- const publicJwk = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
101
- const privateJwk = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
102
- sessionStorage.setItem("zk_eph_priv_jwk", JSON.stringify(privateJwk));
103
- const zkPubParam = bytesToBase64Url(new TextEncoder().encode(JSON.stringify(publicJwk)));
95
+ const zkEnabled = cfg.zk === true;
96
+ let zkPubParam;
97
+ if (zkEnabled) {
98
+ const keyPair = await crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, [
99
+ "deriveKey",
100
+ "deriveBits",
101
+ ]);
102
+ const publicJwk = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
103
+ const privateJwk = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
104
+ sessionStorage.setItem("zk_eph_priv_jwk", JSON.stringify(privateJwk));
105
+ zkPubParam = bytesToBase64Url(new TextEncoder().encode(JSON.stringify(publicJwk)));
106
+ }
104
107
  const state = crypto.randomUUID();
105
108
  const verifier = bytesToBase64Url(crypto.getRandomValues(new Uint8Array(32)));
106
109
  sessionStorage.setItem("pkce_verifier", verifier);
@@ -113,7 +116,7 @@ export async function initiateLogin() {
113
116
  authUrl.searchParams.set("state", state);
114
117
  authUrl.searchParams.set("code_challenge", challenge);
115
118
  authUrl.searchParams.set("code_challenge_method", "S256");
116
- if (cfg.zk !== false)
119
+ if (zkEnabled && zkPubParam)
117
120
  authUrl.searchParams.set("zk_pub", zkPubParam);
118
121
  location.assign(authUrl.toString());
119
122
  }
@@ -202,7 +205,9 @@ export async function refreshSession() {
202
205
  }),
203
206
  });
204
207
  if (!response.ok) {
205
- localStorage.removeItem("refresh_token");
208
+ if (response.status === 401) {
209
+ localStorage.removeItem("refresh_token");
210
+ }
206
211
  return null;
207
212
  }
208
213
  const tokenResponse = await response.json();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkauth/client",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "build": "tsc",
15
+ "test": "npm run build && node --test --test-reporter=dot --experimental-specifier-resolution=node",
15
16
  "prepack": "npm run build",
16
17
  "typecheck": "tsc --noEmit",
17
18
  "prepare": "tsc",