@atxp/base 0.2.22 → 0.3.0
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/baseAppAccount.js +6 -3
- package/dist/baseAppAccount.js.map +1 -1
- package/dist/baseAppPaymentMaker.js +22 -42
- package/dist/baseAppPaymentMaker.js.map +1 -1
- package/dist/eip1271JwtHelper.js +83 -0
- package/dist/eip1271JwtHelper.js.map +1 -0
- package/dist/index.cjs +630 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +157 -6
- package/dist/index.js +623 -5
- package/dist/index.js.map +1 -1
- package/dist/mainWalletPaymentMaker.js +26 -48
- package/dist/mainWalletPaymentMaker.js.map +1 -1
- package/dist/smartWalletHelpers.js +6 -3
- package/dist/smartWalletHelpers.js.map +1 -1
- package/dist/spendPermissionUtils.js +4 -2
- package/dist/spendPermissionUtils.js.map +1 -1
- package/dist/storage.js +6 -4
- package/dist/storage.js.map +1 -1
- package/package.json +21 -7
- package/dist/baseAppAccount.d.ts +0 -33
- package/dist/baseAppAccount.d.ts.map +0 -1
- package/dist/baseAppAccount.ephemeral.test.d.ts +0 -2
- package/dist/baseAppAccount.ephemeral.test.d.ts.map +0 -1
- package/dist/baseAppAccount.ephemeral.test.js +0 -426
- package/dist/baseAppAccount.ephemeral.test.js.map +0 -1
- package/dist/baseAppAccount.mainWallet.test.d.ts +0 -2
- package/dist/baseAppAccount.mainWallet.test.d.ts.map +0 -1
- package/dist/baseAppAccount.mainWallet.test.js +0 -259
- package/dist/baseAppAccount.mainWallet.test.js.map +0 -1
- package/dist/baseAppPaymentMaker.d.ts +0 -16
- package/dist/baseAppPaymentMaker.d.ts.map +0 -1
- package/dist/baseAppPaymentMaker.test.d.ts +0 -2
- package/dist/baseAppPaymentMaker.test.d.ts.map +0 -1
- package/dist/baseAppPaymentMaker.test.js +0 -113
- package/dist/baseAppPaymentMaker.test.js.map +0 -1
- package/dist/compatibility.test.d.ts +0 -2
- package/dist/compatibility.test.d.ts.map +0 -1
- package/dist/compatibility.test.js +0 -94
- package/dist/compatibility.test.js.map +0 -1
- package/dist/environment.test.d.ts +0 -2
- package/dist/environment.test.d.ts.map +0 -1
- package/dist/environment.test.js +0 -77
- package/dist/environment.test.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mainWalletPaymentMaker.d.ts +0 -22
- package/dist/mainWalletPaymentMaker.d.ts.map +0 -1
- package/dist/mainWalletPaymentMaker.test.d.ts +0 -2
- package/dist/mainWalletPaymentMaker.test.d.ts.map +0 -1
- package/dist/mainWalletPaymentMaker.test.js +0 -340
- package/dist/mainWalletPaymentMaker.test.js.map +0 -1
- package/dist/smartWalletHelpers.d.ts +0 -13
- package/dist/smartWalletHelpers.d.ts.map +0 -1
- package/dist/spendPermissionUtils.d.ts +0 -9
- package/dist/spendPermissionUtils.d.ts.map +0 -1
- package/dist/storage.d.ts +0 -51
- package/dist/storage.d.ts.map +0 -1
- package/dist/testHelpers.d.ts +0 -88
- package/dist/testHelpers.d.ts.map +0 -1
- package/dist/testHelpers.js +0 -202
- package/dist/testHelpers.js.map +0 -1
- package/dist/types.d.ts +0 -35
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
// Mock all external modules before imports
|
|
2
|
-
vi.mock('@base-org/account', () => ({
|
|
3
|
-
createBaseAccountSDK: vi.fn(() => ({
|
|
4
|
-
getProvider: vi.fn(() => ({
|
|
5
|
-
request: vi.fn()
|
|
6
|
-
}))
|
|
7
|
-
}))
|
|
8
|
-
}));
|
|
9
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
-
import { BaseAppAccount } from './baseAppAccount.js';
|
|
11
|
-
import { MainWalletPaymentMaker } from './mainWalletPaymentMaker.js';
|
|
12
|
-
import { MemoryStorage } from './storage.js';
|
|
13
|
-
import BigNumber from 'bignumber.js';
|
|
14
|
-
import { USDC_CONTRACT_ADDRESS_BASE } from '@atxp/client';
|
|
15
|
-
import { TEST_API_KEY, TEST_WALLET_ADDRESS, mockProvider, mockBaseAccountSDK, } from './testHelpers.js';
|
|
16
|
-
const { createBaseAccountSDK } = await import('@base-org/account');
|
|
17
|
-
describe('BaseAppAccount - Main Wallet Mode', () => {
|
|
18
|
-
let storage;
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
vi.clearAllMocks();
|
|
21
|
-
storage = new MemoryStorage();
|
|
22
|
-
});
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
vi.restoreAllMocks();
|
|
25
|
-
});
|
|
26
|
-
describe('initialize with useEphemeralWallet=false', () => {
|
|
27
|
-
it('should initialize without creating ephemeral wallet', async () => {
|
|
28
|
-
const provider = mockProvider();
|
|
29
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
30
|
-
// @ts-expect-error - mocked function
|
|
31
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
32
|
-
const account = await BaseAppAccount.initialize({
|
|
33
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
34
|
-
apiKey: TEST_API_KEY,
|
|
35
|
-
appName: 'test-app',
|
|
36
|
-
useEphemeralWallet: false,
|
|
37
|
-
storage,
|
|
38
|
-
});
|
|
39
|
-
// Should have main wallet address as account ID
|
|
40
|
-
expect(account.accountId).toBe(TEST_WALLET_ADDRESS);
|
|
41
|
-
// Should have main wallet payment maker
|
|
42
|
-
expect(account.paymentMakers['base']).toBeInstanceOf(MainWalletPaymentMaker);
|
|
43
|
-
// Should still connect wallet
|
|
44
|
-
expect(provider.request).toHaveBeenCalledWith({ method: 'wallet_connect' });
|
|
45
|
-
// Should NOT create ephemeral wallet or request spend permission
|
|
46
|
-
expect(createBaseAccountSDK).toHaveBeenCalledTimes(1);
|
|
47
|
-
// Storage should remain empty (no ephemeral wallet data saved)
|
|
48
|
-
const storageKey = `atxp-base-permission-${TEST_WALLET_ADDRESS}`;
|
|
49
|
-
expect(storage.get(storageKey)).toBeNull();
|
|
50
|
-
});
|
|
51
|
-
it('should make correct blockchain calls in main wallet mode', async () => {
|
|
52
|
-
const provider = mockProvider();
|
|
53
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
54
|
-
// @ts-expect-error - mocked function
|
|
55
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
56
|
-
await BaseAppAccount.initialize({
|
|
57
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
58
|
-
apiKey: TEST_API_KEY,
|
|
59
|
-
appName: 'test-app',
|
|
60
|
-
useEphemeralWallet: false,
|
|
61
|
-
storage,
|
|
62
|
-
});
|
|
63
|
-
// Verify SDK initialization
|
|
64
|
-
expect(createBaseAccountSDK).toHaveBeenCalledWith({
|
|
65
|
-
appName: 'test-app',
|
|
66
|
-
appChainIds: [8453], // base.id
|
|
67
|
-
paymasterUrls: {
|
|
68
|
-
8453: 'https://api.developer.coinbase.com/rpc/v1/base/snPdXqIzOGhRkGNJvEHM5bl9Hm3yRO3m'
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
// Verify provider setup
|
|
72
|
-
expect(sdk.getProvider).toHaveBeenCalled();
|
|
73
|
-
// Verify wallet_connect attempt
|
|
74
|
-
expect(provider.request).toHaveBeenCalledWith({ method: 'wallet_connect' });
|
|
75
|
-
// Verify NO ephemeral wallet operations
|
|
76
|
-
expect(provider.request).toHaveBeenCalledTimes(1); // Only wallet_connect
|
|
77
|
-
});
|
|
78
|
-
it('should handle wallet_connect failure gracefully', async () => {
|
|
79
|
-
const provider = mockProvider();
|
|
80
|
-
provider.request.mockRejectedValueOnce(new Error('wallet_connect not supported'));
|
|
81
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
82
|
-
// @ts-expect-error - mocked function
|
|
83
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
84
|
-
const account = await BaseAppAccount.initialize({
|
|
85
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
86
|
-
apiKey: TEST_API_KEY,
|
|
87
|
-
appName: 'test-app',
|
|
88
|
-
useEphemeralWallet: false,
|
|
89
|
-
storage,
|
|
90
|
-
});
|
|
91
|
-
expect(account.accountId).toBe(TEST_WALLET_ADDRESS);
|
|
92
|
-
expect(account.paymentMakers['base']).toBeInstanceOf(MainWalletPaymentMaker);
|
|
93
|
-
});
|
|
94
|
-
it('should not require apiKey in main wallet mode', async () => {
|
|
95
|
-
const provider = mockProvider();
|
|
96
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
97
|
-
// @ts-expect-error - mocked function
|
|
98
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
99
|
-
// Should not throw without API key when useEphemeralWallet=false
|
|
100
|
-
const account = await BaseAppAccount.initialize({
|
|
101
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
102
|
-
apiKey: '', // Empty API key
|
|
103
|
-
appName: 'test-app',
|
|
104
|
-
useEphemeralWallet: false,
|
|
105
|
-
storage,
|
|
106
|
-
});
|
|
107
|
-
expect(account.accountId).toBe(TEST_WALLET_ADDRESS);
|
|
108
|
-
});
|
|
109
|
-
it('should pass the provider to MainWalletPaymentMaker', async () => {
|
|
110
|
-
const provider = mockProvider();
|
|
111
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
112
|
-
// @ts-expect-error - mocked function
|
|
113
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
114
|
-
const account = await BaseAppAccount.initialize({
|
|
115
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
116
|
-
apiKey: TEST_API_KEY,
|
|
117
|
-
appName: 'test-app',
|
|
118
|
-
useEphemeralWallet: false,
|
|
119
|
-
storage,
|
|
120
|
-
});
|
|
121
|
-
// Get the payment maker and verify it has the right properties
|
|
122
|
-
const paymentMaker = account.paymentMakers['base'];
|
|
123
|
-
expect(paymentMaker).toBeInstanceOf(MainWalletPaymentMaker);
|
|
124
|
-
// Test that the payment maker can use the provider
|
|
125
|
-
await paymentMaker.generateJWT({ paymentRequestId: 'test', codeChallenge: 'test' });
|
|
126
|
-
expect(provider.request).toHaveBeenCalledWith({
|
|
127
|
-
method: 'personal_sign',
|
|
128
|
-
params: expect.any(Array)
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
it('should not interact with storage in main wallet mode', async () => {
|
|
132
|
-
const provider = mockProvider();
|
|
133
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
134
|
-
// @ts-expect-error - mocked function
|
|
135
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
136
|
-
// Spy on storage methods
|
|
137
|
-
const getSpy = vi.spyOn(storage, 'get');
|
|
138
|
-
const setSpy = vi.spyOn(storage, 'set');
|
|
139
|
-
const deleteSpy = vi.spyOn(storage, 'delete');
|
|
140
|
-
await BaseAppAccount.initialize({
|
|
141
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
142
|
-
apiKey: TEST_API_KEY,
|
|
143
|
-
appName: 'test-app',
|
|
144
|
-
useEphemeralWallet: false,
|
|
145
|
-
storage,
|
|
146
|
-
});
|
|
147
|
-
// Storage should not be accessed in main wallet mode
|
|
148
|
-
expect(getSpy).not.toHaveBeenCalled();
|
|
149
|
-
expect(setSpy).not.toHaveBeenCalled();
|
|
150
|
-
expect(deleteSpy).not.toHaveBeenCalled();
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe('initialize with useEphemeralWallet not specified', () => {
|
|
154
|
-
it('should default to ephemeral wallet mode for backward compatibility', async () => {
|
|
155
|
-
const provider = mockProvider();
|
|
156
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
157
|
-
// @ts-expect-error - mocked function
|
|
158
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
159
|
-
// This should throw because apiKey is required for ephemeral wallet mode
|
|
160
|
-
await expect(BaseAppAccount.initialize({
|
|
161
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
162
|
-
apiKey: '', // Empty API key
|
|
163
|
-
appName: 'test-app',
|
|
164
|
-
storage,
|
|
165
|
-
// useEphemeralWallet not specified - should default to true
|
|
166
|
-
})).rejects.toThrow('Smart wallet API key is required for ephemeral wallet mode');
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe('clearAllStoredData in main wallet mode', () => {
|
|
170
|
-
it('should handle clearAllStoredData even though main wallet stores no data', () => {
|
|
171
|
-
const setSpy = vi.spyOn(storage, 'set');
|
|
172
|
-
const deleteSpy = vi.spyOn(storage, 'delete');
|
|
173
|
-
// Should not throw
|
|
174
|
-
BaseAppAccount.clearAllStoredData(TEST_WALLET_ADDRESS, storage);
|
|
175
|
-
// Should attempt to delete even if nothing was stored
|
|
176
|
-
expect(deleteSpy).toHaveBeenCalledWith(`atxp-base-permission-${TEST_WALLET_ADDRESS}`);
|
|
177
|
-
expect(setSpy).not.toHaveBeenCalled();
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
describe('payment functionality in main wallet mode', () => {
|
|
181
|
-
it('should make payment using the main wallet', async () => {
|
|
182
|
-
const provider = mockProvider();
|
|
183
|
-
provider.request.mockImplementation(async ({ method }) => {
|
|
184
|
-
if (method === 'wallet_connect')
|
|
185
|
-
return undefined;
|
|
186
|
-
if (method === 'personal_sign')
|
|
187
|
-
return '0xmocksignature';
|
|
188
|
-
if (method === 'eth_sendTransaction')
|
|
189
|
-
return '0xtxhash';
|
|
190
|
-
if (method === 'eth_getTransactionReceipt')
|
|
191
|
-
return { status: '0x1', blockNumber: '0x100' };
|
|
192
|
-
if (method === 'eth_blockNumber')
|
|
193
|
-
return '0x102';
|
|
194
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
195
|
-
});
|
|
196
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
197
|
-
// @ts-expect-error - mocked function
|
|
198
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
199
|
-
const account = await BaseAppAccount.initialize({
|
|
200
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
201
|
-
apiKey: TEST_API_KEY,
|
|
202
|
-
appName: 'test-app',
|
|
203
|
-
useEphemeralWallet: false,
|
|
204
|
-
storage,
|
|
205
|
-
});
|
|
206
|
-
const paymentMaker = account.paymentMakers['base'];
|
|
207
|
-
expect(paymentMaker).toBeDefined();
|
|
208
|
-
// Make a payment
|
|
209
|
-
const txHash = await paymentMaker.makePayment(new BigNumber(1.5), 'USDC', '0x1234567890123456789012345678901234567890', 'Test payment');
|
|
210
|
-
expect(txHash).toBe('0xtxhash');
|
|
211
|
-
// Verify eth_sendTransaction was called (it's the 2nd call after wallet_connect)
|
|
212
|
-
expect(provider.request).toHaveBeenCalledWith({
|
|
213
|
-
method: 'eth_sendTransaction',
|
|
214
|
-
params: [{
|
|
215
|
-
from: TEST_WALLET_ADDRESS,
|
|
216
|
-
to: USDC_CONTRACT_ADDRESS_BASE,
|
|
217
|
-
data: expect.any(String),
|
|
218
|
-
value: '0x0'
|
|
219
|
-
}]
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
it('should generate JWT for authentication', async () => {
|
|
223
|
-
const provider = mockProvider();
|
|
224
|
-
provider.request.mockImplementation(async ({ method }) => {
|
|
225
|
-
if (method === 'wallet_connect')
|
|
226
|
-
return undefined;
|
|
227
|
-
if (method === 'personal_sign')
|
|
228
|
-
return '0xmocksignature';
|
|
229
|
-
throw new Error(`Unexpected method: ${method}`);
|
|
230
|
-
});
|
|
231
|
-
const sdk = mockBaseAccountSDK({ provider });
|
|
232
|
-
// @ts-expect-error - mocked function
|
|
233
|
-
createBaseAccountSDK.mockReturnValue(sdk);
|
|
234
|
-
const account = await BaseAppAccount.initialize({
|
|
235
|
-
walletAddress: TEST_WALLET_ADDRESS,
|
|
236
|
-
apiKey: TEST_API_KEY,
|
|
237
|
-
appName: 'test-app',
|
|
238
|
-
useEphemeralWallet: false,
|
|
239
|
-
storage,
|
|
240
|
-
});
|
|
241
|
-
const paymentMaker = account.paymentMakers['base'];
|
|
242
|
-
const jwt = await paymentMaker.generateJWT({
|
|
243
|
-
paymentRequestId: 'test-payment-id',
|
|
244
|
-
codeChallenge: 'test-challenge'
|
|
245
|
-
});
|
|
246
|
-
// JWT should be base64url encoded
|
|
247
|
-
expect(jwt).toMatch(/^[A-Za-z0-9_-]+$/);
|
|
248
|
-
// Verify personal_sign was called
|
|
249
|
-
expect(provider.request).toHaveBeenCalledWith({
|
|
250
|
-
method: 'personal_sign',
|
|
251
|
-
params: [
|
|
252
|
-
expect.stringContaining('PayMCP Authorization Request'),
|
|
253
|
-
TEST_WALLET_ADDRESS
|
|
254
|
-
]
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
//# sourceMappingURL=baseAppAccount.mainWallet.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseAppAccount.mainWallet.test.js","sourceRoot":"","sources":["../src/baseAppAccount.mainWallet.test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IAClC,oBAAoB,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QACjC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;YACxB,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE;SACjB,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ,CAAC,CAAC,CAAC;AAEJ,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,E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CAAC;gBACzD,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,EAAE,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;YAEH,MAAM,GAAG,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;YAE7C,qCAAqC;YACrC,oBAAoB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAE1C,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC;gBAC9C,aAAa,EAAE,mBAAmB;gBAClC,MAAM,EAAE,YAAY;gBACpB,OAAO,EAAE,UAAU;gBACnB,kBAAkB,EAAE,KAAK;gBACzB,OAAO;aACR,CAAC,CAAC;YAEH,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACnD,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC;gBACzC,gBAAgB,EAAE,iBAAiB;gBACnC,aAAa,EAAE,gBAAgB;aAChC,CAAC,CAAC;YAEH,kCAAkC;YAClC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;YAExC,kCAAkC;YAClC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC;gBAC5C,MAAM,EAAE,eAAe;gBACvB,MAAM,EAAE;oBACN,MAAM,CAAC,gBAAgB,CAAC,8BAA8B,CAAC;oBACvD,mBAAmB;iBACpB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type PaymentMaker } from '@atxp/client';
|
|
2
|
-
import { Logger, Currency } from '@atxp/common';
|
|
3
|
-
import { SpendPermission } from './types.js';
|
|
4
|
-
import { type EphemeralSmartWallet } from './smartWalletHelpers.js';
|
|
5
|
-
export declare class BaseAppPaymentMaker implements PaymentMaker {
|
|
6
|
-
private logger;
|
|
7
|
-
private spendPermission;
|
|
8
|
-
private smartWallet;
|
|
9
|
-
constructor(spendPermission: SpendPermission, smartWallet: EphemeralSmartWallet, logger?: Logger);
|
|
10
|
-
generateJWT({ paymentRequestId, codeChallenge }: {
|
|
11
|
-
paymentRequestId: string;
|
|
12
|
-
codeChallenge: string;
|
|
13
|
-
}): Promise<string>;
|
|
14
|
-
makePayment(amount: BigNumber, currency: Currency, receiver: string, memo: string): Promise<string>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=baseAppPaymentMaker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseAppPaymentMaker.d.ts","sourceRoot":"","sources":["../src/baseAppPaymentMaker.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAiB,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAsDpE,qBAAa,mBAAoB,YAAW,YAAY;IACtD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,WAAW,CAAuB;gBAGxC,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,oBAAoB,EACjC,MAAM,CAAC,EAAE,MAAM;IAaX,WAAW,CAAC,EAAC,gBAAgB,EAAE,aAAa,EAAC,EAAE;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAqDlH,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiF1G"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseAppPaymentMaker.test.d.ts","sourceRoot":"","sources":["../src/baseAppPaymentMaker.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
// Mock window object to simulate browser environment for payment maker tests
|
|
3
|
-
Object.defineProperty(global, 'window', {
|
|
4
|
-
value: {},
|
|
5
|
-
writable: true,
|
|
6
|
-
configurable: true
|
|
7
|
-
});
|
|
8
|
-
// Mock all external modules before imports
|
|
9
|
-
vi.mock('@base-org/account/spend-permission/browser', () => ({
|
|
10
|
-
prepareSpendCallData: vi.fn()
|
|
11
|
-
}));
|
|
12
|
-
vi.mock('viem', async () => {
|
|
13
|
-
const actual = await vi.importActual('viem');
|
|
14
|
-
return {
|
|
15
|
-
...actual,
|
|
16
|
-
encodeFunctionData: vi.fn(() => '0xmockencodeddata')
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
import { BaseAppPaymentMaker } from './baseAppPaymentMaker.js';
|
|
20
|
-
import { USDC_CONTRACT_ADDRESS_BASE } from '@atxp/client';
|
|
21
|
-
import BigNumber from 'bignumber.js';
|
|
22
|
-
import { setupPaymentMocks, mockSpendPermission, mockEphemeralSmartWallet, mockBundlerClient, mockFailedBundlerClient, mockSpendCalls, TEST_RECEIVER_ADDRESS } from './testHelpers.js';
|
|
23
|
-
describe('basePaymentMaker.generateJWT', () => {
|
|
24
|
-
it('should generate EIP-1271 auth data with default payload', async () => {
|
|
25
|
-
const permission = mockSpendPermission();
|
|
26
|
-
const smartWallet = mockEphemeralSmartWallet();
|
|
27
|
-
const paymentMaker = new BaseAppPaymentMaker(permission, smartWallet);
|
|
28
|
-
const authData = await paymentMaker.generateJWT({ paymentRequestId: '', codeChallenge: 'testCodeChallenge' });
|
|
29
|
-
// Should return base64-encoded EIP-1271 auth data
|
|
30
|
-
expect(authData).toBeDefined();
|
|
31
|
-
expect(typeof authData).toBe('string');
|
|
32
|
-
// Decode and verify the auth data
|
|
33
|
-
const decoded = JSON.parse(Buffer.from(authData, 'base64').toString('utf-8'));
|
|
34
|
-
expect(decoded.type).toBe('EIP1271_AUTH');
|
|
35
|
-
expect(decoded.walletAddress).toBe(smartWallet.address);
|
|
36
|
-
expect(decoded.message).toContain('PayMCP Authorization Request');
|
|
37
|
-
expect(decoded.signature).toBeDefined();
|
|
38
|
-
expect(decoded.timestamp).toBeDefined();
|
|
39
|
-
expect(decoded.nonce).toBeDefined();
|
|
40
|
-
expect(decoded.code_challenge).toBe('testCodeChallenge');
|
|
41
|
-
});
|
|
42
|
-
it('should include payment request id if provided', async () => {
|
|
43
|
-
const permission = mockSpendPermission();
|
|
44
|
-
const smartWallet = mockEphemeralSmartWallet();
|
|
45
|
-
const paymentMaker = new BaseAppPaymentMaker(permission, smartWallet);
|
|
46
|
-
const paymentRequestId = 'id1';
|
|
47
|
-
const authData = await paymentMaker.generateJWT({ paymentRequestId, codeChallenge: '' });
|
|
48
|
-
// Decode and verify the auth data includes payment request ID
|
|
49
|
-
const decoded = JSON.parse(Buffer.from(authData, 'base64').toString('utf-8'));
|
|
50
|
-
expect(decoded.payment_request_id).toEqual(paymentRequestId);
|
|
51
|
-
expect(decoded.message).toContain(`Payment Request ID: ${paymentRequestId}`);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('baseAppPaymentMaker.makePayment', () => {
|
|
55
|
-
it('should successfully make a USDC payment', async () => {
|
|
56
|
-
const permission = mockSpendPermission();
|
|
57
|
-
const bundlerClient = mockBundlerClient();
|
|
58
|
-
const smartWallet = mockEphemeralSmartWallet({ client: bundlerClient });
|
|
59
|
-
const spendCalls = mockSpendCalls();
|
|
60
|
-
const { prepareSpendCallData } = await setupPaymentMocks({ spendCalls });
|
|
61
|
-
const paymentMaker = new BaseAppPaymentMaker(permission, smartWallet);
|
|
62
|
-
const amount = new BigNumber(1.5); // 1.5 USDC
|
|
63
|
-
const txHash = await paymentMaker.makePayment(amount, 'USDC', TEST_RECEIVER_ADDRESS, 'test payment');
|
|
64
|
-
// Verify the transaction hash
|
|
65
|
-
expect(txHash).toBe('0xtxhash');
|
|
66
|
-
// Verify prepareSpendCallData was called with correct amount
|
|
67
|
-
expect(prepareSpendCallData).toHaveBeenCalledWith(permission, 1500000n); // 1.5 USDC = 1,500,000 in smallest units
|
|
68
|
-
// Verify sendUserOperation was called with correct parameters
|
|
69
|
-
expect(bundlerClient.sendUserOperation).toHaveBeenCalledWith({
|
|
70
|
-
account: smartWallet.account,
|
|
71
|
-
calls: [
|
|
72
|
-
// Spend permission calls
|
|
73
|
-
{ to: '0xcontract1', data: '0xdata1', value: 0n },
|
|
74
|
-
{ to: '0xcontract2', data: '0xdata2', value: 0n },
|
|
75
|
-
// Transfer call
|
|
76
|
-
{
|
|
77
|
-
to: USDC_CONTRACT_ADDRESS_BASE,
|
|
78
|
-
data: expect.any(String), // Encoded transfer function
|
|
79
|
-
value: 0n
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
maxPriorityFeePerGas: expect.any(BigInt)
|
|
83
|
-
});
|
|
84
|
-
// Verify waitForUserOperationReceipt was called
|
|
85
|
-
expect(bundlerClient.waitForUserOperationReceipt).toHaveBeenCalledWith({ hash: '0xoperationhash' });
|
|
86
|
-
});
|
|
87
|
-
it('should throw error for non-USDC currency', async () => {
|
|
88
|
-
const permission = mockSpendPermission();
|
|
89
|
-
const smartWallet = mockEphemeralSmartWallet();
|
|
90
|
-
const paymentMaker = new BaseAppPaymentMaker(permission, smartWallet);
|
|
91
|
-
const amount = new BigNumber(1.5);
|
|
92
|
-
await expect(paymentMaker.makePayment(amount, 'ETH', TEST_RECEIVER_ADDRESS, 'test payment')).rejects.toThrow('Only usdc currency is supported');
|
|
93
|
-
});
|
|
94
|
-
it('should throw error if user operation fails', async () => {
|
|
95
|
-
const permission = mockSpendPermission();
|
|
96
|
-
const bundlerClient = mockFailedBundlerClient({ failureType: 'receipt' });
|
|
97
|
-
const smartWallet = mockEphemeralSmartWallet({ client: bundlerClient });
|
|
98
|
-
await setupPaymentMocks({ spendCalls: [] });
|
|
99
|
-
const paymentMaker = new BaseAppPaymentMaker(permission, smartWallet);
|
|
100
|
-
const amount = new BigNumber(1.5);
|
|
101
|
-
await expect(paymentMaker.makePayment(amount, 'USDC', TEST_RECEIVER_ADDRESS, 'test payment')).rejects.toThrow('User operation failed');
|
|
102
|
-
});
|
|
103
|
-
it('should throw error if transaction hash is not returned', async () => {
|
|
104
|
-
const permission = mockSpendPermission();
|
|
105
|
-
const bundlerClient = mockFailedBundlerClient({ failureType: 'noTxHash' });
|
|
106
|
-
const smartWallet = mockEphemeralSmartWallet({ client: bundlerClient });
|
|
107
|
-
await setupPaymentMocks({ spendCalls: [] });
|
|
108
|
-
const paymentMaker = new BaseAppPaymentMaker(permission, smartWallet);
|
|
109
|
-
const amount = new BigNumber(1.5);
|
|
110
|
-
await expect(paymentMaker.makePayment(amount, 'USDC', TEST_RECEIVER_ADDRESS, 'test payment')).rejects.toThrow('User operation was executed but no transaction hash was returned');
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
//# sourceMappingURL=baseAppPaymentMaker.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseAppPaymentMaker.test.js","sourceRoot":"","sources":["../src/baseAppPaymentMaker.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAElD,6EAA6E;AAC7E,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;IACtC,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,2CAA2C;AAC3C,EAAE,CAAC,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3D,oBAAoB,EAAE,EAAE,CAAC,EAAE,EAAE;CAC9B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,YAAY,GAAG,IAAI,mBAAmB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACtE,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;QAElC,MAAM,MAAM,CACV,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,cAAc,CAAC,CAChF,CAAC,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,KAAK,IAAI,EAAE;QACtE,MAAM,UAAU,GAAG,mBAAmB,EAAE,CAAC;QACzC,MAAM,aAAa,GAAG,uBAAuB,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;QAC3E,MAAM,WAAW,GAAG,wBAAwB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;QAExE,MAAM,iBAAiB,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QAE5C,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QACtE,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;QAElC,MAAM,MAAM,CACV,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,cAAc,CAAC,CAChF,CAAC,OAAO,CAAC,OAAO,CAAC,kEAAkE,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility.test.d.ts","sourceRoot":"","sources":["../src/compatibility.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { BaseAppAccount } from './baseAppAccount.js';
|
|
3
|
-
import { BaseAppPaymentMaker } from './baseAppPaymentMaker.js';
|
|
4
|
-
describe('API Compatibility', () => {
|
|
5
|
-
describe('BaseAppAccount', () => {
|
|
6
|
-
it('should export the expected static methods', () => {
|
|
7
|
-
expect(typeof BaseAppAccount.initialize).toBe('function');
|
|
8
|
-
expect(typeof BaseAppAccount.clearAllStoredData).toBe('function');
|
|
9
|
-
// toStorageKey is private, so we test it indirectly through clearAllStoredData
|
|
10
|
-
expect(typeof BaseAppAccount.clearAllStoredData).toBe('function');
|
|
11
|
-
});
|
|
12
|
-
it('should support both ephemeral and main wallet modes', () => {
|
|
13
|
-
// This verifies the API structure supports both modes
|
|
14
|
-
const ephemeralConfig = {
|
|
15
|
-
apiKey: 'test',
|
|
16
|
-
walletAddress: '0x123',
|
|
17
|
-
storage: {}
|
|
18
|
-
};
|
|
19
|
-
const mainWalletConfig = {
|
|
20
|
-
walletAddress: '0x123',
|
|
21
|
-
useEphemeralWallet: false,
|
|
22
|
-
provider: {},
|
|
23
|
-
storage: {}
|
|
24
|
-
};
|
|
25
|
-
// These should be valid configurations (we're just checking types/structure)
|
|
26
|
-
expect(ephemeralConfig.apiKey).toBeDefined();
|
|
27
|
-
expect(mainWalletConfig.useEphemeralWallet).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe('BaseAppPaymentMaker', () => {
|
|
31
|
-
it('should support the required payment interface', () => {
|
|
32
|
-
// Mock the minimum required objects
|
|
33
|
-
const mockSpendPermission = {
|
|
34
|
-
signature: '0xsignature',
|
|
35
|
-
permission: {
|
|
36
|
-
account: '0x456',
|
|
37
|
-
spender: '0x789',
|
|
38
|
-
token: '0xabc',
|
|
39
|
-
allowance: '100',
|
|
40
|
-
period: 3600,
|
|
41
|
-
start: 0,
|
|
42
|
-
end: 3600,
|
|
43
|
-
salt: '0',
|
|
44
|
-
extraData: '0x'
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const mockSmartWallet = {
|
|
48
|
-
address: '0xwallet',
|
|
49
|
-
client: { sendUserOperation: () => { } },
|
|
50
|
-
account: {}
|
|
51
|
-
};
|
|
52
|
-
const mockLogger = {
|
|
53
|
-
info: () => { },
|
|
54
|
-
warn: () => { },
|
|
55
|
-
error: () => { },
|
|
56
|
-
debug: () => { }
|
|
57
|
-
};
|
|
58
|
-
// Should be able to create instance
|
|
59
|
-
const paymentMaker = new BaseAppPaymentMaker(mockSpendPermission, mockSmartWallet, mockLogger);
|
|
60
|
-
expect(paymentMaker).toBeInstanceOf(BaseAppPaymentMaker);
|
|
61
|
-
expect(typeof paymentMaker.makePayment).toBe('function');
|
|
62
|
-
expect(typeof paymentMaker.generateJWT).toBe('function');
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe('Environment Safety', () => {
|
|
66
|
-
it('should have proper error handling for environment detection', () => {
|
|
67
|
-
// Check that our error message is comprehensive
|
|
68
|
-
const expectedErrorPattern = /requestSpendPermission requires browser environment.*client-side.*Next\.js/;
|
|
69
|
-
const testError = new Error('requestSpendPermission requires browser environment. BaseAppAccount.initialize() with ephemeral wallet should only be called client-side in Next.js apps.');
|
|
70
|
-
expect(testError.message).toMatch(expectedErrorPattern);
|
|
71
|
-
});
|
|
72
|
-
it('should provide clear guidance for different environments', () => {
|
|
73
|
-
const browserGuidance = 'Use BaseAppAccount.initialize() with ephemeral wallet in browser/client-side code';
|
|
74
|
-
const serverGuidance = 'Use BaseAppAccount.initialize() with useEphemeralWallet: false in server-side code';
|
|
75
|
-
expect(browserGuidance).toContain('client-side');
|
|
76
|
-
expect(serverGuidance).toContain('server-side');
|
|
77
|
-
expect(serverGuidance).toContain('useEphemeralWallet: false');
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('Import Path Compatibility', () => {
|
|
81
|
-
it('should handle @base-org/account version differences', () => {
|
|
82
|
-
// Test that we can handle both v2.0.2 and v2.1.0+ import structures
|
|
83
|
-
const v2_0_2_pattern = '@base-org/account/spend-permission';
|
|
84
|
-
const v2_1_0_browser_pattern = '@base-org/account/spend-permission/browser';
|
|
85
|
-
const v2_1_0_node_pattern = '@base-org/account/spend-permission/node';
|
|
86
|
-
// Our solution should handle the new patterns
|
|
87
|
-
expect(v2_1_0_browser_pattern).toContain('/browser');
|
|
88
|
-
expect(v2_1_0_node_pattern).toContain('/node');
|
|
89
|
-
expect(v2_0_2_pattern).not.toContain('/browser');
|
|
90
|
-
expect(v2_0_2_pattern).not.toContain('/node');
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
//# sourceMappingURL=compatibility.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility.test.js","sourceRoot":"","sources":["../src/compatibility.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;YACnD,MAAM,CAAC,OAAO,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC1D,MAAM,CAAC,OAAO,cAAc,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClE,+EAA+E;YAC/E,MAAM,CAAC,OAAO,cAAc,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;YAC7D,sDAAsD;YACtD,MAAM,eAAe,GAAG;gBACtB,MAAM,EAAE,MAAM;gBACd,aAAa,EAAE,OAAwB;gBACvC,OAAO,EAAE,EAAS;aACnB,CAAC;YAEF,MAAM,gBAAgB,G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,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YACrD,MAAM,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC/C,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YACjD,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environment.test.d.ts","sourceRoot":"","sources":["../src/environment.test.ts"],"names":[],"mappings":""}
|
package/dist/environment.test.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
describe('Environment Detection', () => {
|
|
3
|
-
let originalWindow;
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
// Store original window state
|
|
6
|
-
originalWindow = global.window;
|
|
7
|
-
});
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
// Restore original window state
|
|
10
|
-
if (originalWindow === undefined) {
|
|
11
|
-
delete global.window;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
global.window = originalWindow;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
describe('Browser environment detection', () => {
|
|
18
|
-
it('should detect browser environment when window is defined', () => {
|
|
19
|
-
// Simulate browser environment
|
|
20
|
-
global.window = {};
|
|
21
|
-
expect(typeof window).not.toBe('undefined');
|
|
22
|
-
expect('window' in global).toBe(true);
|
|
23
|
-
});
|
|
24
|
-
it('should provide window object properties', () => {
|
|
25
|
-
global.window = {
|
|
26
|
-
location: { href: 'http://localhost' },
|
|
27
|
-
navigator: { userAgent: 'test' }
|
|
28
|
-
};
|
|
29
|
-
expect(window.location).toBeDefined();
|
|
30
|
-
expect(window.navigator).toBeDefined();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('Server environment detection', () => {
|
|
34
|
-
it('should detect server environment when window is undefined', () => {
|
|
35
|
-
// Simulate server environment
|
|
36
|
-
delete global.window;
|
|
37
|
-
expect(typeof global.window).toBe('undefined');
|
|
38
|
-
});
|
|
39
|
-
it('should handle environment checks gracefully', () => {
|
|
40
|
-
delete global.window;
|
|
41
|
-
// This is how our code checks for browser vs server
|
|
42
|
-
const isBrowser = typeof global.window !== 'undefined';
|
|
43
|
-
const isServer = typeof global.window === 'undefined';
|
|
44
|
-
expect(isBrowser).toBe(false);
|
|
45
|
-
expect(isServer).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe('Environment-specific error messages', () => {
|
|
49
|
-
it('should provide Next.js specific guidance', () => {
|
|
50
|
-
const errorMessage = 'requestSpendPermission requires browser environment. BaseAppAccount.initialize() with ephemeral wallet should only be called client-side in Next.js apps.';
|
|
51
|
-
expect(errorMessage).toContain('browser environment');
|
|
52
|
-
expect(errorMessage).toContain('client-side');
|
|
53
|
-
expect(errorMessage).toContain('Next.js apps');
|
|
54
|
-
});
|
|
55
|
-
it('should explain the limitation clearly', () => {
|
|
56
|
-
const errorMessage = 'requestSpendPermission requires browser environment. BaseAppAccount.initialize() with ephemeral wallet should only be called client-side in Next.js apps.';
|
|
57
|
-
// The error should be descriptive enough for developers to understand
|
|
58
|
-
expect(errorMessage.length).toBeGreaterThan(50);
|
|
59
|
-
expect(errorMessage).toContain('requestSpendPermission');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('Dynamic import path selection', () => {
|
|
63
|
-
it('should select browser path when window exists', () => {
|
|
64
|
-
global.window = {};
|
|
65
|
-
const isBrowser = typeof global.window !== 'undefined';
|
|
66
|
-
const selectedPath = isBrowser ? 'browser' : 'node';
|
|
67
|
-
expect(selectedPath).toBe('browser');
|
|
68
|
-
});
|
|
69
|
-
it('should select node path when window does not exist', () => {
|
|
70
|
-
delete global.window;
|
|
71
|
-
const isBrowser = typeof global.window !== 'undefined';
|
|
72
|
-
const selectedPath = isBrowser ? 'browser' : 'node';
|
|
73
|
-
expect(selectedPath).toBe('node');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
//# sourceMappingURL=environment.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environment.test.js","sourceRoot":"","sources":["../src/environment.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAErE,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,cAAmB,CAAC;IAExB,UAAU,CAAC,GAAG,EAAE;QACd,8BAA8B;QAC9B,cAAc,GAAI,MAAc,CAAC,MAAM,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,gCAAgC;QAChC,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,OAAQ,MAAc,CAAC,MAAM,CAAC;QAChC,CAAC;aAAM,CAAC;YACL,MAAc,CAAC,MAAM,GAAG,cAAc,CAAC;QAC1C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;YAClE,+BAA+B;YAC9B,MAAc,CAAC,MAAM,GAAG,EAAE,CAAC;YAE5B,MAAM,CAAC,OAAO,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC5C,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YAChD,MAAc,CAAC,MAAM,GAAG;gBACvB,QAAQ,EAAE,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