@idos-network/enclave 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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/base-0xSNl4rW.d.mts +140 -0
  4. package/dist/base-0xSNl4rW.d.mts.map +1 -0
  5. package/dist/client-BSkUuHYm.mjs +1196 -0
  6. package/dist/client-BSkUuHYm.mjs.map +1 -0
  7. package/dist/client-Bu0aO5sT.d.mts +38 -0
  8. package/dist/client-Bu0aO5sT.d.mts.map +1 -0
  9. package/dist/index.d.mts +16 -0
  10. package/dist/index.d.mts.map +1 -0
  11. package/dist/index.mjs +2 -0
  12. package/dist/keys-RuC1M-_K.mjs +187 -0
  13. package/dist/keys-RuC1M-_K.mjs.map +1 -0
  14. package/dist/local.d.mts +96 -0
  15. package/dist/local.d.mts.map +1 -0
  16. package/dist/local.mjs +253 -0
  17. package/dist/local.mjs.map +1 -0
  18. package/dist/mpc/index.d.mts +3 -0
  19. package/dist/mpc/index.mjs +2 -0
  20. package/dist/types-DKsOwtWL.d.mts +73 -0
  21. package/dist/types-DKsOwtWL.d.mts.map +1 -0
  22. package/package.json +76 -0
  23. package/src/base.test.ts +137 -0
  24. package/src/base.ts +306 -0
  25. package/src/index.ts +3 -0
  26. package/src/keys.ts +10 -0
  27. package/src/local.test.ts +113 -0
  28. package/src/local.ts +495 -0
  29. package/src/mpc/api.ts +122 -0
  30. package/src/mpc/client.ts +411 -0
  31. package/src/mpc/engine-client.ts +144 -0
  32. package/src/mpc/generated/IdosContract.ts +92 -0
  33. package/src/mpc/index.ts +2 -0
  34. package/src/mpc/secretsharing/f256.ts +122 -0
  35. package/src/mpc/secretsharing/finite-field-element.ts +50 -0
  36. package/src/mpc/secretsharing/lagrange.ts +163 -0
  37. package/src/mpc/secretsharing/polynomial.ts +84 -0
  38. package/src/mpc/secretsharing/secret-share-factory.ts +30 -0
  39. package/src/mpc/secretsharing/secret-shares.ts +20 -0
  40. package/src/mpc/secretsharing/shamir-secret-shares.ts +164 -0
  41. package/src/mpc/secretsharing/xor-secret-shares.ts +68 -0
  42. package/src/mpc/types.ts +117 -0
  43. package/src/types.ts +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 idOS Network
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # idOS Enclave
2
+
3
+ > ⚖️ Legalities
4
+ >
5
+ > By downloading, installing, or implementing any of the idOS’ SDKs, you acknowledge that you have read and understood idOS’ Privacy Policy and Transparency Document.
6
+ >
7
+ > - <https://www.idos.network/legal/privacy-policy>
8
+ > - <https://www.idos.network/legal/transparency-document>
9
+
10
+ ## Developing the utils locally
11
+
12
+ ```bash
13
+ pnpm build
14
+ ```
15
+
16
+ ## Enclave provider
17
+
18
+ In case you want to build your own enclave (like in a browser-extension) you should use the base or local provider like this:
19
+
20
+ ```typescript
21
+ import type {
22
+ EncryptionPasswordStore,
23
+ MPCPasswordContext,
24
+ PasswordContext,
25
+ } from "@idos-network/enclave";
26
+ import { LocalEnclave, type LocalEnclaveOptions } from "@idos-network/enclave/local";
27
+
28
+ const ENCLAVE_AUTHORIZED_ORIGINS_KEY = "enclave-authorized-origins";
29
+
30
+ export class Enclave extends LocalEnclave<LocalEnclaveOptions> {
31
+ // Override
32
+ }
33
+ ```
34
+
35
+ ## MPC
36
+
37
+ ```typescript
38
+ import { idOSClientConfiguration } from "@idos-network/client";
39
+ import { ChromeExtensionStore } from "@idos-network/utils/store";
40
+ import { Enclave as ChromeExtensionEnclave } from "./enclave"; // The custom Enclave from the example above
41
+
42
+ const configuration = new idOSClientConfiguration<ChromeExtensionEnclave>({
43
+ nodeUrl: "https://nodes.idos.network",
44
+ enclaveOptions: {
45
+ // Your enclave options here
46
+ },
47
+ enclaveProvider: ChromeExtensionEnclave,
48
+ store: new ChromeExtensionStore(),
49
+ });
50
+ ```
@@ -0,0 +1,140 @@
1
+ import { g as RemoveAddressMessageToSign, i as AddAddressSignatureMessage, n as AddAddressMessageToSign, v as RemoveAddressSignatureMessage } from "./types-DKsOwtWL.mjs";
2
+ import { EncryptionPasswordStore as EncryptionPasswordStore$1, WalletType } from "@idos-network/kwil-infra/actions";
3
+ import { idOSCredential } from "@idos-network/credentials/types";
4
+
5
+ //#region src/types.d.ts
6
+ type PublicEncryptionProfile = {
7
+ userId: string;
8
+ userEncryptionPublicKey: string;
9
+ encryptionPasswordStore: EncryptionPasswordStore$1;
10
+ };
11
+ type PrivateEncryptionProfile = {
12
+ userId: string;
13
+ password: string;
14
+ keyPair: nacl.BoxKeyPair;
15
+ encryptionPasswordStore: EncryptionPasswordStore$1;
16
+ };
17
+ type EnclaveOptions = {
18
+ theme?: "light" | "dark";
19
+ mode?: "new" | "existing";
20
+ userId?: string;
21
+ expectedUserEncryptionPublicKey?: string;
22
+ walletAddress?: string;
23
+ walletPublicKey?: string;
24
+ walletType?: WalletType;
25
+ encryptionPasswordStore?: EncryptionPasswordStore$1;
26
+ };
27
+ type PasswordContext = {
28
+ encryptionPasswordStore: "user";
29
+ password: string;
30
+ duration?: number;
31
+ };
32
+ type MPCPasswordContext = {
33
+ encryptionPasswordStore: "mpc";
34
+ };
35
+ //#endregion
36
+ //#region src/base.d.ts
37
+ declare abstract class BaseProvider<K extends EnclaveOptions = EnclaveOptions> {
38
+ readonly options: K;
39
+ protected _signMethod?: (domain: any, types: any, value: any) => Promise<string>;
40
+ private _signMethodType?;
41
+ constructor(options: K);
42
+ /**
43
+ * Sets the signer for the enclave.
44
+ *
45
+ * @param signer - The signer to set, is later used for MPC if allowed.
46
+ */
47
+ setSigner(signer: {
48
+ signTypedData?: (domain: string, types: string[], value: string) => Promise<string>;
49
+ signMessage?: (message: string) => Promise<any>;
50
+ signer?: (message: string) => Promise<any>;
51
+ }): void;
52
+ signTypedData(domain: any, types: any, value: any): Promise<string>;
53
+ /**
54
+ * Helper method to get the user ID.
55
+ *
56
+ * @returns The user ID.
57
+ */
58
+ get userId(): string;
59
+ /**
60
+ * Resets the enclave (storage etc.)
61
+ */
62
+ reset(): Promise<void>;
63
+ /**
64
+ * Reconfigures the enclave (theme etc).
65
+ *
66
+ * @param options - The options to reconfigure.
67
+ */
68
+ reconfigure(options?: Partial<K>): Promise<void>;
69
+ /**
70
+ * Loads the enclave (create iframe, open connection, etc.)
71
+ */
72
+ load(): Promise<void>;
73
+ /**
74
+ * Encrypts a message to a receiver.
75
+ * This method also checks if the user is authorized to use the keys.
76
+ *
77
+ * @param _message - The message to encrypt.
78
+ * @param _receiverPublicKey - The public key of the receiver.
79
+ *
80
+ * @returns The encrypted message.
81
+ */
82
+ encrypt(_message: Uint8Array, _receiverPublicKey: Uint8Array): Promise<{
83
+ content: Uint8Array;
84
+ encryptorPublicKey: Uint8Array;
85
+ }>;
86
+ /**
87
+ * Decrypts a message from a sender.
88
+ * This method also checks if the user is authorized to use the keys.
89
+ *
90
+ * @param _message - The message to decrypt.
91
+ * @param _senderPublicKey - The public key of the sender.
92
+ *
93
+ * @returns The decrypted message.
94
+ */
95
+ decrypt(_message: Uint8Array, _senderPublicKey: Uint8Array): Promise<Uint8Array<ArrayBufferLike>>;
96
+ /**
97
+ * This method is used to confirm the user action.
98
+ *
99
+ * @param _message - The message to confirm.
100
+ *
101
+ * @returns `true` if the user action is confirmed, `false` otherwise.
102
+ */
103
+ confirm(_message: string): Promise<boolean>;
104
+ /**
105
+ * This method is used to backup the password context.
106
+ */
107
+ backupUserEncryptionProfile(): Promise<void>;
108
+ /**
109
+ * Gets the public encryption profile.
110
+ *
111
+ * @returns The public encryption profile.
112
+ */
113
+ ensureUserEncryptionProfile(): Promise<PublicEncryptionProfile>;
114
+ /**
115
+ * This method authorizes the origin in case of enclave
116
+ * to use the keys, without user providing the password or MPC again.
117
+ *
118
+ * @returns `true` if the user action is authorized, `false` otherwise.
119
+ */
120
+ guardKeys(): Promise<boolean>;
121
+ /**
122
+ * Filters the credentials based on the private field filters.
123
+ *
124
+ * @param credentials - The credentials to filter.
125
+ * @param privateFieldFilters - The private field filters.
126
+ *
127
+ * @returns The filtered credentials without the content.
128
+ */
129
+ filterCredentials(credentials: idOSCredential[], privateFieldFilters: {
130
+ pick: Record<string, unknown[]>;
131
+ omit: Record<string, unknown[]>;
132
+ }): Promise<idOSCredential[]>;
133
+ addAddressMessageToSign(_address: string, _publicKey: string | undefined, _addressToAddType: string): Promise<AddAddressMessageToSign>;
134
+ removeAddressMessageToSign(_address: string, _publicKey: string | undefined, _addressToRemoveType: string): Promise<RemoveAddressMessageToSign>;
135
+ addAddressToMpcSecret(_userId: string, _message: AddAddressSignatureMessage, _signature: string): Promise<string>;
136
+ removeAddressFromMpcSecret(_userId: string, _message: RemoveAddressSignatureMessage, _signature: string): Promise<string>;
137
+ }
138
+ //#endregion
139
+ export { PasswordContext as a, MPCPasswordContext as i, EnclaveOptions as n, PrivateEncryptionProfile as o, EncryptionPasswordStore$1 as r, PublicEncryptionProfile as s, BaseProvider as t };
140
+ //# sourceMappingURL=base-0xSNl4rW.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-0xSNl4rW.d.mts","names":[],"sources":["../src/types.ts","../src/base.ts"],"mappings":";;;;;KAIY,uBAAA;EACV,MAAA;EACA,uBAAA;EACA,uBAAA,EAAyB,yBAAA;AAAA;AAAA,KAGf,wBAAA;EACV,MAAA;EACA,QAAA;EACA,OAAA,EAAS,IAAA,CAAK,UAAA;EACd,uBAAA,EAAyB,yBAAA;AAAA;AAAA,KAGf,cAAA;EACV,KAAA;EACA,IAAA;EACA,MAAA;EACA,+BAAA;EACA,aAAA;EACA,eAAA;EACA,UAAA,GAAa,UAAA;EACb,uBAAA,GAA0B,yBAAA;AAAA;AAAA,KAGhB,eAAA;EACV,uBAAA;EACA,QAAA;EACA,QAAA;AAAA;AAAA,KAGU,kBAAA;EACV,uBAAA;AAAA;;;uBCtBoB,YAAA,WAAuB,cAAA,GAAiB,cAAA;EAAA,SACnD,OAAA,EAAS,CAAA;EAAA,UAGR,WAAA,IAAe,MAAA,OAAa,KAAA,OAAY,KAAA,UAAe,OAAA;EAAA,QACzD,eAAA;EAER,WAAA,CAAY,OAAA,EAAS,CAAA;EDbI;;;;;ECsBzB,SAAA,CAAU,MAAA;IACR,aAAA,IAAiB,MAAA,UAAgB,KAAA,YAAiB,KAAA,aAAkB,OAAA;IAEpE,WAAA,IAAe,OAAA,aAAoB,OAAA;IAEnC,MAAA,IAAU,OAAA,aAAoB,OAAA;EAAA;EA4BhC,aAAA,CAAoB,MAAA,OAAa,KAAA,OAAY,KAAA,QAAa,OAAA;;;;;;MAkDtD,MAAA,CAAA;;;;EAUJ,KAAA,CAAA,GAAe,OAAA;EDzGL;;;;;ECkHV,WAAA,CAAkB,OAAA,GAAS,OAAA,CAAQ,CAAA,IAAU,OAAA;;;;EAO7C,IAAA,CAAA,GAAc,OAAA;;;;;;AD9GhB;;;;EC2H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