@effectstream/precompile 0.100.14 → 0.100.16

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 ADDED
@@ -0,0 +1,63 @@
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
+ - Deterministic 20-byte addresses from string names via keccak256.
9
+ - Pure functions; same name in, same address out.
10
+ - Used by intrinsic primitives, timers, and internal accounts.
11
+ - Result is an EVM-shaped `0x[40 hex chars]` string, usable wherever viem/ethers expects an `Address`.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ bun add @effectstream/precompile
17
+ # or
18
+ npm install @effectstream/precompile
19
+ ```
20
+
21
+ ## Standalone usage
22
+
23
+ Pure functions. Given a name, get an address. Same name, same address —
24
+ always.
25
+
26
+ ```typescript
27
+ import { generatePrecompile, generatePrecompiles } from "@effectstream/precompile";
28
+
29
+ const addr = generatePrecompile("MY_FEATURE");
30
+ // addr === "0x<first-20-bytes-of-keccak256-of-MY_FEATURE>"
31
+
32
+ // Bulk-derive a typed map from a string enum.
33
+ enum MyNames {
34
+ A = "feature-a",
35
+ B = "feature-b",
36
+ }
37
+ const map = generatePrecompiles(MyNames);
38
+ // map["feature-a"] === generatePrecompile("feature-a")
39
+ // map["feature-b"] === generatePrecompile("feature-b")
40
+ ```
41
+
42
+ The result is an EVM-shaped `0x[40 hex chars]` string, usable wherever
43
+ viem/ethers expects an `Address`.
44
+
45
+ ## Inside EffectStream
46
+
47
+ Exported through `@effectstream/node-sdk/precompile`. Names are stable
48
+ across versions, so an address generated today matches one generated by
49
+ a future build of the same name.
50
+
51
+ ## Key exports
52
+
53
+ - `generatePrecompile(name: string): HexString0x` — `0x` + first 40 hex chars of `keccak256(name)`.
54
+ - `generatePrecompiles(names: Record<string, string>)` — bulk variant. Returns `{ [value]: address }`.
55
+
56
+ ## Examples
57
+
58
+ Runnable: [`test/examples.test.ts`](./test/examples.test.ts).
59
+
60
+ ## Links
61
+
62
+ - Docs: https://effectstream.github.io/docs/packages/sdk/precompile
63
+ - Source: https://github.com/effectstream/effectstream/tree/main/packages/effectstream-sdk/precompile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/precompile",
3
- "version": "0.100.14",
3
+ "version": "0.100.16",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -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
+ });