@haneullabs/seal 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +459 -0
  2. package/README.md +4 -0
  3. package/dist/cjs/bcs.d.ts +71 -0
  4. package/dist/cjs/bcs.js +74 -0
  5. package/dist/cjs/bcs.js.map +7 -0
  6. package/dist/cjs/bls12381.d.ts +44 -0
  7. package/dist/cjs/bls12381.js +151 -0
  8. package/dist/cjs/bls12381.js.map +7 -0
  9. package/dist/cjs/client.d.ts +84 -0
  10. package/dist/cjs/client.js +414 -0
  11. package/dist/cjs/client.js.map +7 -0
  12. package/dist/cjs/decrypt.d.ts +22 -0
  13. package/dist/cjs/decrypt.js +109 -0
  14. package/dist/cjs/decrypt.js.map +7 -0
  15. package/dist/cjs/dem.d.ts +38 -0
  16. package/dist/cjs/dem.js +185 -0
  17. package/dist/cjs/dem.js.map +7 -0
  18. package/dist/cjs/elgamal.d.ts +13 -0
  19. package/dist/cjs/elgamal.js +46 -0
  20. package/dist/cjs/elgamal.js.map +7 -0
  21. package/dist/cjs/encrypt.d.ts +32 -0
  22. package/dist/cjs/encrypt.js +104 -0
  23. package/dist/cjs/encrypt.js.map +7 -0
  24. package/dist/cjs/error.d.ts +86 -0
  25. package/dist/cjs/error.js +239 -0
  26. package/dist/cjs/error.js.map +7 -0
  27. package/dist/cjs/ibe.d.ts +98 -0
  28. package/dist/cjs/ibe.js +167 -0
  29. package/dist/cjs/ibe.js.map +7 -0
  30. package/dist/cjs/index.d.ts +6 -0
  31. package/dist/cjs/index.js +33 -0
  32. package/dist/cjs/index.js.map +7 -0
  33. package/dist/cjs/kdf.d.ts +30 -0
  34. package/dist/cjs/kdf.js +97 -0
  35. package/dist/cjs/kdf.js.map +7 -0
  36. package/dist/cjs/key-server.d.ts +98 -0
  37. package/dist/cjs/key-server.js +171 -0
  38. package/dist/cjs/key-server.js.map +7 -0
  39. package/dist/cjs/package.json +5 -0
  40. package/dist/cjs/session-key.d.ts +74 -0
  41. package/dist/cjs/session-key.js +245 -0
  42. package/dist/cjs/session-key.js.map +7 -0
  43. package/dist/cjs/shamir.d.ts +91 -0
  44. package/dist/cjs/shamir.js +770 -0
  45. package/dist/cjs/shamir.js.map +7 -0
  46. package/dist/cjs/types.d.ts +83 -0
  47. package/dist/cjs/types.js +17 -0
  48. package/dist/cjs/types.js.map +7 -0
  49. package/dist/cjs/utils.d.ts +47 -0
  50. package/dist/cjs/utils.js +106 -0
  51. package/dist/cjs/utils.js.map +7 -0
  52. package/dist/cjs/version.d.ts +1 -0
  53. package/dist/cjs/version.js +25 -0
  54. package/dist/cjs/version.js.map +7 -0
  55. package/dist/esm/bcs.d.ts +71 -0
  56. package/dist/esm/bcs.js +54 -0
  57. package/dist/esm/bcs.js.map +7 -0
  58. package/dist/esm/bls12381.d.ts +44 -0
  59. package/dist/esm/bls12381.js +131 -0
  60. package/dist/esm/bls12381.js.map +7 -0
  61. package/dist/esm/client.d.ts +84 -0
  62. package/dist/esm/client.js +407 -0
  63. package/dist/esm/client.js.map +7 -0
  64. package/dist/esm/decrypt.d.ts +22 -0
  65. package/dist/esm/decrypt.js +94 -0
  66. package/dist/esm/decrypt.js.map +7 -0
  67. package/dist/esm/dem.d.ts +38 -0
  68. package/dist/esm/dem.js +165 -0
  69. package/dist/esm/dem.js.map +7 -0
  70. package/dist/esm/elgamal.d.ts +13 -0
  71. package/dist/esm/elgamal.js +26 -0
  72. package/dist/esm/elgamal.js.map +7 -0
  73. package/dist/esm/encrypt.d.ts +32 -0
  74. package/dist/esm/encrypt.js +84 -0
  75. package/dist/esm/encrypt.js.map +7 -0
  76. package/dist/esm/error.d.ts +86 -0
  77. package/dist/esm/error.js +219 -0
  78. package/dist/esm/error.js.map +7 -0
  79. package/dist/esm/ibe.d.ts +98 -0
  80. package/dist/esm/ibe.js +147 -0
  81. package/dist/esm/ibe.js.map +7 -0
  82. package/dist/esm/index.d.ts +6 -0
  83. package/dist/esm/index.js +12 -0
  84. package/dist/esm/index.js.map +7 -0
  85. package/dist/esm/kdf.d.ts +30 -0
  86. package/dist/esm/kdf.js +83 -0
  87. package/dist/esm/kdf.js.map +7 -0
  88. package/dist/esm/key-server.d.ts +98 -0
  89. package/dist/esm/key-server.js +151 -0
  90. package/dist/esm/key-server.js.map +7 -0
  91. package/dist/esm/package.json +5 -0
  92. package/dist/esm/session-key.d.ts +74 -0
  93. package/dist/esm/session-key.js +230 -0
  94. package/dist/esm/session-key.js.map +7 -0
  95. package/dist/esm/shamir.d.ts +91 -0
  96. package/dist/esm/shamir.js +750 -0
  97. package/dist/esm/shamir.js.map +7 -0
  98. package/dist/esm/types.d.ts +83 -0
  99. package/dist/esm/types.js +1 -0
  100. package/dist/esm/types.js.map +7 -0
  101. package/dist/esm/utils.d.ts +47 -0
  102. package/dist/esm/utils.js +86 -0
  103. package/dist/esm/utils.js.map +7 -0
  104. package/dist/esm/version.d.ts +1 -0
  105. package/dist/esm/version.js +5 -0
  106. package/dist/esm/version.js.map +7 -0
  107. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  108. package/dist/tsconfig.tsbuildinfo +1 -0
  109. package/package.json +58 -0
