@hashgraphonline/standards-sdk 0.0.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 +244 -0
- package/dist/index-DwQun2ka.js +5209 -0
- package/dist/index-wA88M1Il.js +153505 -0
- package/dist/secp256k1-C2Ousbk3.js +2030 -0
- package/dist/standards-sdk.esm.js +11 -0
- package/dist/standards-sdk.js +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Hashgraph Consensus Standards SDK
|
|
2
|
+
|
|
3
|
+
This SDK provides reference implementations for Hashgraph Consensus Standards (HCS) created by Hashgraph Online.
|
|
4
|
+
|
|
5
|
+
## Supported Standards
|
|
6
|
+
|
|
7
|
+
| Standard | Description | Environments |
|
|
8
|
+
| -------- | --------------------------------------------------- | ----------------------------------- |
|
|
9
|
+
| HCS-3 | Recursion for Inscribed Files | Browser (WebAssembly, HTML5) |
|
|
10
|
+
| HCS-7 | Dynamic, Programmable, and 100% on-graph assets | Node.js, Browser (EVM, WebAssembly) |
|
|
11
|
+
| HCS-10 | Trustless, peer to peer communication for AI Agents | Node.js, Browser |
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @hashgraphonline/standards-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Running Demos
|
|
20
|
+
|
|
21
|
+
The SDK includes demo implementations showcasing various features. To run the demos:
|
|
22
|
+
|
|
23
|
+
1. Clone the repository
|
|
24
|
+
2. Install dependencies:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
3. Set up your environment variables:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cp .env.example .env
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
4. Edit `.env` with your credentials:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
API_KEY=your_api_key_here
|
|
40
|
+
ACCOUNT_ID=0.0.12345
|
|
41
|
+
PRIVATE_KEY=your_private_key_here
|
|
42
|
+
NETWORK=testnet
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
5. Run the demos:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Run the Inscribe Demo
|
|
49
|
+
npm run demo
|
|
50
|
+
|
|
51
|
+
# Run the HCS-10 Demo
|
|
52
|
+
npm run demo:hcs-10
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Available Demos
|
|
56
|
+
|
|
57
|
+
- **Inscribe Demo** (`demo/inscribe-demo.ts`): Demonstrates file inscription capabilities
|
|
58
|
+
|
|
59
|
+
- Text inscription
|
|
60
|
+
- URL inscription
|
|
61
|
+
- Buffer inscription
|
|
62
|
+
- Hashinal NFT creation (from URL, buffer, and text)
|
|
63
|
+
- Manual inscription retrieval
|
|
64
|
+
|
|
65
|
+
- **HCS-10 Demo** (`demo/hcs-10/index.ts`): Demonstrates AI agent communication
|
|
66
|
+
- Agent setup and registration
|
|
67
|
+
- Connection establishment between agents
|
|
68
|
+
- Message exchange
|
|
69
|
+
- Request monitoring
|
|
70
|
+
- Agent metadata management
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
### Inscribing Files
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { inscribe } from '@hashgraphonline/standards-sdk';
|
|
78
|
+
|
|
79
|
+
// Inscribe from URL
|
|
80
|
+
const urlResult = await inscribe(
|
|
81
|
+
{
|
|
82
|
+
type: 'url',
|
|
83
|
+
url: 'https://example.com/file.json',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
network: 'mainnet',
|
|
87
|
+
accountId: '0.0.123456',
|
|
88
|
+
privateKey: 'your-private-key',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
mode: 'file',
|
|
92
|
+
metadata: {
|
|
93
|
+
name: 'My File',
|
|
94
|
+
description: 'A JSON file',
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Inscribe from local file
|
|
100
|
+
const fileResult = await inscribe(
|
|
101
|
+
{
|
|
102
|
+
type: 'file',
|
|
103
|
+
path: './path/to/file.json',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
network: 'mainnet',
|
|
107
|
+
accountId: '0.0.123456',
|
|
108
|
+
privateKey: 'your-private-key',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
mode: 'file',
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Inscribe from buffer
|
|
116
|
+
const bufferResult = await inscribe(
|
|
117
|
+
{
|
|
118
|
+
type: 'buffer',
|
|
119
|
+
buffer: fileBuffer,
|
|
120
|
+
fileName: 'file.json',
|
|
121
|
+
mimeType: 'application/json',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
network: 'mainnet',
|
|
125
|
+
accountId: '0.0.123456',
|
|
126
|
+
privateKey: 'your-private-key',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
mode: 'file',
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### HCS-7: Smart Contract State Processing
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { HCS7 } from '@hashgraphonline/standards-sdk';
|
|
138
|
+
|
|
139
|
+
// Initialize EVM Bridge to read smart contract state
|
|
140
|
+
const evmBridge = new HCS7.EVMBridge('mainnet-public');
|
|
141
|
+
|
|
142
|
+
// Read state from a smart contract
|
|
143
|
+
const contractState = await evmBridge.executeCommand({
|
|
144
|
+
p: 'evm',
|
|
145
|
+
op: 'read',
|
|
146
|
+
m: 'latestRoundData',
|
|
147
|
+
c: {
|
|
148
|
+
contractAddress: '0x...', // Your contract address
|
|
149
|
+
abi: {
|
|
150
|
+
name: 'latestRoundData',
|
|
151
|
+
inputs: [],
|
|
152
|
+
outputs: [
|
|
153
|
+
{ name: 'roundId', type: 'uint80' },
|
|
154
|
+
{ name: 'answer', type: 'int256' },
|
|
155
|
+
{ name: 'startedAt', type: 'uint256' },
|
|
156
|
+
{ name: 'updatedAt', type: 'uint256' },
|
|
157
|
+
{ name: 'answeredInRound', type: 'uint80' },
|
|
158
|
+
],
|
|
159
|
+
stateMutability: 'view',
|
|
160
|
+
type: 'function',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Process state using WASM
|
|
166
|
+
const wasmBridge = new HCS7.WasmBridge();
|
|
167
|
+
await wasmBridge.initWasm(wasmBytes);
|
|
168
|
+
const result = await wasmBridge.executeCommand({
|
|
169
|
+
p: 'wasm',
|
|
170
|
+
op: 'process',
|
|
171
|
+
m: 'process_state',
|
|
172
|
+
c: {
|
|
173
|
+
wasmTopicId: '0.0.123456',
|
|
174
|
+
inputType: {
|
|
175
|
+
stateData: contractState,
|
|
176
|
+
},
|
|
177
|
+
outputType: {
|
|
178
|
+
type: 'json',
|
|
179
|
+
format: 'string',
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### HCS-3: Recursive Content Loading
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { HCS3 } from '@hashgraphonline/standards-sdk';
|
|
189
|
+
|
|
190
|
+
// Initialize HCS-3 with configuration
|
|
191
|
+
const hcs = new HCS3.HCS({
|
|
192
|
+
cdnUrl: 'https://kiloscribe.com/api/inscription-cdn/',
|
|
193
|
+
network: 'mainnet',
|
|
194
|
+
retryAttempts: 3,
|
|
195
|
+
retryBackoff: 300,
|
|
196
|
+
debug: false,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Load specific content types
|
|
200
|
+
await hcs.loadScript('hcs://1/0.0.123456');
|
|
201
|
+
await hcs.loadImage('hcs://1/0.0.123456');
|
|
202
|
+
await hcs.loadVideo('hcs://1/0.0.123456');
|
|
203
|
+
await hcs.loadAudio('hcs://1/0.0.123456');
|
|
204
|
+
await hcs.loadGLB('hcs://1/0.0.123456');
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### HCS-10: AI Agent Communication
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { HCS10 } from '@hashgraphonline/standards-sdk';
|
|
211
|
+
|
|
212
|
+
// Initialize HCS-10 SDK
|
|
213
|
+
const sdk = new HCS10.SDK({
|
|
214
|
+
network: 'mainnet',
|
|
215
|
+
topicId: '0.0.123456',
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Send message to AI agent
|
|
219
|
+
await sdk.sendMessage({
|
|
220
|
+
type: 'command',
|
|
221
|
+
content: 'Process this data',
|
|
222
|
+
metadata: {
|
|
223
|
+
agentId: 'agent-123',
|
|
224
|
+
timestamp: Date.now(),
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Contributing
|
|
230
|
+
|
|
231
|
+
1. Fork the repository.
|
|
232
|
+
2. Create a new feature branch.
|
|
233
|
+
3. Implement your changes.
|
|
234
|
+
4. Submit a pull request.
|
|
235
|
+
|
|
236
|
+
## Resources
|
|
237
|
+
|
|
238
|
+
- [HCS Standards Documentation](https://hcs-improvement-proposals.pages.dev/docs/standards)
|
|
239
|
+
- [Hedera Documentation](https://docs.hedera.com)
|
|
240
|
+
- Join our [Telegram Community](https://t.me/hashinals)
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
Apache-2.0
|