@thru/abi 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +1106 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -0
- package/src/abiSchema.ts +525 -0
- package/src/decodedValue.ts +69 -0
- package/src/decoder.ts +572 -0
- package/src/errors.ts +32 -0
- package/src/expression.ts +165 -0
- package/src/index.test.ts +249 -0
- package/src/index.ts +15 -0
- package/src/typeRegistry.ts +172 -0
- package/src/utils/bytes.ts +7 -0
- package/test/decode-examples.ts +109 -0
- package/tsconfig.json +10 -0
- package/tsup.config.ts +14 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { decodeData } from "../src/index";
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const repoRoot = path.resolve(__dirname, "../../../..");
|
|
8
|
+
const complianceRoot = path.join(repoRoot, "abi/abi_gen/tests/compliance_tests");
|
|
9
|
+
|
|
10
|
+
interface Fixture {
|
|
11
|
+
label: string;
|
|
12
|
+
typeName: string;
|
|
13
|
+
abiFile: string;
|
|
14
|
+
subdir: string;
|
|
15
|
+
binFile: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function loadFixture(subdir: string, abiName: string, binName: string) {
|
|
19
|
+
const abiPath = path.join(complianceRoot, "abi_definitions", abiName);
|
|
20
|
+
const binPath = path.join(complianceRoot, "binary_data", subdir, binName);
|
|
21
|
+
|
|
22
|
+
const abiContent = fs.readFileSync(abiPath, "utf-8");
|
|
23
|
+
const binContent = fs.readFileSync(binPath);
|
|
24
|
+
|
|
25
|
+
return { abiPath, binPath, abiContent, binContent };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function decodeFixture(fixture: Fixture) {
|
|
29
|
+
const { abiPath, binPath, abiContent, binContent } = loadFixture(
|
|
30
|
+
fixture.subdir,
|
|
31
|
+
fixture.abiFile,
|
|
32
|
+
fixture.binFile,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
console.log(`\n${fixture.label}:`);
|
|
36
|
+
console.log(`Reading ABI from ${abiPath}`);
|
|
37
|
+
console.log(`Reading binary from ${binPath}`);
|
|
38
|
+
console.log(`Binary size: ${binContent.length} bytes`);
|
|
39
|
+
|
|
40
|
+
const decoded = decodeData(abiContent, fixture.typeName, new Uint8Array(binContent));
|
|
41
|
+
console.dir(decoded, { depth: null, colors: true });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const fixtures: Fixture[] = [
|
|
45
|
+
{
|
|
46
|
+
label: "Decoded Rectangle Result",
|
|
47
|
+
typeName: "Rectangle",
|
|
48
|
+
abiFile: "structs.abi.yaml",
|
|
49
|
+
subdir: "structs",
|
|
50
|
+
binFile: "rectangle.bin",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: "Decoded SimpleEnum Result",
|
|
54
|
+
typeName: "SimpleEnum",
|
|
55
|
+
abiFile: "enums.abi.yaml",
|
|
56
|
+
subdir: "enums",
|
|
57
|
+
binFile: "value.bin",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
label: "Decoded FixedArrays Result",
|
|
61
|
+
typeName: "FixedArrays",
|
|
62
|
+
abiFile: "arrays.abi.yaml",
|
|
63
|
+
subdir: "arrays",
|
|
64
|
+
binFile: "simple.bin",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: "Decoded AllPrimitives (common values)",
|
|
68
|
+
typeName: "AllPrimitives",
|
|
69
|
+
abiFile: "primitives.abi.yaml",
|
|
70
|
+
subdir: "primitives",
|
|
71
|
+
binFile: "common_values.bin",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
label: "Decoded AllPrimitives (u64 bigint)",
|
|
75
|
+
typeName: "AllPrimitives",
|
|
76
|
+
abiFile: "primitives.abi.yaml",
|
|
77
|
+
subdir: "primitives",
|
|
78
|
+
binFile: "u64_bigint.bin",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: "Decoded SimpleUnion (int variant)",
|
|
82
|
+
typeName: "SimpleUnion",
|
|
83
|
+
abiFile: "unions.abi.yaml",
|
|
84
|
+
subdir: "unions",
|
|
85
|
+
binFile: "int_value.bin",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
label: "Decoded SimpleUnion (float variant)",
|
|
89
|
+
typeName: "SimpleUnion",
|
|
90
|
+
abiFile: "unions.abi.yaml",
|
|
91
|
+
subdir: "unions",
|
|
92
|
+
binFile: "float_value.bin",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
label: "Decoded SimpleUnion (bytes variant)",
|
|
96
|
+
typeName: "SimpleUnion",
|
|
97
|
+
abiFile: "unions.abi.yaml",
|
|
98
|
+
subdir: "unions",
|
|
99
|
+
binFile: "bytes.bin",
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
fixtures.forEach(decodeFixture);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("Error:", error);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED