@dcentralab/d402-client 0.1.1 → 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Traia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -55,7 +55,7 @@ export default function AnalyzeButton() {
55
55
  // Create D402 client with user's wallet
56
56
  const client = new D402Client({
57
57
  operatorAccount: walletClient.account,
58
- walletAddress: '0xUserIATPWallet...', // User's IATPWallet
58
+ iatpWalletAddress: '0xUserIATPWallet...', // User's IATPWallet
59
59
  maxValue: 1000000n // 1 USDC max
60
60
  })
61
61
 
@@ -117,12 +117,12 @@ const result = await createIATPWallet({
117
117
  rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com'
118
118
  })
119
119
 
120
- console.log('Wallet:', result.walletAddress)
120
+ console.log('Wallet:', result.iatpWalletAddress)
121
121
  console.log('Operator key:', result.operatorPrivateKey) // Store securely!
122
122
  ```
123
123
 
124
124
  **Returns:**
125
- - `walletAddress` - IATPWallet contract address
125
+ - `iatpWalletAddress` - IATPWallet contract address
126
126
  - `operatorAddress` - Operator's address
127
127
  - `operatorPrivateKey` - Operator's private key (store securely!)
128
128
  - `transactionHash` - Creation transaction
@@ -135,7 +135,7 @@ import { D402Client } from '@dcentralab/d402-client'
135
135
 
136
136
  const client = new D402Client({
137
137
  operatorAccount,
138
- walletAddress: '0xYourWallet...',
138
+ iatpWalletAddress: '0xYourWallet...',
139
139
  maxValue: 1000000n,
140
140
  networkFilter: 'base-mainnet', // Only Base network
141
141
  schemeFilter: 'exact' // Only exact payments
@@ -169,7 +169,7 @@ if (response.status === 402) {
169
169
  const signedPayment = await signD402Payment({
170
170
  operatorAccount,
171
171
  paymentRequirement: requirement,
172
- walletAddress: '0xYourWallet...'
172
+ iatpWalletAddress: '0xYourWallet...'
173
173
  })
174
174
 
175
175
  // 4. Encode for header
@@ -199,7 +199,7 @@ new D402Client(config: D402ClientConfig)
199
199
  | Option | Type | Required | Description |
200
200
  |--------|------|----------|-------------|
201
201
  | `operatorAccount` | `Account` | ✅ | Viem account for signing payments (EOA) |
202
- | `walletAddress` | `0x${string}` | ❌ | IATPWallet contract address (uses operator address if not provided) |
202
+ | `iatpWalletAddress` | `0x${string}` | ❌ | IATPWallet contract address (uses operator address if not provided) |
203
203
  | `maxValue` | `bigint` | ❌ | Max payment in base units (wei). Safety limit to prevent overpaying. |
204
204
  | `networkFilter` | `string` | ❌ | Only select requirements matching this network |
205
205
  | `schemeFilter` | `string` | ❌ | Payment scheme filter (default: "exact") |
@@ -320,7 +320,7 @@ export default function PaymentComponent() {
320
320
  // User's wallet signs payments
321
321
  const client = new D402Client({
322
322
  operatorAccount: walletClient.account,
323
- walletAddress: '0xUserIATPWallet...',
323
+ iatpWalletAddress: '0xUserIATPWallet...',
324
324
  maxValue: 1000000n
325
325
  })
326
326
 
@@ -360,7 +360,7 @@ const operatorAccount = privateKeyToAccount(process.env.OPERATOR_KEY!)
360
360
  app.post('/api/analyze', async (req, res) => {
361
361
  const client = new D402Client({
362
362
  operatorAccount,
363
- walletAddress: req.user.iatpWallet,
363
+ iatpWalletAddress: req.user.iatpWallet,
364
364
  maxValue: 1000000n
365
365
  })
366
366
 
package/dist/index.d.mts CHANGED
@@ -189,10 +189,10 @@ interface D402ClientConfig {
189
189
  /** Operator account with private key for signing payments (EOA) */
190
190
  operatorAccount: Account;
191
191
  /**
192
- * Consumer's IATPWallet contract address.
193
- * If not provided, uses operator_account.address for testing.
192
+ * IATPWallet contract address.
193
+ * If not provided, uses operatorAccount.address for testing.
194
194
  */
195
- walletAddress?: `0x${string}`;
195
+ iatpWalletAddress?: `0x${string}`;
196
196
  /**
197
197
  * Optional safety limit for maximum payment amount per request in base units.
198
198
  *
@@ -245,7 +245,7 @@ interface D402ClientConfig {
245
245
  *
246
246
  * const client = new D402Client({
247
247
  * operatorAccount,
248
- * walletAddress: '0xUserIATPWallet...',
248
+ * iatpWalletAddress: '0xUserIATPWallet...',
249
249
  * maxValue: 1000000n // 1 USDC max
250
250
  * })
251
251
  *
@@ -259,7 +259,7 @@ interface D402ClientConfig {
259
259
  */
260
260
  declare class D402Client {
261
261
  private readonly operatorAccount;
262
- private readonly walletAddress;
262
+ private readonly iatpWalletAddress;
263
263
  private readonly maxValue?;
264
264
  private readonly paymentRequirementsSelector;
265
265
  private readonly networkFilter?;
@@ -282,11 +282,11 @@ declare class D402Client {
282
282
  */
283
283
  selectPaymentRequirement(requirements: PaymentRequirement[]): PaymentRequirement;
284
284
  /**
285
- * Get the wallet address used for payments.
285
+ * Get the IATP wallet address used for payments.
286
286
  *
287
287
  * @returns IATPWallet contract address or operator EOA address
288
288
  */
289
- getWalletAddress(): `0x${string}`;
289
+ getIATPWalletAddress(): `0x${string}`;
290
290
  /**
291
291
  * Get the operator account used for signing.
292
292
  *
@@ -318,7 +318,7 @@ declare class D402Client {
318
318
  *
319
319
  * @example
320
320
  * ```ts
321
- * const client = new D402Client({ operatorAccount, walletAddress })
321
+ * const client = new D402Client({ operatorAccount, iatpWalletAddress })
322
322
  *
323
323
  * const response = await client.fetch('http://api.example.com/analyze', {
324
324
  * method: 'POST',
@@ -349,7 +349,7 @@ declare class D402Client {
349
349
  * @param params - Signing parameters
350
350
  * @param params.operatorAccount - Operator account with private key for signing (EOA)
351
351
  * @param params.paymentRequirement - Payment requirements from 402 response
352
- * @param params.walletAddress - Consumer's IATPWallet contract address (optional, uses operator address if not provided)
352
+ * @param params.iatpWalletAddress - IATPWallet contract address (optional, uses operator address if not provided)
353
353
  * @param params.requestPath - API request path (optional, uses payment_requirements.resource if not provided)
354
354
  * @returns Signed payment ready to encode and send
355
355
  *
@@ -359,7 +359,7 @@ declare class D402Client {
359
359
  * const signedPayment = await signD402Payment({
360
360
  * operatorAccount: account,
361
361
  * paymentRequirement: requirement,
362
- * walletAddress: '0xUserWallet...'
362
+ * iatpWalletAddress: '0xUserWallet...'
363
363
  * })
364
364
  * const encoded = encodePayment(signedPayment)
365
365
  * ```
@@ -367,7 +367,7 @@ declare class D402Client {
367
367
  declare function signD402Payment(params: {
368
368
  operatorAccount: Account;
369
369
  paymentRequirement: PaymentRequirement;
370
- walletAddress?: `0x${string}`;
370
+ iatpWalletAddress?: `0x${string}`;
371
371
  requestPath?: string;
372
372
  d402Version?: number;
373
373
  }): Promise<SignedPayment>;
package/dist/index.d.ts CHANGED
@@ -189,10 +189,10 @@ interface D402ClientConfig {
189
189
  /** Operator account with private key for signing payments (EOA) */
190
190
  operatorAccount: Account;
191
191
  /**
192
- * Consumer's IATPWallet contract address.
193
- * If not provided, uses operator_account.address for testing.
192
+ * IATPWallet contract address.
193
+ * If not provided, uses operatorAccount.address for testing.
194
194
  */
195
- walletAddress?: `0x${string}`;
195
+ iatpWalletAddress?: `0x${string}`;
196
196
  /**
197
197
  * Optional safety limit for maximum payment amount per request in base units.
198
198
  *
@@ -245,7 +245,7 @@ interface D402ClientConfig {
245
245
  *
246
246
  * const client = new D402Client({
247
247
  * operatorAccount,
248
- * walletAddress: '0xUserIATPWallet...',
248
+ * iatpWalletAddress: '0xUserIATPWallet...',
249
249
  * maxValue: 1000000n // 1 USDC max
250
250
  * })
251
251
  *
@@ -259,7 +259,7 @@ interface D402ClientConfig {
259
259
  */
260
260
  declare class D402Client {
261
261
  private readonly operatorAccount;
262
- private readonly walletAddress;
262
+ private readonly iatpWalletAddress;
263
263
  private readonly maxValue?;
264
264
  private readonly paymentRequirementsSelector;
265
265
  private readonly networkFilter?;
@@ -282,11 +282,11 @@ declare class D402Client {
282
282
  */
283
283
  selectPaymentRequirement(requirements: PaymentRequirement[]): PaymentRequirement;
284
284
  /**
285
- * Get the wallet address used for payments.
285
+ * Get the IATP wallet address used for payments.
286
286
  *
287
287
  * @returns IATPWallet contract address or operator EOA address
288
288
  */
289
- getWalletAddress(): `0x${string}`;
289
+ getIATPWalletAddress(): `0x${string}`;
290
290
  /**
291
291
  * Get the operator account used for signing.
292
292
  *
@@ -318,7 +318,7 @@ declare class D402Client {
318
318
  *
319
319
  * @example
320
320
  * ```ts
321
- * const client = new D402Client({ operatorAccount, walletAddress })
321
+ * const client = new D402Client({ operatorAccount, iatpWalletAddress })
322
322
  *
323
323
  * const response = await client.fetch('http://api.example.com/analyze', {
324
324
  * method: 'POST',
@@ -349,7 +349,7 @@ declare class D402Client {
349
349
  * @param params - Signing parameters
350
350
  * @param params.operatorAccount - Operator account with private key for signing (EOA)
351
351
  * @param params.paymentRequirement - Payment requirements from 402 response
352
- * @param params.walletAddress - Consumer's IATPWallet contract address (optional, uses operator address if not provided)
352
+ * @param params.iatpWalletAddress - IATPWallet contract address (optional, uses operator address if not provided)
353
353
  * @param params.requestPath - API request path (optional, uses payment_requirements.resource if not provided)
354
354
  * @returns Signed payment ready to encode and send
355
355
  *
@@ -359,7 +359,7 @@ declare class D402Client {
359
359
  * const signedPayment = await signD402Payment({
360
360
  * operatorAccount: account,
361
361
  * paymentRequirement: requirement,
362
- * walletAddress: '0xUserWallet...'
362
+ * iatpWalletAddress: '0xUserWallet...'
363
363
  * })
364
364
  * const encoded = encodePayment(signedPayment)
365
365
  * ```
@@ -367,7 +367,7 @@ declare class D402Client {
367
367
  declare function signD402Payment(params: {
368
368
  operatorAccount: Account;
369
369
  paymentRequirement: PaymentRequirement;
370
- walletAddress?: `0x${string}`;
370
+ iatpWalletAddress?: `0x${string}`;
371
371
  requestPath?: string;
372
372
  d402Version?: number;
373
373
  }): Promise<SignedPayment>;
package/dist/index.js CHANGED
@@ -351,11 +351,11 @@ async function signD402Payment(params) {
351
351
  const {
352
352
  operatorAccount,
353
353
  paymentRequirement,
354
- walletAddress,
354
+ iatpWalletAddress,
355
355
  requestPath,
356
356
  d402Version = 1
357
357
  } = params;
358
- const consumerWallet = walletAddress || operatorAccount.address;
358
+ const consumerWallet = iatpWalletAddress || operatorAccount.address;
359
359
  let finalRequestPath = requestPath || paymentRequirement.resource || "/mcp";
360
360
  if (!finalRequestPath || finalRequestPath.trim() === "") {
361
361
  finalRequestPath = "/mcp";
@@ -545,7 +545,7 @@ var D402Client = class {
545
545
  */
546
546
  constructor(config) {
547
547
  this.operatorAccount = config.operatorAccount;
548
- this.walletAddress = config.walletAddress || config.operatorAccount.address;
548
+ this.iatpWalletAddress = config.iatpWalletAddress || config.operatorAccount.address;
549
549
  this.maxValue = config.maxValue;
550
550
  this.networkFilter = config.networkFilter;
551
551
  this.schemeFilter = config.schemeFilter || "exact";
@@ -567,12 +567,12 @@ var D402Client = class {
567
567
  });
568
568
  }
569
569
  /**
570
- * Get the wallet address used for payments.
570
+ * Get the IATP wallet address used for payments.
571
571
  *
572
572
  * @returns IATPWallet contract address or operator EOA address
573
573
  */
574
- getWalletAddress() {
575
- return this.walletAddress;
574
+ getIATPWalletAddress() {
575
+ return this.iatpWalletAddress;
576
576
  }
577
577
  /**
578
578
  * Get the operator account used for signing.
@@ -609,7 +609,7 @@ var D402Client = class {
609
609
  *
610
610
  * @example
611
611
  * ```ts
612
- * const client = new D402Client({ operatorAccount, walletAddress })
612
+ * const client = new D402Client({ operatorAccount, iatpWalletAddress })
613
613
  *
614
614
  * const response = await client.fetch('http://api.example.com/analyze', {
615
615
  * method: 'POST',
@@ -634,7 +634,7 @@ var D402Client = class {
634
634
  const signedPayment = await signD402Payment2({
635
635
  operatorAccount: this.operatorAccount,
636
636
  paymentRequirement: selectedRequirement,
637
- walletAddress: this.walletAddress
637
+ iatpWalletAddress: this.iatpWalletAddress
638
638
  });
639
639
  const paymentHeader = encodePayment2(signedPayment);
640
640
  response = await fetch(url, {