@seljs/types 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +190 -0
  3. package/README.md +5 -0
  4. package/dist/abstracts/index.d.ts +2 -0
  5. package/dist/abstracts/index.d.ts.map +1 -0
  6. package/dist/abstracts/index.js +1 -0
  7. package/dist/abstracts/type-wrapper.d.ts +13 -0
  8. package/dist/abstracts/type-wrapper.d.ts.map +1 -0
  9. package/dist/abstracts/type-wrapper.js +1 -0
  10. package/dist/context.d.ts +58 -0
  11. package/dist/context.d.ts.map +1 -0
  12. package/dist/context.js +1 -0
  13. package/dist/context.spec.d.ts +2 -0
  14. package/dist/context.spec.d.ts.map +1 -0
  15. package/dist/context.spec.js +38 -0
  16. package/dist/conversion.d.ts +13 -0
  17. package/dist/conversion.d.ts.map +1 -0
  18. package/dist/conversion.js +48 -0
  19. package/dist/conversion.spec.d.ts +2 -0
  20. package/dist/conversion.spec.d.ts.map +1 -0
  21. package/dist/conversion.spec.js +53 -0
  22. package/dist/custom-types/index.d.ts +3 -0
  23. package/dist/custom-types/index.d.ts.map +1 -0
  24. package/dist/custom-types/index.js +2 -0
  25. package/dist/custom-types/solidity-address-type-wrapper.d.ts +22 -0
  26. package/dist/custom-types/solidity-address-type-wrapper.d.ts.map +1 -0
  27. package/dist/custom-types/solidity-address-type-wrapper.js +40 -0
  28. package/dist/custom-types/solidity-int-type-wrapper.d.ts +19 -0
  29. package/dist/custom-types/solidity-int-type-wrapper.d.ts.map +1 -0
  30. package/dist/custom-types/solidity-int-type-wrapper.js +35 -0
  31. package/dist/index.d.ts +7 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +6 -0
  34. package/dist/registry.d.ts +26 -0
  35. package/dist/registry.d.ts.map +1 -0
  36. package/dist/registry.js +58 -0
  37. package/dist/registry.spec.d.ts +2 -0
  38. package/dist/registry.spec.d.ts.map +1 -0
  39. package/dist/registry.spec.js +57 -0
  40. package/dist/units.d.ts +15 -0
  41. package/dist/units.d.ts.map +1 -0
  42. package/dist/units.js +55 -0
  43. package/dist/units.spec.d.ts +2 -0
  44. package/dist/units.spec.d.ts.map +1 -0
  45. package/dist/units.spec.js +77 -0
  46. package/package.json +61 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2026-03-13)
