@mysten/seal 0.0.0-experimental-20250330082435
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 +31 -0
- package/README.md +4 -0
- package/dist/cjs/bcs.d.ts +132 -0
- package/dist/cjs/bcs.js +67 -0
- package/dist/cjs/bcs.js.map +7 -0
- package/dist/cjs/bls12381.d.ts +37 -0
- package/dist/cjs/bls12381.js +110 -0
- package/dist/cjs/bls12381.js.map +7 -0
- package/dist/cjs/client.d.ts +83 -0
- package/dist/cjs/client.js +283 -0
- package/dist/cjs/client.js.map +7 -0
- package/dist/cjs/decrypt.d.ts +15 -0
- package/dist/cjs/decrypt.js +94 -0
- package/dist/cjs/decrypt.js.map +7 -0
- package/dist/cjs/dem.d.ts +36 -0
- package/dist/cjs/dem.js +173 -0
- package/dist/cjs/dem.js.map +7 -0
- package/dist/cjs/elgamal.d.ts +11 -0
- package/dist/cjs/elgamal.js +46 -0
- package/dist/cjs/elgamal.js.map +7 -0
- package/dist/cjs/encrypt.d.ts +33 -0
- package/dist/cjs/encrypt.js +118 -0
- package/dist/cjs/encrypt.js.map +7 -0
- package/dist/cjs/error.d.ts +58 -0
- package/dist/cjs/error.js +175 -0
- package/dist/cjs/error.js.map +7 -0
- package/dist/cjs/ibe.d.ts +63 -0
- package/dist/cjs/ibe.js +104 -0
- package/dist/cjs/ibe.js.map +7 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/kdf.d.ts +14 -0
- package/dist/cjs/kdf.js +64 -0
- package/dist/cjs/kdf.js.map +7 -0
- package/dist/cjs/key-server.d.ts +38 -0
- package/dist/cjs/key-server.js +101 -0
- package/dist/cjs/key-server.js.map +7 -0
- package/dist/cjs/keys.d.ts +17 -0
- package/dist/cjs/keys.js +61 -0
- package/dist/cjs/keys.js.map +7 -0
- package/dist/cjs/package.json +5 -0
- package/dist/cjs/session-key.d.ts +42 -0
- package/dist/cjs/session-key.js +140 -0
- package/dist/cjs/session-key.js.map +7 -0
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/utils.d.ts +10 -0
- package/dist/cjs/utils.js +51 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +25 -0
- package/dist/cjs/version.js.map +7 -0
- package/dist/esm/bcs.d.ts +132 -0
- package/dist/esm/bcs.js +47 -0
- package/dist/esm/bcs.js.map +7 -0
- package/dist/esm/bls12381.d.ts +37 -0
- package/dist/esm/bls12381.js +90 -0
- package/dist/esm/bls12381.js.map +7 -0
- package/dist/esm/client.d.ts +83 -0
- package/dist/esm/client.js +268 -0
- package/dist/esm/client.js.map +7 -0
- package/dist/esm/decrypt.d.ts +15 -0
- package/dist/esm/decrypt.js +74 -0
- package/dist/esm/decrypt.js.map +7 -0
- package/dist/esm/dem.d.ts +36 -0
- package/dist/esm/dem.js +153 -0
- package/dist/esm/dem.js.map +7 -0
- package/dist/esm/elgamal.d.ts +11 -0
- package/dist/esm/elgamal.js +26 -0
- package/dist/esm/elgamal.js.map +7 -0
- package/dist/esm/encrypt.d.ts +33 -0
- package/dist/esm/encrypt.js +98 -0
- package/dist/esm/encrypt.js.map +7 -0
- package/dist/esm/error.d.ts +58 -0
- package/dist/esm/error.js +155 -0
- package/dist/esm/error.js.map +7 -0
- package/dist/esm/ibe.d.ts +63 -0
- package/dist/esm/ibe.js +84 -0
- package/dist/esm/ibe.js.map +7 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/kdf.d.ts +14 -0
- package/dist/esm/kdf.js +44 -0
- package/dist/esm/kdf.js.map +7 -0
- package/dist/esm/key-server.d.ts +38 -0
- package/dist/esm/key-server.js +86 -0
- package/dist/esm/key-server.js.map +7 -0
- package/dist/esm/keys.d.ts +17 -0
- package/dist/esm/keys.js +41 -0
- package/dist/esm/keys.js.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/esm/session-key.d.ts +42 -0
- package/dist/esm/session-key.js +124 -0
- package/dist/esm/session-key.js.map +7 -0
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/utils.d.ts +10 -0
- package/dist/esm/utils.js +31 -0
- package/dist/esm/utils.js.map +7 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +5 -0
- package/dist/esm/version.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 { InvalidCiphertextError } from './error.js';\nimport { xorUnchecked } from './utils.js';\n\n// Use a fixed IV for AES.\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\tconst aesCryptoKey = await crypto.subtle.importKey('raw', key, 'AES-GCM', false, ['decrypt']);\n\n\t\treturn new Uint8Array(\n\t\t\tawait crypto.subtle.decrypt(\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: new Uint8Array(ciphertext.Aes256Gcm.aad ?? []),\n\t\t\t\t},\n\t\t\t\taesCryptoKey,\n\t\t\t\tnew Uint8Array(ciphertext.Aes256Gcm.blob),\n\t\t\t),\n\t\t);\n\t}\n}\n\nexport class Plain implements EncryptionInput {\n\tasync encrypt(_key: Uint8Array): Promise<typeof Ciphertext.$inferInput> {\n\t\treturn {\n\t\t\tPlain: {},\n\t\t};\n\t}\n\n\tgenerateKey(): Promise<Uint8Array> {\n\t\treturn generateAesKey();\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 InvalidCiphertextError(`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 macKey = hmac(sha3_256, key, MacKeyTag);\n\t\tconst macInput = new Uint8Array([...toBytes(aad.length), ...aad, ...ciphertext]);\n\t\tconst mac = hmac(sha3_256, macKey, macInput);\n\t\treturn mac;\n\t}\n\n\tprivate static encryptInCtrMode(key: Uint8Array, msg: Uint8Array): Uint8Array {\n\t\tconst blockSize = 32;\n\t\tlet result = Uint8Array.from({ length: msg.length }, () => 0);\n\t\tconst encryptionKey = hmac(sha3_256, key, EncryptionKeyTag);\n\t\tfor (let i = 0; i * blockSize < msg.length; i++) {\n\t\t\tconst block = msg.slice(i * blockSize, (i + 1) * blockSize);\n\t\t\tlet mask = hmac(sha3_256, encryptionKey, 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 Uint8Array([1]);\nconst MacKeyTag = new Uint8Array([2]);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AACpB,mBAA2B;AAC3B,kBAAqB;AACrB,kBAAyB;AAGzB,mBAAuC;AACvC,IAAAA,gBAA6B;AAGtB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oCAAuB,eAAe,GAAG,EAAE;AAAA,IACtD;AACA,WAAO,WAAW,iBAAiB,KAAK,IAAI;AAAA,EAC7C;AAAA,EAEA,OAAe,WAAW,KAAiB,KAAiB,YAAoC;AAC/F,UAAM,aAAS,kBAAK,sBAAU,KAAK,SAAS;AAC5C,UAAM,WAAW,IAAI,WAAW,CAAC,GAAG,QAAQ,IAAI,MAAM,GAAG,GAAG,KAAK,GAAG,UAAU,CAAC;AAC/E,UAAM,UAAM,kBAAK,sBAAU,QAAQ,QAAQ;AAC3C,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,iBAAiB,KAAiB,KAA6B;AAC7E,UAAM,YAAY;AAClB,QAAI,SAAS,WAAW,KAAK,EAAE,QAAQ,IAAI,OAAO,GAAG,MAAM,CAAC;AAC5D,UAAM,oBAAgB,kBAAK,sBAAU,KAAK,gBAAgB;AAC1D,aAAS,IAAI,GAAG,IAAI,YAAY,IAAI,QAAQ,KAAK;AAChD,YAAM,QAAQ,IAAI,MAAM,IAAI,YAAY,IAAI,KAAK,SAAS;AAC1D,UAAI,WAAO,kBAAK,sBAAU,eAAe,QAAQ,CAAC,CAAC;AACnD,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,WAAW,CAAC,CAAC,CAAC;AAC3C,MAAM,YAAY,IAAI,WAAW,CAAC,CAAC,CAAC;",
|
|
6
|
+
"names": ["import_utils"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decrypt a ciphertext with a given secret key. The secret key must be a 32-byte scalar.
|
|
3
|
+
* The ciphertext is a pair of G1Elements (48 bytes).
|
|
4
|
+
*/
|
|
5
|
+
export declare function elgamalDecrypt(sk: Uint8Array, ciphertext: [Uint8Array, Uint8Array]): Uint8Array;
|
|
6
|
+
/** Generate a random secret key. */
|
|
7
|
+
export declare function generateSecretKey(): Uint8Array;
|
|
8
|
+
/** Derive the BLS public key for a given secret key. */
|
|
9
|
+
export declare function toPublicKey(sk: Uint8Array): Uint8Array;
|
|
10
|
+
/** Derive the BLS verification key for a given secret key. */
|
|
11
|
+
export declare function toVerificationKey(sk: Uint8Array): Uint8Array;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var elgamal_exports = {};
|
|
20
|
+
__export(elgamal_exports, {
|
|
21
|
+
elgamalDecrypt: () => elgamalDecrypt,
|
|
22
|
+
generateSecretKey: () => generateSecretKey,
|
|
23
|
+
toPublicKey: () => toPublicKey,
|
|
24
|
+
toVerificationKey: () => toVerificationKey
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(elgamal_exports);
|
|
27
|
+
var import_bls12381 = require("./bls12381.js");
|
|
28
|
+
function elgamalDecrypt(sk, ciphertext) {
|
|
29
|
+
return decrypt(import_bls12381.Scalar.fromBytes(sk), [
|
|
30
|
+
import_bls12381.G1Element.fromBytes(ciphertext[0]),
|
|
31
|
+
import_bls12381.G1Element.fromBytes(ciphertext[1])
|
|
32
|
+
]).toBytes();
|
|
33
|
+
}
|
|
34
|
+
function decrypt(sk, encryption) {
|
|
35
|
+
return encryption[1].subtract(encryption[0].multiply(sk));
|
|
36
|
+
}
|
|
37
|
+
function generateSecretKey() {
|
|
38
|
+
return import_bls12381.Scalar.random().toBytes();
|
|
39
|
+
}
|
|
40
|
+
function toPublicKey(sk) {
|
|
41
|
+
return import_bls12381.G1Element.generator().multiply(import_bls12381.Scalar.fromBytes(sk)).toBytes();
|
|
42
|
+
}
|
|
43
|
+
function toVerificationKey(sk) {
|
|
44
|
+
return import_bls12381.G2Element.generator().multiply(import_bls12381.Scalar.fromBytes(sk)).toBytes();
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=elgamal.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/elgamal.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { G1Element, G2Element, Scalar } from './bls12381.js';\n\n/**\n * Decrypt a ciphertext with a given secret key. The secret key must be a 32-byte scalar.\n * The ciphertext is a pair of G1Elements (48 bytes).\n */\nexport function elgamalDecrypt(sk: Uint8Array, ciphertext: [Uint8Array, Uint8Array]): Uint8Array {\n\treturn decrypt(Scalar.fromBytes(sk), [\n\t\tG1Element.fromBytes(ciphertext[0]),\n\t\tG1Element.fromBytes(ciphertext[1]),\n\t]).toBytes();\n}\n\n/**\n * Decrypt a ciphertext with a given secret key. The secret key must be a 32-byte scalar.\n * The ciphertext is a pair of G1Elements (48 bytes).\n */\nfunction decrypt(sk: Scalar, encryption: [G1Element, G1Element]): G1Element {\n\treturn encryption[1].subtract(encryption[0].multiply(sk));\n}\n\n/** Generate a random secret key. */\nexport function generateSecretKey(): Uint8Array {\n\treturn Scalar.random().toBytes();\n}\n\n/** Derive the BLS public key for a given secret key. */\nexport function toPublicKey(sk: Uint8Array): Uint8Array {\n\treturn G1Element.generator().multiply(Scalar.fromBytes(sk)).toBytes();\n}\n\n/** Derive the BLS verification key for a given secret key. */\nexport function toVerificationKey(sk: Uint8Array): Uint8Array {\n\treturn G2Element.generator().multiply(Scalar.fromBytes(sk)).toBytes();\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA6C;AAMtC,SAAS,eAAe,IAAgB,YAAkD;AAChG,SAAO,QAAQ,uBAAO,UAAU,EAAE,GAAG;AAAA,IACpC,0BAAU,UAAU,WAAW,CAAC,CAAC;AAAA,IACjC,0BAAU,UAAU,WAAW,CAAC,CAAC;AAAA,EAClC,CAAC,EAAE,QAAQ;AACZ;AAMA,SAAS,QAAQ,IAAY,YAA+C;AAC3E,SAAO,WAAW,CAAC,EAAE,SAAS,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC;AACzD;AAGO,SAAS,oBAAgC;AAC/C,SAAO,uBAAO,OAAO,EAAE,QAAQ;AAChC;AAGO,SAAS,YAAY,IAA4B;AACvD,SAAO,0BAAU,UAAU,EAAE,SAAS,uBAAO,UAAU,EAAE,CAAC,EAAE,QAAQ;AACrE;AAGO,SAAS,kBAAkB,IAA4B;AAC7D,SAAO,0BAAU,UAAU,EAAE,SAAS,uBAAO,UAAU,EAAE,CAAC,EAAE,QAAQ;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { EncryptionInput } from './dem.js';
|
|
2
|
+
import type { KeyServer } from './key-server.js';
|
|
3
|
+
export declare const MAX_U8 = 255;
|
|
4
|
+
/**
|
|
5
|
+
* 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
|
+
*
|
|
7
|
+
* @param keyServers - A list of KeyServers (same server can be used multiple times)
|
|
8
|
+
* @param kemType - The type of KEM to use.
|
|
9
|
+
* @param packageId - packageId
|
|
10
|
+
* @param id - id
|
|
11
|
+
* @param encryptionInput - Input to the encryption. Should be one of the EncryptionInput types, AesGcmEncryptionInput or Plain.
|
|
12
|
+
* @param threshold - The threshold for the TSS encryption.
|
|
13
|
+
* @returns The bcs bytes of the encrypted object containing all metadata and the 256-bit symmetric key that was used to encrypt the object.
|
|
14
|
+
* Since the key can be used to decrypt, it should not be shared but can be used eg. for backup.
|
|
15
|
+
*/
|
|
16
|
+
export declare function encrypt({ keyServers, kemType, threshold, packageId, id, encryptionInput, }: {
|
|
17
|
+
keyServers: KeyServer[];
|
|
18
|
+
kemType: KemType;
|
|
19
|
+
threshold: number;
|
|
20
|
+
packageId: string;
|
|
21
|
+
id: string;
|
|
22
|
+
encryptionInput: EncryptionInput;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
encryptedObject: Uint8Array;
|
|
25
|
+
key: Uint8Array;
|
|
26
|
+
}>;
|
|
27
|
+
export declare enum KemType {
|
|
28
|
+
BonehFranklinBLS12381DemCCA = 0
|
|
29
|
+
}
|
|
30
|
+
export declare enum DemType {
|
|
31
|
+
AesGcm256 = 0,
|
|
32
|
+
Hmac256Ctr = 1
|
|
33
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var encrypt_exports = {};
|
|
20
|
+
__export(encrypt_exports, {
|
|
21
|
+
DemType: () => DemType,
|
|
22
|
+
KemType: () => KemType,
|
|
23
|
+
MAX_U8: () => MAX_U8,
|
|
24
|
+
encrypt: () => encrypt
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(encrypt_exports);
|
|
27
|
+
var import_bcs = require("@mysten/bcs");
|
|
28
|
+
var import_utils = require("@mysten/sui/utils");
|
|
29
|
+
var import_shamir_secret_sharing = require("shamir-secret-sharing");
|
|
30
|
+
var import_bcs2 = require("./bcs.js");
|
|
31
|
+
var import_error = require("./error.js");
|
|
32
|
+
var import_ibe = require("./ibe.js");
|
|
33
|
+
var import_kdf = require("./kdf.js");
|
|
34
|
+
var import_utils2 = require("./utils.js");
|
|
35
|
+
const MAX_U8 = 255;
|
|
36
|
+
async function encrypt({
|
|
37
|
+
keyServers,
|
|
38
|
+
kemType,
|
|
39
|
+
threshold,
|
|
40
|
+
packageId,
|
|
41
|
+
id,
|
|
42
|
+
encryptionInput
|
|
43
|
+
}) {
|
|
44
|
+
if (keyServers.length < threshold || threshold === 0 || keyServers.length > MAX_U8 || threshold > MAX_U8 || !(0, import_utils.isValidSuiObjectId)(packageId)) {
|
|
45
|
+
throw new import_error.UserError(
|
|
46
|
+
`Invalid key servers or threshold ${threshold} for ${keyServers.length} key servers for package ${packageId}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
const key = await encryptionInput.generateKey();
|
|
50
|
+
const demKey = (0, import_kdf.deriveKey)(import_kdf.KeyPurpose.DEM, key);
|
|
51
|
+
const ciphertext = await encryptionInput.encrypt(demKey);
|
|
52
|
+
const shares = await split(key, keyServers.length, threshold);
|
|
53
|
+
const fullId = (0, import_utils2.createFullId)(import_ibe.DST, packageId, id);
|
|
54
|
+
const encryptedShares = encryptBatched(
|
|
55
|
+
keyServers,
|
|
56
|
+
kemType,
|
|
57
|
+
(0, import_bcs.fromHex)(fullId),
|
|
58
|
+
shares.map(({ share, index }) => ({
|
|
59
|
+
msg: share,
|
|
60
|
+
index
|
|
61
|
+
})),
|
|
62
|
+
(0, import_kdf.deriveKey)(import_kdf.KeyPurpose.EncryptedRandomness, key)
|
|
63
|
+
);
|
|
64
|
+
const services = keyServers.map((server, i) => [
|
|
65
|
+
server.objectId,
|
|
66
|
+
shares[i].index
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
encryptedObject: import_bcs2.EncryptedObject.serialize({
|
|
70
|
+
version: 0,
|
|
71
|
+
packageId,
|
|
72
|
+
id,
|
|
73
|
+
services,
|
|
74
|
+
threshold,
|
|
75
|
+
encryptedShares,
|
|
76
|
+
ciphertext
|
|
77
|
+
}).toBytes(),
|
|
78
|
+
key: demKey
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var KemType = /* @__PURE__ */ ((KemType2) => {
|
|
82
|
+
KemType2[KemType2["BonehFranklinBLS12381DemCCA"] = 0] = "BonehFranklinBLS12381DemCCA";
|
|
83
|
+
return KemType2;
|
|
84
|
+
})(KemType || {});
|
|
85
|
+
var DemType = /* @__PURE__ */ ((DemType2) => {
|
|
86
|
+
DemType2[DemType2["AesGcm256"] = 0] = "AesGcm256";
|
|
87
|
+
DemType2[DemType2["Hmac256Ctr"] = 1] = "Hmac256Ctr";
|
|
88
|
+
return DemType2;
|
|
89
|
+
})(DemType || {});
|
|
90
|
+
function encryptBatched(keyServers, kemType, id, shares, randomnessKey) {
|
|
91
|
+
switch (kemType) {
|
|
92
|
+
case 0 /* BonehFranklinBLS12381DemCCA */:
|
|
93
|
+
return new import_ibe.BonehFranklinBLS12381Services(keyServers).encryptBatched(
|
|
94
|
+
id,
|
|
95
|
+
shares,
|
|
96
|
+
randomnessKey
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function split(secret, n, threshold) {
|
|
101
|
+
if (n === 0 || threshold === 0 || threshold > n) {
|
|
102
|
+
throw new Error("Invalid threshold or number of shares");
|
|
103
|
+
} else if (threshold === 1) {
|
|
104
|
+
const result = [];
|
|
105
|
+
for (let i = 0; i < n; i++) {
|
|
106
|
+
result.push({ share: secret, index: i });
|
|
107
|
+
}
|
|
108
|
+
return Promise.resolve(result);
|
|
109
|
+
}
|
|
110
|
+
return (0, import_shamir_secret_sharing.split)(secret, n, threshold).then(
|
|
111
|
+
(share) => share.map((s) => ({
|
|
112
|
+
share: s.subarray(0, s.length - 1),
|
|
113
|
+
// split() returns the share index in the last byte
|
|
114
|
+
index: s[s.length - 1]
|
|
115
|
+
}))
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=encrypt.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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';\nimport { split as externalSplit } from 'shamir-secret-sharing';\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, DST } from './ibe.js';\nimport { deriveKey, KeyPurpose } from './kdf.js';\nimport type { KeyServer } from './key-server.js';\nimport { createFullId } from './utils.js';\n\nexport const MAX_U8 = 255;\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\tkeyServers.length < threshold ||\n\t\tthreshold === 0 ||\n\t\tkeyServers.length > MAX_U8 ||\n\t\tthreshold > 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 symmetric key and encrypt the encryption input using this key.\n\tconst key = await encryptionInput.generateKey();\n\tconst demKey = deriveKey(KeyPurpose.DEM, key);\n\tconst ciphertext = await encryptionInput.encrypt(demKey);\n\n\t// Split the symmetric key into shares and encrypt each share with the public keys of the key servers.\n\tconst shares = await split(key, keyServers.length, threshold);\n\n\t// Encrypt the shares with the public keys of the key servers.\n\tconst fullId = createFullId(DST, 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\tderiveKey(KeyPurpose.EncryptedRandomness, key),\n\t);\n\n\t// Services and indices of their shares are stored as a tuple\n\tconst services: [string, number][] = keyServers.map((server, i) => [\n\t\tserver.objectId,\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\tshares: { msg: Uint8Array; index: number }[],\n\trandomnessKey: Uint8Array,\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\tshares,\n\t\t\t\trandomnessKey,\n\t\t\t);\n\t}\n}\n\nasync function split(\n\tsecret: Uint8Array,\n\tn: number,\n\tthreshold: number,\n): Promise<{ index: number; share: Uint8Array }[]> {\n\t// The externalSplit function is from the 'shamir-secret-sharing' package and requires t > 1 and n >= 2.\n\t// So we handle the special cases here.\n\tif (n === 0 || threshold === 0 || threshold > n) {\n\t\tthrow new Error('Invalid threshold or number of shares');\n\t} else if (threshold === 1) {\n\t\t// If the threshold is 1, the secret is not split.\n\t\tconst result = [];\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\t// The shared polynomial is a constant in this case, so the index doesn't matter.\n\t\t\t// To make sure they are unique, we use a counter.\n\t\t\tresult.push({ share: secret, index: i });\n\t\t}\n\t\treturn Promise.resolve(result);\n\t}\n\n\treturn externalSplit(secret, n, threshold).then((share) =>\n\t\tshare.map((s) => ({\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
+
export declare class SealError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class UserError extends SealError {
|
|
4
|
+
}
|
|
5
|
+
export declare class SealAPIError extends SealError {
|
|
6
|
+
#private;
|
|
7
|
+
requestId?: string | undefined;
|
|
8
|
+
status?: number | undefined;
|
|
9
|
+
constructor(message: string, requestId?: string | undefined, status?: number | undefined);
|
|
10
|
+
static assertResponse(response: Response, requestId: string): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare class InvalidPTBError extends SealAPIError {
|
|
13
|
+
constructor(requestId?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class InvalidPackageError extends SealAPIError {
|
|
16
|
+
constructor(requestId?: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class OldPackageError extends SealAPIError {
|
|
19
|
+
constructor(requestId?: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class InvalidUserSignatureError extends SealAPIError {
|
|
22
|
+
constructor(requestId?: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class InvalidSessionKeySignatureError extends SealAPIError {
|
|
25
|
+
constructor(requestId?: string);
|
|
26
|
+
}
|
|
27
|
+
/** Server error indicating that the user does not have access to one or more of the requested keys */
|
|
28
|
+
export declare class NoAccessError extends SealAPIError {
|
|
29
|
+
constructor(requestId?: string);
|
|
30
|
+
}
|
|
31
|
+
/** Server error indicating that the session key has expired */
|
|
32
|
+
export declare class ExpiredSessionKeyError extends SealAPIError {
|
|
33
|
+
constructor(requestId?: string);
|
|
34
|
+
}
|
|
35
|
+
/** Internal server error, caller should retry */
|
|
36
|
+
export declare class InternalError extends SealAPIError {
|
|
37
|
+
constructor(requestId?: string);
|
|
38
|
+
}
|
|
39
|
+
/** General server errors that are not specific to the Seal API (e.g., 404 "Not Found") */
|
|
40
|
+
export declare class GeneralError extends SealAPIError {
|
|
41
|
+
}
|
|
42
|
+
export declare class InvalidPersonalMessageSignatureError extends UserError {
|
|
43
|
+
}
|
|
44
|
+
export declare class InvalidGetObjectError extends UserError {
|
|
45
|
+
}
|
|
46
|
+
export declare class UnsupportedFeatureError extends UserError {
|
|
47
|
+
}
|
|
48
|
+
export declare class UnsupportedNetworkError extends UserError {
|
|
49
|
+
}
|
|
50
|
+
export declare class InvalidKeyServerError extends UserError {
|
|
51
|
+
}
|
|
52
|
+
export declare class InvalidCiphertextError extends UserError {
|
|
53
|
+
}
|
|
54
|
+
export declare class InvalidThresholdError extends UserError {
|
|
55
|
+
}
|
|
56
|
+
export declare class InconsistentKeyServersError extends UserError {
|
|
57
|
+
}
|
|
58
|
+
export declare function toMajorityError(errors: Error[]): Error;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
24
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
25
|
+
var error_exports = {};
|
|
26
|
+
__export(error_exports, {
|
|
27
|
+
ExpiredSessionKeyError: () => ExpiredSessionKeyError,
|
|
28
|
+
GeneralError: () => GeneralError,
|
|
29
|
+
InconsistentKeyServersError: () => InconsistentKeyServersError,
|
|
30
|
+
InternalError: () => InternalError,
|
|
31
|
+
InvalidCiphertextError: () => InvalidCiphertextError,
|
|
32
|
+
InvalidGetObjectError: () => InvalidGetObjectError,
|
|
33
|
+
InvalidKeyServerError: () => InvalidKeyServerError,
|
|
34
|
+
InvalidPTBError: () => InvalidPTBError,
|
|
35
|
+
InvalidPackageError: () => InvalidPackageError,
|
|
36
|
+
InvalidPersonalMessageSignatureError: () => InvalidPersonalMessageSignatureError,
|
|
37
|
+
InvalidSessionKeySignatureError: () => InvalidSessionKeySignatureError,
|
|
38
|
+
InvalidThresholdError: () => InvalidThresholdError,
|
|
39
|
+
InvalidUserSignatureError: () => InvalidUserSignatureError,
|
|
40
|
+
NoAccessError: () => NoAccessError,
|
|
41
|
+
OldPackageError: () => OldPackageError,
|
|
42
|
+
SealAPIError: () => SealAPIError,
|
|
43
|
+
SealError: () => SealError,
|
|
44
|
+
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
45
|
+
UnsupportedNetworkError: () => UnsupportedNetworkError,
|
|
46
|
+
UserError: () => UserError,
|
|
47
|
+
toMajorityError: () => toMajorityError
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(error_exports);
|
|
50
|
+
var _SealAPIError_static, generate_fn;
|
|
51
|
+
class SealError extends Error {
|
|
52
|
+
}
|
|
53
|
+
class UserError extends SealError {
|
|
54
|
+
}
|
|
55
|
+
const _SealAPIError = class _SealAPIError extends SealError {
|
|
56
|
+
constructor(message, requestId, status) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.requestId = requestId;
|
|
59
|
+
this.status = status;
|
|
60
|
+
}
|
|
61
|
+
static async assertResponse(response, requestId) {
|
|
62
|
+
var _a;
|
|
63
|
+
if (response.ok) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
let errorInstance;
|
|
67
|
+
try {
|
|
68
|
+
const text = await response.text();
|
|
69
|
+
const error = JSON.parse(text)["error"];
|
|
70
|
+
errorInstance = __privateMethod(_a = _SealAPIError, _SealAPIError_static, generate_fn).call(_a, error, requestId);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
errorInstance = new GeneralError(response.statusText, requestId, response.status);
|
|
73
|
+
}
|
|
74
|
+
throw errorInstance;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
_SealAPIError_static = new WeakSet();
|
|
78
|
+
generate_fn = function(message, requestId, status) {
|
|
79
|
+
switch (message) {
|
|
80
|
+
case "InvalidPTB":
|
|
81
|
+
return new InvalidPTBError(requestId);
|
|
82
|
+
case "InvalidPackage":
|
|
83
|
+
return new InvalidPackageError(requestId);
|
|
84
|
+
case "NoAccess":
|
|
85
|
+
return new NoAccessError(requestId);
|
|
86
|
+
case "InvalidCertificate":
|
|
87
|
+
return new ExpiredSessionKeyError(requestId);
|
|
88
|
+
case "OldPackageVersion":
|
|
89
|
+
return new OldPackageError(requestId);
|
|
90
|
+
case "InvalidSignature":
|
|
91
|
+
return new InvalidUserSignatureError(requestId);
|
|
92
|
+
case "InvalidSessionSignature":
|
|
93
|
+
return new InvalidSessionKeySignatureError(requestId);
|
|
94
|
+
case "Failure":
|
|
95
|
+
return new InternalError(requestId);
|
|
96
|
+
default:
|
|
97
|
+
return new GeneralError(message, requestId, status);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__privateAdd(_SealAPIError, _SealAPIError_static);
|
|
101
|
+
let SealAPIError = _SealAPIError;
|
|
102
|
+
class InvalidPTBError extends SealAPIError {
|
|
103
|
+
constructor(requestId) {
|
|
104
|
+
super("PTB does not conform to the expected format", requestId);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
class InvalidPackageError extends SealAPIError {
|
|
108
|
+
constructor(requestId) {
|
|
109
|
+
super("Package ID used in PTB is invalid", requestId);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class OldPackageError extends SealAPIError {
|
|
113
|
+
constructor(requestId) {
|
|
114
|
+
super("PTB must call the latest version of the package", requestId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class InvalidUserSignatureError extends SealAPIError {
|
|
118
|
+
constructor(requestId) {
|
|
119
|
+
super("User signature on the session key is invalid", requestId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
class InvalidSessionKeySignatureError extends SealAPIError {
|
|
123
|
+
constructor(requestId) {
|
|
124
|
+
super("Session key signature is invalid", requestId);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
class NoAccessError extends SealAPIError {
|
|
128
|
+
constructor(requestId) {
|
|
129
|
+
super("User does not have access to one or more of the requested keys", requestId);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class ExpiredSessionKeyError extends SealAPIError {
|
|
133
|
+
constructor(requestId) {
|
|
134
|
+
super("Session key has expired", requestId);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class InternalError extends SealAPIError {
|
|
138
|
+
constructor(requestId) {
|
|
139
|
+
super("Internal server error, caller should retry", requestId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
class GeneralError extends SealAPIError {
|
|
143
|
+
}
|
|
144
|
+
class InvalidPersonalMessageSignatureError extends UserError {
|
|
145
|
+
}
|
|
146
|
+
class InvalidGetObjectError extends UserError {
|
|
147
|
+
}
|
|
148
|
+
class UnsupportedFeatureError extends UserError {
|
|
149
|
+
}
|
|
150
|
+
class UnsupportedNetworkError extends UserError {
|
|
151
|
+
}
|
|
152
|
+
class InvalidKeyServerError extends UserError {
|
|
153
|
+
}
|
|
154
|
+
class InvalidCiphertextError extends UserError {
|
|
155
|
+
}
|
|
156
|
+
class InvalidThresholdError extends UserError {
|
|
157
|
+
}
|
|
158
|
+
class InconsistentKeyServersError extends UserError {
|
|
159
|
+
}
|
|
160
|
+
function toMajorityError(errors) {
|
|
161
|
+
let maxCount = 0;
|
|
162
|
+
let majorityError = errors[0];
|
|
163
|
+
const counts = /* @__PURE__ */ new Map();
|
|
164
|
+
for (const error of errors) {
|
|
165
|
+
const errorName = error.constructor.name;
|
|
166
|
+
const newCount = (counts.get(errorName) || 0) + 1;
|
|
167
|
+
counts.set(errorName, newCount);
|
|
168
|
+
if (newCount > maxCount) {
|
|
169
|
+
maxCount = newCount;
|
|
170
|
+
majorityError = error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return majorityError;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/error.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport class SealError extends Error {}\n\nexport class UserError extends SealError {}\n\n// Errors returned by the Seal server\nexport class SealAPIError extends SealError {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic requestId?: string,\n\t\tpublic status?: number,\n\t) {\n\t\tsuper(message);\n\t}\n\n\tstatic #generate(message: string, requestId: string, status?: number) {\n\t\tswitch (message) {\n\t\t\tcase 'InvalidPTB':\n\t\t\t\treturn new InvalidPTBError(requestId);\n\t\t\tcase 'InvalidPackage':\n\t\t\t\treturn new InvalidPackageError(requestId);\n\t\t\tcase 'NoAccess':\n\t\t\t\treturn new NoAccessError(requestId);\n\t\t\tcase 'InvalidCertificate':\n\t\t\t\treturn new ExpiredSessionKeyError(requestId);\n\t\t\tcase 'OldPackageVersion':\n\t\t\t\treturn new OldPackageError(requestId);\n\t\t\tcase 'InvalidSignature':\n\t\t\t\treturn new InvalidUserSignatureError(requestId);\n\t\t\tcase 'InvalidSessionSignature':\n\t\t\t\treturn new InvalidSessionKeySignatureError(requestId);\n\t\t\tcase 'Failure':\n\t\t\t\treturn new InternalError(requestId);\n\t\t\tdefault:\n\t\t\t\treturn new GeneralError(message, requestId, status);\n\t\t}\n\t}\n\n\tstatic async assertResponse(response: Response, requestId: string) {\n\t\tif (response.ok) {\n\t\t\treturn;\n\t\t}\n\t\tlet errorInstance: SealAPIError;\n\t\ttry {\n\t\t\tconst text = await response.text();\n\t\t\tconst error = JSON.parse(text)['error'];\n\t\t\terrorInstance = SealAPIError.#generate(error, requestId);\n\t\t} catch (e) {\n\t\t\t// If we can't parse the response as JSON or if it doesn't have the expected format,\n\t\t\t// fall back to using the status text\n\t\t\terrorInstance = new GeneralError(response.statusText, requestId, response.status);\n\t\t}\n\t\tthrow errorInstance;\n\t}\n}\n\n// Errors returned by the Seal server that indicate that the PTB is invalid\n\nexport class InvalidPTBError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('PTB does not conform to the expected format', requestId);\n\t}\n}\n\nexport class InvalidPackageError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('Package ID used in PTB is invalid', requestId);\n\t}\n}\n\nexport class OldPackageError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('PTB must call the latest version of the package', requestId);\n\t}\n}\n\n// Errors returned by the Seal server that indicate that the user's signature is invalid\n\nexport class InvalidUserSignatureError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('User signature on the session key is invalid', requestId);\n\t}\n}\n\nexport class InvalidSessionKeySignatureError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('Session key signature is invalid', requestId);\n\t}\n}\n\n/** Server error indicating that the user does not have access to one or more of the requested keys */\nexport class NoAccessError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('User does not have access to one or more of the requested keys', requestId);\n\t}\n}\n\n/** Server error indicating that the session key has expired */\nexport class ExpiredSessionKeyError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('Session key has expired', requestId);\n\t}\n}\n\n/** Internal server error, caller should retry */\nexport class InternalError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('Internal server error, caller should retry', requestId);\n\t}\n}\n\n/** General server errors that are not specific to the Seal API (e.g., 404 \"Not Found\") */\nexport class GeneralError extends SealAPIError {}\n\n// Errors returned by the SDK\nexport class InvalidPersonalMessageSignatureError extends UserError {}\nexport class InvalidGetObjectError extends UserError {}\nexport class UnsupportedFeatureError extends UserError {}\nexport class UnsupportedNetworkError extends UserError {}\nexport class InvalidKeyServerError extends UserError {}\nexport class InvalidCiphertextError extends UserError {}\nexport class InvalidThresholdError extends UserError {}\nexport class InconsistentKeyServersError extends UserError {}\n\nexport function toMajorityError(errors: Error[]): Error {\n\tlet maxCount = 0;\n\tlet majorityError = errors[0];\n\tconst counts = new Map<string, number>();\n\tfor (const error of errors) {\n\t\tconst errorName = error.constructor.name;\n\t\tconst newCount = (counts.get(errorName) || 0) + 1;\n\t\tcounts.set(errorName, newCount);\n\n\t\tif (newCount > maxCount) {\n\t\t\tmaxCount = newCount;\n\t\t\tmajorityError = error;\n\t\t}\n\t}\n\n\treturn majorityError;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,kBAAkB,MAAM;AAAC;AAE/B,MAAM,kBAAkB,UAAU;AAAC;AAGnC,MAAM,gBAAN,MAAM,sBAAqB,UAAU;AAAA,EAC3C,YACC,SACO,WACA,QACN;AACD,UAAM,OAAO;AAHN;AACA;AAAA,EAGR;AAAA,EAyBA,aAAa,eAAe,UAAoB,WAAmB;AAxCpE;AAyCE,QAAI,SAAS,IAAI;AAChB;AAAA,IACD;AACA,QAAI;AACJ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AAwC,aAAa;AAAA,EACjE,YAAY,WAAoB;AAC/B,UAAM,oCAAoC,SAAS;AAAA,EACpD;AACD;AAGO,MAAM,sBAAsB,aAAa;AAAA,EAC/C,YAAY,WAAoB;AAC/B,UAAM,kEAAkE,SAAS;AAAA,EAClF;AACD;AAGO,MAAM,+BAA+B,aAAa;AAAA,EACxD,YAAY,WAAoB;AAC/B,UAAM,2BAA2B,SAAS;AAAA,EAC3C;AACD;AAGO,MAAM,sBAAsB,aAAa;AAAA,EAC/C,YAAY,WAAoB;AAC/B,UAAM,8CAA8C,SAAS;AAAA,EAC9D;AACD;AAGO,MAAM,qBAAqB,aAAa;AAAC;AAGzC,MAAM,6CAA6C,UAAU;AAAC;AAC9D,MAAM,8BAA8B,UAAU;AAAC;AAC/C,MAAM,gCAAgC,UAAU;AAAC;AACjD,MAAM,gCAAgC,UAAU;AAAC;AACjD,MAAM,8BAA8B,UAAU;AAAC;AAC/C,MAAM,+BAA+B,UAAU;AAAC;AAChD,MAAM,8BAA8B,UAAU;AAAC;AAC/C,MAAM,oCAAoC,UAAU;AAAC;AAErD,SAAS,gBAAgB,QAAwB;AACvD,MAAI,WAAW;AACf,MAAI,gBAAgB,OAAO,CAAC;AAC5B,QAAM,SAAS,oBAAI,IAAoB;AACvC,aAAW,SAAS,QAAQ;AAC3B,UAAM,YAAY,MAAM,YAAY;AACpC,UAAM,YAAY,OAAO,IAAI,SAAS,KAAK,KAAK;AAChD,WAAO,IAAI,WAAW,QAAQ;AAE9B,QAAI,WAAW,UAAU;AACxB,iBAAW;AACX,sBAAgB;AAAA,IACjB;AAAA,EACD;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { IBEEncryptions } from './bcs.js';
|
|
2
|
+
import { G1Element, G2Element } from './bls12381.js';
|
|
3
|
+
import type { KeyServer } from './key-server.js';
|
|
4
|
+
/**
|
|
5
|
+
* The domain separation tag for the hash-to-group function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DST: Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* The domain separation tag for the signing proof of possession.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DST_POP: Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* The interface for the key servers.
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class IBEServers {
|
|
16
|
+
objectIds: string[];
|
|
17
|
+
constructor(objectIds: string[]);
|
|
18
|
+
/**
|
|
19
|
+
* The number of key servers.
|
|
20
|
+
*/
|
|
21
|
+
size(): number;
|
|
22
|
+
/**
|
|
23
|
+
* Encrypt a batch of messages for the given identity.
|
|
24
|
+
*
|
|
25
|
+
* @param id The identity.
|
|
26
|
+
* @param msgAndIndices The messages and the corresponding indices of the share being encrypted.
|
|
27
|
+
* @returns The encrypted messages.
|
|
28
|
+
*/
|
|
29
|
+
abstract encryptBatched(id: Uint8Array, msgAndIndices: {
|
|
30
|
+
msg: Uint8Array;
|
|
31
|
+
index: number;
|
|
32
|
+
}[], randomnessKey: Uint8Array): typeof IBEEncryptions.$inferType;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Identity-based encryption based on the Boneh-Franklin IBE scheme.
|
|
36
|
+
* This object represents a set of key servers that can be used to encrypt messages for a given identity.
|
|
37
|
+
*/
|
|
38
|
+
export declare class BonehFranklinBLS12381Services extends IBEServers {
|
|
39
|
+
readonly publicKeys: G2Element[];
|
|
40
|
+
constructor(services: KeyServer[]);
|
|
41
|
+
encryptBatched(id: Uint8Array, msgAndIndices: {
|
|
42
|
+
msg: Uint8Array;
|
|
43
|
+
index: number;
|
|
44
|
+
}[], randomnessKey: Uint8Array): typeof IBEEncryptions.$inferType;
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if the user secret key is valid for the given public key and id.
|
|
47
|
+
* @param user_secret_key - The user secret key.
|
|
48
|
+
* @param id - The identity.
|
|
49
|
+
* @param public_key - The public key.
|
|
50
|
+
* @returns True if the user secret key is valid for the given public key and id.
|
|
51
|
+
*/
|
|
52
|
+
static verifyUserSecretKey(userSecretKey: G1Element, id: string, publicKey: G2Element): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Identity-based decryption.
|
|
55
|
+
*
|
|
56
|
+
* @param nonce The encryption nonce.
|
|
57
|
+
* @param sk The user secret key.
|
|
58
|
+
* @param ciphertext The encrypted message.
|
|
59
|
+
* @param info An info parameter also included in the KDF.
|
|
60
|
+
* @returns The decrypted message.
|
|
61
|
+
*/
|
|
62
|
+
static decrypt(nonce: G2Element, sk: G1Element, ciphertext: Uint8Array, id: Uint8Array, [objectId, index]: [string, number]): Uint8Array;
|
|
63
|
+
}
|