@idos-network/client 1.0.0-rc.1.0 → 1.0.0-rc.1.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/index.d.ts +206 -168
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32815 -4606
- package/dist/index.js.map +1 -1
- package/package.json +17 -14
- package/src/enclave/helpers.ts +25 -0
- package/src/enclave/iframe-enclave.ts +117 -128
- package/src/index.ts +152 -91
- package/src/enclave/index.ts +0 -3
- package/src/enclave/metamask-snap-enclave.ts +0 -91
- package/src/enclave/types.ts +0 -44
package/src/index.ts
CHANGED
|
@@ -1,59 +1,63 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
hexEncodeSha256Hash,
|
|
5
|
-
utf8Decode,
|
|
6
|
-
utf8Encode,
|
|
7
|
-
} from "@idos-network/core/codecs";
|
|
8
|
-
import {
|
|
9
|
-
type AddWalletParams,
|
|
10
|
-
type GetGrantsParams,
|
|
11
|
-
type ShareableCredential,
|
|
2
|
+
type AddAttributeInput,
|
|
3
|
+
type AddWalletInput,
|
|
12
4
|
addWallet,
|
|
13
5
|
addWallets,
|
|
14
|
-
createAttribute,
|
|
6
|
+
addAttribute as createAttribute,
|
|
15
7
|
createCredentialCopy,
|
|
8
|
+
type DagMessageInput,
|
|
9
|
+
dagMessage,
|
|
10
|
+
dwgMessage,
|
|
11
|
+
type GetGrantsPaginatedInput,
|
|
12
|
+
type GetWalletsOutput,
|
|
16
13
|
getAccessGrantsOwned,
|
|
17
|
-
getAllCredentials,
|
|
18
14
|
getAttributes,
|
|
19
|
-
getCredentialById,
|
|
20
15
|
getCredentialOwned,
|
|
16
|
+
getCredentials,
|
|
21
17
|
getGrants,
|
|
22
18
|
getGrantsCount,
|
|
23
19
|
getSharedCredential,
|
|
24
|
-
|
|
20
|
+
getUser,
|
|
25
21
|
getWallets,
|
|
26
22
|
hasProfile,
|
|
27
|
-
type
|
|
23
|
+
type idOSCredential,
|
|
24
|
+
type idOSCredentialListItem,
|
|
25
|
+
type idOSDelegatedWriteGrant,
|
|
26
|
+
type idOSGrant,
|
|
27
|
+
type idOSUser,
|
|
28
|
+
type idOSUserAttribute,
|
|
29
|
+
type idOSWallet,
|
|
28
30
|
removeCredential,
|
|
29
31
|
removeWallet,
|
|
30
32
|
removeWallets,
|
|
31
|
-
requestDAGMessage,
|
|
32
|
-
requestDWGMessage,
|
|
33
33
|
revokeAccessGrant,
|
|
34
|
+
type ShareCredentialInput,
|
|
34
35
|
shareCredential,
|
|
35
36
|
} from "@idos-network/core/kwil-actions";
|
|
36
37
|
import {
|
|
37
|
-
type KwilActionClient,
|
|
38
38
|
createClientKwilSigner,
|
|
39
39
|
createWebKwilClient,
|
|
40
|
+
type KwilActionClient,
|
|
41
|
+
signNearMessage,
|
|
40
42
|
} from "@idos-network/core/kwil-infra";
|
|
41
|
-
import {
|
|
42
|
-
import type {
|
|
43
|
-
DelegatedWriteGrant,
|
|
44
|
-
Wallet,
|
|
45
|
-
idOSCredential,
|
|
46
|
-
idOSGrant,
|
|
47
|
-
idOSUser,
|
|
48
|
-
idOSUserAttribute,
|
|
49
|
-
idOSWallet,
|
|
50
|
-
} from "@idos-network/core/types";
|
|
43
|
+
import type { Wallet } from "@idos-network/core/types";
|
|
51
44
|
import { buildInsertableIDOSCredential } from "@idos-network/core/utils";
|
|
52
|
-
import type { KwilSigner } from "@
|
|
45
|
+
import type { KwilSigner } from "@idos-network/kwil-js";
|
|
46
|
+
import {
|
|
47
|
+
base64Decode,
|
|
48
|
+
base64Encode,
|
|
49
|
+
hexEncodeSha256Hash,
|
|
50
|
+
utf8Decode,
|
|
51
|
+
utf8Encode,
|
|
52
|
+
} from "@idos-network/utils/codecs";
|
|
53
|
+
import type { BaseProvider, PublicEncryptionProfile } from "@idos-network/utils/enclave";
|
|
54
|
+
import { LocalStorageStore, type Store } from "@idos-network/utils/store";
|
|
53
55
|
import { negate } from "es-toolkit";
|
|
54
56
|
import { every, get } from "es-toolkit/compat";
|
|
55
57
|
import invariant from "tiny-invariant";
|
|
56
|
-
|
|
58
|
+
|
|
59
|
+
import { IframeEnclave } from "./enclave/iframe-enclave";
|
|
60
|
+
export { IframeEnclave };
|
|
57
61
|
|
|
58
62
|
type Properties<T> = {
|
|
59
63
|
// biome-ignore lint/complexity/noBannedTypes: All functions are to be removed.
|
|
@@ -66,21 +70,38 @@ export type idOSClient =
|
|
|
66
70
|
| idOSClientWithUserSigner
|
|
67
71
|
| idOSClientLoggedIn;
|
|
68
72
|
|
|
69
|
-
export class idOSClientConfiguration {
|
|
73
|
+
export class idOSClientConfiguration<Provider extends BaseProvider = IframeEnclave> {
|
|
70
74
|
readonly state: "configuration";
|
|
71
75
|
readonly chainId?: string;
|
|
72
76
|
readonly nodeUrl: string;
|
|
73
|
-
readonly enclaveOptions: Omit<
|
|
77
|
+
readonly enclaveOptions: Omit<Provider["options"], "mode">;
|
|
78
|
+
readonly store: Store;
|
|
79
|
+
readonly enclaveProvider: BaseProvider;
|
|
74
80
|
|
|
75
81
|
constructor(params: {
|
|
76
82
|
chainId?: string;
|
|
77
83
|
nodeUrl: string;
|
|
78
|
-
enclaveOptions: Omit<
|
|
84
|
+
enclaveOptions: Omit<Provider["options"], "mode">;
|
|
85
|
+
enclaveProvider?: new (options: Omit<Provider["options"], "mode">) => Provider;
|
|
86
|
+
store?: Store;
|
|
79
87
|
}) {
|
|
80
88
|
this.state = "configuration";
|
|
81
89
|
this.chainId = params.chainId;
|
|
82
90
|
this.nodeUrl = params.nodeUrl;
|
|
83
91
|
this.enclaveOptions = params.enclaveOptions;
|
|
92
|
+
this.store = params.store ?? new LocalStorageStore();
|
|
93
|
+
|
|
94
|
+
// TODO: This is a mess because of types...
|
|
95
|
+
if (params.enclaveProvider) {
|
|
96
|
+
this.enclaveProvider = new params.enclaveProvider({
|
|
97
|
+
...params.enclaveOptions,
|
|
98
|
+
// Some of enclave providers require store to be passed in constructor
|
|
99
|
+
store: this.store,
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
// @ts-expect-error - In case of missing "container" in options, enclave will blow up
|
|
103
|
+
this.enclaveProvider = new IframeEnclave(params.enclaveOptions);
|
|
104
|
+
}
|
|
84
105
|
}
|
|
85
106
|
|
|
86
107
|
async createClient(): Promise<idOSClientIdle> {
|
|
@@ -92,30 +113,28 @@ export class idOSClientIdle {
|
|
|
92
113
|
readonly state: "idle";
|
|
93
114
|
readonly store: Store;
|
|
94
115
|
readonly kwilClient: KwilActionClient;
|
|
95
|
-
readonly enclaveProvider:
|
|
116
|
+
readonly enclaveProvider: BaseProvider;
|
|
96
117
|
|
|
97
|
-
constructor(store: Store, kwilClient: KwilActionClient, enclaveProvider:
|
|
118
|
+
constructor(store: Store, kwilClient: KwilActionClient, enclaveProvider: BaseProvider) {
|
|
98
119
|
this.state = "idle";
|
|
99
120
|
this.store = store;
|
|
100
121
|
this.kwilClient = kwilClient;
|
|
101
122
|
this.enclaveProvider = enclaveProvider;
|
|
102
123
|
}
|
|
103
124
|
|
|
104
|
-
static async fromConfig(params: idOSClientConfiguration): Promise<idOSClientIdle> {
|
|
105
|
-
const store = new Store(window.localStorage);
|
|
125
|
+
static async fromConfig(params: idOSClientConfiguration<BaseProvider>): Promise<idOSClientIdle> {
|
|
106
126
|
const kwilClient = await createWebKwilClient({
|
|
107
127
|
nodeUrl: params.nodeUrl,
|
|
108
128
|
chainId: params.chainId,
|
|
109
129
|
});
|
|
110
130
|
|
|
111
|
-
|
|
112
|
-
await enclaveProvider.load();
|
|
131
|
+
await params.enclaveProvider.load();
|
|
113
132
|
|
|
114
|
-
return new idOSClientIdle(store, kwilClient, enclaveProvider);
|
|
133
|
+
return new idOSClientIdle(params.store, kwilClient, params.enclaveProvider);
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
async addressHasProfile(address: string): Promise<boolean> {
|
|
118
|
-
return hasProfile(this.kwilClient, address);
|
|
137
|
+
return hasProfile(this.kwilClient, { address }).then((res) => res.has_profile);
|
|
119
138
|
}
|
|
120
139
|
|
|
121
140
|
async withUserSigner(signer: Wallet): Promise<idOSClientWithUserSigner> {
|
|
@@ -124,6 +143,7 @@ export class idOSClientIdle {
|
|
|
124
143
|
this.kwilClient,
|
|
125
144
|
signer,
|
|
126
145
|
);
|
|
146
|
+
|
|
127
147
|
this.kwilClient.setSigner(kwilSigner);
|
|
128
148
|
|
|
129
149
|
return new idOSClientWithUserSigner(this, signer, kwilSigner, walletIdentifier);
|
|
@@ -138,7 +158,7 @@ export class idOSClientWithUserSigner implements Omit<Properties<idOSClientIdle>
|
|
|
138
158
|
readonly state: "with-user-signer";
|
|
139
159
|
readonly store: Store;
|
|
140
160
|
readonly kwilClient: KwilActionClient;
|
|
141
|
-
readonly enclaveProvider:
|
|
161
|
+
readonly enclaveProvider: BaseProvider;
|
|
142
162
|
readonly signer: Wallet;
|
|
143
163
|
readonly kwilSigner: KwilSigner;
|
|
144
164
|
readonly walletIdentifier: string;
|
|
@@ -156,6 +176,9 @@ export class idOSClientWithUserSigner implements Omit<Properties<idOSClientIdle>
|
|
|
156
176
|
this.signer = signer;
|
|
157
177
|
this.kwilSigner = kwilSigner;
|
|
158
178
|
this.walletIdentifier = walletIdentifier;
|
|
179
|
+
|
|
180
|
+
// @ts-expect-error - TODO: Fix this
|
|
181
|
+
this.enclaveProvider.setSigner(this.signer);
|
|
159
182
|
}
|
|
160
183
|
|
|
161
184
|
async logOut(): Promise<idOSClientIdle> {
|
|
@@ -164,21 +187,35 @@ export class idOSClientWithUserSigner implements Omit<Properties<idOSClientIdle>
|
|
|
164
187
|
}
|
|
165
188
|
|
|
166
189
|
async hasProfile(): Promise<boolean> {
|
|
167
|
-
return hasProfile(this.kwilClient, this.walletIdentifier)
|
|
190
|
+
return hasProfile(this.kwilClient, { address: this.walletIdentifier }).then(
|
|
191
|
+
(x) => x.has_profile,
|
|
192
|
+
);
|
|
168
193
|
}
|
|
169
194
|
|
|
170
|
-
async
|
|
171
|
-
await this.enclaveProvider.reconfigure({
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
195
|
+
async createUserEncryptionProfile(userId: string): Promise<PublicEncryptionProfile> {
|
|
196
|
+
await this.enclaveProvider.reconfigure({
|
|
197
|
+
mode: "new",
|
|
198
|
+
userId,
|
|
199
|
+
walletAddress: this.walletIdentifier,
|
|
200
|
+
encryptionPasswordStore: undefined,
|
|
201
|
+
expectedUserEncryptionPublicKey: undefined,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return this.enclaveProvider.ensureUserEncryptionProfile();
|
|
175
205
|
}
|
|
176
206
|
|
|
177
207
|
async logIn(): Promise<idOSClientLoggedIn> {
|
|
178
208
|
if (!(await this.hasProfile())) throw new Error("User does not have a profile");
|
|
179
209
|
|
|
180
|
-
await this.
|
|
181
|
-
|
|
210
|
+
const kwilUser = await getUser(this.kwilClient);
|
|
211
|
+
|
|
212
|
+
await this.enclaveProvider.reconfigure({
|
|
213
|
+
mode: "existing",
|
|
214
|
+
userId: kwilUser.id,
|
|
215
|
+
expectedUserEncryptionPublicKey: kwilUser.recipient_encryption_public_key,
|
|
216
|
+
walletAddress: this.walletIdentifier,
|
|
217
|
+
encryptionPasswordStore: kwilUser.encryption_password_store,
|
|
218
|
+
});
|
|
182
219
|
|
|
183
220
|
return new idOSClientLoggedIn(this, kwilUser);
|
|
184
221
|
}
|
|
@@ -188,7 +225,7 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
188
225
|
readonly state: "logged-in";
|
|
189
226
|
readonly store: Store;
|
|
190
227
|
readonly kwilClient: KwilActionClient;
|
|
191
|
-
readonly enclaveProvider:
|
|
228
|
+
readonly enclaveProvider: BaseProvider;
|
|
192
229
|
readonly signer: Wallet;
|
|
193
230
|
readonly kwilSigner: KwilSigner;
|
|
194
231
|
readonly walletIdentifier: string;
|
|
@@ -210,48 +247,47 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
210
247
|
return new idOSClientIdle(this.store, this.kwilClient, this.enclaveProvider);
|
|
211
248
|
}
|
|
212
249
|
|
|
213
|
-
async requestDWGMessage(params:
|
|
214
|
-
return
|
|
250
|
+
async requestDWGMessage(params: idOSDelegatedWriteGrant): Promise<string> {
|
|
251
|
+
return dwgMessage(this.kwilClient, params).then((res) => res.message);
|
|
215
252
|
}
|
|
216
253
|
|
|
217
254
|
async removeCredential(id: string): Promise<{ id: string }> {
|
|
218
|
-
|
|
255
|
+
await removeCredential(this.kwilClient, { id });
|
|
256
|
+
return { id };
|
|
219
257
|
}
|
|
220
258
|
|
|
221
259
|
async getCredentialById(id: string): Promise<idOSCredential | undefined> {
|
|
222
|
-
return
|
|
260
|
+
return getCredentialOwned(this.kwilClient, { id }).then((res) => res[0]);
|
|
223
261
|
}
|
|
224
262
|
|
|
225
|
-
async shareCredential(credential:
|
|
226
|
-
|
|
263
|
+
async shareCredential(credential: ShareCredentialInput): Promise<ShareCredentialInput> {
|
|
264
|
+
await shareCredential(this.kwilClient, credential);
|
|
265
|
+
return credential;
|
|
227
266
|
}
|
|
228
267
|
|
|
229
|
-
async getAllCredentials(): Promise<
|
|
230
|
-
return
|
|
268
|
+
async getAllCredentials(): Promise<idOSCredentialListItem[]> {
|
|
269
|
+
return getCredentials(this.kwilClient);
|
|
231
270
|
}
|
|
232
271
|
|
|
233
272
|
async getAccessGrantsOwned(): Promise<idOSGrant[]> {
|
|
234
273
|
return getAccessGrantsOwned(this.kwilClient);
|
|
235
274
|
}
|
|
236
275
|
|
|
237
|
-
async getCredentialOwned(id: string): Promise<idOSCredential | undefined> {
|
|
238
|
-
return getCredentialOwned(this.kwilClient, id);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
276
|
async getAttributes(): Promise<idOSUserAttribute[]> {
|
|
242
277
|
return getAttributes(this.kwilClient);
|
|
243
278
|
}
|
|
244
279
|
|
|
245
|
-
async createAttribute(attribute:
|
|
246
|
-
|
|
280
|
+
async createAttribute(attribute: AddAttributeInput): Promise<AddAttributeInput> {
|
|
281
|
+
await createAttribute(this.kwilClient, attribute);
|
|
282
|
+
return attribute;
|
|
247
283
|
}
|
|
248
284
|
|
|
249
285
|
async getCredentialContentSha256Hash(id: string): Promise<string> {
|
|
250
|
-
const credential = await getCredentialById(
|
|
286
|
+
const credential = await this.getCredentialById(id);
|
|
251
287
|
|
|
252
288
|
invariant(credential, `"idOSCredential" with id ${id} not found`);
|
|
253
289
|
|
|
254
|
-
await this.enclaveProvider.
|
|
290
|
+
await this.enclaveProvider.ensureUserEncryptionProfile();
|
|
255
291
|
|
|
256
292
|
const plaintext = await this.enclaveProvider.decrypt(
|
|
257
293
|
base64Decode(credential.content),
|
|
@@ -261,21 +297,37 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
261
297
|
return hexEncodeSha256Hash(plaintext);
|
|
262
298
|
}
|
|
263
299
|
|
|
300
|
+
async getCredentialContent(id: string): Promise<string> {
|
|
301
|
+
const credential = await this.getCredentialById(id);
|
|
302
|
+
|
|
303
|
+
invariant(credential, `"idOSCredential" with id ${id} not found`);
|
|
304
|
+
|
|
305
|
+
await this.enclaveProvider.ensureUserEncryptionProfile();
|
|
306
|
+
|
|
307
|
+
const plaintext = await this.enclaveProvider.decrypt(
|
|
308
|
+
base64Decode(credential.content),
|
|
309
|
+
base64Decode(credential.encryptor_public_key),
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
return plaintext as any;
|
|
313
|
+
}
|
|
314
|
+
|
|
264
315
|
async createCredentialCopy(
|
|
265
316
|
id: string,
|
|
266
317
|
consumerRecipientEncryptionPublicKey: string,
|
|
267
318
|
consumerAddress: string,
|
|
268
319
|
lockedUntil: number,
|
|
269
320
|
): Promise<{ id: string }> {
|
|
270
|
-
const originalCredential = await getCredentialById(
|
|
321
|
+
const originalCredential = await this.getCredentialById(id);
|
|
271
322
|
invariant(originalCredential, `"idOSCredential" with id ${id} not found`);
|
|
272
323
|
|
|
273
|
-
await this.enclaveProvider.
|
|
324
|
+
await this.enclaveProvider.ensureUserEncryptionProfile();
|
|
274
325
|
|
|
275
326
|
const decryptedContent = await this.enclaveProvider.decrypt(
|
|
276
327
|
base64Decode(originalCredential.content),
|
|
277
328
|
base64Decode(originalCredential.encryptor_public_key),
|
|
278
329
|
);
|
|
330
|
+
|
|
279
331
|
const { content, encryptorPublicKey } = await this.enclaveProvider.encrypt(
|
|
280
332
|
decryptedContent,
|
|
281
333
|
base64Decode(consumerRecipientEncryptionPublicKey),
|
|
@@ -305,47 +357,56 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
305
357
|
return { id: copyId };
|
|
306
358
|
}
|
|
307
359
|
|
|
308
|
-
async requestDAGMessage(params:
|
|
309
|
-
return
|
|
360
|
+
async requestDAGMessage(params: DagMessageInput): Promise<string> {
|
|
361
|
+
return dagMessage(this.kwilClient, params).then((res) => res.message);
|
|
310
362
|
}
|
|
311
363
|
|
|
312
|
-
async getGrants(
|
|
364
|
+
async getGrants(
|
|
365
|
+
params: GetGrantsPaginatedInput,
|
|
366
|
+
): Promise<{ grants: idOSGrant[]; totalCount: number }> {
|
|
313
367
|
return {
|
|
314
368
|
grants: await getGrants(this.kwilClient, params),
|
|
315
369
|
totalCount: await this.getGrantsCount(),
|
|
316
370
|
};
|
|
317
371
|
}
|
|
318
372
|
|
|
319
|
-
async addWallets(params:
|
|
320
|
-
|
|
373
|
+
async addWallets(params: AddWalletInput[]): Promise<AddWalletInput[]> {
|
|
374
|
+
await addWallets(this.kwilClient, params);
|
|
375
|
+
return params;
|
|
321
376
|
}
|
|
322
377
|
|
|
323
378
|
async getGrantsCount(): Promise<number> {
|
|
324
|
-
return getGrantsCount(this.kwilClient
|
|
379
|
+
return getGrantsCount(this.kwilClient, {
|
|
380
|
+
user_id: null,
|
|
381
|
+
}).then((res) => res.count);
|
|
325
382
|
}
|
|
326
383
|
|
|
327
384
|
async getSharedCredential(id: string): Promise<idOSCredential | undefined> {
|
|
328
|
-
return getSharedCredential(this.kwilClient, id);
|
|
385
|
+
return getSharedCredential(this.kwilClient, { id }).then((res) => res[0]);
|
|
329
386
|
}
|
|
330
387
|
|
|
331
|
-
async revokeAccessGrant(
|
|
332
|
-
|
|
388
|
+
async revokeAccessGrant(id: string): Promise<{ id: string }> {
|
|
389
|
+
await revokeAccessGrant(this.kwilClient, { id });
|
|
390
|
+
return { id };
|
|
333
391
|
}
|
|
334
392
|
|
|
335
|
-
async addWallet(params:
|
|
336
|
-
|
|
393
|
+
async addWallet(params: AddWalletInput): Promise<AddWalletInput> {
|
|
394
|
+
await addWallet(this.kwilClient, params);
|
|
395
|
+
return params;
|
|
337
396
|
}
|
|
338
397
|
|
|
339
|
-
async getWallets(): Promise<
|
|
398
|
+
async getWallets(): Promise<GetWalletsOutput[]> {
|
|
340
399
|
return getWallets(this.kwilClient);
|
|
341
400
|
}
|
|
342
401
|
|
|
343
402
|
async removeWallet(id: string): Promise<{ id: string }> {
|
|
344
|
-
|
|
403
|
+
await removeWallet(this.kwilClient, { id });
|
|
404
|
+
return { id };
|
|
345
405
|
}
|
|
346
406
|
|
|
347
407
|
async removeWallets(ids: string[]): Promise<string[]> {
|
|
348
|
-
|
|
408
|
+
await removeWallets(this.kwilClient, ids);
|
|
409
|
+
return ids;
|
|
349
410
|
}
|
|
350
411
|
|
|
351
412
|
async filterCredentials(requirements: {
|
|
@@ -371,7 +432,7 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
371
432
|
(cred) => !cred.original_id && !!cred.public_notes,
|
|
372
433
|
);
|
|
373
434
|
|
|
374
|
-
invariant(originalCredentials.length, "No original credentials found");
|
|
435
|
+
// invariant(originalCredentials.length, "No original credentials found");
|
|
375
436
|
let result = originalCredentials.filter((cred) => {
|
|
376
437
|
return requirements.acceptedIssuers?.some(
|
|
377
438
|
(issuer) => issuer.authPublicKey === cred.issuer_auth_public_key,
|
|
@@ -409,7 +470,7 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
409
470
|
consumerAuthPublicKey,
|
|
410
471
|
}: { consumerEncryptionPublicKey: string; consumerAuthPublicKey: string },
|
|
411
472
|
): Promise<idOSCredential> {
|
|
412
|
-
const credential = await getCredentialById(
|
|
473
|
+
const credential = await this.getCredentialById(credentialId);
|
|
413
474
|
const contentHash = await this.getCredentialContentSha256Hash(credentialId);
|
|
414
475
|
|
|
415
476
|
invariant(credential, `"idOSCredential" with id ${credentialId} not found`);
|
|
@@ -421,7 +482,7 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
421
482
|
),
|
|
422
483
|
);
|
|
423
484
|
|
|
424
|
-
await this.enclaveProvider.
|
|
485
|
+
await this.enclaveProvider.ensureUserEncryptionProfile();
|
|
425
486
|
|
|
426
487
|
const { content, encryptorPublicKey } = await this.enclaveProvider.encrypt(
|
|
427
488
|
utf8Encode(plaintextContent),
|
|
@@ -451,20 +512,20 @@ export class idOSClientLoggedIn implements Omit<Properties<idOSClientWithUserSig
|
|
|
451
512
|
}
|
|
452
513
|
|
|
453
514
|
export type {
|
|
454
|
-
|
|
515
|
+
idOSDelegatedWriteGrant,
|
|
455
516
|
idOSCredential,
|
|
456
517
|
idOSGrant,
|
|
457
518
|
idOSUser,
|
|
458
519
|
idOSUserAttribute,
|
|
459
520
|
idOSWallet,
|
|
460
|
-
EnclaveOptions,
|
|
461
|
-
EnclaveProvider,
|
|
462
521
|
};
|
|
463
522
|
|
|
523
|
+
export { signNearMessage };
|
|
524
|
+
|
|
464
525
|
export function createIDOSClient(params: {
|
|
465
526
|
nodeUrl: string;
|
|
466
|
-
enclaveOptions: Omit<
|
|
467
|
-
}): idOSClientConfiguration {
|
|
527
|
+
enclaveOptions: Omit<IframeEnclave["options"], "mode">;
|
|
528
|
+
}): idOSClientConfiguration<IframeEnclave> {
|
|
468
529
|
return new idOSClientConfiguration({
|
|
469
530
|
nodeUrl: params.nodeUrl,
|
|
470
531
|
enclaveOptions: params.enclaveOptions,
|
package/src/enclave/index.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { idOSCredential } from "@idos-network/core";
|
|
2
|
-
import type {
|
|
3
|
-
DiscoverUserEncryptionPublicKeyResponse,
|
|
4
|
-
EnclaveOptions,
|
|
5
|
-
EnclaveProvider,
|
|
6
|
-
} from "./types";
|
|
7
|
-
|
|
8
|
-
export class MetaMaskSnapEnclave implements EnclaveProvider {
|
|
9
|
-
// biome-ignore lint/suspicious/noExplicitAny: Types will be added later
|
|
10
|
-
enclaveHost: any;
|
|
11
|
-
snapId: string;
|
|
12
|
-
|
|
13
|
-
constructor(_?: Record<string, unknown>) {
|
|
14
|
-
// biome-ignore lint/suspicious/noExplicitAny: Types will be added later.
|
|
15
|
-
this.enclaveHost = (window as any).ethereum;
|
|
16
|
-
this.snapId = "npm:@idos-network/metamask-snap-enclave";
|
|
17
|
-
}
|
|
18
|
-
reconfigure(_options: Omit<EnclaveOptions, "container" | "url">): Promise<void> {
|
|
19
|
-
throw new Error("Method not implemented.");
|
|
20
|
-
}
|
|
21
|
-
filterCredentials(
|
|
22
|
-
credentials: idOSCredential[],
|
|
23
|
-
privateFieldFilters: { pick: Record<string, unknown[]>; omit: Record<string, unknown[]> },
|
|
24
|
-
): Promise<idOSCredential[]> {
|
|
25
|
-
console.log(credentials, privateFieldFilters);
|
|
26
|
-
throw new Error("Method not implemented.");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async discoverUserEncryptionPublicKey(): Promise<DiscoverUserEncryptionPublicKeyResponse> {
|
|
30
|
-
throw new Error("Method not implemented.");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async load(): Promise<void> {
|
|
34
|
-
const snaps = await this.enclaveHost.request({ method: "wallet_getSnaps" });
|
|
35
|
-
// biome-ignore lint/suspicious/noExplicitAny: Types will be added later
|
|
36
|
-
const connected = Object.values(snaps).find((snap: any) => snap.id === this.snapId);
|
|
37
|
-
|
|
38
|
-
if (!connected)
|
|
39
|
-
await this.enclaveHost.request({
|
|
40
|
-
method: "wallet_requestSnaps",
|
|
41
|
-
params: { [this.snapId]: {} },
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async ready(userId: string): Promise<Uint8Array> {
|
|
46
|
-
let { encryptionPublicKey } = JSON.parse(await this.invokeSnap("storage", { userId }));
|
|
47
|
-
|
|
48
|
-
encryptionPublicKey ||= await this.invokeSnap("init");
|
|
49
|
-
encryptionPublicKey &&= Uint8Array.from(Object.values(encryptionPublicKey));
|
|
50
|
-
|
|
51
|
-
return encryptionPublicKey;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// biome-ignore lint/suspicious/noExplicitAny: Using `any` to avoid type errors.
|
|
55
|
-
invokeSnap(method: string, params: unknown = {}): Promise<any> {
|
|
56
|
-
return this.enclaveHost.request({
|
|
57
|
-
method: "wallet_invokeSnap",
|
|
58
|
-
params: {
|
|
59
|
-
snapId: this.snapId,
|
|
60
|
-
request: { method, params },
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async reset(): Promise<void> {
|
|
66
|
-
return this.invokeSnap("reset");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async confirm(message: string): Promise<boolean> {
|
|
70
|
-
return this.invokeSnap("confirm", { message });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async encrypt(
|
|
74
|
-
message: Uint8Array,
|
|
75
|
-
receiverPublicKey: Uint8Array,
|
|
76
|
-
): Promise<{ content: Uint8Array; encryptorPublicKey: Uint8Array }> {
|
|
77
|
-
await this.invokeSnap("encrypt", { message, receiverPublicKey });
|
|
78
|
-
|
|
79
|
-
throw new Error("The Metamask Enclave needs to be updated");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async decrypt(message: Uint8Array, senderPublicKey: Uint8Array): Promise<Uint8Array> {
|
|
83
|
-
const decrypted = await this.invokeSnap("decrypt", { message, senderPublicKey });
|
|
84
|
-
|
|
85
|
-
return Uint8Array.from(Object.values(decrypted));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async backupPasswordOrSecret(): Promise<void> {
|
|
89
|
-
throw new Error("Method not implemented.");
|
|
90
|
-
}
|
|
91
|
-
}
|
package/src/enclave/types.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { idOSCredential } from "@idos-network/core";
|
|
2
|
-
|
|
3
|
-
export type StoredData = {
|
|
4
|
-
encryptionPublicKey?: Uint8Array;
|
|
5
|
-
userId?: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type DiscoverUserEncryptionPublicKeyResponse = {
|
|
9
|
-
userId: string;
|
|
10
|
-
userEncryptionPublicKey: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type EnclaveOptions = {
|
|
14
|
-
container: string;
|
|
15
|
-
theme?: "light" | "dark";
|
|
16
|
-
mode?: "new" | "existing";
|
|
17
|
-
url?: string;
|
|
18
|
-
throwOnUserCancelUnlock?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export interface EnclaveProvider {
|
|
22
|
-
load(): Promise<void>;
|
|
23
|
-
reconfigure(options: Omit<EnclaveOptions, "container" | "url">): Promise<void>;
|
|
24
|
-
|
|
25
|
-
ready(userId: string, currentUserEncryptionPublicKey?: string): Promise<Uint8Array>;
|
|
26
|
-
reset(): Promise<void>;
|
|
27
|
-
confirm(message: string): Promise<boolean>;
|
|
28
|
-
encrypt(
|
|
29
|
-
message: Uint8Array,
|
|
30
|
-
receiverPublicKey?: Uint8Array,
|
|
31
|
-
): Promise<{ content: Uint8Array; encryptorPublicKey: Uint8Array }>;
|
|
32
|
-
decrypt(message: Uint8Array, senderPublicKey?: Uint8Array): Promise<Uint8Array>;
|
|
33
|
-
discoverUserEncryptionPublicKey(userId: string): Promise<DiscoverUserEncryptionPublicKeyResponse>;
|
|
34
|
-
|
|
35
|
-
filterCredentials(
|
|
36
|
-
credentials: idOSCredential[],
|
|
37
|
-
privateFieldFilters: {
|
|
38
|
-
pick: Record<string, unknown[]>;
|
|
39
|
-
omit: Record<string, unknown[]>;
|
|
40
|
-
},
|
|
41
|
-
): Promise<idOSCredential[]>;
|
|
42
|
-
|
|
43
|
-
backupPasswordOrSecret(): Promise<void>;
|
|
44
|
-
}
|