@mysten/seal 0.10.0 → 1.0.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 (157) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/bcs.d.mts +40 -0
  3. package/dist/bcs.d.mts.map +1 -0
  4. package/dist/bcs.mjs +89 -0
  5. package/dist/bcs.mjs.map +1 -0
  6. package/dist/bls12381.d.mts +30 -0
  7. package/dist/bls12381.d.mts.map +1 -0
  8. package/dist/bls12381.mjs +135 -0
  9. package/dist/bls12381.mjs.map +1 -0
  10. package/dist/client.d.mts +106 -0
  11. package/dist/client.d.mts.map +1 -0
  12. package/dist/client.mjs +274 -0
  13. package/dist/client.mjs.map +1 -0
  14. package/dist/decrypt.mjs +53 -0
  15. package/dist/decrypt.mjs.map +1 -0
  16. package/dist/dem.d.mts +1 -0
  17. package/dist/dem.mjs +134 -0
  18. package/dist/dem.mjs.map +1 -0
  19. package/dist/elgamal.mjs +35 -0
  20. package/dist/elgamal.mjs.map +1 -0
  21. package/dist/encrypt.d.mts +15 -0
  22. package/dist/encrypt.d.mts.map +1 -0
  23. package/dist/encrypt.mjs +61 -0
  24. package/dist/encrypt.mjs.map +1 -0
  25. package/dist/error.d.mts +75 -0
  26. package/dist/error.d.mts.map +1 -0
  27. package/dist/error.mjs +150 -0
  28. package/dist/error.mjs.map +1 -0
  29. package/dist/ibe.mjs +176 -0
  30. package/dist/ibe.mjs.map +1 -0
  31. package/dist/index.d.mts +7 -0
  32. package/dist/index.mjs +7 -0
  33. package/dist/kdf.mjs +81 -0
  34. package/dist/kdf.mjs.map +1 -0
  35. package/dist/key-server.d.mts +22 -0
  36. package/dist/key-server.d.mts.map +1 -0
  37. package/dist/key-server.mjs +195 -0
  38. package/dist/key-server.mjs.map +1 -0
  39. package/dist/session-key.d.mts +83 -0
  40. package/dist/session-key.d.mts.map +1 -0
  41. package/dist/session-key.mjs +171 -0
  42. package/dist/session-key.mjs.map +1 -0
  43. package/dist/shamir.mjs +730 -0
  44. package/dist/shamir.mjs.map +1 -0
  45. package/dist/types.d.mts +79 -0
  46. package/dist/types.d.mts.map +1 -0
  47. package/dist/utils.mjs +89 -0
  48. package/dist/utils.mjs.map +1 -0
  49. package/dist/version.mjs +6 -0
  50. package/dist/version.mjs.map +1 -0
  51. package/package.json +21 -20
  52. package/dist/cjs/bcs.d.ts +0 -147
  53. package/dist/cjs/bcs.js +0 -104
  54. package/dist/cjs/bcs.js.map +0 -7
  55. package/dist/cjs/bls12381.d.ts +0 -44
  56. package/dist/cjs/bls12381.js +0 -151
  57. package/dist/cjs/bls12381.js.map +0 -7
  58. package/dist/cjs/client.d.ts +0 -84
  59. package/dist/cjs/client.js +0 -419
  60. package/dist/cjs/client.js.map +0 -7
  61. package/dist/cjs/decrypt.d.ts +0 -22
  62. package/dist/cjs/decrypt.js +0 -109
  63. package/dist/cjs/decrypt.js.map +0 -7
  64. package/dist/cjs/dem.d.ts +0 -38
  65. package/dist/cjs/dem.js +0 -185
  66. package/dist/cjs/dem.js.map +0 -7
  67. package/dist/cjs/elgamal.d.ts +0 -13
  68. package/dist/cjs/elgamal.js +0 -46
  69. package/dist/cjs/elgamal.js.map +0 -7
  70. package/dist/cjs/encrypt.d.ts +0 -32
  71. package/dist/cjs/encrypt.js +0 -104
  72. package/dist/cjs/encrypt.js.map +0 -7
  73. package/dist/cjs/error.d.ts +0 -86
  74. package/dist/cjs/error.js +0 -239
  75. package/dist/cjs/error.js.map +0 -7
  76. package/dist/cjs/ibe.d.ts +0 -98
  77. package/dist/cjs/ibe.js +0 -167
  78. package/dist/cjs/ibe.js.map +0 -7
  79. package/dist/cjs/index.d.ts +0 -6
  80. package/dist/cjs/index.js +0 -33
  81. package/dist/cjs/index.js.map +0 -7
  82. package/dist/cjs/kdf.d.ts +0 -30
  83. package/dist/cjs/kdf.js +0 -97
  84. package/dist/cjs/kdf.js.map +0 -7
  85. package/dist/cjs/key-server.d.ts +0 -105
  86. package/dist/cjs/key-server.js +0 -230
  87. package/dist/cjs/key-server.js.map +0 -7
  88. package/dist/cjs/package.json +0 -5
  89. package/dist/cjs/session-key.d.ts +0 -74
  90. package/dist/cjs/session-key.js +0 -245
  91. package/dist/cjs/session-key.js.map +0 -7
  92. package/dist/cjs/shamir.d.ts +0 -91
  93. package/dist/cjs/shamir.js +0 -770
  94. package/dist/cjs/shamir.js.map +0 -7
  95. package/dist/cjs/types.d.ts +0 -86
  96. package/dist/cjs/types.js +0 -17
  97. package/dist/cjs/types.js.map +0 -7
  98. package/dist/cjs/utils.d.ts +0 -47
  99. package/dist/cjs/utils.js +0 -106
  100. package/dist/cjs/utils.js.map +0 -7
  101. package/dist/cjs/version.d.ts +0 -1
  102. package/dist/cjs/version.js +0 -25
  103. package/dist/cjs/version.js.map +0 -7
  104. package/dist/esm/bcs.d.ts +0 -147
  105. package/dist/esm/bcs.js +0 -84
  106. package/dist/esm/bcs.js.map +0 -7
  107. package/dist/esm/bls12381.d.ts +0 -44
  108. package/dist/esm/bls12381.js +0 -131
  109. package/dist/esm/bls12381.js.map +0 -7
  110. package/dist/esm/client.d.ts +0 -84
  111. package/dist/esm/client.js +0 -412
  112. package/dist/esm/client.js.map +0 -7
  113. package/dist/esm/decrypt.d.ts +0 -22
  114. package/dist/esm/decrypt.js +0 -94
  115. package/dist/esm/decrypt.js.map +0 -7
  116. package/dist/esm/dem.d.ts +0 -38
  117. package/dist/esm/dem.js +0 -165
  118. package/dist/esm/dem.js.map +0 -7
  119. package/dist/esm/elgamal.d.ts +0 -13
  120. package/dist/esm/elgamal.js +0 -26
  121. package/dist/esm/elgamal.js.map +0 -7
  122. package/dist/esm/encrypt.d.ts +0 -32
  123. package/dist/esm/encrypt.js +0 -84
  124. package/dist/esm/encrypt.js.map +0 -7
  125. package/dist/esm/error.d.ts +0 -86
  126. package/dist/esm/error.js +0 -219
  127. package/dist/esm/error.js.map +0 -7
  128. package/dist/esm/ibe.d.ts +0 -98
  129. package/dist/esm/ibe.js +0 -147
  130. package/dist/esm/ibe.js.map +0 -7
  131. package/dist/esm/index.d.ts +0 -6
  132. package/dist/esm/index.js +0 -12
  133. package/dist/esm/index.js.map +0 -7
  134. package/dist/esm/kdf.d.ts +0 -30
  135. package/dist/esm/kdf.js +0 -83
  136. package/dist/esm/kdf.js.map +0 -7
  137. package/dist/esm/key-server.d.ts +0 -105
  138. package/dist/esm/key-server.js +0 -215
  139. package/dist/esm/key-server.js.map +0 -7
  140. package/dist/esm/package.json +0 -5
  141. package/dist/esm/session-key.d.ts +0 -74
  142. package/dist/esm/session-key.js +0 -230
  143. package/dist/esm/session-key.js.map +0 -7
  144. package/dist/esm/shamir.d.ts +0 -91
  145. package/dist/esm/shamir.js +0 -750
  146. package/dist/esm/shamir.js.map +0 -7
  147. package/dist/esm/types.d.ts +0 -86
  148. package/dist/esm/types.js +0 -1
  149. package/dist/esm/types.js.map +0 -7
  150. package/dist/esm/utils.d.ts +0 -47
  151. package/dist/esm/utils.js +0 -86
  152. package/dist/esm/utils.js.map +0 -7
  153. package/dist/esm/version.d.ts +0 -1
  154. package/dist/esm/version.js +0 -5
  155. package/dist/esm/version.js.map +0 -7
  156. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  157. package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/esm/dem.js DELETED
