@aura-payments/sdk 2.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 +489 -0
- package/dist/index.d.mts +1292 -0
- package/dist/index.d.ts +1292 -0
- package/dist/index.js +1013 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +985 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
# @aura-payments/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Aura Payments Platform API. Build payment flows with multi-party escrows, Circle wallets, and real-time webhooks.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @aura-payments/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @aura-payments/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @aura-payments/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { AuraClient } from '@aura-payments/sdk'
|
|
19
|
+
|
|
20
|
+
const client = new AuraClient({
|
|
21
|
+
apiKey: process.env.AURA_API_KEY!,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Create a multi-party escrow
|
|
25
|
+
const escrow = await client.escrows.create({
|
|
26
|
+
orderId: 'order-123',
|
|
27
|
+
amountUsdc: '100.00',
|
|
28
|
+
splits: {
|
|
29
|
+
vendorEntityId: 'vendor-1',
|
|
30
|
+
sellerEntityId: 'seller-1',
|
|
31
|
+
platformEntityId: 'platform-1',
|
|
32
|
+
vendorPercentage: 70,
|
|
33
|
+
sellerPercentage: 20,
|
|
34
|
+
platformPercentage: 10,
|
|
35
|
+
},
|
|
36
|
+
adminSafeAddress: '0x...',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
console.log(`Escrow created: ${escrow.escrowId}`)
|
|
40
|
+
console.log(`Vault address: ${escrow.vaultAddress}`)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- **Type-Safe** - Full TypeScript support with comprehensive type definitions
|
|
46
|
+
- **Dual Module Support** - Works with ESM and CommonJS
|
|
47
|
+
- **Automatic Retries** - Exponential backoff with jitter for failed requests
|
|
48
|
+
- **Idempotency** - Automatic idempotency key generation for safe retries
|
|
49
|
+
- **Error Handling** - Typed error classes with type guards
|
|
50
|
+
- **Webhook Validation** - HMAC-SHA256 signature verification
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { AuraClient } from '@aura-payments/sdk'
|
|
56
|
+
|
|
57
|
+
const client = new AuraClient({
|
|
58
|
+
// Required: Your API key from the Aura dashboard
|
|
59
|
+
apiKey: 'ak_live_...',
|
|
60
|
+
|
|
61
|
+
// Optional: API base URL (default: https://api.aura-payments.com)
|
|
62
|
+
baseUrl: 'https://api.aura-payments.com',
|
|
63
|
+
|
|
64
|
+
// Optional: Request timeout in ms (default: 30000)
|
|
65
|
+
timeout: 30000,
|
|
66
|
+
|
|
67
|
+
// Optional: Max retry attempts (default: 3)
|
|
68
|
+
maxRetries: 3,
|
|
69
|
+
|
|
70
|
+
// Optional: Auto-generate idempotency keys (default: true)
|
|
71
|
+
autoIdempotency: true,
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
### Escrows
|
|
78
|
+
|
|
79
|
+
Escrows enable secure multi-party payments with configurable splits and release conditions.
|
|
80
|
+
|
|
81
|
+
#### Create Escrow
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const escrow = await client.escrows.create({
|
|
85
|
+
orderId: 'order-123',
|
|
86
|
+
amountUsdc: '100.00',
|
|
87
|
+
splits: {
|
|
88
|
+
vendorEntityId: 'vendor-uuid',
|
|
89
|
+
sellerEntityId: 'seller-uuid',
|
|
90
|
+
platformEntityId: 'platform-uuid',
|
|
91
|
+
vendorPercentage: 70,
|
|
92
|
+
sellerPercentage: 20,
|
|
93
|
+
platformPercentage: 10,
|
|
94
|
+
},
|
|
95
|
+
adminSafeAddress: '0x...',
|
|
96
|
+
unlock: {
|
|
97
|
+
type: 'timeout', // 'oracle' | 'timeout' | 'hybrid' | 'manual'
|
|
98
|
+
days: 14,
|
|
99
|
+
},
|
|
100
|
+
items: [
|
|
101
|
+
{
|
|
102
|
+
orderItemId: 'item-1',
|
|
103
|
+
description: 'Premium Widget',
|
|
104
|
+
amountUsdc: '100.00',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Get Escrow
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const escrow = await client.escrows.get('escrow-id')
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### List Escrows
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const { data, pagination } = await client.escrows.list({
|
|
120
|
+
page: 1,
|
|
121
|
+
limit: 20,
|
|
122
|
+
status: 'funded', // 'pending' | 'funded' | 'locked' | 'released' | 'refunded' | 'disputed'
|
|
123
|
+
orderId: 'order-123',
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Fund Escrow
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const funded = await client.escrows.fund({
|
|
131
|
+
escrowId: 'escrow-id',
|
|
132
|
+
fromEntityId: 'buyer-entity-id',
|
|
133
|
+
amountUsdc: '100.00',
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Release Escrow
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Full release
|
|
141
|
+
const released = await client.escrows.release({
|
|
142
|
+
escrowId: 'escrow-id',
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
// Partial release
|
|
146
|
+
const partialRelease = await client.escrows.release({
|
|
147
|
+
escrowId: 'escrow-id',
|
|
148
|
+
partial: {
|
|
149
|
+
itemIds: ['item-1', 'item-2'],
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// With multisig signature
|
|
154
|
+
const signedRelease = await client.escrows.release({
|
|
155
|
+
escrowId: 'escrow-id',
|
|
156
|
+
signature: {
|
|
157
|
+
digest: '0x...',
|
|
158
|
+
signature: '0x...',
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### Refund Escrow
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const refunded = await client.escrows.refund({
|
|
167
|
+
escrowId: 'escrow-id',
|
|
168
|
+
reason: 'vendor_reject', // 'vendor_reject' | 'sla_breach' | 'manual' | 'dispute_resolved'
|
|
169
|
+
toEntityId: 'buyer-entity-id',
|
|
170
|
+
amountUsdc: '50.00', // Optional: partial refund
|
|
171
|
+
})
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Disputes
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// Open a dispute
|
|
178
|
+
const dispute = await client.escrows.createDispute({
|
|
179
|
+
escrowId: 'escrow-id',
|
|
180
|
+
openedByEntityId: 'buyer-entity-id',
|
|
181
|
+
reason: 'Item not as described',
|
|
182
|
+
evidenceUrl: 'https://...',
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
// Get dispute details
|
|
186
|
+
const disputeDetails = await client.escrows.getDispute('escrow-id', 'dispute-id')
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Wallets
|
|
190
|
+
|
|
191
|
+
Manage Circle Developer-Controlled Wallets for your entities.
|
|
192
|
+
|
|
193
|
+
#### Create Wallet
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
const wallet = await client.wallets.create({
|
|
197
|
+
entityId: 'entity-uuid',
|
|
198
|
+
chain: 'ARC', // 'ARC' | 'ARB' | 'BASE' | 'ETH' | 'MATIC' | 'SOL'
|
|
199
|
+
type: 'developer_controlled', // 'developer_controlled' | 'user_controlled'
|
|
200
|
+
})
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Get Wallet
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
const wallet = await client.wallets.get('wallet-id')
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### List Wallets
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const { data, pagination } = await client.wallets.list({
|
|
213
|
+
entityId: 'entity-uuid',
|
|
214
|
+
chain: 'ARC',
|
|
215
|
+
type: 'developer_controlled',
|
|
216
|
+
page: 1,
|
|
217
|
+
limit: 20,
|
|
218
|
+
})
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Get Balance
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const balance = await client.wallets.getBalance('wallet-id')
|
|
225
|
+
// Returns: { walletId, address, chain, balances: [{ token, amount, decimals, symbol }] }
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Transfer Funds
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const transfer = await client.wallets.transfer({
|
|
232
|
+
fromWalletId: 'wallet-id',
|
|
233
|
+
toAddress: '0x...',
|
|
234
|
+
amount: '50.00',
|
|
235
|
+
token: 'USDC',
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
// Check transfer status
|
|
239
|
+
const status = await client.wallets.getTransfer('wallet-id', transfer.id)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Webhooks
|
|
243
|
+
|
|
244
|
+
Configure webhook endpoints to receive real-time payment events.
|
|
245
|
+
|
|
246
|
+
#### Configure Webhook
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const config = await client.webhooks.configure({
|
|
250
|
+
url: 'https://your-app.com/webhooks/aura',
|
|
251
|
+
events: [
|
|
252
|
+
'escrow.created',
|
|
253
|
+
'escrow.funded',
|
|
254
|
+
'escrow.released',
|
|
255
|
+
'escrow.refunded',
|
|
256
|
+
'escrow.disputed',
|
|
257
|
+
'wallet.created',
|
|
258
|
+
'transfer.completed',
|
|
259
|
+
'transfer.failed',
|
|
260
|
+
'dispute.opened',
|
|
261
|
+
'dispute.resolved',
|
|
262
|
+
],
|
|
263
|
+
})
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
#### Get Webhook Config
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
const config = await client.webhooks.getConfig()
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### Delete Webhook
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
await client.webhooks.delete()
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### Validate Webhook Signature
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { Webhooks } from '@aura-payments/sdk'
|
|
282
|
+
|
|
283
|
+
// In your webhook handler
|
|
284
|
+
app.post('/webhooks/aura', (req, res) => {
|
|
285
|
+
const signature = req.headers['x-aura-signature'] as string
|
|
286
|
+
const secret = process.env.AURA_WEBHOOK_SECRET!
|
|
287
|
+
|
|
288
|
+
const result = Webhooks.validateSignature({
|
|
289
|
+
payload: req.body,
|
|
290
|
+
signature,
|
|
291
|
+
secret,
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
if (!result.valid) {
|
|
295
|
+
console.error('Invalid webhook signature:', result.error)
|
|
296
|
+
return res.status(401).send('Invalid signature')
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const event = result.event!
|
|
300
|
+
|
|
301
|
+
switch (event.type) {
|
|
302
|
+
case 'escrow.funded':
|
|
303
|
+
console.log('Escrow funded:', event.data)
|
|
304
|
+
break
|
|
305
|
+
case 'escrow.released':
|
|
306
|
+
console.log('Escrow released:', event.data)
|
|
307
|
+
break
|
|
308
|
+
case 'transfer.completed':
|
|
309
|
+
console.log('Transfer completed:', event.data)
|
|
310
|
+
break
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
res.status(200).send('OK')
|
|
314
|
+
})
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Error Handling
|
|
318
|
+
|
|
319
|
+
The SDK provides typed error classes for different failure scenarios:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import {
|
|
323
|
+
AuraError,
|
|
324
|
+
AuraAPIError,
|
|
325
|
+
AuraNetworkError,
|
|
326
|
+
AuraTimeoutError,
|
|
327
|
+
AuraValidationError,
|
|
328
|
+
AuraAuthenticationError,
|
|
329
|
+
AuraNotFoundError,
|
|
330
|
+
AuraRateLimitError,
|
|
331
|
+
isAuraError,
|
|
332
|
+
isRetryableError,
|
|
333
|
+
} from '@aura-payments/sdk'
|
|
334
|
+
|
|
335
|
+
try {
|
|
336
|
+
await client.escrows.get('invalid-id')
|
|
337
|
+
} catch (error) {
|
|
338
|
+
if (error instanceof AuraNotFoundError) {
|
|
339
|
+
console.log('Escrow not found')
|
|
340
|
+
} else if (error instanceof AuraValidationError) {
|
|
341
|
+
console.log('Validation failed:', error.details)
|
|
342
|
+
} else if (error instanceof AuraAuthenticationError) {
|
|
343
|
+
console.log('Invalid API key')
|
|
344
|
+
} else if (error instanceof AuraRateLimitError) {
|
|
345
|
+
console.log(`Rate limited. Retry after ${error.retryAfter}s`)
|
|
346
|
+
} else if (error instanceof AuraNetworkError) {
|
|
347
|
+
console.log('Network error:', error.cause)
|
|
348
|
+
} else if (error instanceof AuraTimeoutError) {
|
|
349
|
+
console.log('Request timed out')
|
|
350
|
+
} else if (isAuraError(error)) {
|
|
351
|
+
console.log(`API error: ${error.message} (${error.code})`)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Check if error is retryable
|
|
355
|
+
if (isRetryableError(error)) {
|
|
356
|
+
// Implement retry logic
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Error Types
|
|
362
|
+
|
|
363
|
+
| Error Class | Status Code | Description |
|
|
364
|
+
|-------------|-------------|-------------|
|
|
365
|
+
| `AuraValidationError` | 400 | Invalid request parameters |
|
|
366
|
+
| `AuraAuthenticationError` | 401 | Invalid or missing API key |
|
|
367
|
+
| `AuraNotFoundError` | 404 | Resource not found |
|
|
368
|
+
| `AuraRateLimitError` | 429 | Rate limit exceeded |
|
|
369
|
+
| `AuraTimeoutError` | 408 | Request timeout |
|
|
370
|
+
| `AuraNetworkError` | - | Network connectivity issue |
|
|
371
|
+
| `AuraAPIError` | 5xx | Server error |
|
|
372
|
+
|
|
373
|
+
## TypeScript Types
|
|
374
|
+
|
|
375
|
+
All types are exported for use in your application:
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
import type {
|
|
379
|
+
// Client
|
|
380
|
+
AuraClientConfig,
|
|
381
|
+
|
|
382
|
+
// Escrow types
|
|
383
|
+
Escrow,
|
|
384
|
+
EscrowStatus,
|
|
385
|
+
EscrowSplit,
|
|
386
|
+
UnlockType,
|
|
387
|
+
DisputeStatus,
|
|
388
|
+
Dispute,
|
|
389
|
+
CreateEscrowParams,
|
|
390
|
+
CreateEscrowResponse,
|
|
391
|
+
FundEscrowParams,
|
|
392
|
+
ReleaseEscrowParams,
|
|
393
|
+
RefundEscrowParams,
|
|
394
|
+
CreateDisputeParams,
|
|
395
|
+
ListEscrowsParams,
|
|
396
|
+
ListEscrowsResponse,
|
|
397
|
+
|
|
398
|
+
// Wallet types
|
|
399
|
+
Wallet,
|
|
400
|
+
WalletBalance,
|
|
401
|
+
TokenBalance,
|
|
402
|
+
Chain,
|
|
403
|
+
WalletType,
|
|
404
|
+
CreateWalletParams,
|
|
405
|
+
TransferParams,
|
|
406
|
+
Transfer,
|
|
407
|
+
ListWalletsParams,
|
|
408
|
+
ListWalletsResponse,
|
|
409
|
+
|
|
410
|
+
// Webhook types
|
|
411
|
+
WebhookEvent,
|
|
412
|
+
WebhookEventType,
|
|
413
|
+
WebhookConfig,
|
|
414
|
+
ConfigureWebhookParams,
|
|
415
|
+
WebhookValidationResult,
|
|
416
|
+
ValidateWebhookSignatureOptions,
|
|
417
|
+
|
|
418
|
+
// Shared types
|
|
419
|
+
PaginationParams,
|
|
420
|
+
PaginatedResponse,
|
|
421
|
+
} from '@aura-payments/sdk'
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
## Utilities
|
|
425
|
+
|
|
426
|
+
The SDK exports utility functions for advanced use cases:
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import {
|
|
430
|
+
generateIdempotencyKey,
|
|
431
|
+
retryWithBackoff,
|
|
432
|
+
withTimeout,
|
|
433
|
+
calculateBackoff,
|
|
434
|
+
} from '@aura-payments/sdk'
|
|
435
|
+
|
|
436
|
+
// Generate a unique idempotency key
|
|
437
|
+
const key = generateIdempotencyKey()
|
|
438
|
+
// Returns: "1703001234567-abc123def456"
|
|
439
|
+
|
|
440
|
+
// Retry a function with exponential backoff
|
|
441
|
+
const result = await retryWithBackoff(
|
|
442
|
+
() => someAsyncOperation(),
|
|
443
|
+
3 // max retries
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
// Add timeout to any promise
|
|
447
|
+
const result = await withTimeout(
|
|
448
|
+
fetch('https://api.example.com'),
|
|
449
|
+
5000 // timeout in ms
|
|
450
|
+
)
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## Idempotency
|
|
454
|
+
|
|
455
|
+
All state-changing operations (POST/PUT) automatically include idempotency keys to ensure safe retries. You can provide your own:
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
// Auto-generated idempotency key (default)
|
|
459
|
+
await client.escrows.create(params)
|
|
460
|
+
|
|
461
|
+
// Custom idempotency key
|
|
462
|
+
await client.escrows.create(params, 'my-unique-key-123')
|
|
463
|
+
|
|
464
|
+
// Disable auto-generation globally
|
|
465
|
+
const client = new AuraClient({
|
|
466
|
+
apiKey: '...',
|
|
467
|
+
autoIdempotency: false,
|
|
468
|
+
})
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## Supported Chains
|
|
472
|
+
|
|
473
|
+
| Chain | Identifier | Network |
|
|
474
|
+
|-------|------------|---------|
|
|
475
|
+
| Arc | `ARC` | Arc Testnet / Mainnet |
|
|
476
|
+
| Arbitrum | `ARB` | Arbitrum Sepolia / One |
|
|
477
|
+
| Base | `BASE` | Base Sepolia / Mainnet |
|
|
478
|
+
| Ethereum | `ETH` | Ethereum Mainnet |
|
|
479
|
+
| Polygon | `MATIC` | Polygon Mainnet |
|
|
480
|
+
| Solana | `SOL` | Solana Mainnet |
|
|
481
|
+
|
|
482
|
+
## Requirements
|
|
483
|
+
|
|
484
|
+
- Node.js 18+ (for native `fetch` support)
|
|
485
|
+
- TypeScript 5.x (for best type inference)
|
|
486
|
+
|
|
487
|
+
## License
|
|
488
|
+
|
|
489
|
+
MIT
|