@mysten/seal 0.4.19 → 0.4.21
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/CHANGELOG.md +17 -0
- package/dist/cjs/bcs.d.ts +68 -121
- package/dist/cjs/bcs.js +7 -7
- package/dist/cjs/bcs.js.map +2 -2
- package/dist/cjs/bls12381.js +8 -2
- package/dist/cjs/bls12381.js.map +2 -2
- package/dist/cjs/client.d.ts +21 -53
- package/dist/cjs/client.js +60 -34
- package/dist/cjs/client.js.map +2 -2
- package/dist/cjs/decrypt.d.ts +6 -1
- package/dist/cjs/decrypt.js +26 -9
- package/dist/cjs/decrypt.js.map +2 -2
- package/dist/cjs/dem.d.ts +1 -1
- package/dist/cjs/dem.js +9 -0
- package/dist/cjs/dem.js.map +2 -2
- package/dist/cjs/encrypt.js +6 -10
- package/dist/cjs/encrypt.js.map +3 -3
- package/dist/cjs/ibe.d.ts +32 -12
- package/dist/cjs/ibe.js +32 -12
- package/dist/cjs/ibe.js.map +2 -2
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/kdf.js.map +1 -1
- package/dist/cjs/key-server.d.ts +47 -1
- package/dist/cjs/key-server.js +57 -4
- package/dist/cjs/key-server.js.map +2 -2
- package/dist/cjs/session-key.d.ts +29 -25
- package/dist/cjs/session-key.js +27 -10
- package/dist/cjs/session-key.js.map +2 -2
- package/dist/cjs/shamir.js +1 -1
- package/dist/cjs/shamir.js.map +2 -2
- package/dist/cjs/types.d.ts +67 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils.d.ts +7 -0
- package/dist/cjs/utils.js +7 -0
- package/dist/cjs/utils.js.map +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/bcs.d.ts +68 -121
- package/dist/esm/bcs.js +7 -7
- package/dist/esm/bcs.js.map +2 -2
- package/dist/esm/bls12381.js +8 -2
- package/dist/esm/bls12381.js.map +2 -2
- package/dist/esm/client.d.ts +21 -53
- package/dist/esm/client.js +62 -36
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/decrypt.d.ts +6 -1
- package/dist/esm/decrypt.js +28 -11
- package/dist/esm/decrypt.js.map +2 -2
- package/dist/esm/dem.d.ts +1 -1
- package/dist/esm/dem.js +9 -0
- package/dist/esm/dem.js.map +2 -2
- package/dist/esm/encrypt.js +4 -8
- package/dist/esm/encrypt.js.map +2 -2
- package/dist/esm/ibe.d.ts +32 -12
- package/dist/esm/ibe.js +32 -12
- package/dist/esm/ibe.js.map +2 -2
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/kdf.js.map +1 -1
- package/dist/esm/key-server.d.ts +47 -1
- package/dist/esm/key-server.js +64 -6
- package/dist/esm/key-server.js.map +2 -2
- package/dist/esm/session-key.d.ts +29 -25
- package/dist/esm/session-key.js +27 -10
- package/dist/esm/session-key.js.map +2 -2
- package/dist/esm/shamir.js +1 -1
- package/dist/esm/shamir.js.map +2 -2
- package/dist/esm/types.d.ts +67 -0
- package/dist/esm/utils.d.ts +7 -0
- package/dist/esm/utils.js +7 -0
- package/dist/esm/utils.js.map +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/cjs/keys.d.ts +0 -17
- package/dist/cjs/keys.js +0 -64
- package/dist/cjs/keys.js.map +0 -7
- package/dist/esm/keys.d.ts +0 -17
- package/dist/esm/keys.js +0 -44
- package/dist/esm/keys.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @mysten/seal
|
|
2
2
|
|
|
3
|
+
## 0.4.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [660377c]
|
|
8
|
+
- @mysten/sui@1.37.2
|
|
9
|
+
|
|
10
|
+
## 0.4.20
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [33230ed]
|
|
15
|
+
- Updated dependencies [33230ed]
|
|
16
|
+
- Updated dependencies [33230ed]
|
|
17
|
+
- @mysten/bcs@1.7.0
|
|
18
|
+
- @mysten/sui@1.37.1
|
|
19
|
+
|
|
3
20
|
## 0.4.19
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/cjs/bcs.d.ts
CHANGED
|
@@ -1,142 +1,89 @@
|
|
|
1
|
-
export declare const IBEEncryptions: import("@mysten/bcs").
|
|
2
|
-
BonehFranklinBLS12381: {
|
|
3
|
-
nonce: Uint8Array<ArrayBufferLike>;
|
|
4
|
-
encryptedShares: Uint8Array<ArrayBufferLike>[]
|
|
5
|
-
encryptedRandomness: Uint8Array<ArrayBufferLike>;
|
|
6
|
-
};
|
|
7
|
-
$kind: "BonehFranklinBLS12381";
|
|
8
|
-
}, {
|
|
9
|
-
BonehFranklinBLS12381: {
|
|
10
|
-
nonce: Iterable<number>;
|
|
11
|
-
encryptedShares: Iterable<Iterable<number>> & {
|
|
1
|
+
export declare const IBEEncryptions: import("@mysten/bcs").BcsEnum<{
|
|
2
|
+
BonehFranklinBLS12381: import("@mysten/bcs").BcsStruct<{
|
|
3
|
+
nonce: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[96]">;
|
|
4
|
+
encryptedShares: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>[], Iterable<Iterable<number>> & {
|
|
12
5
|
length: number;
|
|
13
|
-
}
|
|
14
|
-
encryptedRandomness: Iterable<number>;
|
|
15
|
-
}
|
|
16
|
-
}>;
|
|
17
|
-
export declare const Ciphertext: import("@mysten/bcs").
|
|
18
|
-
Aes256Gcm: {
|
|
19
|
-
blob: number[]
|
|
20
|
-
aad: number[] | null;
|
|
21
|
-
};
|
|
22
|
-
Hmac256Ctr: {
|
|
23
|
-
blob: number[];
|
|
24
|
-
aad: number[] | null;
|
|
25
|
-
mac: Uint8Array<ArrayBufferLike>;
|
|
26
|
-
};
|
|
27
|
-
Plain: {};
|
|
28
|
-
}, "Aes256Gcm" | "Hmac256Ctr" | "Plain">, import("@mysten/bcs").EnumInputShape<{
|
|
29
|
-
Aes256Gcm: {
|
|
30
|
-
blob: Iterable<number> & {
|
|
6
|
+
}, string>;
|
|
7
|
+
encryptedRandomness: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
8
|
+
}, string>;
|
|
9
|
+
}, "IBEEncryptions">;
|
|
10
|
+
export declare const Ciphertext: import("@mysten/bcs").BcsEnum<{
|
|
11
|
+
Aes256Gcm: import("@mysten/bcs").BcsStruct<{
|
|
12
|
+
blob: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
31
13
|
length: number;
|
|
32
|
-
}
|
|
33
|
-
aad: (Iterable<number> & {
|
|
14
|
+
}, string>;
|
|
15
|
+
aad: import("@mysten/bcs").BcsType<number[] | null, (Iterable<number> & {
|
|
34
16
|
length: number;
|
|
35
|
-
}) | null | undefined
|
|
36
|
-
}
|
|
37
|
-
Hmac256Ctr: {
|
|
38
|
-
blob: Iterable<number> & {
|
|
17
|
+
}) | null | undefined, "Option<vector<u8>>">;
|
|
18
|
+
}, string>;
|
|
19
|
+
Hmac256Ctr: import("@mysten/bcs").BcsStruct<{
|
|
20
|
+
blob: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
39
21
|
length: number;
|
|
40
|
-
}
|
|
41
|
-
aad: (Iterable<number> & {
|
|
22
|
+
}, string>;
|
|
23
|
+
aad: import("@mysten/bcs").BcsType<number[] | null, (Iterable<number> & {
|
|
42
24
|
length: number;
|
|
43
|
-
}) | null | undefined
|
|
44
|
-
mac: Iterable<number>;
|
|
45
|
-
}
|
|
46
|
-
Plain: {}
|
|
47
|
-
}
|
|
25
|
+
}) | null | undefined, "Option<vector<u8>>">;
|
|
26
|
+
mac: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
27
|
+
}, string>;
|
|
28
|
+
Plain: import("@mysten/bcs").BcsStruct<{}, string>;
|
|
29
|
+
}, "Ciphertext">;
|
|
48
30
|
/**
|
|
49
31
|
* The encrypted object format. Should be aligned with the Rust implementation.
|
|
50
32
|
*/
|
|
51
|
-
export declare const EncryptedObject: import("@mysten/bcs").
|
|
52
|
-
version: number
|
|
53
|
-
packageId: string
|
|
54
|
-
id: string
|
|
55
|
-
services: [string, number][]
|
|
56
|
-
threshold: number;
|
|
57
|
-
encryptedShares: {
|
|
58
|
-
BonehFranklinBLS12381: {
|
|
59
|
-
nonce: Uint8Array<ArrayBufferLike>;
|
|
60
|
-
encryptedShares: Uint8Array<ArrayBufferLike>[];
|
|
61
|
-
encryptedRandomness: Uint8Array<ArrayBufferLike>;
|
|
62
|
-
};
|
|
63
|
-
$kind: "BonehFranklinBLS12381";
|
|
64
|
-
};
|
|
65
|
-
ciphertext: import("@mysten/bcs").EnumOutputShapeWithKeys<{
|
|
66
|
-
Aes256Gcm: {
|
|
67
|
-
blob: number[];
|
|
68
|
-
aad: number[] | null;
|
|
69
|
-
};
|
|
70
|
-
Hmac256Ctr: {
|
|
71
|
-
blob: number[];
|
|
72
|
-
aad: number[] | null;
|
|
73
|
-
mac: Uint8Array<ArrayBufferLike>;
|
|
74
|
-
};
|
|
75
|
-
Plain: {};
|
|
76
|
-
}, "Aes256Gcm" | "Hmac256Ctr" | "Plain">;
|
|
77
|
-
}, {
|
|
78
|
-
version: number;
|
|
79
|
-
packageId: string | Uint8Array<ArrayBufferLike>;
|
|
80
|
-
id: string;
|
|
81
|
-
services: Iterable<readonly [string | Uint8Array<ArrayBufferLike>, number]> & {
|
|
33
|
+
export declare const EncryptedObject: import("@mysten/bcs").BcsStruct<{
|
|
34
|
+
version: import("@mysten/bcs").BcsType<number, number, "u8">;
|
|
35
|
+
packageId: import("@mysten/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
36
|
+
id: import("@mysten/bcs").BcsType<string, string, string>;
|
|
37
|
+
services: import("@mysten/bcs").BcsType<[string, number][], Iterable<readonly [string | Uint8Array<ArrayBufferLike>, number]> & {
|
|
82
38
|
length: number;
|
|
83
|
-
}
|
|
84
|
-
threshold: number
|
|
85
|
-
encryptedShares: {
|
|
86
|
-
BonehFranklinBLS12381: {
|
|
87
|
-
nonce: Iterable<number>;
|
|
88
|
-
encryptedShares: Iterable<Iterable<number>> & {
|
|
39
|
+
}, string>;
|
|
40
|
+
threshold: import("@mysten/bcs").BcsType<number, number, "u8">;
|
|
41
|
+
encryptedShares: import("@mysten/bcs").BcsEnum<{
|
|
42
|
+
BonehFranklinBLS12381: import("@mysten/bcs").BcsStruct<{
|
|
43
|
+
nonce: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[96]">;
|
|
44
|
+
encryptedShares: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>[], Iterable<Iterable<number>> & {
|
|
89
45
|
length: number;
|
|
90
|
-
}
|
|
91
|
-
encryptedRandomness: Iterable<number>;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
ciphertext: import("@mysten/bcs").
|
|
95
|
-
Aes256Gcm: {
|
|
96
|
-
blob: Iterable<number> & {
|
|
46
|
+
}, string>;
|
|
47
|
+
encryptedRandomness: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
48
|
+
}, string>;
|
|
49
|
+
}, "IBEEncryptions">;
|
|
50
|
+
ciphertext: import("@mysten/bcs").BcsEnum<{
|
|
51
|
+
Aes256Gcm: import("@mysten/bcs").BcsStruct<{
|
|
52
|
+
blob: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
97
53
|
length: number;
|
|
98
|
-
}
|
|
99
|
-
aad: (Iterable<number> & {
|
|
54
|
+
}, string>;
|
|
55
|
+
aad: import("@mysten/bcs").BcsType<number[] | null, (Iterable<number> & {
|
|
100
56
|
length: number;
|
|
101
|
-
}) | null | undefined
|
|
102
|
-
}
|
|
103
|
-
Hmac256Ctr: {
|
|
104
|
-
blob: Iterable<number> & {
|
|
57
|
+
}) | null | undefined, "Option<vector<u8>>">;
|
|
58
|
+
}, string>;
|
|
59
|
+
Hmac256Ctr: import("@mysten/bcs").BcsStruct<{
|
|
60
|
+
blob: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
105
61
|
length: number;
|
|
106
|
-
}
|
|
107
|
-
aad: (Iterable<number> & {
|
|
62
|
+
}, string>;
|
|
63
|
+
aad: import("@mysten/bcs").BcsType<number[] | null, (Iterable<number> & {
|
|
108
64
|
length: number;
|
|
109
|
-
}) | null | undefined
|
|
110
|
-
mac: Iterable<number>;
|
|
111
|
-
}
|
|
112
|
-
Plain: {}
|
|
113
|
-
}>;
|
|
114
|
-
}>;
|
|
65
|
+
}) | null | undefined, "Option<vector<u8>>">;
|
|
66
|
+
mac: import("@mysten/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
67
|
+
}, string>;
|
|
68
|
+
Plain: import("@mysten/bcs").BcsStruct<{}, string>;
|
|
69
|
+
}, "Ciphertext">;
|
|
70
|
+
}, string>;
|
|
115
71
|
/**
|
|
116
72
|
* The Move struct for the KeyServerV1 object.
|
|
117
73
|
*/
|
|
118
|
-
export declare const KeyServerMoveV1: import("@mysten/bcs").
|
|
119
|
-
name: string
|
|
120
|
-
url: string
|
|
121
|
-
keyType: number
|
|
122
|
-
pk: number[]
|
|
123
|
-
}, {
|
|
124
|
-
name: string;
|
|
125
|
-
url: string;
|
|
126
|
-
keyType: number;
|
|
127
|
-
pk: Iterable<number> & {
|
|
74
|
+
export declare const KeyServerMoveV1: import("@mysten/bcs").BcsStruct<{
|
|
75
|
+
name: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
76
|
+
url: import("@mysten/bcs").BcsType<string, string, "string">;
|
|
77
|
+
keyType: import("@mysten/bcs").BcsType<number, number, "u8">;
|
|
78
|
+
pk: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
128
79
|
length: number;
|
|
129
|
-
}
|
|
130
|
-
}>;
|
|
80
|
+
}, string>;
|
|
81
|
+
}, string>;
|
|
131
82
|
/**
|
|
132
83
|
* The Move struct for the parent object.
|
|
133
84
|
*/
|
|
134
|
-
export declare const KeyServerMove: import("@mysten/bcs").
|
|
135
|
-
id: string
|
|
136
|
-
firstVersion: string
|
|
137
|
-
lastVersion: string
|
|
138
|
-
},
|
|
139
|
-
id: string | Uint8Array<ArrayBufferLike>;
|
|
140
|
-
firstVersion: string | number | bigint;
|
|
141
|
-
lastVersion: string | number | bigint;
|
|
142
|
-
}>;
|
|
85
|
+
export declare const KeyServerMove: import("@mysten/bcs").BcsStruct<{
|
|
86
|
+
id: import("@mysten/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
87
|
+
firstVersion: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
88
|
+
lastVersion: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
89
|
+
}, string>;
|
package/dist/cjs/bcs.js
CHANGED
|
@@ -36,25 +36,25 @@ const IBEEncryptions = import_bcs2.bcs.enum("IBEEncryptions", {
|
|
|
36
36
|
});
|
|
37
37
|
const Ciphertext = import_bcs2.bcs.enum("Ciphertext", {
|
|
38
38
|
Aes256Gcm: import_bcs2.bcs.struct("Aes256Gcm", {
|
|
39
|
-
blob: import_bcs2.bcs.vector(import_bcs2.bcs.
|
|
40
|
-
aad: import_bcs2.bcs.option(import_bcs2.bcs.vector(import_bcs2.bcs.
|
|
39
|
+
blob: import_bcs2.bcs.vector(import_bcs2.bcs.u8()),
|
|
40
|
+
aad: import_bcs2.bcs.option(import_bcs2.bcs.vector(import_bcs2.bcs.u8()))
|
|
41
41
|
}),
|
|
42
42
|
Hmac256Ctr: import_bcs2.bcs.struct("Hmac256Ctr", {
|
|
43
|
-
blob: import_bcs2.bcs.vector(import_bcs2.bcs.
|
|
44
|
-
aad: import_bcs2.bcs.option(import_bcs2.bcs.vector(import_bcs2.bcs.
|
|
43
|
+
blob: import_bcs2.bcs.vector(import_bcs2.bcs.u8()),
|
|
44
|
+
aad: import_bcs2.bcs.option(import_bcs2.bcs.vector(import_bcs2.bcs.u8())),
|
|
45
45
|
mac: import_bcs2.bcs.bytes(32)
|
|
46
46
|
}),
|
|
47
47
|
Plain: import_bcs2.bcs.struct("Plain", {})
|
|
48
48
|
});
|
|
49
49
|
const EncryptedObject = import_bcs2.bcs.struct("EncryptedObject", {
|
|
50
|
-
version: import_bcs2.bcs.
|
|
50
|
+
version: import_bcs2.bcs.u8(),
|
|
51
51
|
packageId: import_bcs2.bcs.Address,
|
|
52
52
|
id: import_bcs2.bcs.vector(import_bcs2.bcs.U8).transform({
|
|
53
53
|
output: (val) => (0, import_bcs.toHex)(new Uint8Array(val)),
|
|
54
54
|
input: (val) => (0, import_bcs.fromHex)(val)
|
|
55
55
|
}),
|
|
56
|
-
services: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([import_bcs2.bcs.Address, import_bcs2.bcs.
|
|
57
|
-
threshold: import_bcs2.bcs.
|
|
56
|
+
services: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([import_bcs2.bcs.Address, import_bcs2.bcs.u8()])),
|
|
57
|
+
threshold: import_bcs2.bcs.u8(),
|
|
58
58
|
encryptedShares: IBEEncryptions,
|
|
59
59
|
ciphertext: Ciphertext
|
|
60
60
|
});
|
package/dist/cjs/bcs.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/bcs.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex, toHex } from '@mysten/bcs';\nimport { bcs } from '@mysten/sui/bcs';\n\nexport const IBEEncryptions = bcs.enum('IBEEncryptions', {\n\tBonehFranklinBLS12381: bcs.struct('BonehFranklinBLS12381', {\n\t\tnonce: bcs.bytes(96),\n\t\tencryptedShares: bcs.vector(bcs.bytes(32)),\n\t\tencryptedRandomness: bcs.bytes(32),\n\t}),\n});\n\nexport const Ciphertext = bcs.enum('Ciphertext', {\n\tAes256Gcm: bcs.struct('Aes256Gcm', {\n\t\tblob: bcs.vector(bcs.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA+B;AAC/B,IAAAA,cAAoB;AAEb,MAAM,iBAAiB,gBAAI,KAAK,kBAAkB;AAAA,EACxD,uBAAuB,gBAAI,OAAO,yBAAyB;AAAA,IAC1D,OAAO,gBAAI,MAAM,EAAE;AAAA,IACnB,iBAAiB,gBAAI,OAAO,gBAAI,MAAM,EAAE,CAAC;AAAA,IACzC,qBAAqB,gBAAI,MAAM,EAAE;AAAA,EAClC,CAAC;AACF,CAAC;AAEM,MAAM,aAAa,gBAAI,KAAK,cAAc;AAAA,EAChD,WAAW,gBAAI,OAAO,aAAa;AAAA,IAClC,MAAM,gBAAI,OAAO,gBAAI,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex, toHex } from '@mysten/bcs';\nimport { bcs } from '@mysten/sui/bcs';\n\nexport const IBEEncryptions = bcs.enum('IBEEncryptions', {\n\tBonehFranklinBLS12381: bcs.struct('BonehFranklinBLS12381', {\n\t\tnonce: bcs.bytes(96),\n\t\tencryptedShares: bcs.vector(bcs.bytes(32)),\n\t\tencryptedRandomness: bcs.bytes(32),\n\t}),\n});\n\nexport const Ciphertext = bcs.enum('Ciphertext', {\n\tAes256Gcm: bcs.struct('Aes256Gcm', {\n\t\tblob: bcs.vector(bcs.u8()),\n\t\taad: bcs.option(bcs.vector(bcs.u8())),\n\t}),\n\tHmac256Ctr: bcs.struct('Hmac256Ctr', {\n\t\tblob: bcs.vector(bcs.u8()),\n\t\taad: bcs.option(bcs.vector(bcs.u8())),\n\t\tmac: bcs.bytes(32),\n\t}),\n\tPlain: bcs.struct('Plain', {}),\n});\n\n/**\n * The encrypted object format. Should be aligned with the Rust implementation.\n */\nexport const EncryptedObject = bcs.struct('EncryptedObject', {\n\tversion: bcs.u8(),\n\tpackageId: bcs.Address,\n\tid: bcs.vector(bcs.U8).transform({\n\t\toutput: (val) => toHex(new Uint8Array(val)),\n\t\tinput: (val: string) => fromHex(val),\n\t}),\n\tservices: bcs.vector(bcs.tuple([bcs.Address, bcs.u8()])),\n\tthreshold: bcs.u8(),\n\tencryptedShares: IBEEncryptions,\n\tciphertext: Ciphertext,\n});\n\n/**\n * The Move struct for the KeyServerV1 object.\n */\nexport const KeyServerMoveV1 = bcs.struct('KeyServerV1', {\n\tname: bcs.string(),\n\turl: bcs.string(),\n\tkeyType: bcs.u8(),\n\tpk: bcs.vector(bcs.u8()),\n});\n\n/**\n * The Move struct for the parent object.\n */\nexport const KeyServerMove = bcs.struct('KeyServer', {\n\tid: bcs.Address,\n\tfirstVersion: bcs.u64(), // latest version\n\tlastVersion: bcs.u64(), // oldest version\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA+B;AAC/B,IAAAA,cAAoB;AAEb,MAAM,iBAAiB,gBAAI,KAAK,kBAAkB;AAAA,EACxD,uBAAuB,gBAAI,OAAO,yBAAyB;AAAA,IAC1D,OAAO,gBAAI,MAAM,EAAE;AAAA,IACnB,iBAAiB,gBAAI,OAAO,gBAAI,MAAM,EAAE,CAAC;AAAA,IACzC,qBAAqB,gBAAI,MAAM,EAAE;AA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AAAA,EACR,cAAc,gBAAI,IAAI;AAAA;AAAA,EACtB,aAAa,gBAAI,IAAI;AAAA;AACtB,CAAC;",
|
|
6
6
|
"names": ["import_bcs"]
|
|
7
7
|
}
|
package/dist/cjs/bls12381.js
CHANGED
|
@@ -26,7 +26,6 @@ __export(bls12381_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(bls12381_exports);
|
|
27
27
|
var import_bcs = require("@mysten/bcs");
|
|
28
28
|
var import_bls12_381 = require("@noble/curves/bls12-381");
|
|
29
|
-
var import_utils = require("./utils.js");
|
|
30
29
|
const _G1Element = class _G1Element {
|
|
31
30
|
constructor(point) {
|
|
32
31
|
this.point = point;
|
|
@@ -98,7 +97,14 @@ const _GTElement = class _GTElement {
|
|
|
98
97
|
const P = [0, 3, 1, 4, 2, 5];
|
|
99
98
|
const PAIR_SIZE = _GTElement.SIZE / P.length;
|
|
100
99
|
const bytes = import_bls12_381.bls12_381.fields.Fp12.toBytes(this.element);
|
|
101
|
-
|
|
100
|
+
const result = new Uint8Array(_GTElement.SIZE);
|
|
101
|
+
for (let i = 0; i < P.length; i++) {
|
|
102
|
+
const sourceStart = P[i] * PAIR_SIZE;
|
|
103
|
+
const sourceEnd = sourceStart + PAIR_SIZE;
|
|
104
|
+
const targetStart = i * PAIR_SIZE;
|
|
105
|
+
result.set(bytes.subarray(sourceStart, sourceEnd), targetStart);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
102
108
|
}
|
|
103
109
|
equals(other) {
|
|
104
110
|
return import_bls12_381.bls12_381.fields.Fp12.eql(this.element, other.element);
|
package/dist/cjs/bls12381.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/bls12381.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@mysten/bcs';\nimport type { Fp2, Fp12 } from '@noble/curves/abstract/tower';\nimport type { ProjPointType } from '@noble/curves/abstract/weierstrass';\nimport { bls12_381 } from '@noble/curves/bls12-381';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsB;AAGtB,uBAA0B;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toHex } from '@mysten/bcs';\nimport type { Fp2, Fp12 } from '@noble/curves/abstract/tower';\nimport type { ProjPointType } from '@noble/curves/abstract/weierstrass';\nimport { bls12_381 } from '@noble/curves/bls12-381';\n\nexport class G1Element {\n\tpoint: ProjPointType<bigint>;\n\n\tpublic static readonly SIZE = 48;\n\n\tconstructor(point: ProjPointType<bigint>) {\n\t\tthis.point = point;\n\t}\n\n\tstatic generator(): G1Element {\n\t\treturn new G1Element(bls12_381.G1.ProjectivePoint.BASE);\n\t}\n\n\tstatic fromBytes(bytes: Uint8Array): G1Element {\n\t\treturn new G1Element(bls12_381.G1.ProjectivePoint.fromHex(toHex(bytes)));\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\treturn this.point.toRawBytes();\n\t}\n\n\tmultiply(scalar: Scalar): G1Element {\n\t\treturn new G1Element(this.point.multiply(scalar.scalar));\n\t}\n\n\tadd(other: G1Element): G1Element {\n\t\treturn new G1Element(this.point.add(other.point));\n\t}\n\n\tsubtract(other: G1Element): G1Element {\n\t\treturn new G1Element(this.point.subtract(other.point));\n\t}\n\n\tstatic hashToCurve(data: Uint8Array): G1Element {\n\t\treturn new G1Element(\n\t\t\tbls12_381.G1.ProjectivePoint.fromAffine(bls12_381.G1.hashToCurve(data).toAffine()),\n\t\t);\n\t}\n\n\tpairing(other: G2Element): GTElement {\n\t\treturn new GTElement(bls12_381.pairing(this.point, other.point));\n\t}\n}\n\nexport class G2Element {\n\tpoint: ProjPointType<Fp2>;\n\n\tpublic static readonly SIZE = 96;\n\n\tconstructor(point: ProjPointType<Fp2>) {\n\t\tthis.point = point;\n\t}\n\n\tstatic generator(): G2Element {\n\t\treturn new G2Element(bls12_381.G2.ProjectivePoint.BASE);\n\t}\n\n\tstatic fromBytes(bytes: Uint8Array): G2Element {\n\t\treturn new G2Element(bls12_381.G2.ProjectivePoint.fromHex(toHex(bytes)));\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\treturn this.point.toRawBytes();\n\t}\n\n\tmultiply(scalar: Scalar): G2Element {\n\t\treturn new G2Element(this.point.multiply(scalar.scalar));\n\t}\n\n\tadd(other: G2Element): G2Element {\n\t\treturn new G2Element(this.point.add(other.point));\n\t}\n\n\tstatic hashToCurve(data: Uint8Array): G2Element {\n\t\treturn new G2Element(\n\t\t\tbls12_381.G2.ProjectivePoint.fromAffine(bls12_381.G2.hashToCurve(data).toAffine()),\n\t\t);\n\t}\n\n\tequals(other: G2Element): boolean {\n\t\treturn this.point.equals(other.point);\n\t}\n}\n\nexport class GTElement {\n\telement: Fp12;\n\n\tpublic static readonly SIZE = 576;\n\n\tconstructor(element: Fp12) {\n\t\tthis.element = element;\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\t// This permutation reorders the 6 pairs of coefficients of the GT element for compatability with the Rust and Move implementations.\n\t\t//\n\t\t// The permutation P may be computed as:\n\t\t// for i in 0..3 {\n\t\t// for j in 0..2 {\n\t\t// P[2 * i + j] = i + 3 * j;\n\t\t// }\n\t\t// }\n\t\tconst P = [0, 3, 1, 4, 2, 5];\n\t\tconst PAIR_SIZE = GTElement.SIZE / P.length;\n\n\t\tconst bytes = bls12_381.fields.Fp12.toBytes(this.element);\n\t\tconst result = new Uint8Array(GTElement.SIZE);\n\n\t\tfor (let i = 0; i < P.length; i++) {\n\t\t\tconst sourceStart = P[i] * PAIR_SIZE;\n\t\t\tconst sourceEnd = sourceStart + PAIR_SIZE;\n\t\t\tconst targetStart = i * PAIR_SIZE;\n\t\t\tresult.set(bytes.subarray(sourceStart, sourceEnd), targetStart);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tequals(other: GTElement): boolean {\n\t\treturn bls12_381.fields.Fp12.eql(this.element, other.element);\n\t}\n}\n\nexport class Scalar {\n\tscalar: bigint;\n\n\tpublic static readonly SIZE = 32;\n\n\tconstructor(scalar: bigint) {\n\t\tthis.scalar = scalar;\n\t}\n\n\tstatic random(): Scalar {\n\t\treturn Scalar.fromBytes(bls12_381.utils.randomPrivateKey());\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\treturn new Uint8Array(bls12_381.fields.Fr.toBytes(this.scalar));\n\t}\n\n\tstatic fromBytes(bytes: Uint8Array): Scalar {\n\t\treturn new Scalar(bls12_381.fields.Fr.fromBytes(bytes));\n\t}\n\n\tstatic fromNumber(num: number): Scalar {\n\t\treturn new Scalar(BigInt(num));\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsB;AAGtB,uBAA0B;AAEnB,MAAM,aAAN,MAAM,WAAU;AAAA,EAKtB,YAAY,OAA8B;AACzC,SAAK,QAAQ;AAAA,EACd;AAAA,EAEA,OAAO,YAAuB;AAC7B,WAAO,IAAI,WAAU,2BAAU,GAAG,gBAAgB,IAAI;AAAA,EACvD;AAAA,EAEA,OAAO,UAAU,OAA8B;AAC9C,WAAO,IAAI,WAAU,2BAAU,GAAG,gBAAgB,YAAQ,kBAAM,KAAK,CAAC,CAAC;AAAA,EACxE;AAAA,EAEA,UAAsB;AACrB,WAAO,KAAK,MAAM,WAAW;AAAA,EAC9B;AAAA,EAEA,SAAS,QAA2B;AACnC,WAAO,IAAI,WAAU,KAAK,MAAM,SAAS,OAAO,MAAM,CAAC;AAAA,EACxD;AAAA,EAEA,IAAI,OAA6B;AAChC,WAAO,IAAI,WAAU,KAAK,MAAM,IAAI,MAAM,KAAK,CAAC;AAAA,EACjD;AAAA,EAEA,SAAS,OAA6B;AACrC,WAAO,IAAI,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10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G2Element } from './bls12381.js';
|
|
2
2
|
import type { DerivedKey, KeyServer } from './key-server.js';
|
|
3
|
-
import type {
|
|
4
|
-
import type { SealCompatibleClient } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for initializing a SealClient
|
|
7
|
-
* @property serverConfigs: Array of key server configs consisting of objectId, weight, optional API key name and API key.
|
|
8
|
-
* @property verifyKeyServers: Whether to verify the key servers' authenticity.
|
|
9
|
-
* Should be false if servers are pre-verified (e.g., getAllowlistedKeyServers).
|
|
10
|
-
* Defaults to true.
|
|
11
|
-
* @property timeout: Timeout in milliseconds for network requests. Defaults to 10 seconds.
|
|
12
|
-
*/
|
|
13
|
-
export interface SealClientExtensionOptions {
|
|
14
|
-
serverConfigs: KeyServerConfig[];
|
|
15
|
-
verifyKeyServers?: boolean;
|
|
16
|
-
timeout?: number;
|
|
17
|
-
}
|
|
18
|
-
export interface KeyServerConfig {
|
|
19
|
-
objectId: string;
|
|
20
|
-
weight: number;
|
|
21
|
-
apiKeyName?: string;
|
|
22
|
-
apiKey?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface SealClientOptions extends SealClientExtensionOptions {
|
|
25
|
-
suiClient: SealCompatibleClient;
|
|
26
|
-
}
|
|
3
|
+
import type { DecryptOptions, EncryptOptions, FetchKeysOptions, GetDerivedKeysOptions, SealClientExtensionOptions, SealClientOptions, SealCompatibleClient } from './types.js';
|
|
27
4
|
export declare class SealClient {
|
|
28
5
|
#private;
|
|
29
6
|
constructor(options: SealClientOptions);
|
|
30
|
-
static
|
|
7
|
+
static asClientExtension(options: SealClientExtensionOptions): {
|
|
31
8
|
name: "seal";
|
|
32
9
|
register: (client: SealCompatibleClient) => SealClient;
|
|
33
10
|
};
|
|
@@ -44,15 +21,7 @@ export declare class SealClient {
|
|
|
44
21
|
* @returns The bcs bytes of the encrypted object containing all metadata and the 256-bit symmetric key that was used to encrypt the object.
|
|
45
22
|
* Since the symmetric key can be used to decrypt, it should not be shared but can be used e.g. for backup.
|
|
46
23
|
*/
|
|
47
|
-
encrypt({ kemType, demType, threshold, packageId, id, data, aad, }: {
|
|
48
|
-
kemType?: KemType;
|
|
49
|
-
demType?: DemType;
|
|
50
|
-
threshold: number;
|
|
51
|
-
packageId: string;
|
|
52
|
-
id: string;
|
|
53
|
-
data: Uint8Array;
|
|
54
|
-
aad?: Uint8Array;
|
|
55
|
-
}): Promise<{
|
|
24
|
+
encrypt({ kemType, demType, threshold, packageId, id, data, aad, }: EncryptOptions): Promise<{
|
|
56
25
|
encryptedObject: Uint8Array;
|
|
57
26
|
key: Uint8Array;
|
|
58
27
|
}>;
|
|
@@ -62,17 +31,27 @@ export declare class SealClient {
|
|
|
62
31
|
* The function throws an error if the client's key servers are not a subset of
|
|
63
32
|
* the encrypted object's key servers or if the threshold cannot be met.
|
|
64
33
|
*
|
|
34
|
+
* If checkShareConsistency is true, the decrypted shares are checked for consistency, meaning that
|
|
35
|
+
* any combination of at least threshold shares should either succesfully combine to the plaintext or fail.
|
|
36
|
+
* This is useful in case the encryptor is not trusted and the decryptor wants to ensure all decryptors
|
|
37
|
+
* receive the same output (e.g., for onchain encrypted voting).
|
|
38
|
+
*
|
|
65
39
|
* @param data - The encrypted bytes to decrypt.
|
|
66
40
|
* @param sessionKey - The session key to use.
|
|
67
41
|
* @param txBytes - The transaction bytes to use (that calls seal_approve* functions).
|
|
42
|
+
* @param checkShareConsistency - If true, the shares are checked for consistency.
|
|
68
43
|
* @returns - The decrypted plaintext corresponding to ciphertext.
|
|
69
44
|
*/
|
|
70
|
-
decrypt({ data, sessionKey, txBytes, }:
|
|
71
|
-
data: Uint8Array;
|
|
72
|
-
sessionKey: SessionKey;
|
|
73
|
-
txBytes: Uint8Array;
|
|
74
|
-
}): Promise<Uint8Array<ArrayBufferLike>>;
|
|
45
|
+
decrypt({ data, sessionKey, txBytes, checkShareConsistency }: DecryptOptions): Promise<Uint8Array<ArrayBufferLike>>;
|
|
75
46
|
getKeyServers(): Promise<Map<string, KeyServer>>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the public keys for the given services.
|
|
49
|
+
* If all public keys are not in the cache, they are retrieved.
|
|
50
|
+
*
|
|
51
|
+
* @param services - The services to get the public keys for.
|
|
52
|
+
* @returns The public keys for the given services in the same order as the given services.
|
|
53
|
+
*/
|
|
54
|
+
getPublicKeys(services: string[]): Promise<G2Element[]>;
|
|
76
55
|
/**
|
|
77
56
|
* Fetch keys from the key servers and update the cache.
|
|
78
57
|
*
|
|
@@ -85,12 +64,7 @@ export declare class SealClient {
|
|
|
85
64
|
* @param sessionKey - The session key to use.
|
|
86
65
|
* @param threshold - The threshold for the TSS encryptions. The function returns when a threshold of key servers had returned keys for all ids.
|
|
87
66
|
*/
|
|
88
|
-
fetchKeys({ ids, txBytes, sessionKey, threshold
|
|
89
|
-
ids: string[];
|
|
90
|
-
txBytes: Uint8Array;
|
|
91
|
-
sessionKey: SessionKey;
|
|
92
|
-
threshold: number;
|
|
93
|
-
}): Promise<void>;
|
|
67
|
+
fetchKeys({ ids, txBytes, sessionKey, threshold }: FetchKeysOptions): Promise<void>;
|
|
94
68
|
/**
|
|
95
69
|
* Get derived keys from the given services.
|
|
96
70
|
*
|
|
@@ -100,11 +74,5 @@ export declare class SealClient {
|
|
|
100
74
|
* @param threshold - The threshold.
|
|
101
75
|
* @returns - Derived keys for the given services that are in the cache as a "service object ID" -> derived key map. If the call is succesful, exactly threshold keys will be returned.
|
|
102
76
|
*/
|
|
103
|
-
getDerivedKeys({ kemType, id, txBytes, sessionKey, threshold, }:
|
|
104
|
-
kemType?: KemType;
|
|
105
|
-
id: string;
|
|
106
|
-
txBytes: Uint8Array;
|
|
107
|
-
sessionKey: SessionKey;
|
|
108
|
-
threshold: number;
|
|
109
|
-
}): Promise<Map<string, DerivedKey>>;
|
|
77
|
+
getDerivedKeys({ kemType, id, txBytes, sessionKey, threshold, }: GetDerivedKeysOptions): Promise<Map<string, DerivedKey>>;
|
|
110
78
|
}
|
package/dist/cjs/client.js
CHANGED
|
@@ -37,9 +37,8 @@ var import_encrypt = require("./encrypt.js");
|
|
|
37
37
|
var import_error = require("./error.js");
|
|
38
38
|
var import_ibe = require("./ibe.js");
|
|
39
39
|
var import_key_server = require("./key-server.js");
|
|
40
|
-
var import_keys = require("./keys.js");
|
|
41
40
|
var import_utils = require("./utils.js");
|
|
42
|
-
var _suiClient, _configs, _keyServers, _verifyKeyServers, _cachedKeys, _timeout, _totalWeight, _SealClient_instances, createEncryptionInput_fn, weight_fn, validateEncryptionServices_fn, getWeightedKeyServers_fn, loadKeyServers_fn;
|
|
41
|
+
var _suiClient, _configs, _keyServers, _verifyKeyServers, _cachedKeys, _cachedPublicKeys, _timeout, _totalWeight, _SealClient_instances, createEncryptionInput_fn, weight_fn, validateEncryptionServices_fn, getWeightedKeyServers_fn, loadKeyServers_fn;
|
|
43
42
|
const _SealClient = class _SealClient {
|
|
44
43
|
constructor(options) {
|
|
45
44
|
__privateAdd(this, _SealClient_instances);
|
|
@@ -49,6 +48,7 @@ const _SealClient = class _SealClient {
|
|
|
49
48
|
__privateAdd(this, _verifyKeyServers);
|
|
50
49
|
// A caching map for: fullId:object_id -> partial key.
|
|
51
50
|
__privateAdd(this, _cachedKeys, /* @__PURE__ */ new Map());
|
|
51
|
+
__privateAdd(this, _cachedPublicKeys, /* @__PURE__ */ new Map());
|
|
52
52
|
__privateAdd(this, _timeout);
|
|
53
53
|
__privateAdd(this, _totalWeight);
|
|
54
54
|
__privateSet(this, _suiClient, options.suiClient);
|
|
@@ -65,7 +65,7 @@ const _SealClient = class _SealClient {
|
|
|
65
65
|
__privateSet(this, _verifyKeyServers, options.verifyKeyServers ?? true);
|
|
66
66
|
__privateSet(this, _timeout, options.timeout ?? 1e4);
|
|
67
67
|
}
|
|
68
|
-
static
|
|
68
|
+
static asClientExtension(options) {
|
|
69
69
|
return {
|
|
70
70
|
name: "seal",
|
|
71
71
|
register: (client) => {
|
|
@@ -117,16 +117,18 @@ const _SealClient = class _SealClient {
|
|
|
117
117
|
* The function throws an error if the client's key servers are not a subset of
|
|
118
118
|
* the encrypted object's key servers or if the threshold cannot be met.
|
|
119
119
|
*
|
|
120
|
+
* If checkShareConsistency is true, the decrypted shares are checked for consistency, meaning that
|
|
121
|
+
* any combination of at least threshold shares should either succesfully combine to the plaintext or fail.
|
|
122
|
+
* This is useful in case the encryptor is not trusted and the decryptor wants to ensure all decryptors
|
|
123
|
+
* receive the same output (e.g., for onchain encrypted voting).
|
|
124
|
+
*
|
|
120
125
|
* @param data - The encrypted bytes to decrypt.
|
|
121
126
|
* @param sessionKey - The session key to use.
|
|
122
127
|
* @param txBytes - The transaction bytes to use (that calls seal_approve* functions).
|
|
128
|
+
* @param checkShareConsistency - If true, the shares are checked for consistency.
|
|
123
129
|
* @returns - The decrypted plaintext corresponding to ciphertext.
|
|
124
130
|
*/
|
|
125
|
-
async decrypt({
|
|
126
|
-
data,
|
|
127
|
-
sessionKey,
|
|
128
|
-
txBytes
|
|
129
|
-
}) {
|
|
131
|
+
async decrypt({ data, sessionKey, txBytes, checkShareConsistency }) {
|
|
130
132
|
const encryptedObject = import_bcs.EncryptedObject.parse(data);
|
|
131
133
|
__privateMethod(this, _SealClient_instances, validateEncryptionServices_fn).call(this, encryptedObject.services.map((s) => s[0]), encryptedObject.threshold);
|
|
132
134
|
await this.fetchKeys({
|
|
@@ -135,6 +137,12 @@ const _SealClient = class _SealClient {
|
|
|
135
137
|
sessionKey,
|
|
136
138
|
threshold: encryptedObject.threshold
|
|
137
139
|
});
|
|
140
|
+
if (checkShareConsistency) {
|
|
141
|
+
const publicKeys = await this.getPublicKeys(
|
|
142
|
+
encryptedObject.services.map(([objectId, _]) => objectId)
|
|
143
|
+
);
|
|
144
|
+
return (0, import_decrypt.decrypt)({ encryptedObject, keys: __privateGet(this, _cachedKeys), publicKeys });
|
|
145
|
+
}
|
|
138
146
|
return (0, import_decrypt.decrypt)({ encryptedObject, keys: __privateGet(this, _cachedKeys) });
|
|
139
147
|
}
|
|
140
148
|
async getKeyServers() {
|
|
@@ -146,6 +154,34 @@ const _SealClient = class _SealClient {
|
|
|
146
154
|
}
|
|
147
155
|
return __privateGet(this, _keyServers);
|
|
148
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Get the public keys for the given services.
|
|
159
|
+
* If all public keys are not in the cache, they are retrieved.
|
|
160
|
+
*
|
|
161
|
+
* @param services - The services to get the public keys for.
|
|
162
|
+
* @returns The public keys for the given services in the same order as the given services.
|
|
163
|
+
*/
|
|
164
|
+
async getPublicKeys(services) {
|
|
165
|
+
const keyServers = await this.getKeyServers();
|
|
166
|
+
const missingKeyServers = services.filter(
|
|
167
|
+
(objectId) => !keyServers.has(objectId) && !__privateGet(this, _cachedPublicKeys).has(objectId)
|
|
168
|
+
);
|
|
169
|
+
if (missingKeyServers.length > 0) {
|
|
170
|
+
(await (0, import_key_server.retrieveKeyServers)({
|
|
171
|
+
objectIds: missingKeyServers,
|
|
172
|
+
client: __privateGet(this, _suiClient)
|
|
173
|
+
})).forEach(
|
|
174
|
+
(keyServer) => __privateGet(this, _cachedPublicKeys).set(keyServer.objectId, import_bls12381.G2Element.fromBytes(keyServer.pk))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return services.map((objectId) => {
|
|
178
|
+
const keyServer = keyServers.get(objectId);
|
|
179
|
+
if (keyServer) {
|
|
180
|
+
return import_bls12381.G2Element.fromBytes(keyServer.pk);
|
|
181
|
+
}
|
|
182
|
+
return __privateGet(this, _cachedPublicKeys).get(objectId);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
149
185
|
/**
|
|
150
186
|
* Fetch keys from the key servers and update the cache.
|
|
151
187
|
*
|
|
@@ -158,12 +194,7 @@ const _SealClient = class _SealClient {
|
|
|
158
194
|
* @param sessionKey - The session key to use.
|
|
159
195
|
* @param threshold - The threshold for the TSS encryptions. The function returns when a threshold of key servers had returned keys for all ids.
|
|
160
196
|
*/
|
|
161
|
-
async fetchKeys({
|
|
162
|
-
ids,
|
|
163
|
-
txBytes,
|
|
164
|
-
sessionKey,
|
|
165
|
-
threshold
|
|
166
|
-
}) {
|
|
197
|
+
async fetchKeys({ ids, txBytes, sessionKey, threshold }) {
|
|
167
198
|
if (threshold > __privateGet(this, _totalWeight) || threshold < 1) {
|
|
168
199
|
throw new import_error.InvalidThresholdError(
|
|
169
200
|
`Invalid threshold ${threshold} servers with weights ${__privateGet(this, _configs)}`
|
|
@@ -185,15 +216,7 @@ const _SealClient = class _SealClient {
|
|
|
185
216
|
if (completedWeight >= threshold) {
|
|
186
217
|
return;
|
|
187
218
|
}
|
|
188
|
-
|
|
189
|
-
const server = keyServers.get(objectId);
|
|
190
|
-
if (server.keyType !== import_key_server.KeyServerType.BonehFranklinBLS12381) {
|
|
191
|
-
throw new import_error.InvalidKeyServerError(
|
|
192
|
-
`Server ${server.objectId} has invalid key type: ${server.keyType}`
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const cert = await sessionKey.getCertificate();
|
|
219
|
+
const certificate = await sessionKey.getCertificate();
|
|
197
220
|
const signedRequest = await sessionKey.createRequestParams(txBytes);
|
|
198
221
|
const controller = new AbortController();
|
|
199
222
|
const errors = [];
|
|
@@ -201,17 +224,19 @@ const _SealClient = class _SealClient {
|
|
|
201
224
|
const server = keyServers.get(objectId);
|
|
202
225
|
try {
|
|
203
226
|
const config = __privateGet(this, _configs).get(objectId);
|
|
204
|
-
const allKeys = await (0,
|
|
205
|
-
server.url,
|
|
206
|
-
signedRequest.requestSignature,
|
|
207
|
-
txBytes,
|
|
208
|
-
signedRequest.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
227
|
+
const allKeys = await (0, import_key_server.fetchKeysForAllIds)({
|
|
228
|
+
url: server.url,
|
|
229
|
+
requestSignature: signedRequest.requestSignature,
|
|
230
|
+
transactionBytes: txBytes,
|
|
231
|
+
encKey: signedRequest.encKey,
|
|
232
|
+
encKeyPk: signedRequest.encKeyPk,
|
|
233
|
+
encVerificationKey: signedRequest.encVerificationKey,
|
|
234
|
+
certificate,
|
|
235
|
+
timeout: __privateGet(this, _timeout),
|
|
236
|
+
apiKeyName: config?.apiKeyName,
|
|
237
|
+
apiKey: config?.apiKey,
|
|
238
|
+
signal: controller.signal
|
|
239
|
+
});
|
|
215
240
|
for (const { fullId, key } of allKeys) {
|
|
216
241
|
const keyElement = import_bls12381.G1Element.fromBytes(key);
|
|
217
242
|
if (!import_ibe.BonehFranklinBLS12381Services.verifyUserSecretKey(
|
|
@@ -298,6 +323,7 @@ _configs = new WeakMap();
|
|
|
298
323
|
_keyServers = new WeakMap();
|
|
299
324
|
_verifyKeyServers = new WeakMap();
|
|
300
325
|
_cachedKeys = new WeakMap();
|
|
326
|
+
_cachedPublicKeys = new WeakMap();
|
|
301
327
|
_timeout = new WeakMap();
|
|
302
328
|
_totalWeight = new WeakMap();
|
|
303
329
|
_SealClient_instances = new WeakSet();
|