@mysten/seal 0.4.2 → 0.4.4
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 +20 -0
- package/dist/cjs/bls12381.d.ts +5 -0
- package/dist/cjs/bls12381.js +38 -23
- package/dist/cjs/bls12381.js.map +2 -2
- package/dist/cjs/client.d.ts +21 -6
- package/dist/cjs/client.js +111 -55
- package/dist/cjs/client.js.map +2 -2
- package/dist/cjs/decrypt.js +7 -20
- package/dist/cjs/decrypt.js.map +2 -2
- package/dist/cjs/dem.js +20 -16
- package/dist/cjs/dem.js.map +2 -2
- package/dist/cjs/elgamal.d.ts +1 -1
- package/dist/cjs/elgamal.js +5 -5
- package/dist/cjs/elgamal.js.map +2 -2
- package/dist/cjs/encrypt.js +14 -16
- package/dist/cjs/encrypt.js.map +2 -2
- package/dist/cjs/error.d.ts +6 -0
- package/dist/cjs/error.js +9 -0
- package/dist/cjs/error.js.map +2 -2
- package/dist/cjs/ibe.d.ts +3 -1
- package/dist/cjs/ibe.js +4 -4
- package/dist/cjs/ibe.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/kdf.js +6 -16
- package/dist/cjs/kdf.js.map +2 -2
- package/dist/cjs/key-server.d.ts +14 -0
- package/dist/cjs/key-server.js +11 -1
- package/dist/cjs/key-server.js.map +2 -2
- package/dist/cjs/keys.js +1 -1
- package/dist/cjs/keys.js.map +2 -2
- package/dist/cjs/session-key.d.ts +5 -2
- package/dist/cjs/session-key.js +10 -8
- package/dist/cjs/session-key.js.map +2 -2
- package/dist/cjs/utils.d.ts +9 -0
- package/dist/cjs/utils.js +16 -8
- package/dist/cjs/utils.js.map +3 -3
- 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/bls12381.d.ts +5 -0
- package/dist/esm/bls12381.js +38 -23
- package/dist/esm/bls12381.js.map +2 -2
- package/dist/esm/client.d.ts +21 -6
- package/dist/esm/client.js +121 -58
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/decrypt.js +8 -21
- package/dist/esm/decrypt.js.map +2 -2
- package/dist/esm/dem.js +22 -18
- package/dist/esm/dem.js.map +2 -2
- package/dist/esm/elgamal.d.ts +1 -1
- package/dist/esm/elgamal.js +5 -5
- package/dist/esm/elgamal.js.map +2 -2
- package/dist/esm/encrypt.js +14 -16
- package/dist/esm/encrypt.js.map +2 -2
- package/dist/esm/error.d.ts +6 -0
- package/dist/esm/error.js +9 -0
- package/dist/esm/error.js.map +2 -2
- package/dist/esm/ibe.d.ts +3 -1
- package/dist/esm/ibe.js +4 -4
- package/dist/esm/ibe.js.map +2 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/kdf.js +6 -16
- package/dist/esm/kdf.js.map +2 -2
- package/dist/esm/key-server.d.ts +14 -0
- package/dist/esm/key-server.js +13 -3
- package/dist/esm/key-server.js.map +2 -2
- package/dist/esm/keys.js +1 -1
- package/dist/esm/keys.js.map +2 -2
- package/dist/esm/session-key.d.ts +5 -2
- package/dist/esm/session-key.js +10 -8
- package/dist/esm/session-key.js.map +2 -2
- package/dist/esm/utils.d.ts +9 -0
- package/dist/esm/utils.js +16 -8
- package/dist/esm/utils.js.map +3 -3
- 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 +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mysten/seal
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ee1bfd8: Better handling of weighted/duplicate key servers.
|
|
8
|
+
- 5264038: expose ZkLoginCompatibleClient, use ZkLoginCompatibleClient for SessionKey constructor
|
|
9
|
+
- Updated dependencies [2456052]
|
|
10
|
+
- Updated dependencies [5264038]
|
|
11
|
+
- Updated dependencies [2456052]
|
|
12
|
+
- Updated dependencies [2456052]
|
|
13
|
+
- Updated dependencies [2456052]
|
|
14
|
+
- Updated dependencies [2456052]
|
|
15
|
+
- @mysten/sui@1.30.0
|
|
16
|
+
|
|
17
|
+
## 0.4.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- d3f0e8d: Export SessionKeyType
|
|
22
|
+
|
|
3
23
|
## 0.4.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/cjs/bls12381.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Fp2, Fp12 } from '@noble/curves/abstract/tower';
|
|
|
2
2
|
import type { ProjPointType } from '@noble/curves/abstract/weierstrass';
|
|
3
3
|
export declare class G1Element {
|
|
4
4
|
point: ProjPointType<bigint>;
|
|
5
|
+
static readonly SIZE = 48;
|
|
5
6
|
constructor(point: ProjPointType<bigint>);
|
|
6
7
|
static generator(): G1Element;
|
|
7
8
|
static fromBytes(bytes: Uint8Array): G1Element;
|
|
@@ -14,6 +15,7 @@ export declare class G1Element {
|
|
|
14
15
|
}
|
|
15
16
|
export declare class G2Element {
|
|
16
17
|
point: ProjPointType<Fp2>;
|
|
18
|
+
static readonly SIZE = 96;
|
|
17
19
|
constructor(point: ProjPointType<Fp2>);
|
|
18
20
|
static generator(): G2Element;
|
|
19
21
|
static fromBytes(bytes: Uint8Array): G2Element;
|
|
@@ -24,11 +26,14 @@ export declare class G2Element {
|
|
|
24
26
|
}
|
|
25
27
|
export declare class GTElement {
|
|
26
28
|
element: Fp12;
|
|
29
|
+
static readonly SIZE = 576;
|
|
27
30
|
constructor(element: Fp12);
|
|
28
31
|
toBytes(): Uint8Array;
|
|
32
|
+
equals(other: GTElement): boolean;
|
|
29
33
|
}
|
|
30
34
|
export declare class Scalar {
|
|
31
35
|
scalar: bigint;
|
|
36
|
+
static readonly SIZE = 32;
|
|
32
37
|
constructor(scalar: bigint);
|
|
33
38
|
static random(): Scalar;
|
|
34
39
|
toBytes(): Uint8Array;
|
package/dist/cjs/bls12381.js
CHANGED
|
@@ -26,85 +26,100 @@ __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
|
-
|
|
29
|
+
var import_utils = require("./utils.js");
|
|
30
|
+
const _G1Element = class _G1Element {
|
|
30
31
|
constructor(point) {
|
|
31
32
|
this.point = point;
|
|
32
33
|
}
|
|
33
34
|
static generator() {
|
|
34
|
-
return new
|
|
35
|
+
return new _G1Element(import_bls12_381.bls12_381.G1.ProjectivePoint.BASE);
|
|
35
36
|
}
|
|
36
37
|
static fromBytes(bytes) {
|
|
37
|
-
return new
|
|
38
|
+
return new _G1Element(import_bls12_381.bls12_381.G1.ProjectivePoint.fromHex((0, import_bcs.toHex)(bytes)));
|
|
38
39
|
}
|
|
39
40
|
toBytes() {
|
|
40
41
|
return this.point.toRawBytes();
|
|
41
42
|
}
|
|
42
43
|
multiply(scalar) {
|
|
43
|
-
return new
|
|
44
|
+
return new _G1Element(this.point.multiply(scalar.scalar));
|
|
44
45
|
}
|
|
45
46
|
add(other) {
|
|
46
|
-
return new
|
|
47
|
+
return new _G1Element(this.point.add(other.point));
|
|
47
48
|
}
|
|
48
49
|
subtract(other) {
|
|
49
|
-
return new
|
|
50
|
+
return new _G1Element(this.point.subtract(other.point));
|
|
50
51
|
}
|
|
51
52
|
static hashToCurve(data) {
|
|
52
|
-
return new
|
|
53
|
+
return new _G1Element(
|
|
53
54
|
import_bls12_381.bls12_381.G1.ProjectivePoint.fromAffine(import_bls12_381.bls12_381.G1.hashToCurve(data).toAffine())
|
|
54
55
|
);
|
|
55
56
|
}
|
|
56
57
|
pairing(other) {
|
|
57
58
|
return new GTElement(import_bls12_381.bls12_381.pairing(this.point, other.point));
|
|
58
59
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
60
|
+
};
|
|
61
|
+
_G1Element.SIZE = 48;
|
|
62
|
+
let G1Element = _G1Element;
|
|
63
|
+
const _G2Element = class _G2Element {
|
|
61
64
|
constructor(point) {
|
|
62
65
|
this.point = point;
|
|
63
66
|
}
|
|
64
67
|
static generator() {
|
|
65
|
-
return new
|
|
68
|
+
return new _G2Element(import_bls12_381.bls12_381.G2.ProjectivePoint.BASE);
|
|
66
69
|
}
|
|
67
70
|
static fromBytes(bytes) {
|
|
68
|
-
return new
|
|
71
|
+
return new _G2Element(import_bls12_381.bls12_381.G2.ProjectivePoint.fromHex((0, import_bcs.toHex)(bytes)));
|
|
69
72
|
}
|
|
70
73
|
toBytes() {
|
|
71
74
|
return this.point.toRawBytes();
|
|
72
75
|
}
|
|
73
76
|
multiply(scalar) {
|
|
74
|
-
return new
|
|
77
|
+
return new _G2Element(this.point.multiply(scalar.scalar));
|
|
75
78
|
}
|
|
76
79
|
add(other) {
|
|
77
|
-
return new
|
|
80
|
+
return new _G2Element(this.point.add(other.point));
|
|
78
81
|
}
|
|
79
82
|
hashToCurve(data) {
|
|
80
|
-
return new
|
|
83
|
+
return new _G2Element(
|
|
81
84
|
import_bls12_381.bls12_381.G2.ProjectivePoint.fromAffine(import_bls12_381.bls12_381.G2.hashToCurve(data).toAffine())
|
|
82
85
|
);
|
|
83
86
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
87
|
+
};
|
|
88
|
+
_G2Element.SIZE = 96;
|
|
89
|
+
let G2Element = _G2Element;
|
|
90
|
+
const _GTElement = class _GTElement {
|
|
86
91
|
constructor(element) {
|
|
87
92
|
this.element = element;
|
|
88
93
|
}
|
|
89
94
|
toBytes() {
|
|
90
|
-
|
|
95
|
+
const P = [0, 3, 1, 4, 2, 5];
|
|
96
|
+
const PAIR_SIZE = _GTElement.SIZE / P.length;
|
|
97
|
+
const bytes = import_bls12_381.bls12_381.fields.Fp12.toBytes(this.element);
|
|
98
|
+
return (0, import_utils.flatten)(P.map((p) => bytes.subarray(p * PAIR_SIZE, (p + 1) * PAIR_SIZE)));
|
|
99
|
+
}
|
|
100
|
+
equals(other) {
|
|
101
|
+
return import_bls12_381.bls12_381.fields.Fp12.eql(this.element, other.element);
|
|
91
102
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
103
|
+
};
|
|
104
|
+
_GTElement.SIZE = 576;
|
|
105
|
+
let GTElement = _GTElement;
|
|
106
|
+
const _Scalar = class _Scalar {
|
|
94
107
|
constructor(scalar) {
|
|
95
108
|
this.scalar = scalar;
|
|
96
109
|
}
|
|
97
110
|
static random() {
|
|
98
|
-
return
|
|
111
|
+
return _Scalar.fromBytes(import_bls12_381.bls12_381.utils.randomPrivateKey());
|
|
99
112
|
}
|
|
100
113
|
toBytes() {
|
|
101
114
|
return new Uint8Array(import_bls12_381.bls12_381.fields.Fr.toBytes(this.scalar));
|
|
102
115
|
}
|
|
103
116
|
static fromBytes(bytes) {
|
|
104
|
-
return new
|
|
117
|
+
return new _Scalar(import_bls12_381.bls12_381.fields.Fr.fromBytes(bytes));
|
|
105
118
|
}
|
|
106
119
|
static fromNumber(num) {
|
|
107
|
-
return new
|
|
120
|
+
return new _Scalar(BigInt(num));
|
|
108
121
|
}
|
|
109
|
-
}
|
|
122
|
+
};
|
|
123
|
+
_Scalar.SIZE = 32;
|
|
124
|
+
let Scalar = _Scalar;
|
|
110
125
|
//# sourceMappingURL=bls12381.js.map
|
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';\n\nexport class G1Element {\n\tpoint: ProjPointType<bigint>;\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\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\thashToCurve(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\nexport class GTElement {\n\telement: Fp12;\n\n\tconstructor(element: Fp12) {\n\t\tthis.element = element;\n\t}\n\n\ttoBytes(): Uint8Array {\n\t\
|
|
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';\nimport { flatten } from './utils.js';\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\thashToCurve(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\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\treturn flatten(P.map((p) => bytes.subarray(p * PAIR_SIZE, (p + 1) * PAIR_SIZE)));\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": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DemType, KemType } from './encrypt.js';
|
|
2
|
-
import type { KeyServer } from './key-server.js';
|
|
2
|
+
import type { DerivedKey, KeyServer } from './key-server.js';
|
|
3
3
|
import type { SessionKey } from './session-key.js';
|
|
4
4
|
import type { SealCompatibleClient } from './types.js';
|
|
5
5
|
/**
|
|
@@ -11,7 +11,7 @@ import type { SealCompatibleClient } from './types.js';
|
|
|
11
11
|
* @property timeout: Timeout in milliseconds for network requests. Defaults to 10 seconds.
|
|
12
12
|
*/
|
|
13
13
|
export interface SealClientExtensionOptions {
|
|
14
|
-
serverObjectIds: string[];
|
|
14
|
+
serverObjectIds: [string, number][];
|
|
15
15
|
verifyKeyServers?: boolean;
|
|
16
16
|
timeout?: number;
|
|
17
17
|
}
|
|
@@ -54,8 +54,7 @@ export declare class SealClient {
|
|
|
54
54
|
* Decrypt the given encrypted bytes using cached keys.
|
|
55
55
|
* Calls fetchKeys in case one or more of the required keys is not cached yet.
|
|
56
56
|
* The function throws an error if the client's key servers are not a subset of
|
|
57
|
-
* the encrypted object's key servers
|
|
58
|
-
* threshold cannot be met.
|
|
57
|
+
* the encrypted object's key servers or if the threshold cannot be met.
|
|
59
58
|
*
|
|
60
59
|
* @param data - The encrypted bytes to decrypt.
|
|
61
60
|
* @param sessionKey - The session key to use.
|
|
@@ -67,11 +66,11 @@ export declare class SealClient {
|
|
|
67
66
|
sessionKey: SessionKey;
|
|
68
67
|
txBytes: Uint8Array;
|
|
69
68
|
}): Promise<Uint8Array<ArrayBufferLike>>;
|
|
70
|
-
getKeyServers(): Promise<KeyServer
|
|
69
|
+
getKeyServers(): Promise<Map<string, KeyServer>>;
|
|
71
70
|
/**
|
|
72
71
|
* Fetch keys from the key servers and update the cache.
|
|
73
72
|
*
|
|
74
|
-
* It is recommended to call this function once for all ids of all encrypted
|
|
73
|
+
* It is recommended to call this function once for all ids of all encrypted objects if
|
|
75
74
|
* there are multiple, then call decrypt for each object. This avoids calling fetchKey
|
|
76
75
|
* individually for each decrypt.
|
|
77
76
|
*
|
|
@@ -86,4 +85,20 @@ export declare class SealClient {
|
|
|
86
85
|
sessionKey: SessionKey;
|
|
87
86
|
threshold: number;
|
|
88
87
|
}): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Get derived keys from the given services.
|
|
90
|
+
*
|
|
91
|
+
* @param id - The id of the encrypted object.
|
|
92
|
+
* @param txBytes - The transaction bytes to use (that calls seal_approve* functions).
|
|
93
|
+
* @param sessionKey - The session key to use.
|
|
94
|
+
* @param threshold - The threshold.
|
|
95
|
+
* @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.
|
|
96
|
+
*/
|
|
97
|
+
getDerivedKeys({ kemType, id, txBytes, sessionKey, threshold, }: {
|
|
98
|
+
kemType?: KemType;
|
|
99
|
+
id: string;
|
|
100
|
+
txBytes: Uint8Array;
|
|
101
|
+
sessionKey: SessionKey;
|
|
102
|
+
threshold: number;
|
|
103
|
+
}): Promise<Map<string, DerivedKey>>;
|
|
89
104
|
}
|
package/dist/cjs/client.js
CHANGED
|
@@ -39,19 +39,24 @@ var import_ibe = require("./ibe.js");
|
|
|
39
39
|
var import_key_server = require("./key-server.js");
|
|
40
40
|
var import_keys = require("./keys.js");
|
|
41
41
|
var import_utils = require("./utils.js");
|
|
42
|
-
var _suiClient,
|
|
42
|
+
var _suiClient, _weights, _keyServers, _verifyKeyServers, _cachedKeys, _timeout, _totalWeight, _SealClient_instances, createEncryptionInput_fn, weight_fn, validateEncryptionServices_fn, getWeightedKeyServers_fn, loadKeyServers_fn;
|
|
43
43
|
const _SealClient = class _SealClient {
|
|
44
44
|
constructor(options) {
|
|
45
45
|
__privateAdd(this, _SealClient_instances);
|
|
46
46
|
__privateAdd(this, _suiClient);
|
|
47
|
-
__privateAdd(this,
|
|
48
|
-
__privateAdd(this, _verifyKeyServers);
|
|
47
|
+
__privateAdd(this, _weights);
|
|
49
48
|
__privateAdd(this, _keyServers, null);
|
|
49
|
+
__privateAdd(this, _verifyKeyServers);
|
|
50
50
|
// A caching map for: fullId:object_id -> partial key.
|
|
51
51
|
__privateAdd(this, _cachedKeys, /* @__PURE__ */ new Map());
|
|
52
52
|
__privateAdd(this, _timeout);
|
|
53
|
+
__privateAdd(this, _totalWeight);
|
|
53
54
|
__privateSet(this, _suiClient, options.suiClient);
|
|
54
|
-
|
|
55
|
+
if (new Set(options.serverObjectIds.map(([objectId, _]) => objectId)).size !== options.serverObjectIds.length) {
|
|
56
|
+
throw new import_error.InvalidClientOptionsError("Duplicate object IDs");
|
|
57
|
+
}
|
|
58
|
+
__privateSet(this, _weights, new Map(options.serverObjectIds));
|
|
59
|
+
__privateSet(this, _totalWeight, options.serverObjectIds.map(([_, weight]) => weight).reduce((sum, term) => sum + term, 0));
|
|
55
60
|
__privateSet(this, _verifyKeyServers, options.verifyKeyServers ?? true);
|
|
56
61
|
__privateSet(this, _timeout, options.timeout ?? 1e4);
|
|
57
62
|
}
|
|
@@ -89,7 +94,7 @@ const _SealClient = class _SealClient {
|
|
|
89
94
|
aad = new Uint8Array()
|
|
90
95
|
}) {
|
|
91
96
|
return (0, import_encrypt.encrypt)({
|
|
92
|
-
keyServers: await this.
|
|
97
|
+
keyServers: await __privateMethod(this, _SealClient_instances, getWeightedKeyServers_fn).call(this),
|
|
93
98
|
kemType,
|
|
94
99
|
threshold,
|
|
95
100
|
packageId,
|
|
@@ -101,8 +106,7 @@ const _SealClient = class _SealClient {
|
|
|
101
106
|
* Decrypt the given encrypted bytes using cached keys.
|
|
102
107
|
* Calls fetchKeys in case one or more of the required keys is not cached yet.
|
|
103
108
|
* The function throws an error if the client's key servers are not a subset of
|
|
104
|
-
* the encrypted object's key servers
|
|
105
|
-
* threshold cannot be met.
|
|
109
|
+
* the encrypted object's key servers or if the threshold cannot be met.
|
|
106
110
|
*
|
|
107
111
|
* @param data - The encrypted bytes to decrypt.
|
|
108
112
|
* @param sessionKey - The session key to use.
|
|
@@ -136,7 +140,7 @@ const _SealClient = class _SealClient {
|
|
|
136
140
|
/**
|
|
137
141
|
* Fetch keys from the key servers and update the cache.
|
|
138
142
|
*
|
|
139
|
-
* It is recommended to call this function once for all ids of all encrypted
|
|
143
|
+
* It is recommended to call this function once for all ids of all encrypted objects if
|
|
140
144
|
* there are multiple, then call decrypt for each object. This avoids calling fetchKey
|
|
141
145
|
* individually for each decrypt.
|
|
142
146
|
*
|
|
@@ -151,32 +155,29 @@ const _SealClient = class _SealClient {
|
|
|
151
155
|
sessionKey,
|
|
152
156
|
threshold
|
|
153
157
|
}) {
|
|
154
|
-
|
|
155
|
-
if (threshold > keyServers.length || threshold < 1 || keyServers.length < 1) {
|
|
158
|
+
if (threshold > __privateGet(this, _totalWeight) || threshold < 1) {
|
|
156
159
|
throw new import_error.InvalidThresholdError(
|
|
157
|
-
`Invalid threshold ${threshold}
|
|
160
|
+
`Invalid threshold ${threshold} servers with weights ${__privateGet(this, _weights)}`
|
|
158
161
|
);
|
|
159
162
|
}
|
|
160
|
-
|
|
161
|
-
const remainingKeyServers = /* @__PURE__ */ new Set();
|
|
163
|
+
const keyServers = await this.getKeyServers();
|
|
162
164
|
const fullIds = ids.map((id) => (0, import_utils.createFullId)(import_ibe.DST, sessionKey.getPackageId(), id));
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (hasAllKeys) {
|
|
173
|
-
completedServerCount++;
|
|
165
|
+
let completedWeight = 0;
|
|
166
|
+
const remainingKeyServers = [];
|
|
167
|
+
let remainingKeyServersWeight = 0;
|
|
168
|
+
for (const objectId of keyServers.keys()) {
|
|
169
|
+
if (fullIds.every((fullId) => __privateGet(this, _cachedKeys).has(`${fullId}:${objectId}`))) {
|
|
170
|
+
completedWeight += __privateMethod(this, _SealClient_instances, weight_fn).call(this, objectId);
|
|
171
|
+
} else {
|
|
172
|
+
remainingKeyServers.push(objectId);
|
|
173
|
+
remainingKeyServersWeight += __privateMethod(this, _SealClient_instances, weight_fn).call(this, objectId);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
if (
|
|
176
|
+
if (completedWeight >= threshold) {
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
|
-
for (const
|
|
179
|
+
for (const objectId of remainingKeyServers) {
|
|
180
|
+
const server = keyServers.get(objectId);
|
|
180
181
|
if (server.keyType !== import_key_server.KeyServerType.BonehFranklinBLS12381) {
|
|
181
182
|
throw new import_error.InvalidKeyServerError(
|
|
182
183
|
`Server ${server.objectId} has invalid key type: ${server.keyType}`
|
|
@@ -187,7 +188,8 @@ const _SealClient = class _SealClient {
|
|
|
187
188
|
const signedRequest = await sessionKey.createRequestParams(txBytes);
|
|
188
189
|
const controller = new AbortController();
|
|
189
190
|
const errors = [];
|
|
190
|
-
const keyFetches =
|
|
191
|
+
const keyFetches = remainingKeyServers.map(async (objectId) => {
|
|
192
|
+
const server = keyServers.get(objectId);
|
|
191
193
|
try {
|
|
192
194
|
const allKeys = await (0, import_keys.fetchKeysForAllIds)(
|
|
193
195
|
server.url,
|
|
@@ -212,11 +214,9 @@ const _SealClient = class _SealClient {
|
|
|
212
214
|
__privateGet(this, _cachedKeys).set(`${fullId}:${server.objectId}`, keyElement);
|
|
213
215
|
receivedIds.add(fullId);
|
|
214
216
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
completedServerCount++;
|
|
219
|
-
if (completedServerCount >= threshold) {
|
|
217
|
+
if (fullIds.every((fullId) => receivedIds.has(fullId))) {
|
|
218
|
+
completedWeight += __privateMethod(this, _SealClient_instances, weight_fn).call(this, objectId);
|
|
219
|
+
if (completedWeight >= threshold) {
|
|
220
220
|
controller.abort();
|
|
221
221
|
}
|
|
222
222
|
}
|
|
@@ -224,23 +224,72 @@ const _SealClient = class _SealClient {
|
|
|
224
224
|
if (!controller.signal.aborted) {
|
|
225
225
|
errors.push(error);
|
|
226
226
|
}
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
} finally {
|
|
228
|
+
remainingKeyServersWeight -= __privateMethod(this, _SealClient_instances, weight_fn).call(this, objectId);
|
|
229
|
+
if (remainingKeyServersWeight < threshold - completedWeight) {
|
|
230
|
+
controller.abort(new import_error.TooManyFailedFetchKeyRequestsError());
|
|
229
231
|
}
|
|
230
232
|
}
|
|
231
233
|
});
|
|
232
234
|
await Promise.allSettled(keyFetches);
|
|
233
|
-
if (
|
|
235
|
+
if (completedWeight < threshold) {
|
|
234
236
|
throw (0, import_error.toMajorityError)(errors);
|
|
235
237
|
}
|
|
236
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Get derived keys from the given services.
|
|
241
|
+
*
|
|
242
|
+
* @param id - The id of the encrypted object.
|
|
243
|
+
* @param txBytes - The transaction bytes to use (that calls seal_approve* functions).
|
|
244
|
+
* @param sessionKey - The session key to use.
|
|
245
|
+
* @param threshold - The threshold.
|
|
246
|
+
* @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.
|
|
247
|
+
*/
|
|
248
|
+
async getDerivedKeys({
|
|
249
|
+
kemType = import_encrypt.KemType.BonehFranklinBLS12381DemCCA,
|
|
250
|
+
id,
|
|
251
|
+
txBytes,
|
|
252
|
+
sessionKey,
|
|
253
|
+
threshold
|
|
254
|
+
}) {
|
|
255
|
+
switch (kemType) {
|
|
256
|
+
case import_encrypt.KemType.BonehFranklinBLS12381DemCCA:
|
|
257
|
+
const keyServers = await this.getKeyServers();
|
|
258
|
+
if (threshold > __privateGet(this, _totalWeight)) {
|
|
259
|
+
throw new import_error.InvalidThresholdError(
|
|
260
|
+
`Invalid threshold ${threshold} for ${__privateGet(this, _totalWeight)} servers`
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
await this.fetchKeys({
|
|
264
|
+
ids: [id],
|
|
265
|
+
txBytes,
|
|
266
|
+
sessionKey,
|
|
267
|
+
threshold
|
|
268
|
+
});
|
|
269
|
+
const fullId = (0, import_utils.createFullId)(import_ibe.DST, sessionKey.getPackageId(), id);
|
|
270
|
+
const derivedKeys = /* @__PURE__ */ new Map();
|
|
271
|
+
let weight = 0;
|
|
272
|
+
for (const objectId of keyServers.keys()) {
|
|
273
|
+
const cachedKey = __privateGet(this, _cachedKeys).get(`${fullId}:${objectId}`);
|
|
274
|
+
if (cachedKey) {
|
|
275
|
+
derivedKeys.set(objectId, new import_key_server.BonehFranklinBLS12381DerivedKey(cachedKey));
|
|
276
|
+
weight += __privateMethod(this, _SealClient_instances, weight_fn).call(this, objectId);
|
|
277
|
+
if (weight >= threshold) {
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return derivedKeys;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
237
285
|
};
|
|
238
286
|
_suiClient = new WeakMap();
|
|
239
|
-
|
|
240
|
-
_verifyKeyServers = new WeakMap();
|
|
287
|
+
_weights = new WeakMap();
|
|
241
288
|
_keyServers = new WeakMap();
|
|
289
|
+
_verifyKeyServers = new WeakMap();
|
|
242
290
|
_cachedKeys = new WeakMap();
|
|
243
291
|
_timeout = new WeakMap();
|
|
292
|
+
_totalWeight = new WeakMap();
|
|
244
293
|
_SealClient_instances = new WeakSet();
|
|
245
294
|
createEncryptionInput_fn = function(type, data, aad) {
|
|
246
295
|
switch (type) {
|
|
@@ -250,31 +299,38 @@ createEncryptionInput_fn = function(type, data, aad) {
|
|
|
250
299
|
return new import_dem.Hmac256Ctr(data, aad);
|
|
251
300
|
}
|
|
252
301
|
};
|
|
302
|
+
weight_fn = function(objectId) {
|
|
303
|
+
return __privateGet(this, _weights).get(objectId) ?? 0;
|
|
304
|
+
};
|
|
253
305
|
validateEncryptionServices_fn = function(services, threshold) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
for (const [objectId, count] of serverObjectIdsMap) {
|
|
263
|
-
if (servicesMap.get(objectId) !== count) {
|
|
264
|
-
throw new import_error.InconsistentKeyServersError(
|
|
265
|
-
`Client's key servers must be a subset of the encrypted object's key servers`
|
|
266
|
-
);
|
|
267
|
-
}
|
|
306
|
+
if (services.some((objectId) => {
|
|
307
|
+
const countInClient = __privateMethod(this, _SealClient_instances, weight_fn).call(this, objectId);
|
|
308
|
+
return countInClient > 0 && countInClient !== (0, import_utils.count)(services, objectId);
|
|
309
|
+
})) {
|
|
310
|
+
throw new import_error.InconsistentKeyServersError(
|
|
311
|
+
`Client's key servers must be a subset of the encrypted object's key servers`
|
|
312
|
+
);
|
|
268
313
|
}
|
|
269
|
-
if (threshold > __privateGet(this,
|
|
314
|
+
if (threshold > __privateGet(this, _totalWeight)) {
|
|
270
315
|
throw new import_error.InvalidThresholdError(
|
|
271
|
-
`Invalid threshold ${threshold} for ${__privateGet(this,
|
|
316
|
+
`Invalid threshold ${threshold} for ${__privateGet(this, _totalWeight)} servers`
|
|
272
317
|
);
|
|
273
318
|
}
|
|
274
319
|
};
|
|
320
|
+
getWeightedKeyServers_fn = async function() {
|
|
321
|
+
const keyServers = await this.getKeyServers();
|
|
322
|
+
const keyServersWithMultiplicity = [];
|
|
323
|
+
for (const [objectId, weight] of __privateGet(this, _weights)) {
|
|
324
|
+
const keyServer = keyServers.get(objectId);
|
|
325
|
+
for (let i = 0; i < weight; i++) {
|
|
326
|
+
keyServersWithMultiplicity.push(keyServer);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return keyServersWithMultiplicity;
|
|
330
|
+
};
|
|
275
331
|
loadKeyServers_fn = async function() {
|
|
276
332
|
const keyServers = await (0, import_key_server.retrieveKeyServers)({
|
|
277
|
-
objectIds: __privateGet(this,
|
|
333
|
+
objectIds: [...__privateGet(this, _weights)].map(([objectId]) => objectId),
|
|
278
334
|
client: __privateGet(this, _suiClient)
|
|
279
335
|
});
|
|
280
336
|
if (keyServers.length === 0) {
|
|
@@ -289,7 +345,7 @@ loadKeyServers_fn = async function() {
|
|
|
289
345
|
})
|
|
290
346
|
);
|
|
291
347
|
}
|
|
292
|
-
return keyServers;
|
|
348
|
+
return new Map(keyServers.map((server) => [server.objectId, server]));
|
|
293
349
|
};
|
|
294
350
|
let SealClient = _SealClient;
|
|
295
351
|
//# sourceMappingURL=client.js.map
|