@mysten/seal 0.2.0 → 0.3.1
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 +12 -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/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.js.map +2 -2
- package/dist/cjs/encrypt.d.ts +14 -5
- package/dist/cjs/encrypt.js +52 -22
- package/dist/cjs/encrypt.js.map +3 -3
- 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 +13 -17
- package/dist/cjs/ibe.js +25 -28
- package/dist/cjs/ibe.js.map +2 -2
- package/dist/cjs/index.d.ts +3 -5
- package/dist/cjs/index.js +5 -11
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/kdf.d.ts +7 -2
- package/dist/cjs/kdf.js +37 -2
- package/dist/cjs/kdf.js.map +3 -3
- package/dist/cjs/key-server.d.ts +5 -5
- package/dist/cjs/key-server.js +24 -21
- package/dist/cjs/key-server.js.map +2 -2
- 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/session-key.d.ts +20 -14
- package/dist/cjs/session-key.js +90 -23
- package/dist/cjs/session-key.js.map +2 -2
- package/dist/cjs/types.d.ts +1 -86
- package/dist/cjs/types.js +0 -32
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/utils.d.ts +2 -1
- package/dist/cjs/utils.js +17 -5
- package/dist/cjs/utils.js.map +2 -2
- 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/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.js.map +2 -2
- package/dist/esm/encrypt.d.ts +14 -5
- package/dist/esm/encrypt.js +49 -19
- package/dist/esm/encrypt.js.map +3 -3
- 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 +13 -17
- package/dist/esm/ibe.js +25 -28
- package/dist/esm/ibe.js.map +2 -2
- package/dist/esm/index.d.ts +3 -5
- package/dist/esm/index.js +5 -16
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/kdf.d.ts +7 -2
- package/dist/esm/kdf.js +37 -2
- package/dist/esm/kdf.js.map +3 -3
- package/dist/esm/key-server.d.ts +5 -5
- package/dist/esm/key-server.js +29 -21
- package/dist/esm/key-server.js.map +2 -2
- 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/session-key.d.ts +20 -14
- package/dist/esm/session-key.js +95 -24
- package/dist/esm/session-key.js.map +2 -2
- package/dist/esm/types.d.ts +1 -86
- package/dist/esm/types.js +0 -28
- package/dist/esm/types.js.map +3 -3
- package/dist/esm/utils.d.ts +2 -1
- package/dist/esm/utils.js +17 -5
- package/dist/esm/utils.js.map +2 -2
- 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 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/cjs/aes.d.ts +0 -18
- package/dist/cjs/aes.js +0 -111
- package/dist/cjs/aes.js.map +0 -7
- package/dist/cjs/key-store.d.ts +0 -49
- package/dist/cjs/key-store.js +0 -203
- package/dist/cjs/key-store.js.map +0 -7
- package/dist/esm/aes.d.ts +0 -18
- package/dist/esm/aes.js +0 -91
- package/dist/esm/aes.js.map +0 -7
- package/dist/esm/key-store.d.ts +0 -49
- package/dist/esm/key-store.js +0 -183
- package/dist/esm/key-store.js.map +0 -7
package/dist/esm/key-store.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { fromBase64, toBase64, toHex } from "@mysten/bcs";
|
|
2
|
-
import { combine as externalCombine } from "shamir-secret-sharing";
|
|
3
|
-
import { AesGcm256 } from "./aes.js";
|
|
4
|
-
import { G1Element, G2Element } from "./bls12381.js";
|
|
5
|
-
import { elgamalDecrypt, toPublicKey, toVerificationKey } from "./elgamal.js";
|
|
6
|
-
import { BonehFranklinBLS12381Services, DST } from "./ibe.js";
|
|
7
|
-
import { KeyServerType } from "./key-server.js";
|
|
8
|
-
import { createFullId } from "./utils.js";
|
|
9
|
-
class KeyStore {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.keys_map = /* @__PURE__ */ new Map();
|
|
12
|
-
}
|
|
13
|
-
createMapKey(fullId, objectId) {
|
|
14
|
-
return toHex(fullId) + ":" + toHex(objectId);
|
|
15
|
-
}
|
|
16
|
-
/** @internal */
|
|
17
|
-
addKey(fullId, objectId, key) {
|
|
18
|
-
this.keys_map.set(this.createMapKey(fullId, objectId), key);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Get a key from this KeyStore or undefined if the key is not found.
|
|
22
|
-
*
|
|
23
|
-
* @param fullId The full ID used to derive the key.
|
|
24
|
-
* @param objectId The object ID of the key server holding the key.
|
|
25
|
-
*/
|
|
26
|
-
getKey(fullId, objectId) {
|
|
27
|
-
return this.keys_map.get(this.createMapKey(fullId, objectId));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if the key store has a key for the given full ID and object ID.
|
|
31
|
-
*
|
|
32
|
-
* @param fullId The full ID used to derive the key.
|
|
33
|
-
* @param objectId The object ID of the key server holding the key.
|
|
34
|
-
*/
|
|
35
|
-
hasKey(fullId, objectId) {
|
|
36
|
-
return this.keys_map.has(this.createMapKey(fullId, objectId));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Look up URLs of key servers and fetch key from servers with request signature,
|
|
40
|
-
* cert and ephPk, then updates the caching keys_map.
|
|
41
|
-
*/
|
|
42
|
-
async fetchKeys({
|
|
43
|
-
keyServers,
|
|
44
|
-
threshold: _threshold,
|
|
45
|
-
packageId,
|
|
46
|
-
ids,
|
|
47
|
-
txBytes,
|
|
48
|
-
sessionKey
|
|
49
|
-
}) {
|
|
50
|
-
if (ids.length !== 1) {
|
|
51
|
-
throw new Error("Only one ID is supported");
|
|
52
|
-
}
|
|
53
|
-
const fullId = createFullId(DST, packageId, ids[0]);
|
|
54
|
-
const remainingKeyServers = keyServers.filter((ks) => !this.hasKey(fullId, ks.objectId));
|
|
55
|
-
if (remainingKeyServers.length === 0) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const cert = sessionKey.getCertificate();
|
|
59
|
-
const signedRequest = await sessionKey.createRequestParams(txBytes);
|
|
60
|
-
await Promise.all(
|
|
61
|
-
remainingKeyServers.map(async (server) => {
|
|
62
|
-
if (server.keyType !== KeyServerType.BonehFranklinBLS12381) {
|
|
63
|
-
console.warn("Server has invalid key type: " + server.keyType);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const res = await fetchKey(
|
|
67
|
-
server.url,
|
|
68
|
-
signedRequest.request_signature,
|
|
69
|
-
txBytes,
|
|
70
|
-
signedRequest.decryption_key,
|
|
71
|
-
cert
|
|
72
|
-
);
|
|
73
|
-
const key = G1Element.fromBytes(res.key);
|
|
74
|
-
if (!BonehFranklinBLS12381Services.verifyUserSecretKey(
|
|
75
|
-
key,
|
|
76
|
-
fullId,
|
|
77
|
-
G2Element.fromBytes(server.pk)
|
|
78
|
-
)) {
|
|
79
|
-
console.warn("Received invalid key from key server " + server.objectId);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
this.addKey(fullId, server.objectId, key);
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Decrypt the given encrypted bytes with the given cached secret keys for the full ID.
|
|
88
|
-
* It's assumed that fetchKeys has been called to fetch the secret keys for enough key servers
|
|
89
|
-
* otherwise, this will throw an error.
|
|
90
|
-
*
|
|
91
|
-
* @param encryptedObject - EncryptedObject.
|
|
92
|
-
* @returns - The decrypted plaintext corresponding to ciphertext.
|
|
93
|
-
*/
|
|
94
|
-
async decrypt(encryptedObject) {
|
|
95
|
-
if (!encryptedObject.encrypted_shares.BonehFranklinBLS12381) {
|
|
96
|
-
throw new Error("Encryption mode not supported");
|
|
97
|
-
}
|
|
98
|
-
const fullId = createFullId(
|
|
99
|
-
DST,
|
|
100
|
-
encryptedObject.package_id,
|
|
101
|
-
new Uint8Array(encryptedObject.id)
|
|
102
|
-
);
|
|
103
|
-
const in_keystore = encryptedObject.services.map((_, i) => i).filter((i) => this.hasKey(fullId, encryptedObject.services[i][0]));
|
|
104
|
-
if (in_keystore.length < encryptedObject.threshold) {
|
|
105
|
-
throw new Error("Not enough shares. Please fetch more keys.");
|
|
106
|
-
}
|
|
107
|
-
const encryptedShares = encryptedObject.encrypted_shares.BonehFranklinBLS12381.shares;
|
|
108
|
-
if (encryptedShares.length !== encryptedObject.services.length) {
|
|
109
|
-
throw new Error("Invalid input");
|
|
110
|
-
}
|
|
111
|
-
const nonce = G2Element.fromBytes(
|
|
112
|
-
encryptedObject.encrypted_shares.BonehFranklinBLS12381.encapsulation
|
|
113
|
-
);
|
|
114
|
-
const shares = in_keystore.map((i) => {
|
|
115
|
-
const [objectId, index] = encryptedObject.services[i];
|
|
116
|
-
const info = new Uint8Array([index]);
|
|
117
|
-
let share = BonehFranklinBLS12381Services.decrypt(
|
|
118
|
-
nonce,
|
|
119
|
-
this.getKey(fullId, objectId),
|
|
120
|
-
encryptedShares[i],
|
|
121
|
-
info
|
|
122
|
-
);
|
|
123
|
-
return { index, share };
|
|
124
|
-
});
|
|
125
|
-
const key = await combine(shares);
|
|
126
|
-
if (encryptedObject.ciphertext.Aes256Gcm) {
|
|
127
|
-
try {
|
|
128
|
-
return AesGcm256.decrypt(key, encryptedObject.ciphertext);
|
|
129
|
-
} catch {
|
|
130
|
-
throw new Error("Decryption failed");
|
|
131
|
-
}
|
|
132
|
-
} else if (encryptedObject.ciphertext.Plain) {
|
|
133
|
-
return key;
|
|
134
|
-
} else {
|
|
135
|
-
throw new Error("Invalid encrypted object");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async function fetchKey(url, requestSig, txBytes, enc_key, certificate) {
|
|
140
|
-
const enc_key_pk = toPublicKey(enc_key);
|
|
141
|
-
const enc_verification_key = toVerificationKey(enc_key);
|
|
142
|
-
const body = {
|
|
143
|
-
ptb: toBase64(txBytes.slice(1)),
|
|
144
|
-
// removes the byte of the transaction type version
|
|
145
|
-
enc_key: toBase64(enc_key_pk),
|
|
146
|
-
enc_verification_key: toBase64(enc_verification_key),
|
|
147
|
-
request_signature: requestSig,
|
|
148
|
-
// already b64
|
|
149
|
-
certificate
|
|
150
|
-
};
|
|
151
|
-
const response = await fetch(url + "/v1/fetch_key", {
|
|
152
|
-
method: "POST",
|
|
153
|
-
headers: {
|
|
154
|
-
"Content-Type": "application/json"
|
|
155
|
-
},
|
|
156
|
-
body: JSON.stringify(body)
|
|
157
|
-
});
|
|
158
|
-
const resp = await response.json();
|
|
159
|
-
const key = elgamalDecrypt(enc_key, resp.decryption_keys[0].encrypted_key.map(fromBase64));
|
|
160
|
-
return {
|
|
161
|
-
fullId: resp.decryption_keys[0].fullId,
|
|
162
|
-
key
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
async function combine(shares) {
|
|
166
|
-
if (shares.length === 0) {
|
|
167
|
-
throw new Error("Invalid input");
|
|
168
|
-
} else if (shares.length === 1) {
|
|
169
|
-
return Promise.resolve(shares[0].share);
|
|
170
|
-
}
|
|
171
|
-
return externalCombine(
|
|
172
|
-
shares.map(({ index, share }) => {
|
|
173
|
-
const packedShare = new Uint8Array(share.length + 1);
|
|
174
|
-
packedShare.set(share, 0);
|
|
175
|
-
packedShare[share.length] = index;
|
|
176
|
-
return packedShare;
|
|
177
|
-
})
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
export {
|
|
181
|
-
KeyStore
|
|
182
|
-
};
|
|
183
|
-
//# sourceMappingURL=key-store.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/key-store.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase64, toBase64, toHex } from '@mysten/bcs';\nimport { combine as externalCombine } from 'shamir-secret-sharing';\n\nimport { AesGcm256 } from './aes.js';\nimport { G1Element, G2Element } from './bls12381.js';\nimport { elgamalDecrypt, toPublicKey, toVerificationKey } from './elgamal.js';\nimport { BonehFranklinBLS12381Services, DST } from './ibe.js';\nimport type { KeyServer } from './key-server.js';\nimport { KeyServerType } from './key-server.js';\nimport type { Certificate, SessionKey } from './session-key.js';\nimport type { EncryptedObject } from './types.js';\nimport { createFullId } from './utils.js';\n\n/**\n * A class to cache user secret keys after they have been fetched from key servers.\n */\nexport class KeyStore {\n\t// A caching map for: fullId:object_id -> partial key.\n\tprivate readonly keys_map: Map<string, G1Element>;\n\n\tconstructor() {\n\t\tthis.keys_map = new Map();\n\t}\n\n\tprivate createMapKey(fullId: Uint8Array, objectId: Uint8Array): string {\n\t\treturn toHex(fullId) + ':' + toHex(objectId);\n\t}\n\n\t/** @internal */\n\taddKey(fullId: Uint8Array, objectId: Uint8Array, key: G1Element) {\n\t\tthis.keys_map.set(this.createMapKey(fullId, objectId), key);\n\t}\n\n\t/**\n\t * Get a key from this KeyStore or undefined if the key is not found.\n\t *\n\t * @param fullId The full ID used to derive the key.\n\t * @param objectId The object ID of the key server holding the key.\n\t */\n\tprivate getKey(fullId: Uint8Array, objectId: Uint8Array): G1Element | undefined {\n\t\treturn this.keys_map.get(this.createMapKey(fullId, objectId));\n\t}\n\n\t/**\n\t * Check if the key store has a key for the given full ID and object ID.\n\t *\n\t * @param fullId The full ID used to derive the key.\n\t * @param objectId The object ID of the key server holding the key.\n\t */\n\tprivate hasKey(fullId: Uint8Array, objectId: Uint8Array): boolean {\n\t\treturn this.keys_map.has(this.createMapKey(fullId, objectId));\n\t}\n\n\t/**\n\t * Look up URLs of key servers and fetch key from servers with request signature,\n\t * cert and ephPk, then updates the caching keys_map.\n\t */\n\tasync fetchKeys({\n\t\tkeyServers,\n\t\tthreshold: _threshold,\n\t\tpackageId,\n\t\tids,\n\t\ttxBytes,\n\t\tsessionKey,\n\t}: {\n\t\tkeyServers: KeyServer[];\n\t\tthreshold: number;\n\t\tpackageId: Uint8Array;\n\t\tids: Uint8Array[];\n\t\ttxBytes: Uint8Array;\n\t\tsessionKey: SessionKey;\n\t}) {\n\t\t// TODO: support multiple ids.\n\t\tif (ids.length !== 1) {\n\t\t\tthrow new Error('Only one ID is supported');\n\t\t}\n\t\tconst fullId = createFullId(DST, packageId, ids[0]);\n\t\tconst remainingKeyServers = keyServers.filter((ks) => !this.hasKey(fullId, ks.objectId));\n\t\tif (remainingKeyServers.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst cert = sessionKey.getCertificate();\n\t\tconst signedRequest = await sessionKey.createRequestParams(txBytes);\n\n\t\t// TODO: wait for t valid keys, either from completed promises (not failures) or from the cache.\n\t\t// TODO: detect an expired session key and raise an error.\n\t\tawait Promise.all(\n\t\t\tremainingKeyServers.map(async (server) => {\n\t\t\t\tif (server.keyType !== KeyServerType.BonehFranklinBLS12381) {\n\t\t\t\t\tconsole.warn('Server has invalid key type: ' + server.keyType);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst res = await fetchKey(\n\t\t\t\t\tserver.url,\n\t\t\t\t\tsignedRequest.request_signature,\n\t\t\t\t\ttxBytes,\n\t\t\t\t\tsignedRequest.decryption_key,\n\t\t\t\t\tcert,\n\t\t\t\t);\n\n\t\t\t\tconst key = G1Element.fromBytes(res.key);\n\t\t\t\tif (\n\t\t\t\t\t!BonehFranklinBLS12381Services.verifyUserSecretKey(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tfullId,\n\t\t\t\t\t\tG2Element.fromBytes(server.pk),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn('Received invalid key from key server ' + server.objectId);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.addKey(fullId, server.objectId, key);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Decrypt the given encrypted bytes with the given cached secret keys for the full ID.\n\t * It's assumed that fetchKeys has been called to fetch the secret keys for enough key servers\n\t * otherwise, this will throw an error.\n\t *\n\t * @param encryptedObject - EncryptedObject.\n\t * @returns - The decrypted plaintext corresponding to ciphertext.\n\t */\n\tasync decrypt(encryptedObject: typeof EncryptedObject.$inferType): Promise<Uint8Array> {\n\t\tif (!encryptedObject.encrypted_shares.BonehFranklinBLS12381) {\n\t\t\tthrow new Error('Encryption mode not supported');\n\t\t}\n\n\t\tconst fullId = createFullId(\n\t\t\tDST,\n\t\t\tencryptedObject.package_id,\n\t\t\tnew Uint8Array(encryptedObject.id),\n\t\t);\n\n\t\t// Get the indices of the service whose keys are in the keystore.\n\t\tconst in_keystore = encryptedObject.services\n\t\t\t.map((_, i) => i)\n\t\t\t.filter((i) => this.hasKey(fullId, encryptedObject.services[i][0]));\n\t\tif (in_keystore.length < encryptedObject.threshold) {\n\t\t\tthrow new Error('Not enough shares. Please fetch more keys.');\n\t\t}\n\n\t\tconst encryptedShares = encryptedObject.encrypted_shares.BonehFranklinBLS12381.shares;\n\t\tif (encryptedShares.length !== encryptedObject.services.length) {\n\t\t\tthrow new Error('Invalid input');\n\t\t}\n\n\t\tconst nonce = G2Element.fromBytes(\n\t\t\tencryptedObject.encrypted_shares.BonehFranklinBLS12381.encapsulation,\n\t\t);\n\n\t\t// Decrypt each share.\n\t\tconst shares = in_keystore.map((i: number) => {\n\t\t\tconst [objectId, index] = encryptedObject.services[i];\n\t\t\t// Use the index as the unique info parameter to allow for multiple shares per key server.\n\t\t\tconst info = new Uint8Array([index]);\n\t\t\tlet share = BonehFranklinBLS12381Services.decrypt(\n\t\t\t\tnonce,\n\t\t\t\tthis.getKey(fullId, objectId)!,\n\t\t\t\tencryptedShares[i],\n\t\t\t\tinfo,\n\t\t\t);\n\t\t\t// The Shamir secret sharing library expects the index/x-coordinate to be at the end of the share.\n\t\t\treturn { index, share };\n\t\t});\n\n\t\t// Combine the decrypted shares into the key.\n\t\tconst key = await combine(shares);\n\n\t\tif (encryptedObject.ciphertext.Aes256Gcm) {\n\t\t\ttry {\n\t\t\t\t// Decrypt the ciphertext with the key.\n\t\t\t\treturn AesGcm256.decrypt(key, encryptedObject.ciphertext);\n\t\t\t} catch {\n\t\t\t\tthrow new Error('Decryption failed');\n\t\t\t}\n\t\t} else if (encryptedObject.ciphertext.Plain) {\n\t\t\t// In case `Plain` mode is used, return the key.\n\t\t\treturn key;\n\t\t} else {\n\t\t\tthrow new Error('Invalid encrypted object');\n\t\t}\n\t}\n}\n\n/**\n * Helper function to request a Seal key from URL with requestSig, txBytes, ephemeral pubkey.\n * Then decrypt the Seal key with ephemeral secret key.\n */\nasync function fetchKey(\n\turl: string,\n\trequestSig: string,\n\ttxBytes: Uint8Array,\n\tenc_key: Uint8Array,\n\tcertificate: Certificate,\n): Promise<{ fullId: Uint8Array; key: Uint8Array }> {\n\tconst enc_key_pk = toPublicKey(enc_key);\n\tconst enc_verification_key = toVerificationKey(enc_key);\n\tconst body = {\n\t\tptb: toBase64(txBytes.slice(1)), // removes the byte of the transaction type version\n\t\tenc_key: toBase64(enc_key_pk),\n\t\tenc_verification_key: toBase64(enc_verification_key),\n\t\trequest_signature: requestSig, // already b64\n\t\tcertificate,\n\t};\n\tconst response = await fetch(url + '/v1/fetch_key', {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t},\n\t\tbody: JSON.stringify(body),\n\t});\n\tconst resp = await response.json();\n\t// TODO: handle the different error responses.\n\t// TODO: handle multiple decryption keys.\n\tconst key = elgamalDecrypt(enc_key, resp.decryption_keys[0].encrypted_key.map(fromBase64));\n\treturn {\n\t\tfullId: resp.decryption_keys[0].fullId,\n\t\tkey,\n\t};\n}\n\nasync function combine(shares: { index: number; share: Uint8Array }[]): Promise<Uint8Array> {\n\tif (shares.length === 0) {\n\t\tthrow new Error('Invalid input');\n\t} else if (shares.length === 1) {\n\t\t// The Shamir secret sharing library expects at least two shares.\n\t\t// If there is only one and the threshold is 1, the reconstructed secret is the same as the share.\n\t\treturn Promise.resolve(shares[0].share);\n\t}\n\n\t// The Shamir secret sharing library expects the index/x-coordinate to be at the end of the share\n\treturn externalCombine(\n\t\tshares.map(({ index, share }) => {\n\t\t\tconst packedShare = new Uint8Array(share.length + 1);\n\t\t\tpackedShare.set(share, 0);\n\t\t\tpackedShare[share.length] = index;\n\t\t\treturn packedShare;\n\t\t}),\n\t);\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,YAAY,UAAU,aAAa;AAC5C,SAAS,WAAW,uBAAuB;AAE3C,SAAS,iBAAiB;AAC1B,SAAS,WAAW,iBAAiB;AACrC,SAAS,gBAAgB,aAAa,yBAAyB;AAC/D,SAAS,+BAA+B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