@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.
Files changed (67) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/abstracts/{type-wrapper.d.ts → type-wrapper.d.cts} +6 -4
  3. package/dist/abstracts/type-wrapper.d.mts +15 -0
  4. package/dist/{context.d.ts → context.d.cts} +17 -18
  5. package/dist/context.d.mts +57 -0
  6. package/dist/conversion.cjs +41 -0
  7. package/dist/{conversion.d.ts → conversion.d.cts} +5 -3
  8. package/dist/conversion.d.mts +15 -0
  9. package/dist/conversion.mjs +40 -0
  10. package/dist/custom-types/solidity-address-type-wrapper.cjs +38 -0
  11. package/dist/custom-types/solidity-address-type-wrapper.d.cts +25 -0
  12. package/dist/custom-types/solidity-address-type-wrapper.d.mts +25 -0
  13. package/dist/custom-types/solidity-address-type-wrapper.mjs +37 -0
  14. package/dist/custom-types/solidity-int-type-wrapper.cjs +31 -0
  15. package/dist/custom-types/{solidity-int-type-wrapper.d.ts → solidity-int-type-wrapper.d.cts} +10 -7
  16. package/dist/custom-types/solidity-int-type-wrapper.d.mts +22 -0
  17. package/dist/custom-types/solidity-int-type-wrapper.mjs +30 -0
  18. package/dist/index.cjs +15 -0
  19. package/dist/index.d.cts +8 -0
  20. package/dist/index.d.mts +8 -0
  21. package/dist/index.mjs +6 -0
  22. package/dist/registry.cjs +65 -0
  23. package/dist/registry.d.cts +28 -0
  24. package/dist/registry.d.mts +28 -0
  25. package/dist/registry.mjs +65 -0
  26. package/dist/units.cjs +44 -0
  27. package/dist/{units.d.ts → units.d.cts} +7 -4
  28. package/dist/units.d.mts +18 -0
  29. package/dist/units.mjs +43 -0
  30. package/package.json +17 -10
  31. package/dist/abstracts/index.d.ts +0 -2
  32. package/dist/abstracts/index.d.ts.map +0 -1
  33. package/dist/abstracts/index.js +0 -1
  34. package/dist/abstracts/type-wrapper.d.ts.map +0 -1
  35. package/dist/abstracts/type-wrapper.js +0 -1
  36. package/dist/context.d.ts.map +0 -1
  37. package/dist/context.js +0 -1
  38. package/dist/context.spec.d.ts +0 -2
  39. package/dist/context.spec.d.ts.map +0 -1
  40. package/dist/context.spec.js +0 -38
  41. package/dist/conversion.d.ts.map +0 -1
  42. package/dist/conversion.js +0 -48
  43. package/dist/conversion.spec.d.ts +0 -2
  44. package/dist/conversion.spec.d.ts.map +0 -1
  45. package/dist/conversion.spec.js +0 -53
  46. package/dist/custom-types/index.d.ts +0 -3
  47. package/dist/custom-types/index.d.ts.map +0 -1
  48. package/dist/custom-types/index.js +0 -2
  49. package/dist/custom-types/solidity-address-type-wrapper.d.ts +0 -22
  50. package/dist/custom-types/solidity-address-type-wrapper.d.ts.map +0 -1
  51. package/dist/custom-types/solidity-address-type-wrapper.js +0 -40
  52. package/dist/custom-types/solidity-int-type-wrapper.d.ts.map +0 -1
  53. package/dist/custom-types/solidity-int-type-wrapper.js +0 -35
  54. package/dist/index.d.ts +0 -7
  55. package/dist/index.d.ts.map +0 -1
  56. package/dist/index.js +0 -6
  57. package/dist/registry.d.ts +0 -26
  58. package/dist/registry.d.ts.map +0 -1
  59. package/dist/registry.js +0 -58
  60. package/dist/registry.spec.d.ts +0 -2
  61. package/dist/registry.spec.d.ts.map +0 -1
  62. package/dist/registry.spec.js +0 -57
  63. package/dist/units.d.ts.map +0 -1
  64. package/dist/units.js +0 -55
  65. package/dist/units.spec.d.ts +0 -2
  66. package/dist/units.spec.d.ts.map +0 -1
  67. package/dist/units.spec.js +0 -77
