@primuslabs/fhetransform-sdk 0.4.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/README.md +198 -0
- package/dist/abis/acl.abi.d.ts +379 -0
- package/dist/abis/acl.abi.js +495 -0
- package/dist/abis/acl.abi.js.map +1 -0
- package/dist/abis/alphatrion_reward.abi.d.ts +407 -0
- package/dist/abis/alphatrion_reward.abi.js +532 -0
- package/dist/abis/alphatrion_reward.abi.js.map +1 -0
- package/dist/abis/ciphertext_digests.abi.d.ts +336 -0
- package/dist/abis/ciphertext_digests.abi.js +444 -0
- package/dist/abis/ciphertext_digests.abi.js.map +1 -0
- package/dist/abis/ciphertext_verification.abi.d.ts +637 -0
- package/dist/abis/ciphertext_verification.abi.js +830 -0
- package/dist/abis/ciphertext_verification.abi.js.map +1 -0
- package/dist/abis/convert_token.abi.d.ts +922 -0
- package/dist/abis/convert_token.abi.js +1208 -0
- package/dist/abis/convert_token.abi.js.map +1 -0
- package/dist/abis/decryption.abi.d.ts +956 -0
- package/dist/abis/decryption.abi.js +1244 -0
- package/dist/abis/decryption.abi.js.map +1 -0
- package/dist/abis/erc20.abi.d.ts +265 -0
- package/dist/abis/erc20.abi.js +350 -0
- package/dist/abis/erc20.abi.js.map +1 -0
- package/dist/abis/fhe_executor.abi.d.ts +1535 -0
- package/dist/abis/fhe_executor.abi.js +1962 -0
- package/dist/abis/fhe_executor.abi.js.map +1 -0
- package/dist/abis/space_bridge_config.abi.d.ts +792 -0
- package/dist/abis/space_bridge_config.abi.js +1032 -0
- package/dist/abis/space_bridge_config.abi.js.map +1 -0
- package/dist/abis/token.abi.d.ts +630 -0
- package/dist/abis/token.abi.js +828 -0
- package/dist/abis/token.abi.js.map +1 -0
- package/dist/cli/eusdc.d.ts +2 -0
- package/dist/cli/eusdc.js +41 -0
- package/dist/cli/eusdc.js.map +1 -0
- package/dist/contract/callbacks.d.ts +59 -0
- package/dist/contract/callbacks.js +2 -0
- package/dist/contract/callbacks.js.map +1 -0
- package/dist/contract/convert-token.d.ts +107 -0
- package/dist/contract/convert-token.js +249 -0
- package/dist/contract/convert-token.js.map +1 -0
- package/dist/contract/token.d.ts +167 -0
- package/dist/contract/token.js +404 -0
- package/dist/contract/token.js.map +1 -0
- package/dist/contract/transaction.d.ts +29 -0
- package/dist/contract/transaction.js +2 -0
- package/dist/contract/transaction.js.map +1 -0
- package/dist/core/address.d.ts +118 -0
- package/dist/core/address.js +200 -0
- package/dist/core/address.js.map +1 -0
- package/dist/core/auth.d.ts +68 -0
- package/dist/core/auth.js +58 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/bytes.d.ts +48 -0
- package/dist/core/bytes.js +117 -0
- package/dist/core/bytes.js.map +1 -0
- package/dist/core/cache-manager.d.ts +138 -0
- package/dist/core/cache-manager.js +440 -0
- package/dist/core/cache-manager.js.map +1 -0
- package/dist/core/chain.d.ts +41 -0
- package/dist/core/chain.js +59 -0
- package/dist/core/chain.js.map +1 -0
- package/dist/core/constants.d.ts +24 -0
- package/dist/core/constants.js +25 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/error.d.ts +2 -0
- package/dist/core/error.js +14 -0
- package/dist/core/error.js.map +1 -0
- package/dist/core/errors/error-catalog.d.ts +29 -0
- package/dist/core/errors/error-catalog.js +84 -0
- package/dist/core/errors/error-catalog.js.map +1 -0
- package/dist/core/errors/error-codes.d.ts +52 -0
- package/dist/core/errors/error-codes.js +61 -0
- package/dist/core/errors/error-codes.js.map +1 -0
- package/dist/core/errors/error-utils.d.ts +27 -0
- package/dist/core/errors/error-utils.js +110 -0
- package/dist/core/errors/error-utils.js.map +1 -0
- package/dist/core/errors/fhe-error.d.ts +98 -0
- package/dist/core/errors/fhe-error.js +190 -0
- package/dist/core/errors/fhe-error.js.map +1 -0
- package/dist/core/errors/index.d.ts +4 -0
- package/dist/core/errors/index.js +5 -0
- package/dist/core/errors/index.js.map +1 -0
- package/dist/core/estimate.d.ts +39 -0
- package/dist/core/estimate.js +111 -0
- package/dist/core/estimate.js.map +1 -0
- package/dist/core/event.d.ts +212 -0
- package/dist/core/event.js +42 -0
- package/dist/core/event.js.map +1 -0
- package/dist/core/fhe-type.d.ts +75 -0
- package/dist/core/fhe-type.js +115 -0
- package/dist/core/fhe-type.js.map +1 -0
- package/dist/core/fhe.d.ts +11 -0
- package/dist/core/fhe.js +23 -0
- package/dist/core/fhe.js.map +1 -0
- package/dist/core/handle.d.ts +42 -0
- package/dist/core/handle.js +99 -0
- package/dist/core/handle.js.map +1 -0
- package/dist/core/json-utils.d.ts +18 -0
- package/dist/core/json-utils.js +37 -0
- package/dist/core/json-utils.js.map +1 -0
- package/dist/core/kms.d.ts +42 -0
- package/dist/core/kms.js +70 -0
- package/dist/core/kms.js.map +1 -0
- package/dist/core/logger.d.ts +3 -0
- package/dist/core/logger.js +11 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/pretty-print.d.ts +18 -0
- package/dist/core/pretty-print.js +84 -0
- package/dist/core/pretty-print.js.map +1 -0
- package/dist/core/primitives.d.ts +22 -0
- package/dist/core/primitives.js +2 -0
- package/dist/core/primitives.js.map +1 -0
- package/dist/core/retryable-handler.d.ts +74 -0
- package/dist/core/retryable-handler.js +227 -0
- package/dist/core/retryable-handler.js.map +1 -0
- package/dist/core/signer-address-info.d.ts +15 -0
- package/dist/core/signer-address-info.js +33 -0
- package/dist/core/signer-address-info.js.map +1 -0
- package/dist/core/string.d.ts +28 -0
- package/dist/core/string.js +33 -0
- package/dist/core/string.js.map +1 -0
- package/dist/core/swallow.d.ts +23 -0
- package/dist/core/swallow.js +37 -0
- package/dist/core/swallow.js.map +1 -0
- package/dist/core/system-contract-info.d.ts +17 -0
- package/dist/core/system-contract-info.js +41 -0
- package/dist/core/system-contract-info.js.map +1 -0
- package/dist/core/ttl-cache.d.ts +81 -0
- package/dist/core/ttl-cache.js +113 -0
- package/dist/core/ttl-cache.js.map +1 -0
- package/dist/core/tx-error-parser.d.ts +40 -0
- package/dist/core/tx-error-parser.js +83 -0
- package/dist/core/tx-error-parser.js.map +1 -0
- package/dist/core/utils.d.ts +62 -0
- package/dist/core/utils.js +143 -0
- package/dist/core/utils.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/jazz/encrypt-key-p.d.ts +65 -0
- package/dist/jazz/encrypt-key-p.js +283 -0
- package/dist/jazz/encrypt-key-p.js.map +1 -0
- package/dist/jazz/encrypt-p.d.ts +82 -0
- package/dist/jazz/encrypt-p.js +139 -0
- package/dist/jazz/encrypt-p.js.map +1 -0
- package/dist/jazz/encrypt.d.ts +58 -0
- package/dist/jazz/encrypt.js +155 -0
- package/dist/jazz/encrypt.js.map +1 -0
- package/dist/jazz/input-proof-p.d.ts +122 -0
- package/dist/jazz/input-proof-p.js +265 -0
- package/dist/jazz/input-proof-p.js.map +1 -0
- package/dist/jazz/jazz-client-i.d.ts +16 -0
- package/dist/jazz/jazz-client-i.js +2 -0
- package/dist/jazz/jazz-client-i.js.map +1 -0
- package/dist/jazz/jazz-client.d.ts +18 -0
- package/dist/jazz/jazz-client.js +24 -0
- package/dist/jazz/jazz-client.js.map +1 -0
- package/dist/jazz/key-pair.d.ts +50 -0
- package/dist/jazz/key-pair.js +166 -0
- package/dist/jazz/key-pair.js.map +1 -0
- package/dist/jazz/mock/fake.d.ts +3 -0
- package/dist/jazz/mock/fake.js +23 -0
- package/dist/jazz/mock/fake.js.map +1 -0
- package/dist/jazz/mock/fetch-input-proof.d.ts +4 -0
- package/dist/jazz/mock/fetch-input-proof.js +63 -0
- package/dist/jazz/mock/fetch-input-proof.js.map +1 -0
- package/dist/jazz/mock/fetch-key-url.d.ts +3 -0
- package/dist/jazz/mock/fetch-key-url.js +15 -0
- package/dist/jazz/mock/fetch-key-url.js.map +1 -0
- package/dist/jazz/mock/fetch-public-decrypt.d.ts +3 -0
- package/dist/jazz/mock/fetch-public-decrypt.js +81 -0
- package/dist/jazz/mock/fetch-public-decrypt.js.map +1 -0
- package/dist/jazz/mock/fetch-user-decrypt.d.ts +4 -0
- package/dist/jazz/mock/fetch-user-decrypt.js +174 -0
- package/dist/jazz/mock/fetch-user-decrypt.js.map +1 -0
- package/dist/jazz/module/fetch-input-proof.d.ts +19 -0
- package/dist/jazz/module/fetch-input-proof.js +72 -0
- package/dist/jazz/module/fetch-input-proof.js.map +1 -0
- package/dist/jazz/module/fetch-key-url.d.ts +17 -0
- package/dist/jazz/module/fetch-key-url.js +46 -0
- package/dist/jazz/module/fetch-key-url.js.map +1 -0
- package/dist/jazz/module/fetch-public-decrypt.d.ts +19 -0
- package/dist/jazz/module/fetch-public-decrypt.js +65 -0
- package/dist/jazz/module/fetch-public-decrypt.js.map +1 -0
- package/dist/jazz/module/fetch-user-decrypt.d.ts +19 -0
- package/dist/jazz/module/fetch-user-decrypt.js +109 -0
- package/dist/jazz/module/fetch-user-decrypt.js.map +1 -0
- package/dist/jazz/module/jazz-async-request.d.ts +102 -0
- package/dist/jazz/module/jazz-async-request.js +515 -0
- package/dist/jazz/module/jazz-async-request.js.map +1 -0
- package/dist/jazz/module/jazz-p.d.ts +61 -0
- package/dist/jazz/module/jazz-p.js +33 -0
- package/dist/jazz/module/jazz-p.js.map +1 -0
- package/dist/jazz/module/s3-download.d.ts +85 -0
- package/dist/jazz/module/s3-download.js +293 -0
- package/dist/jazz/module/s3-download.js.map +1 -0
- package/dist/jazz/permit.d.ts +200 -0
- package/dist/jazz/permit.js +319 -0
- package/dist/jazz/permit.js.map +1 -0
- package/dist/jazz/public-decrypt-p.d.ts +96 -0
- package/dist/jazz/public-decrypt-p.js +258 -0
- package/dist/jazz/public-decrypt-p.js.map +1 -0
- package/dist/jazz/public-decrypt.d.ts +48 -0
- package/dist/jazz/public-decrypt.js +156 -0
- package/dist/jazz/public-decrypt.js.map +1 -0
- package/dist/jazz/read-contract.d.ts +81 -0
- package/dist/jazz/read-contract.js +125 -0
- package/dist/jazz/read-contract.js.map +1 -0
- package/dist/jazz/types/common.d.ts +17 -0
- package/dist/jazz/types/common.js +2 -0
- package/dist/jazz/types/common.js.map +1 -0
- package/dist/jazz/types/input-proof.d.ts +76 -0
- package/dist/jazz/types/input-proof.js +2 -0
- package/dist/jazz/types/input-proof.js.map +1 -0
- package/dist/jazz/types/key-url.d.ts +68 -0
- package/dist/jazz/types/key-url.js +5 -0
- package/dist/jazz/types/key-url.js.map +1 -0
- package/dist/jazz/types/public-decrypt.d.ts +61 -0
- package/dist/jazz/types/public-decrypt.js +2 -0
- package/dist/jazz/types/public-decrypt.js.map +1 -0
- package/dist/jazz/types/user-decrypt.d.ts +123 -0
- package/dist/jazz/types/user-decrypt.js +2 -0
- package/dist/jazz/types/user-decrypt.js.map +1 -0
- package/dist/jazz/user-decrypt-p.d.ts +111 -0
- package/dist/jazz/user-decrypt-p.js +280 -0
- package/dist/jazz/user-decrypt-p.js.map +1 -0
- package/dist/jazz/user-decrypt.d.ts +74 -0
- package/dist/jazz/user-decrypt.js +143 -0
- package/dist/jazz/user-decrypt.js.map +1 -0
- package/dist/native/fhe-api.js +5959 -0
- package/dist/native/fhe-api.node.cjs +6167 -0
- package/dist/native/fhe-api.node.worker.cjs +210 -0
- package/dist/native/fhe-api.wasm +0 -0
- package/dist/native/fhe-api.worker.js +164 -0
- package/dist/native/kms/node/kms_lib.d.ts +38 -0
- package/dist/native/kms/node/kms_lib.js +356 -0
- package/dist/native/kms/node/kms_lib_bg.wasm +0 -0
- package/dist/native/kms/node/kms_lib_bg.wasm.d.ts +21 -0
- package/dist/native/kms/node/package.json +11 -0
- package/dist/native/kms/web/kms_lib.d.ts +84 -0
- package/dist/native/kms/web/kms_lib.js +443 -0
- package/dist/native/kms/web/kms_lib_bg.wasm +0 -0
- package/dist/native/kms/web/kms_lib_bg.wasm.d.ts +21 -0
- package/dist/native/kms/web/package.json +15 -0
- package/dist/runtime/browser.d.ts +36 -0
- package/dist/runtime/browser.js +115 -0
- package/dist/runtime/browser.js.map +1 -0
- package/dist/runtime/node.d.ts +30 -0
- package/dist/runtime/node.js +95 -0
- package/dist/runtime/node.js.map +1 -0
- package/dist/sdk/fhetransform-sdk-b.d.ts +102 -0
- package/dist/sdk/fhetransform-sdk-b.js +294 -0
- package/dist/sdk/fhetransform-sdk-b.js.map +1 -0
- package/dist/sdk/fhetransform-sdk.d.ts +87 -0
- package/dist/sdk/fhetransform-sdk.js +135 -0
- package/dist/sdk/fhetransform-sdk.js.map +1 -0
- package/dist/sdk/jazz-service.d.ts +13 -0
- package/dist/sdk/jazz-service.js +58 -0
- package/dist/sdk/jazz-service.js.map +1 -0
- package/dist/sdk/permit-service.d.ts +45 -0
- package/dist/sdk/permit-service.js +144 -0
- package/dist/sdk/permit-service.js.map +1 -0
- package/dist/wasm/fhe-wasm-client.d.ts +19 -0
- package/dist/wasm/fhe-wasm-client.js +23 -0
- package/dist/wasm/fhe-wasm-client.js.map +1 -0
- package/dist/wasm/fhe-wasm-module.d.ts +24 -0
- package/dist/wasm/fhe-wasm-module.js +141 -0
- package/dist/wasm/fhe-wasm-module.js.map +1 -0
- package/dist/wasm/fhe-wasm-type.d.ts +59 -0
- package/dist/wasm/fhe-wasm-type.js +244 -0
- package/dist/wasm/fhe-wasm-type.js.map +1 -0
- package/dist/wasm/wasm-loader.browser.d.ts +21 -0
- package/dist/wasm/wasm-loader.browser.js +143 -0
- package/dist/wasm/wasm-loader.browser.js.map +1 -0
- package/dist/wasm/wasm-loader.node.d.ts +24 -0
- package/dist/wasm/wasm-loader.node.js +114 -0
- package/dist/wasm/wasm-loader.node.js.map +1 -0
- package/dist/wasm/worker-client.browser.d.ts +6 -0
- package/dist/wasm/worker-client.browser.js +21 -0
- package/dist/wasm/worker-client.browser.js.map +1 -0
- package/dist/wasm/worker-client.d.ts +34 -0
- package/dist/wasm/worker-client.js +160 -0
- package/dist/wasm/worker-client.js.map +1 -0
- package/dist/wasm/worker-client.node.d.ts +6 -0
- package/dist/wasm/worker-client.node.js +20 -0
- package/dist/wasm/worker-client.node.js.map +1 -0
- package/dist/wasm/worker-message.d.ts +61 -0
- package/dist/wasm/worker-message.js +2 -0
- package/dist/wasm/worker-message.js.map +1 -0
- package/dist/wasm/worker-transport.browser.d.ts +15 -0
- package/dist/wasm/worker-transport.browser.js +35 -0
- package/dist/wasm/worker-transport.browser.js.map +1 -0
- package/dist/wasm/worker-transport.d.ts +6 -0
- package/dist/wasm/worker-transport.js +2 -0
- package/dist/wasm/worker-transport.js.map +1 -0
- package/dist/wasm/worker-transport.node.d.ts +17 -0
- package/dist/wasm/worker-transport.node.js +39 -0
- package/dist/wasm/worker-transport.node.js.map +1 -0
- package/dist/wasm/worker.d.ts +1 -0
- package/dist/wasm/worker.js +69 -0
- package/dist/wasm/worker.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Bytes32Hex, BytesHex } from "./primitives.js";
|
|
2
|
+
/**
|
|
3
|
+
* FHE operation types.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum Operator {
|
|
6
|
+
fheNone = 0,
|
|
7
|
+
fheAdd = 1,
|
|
8
|
+
fheSub = 2,
|
|
9
|
+
fheMul = 3,
|
|
10
|
+
fheDiv = 4,
|
|
11
|
+
fheBitAnd = 5,
|
|
12
|
+
fheBitOr = 6,
|
|
13
|
+
fheBitXor = 7,
|
|
14
|
+
fheBitNot = 8,
|
|
15
|
+
fheEq = 9,
|
|
16
|
+
fheNe = 10,
|
|
17
|
+
fheGe = 11,
|
|
18
|
+
fheGt = 12,
|
|
19
|
+
fheLe = 13,
|
|
20
|
+
fheLt = 14,
|
|
21
|
+
fheIfThenElse = 15,
|
|
22
|
+
trivialEncrypt = 16,
|
|
23
|
+
verifyAttestation = 17
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* FHE (Fully Homomorphic Encryption) data types.
|
|
27
|
+
* Represents different integer sizes for encrypted values.
|
|
28
|
+
*/
|
|
29
|
+
export declare enum FheType {
|
|
30
|
+
ve_bool = 0,
|
|
31
|
+
ve_uint8 = 1,
|
|
32
|
+
ve_uint16 = 2,
|
|
33
|
+
ve_uint32 = 3,
|
|
34
|
+
ve_uint64 = 4,
|
|
35
|
+
ve_uint128 = 5,
|
|
36
|
+
ve_uint256 = 6
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts an FheType enum value to its Solidity type string representation.
|
|
40
|
+
* @param fheType - The FheType enum value
|
|
41
|
+
* @returns The corresponding Solidity type string
|
|
42
|
+
* @throws Error if the FheType is unsupported
|
|
43
|
+
*/
|
|
44
|
+
export declare function getFheTypeString(fheType: FheType): string;
|
|
45
|
+
/**
|
|
46
|
+
* Converts a Solidity type string to its FheType enum value.
|
|
47
|
+
* @param type - The Solidity type string (e.g., "uint256")
|
|
48
|
+
* @returns The corresponding FheType enum value
|
|
49
|
+
* @throws Error if the Solidity type is unsupported
|
|
50
|
+
*/
|
|
51
|
+
export declare function getFheTypeFromString(type: string): FheType;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the byte length for a given FHE type.
|
|
54
|
+
* @param fheType - The FheType enum value
|
|
55
|
+
* @returns The byte length of the type
|
|
56
|
+
*/
|
|
57
|
+
export declare function getTypeLength(fheType: FheType): number;
|
|
58
|
+
/**
|
|
59
|
+
* Handle identifier type - a hex string representing a 32-byte handle.
|
|
60
|
+
*/
|
|
61
|
+
export type HandleLike = Bytes32Hex;
|
|
62
|
+
/**
|
|
63
|
+
* Unverified encryption data returned from the server.
|
|
64
|
+
*/
|
|
65
|
+
export interface UnverifiedEncryptData {
|
|
66
|
+
handle: HandleLike;
|
|
67
|
+
data: BytesHex;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Decrypted plaintext result containing both type and value.
|
|
71
|
+
*/
|
|
72
|
+
export interface Plaintext {
|
|
73
|
+
type: FheType;
|
|
74
|
+
value: bigint | boolean;
|
|
75
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { logger } from "./logger.js";
|
|
2
|
+
import { FheErrorCode } from "./errors/error-codes.js";
|
|
3
|
+
import { FheError } from "./errors/fhe-error.js";
|
|
4
|
+
/**
|
|
5
|
+
* FHE operation types.
|
|
6
|
+
*/
|
|
7
|
+
export var Operator;
|
|
8
|
+
(function (Operator) {
|
|
9
|
+
Operator[Operator["fheNone"] = 0] = "fheNone";
|
|
10
|
+
Operator[Operator["fheAdd"] = 1] = "fheAdd";
|
|
11
|
+
Operator[Operator["fheSub"] = 2] = "fheSub";
|
|
12
|
+
Operator[Operator["fheMul"] = 3] = "fheMul";
|
|
13
|
+
Operator[Operator["fheDiv"] = 4] = "fheDiv";
|
|
14
|
+
Operator[Operator["fheBitAnd"] = 5] = "fheBitAnd";
|
|
15
|
+
Operator[Operator["fheBitOr"] = 6] = "fheBitOr";
|
|
16
|
+
Operator[Operator["fheBitXor"] = 7] = "fheBitXor";
|
|
17
|
+
Operator[Operator["fheBitNot"] = 8] = "fheBitNot";
|
|
18
|
+
Operator[Operator["fheEq"] = 9] = "fheEq";
|
|
19
|
+
Operator[Operator["fheNe"] = 10] = "fheNe";
|
|
20
|
+
Operator[Operator["fheGe"] = 11] = "fheGe";
|
|
21
|
+
Operator[Operator["fheGt"] = 12] = "fheGt";
|
|
22
|
+
Operator[Operator["fheLe"] = 13] = "fheLe";
|
|
23
|
+
Operator[Operator["fheLt"] = 14] = "fheLt";
|
|
24
|
+
Operator[Operator["fheIfThenElse"] = 15] = "fheIfThenElse";
|
|
25
|
+
Operator[Operator["trivialEncrypt"] = 16] = "trivialEncrypt";
|
|
26
|
+
Operator[Operator["verifyAttestation"] = 17] = "verifyAttestation";
|
|
27
|
+
})(Operator || (Operator = {}));
|
|
28
|
+
/**
|
|
29
|
+
* FHE (Fully Homomorphic Encryption) data types.
|
|
30
|
+
* Represents different integer sizes for encrypted values.
|
|
31
|
+
*/
|
|
32
|
+
export var FheType;
|
|
33
|
+
(function (FheType) {
|
|
34
|
+
FheType[FheType["ve_bool"] = 0] = "ve_bool";
|
|
35
|
+
FheType[FheType["ve_uint8"] = 1] = "ve_uint8";
|
|
36
|
+
FheType[FheType["ve_uint16"] = 2] = "ve_uint16";
|
|
37
|
+
FheType[FheType["ve_uint32"] = 3] = "ve_uint32";
|
|
38
|
+
FheType[FheType["ve_uint64"] = 4] = "ve_uint64";
|
|
39
|
+
FheType[FheType["ve_uint128"] = 5] = "ve_uint128";
|
|
40
|
+
FheType[FheType["ve_uint256"] = 6] = "ve_uint256";
|
|
41
|
+
})(FheType || (FheType = {}));
|
|
42
|
+
// Mapping from FheType enum to corresponding Solidity type strings
|
|
43
|
+
const FHE_TYPE_TO_SOLIDITY_TYPE = {
|
|
44
|
+
[FheType.ve_bool]: "bool",
|
|
45
|
+
[FheType.ve_uint8]: "uint8",
|
|
46
|
+
[FheType.ve_uint16]: "uint16",
|
|
47
|
+
[FheType.ve_uint32]: "uint32",
|
|
48
|
+
[FheType.ve_uint64]: "uint64",
|
|
49
|
+
[FheType.ve_uint128]: "uint128",
|
|
50
|
+
[FheType.ve_uint256]: "uint256",
|
|
51
|
+
};
|
|
52
|
+
// Mapping from Solidity type strings to FheType enum values
|
|
53
|
+
const SOLIDITY_TYPE_TO_FHE_TYPE = {
|
|
54
|
+
bool: FheType.ve_bool,
|
|
55
|
+
uint8: FheType.ve_uint8,
|
|
56
|
+
uint16: FheType.ve_uint16,
|
|
57
|
+
uint32: FheType.ve_uint32,
|
|
58
|
+
uint64: FheType.ve_uint64,
|
|
59
|
+
uint128: FheType.ve_uint128,
|
|
60
|
+
uint256: FheType.ve_uint256,
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Converts an FheType enum value to its Solidity type string representation.
|
|
64
|
+
* @param fheType - The FheType enum value
|
|
65
|
+
* @returns The corresponding Solidity type string
|
|
66
|
+
* @throws Error if the FheType is unsupported
|
|
67
|
+
*/
|
|
68
|
+
export function getFheTypeString(fheType) {
|
|
69
|
+
const type = FHE_TYPE_TO_SOLIDITY_TYPE[fheType];
|
|
70
|
+
if (!type) {
|
|
71
|
+
throw new FheError({ code: FheErrorCode.Unsupported, message: `Unsupported FheType: ${fheType}` });
|
|
72
|
+
}
|
|
73
|
+
return type;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Converts a Solidity type string to its FheType enum value.
|
|
77
|
+
* @param type - The Solidity type string (e.g., "uint256")
|
|
78
|
+
* @returns The corresponding FheType enum value
|
|
79
|
+
* @throws Error if the Solidity type is unsupported
|
|
80
|
+
*/
|
|
81
|
+
export function getFheTypeFromString(type) {
|
|
82
|
+
const fheType = SOLIDITY_TYPE_TO_FHE_TYPE[type];
|
|
83
|
+
if (fheType === undefined) {
|
|
84
|
+
throw new FheError({ code: FheErrorCode.Unsupported, message: `Unsupported Solidity type: ${type}` });
|
|
85
|
+
}
|
|
86
|
+
return fheType;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the byte length for a given FHE type.
|
|
90
|
+
* @param fheType - The FheType enum value
|
|
91
|
+
* @returns The byte length of the type
|
|
92
|
+
*/
|
|
93
|
+
export function getTypeLength(fheType) {
|
|
94
|
+
switch (fheType) {
|
|
95
|
+
case FheType.ve_bool:
|
|
96
|
+
return 1;
|
|
97
|
+
case FheType.ve_uint8:
|
|
98
|
+
return 1;
|
|
99
|
+
case FheType.ve_uint16:
|
|
100
|
+
return 2;
|
|
101
|
+
case FheType.ve_uint32:
|
|
102
|
+
return 4;
|
|
103
|
+
case FheType.ve_uint64:
|
|
104
|
+
return 8;
|
|
105
|
+
case FheType.ve_uint128:
|
|
106
|
+
return 16;
|
|
107
|
+
case FheType.ve_uint256:
|
|
108
|
+
return 32;
|
|
109
|
+
default: {
|
|
110
|
+
logger.warn(`Unknown FheType: ${fheType}, defaulting to 1 byte`);
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=fhe-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fhe-type.js","sourceRoot":"","s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AK,OAAO,CAAC,SAAS;YACpB,OAAO,CAAC,CAAC;QACX,KAAK,OAAO,CAAC,SAAS;YACpB,OAAO,CAAC,CAAC;QACX,KAAK,OAAO,CAAC,UAAU;YACrB,OAAO,EAAE,CAAC;QACZ,KAAK,OAAO,CAAC,UAAU;YACrB,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,CAAC,IAAI,CAAC,oBAAoB,OAAO,wBAAwB,CAAC,CAAC;YACjE,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts an integer with ZK proof support.
|
|
3
|
+
*
|
|
4
|
+
* @param input - Input data to encrypt as Uint8Array
|
|
5
|
+
* @param pk - Public key as Uint8Array
|
|
6
|
+
* @param crs - CRS bytes for ZK proof
|
|
7
|
+
* @param metadata - Metadata for ZK proof
|
|
8
|
+
* @returns Promise resolving to ciphertext as Uint8Array
|
|
9
|
+
* @throws Error if input is invalid or encryption fails
|
|
10
|
+
*/
|
|
11
|
+
export declare function encryptIntegerWithZkProof(input: Uint8Array, pk: Uint8Array, crs: Uint8Array, metadata: Uint8Array): Promise<Uint8Array>;
|
package/dist/core/fhe.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createFheWasmClient } from '#worker-client';
|
|
2
|
+
const client = createFheWasmClient();
|
|
3
|
+
/**
|
|
4
|
+
* Encrypts an integer with ZK proof support.
|
|
5
|
+
*
|
|
6
|
+
* @param input - Input data to encrypt as Uint8Array
|
|
7
|
+
* @param pk - Public key as Uint8Array
|
|
8
|
+
* @param crs - CRS bytes for ZK proof
|
|
9
|
+
* @param metadata - Metadata for ZK proof
|
|
10
|
+
* @returns Promise resolving to ciphertext as Uint8Array
|
|
11
|
+
* @throws Error if input is invalid or encryption fails
|
|
12
|
+
*/
|
|
13
|
+
export async function encryptIntegerWithZkProof(input, pk, crs, metadata) {
|
|
14
|
+
// return encryptInternal(input, PK_TYPE.ZK, pk, crs, metadata);
|
|
15
|
+
const ciphertext = await client.encryptIntegerWithZkProof(
|
|
16
|
+
// {input, pk, crs, metadata, refresh:false}
|
|
17
|
+
{
|
|
18
|
+
input: new Uint8Array(input), pk: new Uint8Array(pk), crs: new Uint8Array(crs),
|
|
19
|
+
metadata: new Uint8Array(metadata), refresh: false,
|
|
20
|
+
});
|
|
21
|
+
return ciphertext;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=fhe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fhe.js","sourceRoot":"","sources":["../../src/core/fhe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,KAAiB,EACjB,EAAc,EACd,GAAe,EACf,QAAoB;IAEpB,gEAAgE;IAChE,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,yBAAyB;IACvD,4CAA4C;IAC5C;QACE,KAAK,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC;QAC9E,QAAQ,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK;KACnD,CACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { FheType, HandleLike } from "./fhe-type.js";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the current handle version used by local handle generation.
|
|
4
|
+
* The version is compiled into the build rather than fetched from the chain.
|
|
5
|
+
*
|
|
6
|
+
* @returns The handle version number
|
|
7
|
+
*/
|
|
8
|
+
export declare function getHandleVersion(): number;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a 32-byte handle identifier for off-chain ciphertext.
|
|
11
|
+
* The layout depends on the active handle version.
|
|
12
|
+
*
|
|
13
|
+
* Handle structure:
|
|
14
|
+
* - Version 0: [20..27] Chain ID, [28] Input type, [29] Operator, [30] FHE type, [31] Version
|
|
15
|
+
* - Version 1: [28] Chain key, [29] Operator, [30] FHE type, [31] Version
|
|
16
|
+
*
|
|
17
|
+
* @param chainId - Blockchain chain ID
|
|
18
|
+
* @param fheType - FHE data type
|
|
19
|
+
* @param handleVersion - Handle version (defaults to the compiled-in version)
|
|
20
|
+
* @returns Hex string representation of the 32-byte handle (0x-prefixed)
|
|
21
|
+
* @throws Error if the handle version is unsupported
|
|
22
|
+
*/
|
|
23
|
+
export declare function makeHandle(chainId: number, fheType: FheType, handleVersion?: number): `0x${string}`;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the FHE type from a handle.
|
|
26
|
+
* @param handle - The handle identifier (32-byte hex string)
|
|
27
|
+
* @returns The FheType enum value
|
|
28
|
+
*/
|
|
29
|
+
export declare function getHandleFheType(handle: HandleLike): FheType;
|
|
30
|
+
/**
|
|
31
|
+
* Extracts and returns the ABI type string from a handle.
|
|
32
|
+
* @param handle - The handle identifier (32-byte hex string)
|
|
33
|
+
* @returns The Solidity type string (e.g., "uint256")
|
|
34
|
+
*/
|
|
35
|
+
export declare function getHandleAbiType(handle: HandleLike): string;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts the blockchain chain ID from a handle by reading the chain key at byte 28.
|
|
38
|
+
* @param handle - The handle identifier (32-byte hex string)
|
|
39
|
+
* @returns The blockchain chain ID
|
|
40
|
+
* @throws Error if the chain key is not found in the CHAINS mapping
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractChainIdFromHandle(handle: HandleLike): bigint;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { bytesToHex, fromHexString } from "./bytes.js";
|
|
2
|
+
import { chainKeyToChainIdMap, getChainKey } from "./chain.js";
|
|
3
|
+
import { getFheTypeString, Operator } from "./fhe-type.js";
|
|
4
|
+
import { logger } from "./logger.js";
|
|
5
|
+
import { FheErrorCode } from "./errors/error-codes.js";
|
|
6
|
+
import { FheError } from "./errors/fhe-error.js";
|
|
7
|
+
/**
|
|
8
|
+
* Gets the current handle version used by local handle generation.
|
|
9
|
+
* The version is compiled into the build rather than fetched from the chain.
|
|
10
|
+
*
|
|
11
|
+
* @returns The handle version number
|
|
12
|
+
*/
|
|
13
|
+
export function getHandleVersion() {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a 32-byte handle identifier for off-chain ciphertext.
|
|
18
|
+
* The layout depends on the active handle version.
|
|
19
|
+
*
|
|
20
|
+
* Handle structure:
|
|
21
|
+
* - Version 0: [20..27] Chain ID, [28] Input type, [29] Operator, [30] FHE type, [31] Version
|
|
22
|
+
* - Version 1: [28] Chain key, [29] Operator, [30] FHE type, [31] Version
|
|
23
|
+
*
|
|
24
|
+
* @param chainId - Blockchain chain ID
|
|
25
|
+
* @param fheType - FHE data type
|
|
26
|
+
* @param handleVersion - Handle version (defaults to the compiled-in version)
|
|
27
|
+
* @returns Hex string representation of the 32-byte handle (0x-prefixed)
|
|
28
|
+
* @throws Error if the handle version is unsupported
|
|
29
|
+
*/
|
|
30
|
+
export function makeHandle(chainId, fheType, handleVersion = getHandleVersion()) {
|
|
31
|
+
const handleBytes = new Uint8Array(32);
|
|
32
|
+
crypto.getRandomValues(handleBytes);
|
|
33
|
+
handleBytes.fill(0, 20, 32);
|
|
34
|
+
logger.debug(`Creating handle: chainId=${chainId}, fheType=${fheType}, version=${handleVersion}`);
|
|
35
|
+
if (handleVersion === 0) {
|
|
36
|
+
// Version 0 handle format
|
|
37
|
+
const chainIdBytes = fromHexString(chainId.toString(16).padStart(16, "0"));
|
|
38
|
+
handleBytes.set(chainIdBytes, 20); // Chain ID bytes
|
|
39
|
+
handleBytes[28] = 0x00; // Input type: off-chain
|
|
40
|
+
handleBytes[29] = Operator.fheNone;
|
|
41
|
+
handleBytes[30] = fheType; // FHE type
|
|
42
|
+
handleBytes[31] = handleVersion; // Handle version
|
|
43
|
+
}
|
|
44
|
+
else if (handleVersion === 1) {
|
|
45
|
+
// Version 1 handle format
|
|
46
|
+
// Bytes 20-27 are zeroed for off-chain handles; byte 28 stores the chain key
|
|
47
|
+
const chainKey = getChainKey(BigInt(chainId));
|
|
48
|
+
handleBytes[28] = chainKey;
|
|
49
|
+
handleBytes[29] = Operator.fheNone;
|
|
50
|
+
handleBytes[30] = fheType; // FHE type
|
|
51
|
+
// Lower nibble stores the handle version: 000b|00001b (off-chain | handleVersion)
|
|
52
|
+
handleBytes[31] = handleVersion;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
logger.error(`Unsupported handle version: ${handleVersion}`);
|
|
56
|
+
throw new FheError({ code: FheErrorCode.Unsupported, message: `Unsupported handle version: ${handleVersion}` });
|
|
57
|
+
}
|
|
58
|
+
const result = bytesToHex(handleBytes);
|
|
59
|
+
logger.trace(`Handle created: ${result.substring(0, 20)}...`);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Extracts the FHE type from a handle.
|
|
64
|
+
* @param handle - The handle identifier (32-byte hex string)
|
|
65
|
+
* @returns The FheType enum value
|
|
66
|
+
*/
|
|
67
|
+
export function getHandleFheType(handle) {
|
|
68
|
+
const handleBytes = fromHexString(handle);
|
|
69
|
+
return handleBytes[30];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Extracts and returns the ABI type string from a handle.
|
|
73
|
+
* @param handle - The handle identifier (32-byte hex string)
|
|
74
|
+
* @returns The Solidity type string (e.g., "uint256")
|
|
75
|
+
*/
|
|
76
|
+
export function getHandleAbiType(handle) {
|
|
77
|
+
const handleBytes = fromHexString(handle);
|
|
78
|
+
const fheType = handleBytes[30];
|
|
79
|
+
return getFheTypeString(fheType);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Extracts the blockchain chain ID from a handle by reading the chain key at byte 28.
|
|
83
|
+
* @param handle - The handle identifier (32-byte hex string)
|
|
84
|
+
* @returns The blockchain chain ID
|
|
85
|
+
* @throws Error if the chain key is not found in the CHAINS mapping
|
|
86
|
+
*/
|
|
87
|
+
export function extractChainIdFromHandle(handle) {
|
|
88
|
+
const handleBytes = fromHexString(handle);
|
|
89
|
+
const chainKey = handleBytes[28]; // Chain key is stored at byte offset 28
|
|
90
|
+
const chainId = chainKeyToChainIdMap.get(chainKey);
|
|
91
|
+
if (chainId === undefined) {
|
|
92
|
+
throw new FheError({
|
|
93
|
+
code: FheErrorCode.UnsupportedChain,
|
|
94
|
+
message: `Unsupported chain key: ${chainKey} (not found in CHAINS mapping)`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return chainId;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=handle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/core/handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAW,gBAAgB,EAAc,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CACxB,OAAe,EACf,OAAgB,EAChB,gBAAwB,gBAAgB,EAAE;IAE1C,MAAM,WAAW,GAAG,I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
|
2
|
+
* Utility class for serializing and deserializing JSON data that contains BigInt values.
|
|
3
|
+
* BigInts are encoded as objects with a type marker to preserve precision during serialization.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JSONWithBigInt {
|
|
6
|
+
/**
|
|
7
|
+
* Serializes a value to a JSON string, converting BigInts to a serializable format.
|
|
8
|
+
* @param value - The value to serialize (may contain BigInts)
|
|
9
|
+
* @returns A JSON string with BigInts encoded as `{ __type: 'bigint', value: '123' }`
|
|
10
|
+
*/
|
|
11
|
+
static stringify(value: any): string;
|
|
12
|
+
/**
|
|
13
|
+
* Parses a JSON string, restoring encoded BigInts to their original type.
|
|
14
|
+
* @param text - The JSON string to parse
|
|
15
|
+
* @returns The parsed value with BigInts restored
|
|
16
|
+
*/
|
|
17
|
+
static parse(text: string): any;
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for serializing and deserializing JSON data that contains BigInt values.
|
|
3
|
+
* BigInts are encoded as objects with a type marker to preserve precision during serialization.
|
|
4
|
+
*/
|
|
5
|
+
export class JSONWithBigInt {
|
|
6
|
+
/**
|
|
7
|
+
* Serializes a value to a JSON string, converting BigInts to a serializable format.
|
|
8
|
+
* @param value - The value to serialize (may contain BigInts)
|
|
9
|
+
* @returns A JSON string with BigInts encoded as `{ __type: 'bigint', value: '123' }`
|
|
10
|
+
*/
|
|
11
|
+
static stringify(value) {
|
|
12
|
+
return JSON.stringify(value, (_key, val) => {
|
|
13
|
+
if (typeof val === "bigint") {
|
|
14
|
+
return {
|
|
15
|
+
__type: "bigint",
|
|
16
|
+
value: val.toString(),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return val;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parses a JSON string, restoring encoded BigInts to their original type.
|
|
24
|
+
* @param text - The JSON string to parse
|
|
25
|
+
* @returns The parsed value with BigInts restored
|
|
26
|
+
*/
|
|
27
|
+
static parse(text) {
|
|
28
|
+
return JSON.parse(text, (_key, value) => {
|
|
29
|
+
// Check for the BigInt type marker and restore as BigInt
|
|
30
|
+
if (value && typeof value === "object" && value.__type === "bigint") {
|
|
31
|
+
return BigInt(value.value);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=json-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-utils.js","sourceRoot":"","sources":["../../src/core/json-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,KAAU;QACzB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YACzC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC5B,OAAO;oBACL,MAAM,EAAE,QAAQ;oBAChB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;iBACtB,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,IAAY;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YACtC,yDAAyD;YACzD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACpE,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export { kms_init } from "#wasm-loader";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a new encryption key pair.
|
|
4
|
+
* @returns The generated key pair as a WASM-compatible object.
|
|
5
|
+
*/
|
|
6
|
+
export declare const kms_enc_keygen: (...args: any[]) => any;
|
|
7
|
+
/**
|
|
8
|
+
* Encrypts data using the KMS encryption scheme.
|
|
9
|
+
* @param ...args - Arguments required for encryption (key, plaintext, etc.).
|
|
10
|
+
* @returns The encrypted data.
|
|
11
|
+
*/
|
|
12
|
+
export declare const kms_encrypt: (...args: any[]) => any;
|
|
13
|
+
/**
|
|
14
|
+
* Decrypts data using the KMS encryption scheme.
|
|
15
|
+
* @param ...args - Arguments required for decryption (key, ciphertext, etc.).
|
|
16
|
+
* @returns The decrypted plaintext.
|
|
17
|
+
*/
|
|
18
|
+
export declare const kms_decrypt: (...args: any[]) => any;
|
|
19
|
+
/**
|
|
20
|
+
* Performs signcryption (signature + encryption) on data.
|
|
21
|
+
* @param ...args - Arguments required for signcryption.
|
|
22
|
+
* @returns The signcrypted data.
|
|
23
|
+
*/
|
|
24
|
+
export declare const kms_signcrypt_ex: (...args: any[]) => any;
|
|
25
|
+
/**
|
|
26
|
+
* Performs unsigncryption (decryption + signature verification) on data.
|
|
27
|
+
* @param ...args - Arguments required for unsigncryption.
|
|
28
|
+
* @returns The decrypted and verified data.
|
|
29
|
+
*/
|
|
30
|
+
export declare const kms_unsigncrypt: (...args: any[]) => any;
|
|
31
|
+
/**
|
|
32
|
+
* Splits a secret into multiple shares using a secret sharing scheme.
|
|
33
|
+
* @param ...args - Arguments required for splitting.
|
|
34
|
+
* @returns Array of secret shares.
|
|
35
|
+
*/
|
|
36
|
+
export declare const kms_split_secret: (...args: any[]) => any;
|
|
37
|
+
/**
|
|
38
|
+
* Combines multiple secret shares to reconstruct the original secret.
|
|
39
|
+
* @param ...args - Arguments required for combining.
|
|
40
|
+
* @returns The reconstructed secret.
|
|
41
|
+
*/
|
|
42
|
+
export declare const kms_combine_secret: (...args: any[]) => any;
|
package/dist/core/kms.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { kms_module } from "#wasm-loader";
|
|
2
|
+
export { kms_init } from "#wasm-loader";
|
|
3
|
+
import { FheErrorCode } from "./errors/error-codes.js";
|
|
4
|
+
import { FheError } from "./errors/fhe-error.js";
|
|
5
|
+
/**
|
|
6
|
+
* KMS (Key Management Service) WebAssembly module.
|
|
7
|
+
* Provides cryptographic operations including encryption, decryption,
|
|
8
|
+
* signcryption, and secret splitting.
|
|
9
|
+
*
|
|
10
|
+
* The module automatically loads the appropriate WASM bundle based on the
|
|
11
|
+
* runtime environment (browser vs Node.js).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Creates an API function that wraps a WASM module method.
|
|
15
|
+
* Ensures the module is initialized before calling the method.
|
|
16
|
+
*
|
|
17
|
+
* @param name - The name of the WASM function to call.
|
|
18
|
+
* @returns A function that calls the WASM method with the provided arguments.
|
|
19
|
+
*/
|
|
20
|
+
const api = (name) => (...args) => {
|
|
21
|
+
if (!kms_module()) {
|
|
22
|
+
throw new FheError({ code: FheErrorCode.KmsNotInitialized, message: "KMS WASM module not initialized. Please call kms_init() first." });
|
|
23
|
+
}
|
|
24
|
+
return kms_module()[name](...args);
|
|
25
|
+
};
|
|
26
|
+
// ============================================
|
|
27
|
+
// Cryptographic Operations
|
|
28
|
+
// ============================================
|
|
29
|
+
/**
|
|
30
|
+
* Generates a new encryption key pair.
|
|
31
|
+
* @returns The generated key pair as a WASM-compatible object.
|
|
32
|
+
*/
|
|
33
|
+
export const kms_enc_keygen = api("wasm_enc_keygen");
|
|
34
|
+
/**
|
|
35
|
+
* Encrypts data using the KMS encryption scheme.
|
|
36
|
+
* @param ...args - Arguments required for encryption (key, plaintext, etc.).
|
|
37
|
+
* @returns The encrypted data.
|
|
38
|
+
*/
|
|
39
|
+
export const kms_encrypt = api("wasm_encrypt");
|
|
40
|
+
/**
|
|
41
|
+
* Decrypts data using the KMS encryption scheme.
|
|
42
|
+
* @param ...args - Arguments required for decryption (key, ciphertext, etc.).
|
|
43
|
+
* @returns The decrypted plaintext.
|
|
44
|
+
*/
|
|
45
|
+
export const kms_decrypt = api("wasm_decrypt");
|
|
46
|
+
/**
|
|
47
|
+
* Performs signcryption (signature + encryption) on data.
|
|
48
|
+
* @param ...args - Arguments required for signcryption.
|
|
49
|
+
* @returns The signcrypted data.
|
|
50
|
+
*/
|
|
51
|
+
export const kms_signcrypt_ex = api("wasm_signcrypt_ex");
|
|
52
|
+
/**
|
|
53
|
+
* Performs unsigncryption (decryption + signature verification) on data.
|
|
54
|
+
* @param ...args - Arguments required for unsigncryption.
|
|
55
|
+
* @returns The decrypted and verified data.
|
|
56
|
+
*/
|
|
57
|
+
export const kms_unsigncrypt = api("wasm_unsigncrypt");
|
|
58
|
+
/**
|
|
59
|
+
* Splits a secret into multiple shares using a secret sharing scheme.
|
|
60
|
+
* @param ...args - Arguments required for splitting.
|
|
61
|
+
* @returns Array of secret shares.
|
|
62
|
+
*/
|
|
63
|
+
export const kms_split_secret = api("wasm_split_secret");
|
|
64
|
+
/**
|
|
65
|
+
* Combines multiple secret shares to reconstruct the original secret.
|
|
66
|
+
* @param ...args - Arguments required for combining.
|
|
67
|
+
* @returns The reconstructed secret.
|
|
68
|
+
*/
|
|
69
|
+
export const kms_combine_secret = api("wasm_combine_secret");
|
|
70
|
+
//# sourceMappingURL=kms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kms.js","sourceRoot":"","sources":["../../src/core/kms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;IAC/C,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;QAClB,MAAM,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,iBAAiB,EAAE,OAAO,EAAE,gEAAgE,EAAE,CAAC,CAAC;IAC1I,CAAC;IACD,OAAO,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,+CAA+C;AAC/C,2BAA2B;AAC3B,+CAA+C;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from "tslog";
|
|
2
|
+
export const logger = new Logger({
|
|
3
|
+
type: "pretty",
|
|
4
|
+
pretty: {},
|
|
5
|
+
minLevel: 'INFO',
|
|
6
|
+
stack: { capture: "off" }
|
|
7
|
+
});
|
|
8
|
+
export function setLogLevel(level) {
|
|
9
|
+
logger.setMinLevel(level);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,OAAO,CAAC;AAE9C,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;IAC/B,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,EACP;IACD,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;CAC1B,CAAC,CAAC;AAEH,MAAM,UAAU,WAAW,CAAC,KAAoB;IAC9C,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively formats values for human-readable display.
|
|
3
|
+
* - Truncates long strings (>132 chars) to show head and tail with length.
|
|
4
|
+
* - Converts BigInts to strings.
|
|
5
|
+
* - Recursively processes objects.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to format
|
|
8
|
+
* @returns The formatted value
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatValue(value: any): any;
|
|
11
|
+
/**
|
|
12
|
+
* Pretty-prints data to the console with hex string truncation.
|
|
13
|
+
* - In browser environments: uses console.log with JSON formatting
|
|
14
|
+
* - In Node.js environments: uses console.dir with detailed options
|
|
15
|
+
*
|
|
16
|
+
* @param data - The data to pretty-print
|
|
17
|
+
*/
|
|
18
|
+
export declare function prettyPrint(data: any): void;
|