@effectstream/precompile 0.100.14 → 0.100.15
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 +58 -0
- package/package.json +1 -1
- package/test/examples.test.ts +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @effectstream/precompile
|
|
2
|
+
|
|
3
|
+
Generate deterministic EVM-sized (20-byte) addresses from string names
|
|
4
|
+
by hashing with keccak256. The intended use is "precompile" addresses —
|
|
5
|
+
synthetic 0x-addresses reserved by an EffectStream node for non-user
|
|
6
|
+
logic (intrinsic primitives, timers, internal accounts).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bun add @effectstream/precompile
|
|
12
|
+
# or
|
|
13
|
+
npm install @effectstream/precompile
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Standalone usage
|
|
17
|
+
|
|
18
|
+
Pure functions. Given a name, get an address. Same name, same address —
|
|
19
|
+
always.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { generatePrecompile, generatePrecompiles } from "@effectstream/precompile";
|
|
23
|
+
|
|
24
|
+
const addr = generatePrecompile("MY_FEATURE");
|
|
25
|
+
// addr === "0x<first-20-bytes-of-keccak256-of-MY_FEATURE>"
|
|
26
|
+
|
|
27
|
+
// Bulk-derive a typed map from a string enum.
|
|
28
|
+
enum MyNames {
|
|
29
|
+
A = "feature-a",
|
|
30
|
+
B = "feature-b",
|
|
31
|
+
}
|
|
32
|
+
const map = generatePrecompiles(MyNames);
|
|
33
|
+
// map["feature-a"] === generatePrecompile("feature-a")
|
|
34
|
+
// map["feature-b"] === generatePrecompile("feature-b")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The result is an EVM-shaped `0x[40 hex chars]` string, usable wherever
|
|
38
|
+
viem/ethers expects an `Address`.
|
|
39
|
+
|
|
40
|
+
## Inside EffectStream
|
|
41
|
+
|
|
42
|
+
Exported through `@effectstream/node-sdk/precompile`. Names are stable
|
|
43
|
+
across versions, so an address generated today matches one generated by
|
|
44
|
+
a future build of the same name.
|
|
45
|
+
|
|
46
|
+
## Key exports
|
|
47
|
+
|
|
48
|
+
- `generatePrecompile(name: string): HexString0x` — `0x` + first 40 hex chars of `keccak256(name)`.
|
|
49
|
+
- `generatePrecompiles(names: Record<string, string>)` — bulk variant. Returns `{ [value]: address }`.
|
|
50
|
+
|
|
51
|
+
## Examples
|
|
52
|
+
|
|
53
|
+
Runnable: [`test/examples.test.ts`](./test/examples.test.ts).
|
|
54
|
+
|
|
55
|
+
## Links
|
|
56
|
+
|
|
57
|
+
- Docs: https://effectstream.github.io/docs/packages/sdk/precompile
|
|
58
|
+
- Source: https://github.com/PaimaStudios/paima-engine/tree/main/packages/effectstream-sdk/precompile
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Examples for the README.
|
|
2
|
+
|
|
3
|
+
import { test, expect } from "bun:test";
|
|
4
|
+
import { generatePrecompile, generatePrecompiles } from "../src/mod.ts";
|
|
5
|
+
|
|
6
|
+
test("README: generatePrecompile returns a 0x-prefixed 40-hex-char address", () => {
|
|
7
|
+
const addr = generatePrecompile("MY_FEATURE");
|
|
8
|
+
expect(addr).toMatch(/^0x[0-9a-f]{40}$/);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("README: same name always produces the same address", () => {
|
|
12
|
+
expect(generatePrecompile("MY_FEATURE")).toBe(
|
|
13
|
+
generatePrecompile("MY_FEATURE"),
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("README: different names produce different addresses", () => {
|
|
18
|
+
expect(generatePrecompile("a")).not.toBe(generatePrecompile("b"));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("README: generatePrecompiles bulk-derives a typed map from a string enum", () => {
|
|
22
|
+
enum MyNames {
|
|
23
|
+
A = "feature-a",
|
|
24
|
+
B = "feature-b",
|
|
25
|
+
}
|
|
26
|
+
const map = generatePrecompiles(MyNames);
|
|
27
|
+
expect(map["feature-a"]).toBe(generatePrecompile("feature-a"));
|
|
28
|
+
expect(map["feature-b"]).toBe(generatePrecompile("feature-b"));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("README: empty enum produces empty map (no throw)", () => {
|
|
32
|
+
const map = generatePrecompiles({} as Record<string, string>);
|
|
33
|
+
expect(Object.keys(map).length).toBe(0);
|
|
34
|
+
});
|