@atxp/base 0.8.3 → 0.9.1
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/baseAccount.d.ts +20 -0
- package/dist/baseAccount.d.ts.map +1 -0
- package/dist/baseAccount.js +46 -0
- package/dist/baseAccount.js.map +1 -0
- package/dist/baseAppAccount.js +1 -1
- package/dist/baseAppPaymentMaker.js +1 -1
- package/dist/baseConstants.d.ts +10 -0
- package/dist/baseConstants.d.ts.map +1 -0
- package/dist/baseConstants.js +21 -0
- package/dist/baseConstants.js.map +1 -0
- package/dist/basePaymentMaker.d.ts +23 -0
- package/dist/basePaymentMaker.d.ts.map +1 -0
- package/dist/basePaymentMaker.js +196 -0
- package/dist/basePaymentMaker.js.map +1 -0
- package/dist/index.cjs +5258 -209
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +49 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5254 -210
- package/dist/index.js.map +1 -1
- package/dist/mainWalletPaymentMaker.d.ts.map +1 -1
- package/dist/mainWalletPaymentMaker.js +1 -1
- package/dist/mainWalletPaymentMaker.js.map +1 -1
- package/dist/node_modules/@aa-sdk/core/dist/esm/client/schema.js +69 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/client/schema.js.map +1 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/errors/base.js +43 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/errors/base.js.map +1 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/errors/client.js +22 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/errors/client.js.map +1 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/transport/split.js +57 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/transport/split.js.map +1 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/utils/schema.js +33 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/utils/schema.js.map +1 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/utils/traceHeader.js +22 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/utils/traceHeader.js.map +1 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/version.js +6 -0
- package/dist/node_modules/@aa-sdk/core/dist/esm/version.js.map +1 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/alchemyTrackerHeaders.js +36 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/alchemyTrackerHeaders.js.map +1 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/alchemyTransport.js +190 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/alchemyTransport.js.map +1 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/schema.js +10 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/schema.js.map +1 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/version.js +6 -0
- package/dist/node_modules/@account-kit/infra/dist/esm/version.js.map +1 -0
- package/dist/node_modules/zod/index.js +6 -0
- package/dist/node_modules/zod/index.js.map +1 -0
- package/dist/node_modules/zod/v3/ZodError.js +137 -0
- package/dist/node_modules/zod/v3/ZodError.js.map +1 -0
- package/dist/node_modules/zod/v3/errors.js +12 -0
- package/dist/node_modules/zod/v3/errors.js.map +1 -0
- package/dist/node_modules/zod/v3/external.js +7 -0
- package/dist/node_modules/zod/v3/external.js.map +1 -0
- package/dist/node_modules/zod/v3/helpers/errorUtil.js +9 -0
- package/dist/node_modules/zod/v3/helpers/errorUtil.js.map +1 -0
- package/dist/node_modules/zod/v3/helpers/parseUtil.js +113 -0
- package/dist/node_modules/zod/v3/helpers/parseUtil.js.map +1 -0
- package/dist/node_modules/zod/v3/helpers/util.js +136 -0
- package/dist/node_modules/zod/v3/helpers/util.js.map +1 -0
- package/dist/node_modules/zod/v3/locales/en.js +112 -0
- package/dist/node_modules/zod/v3/locales/en.js.map +1 -0
- package/dist/node_modules/zod/v3/types.js +3690 -0
- package/dist/node_modules/zod/v3/types.js.map +1 -0
- package/dist/smartWalletHelpers.d.ts +5 -1
- package/dist/smartWalletHelpers.d.ts.map +1 -1
- package/dist/smartWalletHelpers.js +67 -3
- package/dist/smartWalletHelpers.js.map +1 -1
- package/package.json +5 -6
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Account, PaymentMaker } from '@atxp/client';
|
|
2
|
+
import type { AccountId, Source } from '@atxp/common';
|
|
3
|
+
import { LocalAccount } from 'viem';
|
|
4
|
+
export declare class BaseAccount implements Account {
|
|
5
|
+
accountId: AccountId;
|
|
6
|
+
paymentMakers: PaymentMaker[];
|
|
7
|
+
private walletClient;
|
|
8
|
+
private account;
|
|
9
|
+
constructor(baseRPCUrl: string, sourceSecretKey: string);
|
|
10
|
+
/**
|
|
11
|
+
* Get the LocalAccount (signer) for this account.
|
|
12
|
+
* This can be used with the x402 library or other signing operations.
|
|
13
|
+
*/
|
|
14
|
+
getLocalAccount(): LocalAccount;
|
|
15
|
+
/**
|
|
16
|
+
* Get sources for this account
|
|
17
|
+
*/
|
|
18
|
+
getSources(): Promise<Source[]>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=baseAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseAccount.d.ts","sourceRoot":"","sources":["../src/baseAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAO,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,EAA0C,YAAY,EAAE,MAAM,MAAM,CAAC;AAG5E,qBAAa,WAAY,YAAW,OAAO;IACzC,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,OAAO,CAAoB;gBAEvB,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;IAsBvD;;;OAGG;IACH,eAAe,IAAI,YAAY;IAI/B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAOtC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
2
|
+
import { BasePaymentMaker } from './basePaymentMaker.js';
|
|
3
|
+
import { createWalletClient, http } from 'viem';
|
|
4
|
+
import { base } from 'viem/chains';
|
|
5
|
+
|
|
6
|
+
class BaseAccount {
|
|
7
|
+
constructor(baseRPCUrl, sourceSecretKey) {
|
|
8
|
+
if (!baseRPCUrl) {
|
|
9
|
+
throw new Error('Base RPC URL is required');
|
|
10
|
+
}
|
|
11
|
+
if (!sourceSecretKey) {
|
|
12
|
+
throw new Error('Source secret key is required');
|
|
13
|
+
}
|
|
14
|
+
this.account = privateKeyToAccount(sourceSecretKey);
|
|
15
|
+
// Format accountId as network:address
|
|
16
|
+
this.accountId = `base:${this.account.address}`;
|
|
17
|
+
this.walletClient = createWalletClient({
|
|
18
|
+
account: this.account,
|
|
19
|
+
chain: base,
|
|
20
|
+
transport: http(baseRPCUrl),
|
|
21
|
+
});
|
|
22
|
+
this.paymentMakers = [
|
|
23
|
+
new BasePaymentMaker(baseRPCUrl, this.walletClient)
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the LocalAccount (signer) for this account.
|
|
28
|
+
* This can be used with the x402 library or other signing operations.
|
|
29
|
+
*/
|
|
30
|
+
getLocalAccount() {
|
|
31
|
+
return this.account;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get sources for this account
|
|
35
|
+
*/
|
|
36
|
+
async getSources() {
|
|
37
|
+
return [{
|
|
38
|
+
address: this.account.address,
|
|
39
|
+
chain: 'base',
|
|
40
|
+
walletType: 'eoa'
|
|
41
|
+
}];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { BaseAccount };
|
|
46
|
+
//# sourceMappingURL=baseAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseAccount.js","sources":["../src/baseAccount.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;MAOa,WAAW,CAAA;IAMtB,WAAA,CAAY,UAAkB,EAAE,eAAuB,EAAA;QACrD,IAAI,CAAC,UAAU,EAAE;AACf,YAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC;QAC7C;QACA,IAAI,CAAC,eAAe,EAAE;AACpB,YAAA,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC;QAClD;AAEA,QAAA,IAAI,CAAC,OAAO,GAAG,mBAAmB,CAAC,eAAsB,CAAC;;QAG1D,IAAI,CAAC,SAAS,GAAG,CAAA,KAAA,EAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAA,CAAe;AAC5D,QAAA,IAAI,CAAC,YAAY,GAAG,kBAAkB,CAAC;YACrC,OAAO,EAAE,IAAI,CAAC,OAAO;AACrB,YAAA,KAAK,EAAE,IAAI;AACX,YAAA,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC;AAC5B,SAAA,CAAC;QACF,IAAI,CAAC,aAAa,GAAG;AACnB,YAAA,IAAI,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY;SACnD;IACH;AAEA;;;AAGG;IACH,eAAe,GAAA;QACb,OAAO,IAAI,CAAC,OAAO;IACrB;AAEA;;AAEG;AACH,IAAA,MAAM,UAAU,GAAA;AACd,QAAA,OAAO,CAAC;AACN,gBAAA,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;AAC7B,gBAAA,KAAK,EAAE,MAAM;AACb,gBAAA,UAAU,EAAE;AACb,aAAA,CAAC;IACJ;AACD;;;;"}
|
package/dist/baseAppAccount.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConsoleLogger, BrowserCache, ChainEnum, WalletTypeEnum } from '@atxp/common';
|
|
2
|
-
import { getBaseUSDCAddress } from '
|
|
2
|
+
import { getBaseUSDCAddress } from './baseConstants.js';
|
|
3
3
|
import { BaseAppPaymentMaker } from './baseAppPaymentMaker.js';
|
|
4
4
|
import { MainWalletPaymentMaker } from './mainWalletPaymentMaker.js';
|
|
5
5
|
import { generatePrivateKey } from 'viem/accounts';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getBaseUSDCAddress } from '
|
|
1
|
+
import { getBaseUSDCAddress } from './baseConstants.js';
|
|
2
2
|
import { base } from 'viem/chains';
|
|
3
3
|
import { ConsoleLogger, constructEIP1271Message, createEIP1271AuthData, createEIP1271JWT } from '@atxp/common';
|
|
4
4
|
import { encodeFunctionData, parseEther } from 'viem';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const USDC_CONTRACT_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2
|
+
export declare const USDC_CONTRACT_ADDRESS_BASE_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
3
|
+
/**
|
|
4
|
+
* Get USDC contract address for Base chain by chain ID
|
|
5
|
+
* @param chainId - Chain ID (8453 for mainnet, 84532 for sepolia)
|
|
6
|
+
* @returns USDC contract address
|
|
7
|
+
* @throws Error if chain ID is not supported
|
|
8
|
+
*/
|
|
9
|
+
export declare const getBaseUSDCAddress: (chainId: number) => string;
|
|
10
|
+
//# sourceMappingURL=baseConstants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseConstants.d.ts","sourceRoot":"","sources":["../src/baseConstants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,+CAA+C,CAAC;AACvF,eAAO,MAAM,kCAAkC,+CAA+C,CAAC;AAE/F;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MASpD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const USDC_CONTRACT_ADDRESS_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"; // USDC on Base mainnet
|
|
2
|
+
const USDC_CONTRACT_ADDRESS_BASE_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e"; // USDC on Base Sepolia testnet
|
|
3
|
+
/**
|
|
4
|
+
* Get USDC contract address for Base chain by chain ID
|
|
5
|
+
* @param chainId - Chain ID (8453 for mainnet, 84532 for sepolia)
|
|
6
|
+
* @returns USDC contract address
|
|
7
|
+
* @throws Error if chain ID is not supported
|
|
8
|
+
*/
|
|
9
|
+
const getBaseUSDCAddress = (chainId) => {
|
|
10
|
+
switch (chainId) {
|
|
11
|
+
case 8453: // Base mainnet
|
|
12
|
+
return USDC_CONTRACT_ADDRESS_BASE;
|
|
13
|
+
case 84532: // Base Sepolia
|
|
14
|
+
return USDC_CONTRACT_ADDRESS_BASE_SEPOLIA;
|
|
15
|
+
default:
|
|
16
|
+
throw new Error(`Unsupported Base Chain ID: ${chainId}. Supported chains: 8453 (mainnet), 84532 (sepolia)`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { USDC_CONTRACT_ADDRESS_BASE, USDC_CONTRACT_ADDRESS_BASE_SEPOLIA, getBaseUSDCAddress };
|
|
21
|
+
//# sourceMappingURL=baseConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseConstants.js","sources":["../src/baseConstants.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAO,MAAM,0BAA0B,GAAG,6CAA6C;AAChF,MAAM,kCAAkC,GAAG,6CAA6C;AAE/F;;;;;AAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAAe,KAAY;IAC5D,QAAQ,OAAO;QACb,KAAK,IAAI;AACP,YAAA,OAAO,0BAA0B;QACnC,KAAK,KAAK;AACR,YAAA,OAAO,kCAAkC;AAC3C,QAAA;AACE,YAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,CAAA,mDAAA,CAAqD,CAAC;;AAEjH;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PaymentMaker } from '@atxp/client';
|
|
2
|
+
import { Logger, Currency, AccountId, PaymentIdentifier, Destination } from '@atxp/common';
|
|
3
|
+
import { WalletClient, PublicActions } from "viem";
|
|
4
|
+
type ExtendedWalletClient = WalletClient & PublicActions;
|
|
5
|
+
export declare class BasePaymentMaker implements PaymentMaker {
|
|
6
|
+
protected signingClient: ExtendedWalletClient;
|
|
7
|
+
protected logger: Logger;
|
|
8
|
+
constructor(baseRPCUrl: string, walletClient: WalletClient, logger?: Logger);
|
|
9
|
+
getSourceAddress(_params: {
|
|
10
|
+
amount: BigNumber;
|
|
11
|
+
currency: Currency;
|
|
12
|
+
receiver: string;
|
|
13
|
+
memo: string;
|
|
14
|
+
}): string;
|
|
15
|
+
generateJWT({ paymentRequestId, codeChallenge, accountId }: {
|
|
16
|
+
paymentRequestId: string;
|
|
17
|
+
codeChallenge: string;
|
|
18
|
+
accountId?: AccountId | null;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
makePayment(destinations: Destination[], _memo: string, _paymentRequestId?: string): Promise<PaymentIdentifier | null>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=basePaymentMaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basePaymentMaker.d.ts","sourceRoot":"","sources":["../src/basePaymentMaker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAO,MAAM,cAAc,CAAC;AAWtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3F,OAAO,EAKL,YAAY,EACZ,aAAa,EACd,MAAM,MAAM,CAAC;AAMd,KAAK,oBAAoB,GAAG,YAAY,GAAG,aAAa,CAAC;AA6CzD,qBAAa,gBAAiB,YAAW,YAAY;IACnD,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC;IAC9C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEb,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM;IAe3E,gBAAgB,CAAC,OAAO,EAAE;QAAC,MAAM,EAAE,SAAS,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM;IAIpG,WAAW,CAAC,EAAC,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAC,EAAE;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAsC3J,WAAW,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAkH7H"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { UnsupportedCurrencyError, InsufficientFundsError, TransactionRevertedError, ATXPPaymentError, UserRejectedError, GasEstimationError, RpcError, PaymentNetworkError } from '@atxp/client';
|
|
2
|
+
import { ConsoleLogger } from '@atxp/common';
|
|
3
|
+
import { publicActions, encodeFunctionData, parseEther } from 'viem';
|
|
4
|
+
import { base } from 'viem/chains';
|
|
5
|
+
import { BigNumber } from 'bignumber.js';
|
|
6
|
+
import { USDC_CONTRACT_ADDRESS_BASE } from './baseConstants.js';
|
|
7
|
+
|
|
8
|
+
// Helper function to convert to base64url that works in both Node.js and browsers
|
|
9
|
+
function toBase64Url(data) {
|
|
10
|
+
// Convert string to base64
|
|
11
|
+
const base64 = typeof Buffer !== 'undefined'
|
|
12
|
+
? Buffer.from(data).toString('base64')
|
|
13
|
+
: btoa(data);
|
|
14
|
+
// Convert base64 to base64url
|
|
15
|
+
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
16
|
+
}
|
|
17
|
+
const USDC_DECIMALS = 6;
|
|
18
|
+
const ERC20_ABI = [
|
|
19
|
+
{
|
|
20
|
+
constant: false,
|
|
21
|
+
inputs: [
|
|
22
|
+
{ name: "_to", type: "address" },
|
|
23
|
+
{ name: "_value", type: "uint256" },
|
|
24
|
+
],
|
|
25
|
+
name: "transfer",
|
|
26
|
+
outputs: [{ name: "", type: "bool" }],
|
|
27
|
+
type: "function",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"constant": true,
|
|
31
|
+
"inputs": [
|
|
32
|
+
{
|
|
33
|
+
"name": "_owner",
|
|
34
|
+
"type": "address"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"name": "balanceOf",
|
|
38
|
+
"outputs": [
|
|
39
|
+
{
|
|
40
|
+
"name": "balance",
|
|
41
|
+
"type": "uint256"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"payable": false,
|
|
45
|
+
"stateMutability": "view",
|
|
46
|
+
"type": "function"
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
class BasePaymentMaker {
|
|
50
|
+
constructor(baseRPCUrl, walletClient, logger) {
|
|
51
|
+
if (!baseRPCUrl) {
|
|
52
|
+
throw new Error('baseRPCUrl was empty');
|
|
53
|
+
}
|
|
54
|
+
if (!walletClient) {
|
|
55
|
+
throw new Error('walletClient was empty');
|
|
56
|
+
}
|
|
57
|
+
if (!walletClient.account) {
|
|
58
|
+
throw new Error('walletClient.account was empty');
|
|
59
|
+
}
|
|
60
|
+
this.signingClient = walletClient.extend(publicActions);
|
|
61
|
+
this.logger = logger ?? new ConsoleLogger();
|
|
62
|
+
}
|
|
63
|
+
getSourceAddress(_params) {
|
|
64
|
+
return this.signingClient.account.address;
|
|
65
|
+
}
|
|
66
|
+
async generateJWT({ paymentRequestId, codeChallenge, accountId }) {
|
|
67
|
+
const headerObj = { alg: 'ES256K' };
|
|
68
|
+
const payloadObj = {
|
|
69
|
+
sub: this.signingClient.account.address,
|
|
70
|
+
iss: 'accounts.atxp.ai',
|
|
71
|
+
aud: 'https://auth.atxp.ai',
|
|
72
|
+
iat: Math.floor(Date.now() / 1000),
|
|
73
|
+
exp: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
74
|
+
...(codeChallenge ? { code_challenge: codeChallenge } : {}),
|
|
75
|
+
...(paymentRequestId ? { payment_request_id: paymentRequestId } : {}),
|
|
76
|
+
...(accountId ? { account_id: accountId } : {}),
|
|
77
|
+
};
|
|
78
|
+
const header = toBase64Url(JSON.stringify(headerObj));
|
|
79
|
+
const payload = toBase64Url(JSON.stringify(payloadObj));
|
|
80
|
+
const message = `${header}.${payload}`;
|
|
81
|
+
const messageBytes = typeof Buffer !== 'undefined'
|
|
82
|
+
? Buffer.from(message, 'utf8')
|
|
83
|
+
: new TextEncoder().encode(message);
|
|
84
|
+
const signResult = await this.signingClient.signMessage({
|
|
85
|
+
account: this.signingClient.account,
|
|
86
|
+
message: { raw: messageBytes },
|
|
87
|
+
});
|
|
88
|
+
// For ES256K, signature is typically 65 bytes (r,s,v)
|
|
89
|
+
// Server expects the hex signature string (with 0x prefix) to be base64url encoded
|
|
90
|
+
// This creates: base64url("0x6eb2565...") not base64url(rawBytes)
|
|
91
|
+
// Pass the hex string directly to toBase64Url which will UTF-8 encode and base64url it
|
|
92
|
+
const signature = toBase64Url(signResult);
|
|
93
|
+
const jwt = `${header}.${payload}.${signature}`;
|
|
94
|
+
this.logger.info(`Generated ES256K JWT: ${jwt}`);
|
|
95
|
+
return jwt;
|
|
96
|
+
}
|
|
97
|
+
async makePayment(destinations, _memo, _paymentRequestId) {
|
|
98
|
+
// Filter to base chain destinations
|
|
99
|
+
const baseDestinations = destinations.filter(d => d.chain === 'base');
|
|
100
|
+
if (baseDestinations.length === 0) {
|
|
101
|
+
this.logger.debug('BasePaymentMaker: No base destinations found, cannot handle payment');
|
|
102
|
+
return null; // Cannot handle these destinations
|
|
103
|
+
}
|
|
104
|
+
// Pick first base destination
|
|
105
|
+
const dest = baseDestinations[0];
|
|
106
|
+
const amount = dest.amount;
|
|
107
|
+
const currency = dest.currency;
|
|
108
|
+
const receiver = dest.address;
|
|
109
|
+
if (currency.toUpperCase() !== 'USDC') {
|
|
110
|
+
throw new UnsupportedCurrencyError(currency, 'base', ['USDC']);
|
|
111
|
+
}
|
|
112
|
+
this.logger.info(`Making payment of ${amount} ${currency} to ${receiver} on Base from ${this.signingClient.account.address}`);
|
|
113
|
+
try {
|
|
114
|
+
// Check balance before attempting payment
|
|
115
|
+
const balanceRaw = await this.signingClient.readContract({
|
|
116
|
+
address: USDC_CONTRACT_ADDRESS_BASE,
|
|
117
|
+
abi: ERC20_ABI,
|
|
118
|
+
functionName: 'balanceOf',
|
|
119
|
+
args: [this.signingClient.account.address],
|
|
120
|
+
});
|
|
121
|
+
const balance = new BigNumber(balanceRaw.toString()).dividedBy(10 ** USDC_DECIMALS);
|
|
122
|
+
if (balance.lt(amount)) {
|
|
123
|
+
this.logger.warn(`Insufficient ${currency} balance for payment. Required: ${amount}, Available: ${balance}`);
|
|
124
|
+
throw new InsufficientFundsError(currency, amount, balance, 'base');
|
|
125
|
+
}
|
|
126
|
+
// Convert amount to USDC units (6 decimals) as BigInt
|
|
127
|
+
const amountInUSDCUnits = BigInt(amount.multipliedBy(10 ** USDC_DECIMALS).toFixed(0));
|
|
128
|
+
const data = encodeFunctionData({
|
|
129
|
+
abi: ERC20_ABI,
|
|
130
|
+
functionName: "transfer",
|
|
131
|
+
args: [receiver, amountInUSDCUnits],
|
|
132
|
+
});
|
|
133
|
+
const hash = await this.signingClient.sendTransaction({
|
|
134
|
+
chain: base,
|
|
135
|
+
account: this.signingClient.account,
|
|
136
|
+
to: USDC_CONTRACT_ADDRESS_BASE,
|
|
137
|
+
data: data,
|
|
138
|
+
value: parseEther('0'),
|
|
139
|
+
maxPriorityFeePerGas: parseEther('0.000000001')
|
|
140
|
+
});
|
|
141
|
+
// Wait for transaction confirmation with more blocks to ensure propagation
|
|
142
|
+
this.logger.info(`Waiting for transaction confirmation: ${hash}`);
|
|
143
|
+
const receipt = await this.signingClient.waitForTransactionReceipt({
|
|
144
|
+
hash: hash,
|
|
145
|
+
confirmations: 1
|
|
146
|
+
});
|
|
147
|
+
if (receipt.status === 'reverted') {
|
|
148
|
+
// Try to extract revert reason if available
|
|
149
|
+
// Note: viem doesn't provide revert reason in receipt, would need additional call
|
|
150
|
+
throw new TransactionRevertedError(hash, 'base');
|
|
151
|
+
}
|
|
152
|
+
this.logger.info(`Transaction confirmed: ${hash} in block ${receipt.blockNumber}`);
|
|
153
|
+
// Return payment result with chain and currency
|
|
154
|
+
return {
|
|
155
|
+
transactionId: hash,
|
|
156
|
+
chain: 'base',
|
|
157
|
+
currency: 'USDC'
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
// Re-throw our custom payment errors
|
|
162
|
+
if (error instanceof ATXPPaymentError) {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
// Categorize viem/blockchain errors
|
|
166
|
+
const errorMessage = error.message || '';
|
|
167
|
+
const errorName = error.name || '';
|
|
168
|
+
// User rejected in wallet
|
|
169
|
+
if (errorMessage.includes('User rejected') ||
|
|
170
|
+
errorMessage.includes('user rejected') ||
|
|
171
|
+
errorMessage.includes('User denied') ||
|
|
172
|
+
errorName === 'UserRejectedRequestError') {
|
|
173
|
+
throw new UserRejectedError('base');
|
|
174
|
+
}
|
|
175
|
+
// Gas estimation failed
|
|
176
|
+
if (errorMessage.includes('gas') &&
|
|
177
|
+
(errorMessage.includes('estimation') || errorMessage.includes('estimate'))) {
|
|
178
|
+
throw new GasEstimationError('base', errorMessage);
|
|
179
|
+
}
|
|
180
|
+
// RPC/network errors
|
|
181
|
+
if (errorMessage.includes('fetch failed') ||
|
|
182
|
+
errorMessage.includes('network') ||
|
|
183
|
+
errorMessage.includes('timeout') ||
|
|
184
|
+
errorMessage.includes('ECONNREFUSED') ||
|
|
185
|
+
errorMessage.includes('ETIMEDOUT') ||
|
|
186
|
+
errorName === 'FetchError') {
|
|
187
|
+
throw new RpcError('base', undefined, error);
|
|
188
|
+
}
|
|
189
|
+
// Fallback to generic network error with original error attached
|
|
190
|
+
throw new PaymentNetworkError('base', errorMessage || 'Unknown error', error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export { BasePaymentMaker };
|
|
196
|
+
//# sourceMappingURL=basePaymentMaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basePaymentMaker.js","sources":["../src/basePaymentMaker.ts"],"sourcesContent":[null],"names":["InsufficientFundsErrorClass","PaymentNetworkErrorClass"],"mappings":";;;;;;;AA4BA;AACA,SAAS,WAAW,CAAC,IAAY,EAAA;;AAE/B,IAAA,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK;UAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ;AACrC,UAAE,IAAI,CAAC,IAAI,CAAC;;IAEd,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;AACzE;AAEA,MAAM,aAAa,GAAG,CAAC;AACvB,MAAM,SAAS,GAAG;AAChB,IAAA;AACE,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,MAAM,EAAE;AACN,YAAA,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE;AAChC,YAAA,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;AACpC,SAAA;AACD,QAAA,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,C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