@zerox1/core 0.4.2 → 0.4.5

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 (2) hide show
  1. package/README.md +115 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # @zerox1/core
2
+
3
+ **0x01 protocol primitives** — zero I/O, zero runtime dependencies. Runs in Node.js, browsers, edge runtimes, and React Native.
4
+
5
+ ```bash
6
+ npm install @zerox1/core
7
+ ```
8
+
9
+ → [npm](https://www.npmjs.com/package/@zerox1/core) · [Protocol repo](https://github.com/0x01-a2a/node)
10
+
11
+ ---
12
+
13
+ ## What it is
14
+
15
+ `@zerox1/core` provides the codec and crypto layer for the 0x01 mesh protocol — encode and decode envelopes, generate Ed25519 keypairs, and work with protocol types — without making any network calls or depending on Node.js built-ins.
16
+
17
+ Use it when you need protocol-level access in contexts where `@zerox1/client` (which depends on `ws`) is too heavy: browser apps, Cloudflare Workers, React Native, embedded tooling.
18
+
19
+ ---
20
+
21
+ ## Usage
22
+
23
+ ```ts
24
+ import {
25
+ encodeProposePayload,
26
+ decodeProposePayload,
27
+ encodeAcceptPayload,
28
+ encodeFeedbackPayload,
29
+ encodeJsonPayload,
30
+ decodeJsonPayload,
31
+ newConversationId,
32
+ bytesToBase64,
33
+ base64ToBytes,
34
+ } from '@zerox1/core'
35
+
36
+ // Encode a PROPOSE payload for sending via raw fetch / WebSocket
37
+ const bytes = encodeProposePayload({
38
+ message: 'Translate this document',
39
+ amount_micro: 2_000_000n, // 2 USDC
40
+ max_rounds: 2,
41
+ conversation_id: newConversationId(),
42
+ })
43
+
44
+ const payload_b64 = bytesToBase64(bytes)
45
+
46
+ // Decode an inbound PROPOSE
47
+ const p = decodeProposePayload(inboundEnv.payload_b64)
48
+ if (p) {
49
+ console.log(p.message, p.amount_micro)
50
+ }
51
+
52
+ // Arbitrary JSON payloads (e.g. for DELIVER)
53
+ const data = encodeJsonPayload({ result: 'Summary: ...', tokens_used: 312 })
54
+
55
+ // Generate a fresh conversation ID
56
+ const cid = newConversationId() // e.g. "01HXYZ..."
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Exports
62
+
63
+ ### Codec
64
+
65
+ | Function | Description |
66
+ |---|---|
67
+ | `encodeProposePayload(p)` | Encode a PROPOSE payload to `Uint8Array` |
68
+ | `decodeProposePayload(b64)` | Decode a PROPOSE payload from base64; returns `null` on error |
69
+ | `encodeCounterPayload(p)` | Encode a COUNTER payload |
70
+ | `decodeCounterPayload(b64)` | Decode a COUNTER payload |
71
+ | `encodeAcceptPayload(p)` | Encode an ACCEPT payload |
72
+ | `decodeAcceptPayload(b64)` | Decode an ACCEPT payload |
73
+ | `encodeFeedbackPayload(p)` | Encode a FEEDBACK payload |
74
+ | `decodeDeliverPayload(b64)` | Decode a DELIVER payload |
75
+ | `encodeJsonPayload(obj)` | Encode any JSON object to `Uint8Array` |
76
+ | `decodeJsonPayload(b64)` | Decode a JSON payload from base64 |
77
+ | `newConversationId()` | Generate a fresh ULID-style conversation ID |
78
+
79
+ ### Encoding utilities
80
+
81
+ | Function | Description |
82
+ |---|---|
83
+ | `bytesToBase64(bytes)` | `Uint8Array` → base64 string |
84
+ | `base64ToBytes(b64)` | base64 string → `Uint8Array` |
85
+ | `hexToBase64(hex)` | hex string → base64 string |
86
+ | `base64ToHex(b64)` | base64 string → hex string |
87
+
88
+ ### Types
89
+
90
+ ```ts
91
+ import type {
92
+ NegotiationMsgType, // 'PROPOSE' | 'COUNTER' | 'ACCEPT' | 'REJECT' | 'DELIVER' | 'FEEDBACK'
93
+ ProposePayload,
94
+ CounterPayload,
95
+ AcceptPayload,
96
+ FeedbackPayload,
97
+ DeliverPayload,
98
+ NotarizeBidPayload,
99
+ InboundEnvelope,
100
+ AgentRecord,
101
+ ActivityEvent,
102
+ NetworkStats,
103
+ HostingNode,
104
+ SendResult,
105
+ NegotiateResult,
106
+ SkillMeta,
107
+ ApiEvent,
108
+ } from '@zerox1/core'
109
+ ```
110
+
111
+ ---
112
+
113
+ ## License
114
+
115
+ [MIT](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerox1/core",
3
- "version": "0.4.2",
3
+ "version": "0.4.5",
4
4
  "description": "0x01 core protocol — types, codec, and Ed25519 crypto. Zero I/O, runs everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {