@aura-payments/sdk 2.2.0 → 2.3.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 +81 -18
- package/dist/index.d.mts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +8 -7
- package/dist/index.mjs +8 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ pnpm add @aura-payments/sdk
|
|
|
14
14
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
|
17
|
+
Receive USDC and split it across recipients in one call (testnet):
|
|
18
|
+
|
|
17
19
|
```typescript
|
|
18
20
|
import { AuraClient } from '@aura-payments/sdk'
|
|
19
21
|
|
|
@@ -21,25 +23,36 @@ const client = new AuraClient({
|
|
|
21
23
|
apiKey: process.env.AURA_API_KEY!,
|
|
22
24
|
})
|
|
23
25
|
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
+
// receiveAndSplit pays from the wallet owned by this id with type 'buyer' —
|
|
27
|
+
// create the wallet with the SAME id and type (the default type is 'BUSINESS').
|
|
28
|
+
const PAYER_ID = 'my-agent'
|
|
29
|
+
|
|
30
|
+
// 1. Provision (create-or-get) the payer wallet — moves no money.
|
|
31
|
+
const wallet = await client.wallets.create({ entityId: PAYER_ID, chain: 'ARC', type: 'buyer' })
|
|
32
|
+
|
|
33
|
+
// 2. (testnet) drip USDC into the payer wallet.
|
|
34
|
+
await client.wallets.requestTestnetFunds(wallet.walletId)
|
|
35
|
+
|
|
36
|
+
// 3. Escrow create → fund → release, in one call.
|
|
37
|
+
const result = await client.escrows.receiveAndSplit({
|
|
26
38
|
orderId: 'order-123',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
platformPercentage: 10,
|
|
35
|
-
},
|
|
36
|
-
adminSafeAddress: '0x...',
|
|
39
|
+
payerOwnerId: PAYER_ID,
|
|
40
|
+
amount: '10',
|
|
41
|
+
chain: 'ARC',
|
|
42
|
+
splits: [
|
|
43
|
+
{ ownerType: 'vendor', ownerId: 'vendor-1', role: 'vendor', percentage: 80 },
|
|
44
|
+
{ ownerType: 'platform', ownerId: 'platform-1', role: 'platform', percentage: 20 },
|
|
45
|
+
],
|
|
37
46
|
})
|
|
38
47
|
|
|
39
|
-
console.log(
|
|
40
|
-
console.log(
|
|
48
|
+
console.log(result.stage) // 'released' on the happy path
|
|
49
|
+
console.log(result.escrow.escrowId)
|
|
41
50
|
```
|
|
42
51
|
|
|
52
|
+
Scaffold this flow into any project with the CLI: `npx @aura-payments/cli init`
|
|
53
|
+
(writes `.mcp.json`, `.env.example`, an `AGENTS.md` section, and
|
|
54
|
+
`examples/aura/receive.ts`).
|
|
55
|
+
|
|
43
56
|
## Features
|
|
44
57
|
|
|
45
58
|
- **Type-Safe** - Full TypeScript support with comprehensive type definitions
|
|
@@ -58,8 +71,8 @@ const client = new AuraClient({
|
|
|
58
71
|
// Required: Your API key from the Aura dashboard
|
|
59
72
|
apiKey: 'ak_live_...',
|
|
60
73
|
|
|
61
|
-
// Optional: API base URL (default: https://api
|
|
62
|
-
baseUrl: 'https://api
|
|
74
|
+
// Optional: API base URL (default: https://getaura.sh/api)
|
|
75
|
+
baseUrl: 'https://getaura.sh/api',
|
|
63
76
|
|
|
64
77
|
// Optional: Request timeout in ms (default: 30000)
|
|
65
78
|
timeout: 30000,
|
|
@@ -78,6 +91,39 @@ const client = new AuraClient({
|
|
|
78
91
|
|
|
79
92
|
Escrows enable secure multi-party payments with configurable splits and release conditions.
|
|
80
93
|
|
|
94
|
+
#### Receive and Split (one call)
|
|
95
|
+
|
|
96
|
+
`receiveAndSplit` composes the full escrow loop — create → wait for deployment →
|
|
97
|
+
pre-flight balance check → fund → wait for settlement → release:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const result = await client.escrows.receiveAndSplit({
|
|
101
|
+
orderId: 'order-123',
|
|
102
|
+
payerOwnerId: 'my-agent', // wallet owned by this id with type 'buyer' pays
|
|
103
|
+
amount: '10',
|
|
104
|
+
chain: 'ARC',
|
|
105
|
+
splits: [
|
|
106
|
+
{ ownerType: 'vendor', ownerId: 'vendor-1', role: 'vendor', percentage: 80 },
|
|
107
|
+
{ ownerType: 'platform', ownerId: 'platform-1', role: 'platform', percentage: 20 },
|
|
108
|
+
],
|
|
109
|
+
// Optional: autoRelease (default true), waitForDeploymentMs, waitForFundingMs,
|
|
110
|
+
// pollIntervalMs, idempotencyKey
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The result's `stage` makes partial runs explicit:
|
|
115
|
+
|
|
116
|
+
| Stage | Meaning | Resume with |
|
|
117
|
+
|-------|---------|-------------|
|
|
118
|
+
| `created` | deployment didn't confirm in time (`deploymentPending: true`) | re-check `result.escrow.escrowId` |
|
|
119
|
+
| `deployed` | payer wallet lacks funds — see `result.fundingRequired` | fund the payer wallet, then `escrows.fund` + `escrows.release` |
|
|
120
|
+
| `funded` | funded but not released (`autoRelease: false` or settlement pending) | `escrows.release` |
|
|
121
|
+
| `released` | funds split to recipients (happy path) | — |
|
|
122
|
+
|
|
123
|
+
Resume a partial run by acting on the returned `escrow.escrowId` — do NOT
|
|
124
|
+
re-call `receiveAndSplit` with the same `orderId` (it would re-create and hit a
|
|
125
|
+
duplicate-orderId error).
|
|
126
|
+
|
|
81
127
|
#### Create Escrow
|
|
82
128
|
|
|
83
129
|
```typescript
|
|
@@ -194,12 +240,29 @@ Manage Circle Developer-Controlled Wallets for your entities.
|
|
|
194
240
|
|
|
195
241
|
```typescript
|
|
196
242
|
const wallet = await client.wallets.create({
|
|
197
|
-
entityId: 'entity-
|
|
243
|
+
entityId: 'entity-id', // your unique entity identifier
|
|
198
244
|
chain: 'ARC', // 'ARC' | 'ARB' | 'BASE' | 'ETH' | 'MATIC' | 'SOL'
|
|
199
|
-
type: '
|
|
245
|
+
type: 'buyer', // owner type: 'BUSINESS' (default) | 'buyer' | 'seller' | 'vendor' | 'platform' | ...
|
|
200
246
|
})
|
|
247
|
+
// Create-or-get: returns { walletId, address, ownerType, ownerId, isNew, ... }
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Note: `receiveAndSplit` pays from the wallet owned by `payerOwnerId` with type
|
|
251
|
+
`'buyer'` — create that wallet with the same `entityId` and `type: 'buyer'`.
|
|
252
|
+
|
|
253
|
+
#### Request Testnet Funds
|
|
254
|
+
|
|
255
|
+
Drip testnet USDC into a wallet from the platform faucet (testnet only):
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
await client.wallets.requestTestnetFunds(wallet.walletId)
|
|
259
|
+
// Optional params: { token: 'USDC', chain: 'ARC' }
|
|
201
260
|
```
|
|
202
261
|
|
|
262
|
+
The drip lands asynchronously on-chain — poll `getBalance` until it reflects.
|
|
263
|
+
Throws `AuraFaucetUnavailableError` if the deployment has no faucet enabled;
|
|
264
|
+
fund the wallet address manually in that case.
|
|
265
|
+
|
|
203
266
|
#### Get Wallet
|
|
204
267
|
|
|
205
268
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -69,6 +69,13 @@ interface Escrow {
|
|
|
69
69
|
factoryAddress: string | null;
|
|
70
70
|
deployed: boolean;
|
|
71
71
|
mode: string;
|
|
72
|
+
/**
|
|
73
|
+
* Definitive fund gate: true only once the deploy outcome is known —
|
|
74
|
+
* contract deployed (mode 'hybrid') or the platform completed the
|
|
75
|
+
* Circle-only fallback (mode 'circle-only'). False while a deployment
|
|
76
|
+
* is still running (mode 'pending').
|
|
77
|
+
*/
|
|
78
|
+
ready?: boolean;
|
|
72
79
|
};
|
|
73
80
|
createdAt: string;
|
|
74
81
|
}
|
|
@@ -118,6 +125,13 @@ interface CreateEscrowResponse {
|
|
|
118
125
|
factoryAddress: string | null;
|
|
119
126
|
deployed: boolean;
|
|
120
127
|
mode: string;
|
|
128
|
+
/**
|
|
129
|
+
* Definitive fund gate: true only once the deploy outcome is known —
|
|
130
|
+
* contract deployed (mode 'hybrid') or the platform completed the
|
|
131
|
+
* Circle-only fallback (mode 'circle-only'). False while a deployment
|
|
132
|
+
* is still running (mode 'pending').
|
|
133
|
+
*/
|
|
134
|
+
ready?: boolean;
|
|
121
135
|
};
|
|
122
136
|
unlock?: {
|
|
123
137
|
type: 'manual' | 'timeout' | 'oracle' | 'hybrid';
|
|
@@ -519,11 +533,12 @@ declare class Escrows {
|
|
|
519
533
|
* Receive USDC and split it across recipients in a single call (board D4).
|
|
520
534
|
*
|
|
521
535
|
* Composes the existing, crash-safe escrow path:
|
|
522
|
-
* create → poll-until-deployed → pre-flight balance → fund → poll-until-funded → release.
|
|
536
|
+
* create → poll-until-fundable (deployed or completed Circle-only fallback) → pre-flight balance → fund → poll-until-funded → release.
|
|
523
537
|
*
|
|
524
538
|
* Funds move from an Aura wallet owned by `payerOwnerId` (the agent itself or a
|
|
525
539
|
* counterparty). The result's `stage` makes a partial run explicit:
|
|
526
|
-
* - `created` —
|
|
540
|
+
* - `created` — deploy outcome not definitive within `waitForDeploymentMs`
|
|
541
|
+
* (neither deployed nor the completed Circle-only fallback)
|
|
527
542
|
* - `deployed` — payer wallet lacks funds (see `fundingRequired`); no money moved
|
|
528
543
|
* - `funded` — funded but not released (`autoRelease:false`, or funding didn't
|
|
529
544
|
* settle within `waitForFundingMs` → `fundingPending: true`)
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,13 @@ interface Escrow {
|
|
|
69
69
|
factoryAddress: string | null;
|
|
70
70
|
deployed: boolean;
|
|
71
71
|
mode: string;
|
|
72
|
+
/**
|
|
73
|
+
* Definitive fund gate: true only once the deploy outcome is known —
|
|
74
|
+
* contract deployed (mode 'hybrid') or the platform completed the
|
|
75
|
+
* Circle-only fallback (mode 'circle-only'). False while a deployment
|
|
76
|
+
* is still running (mode 'pending').
|
|
77
|
+
*/
|
|
78
|
+
ready?: boolean;
|
|
72
79
|
};
|
|
73
80
|
createdAt: string;
|
|
74
81
|
}
|
|
@@ -118,6 +125,13 @@ interface CreateEscrowResponse {
|
|
|
118
125
|
factoryAddress: string | null;
|
|
119
126
|
deployed: boolean;
|
|
120
127
|
mode: string;
|
|
128
|
+
/**
|
|
129
|
+
* Definitive fund gate: true only once the deploy outcome is known —
|
|
130
|
+
* contract deployed (mode 'hybrid') or the platform completed the
|
|
131
|
+
* Circle-only fallback (mode 'circle-only'). False while a deployment
|
|
132
|
+
* is still running (mode 'pending').
|
|
133
|
+
*/
|
|
134
|
+
ready?: boolean;
|
|
121
135
|
};
|
|
122
136
|
unlock?: {
|
|
123
137
|
type: 'manual' | 'timeout' | 'oracle' | 'hybrid';
|
|
@@ -519,11 +533,12 @@ declare class Escrows {
|
|
|
519
533
|
* Receive USDC and split it across recipients in a single call (board D4).
|
|
520
534
|
*
|
|
521
535
|
* Composes the existing, crash-safe escrow path:
|
|
522
|
-
* create → poll-until-deployed → pre-flight balance → fund → poll-until-funded → release.
|
|
536
|
+
* create → poll-until-fundable (deployed or completed Circle-only fallback) → pre-flight balance → fund → poll-until-funded → release.
|
|
523
537
|
*
|
|
524
538
|
* Funds move from an Aura wallet owned by `payerOwnerId` (the agent itself or a
|
|
525
539
|
* counterparty). The result's `stage` makes a partial run explicit:
|
|
526
|
-
* - `created` —
|
|
540
|
+
* - `created` — deploy outcome not definitive within `waitForDeploymentMs`
|
|
541
|
+
* (neither deployed nor the completed Circle-only fallback)
|
|
527
542
|
* - `deployed` — payer wallet lacks funds (see `fundingRequired`); no money moved
|
|
528
543
|
* - `funded` — funded but not released (`autoRelease:false`, or funding didn't
|
|
529
544
|
* settle within `waitForFundingMs` → `fundingPending: true`)
|
package/dist/index.js
CHANGED
|
@@ -252,8 +252,8 @@ async function withTimeout(promise, timeoutMs, timeoutMessage) {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
// src/resources/escrows.ts
|
|
255
|
-
function
|
|
256
|
-
if (e.blockchain?.deployed) return true;
|
|
255
|
+
function isEscrowFundable(e) {
|
|
256
|
+
if (e.blockchain?.deployed || e.blockchain?.ready) return true;
|
|
257
257
|
return ["deployed", "funded", "locked", "released"].includes(e.state ?? "");
|
|
258
258
|
}
|
|
259
259
|
function isEscrowFunded(e) {
|
|
@@ -338,11 +338,12 @@ var Escrows = class {
|
|
|
338
338
|
* Receive USDC and split it across recipients in a single call (board D4).
|
|
339
339
|
*
|
|
340
340
|
* Composes the existing, crash-safe escrow path:
|
|
341
|
-
* create → poll-until-deployed → pre-flight balance → fund → poll-until-funded → release.
|
|
341
|
+
* create → poll-until-fundable (deployed or completed Circle-only fallback) → pre-flight balance → fund → poll-until-funded → release.
|
|
342
342
|
*
|
|
343
343
|
* Funds move from an Aura wallet owned by `payerOwnerId` (the agent itself or a
|
|
344
344
|
* counterparty). The result's `stage` makes a partial run explicit:
|
|
345
|
-
* - `created` —
|
|
345
|
+
* - `created` — deploy outcome not definitive within `waitForDeploymentMs`
|
|
346
|
+
* (neither deployed nor the completed Circle-only fallback)
|
|
346
347
|
* - `deployed` — payer wallet lacks funds (see `fundingRequired`); no money moved
|
|
347
348
|
* - `funded` — funded but not released (`autoRelease:false`, or funding didn't
|
|
348
349
|
* settle within `waitForFundingMs` → `fundingPending: true`)
|
|
@@ -389,12 +390,12 @@ var Escrows = class {
|
|
|
389
390
|
const escrowId = created.escrowId;
|
|
390
391
|
const deployed = await this.pollEscrowUntil(
|
|
391
392
|
escrowId,
|
|
392
|
-
|
|
393
|
+
isEscrowFundable,
|
|
393
394
|
waitForDeploymentMs,
|
|
394
395
|
pollMs,
|
|
395
396
|
created
|
|
396
397
|
);
|
|
397
|
-
if (!
|
|
398
|
+
if (!isEscrowFundable(deployed)) {
|
|
398
399
|
return {
|
|
399
400
|
stage: "created",
|
|
400
401
|
escrow: deployed,
|
|
@@ -402,7 +403,7 @@ var Escrows = class {
|
|
|
402
403
|
deploymentPending: true
|
|
403
404
|
};
|
|
404
405
|
}
|
|
405
|
-
const payerWalletId = deployed.buyerWalletId;
|
|
406
|
+
const payerWalletId = deployed.buyerWalletId ?? deployed.buyerWallet?.walletId;
|
|
406
407
|
const balance = await this.client.wallets.getBalance(payerWalletId);
|
|
407
408
|
if (parseUsdc(balance.balance.usdc) < parseUsdc(amount)) {
|
|
408
409
|
return {
|
package/dist/index.mjs
CHANGED
|
@@ -250,8 +250,8 @@ async function withTimeout(promise, timeoutMs, timeoutMessage) {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// src/resources/escrows.ts
|
|
253
|
-
function
|
|
254
|
-
if (e.blockchain?.deployed) return true;
|
|
253
|
+
function isEscrowFundable(e) {
|
|
254
|
+
if (e.blockchain?.deployed || e.blockchain?.ready) return true;
|
|
255
255
|
return ["deployed", "funded", "locked", "released"].includes(e.state ?? "");
|
|
256
256
|
}
|
|
257
257
|
function isEscrowFunded(e) {
|
|
@@ -336,11 +336,12 @@ var Escrows = class {
|
|
|
336
336
|
* Receive USDC and split it across recipients in a single call (board D4).
|
|
337
337
|
*
|
|
338
338
|
* Composes the existing, crash-safe escrow path:
|
|
339
|
-
* create → poll-until-deployed → pre-flight balance → fund → poll-until-funded → release.
|
|
339
|
+
* create → poll-until-fundable (deployed or completed Circle-only fallback) → pre-flight balance → fund → poll-until-funded → release.
|
|
340
340
|
*
|
|
341
341
|
* Funds move from an Aura wallet owned by `payerOwnerId` (the agent itself or a
|
|
342
342
|
* counterparty). The result's `stage` makes a partial run explicit:
|
|
343
|
-
* - `created` —
|
|
343
|
+
* - `created` — deploy outcome not definitive within `waitForDeploymentMs`
|
|
344
|
+
* (neither deployed nor the completed Circle-only fallback)
|
|
344
345
|
* - `deployed` — payer wallet lacks funds (see `fundingRequired`); no money moved
|
|
345
346
|
* - `funded` — funded but not released (`autoRelease:false`, or funding didn't
|
|
346
347
|
* settle within `waitForFundingMs` → `fundingPending: true`)
|
|
@@ -387,12 +388,12 @@ var Escrows = class {
|
|
|
387
388
|
const escrowId = created.escrowId;
|
|
388
389
|
const deployed = await this.pollEscrowUntil(
|
|
389
390
|
escrowId,
|
|
390
|
-
|
|
391
|
+
isEscrowFundable,
|
|
391
392
|
waitForDeploymentMs,
|
|
392
393
|
pollMs,
|
|
393
394
|
created
|
|
394
395
|
);
|
|
395
|
-
if (!
|
|
396
|
+
if (!isEscrowFundable(deployed)) {
|
|
396
397
|
return {
|
|
397
398
|
stage: "created",
|
|
398
399
|
escrow: deployed,
|
|
@@ -400,7 +401,7 @@ var Escrows = class {
|
|
|
400
401
|
deploymentPending: true
|
|
401
402
|
};
|
|
402
403
|
}
|
|
403
|
-
const payerWalletId = deployed.buyerWalletId;
|
|
404
|
+
const payerWalletId = deployed.buyerWalletId ?? deployed.buyerWallet?.walletId;
|
|
404
405
|
const balance = await this.client.wallets.getBalance(payerWalletId);
|
|
405
406
|
if (parseUsdc(balance.balance.usdc) < parseUsdc(amount)) {
|
|
406
407
|
return {
|