@trusset/sdk 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/README.md +246 -0
- package/dist/index.d.mts +488 -0
- package/dist/index.d.ts +488 -0
- package/dist/index.js +606 -0
- package/dist/index.mjs +570 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# @trusset/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Trusset tokenization infrastructure API. Built for financial institutions, banks, and fintechs integrating MiCA/eWpG-compliant tokenized asset management.
|
|
4
|
+
|
|
5
|
+
Zero dependencies. Works in Node.js 18+ and modern runtimes with native `fetch`.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @trusset/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires an API key from your Trusset instance dashboard. Each API key is scoped to a single instance (isolated environment with its own data, contracts, and network config).
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { TrussetClient } from '@trusset/sdk'
|
|
17
|
+
|
|
18
|
+
const trusset = new TrussetClient({
|
|
19
|
+
apiKey: 'tsk_live_...',
|
|
20
|
+
// baseUrl defaults to https://api.trusset.org
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Modules
|
|
25
|
+
|
|
26
|
+
The SDK currently ships the `customers` module. Tokenization, trading, and lending modules will follow.
|
|
27
|
+
|
|
28
|
+
### customers.manage - CRUD and search
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// Create a customer (with or without a wallet)
|
|
32
|
+
const customer = await trusset.customers.manage.create({
|
|
33
|
+
name: 'Acme GmbH',
|
|
34
|
+
country: 'DE',
|
|
35
|
+
investorType: 'PROFESSIONAL',
|
|
36
|
+
externalId: 'your-internal-id-123',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// The customer gets a referenceKey if no wallet was provided.
|
|
40
|
+
// Link a wallet later:
|
|
41
|
+
await trusset.customers.manage.linkWallet({
|
|
42
|
+
referenceKey: customer.referenceKey!,
|
|
43
|
+
walletAddress: '0x...',
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Search
|
|
47
|
+
const byName = await trusset.customers.manage.searchByName('Acme')
|
|
48
|
+
const byWallet = await trusset.customers.manage.searchByWallet('0x...')
|
|
49
|
+
const byExtId = await trusset.customers.manage.searchByExternalId('your-internal-id-123')
|
|
50
|
+
|
|
51
|
+
// List with pagination
|
|
52
|
+
const page = await trusset.customers.manage.list({ limit: 50, offset: 0, search: 'bank' })
|
|
53
|
+
|
|
54
|
+
// Update
|
|
55
|
+
await trusset.customers.manage.update(customer.id, { country: 'AT' })
|
|
56
|
+
|
|
57
|
+
// Archive
|
|
58
|
+
await trusset.customers.manage.archive(customer.id)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### customers.identity - On-chain KYC
|
|
62
|
+
|
|
63
|
+
All write operations require a configured relayer wallet on the instance. The relayer signs transactions against the IdentityRegistry contract (UUPS upgradeable, MiCA/eWpG compliant).
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// Verify a single identity on-chain
|
|
67
|
+
const result = await trusset.customers.identity.verify({
|
|
68
|
+
walletAddress: '0x...',
|
|
69
|
+
country: 'DE',
|
|
70
|
+
investorType: 'RETAIL',
|
|
71
|
+
softExpiryDays: 365,
|
|
72
|
+
hardExpiryDays: 730,
|
|
73
|
+
})
|
|
74
|
+
// result.txHash, result.gasUsed
|
|
75
|
+
|
|
76
|
+
// Batch verify up to 500 identities in one transaction
|
|
77
|
+
await trusset.customers.identity.batchVerify([
|
|
78
|
+
{ walletAddress: '0xaaa...', country: 'DE' },
|
|
79
|
+
{ walletAddress: '0xbbb...', country: 'FR', investorType: 'PROFESSIONAL' },
|
|
80
|
+
])
|
|
81
|
+
|
|
82
|
+
// Revoke
|
|
83
|
+
await trusset.customers.identity.revoke('0x...')
|
|
84
|
+
|
|
85
|
+
// Get combined on-chain + off-chain status
|
|
86
|
+
const status = await trusset.customers.identity.getStatus('0x...')
|
|
87
|
+
// status.onChain.isVerified, status.offChain.status
|
|
88
|
+
|
|
89
|
+
// Compliance check before a token transfer
|
|
90
|
+
const check = await trusset.customers.identity.canTransfer({
|
|
91
|
+
from: '0xaaa...',
|
|
92
|
+
to: '0xbbb...',
|
|
93
|
+
amount: '1000000000000000000',
|
|
94
|
+
fromBalance: '5000000000000000000',
|
|
95
|
+
toBalance: '0',
|
|
96
|
+
})
|
|
97
|
+
// check.allowed, check.reason, check.senderStatus, check.receiverStatus
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### customers.idLinks - KYC verification links
|
|
101
|
+
|
|
102
|
+
Send Sumsub-powered KYC verification links to investors via email or SMS.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const link = await trusset.customers.idLinks.create({
|
|
106
|
+
recipientEmail: 'investor@example.com',
|
|
107
|
+
investorType: 'RETAIL',
|
|
108
|
+
country: 'DE',
|
|
109
|
+
expiryDays: 30,
|
|
110
|
+
sendVia: ['email'],
|
|
111
|
+
})
|
|
112
|
+
// link.verificationUrl, link.token
|
|
113
|
+
|
|
114
|
+
const links = await trusset.customers.idLinks.list({ status: 'PENDING' })
|
|
115
|
+
await trusset.customers.idLinks.revoke(link.id)
|
|
116
|
+
await trusset.customers.idLinks.resend(link.id, ['email'])
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### customers.sync - Database synchronization
|
|
120
|
+
|
|
121
|
+
The sync module is built for institutions migrating existing customer databases into Trusset. It handles batched upserts, conflict resolution, and optional on-chain verification in a single call.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { SyncRecord } from '@trusset/sdk'
|
|
125
|
+
|
|
126
|
+
// Map your existing database rows to SyncRecord
|
|
127
|
+
const records: SyncRecord[] = existingCustomers.map(row => ({
|
|
128
|
+
externalId: row.id, // Your system's unique ID
|
|
129
|
+
name: row.fullName,
|
|
130
|
+
walletAddress: row.ethAddress, // Optional
|
|
131
|
+
country: row.countryCode,
|
|
132
|
+
investorType: 'RETAIL',
|
|
133
|
+
metadata: { source: 'legacy-crm' },
|
|
134
|
+
}))
|
|
135
|
+
|
|
136
|
+
const result = await trusset.customers.sync.importRecords(records, {
|
|
137
|
+
batchSize: 50,
|
|
138
|
+
onConflict: 'update', // 'skip' or 'update'
|
|
139
|
+
verifyOnChain: true, // Also verify wallets on IdentityRegistry
|
|
140
|
+
verificationDefaults: {
|
|
141
|
+
softExpiryDays: 365,
|
|
142
|
+
hardExpiryDays: 730,
|
|
143
|
+
},
|
|
144
|
+
onProgress: (done, total) => {
|
|
145
|
+
console.log(`Synced ${done}/${total}`)
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// result.created, result.updated, result.skipped, result.errors
|
|
150
|
+
|
|
151
|
+
// Export back to your system
|
|
152
|
+
const exported = await trusset.customers.sync.exportRecords()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Error handling
|
|
156
|
+
|
|
157
|
+
All errors extend `TrussetError` and carry machine-readable codes.
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { TrussetError, AuthError, ValidationError, NetworkError } from '@trusset/sdk'
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
await trusset.customers.manage.get('0xinvalid')
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (err instanceof AuthError) {
|
|
166
|
+
// API key invalid or expired
|
|
167
|
+
}
|
|
168
|
+
if (err instanceof ValidationError) {
|
|
169
|
+
// Bad input, check err.message
|
|
170
|
+
}
|
|
171
|
+
if (err instanceof TrussetError) {
|
|
172
|
+
// err.code, err.statusCode, err.requestId
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The HTTP layer retries transient errors (408, 429, 5xx, network failures) with exponential backoff. Default: 3 retries, 30s timeout. Override via config:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
new TrussetClient({
|
|
181
|
+
apiKey: '...',
|
|
182
|
+
timeoutMs: 60_000,
|
|
183
|
+
maxRetries: 5,
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Configuration
|
|
188
|
+
|
|
189
|
+
| Option | Type | Default | Description |
|
|
190
|
+
|---|---|---|---|
|
|
191
|
+
| `apiKey` | `string` | required | Instance API key from dashboard |
|
|
192
|
+
| `baseUrl` | `string` | `https://api.trusset.org` | API base URL |
|
|
193
|
+
| `timeoutMs` | `number` | `30000` | Request timeout in ms |
|
|
194
|
+
| `maxRetries` | `number` | `3` | Retries on transient failures |
|
|
195
|
+
| `logger` | `Logger` | silent | Custom logger implementing `debug/info/warn/error` |
|
|
196
|
+
|
|
197
|
+
## Architecture
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
src/
|
|
201
|
+
index.ts Public exports
|
|
202
|
+
client.ts TrussetClient entry point
|
|
203
|
+
types/
|
|
204
|
+
common.ts Shared types (config, API envelope, pagination)
|
|
205
|
+
customers.ts All customer-related types and interfaces
|
|
206
|
+
modules/
|
|
207
|
+
customers/
|
|
208
|
+
index.ts Customers facade (combines sub-modules)
|
|
209
|
+
management.ts CRUD, search, wallet linking
|
|
210
|
+
identity.ts On-chain verification, compliance checks
|
|
211
|
+
id-links.ts KYC verification link management
|
|
212
|
+
sync.ts Bulk database import/export
|
|
213
|
+
utils/
|
|
214
|
+
http.ts HTTP client with retries and error mapping
|
|
215
|
+
errors.ts Error class hierarchy
|
|
216
|
+
validation.ts Input validation helpers
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The SDK is structured so additional product modules (tokenization, trading, lending) slot in as sibling directories under `modules/`. Each module receives the shared `HttpClient` instance and exposes a clean public API.
|
|
220
|
+
|
|
221
|
+
## Compatibility
|
|
222
|
+
|
|
223
|
+
- **TypeScript / ESM** - primary target, full type safety
|
|
224
|
+
- **Node.js / CommonJS** - dual CJS/ESM build via tsup
|
|
225
|
+
- **Java / Python** - the SDK calls a standard REST API with JSON over HTTPS. Any HTTP client in any language works. Typed wrappers for Java and Python are planned.
|
|
226
|
+
|
|
227
|
+
## Build
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
npm install
|
|
231
|
+
npm run build # outputs to dist/
|
|
232
|
+
npm run typecheck # type validation
|
|
233
|
+
npm run test # vitest
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
MIT - Trusset UG
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
For future modules (tokenization, trading, lending) we*ll go as siblings:
|
|
242
|
+
└── modules/
|
|
243
|
+
├── customers/
|
|
244
|
+
├── tokenization/ # next
|
|
245
|
+
├── trading/ # next
|
|
246
|
+
└── lending/ # next
|