@coinbase/agentkit 0.2.0 → 0.2.2
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 +88 -2
- 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.js +4 -1
- 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/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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
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 _PrivySvmWalletProvider_walletId, _PrivySvmWalletProvider_address, _PrivySvmWalletProvider_authorizationPrivateKey, _PrivySvmWalletProvider_privyClient, _PrivySvmWalletProvider_connection, _PrivySvmWalletProvider_genesisHash;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PrivySvmWalletProvider = void 0;
|
|
16
|
+
const svmWalletProvider_1 = require("./svmWalletProvider");
|
|
17
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
+
const svm_1 = require("../network/svm");
|
|
19
|
+
const privyShared_1 = require("./privyShared");
|
|
20
|
+
/**
|
|
21
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
22
|
+
* This provider extends the SvmWalletProvider to provide Privy-specific wallet functionality
|
|
23
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
24
|
+
*/
|
|
25
|
+
class PrivySvmWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
|
|
26
|
+
/**
|
|
27
|
+
* Private constructor to enforce use of factory method.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The configuration options for the Privy wallet
|
|
30
|
+
*/
|
|
31
|
+
constructor(config) {
|
|
32
|
+
super();
|
|
33
|
+
_PrivySvmWalletProvider_walletId.set(this, void 0);
|
|
34
|
+
_PrivySvmWalletProvider_address.set(this, void 0);
|
|
35
|
+
_PrivySvmWalletProvider_authorizationPrivateKey.set(this, void 0);
|
|
36
|
+
_PrivySvmWalletProvider_privyClient.set(this, void 0);
|
|
37
|
+
_PrivySvmWalletProvider_connection.set(this, void 0);
|
|
38
|
+
_PrivySvmWalletProvider_genesisHash.set(this, void 0);
|
|
39
|
+
__classPrivateFieldSet(this, _PrivySvmWalletProvider_walletId, config.walletId, "f");
|
|
40
|
+
__classPrivateFieldSet(this, _PrivySvmWalletProvider_address, config.address, "f");
|
|
41
|
+
__classPrivateFieldSet(this, _PrivySvmWalletProvider_authorizationPrivateKey, config.authorizationPrivateKey, "f");
|
|
42
|
+
__classPrivateFieldSet(this, _PrivySvmWalletProvider_privyClient, config.privyClient, "f");
|
|
43
|
+
__classPrivateFieldSet(this, _PrivySvmWalletProvider_connection, config.connection, "f");
|
|
44
|
+
__classPrivateFieldSet(this, _PrivySvmWalletProvider_genesisHash, config.genesisHash, "f");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates and configures a new PrivySolanaWalletProvider instance.
|
|
48
|
+
*
|
|
49
|
+
* @param config - The configuration options for the Privy wallet
|
|
50
|
+
* @returns A configured PrivySolanaWalletProvider instance
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const provider = await PrivySolanaWalletProvider.configureWithWallet({
|
|
55
|
+
* appId: "your-app-id",
|
|
56
|
+
* appSecret: "your-app-secret",
|
|
57
|
+
* walletId: "wallet-id",
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static async configureWithWallet(config) {
|
|
62
|
+
const { wallet, privy } = await (0, privyShared_1.createPrivyWallet)(config);
|
|
63
|
+
const connection = config.connection ??
|
|
64
|
+
new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)(svm_1.SOLANA_CLUSTER_ID_BY_NETWORK_ID[config.networkId ?? ""]));
|
|
65
|
+
return new PrivySvmWalletProvider({
|
|
66
|
+
...config,
|
|
67
|
+
walletId: wallet.id,
|
|
68
|
+
address: wallet.address,
|
|
69
|
+
privyClient: privy,
|
|
70
|
+
connection,
|
|
71
|
+
genesisHash: await connection.getGenesisHash(),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sign a transaction.
|
|
76
|
+
*
|
|
77
|
+
* @param transaction - The transaction to sign.
|
|
78
|
+
* @returns The signed transaction.
|
|
79
|
+
*/
|
|
80
|
+
async signTransaction(transaction) {
|
|
81
|
+
const { signedTransaction } = await __classPrivateFieldGet(this, _PrivySvmWalletProvider_privyClient, "f").walletApi.solana.signTransaction({
|
|
82
|
+
walletId: __classPrivateFieldGet(this, _PrivySvmWalletProvider_walletId, "f"),
|
|
83
|
+
transaction,
|
|
84
|
+
});
|
|
85
|
+
return signedTransaction;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sign and send a transaction.
|
|
89
|
+
*
|
|
90
|
+
* @param transaction - The transaction to send.
|
|
91
|
+
* @returns The transaction hash.
|
|
92
|
+
*/
|
|
93
|
+
async signAndSendTransaction(transaction) {
|
|
94
|
+
try {
|
|
95
|
+
const { hash } = await __classPrivateFieldGet(this, _PrivySvmWalletProvider_privyClient, "f").walletApi.solana.signAndSendTransaction({
|
|
96
|
+
walletId: __classPrivateFieldGet(this, _PrivySvmWalletProvider_walletId, "f"),
|
|
97
|
+
caip2: `solana:${__classPrivateFieldGet(this, _PrivySvmWalletProvider_genesisHash, "f").substring(0, 32)}`,
|
|
98
|
+
transaction,
|
|
99
|
+
});
|
|
100
|
+
return hash;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error("Failed to send transaction", error);
|
|
104
|
+
throw new Error("Failed to send transaction");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Send a transaction.
|
|
109
|
+
*
|
|
110
|
+
* @param _ - The transaction to send.
|
|
111
|
+
* @returns The transaction hash.
|
|
112
|
+
*/
|
|
113
|
+
async sendTransaction(_) {
|
|
114
|
+
throw new Error("Method not implemented.");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Exports the wallet data.
|
|
118
|
+
*
|
|
119
|
+
* @returns The wallet data
|
|
120
|
+
*/
|
|
121
|
+
exportWallet() {
|
|
122
|
+
return {
|
|
123
|
+
walletId: __classPrivateFieldGet(this, _PrivySvmWalletProvider_walletId, "f"),
|
|
124
|
+
authorizationPrivateKey: __classPrivateFieldGet(this, _PrivySvmWalletProvider_authorizationPrivateKey, "f"),
|
|
125
|
+
chainId: this.getNetwork().chainId,
|
|
126
|
+
networkId: this.getNetwork().networkId,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets the name of the wallet provider.
|
|
131
|
+
*
|
|
132
|
+
* @returns The string identifier for this wallet provider
|
|
133
|
+
*/
|
|
134
|
+
getName() {
|
|
135
|
+
return "privy_svm_wallet_provider";
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get the address of the wallet.
|
|
139
|
+
*
|
|
140
|
+
* @returns The address of the wallet.
|
|
141
|
+
*/
|
|
142
|
+
getAddress() {
|
|
143
|
+
return __classPrivateFieldGet(this, _PrivySvmWalletProvider_address, "f");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the network of the wallet.
|
|
147
|
+
*
|
|
148
|
+
* @returns The network of the wallet.
|
|
149
|
+
*/
|
|
150
|
+
getNetwork() {
|
|
151
|
+
return svm_1.SOLANA_NETWORKS[__classPrivateFieldGet(this, _PrivySvmWalletProvider_genesisHash, "f")];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the balance of the wallet.
|
|
155
|
+
*
|
|
156
|
+
* @returns The balance of the wallet.
|
|
157
|
+
*/
|
|
158
|
+
async getBalance() {
|
|
159
|
+
const balance = await __classPrivateFieldGet(this, _PrivySvmWalletProvider_connection, "f").getBalance(new web3_js_1.PublicKey(__classPrivateFieldGet(this, _PrivySvmWalletProvider_address, "f")));
|
|
160
|
+
return BigInt(balance);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Transfer a native token.
|
|
164
|
+
*
|
|
165
|
+
* @param _ - The address to transfer the token to.
|
|
166
|
+
* @param arg2 - The value to transfer.
|
|
167
|
+
* @returns The transaction hash.
|
|
168
|
+
*/
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
170
|
+
async nativeTransfer(_, arg2) {
|
|
171
|
+
throw new Error("Method not implemented.");
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get the status of a transaction.
|
|
175
|
+
*
|
|
176
|
+
* @param signature - The transaction signature.
|
|
177
|
+
* @returns The transaction status.
|
|
178
|
+
*/
|
|
179
|
+
async getSignatureStatus(signature) {
|
|
180
|
+
return __classPrivateFieldGet(this, _PrivySvmWalletProvider_connection, "f").getSignatureStatus(signature);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Wait for a signature result.
|
|
184
|
+
*
|
|
185
|
+
* @param signature - The signature to wait for.
|
|
186
|
+
* @returns The signature result.
|
|
187
|
+
*/
|
|
188
|
+
waitForSignatureResult(signature) {
|
|
189
|
+
return __classPrivateFieldGet(this, _PrivySvmWalletProvider_connection, "f").confirmTransaction({
|
|
190
|
+
signature,
|
|
191
|
+
...svm_1.SOLANA_NETWORKS[__classPrivateFieldGet(this, _PrivySvmWalletProvider_genesisHash, "f")],
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the connection.
|
|
196
|
+
*
|
|
197
|
+
* @returns The connection.
|
|
198
|
+
*/
|
|
199
|
+
getConnection() {
|
|
200
|
+
return __classPrivateFieldGet(this, _PrivySvmWalletProvider_connection, "f");
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get the public key.
|
|
204
|
+
*
|
|
205
|
+
* @returns The public key.
|
|
206
|
+
*/
|
|
207
|
+
getPublicKey() {
|
|
208
|
+
return new web3_js_1.PublicKey(__classPrivateFieldGet(this, _PrivySvmWalletProvider_address, "f"));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.PrivySvmWalletProvider = PrivySvmWalletProvider;
|
|
212
|
+
_PrivySvmWalletProvider_walletId = new WeakMap(), _PrivySvmWalletProvider_address = new WeakMap(), _PrivySvmWalletProvider_authorizationPrivateKey = new WeakMap(), _PrivySvmWalletProvider_privyClient = new WeakMap(), _PrivySvmWalletProvider_connection = new WeakMap(), _PrivySvmWalletProvider_genesisHash = new WeakMap();
|
|
@@ -1,70 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrivyEvmWalletProvider, PrivyEvmWalletConfig } from "./privyEvmWalletProvider";
|
|
2
|
+
import { PrivySvmWalletProvider, PrivySvmWalletConfig } from "./privySvmWalletProvider";
|
|
3
|
+
export type PrivyWalletConfig = PrivyEvmWalletConfig | PrivySvmWalletConfig;
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @interface
|
|
5
|
+
* Factory class for creating chain-specific Privy wallet providers
|
|
6
6
|
*/
|
|
7
|
-
|
|
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 chain ID to connect to */
|
|
15
|
-
chainId?: string;
|
|
16
|
-
/** Optional authorization key for the wallet API */
|
|
17
|
-
authorizationPrivateKey?: string;
|
|
18
|
-
/** Optional authorization key ID for creating new wallets */
|
|
19
|
-
authorizationKeyId?: string;
|
|
20
|
-
}
|
|
21
|
-
type PrivyWalletExport = {
|
|
22
|
-
walletId: string;
|
|
23
|
-
authorizationPrivateKey: string | undefined;
|
|
24
|
-
chainId: string | undefined;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* A wallet provider that uses Privy's server wallet API.
|
|
28
|
-
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
29
|
-
* while maintaining compatibility with the base wallet provider interface.
|
|
30
|
-
*/
|
|
31
|
-
export declare class PrivyWalletProvider extends ViemWalletProvider {
|
|
32
|
-
#private;
|
|
33
|
-
/**
|
|
34
|
-
* Private constructor to enforce use of factory method.
|
|
35
|
-
*
|
|
36
|
-
* @param walletClient - The Viem wallet client instance
|
|
37
|
-
* @param config - The configuration options for the Privy wallet
|
|
38
|
-
*/
|
|
39
|
-
private constructor();
|
|
7
|
+
export declare class PrivyWalletProvider {
|
|
40
8
|
/**
|
|
41
|
-
* Creates and configures a new
|
|
9
|
+
* Creates and configures a new wallet provider instance based on the chain type.
|
|
42
10
|
*
|
|
43
11
|
* @param config - The configuration options for the Privy wallet
|
|
44
|
-
* @returns A configured
|
|
12
|
+
* @returns A configured WalletProvider instance for the specified chain
|
|
45
13
|
*
|
|
46
14
|
* @example
|
|
47
15
|
* ```typescript
|
|
48
|
-
*
|
|
16
|
+
* // For EVM (default)
|
|
17
|
+
* const evmWallet = await PrivyWalletProvider.configureWithWallet({
|
|
18
|
+
* appId: "your-app-id",
|
|
19
|
+
* appSecret: "your-app-secret"
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // For Solana
|
|
23
|
+
* const solanaWallet = await PrivyWalletProvider.configureWithWallet({
|
|
49
24
|
* appId: "your-app-id",
|
|
50
25
|
* appSecret: "your-app-secret",
|
|
51
|
-
*
|
|
52
|
-
* chainId: "84532"
|
|
26
|
+
* chainType: "solana"
|
|
53
27
|
* });
|
|
54
28
|
* ```
|
|
55
29
|
*/
|
|
56
|
-
static configureWithWallet(config:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
getName(): string;
|
|
63
|
-
/**
|
|
64
|
-
* Exports the wallet data.
|
|
65
|
-
*
|
|
66
|
-
* @returns The wallet data
|
|
67
|
-
*/
|
|
68
|
-
exportWallet(): PrivyWalletExport;
|
|
30
|
+
static configureWithWallet<T extends PrivyWalletConfig>(config: T & {
|
|
31
|
+
chainType?: "ethereum" | "solana";
|
|
32
|
+
}): Promise<T extends {
|
|
33
|
+
chainType: "solana";
|
|
34
|
+
} ? PrivySvmWalletProvider : PrivyEvmWalletProvider>;
|
|
69
35
|
}
|
|
70
|
-
export {};
|