@hsuite/smart-engines-sdk 3.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/CHANGELOG.md +20 -0
- package/README.md +373 -0
- package/dist/index.d.ts +2881 -0
- package/dist/index.js +4350 -0
- package/dist/index.js.map +1 -0
- package/dist/nestjs/index.d.ts +2341 -0
- package/dist/nestjs/index.js +3338 -0
- package/dist/nestjs/index.js.map +1 -0
- package/package.json +63 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 3.0.0 — 2026-05-11
|
|
4
|
+
|
|
5
|
+
**First publishable release.**
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
- The SDK is now self-contained: workspace-only dependencies (`@hsuite/smart-engines-multi-chain-core`, `@hsuite/smart-engines-shared`) have been vendored under `src/_vendor/` and are no longer required as runtime dependencies. Consumers no longer need access to the HSuite monorepo to install the SDK.
|
|
9
|
+
- Heavy peer-style dependencies (`@hashgraph/sdk`, `xrpl`, `@nestjs/common`, `@nestjs/core`, `zod`) are now declared as `peerDependencies` — apps must install them directly.
|
|
10
|
+
- Build pipeline switched from raw `tsc` to `tsup` (CJS bundle) + `dts-bundle-generator` (single-file `.d.ts`).
|
|
11
|
+
|
|
12
|
+
### Bundle
|
|
13
|
+
- `dist/index.js` — 134 KB CJS bundle of the validator / gateway / BaaS clients + auth/discovery + chain helpers + resilience primitives.
|
|
14
|
+
- `dist/index.d.ts` — single-file TypeScript declarations.
|
|
15
|
+
- `dist/nestjs/index.{js,d.ts}` — NestJS module integration.
|
|
16
|
+
|
|
17
|
+
### Publishing
|
|
18
|
+
```
|
|
19
|
+
npm publish --access=public
|
|
20
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# @hsuite/smart-engines-sdk
|
|
2
|
+
|
|
3
|
+
Type-safe client SDK for Smart Engines multi-chain infrastructure. Build decentralized apps across Hedera, XRPL, Ethereum, Polygon, Solana, Polkadot, Stellar, and Bitcoin.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @hsuite/smart-engines-sdk
|
|
9
|
+
# or
|
|
10
|
+
npm install @hsuite/smart-engines-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { SmartEngineClient } from '@hsuite/smart-engines-sdk';
|
|
17
|
+
|
|
18
|
+
// Connect to a validator
|
|
19
|
+
const client = new SmartEngineClient({
|
|
20
|
+
baseUrl: 'https://v3-testnet-sn1.hsuite.network',
|
|
21
|
+
apiKey: 'your-api-key',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Check health
|
|
25
|
+
const health = await client.getHealth();
|
|
26
|
+
console.log(health.status); // 'ok'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Auto-Discovery with Authentication
|
|
30
|
+
|
|
31
|
+
Connect to the network automatically via HCS registry:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { SmartEngineClient } from '@hsuite/smart-engines-sdk';
|
|
35
|
+
import { PrivateKey } from '@hashgraph/sdk';
|
|
36
|
+
|
|
37
|
+
const privateKey = PrivateKey.fromString(process.env.HEDERA_PRIVATE_KEY!);
|
|
38
|
+
|
|
39
|
+
const { client, validator, session } = await SmartEngineClient.connectToNetwork({
|
|
40
|
+
network: 'testnet',
|
|
41
|
+
registryTopicId: process.env.REGISTRY_TOPIC_ID!,
|
|
42
|
+
chain: 'hedera',
|
|
43
|
+
address: process.env.HEDERA_ACCOUNT_ID!,
|
|
44
|
+
publicKey: privateKey.publicKey.toStringRaw(),
|
|
45
|
+
signFn: (challenge) => {
|
|
46
|
+
const sig = privateKey.sign(Buffer.from(challenge));
|
|
47
|
+
return Buffer.from(sig).toString('hex');
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log(`Connected to ${validator.operator} at ${validator.endpoint}`);
|
|
52
|
+
console.log(`Session expires: ${session.expiresAt}`);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API Reference
|
|
56
|
+
|
|
57
|
+
### Account Operations
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Create account
|
|
61
|
+
const account = await client.createAccount({
|
|
62
|
+
chain: 'hedera',
|
|
63
|
+
initialBalance: '10',
|
|
64
|
+
validatorTimestamp: '1766490325.123456789',
|
|
65
|
+
validatorTopicId: '0.0.98765',
|
|
66
|
+
});
|
|
67
|
+
console.log(`Account: ${account.accountId}`);
|
|
68
|
+
|
|
69
|
+
// Get account info
|
|
70
|
+
const info = await client.getAccountInfo('hedera', '0.0.12345');
|
|
71
|
+
|
|
72
|
+
// Get balance (native + tokens)
|
|
73
|
+
const balance = await client.getBalance('hedera', '0.0.12345');
|
|
74
|
+
console.log(`Balance: ${balance.balance} | Tokens: ${balance.tokens.length}`);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Token Operations
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Create a fungible token
|
|
81
|
+
const token = await client.createToken({
|
|
82
|
+
chain: 'hedera',
|
|
83
|
+
name: 'My Token',
|
|
84
|
+
symbol: 'MTK',
|
|
85
|
+
decimals: 8,
|
|
86
|
+
initialSupply: '1000000',
|
|
87
|
+
type: 'fungible',
|
|
88
|
+
validatorTimestamp: '1766490325.123456789',
|
|
89
|
+
validatorTopicId: '0.0.98765',
|
|
90
|
+
capabilities: {
|
|
91
|
+
mintable: true,
|
|
92
|
+
burnable: true,
|
|
93
|
+
pausable: true,
|
|
94
|
+
restrictable: true,
|
|
95
|
+
compliant: true,
|
|
96
|
+
wipeable: true,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
console.log(`Token: ${token.tokenId}`);
|
|
100
|
+
|
|
101
|
+
// Mint additional tokens
|
|
102
|
+
await client.mintToken({
|
|
103
|
+
chain: 'hedera',
|
|
104
|
+
tokenId: token.tokenId,
|
|
105
|
+
amount: '500000',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Burn tokens
|
|
109
|
+
await client.burnToken({
|
|
110
|
+
chain: 'hedera',
|
|
111
|
+
tokenId: token.tokenId,
|
|
112
|
+
amount: '100',
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Get token info
|
|
116
|
+
const tokenInfo = await client.getTokenInfo('hedera', token.tokenId);
|
|
117
|
+
console.log(`Supply: ${tokenInfo.totalSupply}`);
|
|
118
|
+
console.log(`Capabilities:`, tokenInfo.capabilities);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Token Management (Universal Actions)
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Pause all operations on a token
|
|
125
|
+
await client.pauseToken({ chain: 'hedera', tokenId: '0.0.123' });
|
|
126
|
+
await client.unpauseToken({ chain: 'hedera', tokenId: '0.0.123' });
|
|
127
|
+
|
|
128
|
+
// Freeze/unfreeze an account
|
|
129
|
+
await client.restrictAccount({ chain: 'hedera', tokenId: '0.0.123', accountId: '0.0.456' });
|
|
130
|
+
await client.unrestrictAccount({ chain: 'hedera', tokenId: '0.0.123', accountId: '0.0.456' });
|
|
131
|
+
|
|
132
|
+
// KYC grant/revoke
|
|
133
|
+
await client.enableCompliance({ chain: 'hedera', tokenId: '0.0.123', accountId: '0.0.456' });
|
|
134
|
+
await client.disableCompliance({ chain: 'hedera', tokenId: '0.0.123', accountId: '0.0.456' });
|
|
135
|
+
|
|
136
|
+
// Wipe tokens from account (compliance action)
|
|
137
|
+
await client.wipeFromAccount({ chain: 'hedera', tokenId: '0.0.123', accountId: '0.0.456', amount: '100' });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Transaction Operations
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// Transfer native currency
|
|
144
|
+
const tx = await client.transfer({
|
|
145
|
+
chain: 'hedera',
|
|
146
|
+
from: '0.0.12345',
|
|
147
|
+
to: '0.0.67890',
|
|
148
|
+
amount: '5.0',
|
|
149
|
+
});
|
|
150
|
+
console.log(`TX: ${tx.transactionId} Status: ${tx.status}`);
|
|
151
|
+
|
|
152
|
+
// Get transaction details
|
|
153
|
+
const details = await client.getTransaction('hedera', tx.transactionId);
|
|
154
|
+
|
|
155
|
+
// Get receipt
|
|
156
|
+
const receipt = await client.getTransactionReceipt('hedera', tx.transactionId);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Multi-Chain Examples
|
|
160
|
+
|
|
161
|
+
The same API works across all supported chains:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// Create accounts on different chains
|
|
165
|
+
const hederaAccount = await client.createAccount({ chain: 'hedera', initialBalance: '10', ... });
|
|
166
|
+
const xrplAccount = await client.createAccount({ chain: 'xrpl', initialBalance: '25', ... });
|
|
167
|
+
const ethAccount = await client.createAccount({ chain: 'ethereum', initialBalance: '0.1', ... });
|
|
168
|
+
const solAccount = await client.createAccount({ chain: 'solana', initialBalance: '1', ... });
|
|
169
|
+
|
|
170
|
+
// Check balances across chains
|
|
171
|
+
const chains = ['hedera', 'xrpl', 'ethereum', 'solana', 'polkadot', 'stellar', 'bitcoin'];
|
|
172
|
+
for (const chain of chains) {
|
|
173
|
+
const caps = await client.getChainCapabilities(chain);
|
|
174
|
+
console.log(`${chain}: tokens=${caps.hasTokens} nfts=${caps.hasNFTs} dex=${caps.hasDEX}`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Query capabilities
|
|
178
|
+
const allCaps = await client.getAllCapabilities();
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Consensus Messaging (Hedera HCS)
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Submit message to HCS topic
|
|
185
|
+
const result = await client.submitMessage('hedera', '0.0.98765', JSON.stringify({
|
|
186
|
+
type: 'governance.proposal',
|
|
187
|
+
data: { title: 'Increase validator cap', description: '...' },
|
|
188
|
+
}));
|
|
189
|
+
console.log(`Sequence: ${result.sequenceNumber}`);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Validator Management
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// List validator templates
|
|
196
|
+
const templates = await client.validators.listTemplates();
|
|
197
|
+
|
|
198
|
+
// Check validator health
|
|
199
|
+
const health = await client.validators.getHealth();
|
|
200
|
+
|
|
201
|
+
// Get validator info
|
|
202
|
+
const validatorInfo = await client.validators.getInfo();
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Subscription Management
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// Check subscription status
|
|
209
|
+
const status = await client.subscription.getStatus('my-app-id');
|
|
210
|
+
|
|
211
|
+
// Request subscription (deposits HSUITE tokens)
|
|
212
|
+
const sub = await client.subscription.request({
|
|
213
|
+
appId: 'my-app',
|
|
214
|
+
developerAccountId: '0.0.12345',
|
|
215
|
+
chain: 'hedera',
|
|
216
|
+
selectedTier: 'starter',
|
|
217
|
+
selectedNetworks: ['hedera'],
|
|
218
|
+
});
|
|
219
|
+
console.log(`Deposit to: ${sub.depositWallet} Amount: ${sub.amount}`);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### BaaS (Backend-as-a-Service)
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
import { BaasClient } from '@hsuite/smart-engines-sdk';
|
|
226
|
+
|
|
227
|
+
const baas = new BaasClient({
|
|
228
|
+
hostUrl: 'https://host.hsuite.network',
|
|
229
|
+
appId: 'my-app-id',
|
|
230
|
+
chain: 'hedera',
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// Authenticate with wallet
|
|
234
|
+
await baas.authenticate({
|
|
235
|
+
address: '0.0.12345',
|
|
236
|
+
signFn: async (challenge) => privateKey.sign(Buffer.from(challenge)).toString('hex'),
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// Database operations (with Merkle proofs)
|
|
240
|
+
const doc = await baas.database.insert('users', { name: 'Alice', role: 'admin' });
|
|
241
|
+
const users = await baas.database.find('users', { role: 'admin' });
|
|
242
|
+
const proof = await baas.database.getProof('users', doc.id); // Merkle proof
|
|
243
|
+
|
|
244
|
+
// Storage (IPFS-backed)
|
|
245
|
+
const file = await baas.storage.upload('data.json', Buffer.from(JSON.stringify(data)));
|
|
246
|
+
const download = await baas.storage.download(file.fileId);
|
|
247
|
+
|
|
248
|
+
// Serverless functions (Ed25519 code signing required)
|
|
249
|
+
await baas.functions.deploy({
|
|
250
|
+
name: 'process-payment',
|
|
251
|
+
runtime: 'nodejs',
|
|
252
|
+
signedCode: { code, signature, publicKey, timestamp, hash },
|
|
253
|
+
});
|
|
254
|
+
const result = await baas.functions.invoke('process-payment', { amount: 100 });
|
|
255
|
+
|
|
256
|
+
// Real-time messaging
|
|
257
|
+
await baas.messaging.publish('notifications', { type: 'payment', amount: 100 });
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Error Handling
|
|
261
|
+
|
|
262
|
+
All errors are instances of `SmartEngineError` with structured error codes:
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
import { SmartEngineError, ErrorCode } from '@hsuite/smart-engines-sdk';
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
await client.transfer({ chain: 'hedera', from: '0.0.1', to: '0.0.2', amount: '999999' });
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (error instanceof SmartEngineError) {
|
|
271
|
+
console.log(`Code: ${error.code}`); // e.g., 'INSUFFICIENT_BALANCE'
|
|
272
|
+
console.log(`Status: ${error.statusCode}`); // e.g., 400
|
|
273
|
+
console.log(`Retryable: ${error.isRetryable}`); // e.g., false
|
|
274
|
+
console.log(`Context:`, error.context); // e.g., { chain: 'hedera' }
|
|
275
|
+
|
|
276
|
+
switch (error.code) {
|
|
277
|
+
case ErrorCode.INSUFFICIENT_BALANCE:
|
|
278
|
+
console.log('Not enough funds');
|
|
279
|
+
break;
|
|
280
|
+
case ErrorCode.CHAIN_CONNECTION_ERROR:
|
|
281
|
+
console.log('Network issue — will retry');
|
|
282
|
+
if (error.isRetryable) { /* retry logic */ }
|
|
283
|
+
break;
|
|
284
|
+
case ErrorCode.RATE_LIMIT_EXCEEDED:
|
|
285
|
+
console.log('Too many requests — back off');
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Error Codes
|
|
293
|
+
|
|
294
|
+
| Code | Description | Retryable |
|
|
295
|
+
|------|-------------|-----------|
|
|
296
|
+
| `INSUFFICIENT_BALANCE` | Not enough native or token balance | No |
|
|
297
|
+
| `INVALID_ACCOUNT_ID` | Account doesn't exist or is deleted | No |
|
|
298
|
+
| `CHAIN_CONNECTION_ERROR` | Network/RPC connectivity issue | Yes |
|
|
299
|
+
| `CHAIN_TIMEOUT` | Request timed out | Yes |
|
|
300
|
+
| `RATE_LIMIT_EXCEEDED` | Too many requests | Yes |
|
|
301
|
+
| `INVALID_TRANSACTION` | Malformed or invalid transaction | No |
|
|
302
|
+
| `TRANSACTION_FAILED` | Transaction executed but failed | No |
|
|
303
|
+
| `CONTRACT_REVERT` | Smart contract execution reverted | No |
|
|
304
|
+
| `TOKEN_NOT_ASSOCIATED` | Token not associated to account (Hedera) | No |
|
|
305
|
+
| `TRUST_LINE_REQUIRED` | Trust line needed (XRPL/Stellar) | No |
|
|
306
|
+
| `INVALID_SIGNATURE` | Bad signature on transaction | No |
|
|
307
|
+
|
|
308
|
+
## NestJS Integration
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
import { Module } from '@nestjs/common';
|
|
312
|
+
import { SmartEngineModule } from '@hsuite/smart-engines-sdk';
|
|
313
|
+
|
|
314
|
+
@Module({
|
|
315
|
+
imports: [
|
|
316
|
+
SmartEngineModule.forRoot({
|
|
317
|
+
baseUrl: 'https://v3-testnet-sn1.hsuite.network',
|
|
318
|
+
apiKey: process.env.SMART_ENGINE_API_KEY,
|
|
319
|
+
}),
|
|
320
|
+
],
|
|
321
|
+
})
|
|
322
|
+
export class AppModule {}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Then inject:
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
import { Injectable } from '@nestjs/common';
|
|
329
|
+
import { SmartEngineService } from '@hsuite/smart-engines-sdk';
|
|
330
|
+
|
|
331
|
+
@Injectable()
|
|
332
|
+
export class PaymentService {
|
|
333
|
+
constructor(private readonly smartEngine: SmartEngineService) {}
|
|
334
|
+
|
|
335
|
+
async processPayment(from: string, to: string, amount: string) {
|
|
336
|
+
return this.smartEngine.client.transfer({
|
|
337
|
+
chain: 'hedera',
|
|
338
|
+
from,
|
|
339
|
+
to,
|
|
340
|
+
amount,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Async configuration:
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
SmartEngineModule.forRootAsync({
|
|
350
|
+
useFactory: (config: ConfigService) => ({
|
|
351
|
+
baseUrl: config.get('VALIDATOR_URL'),
|
|
352
|
+
apiKey: config.get('API_KEY'),
|
|
353
|
+
}),
|
|
354
|
+
inject: [ConfigService],
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Supported Chains
|
|
359
|
+
|
|
360
|
+
| Chain | Account Ops | Tokens | NFTs | Messaging | DEX | Multi-Sig |
|
|
361
|
+
|-------|------------|--------|------|-----------|-----|-----------|
|
|
362
|
+
| Hedera | ✅ | ✅ HTS | ✅ | ✅ HCS | — | ✅ TSS |
|
|
363
|
+
| XRPL | ✅ | ✅ Trust Lines | ✅ XLS-20 | — | ✅ Native | ✅ SignerList |
|
|
364
|
+
| Ethereum | ✅ | ✅ ERC-20 | — | — | — | ✅ Safe |
|
|
365
|
+
| Polygon | ✅ | ✅ ERC-20 | — | — | — | ✅ Safe |
|
|
366
|
+
| Solana | ✅ | ✅ SPL | ✅ Metaplex | — | — | ✅ Squads |
|
|
367
|
+
| Polkadot | ✅ | ✅ Assets | — | — | — | — |
|
|
368
|
+
| Stellar | ✅ | ✅ Assets | — | — | ✅ SDEX | — |
|
|
369
|
+
| Bitcoin | ✅ | — | — | — | — | — |
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
Proprietary — HSuite Trust
|