@idos-network/client 1.0.0-rc.1.1 → 1.1.0
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 +113 -3
- package/dist/index.d.ts +37 -218
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +109 -33486
- package/dist/index.js.map +1 -1
- package/package.json +30 -42
- package/src/enclave/helpers.ts +2 -2
- package/src/enclave/iframe-enclave.ts +60 -8
- package/src/index.ts +222 -105
package/package.json
CHANGED
|
@@ -1,58 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idos-network/client",
|
|
3
|
+
"version": "1.1.0",
|
|
3
4
|
"description": "idOS Client JavaScript SDK for browser environments",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"devDependencies.@idos-network/core",
|
|
8
|
-
"devDependencies.@idos-network/credentials"
|
|
9
|
-
]
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@gemwallet/api": "catalog:core",
|
|
13
|
-
"@idos-network/kwil-js": "catalog:core",
|
|
14
|
-
"@idos-network/utils": "workspace:*",
|
|
15
|
-
"es-toolkit": "catalog:utils"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"clean-package": "^2.2.0",
|
|
19
|
-
"release-it": "^19.0.2",
|
|
20
|
-
"release-it-pnpm": "^4.6.5",
|
|
21
|
-
"tiny-invariant": "catalog:core",
|
|
22
|
-
"tsdown": "catalog:build"
|
|
23
|
-
},
|
|
24
|
-
"engines": {
|
|
25
|
-
"node": ">=20.0.0"
|
|
26
|
-
},
|
|
27
|
-
"exports": {
|
|
28
|
-
".": {
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
|
-
"import": "./dist/index.js"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
5
|
+
"homepage": "https://idos.network",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": "github:idos-network/idos-sdk-js",
|
|
33
8
|
"files": [
|
|
34
9
|
"dist/**/*",
|
|
35
10
|
"src/**/*"
|
|
36
11
|
],
|
|
37
|
-
"
|
|
38
|
-
"
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "./dist/index.js",
|
|
39
15
|
"module": "dist/index.js",
|
|
40
|
-
"
|
|
41
|
-
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
42
22
|
},
|
|
43
23
|
"publishConfig": {
|
|
44
24
|
"access": "public"
|
|
45
25
|
},
|
|
46
|
-
"
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@idos-network/kwil-js": "0.1.3",
|
|
28
|
+
"tiny-invariant": "^1.3.3",
|
|
29
|
+
"@idos-network/credentials": "1.1.0",
|
|
30
|
+
"@idos-network/utils": "1.1.0",
|
|
31
|
+
"@idos-network/enclave": "1.1.0",
|
|
32
|
+
"@idos-network/kwil-infra": "1.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsdown": "^0.21.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22.19.0"
|
|
39
|
+
},
|
|
47
40
|
"scripts": {
|
|
48
41
|
"build": "tsdown",
|
|
49
42
|
"dev": "tsdown --watch",
|
|
50
|
-
"postpack": "clean-package restore",
|
|
51
|
-
"prepack": "clean-package",
|
|
52
43
|
"publint": "pnpx publint --strict",
|
|
53
|
-
"
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
"type": "module",
|
|
57
|
-
"types": "dist/index.d.ts"
|
|
58
|
-
}
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/enclave/helpers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import type { BaseProvider } from "@idos-network/
|
|
1
|
+
/* oxlint-disable typescript/no-explicit-any -- any is fine here. */
|
|
2
|
+
import type { BaseProvider } from "@idos-network/enclave";
|
|
3
3
|
|
|
4
4
|
type BaseProviderInstance = typeof BaseProvider.prototype & {
|
|
5
5
|
// Custom method from enclave to ensure <-> iframe communication
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import type { idOSCredential } from "@idos-network/credentials";
|
|
1
|
+
import type { idOSCredential } from "@idos-network/credentials/types";
|
|
2
|
+
import type {
|
|
3
|
+
AddAddressMessageToSign,
|
|
4
|
+
AddAddressSignatureMessage,
|
|
5
|
+
RemoveAddressMessageToSign,
|
|
6
|
+
RemoveAddressSignatureMessage,
|
|
7
|
+
} from "@idos-network/enclave/mpc";
|
|
8
|
+
|
|
2
9
|
import {
|
|
3
10
|
BaseProvider,
|
|
4
11
|
type EnclaveOptions,
|
|
5
12
|
type PublicEncryptionProfile,
|
|
6
|
-
} from "@idos-network/
|
|
13
|
+
} from "@idos-network/enclave";
|
|
14
|
+
|
|
7
15
|
import type { BaseProviderMethodArgs, BaseProviderMethodReturn } from "./helpers";
|
|
8
16
|
|
|
9
17
|
export interface IframeEnclaveOptions extends EnclaveOptions {
|
|
@@ -16,6 +24,7 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
16
24
|
private container: string;
|
|
17
25
|
private iframe: HTMLIFrameElement;
|
|
18
26
|
private hostUrl: URL;
|
|
27
|
+
private bound = false;
|
|
19
28
|
|
|
20
29
|
constructor(options: IframeEnclaveOptions) {
|
|
21
30
|
super(options);
|
|
@@ -118,6 +127,43 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
118
127
|
}
|
|
119
128
|
}
|
|
120
129
|
|
|
130
|
+
async addAddressMessageToSign(
|
|
131
|
+
address: string,
|
|
132
|
+
publicKey: string | undefined,
|
|
133
|
+
addressToAddType: string,
|
|
134
|
+
): Promise<AddAddressMessageToSign> {
|
|
135
|
+
return this.requestToEnclave("addAddressMessageToSign", address, publicKey, addressToAddType);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async removeAddressMessageToSign(
|
|
139
|
+
address: string,
|
|
140
|
+
publicKey: string | undefined,
|
|
141
|
+
addressToRemoveType: string,
|
|
142
|
+
): Promise<RemoveAddressMessageToSign> {
|
|
143
|
+
return this.requestToEnclave(
|
|
144
|
+
"removeAddressMessageToSign",
|
|
145
|
+
address,
|
|
146
|
+
publicKey,
|
|
147
|
+
addressToRemoveType,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async addAddressToMpcSecret(
|
|
152
|
+
userId: string,
|
|
153
|
+
message: AddAddressSignatureMessage,
|
|
154
|
+
signature: string,
|
|
155
|
+
): Promise<string> {
|
|
156
|
+
return this.requestToEnclave("addAddressToMpcSecret", userId, message, signature);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async removeAddressFromMpcSecret(
|
|
160
|
+
userId: string,
|
|
161
|
+
message: RemoveAddressSignatureMessage,
|
|
162
|
+
signature: string,
|
|
163
|
+
): Promise<string> {
|
|
164
|
+
return this.requestToEnclave("removeAddressFromMpcSecret", userId, message, signature);
|
|
165
|
+
}
|
|
166
|
+
|
|
121
167
|
private async createAndLoadIframe(): Promise<void> {
|
|
122
168
|
const container = document.querySelector(this.container);
|
|
123
169
|
|
|
@@ -146,6 +192,7 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
146
192
|
"background-color": "transparent",
|
|
147
193
|
border: "none",
|
|
148
194
|
display: "block",
|
|
195
|
+
overflow: "hidden",
|
|
149
196
|
width: "100%",
|
|
150
197
|
};
|
|
151
198
|
|
|
@@ -158,7 +205,7 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
158
205
|
}
|
|
159
206
|
|
|
160
207
|
let el: HTMLElement | null;
|
|
161
|
-
//
|
|
208
|
+
// oxlint-disable-next-line no-cond-assign -- it's on purpose
|
|
162
209
|
while ((el = document.getElementById(this.iframe.id))) {
|
|
163
210
|
console.log("reinstalling idOS iframe...");
|
|
164
211
|
container.removeChild(el);
|
|
@@ -177,12 +224,12 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
177
224
|
}
|
|
178
225
|
|
|
179
226
|
private showEnclave(): void {
|
|
180
|
-
//
|
|
227
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion -- Make the explosion visible.
|
|
181
228
|
this.iframe.parentElement!.classList.add("visible");
|
|
182
229
|
}
|
|
183
230
|
|
|
184
231
|
private hideEnclave(): void {
|
|
185
|
-
//
|
|
232
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion -- Make the explosion visible.
|
|
186
233
|
this.iframe.parentElement!.classList.remove("visible");
|
|
187
234
|
}
|
|
188
235
|
|
|
@@ -195,10 +242,11 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
195
242
|
|
|
196
243
|
port1.onmessage = ({ data }) => {
|
|
197
244
|
port1.close();
|
|
245
|
+
// oxlint-disable-next-line no-unused-expressions
|
|
198
246
|
data.error ? reject(data.error) : resolve(data.result);
|
|
199
247
|
};
|
|
200
248
|
|
|
201
|
-
//
|
|
249
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion -- Make the explosion visible.
|
|
202
250
|
this.iframe.contentWindow!.postMessage(
|
|
203
251
|
{
|
|
204
252
|
method,
|
|
@@ -211,16 +259,20 @@ export class IframeEnclave extends BaseProvider<IframeEnclaveOptions> {
|
|
|
211
259
|
}
|
|
212
260
|
|
|
213
261
|
private bindMessageListener(): void {
|
|
214
|
-
window.addEventListener("message", this.onMessage.bind(this));
|
|
262
|
+
if (!this.bound) window.addEventListener("message", this.onMessage.bind(this));
|
|
263
|
+
this.bound = true;
|
|
215
264
|
}
|
|
216
265
|
|
|
217
266
|
private async onMessage(message: MessageEvent): Promise<void> {
|
|
267
|
+
// We can't be sure about the message and the content
|
|
268
|
+
// so we have to validate it carefully.
|
|
269
|
+
if (!message || !message.data || typeof message.data !== "object") return;
|
|
270
|
+
|
|
218
271
|
if (message.data.type !== "idOS:signTypedData" || message.origin !== this.hostUrl.origin)
|
|
219
272
|
return;
|
|
220
273
|
|
|
221
274
|
const payload = message.data.payload;
|
|
222
275
|
const signature = await this.signTypedData(payload.domain, payload.types, payload.value);
|
|
223
|
-
|
|
224
276
|
await this.requestToEnclave("signTypedDataResponse", signature);
|
|
225
277
|
}
|
|
226
278
|
}
|