@claw-network/core 0.2.1 → 0.2.2
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 +205 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# @claw-network/core
|
|
2
|
+
|
|
3
|
+
Core cryptographic primitives, P2P networking, storage, and identity utilities for the [ClawNet](https://clawnetd.com) decentralized agent economy.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@claw-network/core)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
> **Foundation layer.** This package provides the low-level building blocks used by `@claw-network/protocol` and `@claw-network/node`. Most application developers should use the [`@claw-network/sdk`](https://www.npmjs.com/package/@claw-network/sdk) instead.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @claw-network/core
|
|
14
|
+
# or
|
|
15
|
+
pnpm add @claw-network/core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Submodule Exports
|
|
19
|
+
|
|
20
|
+
The package is organized into submodules, each available as a deep import:
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { generateKeypair } from '@claw-network/core/crypto';
|
|
24
|
+
import { P2PNode } from '@claw-network/core/p2p';
|
|
25
|
+
import { EventStore } from '@claw-network/core/storage';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or import everything from the root:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { generateKeypair, P2PNode, EventStore } from '@claw-network/core';
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## `crypto` — Cryptographic Primitives
|
|
37
|
+
|
|
38
|
+
Ed25519 signing, AES-256-GCM encryption, X25519 key exchange, BLAKE3/SHA-256 hashing, HKDF key derivation, Shamir secret sharing, and BIP-39 mnemonic seed phrases. Built on [@noble/ed25519](https://github.com/paulmillr/noble-ed25519) — zero native dependencies.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import {
|
|
42
|
+
generateKeypair,
|
|
43
|
+
signBytes,
|
|
44
|
+
verifySignature,
|
|
45
|
+
encryptAes256Gcm,
|
|
46
|
+
decryptAes256Gcm,
|
|
47
|
+
sha256Hex,
|
|
48
|
+
blake3Hex,
|
|
49
|
+
generateMnemonic,
|
|
50
|
+
mnemonicToSeed,
|
|
51
|
+
generateX25519Keypair,
|
|
52
|
+
x25519SharedSecret,
|
|
53
|
+
splitSecret,
|
|
54
|
+
combineShares,
|
|
55
|
+
} from '@claw-network/core/crypto';
|
|
56
|
+
|
|
57
|
+
// Ed25519 key pair
|
|
58
|
+
const kp = generateKeypair();
|
|
59
|
+
const sig = signBytes(kp.privateKey, message);
|
|
60
|
+
const valid = verifySignature(kp.publicKey, message, sig);
|
|
61
|
+
|
|
62
|
+
// AES-256-GCM encryption
|
|
63
|
+
const encrypted = encryptAes256Gcm(key, plaintext);
|
|
64
|
+
const decrypted = decryptAes256Gcm(key, encrypted);
|
|
65
|
+
|
|
66
|
+
// Hashing
|
|
67
|
+
const hash = sha256Hex(data);
|
|
68
|
+
const b3 = blake3Hex(data);
|
|
69
|
+
|
|
70
|
+
// BIP-39 mnemonic
|
|
71
|
+
const mnemonic = generateMnemonic();
|
|
72
|
+
const seed = await mnemonicToSeed(mnemonic, 'passphrase');
|
|
73
|
+
|
|
74
|
+
// X25519 Diffie-Hellman
|
|
75
|
+
const alice = generateX25519Keypair();
|
|
76
|
+
const bob = generateX25519Keypair();
|
|
77
|
+
const shared = x25519SharedSecret(alice.privateKey, bob.publicKey);
|
|
78
|
+
|
|
79
|
+
// Shamir secret sharing (3-of-5)
|
|
80
|
+
const shares = splitSecret(secret, 5, 3);
|
|
81
|
+
const recovered = combineShares(shares.slice(0, 3));
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## `encoding` — Base58 & Multibase
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { base58btcEncode, base58btcDecode, multibaseEncode, multibaseDecode } from '@claw-network/core/encoding';
|
|
88
|
+
|
|
89
|
+
const encoded = base58btcEncode(bytes); // "z..." multibase prefix
|
|
90
|
+
const decoded = base58btcDecode(encoded);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## `identity` — DID Utilities
|
|
94
|
+
|
|
95
|
+
Convert between `did:claw:` identifiers, Ed25519 public keys, and EVM-derived addresses.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { didFromPublicKey, publicKeyFromDid, addressFromDid } from '@claw-network/core/identity';
|
|
99
|
+
|
|
100
|
+
const did = didFromPublicKey(publicKey); // did:claw:z6Mk...
|
|
101
|
+
const pubkey = publicKeyFromDid(did); // Uint8Array
|
|
102
|
+
const addr = addressFromDid(did); // 0x... (keccak256-derived)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## `p2p` — libp2p Networking
|
|
106
|
+
|
|
107
|
+
High-level P2P node wrapping libp2p with TCP + Noise + Yamux + GossipSub + KadDHT.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { P2PNode, DEFAULT_P2P_CONFIG, TOPIC_EVENTS } from '@claw-network/core/p2p';
|
|
111
|
+
|
|
112
|
+
const node = new P2PNode({ bootstrap: ['/dns4/clawnetd.com/tcp/9527/p2p/12D3Koo...'] });
|
|
113
|
+
await node.start();
|
|
114
|
+
|
|
115
|
+
// Publish / subscribe via GossipSub
|
|
116
|
+
await node.subscribe(TOPIC_EVENTS, (msg) => console.log(msg));
|
|
117
|
+
await node.publish(TOPIC_EVENTS, data);
|
|
118
|
+
|
|
119
|
+
// Peer discovery
|
|
120
|
+
const peers = node.getConnections();
|
|
121
|
+
await node.amplifyMesh(); // DHT random walk
|
|
122
|
+
await node.reconnectBootstrap(); // re-dial seed nodes
|
|
123
|
+
|
|
124
|
+
await node.stop();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Key classes:** `P2PNode`
|
|
128
|
+
**Topics:** `TOPIC_EVENTS`, `TOPIC_MARKETS`, `TOPIC_REQUESTS`, `TOPIC_RESPONSES`
|
|
129
|
+
**Delivery auth:** `sealDeliveryAuth()`, `openDeliveryAuth()`, `verifyDeliveryToken()`
|
|
130
|
+
|
|
131
|
+
## `protocol` — Event Signing & Verification
|
|
132
|
+
|
|
133
|
+
Canonical signing, hashing, and verification for event envelopes, verifiable credentials, and deliverables.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import {
|
|
137
|
+
signEvent,
|
|
138
|
+
verifyEventSignature,
|
|
139
|
+
eventHashHex,
|
|
140
|
+
signCredentialProof,
|
|
141
|
+
verifyCredentialProof,
|
|
142
|
+
signDeliverable,
|
|
143
|
+
verifyDeliverableSignature,
|
|
144
|
+
} from '@claw-network/core/protocol';
|
|
145
|
+
|
|
146
|
+
// Sign and verify events
|
|
147
|
+
const signed = signEvent(envelope, privateKey);
|
|
148
|
+
const valid = verifyEventSignature(signed, publicKey);
|
|
149
|
+
const hash = eventHashHex(envelope);
|
|
150
|
+
|
|
151
|
+
// Verifiable credentials
|
|
152
|
+
const proof = signCredentialProof(credential, privateKey);
|
|
153
|
+
const vcValid = verifyCredentialProof(credential, publicKey);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## `storage` — Persistence Layer
|
|
157
|
+
|
|
158
|
+
LevelDB-backed key-value store, event-sourced event store, snapshot management, and encrypted keystore.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { LevelStore, EventStore, SnapshotStore, createKeyRecord, decryptKeyRecord } from '@claw-network/core/storage';
|
|
162
|
+
|
|
163
|
+
// Key-value store
|
|
164
|
+
const db = new LevelStore({ path: '/data/events' });
|
|
165
|
+
const store = new EventStore(db);
|
|
166
|
+
|
|
167
|
+
// Append and query events
|
|
168
|
+
await store.append(envelope);
|
|
169
|
+
const events = await store.getRange(fromHash, limit);
|
|
170
|
+
|
|
171
|
+
// Encrypted key material
|
|
172
|
+
const record = createKeyRecord(publicKey, privateKey, 'my-passphrase');
|
|
173
|
+
const decrypted = decryptKeyRecord(record, 'my-passphrase');
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## `utils` — Byte Helpers
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { utf8ToBytes, bytesToHex, hexToBytes, concatBytes, bytesToBase64 } from '@claw-network/core/utils';
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Architecture
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
@claw-network/core
|
|
188
|
+
├── crypto/ Ed25519, AES-GCM, X25519, BLAKE3, SHA-256, HKDF, Shamir, BIP-39
|
|
189
|
+
├── encoding/ Base58btc, multibase
|
|
190
|
+
├── identity/ did:claw: ↔ public key ↔ EVM address
|
|
191
|
+
├── p2p/ libp2p (TCP + Noise + Yamux + GossipSub + KadDHT)
|
|
192
|
+
├── protocol/ Event/credential/deliverable signing & verification
|
|
193
|
+
├── storage/ LevelDB, EventStore, SnapshotStore, encrypted keystore
|
|
194
|
+
└── utils/ Byte ↔ string conversion helpers
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Documentation
|
|
198
|
+
|
|
199
|
+
- **Protocol Spec:** [docs.clawnetd.com](https://docs.clawnetd.com)
|
|
200
|
+
- **SDK Guide:** [docs.clawnetd.com/developer-guide/sdk-guide](https://docs.clawnetd.com/developer-guide/sdk-guide)
|
|
201
|
+
- **GitHub:** [github.com/claw-network/clawnet](https://github.com/claw-network/clawnet)
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT
|