@keyringnetwork/keyring-connect-sdk 0.0.8 → 1.0.1

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/main.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ExtensionConfig, ExtensionState } from './types';
1
+ import { ExtensionSDKConfig, ExtensionState } from './types';
2
2
  /**
3
3
  * Class for interacting with the Keyring Connect browser extension
4
4
  */
@@ -7,7 +7,7 @@ export declare class KeyringConnect {
7
7
  * Launch the Keyring Connect Extension with the provided configuration
8
8
  * @note This will throw an error if the extension is not installed
9
9
  */
10
- static launchExtension(data: ExtensionConfig): Promise<void>;
10
+ static launchExtension(data: ExtensionSDKConfig): Promise<void>;
11
11
  /**
12
12
  * Check if Keyring Connect Extension is installed and ready to use
13
13
  */
@@ -16,4 +16,7 @@ export declare class KeyringConnect {
16
16
  * Get the current state of the Keyring Connect Extension to allow for UI updates
17
17
  */
18
18
  static getExtensionState(): Promise<ExtensionState>;
19
+ private static validateClientConfig;
20
+ private static validateProofConfig;
21
+ private static convertToLaunchConfig;
19
22
  }
package/dist/main.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.KeyringConnect = void 0;
13
+ const jwt_decode_1 = require("jwt-decode");
13
14
  const types_1 = require("./types");
14
15
  /**
15
16
  * Class for interacting with the Keyring Connect browser extension
@@ -21,12 +22,28 @@ class KeyringConnect {
21
22
  */
22
23
  static launchExtension(data) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
25
+ var _a;
24
26
  const keyringConnectAvailable = yield this.isKeyringConnectInstalled();
25
27
  if (!keyringConnectAvailable) {
26
28
  throw new Error('Keyring Connect is not installed');
27
29
  }
30
+ this.validateClientConfig(data);
31
+ this.validateProofConfig(data);
32
+ let launchConfig = this.convertToLaunchConfig(data);
33
+ if ((_a = data.krn_config) === null || _a === void 0 ? void 0 : _a.auth0_id_token) {
34
+ try {
35
+ const decodedJwt = (0, jwt_decode_1.jwtDecode)(data.krn_config.auth0_id_token);
36
+ if (!decodedJwt) {
37
+ throw new Error('Failed to decode auth token');
38
+ }
39
+ launchConfig.auth_user = Object.assign(Object.assign({}, decodedJwt), { id_token: data.krn_config.auth0_id_token });
40
+ }
41
+ catch (error) {
42
+ throw new Error('Invalid auth token provided');
43
+ }
44
+ }
28
45
  console.log('launching keyring connect');
29
- window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data }, '*');
46
+ window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data: launchConfig }, '*');
30
47
  });
31
48
  }
