@phantom/browser-injected-sdk 1.0.0 → 1.0.3
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/dist/auto-confirm/index.d.ts +2 -1
- package/dist/{chunk-MDTCVDFZ.mjs → chunk-JJH6SEIK.mjs} +231 -57
- package/dist/ethereum/index.d.ts +2 -1
- package/dist/ethereum/index.js +234 -59
- package/dist/ethereum/index.mjs +5 -3
- package/dist/index-673af1e4.d.ts +93 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +232 -57
- package/dist/index.mjs +4 -2
- package/dist/solana/index.d.ts +5 -94
- package/dist/solana/index.js +93 -60
- package/dist/solana/index.mjs +93 -60
- package/package.json +6 -3
- package/dist/index-3a750f13.d.ts +0 -208
package/dist/solana/index.js
CHANGED
|
@@ -212,28 +212,26 @@ function addEventListener(event, callback) {
|
|
|
212
212
|
if (!eventCallbacks.has(event)) {
|
|
213
213
|
eventCallbacks.set(event, /* @__PURE__ */ new Set());
|
|
214
214
|
}
|
|
215
|
-
eventCallbacks.get(event)
|
|
215
|
+
eventCallbacks.get(event)?.add(callback);
|
|
216
216
|
return () => {
|
|
217
217
|
removeEventListener(event, callback);
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
function removeEventListener(event, callback) {
|
|
221
221
|
if (eventCallbacks.has(event)) {
|
|
222
|
-
eventCallbacks.get(event)
|
|
223
|
-
if (eventCallbacks.get(event)
|
|
222
|
+
eventCallbacks.get(event)?.delete(callback);
|
|
223
|
+
if (eventCallbacks.get(event)?.size === 0) {
|
|
224
224
|
eventCallbacks.delete(event);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
function triggerEvent(event, ...args) {
|
|
229
229
|
if (eventCallbacks.has(event)) {
|
|
230
|
-
eventCallbacks.get(event)
|
|
231
|
-
|
|
232
|
-
cb(args
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
} else if (event === "accountChanged" && args[0] && typeof args[0] === "string") {
|
|
236
|
-
cb(args[0]);
|
|
230
|
+
eventCallbacks.get(event)?.forEach((cb) => {
|
|
231
|
+
try {
|
|
232
|
+
cb(...args);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
237
235
|
}
|
|
238
236
|
});
|
|
239
237
|
}
|
|
@@ -280,12 +278,6 @@ async function disconnect() {
|
|
|
280
278
|
triggerEvent("disconnect");
|
|
281
279
|
}
|
|
282
280
|
|
|
283
|
-
// src/solana/getAccount.ts
|
|
284
|
-
async function getAccount() {
|
|
285
|
-
const provider = await getProvider();
|
|
286
|
-
return provider.getAccount();
|
|
287
|
-
}
|
|
288
|
-
|
|
289
281
|
// src/solana/signAndSendTransaction.ts
|
|
290
282
|
async function signAndSendTransaction(transaction) {
|
|
291
283
|
const provider = await getProvider();
|
|
@@ -334,19 +326,6 @@ async function signAllTransactions(transactions) {
|
|
|
334
326
|
return provider.signAllTransactions(transactions);
|
|
335
327
|
}
|
|
336
328
|
|
|
337
|
-
// src/solana/signIn.ts
|
|
338
|
-
async function signIn(signInData) {
|
|
339
|
-
const provider = await getProvider();
|
|
340
|
-
if (!provider) {
|
|
341
|
-
throw new Error("Provider not found.");
|
|
342
|
-
}
|
|
343
|
-
const result = await provider.signIn(signInData);
|
|
344
|
-
if (result.address) {
|
|
345
|
-
triggerEvent("connect", result.address);
|
|
346
|
-
}
|
|
347
|
-
return result;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
329
|
// src/solana/signMessage.ts
|
|
351
330
|
async function signMessage(message, display) {
|
|
352
331
|
const provider = await getProvider();
|
|
@@ -360,43 +339,97 @@ async function signMessage(message, display) {
|
|
|
360
339
|
}
|
|
361
340
|
|
|
362
341
|
// src/solana/plugin.ts
|
|
363
|
-
var
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const strategy = await getProvider();
|
|
379
|
-
const provider = strategy.getProvider();
|
|
380
|
-
if (provider) {
|
|
381
|
-
provider.on("connect", (publicKey) => {
|
|
382
|
-
if (publicKey)
|
|
383
|
-
triggerEvent("connect", publicKey.toString());
|
|
384
|
-
});
|
|
385
|
-
provider.on("disconnect", () => triggerEvent("disconnect"));
|
|
386
|
-
provider.on("accountChanged", (publicKey) => {
|
|
387
|
-
if (publicKey)
|
|
388
|
-
triggerEvent("accountChanged", publicKey.toString());
|
|
389
|
-
});
|
|
342
|
+
var Solana = class {
|
|
343
|
+
constructor() {
|
|
344
|
+
this._publicKey = null;
|
|
345
|
+
this.bindProviderEvents();
|
|
346
|
+
}
|
|
347
|
+
get publicKey() {
|
|
348
|
+
return this._publicKey;
|
|
349
|
+
}
|
|
350
|
+
get isConnected() {
|
|
351
|
+
return this._publicKey !== null;
|
|
352
|
+
}
|
|
353
|
+
async connect(options) {
|
|
354
|
+
const address = await connect(options);
|
|
355
|
+
if (!address) {
|
|
356
|
+
throw new Error("Failed to connect to Solana wallet");
|
|
390
357
|
}
|
|
391
|
-
|
|
358
|
+
this._publicKey = address;
|
|
359
|
+
return { publicKey: address };
|
|
392
360
|
}
|
|
393
|
-
|
|
361
|
+
async disconnect() {
|
|
362
|
+
await disconnect();
|
|
363
|
+
this._publicKey = null;
|
|
364
|
+
}
|
|
365
|
+
async signMessage(message) {
|
|
366
|
+
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
367
|
+
const result = await signMessage(messageBytes);
|
|
368
|
+
return {
|
|
369
|
+
signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(result.signature),
|
|
370
|
+
publicKey: result.address || this._publicKey || ""
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
signTransaction(transaction) {
|
|
374
|
+
return signTransaction(transaction);
|
|
375
|
+
}
|
|
376
|
+
async signAndSendTransaction(transaction) {
|
|
377
|
+
const result = await signAndSendTransaction(transaction);
|
|
378
|
+
return { signature: result.signature };
|
|
379
|
+
}
|
|
380
|
+
signAllTransactions(transactions) {
|
|
381
|
+
return signAllTransactions(transactions);
|
|
382
|
+
}
|
|
383
|
+
async signAndSendAllTransactions(transactions) {
|
|
384
|
+
const result = await signAndSendAllTransactions(transactions);
|
|
385
|
+
return { signatures: result.signatures };
|
|
386
|
+
}
|
|
387
|
+
async switchNetwork(_network) {
|
|
388
|
+
return Promise.resolve();
|
|
389
|
+
}
|
|
390
|
+
on(event, listener) {
|
|
391
|
+
addEventListener(event, listener);
|
|
392
|
+
}
|
|
393
|
+
off(event, listener) {
|
|
394
|
+
removeEventListener(event, listener);
|
|
395
|
+
}
|
|
396
|
+
async bindProviderEvents() {
|
|
397
|
+
try {
|
|
398
|
+
const strategy = await getProvider();
|
|
399
|
+
const provider = strategy.getProvider();
|
|
400
|
+
if (provider) {
|
|
401
|
+
provider.on("connect", (publicKey) => {
|
|
402
|
+
if (publicKey) {
|
|
403
|
+
const pubKey = publicKey.toString();
|
|
404
|
+
this._publicKey = pubKey;
|
|
405
|
+
triggerEvent("connect", pubKey);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
provider.on("disconnect", () => {
|
|
409
|
+
this._publicKey = null;
|
|
410
|
+
triggerEvent("disconnect");
|
|
411
|
+
});
|
|
412
|
+
provider.on("accountChanged", (publicKey) => {
|
|
413
|
+
if (publicKey) {
|
|
414
|
+
const pubKey = publicKey.toString();
|
|
415
|
+
this._publicKey = pubKey;
|
|
416
|
+
triggerEvent("accountChanged", pubKey);
|
|
417
|
+
triggerEvent("connect", pubKey);
|
|
418
|
+
} else {
|
|
419
|
+
this._publicKey = null;
|
|
420
|
+
triggerEvent("accountChanged", null);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
} catch (error) {
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
394
428
|
function createSolanaPlugin() {
|
|
395
429
|
return {
|
|
396
430
|
name: "solana",
|
|
397
431
|
create: () => {
|
|
398
|
-
|
|
399
|
-
return solana;
|
|
432
|
+
return new Solana();
|
|
400
433
|
}
|
|
401
434
|
};
|
|
402
435
|
}
|
package/dist/solana/index.mjs
CHANGED
|
@@ -179,28 +179,26 @@ function addEventListener(event, callback) {
|
|
|
179
179
|
if (!eventCallbacks.has(event)) {
|
|
180
180
|
eventCallbacks.set(event, /* @__PURE__ */ new Set());
|
|
181
181
|
}
|
|
182
|
-
eventCallbacks.get(event)
|
|
182
|
+
eventCallbacks.get(event)?.add(callback);
|
|
183
183
|
return () => {
|
|
184
184
|
removeEventListener(event, callback);
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
function removeEventListener(event, callback) {
|
|
188
188
|
if (eventCallbacks.has(event)) {
|
|
189
|
-
eventCallbacks.get(event)
|
|
190
|
-
if (eventCallbacks.get(event)
|
|
189
|
+
eventCallbacks.get(event)?.delete(callback);
|
|
190
|
+
if (eventCallbacks.get(event)?.size === 0) {
|
|
191
191
|
eventCallbacks.delete(event);
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
function triggerEvent(event, ...args) {
|
|
196
196
|
if (eventCallbacks.has(event)) {
|
|
197
|
-
eventCallbacks.get(event)
|
|
198
|
-
|
|
199
|
-
cb(args
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
} else if (event === "accountChanged" && args[0] && typeof args[0] === "string") {
|
|
203
|
-
cb(args[0]);
|
|
197
|
+
eventCallbacks.get(event)?.forEach((cb) => {
|
|
198
|
+
try {
|
|
199
|
+
cb(...args);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error(`Error in ${event} event listener:`, error);
|
|
204
202
|
}
|
|
205
203
|
});
|
|
206
204
|
}
|
|
@@ -247,12 +245,6 @@ async function disconnect() {
|
|
|
247
245
|
triggerEvent("disconnect");
|
|
248
246
|
}
|
|
249
247
|
|
|
250
|
-
// src/solana/getAccount.ts
|
|
251
|
-
async function getAccount() {
|
|
252
|
-
const provider = await getProvider();
|
|
253
|
-
return provider.getAccount();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
248
|
// src/solana/signAndSendTransaction.ts
|
|
257
249
|
async function signAndSendTransaction(transaction) {
|
|
258
250
|
const provider = await getProvider();
|
|
@@ -301,19 +293,6 @@ async function signAllTransactions(transactions) {
|
|
|
301
293
|
return provider.signAllTransactions(transactions);
|
|
302
294
|
}
|
|
303
295
|
|
|
304
|
-
// src/solana/signIn.ts
|
|
305
|
-
async function signIn(signInData) {
|
|
306
|
-
const provider = await getProvider();
|
|
307
|
-
if (!provider) {
|
|
308
|
-
throw new Error("Provider not found.");
|
|
309
|
-
}
|
|
310
|
-
const result = await provider.signIn(signInData);
|
|
311
|
-
if (result.address) {
|
|
312
|
-
triggerEvent("connect", result.address);
|
|
313
|
-
}
|
|
314
|
-
return result;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
296
|
// src/solana/signMessage.ts
|
|
318
297
|
async function signMessage(message, display) {
|
|
319
298
|
const provider = await getProvider();
|
|
@@ -327,43 +306,97 @@ async function signMessage(message, display) {
|
|
|
327
306
|
}
|
|
328
307
|
|
|
329
308
|
// src/solana/plugin.ts
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const strategy = await getProvider();
|
|
346
|
-
const provider = strategy.getProvider();
|
|
347
|
-
if (provider) {
|
|
348
|
-
provider.on("connect", (publicKey) => {
|
|
349
|
-
if (publicKey)
|
|
350
|
-
triggerEvent("connect", publicKey.toString());
|
|
351
|
-
});
|
|
352
|
-
provider.on("disconnect", () => triggerEvent("disconnect"));
|
|
353
|
-
provider.on("accountChanged", (publicKey) => {
|
|
354
|
-
if (publicKey)
|
|
355
|
-
triggerEvent("accountChanged", publicKey.toString());
|
|
356
|
-
});
|
|
309
|
+
var Solana = class {
|
|
310
|
+
constructor() {
|
|
311
|
+
this._publicKey = null;
|
|
312
|
+
this.bindProviderEvents();
|
|
313
|
+
}
|
|
314
|
+
get publicKey() {
|
|
315
|
+
return this._publicKey;
|
|
316
|
+
}
|
|
317
|
+
get isConnected() {
|
|
318
|
+
return this._publicKey !== null;
|
|
319
|
+
}
|
|
320
|
+
async connect(options) {
|
|
321
|
+
const address = await connect(options);
|
|
322
|
+
if (!address) {
|
|
323
|
+
throw new Error("Failed to connect to Solana wallet");
|
|
357
324
|
}
|
|
358
|
-
|
|
325
|
+
this._publicKey = address;
|
|
326
|
+
return { publicKey: address };
|
|
359
327
|
}
|
|
360
|
-
|
|
328
|
+
async disconnect() {
|
|
329
|
+
await disconnect();
|
|
330
|
+
this._publicKey = null;
|
|
331
|
+
}
|
|
332
|
+
async signMessage(message) {
|
|
333
|
+
const messageBytes = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
334
|
+
const result = await signMessage(messageBytes);
|
|
335
|
+
return {
|
|
336
|
+
signature: result.signature instanceof Uint8Array ? result.signature : new Uint8Array(result.signature),
|
|
337
|
+
publicKey: result.address || this._publicKey || ""
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
signTransaction(transaction) {
|
|
341
|
+
return signTransaction(transaction);
|
|
342
|
+
}
|
|
343
|
+
async signAndSendTransaction(transaction) {
|
|
344
|
+
const result = await signAndSendTransaction(transaction);
|
|
345
|
+
return { signature: result.signature };
|
|
346
|
+
}
|
|
347
|
+
signAllTransactions(transactions) {
|
|
348
|
+
return signAllTransactions(transactions);
|
|
349
|
+
}
|
|
350
|
+
async signAndSendAllTransactions(transactions) {
|
|
351
|
+
const result = await signAndSendAllTransactions(transactions);
|
|
352
|
+
return { signatures: result.signatures };
|
|
353
|
+
}
|
|
354
|
+
async switchNetwork(_network) {
|
|
355
|
+
return Promise.resolve();
|
|
356
|
+
}
|
|
357
|
+
on(event, listener) {
|
|
358
|
+
addEventListener(event, listener);
|
|
359
|
+
}
|
|
360
|
+
off(event, listener) {
|
|
361
|
+
removeEventListener(event, listener);
|
|
362
|
+
}
|
|
363
|
+
async bindProviderEvents() {
|
|
364
|
+
try {
|
|
365
|
+
const strategy = await getProvider();
|
|
366
|
+
const provider = strategy.getProvider();
|
|
367
|
+
if (provider) {
|
|
368
|
+
provider.on("connect", (publicKey) => {
|
|
369
|
+
if (publicKey) {
|
|
370
|
+
const pubKey = publicKey.toString();
|
|
371
|
+
this._publicKey = pubKey;
|
|
372
|
+
triggerEvent("connect", pubKey);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
provider.on("disconnect", () => {
|
|
376
|
+
this._publicKey = null;
|
|
377
|
+
triggerEvent("disconnect");
|
|
378
|
+
});
|
|
379
|
+
provider.on("accountChanged", (publicKey) => {
|
|
380
|
+
if (publicKey) {
|
|
381
|
+
const pubKey = publicKey.toString();
|
|
382
|
+
this._publicKey = pubKey;
|
|
383
|
+
triggerEvent("accountChanged", pubKey);
|
|
384
|
+
triggerEvent("connect", pubKey);
|
|
385
|
+
} else {
|
|
386
|
+
this._publicKey = null;
|
|
387
|
+
triggerEvent("accountChanged", null);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
} catch (error) {
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
361
395
|
function createSolanaPlugin() {
|
|
362
396
|
return {
|
|
363
397
|
name: "solana",
|
|
364
398
|
create: () => {
|
|
365
|
-
|
|
366
|
-
return solana;
|
|
399
|
+
return new Solana();
|
|
367
400
|
}
|
|
368
401
|
};
|
|
369
402
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/browser-injected-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/phantom/phantom-connect-sdk",
|
|
@@ -47,13 +47,16 @@
|
|
|
47
47
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@phantom/
|
|
51
|
-
"@phantom/
|
|
50
|
+
"@phantom/chain-interfaces": "^1.0.3",
|
|
51
|
+
"@phantom/constants": "^1.0.3",
|
|
52
|
+
"@phantom/sdk-types": "^1.0.3"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
55
|
+
"@jest/fake-timers": "^29.7.0",
|
|
54
56
|
"@types/jest": "^29.5.14",
|
|
55
57
|
"eslint": "8.53.0",
|
|
56
58
|
"jest": "^29.7.0",
|
|
59
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
57
60
|
"prettier": "^3.5.2",
|
|
58
61
|
"rimraf": "^6.0.1",
|
|
59
62
|
"tsup": "^6.7.0",
|
package/dist/index-3a750f13.d.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
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({ onlyIfTrusted }?: {
|
|
15
|
-
onlyIfTrusted?: boolean | undefined;
|
|
16
|
-
}): Promise<string[]>;
|
|
17
|
-
|
|
18
|
-
declare function disconnect(): Promise<void>;
|
|
19
|
-
|
|
20
|
-
type EthereumTransaction = {
|
|
21
|
-
to?: string;
|
|
22
|
-
from?: string;
|
|
23
|
-
value?: string;
|
|
24
|
-
gas?: string;
|
|
25
|
-
gasPrice?: string;
|
|
26
|
-
maxFeePerGas?: string;
|
|
27
|
-
maxPriorityFeePerGas?: string;
|
|
28
|
-
data?: string;
|
|
29
|
-
nonce?: string;
|
|
30
|
-
type?: string;
|
|
31
|
-
chainId?: string;
|
|
32
|
-
};
|
|
33
|
-
type EthereumSignInData = {
|
|
34
|
-
domain?: string;
|
|
35
|
-
address?: string;
|
|
36
|
-
statement?: string;
|
|
37
|
-
uri?: string;
|
|
38
|
-
version?: string;
|
|
39
|
-
chainId?: string;
|
|
40
|
-
nonce?: string;
|
|
41
|
-
issuedAt?: string;
|
|
42
|
-
expirationTime?: string;
|
|
43
|
-
notBefore?: string;
|
|
44
|
-
requestId?: string;
|
|
45
|
-
resources?: string[];
|
|
46
|
-
};
|
|
47
|
-
type EthereumEventType = "connect" | "disconnect" | "accountsChanged" | "chainChanged";
|
|
48
|
-
interface PhantomEthereumProvider {
|
|
49
|
-
isPhantom: boolean;
|
|
50
|
-
selectedAddress: string | null;
|
|
51
|
-
chainId: string;
|
|
52
|
-
isConnected: boolean;
|
|
53
|
-
request: (args: {
|
|
54
|
-
method: string;
|
|
55
|
-
params?: any[];
|
|
56
|
-
}) => Promise<any>;
|
|
57
|
-
on: (event: EthereumEventType, handler: (...args: any[]) => void) => void;
|
|
58
|
-
off: (event: EthereumEventType, handler: (...args: any[]) => void) => void;
|
|
59
|
-
removeAllListeners: (event?: EthereumEventType) => void;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type PhantomEthereumEventCallback = (data: any) => void;
|
|
63
|
-
|
|
64
|
-
declare function getAccounts(): Promise<string[]>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Signs a message using the Phantom Ethereum provider.
|
|
68
|
-
* @param message The message to sign (as a string).
|
|
69
|
-
* @param address The address to sign with.
|
|
70
|
-
* @returns A promise that resolves with the signature.
|
|
71
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
72
|
-
*/
|
|
73
|
-
declare function signMessage(message: string, address: string): Promise<string>;
|
|
74
|
-
/**
|
|
75
|
-
* Signs a personal message using the Phantom Ethereum provider.
|
|
76
|
-
* @param message The message to sign (as a string).
|
|
77
|
-
* @param address The address to sign with.
|
|
78
|
-
* @returns A promise that resolves with the signature.
|
|
79
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
80
|
-
*/
|
|
81
|
-
declare function signPersonalMessage(message: string, address: string): Promise<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Signs typed data using the Phantom Ethereum provider.
|
|
84
|
-
* @param typedData The typed data to sign.
|
|
85
|
-
* @param address The address to sign with.
|
|
86
|
-
* @returns A promise that resolves with the signature.
|
|
87
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
88
|
-
*/
|
|
89
|
-
declare function signTypedData(typedData: any, address: string): Promise<string>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Signs in using the Phantom Ethereum provider.
|
|
93
|
-
* @param signInData The sign-in data.
|
|
94
|
-
* @returns A promise that resolves with the signature data.
|
|
95
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
96
|
-
*/
|
|
97
|
-
declare function signIn(signInData: EthereumSignInData): Promise<{
|
|
98
|
-
address: string;
|
|
99
|
-
signature: string;
|
|
100
|
-
signedMessage: string;
|
|
101
|
-
}>;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Sends a transaction using the Phantom Ethereum provider.
|
|
105
|
-
* @param transaction The transaction to send.
|
|
106
|
-
* @returns A promise that resolves with the transaction hash.
|
|
107
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
108
|
-
*/
|
|
109
|
-
declare function sendTransaction(transaction: EthereumTransaction): Promise<string>;
|
|
110
|
-
/**
|
|
111
|
-
* Signs a transaction using the Phantom Ethereum provider.
|
|
112
|
-
* @param transaction The transaction to sign.
|
|
113
|
-
* @returns A promise that resolves with the signed transaction.
|
|
114
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
115
|
-
*/
|
|
116
|
-
declare function signTransaction(transaction: EthereumTransaction): Promise<string>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Gets the current chain ID.
|
|
120
|
-
* @returns A promise that resolves with the chain ID.
|
|
121
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
122
|
-
*/
|
|
123
|
-
declare function getChainId(): Promise<string>;
|
|
124
|
-
/**
|
|
125
|
-
* Switches to a different chain.
|
|
126
|
-
* @param chainId The chain ID to switch to.
|
|
127
|
-
* @returns A promise that resolves when the switch is complete.
|
|
128
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
129
|
-
*/
|
|
130
|
-
declare function switchChain(chainId: string): Promise<void>;
|
|
131
|
-
|
|
132
|
-
declare enum ProviderStrategy {
|
|
133
|
-
INJECTED = "injected"
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
interface EthereumStrategy {
|
|
137
|
-
readonly type: ProviderStrategy;
|
|
138
|
-
isConnected: boolean;
|
|
139
|
-
getProvider: () => PhantomEthereumProvider | null;
|
|
140
|
-
connect: ({ onlyIfTrusted }: {
|
|
141
|
-
onlyIfTrusted: boolean;
|
|
142
|
-
}) => Promise<string[] | undefined>;
|
|
143
|
-
disconnect: () => Promise<void>;
|
|
144
|
-
getAccounts: () => Promise<string[]>;
|
|
145
|
-
signMessage: (message: string, address: string) => Promise<string>;
|
|
146
|
-
signPersonalMessage: (message: string, address: string) => Promise<string>;
|
|
147
|
-
signTypedData: (typedData: any, address: string) => Promise<string>;
|
|
148
|
-
signIn: (signInData: EthereumSignInData) => Promise<{
|
|
149
|
-
address: string;
|
|
150
|
-
signature: string;
|
|
151
|
-
signedMessage: string;
|
|
152
|
-
}>;
|
|
153
|
-
sendTransaction: (transaction: EthereumTransaction) => Promise<string>;
|
|
154
|
-
signTransaction: (transaction: EthereumTransaction) => Promise<string>;
|
|
155
|
-
getChainId: () => Promise<string>;
|
|
156
|
-
switchChain: (chainId: string) => Promise<void>;
|
|
157
|
-
request: <T = any>(args: {
|
|
158
|
-
method: string;
|
|
159
|
-
params?: unknown[];
|
|
160
|
-
}) => Promise<T>;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Retrieves Phantom Ethereum provider and returns it if it exists.
|
|
165
|
-
* @returns Phantom Ethereum provider or throws error if it doesn't exist.
|
|
166
|
-
*/
|
|
167
|
-
declare function getProvider(strategy?: ProviderStrategy): Promise<EthereumStrategy>;
|
|
168
|
-
|
|
169
|
-
type Ethereum = {
|
|
170
|
-
connect: typeof connect;
|
|
171
|
-
disconnect: typeof disconnect;
|
|
172
|
-
getAccounts: typeof getAccounts;
|
|
173
|
-
signMessage: typeof signMessage;
|
|
174
|
-
signPersonalMessage: typeof signPersonalMessage;
|
|
175
|
-
signTypedData: typeof signTypedData;
|
|
176
|
-
signIn: typeof signIn;
|
|
177
|
-
sendTransaction: typeof sendTransaction;
|
|
178
|
-
signTransaction: typeof signTransaction;
|
|
179
|
-
getChainId: typeof getChainId;
|
|
180
|
-
switchChain: typeof switchChain;
|
|
181
|
-
getProvider: typeof getProvider;
|
|
182
|
-
addEventListener: (event: EthereumEventType, callback: PhantomEthereumEventCallback) => () => void;
|
|
183
|
-
removeEventListener: (event: EthereumEventType, callback: PhantomEthereumEventCallback) => void;
|
|
184
|
-
};
|
|
185
|
-
declare function createEthereumPlugin(): Plugin<Ethereum>;
|
|
186
|
-
|
|
187
|
-
declare module "../index" {
|
|
188
|
-
interface Phantom {
|
|
189
|
-
ethereum: Ethereum;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
type Plugin<T> = {
|
|
194
|
-
name: string;
|
|
195
|
-
create: () => T;
|
|
196
|
-
};
|
|
197
|
-
type CreatePhantomConfig = {
|
|
198
|
-
plugins?: Plugin<unknown>[];
|
|
199
|
-
};
|
|
200
|
-
interface Phantom {
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Creates a Phantom instance with the provided plugins.
|
|
204
|
-
* Each plugin extends the Phantom interface via declaration merging.
|
|
205
|
-
*/
|
|
206
|
-
declare function createPhantom({ plugins }: CreatePhantomConfig): Phantom;
|
|
207
|
-
|
|
208
|
-
export { CreatePhantomConfig as C, Ethereum as E, Plugin as P, PhantomEthereumProvider as a, EthereumTransaction as b, createEthereumPlugin as c, EthereumSignInData as d, EthereumEventType as e, Phantom as f, createPhantom as g, createExtensionPlugin as h, Extension as i, isInstalled as j };
|