Skip to content

Commit e24a661

Browse files
authored
Merge pull request #3 from hpp-io/1-noosphere-payload
1 noosphere pURI scheme-based payload handlingayload
2 parents 187ef00 + b1236f3 commit e24a661

File tree

85 files changed

+21469
-9239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+21469
-9239
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [18.x, 20.x]
15+
node-version: [20.x, 22.x]
1616

1717
steps:
1818
- name: Checkout repository
@@ -22,10 +22,9 @@ jobs:
2222
uses: actions/setup-node@v4
2323
with:
2424
node-version: ${{ matrix.node-version }}
25-
cache: 'npm'
2625

2726
- name: Install dependencies
28-
run: npm ci
27+
run: yarn install --frozen-lockfile || yarn install
2928

3029
- name: Build
3130
run: npm run build

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Dependencies
22
node_modules/
3-
yarn.lock
43

54
# Build outputs
65
dist/

README.md

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Noosphere SDK enables you to build and run compute agents that participate in th
4040
npm install @noosphere/sdk
4141

4242
# Or install individual packages
43-
npm install @noosphere/agent-core @noosphere/crypto @noosphere/contracts @noosphere/registry
43+
npm install @noosphere/agent-core @noosphere/crypto @noosphere/contracts @noosphere/registry @noosphere/payload
4444
```
4545

4646
### Basic Example
@@ -94,6 +94,14 @@ await agent.start();
9494
│ ├── EventMonitor (blockchain events) │
9595
│ └── ContainerManager (Docker execution) │
9696
├─────────────────────────────────────────────────────────┤
97+
│ @noosphere/payload (browser & Node.js) │
98+
│ ├── PayloadResolver (URI-based payload handling) │
99+
│ └── Storage providers │
100+
│ ├── IpfsStorage (IPFS/Pinata) │
101+
│ ├── S3Storage (S3/R2/MinIO) │
102+
│ ├── DataUriStorage (inline data) │
103+
│ └── HttpStorage (HTTP/HTTPS) │
104+
├─────────────────────────────────────────────────────────┤
97105
│ @noosphere/contracts │
98106
│ ├── ABIs (contract interfaces) │
99107
│ ├── TypeChain types (type-safe wrappers) │
@@ -127,6 +135,32 @@ await agent.start();
127135
- `EventMonitor` - Blockchain event listener with WebSocket support
128136
- `ContainerManager` - Docker container execution
129137

138+
### [@noosphere/payload](./packages/payload) · [npm](https://www.npmjs.com/package/@noosphere/payload)
139+
140+
PayloadData utilities for URI-based payload handling. Works in both browser and Node.js environments.
141+
142+
```typescript
143+
import { PayloadResolver, createDataUriPayload } from '@noosphere/payload';
144+
145+
// Create PayloadData
146+
const payload = createDataUriPayload('{"action": "ping"}');
147+
148+
// Resolve PayloadData
149+
const resolver = new PayloadResolver({ ipfs: { gateway: 'https://ipfs.io/ipfs/' } });
150+
const { content, verified } = await resolver.resolve(payload);
151+
```
152+
153+
**Key Components:**
154+
- `PayloadResolver` - Resolves and encodes PayloadData with verification
155+
- `IpfsStorage` - IPFS/Pinata storage provider
156+
- `S3Storage` - S3/R2/MinIO storage provider
157+
- `DataUriStorage` - Inline base64 data URI provider
158+
159+
**Supported URI Schemes:**
160+
- `data:` - Inline base64-encoded data
161+
- `ipfs://` - IPFS content addressing
162+
- `https://` / `http://` - HTTP(S) URLs
163+
130164
### [@noosphere/contracts](./packages/contracts) · [npm](https://www.npmjs.com/package/@noosphere/contracts)
131165

132166
Type-safe contract interfaces and ABIs.
@@ -205,6 +239,54 @@ if (verifier.requiresProof && verifier.proofService) {
205239
}
206240
```
207241

242+
### Payload Resolution
243+
244+
The SDK includes `PayloadResolver` for handling URI-based payload data with multiple storage backends.
245+
246+
```typescript
247+
import { PayloadResolver } from '@noosphere/agent-core';
248+
249+
const resolver = new PayloadResolver({
250+
// IPFS configuration
251+
ipfs: {
252+
gateway: 'https://gateway.pinata.cloud/ipfs/',
253+
apiEndpoint: 'https://api.pinata.cloud',
254+
apiKey: process.env.PINATA_API_KEY,
255+
apiSecret: process.env.PINATA_API_SECRET,
256+
},
257+
// S3-compatible storage (R2, S3, MinIO)
258+
s3: {
259+
endpoint: process.env.R2_ENDPOINT,
260+
accessKeyId: process.env.R2_ACCESS_KEY_ID,
261+
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY,
262+
bucket: process.env.R2_BUCKET,
263+
publicUrlBase: process.env.R2_PUBLIC_URL,
264+
},
265+
// Auto-upload threshold (bytes)
266+
uploadThreshold: 1024,
267+
// Default storage for large payloads
268+
defaultStorage: 's3', // 'ipfs' | 's3' | 'data'
269+
});
270+
271+
// Resolve PayloadData from various URI schemes
272+
const { content, verified } = await resolver.resolve(payloadData);
273+
// Supports: data:, ipfs://, https://, http://
274+
275+
// Encode output (auto-uploads if > threshold)
276+
const outputPayload = await resolver.encode(outputContent);
277+
```
278+
279+
**Supported URI Schemes:**
280+
- `data:` - Inline base64-encoded data
281+
- `ipfs://` - IPFS content addressing
282+
- `https://` / `http://` - HTTP(S) URLs
283+
284+
**Storage Backends:**
285+
- `IpfsStorage` - Pinata IPFS pinning service
286+
- `S3Storage` - S3-compatible storage (AWS S3, Cloudflare R2, MinIO)
287+
- `DataUriStorage` - Inline data URI encoding
288+
- `HttpStorage` - HTTP(S) fetch
289+
208290
## Usage Examples
209291

