@phantom/browser-injected-sdk 0.0.9
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 +161 -0
- package/dist/auto-confirm/index.d.ts +37 -0
- package/dist/auto-confirm/index.js +107 -0
- package/dist/auto-confirm/index.mjs +82 -0
- package/dist/chunk-GV6AIHPN.mjs +18 -0
- package/dist/chunk-QNVIOBKG.mjs +382 -0
- package/dist/chunk-WUKYLWAZ.mjs +0 -0
- package/dist/ethereum/index.d.ts +1 -0
- package/dist/ethereum/index.js +416 -0
- package/dist/ethereum/index.mjs +8 -0
- package/dist/index-2f448acb.d.ts +168 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +452 -0
- package/dist/index.mjs +41 -0
- package/dist/solana/index.d.ts +139 -0
- package/dist/solana/index.js +413 -0
- package/dist/solana/index.mjs +379 -0
- package/package.json +61 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __accessCheck = (obj, member, msg) => {
|
|
20
|
+
if (!member.has(obj))
|
|
21
|
+
throw TypeError("Cannot " + msg);
|
|
22
|
+
};
|
|
23
|
+
var __privateAdd = (obj, member, value) => {
|
|
24
|
+
if (member.has(obj))
|
|
25
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
26
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
27
|
+
};
|
|
28
|
+
var __privateMethod = (obj, member, method) => {
|
|
29
|
+
__accessCheck(obj, member, "access private method");
|
|
30
|
+
return method;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/ethereum/index.ts
|
|
34
|
+
var ethereum_exports = {};
|
|
35
|
+
__export(ethereum_exports, {
|
|
36
|
+
createEthereumPlugin: () => createEthereumPlugin
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(ethereum_exports);
|
|
39
|
+
|
|
40
|
+
// src/ethereum/strategies/injected.ts
|
|
41
|
+
var MAX_RETRIES = 4;
|
|
42
|
+
var BASE_DELAY = 100;
|
|
43
|
+
var _getProvider, getProvider_fn;
|
|
44
|
+
var InjectedEthereumStrategy = class {
|
|
45
|
+
constructor() {
|
|
46
|
+
__privateAdd(this, _getProvider);
|
|
47
|
+
this.type = "injected" /* INJECTED */;
|
|
48
|
+
}
|
|
49
|
+
load() {
|
|
50
|
+
let retryCount = 0;
|
|
51
|
+
const scheduleRetry = (resolve, reject) => {
|
|
52
|
+
const delay = BASE_DELAY * Math.pow(2, Math.min(retryCount, 5));
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
if (__privateMethod(this, _getProvider, getProvider_fn).call(this)) {
|
|
55
|
+
resolve();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
retryCount++;
|
|
59
|
+
if (retryCount >= MAX_RETRIES) {
|
|
60
|
+
reject();
|
|
61
|
+
} else {
|
|
62
|
+
scheduleRetry(resolve, reject);
|
|
63
|
+
}
|
|
64
|
+
}, delay);
|
|
65
|
+
};
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
scheduleRetry(() => resolve(this), reject);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
get isConnected() {
|
|
71
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
72
|
+
return provider?.isConnected && provider.selectedAddress ? true : false;
|
|
73
|
+
}
|
|
74
|
+
async connect({ onlyIfTrusted }) {
|
|
75
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
76
|
+
if (!provider) {
|
|
77
|
+
throw new Error("Provider not found.");
|
|
78
|
+
}
|
|
79
|
+
if (provider.isConnected && provider.selectedAddress) {
|
|
80
|
+
return this.getAccounts();
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const accounts = await provider.request({
|
|
84
|
+
method: onlyIfTrusted ? "eth_accounts" : "eth_requestAccounts"
|
|
85
|
+
});
|
|
86
|
+
return accounts;
|
|
87
|
+
} catch (_) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async disconnect() {
|
|
92
|
+
return Promise.resolve();
|
|
93
|
+
}
|
|
94
|
+
async getAccounts() {
|
|
95
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
96
|
+
if (!provider) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
101
|
+
return accounts || [];
|
|
102
|
+
} catch (_) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async signMessage(message, address) {
|
|
107
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
108
|
+
if (!provider) {
|
|
109
|
+
throw new Error("Provider not found.");
|
|
110
|
+
}
|
|
111
|
+
if (!provider.isConnected) {
|
|
112
|
+
throw new Error("Provider is not connected.");
|
|
113
|
+
}
|
|
114
|
+
const signature = await provider.request({
|
|
115
|
+
method: "eth_sign",
|
|
116
|
+
params: [address, message]
|
|
117
|
+
});
|
|
118
|
+
return signature;
|
|
119
|
+
}
|
|
120
|
+
async signPersonalMessage(message, address) {
|
|
121
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
122
|
+
if (!provider) {
|
|
123
|
+
throw new Error("Provider not found.");
|
|
124
|
+
}
|
|
125
|
+
if (!provider.isConnected) {
|
|
126
|
+
throw new Error("Provider is not connected.");
|
|
127
|
+
}
|
|
128
|
+
const signature = await provider.request({
|
|
129
|
+
method: "personal_sign",
|
|
130
|
+
params: [message, address]
|
|
131
|
+
});
|
|
132
|
+
return signature;
|
|
133
|
+
}
|
|
134
|
+
async signTypedData(typedData, address) {
|
|
135
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
136
|
+
if (!provider) {
|
|
137
|
+
throw new Error("Provider not found.");
|
|
138
|
+
}
|
|
139
|
+
if (!provider.isConnected) {
|
|
140
|
+
throw new Error("Provider is not connected.");
|
|
141
|
+
}
|
|
142
|
+
const signature = await provider.request({
|
|
143
|
+
method: "eth_signTypedData_v4",
|
|
144
|
+
params: [address, JSON.stringify(typedData)]
|
|
145
|
+
});
|
|
146
|
+
return signature;
|
|
147
|
+
}
|
|
148
|
+
async signIn(signInData) {
|
|
149
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
150
|
+
if (!provider) {
|
|
151
|
+
throw new Error("Provider not found.");
|
|
152
|
+
}
|
|
153
|
+
const message = `Sign in to ${signInData.domain || "this application"}`;
|
|
154
|
+
const address = provider.selectedAddress;
|
|
155
|
+
if (!address) {
|
|
156
|
+
throw new Error("No address available.");
|
|
157
|
+
}
|
|
158
|
+
const signature = await this.signPersonalMessage(message, address);
|
|
159
|
+
return {
|
|
160
|
+
address,
|
|
161
|
+
signature,
|
|
162
|
+
signedMessage: message
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
async sendTransaction(transaction) {
|
|
166
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
167
|
+
if (!provider) {
|
|
168
|
+
throw new Error("Provider not found.");
|
|
169
|
+
}
|
|
170
|
+
if (!provider.isConnected) {
|
|
171
|
+
throw new Error("Provider is not connected.");
|
|
172
|
+
}
|
|
173
|
+
const txHash = await provider.request({
|
|
174
|
+
method: "eth_sendTransaction",
|
|
175
|
+
params: [transaction]
|
|
176
|
+
});
|
|
177
|
+
return txHash;
|
|
178
|
+
}
|
|
179
|
+
async signTransaction(transaction) {
|
|
180
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
181
|
+
if (!provider) {
|
|
182
|
+
throw new Error("Provider not found.");
|
|
183
|
+
}
|
|
184
|
+
if (!provider.isConnected) {
|
|
185
|
+
throw new Error("Provider is not connected.");
|
|
186
|
+
}
|
|
187
|
+
const signedTx = await provider.request({
|
|
188
|
+
method: "eth_signTransaction",
|
|
189
|
+
params: [transaction]
|
|
190
|
+
});
|
|
191
|
+
return signedTx;
|
|
192
|
+
}
|
|
193
|
+
async getChainId() {
|
|
194
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
195
|
+
if (!provider) {
|
|
196
|
+
throw new Error("Provider not found.");
|
|
197
|
+
}
|
|
198
|
+
const chainId = await provider.request({ method: "eth_chainId" });
|
|
199
|
+
return chainId;
|
|
200
|
+
}
|
|
201
|
+
async switchChain(chainId) {
|
|
202
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
203
|
+
if (!provider) {
|
|
204
|
+
throw new Error("Provider not found.");
|
|
205
|
+
}
|
|
206
|
+
await provider.request({
|
|
207
|
+
method: "wallet_switchEthereumChain",
|
|
208
|
+
params: [{ chainId }]
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
_getProvider = new WeakSet();
|
|
213
|
+
getProvider_fn = function() {
|
|
214
|
+
return window?.phantom?.ethereum;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/ethereum/getProvider.ts
|
|
218
|
+
async function getProvider(strategy = "injected" /* INJECTED */) {
|
|
219
|
+
if (strategy === "injected") {
|
|
220
|
+
const provider = new InjectedEthereumStrategy();
|
|
221
|
+
try {
|
|
222
|
+
await provider.load();
|
|
223
|
+
return provider;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
throw new Error("Provider not found.");
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
throw new Error("Invalid provider type.");
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// src/ethereum/eventListeners.ts
|
|
233
|
+
var eventListeners = /* @__PURE__ */ new Map();
|
|
234
|
+
function addEventListener(event, callback) {
|
|
235
|
+
if (!eventListeners.has(event)) {
|
|
236
|
+
eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
237
|
+
}
|
|
238
|
+
const listeners = eventListeners.get(event);
|
|
239
|
+
listeners.add(callback);
|
|
240
|
+
return () => removeEventListener(event, callback);
|
|
241
|
+
}
|
|
242
|
+
function removeEventListener(event, callback) {
|
|
243
|
+
const listeners = eventListeners.get(event);
|
|
244
|
+
if (listeners) {
|
|
245
|
+
listeners.delete(callback);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function triggerEvent(event, data) {
|
|
249
|
+
const listeners = eventListeners.get(event);
|
|
250
|
+
if (listeners) {
|
|
251
|
+
listeners.forEach((callback) => {
|
|
252
|
+
try {
|
|
253
|
+
callback(data);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/ethereum/connect.ts
|
|
262
|
+
async function connect() {
|
|
263
|
+
const provider = await getProvider();
|
|
264
|
+
if (!provider) {
|
|
265
|
+
throw new Error("Provider not found.");
|
|
266
|
+
}
|
|
267
|
+
if (provider.isConnected) {
|
|
268
|
+
const accounts = await provider.getAccounts();
|
|
269
|
+
return accounts;
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const accounts = await provider.connect({ onlyIfTrusted: true });
|
|
273
|
+
if (accounts && accounts.length > 0) {
|
|
274
|
+
triggerEvent("connect", accounts);
|
|
275
|
+
return accounts;
|
|
276
|
+
}
|
|
277
|
+
} catch (error) {
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
const accounts = await provider.connect({ onlyIfTrusted: false });
|
|
281
|
+
if (accounts && accounts.length > 0) {
|
|
282
|
+
triggerEvent("connect", accounts);
|
|
283
|
+
return accounts;
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
}
|
|
287
|
+
throw new Error("Failed to connect to Phantom.");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/ethereum/disconnect.ts
|
|
291
|
+
async function disconnect() {
|
|
292
|
+
const provider = await getProvider();
|
|
293
|
+
if (!provider) {
|
|
294
|
+
throw new Error("Provider not found.");
|
|
295
|
+
}
|
|
296
|
+
await provider.disconnect();
|
|
297
|
+
triggerEvent("disconnect", []);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/ethereum/getAccounts.ts
|
|
301
|
+
async function getAccounts() {
|
|
302
|
+
const provider = await getProvider();
|
|
303
|
+
if (!provider) {
|
|
304
|
+
throw new Error("Provider not found.");
|
|
305
|
+
}
|
|
306
|
+
return provider.getAccounts();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/ethereum/signMessage.ts
|
|
310
|
+
async function signMessage(message, address) {
|
|
311
|
+
const provider = await getProvider();
|
|
312
|
+
if (!provider) {
|
|
313
|
+
throw new Error("Provider not found.");
|
|
314
|
+
}
|
|
315
|
+
if (!provider.isConnected) {
|
|
316
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
317
|
+
}
|
|
318
|
+
return provider.signMessage(message, address);
|
|
319
|
+
}
|
|
320
|
+
async function signPersonalMessage(message, address) {
|
|
321
|
+
const provider = await getProvider();
|
|
322
|
+
if (!provider) {
|
|
323
|
+
throw new Error("Provider not found.");
|
|
324
|
+
}
|
|
325
|
+
if (!provider.isConnected) {
|
|
326
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
327
|
+
}
|
|
328
|
+
return provider.signPersonalMessage(message, address);
|
|
329
|
+
}
|
|
330
|
+
async function signTypedData(typedData, address) {
|
|
331
|
+
const provider = await getProvider();
|
|
332
|
+
if (!provider) {
|
|
333
|
+
throw new Error("Provider not found.");
|
|
334
|
+
}
|
|
335
|
+
if (!provider.isConnected) {
|
|
336
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
337
|
+
}
|
|
338
|
+
return provider.signTypedData(typedData, address);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/ethereum/signIn.ts
|
|
342
|
+
async function signIn(signInData) {
|
|
343
|
+
const provider = await getProvider();
|
|
344
|
+
if (!provider) {
|
|
345
|
+
throw new Error("Provider not found.");
|
|
346
|
+
}
|
|
347
|
+
if (!provider.isConnected) {
|
|
348
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
349
|
+
}
|
|
350
|
+
return provider.signIn(signInData);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/ethereum/sendTransaction.ts
|
|
354
|
+
async function sendTransaction(transaction) {
|
|
355
|
+
const provider = await getProvider();
|
|
356
|
+
if (!provider) {
|
|
357
|
+
throw new Error("Provider not found.");
|
|
358
|
+
}
|
|
359
|
+
if (!provider.isConnected) {
|
|
360
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
361
|
+
}
|
|
362
|
+
return provider.sendTransaction(transaction);
|
|
363
|
+
}
|
|
364
|
+
async function signTransaction(transaction) {
|
|
365
|
+
const provider = await getProvider();
|
|
366
|
+
if (!provider) {
|
|
367
|
+
throw new Error("Provider not found.");
|
|
368
|
+
}
|
|
369
|
+
if (!provider.isConnected) {
|
|
370
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
371
|
+
}
|
|
372
|
+
return provider.signTransaction(transaction);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/ethereum/chainUtils.ts
|
|
376
|
+
async function getChainId() {
|
|
377
|
+
const provider = await getProvider();
|
|
378
|
+
if (!provider) {
|
|
379
|
+
throw new Error("Provider not found.");
|
|
380
|
+
}
|
|
381
|
+
return provider.getChainId();
|
|
382
|
+
}
|
|
383
|
+
async function switchChain(chainId) {
|
|
384
|
+
const provider = await getProvider();
|
|
385
|
+
if (!provider) {
|
|
386
|
+
throw new Error("Provider not found.");
|
|
387
|
+
}
|
|
388
|
+
return provider.switchChain(chainId);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/ethereum/plugin.ts
|
|
392
|
+
var ethereum = {
|
|
393
|
+
connect,
|
|
394
|
+
disconnect,
|
|
395
|
+
getAccounts,
|
|
396
|
+
signMessage,
|
|
397
|
+
signPersonalMessage,
|
|
398
|
+
signTypedData,
|
|
399
|
+
signIn,
|
|
400
|
+
sendTransaction,
|
|
401
|
+
signTransaction,
|
|
402
|
+
getChainId,
|
|
403
|
+
switchChain,
|
|
404
|
+
addEventListener,
|
|
405
|
+
removeEventListener
|
|
406
|
+
};
|
|
407
|
+
function createEthereumPlugin() {
|
|
408
|
+
return {
|
|
409
|
+
name: "ethereum",
|
|
410
|
+
create: () => ethereum
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
414
|
+
0 && (module.exports = {
|
|
415
|
+
createEthereumPlugin
|
|
416
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
declare function isInstalled(): boolean;
|
|
2
|
+
|
|
3
|
+
type Extension = {
|
|
4
|
+
isInstalled: typeof isInstalled;
|
|
5
|
+
};
|
|
6
|
+
declare function createExtensionPlugin(): Plugin<Extension>;
|
|
7
|
+
|
|
8
|
+
declare module "../index" {
|
|
9
|
+
interface Phantom {
|
|
10
|
+
extension: Extension;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function connect(): Promise<string[]>;
|
|
15
|
+
|
|
16
|
+
declare function disconnect(): Promise<void>;
|
|
17
|
+
|
|
18
|
+
type EthereumTransaction = {
|
|
19
|
+
to?: string;
|
|
20
|
+
from?: string;
|
|
21
|
+
value?: string;
|
|
22
|
+
gas?: string;
|
|
23
|
+
gasPrice?: string;
|
|
24
|
+
maxFeePerGas?: string;
|
|
25
|
+
maxPriorityFeePerGas?: string;
|
|
26
|
+
data?: string;
|
|
27
|
+
nonce?: string;
|
|
28
|
+
type?: string;
|
|
29
|
+
chainId?: string;
|
|
30
|
+
};
|
|
31
|
+
type EthereumSignInData = {
|
|
32
|
+
domain?: string;
|
|
33
|
+
address?: string;
|
|
34
|
+
statement?: string;
|
|
35
|
+
uri?: string;
|
|
36
|
+
version?: string;
|
|
37
|
+
chainId?: string;
|
|
38
|
+
nonce?: string;
|
|
39
|
+
issuedAt?: string;
|
|
40
|
+
expirationTime?: string;
|
|
41
|
+
notBefore?: string;
|
|
42
|
+
requestId?: string;
|
|
43
|
+
resources?: string[];
|
|
44
|
+
};
|
|
45
|
+
type EthereumEventType = "connect" | "disconnect" | "accountsChanged" | "chainChanged";
|
|
46
|
+
interface PhantomEthereumProvider {
|
|
47
|
+
isPhantom: boolean;
|
|
48
|
+
selectedAddress: string | null;
|
|
49
|
+
chainId: string;
|
|
50
|
+
isConnected: boolean;
|
|
51
|
+
request: (args: {
|
|
52
|
+
method: string;
|
|
53
|
+
params?: any[];
|
|
54
|
+
}) => Promise<any>;
|
|
55
|
+
on: (event: EthereumEventType, handler: (...args: any[]) => void) => void;
|
|
56
|
+
off: (event: EthereumEventType, handler: (...args: any[]) => void) => void;
|
|
57
|
+
removeAllListeners: (event?: EthereumEventType) => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type PhantomEthereumEventCallback = (data: any) => void;
|
|
61
|
+
|
|
62
|
+
declare function getAccounts(): Promise<string[]>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Signs a message using the Phantom Ethereum provider.
|
|
66
|
+
* @param message The message to sign (as a string).
|
|
67
|
+
* @param address The address to sign with.
|
|
68
|
+
* @returns A promise that resolves with the signature.
|
|
69
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
70
|
+
*/
|
|
71
|
+
declare function signMessage(message: string, address: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Signs a personal message using the Phantom Ethereum provider.
|
|
74
|
+
* @param message The message to sign (as a string).
|
|
75
|
+
* @param address The address to sign with.
|
|
76
|
+
* @returns A promise that resolves with the signature.
|
|
77
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
78
|
+
*/
|
|
79
|
+
declare function signPersonalMessage(message: string, address: string): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Signs typed data using the Phantom Ethereum provider.
|
|
82
|
+
* @param typedData The typed data to sign.
|
|
83
|
+
* @param address The address to sign with.
|
|
84
|
+
* @returns A promise that resolves with the signature.
|
|
85
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
86
|
+
*/
|
|
87
|
+
declare function signTypedData(typedData: any, address: string): Promise<string>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Signs in using the Phantom Ethereum provider.
|
|
91
|
+
* @param signInData The sign-in data.
|
|
92
|
+
* @returns A promise that resolves with the signature data.
|
|
93
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
94
|
+
*/
|
|
95
|
+
declare function signIn(signInData: EthereumSignInData): Promise<{
|
|
96
|
+
address: string;
|
|
97
|
+
signature: string;
|
|
98
|
+
signedMessage: string;
|
|
99
|
+
}>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Sends a transaction using the Phantom Ethereum provider.
|
|
103
|
+
* @param transaction The transaction to send.
|
|
104
|
+
* @returns A promise that resolves with the transaction hash.
|
|
105
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
106
|
+
*/
|
|
107
|
+
declare function sendTransaction(transaction: EthereumTransaction): Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Signs a transaction using the Phantom Ethereum provider.
|
|
110
|
+
* @param transaction The transaction to sign.
|
|
111
|
+
* @returns A promise that resolves with the signed transaction.
|
|
112
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
113
|
+
*/
|
|
114
|
+
declare function signTransaction(transaction: EthereumTransaction): Promise<string>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Gets the current chain ID.
|
|
118
|
+
* @returns A promise that resolves with the chain ID.
|
|
119
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
120
|
+
*/
|
|
121
|
+
declare function getChainId(): Promise<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Switches to a different chain.
|
|
124
|
+
* @param chainId The chain ID to switch to.
|
|
125
|
+
* @returns A promise that resolves when the switch is complete.
|
|
126
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
127
|
+
*/
|
|
128
|
+
declare function switchChain(chainId: string): Promise<void>;
|
|
129
|
+
|
|
130
|
+
type Ethereum = {
|
|
131
|
+
connect: typeof connect;
|
|
132
|
+
disconnect: typeof disconnect;
|
|
133
|
+
getAccounts: typeof getAccounts;
|
|
134
|
+
signMessage: typeof signMessage;
|
|
135
|
+
signPersonalMessage: typeof signPersonalMessage;
|
|
136
|
+
signTypedData: typeof signTypedData;
|
|
137
|
+
signIn: typeof signIn;
|
|
138
|
+
sendTransaction: typeof sendTransaction;
|
|
139
|
+
signTransaction: typeof signTransaction;
|
|
140
|
+
getChainId: typeof getChainId;
|
|
141
|
+
switchChain: typeof switchChain;
|
|
142
|
+
addEventListener: (event: EthereumEventType, callback: PhantomEthereumEventCallback) => () => void;
|
|
143
|
+
removeEventListener: (event: EthereumEventType, callback: PhantomEthereumEventCallback) => void;
|
|
144
|
+
};
|
|
145
|
+
declare function createEthereumPlugin(): Plugin<Ethereum>;
|
|
146
|
+
|
|
147
|
+
declare module "../index" {
|
|
148
|
+
interface Phantom {
|
|
149
|
+
ethereum: Ethereum;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
type Plugin<T> = {
|
|
154
|
+
name: string;
|
|
155
|
+
create: () => T;
|
|
156
|
+
};
|
|
157
|
+
type CreatePhantomConfig = {
|
|
158
|
+
plugins?: Plugin<unknown>[];
|
|
159
|
+
};
|
|
160
|
+
interface Phantom {
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Creates a Phantom instance with the provided plugins.
|
|
164
|
+
* Each plugin extends the Phantom interface via declaration merging.
|
|
165
|
+
*/
|
|
166
|
+
declare function createPhantom({ plugins }: CreatePhantomConfig): Phantom;
|
|
167
|
+
|
|
168
|
+
export { CreatePhantomConfig as C, EthereumTransaction as E, Plugin as P, PhantomEthereumProvider as a, EthereumSignInData as b, createEthereumPlugin as c, EthereumEventType as d, Phantom as e, createPhantom as f, createExtensionPlugin as g, isInstalled as i };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { C as CreatePhantomConfig, e as Phantom, P as Plugin, c as createEthereumPlugin, g as createExtensionPlugin, f as createPhantom, i as isPhantomExtensionInstalled } from './index-2f448acb.js';
|