@mixrpay/agent-sdk 0.8.6 → 0.8.7
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.
Potentially problematic release.
This version of @mixrpay/agent-sdk might be problematic. Click here for more details.
- package/README.md +58 -4
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,71 @@
|
|
|
2
2
|
|
|
3
3
|
Enable AI agents to make payments to MixrPay-powered APIs.
|
|
4
4
|
|
|
5
|
+
## Getting Started: Claim an Access Code
|
|
6
|
+
|
|
7
|
+
Agents get spending authorization by claiming an **Access Code** from a human wallet owner.
|
|
8
|
+
|
|
9
|
+
### Step 1: Human Creates Access Code
|
|
10
|
+
|
|
11
|
+
The human logs in at [mixrpay.com/manage/invites](https://www.mixrpay.com/manage/invites), deposits funds, and creates an Access Code (e.g., `mixr-abc123`) with a budget.
|
|
12
|
+
|
|
13
|
+
### Step 2: Agent Claims the Access Code
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AgentWallet } from '@mixrpay/agent-sdk';
|
|
17
|
+
|
|
18
|
+
// Claim the Access Code to get your session key
|
|
19
|
+
const result = await AgentWallet.claimInvite({
|
|
20
|
+
inviteCode: 'mixr-abc123', // From the human
|
|
21
|
+
privateKey: process.env.AGENT_WALLET_KEY as `0x${string}`,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// IMPORTANT: Save this immediately — shown ONCE, cannot be recovered!
|
|
25
|
+
console.log('Session Key:', result.sessionKey); // sk_live_xxx
|
|
26
|
+
console.log('Budget:', result.limits.budgetUsd);
|
|
27
|
+
console.log('Invited by:', result.inviterName);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Step 3: Use the Session Key
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const wallet = new AgentWallet({
|
|
34
|
+
sessionKey: result.sessionKey, // or process.env.MIXRPAY_SESSION_KEY
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// All spending is authorized from the human's wallet
|
|
38
|
+
const response = await wallet.fetch('https://api.example.com/paid-endpoint');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Understanding Wallet Addresses
|
|
42
|
+
|
|
43
|
+
When you claim an Access Code, two addresses are involved:
|
|
44
|
+
|
|
45
|
+
| Address | What it is | Purpose |
|
|
46
|
+
|---------|-----------|---------|
|
|
47
|
+
| `info.address` | Session key's derived address | Used for signing requests |
|
|
48
|
+
| `info.walletAddress` | Human's funded wallet | Where funds are charged FROM |
|
|
49
|
+
|
|
50
|
+
**Verify which wallet you're spending from:**
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const info = await wallet.getSessionKeyInfo();
|
|
54
|
+
console.log('Session key:', info.address); // Your signing key
|
|
55
|
+
console.log('Spending from:', info.walletAddress); // Human's wallet (funding source)
|
|
56
|
+
console.log('Budget remaining:', info.limits.totalUsd);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This is important: your session key authorizes spending from the **human's wallet**, not your own external wallet. The human controls the budget and can revoke access at any time.
|
|
60
|
+
|
|
5
61
|
## Important: Session Key Security
|
|
6
62
|
|
|
7
63
|
Your session key (`sk_live_...`) is a **private key**. Treat it like a password:
|
|
8
64
|
|
|
9
|
-
- **Save it immediately** when you receive it (from `claimInvite()`
|
|
65
|
+
- **Save it immediately** when you receive it (from `claimInvite()`)
|
|
10
66
|
- **Store it securely** (environment variable, secrets manager)
|
|
11
67
|
- **Never commit it** to version control
|
|
12
68
|
- **Never log it** to console or files
|
|
13
|
-
- **It cannot be recovered** if lost - you will need a new
|
|
69
|
+
- **It cannot be recovered** if lost - you will need a new Access Code
|
|
14
70
|
|
|
15
71
|
The session key is shown **only once** when claimed. MixrPay does not store it.
|
|
16
72
|
|
|
@@ -39,8 +95,6 @@ const response = await wallet.callMerchantApi({
|
|
|
39
95
|
const data = await response.json();
|
|
40
96
|
```
|
|
41
97
|
|
|
42
|
-
Get session keys at [mixrpay.com/wallet/sessions](https://www.mixrpay.com/wallet/sessions).
|
|
43
|
-
|
|
44
98
|
## Core Methods
|
|
45
99
|
|
|
46
100
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -532,7 +532,7 @@ function getAmountUsd(requirements) {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
// src/agent-wallet.ts
|
|
535
|
-
var SDK_VERSION = "0.8.
|
|
535
|
+
var SDK_VERSION = "0.8.7";
|
|
536
536
|
var DEFAULT_BASE_URL = process.env.MIXRPAY_BASE_URL || "https://www.mixrpay.com";
|
|
537
537
|
var DEFAULT_TIMEOUT = 3e4;
|
|
538
538
|
var NETWORKS = {
|
|
@@ -1707,6 +1707,7 @@ var AgentWallet = class {
|
|
|
1707
1707
|
const data = await response.json();
|
|
1708
1708
|
this.sessionKeyInfo = {
|
|
1709
1709
|
address: this.sessionKey.address,
|
|
1710
|
+
walletAddress: data.wallet_address ?? data.walletAddress ?? null,
|
|
1710
1711
|
isValid: data.is_valid ?? data.isValid ?? true,
|
|
1711
1712
|
limits: {
|
|
1712
1713
|
perTxUsd: data.per_tx_limit_usd ?? data.perTxLimitUsd ?? null,
|
|
@@ -1731,6 +1732,7 @@ var AgentWallet = class {
|
|
|
1731
1732
|
}
|
|
1732
1733
|
return {
|
|
1733
1734
|
address: this.sessionKey.address,
|
|
1735
|
+
walletAddress: null,
|
|
1734
1736
|
isValid: true,
|
|
1735
1737
|
limits: { perTxUsd: null, dailyUsd: null, totalUsd: null },
|
|
1736
1738
|
usage: { todayUsd: this.totalSpentUsd, totalUsd: this.totalSpentUsd, txCount: this.payments.length },
|
package/dist/index.d.cts
CHANGED
|
@@ -129,8 +129,14 @@ interface PaymentEvent {
|
|
|
129
129
|
* Information about a session key.
|
|
130
130
|
*/
|
|
131
131
|
interface SessionKeyInfo {
|
|
132
|
-
/** The session key's address (
|
|
132
|
+
/** The session key's derived address (used for signing requests) */
|
|
133
133
|
address: string;
|
|
134
|
+
/**
|
|
135
|
+
* The wallet address this session key is authorized to spend from.
|
|
136
|
+
* This is the human's funded wallet, NOT your agent's external wallet.
|
|
137
|
+
* All charges are deducted from this wallet.
|
|
138
|
+
*/
|
|
139
|
+
walletAddress: string | null;
|
|
134
140
|
/** Whether the session key is currently valid */
|
|
135
141
|
isValid: boolean;
|
|
136
142
|
/** Spending limits configured for this session key */
|
|
@@ -379,7 +385,7 @@ interface SessionStats {
|
|
|
379
385
|
*/
|
|
380
386
|
|
|
381
387
|
/** Current SDK version */
|
|
382
|
-
declare const SDK_VERSION = "0.8.
|
|
388
|
+
declare const SDK_VERSION = "0.8.7";
|
|
383
389
|
/** Supported networks */
|
|
384
390
|
declare const NETWORKS: {
|
|
385
391
|
readonly BASE_MAINNET: {
|
package/dist/index.d.ts
CHANGED
|
@@ -129,8 +129,14 @@ interface PaymentEvent {
|
|
|
129
129
|
* Information about a session key.
|
|
130
130
|
*/
|
|
131
131
|
interface SessionKeyInfo {
|
|
132
|
-
/** The session key's address (
|
|
132
|
+
/** The session key's derived address (used for signing requests) */
|
|
133
133
|
address: string;
|
|
134
|
+
/**
|
|
135
|
+
* The wallet address this session key is authorized to spend from.
|
|
136
|
+
* This is the human's funded wallet, NOT your agent's external wallet.
|
|
137
|
+
* All charges are deducted from this wallet.
|
|
138
|
+
*/
|
|
139
|
+
walletAddress: string | null;
|
|
134
140
|
/** Whether the session key is currently valid */
|
|
135
141
|
isValid: boolean;
|
|
136
142
|
/** Spending limits configured for this session key */
|
|
@@ -379,7 +385,7 @@ interface SessionStats {
|
|
|
379
385
|
*/
|
|
380
386
|
|
|
381
387
|
/** Current SDK version */
|
|
382
|
-
declare const SDK_VERSION = "0.8.
|
|
388
|
+
declare const SDK_VERSION = "0.8.7";
|
|
383
389
|
/** Supported networks */
|
|
384
390
|
declare const NETWORKS: {
|
|
385
391
|
readonly BASE_MAINNET: {
|
package/dist/index.js
CHANGED
|
@@ -495,7 +495,7 @@ function getAmountUsd(requirements) {
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
// src/agent-wallet.ts
|
|
498
|
-
var SDK_VERSION = "0.8.
|
|
498
|
+
var SDK_VERSION = "0.8.7";
|
|
499
499
|
var DEFAULT_BASE_URL = process.env.MIXRPAY_BASE_URL || "https://www.mixrpay.com";
|
|
500
500
|
var DEFAULT_TIMEOUT = 3e4;
|
|
501
501
|
var NETWORKS = {
|
|
@@ -1670,6 +1670,7 @@ var AgentWallet = class {
|
|
|
1670
1670
|
const data = await response.json();
|
|
1671
1671
|
this.sessionKeyInfo = {
|
|
1672
1672
|
address: this.sessionKey.address,
|
|
1673
|
+
walletAddress: data.wallet_address ?? data.walletAddress ?? null,
|
|
1673
1674
|
isValid: data.is_valid ?? data.isValid ?? true,
|
|
1674
1675
|
limits: {
|
|
1675
1676
|
perTxUsd: data.per_tx_limit_usd ?? data.perTxLimitUsd ?? null,
|
|
@@ -1694,6 +1695,7 @@ var AgentWallet = class {
|
|
|
1694
1695
|
}
|
|
1695
1696
|
return {
|
|
1696
1697
|
address: this.sessionKey.address,
|
|
1698
|
+
walletAddress: null,
|
|
1697
1699
|
isValid: true,
|
|
1698
1700
|
limits: { perTxUsd: null, dailyUsd: null, totalUsd: null },
|
|
1699
1701
|
usage: { todayUsd: this.totalSpentUsd, totalUsd: this.totalSpentUsd, txCount: this.payments.length },
|