@coinbase/agentkit 0.4.0 → 0.6.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/README.md +103 -7
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/erc20/constants.d.ts +2 -0
- package/dist/action-providers/erc20/constants.js +12 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +18 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +4 -0
- package/dist/action-providers/flaunch/constants.d.ts +1078 -0
- package/dist/action-providers/flaunch/constants.js +709 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +102 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.js +519 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.d.ts +1 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +307 -0
- package/dist/action-providers/flaunch/index.d.ts +7 -0
- package/dist/action-providers/flaunch/index.js +23 -0
- package/dist/action-providers/flaunch/schemas.d.ts +77 -0
- package/dist/action-providers/flaunch/schemas.js +71 -0
- package/dist/action-providers/flaunch/types.d.ts +64 -0
- package/dist/action-providers/flaunch/types.js +2 -0
- package/dist/action-providers/flaunch/utils.d.ts +60 -0
- package/dist/action-providers/flaunch/utils.js +507 -0
- package/dist/action-providers/index.d.ts +4 -0
- package/dist/action-providers/index.js +4 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- package/dist/action-providers/onramp/index.d.ts +7 -0
- package/dist/action-providers/onramp/index.js +23 -0
- package/dist/action-providers/onramp/onrampActionProvider.d.ts +56 -0
- package/dist/action-providers/onramp/onrampActionProvider.js +109 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.d.ts +1 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.js +97 -0
- package/dist/action-providers/onramp/schemas.d.ts +12 -0
- package/dist/action-providers/onramp/schemas.js +15 -0
- package/dist/action-providers/onramp/types.d.ts +107 -0
- package/dist/action-providers/onramp/types.js +2 -0
- package/dist/action-providers/onramp/utils.d.ts +16 -0
- package/dist/action-providers/onramp/utils.js +56 -0
- package/dist/action-providers/onramp/version.d.ts +2 -0
- package/dist/action-providers/onramp/version.js +5 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
- package/dist/wallet-providers/cdpWalletProvider.js +44 -10
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +735 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +1 -0
- package/dist/wallet-providers/index.js +1 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +167 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +438 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +280 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +9 -0
- package/dist/wallet-providers/privyShared.js +16 -5
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +21 -8
- package/dist/wallet-providers/privyWalletProvider.js +39 -7
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +210 -16
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +26 -21
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const privySvmWalletProvider_1 = require("./privySvmWalletProvider");
|
|
37
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
38
|
+
const solanaNetworks = __importStar(require("../network/svm"));
|
|
39
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
40
|
+
ok: true,
|
|
41
|
+
json: () => Promise.resolve({}),
|
|
42
|
+
}));
|
|
43
|
+
jest.mock("../analytics", () => ({
|
|
44
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
45
|
+
}));
|
|
46
|
+
jest.mock("@privy-io/server-auth", () => ({
|
|
47
|
+
PrivyClient: jest.fn().mockImplementation(() => ({
|
|
48
|
+
walletApi: {
|
|
49
|
+
getWallet: jest.fn().mockResolvedValue({
|
|
50
|
+
id: "test-wallet-id",
|
|
51
|
+
address: "AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM",
|
|
52
|
+
}),
|
|
53
|
+
create: jest.fn().mockResolvedValue({
|
|
54
|
+
id: "test-wallet-id",
|
|
55
|
+
address: "AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM",
|
|
56
|
+
}),
|
|
57
|
+
solana: {
|
|
58
|
+
signTransaction: jest.fn().mockResolvedValue({
|
|
59
|
+
signedTransaction: "mock-signed-transaction",
|
|
60
|
+
}),
|
|
61
|
+
signAndSendTransaction: jest.fn().mockResolvedValue({
|
|
62
|
+
hash: "mock-hash",
|
|
63
|
+
}),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
})),
|
|
67
|
+
}));
|
|
68
|
+
jest.mock("@solana/web3.js", () => {
|
|
69
|
+
const actual = jest.requireActual("@solana/web3.js");
|
|
70
|
+
return {
|
|
71
|
+
...actual,
|
|
72
|
+
Connection: jest.fn().mockImplementation(() => ({
|
|
73
|
+
getGenesisHash: jest.fn().mockResolvedValue(solanaNetworks.SOLANA_DEVNET_GENESIS_BLOCK_HASH),
|
|
74
|
+
getBalance: jest.fn().mockResolvedValue(1000000000),
|
|
75
|
+
getSignatureStatus: jest.fn().mockResolvedValue({
|
|
76
|
+
context: { slot: 123 },
|
|
77
|
+
value: { slot: 123, confirmations: 10, err: null },
|
|
78
|
+
}),
|
|
79
|
+
confirmTransaction: jest.fn().mockResolvedValue({
|
|
80
|
+
context: { slot: 123 },
|
|
81
|
+
value: { err: null },
|
|
82
|
+
}),
|
|
83
|
+
})),
|
|
84
|
+
PublicKey: jest.fn().mockImplementation(address => ({
|
|
85
|
+
toBase58: jest.fn().mockReturnValue(address),
|
|
86
|
+
})),
|
|
87
|
+
VersionedTransaction: jest.fn().mockImplementation(() => ({
|
|
88
|
+
signatures: [],
|
|
89
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
90
|
+
})),
|
|
91
|
+
clusterApiUrl: jest.fn().mockImplementation(network => `https://api.${network}.solana.com`),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
jest.mock("./privyShared", () => ({
|
|
95
|
+
createPrivyWallet: jest.fn().mockResolvedValue({
|
|
96
|
+
wallet: {
|
|
97
|
+
id: "test-wallet-id",
|
|
98
|
+
address: "AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM",
|
|
99
|
+
},
|
|
100
|
+
privy: {
|
|
101
|
+
walletApi: {
|
|
102
|
+
solana: {
|
|
103
|
+
signTransaction: jest.fn().mockResolvedValue({
|
|
104
|
+
signedTransaction: "mock-signed-transaction",
|
|
105
|
+
}),
|
|
106
|
+
signAndSendTransaction: jest.fn().mockResolvedValue({
|
|
107
|
+
hash: "mock-hash",
|
|
108
|
+
}),
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
}));
|
|
114
|
+
jest.mock("../network/svm", () => {
|
|
115
|
+
const SOLANA_DEVNET_GENESIS_BLOCK_HASH = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
116
|
+
const SOLANA_TESTNET_GENESIS_BLOCK_HASH = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
|
117
|
+
const SOLANA_MAINNET_GENESIS_BLOCK_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
118
|
+
return {
|
|
119
|
+
SOLANA_DEVNET_GENESIS_BLOCK_HASH,
|
|
120
|
+
SOLANA_TESTNET_GENESIS_BLOCK_HASH,
|
|
121
|
+
SOLANA_MAINNET_GENESIS_BLOCK_HASH,
|
|
122
|
+
SOLANA_CLUSTER_ID_BY_NETWORK_ID: {
|
|
123
|
+
devnet: "devnet",
|
|
124
|
+
testnet: "testnet",
|
|
125
|
+
"mainnet-beta": "mainnet-beta",
|
|
126
|
+
},
|
|
127
|
+
SOLANA_NETWORKS: {
|
|
128
|
+
[SOLANA_DEVNET_GENESIS_BLOCK_HASH]: {
|
|
129
|
+
protocolFamily: "solana",
|
|
130
|
+
chainId: "devnet",
|
|
131
|
+
networkId: "devnet",
|
|
132
|
+
},
|
|
133
|
+
[SOLANA_TESTNET_GENESIS_BLOCK_HASH]: {
|
|
134
|
+
protocolFamily: "solana",
|
|
135
|
+
chainId: "testnet",
|
|
136
|
+
networkId: "testnet",
|
|
137
|
+
},
|
|
138
|
+
[SOLANA_MAINNET_GENESIS_BLOCK_HASH]: {
|
|
139
|
+
protocolFamily: "solana",
|
|
140
|
+
chainId: "mainnet-beta",
|
|
141
|
+
networkId: "mainnet-beta",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
describe("PrivySvmWalletProvider", () => {
|
|
147
|
+
const MOCK_ADDRESS = "AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM";
|
|
148
|
+
const MOCK_CONFIG = {
|
|
149
|
+
appId: "test-app-id",
|
|
150
|
+
appSecret: "test-app-secret",
|
|
151
|
+
};
|
|
152
|
+
const MOCK_CONFIG_WITH_WALLET_ID = {
|
|
153
|
+
...MOCK_CONFIG,
|
|
154
|
+
walletId: "test-wallet-id",
|
|
155
|
+
};
|
|
156
|
+
const MOCK_CONFIG_WITH_NETWORK_ID = {
|
|
157
|
+
...MOCK_CONFIG,
|
|
158
|
+
networkId: "devnet",
|
|
159
|
+
};
|
|
160
|
+
const MOCK_CONFIG_WITH_AUTH_KEY = {
|
|
161
|
+
...MOCK_CONFIG,
|
|
162
|
+
authorizationPrivateKey: "test-auth-key",
|
|
163
|
+
authorizationKeyId: "test-auth-key-id",
|
|
164
|
+
};
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
jest.clearAllMocks();
|
|
167
|
+
});
|
|
168
|
+
describe("configureWithWallet", () => {
|
|
169
|
+
it("should configure with default settings", async () => {
|
|
170
|
+
const provider = await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet(MOCK_CONFIG);
|
|
171
|
+
expect(provider).toBeInstanceOf(privySvmWalletProvider_1.PrivySvmWalletProvider);
|
|
172
|
+
});
|
|
173
|
+
it("should configure with an existing wallet ID", async () => {
|
|
174
|
+
const provider = await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet(MOCK_CONFIG_WITH_WALLET_ID);
|
|
175
|
+
expect(provider).toBeInstanceOf(privySvmWalletProvider_1.PrivySvmWalletProvider);
|
|
176
|
+
});
|
|
177
|
+
it("should configure with a specified network ID", async () => {
|
|
178
|
+
const provider = await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet(MOCK_CONFIG_WITH_NETWORK_ID);
|
|
179
|
+
expect(provider).toBeInstanceOf(privySvmWalletProvider_1.PrivySvmWalletProvider);
|
|
180
|
+
});
|
|
181
|
+
it("should configure with authorization keys", async () => {
|
|
182
|
+
const provider = await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet(MOCK_CONFIG_WITH_AUTH_KEY);
|
|
183
|
+
expect(provider).toBeInstanceOf(privySvmWalletProvider_1.PrivySvmWalletProvider);
|
|
184
|
+
});
|
|
185
|
+
it("should configure with a custom connection", async () => {
|
|
186
|
+
const connection = new web3_js_1.Connection("https://custom-rpc.example.com");
|
|
187
|
+
const provider = await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet({
|
|
188
|
+
...MOCK_CONFIG,
|
|
189
|
+
connection,
|
|
190
|
+
});
|
|
191
|
+
expect(provider).toBeInstanceOf(privySvmWalletProvider_1.PrivySvmWalletProvider);
|
|
192
|
+
});
|
|
193
|
+
it("should handle configuration with invalid network", async () => {
|
|
194
|
+
const mockClusterApiUrl = jest.fn().mockImplementation(() => {
|
|
195
|
+
throw new Error("Invalid cluster");
|
|
196
|
+
});
|
|
197
|
+
const webThreeJs = jest.requireMock("@solana/web3.js");
|
|
198
|
+
const originalFn = webThreeJs.clusterApiUrl;
|
|
199
|
+
webThreeJs.clusterApiUrl = mockClusterApiUrl;
|
|
200
|
+
await expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet({
|
|
201
|
+
...MOCK_CONFIG,
|
|
202
|
+
networkId: "this-network-definitely-does-not-exist",
|
|
203
|
+
})).rejects.toThrow();
|
|
204
|
+
webThreeJs.clusterApiUrl = originalFn;
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe("wallet methods", () => {
|
|
208
|
+
let provider;
|
|
209
|
+
let mockTransaction;
|
|
210
|
+
beforeEach(async () => {
|
|
211
|
+
provider = await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet(MOCK_CONFIG);
|
|
212
|
+
mockTransaction = {
|
|
213
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
214
|
+
signatures: [],
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
it("should get the wallet address", () => {
|
|
218
|
+
expect(provider.getAddress()).toBe(MOCK_ADDRESS);
|
|
219
|
+
});
|
|
220
|
+
it("should get the network information", () => {
|
|
221
|
+
expect(provider.getNetwork()).toEqual({
|
|
222
|
+
protocolFamily: "solana",
|
|
223
|
+
chainId: "devnet",
|
|
224
|
+
networkId: "devnet",
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
it("should get the provider name", () => {
|
|
228
|
+
expect(provider.getName()).toBe("privy_svm_wallet_provider");
|
|
229
|
+
});
|
|
230
|
+
it("should get the wallet balance", async () => {
|
|
231
|
+
const balance = await provider.getBalance();
|
|
232
|
+
expect(balance).toBe(BigInt(1000000000));
|
|
233
|
+
});
|
|
234
|
+
it("should sign a transaction", async () => {
|
|
235
|
+
const signedTx = await provider.signTransaction(mockTransaction);
|
|
236
|
+
expect(signedTx).toBe("mock-signed-transaction");
|
|
237
|
+
});
|
|
238
|
+
it("should sign and send a transaction", async () => {
|
|
239
|
+
const hash = await provider.signAndSendTransaction(mockTransaction);
|
|
240
|
+
expect(hash).toBe("mock-hash");
|
|
241
|
+
});
|
|
242
|
+
it("should throw an error when sending a transaction directly", async () => {
|
|
243
|
+
await expect(provider.sendTransaction(mockTransaction)).rejects.toThrow("Method not implemented");
|
|
244
|
+
});
|
|
245
|
+
it("should throw an error when transferring native tokens", async () => {
|
|
246
|
+
await expect(provider.nativeTransfer("destination-address", "1.0")).rejects.toThrow("Method not implemented");
|
|
247
|
+
});
|
|
248
|
+
it("should get the signature status", async () => {
|
|
249
|
+
const status = await provider.getSignatureStatus("mock-signature");
|
|
250
|
+
expect(status).toEqual({
|
|
251
|
+
context: { slot: 123 },
|
|
252
|
+
value: { slot: 123, confirmations: 10, err: null },
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
it("should wait for signature result", async () => {
|
|
256
|
+
const result = await provider.waitForSignatureResult("mock-signature");
|
|
257
|
+
expect(result).toEqual({
|
|
258
|
+
context: { slot: 123 },
|
|
259
|
+
value: { err: null },
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
it("should get the connection", () => {
|
|
263
|
+
const connection = provider.getConnection();
|
|
264
|
+
expect(connection).toBeDefined();
|
|
265
|
+
});
|
|
266
|
+
it("should get the public key", () => {
|
|
267
|
+
const publicKey = provider.getPublicKey();
|
|
268
|
+
expect(publicKey.toBase58()).toBe(MOCK_ADDRESS);
|
|
269
|
+
});
|
|
270
|
+
it("should export wallet data", () => {
|
|
271
|
+
const walletData = provider.exportWallet();
|
|
272
|
+
expect(walletData).toEqual({
|
|
273
|
+
walletId: "test-wallet-id",
|
|
274
|
+
authorizationPrivateKey: undefined,
|
|
275
|
+
chainId: "devnet",
|
|
276
|
+
networkId: "devnet",
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
it("should handle errors when signing transaction", async () => {
|
|
280
|
+
jest.spyOn(provider, "signTransaction").mockRejectedValueOnce(new Error("Signing failed"));
|
|
281
|
+
const mockTransaction = {
|
|
282
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
283
|
+
signatures: [],
|
|
284
|
+
};
|
|
285
|
+
await expect(provider.signTransaction(mockTransaction)).rejects.toThrow("Signing failed");
|
|
286
|
+
});
|
|
287
|
+
it("should handle errors when signing and sending transaction", async () => {
|
|
288
|
+
jest
|
|
289
|
+
.spyOn(provider, "signAndSendTransaction")
|
|
290
|
+
.mockRejectedValueOnce(new Error("Failed to send transaction"));
|
|
291
|
+
const mockTransaction = {
|
|
292
|
+
message: { compiledMessage: Buffer.from([]) },
|
|
293
|
+
signatures: [],
|
|
294
|
+
};
|
|
295
|
+
await expect(provider.signAndSendTransaction(mockTransaction)).rejects.toThrow("Failed to send transaction");
|
|
296
|
+
});
|
|
297
|
+
it("should handle timeout during transaction signature status check", async () => {
|
|
298
|
+
const mockMethod = jest.fn().mockRejectedValueOnce(new Error("Request timed out"));
|
|
299
|
+
const connection = provider.getConnection();
|
|
300
|
+
connection.getSignatureStatus = mockMethod;
|
|
301
|
+
await expect(provider.getSignatureStatus("mock-signature")).rejects.toThrow("Request timed out");
|
|
302
|
+
});
|
|
303
|
+
it("should handle network errors during balance check", async () => {
|
|
304
|
+
const mockMethod = jest.fn().mockRejectedValueOnce(new Error("RPC endpoint error"));
|
|
305
|
+
const connection = provider.getConnection();
|
|
306
|
+
connection.getBalance = mockMethod;
|
|
307
|
+
await expect(provider.getBalance()).rejects.toThrow("RPC endpoint error");
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
});
|
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
import { PrivyEvmWalletProvider, PrivyEvmWalletConfig } from "./privyEvmWalletProvider";
|
|
2
2
|
import { PrivySvmWalletProvider, PrivySvmWalletConfig } from "./privySvmWalletProvider";
|
|
3
|
-
|
|
3
|
+
import { PrivyEvmDelegatedEmbeddedWalletProvider, PrivyEvmDelegatedEmbeddedWalletConfig } from "./privyEvmDelegatedEmbeddedWalletProvider";
|
|
4
|
+
export type PrivyWalletConfig = PrivyEvmWalletConfig | PrivySvmWalletConfig | PrivyEvmDelegatedEmbeddedWalletConfig;
|
|
5
|
+
export type PrivyWalletProviderVariant<T> = T extends {
|
|
6
|
+
walletType: "embedded";
|
|
7
|
+
} ? PrivyEvmDelegatedEmbeddedWalletProvider : T extends {
|
|
8
|
+
chainType: "solana";
|
|
9
|
+
} ? PrivySvmWalletProvider : PrivyEvmWalletProvider;
|
|
4
10
|
/**
|
|
5
11
|
* Factory class for creating chain-specific Privy wallet providers
|
|
6
12
|
*/
|
|
7
13
|
export declare class PrivyWalletProvider {
|
|
8
14
|
/**
|
|
9
|
-
* Creates and configures a new wallet provider instance based on the chain type.
|
|
15
|
+
* Creates and configures a new wallet provider instance based on the chain type and wallet type.
|
|
10
16
|
*
|
|
11
17
|
* @param config - The configuration options for the Privy wallet
|
|
12
|
-
* @returns A configured WalletProvider instance for the specified chain
|
|
18
|
+
* @returns A configured WalletProvider instance for the specified chain and wallet type
|
|
13
19
|
*
|
|
14
20
|
* @example
|
|
15
21
|
* ```typescript
|
|
16
|
-
* // For EVM (default)
|
|
22
|
+
* // For EVM server wallets (default)
|
|
17
23
|
* const evmWallet = await PrivyWalletProvider.configureWithWallet({
|
|
18
24
|
* appId: "your-app-id",
|
|
19
25
|
* appSecret: "your-app-secret"
|
|
20
26
|
* });
|
|
21
27
|
*
|
|
22
|
-
* // For Solana
|
|
28
|
+
* // For Solana server wallets
|
|
23
29
|
* const solanaWallet = await PrivyWalletProvider.configureWithWallet({
|
|
24
30
|
* appId: "your-app-id",
|
|
25
31
|
* appSecret: "your-app-secret",
|
|
26
32
|
* chainType: "solana"
|
|
27
33
|
* });
|
|
34
|
+
*
|
|
35
|
+
* // For Ethereum embedded wallets
|
|
36
|
+
* const embeddedWallet = await PrivyWalletProvider.configureWithWallet({
|
|
37
|
+
* appId: "your-app-id",
|
|
38
|
+
* appSecret: "your-app-secret",
|
|
39
|
+
* walletId: "delegated-wallet-id",
|
|
40
|
+
* walletType: "embedded"
|
|
41
|
+
* });
|
|
28
42
|
* ```
|
|
29
43
|
*/
|
|
30
44
|
static configureWithWallet<T extends PrivyWalletConfig>(config: T & {
|
|
31
45
|
chainType?: "ethereum" | "solana";
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} ? PrivySvmWalletProvider : PrivyEvmWalletProvider>;
|
|
46
|
+
walletType?: "server" | "embedded";
|
|
47
|
+
}): Promise<PrivyWalletProviderVariant<T>>;
|
|
35
48
|
}
|
|
@@ -3,37 +3,69 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PrivyWalletProvider = void 0;
|
|
4
4
|
const privyEvmWalletProvider_1 = require("./privyEvmWalletProvider");
|
|
5
5
|
const privySvmWalletProvider_1 = require("./privySvmWalletProvider");
|
|
6
|
+
const privyEvmDelegatedEmbeddedWalletProvider_1 = require("./privyEvmDelegatedEmbeddedWalletProvider");
|
|
6
7
|
/**
|
|
7
8
|
* Factory class for creating chain-specific Privy wallet providers
|
|
8
9
|
*/
|
|
9
10
|
class PrivyWalletProvider {
|
|
10
11
|
/**
|
|
11
|
-
* Creates and configures a new wallet provider instance based on the chain type.
|
|
12
|
+
* Creates and configures a new wallet provider instance based on the chain type and wallet type.
|
|
12
13
|
*
|
|
13
14
|
* @param config - The configuration options for the Privy wallet
|
|
14
|
-
* @returns A configured WalletProvider instance for the specified chain
|
|
15
|
+
* @returns A configured WalletProvider instance for the specified chain and wallet type
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```typescript
|
|
18
|
-
* // For EVM (default)
|
|
19
|
+
* // For EVM server wallets (default)
|
|
19
20
|
* const evmWallet = await PrivyWalletProvider.configureWithWallet({
|
|
20
21
|
* appId: "your-app-id",
|
|
21
22
|
* appSecret: "your-app-secret"
|
|
22
23
|
* });
|
|
23
24
|
*
|
|
24
|
-
* // For Solana
|
|
25
|
+
* // For Solana server wallets
|
|
25
26
|
* const solanaWallet = await PrivyWalletProvider.configureWithWallet({
|
|
26
27
|
* appId: "your-app-id",
|
|
27
28
|
* appSecret: "your-app-secret",
|
|
28
29
|
* chainType: "solana"
|
|
29
30
|
* });
|
|
31
|
+
*
|
|
32
|
+
* // For Ethereum embedded wallets
|
|
33
|
+
* const embeddedWallet = await PrivyWalletProvider.configureWithWallet({
|
|
34
|
+
* appId: "your-app-id",
|
|
35
|
+
* appSecret: "your-app-secret",
|
|
36
|
+
* walletId: "delegated-wallet-id",
|
|
37
|
+
* walletType: "embedded"
|
|
38
|
+
* });
|
|
30
39
|
* ```
|
|
31
40
|
*/
|
|
32
41
|
static async configureWithWallet(config) {
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
const chainType = config.chainType || "ethereum";
|
|
43
|
+
const walletType = config.walletType || "server";
|
|
44
|
+
switch (chainType) {
|
|
45
|
+
case "ethereum": {
|
|
46
|
+
switch (walletType) {
|
|
47
|
+
case "server":
|
|
48
|
+
return (await privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet(config));
|
|
49
|
+
case "embedded":
|
|
50
|
+
return (await privyEvmDelegatedEmbeddedWalletProvider_1.PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet(config));
|
|
51
|
+
default:
|
|
52
|
+
throw new Error("Invalid wallet type");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
case "solana": {
|
|
56
|
+
switch (walletType) {
|
|
57
|
+
case "server":
|
|
58
|
+
return (await privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet(config));
|
|
59
|
+
case "embedded":
|
|
60
|
+
throw new Error("Embedded wallets are not supported for Solana");
|
|
61
|
+
default:
|
|
62
|
+
throw new Error("Invalid wallet type");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
default: {
|
|
66
|
+
throw new Error("Invalid chain type");
|
|
67
|
+
}
|
|
35
68
|
}
|
|
36
|
-
return (await privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet(config));
|
|
37
69
|
}
|
|
38
70
|
}
|
|
39
71
|
exports.PrivyWalletProvider = PrivyWalletProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const privyWalletProvider_1 = require("./privyWalletProvider");
|
|
4
|
+
const privyEvmWalletProvider_1 = require("./privyEvmWalletProvider");
|
|
5
|
+
const privySvmWalletProvider_1 = require("./privySvmWalletProvider");
|
|
6
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
7
|
+
ok: true,
|
|
8
|
+
json: () => Promise.resolve({}),
|
|
9
|
+
}));
|
|
10
|
+
jest.mock("../analytics", () => ({
|
|
11
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
12
|
+
}));
|
|
13
|
+
jest.mock("./privyEvmWalletProvider", () => ({
|
|
14
|
+
PrivyEvmWalletProvider: {
|
|
15
|
+
configureWithWallet: jest.fn().mockResolvedValue({
|
|
16
|
+
getAddress: jest.fn().mockReturnValue("0x742d35Cc6634C0532925a3b844Bc454e4438f44e"),
|
|
17
|
+
getNetwork: jest.fn().mockReturnValue({
|
|
18
|
+
protocolFamily: "evm",
|
|
19
|
+
chainId: "1",
|
|
20
|
+
networkId: "mainnet",
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
jest.mock("./privySvmWalletProvider", () => ({
|
|
26
|
+
PrivySvmWalletProvider: {
|
|
27
|
+
configureWithWallet: jest.fn().mockResolvedValue({
|
|
28
|
+
getAddress: jest.fn().mockReturnValue("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM"),
|
|
29
|
+
getNetwork: jest.fn().mockReturnValue({
|
|
30
|
+
protocolFamily: "solana",
|
|
31
|
+
chainId: "mainnet-beta",
|
|
32
|
+
networkId: "mainnet-beta",
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
describe("PrivyWalletProvider", () => {
|
|
38
|
+
const MOCK_EVM_CONFIG = {
|
|
39
|
+
appId: "test-app-id",
|
|
40
|
+
appSecret: "test-app-secret",
|
|
41
|
+
};
|
|
42
|
+
const MOCK_SVM_CONFIG = {
|
|
43
|
+
appId: "test-app-id",
|
|
44
|
+
appSecret: "test-app-secret",
|
|
45
|
+
chainType: "solana",
|
|
46
|
+
};
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
});
|
|
50
|
+
it("should create an EVM wallet provider by default", async () => {
|
|
51
|
+
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(MOCK_EVM_CONFIG);
|
|
52
|
+
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(MOCK_EVM_CONFIG);
|
|
53
|
+
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
54
|
+
expect(provider.getAddress()).toBe("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");
|
|
55
|
+
expect(provider.getNetwork().protocolFamily).toBe("evm");
|
|
56
|
+
});
|
|
57
|
+
it("should create an EVM wallet provider when explicitly requested", async () => {
|
|
58
|
+
const config = {
|
|
59
|
+
...MOCK_EVM_CONFIG,
|
|
60
|
+
chainType: "ethereum",
|
|
61
|
+
};
|
|
62
|
+
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(config);
|
|
63
|
+
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(config);
|
|
64
|
+
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
65
|
+
expect(provider.getAddress()).toBe("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");
|
|
66
|
+
expect(provider.getNetwork().protocolFamily).toBe("evm");
|
|
67
|
+
});
|
|
68
|
+
it("should create an SVM wallet provider when solana is specified", async () => {
|
|
69
|
+
const provider = await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(MOCK_SVM_CONFIG);
|
|
70
|
+
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(MOCK_SVM_CONFIG);
|
|
71
|
+
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
72
|
+
expect(provider.getAddress()).toBe("AQoKYV7tYpTrFZN6P5oUufbQKAUr9mNYGe1TTJC9wajM");
|
|
73
|
+
expect(provider.getNetwork().protocolFamily).toBe("solana");
|
|
74
|
+
});
|
|
75
|
+
it("should pass through all config properties", async () => {
|
|
76
|
+
const fullConfig = {
|
|
77
|
+
...MOCK_EVM_CONFIG,
|
|
78
|
+
walletId: "test-wallet-id",
|
|
79
|
+
authorizationPrivateKey: "test-auth-key",
|
|
80
|
+
authorizationKeyId: "test-auth-key-id",
|
|
81
|
+
chainId: "5",
|
|
82
|
+
};
|
|
83
|
+
await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(fullConfig);
|
|
84
|
+
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(fullConfig);
|
|
85
|
+
});
|
|
86
|
+
it("should handle initialization failures properly", async () => {
|
|
87
|
+
const mockEvmConfigureWithWallet = privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet;
|
|
88
|
+
const originalImplementation = mockEvmConfigureWithWallet.getMockImplementation();
|
|
89
|
+
mockEvmConfigureWithWallet.mockImplementation(() => {
|
|
90
|
+
throw new Error("API key not found");
|
|
91
|
+
});
|
|
92
|
+
await expect(privyWalletProvider_1.PrivyWalletProvider.configureWithWallet({
|
|
93
|
+
appId: "test-app-id",
|
|
94
|
+
appSecret: "test-app-secret",
|
|
95
|
+
})).rejects.toThrow("API key not found");
|
|
96
|
+
mockEvmConfigureWithWallet.mockImplementation(originalImplementation);
|
|
97
|
+
});
|
|
98
|
+
it("should validate config properly", async () => {
|
|
99
|
+
const mockEvmConfigureWithWallet = privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet;
|
|
100
|
+
const originalImplementation = mockEvmConfigureWithWallet.getMockImplementation();
|
|
101
|
+
mockEvmConfigureWithWallet.mockImplementation(config => {
|
|
102
|
+
if (config.appId === "test-app-id") {
|
|
103
|
+
throw new Error("Missing required appSecret");
|
|
104
|
+
}
|
|
105
|
+
return Promise.resolve({});
|
|
106
|
+
});
|
|
107
|
+
const testConfig = {
|
|
108
|
+
appId: "test-app-id",
|
|
109
|
+
appSecret: "test-app-secret",
|
|
110
|
+
};
|
|
111
|
+
await expect(privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(testConfig)).rejects.toThrow("Missing required appSecret");
|
|
112
|
+
mockEvmConfigureWithWallet.mockImplementation(originalImplementation);
|
|
113
|
+
});
|
|
114
|
+
it("should prefer chainType over extension-based inference", async () => {
|
|
115
|
+
const explicitConfig = {
|
|
116
|
+
...MOCK_EVM_CONFIG,
|
|
117
|
+
chainType: "ethereum",
|
|
118
|
+
extension: ".sol",
|
|
119
|
+
};
|
|
120
|
+
await privyWalletProvider_1.PrivyWalletProvider.configureWithWallet(explicitConfig);
|
|
121
|
+
expect(privyEvmWalletProvider_1.PrivyEvmWalletProvider.configureWithWallet).toHaveBeenCalledWith(explicitConfig);
|
|
122
|
+
expect(privySvmWalletProvider_1.PrivySvmWalletProvider.configureWithWallet).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|