@coinbase/agentkit 0.2.0 → 0.2.2-nightly.20250221.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -3
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +1 -1
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +9 -9
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +5 -3
- package/dist/action-providers/cdp/cdpApiActionProvider.js +15 -4
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +14 -2
- package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +2 -2
- package/dist/action-providers/cdp/cdpWalletActionProvider.js +6 -3
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +8 -0
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +2 -2
- package/dist/action-providers/erc20/erc20ActionProvider.js +2 -2
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +8 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +2 -2
- package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -2
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +8 -0
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/jupiter/index.d.ts +1 -0
- package/dist/action-providers/jupiter/index.js +17 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.d.ts +36 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +115 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +146 -0
- package/dist/action-providers/jupiter/schemas.d.ts +20 -0
- package/dist/action-providers/jupiter/schemas.js +20 -0
- package/dist/action-providers/spl/schemas.d.ts +13 -0
- package/dist/action-providers/spl/schemas.js +13 -1
- package/dist/action-providers/spl/splActionProvider.d.ts +9 -1
- package/dist/action-providers/spl/splActionProvider.js +62 -1
- package/dist/action-providers/spl/splActionProvider.test.js +101 -7
- package/dist/action-providers/wow/constants.js +1 -1
- package/dist/action-providers/wow/wowActionProvider.d.ts +4 -4
- package/dist/action-providers/wow/wowActionProvider.js +19 -19
- package/dist/action-providers/wow/wowActionProvider.test.js +14 -10
- package/dist/agentkit.js +8 -0
- package/dist/analytics/sendAnalyticsEvent.js +1 -0
- package/dist/network/svm.d.ts +1 -0
- package/dist/network/svm.js +6 -1
- package/dist/wallet-providers/cdpWalletProvider.js +1 -1
- package/dist/wallet-providers/index.d.ts +2 -0
- package/dist/wallet-providers/index.js +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
- package/dist/wallet-providers/privyShared.d.ts +40 -0
- package/dist/wallet-providers/privyShared.js +49 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +21 -56
- package/dist/wallet-providers/privyWalletProvider.js +18 -118
- package/package.json +2 -1
package/dist/agentkit.js
CHANGED
|
@@ -49,10 +49,18 @@ class AgentKit {
|
|
|
49
49
|
*/
|
|
50
50
|
getActions() {
|
|
51
51
|
const actions = [];
|
|
52
|
+
const unsupported = [];
|
|
52
53
|
for (const actionProvider of this.actionProviders) {
|
|
53
54
|
if (actionProvider.supportsNetwork(this.walletProvider.getNetwork())) {
|
|
54
55
|
actions.push(...actionProvider.getActions(this.walletProvider));
|
|
55
56
|
}
|
|
57
|
+
else {
|
|
58
|
+
unsupported.push(actionProvider.name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (unsupported.length > 0) {
|
|
62
|
+
console.log(`Warning: The following action providers are not supported on the current network and will be unavailable: ${unsupported.join(", ")}`);
|
|
63
|
+
console.log("Current network:", this.walletProvider.getNetwork());
|
|
56
64
|
}
|
|
57
65
|
return actions;
|
|
58
66
|
}
|
package/dist/network/svm.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export declare const SOLANA_MAINNET_NETWORK: Network;
|
|
|
12
12
|
export declare const SOLANA_TESTNET_NETWORK: Network;
|
|
13
13
|
export declare const SOLANA_DEVNET_NETWORK: Network;
|
|
14
14
|
export declare const SOLANA_NETWORKS: Record<SOLANA_CLUSTER, Network>;
|
|
15
|
+
export declare const SOLANA_CLUSTER_ID_BY_NETWORK_ID: Record<SOLANA_NETWORK_ID, string>;
|
package/dist/network/svm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SOLANA_NETWORKS = exports.SOLANA_DEVNET_NETWORK = exports.SOLANA_TESTNET_NETWORK = exports.SOLANA_MAINNET_NETWORK = exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = exports.SOLANA_PROTOCOL_FAMILY = exports.SOLANA_DEVNET_NETWORK_ID = exports.SOLANA_TESTNET_NETWORK_ID = exports.SOLANA_MAINNET_NETWORK_ID = void 0;
|
|
3
|
+
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = exports.SOLANA_NETWORKS = exports.SOLANA_DEVNET_NETWORK = exports.SOLANA_TESTNET_NETWORK = exports.SOLANA_MAINNET_NETWORK = exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = exports.SOLANA_PROTOCOL_FAMILY = exports.SOLANA_DEVNET_NETWORK_ID = exports.SOLANA_TESTNET_NETWORK_ID = exports.SOLANA_MAINNET_NETWORK_ID = void 0;
|
|
4
4
|
// CDP Network IDs
|
|
5
5
|
exports.SOLANA_MAINNET_NETWORK_ID = "solana-mainnet";
|
|
6
6
|
exports.SOLANA_TESTNET_NETWORK_ID = "solana-testnet";
|
|
@@ -31,3 +31,8 @@ exports.SOLANA_NETWORKS = {
|
|
|
31
31
|
[exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH]: exports.SOLANA_TESTNET_NETWORK,
|
|
32
32
|
[exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH]: exports.SOLANA_DEVNET_NETWORK,
|
|
33
33
|
};
|
|
34
|
+
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = {
|
|
35
|
+
[exports.SOLANA_MAINNET_NETWORK_ID]: "mainnet-beta",
|
|
36
|
+
[exports.SOLANA_TESTNET_NETWORK_ID]: "testnet",
|
|
37
|
+
[exports.SOLANA_DEVNET_NETWORK_ID]: "devnet",
|
|
38
|
+
};
|
|
@@ -58,7 +58,7 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
58
58
|
if (config.apiKeyName && config.apiKeyPrivateKey) {
|
|
59
59
|
coinbase_sdk_1.Coinbase.configure({
|
|
60
60
|
apiKeyName: config.apiKeyName,
|
|
61
|
-
privateKey: config.apiKeyPrivateKey,
|
|
61
|
+
privateKey: config.apiKeyPrivateKey?.replace(/\\n/g, "\n"),
|
|
62
62
|
source: "agentkit",
|
|
63
63
|
sourceVersion: package_json_1.version,
|
|
64
64
|
});
|
|
@@ -21,3 +21,5 @@ __exportStar(require("./cdpWalletProvider"), exports);
|
|
|
21
21
|
__exportStar(require("./svmWalletProvider"), exports);
|
|
22
22
|
__exportStar(require("./solanaKeypairWalletProvider"), exports);
|
|
23
23
|
__exportStar(require("./privyWalletProvider"), exports);
|
|
24
|
+
__exportStar(require("./privyEvmWalletProvider"), exports);
|
|
25
|
+
__exportStar(require("./privySvmWalletProvider"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ViemWalletProvider } from "./viemWalletProvider";
|
|
2
|
+
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Privy wallet provider.
|
|
5
|
+
*
|
|
6
|
+
* @interface
|
|
7
|
+
*/
|
|
8
|
+
export interface PrivyEvmWalletConfig extends PrivyWalletConfig {
|
|
9
|
+
/** Optional chain ID to connect to */
|
|
10
|
+
chainId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
14
|
+
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
15
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PrivyEvmWalletProvider extends ViemWalletProvider {
|
|
18
|
+
#private;
|
|
19
|
+
/**
|
|
20
|
+
* Private constructor to enforce use of factory method.
|
|
21
|
+
*
|
|
22
|
+
* @param walletClient - The Viem wallet client instance
|
|
23
|
+
* @param config - The configuration options for the Privy wallet
|
|
24
|
+
*/
|
|
25
|
+
private constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Creates and configures a new PrivyWalletProvider instance.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The configuration options for the Privy wallet
|
|
30
|
+
* @returns A configured PrivyWalletProvider instance
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const provider = await PrivyWalletProvider.configureWithWallet({
|
|
35
|
+
* appId: "your-app-id",
|
|
36
|
+
* appSecret: "your-app-secret",
|
|
37
|
+
* walletId: "wallet-id",
|
|
38
|
+
* chainId: "84532"
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static configureWithWallet(config: PrivyEvmWalletConfig): Promise<PrivyEvmWalletProvider>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the name of the wallet provider.
|
|
45
|
+
*
|
|
46
|
+
* @returns The string identifier for this wallet provider
|
|
47
|
+
*/
|
|
48
|
+
getName(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Exports the wallet data.
|
|
51
|
+
*
|
|
52
|
+
* @returns The wallet data
|
|
53
|
+
*/
|
|
54
|
+
exportWallet(): PrivyWalletExport;
|
|
55
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _PrivyEvmWalletProvider_walletId, _PrivyEvmWalletProvider_authorizationPrivateKey;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PrivyEvmWalletProvider = void 0;
|
|
16
|
+
const server_auth_1 = require("@privy-io/server-auth");
|
|
17
|
+
const viem_1 = require("@privy-io/server-auth/viem");
|
|
18
|
+
const viemWalletProvider_1 = require("./viemWalletProvider");
|
|
19
|
+
const viem_2 = require("viem");
|
|
20
|
+
const network_1 = require("../network/network");
|
|
21
|
+
/**
|
|
22
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
23
|
+
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
24
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
25
|
+
*/
|
|
26
|
+
class PrivyEvmWalletProvider extends viemWalletProvider_1.ViemWalletProvider {
|
|
27
|
+
/**
|
|
28
|
+
* Private constructor to enforce use of factory method.
|
|
29
|
+
*
|
|
30
|
+
* @param walletClient - The Viem wallet client instance
|
|
31
|
+
* @param config - The configuration options for the Privy wallet
|
|
32
|
+
*/
|
|
33
|
+
constructor(walletClient, config) {
|
|
34
|
+
super(walletClient);
|
|
35
|
+
_PrivyEvmWalletProvider_walletId.set(this, void 0);
|
|
36
|
+
_PrivyEvmWalletProvider_authorizationPrivateKey.set(this, void 0);
|
|
37
|
+
__classPrivateFieldSet(this, _PrivyEvmWalletProvider_walletId, config.walletId, "f"); // Now guaranteed to exist
|
|
38
|
+
__classPrivateFieldSet(this, _PrivyEvmWalletProvider_authorizationPrivateKey, config.authorizationPrivateKey, "f");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates and configures a new PrivyWalletProvider instance.
|
|
42
|
+
*
|
|
43
|
+
* @param config - The configuration options for the Privy wallet
|
|
44
|
+
* @returns A configured PrivyWalletProvider instance
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const provider = await PrivyWalletProvider.configureWithWallet({
|
|
49
|
+
* appId: "your-app-id",
|
|
50
|
+
* appSecret: "your-app-secret",
|
|
51
|
+
* walletId: "wallet-id",
|
|
52
|
+
* chainId: "84532"
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
static async configureWithWallet(config) {
|
|
57
|
+
const privy = new server_auth_1.PrivyClient(config.appId, config.appSecret, {
|
|
58
|
+
walletApi: config.authorizationPrivateKey
|
|
59
|
+
? {
|
|
60
|
+
authorizationPrivateKey: config.authorizationPrivateKey,
|
|
61
|
+
}
|
|
62
|
+
: undefined,
|
|
63
|
+
});
|
|
64
|
+
let walletId;
|
|
65
|
+
let address;
|
|
66
|
+
if (!config.walletId) {
|
|
67
|
+
if (config.authorizationPrivateKey && !config.authorizationKeyId) {
|
|
68
|
+
throw new Error("authorizationKeyId is required when creating a new wallet with an authorization key, this can be found in your Privy Dashboard");
|
|
69
|
+
}
|
|
70
|
+
if (config.authorizationKeyId && !config.authorizationPrivateKey) {
|
|
71
|
+
throw new Error("authorizationPrivateKey is required when creating a new wallet with an authorizationKeyId. " +
|
|
72
|
+
"If you don't have it, you can create a new one in your Privy Dashboard, or delete the authorization key.");
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const wallet = await privy.walletApi.create({
|
|
76
|
+
chainType: "ethereum",
|
|
77
|
+
authorizationKeyIds: config.authorizationKeyId ? [config.authorizationKeyId] : undefined,
|
|
78
|
+
});
|
|
79
|
+
walletId = wallet.id;
|
|
80
|
+
address = wallet.address;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(error);
|
|
84
|
+
if (error instanceof Error &&
|
|
85
|
+
error.message.includes("Missing `privy-authorization-signature` header")) {
|
|
86
|
+
// Providing a more informative error message, see context: https://github.com/coinbase/agentkit/pull/242#discussion_r1956428617
|
|
87
|
+
throw new Error("Privy error: you have an authorization key on your account which can create and modify wallets, please delete this key or pass it to the PrivyWalletProvider to create a new wallet");
|
|
88
|
+
}
|
|
89
|
+
throw new Error("Failed to create wallet");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
walletId = config.walletId;
|
|
94
|
+
const wallet = await privy.walletApi.getWallet({ id: walletId });
|
|
95
|
+
if (!wallet) {
|
|
96
|
+
throw new Error(`Wallet with ID ${walletId} not found`);
|
|
97
|
+
}
|
|
98
|
+
address = wallet.address;
|
|
99
|
+
}
|
|
100
|
+
const account = await (0, viem_1.createViemAccount)({
|
|
101
|
+
walletId,
|
|
102
|
+
address,
|
|
103
|
+
privy,
|
|
104
|
+
});
|
|
105
|
+
const chainId = config.chainId || "84532";
|
|
106
|
+
const chain = (0, network_1.getChain)(chainId);
|
|
107
|
+
if (!chain) {
|
|
108
|
+
throw new Error(`Chain with ID ${chainId} not found`);
|
|
109
|
+
}
|
|
110
|
+
const walletClient = (0, viem_2.createWalletClient)({
|
|
111
|
+
account,
|
|
112
|
+
chain,
|
|
113
|
+
transport: (0, viem_2.http)(),
|
|
114
|
+
});
|
|
115
|
+
return new PrivyEvmWalletProvider(walletClient, { ...config, walletId });
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the name of the wallet provider.
|
|
119
|
+
*
|
|
120
|
+
* @returns The string identifier for this wallet provider
|
|
121
|
+
*/
|
|
122
|
+
getName() {
|
|
123
|
+
return "privy_evm_wallet_provider";
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Exports the wallet data.
|
|
127
|
+
*
|
|
128
|
+
* @returns The wallet data
|
|
129
|
+
*/
|
|
130
|
+
exportWallet() {
|
|
131
|
+
return {
|
|
132
|
+
walletId: __classPrivateFieldGet(this, _PrivyEvmWalletProvider_walletId, "f"),
|
|
133
|
+
authorizationPrivateKey: __classPrivateFieldGet(this, _PrivyEvmWalletProvider_authorizationPrivateKey, "f"),
|
|
134
|
+
chainId: this.getNetwork().chainId,
|
|
135
|
+
networkId: this.getNetwork().networkId,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.PrivyEvmWalletProvider = PrivyEvmWalletProvider;
|
|
140
|
+
_PrivyEvmWalletProvider_walletId = new WeakMap(), _PrivyEvmWalletProvider_authorizationPrivateKey = new WeakMap();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PrivyClient, Wallet } from "@privy-io/server-auth";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for the Privy wallet provider.
|
|
4
|
+
*
|
|
5
|
+
* @interface
|
|
6
|
+
*/
|
|
7
|
+
export interface PrivyWalletConfig {
|
|
8
|
+
/** The Privy application ID */
|
|
9
|
+
appId: string;
|
|
10
|
+
/** The Privy application secret */
|
|
11
|
+
appSecret: string;
|
|
12
|
+
/** The ID of the wallet to use, if not provided a new wallet will be created */
|
|
13
|
+
walletId?: string;
|
|
14
|
+
/** Optional authorization key for the wallet API */
|
|
15
|
+
authorizationPrivateKey?: string;
|
|
16
|
+
/** Optional authorization key ID for creating new wallets */
|
|
17
|
+
authorizationKeyId?: string;
|
|
18
|
+
/** The chain type to create the wallet on */
|
|
19
|
+
chainType?: "ethereum" | "solana";
|
|
20
|
+
}
|
|
21
|
+
export type PrivyWalletExport = {
|
|
22
|
+
walletId: string;
|
|
23
|
+
authorizationPrivateKey: string | undefined;
|
|
24
|
+
chainId: string | undefined;
|
|
25
|
+
networkId: string | undefined;
|
|
26
|
+
};
|
|
27
|
+
type CreatePrivyWalletReturnType = {
|
|
28
|
+
wallet: Wallet & {
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
privy: PrivyClient;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Create a Privy wallet
|
|
35
|
+
*
|
|
36
|
+
* @param config - The configuration options for the Privy wallet
|
|
37
|
+
* @returns The created Privy wallet
|
|
38
|
+
*/
|
|
39
|
+
export declare function createPrivyWallet(config: PrivyWalletConfig): Promise<CreatePrivyWalletReturnType>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrivyWallet = createPrivyWallet;
|
|
4
|
+
const server_auth_1 = require("@privy-io/server-auth");
|
|
5
|
+
/**
|
|
6
|
+
* Create a Privy wallet
|
|
7
|
+
*
|
|
8
|
+
* @param config - The configuration options for the Privy wallet
|
|
9
|
+
* @returns The created Privy wallet
|
|
10
|
+
*/
|
|
11
|
+
async function createPrivyWallet(config) {
|
|
12
|
+
const privy = new server_auth_1.PrivyClient(config.appId, config.appSecret, {
|
|
13
|
+
walletApi: config.authorizationPrivateKey
|
|
14
|
+
? {
|
|
15
|
+
authorizationPrivateKey: config.authorizationPrivateKey,
|
|
16
|
+
}
|
|
17
|
+
: undefined,
|
|
18
|
+
});
|
|
19
|
+
if (config.walletId) {
|
|
20
|
+
const wallet = await privy.walletApi.getWallet({ id: config.walletId });
|
|
21
|
+
if (!wallet) {
|
|
22
|
+
throw new Error(`Wallet with ID ${config.walletId} not found`);
|
|
23
|
+
}
|
|
24
|
+
return { wallet, privy };
|
|
25
|
+
}
|
|
26
|
+
if (config.authorizationPrivateKey && !config.authorizationKeyId) {
|
|
27
|
+
throw new Error("authorizationKeyId is required when creating a new wallet with an authorization key, this can be found in your Privy Dashboard");
|
|
28
|
+
}
|
|
29
|
+
if (config.authorizationKeyId && !config.authorizationPrivateKey) {
|
|
30
|
+
throw new Error("authorizationPrivateKey is required when creating a new wallet with an authorizationKeyId. " +
|
|
31
|
+
"If you don't have it, you can create a new one in your Privy Dashboard, or delete the authorization key.");
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const wallet = await privy.walletApi.create({
|
|
35
|
+
chainType: config.chainType,
|
|
36
|
+
authorizationKeyIds: config.authorizationKeyId ? [config.authorizationKeyId] : undefined,
|
|
37
|
+
});
|
|
38
|
+
return { wallet, privy };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(error);
|
|
42
|
+
if (error instanceof Error &&
|
|
43
|
+
error.message.includes("Missing `privy-authorization-signature` header")) {
|
|
44
|
+
// Providing a more informative error message, see context: https://github.com/coinbase/agentkit/pull/242#discussion_r1956428617
|
|
45
|
+
throw new Error("Privy error: you have an authorization key on your account which can create and modify wallets, please delete this key or pass it to the PrivyWalletProvider to create a new wallet");
|
|
46
|
+
}
|
|
47
|
+
throw new Error("Failed to create wallet");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SvmWalletProvider } from "./svmWalletProvider";
|
|
2
|
+
import { RpcResponseAndContext, SignatureStatus, VersionedTransaction, Connection, PublicKey, SignatureResult } from "@solana/web3.js";
|
|
3
|
+
import { Network } from "../network/types";
|
|
4
|
+
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the Privy Svm wallet provider.
|
|
7
|
+
*/
|
|
8
|
+
export interface PrivySvmWalletConfig extends PrivyWalletConfig {
|
|
9
|
+
/** The network ID to use for the wallet */
|
|
10
|
+
networkId?: string;
|
|
11
|
+
/** The connection to use for the wallet */
|
|
12
|
+
connection?: Connection;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
16
|
+
* This provider extends the SvmWalletProvider to provide Privy-specific wallet functionality
|
|
17
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
18
|
+
*/
|
|
19
|
+
export declare class PrivySvmWalletProvider extends SvmWalletProvider {
|
|
20
|
+
#private;
|
|
21
|
+
/**
|
|
22
|
+
* Private constructor to enforce use of factory method.
|
|
23
|
+
*
|
|
24
|
+
* @param config - The configuration options for the Privy wallet
|
|
25
|
+
*/
|
|
26
|
+
private constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Creates and configures a new PrivySolanaWalletProvider instance.
|
|
29
|
+
*
|
|
30
|
+
* @param config - The configuration options for the Privy wallet
|
|
31
|
+
* @returns A configured PrivySolanaWalletProvider instance
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const provider = await PrivySolanaWalletProvider.configureWithWallet({
|
|
36
|
+
* appId: "your-app-id",
|
|
37
|
+
* appSecret: "your-app-secret",
|
|
38
|
+
* walletId: "wallet-id",
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static configureWithWallet<T extends PrivySvmWalletProvider>(config: PrivySvmWalletConfig): Promise<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Sign a transaction.
|
|
45
|
+
*
|
|
46
|
+
* @param transaction - The transaction to sign.
|
|
47
|
+
* @returns The signed transaction.
|
|
48
|
+
*/
|
|
49
|
+
signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
50
|
+
/**
|
|
51
|
+
* Sign and send a transaction.
|
|
52
|
+
*
|
|
53
|
+
* @param transaction - The transaction to send.
|
|
54
|
+
* @returns The transaction hash.
|
|
55
|
+
*/
|
|
56
|
+
signAndSendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Send a transaction.
|
|
59
|
+
*
|
|
60
|
+
* @param _ - The transaction to send.
|
|
61
|
+
* @returns The transaction hash.
|
|
62
|
+
*/
|
|
63
|
+
sendTransaction(_: VersionedTransaction): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Exports the wallet data.
|
|
66
|
+
*
|
|
67
|
+
* @returns The wallet data
|
|
68
|
+
*/
|
|
69
|
+
exportWallet(): PrivyWalletExport;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the name of the wallet provider.
|
|
72
|
+
*
|
|
73
|
+
* @returns The string identifier for this wallet provider
|
|
74
|
+
*/
|
|
75
|
+
getName(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Get the address of the wallet.
|
|
78
|
+
*
|
|
79
|
+
* @returns The address of the wallet.
|
|
80
|
+
*/
|
|
81
|
+
getAddress(): string;
|
|
82
|
+
/**
|
|
83
|
+
* Get the network of the wallet.
|
|
84
|
+
*
|
|
85
|
+
* @returns The network of the wallet.
|
|
86
|
+
*/
|
|
87
|
+
getNetwork(): Network;
|
|
88
|
+
/**
|
|
89
|
+
* Get the balance of the wallet.
|
|
90
|
+
*
|
|
91
|
+
* @returns The balance of the wallet.
|
|
92
|
+
*/
|
|
93
|
+
getBalance(): Promise<bigint>;
|
|
94
|
+
/**
|
|
95
|
+
* Transfer a native token.
|
|
96
|
+
*
|
|
97
|
+
* @param _ - The address to transfer the token to.
|
|
98
|
+
* @param arg2 - The value to transfer.
|
|
99
|
+
* @returns The transaction hash.
|
|
100
|
+
*/
|
|
101
|
+
nativeTransfer(_: string, arg2: string): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Get the status of a transaction.
|
|
104
|
+
*
|
|
105
|
+
* @param signature - The transaction signature.
|
|
106
|
+
* @returns The transaction status.
|
|
107
|
+
*/
|
|
108
|
+
getSignatureStatus(signature: string): Promise<RpcResponseAndContext<SignatureStatus | null>>;
|
|
109
|
+
/**
|
|
110
|
+
* Wait for a signature result.
|
|
111
|
+
*
|
|
112
|
+
* @param signature - The signature to wait for.
|
|
113
|
+
* @returns The signature result.
|
|
114
|
+
*/
|
|
115
|
+
waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
116
|
+
/**
|
|
117
|
+
* Get the connection.
|
|
118
|
+
*
|
|
119
|
+
* @returns The connection.
|
|
120
|
+
*/
|
|
121
|
+
getConnection(): Connection;
|
|
122
|
+
/**
|
|
123
|
+
* Get the public key.
|
|
124
|
+
*
|
|
125
|
+
* @returns The public key.
|
|
126
|
+
*/
|
|
127
|
+
getPublicKey(): PublicKey;
|
|
128
|
+
}
|