@seljs/types 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/abstracts/{type-wrapper.d.ts → type-wrapper.d.cts} +6 -4
- package/dist/abstracts/type-wrapper.d.mts +15 -0
- package/dist/{context.d.ts → context.d.cts} +17 -18
- package/dist/context.d.mts +57 -0
- package/dist/conversion.cjs +41 -0
- package/dist/{conversion.d.ts → conversion.d.cts} +5 -3
- package/dist/conversion.d.mts +15 -0
- package/dist/conversion.mjs +40 -0
- package/dist/custom-types/solidity-address-type-wrapper.cjs +38 -0
- package/dist/custom-types/solidity-address-type-wrapper.d.cts +25 -0
- package/dist/custom-types/solidity-address-type-wrapper.d.mts +25 -0
- package/dist/custom-types/solidity-address-type-wrapper.mjs +37 -0
- package/dist/custom-types/solidity-int-type-wrapper.cjs +31 -0
- package/dist/custom-types/{solidity-int-type-wrapper.d.ts → solidity-int-type-wrapper.d.cts} +10 -7
- package/dist/custom-types/solidity-int-type-wrapper.d.mts +22 -0
- package/dist/custom-types/solidity-int-type-wrapper.mjs +30 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +6 -0
- package/dist/registry.cjs +65 -0
- package/dist/registry.d.cts +28 -0
- package/dist/registry.d.mts +28 -0
- package/dist/registry.mjs +65 -0
- package/dist/units.cjs +44 -0
- package/dist/{units.d.ts → units.d.cts} +7 -4
- package/dist/units.d.mts +18 -0
- package/dist/units.mjs +43 -0
- package/package.json +17 -10
- package/dist/abstracts/index.d.ts +0 -2
- package/dist/abstracts/index.d.ts.map +0 -1
- package/dist/abstracts/index.js +0 -1
- package/dist/abstracts/type-wrapper.d.ts.map +0 -1
- package/dist/abstracts/type-wrapper.js +0 -1
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -1
- package/dist/context.spec.d.ts +0 -2
- package/dist/context.spec.d.ts.map +0 -1
- package/dist/context.spec.js +0 -38
- package/dist/conversion.d.ts.map +0 -1
- package/dist/conversion.js +0 -48
- package/dist/conversion.spec.d.ts +0 -2
- package/dist/conversion.spec.d.ts.map +0 -1
- package/dist/conversion.spec.js +0 -53
- package/dist/custom-types/index.d.ts +0 -3
- package/dist/custom-types/index.d.ts.map +0 -1
- package/dist/custom-types/index.js +0 -2
- package/dist/custom-types/solidity-address-type-wrapper.d.ts +0 -22
- package/dist/custom-types/solidity-address-type-wrapper.d.ts.map +0 -1
- package/dist/custom-types/solidity-address-type-wrapper.js +0 -40
- package/dist/custom-types/solidity-int-type-wrapper.d.ts.map +0 -1
- package/dist/custom-types/solidity-int-type-wrapper.js +0 -35
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/registry.d.ts +0 -26
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -58
- package/dist/registry.spec.d.ts +0 -2
- package/dist/registry.spec.d.ts.map +0 -1
- package/dist/registry.spec.js +0 -57
- package/dist/units.d.ts.map +0 -1
- package/dist/units.js +0 -55
- package/dist/units.spec.d.ts +0 -2
- package/dist/units.spec.d.ts.map +0 -1
- package/dist/units.spec.js +0 -77
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.1](https://github.com/abinnovision/seljs/compare/types-v1.0.0...types-v1.0.1) (2026-03-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* export esm and cjs ([#23](https://github.com/abinnovision/seljs/issues/23)) ([23d525d](https://github.com/abinnovision/seljs/commit/23d525d9084d18a370d4c6307b983a857a865f59))
|
|
9
|
+
|
|
3
10
|
## 1.0.0 (2026-03-13)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/abstracts/type-wrapper.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Shared interface for Solidity wrapper types (UInt256, Int256, Address).
|
|
3
4
|
*
|
|
@@ -6,8 +7,9 @@
|
|
|
6
7
|
* can identify runtime values as custom Solidity types rather than native JS
|
|
7
8
|
* primitives (BigInt → "int", string → "string").
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
interface TypeWrapper<T> {
|
|
11
|
+
readonly value: T;
|
|
12
|
+
valueOf: () => T;
|
|
12
13
|
}
|
|
13
|
-
//#
|
|
14
|
+
//#endregion
|
|
15
|
+
export { TypeWrapper };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/abstracts/type-wrapper.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared interface for Solidity wrapper types (UInt256, Int256, Address).
|
|
4
|
+
*
|
|
5
|
+
* These wrappers are registered on the CEL environment via `registerType` so
|
|
6
|
+
* that cel-js's constructor-based type matching (`objectTypesByConstructor`)
|
|
7
|
+
* can identify runtime values as custom Solidity types rather than native JS
|
|
8
|
+
* primitives (BigInt → "int", string → "string").
|
|
9
|
+
*/
|
|
10
|
+
interface TypeWrapper<T> {
|
|
11
|
+
readonly value: T;
|
|
12
|
+
valueOf: () => T;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { TypeWrapper };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/context.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Infers the TypeScript type for a CEL type string.
|
|
3
4
|
* Handles primitives and list<T>.
|
|
@@ -7,38 +8,38 @@ type InferCelType<T extends ContextCelType> = T extends `list<${infer E extends
|
|
|
7
8
|
* Resolves a ContextFieldDefinition to its ContextCelType.
|
|
8
9
|
*/
|
|
9
10
|
type ResolveCelType<T extends ContextFieldDefinition> = T extends ContextCelType ? T : T extends {
|
|
10
|
-
|
|
11
|
+
type: infer U extends ContextCelType;
|
|
11
12
|
} ? U : never;
|
|
12
13
|
/**
|
|
13
14
|
* Primitive CEL types valid for user-defined context variables.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
type PrimitiveCelType = "sol_int" | "sol_address" | "bool" | "string" | "bytes";
|
|
16
17
|
/**
|
|
17
18
|
* All CEL types valid for user-defined context variables.
|
|
18
19
|
* Includes primitives and list<primitive>.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
type ContextCelType = PrimitiveCelType | `list<${PrimitiveCelType}>`;
|
|
21
22
|
/**
|
|
22
23
|
* Maps primitive CEL type names to their TypeScript representation.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
interface CelTypeToTs {
|
|
26
|
+
sol_int: bigint;
|
|
27
|
+
sol_address: `0x${string}`;
|
|
28
|
+
bool: boolean;
|
|
29
|
+
string: string;
|
|
30
|
+
bytes: string;
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* A context field can be a bare CEL type string or an object with type and description.
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
type ContextFieldDefinition = ContextCelType | {
|
|
36
|
+
type: ContextCelType;
|
|
37
|
+
description: string;
|
|
37
38
|
};
|
|
38
39
|
/**
|
|
39
40
|
* Flat definition of context variables: key is the variable name, value is the CEL type or a typed object with description.
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
type ContextDefinition = Record<string, ContextFieldDefinition>;
|
|
42
43
|
/**
|
|
43
44
|
* Infers the TypeScript type of context values from a ContextDefinition.
|
|
44
45
|
*
|
|
@@ -51,8 +52,6 @@ export type ContextDefinition = Record<string, ContextFieldDefinition>;
|
|
|
51
52
|
* // { addrs: `0x${string}`[] }
|
|
52
53
|
* ```
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=context.d.ts.map
|
|
55
|
+
type InferContext<T extends ContextDefinition> = { [K in keyof T]: InferCelType<ResolveCelType<T[K]>> };
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CelTypeToTs, ContextCelType, ContextDefinition, ContextFieldDefinition, InferContext, PrimitiveCelType };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/context.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Infers the TypeScript type for a CEL type string.
|
|
4
|
+
* Handles primitives and list<T>.
|
|
5
|
+
*/
|
|
6
|
+
type InferCelType<T extends ContextCelType> = T extends `list<${infer E extends PrimitiveCelType}>` ? CelTypeToTs[E][] : T extends keyof CelTypeToTs ? CelTypeToTs[T] : never;
|
|
7
|
+
/**
|
|
8
|
+
* Resolves a ContextFieldDefinition to its ContextCelType.
|
|
9
|
+
*/
|
|
10
|
+
type ResolveCelType<T extends ContextFieldDefinition> = T extends ContextCelType ? T : T extends {
|
|
11
|
+
type: infer U extends ContextCelType;
|
|
12
|
+
} ? U : never;
|
|
13
|
+
/**
|
|
14
|
+
* Primitive CEL types valid for user-defined context variables.
|
|
15
|
+
*/
|
|
16
|
+
type PrimitiveCelType = "sol_int" | "sol_address" | "bool" | "string" | "bytes";
|
|
17
|
+
/**
|
|
18
|
+
* All CEL types valid for user-defined context variables.
|
|
19
|
+
* Includes primitives and list<primitive>.
|
|
20
|
+
*/
|
|
21
|
+
type ContextCelType = PrimitiveCelType | `list<${PrimitiveCelType}>`;
|
|
22
|
+
/**
|
|
23
|
+
* Maps primitive CEL type names to their TypeScript representation.
|
|
24
|
+
*/
|
|
25
|
+
interface CelTypeToTs {
|
|
26
|
+
sol_int: bigint;
|
|
27
|
+
sol_address: `0x${string}`;
|
|
28
|
+
bool: boolean;
|
|
29
|
+
string: string;
|
|
30
|
+
bytes: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A context field can be a bare CEL type string or an object with type and description.
|
|
34
|
+
*/
|
|
35
|
+
type ContextFieldDefinition = ContextCelType | {
|
|
36
|
+
type: ContextCelType;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Flat definition of context variables: key is the variable name, value is the CEL type or a typed object with description.
|
|
41
|
+
*/
|
|
42
|
+
type ContextDefinition = Record<string, ContextFieldDefinition>;
|
|
43
|
+
/**
|
|
44
|
+
* Infers the TypeScript type of context values from a ContextDefinition.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* type Ctx = InferContext<{ user: "sol_address"; amount: "sol_int" }>;
|
|
49
|
+
* // { user: `0x${string}`; amount: bigint }
|
|
50
|
+
*
|
|
51
|
+
* type CtxList = InferContext<{ addrs: "list<sol_address>" }>;
|
|
52
|
+
* // { addrs: `0x${string}`[] }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
type InferContext<T extends ContextDefinition> = { [K in keyof T]: InferCelType<ResolveCelType<T[K]>> };
|
|
56
|
+
//#endregion
|
|
57
|
+
export { CelTypeToTs, ContextCelType, ContextDefinition, ContextFieldDefinition, InferContext, PrimitiveCelType };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const require_registry = require("./registry.cjs");
|
|
2
|
+
//#region src/conversion.ts
|
|
3
|
+
const LIST_REGEX = /^(.*)(\[\d*\])$/;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a Solidity type string represents a list type (e.g. "uint256[]", "address[5]") and extracts the base type.
|
|
6
|
+
*
|
|
7
|
+
* @param input Solidity type string to check (e.g. "uint256[]", "address[5]", "bool")
|
|
8
|
+
* @return The base type string if the input is a list type (e.g. "uint256" for "uint256[]"), or null if the input is not a list type
|
|
9
|
+
*/
|
|
10
|
+
const tryListMatch = (input) => {
|
|
11
|
+
const match = input.match(LIST_REGEX);
|
|
12
|
+
if (match) return match[1] ?? null;
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Maps a raw Solidity type string to its corresponding CEL type.
|
|
17
|
+
*
|
|
18
|
+
* @param input The raw Solidity type string (e.g. "uint256", "address", "bool")
|
|
19
|
+
* @return The corresponding CEL type name, or null if the type is not recognized
|
|
20
|
+
*/
|
|
21
|
+
const mapSolidityTypeToCEL = (input) => {
|
|
22
|
+
const listBaseType = tryListMatch(input);
|
|
23
|
+
if (listBaseType) {
|
|
24
|
+
const celBaseType = mapSolidityTypeToCEL(listBaseType);
|
|
25
|
+
if (celBaseType) return `list<${celBaseType}>`;
|
|
26
|
+
} else {
|
|
27
|
+
const aliasedType = require_registry.SOLIDITY_TYPES.find((type) => type.solidityAliases.includes(input));
|
|
28
|
+
if (aliasedType) return aliasedType.name;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a given Solidity type string represents a list type (e.g. "uint256[]", "address[5]").
|
|
34
|
+
* @param input
|
|
35
|
+
*/
|
|
36
|
+
const isSolidityTypeList = (input) => {
|
|
37
|
+
return tryListMatch(input) !== null;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.isSolidityTypeList = isSolidityTypeList;
|
|
41
|
+
exports.mapSolidityTypeToCEL = mapSolidityTypeToCEL;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
//#region src/conversion.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Maps a raw Solidity type string to its corresponding CEL type.
|
|
3
4
|
*
|
|
4
5
|
* @param input The raw Solidity type string (e.g. "uint256", "address", "bool")
|
|
5
6
|
* @return The corresponding CEL type name, or null if the type is not recognized
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
declare const mapSolidityTypeToCEL: (input: string) => string | null;
|
|
8
9
|
/**
|
|
9
10
|
* Checks if a given Solidity type string represents a list type (e.g. "uint256[]", "address[5]").
|
|
10
11
|
* @param input
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
//#
|
|
13
|
+
declare const isSolidityTypeList: (input: string) => boolean;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isSolidityTypeList, mapSolidityTypeToCEL };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/conversion.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Maps a raw Solidity type string to its corresponding CEL type.
|
|
4
|
+
*
|
|
5
|
+
* @param input The raw Solidity type string (e.g. "uint256", "address", "bool")
|
|
6
|
+
* @return The corresponding CEL type name, or null if the type is not recognized
|
|
7
|
+
*/
|
|
8
|
+
declare const mapSolidityTypeToCEL: (input: string) => string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a given Solidity type string represents a list type (e.g. "uint256[]", "address[5]").
|
|
11
|
+
* @param input
|
|
12
|
+
*/
|
|
13
|
+
declare const isSolidityTypeList: (input: string) => boolean;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isSolidityTypeList, mapSolidityTypeToCEL };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SOLIDITY_TYPES } from "./registry.mjs";
|
|
2
|
+
//#region src/conversion.ts
|
|
3
|
+
const LIST_REGEX = /^(.*)(\[\d*\])$/;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a Solidity type string represents a list type (e.g. "uint256[]", "address[5]") and extracts the base type.
|
|
6
|
+
*
|
|
7
|
+
* @param input Solidity type string to check (e.g. "uint256[]", "address[5]", "bool")
|
|
8
|
+
* @return The base type string if the input is a list type (e.g. "uint256" for "uint256[]"), or null if the input is not a list type
|
|
9
|
+
*/
|
|
10
|
+
const tryListMatch = (input) => {
|
|
11
|
+
const match = input.match(LIST_REGEX);
|
|
12
|
+
if (match) return match[1] ?? null;
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Maps a raw Solidity type string to its corresponding CEL type.
|
|
17
|
+
*
|
|
18
|
+
* @param input The raw Solidity type string (e.g. "uint256", "address", "bool")
|
|
19
|
+
* @return The corresponding CEL type name, or null if the type is not recognized
|
|
20
|
+
*/
|
|
21
|
+
const mapSolidityTypeToCEL = (input) => {
|
|
22
|
+
const listBaseType = tryListMatch(input);
|
|
23
|
+
if (listBaseType) {
|
|
24
|
+
const celBaseType = mapSolidityTypeToCEL(listBaseType);
|
|
25
|
+
if (celBaseType) return `list<${celBaseType}>`;
|
|
26
|
+
} else {
|
|
27
|
+
const aliasedType = SOLIDITY_TYPES.find((type) => type.solidityAliases.includes(input));
|
|
28
|
+
if (aliasedType) return aliasedType.name;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a given Solidity type string represents a list type (e.g. "uint256[]", "address[5]").
|
|
34
|
+
* @param input
|
|
35
|
+
*/
|
|
36
|
+
const isSolidityTypeList = (input) => {
|
|
37
|
+
return tryListMatch(input) !== null;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { isSolidityTypeList, mapSolidityTypeToCEL };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/custom-types/solidity-address-type-wrapper.ts
|
|
2
|
+
const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
3
|
+
/**
|
|
4
|
+
* Convert a value to a valid Ethereum address string.
|
|
5
|
+
*
|
|
6
|
+
* @param value
|
|
7
|
+
*/
|
|
8
|
+
const toAddress = (value) => {
|
|
9
|
+
if (value instanceof SolidityAddressTypeWrapper) return value.value;
|
|
10
|
+
if (typeof value !== "string") throw new TypeError(`Invalid address value: ${String(value)}`);
|
|
11
|
+
if (!SolidityAddressTypeWrapper.isValid(value)) throw new TypeError(`Invalid address value: ${value}`);
|
|
12
|
+
return value.toLowerCase();
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Ethereum address wrapper with regex-based validation.
|
|
16
|
+
* Normalizes to lowercase (no viem dependency).
|
|
17
|
+
*/
|
|
18
|
+
var SolidityAddressTypeWrapper = class {
|
|
19
|
+
value;
|
|
20
|
+
constructor(value) {
|
|
21
|
+
this.value = toAddress(value);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check whether a string is a valid 20-byte hex address.
|
|
25
|
+
*/
|
|
26
|
+
static isValid(value) {
|
|
27
|
+
return ADDRESS_REGEX.test(value);
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return this.value;
|
|
31
|
+
}
|
|
32
|
+
valueOf() {
|
|
33
|
+
return this.value;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.SolidityAddressTypeWrapper = SolidityAddressTypeWrapper;
|
|
38
|
+
exports.toAddress = toAddress;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TypeWrapper } from "../abstracts/type-wrapper.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/custom-types/solidity-address-type-wrapper.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Convert a value to a valid Ethereum address string.
|
|
6
|
+
*
|
|
7
|
+
* @param value
|
|
8
|
+
*/
|
|
9
|
+
declare const toAddress: (value: unknown) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Ethereum address wrapper with regex-based validation.
|
|
12
|
+
* Normalizes to lowercase (no viem dependency).
|
|
13
|
+
*/
|
|
14
|
+
declare class SolidityAddressTypeWrapper implements TypeWrapper<string> {
|
|
15
|
+
readonly value: string;
|
|
16
|
+
constructor(value: unknown);
|
|
17
|
+
/**
|
|
18
|
+
* Check whether a string is a valid 20-byte hex address.
|
|
19
|
+
*/
|
|
20
|
+
static isValid(value: string): boolean;
|
|
21
|
+
toString(): string;
|
|
22
|
+
valueOf(): string;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SolidityAddressTypeWrapper, toAddress };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TypeWrapper } from "../abstracts/type-wrapper.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/custom-types/solidity-address-type-wrapper.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Convert a value to a valid Ethereum address string.
|
|
6
|
+
*
|
|
7
|
+
* @param value
|
|
8
|
+
*/
|
|
9
|
+
declare const toAddress: (value: unknown) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Ethereum address wrapper with regex-based validation.
|
|
12
|
+
* Normalizes to lowercase (no viem dependency).
|
|
13
|
+
*/
|
|
14
|
+
declare class SolidityAddressTypeWrapper implements TypeWrapper<string> {
|
|
15
|
+
readonly value: string;
|
|
16
|
+
constructor(value: unknown);
|
|
17
|
+
/**
|
|
18
|
+
* Check whether a string is a valid 20-byte hex address.
|
|
19
|
+
*/
|
|
20
|
+
static isValid(value: string): boolean;
|
|
21
|
+
toString(): string;
|
|
22
|
+
valueOf(): string;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SolidityAddressTypeWrapper, toAddress };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/custom-types/solidity-address-type-wrapper.ts
|
|
2
|
+
const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
3
|
+
/**
|
|
4
|
+
* Convert a value to a valid Ethereum address string.
|
|
5
|
+
*
|
|
6
|
+
* @param value
|
|
7
|
+
*/
|
|
8
|
+
const toAddress = (value) => {
|
|
9
|
+
if (value instanceof SolidityAddressTypeWrapper) return value.value;
|
|
10
|
+
if (typeof value !== "string") throw new TypeError(`Invalid address value: ${String(value)}`);
|
|
11
|
+
if (!SolidityAddressTypeWrapper.isValid(value)) throw new TypeError(`Invalid address value: ${value}`);
|
|
12
|
+
return value.toLowerCase();
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Ethereum address wrapper with regex-based validation.
|
|
16
|
+
* Normalizes to lowercase (no viem dependency).
|
|
17
|
+
*/
|
|
18
|
+
var SolidityAddressTypeWrapper = class {
|
|
19
|
+
value;
|
|
20
|
+
constructor(value) {
|
|
21
|
+
this.value = toAddress(value);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check whether a string is a valid 20-byte hex address.
|
|
25
|
+
*/
|
|
26
|
+
static isValid(value) {
|
|
27
|
+
return ADDRESS_REGEX.test(value);
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return this.value;
|
|
31
|
+
}
|
|
32
|
+
valueOf() {
|
|
33
|
+
return this.value;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { SolidityAddressTypeWrapper, toAddress };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/custom-types/solidity-int-type-wrapper.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert any BigInt-compatible value to a native bigint.
|
|
4
|
+
* Handles SolidityIntTypeWrapper instances, bigint literals, integer numbers, and numeric strings.
|
|
5
|
+
*/
|
|
6
|
+
function toBigInt(value) {
|
|
7
|
+
if (value instanceof SolidityIntTypeWrapper) return value.value;
|
|
8
|
+
if (typeof value === "bigint") return value;
|
|
9
|
+
if (typeof value === "number" && Number.isInteger(value)) return BigInt(value);
|
|
10
|
+
if (typeof value === "string") return BigInt(value);
|
|
11
|
+
throw new TypeError(`Invalid integer value: ${String(value)}`);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Unified Solidity integer wrapper for the CEL runtime.
|
|
15
|
+
*
|
|
16
|
+
* Wraps all Solidity integer types (uint8–uint256, int8–int256) as a single
|
|
17
|
+
* CEL custom type backed by native BigInt. This bypasses cel-js's built-in
|
|
18
|
+
* "int" type which enforces 64-bit overflow checks.
|
|
19
|
+
*/
|
|
20
|
+
var SolidityIntTypeWrapper = class {
|
|
21
|
+
value;
|
|
22
|
+
constructor(value) {
|
|
23
|
+
this.value = toBigInt(value);
|
|
24
|
+
}
|
|
25
|
+
valueOf() {
|
|
26
|
+
return this.value;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.SolidityIntTypeWrapper = SolidityIntTypeWrapper;
|
|
31
|
+
exports.toBigInt = toBigInt;
|
package/dist/custom-types/{solidity-int-type-wrapper.d.ts → solidity-int-type-wrapper.d.cts}
RENAMED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TypeWrapper } from "../abstracts/type-wrapper.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/custom-types/solidity-int-type-wrapper.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Convert any BigInt-compatible value to a native bigint.
|
|
4
6
|
* Handles SolidityIntTypeWrapper instances, bigint literals, integer numbers, and numeric strings.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
declare function toBigInt(value: unknown): bigint;
|
|
7
9
|
/**
|
|
8
10
|
* Unified Solidity integer wrapper for the CEL runtime.
|
|
9
11
|
*
|
|
@@ -11,9 +13,10 @@ export declare function toBigInt(value: unknown): bigint;
|
|
|
11
13
|
* CEL custom type backed by native BigInt. This bypasses cel-js's built-in
|
|
12
14
|
* "int" type which enforces 64-bit overflow checks.
|
|
13
15
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
declare class SolidityIntTypeWrapper implements TypeWrapper<bigint> {
|
|
17
|
+
readonly value: bigint;
|
|
18
|
+
constructor(value: unknown);
|
|
19
|
+
valueOf(): bigint;
|
|
18
20
|
}
|
|
19
|
-
//#
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SolidityIntTypeWrapper, toBigInt };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TypeWrapper } from "../abstracts/type-wrapper.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/custom-types/solidity-int-type-wrapper.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Convert any BigInt-compatible value to a native bigint.
|
|
6
|
+
* Handles SolidityIntTypeWrapper instances, bigint literals, integer numbers, and numeric strings.
|
|
7
|
+
*/
|
|
8
|
+
declare function toBigInt(value: unknown): bigint;
|
|
9
|
+
/**
|
|
10
|
+
* Unified Solidity integer wrapper for the CEL runtime.
|
|
11
|
+
*
|
|
12
|
+
* Wraps all Solidity integer types (uint8–uint256, int8–int256) as a single
|
|
13
|
+
* CEL custom type backed by native BigInt. This bypasses cel-js's built-in
|
|
14
|
+
* "int" type which enforces 64-bit overflow checks.
|
|
15
|
+
*/
|
|
16
|
+
declare class SolidityIntTypeWrapper implements TypeWrapper<bigint> {
|
|
17
|
+
readonly value: bigint;
|
|
18
|
+
constructor(value: unknown);
|
|
19
|
+
valueOf(): bigint;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SolidityIntTypeWrapper, toBigInt };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/custom-types/solidity-int-type-wrapper.ts
|
|
2
|
+
/**
|
|
3
|
+
* Convert any BigInt-compatible value to a native bigint.
|
|
4
|
+
* Handles SolidityIntTypeWrapper instances, bigint literals, integer numbers, and numeric strings.
|
|
5
|
+
*/
|
|
6
|
+
function toBigInt(value) {
|
|
7
|
+
if (value instanceof SolidityIntTypeWrapper) return value.value;
|
|
8
|
+
if (typeof value === "bigint") return value;
|
|
9
|
+
if (typeof value === "number" && Number.isInteger(value)) return BigInt(value);
|
|
10
|
+
if (typeof value === "string") return BigInt(value);
|
|
11
|
+
throw new TypeError(`Invalid integer value: ${String(value)}`);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Unified Solidity integer wrapper for the CEL runtime.
|
|
15
|
+
*
|
|
16
|
+
* Wraps all Solidity integer types (uint8–uint256, int8–int256) as a single
|
|
17
|
+
* CEL custom type backed by native BigInt. This bypasses cel-js's built-in
|
|
18
|
+
* "int" type which enforces 64-bit overflow checks.
|
|
19
|
+
*/
|
|
20
|
+
var SolidityIntTypeWrapper = class {
|
|
21
|
+
value;
|
|
22
|
+
constructor(value) {
|
|
23
|
+
this.value = toBigInt(value);
|
|
24
|
+
}
|
|
25
|
+
valueOf() {
|
|
26
|
+
return this.value;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { SolidityIntTypeWrapper, toBigInt };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_solidity_address_type_wrapper = require("./custom-types/solidity-address-type-wrapper.cjs");
|
|
3
|
+
const require_solidity_int_type_wrapper = require("./custom-types/solidity-int-type-wrapper.cjs");
|
|
4
|
+
const require_registry = require("./registry.cjs");
|
|
5
|
+
const require_conversion = require("./conversion.cjs");
|
|
6
|
+
const require_units = require("./units.cjs");
|
|
7
|
+
exports.SOLIDITY_TYPES = require_registry.SOLIDITY_TYPES;
|
|
8
|
+
exports.SolidityAddressTypeWrapper = require_solidity_address_type_wrapper.SolidityAddressTypeWrapper;
|
|
9
|
+
exports.SolidityIntTypeWrapper = require_solidity_int_type_wrapper.SolidityIntTypeWrapper;
|
|
10
|
+
exports.formatUnitsValue = require_units.formatUnitsValue;
|
|
11
|
+
exports.isSolidityTypeList = require_conversion.isSolidityTypeList;
|
|
12
|
+
exports.mapSolidityTypeToCEL = require_conversion.mapSolidityTypeToCEL;
|
|
13
|
+
exports.parseUnitsValue = require_units.parseUnitsValue;
|
|
14
|
+
exports.toAddress = require_solidity_address_type_wrapper.toAddress;
|
|
15
|
+
exports.toBigInt = require_solidity_int_type_wrapper.toBigInt;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TypeWrapper } from "./abstracts/type-wrapper.cjs";
|
|
2
|
+
import { SolidityAddressTypeWrapper, toAddress } from "./custom-types/solidity-address-type-wrapper.cjs";
|
|
3
|
+
import { SolidityIntTypeWrapper, toBigInt } from "./custom-types/solidity-int-type-wrapper.cjs";
|
|
4
|
+
import { SOLIDITY_TYPES } from "./registry.cjs";
|
|
5
|
+
import { isSolidityTypeList, mapSolidityTypeToCEL } from "./conversion.cjs";
|
|
6
|
+
import { formatUnitsValue, parseUnitsValue } from "./units.cjs";
|
|
7
|
+
import { CelTypeToTs, ContextCelType, ContextDefinition, ContextFieldDefinition, InferContext, PrimitiveCelType } from "./context.cjs";
|
|
8
|
+
export { CelTypeToTs, ContextCelType, ContextDefinition, ContextFieldDefinition, InferContext, PrimitiveCelType, SOLIDITY_TYPES, SolidityAddressTypeWrapper, SolidityIntTypeWrapper, TypeWrapper, formatUnitsValue, isSolidityTypeList, mapSolidityTypeToCEL, parseUnitsValue, toAddress, toBigInt };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TypeWrapper } from "./abstracts/type-wrapper.mjs";
|
|
2
|
+
import { SolidityAddressTypeWrapper, toAddress } from "./custom-types/solidity-address-type-wrapper.mjs";
|
|
3
|
+
import { SolidityIntTypeWrapper, toBigInt } from "./custom-types/solidity-int-type-wrapper.mjs";
|
|
4
|
+
import { SOLIDITY_TYPES } from "./registry.mjs";
|
|
5
|
+
import { isSolidityTypeList, mapSolidityTypeToCEL } from "./conversion.mjs";
|
|
6
|
+
import { formatUnitsValue, parseUnitsValue } from "./units.mjs";
|
|
7
|
+
import { CelTypeToTs, ContextCelType, ContextDefinition, ContextFieldDefinition, InferContext, PrimitiveCelType } from "./context.mjs";
|
|
8
|
+
export { CelTypeToTs, ContextCelType, ContextDefinition, ContextFieldDefinition, InferContext, PrimitiveCelType, SOLIDITY_TYPES, SolidityAddressTypeWrapper, SolidityIntTypeWrapper, TypeWrapper, formatUnitsValue, isSolidityTypeList, mapSolidityTypeToCEL, parseUnitsValue, toAddress, toBigInt };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SolidityAddressTypeWrapper, toAddress } from "./custom-types/solidity-address-type-wrapper.mjs";
|
|
2
|
+
import { SolidityIntTypeWrapper, toBigInt } from "./custom-types/solidity-int-type-wrapper.mjs";
|
|
3
|
+
import { SOLIDITY_TYPES } from "./registry.mjs";
|
|
4
|
+
import { isSolidityTypeList, mapSolidityTypeToCEL } from "./conversion.mjs";
|
|
5
|
+
import { formatUnitsValue, parseUnitsValue } from "./units.mjs";
|
|
6
|
+
export { SOLIDITY_TYPES, SolidityAddressTypeWrapper, SolidityIntTypeWrapper, formatUnitsValue, isSolidityTypeList, mapSolidityTypeToCEL, parseUnitsValue, toAddress, toBigInt };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const require_solidity_address_type_wrapper = require("./custom-types/solidity-address-type-wrapper.cjs");
|
|
2
|
+
const require_solidity_int_type_wrapper = require("./custom-types/solidity-int-type-wrapper.cjs");
|
|
3
|
+
//#region src/registry.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates the list of Solidity bytes type aliases (bytes, bytes1, ..., bytes32).
|
|
6
|
+
*/
|
|
7
|
+
const generateBytesAliases = () => {
|
|
8
|
+
const aliases = ["bytes"];
|
|
9
|
+
for (let size = 1; size <= 32; size++) aliases.push(`bytes${String(size)}`);
|
|
10
|
+
return aliases;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Generates the list of Solidity int/uint type aliases (int, uint, int8, uint8, ..., int256, uint256).
|
|
14
|
+
*/
|
|
15
|
+
const generateIntAliases = () => {
|
|
16
|
+
const aliases = ["uint", "int"];
|
|
17
|
+
for (let size = 8; size <= 256; size += 8) aliases.push(`uint${String(size)}`);
|
|
18
|
+
for (let size = 8; size <= 256; size += 8) aliases.push(`int${String(size)}`);
|
|
19
|
+
return aliases;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The single source of truth for Solidity type identity in the CEL environment.
|
|
23
|
+
* Keyed by CEL type name.
|
|
24
|
+
*/
|
|
25
|
+
const SOLIDITY_TYPES = [
|
|
26
|
+
{
|
|
27
|
+
type: "builtin",
|
|
28
|
+
name: "bytes",
|
|
29
|
+
solidityAliases: generateBytesAliases()
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
type: "builtin",
|
|
33
|
+
name: "string",
|
|
34
|
+
solidityAliases: ["string"]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: "builtin",
|
|
38
|
+
name: "bool",
|
|
39
|
+
solidityAliases: ["bool"]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: "custom",
|
|
43
|
+
name: "sol_address",
|
|
44
|
+
solidityAliases: ["address"],
|
|
45
|
+
wrapperClass: require_solidity_address_type_wrapper.SolidityAddressTypeWrapper,
|
|
46
|
+
schema: {
|
|
47
|
+
kind: "primitive",
|
|
48
|
+
description: "20-byte Ethereum address"
|
|
49
|
+
},
|
|
50
|
+
castSignatures: ["solAddress(string): sol_address"]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "custom",
|
|
54
|
+
name: "sol_int",
|
|
55
|
+
solidityAliases: generateIntAliases(),
|
|
56
|
+
wrapperClass: require_solidity_int_type_wrapper.SolidityIntTypeWrapper,
|
|
57
|
+
schema: {
|
|
58
|
+
kind: "primitive",
|
|
59
|
+
description: "Arbitrary-size integer"
|
|
60
|
+
},
|
|
61
|
+
castSignatures: ["solInt(string): sol_int", "solInt(int): sol_int"]
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.SOLIDITY_TYPES = SOLIDITY_TYPES;
|