@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.
- package/CHANGELOG.md +30 -0
- package/dist/bcs.d.mts +40 -0
- package/dist/bcs.d.mts.map +1 -0
- package/dist/bcs.mjs +89 -0
- package/dist/bcs.mjs.map +1 -0
- package/dist/bls12381.d.mts +30 -0
- package/dist/bls12381.d.mts.map +1 -0
- package/dist/bls12381.mjs +135 -0
- package/dist/bls12381.mjs.map +1 -0
- package/dist/client.d.mts +106 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +274 -0
- package/dist/client.mjs.map +1 -0
- package/dist/decrypt.mjs +53 -0
- package/dist/decrypt.mjs.map +1 -0
- package/dist/dem.d.mts +1 -0
- package/dist/dem.mjs +134 -0
- package/dist/dem.mjs.map +1 -0
- package/dist/elgamal.mjs +35 -0
- package/dist/elgamal.mjs.map +1 -0
- package/dist/encrypt.d.mts +15 -0
- package/dist/encrypt.d.mts.map +1 -0
- package/dist/encrypt.mjs +61 -0
- package/dist/encrypt.mjs.map +1 -0
- package/dist/error.d.mts +75 -0
- package/dist/error.d.mts.map +1 -0
- package/dist/error.mjs +150 -0
- package/dist/error.mjs.map +1 -0
- package/dist/ibe.mjs +176 -0
- package/dist/ibe.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/kdf.mjs +81 -0
- package/dist/kdf.mjs.map +1 -0
- package/dist/key-server.d.mts +22 -0
- package/dist/key-server.d.mts.map +1 -0
- package/dist/key-server.mjs +195 -0
- package/dist/key-server.mjs.map +1 -0
- package/dist/session-key.d.mts +83 -0
- package/dist/session-key.d.mts.map +1 -0
- package/dist/session-key.mjs +171 -0
- package/dist/session-key.mjs.map +1 -0
- package/dist/shamir.mjs +730 -0
- package/dist/shamir.mjs.map +1 -0
- package/dist/types.d.mts +79 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/utils.mjs +89 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/version.mjs +6 -0
- package/dist/version.mjs.map +1 -0
- package/package.json +21 -20
- package/dist/cjs/bcs.d.ts +0 -147
- package/dist/cjs/bcs.js +0 -104
- package/dist/cjs/bcs.js.map +0 -7
- package/dist/cjs/bls12381.d.ts +0 -44
- package/dist/cjs/bls12381.js +0 -151
- package/dist/cjs/bls12381.js.map +0 -7
- package/dist/cjs/client.d.ts +0 -84
- package/dist/cjs/client.js +0 -419
- package/dist/cjs/client.js.map +0 -7
- package/dist/cjs/decrypt.d.ts +0 -22
- package/dist/cjs/decrypt.js +0 -109
- package/dist/cjs/decrypt.js.map +0 -7
- package/dist/cjs/dem.d.ts +0 -38
- package/dist/cjs/dem.js +0 -185
- package/dist/cjs/dem.js.map +0 -7
- package/dist/cjs/elgamal.d.ts +0 -13
- package/dist/cjs/elgamal.js +0 -46
- package/dist/cjs/elgamal.js.map +0 -7
- package/dist/cjs/encrypt.d.ts +0 -32
- package/dist/cjs/encrypt.js +0 -104
- package/dist/cjs/encrypt.js.map +0 -7
- package/dist/cjs/error.d.ts +0 -86
- package/dist/cjs/error.js +0 -239
- package/dist/cjs/error.js.map +0 -7
- package/dist/cjs/ibe.d.ts +0 -98
- package/dist/cjs/ibe.js +0 -167
- package/dist/cjs/ibe.js.map +0 -7
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/index.js +0 -33
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/kdf.d.ts +0 -30
- package/dist/cjs/kdf.js +0 -97
- package/dist/cjs/kdf.js.map +0 -7
- package/dist/cjs/key-server.d.ts +0 -105
- package/dist/cjs/key-server.js +0 -230
- package/dist/cjs/key-server.js.map +0 -7
- package/dist/cjs/package.json +0 -5
- package/dist/cjs/session-key.d.ts +0 -74
- package/dist/cjs/session-key.js +0 -245
- package/dist/cjs/session-key.js.map +0 -7
- package/dist/cjs/shamir.d.ts +0 -91
- package/dist/cjs/shamir.js +0 -770
- package/dist/cjs/shamir.js.map +0 -7
- package/dist/cjs/types.d.ts +0 -86
- package/dist/cjs/types.js +0 -17
- package/dist/cjs/types.js.map +0 -7
- package/dist/cjs/utils.d.ts +0 -47
- package/dist/cjs/utils.js +0 -106
- package/dist/cjs/utils.js.map +0 -7
- package/dist/cjs/version.d.ts +0 -1
- package/dist/cjs/version.js +0 -25
- package/dist/cjs/version.js.map +0 -7
- package/dist/esm/bcs.d.ts +0 -147
- package/dist/esm/bcs.js +0 -84
- package/dist/esm/bcs.js.map +0 -7
- package/dist/esm/bls12381.d.ts +0 -44
- package/dist/esm/bls12381.js +0 -131
- package/dist/esm/bls12381.js.map +0 -7
- package/dist/esm/client.d.ts +0 -84
- package/dist/esm/client.js +0 -412
- package/dist/esm/client.js.map +0 -7
- package/dist/esm/decrypt.d.ts +0 -22
- package/dist/esm/decrypt.js +0 -94
- package/dist/esm/decrypt.js.map +0 -7
- package/dist/esm/dem.d.ts +0 -38
- package/dist/esm/dem.js +0 -165
- package/dist/esm/dem.js.map +0 -7
- package/dist/esm/elgamal.d.ts +0 -13
- package/dist/esm/elgamal.js +0 -26
- package/dist/esm/elgamal.js.map +0 -7
- package/dist/esm/encrypt.d.ts +0 -32
- package/dist/esm/encrypt.js +0 -84
- package/dist/esm/encrypt.js.map +0 -7
- package/dist/esm/error.d.ts +0 -86
- package/dist/esm/error.js +0 -219
- package/dist/esm/error.js.map +0 -7
- package/dist/esm/ibe.d.ts +0 -98
- package/dist/esm/ibe.js +0 -147
- package/dist/esm/ibe.js.map +0 -7
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/kdf.d.ts +0 -30
- package/dist/esm/kdf.js +0 -83
- package/dist/esm/kdf.js.map +0 -7
- package/dist/esm/key-server.d.ts +0 -105
- package/dist/esm/key-server.js +0 -215
- package/dist/esm/key-server.js.map +0 -7
- package/dist/esm/package.json +0 -5
- package/dist/esm/session-key.d.ts +0 -74
- package/dist/esm/session-key.js +0 -230
- package/dist/esm/session-key.js.map +0 -7
- package/dist/esm/shamir.d.ts +0 -91
- package/dist/esm/shamir.js +0 -750
- package/dist/esm/shamir.js.map +0 -7
- package/dist/esm/types.d.ts +0 -86
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/esm/utils.d.ts +0 -47
- package/dist/esm/utils.js +0 -86
- package/dist/esm/utils.js.map +0 -7
- package/dist/esm/version.d.ts +0 -1
- package/dist/esm/version.js +0 -5
- package/dist/esm/version.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/esm/error.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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;AAGO,MAAM,kBAAkB,MAAM;AAAC;AAE/B,MAAM,kBAAkB,UAAU;AAAC;AAGnC,MAAM,gBAAN,MAAM,sBAAqB,UAAU;AAAA,EAC3C,YACC,SACO,WACA,QACN;AACD,UAAM,OAAO;AAHN;AACA;AAAA,EAGR;AAAA,EAqCA,aAAa,eAAe,UAAoB,WAAmB;AApDpE;AAqDE,QAAI,SAAS,IAAI;AAChB;AAAA,IACD;AACA,QAAI;AACJ,QAAI;AACH,YAAM,OAAO,MAAM,SAAS,KAAK;AACjC,YAAM,QAAQ,KAAK,MAAM,IAAI,EAAE,OAAO;AACtC,YAAM,UAAU,KAAK,MAAM,IAAI,EAAE,SAAS;AAC1C,sB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C;AAGzC,MAAM,6CAA6C,UAAU;AAAC;AAC9D,MAAM,8BAA8B,UAAU;AAAC;AAC/C,MAAM,gCAAgC,UAAU;AAAC;AACjD,MAAM,gCAAgC,UAAU;AAAC;AACjD,MAAM,8BAA8B,UAAU;AAAC;AAC/C,MAAM,qCAAqC,UAAU;AAAC;AACtD,MAAM,+BAA+B,UAAU;AAAC;AAChD,MAAM,8BAA8B,UAAU;AAAC;AAC/C,MAAM,oCAAoC,UAAU;AAAC;AACrD,MAAM,wBAAwB,UAAU;AAAC;AACzC,MAAM,kCAAkC,UAAU;AAAC;AACnD,MAAM,2CAA2C,UAAU;AAAC;AAE5D,SAAS,gBAAgB,QAAwB;AACvD,MAAI,WAAW;AACf,MAAI,gBAAgB,OAAO,CAAC;AAC5B,QAAM,SAAS,oBAAI,IAAoB;AACvC,aAAW,SAAS,QAAQ;AAC3B,UAAM,YAAY,MAAM,YAAY;AACpC,UAAM,YAAY,OAAO,IAAI,SAAS,KAAK,KAAK;AAChD,WAAO,IAAI,WAAW,QAAQ;AAE9B,QAAI,WAAW,UAAU;AACxB,iBAAW;AACX,sBAAgB;AAAA,IACjB;AAAA,EACD;AAEA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/esm/ibe.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
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;
|
package/dist/esm/ibe.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { fromHex } from "@mysten/bcs";
|
|
2
|
-
import { G2Element, Scalar } from "./bls12381.js";
|
|
3
|
-
import { deriveKey, hashToG1, kdf, KeyPurpose } from "./kdf.js";
|
|
4
|
-
import { xor } from "./utils.js";
|
|
5
|
-
import { InvalidCiphertextError } from "./error.js";
|
|
6
|
-
const DST_POP = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-POP-00");
|
|
7
|
-
class IBEServers {
|
|
8
|
-
constructor(objectIds) {
|
|
9
|
-
this.objectIds = objectIds;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
class BonehFranklinBLS12381Services extends IBEServers {
|
|
13
|
-
constructor(services) {
|
|
14
|
-
super(services.map((service) => service.objectId));
|
|
15
|
-
this.publicKeys = services.map((service) => G2Element.fromBytes(service.pk));
|
|
16
|
-
}
|
|
17
|
-
encryptBatched(id, shares, baseKey, threshold) {
|
|
18
|
-
if (this.publicKeys.length === 0 || this.publicKeys.length !== shares.length) {
|
|
19
|
-
throw new Error("Invalid public keys");
|
|
20
|
-
}
|
|
21
|
-
const [r, nonce, keys] = encapBatched(this.publicKeys, id);
|
|
22
|
-
const encryptedShares = shares.map(
|
|
23
|
-
({ share, index }, i) => xor(share, kdf(keys[i], nonce, id, this.objectIds[i], index))
|
|
24
|
-
);
|
|
25
|
-
const randomnessKey = deriveKey(
|
|
26
|
-
KeyPurpose.EncryptedRandomness,
|
|
27
|
-
baseKey,
|
|
28
|
-
encryptedShares,
|
|
29
|
-
threshold,
|
|
30
|
-
this.objectIds
|
|
31
|
-
);
|
|
32
|
-
const encryptedRandomness = xor(randomnessKey, r.toBytes());
|
|
33
|
-
return {
|
|
34
|
-
BonehFranklinBLS12381: {
|
|
35
|
-
nonce: nonce.toBytes(),
|
|
36
|
-
encryptedShares,
|
|
37
|
-
encryptedRandomness
|
|
38
|
-
},
|
|
39
|
-
$kind: "BonehFranklinBLS12381"
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns true if the user secret key is valid for the given public key and id.
|
|
44
|
-
* @param user_secret_key - The user secret key.
|
|
45
|
-
* @param id - The identity.
|
|
46
|
-
* @param public_key - The public key.
|
|
47
|
-
* @returns True if the user secret key is valid for the given public key and id.
|
|
48
|
-
*/
|
|
49
|
-
static verifyUserSecretKey(userSecretKey, id, publicKey) {
|
|
50
|
-
const lhs = userSecretKey.pairing(G2Element.generator());
|
|
51
|
-
const rhs = hashToG1(fromHex(id)).pairing(publicKey);
|
|
52
|
-
return lhs.equals(rhs);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Identity-based decryption.
|
|
56
|
-
*
|
|
57
|
-
* @param nonce The encryption nonce.
|
|
58
|
-
* @param sk The user secret key.
|
|
59
|
-
* @param ciphertext The encrypted message.
|
|
60
|
-
* @param id The identity.
|
|
61
|
-
* @param [objectId, index] The object id and index of the share.
|
|
62
|
-
* @returns The decrypted message.
|
|
63
|
-
*/
|
|
64
|
-
static decrypt(nonce, sk, ciphertext, id, [objectId, index]) {
|
|
65
|
-
return xor(ciphertext, kdf(decap(nonce, sk), nonce, id, objectId, index));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Decrypt all shares and verify that the randomness was used to create the given nonce.
|
|
69
|
-
*
|
|
70
|
-
* @param randomness - The randomness.
|
|
71
|
-
* @param encryptedShares - The encrypted shares.
|
|
72
|
-
* @param services - The services.
|
|
73
|
-
* @param publicKeys - The public keys.
|
|
74
|
-
* @param nonce - The nonce.
|
|
75
|
-
* @param id - The id.
|
|
76
|
-
* @returns All decrypted shares.
|
|
77
|
-
*/
|
|
78
|
-
static decryptAllSharesUsingRandomness(randomness, encryptedShares, services, publicKeys, nonce, id) {
|
|
79
|
-
if (publicKeys.length !== encryptedShares.length || publicKeys.length !== services.length) {
|
|
80
|
-
throw new Error("The number of public keys, encrypted shares and services must be the same");
|
|
81
|
-
}
|
|
82
|
-
let r;
|
|
83
|
-
try {
|
|
84
|
-
r = Scalar.fromBytes(randomness);
|
|
85
|
-
} catch {
|
|
86
|
-
throw new InvalidCiphertextError("Invalid randomness");
|
|
87
|
-
}
|
|
88
|
-
const gid_r = hashToG1(id).multiply(r);
|
|
89
|
-
return services.map(([objectId, index], i) => {
|
|
90
|
-
return {
|
|
91
|
-
index,
|
|
92
|
-
share: xor(
|
|
93
|
-
encryptedShares[i],
|
|
94
|
-
kdf(gid_r.pairing(publicKeys[i]), nonce, id, objectId, index)
|
|
95
|
-
)
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function encapBatched(publicKeys, id) {
|
|
101
|
-
if (publicKeys.length === 0) {
|
|
102
|
-
throw new Error("No public keys provided");
|
|
103
|
-
}
|
|
104
|
-
const r = Scalar.random();
|
|
105
|
-
const nonce = G2Element.generator().multiply(r);
|
|
106
|
-
const gid_r = hashToG1(id).multiply(r);
|
|
107
|
-
return [r, nonce, publicKeys.map((public_key) => gid_r.pairing(public_key))];
|
|
108
|
-
}
|
|
109
|
-
function decap(nonce, usk) {
|
|
110
|
-
return usk.pairing(nonce);
|
|
111
|
-
}
|
|
112
|
-
function verifyNonce(nonce, randomness, useBE = true) {
|
|
113
|
-
try {
|
|
114
|
-
const r = decodeRandomness(randomness, useBE);
|
|
115
|
-
return G2Element.generator().multiply(r).equals(nonce);
|
|
116
|
-
} catch {
|
|
117
|
-
throw new InvalidCiphertextError("Invalid randomness");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function decodeRandomness(bytes, useBE) {
|
|
121
|
-
if (useBE) {
|
|
122
|
-
return Scalar.fromBytes(bytes);
|
|
123
|
-
} else {
|
|
124
|
-
return Scalar.fromBytesLE(bytes);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function decryptRandomness(encryptedRandomness, randomnessKey) {
|
|
128
|
-
return xor(encryptedRandomness, randomnessKey);
|
|
129
|
-
}
|
|
130
|
-
function verifyNonceWithLE(nonce, randomness) {
|
|
131
|
-
try {
|
|
132
|
-
if (verifyNonce(nonce, randomness, false)) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
} catch {
|
|
136
|
-
}
|
|
137
|
-
return verifyNonce(nonce, randomness, true);
|
|
138
|
-
}
|
|
139
|
-
export {
|
|
140
|
-
BonehFranklinBLS12381Services,
|
|
141
|
-
DST_POP,
|
|
142
|
-
IBEServers,
|
|
143
|
-
decryptRandomness,
|
|
144
|
-
verifyNonce,
|
|
145
|
-
verifyNonceWithLE
|
|
146
|
-
};
|
|
147
|
-
//# sourceMappingURL=ibe.js.map
|
package/dist/esm/ibe.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/ibe.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 type { G1Element, GTElement } from './bls12381.js';\nimport { G2Element, Scalar } from './bls12381.js';\nimport { deriveKey, hashToG1, kdf, KeyPurpose } from './kdf.js';\nimport type { KeyServer } from './key-server.js';\nimport { xor } from './utils.js';\nimport type { Share } from './shamir.js';\nimport { InvalidCiphertextError } from './error.js';\n\n/**\n * The domain separation tag for the signing proof of possession.\n */\nexport const DST_POP: Uint8Array = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-POP-00');\n\n/**\n * The interface for the key servers.\n */\nexport abstract class IBEServers {\n\tobjectIds: string[];\n\n\tconstructor(objectIds: string[]) {\n\t\tthis.objectIds = objectIds;\n\t}\n\n\t/**\n\t * Encrypt a batch of messages for the given identity.\n\t *\n\t * @param id The identity.\n\t * @param msgAndIndices The messages and the corresponding indices of the share being encrypted.\n\t * @returns The encrypted messages.\n\t */\n\tabstract encryptBatched(\n\t\tid: Uint8Array,\n\t\tshares: Share[],\n\t\tbaseKey: Uint8Array,\n\t\tthreshold: number,\n\t): typeof IBEEncryptions.$inferType;\n}\n\n/**\n * Identity-based encryption based on the Boneh-Franklin IBE scheme (https://eprint.iacr.org/2001/090).\n * 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.\n *\n * This object represents a set of key servers that can be used to encrypt messages for a given identity.\n */\nexport class BonehFranklinBLS12381Services extends IBEServers {\n\treadonly publicKeys: G2Element[];\n\n\tconstructor(services: KeyServer[]) {\n\t\tsuper(services.map((service) => service.objectId));\n\t\tthis.publicKeys = services.map((service) => G2Element.fromBytes(service.pk));\n\t}\n\n\tencryptBatched(\n\t\tid: Uint8Array,\n\t\tshares: Share[],\n\t\tbaseKey: Uint8Array,\n\t\tthreshold: number,\n\t): typeof IBEEncryptions.$inferType {\n\t\tif (this.publicKeys.length === 0 || this.publicKeys.length !== shares.length) {\n\t\t\tthrow new Error('Invalid public keys');\n\t\t}\n\t\tconst [r, nonce, keys] = encapBatched(this.publicKeys, id);\n\t\tconst encryptedShares = shares.map(({ share, index }, i) =>\n\t\t\txor(share, kdf(keys[i], nonce, id, this.objectIds[i], index)),\n\t\t);\n\t\tconst randomnessKey = deriveKey(\n\t\t\tKeyPurpose.EncryptedRandomness,\n\t\t\tbaseKey,\n\t\t\tencryptedShares,\n\t\t\tthreshold,\n\t\t\tthis.objectIds,\n\t\t);\n\t\tconst encryptedRandomness = xor(randomnessKey, r.toBytes());\n\n\t\treturn {\n\t\t\tBonehFranklinBLS12381: {\n\t\t\t\tnonce: nonce.toBytes(),\n\t\t\t\tencryptedShares,\n\t\t\t\tencryptedRandomness,\n\t\t\t},\n\t\t\t$kind: 'BonehFranklinBLS12381',\n\t\t};\n\t}\n\n\t/**\n\t * Returns true if the user secret key is valid for the given public key and id.\n\t * @param user_secret_key - The user secret key.\n\t * @param id - The identity.\n\t * @param public_key - The public key.\n\t * @returns True if the user secret key is valid for the given public key and id.\n\t */\n\tstatic verifyUserSecretKey(userSecretKey: G1Element, id: string, publicKey: G2Element): boolean {\n\t\tconst lhs = userSecretKey.pairing(G2Element.generator());\n\t\tconst rhs = hashToG1(fromHex(id)).pairing(publicKey);\n\t\treturn lhs.equals(rhs);\n\t}\n\n\t/**\n\t * Identity-based decryption.\n\t *\n\t * @param nonce The encryption nonce.\n\t * @param sk The user secret key.\n\t * @param ciphertext The encrypted message.\n\t * @param id The identity.\n\t * @param [objectId, index] The object id and index of the share.\n\t * @returns The decrypted message.\n\t */\n\tstatic decrypt(\n\t\tnonce: G2Element,\n\t\tsk: G1Element,\n\t\tciphertext: Uint8Array,\n\t\tid: Uint8Array,\n\t\t[objectId, index]: [string, number],\n\t): Uint8Array {\n\t\treturn xor(ciphertext, kdf(decap(nonce, sk), nonce, id, objectId, index));\n\t}\n\n\t/**\n\t * Decrypt all shares and verify that the randomness was used to create the given nonce.\n\t *\n\t * @param randomness - The randomness.\n\t * @param encryptedShares - The encrypted shares.\n\t * @param services - The services.\n\t * @param publicKeys - The public keys.\n\t * @param nonce - The nonce.\n\t * @param id - The id.\n\t * @returns All decrypted shares.\n\t */\n\tstatic decryptAllSharesUsingRandomness(\n\t\trandomness: Uint8Array,\n\t\tencryptedShares: Uint8Array[],\n\t\tservices: [string, number][],\n\t\tpublicKeys: G2Element[],\n\t\tnonce: G2Element,\n\t\tid: Uint8Array,\n\t): { index: number; share: Uint8Array }[] {\n\t\tif (publicKeys.length !== encryptedShares.length || publicKeys.length !== services.length) {\n\t\t\tthrow new Error('The number of public keys, encrypted shares and services must be the same');\n\t\t}\n\t\tlet r;\n\t\ttry {\n\t\t\tr = Scalar.fromBytes(randomness);\n\t\t} catch {\n\t\t\tthrow new InvalidCiphertextError('Invalid randomness');\n\t\t}\n\t\tconst gid_r = hashToG1(id).multiply(r);\n\t\treturn services.map(([objectId, index], i) => {\n\t\t\treturn {\n\t\t\t\tindex,\n\t\t\t\tshare: xor(\n\t\t\t\t\tencryptedShares[i],\n\t\t\t\t\tkdf(gid_r.pairing(publicKeys[i]), nonce, id, objectId, index),\n\t\t\t\t),\n\t\t\t};\n\t\t});\n\t}\n}\n\n/**\n * Batched identity-based key-encapsulation mechanism: encapsulate multiple keys for given identity using different key servers.\n *\n * @param publicKeys Public keys for a set of key servers.\n * @param id The identity used to encapsulate the keys.\n * @returns The randomness, a common nonce of the keys and a list of keys.\n */\nfunction encapBatched(publicKeys: G2Element[], id: Uint8Array): [Scalar, G2Element, GTElement[]] {\n\tif (publicKeys.length === 0) {\n\t\tthrow new Error('No public keys provided');\n\t}\n\tconst r = Scalar.random();\n\tconst nonce = G2Element.generator().multiply(r);\n\tconst gid_r = hashToG1(id).multiply(r);\n\treturn [r, nonce, publicKeys.map((public_key) => gid_r.pairing(public_key))];\n}\n\n/**\n * Decapsulate a key using a user secret key and the nonce.\n *\n * @param usk The user secret key.\n * @param nonce The nonce.\n * @returns The encapsulated key.\n */\nfunction decap(nonce: G2Element, usk: G1Element): GTElement {\n\treturn usk.pairing(nonce);\n}\n\n/**\n * Verify that the given randomness was used to crate the nonce.\n * Throws an error if the given randomness is invalid (not a BLS scalar).\n *\n * @param randomness - The randomness.\n * @param nonce - The nonce.\n * @param useBE - Flag to indicate if BE encoding is used for the randomness. Defaults to true.\n * @returns True if the randomness was used to create the nonce, false otherwise.\n */\nexport function verifyNonce(\n\tnonce: G2Element,\n\trandomness: Uint8Array,\n\tuseBE: boolean = true,\n): boolean {\n\ttry {\n\t\tconst r = decodeRandomness(randomness, useBE);\n\t\treturn G2Element.generator().multiply(r).equals(nonce);\n\t} catch {\n\t\tthrow new InvalidCiphertextError('Invalid randomness');\n\t}\n}\n\nfunction decodeRandomness(bytes: Uint8Array, useBE: boolean): Scalar {\n\tif (useBE) {\n\t\treturn Scalar.fromBytes(bytes);\n\t} else {\n\t\treturn Scalar.fromBytesLE(bytes);\n\t}\n}\n\n/**\n * Decrypt the randomness using a key.\n *\n * @param encrypted_randomness - The encrypted randomness.\n * @param derived_key - The derived key.\n * @returns The randomness. Returns both the scalar interpreted in big-endian and little-endian encoding.\n */\nexport function decryptRandomness(\n\tencryptedRandomness: Uint8Array,\n\trandomnessKey: Uint8Array,\n): Uint8Array {\n\treturn xor(encryptedRandomness, randomnessKey);\n}\n\n/**\n * Verify that the given randomness was used to crate the nonce.\n * Check using both big-endian and little-endian encoding of the randomness.\n *\n * Throws an error if the nonce check doesn't pass using LE encoding _and_ the randomness is invalid as a BE encoded scalar.\n *\n * @param randomness - The randomness.\n * @param nonce - The nonce.\n * @returns True if the randomness was used to create the nonce using either LE or BE encoding, false otherwise.\n */\nexport function verifyNonceWithLE(nonce: G2Element, randomness: Uint8Array): boolean {\n\ttry {\n\t\t// First try little-endian encoding\n\t\tif (verifyNonce(nonce, randomness, false)) {\n\t\t\treturn true;\n\t\t}\n\t} catch {\n\t\t// Ignore error and try big-endian encoding\n\t}\n\treturn verifyNonce(nonce, randomness, true);\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,eAAe;AAIxB,SAAS,WAAW,cAAc;AAClC,SAAS,WAAW,UAAU,KAAK,kBAAkB;AAErD,SAAS,WAAW;AAEpB,SAAS,8BAA8B;AAKhC,MAAM,UAAsB,IAAI,YAAY,EAAE,OAAO,8BAA8B;AAKnF,MAAe,WAAW;AAAA,EAGhC,YAAY,WAAqB;AAChC,SAAK,YAAY;AAAA,EAClB;AAeD;AAQO,MAAM,sCAAsC,WAAW;AAAA,EAG7D,YAAY,UAAuB;AAClC,UAAM,SAAS,IAAI,CAAC,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D,QAAQ;AACP,UAAM,IAAI,uBAAuB,oBAAoB;AAAA,EACtD;AACD;AAEA,SAAS,iBAAiB,OAAmB,OAAwB;AACpE,MAAI,OAAO;AACV,WAAO,OAAO,UAAU,KAAK;AAAA,EAC9B,OAAO;AACN,WAAO,OAAO,YAAY,KAAK;AAAA,EAChC;AACD;AASO,SAAS,kBACf,qBACA,eACa;AACb,SAAO,IAAI,qBAAqB,aAAa;AAC9C;AAYO,SAAS,kBAAkB,OAAkB,YAAiC;AACpF,MAAI;AAEH,QAAI,YAAY,OAAO,YAAY,KAAK,GAAG;AAC1C,aAAO;AAAA,IACR;AAAA,EACD,QAAQ;AAAA,EAER;AACA,SAAO,YAAY,OAAO,YAAY,IAAI;AAC3C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { EncryptedObject } from './bcs.js';
|
|
2
|
-
export { SealClient } from './client.js';
|
|
3
|
-
export { SessionKey, type ExportedSessionKey } from './session-key.js';
|
|
4
|
-
export * from './error.js';
|
|
5
|
-
export type { SealCompatibleClient, SealClientOptions, SealClientExtensionOptions, KeyServerConfig, EncryptOptions, DecryptOptions, FetchKeysOptions, GetDerivedKeysOptions, } from './types.js';
|
|
6
|
-
export { DemType } from './encrypt.js';
|
package/dist/esm/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { EncryptedObject } from "./bcs.js";
|
|
2
|
-
import { SealClient } from "./client.js";
|
|
3
|
-
import { SessionKey } from "./session-key.js";
|
|
4
|
-
export * from "./error.js";
|
|
5
|
-
import { DemType } from "./encrypt.js";
|
|
6
|
-
export {
|
|
7
|
-
DemType,
|
|
8
|
-
EncryptedObject,
|
|
9
|
-
SealClient,
|
|
10
|
-
SessionKey
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nexport { EncryptedObject } from './bcs.js';\nexport { SealClient } from './client.js';\nexport { SessionKey, type ExportedSessionKey } from './session-key.js';\nexport * from './error.js';\nexport type {\n\tSealCompatibleClient,\n\tSealClientOptions,\n\tSealClientExtensionOptions,\n\tKeyServerConfig,\n\tEncryptOptions,\n\tDecryptOptions,\n\tFetchKeysOptions,\n\tGetDerivedKeysOptions,\n} from './types.js';\nexport { DemType } from './encrypt.js';\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,kBAA2C;AACpD,cAAc;AAWd,SAAS,eAAe;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/esm/kdf.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { G1Element } from './bls12381.js';
|
|
2
|
-
import type { G2Element, GTElement } from './bls12381.js';
|
|
3
|
-
/**
|
|
4
|
-
* Hash an id to a G1Element.
|
|
5
|
-
*
|
|
6
|
-
* @param id The id to hash.
|
|
7
|
-
* @returns The G1Element.
|
|
8
|
-
*/
|
|
9
|
-
export declare function hashToG1(id: Uint8Array): G1Element;
|
|
10
|
-
/**
|
|
11
|
-
* The default key derivation function.
|
|
12
|
-
*
|
|
13
|
-
* @returns The derived key.
|
|
14
|
-
*/
|
|
15
|
-
export declare function kdf(element: GTElement, nonce: G2Element, id: Uint8Array, objectId: string, index: number): Uint8Array;
|
|
16
|
-
export declare enum KeyPurpose {
|
|
17
|
-
EncryptedRandomness = 0,
|
|
18
|
-
DEM = 1
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Derive a key from a base key and a list of encrypted shares.
|
|
22
|
-
*
|
|
23
|
-
* @param purpose The purpose of the key.
|
|
24
|
-
* @param baseKey The base key.
|
|
25
|
-
* @param encryptedShares The encrypted shares.
|
|
26
|
-
* @param threshold The threshold.
|
|
27
|
-
* @param keyServers The object ids of the key servers.
|
|
28
|
-
* @returns The derived key.
|
|
29
|
-
*/
|
|
30
|
-
export declare function deriveKey(purpose: KeyPurpose, baseKey: Uint8Array, encryptedShares: Uint8Array[], threshold: number, keyServers: string[]): Uint8Array;
|
package/dist/esm/kdf.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { fromHex } from "@mysten/bcs";
|
|
2
|
-
import { sha3_256 } from "@noble/hashes/sha3";
|
|
3
|
-
import { G1Element } from "./bls12381.js";
|
|
4
|
-
import {
|
|
5
|
-
ENCRYPTED_SHARE_LENGTH,
|
|
6
|
-
flatten,
|
|
7
|
-
KEY_LENGTH,
|
|
8
|
-
MAX_U8,
|
|
9
|
-
SUI_ADDRESS_LENGTH
|
|
10
|
-
} from "./utils.js";
|
|
11
|
-
const DST = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-00");
|
|
12
|
-
const KDF_DST = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-H2-00");
|
|
13
|
-
const DERIVE_KEY_DST = new TextEncoder().encode("SUI-SEAL-IBE-BLS12381-H3-00");
|
|
14
|
-
function hashToG1(id) {
|
|
15
|
-
return G1Element.hashToCurve(flatten([DST, id]));
|
|
16
|
-
}
|
|
17
|
-
function kdf(element, nonce, id, objectId, index) {
|
|
18
|
-
if (!Number.isInteger(index) || index < 0 || index > MAX_U8) {
|
|
19
|
-
throw new Error(`Invalid index ${index}`);
|
|
20
|
-
}
|
|
21
|
-
const objectIdBytes = fromHex(objectId);
|
|
22
|
-
if (objectIdBytes.length !== SUI_ADDRESS_LENGTH) {
|
|
23
|
-
throw new Error(`Invalid object id ${objectId}`);
|
|
24
|
-
}
|
|
25
|
-
const hash = sha3_256.create();
|
|
26
|
-
hash.update(KDF_DST);
|
|
27
|
-
hash.update(element.toBytes());
|
|
28
|
-
hash.update(nonce.toBytes());
|
|
29
|
-
hash.update(hashToG1(id).toBytes());
|
|
30
|
-
hash.update(objectIdBytes);
|
|
31
|
-
hash.update(new Uint8Array([index]));
|
|
32
|
-
return hash.digest();
|
|
33
|
-
}
|
|
34
|
-
var KeyPurpose = /* @__PURE__ */ ((KeyPurpose2) => {
|
|
35
|
-
KeyPurpose2[KeyPurpose2["EncryptedRandomness"] = 0] = "EncryptedRandomness";
|
|
36
|
-
KeyPurpose2[KeyPurpose2["DEM"] = 1] = "DEM";
|
|
37
|
-
return KeyPurpose2;
|
|
38
|
-
})(KeyPurpose || {});
|
|
39
|
-
function tag(purpose) {
|
|
40
|
-
switch (purpose) {
|
|
41
|
-
case 0 /* EncryptedRandomness */:
|
|
42
|
-
return new Uint8Array([0]);
|
|
43
|
-
case 1 /* DEM */:
|
|
44
|
-
return new Uint8Array([1]);
|
|
45
|
-
default:
|
|
46
|
-
throw new Error(`Invalid key purpose ${purpose}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function deriveKey(purpose, baseKey, encryptedShares, threshold, keyServers) {
|
|
50
|
-
if (!Number.isInteger(threshold) || threshold <= 0 || threshold > MAX_U8) {
|
|
51
|
-
throw new Error(`Invalid threshold ${threshold}`);
|
|
52
|
-
}
|
|
53
|
-
if (encryptedShares.length !== keyServers.length) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Mismatched shares ${encryptedShares.length} and key servers ${keyServers.length}`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
const keyServerBytes = keyServers.map((keyServer) => fromHex(keyServer));
|
|
59
|
-
if (keyServerBytes.some((keyServer) => keyServer.length !== SUI_ADDRESS_LENGTH)) {
|
|
60
|
-
throw new Error(`Invalid key servers ${keyServers}`);
|
|
61
|
-
}
|
|
62
|
-
if (encryptedShares.some((share) => share.length !== ENCRYPTED_SHARE_LENGTH)) {
|
|
63
|
-
throw new Error(`Invalid encrypted shares ${encryptedShares}`);
|
|
64
|
-
}
|
|
65
|
-
if (baseKey.length !== KEY_LENGTH) {
|
|
66
|
-
throw new Error(`Invalid base key ${baseKey}`);
|
|
67
|
-
}
|
|
68
|
-
const hash = sha3_256.create();
|
|
69
|
-
hash.update(DERIVE_KEY_DST);
|
|
70
|
-
hash.update(baseKey);
|
|
71
|
-
hash.update(tag(purpose));
|
|
72
|
-
hash.update(new Uint8Array([threshold]));
|
|
73
|
-
encryptedShares.forEach((share) => hash.update(share));
|
|
74
|
-
keyServerBytes.forEach((keyServer) => hash.update(keyServer));
|
|
75
|
-
return hash.digest();
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
KeyPurpose,
|
|
79
|
-
deriveKey,
|
|
80
|
-
hashToG1,
|
|
81
|
-
kdf
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=kdf.js.map
|
package/dist/esm/kdf.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/kdf.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex } from '@mysten/bcs';\nimport { sha3_256 } from '@noble/hashes/sha3';\n\nimport { G1Element } from './bls12381.js';\nimport type { G2Element, GTElement } from './bls12381.js';\nimport {\n\tENCRYPTED_SHARE_LENGTH,\n\tflatten,\n\tKEY_LENGTH,\n\tMAX_U8,\n\tSUI_ADDRESS_LENGTH,\n} from './utils.js';\n\n/**\n * The domain separation tag for the hash-to-group function.\n */\nconst DST: Uint8Array = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-00');\nconst KDF_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H2-00');\nconst DERIVE_KEY_DST = new TextEncoder().encode('SUI-SEAL-IBE-BLS12381-H3-00');\n\n/**\n * Hash an id to a G1Element.\n *\n * @param id The id to hash.\n * @returns The G1Element.\n */\nexport function hashToG1(id: Uint8Array): G1Element {\n\treturn G1Element.hashToCurve(flatten([DST, id]));\n}\n\n/**\n * The default key derivation function.\n *\n * @returns The derived key.\n */\nexport function kdf(\n\telement: GTElement,\n\tnonce: G2Element,\n\tid: Uint8Array,\n\tobjectId: string,\n\tindex: number,\n): Uint8Array {\n\tif (!Number.isInteger(index) || index < 0 || index > MAX_U8) {\n\t\tthrow new Error(`Invalid index ${index}`);\n\t}\n\tconst objectIdBytes = fromHex(objectId);\n\tif (objectIdBytes.length !== SUI_ADDRESS_LENGTH) {\n\t\tthrow new Error(`Invalid object id ${objectId}`);\n\t}\n\tconst hash = sha3_256.create();\n\thash.update(KDF_DST);\n\thash.update(element.toBytes());\n\thash.update(nonce.toBytes());\n\thash.update(hashToG1(id).toBytes());\n\thash.update(objectIdBytes);\n\thash.update(new Uint8Array([index])); // this is safe because index < 256.\n\treturn hash.digest();\n}\n\nexport enum KeyPurpose {\n\tEncryptedRandomness,\n\tDEM,\n}\n\nfunction tag(purpose: KeyPurpose): Uint8Array {\n\tswitch (purpose) {\n\t\tcase KeyPurpose.EncryptedRandomness:\n\t\t\treturn new Uint8Array([0]);\n\t\tcase KeyPurpose.DEM:\n\t\t\treturn new Uint8Array([1]);\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid key purpose ${purpose}`);\n\t}\n}\n\n/**\n * Derive a key from a base key and a list of encrypted shares.\n *\n * @param purpose The purpose of the key.\n * @param baseKey The base key.\n * @param encryptedShares The encrypted shares.\n * @param threshold The threshold.\n * @param keyServers The object ids of the key servers.\n * @returns The derived key.\n */\nexport function deriveKey(\n\tpurpose: KeyPurpose,\n\tbaseKey: Uint8Array,\n\tencryptedShares: Uint8Array[],\n\tthreshold: number,\n\tkeyServers: string[],\n): Uint8Array {\n\tif (!Number.isInteger(threshold) || threshold <= 0 || threshold > MAX_U8) {\n\t\tthrow new Error(`Invalid threshold ${threshold}`);\n\t}\n\n\tif (encryptedShares.length !== keyServers.length) {\n\t\tthrow new Error(\n\t\t\t`Mismatched shares ${encryptedShares.length} and key servers ${keyServers.length}`,\n\t\t);\n\t}\n\tconst keyServerBytes = keyServers.map((keyServer) => fromHex(keyServer));\n\tif (keyServerBytes.some((keyServer) => keyServer.length !== SUI_ADDRESS_LENGTH)) {\n\t\tthrow new Error(`Invalid key servers ${keyServers}`);\n\t}\n\tif (encryptedShares.some((share) => share.length !== ENCRYPTED_SHARE_LENGTH)) {\n\t\tthrow new Error(`Invalid encrypted shares ${encryptedShares}`);\n\t}\n\n\tif (baseKey.length !== KEY_LENGTH) {\n\t\tthrow new Error(`Invalid base key ${baseKey}`);\n\t}\n\n\tconst hash = sha3_256.create();\n\thash.update(DERIVE_KEY_DST);\n\thash.update(baseKey);\n\thash.update(tag(purpose));\n\thash.update(new Uint8Array([threshold]));\n\tencryptedShares.forEach((share) => hash.update(share));\n\tkeyServerBytes.forEach((keyServer) => hash.update(keyServer));\n\treturn hash.digest();\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAE1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,MAAM,MAAkB,IAAI,YAAY,EAAE,OAAO,0BAA0B;AAC3E,MAAM,UAAU,IAAI,YAAY,EAAE,OAAO,6BAA6B;AACtE,MAAM,iBAAiB,IAAI,YAAY,EAAE,OAAO,6BAA6B;AAQtE,SAAS,SAAS,IAA2B;AACnD,SAAO,UAAU,YAAY,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;AAChD;AAOO,SAAS,IACf,SACA,OACA,IACA,UACA,OACa;AACb,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAC5D,UAAM,IAAI,MAAM,iBAAiB,KAAK,EAAE;AAAA,EACzC;AACA,QAAM,gBAAgB,QAAQ,QAAQ;AACtC,MAAI,cAAc,WAAW,oBAAoB;AAChD,UAAM,IAAI,MAAM,qBAAqB,QAAQ,EAAE;AAAA,EAChD;AACA,QAAM,O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,QAAQ,WAAW,YAAY;AAClC,UAAM,IAAI,MAAM,oBAAoB,OAAO,EAAE;AAAA,EAC9C;AAEA,QAAM,OAAO,SAAS,OAAO;AAC7B,OAAK,OAAO,cAAc;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,OAAO,IAAI,OAAO,CAAC;AACxB,OAAK,OAAO,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;AACvC,kBAAgB,QAAQ,CAAC,UAAU,KAAK,OAAO,KAAK,CAAC;AACrD,iBAAe,QAAQ,CAAC,cAAc,KAAK,OAAO,SAAS,CAAC;AAC5D,SAAO,KAAK,OAAO;AACpB;",
|
|
6
|
-
"names": ["KeyPurpose"]
|
|
7
|
-
}
|
package/dist/esm/key-server.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { KeyServerConfig, SealCompatibleClient } from './types.js';
|
|
2
|
-
import type { G1Element } from './bls12381.js';
|
|
3
|
-
import { Version } from './utils.js';
|
|
4
|
-
import type { Certificate } from './session-key.js';
|
|
5
|
-
export type ServerType = 'Independent' | 'Committee';
|
|
6
|
-
export type KeyServer = {
|
|
7
|
-
objectId: string;
|
|
8
|
-
name: string;
|
|
9
|
-
url: string;
|
|
10
|
-
keyType: KeyType;
|
|
11
|
-
pk: Uint8Array<ArrayBuffer>;
|
|
12
|
-
serverType: ServerType;
|
|
13
|
-
};
|
|
14
|
-
export declare enum KeyType {
|
|
15
|
-
BonehFranklinBLS12381 = 0
|
|
16
|
-
}
|
|
17
|
-
export declare const SERVER_VERSION_REQUIREMENT: Version;
|
|
18
|
-
/**
|
|
19
|
-
* Given a list of key server object IDs, returns a list of SealKeyServer
|
|
20
|
-
* from onchain state containing name, objectId, URL and pk.
|
|
21
|
-
*
|
|
22
|
-
* Supports both V1 (independent servers) and V2 (independent + committee servers).
|
|
23
|
-
* For V2 committee servers, returns the aggregator URL from the config.
|
|
24
|
-
*
|
|
25
|
-
* @param objectIds - The key server object IDs.
|
|
26
|
-
* @param client - The SuiClient to use.
|
|
27
|
-
* @param configs - The key server configurations containing aggregator URLs.
|
|
28
|
-
* @returns - An array of SealKeyServer.
|
|
29
|
-
*/
|
|
30
|
-
export declare function retrieveKeyServers({ objectIds, client, configs, }: {
|
|
31
|
-
objectIds: string[];
|
|
32
|
-
client: SealCompatibleClient;
|
|
33
|
-
configs: Map<string, KeyServerConfig>;
|
|
34
|
-
}): Promise<KeyServer[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Given a KeyServer, fetch the proof of possession (PoP) from the URL and verify it
|
|
37
|
-
* against the pubkey. This should be used only rarely when the dapp uses a dynamic
|
|
38
|
-
* set of key servers.
|
|
39
|
-
*
|
|
40
|
-
* @param server - The KeyServer to verify.
|
|
41
|
-
* @returns - True if the key server is valid, false otherwise.
|
|
42
|
-
*/
|
|
43
|
-
export declare function verifyKeyServer(server: KeyServer, timeout: number, apiKeyName?: string, apiKey?: string): Promise<boolean>;
|
|
44
|
-
/**
|
|
45
|
-
* Verify the key server version. Throws an `InvalidKeyServerError` if the version is not supported.
|
|
46
|
-
*
|
|
47
|
-
* @param response - The response from the key server.
|
|
48
|
-
*/
|
|
49
|
-
export declare function verifyKeyServerVersion(response: Response): void;
|
|
50
|
-
export interface DerivedKey {
|
|
51
|
-
toString(): string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* A user secret key for the Boneh-Franklin BLS12381 scheme.
|
|
55
|
-
* This is a wrapper around the G1Element type.
|
|
56
|
-
*/
|
|
57
|
-
export declare class BonehFranklinBLS12381DerivedKey implements DerivedKey {
|
|
58
|
-
key: G1Element;
|
|
59
|
-
representation: string;
|
|
60
|
-
constructor(key: G1Element);
|
|
61
|
-
toString(): string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Options for fetching keys from the key server.
|
|
65
|
-
*/
|
|
66
|
-
export interface FetchKeysOptions {
|
|
67
|
-
/** The URL of the key server. */
|
|
68
|
-
url: string;
|
|
69
|
-
/** The Base64 string of request signature. */
|
|
70
|
-
requestSignature: string;
|
|
71
|
-
/** The transaction bytes. */
|
|
72
|
-
transactionBytes: Uint8Array;
|
|
73
|
-
/** The ephemeral secret key. */
|
|
74
|
-
encKey: Uint8Array<ArrayBuffer>;
|
|
75
|
-
/** The ephemeral public key. */
|
|
76
|
-
encKeyPk: Uint8Array<ArrayBuffer>;
|
|
77
|
-
/** The ephemeral verification key. */
|
|
78
|
-
encVerificationKey: Uint8Array;
|
|
79
|
-
/** The certificate. */
|
|
80
|
-
certificate: Certificate;
|
|
81
|
-
/** Request timeout in milliseconds. */
|
|
82
|
-
timeout: number;
|
|
83
|
-
/** Optional API key name. */
|
|
84
|
-
apiKeyName?: string;
|
|
85
|
-
/** Optional API key. */
|
|
86
|
-
apiKey?: string;
|
|
87
|
-
/** Optional abort signal for cancellation. */
|
|
88
|
-
signal?: AbortSignal;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Helper function to request all keys from URL with requestSig, txBytes, ephemeral pubkey.
|
|
92
|
-
* Then decrypt the Seal key with ephemeral secret key. Returns a list decryption keys with
|
|
93
|
-
* their full IDs.
|
|
94
|
-
*
|
|
95
|
-
* @param url - The URL of the key server.
|
|
96
|
-
* @param requestSig - The Base64 string of request signature.
|
|
97
|
-
* @param txBytes - The transaction bytes.
|
|
98
|
-
* @param encKey - The ephemeral secret key.
|
|
99
|
-
* @param certificate - The certificate.
|
|
100
|
-
* @returns - A list of full ID and the decrypted key.
|
|
101
|
-
*/
|
|
102
|
-
export declare function fetchKeysForAllIds({ url, requestSignature, transactionBytes, encKey, encKeyPk, encVerificationKey, certificate, timeout, apiKeyName, apiKey, signal, }: FetchKeysOptions): Promise<{
|
|
103
|
-
fullId: string;
|
|
104
|
-
key: Uint8Array<ArrayBuffer>;
|
|
105
|
-
}[]>;
|