@@ -0,0 +1,28 @@
1
+ import { TypeWrapper } from "./abstracts/type-wrapper.cjs";
2
+ import { AbiType } from "abitype";
3
+
4
+ //#region src/registry.d.ts
5
+ /**
6
+ * Unified representation of Solidity type identity in the CEL environment.
7
+ */
8
+ type SolidityTypeIdentity = {
9
+ name: string;
10
+ solidityAliases: readonly AbiType[];
11
+ } & ({
12
+ type: "builtin";
13
+ } | {
14
+ type: "custom";
15
+ schema: {
16
+ kind: "primitive";
17
+ description: string;
18
+ };
19
+ wrapperClass: new (value: unknown) => TypeWrapper<unknown>;
20
+ castSignatures: readonly string[];
21
+ });
22
+ /**
23
+ * The single source of truth for Solidity type identity in the CEL environment.
24
+ * Keyed by CEL type name.
25
+ */
26
+ declare const SOLIDITY_TYPES: SolidityTypeIdentity[];
27
+ //#endregion
28
+ export { SOLIDITY_TYPES };
@@ -0,0 +1,28 @@
1
+ import { TypeWrapper } from "./abstracts/type-wrapper.mjs";
2
+ import { AbiType } from "abitype";
3
+
4
+ //#region src/registry.d.ts
5
+ /**
6
+ * Unified representation of Solidity type identity in the CEL environment.
7
+ */
8
+ type SolidityTypeIdentity = {
9
+ name: string;
10
+ solidityAliases: readonly AbiType[];
11
+ } & ({
12
+ type: "builtin";
13
+ } | {
14
+ type: "custom";
15
+ schema: {
16
+ kind: "primitive";
17
+ description: string;
18
+ };
19
+ wrapperClass: new (value: unknown) => TypeWrapper<unknown>;
20
+ castSignatures: readonly string[];
21
+ });
22
+ /**
23
+ * The single source of truth for Solidity type identity in the CEL environment.
24
+ * Keyed by CEL type name.
25
+ */
26
+ declare const SOLIDITY_TYPES: SolidityTypeIdentity[];
27
+ //#endregion
28
+ export { SOLIDITY_TYPES };
@@ -0,0 +1,65 @@
1
+ import { SolidityAddressTypeWrapper } from "./custom-types/solidity-address-type-wrapper.mjs";
2
+ import { SolidityIntTypeWrapper } from "./custom-types/solidity-int-type-wrapper.mjs";
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: 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: 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
+ export { SOLIDITY_TYPES };
package/dist/units.cjs ADDED
@@ -0,0 +1,44 @@
1
+ const require_solidity_int_type_wrapper = require("./custom-types/solidity-int-type-wrapper.cjs");
2
+ //#region src/units.ts
3
+ const parseDecimalString = (value, decimals, scale) => {
4
+ const negative = value.startsWith("-");
5
+ const parts = (negative ? value.slice(1) : value).split(".");
6
+ if (parts.length > 2) throw new TypeError(`parseUnits: invalid decimal string: "${value}"`);
7
+ const wholePart = parts[0] ?? "0";
8
+ const fracPart = parts[1] ?? "";
9
+ if (fracPart.length > decimals) throw new TypeError(`parseUnits: fractional part "${fracPart}" exceeds ${String(decimals)} decimals`);
10
+ const result = BigInt(wholePart) * scale + (fracPart.length > 0 ? BigInt(fracPart.padEnd(decimals, "0")) : 0n);
11
+ return new require_solidity_int_type_wrapper.SolidityIntTypeWrapper(negative ? -result : result);
12
+ };
13
+ /**
14
+ * Parse a human-readable value into a scaled sol_int.
15
+ * Mirrors viem/ethers parseUnits behavior.
16
+ *
17
+ * Accepts: bigint, number (int or float), string (decimal notation), SolidityIntTypeWrapper.
18
+ * Floats are converted to string first to avoid floating-point math.
19
+ */
20
+ const parseUnitsValue = (value, decimals) => {
21
+ const scale = 10n ** BigInt(decimals);
22
+ if (value instanceof require_solidity_int_type_wrapper.SolidityIntTypeWrapper) return new require_solidity_int_type_wrapper.SolidityIntTypeWrapper(value.value * scale);
23
+ if (typeof value === "bigint") return new require_solidity_int_type_wrapper.SolidityIntTypeWrapper(value * scale);
24
+ if (typeof value === "number") {
25
+ if (Number.isInteger(value)) return new require_solidity_int_type_wrapper.SolidityIntTypeWrapper(BigInt(value) * scale);
26
+ return parseUnitsValue(String(value), decimals);
27
+ }
28
+ if (typeof value === "string") return parseDecimalString(value, decimals, scale);
29
+ throw new TypeError(`parseUnits: unsupported value type: ${typeof value}`);
30
+ };
31
+ /**
32
+ * Format a sol_int value into a human-readable double.
33
+ * Mirrors viem/ethers formatUnits behavior.
34
+ */
35
+ const formatUnitsValue = (value, decimals) => {
36
+ const raw = require_solidity_int_type_wrapper.toBigInt(value);
37
+ const scale = 10n ** BigInt(decimals);
38
+ const whole = raw / scale;
39
+ const remainder = raw % scale;
40
+ return Number(whole) + Number(remainder) / Number(scale);
41
+ };
42
+ //#endregion
43
+ exports.formatUnitsValue = formatUnitsValue;
44
+ exports.parseUnitsValue = parseUnitsValue;
@@ -1,4 +1,6 @@
1
- import { SolidityIntTypeWrapper } from "./custom-types/index.js";
1
+ import { SolidityIntTypeWrapper } from "./custom-types/solidity-int-type-wrapper.cjs";
2
+
3
+ //#region src/units.d.ts
2
4
  /**
3
5
  * Parse a human-readable value into a scaled sol_int.
4
6
  * Mirrors viem/ethers parseUnits behavior.
@@ -6,10 +8,11 @@ import { SolidityIntTypeWrapper } from "./custom-types/index.js";
6
8
  * Accepts: bigint, number (int or float), string (decimal notation), SolidityIntTypeWrapper.
7
9
  * Floats are converted to string first to avoid floating-point math.
8
10
  */