210292
### Running a Compute Agent
@@ -324,6 +406,18 @@ RPC_URL=https://...
324406
# Optional
325407
WS_URL=wss://...
326408
WALLET_FACTORY_ADDRESS=0x...
409+
410+
# Payload Storage (S3/R2)
411+
R2_ENDPOINT=https://xxx.r2.cloudflarestorage.com
412+
R2_ACCESS_KEY_ID=your-access-key
413+
R2_SECRET_ACCESS_KEY=your-secret-key
414+
R2_BUCKET=your-bucket
415+
R2_PUBLIC_URL=https://pub-xxx.r2.dev
416+
417+
# Payload Storage (IPFS/Pinata)
418+
PINATA_API_KEY=your-api-key
419+
PINATA_API_SECRET=your-api-secret
420+
IPFS_GATEWAY=https://gateway.pinata.cloud/ipfs/
327421
```
328422

329423
### Keystore Structure

docker/docker-compose.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# =============================================================================
2+
# Noosphere SDK - Local Verdaccio Registry
3+
# =============================================================================
4+
#
5+
# Local npm registry for SDK development and testing.
6+
# Allows publishing @noosphere/* packages locally before pushing to npm.
7+
#
8+
# Usage:
9+
# # Start Verdaccio
10+
# docker compose -f docker/docker-compose.yml up -d
11+
#
12+
# # Publish SDK packages
13+
# ./scripts/publish-local.sh
14+
#
15+
# # Stop Verdaccio
16+
# docker compose -f docker/docker-compose.yml down
17+
#
18+
# Access:
19+
# Registry: http://localhost:4873
20+
# Web UI: http://localhost:4873 (browser)
21+
#
22+
# =============================================================================
23+
24+
services:
25+
verdaccio:
26+
image: verdaccio/verdaccio:5
27+
container_name: noosphere-verdaccio
28+
ports:
29+
- "4873:4873"
30+
volumes:
31+
- ./verdaccio/config.yaml:/verdaccio/conf/config.yaml:ro
32+
- verdaccio-storage:/verdaccio/storage
33+
healthcheck:
34+
test: ["CMD", "sh", "-c", "wget -q --spider http://localhost:4873/-/ping || exit 1"]
35+
interval: 10s
36+
timeout: 5s
37+
retries: 3
38+
39+
volumes:
40+
verdaccio-storage:

docker/verdaccio/config.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# =============================================================================
2+
# Verdaccio - Local npm Registry Configuration
3+
# =============================================================================
4+
#
5+
# This configuration enables a local npm registry for development/testing.
6+
# @noosphere/* packages are served locally, all others proxy to npmjs.
7+
#
8+
# =============================================================================
9+
10+
storage: /verdaccio/storage
11+
plugins: /verdaccio/plugins
12+
13+
web:
14+
title: Noosphere Local Registry
15+
enable: true
16+
17+
auth:
18+
htpasswd:
19+
file: /verdaccio/storage/htpasswd
20+
max_users: 100
21+
22+
uplinks:
23+
npmjs:
24+
url: https://registry.npmjs.org/
25+
cache: true
26+
27+
packages:
28+
# @noosphere/* packages - local only, no proxy
29+
'@noosphere/*':
30+
access: $all
31+
publish: $all
32+
unpublish: $all
33+
# Don't proxy to npmjs - use local only
34+
35+
# All other packages - proxy to npmjs
36+
'**':
37+
access: $all
38+
publish: $authenticated
39+
unpublish: $authenticated
40+
proxy: npmjs
41+
42+
# Logging
43+
logs:
44+
- { type: stdout, format: pretty, level: info }
45+
46+
# Listen on all interfaces
47+
listen:
48+
- 0.0.0.0:4873
49+
50+
# Max body size for publishing
51+
max_body_size: 100mb

0 commit comments

Comments
 (0)