prividium 0.1.1 → 0.1.2

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/README.md CHANGED
@@ -48,7 +48,7 @@ const prividiumChain = defineChain({
48
48
 
49
49
  // Create SDK instance
50
50
  // Note: replace the URLs and clientId with your actual values
51
- // Make sure clientId is registered in User Panel (OAUTH_CLIENTS)
51
+ // Make sure clientId & redirectUrl are from a registered Application in the Admin Panel
52
52
  const prividium = createPrividiumChain({
53
53
  clientId: 'your-client-id',
54
54
  chain: prividiumChain,
@@ -195,11 +195,14 @@ const prividium = createPrividiumChain({
195
195
  rpcUrl: 'https://rpc.prividium.io',
196
196
  authBaseUrl: 'https://auth.prividium.io',
197
197
  redirectUrl: window.location.origin + '/auth/callback',
198
- scope: ['wallet:required', 'network:required'], // Request specific scopes
199
198
  onAuthExpiry: () => {
200
199
  console.log('Authentication expired');
201
200
  }
202
201
  });
202
+
203
+ await prividium.authorize({
204
+ scope: ['wallet:required', 'network:required'] // Request specific scopes
205
+ });
203
206
  ```
204
207
 
205
208
  ### Available Scopes
@@ -225,7 +228,6 @@ interface PrividiumConfig {
225
228
  rpcUrl: string; // Private RPC endpoint URL
226
229
  authBaseUrl: string; // Authorization service base URL
227
230
  redirectUrl: string; // OAuth redirect URL
228
- scope?: OauthScope[]; // Optional OAuth scopes to request (optional)
229
231
  storage?: Storage; // Custom storage implementation (optional)
230
232
  onAuthExpiry?: () => void; // Called when authentication expires (optional)
231
233
  }
@@ -242,6 +244,7 @@ Opens authentication popup and handles OAuth flow.
242
244
  ```typescript
243
245
  await prividium.authorize({
244
246
  popupSize: { w: 600, h: 700 } // Optional custom popup dimensions
247
+ scopes: ['wallet:required', 'network:required'], // Optional scope requests
245
248
  });
246
249
  ```
247
250
 
@@ -2,5 +2,5 @@ export { createPrividiumChain } from './prividium-chain.js';
2
2
  export type { PrividiumConfig, PrividiumChain, PopupOptions, Storage, TokenData, UserProfile, UserRole, AddNetworkParams } from './types.js';
3
3
  export { AUTH_ERRORS, STORAGE_KEYS } from './types.js';
4
4
  export { LocalStorage, TokenManager } from './storage.js';
5
- export { parseToken, isTokenExpired, generateRandomState } from './token-utils.js';
5
+ export { generateRandomState } from './token-utils.js';
6
6
  export { PopupAuth, handleAuthCallback, type AuthCallbackMessage, type OauthScope } from './popup-auth.js';
package/dist/sdk/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createPrividiumChain } from './prividium-chain.js';
2
2
  export { AUTH_ERRORS, STORAGE_KEYS } from './types.js';
3
3
  export { LocalStorage, TokenManager } from './storage.js';
4
- export { parseToken, isTokenExpired, generateRandomState } from './token-utils.js';
4
+ export { generateRandomState } from './token-utils.js';
5
5
  export { PopupAuth, handleAuthCallback } from './popup-auth.js';
@@ -1,5 +1,4 @@
1
1
  import { STORAGE_KEYS } from './types.js';
2
- import { parseToken, isTokenExpired } from './token-utils.js';
3
2
  export class LocalStorage {
4
3
  getItem(key) {
5
4
  if (typeof localStorage === 'undefined') {
@@ -33,26 +32,22 @@ export class TokenManager {
33
32
  return `${STORAGE_KEYS.STATE_PREFIX}${this.chainId}`;
34
33
  }
35
34
  getToken() {
36
- if (this.tokenCache && !isTokenExpired(this.tokenCache)) {
35
+ if (this.tokenCache) {
37
36
  return this.tokenCache;
38
37
  }
39
38
  const rawToken = this.storage.getItem(this.tokenKey);
40
39
  if (!rawToken) {
41
- this.tokenCache = null;
42
- return null;
43
- }
44
- try {
45
- this.tokenCache = parseToken(rawToken);
46
- return this.tokenCache;
47
- }
48
- catch {
49
- this.clearToken();
50
40
  return null;
51
41
  }
42
+ const tokenData = {
43
+ rawToken
44
+ };
45
+ this.tokenCache = tokenData;
46
+ return tokenData;
52
47
  }
53
48
  setToken(rawToken) {
54
49
  try {
55
- const tokenData = parseToken(rawToken);
50
+ const tokenData = { rawToken };
56
51
  this.storage.setItem(this.tokenKey, rawToken);
57
52
  this.tokenCache = tokenData;
58
53
  return tokenData;
@@ -63,12 +58,12 @@ export class TokenManager {
63
58
  }
64
59
  }
65
60
  clearToken() {
66
- this.storage.removeItem(this.tokenKey);
67
61
  this.tokenCache = null;
62
+ this.storage.removeItem(this.tokenKey);
68
63
  }
69
64
  isAuthorized() {
70
65
  const token = this.getToken();
71
- return token !== null && !isTokenExpired(token);
66
+ return token !== null;
72
67
  }
73
68
  setState(state) {
74
69
  this.storage.setItem(this.stateKey, state);
@@ -1,4 +1 @@
1
- import { type TokenData } from './types.js';
2
- export declare function parseToken(rawToken: string): TokenData;
3
- export declare function isTokenExpired(tokenData: TokenData): boolean;
4
1
  export declare function generateRandomState(): string;
@@ -1,53 +1,3 @@
1
- import { z } from 'zod';
2
- import { AUTH_ERRORS } from './types.js';
3
- const tokenSchema = z.object({
4
- exp: z.coerce.number().int(),
5
- sub: z.string().min(1),
6
- preferred_username: z.string().optional()
7
- });
8
- function base64UrlDecode(str) {
9
- const base64Encoded = str.replace(/-/g, '+').replace(/_/g, '/');
10
- const padding = str.length % 4 === 0 ? '' : '='.repeat(4 - (str.length % 4));
11
- const base64WithPadding = base64Encoded + padding;
12
- return atob(base64WithPadding)
13
- .split('')
14
- .map((char) => String.fromCharCode(char.charCodeAt(0)))
15
- .join('');
16
- }
17
- export function parseToken(rawToken) {
18
- const parts = rawToken.split('.');
19
- if (parts.length < 3) {
20
- throw new Error(AUTH_ERRORS.INVALID_JWT);
21
- }
22
- let parsed;
23
- try {
24
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
25
- parsed = JSON.parse(base64UrlDecode(parts[1]));
26
- }
27
- catch (e) {
28
- if (!(e instanceof SyntaxError)) {
29
- console.error(e);
30
- }
31
- throw new Error(AUTH_ERRORS.INVALID_JWT);
32
- }
33
- const validated = tokenSchema.safeParse(parsed);
34
- if (!validated.success) {
35
- throw new Error(`Invalid JWT body format: ${validated.error.message}`);
36
- }
37
- const expirationDate = new Date(validated.data.exp * 1000);
38
- if (expirationDate <= new Date()) {
39
- throw new Error(AUTH_ERRORS.EXPIRED_TOKEN);
40
- }
41
- return {
42
- rawToken,
43
- expirationDate,
44
- sub: validated.data.sub,
45
- preferred_username: validated.data.preferred_username
46
- };
47
- }
48
- export function isTokenExpired(tokenData) {
49
- return tokenData.expirationDate <= new Date();
50
- }
51
1
  export function generateRandomState() {
52
2
  const array = new Uint8Array(32);
53
3
  crypto.getRandomValues(array);
@@ -62,9 +62,6 @@ export interface PrividiumChain {
62
62
  }
63
63
  export interface TokenData {
64
64
  rawToken: string;
65
- expirationDate: Date;
66
- sub: string;
67
- preferred_username?: string;
68
65
  }
69
66
  export interface PopupOptions {
70
67
  popupSize?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prividium",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "bin": {
5
5
  "prividium": "./bin/cli.js"
6
6
  },