9
- export declare const parseUnitsValue: (value: unknown, decimals: number) => SolidityIntTypeWrapper;
11
+ declare const parseUnitsValue: (value: unknown, decimals: number) => SolidityIntTypeWrapper;
10
12
  /**
11
13
  * Format a sol_int value into a human-readable double.
12
14
  * Mirrors viem/ethers formatUnits behavior.
13
15
  */
14
- export declare const formatUnitsValue: (value: unknown, decimals: number) => number;
15
- //# sourceMappingURL=units.d.ts.map
16
+ declare const formatUnitsValue: (value: unknown, decimals: number) => number;
17
+ //#endregion
18
+ export { formatUnitsValue, parseUnitsValue };
@@ -0,0 +1,18 @@
1
+ import { SolidityIntTypeWrapper } from "./custom-types/solidity-int-type-wrapper.mjs";
2
+
3
+ //#region src/units.d.ts
4
+ /**
5
+ * Parse a human-readable value into a scaled sol_int.
6
+ * Mirrors viem/ethers parseUnits behavior.
7
+ *
8
+ * Accepts: bigint, number (int or float), string (decimal notation), SolidityIntTypeWrapper.
9
+ * Floats are converted to string first to avoid floating-point math.
10
+ */
11
+ declare const parseUnitsValue: (value: unknown, decimals: number) => SolidityIntTypeWrapper;
12
+ /**
13
+ * Format a sol_int value into a human-readable double.
14
+ * Mirrors viem/ethers formatUnits behavior.
15
+ */
16
+ declare const formatUnitsValue: (value: unknown, decimals: number) => number;
17
+ //#endregion
18
+ export { formatUnitsValue, parseUnitsValue };
package/dist/units.mjs ADDED
@@ -0,0 +1,43 @@
1
+ import { SolidityIntTypeWrapper, toBigInt } from "./custom-types/solidity-int-type-wrapper.mjs";
2
+ //#region src/units.ts
3
+ const parseDecimalString = (value, decimals, scale) => {
4
+ const negative = value.startsWith("-");
5
+ const parts = (negative ? value.slice(1) : value).split(".");
6
+ if (parts.length > 2) throw new TypeError(`parseUnits: invalid decimal string: "${value}"`);
7
+ const wholePart = parts[0] ?? "0";
8
+ const fracPart = parts[1] ?? "";
9
+ if (fracPart.length > decimals) throw new TypeError(`parseUnits: fractional part "${fracPart}" exceeds ${String(decimals)} decimals`);
10
+ const result = BigInt(wholePart) * scale + (fracPart.length > 0 ? BigInt(fracPart.padEnd(decimals, "0")) : 0n);
11
+ return new SolidityIntTypeWrapper(negative ? -result : result);
12
+ };
13
+ /**
14
+ * Parse a human-readable value into a scaled sol_int.
15
+ * Mirrors viem/ethers parseUnits behavior.
16
+ *
17
+ * Accepts: bigint, number (int or float), string (decimal notation), SolidityIntTypeWrapper.
18
+ * Floats are converted to string first to avoid floating-point math.
19
+ */
20
+ const parseUnitsValue = (value, decimals) => {
21
+ const scale = 10n ** BigInt(decimals);
22
+ if (value instanceof SolidityIntTypeWrapper) return new SolidityIntTypeWrapper(value.value * scale);
23
+ if (typeof value === "bigint") return new SolidityIntTypeWrapper(value * scale);
24
+ if (typeof value === "number") {
25
+ if (Number.isInteger(value)) return new SolidityIntTypeWrapper(BigInt(value) * scale);
26
+ return parseUnitsValue(String(value), decimals);
27
+ }
28
+ if (typeof value === "string") return parseDecimalString(value, decimals, scale);
29
+ throw new TypeError(`parseUnits: unsupported value type: ${typeof value}`);
30
+ };
31
+ /**
32
+ * Format a sol_int value into a human-readable double.
33
+ * Mirrors viem/ethers formatUnits behavior.
34
+ */
35
+ const formatUnitsValue = (value, decimals) => {
36
+ const raw = toBigInt(value);
37
+ const scale = 10n ** BigInt(decimals);
38
+ const whole = raw / scale;
39
+ const remainder = raw % scale;
40
+ return Number(whole) + Number(remainder) / Number(scale);
41
+ };
42
+ //#endregion
43
+ export { formatUnitsValue, parseUnitsValue };
package/package.json CHANGED
@@ -1,30 +1,36 @@
1
1
  {
2
2
  "name": "@seljs/types",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
+ "repository": {
5
+ "url": "https://github.com/abinnovision/seljs"
6
+ },
4
7
  "license": "Apache-2.0",
5
8
  "author": {
6
9
  "name": "abi group GmbH",
7
10
  "email": "info@abigroup.io",
8
11
  "url": "https://abigroup.io/"
9
12
  },
10
- "repository": {
11
- "url": "https://github.com/abinnovision/seljs"
12
- },
13
13
  "type": "module",
14
14
  "exports": {
15
15
  ".": {
16
- "import": "./dist/index.js",
17
- "types": "./dist/index.d.ts"
16
+ "import": {
17
+ "types": "./dist/index.d.mts",
18
+ "default": "./dist/index.mjs"
19
+ },
20
+ "require": {
21
+ "types": "./dist/index.d.cts",
22
+ "default": "./dist/index.cjs"
23
+ }
18
24
  }
19
25
  },
20
- "main": "./dist/index.js",
21
- "types": "./dist/index.d.ts",
26
+ "main": "./dist/index.cjs",
27
+ "types": "./dist/index.d.cts",
22
28
  "files": [
23
29
  "dist",
24
30
  "LICENSE.md"
25
31
  ],
26
32
  "scripts": {
27
- "build": "tsc -p tsconfig.build.json",
33
+ "build": "tsdown",
28
34
  "format:check": "prettier --check '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
29
35
  "format:fix": "prettier --write '{{src,test}/**/*,*}.{{t,j}s{,x},json{,5},md,y{,a}ml}'",
30
36
  "lint:check": "eslint '{{src,test}/**/*,*}.{t,j}s{,x}'",
@@ -42,7 +48,7 @@
42
48
  ]
43
49
  },
