@atxp/base 0.10.5 → 0.10.6
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/baseAppPaymentMaker.d.ts +24 -0
- package/dist/baseConstants.d.ts +10 -0
- package/dist/basePaymentMaker.d.ts +23 -0
- package/dist/cache.d.ts +19 -0
- package/dist/mainWalletPaymentMaker.d.ts +30 -0
- package/dist/smartWalletHelpers.d.ts +19 -0
- package/dist/spendPermissionShim.d.ts +19 -0
- package/dist/testHelpers.d.ts +79 -0
- package/dist/types.d.ts +41 -0
- package/package.json +3 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Logger, Currency, PaymentMaker, AccountId, PaymentIdentifier, Destination } from '@atxp/common';
|
|
2
|
+
import { SpendPermission } from './types.js';
|
|
3
|
+
import { type EphemeralSmartWallet } from './smartWalletHelpers.js';
|
|
4
|
+
export declare class BaseAppPaymentMaker implements PaymentMaker {
|
|
5
|
+
private logger;
|
|
6
|
+
private spendPermission;
|
|
7
|
+
private smartWallet;
|
|
8
|
+
private chainId;
|
|
9
|
+
private usdcAddress;
|
|
10
|
+
constructor(spendPermission: SpendPermission, smartWallet: EphemeralSmartWallet, logger?: Logger, chainId?: number);
|
|
11
|
+
getSourceAddress(_params: {
|
|
12
|
+
amount: BigNumber;
|
|
13
|
+
currency: Currency;
|
|
14
|
+
receiver: string;
|
|
15
|
+
memo: string;
|
|
16
|
+
}): string;
|
|
17
|
+
generateJWT({ paymentRequestId, codeChallenge, accountId }: {
|
|
18
|
+
paymentRequestId: string;
|
|
19
|
+
codeChallenge: string;
|
|
20
|
+
accountId?: AccountId | null;
|
|
21
|
+
}): Promise<string>;
|
|
22
|
+
makePayment(destinations: Destination[], memo: string, _paymentRequestId?: string): Promise<PaymentIdentifier | null>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=baseAppPaymentMaker.d.ts.map
|
|
@@ -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,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
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SpendPermission } from './types.js';
|
|
2
|
+
import { Hex } from '@atxp/client';
|
|
3
|
+
import { type ICache, JsonCache, BrowserCache, MemoryCache } from '@atxp/common';
|
|
4
|
+
/**
|
|
5
|
+
* Stored permission data structure
|
|
6
|
+
*/
|
|
7
|
+
export interface Intermediary {
|
|
8
|
+
/** Ephemeral wallet private key */
|
|
9
|
+
privateKey: Hex;
|
|
10
|
+
/** Spend permission from Base */
|
|
11
|
+
permission: SpendPermission;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Type-safe cache wrapper for permission data
|
|
15
|
+
*/
|
|
16
|
+
export declare class IntermediaryCache extends JsonCache<Intermediary> {
|
|
17
|
+
}
|
|
18
|
+
export { type ICache, BrowserCache, MemoryCache };
|
|
19
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { Logger, Currency, PaymentMaker, AccountId, PaymentIdentifier, Destination } from '@atxp/common';
|
|
3
|
+
export type MainWalletProvider = {
|
|
4
|
+
request: (params: {
|
|
5
|
+
method: string;
|
|
6
|
+
params?: any[];
|
|
7
|
+
}) => Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
export declare class MainWalletPaymentMaker implements PaymentMaker {
|
|
10
|
+
private walletAddress;
|
|
11
|
+
private provider;
|
|
12
|
+
private logger;
|
|
13
|
+
private chainId;
|
|
14
|
+
private usdcAddress;
|
|
15
|
+
constructor(walletAddress: string, provider: MainWalletProvider, logger?: Logger, chainId?: number);
|
|
16
|
+
getSourceAddress(_params: {
|
|
17
|
+
amount: BigNumber;
|
|
18
|
+
currency: Currency;
|
|
19
|
+
receiver: string;
|
|
20
|
+
memo: string;
|
|
21
|
+
}): string;
|
|
22
|
+
generateJWT(payload: {
|
|
23
|
+
paymentRequestId: string;
|
|
24
|
+
codeChallenge: string;
|
|
25
|
+
accountId?: AccountId | null;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
makePayment(destinations: Destination[], _memo: string, _paymentRequestId?: string): Promise<PaymentIdentifier | null>;
|
|
28
|
+
private waitForTransactionConfirmations;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=mainWalletPaymentMaker.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Account, type Address, type Hex } from 'viem';
|
|
2
|
+
import { type BundlerClient, type SmartAccount } from 'viem/account-abstraction';
|
|
3
|
+
export interface EphemeralSmartWallet {
|
|
4
|
+
address: Address;
|
|
5
|
+
client: BundlerClient;
|
|
6
|
+
account: SmartAccount;
|
|
7
|
+
signer: Account;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates an ephemeral smart wallet with paymaster support.
|
|
11
|
+
*
|
|
12
|
+
* Uses Alchemy infrastructure if ALCHEMY_API_KEY and ALCHEMY_GAS_POLICY_ID
|
|
13
|
+
* environment variables are set, otherwise falls back to Coinbase.
|
|
14
|
+
*
|
|
15
|
+
* @param privateKey - Private key for the wallet signer
|
|
16
|
+
* @param chainId - Chain ID (defaults to 8453 for Base mainnet, can be 84532 for Base Sepolia)
|
|
17
|
+
*/
|
|
18
|
+
export declare function toEphemeralSmartWallet(privateKey: Hex, chainId?: number): Promise<EphemeralSmartWallet>;
|
|
19
|
+
//# sourceMappingURL=smartWalletHelpers.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Eip1193Provider, SpendPermission } from "./types.js";
|
|
2
|
+
export declare function requestSpendPermission(params: {
|
|
3
|
+
account: string;
|
|
4
|
+
spender: string;
|
|
5
|
+
token: string;
|
|
6
|
+
chainId: number;
|
|
7
|
+
allowance: bigint;
|
|
8
|
+
periodInDays: number;
|
|
9
|
+
provider: Eip1193Provider;
|
|
10
|
+
}): Promise<SpendPermission>;
|
|
11
|
+
export declare function prepareSpendCallData(params: {
|
|
12
|
+
permission: SpendPermission;
|
|
13
|
+
amount: bigint;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
to: string;
|
|
16
|
+
data: string;
|
|
17
|
+
value: bigint;
|
|
18
|
+
}[]>;
|
|
19
|
+
//# sourceMappingURL=spendPermissionShim.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { SpendPermission } from './types.js';
|
|
2
|
+
import type { EphemeralSmartWallet } from './smartWalletHelpers.js';
|
|
3
|
+
import type { Address } from 'viem';
|
|
4
|
+
export declare const TEST_WALLET_ADDRESS: Address;
|
|
5
|
+
export declare const TEST_SMART_WALLET_ADDRESS: Address;
|
|
6
|
+
export declare const TEST_RECEIVER_ADDRESS: Address;
|
|
7
|
+
export declare const TEST_PRIVATE_KEY: `0x${string}`;
|
|
8
|
+
export declare const TEST_PAYMASTER_URL = "https://api.developer.coinbase.com/rpc/v1/base/snPdXqIzOGhRkGNJvEHM5bl9Hm3yRO3m";
|
|
9
|
+
export declare const TEST_BUNDLER_URL = "https://api.developer.coinbase.com/rpc/v1/base";
|
|
10
|
+
export declare function mockProvider({ request }?: {
|
|
11
|
+
request?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
|
|
12
|
+
}): {
|
|
13
|
+
request: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
14
|
+
};
|
|
15
|
+
export declare function mockSpendPermission({ signature, account, spender, token, allowance, // 10 USDC
|
|
16
|
+
period, // 7 days
|
|
17
|
+
start, end, salt, extraData, chainId }?: {
|
|
18
|
+
signature?: `0x${string}` | undefined;
|
|
19
|
+
account?: `0x${string}` | undefined;
|
|
20
|
+
spender?: `0x${string}` | undefined;
|
|
21
|
+
token?: string | undefined;
|
|
22
|
+
allowance?: string | undefined;
|
|
23
|
+
period?: number | undefined;
|
|
24
|
+
start?: number | undefined;
|
|
25
|
+
end?: number | undefined;
|
|
26
|
+
salt?: string | undefined;
|
|
27
|
+
extraData?: `0x${string}` | undefined;
|
|
28
|
+
chainId?: 8453 | undefined;
|
|
29
|
+
}): SpendPermission;
|
|
30
|
+
export declare function removeTimestamps<T extends Record<string, any>>(obj: T): T;
|
|
31
|
+
export declare function expectTimestampAround(timestamp: number, expectedOffset?: number, tolerance?: number): void;
|
|
32
|
+
export declare function mockExpiredSpendPermission(overrides?: {}): SpendPermission;
|
|
33
|
+
export declare function mockSmartAccount({ address, signMessage }?: {
|
|
34
|
+
address?: `0x${string}` | undefined;
|
|
35
|
+
signMessage?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
|
|
36
|
+
}): any;
|
|
37
|
+
export declare function mockBundlerClient({ sendUserOperation, waitForUserOperationReceipt, waitForTransactionReceipt }?: {
|
|
38
|
+
sendUserOperation?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
|
|
39
|
+
waitForUserOperationReceipt?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
|
|
40
|
+
waitForTransactionReceipt?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
|
|
41
|
+
}): any;
|
|
42
|
+
export declare function mockFailedBundlerClient({ failureType }?: {
|
|
43
|
+
failureType?: string | undefined;
|
|
44
|
+
}): any;
|
|
45
|
+
export declare function mockEphemeralSmartWallet({ address, account, client, privateKey }?: {
|
|
46
|
+
address?: `0x${string}` | undefined;
|
|
47
|
+
account?: any;
|
|
48
|
+
client?: any;
|
|
49
|
+
privateKey?: `0x${string}` | undefined;
|
|
50
|
+
}): EphemeralSmartWallet;
|
|
51
|
+
export declare function mockSpendCalls({ calls }?: {
|
|
52
|
+
calls?: {
|
|
53
|
+
to: string;
|
|
54
|
+
data: string;
|
|
55
|
+
value: string;
|
|
56
|
+
}[] | undefined;
|
|
57
|
+
}): {
|
|
58
|
+
to: string;
|
|
59
|
+
data: string;
|
|
60
|
+
value: string;
|
|
61
|
+
}[];
|
|
62
|
+
export declare function setupInitializationMocks({ provider, smartAccount, bundlerClient, spendPermission, ephemeralWallet }?: {
|
|
63
|
+
provider?: {
|
|
64
|
+
request: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
65
|
+
} | undefined;
|
|
66
|
+
smartAccount?: any;
|
|
67
|
+
bundlerClient?: any;
|
|
68
|
+
spendPermission?: SpendPermission | undefined;
|
|
69
|
+
ephemeralWallet?: EphemeralSmartWallet | undefined;
|
|
70
|
+
}): Promise<any>;
|
|
71
|
+
export declare function setupPaymentMocks({ spendCalls }?: {
|
|
72
|
+
spendCalls?: {
|
|
73
|
+
to: string;
|
|
74
|
+
data: string;
|
|
75
|
+
value: string;
|
|
76
|
+
}[] | undefined;
|
|
77
|
+
}): Promise<any>;
|
|
78
|
+
export declare function getCacheKey(walletAddress: string): string;
|
|
79
|
+
//# sourceMappingURL=testHelpers.d.ts.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a spending permission with limits
|
|
3
|
+
*/
|
|
4
|
+
export type SpendPermission = {
|
|
5
|
+
/** UTC timestamp for when the permission was granted */
|
|
6
|
+
createdAt?: number;
|
|
7
|
+
/** Hash of the permission in hex format */
|
|
8
|
+
permissionHash?: string;
|
|
9
|
+
/** Cryptographic signature in hex format */
|
|
10
|
+
signature: string;
|
|
11
|
+
/** Chain ID */
|
|
12
|
+
chainId?: number;
|
|
13
|
+
/** The permission details */
|
|
14
|
+
permission: {
|
|
15
|
+
/** Wallet address of the account */
|
|
16
|
+
account: string;
|
|
17
|
+
/** Address of the contract/entity allowed to spend */
|
|
18
|
+
spender: string;
|
|
19
|
+
/** Address of the token being spent */
|
|
20
|
+
token: string;
|
|
21
|
+
/** Maximum amount allowed as base 10 numeric string */
|
|
22
|
+
allowance: string;
|
|
23
|
+
/** Time period in seconds */
|
|
24
|
+
period: number;
|
|
25
|
+
/** Start time in unix seconds */
|
|
26
|
+
start: number;
|
|
27
|
+
/** Expiration time in unix seconds */
|
|
28
|
+
end: number;
|
|
29
|
+
/** Salt as base 10 numeric string */
|
|
30
|
+
salt: string;
|
|
31
|
+
/** Additional data in hex format */
|
|
32
|
+
extraData: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type Eip1193Provider = {
|
|
36
|
+
request: (params: {
|
|
37
|
+
method: string;
|
|
38
|
+
params?: unknown[];
|
|
39
|
+
}) => Promise<unknown>;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atxp/base",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6",
|
|
4
4
|
"description": "ATXP for Base Mini Apps",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@account-kit/infra": "^4.81.3",
|
|
37
|
-
"@atxp/client": "0.10.
|
|
38
|
-
"@atxp/common": "0.10.
|
|
37
|
+
"@atxp/client": "0.10.6",
|
|
38
|
+
"@atxp/common": "0.10.6",
|
|
39
39
|
"bignumber.js": "^9.3.0",
|
|
40
40
|
"viem": "^2.34.0"
|
|
41
41
|
},
|