@hauska-sdk/core 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # Changelog - @hauska-sdk/core
2
+
3
+ All notable changes to the Core SDK will be documented in this file.
4
+
5
+ ## [0.1.0] - 2025-02-03
6
+
7
+ ### Added
8
+ - Initial release of unified CNS Protocol Core SDK
9
+ - `CNSSDK` class combining Payment, VDA, Retrieval, and Wallet modules
10
+ - Automatic wallet creation and management
11
+ - `purchaseAndMintVDA()` method for combined payment and VDA minting
12
+ - `createDataRoom()` method for creating VDAs with documents and access passes
13
+ - `retrieveDocument()` method with full access control
14
+ - Comprehensive error handling with custom error types (`SDKError`, `PaymentError`, `VDAError`, `RetrievalError`, `WalletError`, `ConfigurationError`)
15
+ - Logging hooks (`LogHook`) for monitoring and debugging
16
+ - Metrics hooks (`MetricsHook`) for analytics
17
+ - Complete flow examples (architect invoice, data room, healthcare, real estate)
18
+ - Full documentation (README, getting started, API reference, examples, troubleshooting)
19
+
20
+ ### Documentation
21
+ - Comprehensive README with installation and quick start
22
+ - Getting started guide with step-by-step setup
23
+ - Complete API reference
24
+ - Real-world usage examples
25
+ - Troubleshooting guide
26
+
27
+ ---
28
+
29
+ [0.1.0]: https://github.com/hauska-sdk/hauska-sdk/releases/tag/@hauska-sdk/core@0.1.0
package/README.md ADDED
@@ -0,0 +1,263 @@
1
+ # @hauska-sdk/core
2
+
3
+ **CNS Protocol Core SDK** - Unified SDK for Payment, VDA, and Document Retrieval
4
+
5
+ The CNS Protocol Core SDK provides a single, unified interface for all CNS Protocol functionality, combining Payment, VDA (Verified Digital Assets), Document Retrieval, and Wallet Management into one easy-to-use package.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @hauska-sdk/core
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { CNSSDK } from "@hauska-sdk/core";
17
+ import { PostgreSQLStorageAdapter } from "@hauska-sdk/adapters-storage-postgres";
18
+
19
+ // Initialize SDK
20
+ const sdk = new CNSSDK({
21
+ vda: {
22
+ storageAdapter: new PostgreSQLStorageAdapter({
23
+ connectionString: process.env.DATABASE_URL!,
24
+ }),
25
+ },
26
+ payment: {
27
+ storage: new PostgreSQLStorageAdapter({
28
+ connectionString: process.env.DATABASE_URL!,
29
+ }),
30
+ blockchain: {
31
+ chain: "base",
32
+ token: "USDC",
33
+ facilitatorWallet: "0xYourFacilitatorWallet",
34
+ baseRpcUrl: "https://mainnet.base.org",
35
+ },
36
+ },
37
+ retrieval: {
38
+ pinata: {
39
+ pinataJwt: process.env.PINATA_JWT!,
40
+ pinataGateway: "https://gateway.pinata.cloud",
41
+ },
42
+ },
43
+ });
44
+
45
+ // Create a data room with document
46
+ const dataRoom = await sdk.createDataRoom({
47
+ ownerWallet: {
48
+ userId: "owner-123",
49
+ password: "secure-password",
50
+ },
51
+ vdaParams: {
52
+ assetType: "deed",
53
+ address: "123 Main St, Schertz, TX 78154",
54
+ spoke: "real-estate",
55
+ },
56
+ document: {
57
+ content: Buffer.from("Property documents..."),
58
+ name: "property-deed.pdf",
59
+ encrypt: true,
60
+ },
61
+ accessPass: {
62
+ recipientWallet: {
63
+ userId: "buyer-456",
64
+ password: "buyer-password",
65
+ },
66
+ permissions: ["view", "download"],
67
+ expiry: Date.now() + 30 * 24 * 3600000, // 30 days
68
+ },
69
+ });
70
+
71
+ console.log(`Data room created: ${dataRoom.vda.id}`);
72
+ console.log(`Document uploaded: ${dataRoom.document?.cid}`);
73
+ ```
74
+
75
+ ## Features
76
+
77
+ ### 🎯 Unified API
78
+ - Single entry point for all CNS Protocol functionality
79
+ - Automatic wallet management
80
+ - Seamless integration between Payment, VDA, and Retrieval modules
81
+
82
+ ### 💰 Payment Processing
83
+ - HTTP 402 Payment Required protocol (x402)
84
+ - Crypto payment verification (USDC on Base L2)
85
+ - Fiat payment support (via Circle API)
86
+ - Automatic payment recording and audit trails
87
+
88
+ ### 🏷️ VDA Management
89
+ - Mint Verified Digital Assets (metadata-only ownership proofs)
90
+ - Create and manage access passes
91
+ - Transfer ownership
92
+ - Cross-spoke search (real-estate, healthcare, architect, etc.)
93
+
94
+ ### 📄 Document Retrieval
95
+ - IPFS document upload/download via Pinata
96
+ - AES-256-GCM encryption
97
+ - Gated access control (VDA ownership or access passes)
98
+ - PDF watermarking for access pass viewers
99
+ - Access logging and analytics
100
+
101
+ ### 🔐 Wallet Management
102
+ - Automatic wallet creation per user
103
+ - Secure wallet encryption
104
+ - EIP-712 signing support
105
+
106
+ ## Core Concepts
107
+
108
+ ### Verified Digital Assets (VDAs)
109
+ VDAs are metadata-only ownership proofs, not tokens or NFTs. They represent ownership of real-world assets (properties, medical records, blueprints, etc.) without tokenization.
110
+
111
+ ### Access Passes
112
+ Time-bound VDAs that grant temporary, permissioned access to other VDAs. Perfect for data rooms, medical record sharing, and document collaboration.
113
+
114
+ ### Spokes
115
+ Industry verticals (e.g., `real-estate`, `healthcare`, `architect`). Each spoke can have its own metadata schema while sharing universal metadata keys (`address`, `legalDesc`, `patientId`, `api14`).
116
+
117
+ ### Universal Metadata
118
+ Standardized metadata keys that enable cross-spoke search:
119
+ - `address` - Physical address (real estate)
120
+ - `legalDesc` - Legal description (real estate)
121
+ - `patientId` - Patient identifier (healthcare)
122
+ - `api14` - API 14 identifier (oil & gas)
123
+
124
+ ## Documentation
125
+
126
+ - [Getting Started Guide](./docs/getting-started.md) - Step-by-step setup and first steps
127
+ - [API Reference](./docs/api-reference.md) - Complete API documentation
128
+ - [Examples](./docs/examples.md) - Real-world usage examples
129
+ - [Troubleshooting](./docs/troubleshooting.md) - Common issues and solutions
130
+
131
+ ## Examples
132
+
133
+ ### Architect Invoice Flow
134
+ ```typescript
135
+ import { architectInvoiceFlow } from "@hauska-sdk/core/examples/architect-invoice-flow";
136
+
137
+ // Complete flow: Create invoice → Payment → Transfer blueprint
138
+ const result = await architectInvoiceFlow();
139
+ ```
140
+
141
+ ### Data Room Creation
142
+ ```typescript
143
+ // Create a data room with encrypted documents
144
+ const dataRoom = await sdk.createDataRoom({
145
+ ownerWallet: { userId: "owner", password: "pass" },
146
+ vdaParams: {
147
+ assetType: "deed",
148
+ address: "123 Main St",
149
+ spoke: "real-estate",
150
+ },
151
+ document: {
152
+ content: Buffer.from("..."),
153
+ encrypt: true,
154
+ },
155
+ });
156
+ ```
157
+
158
+ ### Purchase and Mint VDA
159
+ ```typescript
160
+ // Purchase and mint a VDA in a single operation
161
+ const result = await sdk.purchaseAndMintVDA({
162
+ wallet: { userId: "user", password: "pass" },
163
+ amount: "5000",
164
+ currency: "USDC",
165
+ method: "crypto",
166
+ vdaParams: {
167
+ assetType: "blueprint",
168
+ address: "123 Main St",
169
+ spoke: "architect",
170
+ },
171
+ });
172
+ ```
173
+
174
+ See [Examples Guide](./docs/examples.md) for more complete examples.
175
+
176
+ ## Error Handling
177
+
178
+ The SDK uses structured error types for better error handling:
179
+
180
+ ```typescript
181
+ import {
182
+ SDKError,
183
+ PaymentError,
184
+ VDAError,
185
+ RetrievalError,
186
+ WalletError,
187
+ ConfigurationError,
188
+ isSDKError,
189
+ isRetryableError,
190
+ } from "@hauska-sdk/core";
191
+
192
+ try {
193
+ await sdk.purchaseAndMintVDA({ /* ... */ });
194
+ } catch (error) {
195
+ if (isSDKError(error)) {
196
+ console.error(`Error code: ${error.code}`);
197
+ console.error(`Context:`, error.context);
198
+
199
+ if (isRetryableError(error)) {
200
+ // Retry logic
201
+ }
202
+ }
203
+ }
204
+ ```
205
+
206
+ See [Error Handling](./docs/api-reference.md#error-handling) for more details.
207
+
208
+ ## Logging and Monitoring
209
+
210
+ The SDK supports logging and metrics hooks for monitoring:
211
+
212
+ ```typescript
213
+ const sdk = new CNSSDK({
214
+ // ... config
215
+ logHook: (level, message, data) => {
216
+ console.log(`[${level}] ${message}`, data);
217
+ },
218
+ metricsHook: (event, data) => {
219
+ // Send to your analytics service
220
+ analytics.track(event, data);
221
+ },
222
+ });
223
+ ```
224
+
225
+ ## Adapters
226
+
227
+ The SDK uses adapters for storage, blockchain, and IPFS:
228
+
229
+ ### Storage Adapters
230
+ - `@hauska-sdk/adapters-storage-postgres` - PostgreSQL (production)
231
+ - `@hauska-sdk/adapters-storage-redis` - Redis caching layer
232
+ - `@hauska-sdk/adapters-storage-mock` - In-memory (testing)
233
+
234
+ ### Blockchain Adapters
235
+ - `@hauska-sdk/adapters-blockchain-ethers` - Ethers.js (Base L2)
236
+
237
+ ### IPFS Adapters
238
+ - Pinata (via `@hauska-sdk/retrieval`)
239
+
240
+ ## Requirements
241
+
242
+ - Node.js 18+
243
+ - TypeScript 5.3+
244
+ - PostgreSQL (for production storage)
245
+ - Pinata account (for IPFS storage)
246
+ - Base L2 RPC endpoint (for blockchain operations)
247
+
248
+ ## License
249
+
250
+ MIT
251
+
252
+ ## Related Packages
253
+
254
+ - [`@hauska-sdk/payment`](../payment/README.md) - Payment SDK
255
+ - [`@hauska-sdk/vda`](../vda/README.md) - VDA SDK
256
+ - [`@hauska-sdk/retrieval`](../retrieval/README.md) - Retrieval SDK
257
+ - [`@hauska-sdk/wallet`](../wallet/README.md) - Wallet Management
258
+
259
+ ## Support
260
+
261
+ - [GitHub Issues](https://github.com/hauska-sdk/issues)
262
+ - [Documentation](https://docs.hauska-sdk.com)
263
+ - [Discord](https://discord.gg/hauska-sdk)
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @hauska-sdk/core
3
+ * Unified CNS SDK - Main entry point
4
+ */
5
+ import { WalletManager } from "@hauska-sdk/wallet";
6
+ import { PaymentSDK } from "@hauska-sdk/payment";
7
+ import { VDASDK } from "@hauska-sdk/vda";
8
+ import { RetrievalSDK } from "@hauska-sdk/retrieval";
9
+ import type { CNSSDKConfig, WalletOptions, PurchaseAndMintVDAOptions, CreateDataRoomOptions, RetrieveDocumentOptions } from "./types";
10
+ import type { PaymentRecord } from "@hauska-sdk/payment";
11
+ import type { VDA } from "@hauska-sdk/vda";
12
+ import type { UploadDocumentResult } from "@hauska-sdk/retrieval";
13
+ /**
14
+ * Unified CNS SDK
15
+ *
16
+ * Main entry point for all CNS Protocol functionality:
17
+ * - Payment processing (x402 protocol)
18
+ * - VDA management (Verified Digital Assets)
19
+ * - Document retrieval (IPFS with gated access)
20
+ * - Wallet management (automatic wallet creation)
21
+ */
22
+ export declare class CNSSDK {
23
+ private config;
24
+ private walletManager;
25
+ private paymentSDK;
26
+ private vdaSDK;
27
+ private retrievalSDK;
28
+ private anchoring?;
29
+ constructor(config: CNSSDKConfig);
30
+ /**
31
+ * Initialize all SDK modules
32
+ */
33
+ private initialize;
34
+ /**
35
+ * Get or create a wallet for a user
36
+ *
37
+ * @param options - Wallet options
38
+ * @returns Wallet instance
39
+ */
40
+ getOrCreateWallet(options: WalletOptions): Promise<import("@hauska-sdk/wallet").Wallet>;
41
+ /**
42
+ * Purchase and mint a VDA in a single operation
43
+ *
44
+ * This method:
45
+ * 1. Gets or creates a wallet for the user
46
+ * 2. Processes the payment
47
+ * 3. Records the payment
48
+ * 4. Mints the VDA
49
+ *
50
+ * @param options - Purchase and mint options
51
+ * @returns Object containing payment record and VDA
52
+ */
53
+ purchaseAndMintVDA(options: PurchaseAndMintVDAOptions): Promise<{
54
+ payment: PaymentRecord;
55
+ vda: VDA;
56
+ wallet: {
57
+ address: string;
58
+ };
59
+ }>;
60
+ /**
61
+ * Create a data room (VDA + optional document + optional access pass)
62
+ *
63
+ * This method:
64
+ * 1. Gets or creates a wallet for the owner
65
+ * 2. Mints a VDA for the data room
66
+ * 3. Optionally uploads a document to IPFS
67
+ * 4. Optionally creates an access pass
68
+ *
69
+ * @param options - Data room creation options
70
+ * @returns Object containing VDA, document (if uploaded), and access pass (if created)
71
+ */
72
+ createDataRoom(options: CreateDataRoomOptions): Promise<{
73
+ vda: VDA;
74
+ document?: UploadDocumentResult;
75
+ accessPass?: VDA;
76
+ }>;
77
+ /**
78
+ * Retrieve a document with access verification
79
+ *
80
+ * This method:
81
+ * 1. Gets or creates a wallet for the requester
82
+ * 2. Verifies access to the document (VDA ownership or access pass)
83
+ * 3. Retrieves the document from IPFS
84
+ * 4. Optionally decrypts and watermarks the document
85
+ *
86
+ * @param options - Document retrieval options
87
+ * @returns Document content as Buffer
88
+ */
89
+ retrieveDocument(options: RetrieveDocumentOptions): Promise<Buffer>;
90
+ /**
91
+ * Get the underlying Payment SDK instance
92
+ */
93
+ getPaymentSDK(): PaymentSDK;
94
+ /**
95
+ * Get the underlying VDA SDK instance
96
+ */
97
+ getVDASDK(): VDASDK;
98
+ /**
99
+ * Get the underlying Retrieval SDK instance
100
+ */
101
+ getRetrievalSDK(): RetrievalSDK;
102
+ /**
103
+ * Get the wallet manager instance
104
+ */
105
+ getWalletManager(): WalletManager;
106
+ /**
107
+ * Log a message using the configured log hook
108
+ */
109
+ private log;
110
+ /**
111
+ * Emit a metrics event using the configured metrics hook
112
+ */
113
+ private metrics;
114
+ }
115
+ //# sourceMappingURL=CNSSDK.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CNSSDK.d.ts","sourceRoot":"","sources":["../src/CNSSDK.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAIlE;;;;;;;;GAQG;AACH,qBAAa,MA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