4
+
5
+
6
+ ### Features
7
+
8
+ * first implementation of seljs ([7548fe0](https://github.com/abinnovision/seljs/commit/7548fe06cbb22ec6b74b20e38ef07d026b3f8def))
package/LICENSE.md ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 abi group GmbH
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # sel-types
2
+
3
+ Type primitives and type knowledge for the SEL system. Provides value wrappers for Solidity types, a type registry with identity data for the CEL environment, and mappings from Solidity type strings to CEL type names.
4
+
5
+ Zero external dependencies. Every other SEL package depends on this one.
@@ -0,0 +1,2 @@
1
+ export * from "./type-wrapper.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abstracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./type-wrapper.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Shared interface for Solidity wrapper types (UInt256, Int256, Address).
3
+ *
4
+ * These wrappers are registered on the CEL environment via `registerType` so
5
+ * that cel-js's constructor-based type matching (`objectTypesByConstructor`)
6
+ * can identify runtime values as custom Solidity types rather than native JS
7
+ * primitives (BigInt → "int", string → "string").
8
+ */
9
+ export interface TypeWrapper<T> {
10
+ readonly value: T;
11
+ valueOf: () => T;
12
+ }
13
+ //# sourceMappingURL=type-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-wrapper.d.ts","sourceRoot":"","sources":["../../src/abstracts/type-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC,CAAC;CACjB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Infers the TypeScript type for a CEL type string.
3
+ * Handles primitives and list<T>.
4
+ */
5
+ type InferCelType<T extends ContextCelType> = T extends `list<${infer E extends PrimitiveCelType}>` ? CelTypeToTs[E][] : T extends keyof CelTypeToTs ? CelTypeToTs[T] : never;
6
+ /**
7
+ * Resolves a ContextFieldDefinition to its ContextCelType.
8
+ */
9
+ type ResolveCelType<T extends ContextFieldDefinition> = T extends ContextCelType ? T : T extends {
10
+ type: infer U extends ContextCelType;
11
+ } ? U : never;
12
+ /**
13
+ * Primitive CEL types valid for user-defined context variables.
14
+ */
15
+ export type PrimitiveCelType = "sol_int" | "sol_address" | "bool" | "string" | "bytes";
16
+ /**
17
+ * All CEL types valid for user-defined context variables.
18
+ * Includes primitives and list<primitive>.
19
+ */
20
+ export type ContextCelType = PrimitiveCelType | `list<${PrimitiveCelType}>`;
21
+ /**
22
+ * Maps primitive CEL type names to their TypeScript representation.
23
+ */
24
+ export interface CelTypeToTs {
25
+ sol_int: bigint;
26
+ sol_address: `0x${string}`;
27
+ bool: boolean;
28
+ string: string;
29
+ bytes: string;
30
+ }
31
+ /**
32
+ * A context field can be a bare CEL type string or an object with type and description.
33
+ */
34
+ export type ContextFieldDefinition = ContextCelType | {
35
+ type: ContextCelType;
36
+ description: string;
37
+ };
38
+ /**
39
+ * Flat definition of context variables: key is the variable name, value is the CEL type or a typed object with description.
40
+ */
41
+ export type ContextDefinition = Record<string, ContextFieldDefinition>;
42
+ /**
43
+ * Infers the TypeScript type of context values from a ContextDefinition.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * type Ctx = InferContext<{ user: "sol_address"; amount: "sol_int" }>;
48
+ * // { user: `0x${string}`; amount: bigint }
49
+ *
50
+ * type CtxList = InferContext<{ addrs: "list<sol_address>" }>;
51
+ * // { addrs: `0x${string}`[] }
52
+ * ```
53
+ */
54
+ export type InferContext<T extends ContextDefinition> = {
55
+ [K in keyof T]: InferCelType<ResolveCelType<T[K]>>;
56
+ };
57
+ export {};
58
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,cAAc,IACzC,CAAC,SAAS,QAAQ,MAAM,CAAC,SAAS,gBAAgB,GAAG,GAClD,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS,MAAM,WAAW,GAC1B,WAAW,CAAC,CAAC,CAAC,GACd,KAAK,CAAC;AAEX;;GAEG;AACH,KAAK,cAAc,CAAC,CAAC,SAAS,sBAAsB,IAAI,CAAC,SAAS,cAAc,GAC7E,CAAC,GACD,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC,SAAS,cAAc,CAAA;CAAE,GACjD,CAAC,GACD,KAAK,CAAC;AAEV;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACzB,SAAS,GACT,aAAa,GACb,MAAM,GACN,QAAQ,GACR,OAAO,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,QAAQ,gBAAgB,GAAG,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC/B,cAAc,GACd;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,iBAAiB,IAAI;KACtD,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClD,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.spec.d.ts","sourceRoot":"","sources":["../src/context.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ import { describe, expectTypeOf, it } from "vitest";
2
+ describe("src/context.ts", () => {
3
+ describe("contextCelType", () => {
4
+ it("accepts primitive types", () => {
5
+ expectTypeOf().toExtend();
6
+ expectTypeOf().toExtend();
7
+ expectTypeOf().toExtend();
8
+ expectTypeOf().toExtend();
9
+ expectTypeOf().toExtend();
10
+ });
11
+ it("accepts list<primitive> types", () => {
12
+ expectTypeOf().toExtend();
13
+ expectTypeOf().toExtend();
14
+ expectTypeOf().toExtend();
15
+ expectTypeOf().toExtend();
16
+ expectTypeOf().toExtend();
17
+ });
18
+ it("rejects invalid types", () => {
19
+ expectTypeOf().not.toExtend();
20
+ expectTypeOf().not.toExtend();
21
+ expectTypeOf().not.toExtend();
22
+ });
23
+ });
24
+ describe("inferContext", () => {
25
+ it("infers primitive types", () => {
26
+ expectTypeOf().toEqualTypeOf();
27
+ });
28
+ it("infers list types", () => {
29
+ expectTypeOf().toEqualTypeOf();
30
+ });
31
+ it("infers list<bool> type", () => {
32
+ expectTypeOf().toEqualTypeOf();
33
+ });
34
+ it("infers types with description objects", () => {
35
+ expectTypeOf().toEqualTypeOf();
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Maps a raw Solidity type string to its corresponding CEL type.
3
+ *
4
+ * @param input The raw Solidity type string (e.g. "uint256", "address", "bool")
5
+ * @return The corresponding CEL type name, or null if the type is not recognized
6
+ */
7
+ export declare const mapSolidityTypeToCEL: (input: string) => string | null;
8
+ /**
9
+ * Checks if a given Solidity type string represents a list type (e.g. "uint256[]", "address[5]").
10
+ * @param input
11
+ */
12
+ export declare const isSolidityTypeList: (input: string) => boolean;
13
+ //# sourceMappingURL=conversion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,IAuB7D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,OAElD,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { SOLIDITY_TYPES } from "./registry.js";
2
+ const LIST_REGEX = /^(.*)(\[\d*\])$/;
3
+ /**
4
+ * Checks if a Solidity type string represents a list type (e.g. "uint256[]", "address[5]") and extracts the base type.
5
+ *
6
+ * @param input Solidity type string to check (e.g. "uint256[]", "address[5]", "bool")
7
+ * @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
8
+ */
9
+ const tryListMatch = (input) => {
10
+ const match = input.match(LIST_REGEX);
11
+ if (match) {
12
+ return match[1] ?? null;
13
+ }
14
+ return null;
15
+ };
16
+ /**
17
+ * Maps a raw Solidity type string to its corresponding CEL type.
18
+ *
19
+ * @param input The raw Solidity type string (e.g. "uint256", "address", "bool")
20
+ * @return The corresponding CEL type name, or null if the type is not recognized
21
+ */
22
+ export const mapSolidityTypeToCEL = (input) => {
23
+ // First check if the input type represents a list type.
24
+ const listBaseType = tryListMatch(input);
25
+ if (listBaseType) {
26
+ // Make a recursive call into this function to resolve the base type of the list.
27
+ const celBaseType = mapSolidityTypeToCEL(listBaseType);
28
+ if (celBaseType) {
29
+ return `list<${celBaseType}>`;
30
+ }
31
+ }
32
+ else {
33
+ // Go through the registry and check all the aliases for each registered type to see if any of them match the input type string.
34
+ const aliasedType = SOLIDITY_TYPES.find((type) => type.solidityAliases.includes(input));
35
+ if (aliasedType) {
36
+ return aliasedType.name;
37
+ }
38
+ }
39
+ // Return null if there is no match.
40
+ return null;
41
+ };
42
+ /**
43
+ * Checks if a given Solidity type string represents a list type (e.g. "uint256[]", "address[5]").
44
+ * @param input
45
+ */
46
+ export const isSolidityTypeList = (input) => {
47
+ return tryListMatch(input) !== null;
48
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=conversion.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversion.spec.d.ts","sourceRoot":"","sources":["../src/conversion.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,53 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { isSolidityTypeList, mapSolidityTypeToCEL } from "./conversion.js";
3
+ describe("src/conversion.ts", () => {
4
+ describe("mapSolidityTypeToCEL", () => {
5
+ it.each([
6
+ // Integer types
7
+ ["uint256", "sol_int"],
8
+ ["uint8", "sol_int"],
9
+ ["uint128", "sol_int"],
10
+ ["uint", "sol_int"],
11
+ ["int256", "sol_int"],
12
+ ["int8", "sol_int"],
13
+ ["int", "sol_int"],
14
+ // Address
15
+ ["address", "sol_address"],
16
+ // Builtins
17
+ ["bool", "bool"],
18
+ ["string", "string"],
19
+ // Bytes
20
+ ["bytes", "bytes"],
21
+ ["bytes1", "bytes"],
22
+ ["bytes20", "bytes"],
23
+ ["bytes32", "bytes"],
24
+ // Arrays
25
+ ["uint256[]", "list<sol_int>"],
26
+ ["address[]", "list<sol_address>"],
27
+ ["bool[]", "list<bool>"],
28
+ ["uint256[5]", "list<sol_int>"],
29
+ ["bytes32[]", "list<bytes>"],
30
+ ["uint256[][]", "list<list<sol_int>>"],
31
+ // Unrecognized / not sel-types concern
32
+ ["tuple", null],
33
+ ["unknown", null],
34
+ ["", null],
35
+ ["uint512", null],
36
+ ["bytes33", null],
37
+ ])("maps %j → %j", (input, expected) => {
38
+ expect(mapSolidityTypeToCEL(input)).toBe(expected);
39
+ });
40
+ });
41
+ describe("isSolidityTypeList", () => {
42
+ it.each([
43
+ ["uint256[]", true],
44
+ ["uint256[5]", true],
45
+ ["uint256[][]", true],
46
+ ["uint256", false],
47
+ ["address", false],
48
+ ["tuple", false],
49
+ ])("isSolidityTypeList(%j) → %j", (input, expected) => {
50
+ expect(isSolidityTypeList(input)).toBe(expected);
51
+ });
52
+ });
53
+ });
@@ -0,0 +1,3 @@
1
+ export * from "./solidity-address-type-wrapper.js";
2
+ export * from "./solidity-int-type-wrapper.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/custom-types/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./solidity-address-type-wrapper.js";
2
+ export * from "./solidity-int-type-wrapper.js";
@@ -0,0 +1,22 @@
1
+ import type { TypeWrapper } from "../abstracts/index.js";
2
+ /**
3
+ * Convert a value to a valid Ethereum address string.
4
+ *
5
+ * @param value
6
+ */
7
+ export declare const toAddress: (value: unknown) => string;
8
+ /**
9
+ * Ethereum address wrapper with regex-based validation.
10
+ * Normalizes to lowercase (no viem dependency).
11
+ */
12
+ export declare class SolidityAddressTypeWrapper implements TypeWrapper<string> {
13
+ readonly value: string;
14
+ constructor(value: unknown);
15
+ /**
16
+ * Check whether a string is a valid 20-byte hex address.
17
+ */
18
+ static isValid(value: string): boolean;
19
+ toString(): string;
20
+ valueOf(): string;
21
+ }
22
+ //# sourceMappingURL=solidity-address-type-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solidity-address-type-wrapper.d.ts","sourceRoot":"","sources":["../../src/custom-types/solidity-address-type-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIzD;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,MAc1C,CAAC;AAEF;;;GAGG;AACH,qBAAa,0BAA2B,YAAW,WAAW,CAAC,MAAM,CAAC;IACrE,SAAgB,KAAK,EAAE,MAAM,CAAC;gBAEX,KAAK,EAAE,OAAO;IAIjC;;OAEG;WACW,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAItC,QAAQ,IAAI,MAAM;IAIlB,OAAO,IAAI,MAAM;CAGxB"}
@@ -0,0 +1,40 @@
1
+ const ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
2
+ /**
3
+ * Convert a value to a valid Ethereum address string.
4
+ *
5
+ * @param value
6
+ */
7
+ export const toAddress = (value) => {
8
+ if (value instanceof SolidityAddressTypeWrapper) {
9
+ return value.value;
10
+ }
11
+ if (typeof value !== "string") {
12
+ throw new TypeError(`Invalid address value: ${String(value)}`);
13
+ }
14
+ if (!SolidityAddressTypeWrapper.isValid(value)) {
15
+ throw new TypeError(`Invalid address value: ${value}`);
16
+ }
17
+ return value.toLowerCase();
18
+ };
19
+ /**
20
+ * Ethereum address wrapper with regex-based validation.
21
+ * Normalizes to lowercase (no viem dependency).
22
+ */
23
+ export class SolidityAddressTypeWrapper {
24
+ value;
25
+ constructor(value) {
26
+ this.value = toAddress(value);
27
+ }
28
+ /**
29
+ * Check whether a string is a valid 20-byte hex address.
30
+ */
31
+ static isValid(value) {
32
+ return ADDRESS_REGEX.test(value);
33
+ }
34
+ toString() {
35
+ return this.value;
36
+ }
37
+ valueOf() {
38
+ return this.value;
39
+ }
40
+ }
@@ -0,0 +1,19 @@
1
+ import type { TypeWrapper } from "../abstracts/index.js";
2
+ /**
3
+ * Convert any BigInt-compatible value to a native bigint.
4
+ * Handles SolidityIntTypeWrapper instances, bigint literals, integer numbers, and numeric strings.
5
+ */
6
+ export declare function toBigInt(value: unknown): bigint;
7
+ /**
8
+ * Unified Solidity integer wrapper for the CEL runtime.
9
+ *
10
+ * Wraps all Solidity integer types (uint8–uint256, int8–int256) as a single
11
+ * CEL custom type backed by native BigInt. This bypasses cel-js's built-in
12
+ * "int" type which enforces 64-bit overflow checks.
13
+ */
14
+ export declare class SolidityIntTypeWrapper implements TypeWrapper<bigint> {
15
+ readonly value: bigint;
16
+ constructor(value: unknown);
17
+ valueOf(): bigint;
18
+ }
19
+ //# sourceMappingURL=solidity-int-type-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solidity-int-type-wrapper.d.ts","sourceRoot":"","sources":["../../src/custom-types/solidity-int-type-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkB/C;AAED;;;;;;GAMG;AACH,qBAAa,sBAAuB,YAAW,WAAW,CAAC,MAAM,CAAC;IACjE,SAAgB,KAAK,EAAE,MAAM,CAAC;gBAEX,KAAK,EAAE,OAAO;IAI1B,OAAO,IAAI,MAAM;CAGxB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Convert any BigInt-compatible value to a native bigint.
3
+ * Handles SolidityIntTypeWrapper instances, bigint literals, integer numbers, and numeric strings.
4
+ */
5
+ export function toBigInt(value) {
6
+ if (value instanceof SolidityIntTypeWrapper) {
7
+ return value.value;
8
+ }
9
+ if (typeof value === "bigint") {
10
+ return value;
11
+ }
12
+ if (typeof value === "number" && Number.isInteger(value)) {
13
+ return BigInt(value);
14
+ }
15
+ if (typeof value === "string") {
16
+ return BigInt(value);
17
+ }
18
+ throw new TypeError(`Invalid integer value: ${String(value)}`);
19
+ }
20
+ /**
21
+ * Unified Solidity integer wrapper for the CEL runtime.
22
+ *
23
+ * Wraps all Solidity integer types (uint8–uint256, int8–int256) as a single
24
+ * CEL custom type backed by native BigInt. This bypasses cel-js's built-in
25
+ * "int" type which enforces 64-bit overflow checks.
26
+ */
27
+ export class SolidityIntTypeWrapper {
28
+ value;
29
+ constructor(value) {
30
+ this.value = toBigInt(value);
31
+ }
32
+ valueOf() {
33
+ return this.value;
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./abstracts/index.js";
2
+ export * from "./custom-types/index.js";
3
+ export * from "./registry.js";
4
+ export * from "./conversion.js";
5
+ export * from "./units.js";
6
+ export * from "./context.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./abstracts/index.js";
2
+ export * from "./custom-types/index.js";
3
+ export * from "./registry.js";
4
+ export * from "./conversion.js";
5
+ export * from "./units.js";
6
+ export * from "./context.js";
@@ -0,0 +1,26 @@
1
+ import type { TypeWrapper } from "./abstracts/index.js";
2
+ import type { AbiType } from "abitype";
3
+ /**
4
+ * Unified representation of Solidity type identity in the CEL environment.
5
+ */
6
+ type SolidityTypeIdentity = {
7
+ name: string;
8
+ solidityAliases: readonly AbiType[];
9
+ } & ({
10
+ type: "builtin";
11
+ } | {
12
+ type: "custom";
13
+ schema: {
14
+ kind: "primitive";
15
+ description: string;
16
+ };
17
+ wrapperClass: new (value: unknown) => TypeWrapper<unknown>;
18
+ castSignatures: readonly string[];
19
+ });
20
+ /**
21
+ * The single source of truth for Solidity type identity in the CEL environment.
22
+ * Keyed by CEL type name.
23
+ */
24
+ export declare const SOLIDITY_TYPES: SolidityTypeIdentity[];
25
+ export {};
26
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAA8B,MAAM,SAAS,CAAC;AAEnE;;GAEG;AACH,KAAK,oBAAoB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,SAAS,OAAO,EAAE,CAAC;CACpC,GAAG,CACD;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,YAAY,EAAE,KAAK,KAAK,EAAE,OAAO,KAAK,WAAW,CAAC,OAAO,CAAC,CAAC;IAC3D,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC,CACH,CAAC;AAmCF;;;GAGG;AACH,eAAO,MAAM,cAAc,EA4BW,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { SolidityAddressTypeWrapper, SolidityIntTypeWrapper, } from "./custom-types/index.js";
2
+ /**
3
+ * Generates the list of Solidity bytes type aliases (bytes, bytes1, ..., bytes32).
4
+ */
5
+ const generateBytesAliases = () => {
6
+ const aliases = ["bytes"];
7
+ // Generate bytes1 to bytes32 aliases.
8
+ for (let size = 1; size <= 32; size++) {
9
+ aliases.push(`bytes${String(size)}`);
10
+ }
11
+ return aliases;
12
+ };
13
+ /**
14
+ * Generates the list of Solidity int/uint type aliases (int, uint, int8, uint8, ..., int256, uint256).
15
+ */
16
+ const generateIntAliases = () => {
17
+ const aliases = ["uint", "int"];
18
+ // Generate uint8 to uint256 aliases (including "uint" as alias for "uint256").
19
+ for (let size = 8; size <= 256; size += 8) {
20
+ aliases.push(`uint${String(size)}`);
21
+ }
22
+ // Generate int8 to int256 aliases (including "int" as alias for "int256").
23
+ for (let size = 8; size <= 256; size += 8) {
24
+ aliases.push(`int${String(size)}`);
25
+ }
26
+ return aliases;
27
+ };
28
+ /**
29
+ * The single source of truth for Solidity type identity in the CEL environment.
30
+ * Keyed by CEL type name.
31
+ */
32
+ export const SOLIDITY_TYPES = [
33
+ /*
34
+ * - Byte types: bytes, bytes1-bytes32 → "bytes"
35
+ * This maps all byte array types to a single "bytes" CEL type.
36
+ */
37
+ { type: "builtin", name: "bytes", solidityAliases: generateBytesAliases() },
38
+ { type: "builtin", name: "string", solidityAliases: ["string"] },
39
+ { type: "builtin", name: "bool", solidityAliases: ["bool"] },
40
+ // - Address type: address → "sol_address"
41
+ {
42
+ type: "custom",
43
+ name: "sol_address",
44
+ solidityAliases: ["address"],
45
+ wrapperClass: SolidityAddressTypeWrapper,
46
+ schema: { kind: "primitive", description: "20-byte Ethereum address" },
47
+ castSignatures: ["solAddress(string): sol_address"],
48
+ },
49
+ // - Integer types: sol_int
50
+ {
51
+ type: "custom",
52
+ name: "sol_int",
53
+ solidityAliases: generateIntAliases(),
54
+ wrapperClass: SolidityIntTypeWrapper,
55
+ schema: { kind: "primitive", description: "Arbitrary-size integer" },
56
+ castSignatures: ["solInt(string): sol_int", "solInt(int): sol_int"],
57
+ },
58
+ ];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=registry.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.spec.d.ts","sourceRoot":"","sources":["../src/registry.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { SolidityAddressTypeWrapper, SolidityIntTypeWrapper, } from "./custom-types/index.js";
3
+ import { SOLIDITY_TYPES } from "./registry.js";
4
+ describe("src/registry.ts", () => {
5
+ const findByName = (name) => SOLIDITY_TYPES.find((t) => t.name === name);
6
+ describe("registered types", () => {
7
+ it.each(["bytes", "string", "bool", "sol_address", "sol_int"])("has %j registered", (name) => {
8
+ expect(findByName(name)).toBeDefined();
9
+ });
10
+ });
11
+ describe("builtins", () => {
12
+ it.each([
13
+ ["bytes", "builtin"],
14
+ ["string", "builtin"],
15
+ ["bool", "builtin"],
16
+ ])("%j is type %j", (name, expectedType) => {
17
+ expect(findByName(name)?.type).toBe(expectedType);
18
+ });
19
+ });
20
+ describe("custom types", () => {
21
+ it.each([
22
+ ["sol_address", SolidityAddressTypeWrapper],
23
+ ["sol_int", SolidityIntTypeWrapper],
24
+ ])("%j has wrapperClass", (name, expectedClass) => {
25
+ const entry = findByName(name);
26
+ expect(entry?.type).toBe("custom");
27
+ expect(entry.wrapperClass).toBe(expectedClass);
28
+ });
29
+ });
30
+ describe("bytes aliases", () => {
31
+ const bytesEntry = findByName("bytes");
32
+ it("includes dynamic bytes", () => {
33
+ expect(bytesEntry?.solidityAliases).toContain("bytes");
34
+ });
35
+ it.each(["bytes1", "bytes16", "bytes32"])("includes %j", (alias) => {
36
+ expect(bytesEntry?.solidityAliases).toContain(alias);
37
+ });
38
+ it("has 33 aliases (bytes + bytes1..bytes32)", () => {
39
+ expect(bytesEntry?.solidityAliases).toHaveLength(33);
40
+ });
41
+ });
42
+ describe("int aliases", () => {
43
+ const intEntry = findByName("sol_int");
44
+ it.each(["uint", "int", "uint8", "int8", "uint256", "int256"])("includes %j", (alias) => {
45
+ expect(intEntry?.solidityAliases).toContain(alias);
46
+ });
47
+ it("has 66 aliases (uint + int + uint8..uint256 + int8..int256)", () => {
48
+ // 2 bare aliases + 32 uint sizes + 32 int sizes = 66
49
+ expect(intEntry?.solidityAliases).toHaveLength(66);
50
+ });
51
+ });
52
+ describe("address aliases", () => {
53
+ it("has only 'address'", () => {
54
+ expect(findByName("sol_address")?.solidityAliases).toEqual(["address"]);
55
+ });
56
+ });
57
+ });
@@ -0,0 +1,15 @@
1
+ import { SolidityIntTypeWrapper } from "./custom-types/index.js";
2
+ /**
3
+ * Parse a human-readable value into a scaled sol_int.
4
+ * Mirrors viem/ethers parseUnits behavior.
5
+ *
6
+ * Accepts: bigint, number (int or float), string (decimal notation), SolidityIntTypeWrapper.
7
+ * Floats are converted to string first to avoid floating-point math.
8
+ */
9
+ export declare const parseUnitsValue: (value: unknown, decimals: number) => SolidityIntTypeWrapper;
10
+ /**
11
+ * Format a sol_int value into a human-readable double.
12
+ * Mirrors viem/ethers formatUnits behavior.
13
+ */
14
+ export declare const formatUnitsValue: (value: unknown, decimals: number) => number;
15
+ //# sourceMappingURL=units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../src/units.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAY,MAAM,yBAAyB,CAAC;AAkC3E;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC3B,OAAO,OAAO,EACd,UAAU,MAAM,KACd,sBAwBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,EAAE,UAAU,MAAM,KAAG,MAOnE,CAAC"}
package/dist/units.js ADDED
@@ -0,0 +1,55 @@
1
+ import { SolidityIntTypeWrapper, toBigInt } from "./custom-types/index.js";
2
+ const parseDecimalString = (value, decimals, scale) => {
3
+ const negative = value.startsWith("-");
4
+ const abs = negative ? value.slice(1) : value;
5
+ const parts = abs.split(".");
6
+ if (parts.length > 2) {
7
+ throw new TypeError(`parseUnits: invalid decimal string: "${value}"`);
8
+ }
9
+ const wholePart = parts[0] ?? "0";
10
+ const fracPart = parts[1] ?? "";
11
+ if (fracPart.length > decimals) {
12
+ throw new TypeError(`parseUnits: fractional part "${fracPart}" exceeds ${String(decimals)} decimals`);
13
+ }
14
+ const whole = BigInt(wholePart) * scale;
15
+ const frac = fracPart.length > 0 ? BigInt(fracPart.padEnd(decimals, "0")) : 0n;
16
+ const result = whole + frac;
17
+ return new SolidityIntTypeWrapper(negative ? -result : result);
18
+ };
19
+ /**
20
+ * Parse a human-readable value into a scaled sol_int.
21
+ * Mirrors viem/ethers parseUnits behavior.
22
+ *
23
+ * Accepts: bigint, number (int or float), string (decimal notation), SolidityIntTypeWrapper.
24
+ * Floats are converted to string first to avoid floating-point math.
25
+ */
26
+ export const parseUnitsValue = (value, decimals) => {
27
+ const scale = 10n ** BigInt(decimals);
28
+ if (value instanceof SolidityIntTypeWrapper) {
29
+ return new SolidityIntTypeWrapper(value.value * scale);
30
+ }
31
+ if (typeof value === "bigint") {
32
+ return new SolidityIntTypeWrapper(value * scale);
33
+ }
34
+ if (typeof value === "number") {
35
+ if (Number.isInteger(value)) {
36
+ return new SolidityIntTypeWrapper(BigInt(value) * scale);
37
+ }
38
+ return parseUnitsValue(String(value), decimals);
39
+ }
40
+ if (typeof value === "string") {
41
+ return parseDecimalString(value, decimals, scale);
42
+ }
43
+ throw new TypeError(`parseUnits: unsupported value type: ${typeof value}`);
44
+ };
45
+ /**
46
+ * Format a sol_int value into a human-readable double.
47
+ * Mirrors viem/ethers formatUnits behavior.
48
+ */
49
+ export const formatUnitsValue = (value, decimals) => {
50
+ const raw = toBigInt(value);
51
+ const scale = 10n ** BigInt(decimals);
52
+ const whole = raw / scale;
53
+ const remainder = raw % scale;
54
+ return Number(whole) + Number(remainder) / Number(scale);
55
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=units.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.spec.d.ts","sourceRoot":"","sources":["../src/units.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,77 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { SolidityIntTypeWrapper } from "./custom-types/index.js";
3
+ import { parseUnitsValue, formatUnitsValue } from "./units.js";
4
+ describe("parseUnitsValue", () => {
5
+ it("scales a bigint by decimals", () => {
6
+ expect(parseUnitsValue(1000n, 6)).toEqual(new SolidityIntTypeWrapper(1000000000n));
7
+ });
8
+ it("scales an integer number by decimals", () => {
9
+ expect(parseUnitsValue(1000, 6)).toEqual(new SolidityIntTypeWrapper(1000000000n));
10
+ });
11
+ it("parses a decimal string", () => {
12
+ expect(parseUnitsValue("1.5", 18)).toEqual(new SolidityIntTypeWrapper(1500000000000000000n));
13
+ });
14
+ it("parses a whole-number string", () => {
15
+ expect(parseUnitsValue("1000", 6)).toEqual(new SolidityIntTypeWrapper(1000000000n));
16
+ });
17
+ it("parses a string with trailing zeros in fraction", () => {
18
+ expect(parseUnitsValue("1.50", 18)).toEqual(new SolidityIntTypeWrapper(1500000000000000000n));
19
+ });
20
+ it("handles zero values", () => {
21
+ expect(parseUnitsValue(0, 18)).toEqual(new SolidityIntTypeWrapper(0n));
22
+ expect(parseUnitsValue("0", 18)).toEqual(new SolidityIntTypeWrapper(0n));
23
+ expect(parseUnitsValue("0.0", 18)).toEqual(new SolidityIntTypeWrapper(0n));
24
+ });
25
+ it("handles double input by converting to string first", () => {
26
+ expect(parseUnitsValue(1.5, 18)).toEqual(new SolidityIntTypeWrapper(1500000000000000000n));
27
+ });
28
+ it("handles SolidityIntTypeWrapper input", () => {
29
+ const input = new SolidityIntTypeWrapper(1000n);
30
+ expect(parseUnitsValue(input, 6)).toEqual(new SolidityIntTypeWrapper(1000000000n));
31
+ });
32
+ it("throws when fractional part exceeds decimals", () => {
33
+ expect(() => parseUnitsValue("1.1234567", 6)).toThrow("exceeds");
34
+ });
35
+ it("handles zero decimals with integer", () => {
36
+ expect(parseUnitsValue(1000, 0)).toEqual(new SolidityIntTypeWrapper(1000n));
37
+ });
38
+ it("throws for zero decimals with fractional string", () => {
39
+ expect(() => parseUnitsValue("1.5", 0)).toThrow("exceeds");
40
+ });
41
+ it("throws for unsupported types", () => {
42
+ expect(() => parseUnitsValue(true, 6)).toThrow("unsupported");
43
+ });
44
+ it("throws for invalid decimal string", () => {
45
+ expect(() => parseUnitsValue("1.2.3", 6)).toThrow("invalid");
46
+ });
47
+ it("parses a negative decimal string", () => {
48
+ expect(parseUnitsValue("-1.5", 18)).toEqual(new SolidityIntTypeWrapper(-1500000000000000000n));
49
+ });
50
+ it("parses a negative whole-number string", () => {
51
+ expect(parseUnitsValue("-1000", 6)).toEqual(new SolidityIntTypeWrapper(-1000000000n));
52
+ });
53
+ it("parses a negative double input", () => {
54
+ expect(parseUnitsValue(-1.5, 18)).toEqual(new SolidityIntTypeWrapper(-1500000000000000000n));
55
+ });
56
+ it("handles negative bigint input", () => {
57
+ expect(parseUnitsValue(-1000n, 6)).toEqual(new SolidityIntTypeWrapper(-1000000000n));
58
+ });
59
+ });
60
+ describe("formatUnitsValue", () => {
61
+ it("formats a bigint with decimals", () => {
62
+ expect(formatUnitsValue(1000000000n, 6)).toBe(1000);
63
+ });
64
+ it("formats a fractional result", () => {
65
+ expect(formatUnitsValue(1500000000000000000n, 18)).toBe(1.5);
66
+ });
67
+ it("formats zero", () => {
68
+ expect(formatUnitsValue(0n, 18)).toBe(0);
69
+ });
70
+ it("formats a SolidityIntTypeWrapper", () => {
71
+ const input = new SolidityIntTypeWrapper(1000000n);
72
+ expect(formatUnitsValue(input, 6)).toBe(1);
73
+ });
74
+ it("handles zero decimals", () => {
75
+ expect(formatUnitsValue(1000n, 0)).toBe(1000);
76
+ });
77
+ });
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@seljs/types",
3
+ "version": "1.0.0",
4
+ "license": "Apache-2.0",
5
+ "author": {
6
+ "name": "abi group GmbH",
7
+ "email": "info@abigroup.io",
8
+ "url": "https://abigroup.io/"
9
+ },
10
+ "repository": {
11
+ "url": "https://github.com/abinnovision/seljs"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/index.d.ts",
22
+ "files": [
23
+ "dist",
24
+ "LICENSE.md"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc -p tsconfig.build.json",
28
+ "format:check": "prettier --check '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
29
+ "format:fix": "prettier --write '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
30
+ "lint:check": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}'",
31
+ "lint:fix": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}' --fix",
32
+ "test-unit": "vitest run",
33
+ "test-unit:watch": "vitest watch",
34
+ "typecheck": "tsc --noEmit"
35
+ },
36
+ "lint-staged": {
37
+ "{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}": [
38
+ "prettier --write"
39
+ ],
40
+ "{{src,test}/**/*,*}.{t,j}s{,x}": [
41
+ "eslint --fix"
42
+ ]
43
+ },
44
+ "dependencies": {
45
+ "@seljs/common": "1.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@abinnovision/eslint-config-base": "^3.2.0",
49
+ "@abinnovision/prettier-config": "^2.1.5",
50
+ "@seljs-internal/tsconfig": "^0.0.0",
51
+ "abitype": "^1.2.3",
52
+ "eslint": "^9.39.4",
53
+ "prettier": "^3.8.1",
54
+ "typescript": "^5.9.3",
55
+ "vitest": "^4.0.18"
56
+ },
57
+ "publishConfig": {
58
+ "npm": true,
59
+ "npmAccess": "public"
60
+ }
61
+ }