@keyringnetwork/keyring-connect-sdk 1.0.4 → 1.0.5
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 +2 -1
- package/dist/main.js +26 -14
- package/dist/types.d.ts +7 -0
- package/package.json +2 -2
package/dist/main.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { ExtensionSDKConfig, ExtensionState } from './types';
|
|
|
3
3
|
* Class for interacting with the Keyring Connect browser extension
|
|
4
4
|
*/
|
|
5
5
|
export declare class KeyringConnect {
|
|
6
|
+
private static keyringConnectUrl;
|
|
6
7
|
/**
|
|
7
8
|
* Launch the Keyring Connect Extension with the provided configuration
|
|
8
|
-
* @note This will
|
|
9
|
+
* @note This will redirect to the Keyring Connect page if it is not installed
|
|
9
10
|
*/
|
|
10
11
|
static launchExtension(data: ExtensionSDKConfig): Promise<void>;
|
|
11
12
|
/**
|
package/dist/main.js
CHANGED
|
@@ -18,14 +18,22 @@ const types_1 = require("./types");
|
|
|
18
18
|
class KeyringConnect {
|
|
19
19
|
/**
|
|
20
20
|
* Launch the Keyring Connect Extension with the provided configuration
|
|
21
|
-
* @note This will
|
|
21
|
+
* @note This will redirect to the Keyring Connect page if it is not installed
|
|
22
22
|
*/
|
|
23
23
|
static launchExtension(data) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
var _a;
|
|
26
26
|
const keyringConnectAvailable = yield this.isKeyringConnectInstalled();
|
|
27
27
|
if (!keyringConnectAvailable) {
|
|
28
|
-
|
|
28
|
+
if (typeof window !== "undefined") {
|
|
29
|
+
const url = new URL(this.keyringConnectUrl);
|
|
30
|
+
url.searchParams.set("ref", window.location.href);
|
|
31
|
+
window.location.href = url.toString();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error("Keyring Connect is not installed");
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
29
37
|
}
|
|
30
38
|
this.validateClientConfig(data);
|
|
31
39
|
this.validateProofConfig(data);
|
|
@@ -34,16 +42,16 @@ class KeyringConnect {
|
|
|
34
42
|
try {
|
|
35
43
|
const decodedJwt = (0, jwt_decode_1.jwtDecode)(data.krn_config.auth0_id_token);
|
|
36
44
|
if (!decodedJwt) {
|
|
37
|
-
throw new Error(
|
|
45
|
+
throw new Error("Failed to decode auth token");
|
|
38
46
|
}
|
|
39
47
|
launchConfig.auth_user = Object.assign(Object.assign({}, decodedJwt), { id_token: data.krn_config.auth0_id_token });
|
|
40
48
|
}
|
|
41
49
|
catch (error) {
|
|
42
|
-
throw new Error(
|
|
50
|
+
throw new Error("Invalid auth token provided");
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
|
-
console.log(
|
|
46
|
-
window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data: launchConfig },
|
|
53
|
+
console.log("launching keyring connect");
|
|
54
|
+
window.postMessage({ type: types_1.EVENT_ACTIONS.LAUNCH_KEYRING_CONNECT, data: launchConfig }, "*");
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
57
|
/**
|
|
@@ -69,37 +77,37 @@ class KeyringConnect {
|
|
|
69
77
|
static getExtensionState() {
|
|
70
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
79
|
return new Promise((resolve) => {
|
|
72
|
-
window.addEventListener(
|
|
80
|
+
window.addEventListener("message", (event) => {
|
|
73
81
|
if (event.data.type === types_1.EVENT_ACTIONS.KEYRING_CONNECT_STATUS) {
|
|
74
82
|
resolve(event.data.data);
|
|
75
83
|
}
|
|
76
84
|
});
|
|
77
|
-
window.postMessage({ type: types_1.EVENT_ACTIONS.GET_STATUS },
|
|
85
|
+
window.postMessage({ type: types_1.EVENT_ACTIONS.GET_STATUS }, "*");
|
|
78
86
|
});
|
|
79
87
|
});
|
|
80
88
|
}
|
|
81
89
|
static validateClientConfig(config) {
|
|
82
90
|
if (!config.name) {
|
|
83
|
-
throw new Error(
|
|
91
|
+
throw new Error("Name is required");
|
|
84
92
|
}
|
|
85
93
|
if (!config.app_url) {
|
|
86
|
-
throw new Error(
|
|
94
|
+
throw new Error("App URL is required");
|
|
87
95
|
}
|
|
88
96
|
if (!config.logo_url) {
|
|
89
|
-
throw new Error(
|
|
97
|
+
throw new Error("Logo URL is required");
|
|
90
98
|
}
|
|
91
99
|
if (!config.policy_id) {
|
|
92
|
-
throw new Error(
|
|
100
|
+
throw new Error("Policy ID is required");
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
static validateProofConfig(config) {
|
|
96
104
|
var _a;
|
|
97
105
|
if ((_a = config.proof_config) === null || _a === void 0 ? void 0 : _a.datasource) {
|
|
98
106
|
if (config.proof_config.datasource.proof_sources.length === 0) {
|
|
99
|
-
throw new Error(
|
|
107
|
+
throw new Error("At least one proof source is required");
|
|
100
108
|
}
|
|
101
109
|
if (!config.proof_config.datasource.proof_sources.some((source) => source.claims.length > 0)) {
|
|
102
|
-
throw new Error(
|
|
110
|
+
throw new Error("At least one claim is required per proof source");
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
113
|
}
|
|
@@ -118,6 +126,9 @@ class KeyringConnect {
|
|
|
118
126
|
onboarding_api_url: config.krn_config.onboarding_api_url,
|
|
119
127
|
datastore_api_url: config.krn_config.datastore_api_url,
|
|
120
128
|
analytics_api_url: config.krn_config.analytics_api_url,
|
|
129
|
+
isolate_proving: config.krn_config.isolate_proving,
|
|
130
|
+
notaryUrl: config.krn_config.notaryUrl,
|
|
131
|
+
notaryWebsocketUrl: config.krn_config.notaryWebsocketUrl,
|
|
121
132
|
}
|
|
122
133
|
: undefined,
|
|
123
134
|
proof_config: config.proof_config,
|
|
@@ -126,3 +137,4 @@ class KeyringConnect {
|
|
|
126
137
|
}
|
|
127
138
|
}
|
|
128
139
|
exports.KeyringConnect = KeyringConnect;
|
|
140
|
+
KeyringConnect.keyringConnectUrl = "https://app.keyring.network/connect";
|
package/dist/types.d.ts
CHANGED
|
@@ -38,6 +38,9 @@ export type ExtensionSDKConfig = {
|
|
|
38
38
|
analytics_api_url?: string;
|
|
39
39
|
auth0_id_token?: string;
|
|
40
40
|
entity_id?: string;
|
|
41
|
+
isolate_proving?: boolean;
|
|
42
|
+
notaryUrl?: string;
|
|
43
|
+
notaryWebsocketUrl?: string;
|
|
41
44
|
};
|
|
42
45
|
};
|
|
43
46
|
export type ExtensionLaunchConfig = {
|
|
@@ -56,6 +59,9 @@ export type ExtensionLaunchConfig = {
|
|
|
56
59
|
onboarding_api_url?: string;
|
|
57
60
|
datastore_api_url?: string;
|
|
58
61
|
analytics_api_url?: string;
|
|
62
|
+
isolate_proving?: boolean;
|
|
63
|
+
notaryUrl?: string;
|
|
64
|
+
notaryWebsocketUrl?: string;
|
|
59
65
|
};
|
|
60
66
|
auth_user?: any;
|
|
61
67
|
};
|
|
@@ -89,6 +95,7 @@ export interface ExtensionState {
|
|
|
89
95
|
manifest?: any;
|
|
90
96
|
error?: string;
|
|
91
97
|
user?: User;
|
|
98
|
+
tlsn_proof?: string;
|
|
92
99
|
}
|
|
93
100
|
export interface DataSource {
|
|
94
101
|
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.5",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"jwt-decode": "^4.0.0"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "tsc",
|
|
21
|
+
"build": "rm -rf dist && tsc",
|
|
22
22
|
"dev": "tsc --watch"
|
|
23
23
|
}
|
|
24
24
|
}
|