@atxp/base 0.10.12 → 0.10.13

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/dist/index.js CHANGED
@@ -5507,29 +5507,32 @@ class BaseAppAccount {
5507
5507
  * Authorize a payment through the appropriate channel for Base browser accounts.
5508
5508
  */
5509
5509
  async authorize(params) {
5510
- const { protocol } = params;
5511
- switch (protocol) {
5512
- case 'atxp': {
5513
- const chain = this.chainId === 84532 ? ChainEnum.BaseSepolia : ChainEnum.Base;
5514
- const destination = {
5515
- chain,
5516
- currency: 'USDC',
5517
- address: params.destination,
5518
- amount: new BigNumber(params.amount),
5519
- };
5520
- const result = await this.paymentMakers[0].makePayment([destination], params.memo || '');
5521
- if (!result) {
5522
- throw new Error('BaseAppAccount: payment execution returned no result');
5523
- }
5524
- return { protocol, credential: JSON.stringify(result) };
5525
- }
5526
- case 'x402':
5527
- throw new Error('BaseAppAccount does not support x402 protocol');
5528
- case 'mpp':
5529
- throw new Error('BaseAppAccount does not support MPP protocol');
5530
- default:
5531
- throw new Error(`BaseAppAccount: unsupported protocol '${protocol}'`);
5510
+ if (!params.protocols || params.protocols.length === 0) {
5511
+ throw new Error('BaseAppAccount: protocols array must not be empty');
5512
+ }
5513
+ const supported = ['atxp'];
5514
+ const protocol = params.protocols.find(p => supported.includes(p));
5515
+ if (!protocol) {
5516
+ throw new Error(`BaseAppAccount does not support any of: ${params.protocols.join(', ')}`);
5517
+ }
5518
+ if (!params.amount) {
5519
+ throw new Error('BaseAppAccount: amount is required for atxp authorize');
5532
5520
  }
5521
+ if (!params.destination) {
5522
+ throw new Error('BaseAppAccount: destination is required for atxp authorize');
5523
+ }
5524
+ const chain = this.chainId === 84532 ? ChainEnum.BaseSepolia : ChainEnum.Base;
5525
+ const destination = {
5526
+ chain,
5527
+ currency: 'USDC',
5528
+ address: params.destination,
5529
+ amount: new BigNumber(params.amount),
5530
+ };
5531
+ const result = await this.paymentMakers[0].makePayment([destination], params.memo || '');
5532
+ if (!result) {
5533
+ throw new Error('BaseAppAccount: payment execution returned no result');
5534
+ }
5535
+ return { protocol, credential: JSON.stringify(result) };
5533
5536
  }
5534
5537
  }
5535
5538
 
@@ -5774,7 +5777,14 @@ class BaseAccount {
5774
5777
  * Authorize a payment through the appropriate channel for Base accounts.
5775
5778
  */
5776
5779
  async authorize(params) {
5777
- const { protocol } = params;
5780
+ if (!params.protocols || params.protocols.length === 0) {
5781
+ throw new Error('BaseAccount: protocols array must not be empty');
5782
+ }
5783
+ const supported = ['x402', 'atxp'];
5784
+ const protocol = params.protocols.find(p => supported.includes(p));
5785
+ if (!protocol) {
5786
+ throw new Error(`BaseAccount does not support any of: ${params.protocols.join(', ')}`);
5787
+ }
5778
5788
  switch (protocol) {
5779
5789
  case 'x402': {
5780
5790
  const { createPaymentHeader } = await import('x402/client');
@@ -5788,6 +5798,12 @@ class BaseAccount {
5788
5798
  return { protocol, credential: paymentHeader };
5789
5799
  }
5790
5800
  case 'atxp': {
5801
+ if (!params.amount) {
5802
+ throw new Error('BaseAccount: amount is required for atxp authorize');
5803
+ }
5804
+ if (!params.destination) {
5805
+ throw new Error('BaseAccount: destination is required for atxp authorize');
5806
+ }
5791
5807
  const destination = {
5792
5808
  chain: 'base',
5793
5809
  currency: 'USDC',
@@ -5800,8 +5816,6 @@ class BaseAccount {
5800
5816
  }
5801
5817
  return { protocol, credential: JSON.stringify({ transactionId: result.transactionId, chain: result.chain, currency: result.currency }) };
5802
5818
  }
5803
- case 'mpp':
5804
- throw new Error('BaseAccount does not support MPP protocol');
5805
5819
  default:
5806
5820
  throw new Error(`BaseAccount: unsupported protocol '${protocol}'`);
5807
5821
  }