@@ -1,165 +0,0 @@
1
- import { bcs } from "@mysten/bcs";
2
- import { equalBytes } from "@noble/curves/abstract/utils";
3
- import { hmac } from "@noble/hashes/hmac";
4
- import { sha3_256 } from "@noble/hashes/sha3";
5
- import { DecryptionError, InvalidCiphertextError } from "./error.js";
6
- import { flatten, xorUnchecked } from "./utils.js";
7
- const iv = Uint8Array.from([
8
- 138,
9
- 55,
10
- 153,
11
- 253,
12
- 198,
13
- 46,
14
- 121,
15
- 219,
16
- 160,
17
- 128,
18
- 89,
19
- 7,
20
- 214,
21
- 156,
22
- 148,
23
- 220
24
- ]);
25
- async function generateAesKey() {
26
- const key = await crypto.subtle.generateKey(
27
- {
28
- name: "AES-GCM",
29
- length: 256
30
- },
31
- true,
32
- ["encrypt", "decrypt"]
33
- );
34
- return await crypto.subtle.exportKey("raw", key).then((keyData) => new Uint8Array(keyData));
35
- }
36
- class AesGcm256 {
37
- constructor(msg, aad) {
38
- this.plaintext = msg;
39
- this.aad = aad;
40
- }
41
- generateKey() {
42
- return generateAesKey();
43
- }
44
- async encrypt(key) {
45
- if (key.length !== 32) {
46
- throw new Error("Key must be 32 bytes");
47
- }
48
- const aesCryptoKey = await crypto.subtle.importKey(
49
- "raw",
50
- key,
51
- "AES-GCM",
52
- false,
53
- ["encrypt"]
54
- );
55
- const blob = new Uint8Array(
56
- await crypto.subtle.encrypt(
57
- {
58
- name: "AES-GCM",
59
- iv,
60
- additionalData: this.aad
61
- },
62
- aesCryptoKey,
63
- this.plaintext
64
- )
65
- );
66
- return {
67
- Aes256Gcm: {
68
- blob,
69
- aad: this.aad ?? []
70
- }
71
- };
72
- }
73
- static async decrypt(key, ciphertext) {
74
- if (!("Aes256Gcm" in ciphertext)) {
75
- throw new InvalidCiphertextError(`Invalid ciphertext ${JSON.stringify(ciphertext)}`);
76
- }
77
- if (key.length !== 32) {
78
- throw new Error("Key must be 32 bytes");
79
- }
80
- try {
81
- const aesCryptoKey = await crypto.subtle.importKey(
82
- "raw",
83
- key,
84
- "AES-GCM",
85
- false,
86
- ["decrypt"]
87
- );
88
- return new Uint8Array(
89
- await crypto.subtle.decrypt(
90
- {
91
- name: "AES-GCM",
92
- iv,
93
- additionalData: new Uint8Array(ciphertext.Aes256Gcm.aad ?? [])
94
- },
95
- aesCryptoKey,
96
- new Uint8Array(ciphertext.Aes256Gcm.blob)
97
- )
98
- );
99
- } catch {
100
- throw new DecryptionError(`Decryption failed`);
101
- }
102
- }
103
- }
104
- class Hmac256Ctr {
105
- constructor(msg, aad) {
106
- this.plaintext = msg;
107
- this.aad = aad;
108
- }
109
- generateKey() {
110
- return generateAesKey();
111
- }
112
- async encrypt(key) {
113
- const blob = Hmac256Ctr.encryptInCtrMode(key, this.plaintext);
114
- const mac = Hmac256Ctr.computeMac(key, this.aad, blob);
115
- return {
116
- Hmac256Ctr: {
117
- blob,
118
- mac,
119
- aad: this.aad ?? []
120
- }
121
- };
122
- }
123
- static async decrypt(key, ciphertext) {
124
- if (!("Hmac256Ctr" in ciphertext)) {
125
- throw new InvalidCiphertextError(`Invalid ciphertext ${JSON.stringify(ciphertext)}`);
126
- }
127
- if (key.length !== 32) {
128
- throw new Error("Key must be 32 bytes");
129
- }
130
- const aad = new Uint8Array(ciphertext.Hmac256Ctr.aad ?? []);
131
- const blob = new Uint8Array(ciphertext.Hmac256Ctr.blob);
132
- const mac = Hmac256Ctr.computeMac(key, aad, blob);
133
- if (!equalBytes(mac, new Uint8Array(ciphertext.Hmac256Ctr.mac))) {
134
- throw new DecryptionError(`Invalid MAC ${mac}`);
135
- }
136
- return Hmac256Ctr.encryptInCtrMode(key, blob);
137
- }
138
- static computeMac(key, aad, ciphertext) {
139
- const macInput = flatten([MacKeyTag, toBytes(aad.length), aad, ciphertext]);
140
- const mac = hmac(sha3_256, key, macInput);
141
- return mac;
142
- }
143
- static encryptInCtrMode(key, msg) {
144
- const blockSize = 32;
145
- const result = new Uint8Array(msg.length);
146
- for (let i = 0; i * blockSize < msg.length; i++) {
147
- const block = msg.subarray(i * blockSize, (i + 1) * blockSize);
148
- const mask = hmac(sha3_256, key, flatten([EncryptionKeyTag, toBytes(i)]));
149
- const encryptedBlock = xorUnchecked(block, mask);
150
- result.set(encryptedBlock, i * blockSize);
151
- }
152
- return result;
153
- }
154
- }
155
- function toBytes(n) {
156
- return bcs.u64().serialize(n).toBytes();
157
- }
158
- const EncryptionKeyTag = new TextEncoder().encode("HMAC-CTR-ENC");
159
- const MacKeyTag = new TextEncoder().encode("HMAC-CTR-MAC");
160
- export {
161
- AesGcm256,
162
- Hmac256Ctr,
163
- iv
164
- };
165
- //# sourceMappingURL=dem.js.map
@@ -1,7 +0,0 @@
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 { 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<ArrayBuffer>> {\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\n/**\n * An interface for supported DEMs.\n */\nexport interface EncryptionInput {\n\tencrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput>;\n\tgenerateKey(): Promise<Uint8Array<ArrayBuffer>>;\n}\n\n/**\n * AES-GCM encryption.\n */\nexport class AesGcm256 implements EncryptionInput {\n\treadonly plaintext: Uint8Array<ArrayBuffer>;\n\treadonly aad: Uint8Array<ArrayBuffer>;\n\n\tconstructor(msg: Uint8Array<ArrayBuffer>, aad: Uint8Array<ArrayBuffer>) {\n\t\tthis.plaintext = msg;\n\t\tthis.aad = aad;\n\t}\n\n\tgenerateKey(): Promise<Uint8Array<ArrayBuffer>> {\n\t\t// generate a random key\n\t\treturn generateAesKey();\n\t}\n\n\tasync encrypt(key: Uint8Array): Promise<typeof Ciphertext.$inferInput> {\n\t\tif (key.length !== 32) {\n\t\t\tthrow new Error('Key must be 32 bytes');\n\t\t}\n\t\tconst aesCryptoKey = await crypto.subtle.importKey(\n\t\t\t'raw',\n\t\t\tkey as BufferSource,\n\t\t\t'AES-GCM',\n\t\t\tfalse,\n\t\t\t['encrypt'],\n\t\t);\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 as BufferSource,\n\t\t\t\t},\n\t\t\t\taesCryptoKey,\n\t\t\t\tthis.plaintext as BufferSource,\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 ${JSON.stringify(ciphertext)}`);\n\t\t}\n\t\tif (key.length !== 32) {\n\t\t\tthrow new Error('Key must be 32 bytes');\n\t\t}\n\n\t\ttry {\n\t\t\tconst aesCryptoKey = await crypto.subtle.importKey(\n\t\t\t\t'raw',\n\t\t\t\tkey as BufferSource,\n\t\t\t\t'AES-GCM',\n\t\t\t\tfalse,\n\t\t\t\t['decrypt'],\n\t\t\t);\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 {\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 || aad || c</i>.\n */\nexport class Hmac256Ctr implements EncryptionInput {\n\treadonly plaintext: Uint8Array<ArrayBuffer>;\n\treadonly aad: Uint8Array<ArrayBuffer>;\n\n\tconstructor(msg: Uint8Array<ArrayBuffer>, aad: Uint8Array<ArrayBuffer>) {\n\t\tthis.plaintext = msg;\n\t\tthis.aad = aad;\n\t}\n\n\tgenerateKey(): Promise<Uint8Array<ArrayBuffer>> {\n\t\t// generate a random key\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 ${JSON.stringify(ciphertext)}`);\n\t\t}\n\t\tif (key.length !== 32) {\n\t\t\tthrow new Error('Key must be 32 bytes');\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": "AAGA,SAAS,WAAW;AACpB,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAGzB,SAAS,iBAAiB,8BAA8B;AACxD,SAAS,SAAS,oBAAoB;AAG/B,MAAM,KAAK,WAAW,KAAK;AAAA,EACjC;AAAA,EAAK;AAAA,EAAI;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAI;AA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AW,KAAK,KAAK,IAAI;AAChD,QAAI,CAAC,WAAW,KAAK,IAAI,WAAW,WAAW,WAAW,GAAG,CAAC,GAAG;AAChE,YAAM,IAAI,gBAAgB,eAAe,GAAG,EAAE;AAAA,IAC/C;AACA,WAAO,WAAW,iBAAiB,KAAK,IAAI;AAAA,EAC7C;AAAA,EAEA,OAAe,WAAW,KAAiB,KAAiB,YAAoC;AAC/F,UAAM,WAAW,QAAQ,CAAC,WAAW,QAAQ,IAAI,MAAM,GAAG,KAAK,UAAU,CAAC;AAC1E,UAAM,MAAM,KAAK,UAAU,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,OAAO,KAAK,UAAU,KAAK,QAAQ,CAAC,kBAAkB,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxE,YAAM,iBAAiB,aAAa,OAAO,IAAI;AAC/C,aAAO,IAAI,gBAAgB,IAAI,SAAS;AAAA,IACzC;AACA,WAAO;AAAA,EACR;AACD;AAKA,SAAS,QAAQ,GAAuB;AACvC,SAAO,IAAI,IAAI,EAAE,UAAU,CAAC,EAAE,QAAQ;AACvC;AAEA,MAAM,mBAAmB,IAAI,YAAY,EAAE,OAAO,cAAc;AAChE,MAAM,YAAY,IAAI,YAAY,EAAE,OAAO,cAAc;",
6
- "names": []
7
- }
@@ -1,13 +0,0 @@
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
- * Throws an error if the secret key is not a valid scalar or if the ciphertext elements are not valid G1 points.
6
- */
7
- export declare function elgamalDecrypt(sk: Uint8Array, [c0, c1]: [Uint8Array, Uint8Array]): Uint8Array;
8
- /** Generate a random secret key. */
9
- export declare function generateSecretKey(): Uint8Array<ArrayBuffer>;
10
- /** Derive the BLS public key for a given secret key. */
11
- export declare function toPublicKey(sk: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
12
- /** Derive the BLS verification key for a given secret key. */
13
- export declare function toVerificationKey(sk: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
@@ -1,26 +0,0 @@
1
- import { G1Element, G2Element, Scalar } from "./bls12381.js";
2
- function elgamalDecrypt(sk, [c0, c1]) {
3
- return decrypt(Scalar.fromBytes(sk), [
4
- G1Element.fromBytes(c0),
5
- G1Element.fromBytes(c1)
6
- ]).toBytes();
7
- }
8
- function decrypt(sk, [c0, c1]) {
9
- return c1.subtract(c0.multiply(sk));
10
- }
11
- function generateSecretKey() {
12
- return Scalar.random().toBytes();
13
- }
14
- function toPublicKey(sk) {
15
- return G1Element.generator().multiply(Scalar.fromBytes(sk)).toBytes();
16
- }
17
- function toVerificationKey(sk) {
18
- return G2Element.generator().multiply(Scalar.fromBytes(sk)).toBytes();
19
- }
20
- export {
21
- elgamalDecrypt,
22
- generateSecretKey,
23
- toPublicKey,
24
- toVerificationKey
25
- };
26
- //# sourceMappingURL=elgamal.js.map
@@ -1,7 +0,0 @@
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 *\n * Throws an error if the secret key is not a valid scalar or if the ciphertext elements are not valid G1 points.\n */\nexport function elgamalDecrypt(sk: Uint8Array, [c0, c1]: [Uint8Array, Uint8Array]): Uint8Array {\n\treturn decrypt(Scalar.fromBytes(sk), [\n\t\tG1Element.fromBytes(c0),\n\t\tG1Element.fromBytes(c1),\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, [c0, c1]: [G1Element, G1Element]): G1Element {\n\treturn c1.subtract(c0.multiply(sk));\n}\n\n/** Generate a random secret key. */\nexport function generateSecretKey(): Uint8Array<ArrayBuffer> {\n\treturn Scalar.random().toBytes() as Uint8Array<ArrayBuffer>;\n}\n\n/** Derive the BLS public key for a given secret key. */\nexport function toPublicKey(sk: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> {\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<ArrayBuffer>): Uint8Array<ArrayBuffer> {\n\treturn G2Element.generator().multiply(Scalar.fromBytes(sk)).toBytes();\n}\n"],
5
- "mappings": "AAGA,SAAS,WAAW,WAAW,cAAc;AAQtC,SAAS,eAAe,IAAgB,CAAC,IAAI,EAAE,GAAyC;AAC9F,SAAO,QAAQ,OAAO,UAAU,EAAE,GAAG;AAAA,IACpC,UAAU,UAAU,EAAE;AAAA,IACtB,UAAU,UAAU,EAAE;AAAA,EACvB,CAAC,EAAE,QAAQ;AACZ;AAMA,SAAS,QAAQ,IAAY,CAAC,IAAI,EAAE,GAAsC;AACzE,SAAO,GAAG,SAAS,GAAG,SAAS,EAAE,CAAC;AACnC;AAGO,SAAS,oBAA6C;AAC5D,SAAO,OAAO,OAAO,EAAE,QAAQ;AAChC;AAGO,SAAS,YAAY,IAAsD;AACjF,SAAO,UAAU,UAAU,EAAE,SAAS,OAAO,UAAU,EAAE,CAAC,EAAE,QAAQ;AACrE;AAGO,SAAS,kBAAkB,IAAsD;AACvF,SAAO,UAAU,UAAU,EAAE,SAAS,OAAO,UAAU,EAAE,CAAC,EAAE,QAAQ;AACrE;",
6
- "names": []
7
- }
@@ -1,32 +0,0 @@
1
- import type { EncryptionInput } from './dem.js';
2
- import type { KeyServer } from './key-server.js';
3
- /**
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.
5
- *
6
- * @param keyServers - A list of KeyServers (same server can be used multiple times)
7
- * @param kemType - The type of KEM to use.
8
- * @param packageId - packageId
9
- * @param id - id
10
- * @param encryptionInput - Input to the encryption. Should be one of the EncryptionInput types, AesGcmEncryptionInput or Hmac256CtrEncryptionInput.
11
- * @param threshold - The threshold for the TSS encryption.
12
- * @returns The bcs bytes of the encrypted object containing all metadata and the 256-bit symmetric key that was used to encrypt the object.
13
- * Since the key can be used to decrypt, it should not be shared but can be used eg. for backup.
14
- */
15
- export declare function encrypt({ keyServers, kemType, threshold, packageId, id, encryptionInput, }: {
16
- keyServers: KeyServer[];
17
- kemType: KemType;
18
- threshold: number;
19
- packageId: string;
20
- id: string;
21
- encryptionInput: EncryptionInput;
22
- }): Promise<{
23
- encryptedObject: Uint8Array<ArrayBuffer>;
24
- key: Uint8Array<ArrayBuffer>;
25
- }>;
26
- export declare enum KemType {
27
- BonehFranklinBLS12381DemCCA = 0
28
- }
29
- export declare enum DemType {
30
- AesGcm256 = 0,
31
- Hmac256Ctr = 1
32
- }
@@ -1,84 +0,0 @@
1
- import { fromHex } from "@mysten/bcs";
2
- import { EncryptedObject } from "./bcs.js";
3
- import { UserError } from "./error.js";
4
- import { BonehFranklinBLS12381Services } from "./ibe.js";
5
- import { deriveKey, KeyPurpose } from "./kdf.js";
6
- import { createFullId, MAX_U8 } from "./utils.js";
7
- import { split } from "./shamir.js";
8
- async function encrypt({
9
- keyServers,
10
- kemType,
11
- threshold,
12
- packageId,
13
- id,
14
- encryptionInput
15
- }) {
16
- if (threshold <= 0 || threshold >= MAX_U8 || keyServers.length < threshold || keyServers.length >= MAX_U8) {
17
- throw new UserError(
18
- `Invalid key servers or threshold ${threshold} for ${keyServers.length} key servers for package ${packageId}`
19
- );
20
- }
21
- const baseKey = await encryptionInput.generateKey();
22
- const shares = split(baseKey, threshold, keyServers.length);
23
- const fullId = createFullId(packageId, id);
24
- const encryptedShares = encryptBatched(
25
- keyServers,
26
- kemType,
27
- fromHex(fullId),
28
- shares,
29
- baseKey,
30
- threshold
31
- );
32
- const demKey = deriveKey(
33
- KeyPurpose.DEM,
34
- baseKey,
35
- encryptedShares.BonehFranklinBLS12381.encryptedShares,
36
- threshold,
37
- keyServers.map(({ objectId }) => objectId)
38
- );
39
- const ciphertext = await encryptionInput.encrypt(demKey);
40
- const services = keyServers.map(({ objectId }, i) => [
41
- objectId,
42
- shares[i].index
43
- ]);
44
- return {
45
- encryptedObject: EncryptedObject.serialize({
46
- version: 0,
47
- packageId,
48
- id,
49
- services,
50
- threshold,
51
- encryptedShares,
52
- ciphertext
53
- }).toBytes(),
54
- key: new Uint8Array(demKey)
55
- };
56
- }
57
- var KemType = /* @__PURE__ */ ((KemType2) => {
58
- KemType2[KemType2["BonehFranklinBLS12381DemCCA"] = 0] = "BonehFranklinBLS12381DemCCA";
59
- return KemType2;
60
- })(KemType || {});
61
- var DemType = /* @__PURE__ */ ((DemType2) => {
62
- DemType2[DemType2["AesGcm256"] = 0] = "AesGcm256";
63
- DemType2[DemType2["Hmac256Ctr"] = 1] = "Hmac256Ctr";
64
- return DemType2;
65
- })(DemType || {});
66
- function encryptBatched(keyServers, kemType, id, shares, baseKey, threshold) {
67
- switch (kemType) {
68
- case 0 /* BonehFranklinBLS12381DemCCA */:
69
- return new BonehFranklinBLS12381Services(keyServers).encryptBatched(
70
- id,
71
- shares,
72
- baseKey,
73
- threshold
74
- );
75
- default:
76
- throw new Error(`Invalid KEM type ${kemType}`);
77
- }
78
- }
79
- export {
80
- DemType,
81
- KemType,
82
- encrypt
83
- };
84
- //# sourceMappingURL=encrypt.js.map
@@ -1,7 +0,0 @@
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';\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": "AAGA,SAAS,eAAe;AAGxB,SAAS,uBAAuB;AAEhC,SAA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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,8BAA8B,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": ["KemType", "DemType"]
7
- }
@@ -1,86 +0,0 @@
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;
package/dist/esm/error.js DELETED
@@ -1,219 +0,0 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- 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);
6
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
7
- var _SealAPIError_static, generate_fn;
8
- class SealError extends Error {
9
- }
10
- class UserError extends SealError {
11
- }
12
- const _SealAPIError = class _SealAPIError extends SealError {
13
- constructor(message, requestId, status) {
14
- super(message);
15
- this.requestId = requestId;
16
- this.status = status;
17
- }
18
- static async assertResponse(response, requestId) {
19
- var _a;
20
- if (response.ok) {
21
- return;
22
- }
23
- let errorInstance;
24
- try {
25
- const text = await response.text();
26
- const error = JSON.parse(text)["error"];
27
- const message = JSON.parse(text)["message"];
28
- errorInstance = __privateMethod(_a = _SealAPIError, _SealAPIError_static, generate_fn).call(_a, error, message, requestId);
29
- } catch {
30
- errorInstance = new GeneralError(response.statusText, requestId, response.status);
31
- }
32
- throw errorInstance;
33
- }
34
- };
35
- _SealAPIError_static = new WeakSet();
36
- generate_fn = function(error, message, requestId, status) {
37
- switch (error) {
38
- case "InvalidPTB":
39
- return new InvalidPTBError(requestId, message);
40
- case "InvalidPackage":
41
- return new InvalidPackageError(requestId);
42
- case "NoAccess":
43
- return new NoAccessError(requestId);
44
- case "InvalidSignature":
45
- return new InvalidUserSignatureError(requestId);
46
- case "InvalidSessionSignature":
47
- return new InvalidSessionKeySignatureError(requestId);
48
- case "InvalidCertificate":
49
- return new ExpiredSessionKeyError(requestId);
50
- case "InvalidSDKVersion":
51
- return new InvalidSDKVersionError(requestId);
52
- case "InvalidSDKType":
53
- return new InvalidSDKTypeError(requestId);
54
- case "DeprecatedSDKVersion":
55
- return new DeprecatedSDKVersionError(requestId);
56
- case "InvalidParameter":
57
- return new InvalidParameterError(requestId);
58
- case "InvalidMVRName":
59
- return new InvalidMVRNameError(requestId);
60
- case "InvalidServiceId":
61
- return new InvalidKeyServerObjectIdError(requestId);
62
- case "UnsupportedPackageId":
63
- return new UnsupportedPackageIdError(requestId);
64
- case "Failure":
65
- return new InternalError(requestId);
66
- default:
67
- return new GeneralError(message, requestId, status);
68
- }
69
- };
70
- __privateAdd(_SealAPIError, _SealAPIError_static);
71
- let SealAPIError = _SealAPIError;
72
- class InvalidPTBError extends SealAPIError {
73
- constructor(requestId, message) {
74
- super("PTB does not conform to the expected format " + message, requestId);
75
- }
76
- }
77
- class InvalidPackageError extends SealAPIError {
78
- constructor(requestId) {
79
- super("Package ID used in PTB is invalid", requestId);
80
- }
81
- }
82
- class InvalidParameterError extends SealAPIError {
83
- constructor(requestId) {
84
- super(
85
- "PTB contains an invalid parameter, possibly a newly created object that the FN has not yet seen",
86
- requestId
87
- );
88
- }
89
- }
90
- class InvalidUserSignatureError extends SealAPIError {
91
- constructor(requestId) {
92
- super("User signature on the session key is invalid", requestId);
93
- }
94
- }
95
- class InvalidSessionKeySignatureError extends SealAPIError {
96
- constructor(requestId) {
97
- super("Session key signature is invalid", requestId);
98
- }
99
- }
100
- class InvalidMVRNameError extends SealAPIError {
101
- constructor(requestId) {
102
- super("MVR name is invalid or not consistent with the first version of the package", requestId);
103
- }
104
- }
105
- class InvalidKeyServerObjectIdError extends SealAPIError {
106
- constructor(requestId) {
107
- super("Key server object ID is invalid", requestId);
108
- }
109
- }
110
- class UnsupportedPackageIdError extends SealAPIError {
111
- constructor(requestId) {
112
- super("Requested package is not supported", requestId);
113
- }
114
- }
115
- class InvalidSDKVersionError extends SealAPIError {
116
- constructor(requestId) {
117
- super("SDK version is invalid", requestId);
118
- }
119
- }
120
- class InvalidSDKTypeError extends SealAPIError {
121
- constructor(requestId) {
122
- super("SDK type is invalid", requestId);
123
- }
124
- }
125
- class DeprecatedSDKVersionError extends SealAPIError {
126
- constructor(requestId) {
127
- super("SDK version is deprecated", requestId);
128
- }
129
- }
130
- class NoAccessError extends SealAPIError {
131
- constructor(requestId) {
132
- super("User does not have access to one or more of the requested keys", requestId);
133
- }
134
- }
135
- class ExpiredSessionKeyError extends SealAPIError {
136
- constructor(requestId) {
137
- super("Session key has expired", requestId);
138
- }
139
- }
140
- class InternalError extends SealAPIError {
141
- constructor(requestId) {
142
- super("Internal server error, caller should retry", requestId);
143
- }
144
- }
145
- class GeneralError extends SealAPIError {
146
- }
147
- class InvalidPersonalMessageSignatureError extends UserError {
148
- }
149
- class InvalidGetObjectError extends UserError {
150
- }
151
- class UnsupportedFeatureError extends UserError {
152
- }
153
- class UnsupportedNetworkError extends UserError {
154
- }
155
- class InvalidKeyServerError extends UserError {
156
- }
157
- class InvalidKeyServerVersionError extends UserError {
158
- }
159
- class InvalidCiphertextError extends UserError {
160
- }
161
- class InvalidThresholdError extends UserError {
162
- }
163
- class InconsistentKeyServersError extends UserError {
164
- }
165
- class DecryptionError extends UserError {
166
- }
167
- class InvalidClientOptionsError extends UserError {
168
- }
169
- class TooManyFailedFetchKeyRequestsError extends UserError {
170
- }
171
- function toMajorityError(errors) {
172
- let maxCount = 0;
173
- let majorityError = errors[0];
174
- const counts = /* @__PURE__ */ new Map();
175
- for (const error of errors) {
176
- const errorName = error.constructor.name;
177
- const newCount = (counts.get(errorName) || 0) + 1;
178
- counts.set(errorName, newCount);
179
- if (newCount > maxCount) {
180
- maxCount = newCount;
181
- majorityError = error;
182
- }
183
- }
184
- return majorityError;
185
- }
186
- export {
187
- DecryptionError,
188
- DeprecatedSDKVersionError,
189
- ExpiredSessionKeyError,
190
- GeneralError,
191
- InconsistentKeyServersError,
192
- InternalError,
193
- InvalidCiphertextError,
194
- InvalidClientOptionsError,
195
- InvalidGetObjectError,
196
- InvalidKeyServerError,
197
- InvalidKeyServerObjectIdError,
198
- InvalidKeyServerVersionError,
199
- InvalidMVRNameError,
200
- InvalidPTBError,
201
- InvalidPackageError,
202
- InvalidParameterError,
203
- InvalidPersonalMessageSignatureError,
204
- InvalidSDKTypeError,
205
- InvalidSDKVersionError,
206
- InvalidSessionKeySignatureError,
207
- InvalidThresholdError,
208
- InvalidUserSignatureError,
209
- NoAccessError,
210
- SealAPIError,
211
- SealError,
212
- TooManyFailedFetchKeyRequestsError,
213
- UnsupportedFeatureError,
214
- UnsupportedNetworkError,
215
- UnsupportedPackageIdError,
216
- UserError,
217
- toMajorityError
218
- };
219
- //# sourceMappingURL=error.js.map