@uvrn/sdk 1.0.0
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/LICENSE +21 -0
- package/README.md +331 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Loosechain / Suttle Media LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
# @uvrn/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for [UVRN Delta Engine](https://github.com/uvrn/uvrn-core) (formerly Loosechain) — programmatic access to deterministic verification and consensus computation.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Delta Engine SDK provides a developer-friendly interface to interact with the Loosechain Delta Engine in multiple execution modes:
|
|
8
|
+
|
|
9
|
+
- **CLI Mode**: Spawn the CLI executable as a child process
|
|
10
|
+
- **HTTP Mode**: Make REST API calls to a running Delta Engine server
|
|
11
|
+
- **Local Mode**: Direct import and execution of the core engine
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @uvrn/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### TypeScript Example
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { DeltaEngineClient, BundleBuilder } from '@uvrn/sdk';
|
|
25
|
+
|
|
26
|
+
// Create a client (choose your mode)
|
|
27
|
+
const client = new DeltaEngineClient({
|
|
28
|
+
mode: 'http',
|
|
29
|
+
apiUrl: 'http://localhost:3000',
|
|
30
|
+
timeout: 30000
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Build a bundle
|
|
34
|
+
const bundle = new BundleBuilder()
|
|
35
|
+
.setClaim('Q1 revenue matches forecast within 5%')
|
|
36
|
+
.addDataSpecQuick(
|
|
37
|
+
'forecast',
|
|
38
|
+
'Q1 Forecast',
|
|
39
|
+
'report',
|
|
40
|
+
['forecast-doc-123'],
|
|
41
|
+
[{ key: 'revenue', value: 1000000, unit: 'USD' }]
|
|
42
|
+
)
|
|
43
|
+
.addDataSpecQuick(
|
|
44
|
+
'actual',
|
|
45
|
+
'Q1 Actual',
|
|
46
|
+
'report',
|
|
47
|
+
['actuals-doc-456'],
|
|
48
|
+
[{ key: 'revenue', value: 1020000, unit: 'USD' }]
|
|
49
|
+
)
|
|
50
|
+
.setThreshold(0.05)
|
|
51
|
+
.build();
|
|
52
|
+
|
|
53
|
+
// Execute the bundle
|
|
54
|
+
const receipt = await client.runEngine(bundle);
|
|
55
|
+
|
|
56
|
+
console.log('Outcome:', receipt.outcome);
|
|
57
|
+
console.log('Delta:', receipt.deltaFinal);
|
|
58
|
+
console.log('Hash:', receipt.hash);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### JavaScript Example (ES Modules)
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import { DeltaEngineClient, BundleBuilder } from '@uvrn/sdk';
|
|
65
|
+
|
|
66
|
+
const client = new DeltaEngineClient({
|
|
67
|
+
mode: 'local'
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const bundle = new BundleBuilder()
|
|
71
|
+
.setClaim('Sales projections are accurate')
|
|
72
|
+
.addDataSpec({
|
|
73
|
+
id: 'source-1',
|
|
74
|
+
label: 'Projected Sales',
|
|
75
|
+
sourceKind: 'report',
|
|
76
|
+
originDocIds: ['proj-123'],
|
|
77
|
+
metrics: [{ key: 'total_sales', value: 500000 }]
|
|
78
|
+
})
|
|
79
|
+
.addDataSpec({
|
|
80
|
+
id: 'source-2',
|
|
81
|
+
label: 'Actual Sales',
|
|
82
|
+
sourceKind: 'report',
|
|
83
|
+
originDocIds: ['actual-456'],
|
|
84
|
+
metrics: [{ key: 'total_sales', value: 485000 }]
|
|
85
|
+
})
|
|
86
|
+
.setThresholdPercent(10)
|
|
87
|
+
.build();
|
|
88
|
+
|
|
89
|
+
const receipt = await client.runEngine(bundle);
|
|
90
|
+
console.log('Result:', receipt);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### JavaScript Example (CommonJS)
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
const { DeltaEngineClient, BundleBuilder } = require('@uvrn/sdk');
|
|
97
|
+
|
|
98
|
+
// ... same as ES modules example
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Client Modes
|
|
102
|
+
|
|
103
|
+
### CLI Mode
|
|
104
|
+
|
|
105
|
+
Spawns the Delta Engine CLI as a child process:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const client = new DeltaEngineClient({
|
|
109
|
+
mode: 'cli',
|
|
110
|
+
cliPath: '/usr/local/bin/delta-engine', // or './node_modules/.bin/delta-engine'
|
|
111
|
+
timeout: 30000
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Requirements:**
|
|
116
|
+
- Delta Engine CLI must be installed
|
|
117
|
+
- `cliPath` must point to the executable
|
|
118
|
+
|
|
119
|
+
### HTTP Mode
|
|
120
|
+
|
|
121
|
+
Makes REST API calls to a running Delta Engine server:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const client = new DeltaEngineClient({
|
|
125
|
+
mode: 'http',
|
|
126
|
+
apiUrl: 'http://localhost:3000',
|
|
127
|
+
timeout: 30000,
|
|
128
|
+
retries: 3
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Requirements:**
|
|
133
|
+
- Delta Engine API server must be running
|
|
134
|
+
- Server must be accessible at `apiUrl`
|
|
135
|
+
|
|
136
|
+
### Local Mode
|
|
137
|
+
|
|
138
|
+
Directly imports and executes the core engine:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const client = new DeltaEngineClient({
|
|
142
|
+
mode: 'local'
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Requirements:**
|
|
147
|
+
- `@uvrn/core` must be installed
|
|
148
|
+
|
|
149
|
+
## API Reference
|
|
150
|
+
|
|
151
|
+
### `DeltaEngineClient`
|
|
152
|
+
|
|
153
|
+
Main client class for executing bundles and verifying receipts.
|
|
154
|
+
|
|
155
|
+
#### Constructor
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
new DeltaEngineClient(options: ClientOptions)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Options:**
|
|
162
|
+
- `mode`: `'cli' | 'http' | 'local'` - Execution mode
|
|
163
|
+
- `cliPath?`: `string` - Path to CLI executable (CLI mode only)
|
|
164
|
+
- `apiUrl?`: `string` - API base URL (HTTP mode only)
|
|
165
|
+
- `timeout?`: `number` - Request timeout in ms (default: 30000)
|
|
166
|
+
- `retries?`: `number` - Retry attempts (default: 3)
|
|
167
|
+
|
|
168
|
+
#### Methods
|
|
169
|
+
|
|
170
|
+
**`async runEngine(bundle: DeltaBundle): Promise<DeltaReceipt>`**
|
|
171
|
+
|
|
172
|
+
Executes a bundle and returns a receipt.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const receipt = await client.runEngine(bundle);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**`async validateBundle(bundle: DeltaBundle): Promise<ValidationResult>`**
|
|
179
|
+
|
|
180
|
+
Validates a bundle without executing it.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const result = await client.validateBundle(bundle);
|
|
184
|
+
if (!result.valid) {
|
|
185
|
+
console.error('Errors:', result.errors);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**`async verifyReceipt(receipt: DeltaReceipt): Promise<VerificationResult>`**
|
|
190
|
+
|
|
191
|
+
Verifies a receipt's hash integrity.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const result = await client.verifyReceipt(receipt);
|
|
195
|
+
if (!result.verified) {
|
|
196
|
+
console.error('Receipt verification failed!');
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### `BundleBuilder`
|
|
201
|
+
|
|
202
|
+
Fluent API for building Delta Bundles.
|
|
203
|
+
|
|
204
|
+
#### Methods
|
|
205
|
+
|
|
206
|
+
**`setClaim(claim: string): this`**
|
|
207
|
+
|
|
208
|
+
Sets the claim statement.
|
|
209
|
+
|
|
210
|
+
**`addDataSpec(spec: DataSpec): this`**
|
|
211
|
+
|
|
212
|
+
Adds a complete DataSpec.
|
|
213
|
+
|
|
214
|
+
**`addDataSpecQuick(id, label, sourceKind, originDocIds, metrics): this`**
|
|
215
|
+
|
|
216
|
+
Shorthand for adding a DataSpec.
|
|
217
|
+
|
|
218
|
+
**`setThreshold(threshold: number): this`**
|
|
219
|
+
|
|
220
|
+
Sets threshold as decimal (0.0 to 1.0).
|
|
221
|
+
|
|
222
|
+
**`setThresholdPercent(percent: number): this`**
|
|
223
|
+
|
|
224
|
+
Sets threshold as percentage (0 to 100).
|
|
225
|
+
|
|
226
|
+
**`setMaxRounds(rounds: number): this`**
|
|
227
|
+
|
|
228
|
+
Sets maximum rounds (default: 5).
|
|
229
|
+
|
|
230
|
+
**`validate(): ValidationResult`**
|
|
231
|
+
|
|
232
|
+
Validates current configuration.
|
|
233
|
+
|
|
234
|
+
**`build(): DeltaBundle`**
|
|
235
|
+
|
|
236
|
+
Builds and returns the bundle (throws if invalid).
|
|
237
|
+
|
|
238
|
+
### Validators
|
|
239
|
+
|
|
240
|
+
**`validateBundle(bundle: unknown): ValidationResult`**
|
|
241
|
+
|
|
242
|
+
Validates bundle structure.
|
|
243
|
+
|
|
244
|
+
**`validateReceipt(receipt: unknown): ValidationResult`**
|
|
245
|
+
|
|
246
|
+
Validates receipt structure.
|
|
247
|
+
|
|
248
|
+
**`verifyReceiptHash(receipt: DeltaReceipt): boolean`**
|
|
249
|
+
|
|
250
|
+
Verifies receipt hash integrity.
|
|
251
|
+
|
|
252
|
+
## Error Handling
|
|
253
|
+
|
|
254
|
+
The SDK provides typed error classes:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import {
|
|
258
|
+
DeltaEngineError,
|
|
259
|
+
ValidationError,
|
|
260
|
+
ExecutionError,
|
|
261
|
+
NetworkError,
|
|
262
|
+
ConfigurationError
|
|
263
|
+
} from '@uvrn/sdk';
|
|
264
|
+
|
|
265
|
+
try {
|
|
266
|
+
const receipt = await client.runEngine(bundle);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
if (error instanceof ValidationError) {
|
|
269
|
+
console.error('Bundle is invalid:', error.errors);
|
|
270
|
+
} else if (error instanceof ExecutionError) {
|
|
271
|
+
console.error('Execution failed:', error.message, error.exitCode);
|
|
272
|
+
} else if (error instanceof NetworkError) {
|
|
273
|
+
console.error('Network error:', error.statusCode, error.response);
|
|
274
|
+
} else if (error instanceof ConfigurationError) {
|
|
275
|
+
console.error('Configuration error:', error.message);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## TypeScript Support
|
|
281
|
+
|
|
282
|
+
The SDK is written in TypeScript and includes full type definitions:
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
import type {
|
|
286
|
+
DeltaBundle,
|
|
287
|
+
DeltaReceipt,
|
|
288
|
+
DataSpec,
|
|
289
|
+
MetricPoint,
|
|
290
|
+
ClientOptions,
|
|
291
|
+
ValidationResult,
|
|
292
|
+
VerificationResult
|
|
293
|
+
} from '@uvrn/sdk';
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Examples
|
|
297
|
+
|
|
298
|
+
See the [examples directory](./examples/) for complete working examples:
|
|
299
|
+
|
|
300
|
+
- [examples/typescript-client/](./examples/typescript-client/) - TypeScript usage
|
|
301
|
+
- [examples/javascript-client/](./examples/javascript-client/) - JavaScript (ESM and CommonJS)
|
|
302
|
+
- [examples/error-handling/](./examples/error-handling/) - Error handling patterns
|
|
303
|
+
- [examples/batch-processing/](./examples/batch-processing/) - Processing multiple bundles
|
|
304
|
+
|
|
305
|
+
## Documentation
|
|
306
|
+
|
|
307
|
+
- [SDK Guide](./docs/SDK_GUIDE.md) - Comprehensive usage guide
|
|
308
|
+
- [API Documentation](./docs/api/) - Generated TypeDoc documentation
|
|
309
|
+
- [Delta Engine Core](https://github.com/uvrn/uvrn-core) - Core engine documentation
|
|
310
|
+
|
|
311
|
+
## Requirements
|
|
312
|
+
|
|
313
|
+
- Node.js >= 18.0.0
|
|
314
|
+
- TypeScript >= 5.0.0 (for TypeScript projects)
|
|
315
|
+
|
|
316
|
+
## License
|
|
317
|
+
|
|
318
|
+
MIT
|
|
319
|
+
|
|
320
|
+
## Contributing
|
|
321
|
+
|
|
322
|
+
Contributions are welcome! Please see the main repository for contribution guidelines.
|
|
323
|
+
|
|
324
|
+
## Support
|
|
325
|
+
|
|
326
|
+
- GitHub Issues: [Report a bug](https://github.com/uvrn/uvrn-core/issues)
|
|
327
|
+
- Documentation: [Full documentation](https://github.com/uvrn/uvrn-core/tree/main/docs)
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
Built with ❤️ by the Loosechain team
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uvrn/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "UVRN TypeScript SDK — programmatic access to deterministic verification",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"uvrn",
|
|
15
|
+
"sdk",
|
|
16
|
+
"verification",
|
|
17
|
+
"receipt",
|
|
18
|
+
"deterministic",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@uvrn/core": "^1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^29.5.0",
|
|
28
|
+
"@types/node": "^20.0.0",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
30
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
31
|
+
"eslint": "^8.0.0",
|
|
32
|
+
"jest": "^29.5.0",
|
|
33
|
+
"ts-jest": "^29.1.0",
|
|
34
|
+
"typescript": "^5.3.0",
|
|
35
|
+
"@uvrn/core": "1.0.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "npm run clean && tsc",
|
|
47
|
+
"build:watch": "tsc --watch",
|
|
48
|
+
"clean": "rm -rf dist dist-esm",
|
|
49
|
+
"test": "jest",
|
|
50
|
+
"test:watch": "jest --watch",
|
|
51
|
+
"test:coverage": "jest --coverage",
|
|
52
|
+
"lint": "eslint src/**/*.ts"
|
|
53
|
+
}
|
|
54
|
+
}
|