@mysten/seal 0.4.18 → 0.4.20
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/bls12381.d.ts +1 -1
- package/dist/cjs/bls12381.js +1 -1
- package/dist/cjs/bls12381.js.map +2 -2
- package/dist/cjs/decrypt.d.ts +1 -0
- package/dist/cjs/decrypt.js.map +2 -2
- package/dist/cjs/dem.d.ts +0 -4
- package/dist/cjs/dem.js +0 -11
- package/dist/cjs/dem.js.map +2 -2
- package/dist/cjs/encrypt.d.ts +0 -1
- package/dist/cjs/encrypt.js +3 -3
- package/dist/cjs/encrypt.js.map +2 -2
- package/dist/cjs/kdf.js +8 -0
- package/dist/cjs/kdf.js.map +2 -2
- package/dist/cjs/session-key.d.ts +8 -12
- package/dist/cjs/utils.d.ts +2 -0
- package/dist/cjs/utils.js +2 -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/bls12381.d.ts +1 -1
- package/dist/esm/bls12381.js +1 -1
- package/dist/esm/bls12381.js.map +2 -2
- package/dist/esm/decrypt.d.ts +1 -0
- package/dist/esm/decrypt.js.map +2 -2
- package/dist/esm/dem.d.ts +0 -4
- package/dist/esm/dem.js +0 -11
- package/dist/esm/dem.js.map +2 -2
- package/dist/esm/encrypt.d.ts +0 -1
- package/dist/esm/encrypt.js +4 -4
- package/dist/esm/encrypt.js.map +2 -2
- package/dist/esm/kdf.js +9 -1
- package/dist/esm/kdf.js.map +2 -2
- package/dist/esm/session-key.d.ts +8 -12
- package/dist/esm/utils.d.ts +2 -0
- package/dist/esm/utils.js +2 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @mysten/seal
|
|
2
2
|
|
|
3
|
+
## 0.4.20
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [33230ed]
|
|
8
|
+
- Updated dependencies [33230ed]
|
|
9
|
+
- Updated dependencies [33230ed]
|
|
10
|
+
- @mysten/bcs@1.7.0
|
|
11
|
+
- @mysten/sui@1.37.1
|
|
12
|
+
|
|
13
|
+
## 0.4.19
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [72168f0]
|
|
18
|
+
- @mysten/sui@1.37.0
|
|
19
|
+
|
|
3
20
|
## 0.4.18
|
|
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/bls12381.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class G2Element {
|
|
|
22
22
|
toBytes(): Uint8Array;
|
|
23
23
|
multiply(scalar: Scalar): G2Element;
|
|
24
24
|
add(other: G2Element): G2Element;
|
|
25
|
-
hashToCurve(data: Uint8Array): G2Element;
|
|
25
|
+
static hashToCurve(data: Uint8Array): G2Element;
|
|
26
26
|
equals(other: G2Element): boolean;
|
|
27
27
|
}
|
|
28
28
|
export declare class GTElement {
|
package/dist/cjs/bls12381.js
CHANGED
|
@@ -79,7 +79,7 @@ const _G2Element = class _G2Element {
|
|
|
79
79
|
add(other) {
|
|
80
80
|
return new _G2Element(this.point.add(other.point));
|
|
81
81
|
}
|
|
82
|
-
hashToCurve(data) {
|
|
82
|
+
static hashToCurve(data) {
|
|
83
83
|
return new _G2Element(
|
|
84
84
|
import_bls12_381.bls12_381.G2.ProjectivePoint.fromAffine(import_bls12_381.bls12_381.G2.hashToCurve(data).toAffine())
|
|
85
85
|
);
|
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';\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\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsB;AAGtB,uBAA0B;AAC1B,mBAAwB;AAEjB,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,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EACjD;AAAA,EAEA,YAAY,MAA6B;
|
|
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\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\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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsB;AAGtB,uBAA0B;AAC1B,mBAAwB;AAEjB,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,WAAU,KAAK,MAAM,SAAS,MAAM,KAAK,CAAC;AAAA,EACtD;AAAA,EAEA,OAAO,YAAY,MAA6B;AAC/C,WAAO,IAAI;AAAA,MACV,2BAAU,GAAG,gBAAgB,WAAW,2BAAU,GAAG,YAAY,IAAI,EAAE,SAAS,CAAC;AAAA,IAClF;AAAA,EACD;AAAA,EAEA,QAAQ,OAA6B;AACpC,WAAO,IAAI,UAAU,2BAAU,QAAQ,KAAK,OAAO,MAAM,KAAK,CAAC;AAAA,EA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,CAAC,CAAC;AAAA,EAChF;AAAA,EAEA,OAAO,OAA2B;AACjC,WAAO,2BAAU,OAAO,KAAK,IAAI,KAAK,SAAS,MAAM,OAAO;AAAA,EAC7D;AACD;AA5Ba,WAGW,OAAO;AAHxB,IAAM,YAAN;AA8BA,MAAM,UAAN,MAAM,QAAO;AAAA,EAKnB,YAAY,QAAgB;AAC3B,SAAK,SAAS;AAAA,EACf;AAAA,EAEA,OAAO,SAAiB;AACvB,WAAO,QAAO,UAAU,2BAAU,MAAM,iBAAiB,CAAC;AAAA,EAC3D;AAAA,EAEA,UAAsB;AACrB,WAAO,IAAI,WAAW,2BAAU,OAAO,GAAG,QAAQ,KAAK,MAAM,CAAC;AAAA,EAC/D;AAAA,EAEA,OAAO,UAAU,OAA2B;AAC3C,WAAO,IAAI,QAAO,2BAAU,OAAO,GAAG,UAAU,KAAK,CAAC;AAAA,EACvD;AAAA,EAEA,OAAO,WAAW,KAAqB;AACtC,WAAO,IAAI,QAAO,OAAO,GAAG,CAAC;AAAA,EAC9B;AACD;AAxBa,QAGW,OAAO;AAHxB,IAAM,SAAN;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/decrypt.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface DecryptOptions {
|
|
|
9
9
|
* Decrypt the given encrypted bytes with the given cached secret keys for the full ID.
|
|
10
10
|
* It's assumed that fetchKeys has been called to fetch the secret keys for enough key servers
|
|
11
11
|
* otherwise, this will throw an error.
|
|
12
|
+
* Also, it's assumed that the keys were verified by the caller.
|
|
12
13
|
*
|
|
13
14
|
* @returns - The decrypted plaintext corresponding to ciphertext.
|
|
14
15
|
*/
|
package/dist/cjs/decrypt.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/decrypt.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\n\nimport type { EncryptedObject } from './bcs.js';\nimport type { G1Element } from './bls12381.js';\nimport { G2Element } from './bls12381.js';\nimport { AesGcm256, Hmac256Ctr } from './dem.js';\nimport { InvalidCiphertextError, UnsupportedFeatureError } from './error.js';\nimport { BonehFranklinBLS12381Services, decryptRandomness, verifyNonce } from './ibe.js';\nimport { deriveKey, KeyPurpose } from './kdf.js';\nimport type { KeyCacheKey } from './types.js';\nimport { createFullId } from './utils.js';\nimport { combine } from './shamir.js';\n\nexport interface DecryptOptions {\n\tencryptedObject: typeof EncryptedObject.$inferType;\n\tkeys: Map<KeyCacheKey, G1Element>;\n}\n\n/**\n * Decrypt the given encrypted bytes with the given cached secret keys for the full ID.\n * It's assumed that fetchKeys has been called to fetch the secret keys for enough key servers\n * otherwise, this will throw an error.\n *\n * @returns - The decrypted plaintext corresponding to ciphertext.\n */\nexport async function decrypt({ encryptedObject, keys }: DecryptOptions): Promise<Uint8Array> {\n\tif (!encryptedObject.encryptedShares.BonehFranklinBLS12381) {\n\t\tthrow new UnsupportedFeatureError('Encryption mode not supported');\n\t}\n\n\tconst fullId = createFullId(encryptedObject.packageId, encryptedObject.id);\n\n\t// Get the indices of the service whose keys are in the keystore.\n\tconst inKeystore = encryptedObject.services\n\t\t.map((_, i) => i)\n\t\t.filter((i) => keys.has(`${fullId}:${encryptedObject.services[i][0]}`));\n\n\tif (inKeystore.length < encryptedObject.threshold) {\n\t\tthrow new Error('Not enough shares. Please fetch more keys.');\n\t}\n\n\tconst encryptedShares = encryptedObject.encryptedShares.BonehFranklinBLS12381.encryptedShares;\n\tif (encryptedShares.length !== encryptedObject.services.length) {\n\t\tthrow new InvalidCiphertextError(\n\t\t\t`Mismatched shares ${encryptedShares.length} and services ${encryptedObject.services.length}`,\n\t\t);\n\t}\n\n\tconst nonce = G2Element.fromBytes(encryptedObject.encryptedShares.BonehFranklinBLS12381.nonce);\n\n\t// Decrypt each share.\n\tconst shares = inKeystore.map((i) => {\n\t\tconst [objectId, index] = encryptedObject.services[i];\n\t\t// Use the index as the unique info parameter to allow for multiple shares per key server.\n\t\tconst share = BonehFranklinBLS12381Services.decrypt(\n\t\t\tnonce,\n\t\t\tkeys.get(`${fullId}:${objectId}`)!,\n\t\t\tencryptedShares[i],\n\t\t\tfromHex(fullId),\n\t\t\t[objectId, index],\n\t\t);\n\t\t// The Shamir secret sharing library expects the index/x-coordinate to be at the end of the share.\n\t\treturn { index, share };\n\t});\n\n\t// Combine the decrypted shares into the key.\n\tconst baseKey = combine(shares);\n\n\t// Decrypt randomness and check validity of the nonce\n\tconst randomnessKey = deriveKey(\n\t\tKeyPurpose.EncryptedRandomness,\n\t\tbaseKey,\n\t\tencryptedShares,\n\t\tencryptedObject.threshold,\n\t\tencryptedObject.services.map(([objectIds, _]) => objectIds),\n\t);\n\tif (\n\t\t!verifyNonce(\n\t\t\tnonce,\n\t\t\tdecryptRandomness(\n\t\t\t\tencryptedObject.encryptedShares.BonehFranklinBLS12381.encryptedRandomness,\n\t\t\t\trandomnessKey,\n\t\t\t),\n\t\t)\n\t) {\n\t\tthrow new InvalidCiphertextError('Invalid nonce');\n\t}\n\n\t// Derive the DEM key and decrypt the ciphertext\n\tconst demKey = deriveKey(\n\t\tKeyPurpose.DEM,\n\t\tbaseKey,\n\t\tencryptedObject.encryptedShares.BonehFranklinBLS12381.encryptedShares,\n\t\tencryptedObject.threshold,\n\t\tencryptedObject.services.map(([objectId, _]) => objectId),\n\t);\n\n\tif (encryptedObject.ciphertext.Aes256Gcm) {\n\t\treturn AesGcm256.decrypt(demKey, encryptedObject.ciphertext);\n\t} else if (encryptedObject.ciphertext.Hmac256Ctr) {\n\t\treturn Hmac256Ctr.decrypt(demKey, encryptedObject.ciphertext);\n\t} else if (encryptedObject.ciphertext.Plain) {\n\t\t// In case `Plain` mode is used, return the key.\n\t\treturn demKey;\n\t} else {\n\t\tthrow new InvalidCiphertextError('Invalid ciphertext type');\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAwB;AAIxB,sBAA0B;AAC1B,iBAAsC;AACtC,mBAAgE;AAChE,iBAA8E;AAC9E,iBAAsC;AAEtC,mBAA6B;AAC7B,oBAAwB;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\n\nimport type { EncryptedObject } from './bcs.js';\nimport type { G1Element } from './bls12381.js';\nimport { G2Element } from './bls12381.js';\nimport { AesGcm256, Hmac256Ctr } from './dem.js';\nimport { InvalidCiphertextError, UnsupportedFeatureError } from './error.js';\nimport { BonehFranklinBLS12381Services, decryptRandomness, verifyNonce } from './ibe.js';\nimport { deriveKey, KeyPurpose } from './kdf.js';\nimport type { KeyCacheKey } from './types.js';\nimport { createFullId } from './utils.js';\nimport { combine } from './shamir.js';\n\nexport interface DecryptOptions {\n\tencryptedObject: typeof EncryptedObject.$inferType;\n\tkeys: Map<KeyCacheKey, G1Element>;\n}\n\n/**\n * Decrypt the given encrypted bytes with the given cached secret keys for the full ID.\n * It's assumed that fetchKeys has been called to fetch the secret keys for enough key servers\n * otherwise, this will throw an error.\n * Also, it's assumed that the keys were verified by the caller.\n *\n * @returns - The decrypted plaintext corresponding to ciphertext.\n */\nexport async function decrypt({ encryptedObject, keys }: DecryptOptions): Promise<Uint8Array> {\n\tif (!encryptedObject.encryptedShares.BonehFranklinBLS12381) {\n\t\tthrow new UnsupportedFeatureError('Encryption mode not supported');\n\t}\n\n\tconst fullId = createFullId(encryptedObject.packageId, encryptedObject.id);\n\n\t// Get the indices of the service whose keys are in the keystore.\n\tconst inKeystore = encryptedObject.services\n\t\t.map((_, i) => i)\n\t\t.filter((i) => keys.has(`${fullId}:${encryptedObject.services[i][0]}`));\n\n\tif (inKeystore.length < encryptedObject.threshold) {\n\t\tthrow new Error('Not enough shares. Please fetch more keys.');\n\t}\n\n\tconst encryptedShares = encryptedObject.encryptedShares.BonehFranklinBLS12381.encryptedShares;\n\tif (encryptedShares.length !== encryptedObject.services.length) {\n\t\tthrow new InvalidCiphertextError(\n\t\t\t`Mismatched shares ${encryptedShares.length} and services ${encryptedObject.services.length}`,\n\t\t);\n\t}\n\n\tconst nonce = G2Element.fromBytes(encryptedObject.encryptedShares.BonehFranklinBLS12381.nonce);\n\n\t// Decrypt each share.\n\tconst shares = inKeystore.map((i) => {\n\t\tconst [objectId, index] = encryptedObject.services[i];\n\t\t// Use the index as the unique info parameter to allow for multiple shares per key server.\n\t\tconst share = BonehFranklinBLS12381Services.decrypt(\n\t\t\tnonce,\n\t\t\tkeys.get(`${fullId}:${objectId}`)!,\n\t\t\tencryptedShares[i],\n\t\t\tfromHex(fullId),\n\t\t\t[objectId, index],\n\t\t);\n\t\t// The Shamir secret sharing library expects the index/x-coordinate to be at the end of the share.\n\t\treturn { index, share };\n\t});\n\n\t// Combine the decrypted shares into the key.\n\tconst baseKey = combine(shares);\n\n\t// Decrypt randomness and check validity of the nonce\n\tconst randomnessKey = deriveKey(\n\t\tKeyPurpose.EncryptedRandomness,\n\t\tbaseKey,\n\t\tencryptedShares,\n\t\tencryptedObject.threshold,\n\t\tencryptedObject.services.map(([objectIds, _]) => objectIds),\n\t);\n\tif (\n\t\t!verifyNonce(\n\t\t\tnonce,\n\t\t\tdecryptRandomness(\n\t\t\t\tencryptedObject.encryptedShares.BonehFranklinBLS12381.encryptedRandomness,\n\t\t\t\trandomnessKey,\n\t\t\t),\n\t\t)\n\t) {\n\t\tthrow new InvalidCiphertextError('Invalid nonce');\n\t}\n\n\t// Derive the DEM key and decrypt the ciphertext\n\tconst demKey = deriveKey(\n\t\tKeyPurpose.DEM,\n\t\tbaseKey,\n\t\tencryptedObject.encryptedShares.BonehFranklinBLS12381.encryptedShares,\n\t\tencryptedObject.threshold,\n\t\tencryptedObject.services.map(([objectId, _]) => objectId),\n\t);\n\n\tif (encryptedObject.ciphertext.Aes256Gcm) {\n\t\treturn AesGcm256.decrypt(demKey, encryptedObject.ciphertext);\n\t} else if (encryptedObject.ciphertext.Hmac256Ctr) {\n\t\treturn Hmac256Ctr.decrypt(demKey, encryptedObject.ciphertext);\n\t} else if (encryptedObject.ciphertext.Plain) {\n\t\t// In case `Plain` mode is used, return the key.\n\t\treturn demKey;\n\t} else {\n\t\tthrow new InvalidCiphertextError('Invalid ciphertext type');\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAwB;AAIxB,sBAA0B;AAC1B,iBAAsC;AACtC,mBAAgE;AAChE,iBAA8E;AAC9E,iBAAsC;AAEtC,mBAA6B;AAC7B,oBAAwB;AAexB,eAAsB,QAAQ,EAAE,iBAAiB,KAAK,GAAwC;AAC7F,MAAI,CAAC,gBAAgB,gBAAgB,uBAAuB;AAC3D,UAAM,IAAI,qCAAwB,+BAA+B;AAAA,EAClE;AAEA,QAAM,aAAS,2BAAa,gBAAgB,WAAW,gBAAgB,EAAE;AAGzE,QAAM,aAAa,gBAAgB,SACjC,IAAI,CAAC,GAAG,MAAM,CAAC,EACf,OAAO,CAAC,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,gBAAgB,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAEvE,MAAI,WAAW,SAAS,gBAAgB,WAAW;AAClD,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC7D;AAEA,QAAM,kBAAkB,gBAAgB,gBAAgB,sBAAsB;AAC9E,MAAI,gBAAgB,WAAW,gBAAgB,SAAS,QAAQ;AAC/D,UAAM,IAAI;AAAA,MACT,qBAAqB,gBAAgB,MAAM,iBAAiB,gBAAgB,SAAS,MAAM;AAAA,IAC5F;AAAA,EACD;AAEA,QAAM,QAAQ,0BAAU,UAAU,gBAAgB,gBAAgB,sBAAsB,KAAK;AAG7F,QAAM,SAAS,WAAW,IAAI,CAAC,MAAM;AACpC,UAA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12
12
|
encrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput>;
|
|
13
13
|
static decrypt(key: Uint8Array, ciphertext: typeof Ciphertext.$inferInput): Promise<Uint8Array>;
|
|
14
14
|
}
|
|
15
|
-
export declare class Plain implements EncryptionInput {
|
|
16
|
-
encrypt(_key: Uint8Array): Promise<typeof Ciphertext.$inferInput>;
|
|
17
|
-
generateKey(): Promise<Uint8Array>;
|
|
18
|
-
}
|
|
19
15
|
/**
|
|
20
16
|
* Authenticated encryption using CTR mode with HMAC-SHA3-256 as a PRF.
|
|
21
17
|
* 1. Derive an encryption key, <i>k<sub>1</sub> = <b>hmac</b>(key, 1)</i>.
|
package/dist/cjs/dem.js
CHANGED
|
@@ -20,7 +20,6 @@ var dem_exports = {};
|
|
|
20
20
|
__export(dem_exports, {
|
|
21
21
|
AesGcm256: () => AesGcm256,
|
|
22
22
|
Hmac256Ctr: () => Hmac256Ctr,
|
|
23
|
-
Plain: () => Plain,
|
|
24
23
|
iv: () => iv
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(dem_exports);
|
|
@@ -109,16 +108,6 @@ class AesGcm256 {
|
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
class Plain {
|
|
113
|
-
async encrypt(_key) {
|
|
114
|
-
return {
|
|
115
|
-
Plain: {}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
generateKey() {
|
|
119
|
-
return generateAesKey();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
111
|
class Hmac256Ctr {
|
|
123
112
|
constructor(msg, aad) {
|
|
124
113
|
this.plaintext = msg;
|
package/dist/cjs/dem.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dem.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/bcs';\nimport { equalBytes } from '@noble/curves/abstract/utils';\nimport { hmac } from '@noble/hashes/hmac';\nimport { sha3_256 } from '@noble/hashes/sha3';\n\nimport type { Ciphertext } from './bcs.js';\nimport { DecryptionError, InvalidCiphertextError } from './error.js';\nimport { flatten, xorUnchecked } from './utils.js';\n\n// Use a fixed IV for AES. This is okay because the key is unique for each message.\nexport const iv = Uint8Array.from([\n\t138, 55, 153, 253, 198, 46, 121, 219, 160, 128, 89, 7, 214, 156, 148, 220,\n]);\n\nasync function generateAesKey(): Promise<Uint8Array> {\n\tconst key = await crypto.subtle.generateKey(\n\t\t{\n\t\t\tname: 'AES-GCM',\n\t\t\tlength: 256,\n\t\t},\n\t\ttrue,\n\t\t['encrypt', 'decrypt'],\n\t);\n\treturn await crypto.subtle.exportKey('raw', key).then((keyData) => new Uint8Array(keyData));\n}\n\nexport interface EncryptionInput {\n\tencrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput>;\n\tgenerateKey(): Promise<Uint8Array>;\n}\n\nexport class AesGcm256 implements EncryptionInput {\n\treadonly plaintext: Uint8Array;\n\treadonly aad: Uint8Array;\n\n\tconstructor(msg: Uint8Array, aad: Uint8Array) {\n\t\tthis.plaintext = msg;\n\t\tthis.aad = aad;\n\t}\n\n\tgenerateKey(): Promise<Uint8Array> {\n\t\treturn generateAesKey();\n\t}\n\n\tasync encrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput> {\n\t\tconst aesCryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['encrypt']);\n\n\t\tconst blob = new Uint8Array(\n\t\t\tawait crypto.subtle.encrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv,\n\t\t\t\t\tadditionalData: this.aad,\n\t\t\t\t},\n\t\t\t\taesCryptoKey,\n\t\t\t\tthis.plaintext,\n\t\t\t),\n\t\t);\n\n\t\treturn {\n\t\t\tAes256Gcm: {\n\t\t\t\tblob,\n\t\t\t\taad: this.aad ?? [],\n\t\t\t},\n\t\t};\n\t}\n\n\tstatic async decrypt(\n\t\tkey: Uint8Array,\n\t\tciphertext: typeof Ciphertext.$inferInput,\n\t): Promise<Uint8Array> {\n\t\tif (!('Aes256Gcm' in ciphertext)) {\n\t\t\tthrow new InvalidCiphertextError(`Invalid ciphertext ${ciphertext}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst aesCryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['decrypt']);\n\t\t\treturn new Uint8Array(\n\t\t\t\tawait crypto.subtle.decrypt(\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\t\tiv,\n\t\t\t\t\t\tadditionalData: new Uint8Array(ciphertext.Aes256Gcm.aad ?? []),\n\t\t\t\t\t},\n\t\t\t\t\taesCryptoKey,\n\t\t\t\t\tnew Uint8Array(ciphertext.Aes256Gcm.blob),\n\t\t\t\t),\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tthrow new DecryptionError(`Decryption failed`);\n\t\t}\n\t}\n}\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/bcs';\nimport { equalBytes } from '@noble/curves/abstract/utils';\nimport { hmac } from '@noble/hashes/hmac';\nimport { sha3_256 } from '@noble/hashes/sha3';\n\nimport type { Ciphertext } from './bcs.js';\nimport { DecryptionError, InvalidCiphertextError } from './error.js';\nimport { flatten, xorUnchecked } from './utils.js';\n\n// Use a fixed IV for AES. This is okay because the key is unique for each message.\nexport const iv = Uint8Array.from([\n\t138, 55, 153, 253, 198, 46, 121, 219, 160, 128, 89, 7, 214, 156, 148, 220,\n]);\n\nasync function generateAesKey(): Promise<Uint8Array> {\n\tconst key = await crypto.subtle.generateKey(\n\t\t{\n\t\t\tname: 'AES-GCM',\n\t\t\tlength: 256,\n\t\t},\n\t\ttrue,\n\t\t['encrypt', 'decrypt'],\n\t);\n\treturn await crypto.subtle.exportKey('raw', key).then((keyData) => new Uint8Array(keyData));\n}\n\nexport interface EncryptionInput {\n\tencrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput>;\n\tgenerateKey(): Promise<Uint8Array>;\n}\n\nexport class AesGcm256 implements EncryptionInput {\n\treadonly plaintext: Uint8Array;\n\treadonly aad: Uint8Array;\n\n\tconstructor(msg: Uint8Array, aad: Uint8Array) {\n\t\tthis.plaintext = msg;\n\t\tthis.aad = aad;\n\t}\n\n\tgenerateKey(): Promise<Uint8Array> {\n\t\treturn generateAesKey();\n\t}\n\n\tasync encrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput> {\n\t\tconst aesCryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['encrypt']);\n\n\t\tconst blob = new Uint8Array(\n\t\t\tawait crypto.subtle.encrypt(\n\t\t\t\t{\n\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\tiv,\n\t\t\t\t\tadditionalData: this.aad,\n\t\t\t\t},\n\t\t\t\taesCryptoKey,\n\t\t\t\tthis.plaintext,\n\t\t\t),\n\t\t);\n\n\t\treturn {\n\t\t\tAes256Gcm: {\n\t\t\t\tblob,\n\t\t\t\taad: this.aad ?? [],\n\t\t\t},\n\t\t};\n\t}\n\n\tstatic async decrypt(\n\t\tkey: Uint8Array,\n\t\tciphertext: typeof Ciphertext.$inferInput,\n\t): Promise<Uint8Array> {\n\t\tif (!('Aes256Gcm' in ciphertext)) {\n\t\t\tthrow new InvalidCiphertextError(`Invalid ciphertext ${ciphertext}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst aesCryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['decrypt']);\n\t\t\treturn new Uint8Array(\n\t\t\t\tawait crypto.subtle.decrypt(\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'AES-GCM',\n\t\t\t\t\t\tiv,\n\t\t\t\t\t\tadditionalData: new Uint8Array(ciphertext.Aes256Gcm.aad ?? []),\n\t\t\t\t\t},\n\t\t\t\t\taesCryptoKey,\n\t\t\t\t\tnew Uint8Array(ciphertext.Aes256Gcm.blob),\n\t\t\t\t),\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tthrow new DecryptionError(`Decryption failed`);\n\t\t}\n\t}\n}\n\n/**\n * Authenticated encryption using CTR mode with HMAC-SHA3-256 as a PRF.\n * 1. Derive an encryption key, <i>k<sub>1</sub> = <b>hmac</b>(key, 1)</i>.\n * 2. Chunk the message into blocks of 32 bytes, <i>m = m<sub>1</sub> || ... || m<sub>n</sub></i>.\n * 3. Let the ciphertext be defined by <i>c = c<sub>1</sub> || ... || c<sub>n</sub></i> where <i>c<sub>i</sub> = m<sub>i</sub> \u2295 <b>hmac</b>(k<sub>1</sub>, i)</i>.\n * 4. Compute a MAC over the AAD and the ciphertext, <i>mac = <b>hmac</b>(k<sub>2</sub>, aad || c) where k<sub>2</sub> = <b>hmac</b>(key, 2)</i>.\n * 5. Return <i>mac || c</i>.\n */\nexport class Hmac256Ctr implements EncryptionInput {\n\treadonly plaintext: Uint8Array;\n\treadonly aad: Uint8Array;\n\n\tconstructor(msg: Uint8Array, aad: Uint8Array) {\n\t\tthis.plaintext = msg;\n\t\tthis.aad = aad;\n\t}\n\n\tgenerateKey(): Promise<Uint8Array> {\n\t\treturn generateAesKey();\n\t}\n\n\tasync encrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput> {\n\t\tconst blob = Hmac256Ctr.encryptInCtrMode(key, this.plaintext);\n\t\tconst mac = Hmac256Ctr.computeMac(key, this.aad, blob);\n\t\treturn {\n\t\t\tHmac256Ctr: {\n\t\t\t\tblob,\n\t\t\t\tmac,\n\t\t\t\taad: this.aad ?? [],\n\t\t\t},\n\t\t};\n\t}\n\n\tstatic async decrypt(\n\t\tkey: Uint8Array,\n\t\tciphertext: typeof Ciphertext.$inferInput,\n\t): Promise<Uint8Array> {\n\t\tif (!('Hmac256Ctr' in ciphertext)) {\n\t\t\tthrow new InvalidCiphertextError(`Invalid ciphertext ${ciphertext}`);\n\t\t}\n\t\tconst aad = new Uint8Array(ciphertext.Hmac256Ctr.aad ?? []);\n\t\tconst blob = new Uint8Array(ciphertext.Hmac256Ctr.blob);\n\t\tconst mac = Hmac256Ctr.computeMac(key, aad, blob);\n\t\tif (!equalBytes(mac, new Uint8Array(ciphertext.Hmac256Ctr.mac))) {\n\t\t\tthrow new DecryptionError(`Invalid MAC ${mac}`);\n\t\t}\n\t\treturn Hmac256Ctr.encryptInCtrMode(key, blob);\n\t}\n\n\tprivate static computeMac(key: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array): Uint8Array {\n\t\tconst macInput = flatten([MacKeyTag, toBytes(aad.length), aad, ciphertext]);\n\t\tconst mac = hmac(sha3_256, key, macInput);\n\t\treturn mac;\n\t}\n\n\tprivate static encryptInCtrMode(key: Uint8Array, msg: Uint8Array): Uint8Array {\n\t\tconst blockSize = 32;\n\t\tconst result = new Uint8Array(msg.length);\n\t\tfor (let i = 0; i * blockSize < msg.length; i++) {\n\t\t\tconst block = msg.subarray(i * blockSize, (i + 1) * blockSize);\n\t\t\tconst mask = hmac(sha3_256, key, flatten([EncryptionKeyTag, toBytes(i)]));\n\t\t\tconst encryptedBlock = xorUnchecked(block, mask);\n\t\t\tresult.set(encryptedBlock, i * blockSize);\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/**\n * Convert a u64 to bytes using little-endian representation.\n */\nfunction toBytes(n: number): Uint8Array {\n\treturn bcs.u64().serialize(n).toBytes();\n}\n\nconst EncryptionKeyTag = new TextEncoder().encode('HMAC-CTR-ENC');\nconst MacKeyTag = new TextEncoder().encode('HMAC-CTR-MAC');\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AACpB,mBAA2B;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AAe,GAAG,EAAE;AAAA,IAC/C;AACA,WAAO,WAAW,iBAAiB,KAAK,IAAI;AAAA,EAC7C;AAAA,EAEA,OAAe,WAAW,KAAiB,KAAiB,YAAoC;AAC/F,UAAM,eAAW,uBAAQ,CAAC,WAAW,QAAQ,IAAI,MAAM,GAAG,KAAK,UAAU,CAAC;AAC1E,UAAM,UAAM,kBAAK,sBAAU,KAAK,QAAQ;AACxC,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,iBAAiB,KAAiB,KAA6B;AAC7E,UAAM,YAAY;AAClB,UAAM,SAAS,IAAI,WAAW,IAAI,MAAM;AACxC,aAAS,IAAI,GAAG,IAAI,YAAY,IAAI,QAAQ,KAAK;AAChD,YAAM,QAAQ,IAAI,SAAS,IAAI,YAAY,IAAI,KAAK,SAAS;AAC7D,YAAM,WAAO,kBAAK,sBAAU,SAAK,uBAAQ,CAAC,kBAAkB,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxE,YAAM,qBAAiB,4BAAa,OAAO,IAAI;AAC/C,aAAO,IAAI,gBAAgB,IAAI,SAAS;AAAA,IACzC;AACA,WAAO;AAAA,EACR;AACD;AAKA,SAAS,QAAQ,GAAuB;AACvC,SAAO,eAAI,IAAI,EAAE,UAAU,CAAC,EAAE,QAAQ;AACvC;AAEA,MAAM,mBAAmB,IAAI,YAAY,EAAE,OAAO,cAAc;AAChE,MAAM,YAAY,IAAI,YAAY,EAAE,OAAO,cAAc;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
package/dist/cjs/encrypt.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { EncryptionInput } from './dem.js';
|
|
2
2
|
import type { KeyServer } from './key-server.js';
|
|
3
|
-
export declare const MAX_U8 = 255;
|
|
4
3
|
/**
|
|
5
4
|
* Given full ID and what key servers to use, return the encrypted message under the identity and return the bcs bytes of the encrypted object.
|
|
6
5
|
*
|
package/dist/cjs/encrypt.js
CHANGED
|
@@ -20,7 +20,6 @@ var encrypt_exports = {};
|
|
|
20
20
|
__export(encrypt_exports, {
|
|
21
21
|
DemType: () => DemType,
|
|
22
22
|
KemType: () => KemType,
|
|
23
|
-
MAX_U8: () => MAX_U8,
|
|
24
23
|
encrypt: () => encrypt
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(encrypt_exports);
|
|
@@ -32,7 +31,6 @@ var import_ibe = require("./ibe.js");
|
|
|
32
31
|
var import_kdf = require("./kdf.js");
|
|
33
32
|
var import_utils2 = require("./utils.js");
|
|
34
33
|
var import_shamir = require("./shamir.js");
|
|
35
|
-
const MAX_U8 = 255;
|
|
36
34
|
async function encrypt({
|
|
37
35
|
keyServers,
|
|
38
36
|
kemType,
|
|
@@ -41,7 +39,7 @@ async function encrypt({
|
|
|
41
39
|
id,
|
|
42
40
|
encryptionInput
|
|
43
41
|
}) {
|
|
44
|
-
if (
|
|
42
|
+
if (threshold <= 0 || threshold > import_utils2.MAX_U8 || keyServers.length < threshold || keyServers.length > import_utils2.MAX_U8 || !(0, import_utils.isValidSuiObjectId)(packageId)) {
|
|
45
43
|
throw new import_error.UserError(
|
|
46
44
|
`Invalid key servers or threshold ${threshold} for ${keyServers.length} key servers for package ${packageId}`
|
|
47
45
|
);
|
|
@@ -103,6 +101,8 @@ function encryptBatched(keyServers, kemType, id, msgs, baseKey, threshold) {
|
|
|
103
101
|
baseKey,
|
|
104
102
|
threshold
|
|
105
103
|
);
|
|
104
|
+
default:
|
|
105
|
+
throw new Error(`Invalid KEM type ${kemType}`);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
//# sourceMappingURL=encrypt.js.map
|
package/dist/cjs/encrypt.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/encrypt.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { isValidSuiObjectId } from '@mysten/sui/utils';\n\nimport type { IBEEncryptions } from './bcs.js';\nimport { EncryptedObject } from './bcs.js';\nimport type { EncryptionInput } from './dem.js';\nimport { UserError } from './error.js';\nimport { BonehFranklinBLS12381Services } from './ibe.js';\nimport { deriveKey, KeyPurpose } from './kdf.js';\nimport type { KeyServer } from './key-server.js';\nimport { createFullId } from './utils.js';\nimport { split } from './shamir.js';\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { isValidSuiObjectId } from '@mysten/sui/utils';\n\nimport type { IBEEncryptions } from './bcs.js';\nimport { EncryptedObject } from './bcs.js';\nimport type { EncryptionInput } from './dem.js';\nimport { UserError } from './error.js';\nimport { BonehFranklinBLS12381Services } from './ibe.js';\nimport { deriveKey, KeyPurpose } from './kdf.js';\nimport type { KeyServer } from './key-server.js';\nimport { createFullId, MAX_U8 } from './utils.js';\nimport { split } from './shamir.js';\n\n/**\n * Given full ID and what key servers to use, return the encrypted message under the identity and return the bcs bytes of the encrypted object.\n *\n * @param keyServers - A list of KeyServers (same server can be used multiple times)\n * @param kemType - The type of KEM to use.\n * @param packageId - packageId\n * @param id - id\n * @param encryptionInput - Input to the encryption. Should be one of the EncryptionInput types, AesGcmEncryptionInput or Plain.\n * @param threshold - The threshold for the TSS encryption.\n * @returns The bcs bytes of the encrypted object containing all metadata and the 256-bit symmetric key that was used to encrypt the object.\n * Since the key can be used to decrypt, it should not be shared but can be used eg. for backup.\n */\nexport async function encrypt({\n\tkeyServers,\n\tkemType,\n\tthreshold,\n\tpackageId,\n\tid,\n\tencryptionInput,\n}: {\n\tkeyServers: KeyServer[];\n\tkemType: KemType;\n\tthreshold: number;\n\tpackageId: string;\n\tid: string;\n\tencryptionInput: EncryptionInput;\n}): Promise<{\n\tencryptedObject: Uint8Array;\n\tkey: Uint8Array;\n}> {\n\t// Check inputs\n\tif (\n\t\tthreshold <= 0 ||\n\t\tthreshold > MAX_U8 ||\n\t\tkeyServers.length < threshold ||\n\t\tkeyServers.length > MAX_U8 ||\n\t\t!isValidSuiObjectId(packageId)\n\t) {\n\t\tthrow new UserError(\n\t\t\t`Invalid key servers or threshold ${threshold} for ${keyServers.length} key servers for package ${packageId}`,\n\t\t);\n\t}\n\n\t// Generate a random base key.\n\tconst baseKey = await encryptionInput.generateKey();\n\n\t// Split the key into shares and encrypt each share with the public keys of the key servers.\n\tconst shares = split(baseKey, threshold, keyServers.length);\n\n\t// Encrypt the shares with the public keys of the key servers.\n\tconst fullId = createFullId(packageId, id);\n\tconst encryptedShares = encryptBatched(\n\t\tkeyServers,\n\t\tkemType,\n\t\tfromHex(fullId),\n\t\tshares.map(({ share, index }) => ({\n\t\t\tmsg: share,\n\t\t\tindex,\n\t\t})),\n\t\tbaseKey,\n\t\tthreshold,\n\t);\n\n\t// Encrypt the object with the derived DEM key.\n\tconst demKey = deriveKey(\n\t\tKeyPurpose.DEM,\n\t\tbaseKey,\n\t\tencryptedShares.BonehFranklinBLS12381.encryptedShares,\n\t\tthreshold,\n\t\tkeyServers.map(({ objectId }) => objectId),\n\t);\n\tconst ciphertext = await encryptionInput.encrypt(demKey);\n\n\t// Services and indices of their shares are stored as a tuple\n\tconst services: [string, number][] = keyServers.map(({ objectId }, i) => [\n\t\tobjectId,\n\t\tshares[i].index,\n\t]);\n\n\treturn {\n\t\tencryptedObject: EncryptedObject.serialize({\n\t\t\tversion: 0,\n\t\t\tpackageId,\n\t\t\tid,\n\t\t\tservices,\n\t\t\tthreshold,\n\t\t\tencryptedShares,\n\t\t\tciphertext,\n\t\t}).toBytes(),\n\t\tkey: demKey,\n\t};\n}\n\nexport enum KemType {\n\tBonehFranklinBLS12381DemCCA = 0,\n}\n\nexport enum DemType {\n\tAesGcm256 = 0,\n\tHmac256Ctr = 1,\n}\n\nfunction encryptBatched(\n\tkeyServers: KeyServer[],\n\tkemType: KemType,\n\tid: Uint8Array,\n\tmsgs: { msg: Uint8Array; index: number }[],\n\tbaseKey: Uint8Array,\n\tthreshold: number,\n): typeof IBEEncryptions.$inferType {\n\tswitch (kemType) {\n\t\tcase KemType.BonehFranklinBLS12381DemCCA:\n\t\t\treturn new BonehFranklinBLS12381Services(keyServers).encryptBatched(\n\t\t\t\tid,\n\t\t\t\tmsgs,\n\t\t\t\tbaseKey,\n\t\t\t\tthreshold,\n\t\t\t);\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid KEM type ${kemType}`);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAwB;AACxB,mBAAmC;AAGnC,IAAAA,cAAgC;AAEhC,mBAA0B;AAC1B,iBAA8C;AAC9C,iBAAsC;AAEtC,IAAAC,gBAAqC;AACrC,oBAAsB;AActB,eAAsB,QAAQ;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAUG;AAEF,MACC,aAAa,KACb,YAAY,wBACZ,WAAW,SAAS,aACpB,WAAW,SAAS,wBACpB,KAAC,iCAAmB,SAAS,GAC5B;AACD,UAAM,IAAI;AAAA,MACT,oCAAoC,SAAS,QAAQ,WAAW,MAAM,4BAA4B,SAAS;AAAA,IAC5G;AAAA,EACD;AAGA,QAAM,UAAU,MAAM,gBAAgB,YAAY;AAGlD,QAAM,aAAS,qBAAM,SAAS,WAAW,WAAW,MAAM;AAG1D,QAAM,aAAS,4BAAa,WAAW,EAAE;AACzC,QAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,QACA,oBAAQ,MAAM;AAAA,IACd,OAAO,IAAI,CAAC,EAAE,OAAO,MAAM,OAAO;AAAA,MACjC,KAAK;AAAA,MACL;AAAA,IACD,EAAE;AAAA,IACF;AAAA,IACA;AAAA,EACD;AAGA,QAAM,aAAS;AAAA,IACd,sBAAW;AAAA,IACX;AAAA,IACA,gBAAgB,sBAAsB;AAAA,IACtC;AAAA,IACA,WAAW,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ;AAAA,EAC1C;AACA,QAAM,aAAa,MAAM,gBAAgB,QAAQ,MAAM;AAGvD,QAAM,WAA+B,WAAW,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM;AAAA,IACxE;AAAA,IACA,OAAO,CAAC,EAAE;AAAA,EACX,CAAC;AAED,SAAO;AAAA,IACN,iBAAiB,4BAAgB,UAAU;AAAA,MAC1C,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAC,EAAE,QAAQ;AAAA,IACX,KAAK;AAAA,EACN;AACD;AAEO,IAAK,UAAL,kBAAKC,aAAL;AACN,EAAAA,kBAAA,iCAA8B,KAA9B;AADW,SAAAA;AAAA,GAAA;AAIL,IAAK,UAAL,kBAAKC,aAAL;AACN,EAAAA,kBAAA,eAAY,KAAZ;AACA,EAAAA,kBAAA,gBAAa,KAAb;AAFW,SAAAA;AAAA,GAAA;AAKZ,SAAS,eACR,YACA,SACA,IACA,MACA,SACA,WACmC;AACnC,UAAQ,SAAS;AAAA,IAChB,KAAK;AACJ,aAAO,IAAI,yCAA8B,UAAU,EAAE;AAAA,QACpD;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AACC,YAAM,IAAI,MAAM,oBAAoB,OAAO,EAAE;AAAA,EAC/C;AACD;",
|
|
6
6
|
"names": ["import_bcs", "import_utils", "KemType", "DemType"]
|
|
7
7
|
}
|
package/dist/cjs/kdf.js
CHANGED
|
@@ -35,6 +35,9 @@ function hashToG1(id) {
|
|
|
35
35
|
return import_bls12381.G1Element.hashToCurve((0, import_utils.flatten)([DST, id]));
|
|
36
36
|
}
|
|
37
37
|
function kdf(element, nonce, id, objectId, index) {
|
|
38
|
+
if (index < 0 || index > import_utils.MAX_U8) {
|
|
39
|
+
throw new Error(`Invalid index ${index}`);
|
|
40
|
+
}
|
|
38
41
|
const hash = import_sha3.sha3_256.create();
|
|
39
42
|
hash.update(KDF_DST);
|
|
40
43
|
hash.update(element.toBytes());
|
|
@@ -55,9 +58,14 @@ function tag(purpose) {
|
|
|
55
58
|
return new Uint8Array([0]);
|
|
56
59
|
case 1 /* DEM */:
|
|
57
60
|
return new Uint8Array([1]);
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(`Invalid key purpose ${purpose}`);
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
function deriveKey(purpose, baseKey, encryptedShares, threshold, keyServers) {
|
|
66
|
+
if (threshold <= 0 || threshold > import_utils.MAX_U8) {
|
|
67
|
+
throw new Error(`Invalid threshold ${threshold}`);
|
|
68
|
+
}
|
|
61
69
|
const hash = import_sha3.sha3_256.create();
|
|
62
70
|
hash.update(DERIVE_KEY_DST);
|
|
63
71
|
hash.update(baseKey);
|
package/dist/cjs/kdf.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/kdf.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { sha3_256 } from '@noble/hashes/sha3';\n\nimport { G1Element } from './bls12381.js';\nimport type { G2Element, GTElement } from './bls12381.js';\nimport { flatten } from './utils.js';\n\n/**\n * The domain separation tag for the hash-to-group function.\n */\nconst DST: Uint8Array = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-00');\nconst KDF_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H2-00');\nconst DERIVE_KEY_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H3-00');\n\n/**\n * Hash an id to a G1Element.\n *\n * @param id The id to hash.\n * @returns The G1Element.\n */\nexport function hashToG1(id: Uint8Array): G1Element {\n\treturn G1Element.hashToCurve(flatten([DST, id]));\n}\n\n/**\n * The default key derivation function.\n *\n * @returns The derived key.\n */\nexport function kdf(\n\telement: GTElement,\n\tnonce: G2Element,\n\tid: Uint8Array,\n\tobjectId: string,\n\tindex: number,\n): Uint8Array {\n\tconst hash = sha3_256.create();\n\thash.update(KDF_DST);\n\thash.update(element.toBytes());\n\thash.update(nonce.toBytes());\n\thash.update(hashToG1(id).toBytes());\n\thash.update(fromHex(objectId));\n\thash.update(new Uint8Array([index]));\n\treturn hash.digest();\n}\n\nexport enum KeyPurpose {\n\tEncryptedRandomness,\n\tDEM,\n}\n\nfunction tag(purpose: KeyPurpose): Uint8Array {\n\tswitch (purpose) {\n\t\tcase KeyPurpose.EncryptedRandomness:\n\t\t\treturn new Uint8Array([0]);\n\t\tcase KeyPurpose.DEM:\n\t\t\treturn new Uint8Array([1]);\n\t}\n}\n\n/**\n * Derive a key from a base key and a list of encrypted shares.\n *\n * @param purpose The purpose of the key.\n * @param baseKey The base key.\n * @param encryptedShares The encrypted shares.\n * @param threshold The threshold.\n * @param keyServers The object ids of the key servers.\n * @returns The derived key.\n */\nexport function deriveKey(\n\tpurpose: KeyPurpose,\n\tbaseKey: Uint8Array,\n\tencryptedShares: Uint8Array[],\n\tthreshold: number,\n\tkeyServers: string[],\n): Uint8Array {\n\tconst hash = sha3_256.create();\n\thash.update(DERIVE_KEY_DST);\n\thash.update(baseKey);\n\thash.update(tag(purpose));\n\thash.update(new Uint8Array([threshold]));\n\tencryptedShares.forEach((share) => hash.update(share));\n\tkeyServers.forEach((keyServer) => hash.update(fromHex(keyServer)));\n\treturn hash.digest();\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAwB;AACxB,kBAAyB;AAEzB,sBAA0B;AAE1B,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { sha3_256 } from '@noble/hashes/sha3';\n\nimport { G1Element } from './bls12381.js';\nimport type { G2Element, GTElement } from './bls12381.js';\nimport { flatten, MAX_U8 } from './utils.js';\n\n/**\n * The domain separation tag for the hash-to-group function.\n */\nconst DST: Uint8Array = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-00');\nconst KDF_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H2-00');\nconst DERIVE_KEY_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H3-00');\n\n/**\n * Hash an id to a G1Element.\n *\n * @param id The id to hash.\n * @returns The G1Element.\n */\nexport function hashToG1(id: Uint8Array): G1Element {\n\treturn G1Element.hashToCurve(flatten([DST, id]));\n}\n\n/**\n * The default key derivation function.\n *\n * @returns The derived key.\n */\nexport function kdf(\n\telement: GTElement,\n\tnonce: G2Element,\n\tid: Uint8Array,\n\tobjectId: string,\n\tindex: number,\n): Uint8Array {\n\tif (index < 0 || index > MAX_U8) {\n\t\tthrow new Error(`Invalid index ${index}`);\n\t}\n\tconst hash = sha3_256.create();\n\thash.update(KDF_DST);\n\thash.update(element.toBytes());\n\thash.update(nonce.toBytes());\n\thash.update(hashToG1(id).toBytes());\n\thash.update(fromHex(objectId));\n\thash.update(new Uint8Array([index]));\n\treturn hash.digest();\n}\n\nexport enum KeyPurpose {\n\tEncryptedRandomness,\n\tDEM,\n}\n\nfunction tag(purpose: KeyPurpose): Uint8Array {\n\tswitch (purpose) {\n\t\tcase KeyPurpose.EncryptedRandomness:\n\t\t\treturn new Uint8Array([0]);\n\t\tcase KeyPurpose.DEM:\n\t\t\treturn new Uint8Array([1]);\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid key purpose ${purpose}`);\n\t}\n}\n\n/**\n * Derive a key from a base key and a list of encrypted shares.\n *\n * @param purpose The purpose of the key.\n * @param baseKey The base key.\n * @param encryptedShares The encrypted shares.\n * @param threshold The threshold.\n * @param keyServers The object ids of the key servers.\n * @returns The derived key.\n */\nexport function deriveKey(\n\tpurpose: KeyPurpose,\n\tbaseKey: Uint8Array,\n\tencryptedShares: Uint8Array[],\n\tthreshold: number,\n\tkeyServers: string[],\n): Uint8Array {\n\tif (threshold <= 0 || threshold > MAX_U8) {\n\t\tthrow new Error(`Invalid threshold ${threshold}`);\n\t}\n\tconst hash = sha3_256.create();\n\thash.update(DERIVE_KEY_DST);\n\thash.update(baseKey);\n\thash.update(tag(purpose));\n\thash.update(new Uint8Array([threshold]));\n\tencryptedShares.forEach((share) => hash.update(share));\n\tkeyServers.forEach((keyServer) => hash.update(fromHex(keyServer)));\n\treturn hash.digest();\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAwB;AACxB,kBAAyB;AAEzB,sBAA0B;AAE1B,mBAAgC;AAKhC,MAAM,MAAkB,IAAI,YAAY,EAAE,OAAO,0BAA0B;AAC3E,MAAM,UAAU,IAAI,YAAY,EAAE,OAAO,6BAA6B;AACtE,MAAM,iBAAiB,IAAI,YAAY,EAAE,OAAO,6BAA6B;AAQtE,SAAS,SAAS,IAA2B;AACnD,SAAO,0BAAU,gBAAY,sBAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;AAChD;AAOO,SAAS,IACf,SACA,OACA,IACA,UACA,OACa;AACb,MAAI,QAAQ,KAAK,QAAQ,qBAAQ;AAChC,UAAM,IAAI,MAAM,iBAAiB,KAAK,EAAE;AAAA,EACzC;AACA,QAAM,OAAO,qBAAS,OAAO;AAC7B,OAAK,OAAO,OAAO;AACnB,OAAK,OAAO,QAAQ,QAAQ,CAAC;AAC7B,OAAK,OAAO,MAAM,QAAQ,CAAC;AAC3B,OAAK,OAAO,SAAS,EAAE,EAAE,QAAQ,CAAC;AAClC,OAAK,WAAO,oBAAQ,QAAQ,CAAC;AAC7B,OAAK,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;AACnC,SAAO,KAAK,OAAO;AACpB;AAEO,IAAK,aAAL,kBAAKA,gBAAL;AACN,EAAAA,wBAAA;AACA,EAAAA,wBAAA;AAFW,SAAAA;AAAA,GAAA;AAKZ,SAAS,IAAI,SAAiC;AAC7C,UAAQ,SAAS;AAAA,IAChB,KAAK;AACJ,aAAO,IAAI,WAAW,CAAC,CAAC,CAAC;AAAA,IAC1B,KAAK;AACJ,aAAO,IAAI,WAAW,CAAC,CAAC,CAAC;AAAA,IAC1B;AACC,YAAM,IAAI,MAAM,uBAAuB,OAAO,EAAE;AAAA,EAClD;AACD;AAYO,SAAS,UACf,SACA,SACA,iBACA,WACA,YACa;AACb,MAAI,aAAa,KAAK,YAAY,qBAAQ;AACzC,UAAM,IAAI,MAAM,qBAAqB,SAAS,EAAE;AAAA,EACjD;AACA,QAAM,OAAO,qBAAS,OAAO;AAC7B,OAAK,OAAO,cAAc;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,OAAO,IAAI,OAAO,CAAC;AACxB,OAAK,OAAO,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;AACvC,kBAAgB,QAAQ,CAAC,UAAU,KAAK,OAAO,KAAK,CAAC;AACrD,aAAW,QAAQ,CAAC,cAAc,KAAK,WAAO,oBAAQ,SAAS,CAAC,CAAC;AACjE,SAAO,KAAK,OAAO;AACpB;",
|
|
6
6
|
"names": ["KeyPurpose"]
|
|
7
7
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import type { Signer } from '@mysten/sui/cryptography';
|
|
2
2
|
import type { SealCompatibleClient } from './types.js';
|
|
3
|
-
export declare const RequestFormat: import("@mysten/bcs").
|
|
4
|
-
ptb: number[]
|
|
5
|
-
encKey: number[];
|
|
6
|
-
encVerificationKey: number[];
|
|
7
|
-
}, {
|
|
8
|
-
ptb: Iterable<number> & {
|
|
3
|
+
export declare const RequestFormat: import("@mysten/bcs").BcsStruct<{
|
|
4
|
+
ptb: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
9
5
|
length: number;
|
|
10
|
-
}
|
|
11
|
-
encKey: Iterable<number> & {
|
|
6
|
+
}, string>;
|
|
7
|
+
encKey: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
12
8
|
length: number;
|
|
13
|
-
}
|
|
14
|
-
encVerificationKey: Iterable<number> & {
|
|
9
|
+
}, string>;
|
|
10
|
+
encVerificationKey: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
15
11
|
length: number;
|
|
16
|
-
}
|
|
17
|
-
}>;
|
|
12
|
+
}, string>;
|
|
13
|
+
}, string>;
|
|
18
14
|
export type Certificate = {
|
|
19
15
|
user: string;
|
|
20
16
|
session_vk: string;
|
package/dist/cjs/utils.d.ts
CHANGED
package/dist/cjs/utils.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
MAX_U8: () => MAX_U8,
|
|
21
22
|
Version: () => Version,
|
|
22
23
|
allEqual: () => allEqual,
|
|
23
24
|
count: () => count,
|
|
@@ -31,6 +32,7 @@ module.exports = __toCommonJS(utils_exports);
|
|
|
31
32
|
var import_bcs = require("@mysten/bcs");
|
|
32
33
|
var import_utils = require("@mysten/sui/utils");
|
|
33
34
|
var import_error = require("./error.js");
|
|
35
|
+
const MAX_U8 = 255;
|
|
34
36
|
function xor(a, b) {
|
|
35
37
|
if (a.length !== b.length) {
|
|
36
38
|
throw new Error("Invalid input");
|