@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/ethereum/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createEthereumPlugin
|
|
3
|
-
|
|
2
|
+
createEthereumPlugin,
|
|
3
|
+
createSiweMessage
|
|
4
|
+
} from "../chunk-JJH6SEIK.mjs";
|
|
4
5
|
import "../chunk-WUKYLWAZ.mjs";
|
|
5
6
|
import "../chunk-GV6AIHPN.mjs";
|
|
6
7
|
export {
|
|
7
|
-
createEthereumPlugin
|
|
8
|
+
createEthereumPlugin,
|
|
9
|
+
createSiweMessage
|
|
8
10
|
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { IEthereumChain } from '@phantom/chain-interfaces';
|
|
2
|
+
|
|
3
|
+
declare function isInstalled(): boolean;
|
|
4
|
+
|
|
5
|
+
type Extension = {
|
|
6
|
+
isInstalled: typeof isInstalled;
|
|
7
|
+
};
|
|
8
|
+
declare function createExtensionPlugin(): Plugin<Extension>;
|
|
9
|
+
|
|
10
|
+
declare module "../index" {
|
|
11
|
+
interface Phantom {
|
|
12
|
+
extension: Extension;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type EthereumTransaction = {
|
|
17
|
+
to?: string;
|
|
18
|
+
from?: string;
|
|
19
|
+
value?: string;
|
|
20
|
+
gas?: string;
|
|
21
|
+
gasPrice?: string;
|
|
22
|
+
maxFeePerGas?: string;
|
|
23
|
+
maxPriorityFeePerGas?: string;
|
|
24
|
+
data?: string;
|
|
25
|
+
nonce?: string;
|
|
26
|
+
type?: string;
|
|
27
|
+
chainId?: string;
|
|
28
|
+
};
|
|
29
|
+
type EthereumSignInData = {
|
|
30
|
+
address: `0x${string}`;
|
|
31
|
+
chainId: number;
|
|
32
|
+
domain: string;
|
|
33
|
+
expirationTime?: Date | undefined;
|
|
34
|
+
issuedAt?: Date | undefined;
|
|
35
|
+
nonce: string;
|
|
36
|
+
notBefore?: Date | undefined;
|
|
37
|
+
requestId?: string | undefined;
|
|
38
|
+
resources?: Array<string> | undefined;
|
|
39
|
+
scheme?: string | undefined;
|
|
40
|
+
statement?: string | undefined;
|
|
41
|
+
uri: string;
|
|
42
|
+
version: "1";
|
|
43
|
+
};
|
|
44
|
+
type EthereumEventType = "connect" | "disconnect" | "accountsChanged" | "chainChanged";
|
|
45
|
+
interface PhantomEthereumProvider {
|
|
46
|
+
isPhantom: boolean;
|
|
47
|
+
selectedAddress: string | null;
|
|
48
|
+
chainId: string;
|
|
49
|
+
isConnected: boolean;
|
|
50
|
+
request: <T = any>(args: {
|
|
51
|
+
method: string;
|
|
52
|
+
params?: any[];
|
|
53
|
+
}) => Promise<T>;
|
|
54
|
+
on: (event: EthereumEventType, handler: (...args: any[]) => void) => void;
|
|
55
|
+
off: (event: EthereumEventType, handler: (...args: any[]) => void) => void;
|
|
56
|
+
removeAllListeners: (event?: EthereumEventType) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare function createEthereumPlugin(): Plugin<IEthereumChain>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates an EIP-4361 Sign In With Ethereum message.
|
|
63
|
+
*
|
|
64
|
+
* Adapted from viem's createSiweMessage implementation:
|
|
65
|
+
* https://github.com/wevm/viem/blob/53d302049e166706fecde453ea984284dd180ca6/src/utils/siwe/createSiweMessage.ts
|
|
66
|
+
*
|
|
67
|
+
* Copyright (c) 2023-present weth, LLC
|
|
68
|
+
* Licensed under the MIT License.
|
|
69
|
+
*/
|
|
70
|
+
declare function createSiweMessage({ address, chainId, domain, nonce, uri, version, scheme, statement: _statement, requestId, resources, issuedAt, expirationTime, notBefore, }: EthereumSignInData): string;
|
|
71
|
+
|
|
72
|
+
declare module "../index" {
|
|
73
|
+
interface Phantom {
|
|
74
|
+
ethereum: IEthereumChain;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type Plugin<T> = {
|
|
79
|
+
name: string;
|
|
80
|
+
create: () => T;
|
|
81
|
+
};
|
|
82
|
+
type CreatePhantomConfig = {
|
|
83
|
+
plugins?: Plugin<unknown>[];
|
|
84
|
+
};
|
|
85
|
+
interface Phantom {
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates a Phantom instance with the provided plugins.
|
|
89
|
+
* Each plugin extends the Phantom interface via declaration merging.
|
|
90
|
+
*/
|
|
91
|
+
declare function createPhantom({ plugins }: CreatePhantomConfig): Phantom;
|
|
92
|
+
|
|
93
|
+
export { CreatePhantomConfig as C, EthereumTransaction as E, Plugin as P, createSiweMessage as a, PhantomEthereumProvider 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { C as CreatePhantomConfig, i as Extension, f as Phantom, P as Plugin, c as createEthereumPlugin, h as createExtensionPlugin, g as createPhantom, j as isPhantomExtensionInstalled } from './index-
|
|
1
|
+
export { C as CreatePhantomConfig, i as Extension, f as Phantom, P as Plugin, c as createEthereumPlugin, h as createExtensionPlugin, g as createPhantom, a as createSiweMessage, j as isPhantomExtensionInstalled } from './index-673af1e4.js';
|
|
2
|
+
import '@phantom/chain-interfaces';
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(src_exports, {
|
|
|
36
36
|
createEthereumPlugin: () => createEthereumPlugin,
|
|
37
37
|
createExtensionPlugin: () => createExtensionPlugin,
|
|
38
38
|
createPhantom: () => createPhantom,
|
|
39
|
+
createSiweMessage: () => createSiweMessage,
|
|
39
40
|
isPhantomExtensionInstalled: () => isInstalled
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -61,6 +62,129 @@ function createExtensionPlugin() {
|
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
// src/ethereum/siwe.ts
|
|
66
|
+
var ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
67
|
+
var DOMAIN_REGEX = /^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/;
|
|
68
|
+
var IP_REGEX = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/;
|
|
69
|
+
var LOCALHOST_REGEX = /^localhost(:[0-9]{1,5})?$/;
|
|
70
|
+
var NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
|
|
71
|
+
var SCHEME_REGEX = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
|
|
72
|
+
function createSiweMessage({
|
|
73
|
+
address,
|
|
74
|
+
chainId,
|
|
75
|
+
domain,
|
|
76
|
+
nonce,
|
|
77
|
+
uri,
|
|
78
|
+
version,
|
|
79
|
+
scheme,
|
|
80
|
+
statement: _statement,
|
|
81
|
+
requestId,
|
|
82
|
+
resources,
|
|
83
|
+
issuedAt = /* @__PURE__ */ new Date(),
|
|
84
|
+
expirationTime,
|
|
85
|
+
notBefore
|
|
86
|
+
}) {
|
|
87
|
+
if (!ADDRESS_REGEX.test(address)) {
|
|
88
|
+
throw new Error("address must be a hex value of 20 bytes (40 hex characters).");
|
|
89
|
+
}
|
|
90
|
+
if (chainId !== Math.floor(chainId)) {
|
|
91
|
+
throw new Error("chainId must be a EIP-155 chain ID.");
|
|
92
|
+
}
|
|
93
|
+
if (!(DOMAIN_REGEX.test(domain) || IP_REGEX.test(domain) || LOCALHOST_REGEX.test(domain))) {
|
|
94
|
+
throw new Error("domain must be an RFC 3986 authority.");
|
|
95
|
+
}
|
|
96
|
+
if (!NONCE_REGEX.test(nonce)) {
|
|
97
|
+
throw new Error("nonce must be at least 8 characters.");
|
|
98
|
+
}
|
|
99
|
+
if (!_isUri(uri)) {
|
|
100
|
+
throw new Error("uri must be a RFC 3986 URI referring to the resource that is the subject of the signing.");
|
|
101
|
+
}
|
|
102
|
+
if (version !== "1") {
|
|
103
|
+
throw new Error("version must be '1'.");
|
|
104
|
+
}
|
|
105
|
+
if (scheme && !SCHEME_REGEX.test(scheme)) {
|
|
106
|
+
throw new Error("scheme must be an RFC 3986 URI scheme.");
|
|
107
|
+
}
|
|
108
|
+
if (_statement?.includes("\n")) {
|
|
109
|
+
throw new Error("statement must not include '\\n'.");
|
|
110
|
+
}
|
|
111
|
+
const origin = scheme ? `${scheme}://${domain}` : domain;
|
|
112
|
+
const statement = _statement ? `${_statement}
|
|
113
|
+
` : "";
|
|
114
|
+
const prefix = `${origin} wants you to sign in with your Ethereum account:
|
|
115
|
+
${address}
|
|
116
|
+
|
|
117
|
+
${statement}`;
|
|
118
|
+
let suffix = `URI: ${uri}
|
|
119
|
+
Version: ${version}
|
|
120
|
+
Chain ID: ${chainId}
|
|
121
|
+
Nonce: ${nonce}
|
|
122
|
+
Issued At: ${issuedAt.toISOString()}`;
|
|
123
|
+
if (expirationTime) {
|
|
124
|
+
suffix += `
|
|
125
|
+
Expiration Time: ${expirationTime.toISOString()}`;
|
|
126
|
+
}
|
|
127
|
+
if (notBefore) {
|
|
128
|
+
suffix += `
|
|
129
|
+
Not Before: ${notBefore.toISOString()}`;
|
|
130
|
+
}
|
|
131
|
+
if (requestId) {
|
|
132
|
+
suffix += `
|
|
133
|
+
Request ID: ${requestId}`;
|
|
134
|
+
}
|
|
135
|
+
if (resources) {
|
|
136
|
+
let content = "\nResources:";
|
|
137
|
+
for (const resource of resources) {
|
|
138
|
+
if (!_isUri(resource)) {
|
|
139
|
+
throw new Error("resources must be RFC 3986 URIs.");
|
|
140
|
+
}
|
|
141
|
+
content += `
|
|
142
|
+
- ${resource}`;
|
|
143
|
+
}
|
|
144
|
+
suffix += content;
|
|
145
|
+
}
|
|
146
|
+
return `${prefix}
|
|
147
|
+
${suffix}`;
|
|
148
|
+
}
|
|
149
|
+
function _isUri(value) {
|
|
150
|
+
if (/[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i.test(value))
|
|
151
|
+
return false;
|
|
152
|
+
if (/%[^0-9a-f]/i.test(value))
|
|
153
|
+
return false;
|
|
154
|
+
if (/%[0-9a-f](:?[^0-9a-f]|$)/i.test(value))
|
|
155
|
+
return false;
|
|
156
|
+
const splitted = splitUri(value);
|
|
157
|
+
const scheme = splitted[1];
|
|
158
|
+
const authority = splitted[2];
|
|
159
|
+
const path = splitted[3];
|
|
160
|
+
const query = splitted[4];
|
|
161
|
+
const fragment = splitted[5];
|
|
162
|
+
if (!(scheme?.length && path.length >= 0))
|
|
163
|
+
return false;
|
|
164
|
+
if (authority?.length) {
|
|
165
|
+
if (!(path.length === 0 || /^\//.test(path)))
|
|
166
|
+
return false;
|
|
167
|
+
} else {
|
|
168
|
+
if (/^\/\//.test(path))
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (!/^[a-z][a-z0-9+\-.]*$/.test(scheme.toLowerCase()))
|
|
172
|
+
return false;
|
|
173
|
+
let out = "";
|
|
174
|
+
out += `${scheme}:`;
|
|
175
|
+
if (authority?.length)
|
|
176
|
+
out += `//${authority}`;
|
|
177
|
+
out += path;
|
|
178
|
+
if (query?.length)
|
|
179
|
+
out += `?${query}`;
|
|
180
|
+
if (fragment?.length)
|
|
181
|
+
out += `#${fragment}`;
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function splitUri(value) {
|
|
185
|
+
return value.match(/(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
|
|
186
|
+
}
|
|
187
|
+
|
|
64
188
|
// src/ethereum/strategies/injected.ts
|
|
65
189
|
var MAX_RETRIES = 4;
|
|
66
190
|
var BASE_DELAY = 100;
|
|
@@ -177,7 +301,7 @@ var InjectedEthereumStrategy = class {
|
|
|
177
301
|
if (!provider) {
|
|
178
302
|
throw new Error("Provider not found.");
|
|
179
303
|
}
|
|
180
|
-
const message =
|
|
304
|
+
const message = createSiweMessage(signInData);
|
|
181
305
|
const address = provider.selectedAddress;
|
|
182
306
|
if (!address) {
|
|
183
307
|
throw new Error("No address available.");
|
|
@@ -273,7 +397,7 @@ function addEventListener(event, callback) {
|
|
|
273
397
|
eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
274
398
|
}
|
|
275
399
|
const listeners = eventListeners.get(event);
|
|
276
|
-
listeners
|
|
400
|
+
listeners?.add(callback);
|
|
277
401
|
return () => removeEventListener(event, callback);
|
|
278
402
|
}
|
|
279
403
|
function removeEventListener(event, callback) {
|
|
@@ -347,16 +471,6 @@ async function getAccounts() {
|
|
|
347
471
|
}
|
|
348
472
|
|
|
349
473
|
// src/ethereum/signMessage.ts
|
|
350
|
-
async function signMessage(message, address) {
|
|
351
|
-
const provider = await getProvider();
|
|
352
|
-
if (!provider) {
|
|
353
|
-
throw new Error("Provider not found.");
|
|
354
|
-
}
|
|
355
|
-
if (!provider.isConnected) {
|
|
356
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
357
|
-
}
|
|
358
|
-
return provider.signMessage(message, address);
|
|
359
|
-
}
|
|
360
474
|
async function signPersonalMessage(message, address) {
|
|
361
475
|
const provider = await getProvider();
|
|
362
476
|
if (!provider) {
|
|
@@ -378,18 +492,6 @@ async function signTypedData(typedData, address) {
|
|
|
378
492
|
return provider.signTypedData(typedData, address);
|
|
379
493
|
}
|
|
380
494
|
|
|
381
|
-
// src/ethereum/signIn.ts
|
|
382
|
-
async function signIn(signInData) {
|
|
383
|
-
const provider = await getProvider();
|
|
384
|
-
if (!provider) {
|
|
385
|
-
throw new Error("Provider not found.");
|
|
386
|
-
}
|
|
387
|
-
if (!provider.isConnected) {
|
|
388
|
-
await provider.connect({ onlyIfTrusted: false });
|
|
389
|
-
}
|
|
390
|
-
return provider.signIn(signInData);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
495
|
// src/ethereum/sendTransaction.ts
|
|
394
496
|
async function sendTransaction(transaction) {
|
|
395
497
|
const provider = await getProvider();
|
|
@@ -429,47 +531,119 @@ async function switchChain(chainId) {
|
|
|
429
531
|
}
|
|
430
532
|
|
|
431
533
|
// src/ethereum/plugin.ts
|
|
432
|
-
var
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
534
|
+
var Ethereum = class {
|
|
535
|
+
constructor() {
|
|
536
|
+
this._chainId = "0x1";
|
|
537
|
+
this._accounts = [];
|
|
538
|
+
this.bindProviderEvents();
|
|
539
|
+
}
|
|
540
|
+
get chainId() {
|
|
541
|
+
return this._chainId;
|
|
542
|
+
}
|
|
543
|
+
get accounts() {
|
|
544
|
+
return this._accounts;
|
|
545
|
+
}
|
|
546
|
+
async request(args) {
|
|
547
|
+
const provider = await getProvider();
|
|
548
|
+
if (!provider) {
|
|
549
|
+
throw new Error("Provider not found.");
|
|
550
|
+
}
|
|
551
|
+
const providerInstance = provider.getProvider();
|
|
552
|
+
if (!providerInstance) {
|
|
553
|
+
throw new Error("Provider instance not found.");
|
|
554
|
+
}
|
|
555
|
+
return providerInstance.request(args);
|
|
556
|
+
}
|
|
557
|
+
async connect() {
|
|
558
|
+
const accounts = await connect();
|
|
559
|
+
this._accounts = accounts;
|
|
560
|
+
return accounts;
|
|
561
|
+
}
|
|
562
|
+
async disconnect() {
|
|
563
|
+
await disconnect();
|
|
564
|
+
this._accounts = [];
|
|
565
|
+
}
|
|
566
|
+
signPersonalMessage(message, address) {
|
|
567
|
+
return signPersonalMessage(message, address);
|
|
568
|
+
}
|
|
569
|
+
signTypedData(data, address) {
|
|
570
|
+
return signTypedData(data, address);
|
|
571
|
+
}
|
|
572
|
+
signTransaction(transaction) {
|
|
573
|
+
return signTransaction(transaction);
|
|
574
|
+
}
|
|
575
|
+
sendTransaction(transaction) {
|
|
576
|
+
return sendTransaction(transaction);
|
|
577
|
+
}
|
|
578
|
+
async switchChain(chainId) {
|
|
579
|
+
const hexChainId = typeof chainId === "string" ? chainId.toLowerCase().startsWith("0x") ? chainId.toLowerCase() : `0x${parseInt(chainId, 10).toString(16)}` : `0x${chainId.toString(16)}`;
|
|
580
|
+
await switchChain(hexChainId);
|
|
581
|
+
this._chainId = hexChainId;
|
|
582
|
+
}
|
|
583
|
+
async getChainId() {
|
|
584
|
+
const chainId = await getChainId();
|
|
585
|
+
const parsed = parseInt(chainId, 16);
|
|
586
|
+
this._chainId = chainId;
|
|
587
|
+
return parsed;
|
|
588
|
+
}
|
|
589
|
+
async getAccounts() {
|
|
590
|
+
const accounts = await getAccounts();
|
|
591
|
+
this._accounts = accounts;
|
|
592
|
+
return accounts;
|
|
593
|
+
}
|
|
594
|
+
isConnected() {
|
|
595
|
+
return this._accounts.length > 0;
|
|
596
|
+
}
|
|
597
|
+
on(event, listener) {
|
|
598
|
+
addEventListener(event, listener);
|
|
599
|
+
}
|
|
600
|
+
off(event, listener) {
|
|
601
|
+
removeEventListener(event, listener);
|
|
602
|
+
}
|
|
603
|
+
async bindProviderEvents() {
|
|
604
|
+
try {
|
|
605
|
+
const strategy = await getProvider();
|
|
606
|
+
const provider = strategy.getProvider();
|
|
607
|
+
if (provider) {
|
|
608
|
+
provider.on("connect", async () => {
|
|
609
|
+
try {
|
|
610
|
+
const accounts = await provider.request({ method: "eth_accounts" });
|
|
611
|
+
if (accounts?.length > 0) {
|
|
612
|
+
this._accounts = accounts;
|
|
613
|
+
triggerEvent("connect", accounts);
|
|
614
|
+
}
|
|
615
|
+
} catch {
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
provider.on("disconnect", () => {
|
|
619
|
+
this._accounts = [];
|
|
620
|
+
const error = {
|
|
621
|
+
code: 4900,
|
|
622
|
+
message: "Provider disconnected"
|
|
623
|
+
};
|
|
624
|
+
triggerEvent("disconnect", error);
|
|
625
|
+
});
|
|
626
|
+
provider.on("accountsChanged", (accounts) => {
|
|
627
|
+
this._accounts = accounts;
|
|
628
|
+
triggerEvent("accountsChanged", accounts);
|
|
629
|
+
if (accounts && accounts.length > 0) {
|
|
456
630
|
triggerEvent("connect", accounts);
|
|
457
|
-
|
|
631
|
+
}
|
|
458
632
|
});
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
633
|
+
provider.on("chainChanged", (chainId) => {
|
|
634
|
+
this._chainId = chainId;
|
|
635
|
+
triggerEvent("chainChanged", chainId);
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
} catch (error) {
|
|
463
639
|
}
|
|
464
|
-
} catch (error) {
|
|
465
640
|
}
|
|
466
|
-
}
|
|
641
|
+
};
|
|
467
642
|
function createEthereumPlugin() {
|
|
468
643
|
return {
|
|
469
644
|
name: "ethereum",
|
|
470
645
|
create: () => {
|
|
471
|
-
|
|
472
|
-
return ethereum;
|
|
646
|
+
return new Ethereum();
|
|
473
647
|
}
|
|
474
648
|
};
|
|
475
649
|
}
|
|
@@ -487,5 +661,6 @@ function createPhantom({ plugins = [] }) {
|
|
|
487
661
|
createEthereumPlugin,
|
|
488
662
|
createExtensionPlugin,
|
|
489
663
|
createPhantom,
|
|
664
|
+
createSiweMessage,
|
|
490
665
|
isPhantomExtensionInstalled
|
|
491
666
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createEthereumPlugin
|
|
3
|
-
|
|
2
|
+
createEthereumPlugin,
|
|
3
|
+
createSiweMessage
|
|
4
|
+
} from "./chunk-JJH6SEIK.mjs";
|
|
4
5
|
import "./chunk-WUKYLWAZ.mjs";
|
|
5
6
|
import "./chunk-GV6AIHPN.mjs";
|
|
6
7
|
|
|
@@ -37,5 +38,6 @@ export {
|
|
|
37
38
|
createEthereumPlugin,
|
|
38
39
|
createExtensionPlugin,
|
|
39
40
|
createPhantom,
|
|
41
|
+
createSiweMessage,
|
|
40
42
|
isInstalled as isPhantomExtensionInstalled
|
|
41
43
|
};
|
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { P as Plugin } from '../index-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare function connect({ onlyIfTrusted }?: {
|
|
5
|
-
onlyIfTrusted?: boolean | undefined;
|
|
6
|
-
}): Promise<string | undefined>;
|
|
7
|
-
|
|
8
|
-
declare function disconnect(): Promise<void>;
|
|
1
|
+
import { P as Plugin } from '../index-673af1e4.js';
|
|
2
|
+
import { ISolanaChain } from '@phantom/chain-interfaces';
|
|
9
3
|
|
|
10
4
|
type SendOptions = {
|
|
11
5
|
skipPreflight?: boolean;
|
|
@@ -32,7 +26,6 @@ type SolanaSignInData = {
|
|
|
32
26
|
resources?: string[];
|
|
33
27
|
};
|
|
34
28
|
type DisplayEncoding = "utf8" | "hex";
|
|
35
|
-
type PhantomEventType = "connect" | "disconnect" | "accountChanged";
|
|
36
29
|
interface PhantomSolanaProvider {
|
|
37
30
|
isPhantom: boolean;
|
|
38
31
|
publicKey: PublicKey | null;
|
|
@@ -66,94 +59,12 @@ interface PhantomSolanaProvider {
|
|
|
66
59
|
off: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
|
|
67
60
|
}
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
type DisconnectCallback = () => void;
|
|
71
|
-
type AccountChangedCallback = (publicKey: string) => void;
|
|
72
|
-
type PhantomEventCallback = ConnectCallback | DisconnectCallback | AccountChangedCallback;
|
|
73
|
-
|
|
74
|
-
declare function getAccount(): Promise<string | undefined>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Signs and sends a transaction using the Phantom provider.
|
|
78
|
-
* @param transaction The transaction to sign and send (Web3.js format).
|
|
79
|
-
* @returns A promise that resolves with the transaction signature and optionally the public key.
|
|
80
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
81
|
-
*/
|
|
82
|
-
declare function signAndSendTransaction(transaction: VersionedTransaction | Transaction): Promise<{
|
|
83
|
-
signature: string;
|
|
84
|
-
address?: string;
|
|
85
|
-
}>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Signs and sends all transactions using the Phantom provider.
|
|
89
|
-
* @param transactions An array of transactions to sign and send (Web3.js format).
|
|
90
|
-
* @returns A promise that resolves with an array of transaction signatures and optionally the public key.
|
|
91
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
92
|
-
*/
|
|
93
|
-
declare function signAndSendAllTransactions(transactions: (VersionedTransaction | Transaction)[]): Promise<{
|
|
94
|
-
signatures: string[];
|
|
95
|
-
address?: string;
|
|
96
|
-
}>;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Signs a transaction using the Phantom provider without sending it.
|
|
100
|
-
* @param transaction The transaction to sign (Web3.js format).
|
|
101
|
-
* @returns A promise that resolves with the signed transaction.
|
|
102
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
103
|
-
*/
|
|
104
|
-
declare function signTransaction(transaction: VersionedTransaction | Transaction): Promise<VersionedTransaction | Transaction>;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Signs all transactions using the Phantom provider.
|
|
108
|
-
* @param transactions An array of transactions to sign (Web3.js format).
|
|
109
|
-
* @returns A promise that resolves with an array of signed transactions.
|
|
110
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
111
|
-
*/
|
|
112
|
-
declare function signAllTransactions(transactions: (VersionedTransaction | Transaction)[]): Promise<(VersionedTransaction | Transaction)[]>;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Signs in with Solana using the Phantom provider.
|
|
116
|
-
* @param signInData The sign-in data.
|
|
117
|
-
* @returns A promise that resolves with the address, signature, and signed message.
|
|
118
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
119
|
-
*/
|
|
120
|
-
declare function signIn(signInData: SolanaSignInData): Promise<{
|
|
121
|
-
address: string;
|
|
122
|
-
signature: Uint8Array;
|
|
123
|
-
signedMessage: Uint8Array;
|
|
124
|
-
}>;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Signs a message using the Phantom provider.
|
|
128
|
-
* @param message The message to sign (as a Uint8Array).
|
|
129
|
-
* @param display The display encoding for the message (optional, defaults to utf8).
|
|
130
|
-
* @returns A promise that resolves with the signature and public key.
|
|
131
|
-
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
132
|
-
*/
|
|
133
|
-
declare function signMessage(message: Uint8Array, display?: DisplayEncoding): Promise<{
|
|
134
|
-
signature: Uint8Array;
|
|
135
|
-
address: string;
|
|
136
|
-
}>;
|
|
137
|
-
|
|
138
|
-
type Solana = {
|
|
139
|
-
connect: typeof connect;
|
|
140
|
-
disconnect: typeof disconnect;
|
|
141
|
-
getAccount: typeof getAccount;
|
|
142
|
-
signMessage: typeof signMessage;
|
|
143
|
-
signIn: typeof signIn;
|
|
144
|
-
signTransaction: typeof signTransaction;
|
|
145
|
-
signAllTransactions: typeof signAllTransactions;
|
|
146
|
-
signAndSendTransaction: typeof signAndSendTransaction;
|
|
147
|
-
signAndSendAllTransactions: typeof signAndSendAllTransactions;
|
|
148
|
-
addEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => () => void;
|
|
149
|
-
removeEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => void;
|
|
150
|
-
};
|
|
151
|
-
declare function createSolanaPlugin(): Plugin<Solana>;
|
|
62
|
+
declare function createSolanaPlugin(): Plugin<ISolanaChain>;
|
|
152
63
|
|
|
153
64
|
declare module "../index" {
|
|
154
65
|
interface Phantom {
|
|
155
|
-
solana:
|
|
66
|
+
solana: ISolanaChain;
|
|
156
67
|
}
|
|
157
68
|
}
|
|
158
69
|
|
|
159
|
-
export { PhantomSolanaProvider,
|
|
70
|
+
export { PhantomSolanaProvider, SolanaSignInData, createSolanaPlugin };
|