@keyringnetwork/keyring-connect-sdk 1.0.0 → 1.0.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/dist/main.d.ts +5 -2
- package/dist/main.js +64 -1
- package/dist/types.d.ts +42 -34
- package/package.json +4 -1
- package/readme.md +20 -60
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,58 +3,66 @@ 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
|
+
* Additional configuration to customize the extension's verification process.
|
|
25
|
+
* @note should be used with caution as strict validation is applied to the proof config.
|
|
26
|
+
*/
|
|
27
|
+
proof_config?: {
|
|
28
|
+
datasource: DataSource;
|
|
29
|
+
entity_type?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Keyring Network configuration for the extension.
|
|
33
|
+
* @note this is meant to be used for internal testing and development purposes.
|
|
34
|
+
*/
|
|
35
|
+
krn_config?: {
|
|
36
|
+
onboarding_api_url?: string;
|
|
37
|
+
datastore_api_url?: string;
|
|
38
|
+
analytics_api_url?: string;
|
|
39
|
+
auth0_id_token?: string;
|
|
40
|
+
entity_id?: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type ExtensionLaunchConfig = {
|
|
7
44
|
client: {
|
|
8
|
-
/**
|
|
9
|
-
* The name of the client.
|
|
10
|
-
*/
|
|
11
45
|
client_name: string;
|
|
12
|
-
/**
|
|
13
|
-
* The URL of the client app which the chrome extension will communicate with.
|
|
14
|
-
*/
|
|
15
46
|
client_app_url: string;
|
|
16
|
-
/**
|
|
17
|
-
* The URL of the client logo.
|
|
18
|
-
*/
|
|
19
47
|
client_logo_url: string;
|
|
20
|
-
/**
|
|
21
|
-
* The policy ID of the client.
|
|
22
|
-
*/
|
|
23
48
|
client_policy_id: number;
|
|
24
|
-
/**
|
|
25
|
-
* The entity ID of the client.
|
|
26
|
-
*/
|
|
27
49
|
client_entity_id?: string;
|
|
28
50
|
};
|
|
29
51
|
proof_config?: {
|
|
30
|
-
/**
|
|
31
|
-
* The data source to be used for the proof.
|
|
32
|
-
*/
|
|
33
52
|
datasource: DataSource;
|
|
34
|
-
|
|
35
|
-
* The entity type to be used for the proof.
|
|
36
|
-
*/
|
|
37
|
-
entity_type: string;
|
|
53
|
+
entity_type?: string;
|
|
38
54
|
};
|
|
39
55
|
krn_config?: {
|
|
40
|
-
/**
|
|
41
|
-
* The URL of the onboarding API.
|
|
42
|
-
*/
|
|
43
56
|
onboarding_api_url?: string;
|
|
44
|
-
/**
|
|
45
|
-
* The URL of the datastore API.
|
|
46
|
-
*/
|
|
47
57
|
datastore_api_url?: string;
|
|
48
|
-
/**
|
|
49
|
-
* The URL of the analytics API.
|
|
50
|
-
*/
|
|
51
58
|
analytics_api_url?: string;
|
|
52
59
|
};
|
|
60
|
+
auth_user?: any;
|
|
53
61
|
};
|
|
54
62
|
export type ExtensionStatus = 'idle' | 'mounted' | 'proving' | 'prove_success' | 'error';
|
|
55
63
|
export type AttestationStatus = 'onboarding_required' | 'onboarding_pending' | 'attestation_ready' | 'non_compliant';
|
|
56
64
|
export type CredentialStatus = 'expired' | 'valid' | 'none';
|
|
57
|
-
export type
|
|
65
|
+
export type User = {
|
|
58
66
|
/**
|
|
59
67
|
* Off-chain attestation status.
|
|
60
68
|
*/
|
|
@@ -80,7 +88,7 @@ export interface ExtensionState {
|
|
|
80
88
|
status: ExtensionStatus;
|
|
81
89
|
manifest?: any;
|
|
82
90
|
error?: string;
|
|
83
|
-
user?:
|
|
91
|
+
user?: User;
|
|
84
92
|
}
|
|
85
93
|
export interface DataSource {
|
|
86
94
|
id: string;
|
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.2",
|
|
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,16 +26,20 @@ 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
|
};
|
|
34
|
+
|
|
38
35
|
try {
|
|
39
|
-
await KeyringConnect.
|
|
36
|
+
const isInstalled = await KeyringConnect.isKeyringConnectInstalled();
|
|
37
|
+
|
|
38
|
+
if (isInstalled) {
|
|
39
|
+
await KeyringConnect.launchExtension(extensionConfig);
|
|
40
|
+
} else {
|
|
41
|
+
// show UI to install extension
|
|
42
|
+
}
|
|
40
43
|
} catch (error) {
|
|
41
44
|
console.error('Failed to launch Keyring Connect:', error);
|
|
42
45
|
}
|
|
@@ -45,14 +48,14 @@ try {
|
|
|
45
48
|
### Monitor Extension Status
|
|
46
49
|
|
|
47
50
|
```typescript
|
|
48
|
-
export interface
|
|
49
|
-
status:
|
|
51
|
+
export interface ExtensionState {
|
|
52
|
+
status: 'idle' | 'mounted' | 'proving' | 'prove_success' | 'error';
|
|
50
53
|
manifest?: any;
|
|
51
|
-
error?: string;
|
|
52
|
-
user?:
|
|
54
|
+
error?: string; // error message, only if status is 'error'
|
|
55
|
+
user?: User;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
const
|
|
58
|
+
const extensionState = await KeyringConnect.getExtensionState();
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
## API Reference
|
|
@@ -61,47 +64,18 @@ const status = await KeyringConnect.getExtensionState();
|
|
|
61
64
|
|
|
62
65
|
> 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
66
|
|
|
64
|
-
|
|
65
|
-
#### ExtensionConfig
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
type ExtensionConfig = {
|
|
69
|
-
client: {
|
|
70
|
-
client_name: string; // Name of your application
|
|
71
|
-
client_app_url: string; // Your application's URL
|
|
72
|
-
client_logo_url: string; // Your application's logo URL
|
|
73
|
-
client_policy_id: number; // Your Keyring policy ID
|
|
74
|
-
client_entity_id?: string; // Your user's entity ID
|
|
75
|
-
};
|
|
76
|
-
proof_config?: {
|
|
77
|
-
datasource: DataSource; // Configuration for the proof source
|
|
78
|
-
entity_type: string; // Type of entity to verify
|
|
79
|
-
};
|
|
80
|
-
krn_config?: {
|
|
81
|
-
onboarding_api_url?: string; // URL of the onboarding API
|
|
82
|
-
datastore_api_url?: string; // URL of the datastore API
|
|
83
|
-
analytics_api_url?: string; // URL of the analytics API
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
```
|
|
87
|
-
|
|
88
67
|
#### Core Types Overview
|
|
68
|
+
|
|
89
69
|
- `ExtensionConfig`: Configuration for initializing the Keyring Connect extension
|
|
90
70
|
- `ExtensionState`: Current state and status information of the extension
|
|
91
|
-
- `
|
|
71
|
+
- `User`: User's verification and credential status information
|
|
92
72
|
|
|
93
73
|
#### Status Types
|
|
74
|
+
|
|
94
75
|
- `ExtensionStatus`: Extension states (`idle`, `mounted`, `proving`, `prove_success`, `error`)
|
|
95
76
|
- `AttestationStatus`: Off-chain verification status (`onboarding_required`, `onboarding_pending`, `attestation_ready`, `non_compliant`)
|
|
96
77
|
- `CredentialStatus`: On-chain credential status (`expired`, `valid`, `none`)
|
|
97
78
|
|
|
98
|
-
#### Proof Configuration Types
|
|
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
|
-
- `ProofSource`: Defines how to generate a single Proof on a given Data Source, containing an Endpoint and a list of Claims
|
|
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
|
|
102
|
-
- `DisclosableField`: A field in the Endpoint's response that the Prover must disclose to the Verifier, defined by a JSON path
|
|
103
|
-
- `Claim`: Links Proofs to Keyring rules, containing a label and rule ID for evaluation of its status
|
|
104
|
-
|
|
105
79
|
## Extension States
|
|
106
80
|
|
|
107
81
|
- **idle**: Extension is installed but not active
|
|
@@ -116,17 +90,3 @@ type ExtensionConfig = {
|
|
|
116
90
|
- Chrome browser (version 88 or higher recommended)
|
|
117
91
|
- Keyring Connect browser extension installed
|
|
118
92
|
- Active internet connection
|
|
119
|
-
|
|
120
|
-
## Error Handling
|
|
121
|
-
|
|
122
|
-
The SDK throws errors in the following cases:
|
|
123
|
-
- Network errors
|
|
124
|
-
- Proof generation failures
|
|
125
|
-
- On-chain credential update failures
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
const state = await KeyringConnect.getExtensionState();
|
|
129
|
-
if (state.status === 'error') {
|
|
130
|
-
console.error('An error occurred:', state.error);
|
|
131
|
-
}
|
|
132
|
-
```
|