@atxp/worldchain 0.10.8 → 0.10.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atxp/worldchain",
3
- "version": "0.10.8",
3
+ "version": "0.10.11",
4
4
  "description": "ATXP for World Chain Mini Apps",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -33,8 +33,8 @@
33
33
  "pack:dry": "npm pack --dry-run"
34
34
  },
35
35
  "dependencies": {
36
- "@atxp/client": "0.10.8",
37
- "@atxp/common": "0.10.8",
36
+ "@atxp/client": "0.10.11",
37
+ "@atxp/common": "0.10.11",
38
38
  "@worldcoin/minikit-js": "^1.9.6",
39
39
  "bignumber.js": "^9.3.0",
40
40
  "viem": "^2.34.0"
package/dist/cache.d.ts DELETED
@@ -1,19 +0,0 @@
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 World Chain */
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
@@ -1,29 +0,0 @@
1
- import { Logger, Currency, PaymentMaker, AccountId, PaymentIdentifier, Destination } from '@atxp/common';
2
- import BigNumber from 'bignumber.js';
3
- export type MainWalletProvider = {
4
- request: (params: {
5
- method: string;
6
- params?: unknown[];
7
- }) => Promise<unknown>;
8
- };
9
- export declare class MainWalletPaymentMaker implements PaymentMaker {
10
- private walletAddress;
11
- private provider;
12
- private logger;
13
- private chainId;
14
- private customRpcUrl?;
15
- constructor(walletAddress: string, provider: MainWalletProvider, logger?: Logger, chainId?: number, customRpcUrl?: string);
16
- getSourceAddress(_params: {
17
- amount: BigNumber;
18
- currency: Currency;
19
- receiver: string;
20
- memo: string;
21
- }): string;
22
- generateJWT({ paymentRequestId, codeChallenge, accountId }: {
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
- }
29
- //# sourceMappingURL=mainWalletPaymentMaker.d.ts.map
package/dist/minikit.d.ts DELETED
@@ -1,76 +0,0 @@
1
- import type { MiniKit as MiniKitType } from "@worldcoin/minikit-js";
2
- import { Logger } from "@atxp/common";
3
- import { WorldchainAccount } from "./worldchainAccount.js";
4
- /**
5
- * Loads and initializes a Worldchain account with MiniKit integration
6
- *
7
- * This function creates a Worldchain account that can interact with the World Chain network
8
- * using MiniKit for transaction signing and wallet operations. It sets up a custom provider
9
- * that handles various Ethereum JSON-RPC methods through MiniKit's interface.
10
- *
11
- * @param walletAddress - The wallet address to use for the account
12
- * @param logger - Optional logger instance for debugging and monitoring
13
- * @param customRpcUrl - Optional custom RPC URL for Worldchain. If not provided, uses the public RPC endpoint
14
- * @param chainId - Optional chain ID (defaults to 480 for mainnet, can be 4801 for sepolia)
15
- * @param miniKit - The MiniKit instance to use for transactions and signing
16
- * @returns Promise that resolves to an initialized WorldchainAccount instance
17
- *
18
- * @example
19
- * ```typescript
20
- * // Using public RPC endpoint (mainnet)
21
- * const account = await createMiniKitWorldchainAccount({
22
- * walletAddress: "0x1234...",
23
- * logger: new ConsoleLogger(),
24
- * miniKit: MiniKit
25
- * });
26
- *
27
- * // Using sepolia testnet
28
- * const account = await createMiniKitWorldchainAccount({
29
- * walletAddress: "0x1234...",
30
- * logger: new ConsoleLogger(),
31
- * chainId: 4801,
32
- * miniKit: MiniKit
33
- * });
34
- * ```
35
- *
36
- * @remarks
37
- * The function creates a custom provider that supports:
38
- * - `eth_accounts`: Returns the wallet address
39
- * - `eth_chainId`: Returns Worldchain chain ID (configurable)
40
- * - `eth_requestAccounts`: Returns the wallet address
41
- * - `eth_sendTransaction`: Handles USDC transfers and other transactions via MiniKit
42
- * - `personal_sign`: Signs messages using MiniKit
43
- *
44
- * The account is configured with:
45
- * - 10 USDC allowance
46
- * - 30-day period for permissions
47
- * - Worldchain RPC endpoint (public or custom)
48
- * - Regular wallet mode (no ephemeral wallet)
49
- *
50
- * @throws {Error} When MiniKit operations fail or unsupported transaction types are encountered
51
- */
52
- export declare const createMiniKitWorldchainAccount: ({ walletAddress, logger: loggerParam, customRpcUrl, chainId, miniKit }: {
53
- walletAddress: string;
54
- logger?: Logger;
55
- customRpcUrl?: string;
56
- chainId?: number;
57
- miniKit: typeof MiniKitType;
58
- }) => Promise<WorldchainAccount>;
59
- /**
60
- * Resolves a MiniKit transaction ID to the actual blockchain transaction hash
61
- * using the World API
62
- */
63
- export declare function resolveTransactionHash(transactionId: string, logger: Logger): Promise<{
64
- transactionHash: string;
65
- status: string;
66
- } | null>;
67
- /**
68
- * Waits for a MiniKit transaction to be confirmed and returns the transaction hash
69
- * Polls the World API until the transaction is confirmed or times out
70
- */
71
- export declare function waitForTransactionConfirmation(transactionId: string, logger: Logger, timeoutMs?: number, // 2 minutes
72
- pollIntervalMs?: number): Promise<{
73
- transactionHash: string;
74
- status: string;
75
- } | null>;
76
- //# sourceMappingURL=minikit.d.ts.map
@@ -1,26 +0,0 @@
1
- import { type Account, type Address, type Hex } from 'viem';
2
- import { type BundlerClient, type SmartAccount } from 'viem/account-abstraction';
3
- export declare const DEFAULT_WORLD_CHAIN_MAINNET_RPC = "https://worldchain-mainnet.g.alchemy.com/public";
4
- export declare const DEFAULT_WORLD_CHAIN_SEPOLIA_RPC = "https://worldchain-sepolia.g.alchemy.com/public";
5
- /**
6
- * Get default RPC URL for a World Chain by chain ID
7
- */
8
- export declare const getDefaultWorldChainRPC: (chainId: number) => string;
9
- export interface EphemeralSmartWallet {
10
- address: Address;
11
- client: BundlerClient;
12
- account: SmartAccount;
13
- signer: Account;
14
- }
15
- /**
16
- * Creates an ephemeral smart wallet for World Chain
17
- * Note: This implementation uses Coinbase's smart wallet infrastructure
18
- * adapted for World Chain. This may need updates when World Chain
19
- * provides their own account abstraction infrastructure.
20
- *
21
- * @param privateKey - Private key for the wallet signer
22
- * @param rpcUrl - Optional custom RPC URL
23
- * @param chainId - Chain ID (defaults to 480 for mainnet)
24
- */
25
- export declare function toEphemeralSmartWallet(privateKey: Hex, rpcUrl?: string, chainId?: number): Promise<EphemeralSmartWallet>;
26
- //# sourceMappingURL=smartWalletHelpers.d.ts.map
@@ -1,19 +0,0 @@
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
@@ -1,104 +0,0 @@
1
- import type { SpendPermission } from './types.js';
2
- import type { EphemeralSmartWallet } from './smartWalletHelpers.js';
3
- import { WorldchainPaymentMaker, type ConfirmationDelays, type WorldchainPaymentMakerOptions } from './worldchainPaymentMaker.js';
4
- import type { Address } from 'viem';
5
- export declare const TEST_WALLET_ADDRESS: Address;
6
- export declare const TEST_SMART_WALLET_ADDRESS: Address;
7
- export declare const TEST_RECEIVER_ADDRESS: Address;
8
- export declare const TEST_PRIVATE_KEY: `0x${string}`;
9
- export declare const TEST_PAYMASTER_URL = "https://worldchain-bundler.example.com";
10
- export declare const TEST_BUNDLER_URL = "https://worldchain-bundler.example.com";
11
- export declare const TEST_CONFIRMATION_DELAYS: ConfirmationDelays;
12
- export declare function mockProvider({ request }?: {
13
- request?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
14
- }): {
15
- request: import("vitest").Mock<import("@vitest/spy").Procedure>;
16
- };
17
- export declare function mockSpendPermission({ signature, account, spender, token, allowance, // 10 USDC
18
- period, // 7 days
19
- start, end, salt, extraData, chainId }?: {
20
- signature?: `0x${string}` | undefined;
21
- account?: `0x${string}` | undefined;
22
- spender?: `0x${string}` | undefined;
23
- token?: string | undefined;
24
- allowance?: string | undefined;
25
- period?: number | undefined;
26
- start?: number | undefined;
27
- end?: number | undefined;
28
- salt?: string | undefined;
29
- extraData?: `0x${string}` | undefined;
30
- chainId?: number | undefined;
31
- }): SpendPermission;
32
- export declare function removeTimestamps<T extends Record<string, any>>(obj: T): T;
33
- export declare function expectTimestampAround(timestamp: number, expectedOffset?: number, tolerance?: number): void;
34
- export declare function mockExpiredSpendPermission(overrides?: {}): SpendPermission;
35
- export declare function mockSmartAccount({ address, signMessage }?: {
36
- address?: `0x${string}` | undefined;
37
- signMessage?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
38
- }): any;
39
- export declare function mockBundlerClient({ sendUserOperation, waitForUserOperationReceipt, waitForTransactionReceipt }?: {
40
- sendUserOperation?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
41
- waitForUserOperationReceipt?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
42
- waitForTransactionReceipt?: import("vitest").Mock<import("@vitest/spy").Procedure> | undefined;
43
- }): any;
44
- export declare function mockFailedBundlerClient({ failureType }?: {
45
- failureType?: string | undefined;
46
- }): any;
47
- export declare function mockEphemeralSmartWallet({ address, account, client, privateKey }?: {
48
- address?: `0x${string}` | undefined;
49
- account?: any;
50
- client?: any;
51
- privateKey?: `0x${string}` | undefined;
52
- }): EphemeralSmartWallet;
53
- export declare function mockSpendCalls({ calls }?: {
54
- calls?: {
55
- to: string;
56
- data: string;
57
- value: string;
58
- }[] | undefined;
59
- }): {
60
- to: string;
61
- data: string;
62
- value: string;
63
- }[];
64
- /**
65
- * Helper to create a WorldchainPaymentMaker for testing with fast confirmation delays
66
- *
67
- * @param permission - Spend permission (defaults to mock)
68
- * @param smartWallet - Smart wallet (defaults to mock)
69
- * @param options - Additional options
70
- * @returns WorldchainPaymentMaker configured for testing
71
- */
72
- export declare function createTestWorldchainPaymentMaker(permission?: SpendPermission, smartWallet?: EphemeralSmartWallet, options?: Partial<WorldchainPaymentMakerOptions>): WorldchainPaymentMaker;
73
- /**
74
- * Builder pattern for creating test payment makers with fluent API
75
- */
76
- export declare class TestWorldchainPaymentMakerBuilder {
77
- private permission?;
78
- private smartWallet?;
79
- private options;
80
- withPermission(permission: SpendPermission): this;
81
- withSmartWallet(wallet: EphemeralSmartWallet): this;
82
- withTestDelays(delays?: ConfirmationDelays): this;
83
- withChainId(chainId: number): this;
84
- withCustomRpc(rpcUrl: string): this;
85
- build(): WorldchainPaymentMaker;
86
- }
87
- export declare function setupInitializationMocks({ provider, smartAccount, bundlerClient, spendPermission, ephemeralWallet }?: {
88
- provider?: {
89
- request: import("vitest").Mock<import("@vitest/spy").Procedure>;
90
- } | undefined;
91
- smartAccount?: any;
92
- bundlerClient?: any;
93
- spendPermission?: SpendPermission | undefined;
94
- ephemeralWallet?: EphemeralSmartWallet | undefined;
95
- }): Promise<any>;
96
- export declare function setupPaymentMocks({ spendCalls }?: {
97
- spendCalls?: {
98
- to: string;
99
- data: string;
100
- value: string;
101
- }[] | undefined;
102
- }): Promise<any>;
103
- export declare function getCacheKey(walletAddress: string): string;
104
- //# sourceMappingURL=testHelpers.d.ts.map
package/dist/types.d.ts DELETED
@@ -1,41 +0,0 @@
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
@@ -1,80 +0,0 @@
1
- import { Logger, Currency, PaymentMaker, AccountId, PaymentIdentifier, Destination } from '@atxp/common';
2
- import BigNumber from 'bignumber.js';
3
- import { SpendPermission } from './types.js';
4
- import { type EphemeralSmartWallet } from './smartWalletHelpers.js';
5
- /**
6
- * Configuration for transaction confirmation delays
7
- */
8
- export interface ConfirmationDelays {
9
- /** Network propagation delay in milliseconds (must be >= 0) */
10
- networkPropagationMs: number;
11
- /** Confirmation failed delay in milliseconds (must be >= 0) */
12
- confirmationFailedMs: number;
13
- }
14
- /**
15
- * Options for configuring WorldchainPaymentMaker
16
- */
17
- export interface WorldchainPaymentMakerOptions {
18
- /** Logger instance for debug output */
19
- logger?: Logger;
20
- /** Chain ID (defaults to World Chain Mainnet) */
21
- chainId?: number;
22
- /** Custom RPC URL for the chain */
23
- customRpcUrl?: string;
24
- /** Custom confirmation delays (defaults to production values) */
25
- confirmationDelays?: ConfirmationDelays;
26
- }
27
- /**
28
- * Gets default confirmation delays based on environment
29
- */
30
- export declare const getDefaultConfirmationDelays: () => ConfirmationDelays;
31
- /**
32
- * Payment maker for World Chain transactions using smart wallets and spend permissions
33
- *
34
- * @example
35
- * ```typescript
36
- * // For production use (default delays)
37
- * const paymentMaker = new WorldchainPaymentMaker(permission, wallet);
38
- *
39
- * // For testing (fast delays)
40
- * const paymentMaker = new WorldchainPaymentMaker(permission, wallet, {
41
- * confirmationDelays: { networkPropagationMs: 10, confirmationFailedMs: 20 }
42
- * });
43
- *
44
- * // With custom configuration
45
- * const paymentMaker = new WorldchainPaymentMaker(permission, wallet, {
46
- * chainId: 480, // World Chain Mainnet
47
- * customRpcUrl: 'https://my-rpc.com',
48
- * logger: myLogger
49
- * });
50
- * ```
51
- */
52
- export declare class WorldchainPaymentMaker implements PaymentMaker {
53
- private logger;
54
- private spendPermission;
55
- private smartWallet;
56
- private chainId;
57
- private customRpcUrl?;
58
- private confirmationDelays;
59
- /**
60
- * Creates a new WorldchainPaymentMaker instance
61
- *
62
- * @param spendPermission - The spend permission for transactions
63
- * @param smartWallet - The smart wallet instance to use
64
- * @param options - Optional configuration
65
- */
66
- constructor(spendPermission: SpendPermission, smartWallet: EphemeralSmartWallet, options?: WorldchainPaymentMakerOptions);
67
- getSourceAddress(_params: {
68
- amount: BigNumber;
69
- currency: Currency;
70
- receiver: string;
71
- memo: string;
72
- }): string;
73
- generateJWT({ paymentRequestId, codeChallenge, accountId }: {
74
- paymentRequestId: string;
75
- codeChallenge: string;
76
- accountId?: AccountId | null;
77
- }): Promise<string>;
78
- makePayment(destinations: Destination[], memo: string, _paymentRequestId?: string): Promise<PaymentIdentifier | null>;
79
- }
80
- //# sourceMappingURL=worldchainPaymentMaker.d.ts.map