@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,118 @@
|
|
|
1
|
+
import { FheError } from './errors/fhe-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Branded type for EIP-55 checksummed Ethereum addresses.
|
|
4
|
+
* Use `toChecksumAddress()` to create, never cast directly.
|
|
5
|
+
*/
|
|
6
|
+
export type ChecksumAddress = string & {
|
|
7
|
+
readonly __brand: unique symbol;
|
|
8
|
+
};
|
|
9
|
+
export declare const ADDRESS_ZERO: ChecksumAddress;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a string is a valid EIP-55 checksum address.
|
|
12
|
+
*
|
|
13
|
+
* @param address - The address to validate
|
|
14
|
+
* @returns `true` if the address is valid and checksummed
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* isChecksumAddress('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') // true
|
|
18
|
+
* isChecksumAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') // false
|
|
19
|
+
*/
|
|
20
|
+
export declare function isChecksumAddress(address: string): address is ChecksumAddress;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a string is a valid Ethereum address (with or without checksum).
|
|
23
|
+
*
|
|
24
|
+
* @param address - The address to validate
|
|
25
|
+
* @returns `true` if the address is valid
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* isValidAddress('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') // true
|
|
29
|
+
* isValidAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') // true
|
|
30
|
+
* isValidAddress('0xinvalid') // false
|
|
31
|
+
*/
|
|
32
|
+
export declare function isValidAddress(address: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Assert that a string is a valid checksum address.
|
|
35
|
+
* Throws an error with a descriptive message if validation fails.
|
|
36
|
+
*
|
|
37
|
+
* @param address - The address to validate
|
|
38
|
+
* @param context - Optional context for error message (e.g., 'contractAddress')
|
|
39
|
+
* @throws {ChecksumAddressError} If the address is invalid
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* assertChecksumAddress('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
43
|
+
* assertChecksumAddress(address, 'userAddress');
|
|
44
|
+
*/
|
|
45
|
+
export declare function assertChecksumAddress(address: string, context?: string): asserts address is ChecksumAddress;
|
|
46
|
+
/**
|
|
47
|
+
* Convert an Ethereum address to EIP-55 checksum format.
|
|
48
|
+
*
|
|
49
|
+
* @param address - The address to convert (with or without 0x prefix)
|
|
50
|
+
* @returns The checksummed address as `ChecksumAddress`
|
|
51
|
+
* @throws {ChecksumAddressError} If the address is invalid
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* toChecksumAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
|
|
55
|
+
* // => '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
|
|
56
|
+
*/
|
|
57
|
+
export declare function toChecksumAddress(address: string): ChecksumAddress;
|
|
58
|
+
/**
|
|
59
|
+
* Convert multiple addresses to checksum format.
|
|
60
|
+
*
|
|
61
|
+
* @param addresses - Array of addresses to convert
|
|
62
|
+
* @returns Array of checksummed addresses
|
|
63
|
+
* @throws {ChecksumAddressError} If any address is invalid
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* toChecksumAddresses(['0xf39fd6e...', '0x70997970...'])
|
|
67
|
+
*/
|
|
68
|
+
export declare function toChecksumAddresses(addresses: string[]): ChecksumAddress[];
|
|
69
|
+
/**
|
|
70
|
+
* Safely convert addresses to checksum format.
|
|
71
|
+
* Invalid addresses return `null` instead of throwing.
|
|
72
|
+
*
|
|
73
|
+
* @param addresses - Array of addresses to convert
|
|
74
|
+
* @returns Array of checksummed addresses or `null` for invalid ones
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* toChecksumAddressesSafe(['0xf39fd6e...', '0xinvalid', '0x70997970...'])
|
|
78
|
+
* // => ['0xf39Fd6e...', null, '0x70997970...']
|
|
79
|
+
*/
|
|
80
|
+
export declare function toChecksumAddressesSafe(addresses: string[]): (ChecksumAddress | null)[];
|
|
81
|
+
/**
|
|
82
|
+
* Convert addresses to checksum format and filter out invalid ones.
|
|
83
|
+
*
|
|
84
|
+
* @param addresses - Array of addresses to convert
|
|
85
|
+
* @returns Array of valid checksummed addresses only
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* toChecksumAddressesFiltered(['0xf39fd6e...', '0xinvalid', '0x70997970...'])
|
|
89
|
+
* // => ['0xf39Fd6e...', '0x70997970...']
|
|
90
|
+
*/
|
|
91
|
+
export declare function toChecksumAddressesFiltered(addresses: string[]): ChecksumAddress[];
|
|
92
|
+
/**
|
|
93
|
+
* Compare two addresses for equality (case-insensitive).
|
|
94
|
+
*
|
|
95
|
+
* @param address1 - First address
|
|
96
|
+
* @param address2 - Second address
|
|
97
|
+
* @returns `true` if both addresses are valid and equal
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* areEqualAddresses(
|
|
101
|
+
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
102
|
+
* '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
|
|
103
|
+
* ) // true
|
|
104
|
+
*/
|
|
105
|
+
export declare function areEqualAddresses(address1: string, address2: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Check if an address is the zero address.
|
|
108
|
+
*
|
|
109
|
+
* @param address - The address to check
|
|
110
|
+
* @returns `true` if the address is the zero address
|
|
111
|
+
*/
|
|
112
|
+
export declare function isZeroAddress(address: string): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Custom error for checksum address validation failures.
|
|
115
|
+
*/
|
|
116
|
+
export declare class ChecksumAddressError extends FheError {
|
|
117
|
+
constructor(message: string, options?: ErrorOptions);
|
|
118
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { getAddress, isAddress } from 'ethers';
|
|
2
|
+
import { FheErrorCode } from './errors/error-codes.js';
|
|
3
|
+
import { FheError } from './errors/fhe-error.js';
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Constants
|
|
6
|
+
// ============================================================================
|
|
7
|
+
export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Validation
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Check if a string is a valid EIP-55 checksum address.
|
|
13
|
+
*
|
|
14
|
+
* @param address - The address to validate
|
|
15
|
+
* @returns `true` if the address is valid and checksummed
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* isChecksumAddress('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') // true
|
|
19
|
+
* isChecksumAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') // false
|
|
20
|
+
*/
|
|
21
|
+
export function isChecksumAddress(address) {
|
|
22
|
+
if (!address || typeof address !== 'string') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
return getAddress(address) === address;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a string is a valid Ethereum address (with or without checksum).
|
|
34
|
+
*
|
|
35
|
+
* @param address - The address to validate
|
|
36
|
+
* @returns `true` if the address is valid
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* isValidAddress('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266') // true
|
|
40
|
+
* isValidAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266') // true
|
|
41
|
+
* isValidAddress('0xinvalid') // false
|
|
42
|
+
*/
|
|
43
|
+
export function isValidAddress(address) {
|
|
44
|
+
if (!address || typeof address !== 'string') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return isAddress(address);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Assertions
|
|
56
|
+
// ============================================================================
|
|
57
|
+
/**
|
|
58
|
+
* Assert that a string is a valid checksum address.
|
|
59
|
+
* Throws an error with a descriptive message if validation fails.
|
|
60
|
+
*
|
|
61
|
+
* @param address - The address to validate
|
|
62
|
+
* @param context - Optional context for error message (e.g., 'contractAddress')
|
|
63
|
+
* @throws {ChecksumAddressError} If the address is invalid
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* assertChecksumAddress('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
67
|
+
* assertChecksumAddress(address, 'userAddress');
|
|
68
|
+
*/
|
|
69
|
+
export function assertChecksumAddress(address, context) {
|
|
70
|
+
if (!isChecksumAddress(address)) {
|
|
71
|
+
const prefix = context ? `[${context}] ` : '';
|
|
72
|
+
throw new ChecksumAddressError(`${prefix}Invalid checksum address: ${address}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Conversion
|
|
77
|
+
// ============================================================================
|
|
78
|
+
/**
|
|
79
|
+
* Convert an Ethereum address to EIP-55 checksum format.
|
|
80
|
+
*
|
|
81
|
+
* @param address - The address to convert (with or without 0x prefix)
|
|
82
|
+
* @returns The checksummed address as `ChecksumAddress`
|
|
83
|
+
* @throws {ChecksumAddressError} If the address is invalid
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* toChecksumAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
|
|
87
|
+
* // => '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
|
|
88
|
+
*/
|
|
89
|
+
export function toChecksumAddress(address) {
|
|
90
|
+
if (!address || typeof address !== 'string') {
|
|
91
|
+
throw new ChecksumAddressError('Address is required');
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return getAddress(address);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new ChecksumAddressError(`Invalid address: ${address}`, { cause: error });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Convert multiple addresses to checksum format.
|
|
102
|
+
*
|
|
103
|
+
* @param addresses - Array of addresses to convert
|
|
104
|
+
* @returns Array of checksummed addresses
|
|
105
|
+
* @throws {ChecksumAddressError} If any address is invalid
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* toChecksumAddresses(['0xf39fd6e...', '0x70997970...'])
|
|
109
|
+
*/
|
|
110
|
+
export function toChecksumAddresses(addresses) {
|
|
111
|
+
return addresses.map((addr) => toChecksumAddress(addr));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Safely convert addresses to checksum format.
|
|
115
|
+
* Invalid addresses return `null` instead of throwing.
|
|
116
|
+
*
|
|
117
|
+
* @param addresses - Array of addresses to convert
|
|
118
|
+
* @returns Array of checksummed addresses or `null` for invalid ones
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* toChecksumAddressesSafe(['0xf39fd6e...', '0xinvalid', '0x70997970...'])
|
|
122
|
+
* // => ['0xf39Fd6e...', null, '0x70997970...']
|
|
123
|
+
*/
|
|
124
|
+
export function toChecksumAddressesSafe(addresses) {
|
|
125
|
+
return addresses.map((addr) => {
|
|
126
|
+
try {
|
|
127
|
+
return toChecksumAddress(addr);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Convert addresses to checksum format and filter out invalid ones.
|
|
136
|
+
*
|
|
137
|
+
* @param addresses - Array of addresses to convert
|
|
138
|
+
* @returns Array of valid checksummed addresses only
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* toChecksumAddressesFiltered(['0xf39fd6e...', '0xinvalid', '0x70997970...'])
|
|
142
|
+
* // => ['0xf39Fd6e...', '0x70997970...']
|
|
143
|
+
*/
|
|
144
|
+
export function toChecksumAddressesFiltered(addresses) {
|
|
145
|
+
return toChecksumAddressesSafe(addresses).filter((addr) => addr !== null);
|
|
146
|
+
}
|
|
147
|
+
// ============================================================================
|
|
148
|
+
// Comparison
|
|
149
|
+
// ============================================================================
|
|
150
|
+
/**
|
|
151
|
+
* Compare two addresses for equality (case-insensitive).
|
|
152
|
+
*
|
|
153
|
+
* @param address1 - First address
|
|
154
|
+
* @param address2 - Second address
|
|
155
|
+
* @returns `true` if both addresses are valid and equal
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* areEqualAddresses(
|
|
159
|
+
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
160
|
+
* '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
|
|
161
|
+
* ) // true
|
|
162
|
+
*/
|
|
163
|
+
export function areEqualAddresses(address1, address2) {
|
|
164
|
+
if (!address1 || !address2) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
return getAddress(address1).toLowerCase() === getAddress(address2).toLowerCase();
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check if an address is the zero address.
|
|
176
|
+
*
|
|
177
|
+
* @param address - The address to check
|
|
178
|
+
* @returns `true` if the address is the zero address
|
|
179
|
+
*/
|
|
180
|
+
export function isZeroAddress(address) {
|
|
181
|
+
try {
|
|
182
|
+
return getAddress(address) === ADDRESS_ZERO;
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Error Types
|
|
190
|
+
// ============================================================================
|
|
191
|
+
/**
|
|
192
|
+
* Custom error for checksum address validation failures.
|
|
193
|
+
*/
|
|
194
|
+
export class ChecksumAddressError extends FheError {
|
|
195
|
+
constructor(message, options) {
|
|
196
|
+
super({ code: FheErrorCode.InvalidAddress, message, cause: options?.cause });
|
|
197
|
+
this.name = 'ChecksumAddressError';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/core/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAYjD,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,CAAC,MAAM,YAAY,GAAG,4CAA+D,CAAC;AAE5F,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,OAAO,UAAU,CA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C;IACf,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,QAAQ;IAChD,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { InternalAxiosRequestConfig } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* Supported authentication methods for API requests.
|
|
4
|
+
*/
|
|
5
|
+
export type AuthType = 'BearerToken' | 'ApiKeyHeader' | 'ApiKeyCookie';
|
|
6
|
+
/**
|
|
7
|
+
* Bearer Token authentication.
|
|
8
|
+
* Adds an `Authorization: Bearer <token>` header to the request.
|
|
9
|
+
*/
|
|
10
|
+
export type AuthBearerToken = {
|
|
11
|
+
type: 'BearerToken';
|
|
12
|
+
/** The Bearer token string. */
|
|
13
|
+
token: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Custom header authentication.
|
|
17
|
+
* Adds a custom header (default: `x-api-key`) with the provided API key value.
|
|
18
|
+
*/
|
|
19
|
+
export type AuthApiKeyHeader = {
|
|
20
|
+
type: 'ApiKeyHeader';
|
|
21
|
+
/** The header name. Defaults to `x-api-key` if not specified. */
|
|
22
|
+
header?: string;
|
|
23
|
+
/** The API key value to send in the header. */
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Custom cookie authentication.
|
|
28
|
+
* Sets a cookie (default: `x-api-key`) with the provided API key value.
|
|
29
|
+
* In browser environments, sets `document.cookie`; in Node.js, adds a `Cookie` header.
|
|
30
|
+
*/
|
|
31
|
+
export type AuthApiKeyCookie = {
|
|
32
|
+
type: 'ApiKeyCookie';
|
|
33
|
+
/** The cookie name. Defaults to `x-api-key` if not specified. */
|
|
34
|
+
cookie?: string;
|
|
35
|
+
/** The API key value to set in the cookie. */
|
|
36
|
+
value: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Union type of all supported authentication configurations.
|
|
40
|
+
*/
|
|
41
|
+
export type Auth = AuthBearerToken | AuthApiKeyHeader | AuthApiKeyCookie;
|
|
42
|
+
/**
|
|
43
|
+
* Applies the specified authentication method to an Axios request configuration.
|
|
44
|
+
*
|
|
45
|
+
* Supported authentication methods:
|
|
46
|
+
* - `BearerToken`: Adds `Authorization: Bearer <token>` header.
|
|
47
|
+
* - `ApiKeyHeader`: Adds a custom header (default: `x-api-key`) with the API key.
|
|
48
|
+
* - `ApiKeyCookie`: Sets a cookie (default: `x-api-key`) with the API key.
|
|
49
|
+
*
|
|
50
|
+
* If no authentication is provided, the request configuration is returned unchanged.
|
|
51
|
+
*
|
|
52
|
+
* @param config - The Axios request configuration to modify.
|
|
53
|
+
* @param auth - Optional authentication configuration.
|
|
54
|
+
* @returns The modified Axios request configuration.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Bearer Token
|
|
59
|
+
* setAxiosAuth(config, { type: 'BearerToken', token: 'jwt-token' });
|
|
60
|
+
*
|
|
61
|
+
* // Custom Header
|
|
62
|
+
* setAxiosAuth(config, { type: 'ApiKeyHeader', header: 'api-key', value: 'key-123' });
|
|
63
|
+
*
|
|
64
|
+
* // Custom Cookie
|
|
65
|
+
* setAxiosAuth(config, { type: 'ApiKeyCookie', cookie: 'api_key', value: 'key-123' });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function setAxiosAuth(config: InternalAxiosRequestConfig, auth?: Auth): InternalAxiosRequestConfig;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isNonEmptyString } from "./string.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies the specified authentication method to an Axios request configuration.
|
|
4
|
+
*
|
|
5
|
+
* Supported authentication methods:
|
|
6
|
+
* - `BearerToken`: Adds `Authorization: Bearer <token>` header.
|
|
7
|
+
* - `ApiKeyHeader`: Adds a custom header (default: `x-api-key`) with the API key.
|
|
8
|
+
* - `ApiKeyCookie`: Sets a cookie (default: `x-api-key`) with the API key.
|
|
9
|
+
*
|
|
10
|
+
* If no authentication is provided, the request configuration is returned unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @param config - The Axios request configuration to modify.
|
|
13
|
+
* @param auth - Optional authentication configuration.
|
|
14
|
+
* @returns The modified Axios request configuration.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Bearer Token
|
|
19
|
+
* setAxiosAuth(config, { type: 'BearerToken', token: 'jwt-token' });
|
|
20
|
+
*
|
|
21
|
+
* // Custom Header
|
|
22
|
+
* setAxiosAuth(config, { type: 'ApiKeyHeader', header: 'api-key', value: 'key-123' });
|
|
23
|
+
*
|
|
24
|
+
* // Custom Cookie
|
|
25
|
+
* setAxiosAuth(config, { type: 'ApiKeyCookie', cookie: 'api_key', value: 'key-123' });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function setAxiosAuth(config, auth) {
|
|
29
|
+
if (!auth)
|
|
30
|
+
return config;
|
|
31
|
+
const headers = config.headers;
|
|
32
|
+
switch (auth.type) {
|
|
33
|
+
case 'BearerToken': {
|
|
34
|
+
headers.Authorization = `Bearer ${auth.token}`;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'ApiKeyHeader': {
|
|
38
|
+
const headerName = isNonEmptyString(auth.header) ? auth.header : 'x-api-key';
|
|
39
|
+
headers[headerName] = auth.value;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'ApiKeyCookie': {
|
|
43
|
+
const cookieName = isNonEmptyString(auth.cookie) ? auth.cookie : 'x-api-key';
|
|
44
|
+
if (typeof window !== 'undefined') {
|
|
45
|
+
// Browser environment: set cookie via document.cookie
|
|
46
|
+
document.cookie = `${cookieName}=${auth.value}; path=/; SameSite=Lax; Secure;`;
|
|
47
|
+
config.withCredentials = true;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Node.js environment: set Cookie header
|
|
51
|
+
headers.Cookie = `${cookieName}=${auth.value};`;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/core/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA+C/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAkC,EAClC,IAAW;IAEX,IAAI,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IAEzB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAE/B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,aAAa,CAAC,CAAC,CAAC;YACnB,OAAO,CAAC,aAAa,GAAG,UAAU,IAAI,CAAC,KAAK,EAAE,CAAC;YAC/C,MAAM;QACR,CAAC;QAED,KAAK,cAAc,CAAC,CAAC,CAAC;YACpB,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;YAC7E,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YACjC,MAAM;QACR,CAAC;QAED,KAAK,cAAc,CAAC,CAAC,CAAC;YACpB,MAAM,UAAU,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;YAC7E,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;gBAClC,sDAAsD;gBACtD,QAAQ,CAAC,MAAM,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,KAAK,iCAAiC,CAAC;gBAC/E,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,yCAAyC;gBACzC,OAAO,CAAC,MAAM,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC;YAClD,CAAC;YACD,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Bytes32Hex, BytesHexNo0x } from "./primitives.js";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a hex string to a Uint8Array.
|
|
4
|
+
* Supports both prefixed (0x) and non-prefixed hex strings.
|
|
5
|
+
* @param hexString - Hex string (e.g., "0x1234" or "1234")
|
|
6
|
+
* @returns Uint8Array representation of the hex string
|
|
7
|
+
* @throws Error if the hex string has an odd number of digits or contains non-hex characters
|
|
8
|
+
*/
|
|
9
|
+
export declare const fromHexString: (hexString: string) => Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a Uint8Array to a hex string with a "0x" prefix.
|
|
12
|
+
* @param byteArray - The byte array to convert
|
|
13
|
+
* @returns Hex string with "0x" prefix (e.g., "0x1234")
|
|
14
|
+
*/
|
|
15
|
+
export declare function bytesToHex(byteArray: Uint8Array): `0x${string}`;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a Uint8Array to a hex string without the "0x" prefix.
|
|
18
|
+
*
|
|
19
|
+
* @param bytes - The byte array to convert. Returns `""` if `undefined` or empty.
|
|
20
|
+
* @returns A lowercase hex string with even length (2 chars per byte), without the "0x" prefix.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* bytesToHexNo0x(new Uint8Array([0x48, 0x65])) // "4865"
|
|
24
|
+
* bytesToHexNo0x(new Uint8Array([0x0a])) // "0a"
|
|
25
|
+
* bytesToHexNo0x(undefined) // ""
|
|
26
|
+
* bytesToHexNo0x(new Uint8Array([])) // ""
|
|
27
|
+
*/
|
|
28
|
+
export declare function bytesToHexNo0x(bytes: Uint8Array | undefined): BytesHexNo0x;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a Uint8Array to a BigInt.
|
|
31
|
+
* @param byteArray - The byte array to convert
|
|
32
|
+
* @returns BigInt representation of the byte array
|
|
33
|
+
*/
|
|
34
|
+
export declare function bytesToBigInt(byteArray: Uint8Array): bigint;
|
|
35
|
+
/**
|
|
36
|
+
* Concatenates multiple Uint8Arrays into a single Uint8Array.
|
|
37
|
+
* @param parts - Variable number of Uint8Arrays to concatenate
|
|
38
|
+
* @returns A new Uint8Array containing all input arrays concatenated in order
|
|
39
|
+
*/
|
|
40
|
+
export declare function concatBytes(...parts: Uint8Array[]): Uint8Array;
|
|
41
|
+
/**
|
|
42
|
+
* Validates and casts a string to the Bytes32Hex type.
|
|
43
|
+
* Ensures the string is a 32-byte hex string with a "0x" prefix (66 characters total).
|
|
44
|
+
* @param value - The value to validate and cast
|
|
45
|
+
* @returns The validated Bytes32Hex string
|
|
46
|
+
* @throws Error if the value is not a valid 32-byte hex string
|
|
47
|
+
*/
|
|
48
|
+
export declare function toBytes32Hex(value: unknown): Bytes32Hex;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { FheErrorCode } from "./errors/error-codes.js";
|
|
2
|
+
import { FheError } from "./errors/fhe-error.js";
|
|
3
|
+
/** Nibble lookup table for fast hex decoding (avoids per-byte parseInt). */
|
|
4
|
+
const HEX_VALUE = {
|
|
5
|
+
"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7,
|
|
6
|
+
"8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15,
|
|
7
|
+
"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Converts a hex string to a Uint8Array.
|
|
11
|
+
* Supports both prefixed (0x) and non-prefixed hex strings.
|
|
12
|
+
* @param hexString - Hex string (e.g., "0x1234" or "1234")
|
|
13
|
+
* @returns Uint8Array representation of the hex string
|
|
14
|
+
* @throws Error if the hex string has an odd number of digits or contains non-hex characters
|
|
15
|
+
*/
|
|
16
|
+
export const fromHexString = (hexString) => {
|
|
17
|
+
// Remove the "0x" prefix if present
|
|
18
|
+
const cleaned = hexString.replace(/^(0x)/, "");
|
|
19
|
+
if (cleaned.length === 0)
|
|
20
|
+
return new Uint8Array();
|
|
21
|
+
// Each byte requires exactly two hex digits; reject malformed input instead
|
|
22
|
+
// of silently changing its value (e.g. "0x123" -> 0x0123).
|
|
23
|
+
if (cleaned.length % 2 !== 0) {
|
|
24
|
+
throw new FheError({ code: FheErrorCode.InvalidHex, message: `Invalid hex string: "${hexString}" (odd number of hex digits)` });
|
|
25
|
+
}
|
|
26
|
+
if (!/^[0-9a-fA-F]+$/.test(cleaned)) {
|
|
27
|
+
throw new FheError({ code: FheErrorCode.InvalidHex, message: `Invalid hex string: "${hexString}" (contains non-hex characters)` });
|
|
28
|
+
}
|
|
29
|
+
const result = new Uint8Array(cleaned.length / 2);
|
|
30
|
+
for (let i = 0; i < cleaned.length; i += 2) {
|
|
31
|
+
result[i / 2] = (HEX_VALUE[cleaned[i]] << 4) | HEX_VALUE[cleaned[i + 1]];
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Converts a Uint8Array to a hex string with a "0x" prefix.
|
|
37
|
+
* @param byteArray - The byte array to convert
|
|
38
|
+
* @returns Hex string with "0x" prefix (e.g., "0x1234")
|
|
39
|
+
*/
|
|
40
|
+
export function bytesToHex(byteArray) {
|
|
41
|
+
if (!byteArray || byteArray.length === 0) {
|
|
42
|
+
return "0x";
|
|
43
|
+
}
|
|
44
|
+
let hex = "";
|
|
45
|
+
for (const byte of byteArray) {
|
|
46
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
47
|
+
}
|
|
48
|
+
return `0x${hex}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts a Uint8Array to a hex string without the "0x" prefix.
|
|
52
|
+
*
|
|
53
|
+
* @param bytes - The byte array to convert. Returns `""` if `undefined` or empty.
|
|
54
|
+
* @returns A lowercase hex string with even length (2 chars per byte), without the "0x" prefix.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* bytesToHexNo0x(new Uint8Array([0x48, 0x65])) // "4865"
|
|
58
|
+
* bytesToHexNo0x(new Uint8Array([0x0a])) // "0a"
|
|
59
|
+
* bytesToHexNo0x(undefined) // ""
|
|
60
|
+
* bytesToHexNo0x(new Uint8Array([])) // ""
|
|
61
|
+
*/
|
|
62
|
+
export function bytesToHexNo0x(bytes) {
|
|
63
|
+
if (!bytes || bytes.length === 0) {
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
let hex = '';
|
|
67
|
+
for (const byte of bytes) {
|
|
68
|
+
hex += byte.toString(16).padStart(2, '0');
|
|
69
|
+
}
|
|
70
|
+
return hex;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Converts a Uint8Array to a BigInt.
|
|
74
|
+
* @param byteArray - The byte array to convert
|
|
75
|
+
* @returns BigInt representation of the byte array
|
|
76
|
+
*/
|
|
77
|
+
export function bytesToBigInt(byteArray) {
|
|
78
|
+
if (!byteArray || byteArray.length === 0) {
|
|
79
|
+
return 0n;
|
|
80
|
+
}
|
|
81
|
+
let hex = "";
|
|
82
|
+
for (const byte of byteArray) {
|
|
83
|
+
hex += byte.toString(16).padStart(2, "0");
|
|
84
|
+
}
|
|
85
|
+
return BigInt(`0x${hex}`);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Concatenates multiple Uint8Arrays into a single Uint8Array.
|
|
89
|
+
* @param parts - Variable number of Uint8Arrays to concatenate
|
|
90
|
+
* @returns A new Uint8Array containing all input arrays concatenated in order
|
|
91
|
+
*/
|
|
92
|
+
export function concatBytes(...parts) {
|
|
93
|
+
// Calculate total length of the resulting array
|
|
94
|
+
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
95
|
+
const result = new Uint8Array(totalLength);
|
|
96
|
+
let offset = 0;
|
|
97
|
+
for (const part of parts) {
|
|
98
|
+
result.set(part, offset);
|
|
99
|
+
offset += part.length;
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validates and casts a string to the Bytes32Hex type.
|
|
105
|
+
* Ensures the string is a 32-byte hex string with a "0x" prefix (66 characters total).
|
|
106
|
+
* @param value - The value to validate and cast
|
|
107
|
+
* @returns The validated Bytes32Hex string
|
|
108
|
+
* @throws Error if the value is not a valid 32-byte hex string
|
|
109
|
+
*/
|
|
110
|
+
export function toBytes32Hex(value) {
|
|
111
|
+
// Check if the value is a valid 0x-prefixed 64-character hex string
|
|
112
|
+
if (typeof value === "string" && /^0x[a-fA-F0-9]{64}$/.test(value)) {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
throw new FheError({ code: FheErrorCode.InvalidHex, message: `Invalid Bytes32Hex: ${value}` });
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/core/bytes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,4EAA4E;AAC5E,MAAM,SAAS,GAA2B;IACxC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,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