@@ -0,0 +1,104 @@
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
+ encrypt: () => encrypt
24
+ });
25
+ module.exports = __toCommonJS(encrypt_exports);
26
+ var import_bcs = require("@haneullabs/bcs");
27
+ var import_bcs2 = require("./bcs.js");
28
+ var import_error = require("./error.js");
29
+ var import_ibe = require("./ibe.js");
30
+ var import_kdf = require("./kdf.js");
31
+ var import_utils = require("./utils.js");
32
+ var import_shamir = require("./shamir.js");
33
+ async function encrypt({
34
+ keyServers,
35
+ kemType,
36
+ threshold,
37
+ packageId,
38
+ id,
39
+ encryptionInput
40
+ }) {
41
+ if (threshold <= 0 || threshold >= import_utils.MAX_U8 || keyServers.length < threshold || keyServers.length >= import_utils.MAX_U8) {
42
+ throw new import_error.UserError(
43
+ `Invalid key servers or threshold ${threshold} for ${keyServers.length} key servers for package ${packageId}`
44
+ );
45
+ }
46
+ const baseKey = await encryptionInput.generateKey();
47
+ const shares = (0, import_shamir.split)(baseKey, threshold, keyServers.length);
48
+ const fullId = (0, import_utils.createFullId)(packageId, id);
49
+ const encryptedShares = encryptBatched(
50
+ keyServers,
51
+ kemType,
52
+ (0, import_bcs.fromHex)(fullId),
53
+ shares,
54
+ baseKey,
55
+ threshold
56
+ );
57
+ const demKey = (0, import_kdf.deriveKey)(
58
+ import_kdf.KeyPurpose.DEM,
59
+ baseKey,
60
+ encryptedShares.BonehFranklinBLS12381.encryptedShares,
61
+ threshold,
62
+ keyServers.map(({ objectId }) => objectId)
63
+ );
64
+ const ciphertext = await encryptionInput.encrypt(demKey);
65
+ const services = keyServers.map(({ objectId }, i) => [
66
+ objectId,
67
+ shares[i].index
68
+ ]);
69
+ return {
70
+ encryptedObject: import_bcs2.EncryptedObject.serialize({
71
+ version: 0,
72
+ packageId,
73
+ id,
74
+ services,
75
+ threshold,
76
+ encryptedShares,
77
+ ciphertext
78
+ }).toBytes(),
79
+ key: new Uint8Array(demKey)
80
+ };
81
+ }
82
+ var KemType = /* @__PURE__ */ ((KemType2) => {
83
+ KemType2[KemType2["BonehFranklinBLS12381DemCCA"] = 0] = "BonehFranklinBLS12381DemCCA";
84
+ return KemType2;
85
+ })(KemType || {});
86
+ var DemType = /* @__PURE__ */ ((DemType2) => {
87
+ DemType2[DemType2["AesGcm256"] = 0] = "AesGcm256";
88
+ DemType2[DemType2["Hmac256Ctr"] = 1] = "Hmac256Ctr";
89
+ return DemType2;
90
+ })(DemType || {});
91
+ function encryptBatched(keyServers, kemType, id, shares, baseKey, threshold) {
92
+ switch (kemType) {
93
+ case 0 /* BonehFranklinBLS12381DemCCA */:
94
+ return new import_ibe.BonehFranklinBLS12381Services(keyServers).encryptBatched(
95
+ id,
96
+ shares,
97
+ baseKey,
98
+ threshold
99
+ );
100
+ default:
101
+ throw new Error(`Invalid KEM type ${kemType}`);
102
+ }
103
+ }
104
+ //# 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 '@haneullabs/bcs';\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 type { Share } from './shamir.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 Hmac256CtrEncryptionInput.\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<ArrayBuffer>;\n\tkey: Uint8Array<ArrayBuffer>;\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) {\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,\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: new Uint8Array(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: Share[],\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\tshares,\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;AAGxB,IAAAA,cAAgC;AAEhC,mBAA0B;AAC1B,iBAA8C;AAC9C,iBAAsC;AAEtC,mBAAqC;AAErC,oBAAsB;AActB,eAAsB,QAAQ;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAUG;AAEF,MACC,aAAa,KACb,aAAa,uBACb,WAAW,SAAS,aACpB,WAAW,UAAU,qBACpB;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,2BAAa,WAAW,EAAE;AACzC,QAAM,kBAAkB;AAAA,IACvB;AAAA,IACA;AAAA,QACA,oBAAQ,MAAM;AAAA,IACd;AAAA,IACA;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,IAAI,WAAW,MAAM;AAAA,EAC3B;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,QACA,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
+ "names": ["import_bcs", "KemType", "DemType"]
7
+ }
@@ -0,0 +1,86 @@
1
+ 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, message?: string);
14
+ }
15
+ export declare class InvalidPackageError extends SealAPIError {
16
+ constructor(requestId?: string);
17
+ }
18
+ export declare class InvalidParameterError 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
+ export declare class InvalidMVRNameError extends SealAPIError {
28
+ constructor(requestId?: string);
29
+ }
30
+ /** Server error indicating that the requested key server object id is invalid */
31
+ export declare class InvalidKeyServerObjectIdError extends SealAPIError {
32
+ constructor(requestId?: string);
33
+ }
34
+ /** Server error indicating that the requested package id is not supported (i.e., key server is running in Permissioned mode) */
35
+ export declare class UnsupportedPackageIdError extends SealAPIError {
36
+ constructor(requestId?: string);
37
+ }
38
+ export declare class InvalidSDKVersionError extends SealAPIError {
39
+ constructor(requestId?: string);
40
+ }
41
+ export declare class InvalidSDKTypeError extends SealAPIError {
42
+ constructor(requestId?: string);
43
+ }
44
+ export declare class DeprecatedSDKVersionError extends SealAPIError {
45
+ constructor(requestId?: string);
46
+ }
47
+ /** Server error indicating that the user does not have access to one or more of the requested keys */
48
+ export declare class NoAccessError extends SealAPIError {
49
+ constructor(requestId?: string);
50
+ }
51
+ /** Server error indicating that the session key has expired */
52
+ export declare class ExpiredSessionKeyError extends SealAPIError {
53
+ constructor(requestId?: string);
54
+ }
55
+ /** Internal server error, caller should retry */
56
+ export declare class InternalError extends SealAPIError {
57
+ constructor(requestId?: string);
58
+ }
59
+ /** General server errors that are not specific to the Seal API (e.g., 404 "Not Found") */
60
+ export declare class GeneralError extends SealAPIError {
61
+ }
62
+ export declare class InvalidPersonalMessageSignatureError extends UserError {
63
+ }
64
+ export declare class InvalidGetObjectError extends UserError {
65
+ }
66
+ export declare class UnsupportedFeatureError extends UserError {
67
+ }
68
+ export declare class UnsupportedNetworkError extends UserError {
69
+ }
70
+ export declare class InvalidKeyServerError extends UserError {
71
+ }
72
+ export declare class InvalidKeyServerVersionError extends UserError {
73
+ }
74
+ export declare class InvalidCiphertextError extends UserError {
75
+ }
76
+ export declare class InvalidThresholdError extends UserError {
77
+ }
78
+ export declare class InconsistentKeyServersError extends UserError {
79
+ }
80
+ export declare class DecryptionError extends UserError {
81
+ }
82
+ export declare class InvalidClientOptionsError extends UserError {
83
+ }
84
+ export declare class TooManyFailedFetchKeyRequestsError extends UserError {
85
+ }
86
+ export declare function toMajorityError(errors: Error[]): Error;
@@ -0,0 +1,239 @@
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
+ DecryptionError: () => DecryptionError,
28
+ DeprecatedSDKVersionError: () => DeprecatedSDKVersionError,
29
+ ExpiredSessionKeyError: () => ExpiredSessionKeyError,
30
+ GeneralError: () => GeneralError,
31
+ InconsistentKeyServersError: () => InconsistentKeyServersError,
32
+ InternalError: () => InternalError,
33
+ InvalidCiphertextError: () => InvalidCiphertextError,
34
+ InvalidClientOptionsError: () => InvalidClientOptionsError,
35
+ InvalidGetObjectError: () => InvalidGetObjectError,
36
+ InvalidKeyServerError: () => InvalidKeyServerError,
37
+ InvalidKeyServerObjectIdError: () => InvalidKeyServerObjectIdError,
38
+ InvalidKeyServerVersionError: () => InvalidKeyServerVersionError,
39
+ InvalidMVRNameError: () => InvalidMVRNameError,
40
+ InvalidPTBError: () => InvalidPTBError,
41
+ InvalidPackageError: () => InvalidPackageError,
42
+ InvalidParameterError: () => InvalidParameterError,
43
+ InvalidPersonalMessageSignatureError: () => InvalidPersonalMessageSignatureError,
44
+ InvalidSDKTypeError: () => InvalidSDKTypeError,
45
+ InvalidSDKVersionError: () => InvalidSDKVersionError,
46
+ InvalidSessionKeySignatureError: () => InvalidSessionKeySignatureError,
47
+ InvalidThresholdError: () => InvalidThresholdError,
48
+ InvalidUserSignatureError: () => InvalidUserSignatureError,
49
+ NoAccessError: () => NoAccessError,
50
+ SealAPIError: () => SealAPIError,
51
+ SealError: () => SealError,
52
+ TooManyFailedFetchKeyRequestsError: () => TooManyFailedFetchKeyRequestsError,
53
+ UnsupportedFeatureError: () => UnsupportedFeatureError,
54
+ UnsupportedNetworkError: () => UnsupportedNetworkError,
55
+ UnsupportedPackageIdError: () => UnsupportedPackageIdError,
56
+ UserError: () => UserError,
57
+ toMajorityError: () => toMajorityError
58
+ });
59
+ module.exports = __toCommonJS(error_exports);
60
+ var _SealAPIError_static, generate_fn;
61
+ class SealError extends Error {
62
+ }
63
+ class UserError extends SealError {
64
+ }
65
+ const _SealAPIError = class _SealAPIError extends SealError {
66
+ constructor(message, requestId, status) {
67
+ super(message);
68
+ this.requestId = requestId;
69
+ this.status = status;
70
+ }
71
+ static async assertResponse(response, requestId) {
72
+ var _a;
73
+ if (response.ok) {
74
+ return;
75
+ }
76
+ let errorInstance;
77
+ try {
78
+ const text = await response.text();
79
+ const error = JSON.parse(text)["error"];
80
+ const message = JSON.parse(text)["message"];
81
+ errorInstance = __privateMethod(_a = _SealAPIError, _SealAPIError_static, generate_fn).call(_a, error, message, requestId);
82
+ } catch {
83
+ errorInstance = new GeneralError(response.statusText, requestId, response.status);
84
+ }
85
+ throw errorInstance;
86
+ }
87
+ };
88
+ _SealAPIError_static = new WeakSet();
89
+ generate_fn = function(error, message, requestId, status) {
90
+ switch (error) {
91
+ case "InvalidPTB":
92
+ return new InvalidPTBError(requestId, message);
93
+ case "InvalidPackage":
94
+ return new InvalidPackageError(requestId);
95
+ case "NoAccess":
96
+ return new NoAccessError(requestId);
97
+ case "InvalidSignature":
98
+ return new InvalidUserSignatureError(requestId);
99
+ case "InvalidSessionSignature":
100
+ return new InvalidSessionKeySignatureError(requestId);
101
+ case "InvalidCertificate":
102
+ return new ExpiredSessionKeyError(requestId);
103
+ case "InvalidSDKVersion":
104
+ return new InvalidSDKVersionError(requestId);
105
+ case "InvalidSDKType":
106
+ return new InvalidSDKTypeError(requestId);
107
+ case "DeprecatedSDKVersion":
108
+ return new DeprecatedSDKVersionError(requestId);
109
+ case "InvalidParameter":
110
+ return new InvalidParameterError(requestId);
111
+ case "InvalidMVRName":
112
+ return new InvalidMVRNameError(requestId);
113
+ case "InvalidServiceId":
114
+ return new InvalidKeyServerObjectIdError(requestId);
115
+ case "UnsupportedPackageId":
116
+ return new UnsupportedPackageIdError(requestId);
117
+ case "Failure":
118
+ return new InternalError(requestId);
119
+ default:
120
+ return new GeneralError(message, requestId, status);
121
+ }
122
+ };
123
+ __privateAdd(_SealAPIError, _SealAPIError_static);
124
+ let SealAPIError = _SealAPIError;
125
+ class InvalidPTBError extends SealAPIError {
126
+ constructor(requestId, message) {
127
+ super("PTB does not conform to the expected format " + message, requestId);
128
+ }
129
+ }
130
+ class InvalidPackageError extends SealAPIError {
131
+ constructor(requestId) {
132
+ super("Package ID used in PTB is invalid", requestId);
133
+ }
134
+ }
135
+ class InvalidParameterError extends SealAPIError {
136
+ constructor(requestId) {
137
+ super(
138
+ "PTB contains an invalid parameter, possibly a newly created object that the FN has not yet seen",
139
+ requestId
140
+ );
141
+ }
142
+ }
143
+ class InvalidUserSignatureError extends SealAPIError {
144
+ constructor(requestId) {
145
+ super("User signature on the session key is invalid", requestId);
146
+ }
147
+ }
148
+ class InvalidSessionKeySignatureError extends SealAPIError {
149
+ constructor(requestId) {
150
+ super("Session key signature is invalid", requestId);
151
+ }
152
+ }
153
+ class InvalidMVRNameError extends SealAPIError {
154
+ constructor(requestId) {
155
+ super("MVR name is invalid or not consistent with the first version of the package", requestId);
156
+ }
157
+ }
158
+ class InvalidKeyServerObjectIdError extends SealAPIError {
159
+ constructor(requestId) {
160
+ super("Key server object ID is invalid", requestId);
161
+ }
162
+ }
163
+ class UnsupportedPackageIdError extends SealAPIError {
164
+ constructor(requestId) {
165
+ super("Requested package is not supported", requestId);
166
+ }
167
+ }
168
+ class InvalidSDKVersionError extends SealAPIError {
169
+ constructor(requestId) {
170
+ super("SDK version is invalid", requestId);
171
+ }
172
+ }
173
+ class InvalidSDKTypeError extends SealAPIError {
174
+ constructor(requestId) {
175
+ super("SDK type is invalid", requestId);
176
+ }
177
+ }
178
+ class DeprecatedSDKVersionError extends SealAPIError {
179
+ constructor(requestId) {
180
+ super("SDK version is deprecated", requestId);
181
+ }
182
+ }
183
+ class NoAccessError extends SealAPIError {
184
+ constructor(requestId) {
185
+ super("User does not have access to one or more of the requested keys", requestId);
186
+ }
187
+ }
188
+ class ExpiredSessionKeyError extends SealAPIError {
189
+ constructor(requestId) {
190
+ super("Session key has expired", requestId);
191
+ }
192
+ }
193
+ class InternalError extends SealAPIError {
194
+ constructor(requestId) {
195
+ super("Internal server error, caller should retry", requestId);
196
+ }
197
+ }
198
+ class GeneralError extends SealAPIError {
199
+ }
200
+ class InvalidPersonalMessageSignatureError extends UserError {
201
+ }
202
+ class InvalidGetObjectError extends UserError {
203
+ }
204
+ class UnsupportedFeatureError extends UserError {
205
+ }
206
+ class UnsupportedNetworkError extends UserError {
207
+ }
208
+ class InvalidKeyServerError extends UserError {
209
+ }
210
+ class InvalidKeyServerVersionError extends UserError {
211
+ }
212
+ class InvalidCiphertextError extends UserError {
213
+ }
214
+ class InvalidThresholdError extends UserError {
215
+ }
216
+ class InconsistentKeyServersError extends UserError {
217
+ }
218
+ class DecryptionError extends UserError {
219
+ }
220
+ class InvalidClientOptionsError extends UserError {
221
+ }
222
+ class TooManyFailedFetchKeyRequestsError extends UserError {
223
+ }
224
+ function toMajorityError(errors) {
225
+ let maxCount = 0;
226
+ let majorityError = errors[0];
227
+ const counts = /* @__PURE__ */ new Map();
228
+ for (const error of errors) {
229
+ const errorName = error.constructor.name;
230
+ const newCount = (counts.get(errorName) || 0) + 1;
231
+ counts.set(errorName, newCount);
232
+ if (newCount > maxCount) {
233
+ maxCount = newCount;
234
+ majorityError = error;
235
+ }
236
+ }
237
+ return majorityError;
238
+ }
239
+ //# 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(error: string, message: string, requestId: string, status?: number) {\n\t\tswitch (error) {\n\t\t\tcase 'InvalidPTB':\n\t\t\t\treturn new InvalidPTBError(requestId, message);\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 '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 'InvalidCertificate':\n\t\t\t\treturn new ExpiredSessionKeyError(requestId);\n\t\t\tcase 'InvalidSDKVersion':\n\t\t\t\treturn new InvalidSDKVersionError(requestId);\n\t\t\tcase 'InvalidSDKType':\n\t\t\t\treturn new InvalidSDKTypeError(requestId);\n\t\t\tcase 'DeprecatedSDKVersion':\n\t\t\t\treturn new DeprecatedSDKVersionError(requestId);\n\t\t\tcase 'InvalidParameter':\n\t\t\t\treturn new InvalidParameterError(requestId);\n\t\t\tcase 'InvalidMVRName':\n\t\t\t\treturn new InvalidMVRNameError(requestId);\n\t\t\tcase 'InvalidServiceId':\n\t\t\t\treturn new InvalidKeyServerObjectIdError(requestId);\n\t\t\tcase 'UnsupportedPackageId':\n\t\t\t\treturn new UnsupportedPackageIdError(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\tconst message = JSON.parse(text)['message'];\n\t\t\terrorInstance = SealAPIError.#generate(error, message, requestId);\n\t\t} catch {\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, message?: string) {\n\t\tsuper('PTB does not conform to the expected format ' + message, 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 InvalidParameterError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper(\n\t\t\t'PTB contains an invalid parameter, possibly a newly created object that the FN has not yet seen',\n\t\t\trequestId,\n\t\t);\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\nexport class InvalidMVRNameError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('MVR name is invalid or not consistent with the first version of the package', requestId);\n\t}\n}\n\n/** Server error indicating that the requested key server object id is invalid */\nexport class InvalidKeyServerObjectIdError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('Key server object ID is invalid', requestId);\n\t}\n}\n\n/** Server error indicating that the requested package id is not supported (i.e., key server is running in Permissioned mode) */\nexport class UnsupportedPackageIdError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('Requested package is not supported', requestId);\n\t}\n}\n\n// Errors returned by the Seal server that indicate that the SDK version is invalid (implying that HTTP headers used by the SDK are being removed) or deprecated (implying that the SDK should be upgraded).\n\nexport class InvalidSDKVersionError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('SDK version is invalid', requestId);\n\t}\n}\n\nexport class InvalidSDKTypeError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('SDK type is invalid', requestId);\n\t}\n}\n\nexport class DeprecatedSDKVersionError extends SealAPIError {\n\tconstructor(requestId?: string) {\n\t\tsuper('SDK version is deprecated', 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 InvalidKeyServerVersionError extends UserError {}\nexport class InvalidCiphertextError extends UserError {}\nexport class InvalidThresholdError extends UserError {}\nexport class InconsistentKeyServersError extends UserError {}\nexport class DecryptionError extends UserError {}\nexport class InvalidClientOptionsError extends UserError {}\nexport class TooManyFailedFetchKeyRequestsError 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;AA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IAAI,WAAW,QAAQ;AAE9B,QAAI,WAAW,UAAU;AACxB,iBAAW;AACX,sBAAgB;AAAA,IACjB;AAAA,EACD;AAEA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,98 @@
1
+ import type { IBEEncryptions } from './bcs.js';
2
+ import type { G1Element } from './bls12381.js';
3
+ import { G2Element } from './bls12381.js';
4
+ import type { KeyServer } from './key-server.js';
5
+ import type { Share } from './shamir.js';
6
+ /**
7
+ * The domain separation tag for the signing proof of possession.
8
+ */
9
+ export declare const DST_POP: Uint8Array;
10
+ /**
11
+ * The interface for the key servers.
12
+ */
13
+ export declare abstract class IBEServers {
14
+ objectIds: string[];
15
+ constructor(objectIds: string[]);
16
+ /**
17
+ * Encrypt a batch of messages for the given identity.
18
+ *
19
+ * @param id The identity.
20
+ * @param msgAndIndices The messages and the corresponding indices of the share being encrypted.
21
+ * @returns The encrypted messages.
22
+ */
23
+ abstract encryptBatched(id: Uint8Array, shares: Share[], baseKey: Uint8Array, threshold: number): typeof IBEEncryptions.$inferType;
24
+ }
25
+ /**
26
+ * Identity-based encryption based on the Boneh-Franklin IBE scheme (https://eprint.iacr.org/2001/090).
27
+ * Note that this implementation is of the "BasicIdent" protocol which on its own is not CCA secure, so this IBE implementation should not be used on its own.
28
+ *
29
+ * This object represents a set of key servers that can be used to encrypt messages for a given identity.
30
+ */
31
+ export declare class BonehFranklinBLS12381Services extends IBEServers {
32
+ readonly publicKeys: G2Element[];
33
+ constructor(services: KeyServer[]);
34
+ encryptBatched(id: Uint8Array, shares: Share[], baseKey: Uint8Array, threshold: number): typeof IBEEncryptions.$inferType;
35
+ /**
36
+ * Returns true if the user secret key is valid for the given public key and id.
37
+ * @param user_secret_key - The user secret key.
38
+ * @param id - The identity.
39
+ * @param public_key - The public key.
40
+ * @returns True if the user secret key is valid for the given public key and id.
41
+ */
42
+ static verifyUserSecretKey(userSecretKey: G1Element, id: string, publicKey: G2Element): boolean;
43
+ /**
44
+ * Identity-based decryption.
45
+ *
46
+ * @param nonce The encryption nonce.
47
+ * @param sk The user secret key.
48
+ * @param ciphertext The encrypted message.
49
+ * @param id The identity.
50
+ * @param [objectId, index] The object id and index of the share.
51
+ * @returns The decrypted message.
52
+ */
53
+ static decrypt(nonce: G2Element, sk: G1Element, ciphertext: Uint8Array, id: Uint8Array, [objectId, index]: [string, number]): Uint8Array;
54
+ /**
55
+ * Decrypt all shares and verify that the randomness was used to create the given nonce.
56
+ *
57
+ * @param randomness - The randomness.
58
+ * @param encryptedShares - The encrypted shares.
59
+ * @param services - The services.
60
+ * @param publicKeys - The public keys.
61
+ * @param nonce - The nonce.
62
+ * @param id - The id.
63
+ * @returns All decrypted shares.
64
+ */
65
+ static decryptAllSharesUsingRandomness(randomness: Uint8Array, encryptedShares: Uint8Array[], services: [string, number][], publicKeys: G2Element[], nonce: G2Element, id: Uint8Array): {
66
+ index: number;
67
+ share: Uint8Array;
68
+ }[];
69
+ }
70
+ /**
71
+ * Verify that the given randomness was used to crate the nonce.
72
+ * Throws an error if the given randomness is invalid (not a BLS scalar).
73
+ *
74
+ * @param randomness - The randomness.
75
+ * @param nonce - The nonce.
76
+ * @param useBE - Flag to indicate if BE encoding is used for the randomness. Defaults to true.
77
+ * @returns True if the randomness was used to create the nonce, false otherwise.
78
+ */
79
+ export declare function verifyNonce(nonce: G2Element, randomness: Uint8Array, useBE?: boolean): boolean;
80
+ /**
81
+ * Decrypt the randomness using a key.
82
+ *
83
+ * @param encrypted_randomness - The encrypted randomness.
84
+ * @param derived_key - The derived key.
85
+ * @returns The randomness. Returns both the scalar interpreted in big-endian and little-endian encoding.
86
+ */
87
+ export declare function decryptRandomness(encryptedRandomness: Uint8Array, randomnessKey: Uint8Array): Uint8Array;
88
+ /**
89
+ * Verify that the given randomness was used to crate the nonce.
90
+ * Check using both big-endian and little-endian encoding of the randomness.
91
+ *
92
+ * Throws an error if the nonce check doesn't pass using LE encoding _and_ the randomness is invalid as a BE encoded scalar.
93
+ *
94
+ * @param randomness - The randomness.
95
+ * @param nonce - The nonce.
96
+ * @returns True if the randomness was used to create the nonce using either LE or BE encoding, false otherwise.
97
+ */
98
+ export declare function verifyNonceWithLE(nonce: G2Element, randomness: Uint8Array): boolean;