32
49
  /**
@@ -61,5 +78,51 @@ class KeyringConnect {
61
78
  });
62
79
  });
63
80
  }
81
+ static validateClientConfig(config) {
82
+ if (!config.name) {
83
+ throw new Error('Name is required');
84
+ }
85
+ if (!config.app_url) {
86
+ throw new Error('App URL is required');
87
+ }
88
+ if (!config.logo_url) {
89
+ throw new Error('Logo URL is required');
90
+ }
91
+ if (!config.policy_id) {
92
+ throw new Error('Policy ID is required');
93
+ }
94
+ }
95
+ static validateProofConfig(config) {
96
+ var _a;
97
+ if ((_a = config.proof_config) === null || _a === void 0 ? void 0 : _a.datasource) {
98
+ if (config.proof_config.datasource.proof_sources.length === 0) {
99
+ throw new Error('At least one proof source is required');
100
+ }
101
+ if (!config.proof_config.datasource.proof_sources.some((source) => source.claims.length > 0)) {
102
+ throw new Error('At least one claim is required per proof source');
103
+ }
104
+ }
105
+ }
106
+ static convertToLaunchConfig(config) {
107
+ var _a;
108
+ const launchConfig = {
109
+ client: {
110
+ client_name: config.name,
111
+ client_app_url: config.app_url,
112
+ client_logo_url: config.logo_url,
113
+ client_policy_id: config.policy_id,
114
+ client_entity_id: (_a = config.krn_config) === null || _a === void 0 ? void 0 : _a.entity_id,
115
+ },
116
+ krn_config: config.krn_config
117
+ ? {
118
+ onboarding_api_url: config.krn_config.onboarding_api_url,
119
+ datastore_api_url: config.krn_config.datastore_api_url,
120
+ analytics_api_url: config.krn_config.analytics_api_url,
121
+ }
122
+ : undefined,
123
+ proof_config: config.proof_config,
124
+ };
125
+ return launchConfig;
126
+ }
64
127
  }
65
128
  exports.KeyringConnect = KeyringConnect;
package/dist/types.d.ts CHANGED
@@ -3,54 +3,74 @@ export declare enum EVENT_ACTIONS {
3
3
  GET_STATUS = "GET_STATUS",
4
4
  KEYRING_CONNECT_STATUS = "KEYRING_CONNECT_STATUS"
5
5
  }
6
- export type ExtensionConfig = {
6
+ export type ExtensionSDKConfig = {
7
+ /**
8
+ * The name of the client.
9
+ */
10
+ name: string;
11
+ /**
12
+ * The URL of the client app which the chrome extension will communicate with.
13
+ */
14
+ app_url: string;
15
+ /**
16
+ * The URL of the client logo.
17
+ */
18
+ logo_url: string;
19
+ /**
20
+ * The policy ID of the client.
21
+ */
22
+ policy_id: number;
23
+ /**
24
+ * The proof configuration for the extension. This can break the extension! Please proceed carefully
25
+ */
26
+ proof_config?: {
27
+ datasource: DataSource;
28
+ entity_type?: string;
29
+ };
30
+ /**
31
+ * The KRN configuration for the extension. This can break the extension! Please proceed carefully
32
+ */
33
+ krn_config?: {
34
+ onboarding_api_url?: string;
35
+ datastore_api_url?: string;
36
+ analytics_api_url?: string;
37
+ auth0_id_token?: string;
38
+ entity_id?: string;
39
+ };
40
+ };
41
+ export type ExtensionLaunchConfig = {
7
42
  client: {
8
- /**
9
- * The name of the client.
10
- */
11
43
  client_name: string;
12
- /**
13
- * The URL of the client app which the chrome extension will communicate with.
14
- */
15
44
  client_app_url: string;
16
- /**
17
- * The URL of the client logo.
18
- */
19
45
  client_logo_url: string;
20
- /**
21
- * The policy ID of the client.
22
- */
23
46
  client_policy_id: number;
24
- /**
25
- * The entity ID of the client.
26
- */
27
47
  client_entity_id?: string;
28
48
  };
29
49
  proof_config?: {
30
- /**
31
- * The data source to be used for the proof.
32
- */
33
50
  datasource: DataSource;
34
- /**
35
- * The entity type to be used for the proof.
36
- */
37
- entity_type: string;
51
+ entity_type?: string;
38
52
  };
39
53
  krn_config?: {
40
- /**
41
- * The URL of the onboarding API.
42
- */
43
54
  onboarding_api_url?: string;
44
- /**
45
- * The URL of the datastore API.
46
- */
47
55
  datastore_api_url?: string;
48
- /**
49
- * The URL of the analytics API.
50
- */
51
56
  analytics_api_url?: string;
52
57
  };
58
+ auth_user?: UserProfile;
53
59
  };
60
+ export interface UserProfile {
61
+ sub: string;
62
+ given_name?: string;
63
+ family_name?: string;
64
+ nickname: string;
65
+ name?: string;
66
+ picture?: string;
67
+ updated_at: string;
68
+ email?: string;
69
+ email_verified?: boolean;
70
+ 'keyring-access/roles': string[];
71
+ uid: string;
72
+ id_token: string;
73
+ }
54
74
  export type ExtensionStatus = 'idle' | 'mounted' | 'proving' | 'prove_success' | 'error';
55
75
  export type AttestationStatus = 'onboarding_required' | 'onboarding_pending' | 'attestation_ready' | 'non_compliant';
56
76
  export type CredentialStatus = 'expired' | 'valid' | 'none';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "0.0.8",
3
+ "version": "1.0.1",
4
4
  "description": "An SDK for interacting with Keyring Connect browser extension",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,5 +17,8 @@
17
17
  "devDependencies": {
18
18
  "ts-node": "^10.9.2",
19
19
  "typescript": "^5.6.3"
20
+ },
21
+ "dependencies": {
22
+ "jwt-decode": "^4.0.0"
20
23
  }
21
24
  }
package/readme.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  A TypeScript/JavaScript SDK for integrating with the Keyring Connect browser extension. This SDK enables seamless interaction with the Keyring Connect extension for user verification and attestation.
4
4
 
5
-
6
5
  ## Installation
7
6
 
8
7
  ```bash
@@ -27,27 +26,10 @@ import { KeyringConnect } from '@keyringnetwork/keyring-connect-sdk';
27
26
 
28
27
  ```typescript