44
50
  "dependencies": {
45
- "@seljs/common": "1.0.0"
51
+ "@seljs/common": "1.0.1"
46
52
  },
47
53
  "devDependencies": {
48
54
  "@abinnovision/eslint-config-base": "^3.2.0",
@@ -51,6 +57,7 @@
51
57
  "abitype": "^1.2.3",
52
58
  "eslint": "^9.39.4",
53
59
  "prettier": "^3.8.1",
60
+ "tsdown": "^0.21.3",
54
61
  "typescript": "^5.9.3",
55
62
  "vitest": "^4.0.18"
56
63
  },
@@ -1,2 +0,0 @@
1
- export * from "./type-wrapper.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abstracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1 +0,0 @@
1
- export * from "./type-wrapper.js";
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
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"}
package/dist/context.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=context.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.spec.d.ts","sourceRoot":"","sources":["../src/context.spec.ts"],"names":[],"mappings":""}
@@ -1,38 +0,0 @@
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
- });
@@ -1 +0,0 @@
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"}
@@ -1,48 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=conversion.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conversion.spec.d.ts","sourceRoot":"","sources":["../src/conversion.spec.ts"],"names":[],"mappings":""}
@@ -1,53 +0,0 @@
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
- });
@@ -1,3 +0,0 @@
1
- export * from "./solidity-address-type-wrapper.js";
2
- export * from "./solidity-int-type-wrapper.js";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/custom-types/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from "./solidity-address-type-wrapper.js";
2
- export * from "./solidity-int-type-wrapper.js";
@@ -1,22 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,40 +0,0 @@
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
- }
@@ -1 +0,0 @@
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"}
@@ -1,35 +0,0 @@
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
- }
package/dist/index.d.ts DELETED
@@ -1,7 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
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";