@coinbase/agentkit 0.3.0 → 0.5.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 +90 -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/defillama/constants.d.ts +8 -0
- package/dist/action-providers/defillama/constants.js +11 -0
- package/dist/action-providers/defillama/defillamaActionProvider.d.ts +54 -0
- package/dist/action-providers/defillama/defillamaActionProvider.js +180 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.js +114 -0
- package/dist/action-providers/defillama/index.d.ts +1 -0
- package/dist/action-providers/defillama/index.js +17 -0
- package/dist/action-providers/defillama/schemas.d.ts +34 -0
- package/dist/action-providers/defillama/schemas.js +34 -0
- package/dist/action-providers/defillama/types.d.ts +73 -0
- package/dist/action-providers/defillama/types.js +2 -0
- package/dist/action-providers/defillama/utils.d.ts +10 -0
- package/dist/action-providers/defillama/utils.js +87 -0
- package/dist/action-providers/defillama/utils.test.d.ts +1 -0
- package/dist/action-providers/defillama/utils.test.js +124 -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/index.d.ts +3 -0
- package/dist/action-providers/index.js +3 -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/morpho/morphoActionProvider.js +11 -4
- package/dist/action-providers/morpho/morphoActionProvider.test.js +2 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
- package/dist/wallet-providers/cdpWalletProvider.js +24 -0
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +701 -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 +24 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
4
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
5
|
+
ok: true,
|
|
6
|
+
json: () => Promise.resolve({}),
|
|
7
|
+
}));
|
|
8
|
+
jest.mock("../analytics", () => ({
|
|
9
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
10
|
+
}));
|
|
11
|
+
const EXPECTED_EVM_METHODS = [
|
|
12
|
+
"signMessage",
|
|
13
|
+
"signTypedData",
|
|
14
|
+
"signTransaction",
|
|
15
|
+
"sendTransaction",
|
|
16
|
+
"waitForTransactionReceipt",
|
|
17
|
+
"readContract",
|
|
18
|
+
];
|
|
19
|
+
const EXPECTED_BASE_METHODS = [
|
|
20
|
+
"getAddress",
|
|
21
|
+
"getNetwork",
|
|
22
|
+
"getName",
|
|
23
|
+
"getBalance",
|
|
24
|
+
"nativeTransfer",
|
|
25
|
+
];
|
|
26
|
+
describe("EvmWalletProvider", () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
evmWalletProvider_1.EvmWalletProvider.prototype.signMessage = jest.fn();
|
|
30
|
+
evmWalletProvider_1.EvmWalletProvider.prototype.signTypedData = jest.fn();
|
|
31
|
+
evmWalletProvider_1.EvmWalletProvider.prototype.signTransaction = jest.fn();
|
|
32
|
+
evmWalletProvider_1.EvmWalletProvider.prototype.sendTransaction = jest.fn();
|
|
33
|
+
evmWalletProvider_1.EvmWalletProvider.prototype.waitForTransactionReceipt = jest.fn();
|
|
34
|
+
evmWalletProvider_1.EvmWalletProvider.prototype.readContract = jest.fn();
|
|
35
|
+
});
|
|
36
|
+
it("should define abstract methods (TypeScript only - not a runtime check)", () => {
|
|
37
|
+
const allExpectedMethods = [...EXPECTED_EVM_METHODS, ...EXPECTED_BASE_METHODS];
|
|
38
|
+
expect(Array.isArray(allExpectedMethods)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
it("should extend WalletProvider", () => {
|
|
41
|
+
const proto = Object.getPrototypeOf(evmWalletProvider_1.EvmWalletProvider);
|
|
42
|
+
const protoName = proto.name;
|
|
43
|
+
expect(protoName).toBe("WalletProvider");
|
|
44
|
+
});
|
|
45
|
+
it("should have consistent method signatures", () => {
|
|
46
|
+
const signMessageDescriptor = Object.getOwnPropertyDescriptor(evmWalletProvider_1.EvmWalletProvider.prototype, "signMessage");
|
|
47
|
+
expect(signMessageDescriptor).toBeDefined();
|
|
48
|
+
expect(typeof signMessageDescriptor.value).toBe("function");
|
|
49
|
+
const signTypedDataDescriptor = Object.getOwnPropertyDescriptor(evmWalletProvider_1.EvmWalletProvider.prototype, "signTypedData");
|
|
50
|
+
expect(signTypedDataDescriptor).toBeDefined();
|
|
51
|
+
expect(typeof signTypedDataDescriptor.value).toBe("function");
|
|
52
|
+
const readContractDescriptor = Object.getOwnPropertyDescriptor(evmWalletProvider_1.EvmWalletProvider.prototype, "readContract");
|
|
53
|
+
expect(readContractDescriptor).toBeDefined();
|
|
54
|
+
expect(typeof readContractDescriptor.value).toBe("function");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -24,3 +24,4 @@ __exportStar(require("./solanaKeypairWalletProvider"), exports);
|
|
|
24
24
|
__exportStar(require("./privyWalletProvider"), exports);
|
|
25
25
|
__exportStar(require("./privyEvmWalletProvider"), exports);
|
|
26
26
|
__exportStar(require("./privySvmWalletProvider"), exports);
|
|
27
|
+
__exportStar(require("./privyEvmDelegatedEmbeddedWalletProvider"), exports);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { Abi, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionReceipt, TransactionRequest } from "viem";
|
|
2
|
+
import { Network } from "../network";
|
|
3
|
+
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
4
|
+
import { WalletProvider } from "./walletProvider";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the Privy Embedded Wallet provider.
|
|
7
|
+
*/
|
|
8
|
+
export interface PrivyEvmDelegatedEmbeddedWalletConfig extends PrivyWalletConfig {
|
|
9
|
+
/** The ID of the delegated wallet */
|
|
10
|
+
walletId: string;
|
|
11
|
+
/** The network ID to connect to (e.g., "base-mainnet") */
|
|
12
|
+
networkId?: string;
|
|
13
|
+
/** The chain ID to connect to */
|
|
14
|
+
chainId?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A wallet provider that uses Privy's embedded wallets with delegation.
|
|
18
|
+
* This provider extends the EvmWalletProvider to provide Privy-specific wallet functionality
|
|
19
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
20
|
+
*/
|
|
21
|
+
export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvider {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* Private constructor to enforce use of factory method.
|
|
25
|
+
*
|
|
26
|
+
* @param config - The configuration options for the wallet provider
|
|
27
|
+
*/
|
|
28
|
+
private constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Creates and configures a new PrivyEvmDelegatedEmbeddedWalletProvider instance.
|
|
31
|
+
*
|
|
32
|
+
* @param config - The configuration options for the Privy wallet
|
|
33
|
+
* @returns A configured PrivyEvmDelegatedEmbeddedWalletProvider instance
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const provider = await PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet({
|
|
38
|
+
* appId: "your-app-id",
|
|
39
|
+
* appSecret: "your-app-secret",
|
|
40
|
+
* authorizationPrivateKey: "your-auth-key",
|
|
41
|
+
* walletId: "privy-wallet-id",
|
|
42
|
+
* networkId: "base-mainnet"
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
static configureWithWallet(config: PrivyEvmDelegatedEmbeddedWalletConfig): Promise<PrivyEvmDelegatedEmbeddedWalletProvider>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the address of the wallet.
|
|
49
|
+
*
|
|
50
|
+
* @returns The address of the wallet.
|
|
51
|
+
*/
|
|
52
|
+
getAddress(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the network of the wallet.
|
|
55
|
+
*
|
|
56
|
+
* @returns The network of the wallet.
|
|
57
|
+
*/
|
|
58
|
+
getNetwork(): Network;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the name of the wallet provider.
|
|
61
|
+
*
|
|
62
|
+
* @returns The name of the wallet provider.
|
|
63
|
+
*/
|
|
64
|
+
getName(): string;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the balance of the wallet.
|
|
67
|
+
*
|
|
68
|
+
* @returns The balance of the wallet in wei
|
|
69
|
+
*/
|
|
70
|
+
getBalance(): Promise<bigint>;
|
|
71
|
+
/**
|
|
72
|
+
* Signs a message.
|
|
73
|
+
*
|
|
74
|
+
* @param message - The message to sign.
|
|
75
|
+
* @returns The signed message.
|
|
76
|
+
*/
|
|
77
|
+
signMessage(message: string): Promise<Hex>;
|
|
78
|
+
/**
|
|
79
|
+
* Signs typed data according to EIP-712.
|
|
80
|
+
*
|
|
81
|
+
* @param typedData - The typed data object to sign
|
|
82
|
+
* @param typedData.domain - The domain object containing contract and chain information
|
|
83
|
+
* @param typedData.types - The type definitions for the structured data
|
|
84
|
+
* @param typedData.primaryType - The primary type being signed
|
|
85
|
+
* @param typedData.message - The actual data to sign
|
|
86
|
+
* @returns A Address that resolves to the signed typed data as a hex string
|
|
87
|
+
*/
|
|
88
|
+
signTypedData(typedData: {
|
|
89
|
+
domain: Record<string, unknown>;
|
|
90
|
+
types: Record<string, Array<{
|
|
91
|
+
name: string;
|
|
92
|
+
type: string;
|
|
93
|
+
}>>;
|
|
94
|
+
primaryType: string;
|
|
95
|
+
message: Record<string, unknown>;
|
|
96
|
+
}): Promise<Hex>;
|
|
97
|
+
/**
|
|
98
|
+
* Signs a transaction.
|
|
99
|
+
*
|
|
100
|
+
* @param transaction - The transaction to sign.
|
|
101
|
+
* @returns The signed transaction.
|
|
102
|
+
*/
|
|
103
|
+
signTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
104
|
+
/**
|
|
105
|
+
* Sends a transaction.
|
|
106
|
+
*
|
|
107
|
+
* @param transaction - The transaction to send.
|
|
108
|
+
* @returns The hash of the transaction.
|
|
109
|
+
*/
|
|
110
|
+
sendTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
111
|
+
/**
|
|
112
|
+
* Waits for a transaction receipt.
|
|
113
|
+
*
|
|
114
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
115
|
+
* @returns The transaction receipt.
|
|
116
|
+
*/
|
|
117
|
+
waitForTransactionReceipt(txHash: Hex): Promise<TransactionReceipt>;
|
|
118
|
+
/**
|
|
119
|
+
* Reads data from a smart contract.
|
|
120
|
+
*
|
|
121
|
+
* @param params - Parameters for reading the contract
|
|
122
|
+
* @param params.address - The address of the contract
|
|
123
|
+
* @param params.abi - The ABI of the contract
|
|
124
|
+
* @param params.functionName - The name of the function to call
|
|
125
|
+
* @param params.args - The arguments to pass to the function
|
|
126
|
+
* @returns A Address that resolves to the contract function's return value
|
|
127
|
+
*/
|
|
128
|
+
readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>;
|
|
129
|
+
/**
|
|
130
|
+
* Transfer the native asset of the network.
|
|
131
|
+
*
|
|
132
|
+
* @param to - The destination address.
|
|
133
|
+
* @param value - The amount to transfer in Wei.
|
|
134
|
+
* @returns The transaction hash.
|
|
135
|
+
*/
|
|
136
|
+
nativeTransfer(to: string, value: string): Promise<Hex>;
|
|
137
|
+
/**
|
|
138
|
+
* Exports the wallet information.
|
|
139
|
+
*
|
|
140
|
+
* @returns The wallet data
|
|
141
|
+
*/
|
|
142
|
+
exportWallet(): PrivyWalletExport;
|
|
143
|
+
/**
|
|
144
|
+
* Generate Privy authorization signature for API requests
|
|
145
|
+
*
|
|
146
|
+
* @param url - The URL for the request
|
|
147
|
+
* @param body - The request body
|
|
148
|
+
* @returns The generated signature
|
|
149
|
+
*/
|
|
150
|
+
private generatePrivySignature;
|
|
151
|
+
/**
|
|
152
|
+
* Get Privy headers for API requests
|
|
153
|
+
*
|
|
154
|
+
* @param url - The URL for the request
|
|
155
|
+
* @param body - The request body
|
|
156
|
+
* @returns The headers for the request
|
|
157
|
+
*/
|
|
158
|
+
private getPrivyHeaders;
|
|
159
|
+
/**
|
|
160
|
+
* Execute a Privy API request.
|
|
161
|
+
*
|
|
162
|
+
* @param body - The request body to send to the Privy API
|
|
163
|
+
* @returns A promise that resolves to the response data
|
|
164
|
+
* @throws Error if the request fails
|
|
165
|
+
*/
|
|
166
|
+
private executePrivyRequest;
|
|
167
|
+
}
|
|
@@ -0,0 +1,438 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _PrivyEvmDelegatedEmbeddedWalletProvider_walletId, _PrivyEvmDelegatedEmbeddedWalletProvider_address, _PrivyEvmDelegatedEmbeddedWalletProvider_appId, _PrivyEvmDelegatedEmbeddedWalletProvider_appSecret, _PrivyEvmDelegatedEmbeddedWalletProvider_authKey, _PrivyEvmDelegatedEmbeddedWalletProvider_network, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PrivyEvmDelegatedEmbeddedWalletProvider = void 0;
|
|
19
|
+
const canonicalize_1 = __importDefault(require("canonicalize"));
|
|
20
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
21
|
+
const viem_1 = require("viem");
|
|
22
|
+
const network_1 = require("../network/network");
|
|
23
|
+
const privyShared_1 = require("./privyShared");
|
|
24
|
+
const walletProvider_1 = require("./walletProvider");
|
|
25
|
+
/**
|
|
26
|
+
* A wallet provider that uses Privy's embedded wallets with delegation.
|
|
27
|
+
* This provider extends the EvmWalletProvider to provide Privy-specific wallet functionality
|
|
28
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
29
|
+
*/
|
|
30
|
+
class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletProvider {
|
|
31
|
+
/**
|
|
32
|
+
* Private constructor to enforce use of factory method.
|
|
33
|
+
*
|
|
34
|
+
* @param config - The configuration options for the wallet provider
|
|
35
|
+
*/
|
|
36
|
+
constructor(config) {
|
|
37
|
+
super();
|
|
38
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_walletId.set(this, void 0);
|
|
39
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_address.set(this, void 0);
|
|
40
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_appId.set(this, void 0);
|
|
41
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_appSecret.set(this, void 0);
|
|
42
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_authKey.set(this, void 0);
|
|
43
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_network.set(this, void 0);
|
|
44
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_publicClient.set(this, void 0);
|
|
45
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_walletId, config.walletId, "f");
|
|
46
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, config.address, "f");
|
|
47
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_appId, config.appId, "f");
|
|
48
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_appSecret, config.appSecret, "f");
|
|
49
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_authKey, config.authorizationPrivateKey || "", "f");
|
|
50
|
+
const networkId = config.networkId || "base-sepolia";
|
|
51
|
+
const chainId = config.chainId || network_1.NETWORK_ID_TO_CHAIN_ID[networkId];
|
|
52
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, {
|
|
53
|
+
protocolFamily: "evm",
|
|
54
|
+
networkId: networkId,
|
|
55
|
+
chainId: chainId,
|
|
56
|
+
}, "f");
|
|
57
|
+
// Create a public client for read operations
|
|
58
|
+
const chain = (0, network_1.getChain)(chainId);
|
|
59
|
+
if (!chain) {
|
|
60
|
+
throw new Error(`Chain with ID ${chainId} not found`);
|
|
61
|
+
}
|
|
62
|
+
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
63
|
+
chain,
|
|
64
|
+
transport: (0, viem_1.http)(),
|
|
65
|
+
}), "f");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates and configures a new PrivyEvmDelegatedEmbeddedWalletProvider instance.
|
|
69
|
+
*
|
|
70
|
+
* @param config - The configuration options for the Privy wallet
|
|
71
|
+
* @returns A configured PrivyEvmDelegatedEmbeddedWalletProvider instance
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const provider = await PrivyEvmDelegatedEmbeddedWalletProvider.configureWithWallet({
|
|
76
|
+
* appId: "your-app-id",
|
|
77
|
+
* appSecret: "your-app-secret",
|
|
78
|
+
* authorizationPrivateKey: "your-auth-key",
|
|
79
|
+
* walletId: "privy-wallet-id",
|
|
80
|
+
* networkId: "base-mainnet"
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
static async configureWithWallet(config) {
|
|
85
|
+
try {
|
|
86
|
+
if (!config.walletId) {
|
|
87
|
+
throw new Error("walletId is required for PrivyEvmDelegatedEmbeddedWalletProvider");
|
|
88
|
+
}
|
|
89
|
+
if (!config.appId || !config.appSecret) {
|
|
90
|
+
throw new Error("appId and appSecret are required for PrivyEvmDelegatedEmbeddedWalletProvider");
|
|
91
|
+
}
|
|
92
|
+
if (!config.authorizationPrivateKey) {
|
|
93
|
+
throw new Error("authorizationPrivateKey is required for PrivyEvmDelegatedEmbeddedWalletProvider");
|
|
94
|
+
}
|
|
95
|
+
const privyClient = (0, privyShared_1.createPrivyClient)(config);
|
|
96
|
+
const user = await privyClient.getUser(config.walletId);
|
|
97
|
+
const embeddedWallets = user.linkedAccounts.filter((account) => account.type === "wallet" && account.walletClientType === "privy");
|
|
98
|
+
if (embeddedWallets.length === 0) {
|
|
99
|
+
throw new Error(`Could not find wallet address for wallet ID ${config.walletId}`);
|
|
100
|
+
}
|
|
101
|
+
const walletAddress = embeddedWallets[0].address;
|
|
102
|
+
// Verify the network/chain ID if provided
|
|
103
|
+
if (config.chainId) {
|
|
104
|
+
const chain = (0, network_1.getChain)(config.chainId);
|
|
105
|
+
if (!chain) {
|
|
106
|
+
throw new Error(`Chain with ID ${config.chainId} not found`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return new PrivyEvmDelegatedEmbeddedWalletProvider({
|
|
110
|
+
...config,
|
|
111
|
+
address: walletAddress,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof Error) {
|
|
116
|
+
throw new Error(`Failed to configure Privy embedded wallet provider: ${error.message}`);
|
|
117
|
+
}
|
|
118
|
+
throw new Error("Failed to configure Privy embedded wallet provider");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets the address of the wallet.
|
|
123
|
+
*
|
|
124
|
+
* @returns The address of the wallet.
|
|
125
|
+
*/
|
|
126
|
+
getAddress() {
|
|
127
|
+
return __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets the network of the wallet.
|
|
131
|
+
*
|
|
132
|
+
* @returns The network of the wallet.
|
|
133
|
+
*/
|
|
134
|
+
getNetwork() {
|
|
135
|
+
return __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, "f");
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Gets the name of the wallet provider.
|
|
139
|
+
*
|
|
140
|
+
* @returns The name of the wallet provider.
|
|
141
|
+
*/
|
|
142
|
+
getName() {
|
|
143
|
+
return "privy_evm_embedded_wallet_provider";
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Gets the balance of the wallet.
|
|
147
|
+
*
|
|
148
|
+
* @returns The balance of the wallet in wei
|
|
149
|
+
*/
|
|
150
|
+
async getBalance() {
|
|
151
|
+
try {
|
|
152
|
+
const balance = await __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, "f").getBalance({
|
|
153
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
154
|
+
});
|
|
155
|
+
return balance;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof Error) {
|
|
159
|
+
throw new Error(`Error getting balance: ${error.message}`);
|
|
160
|
+
}
|
|
161
|
+
throw new Error("Error getting balance");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Signs a message.
|
|
166
|
+
*
|
|
167
|
+
* @param message - The message to sign.
|
|
168
|
+
* @returns The signed message.
|
|
169
|
+
*/
|
|
170
|
+
async signMessage(message) {
|
|
171
|
+
const body = {
|
|
172
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
173
|
+
chain_type: "ethereum",
|
|
174
|
+
method: "personal_sign",
|
|
175
|
+
params: {
|
|
176
|
+
message,
|
|
177
|
+
encoding: "utf-8",
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
try {
|
|
181
|
+
const response = await this.executePrivyRequest(body);
|
|
182
|
+
return response.data?.signature;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof Error) {
|
|
186
|
+
throw new Error(`Message signing failed: ${error.message}`);
|
|
187
|
+
}
|
|
188
|
+
throw new Error("Message signing failed");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Signs typed data according to EIP-712.
|
|
193
|
+
*
|
|
194
|
+
* @param typedData - The typed data object to sign
|
|
195
|
+
* @param typedData.domain - The domain object containing contract and chain information
|
|
196
|
+
* @param typedData.types - The type definitions for the structured data
|
|
197
|
+
* @param typedData.primaryType - The primary type being signed
|
|
198
|
+
* @param typedData.message - The actual data to sign
|
|
199
|
+
* @returns A Address that resolves to the signed typed data as a hex string
|
|
200
|
+
*/
|
|
201
|
+
async signTypedData(typedData) {
|
|
202
|
+
const body = {
|
|
203
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
204
|
+
chain_type: "ethereum",
|
|
205
|
+
chain_id: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, "f").chainId,
|
|
206
|
+
...typedData,
|
|
207
|
+
};
|
|
208
|
+
try {
|
|
209
|
+
const response = await this.executePrivyRequest({
|
|
210
|
+
method: "eth_signTypedData_v4",
|
|
211
|
+
params: body,
|
|
212
|
+
});
|
|
213
|
+
return response.signature;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (error instanceof Error) {
|
|
217
|
+
throw new Error("Typed data signing failed: " + error.message);
|
|
218
|
+
}
|
|
219
|
+
throw new Error("Typed data signing failed with unknown error");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Signs a transaction.
|
|
224
|
+
*
|
|
225
|
+
* @param transaction - The transaction to sign.
|
|
226
|
+
* @returns The signed transaction.
|
|
227
|
+
*/
|
|
228
|
+
async signTransaction(transaction) {
|
|
229
|
+
const body = {
|
|
230
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
231
|
+
chain_type: "ethereum",
|
|
232
|
+
method: "eth_signTransaction",
|
|
233
|
+
params: {
|
|
234
|
+
transaction: {
|
|
235
|
+
...transaction,
|
|
236
|
+
from: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
try {
|
|
241
|
+
const response = await this.executePrivyRequest(body);
|
|
242
|
+
return response.data?.signed_transaction;
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
if (error instanceof Error) {
|
|
246
|
+
throw new Error(`Transaction signing failed: ${error.message}`);
|
|
247
|
+
}
|
|
248
|
+
throw new Error("Transaction signing failed");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Sends a transaction.
|
|
253
|
+
*
|
|
254
|
+
* @param transaction - The transaction to send.
|
|
255
|
+
* @returns The hash of the transaction.
|
|
256
|
+
*/
|
|
257
|
+
async sendTransaction(transaction) {
|
|
258
|
+
const body = {
|
|
259
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
260
|
+
chain_type: "ethereum",
|
|
261
|
+
method: "eth_sendTransaction",
|
|
262
|
+
caip2: `eip155:${__classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, "f").chainId}`,
|
|
263
|
+
params: {
|
|
264
|
+
transaction: {
|
|
265
|
+
...transaction,
|
|
266
|
+
from: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
try {
|
|
271
|
+
const response = await this.executePrivyRequest(body);
|
|
272
|
+
return response.data?.hash;
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
if (error instanceof Error) {
|
|
276
|
+
throw new Error(`Transaction sending failed: ${error.message}`);
|
|
277
|
+
}
|
|
278
|
+
throw new Error("Transaction sending failed");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Waits for a transaction receipt.
|
|
283
|
+
*
|
|
284
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
285
|
+
* @returns The transaction receipt.
|
|
286
|
+
*/
|
|
287
|
+
async waitForTransactionReceipt(txHash) {
|
|
288
|
+
return await __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, "f").waitForTransactionReceipt({
|
|
289
|
+
hash: txHash,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Reads data from a smart contract.
|
|
294
|
+
*
|
|
295
|
+
* @param params - Parameters for reading the contract
|
|
296
|
+
* @param params.address - The address of the contract
|
|
297
|
+
* @param params.abi - The ABI of the contract
|
|
298
|
+
* @param params.functionName - The name of the function to call
|
|
299
|
+
* @param params.args - The arguments to pass to the function
|
|
300
|
+
* @returns A Address that resolves to the contract function's return value
|
|
301
|
+
*/
|
|
302
|
+
async readContract(params) {
|
|
303
|
+
return __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, "f").readContract(params);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Transfer the native asset of the network.
|
|
307
|
+
*
|
|
308
|
+
* @param to - The destination address.
|
|
309
|
+
* @param value - The amount to transfer in Wei.
|
|
310
|
+
* @returns The transaction hash.
|
|
311
|
+
*/
|
|
312
|
+
async nativeTransfer(to, value) {
|
|
313
|
+
const valueInWei = (0, viem_1.parseEther)(value);
|
|
314
|
+
const valueHex = `0x${valueInWei.toString(16)}`;
|
|
315
|
+
const body = {
|
|
316
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
317
|
+
chain_type: "ethereum",
|
|
318
|
+
method: "eth_sendTransaction",
|
|
319
|
+
caip2: `eip155:${__classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, "f").chainId}`,
|
|
320
|
+
params: {
|
|
321
|
+
transaction: {
|
|
322
|
+
to,
|
|
323
|
+
value: valueHex,
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
try {
|
|
328
|
+
const response = await this.executePrivyRequest(body);
|
|
329
|
+
const receipt = await this.waitForTransactionReceipt(response.data.hash);
|
|
330
|
+
if (!receipt) {
|
|
331
|
+
throw new Error("Transaction failed");
|
|
332
|
+
}
|
|
333
|
+
return receipt.transactionHash;
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
if (error instanceof Error) {
|
|
337
|
+
throw new Error(`Native transfer failed: ${error.message}`);
|
|
338
|
+
}
|
|
339
|
+
throw new Error("Native transfer failed");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Exports the wallet information.
|
|
344
|
+
*
|
|
345
|
+
* @returns The wallet data
|
|
346
|
+
*/
|
|
347
|
+
exportWallet() {
|
|
348
|
+
return {
|
|
349
|
+
walletId: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_walletId, "f"),
|
|
350
|
+
authorizationPrivateKey: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_authKey, "f"),
|
|
351
|
+
networkId: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, "f").networkId,
|
|
352
|
+
chainId: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_network, "f").chainId,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Generate Privy authorization signature for API requests
|
|
357
|
+
*
|
|
358
|
+
* @param url - The URL for the request
|
|
359
|
+
* @param body - The request body
|
|
360
|
+
* @returns The generated signature
|
|
361
|
+
*/
|
|
362
|
+
generatePrivySignature(url, body) {
|
|
363
|
+
try {
|
|
364
|
+
const payload = {
|
|
365
|
+
version: 1,
|
|
366
|
+
method: "POST",
|
|
367
|
+
url,
|
|
368
|
+
body,
|
|
369
|
+
headers: {
|
|
370
|
+
"privy-app-id": __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_appId, "f"),
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
const serializedPayload = (0, canonicalize_1.default)(payload);
|
|
374
|
+
if (!serializedPayload)
|
|
375
|
+
throw new Error("Failed to canonicalize payload");
|
|
376
|
+
const serializedPayloadBuffer = Buffer.from(serializedPayload);
|
|
377
|
+
const privateKeyAsString = __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_authKey, "f").replace("wallet-auth:", "");
|
|
378
|
+
const privateKeyAsPem = `-----BEGIN PRIVATE KEY-----\n${privateKeyAsString}\n-----END PRIVATE KEY-----`;
|
|
379
|
+
const privateKey = crypto_1.default.createPrivateKey({
|
|
380
|
+
key: privateKeyAsPem,
|
|
381
|
+
format: "pem",
|
|
382
|
+
});
|
|
383
|
+
const signatureBuffer = crypto_1.default.sign("sha256", serializedPayloadBuffer, privateKey);
|
|
384
|
+
return signatureBuffer.toString("base64");
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
if (error instanceof Error) {
|
|
388
|
+
throw new Error(`Error generating Privy authorization signature: ${error.message}`);
|
|
389
|
+
}
|
|
390
|
+
throw new Error("Error generating Privy authorization signature");
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get Privy headers for API requests
|
|
395
|
+
*
|
|
396
|
+
* @param url - The URL for the request
|
|
397
|
+
* @param body - The request body
|
|
398
|
+
* @returns The headers for the request
|
|
399
|
+
*/
|
|
400
|
+
getPrivyHeaders(url, body) {
|
|
401
|
+
return {
|
|
402
|
+
"Content-Type": "application/json",
|
|
403
|
+
Authorization: `Basic ${Buffer.from(`${__classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_appId, "f")}:${__classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_appSecret, "f")}`).toString("base64")}`,
|
|
404
|
+
"privy-app-id": __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_appId, "f"),
|
|
405
|
+
"privy-authorization-signature": this.generatePrivySignature(url, body),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Execute a Privy API request.
|
|
410
|
+
*
|
|
411
|
+
* @param body - The request body to send to the Privy API
|
|
412
|
+
* @returns A promise that resolves to the response data
|
|
413
|
+
* @throws Error if the request fails
|
|
414
|
+
*/
|
|
415
|
+
async executePrivyRequest(body) {
|
|
416
|
+
const url = `https://api.privy.io/v1/wallets/rpc`;
|
|
417
|
+
const headers = this.getPrivyHeaders(url, body);
|
|
418
|
+
try {
|
|
419
|
+
const response = await fetch(url, {
|
|
420
|
+
method: "POST",
|
|
421
|
+
headers,
|
|
422
|
+
body: JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value),
|
|
423
|
+
});
|
|
424
|
+
if (!response.ok) {
|
|
425
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
426
|
+
}
|
|
427
|
+
return await response.json();
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
if (error instanceof Error) {
|
|
431
|
+
throw new Error("Privy request failed: " + error.message);
|
|
432
|
+
}
|
|
433
|
+
throw new Error("Privy request failed with unknown error");
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
exports.PrivyEvmDelegatedEmbeddedWalletProvider = PrivyEvmDelegatedEmbeddedWalletProvider;
|
|
438
|
+
_PrivyEvmDelegatedEmbeddedWalletProvider_walletId = new WeakMap(), _PrivyEvmDelegatedEmbeddedWalletProvider_address = new WeakMap(), _PrivyEvmDelegatedEmbeddedWalletProvider_appId = new WeakMap(), _PrivyEvmDelegatedEmbeddedWalletProvider_appSecret = new WeakMap(), _PrivyEvmDelegatedEmbeddedWalletProvider_authKey = new WeakMap(), _PrivyEvmDelegatedEmbeddedWalletProvider_network = new WeakMap(), _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient = new WeakMap();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|