@keyringnetwork/keyring-connect-sdk 1.0.0 → 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 +5 -2
- package/dist/main.js +64 -1
- package/dist/types.d.ts +52 -32
- package/package.json +4 -1
- package/readme.md +27 -26
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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:
|
|
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
|
|
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": "1.0.
|
|
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,13 +26,10 @@ import { KeyringConnect } from '@keyringnetwork/keyring-connect-sdk';
|
|
|
27
26
|
|
|
28
27
|
```typescript
|
|
29
28
|
const extensionConfig = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
client_policy_id: 123,
|
|
35
|
-
client_entity_id: '123',
|
|
36
|
-
},
|
|
29
|
+
name: 'My App',
|
|
30
|
+
app_url: 'https://myapp.com',
|
|
31
|
+
logo_url: 'https://myapp.com/logo.png',
|
|
32
|
+
policy_id: 123,
|
|
37
33
|
};
|
|
38
34
|
try {
|
|
39
35
|
await KeyringConnect.launchExtension(extensionConfig);
|
|
@@ -61,41 +57,45 @@ const status = await KeyringConnect.getExtensionState();
|
|
|
61
57
|
|
|
62
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)
|
|
63
59
|
|
|
64
|
-
|
|
65
60
|
#### ExtensionConfig
|
|
66
61
|
|
|
67
62
|
```typescript
|
|
68
|
-
type
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
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!
|
|
76
70
|
proof_config?: {
|
|
77
|
-
datasource: DataSource;
|
|
78
|
-
entity_type: string;
|
|
71
|
+
datasource: DataSource;
|
|
72
|
+
entity_type: string;
|
|
79
73
|
};
|
|
74
|
+
|
|
75
|
+
// KRN configuration. This can break the extension!
|
|
80
76
|
krn_config?: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
entity_id?: string;
|
|
78
|
+
onboarding_api_url?: string;
|
|
79
|
+
datastore_api_url?: string;
|
|
80
|
+
analytics_api_url?: string;
|
|
84
81
|
};
|
|
85
82
|
};
|
|
86
83
|
```
|
|
87
84
|
|
|
88
85
|
#### Core Types Overview
|
|
86
|
+
|
|
89
87
|
- `ExtensionConfig`: Configuration for initializing the Keyring Connect extension
|
|
90
88
|
- `ExtensionState`: Current state and status information of the extension
|
|
91
89
|
- `UserState`: User's verification and credential status information
|
|
92
90
|
|
|
93
91
|
#### Status Types
|
|
92
|
+
|
|
94
93
|
- `ExtensionStatus`: Extension states (`idle`, `mounted`, `proving`, `prove_success`, `error`)
|
|
95
94
|
- `AttestationStatus`: Off-chain verification status (`onboarding_required`, `onboarding_pending`, `attestation_ready`, `non_compliant`)
|
|
96
95
|
- `CredentialStatus`: On-chain credential status (`expired`, `valid`, `none`)
|
|
97
96
|
|
|
98
97
|
#### Proof Configuration Types
|
|
98
|
+
|
|
99
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
|
|
100
100
|
- `ProofSource`: Defines how to generate a single Proof on a given Data Source, containing an Endpoint and a list of Claims
|
|
101
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
|
|
@@ -120,13 +120,14 @@ type ExtensionConfig = {
|
|
|
120
120
|
## Error Handling
|
|
121
121
|
|
|
122
122
|
The SDK throws errors in the following cases:
|
|
123
|
+
|
|
123
124
|
- Network errors
|
|
124
125
|
- Proof generation failures
|
|
125
126
|
- On-chain credential update failures
|
|
126
127
|
|
|
127
128
|
```typescript
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
const state = await KeyringConnect.getExtensionState();
|
|
130
|
+
if (state.status === 'error') {
|
|
131
|
+
console.error('An error occurred:', state.error);
|
|
132
|
+
}
|
|
132
133
|
```
|