29
28
  const extensionConfig = {
30
- client: {
31
- client_name: 'My App',
32
- client_app_url: 'https://myapp.com',
33
- client_logo_url: 'https://myapp.com/logo.png',
34
- client_policy_id: 123,
35
- client_entity_id: '123',
36
- },
37
- // Optional proof configuration
38
- proof_config: {
39
- datasource: {
40
- id: 'github',
41
- name: 'GitHub',
42
- label: 'GitHub Account',
43
- link: 'https://github.com',
44
- login_url: 'https://github.com/login',
45
- target_url: null,
46
- image: 'https://github.com/logo.png',
47
- proof_sources: [/ ... /],
48
- },
49
- entity_type: 'individual',
50
- },
29
+ name: 'My App',
30
+ app_url: 'https://myapp.com',
31
+ logo_url: 'https://myapp.com/logo.png',
32
+ policy_id: 123,
51
33
  };
52
34
  try {
53
35
  await KeyringConnect.launchExtension(extensionConfig);
@@ -73,43 +55,47 @@ const status = await KeyringConnect.getExtensionState();
73
55
 
74
56
  ### Key Types
75
57
 
76
- > Full type definitions can be found in our [types.ts](src/types.ts)
77
-
58
+ > Full type definitions can be found in our [types.ts](https://github.com/Keyring-Network/keyring-connect/blob/master/keyring-connect-sdk/src/types.ts)
78
59
 
79
60
  #### ExtensionConfig
80
61
 
81
62
  ```typescript
82
- type ExtensionConfig = {
83
- client: {
84
- client_name: string; // Name of your application
85
- client_app_url: string; // Your application's URL
86
- client_logo_url: string; // Your application's logo URL
87
- client_policy_id: number; // Your Keyring policy ID
88
- client_entity_id?: string; // Your user's entity ID
89
- };
63
+ type ExtensionSDKConfig = {
64
+ name: string; // Name of your application
65
+ client_app_url: string; // Your application's URL
66
+ logo_url: string; // Your application's logo URL
67
+ policy_id: number; // Your Keyring policy ID
68
+
69
+ // Proof configuration. This can break the extension!
90
70
  proof_config?: {
91
- datasource: DataSource; // Configuration for the proof source
92
- entity_type: string; // Type of entity to verify
71
+ datasource: DataSource;
72
+ entity_type: string;
93
73
  };
74
+
75
+ // KRN configuration. This can break the extension!
94
76
  krn_config?: {
95
- onboarding_api_url?: string; // URL of the onboarding API
96
- datastore_api_url?: string; // URL of the datastore API
97
- analytics_api_url?: string; // URL of the analytics API
77
+ entity_id?: string;
78
+ onboarding_api_url?: string;
79
+ datastore_api_url?: string;
80
+ analytics_api_url?: string;
98
81
  };
99
82
  };
100
83
  ```
101
84
 
102
85
  #### Core Types Overview
86
+
103
87
  - `ExtensionConfig`: Configuration for initializing the Keyring Connect extension
104
88
  - `ExtensionState`: Current state and status information of the extension
105
89
  - `UserState`: User's verification and credential status information
106
90
 
107
91
  #### Status Types
92
+
108
93
  - `ExtensionStatus`: Extension states (`idle`, `mounted`, `proving`, `prove_success`, `error`)
109
94
  - `AttestationStatus`: Off-chain verification status (`onboarding_required`, `onboarding_pending`, `attestation_ready`, `non_compliant`)
110
95
  - `CredentialStatus`: On-chain credential status (`expired`, `valid`, `none`)
111
96
 
112
97
  #### Proof Configuration Types
98
+
113
99
  - `DataSource`: The website that owns the data the Prover is trying to prove, defined by a name and login URL, containing a list of Proof Sources
114
100
  - `ProofSource`: Defines how to generate a single Proof on a given Data Source, containing an Endpoint and a list of Claims
115
101
  - `Endpoint`: A URL on the Data Source's server that provides access to the data that will need to be disclosed in the Proof
@@ -134,13 +120,14 @@ type ExtensionConfig = {
134
120
  ## Error Handling
135
121
 
136
122
  The SDK throws errors in the following cases:
123
+
137
124
  - Network errors
138
125
  - Proof generation failures
139
126
  - On-chain credential update failures
140
127
 
141
128
  ```typescript
142
- const state = await KeyringConnect.getExtensionState();
143
- if (state.status === 'error') {
144
- console.error('An error occurred:', state.error);
145
- }
129
+ const state = await KeyringConnect.getExtensionState();
130
+ if (state.status === 'error') {
131
+ console.error('An error occurred:', state.error);
132
+ }
146
133
  ```