@phantom/browser-injected-sdk 1.0.0-beta.1 → 1.0.0-beta.10
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 +1 -1
- package/dist/auto-confirm/index.js +1 -1
- package/dist/auto-confirm/index.mjs +1 -1
- package/dist/{chunk-IHSV7HFD.mjs → chunk-MDTCVDFZ.mjs} +33 -2
- package/dist/ethereum/index.d.ts +1 -1
- package/dist/ethereum/index.js +33 -2
- package/dist/ethereum/index.mjs +1 -1
- package/dist/{index-ecfd5526.d.ts → index-3a750f13.d.ts} +5 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -3
- package/dist/index.mjs +2 -2
- package/dist/solana/index.d.ts +39 -3
- package/dist/solana/index.js +88 -91
- package/dist/solana/index.mjs +88 -91
- package/package.json +8 -3
|
@@ -33,6 +33,9 @@ var InjectedEthereumStrategy = class {
|
|
|
33
33
|
scheduleRetry(() => resolve(this), reject);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
getProvider() {
|
|
37
|
+
return __privateMethod(this, _getProvider, getProvider_fn).call(this) || null;
|
|
38
|
+
}
|
|
36
39
|
get isConnected() {
|
|
37
40
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
38
41
|
return provider?.isConnected && provider.selectedAddress ? true : false;
|
|
@@ -184,6 +187,9 @@ var InjectedEthereumStrategy = class {
|
|
|
184
187
|
};
|
|
185
188
|
_getProvider = new WeakSet();
|
|
186
189
|
getProvider_fn = function() {
|
|
190
|
+
if (typeof window === "undefined") {
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
187
193
|
return window?.phantom?.ethereum;
|
|
188
194
|
};
|
|
189
195
|
|
|
@@ -232,7 +238,7 @@ function triggerEvent(event, data) {
|
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
// src/ethereum/connect.ts
|
|
235
|
-
async function connect() {
|
|
241
|
+
async function connect({ onlyIfTrusted = false } = {}) {
|
|
236
242
|
const provider = await getProvider();
|
|
237
243
|
if (!provider) {
|
|
238
244
|
throw new Error("Provider not found.");
|
|
@@ -249,6 +255,9 @@ async function connect() {
|
|
|
249
255
|
}
|
|
250
256
|
} catch (error) {
|
|
251
257
|
}
|
|
258
|
+
if (onlyIfTrusted) {
|
|
259
|
+
throw new Error("No trusted connection available.");
|
|
260
|
+
}
|
|
252
261
|
try {
|
|
253
262
|
const accounts = await provider.connect({ onlyIfTrusted: false });
|
|
254
263
|
if (accounts && accounts.length > 0) {
|
|
@@ -378,10 +387,32 @@ var ethereum = {
|
|
|
378
387
|
addEventListener,
|
|
379
388
|
removeEventListener
|
|
380
389
|
};
|
|
390
|
+
async function bindProviderEvents() {
|
|
391
|
+
try {
|
|
392
|
+
const strategy = await getProvider();
|
|
393
|
+
const provider = strategy.getProvider();
|
|
394
|
+
if (provider) {
|
|
395
|
+
provider.on("connect", () => {
|
|
396
|
+
provider.request({ method: "eth_accounts" }).then((accounts) => {
|
|
397
|
+
if (accounts?.length > 0)
|
|
398
|
+
triggerEvent("connect", accounts);
|
|
399
|
+
}).catch(() => {
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
provider.on("disconnect", () => triggerEvent("disconnect", []));
|
|
403
|
+
provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
|
|
404
|
+
provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
}
|
|
408
|
+
}
|
|
381
409
|
function createEthereumPlugin() {
|
|
382
410
|
return {
|
|
383
411
|
name: "ethereum",
|
|
384
|
-
create: () =>
|
|
412
|
+
create: () => {
|
|
413
|
+
bindProviderEvents();
|
|
414
|
+
return ethereum;
|
|
415
|
+
}
|
|
385
416
|
};
|
|
386
417
|
}
|
|
387
418
|
|
package/dist/ethereum/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { E as Ethereum, e as EthereumEventType, d as EthereumSignInData, b as EthereumTransaction, a as PhantomEthereumProvider, c as createEthereumPlugin } from '../index-
|
|
1
|
+
export { E as Ethereum, e as EthereumEventType, d as EthereumSignInData, b as EthereumTransaction, a as PhantomEthereumProvider, c as createEthereumPlugin } from '../index-3a750f13.js';
|
package/dist/ethereum/index.js
CHANGED
|
@@ -67,6 +67,9 @@ var InjectedEthereumStrategy = class {
|
|
|
67
67
|
scheduleRetry(() => resolve(this), reject);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
+
getProvider() {
|
|
71
|
+
return __privateMethod(this, _getProvider, getProvider_fn).call(this) || null;
|
|
72
|
+
}
|
|
70
73
|
get isConnected() {
|
|
71
74
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
72
75
|
return provider?.isConnected && provider.selectedAddress ? true : false;
|
|
@@ -218,6 +221,9 @@ var InjectedEthereumStrategy = class {
|
|
|
218
221
|
};
|
|
219
222
|
_getProvider = new WeakSet();
|
|
220
223
|
getProvider_fn = function() {
|
|
224
|
+
if (typeof window === "undefined") {
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
221
227
|
return window?.phantom?.ethereum;
|
|
222
228
|
};
|
|
223
229
|
|
|
@@ -266,7 +272,7 @@ function triggerEvent(event, data) {
|
|
|
266
272
|
}
|
|
267
273
|
|
|
268
274
|
// src/ethereum/connect.ts
|
|
269
|
-
async function connect() {
|
|
275
|
+
async function connect({ onlyIfTrusted = false } = {}) {
|
|
270
276
|
const provider = await getProvider();
|
|
271
277
|
if (!provider) {
|
|
272
278
|
throw new Error("Provider not found.");
|
|
@@ -283,6 +289,9 @@ async function connect() {
|
|
|
283
289
|
}
|
|
284
290
|
} catch (error) {
|
|
285
291
|
}
|
|
292
|
+
if (onlyIfTrusted) {
|
|
293
|
+
throw new Error("No trusted connection available.");
|
|
294
|
+
}
|
|
286
295
|
try {
|
|
287
296
|
const accounts = await provider.connect({ onlyIfTrusted: false });
|
|
288
297
|
if (accounts && accounts.length > 0) {
|
|
@@ -412,10 +421,32 @@ var ethereum = {
|
|
|
412
421
|
addEventListener,
|
|
413
422
|
removeEventListener
|
|
414
423
|
};
|
|
424
|
+
async function bindProviderEvents() {
|
|
425
|
+
try {
|
|
426
|
+
const strategy = await getProvider();
|
|
427
|
+
const provider = strategy.getProvider();
|
|
428
|
+
if (provider) {
|
|
429
|
+
provider.on("connect", () => {
|
|
430
|
+
provider.request({ method: "eth_accounts" }).then((accounts) => {
|
|
431
|
+
if (accounts?.length > 0)
|
|
432
|
+
triggerEvent("connect", accounts);
|
|
433
|
+
}).catch(() => {
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
provider.on("disconnect", () => triggerEvent("disconnect", []));
|
|
437
|
+
provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
|
|
438
|
+
provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
|
|
439
|
+
}
|
|
440
|
+
} catch (error) {
|
|
441
|
+
}
|
|
442
|
+
}
|
|
415
443
|
function createEthereumPlugin() {
|
|
416
444
|
return {
|
|
417
445
|
name: "ethereum",
|
|
418
|
-
create: () =>
|
|
446
|
+
create: () => {
|
|
447
|
+
bindProviderEvents();
|
|
448
|
+
return ethereum;
|
|
449
|
+
}
|
|
419
450
|
};
|
|
420
451
|
}
|
|
421
452
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/ethereum/index.mjs
CHANGED
|
@@ -11,7 +11,9 @@ declare module "../index" {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
declare function connect(
|
|
14
|
+
declare function connect({ onlyIfTrusted }?: {
|
|
15
|
+
onlyIfTrusted?: boolean | undefined;
|
|
16
|
+
}): Promise<string[]>;
|
|
15
17
|
|
|
16
18
|
declare function disconnect(): Promise<void>;
|
|
17
19
|
|
|
@@ -128,13 +130,13 @@ declare function getChainId(): Promise<string>;
|
|
|
128
130
|
declare function switchChain(chainId: string): Promise<void>;
|
|
129
131
|
|
|
130
132
|
declare enum ProviderStrategy {
|
|
131
|
-
INJECTED = "injected"
|
|
132
|
-
DEEPLINK = "deeplink"
|
|
133
|
+
INJECTED = "injected"
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
interface EthereumStrategy {
|
|
136
137
|
readonly type: ProviderStrategy;
|
|
137
138
|
isConnected: boolean;
|
|
139
|
+
getProvider: () => PhantomEthereumProvider | null;
|
|
138
140
|
connect: ({ onlyIfTrusted }: {
|
|
139
141
|
onlyIfTrusted: boolean;
|
|
140
142
|
}) => Promise<string[] | undefined>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
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, j as isPhantomExtensionInstalled } from './index-3a750f13.js';
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
43
43
|
// src/extension/isInstalled.ts
|
|
44
44
|
function isInstalled() {
|
|
45
45
|
try {
|
|
46
|
-
const phantom = window
|
|
46
|
+
const phantom = window?.phantom;
|
|
47
47
|
return !!phantom;
|
|
48
48
|
} catch (error) {
|
|
49
49
|
return false;
|
|
@@ -91,6 +91,9 @@ var InjectedEthereumStrategy = class {
|
|
|
91
91
|
scheduleRetry(() => resolve(this), reject);
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
+
getProvider() {
|
|
95
|
+
return __privateMethod(this, _getProvider, getProvider_fn).call(this) || null;
|
|
96
|
+
}
|
|
94
97
|
get isConnected() {
|
|
95
98
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
96
99
|
return provider?.isConnected && provider.selectedAddress ? true : false;
|
|
@@ -242,6 +245,9 @@ var InjectedEthereumStrategy = class {
|
|
|
242
245
|
};
|
|
243
246
|
_getProvider = new WeakSet();
|
|
244
247
|
getProvider_fn = function() {
|
|
248
|
+
if (typeof window === "undefined") {
|
|
249
|
+
return void 0;
|
|
250
|
+
}
|
|
245
251
|
return window?.phantom?.ethereum;
|
|
246
252
|
};
|
|
247
253
|
|
|
@@ -290,7 +296,7 @@ function triggerEvent(event, data) {
|
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
// src/ethereum/connect.ts
|
|
293
|
-
async function connect() {
|
|
299
|
+
async function connect({ onlyIfTrusted = false } = {}) {
|
|
294
300
|
const provider = await getProvider();
|
|
295
301
|
if (!provider) {
|
|
296
302
|
throw new Error("Provider not found.");
|
|
@@ -307,6 +313,9 @@ async function connect() {
|
|
|
307
313
|
}
|
|
308
314
|
} catch (error) {
|
|
309
315
|
}
|
|
316
|
+
if (onlyIfTrusted) {
|
|
317
|
+
throw new Error("No trusted connection available.");
|
|
318
|
+
}
|
|
310
319
|
try {
|
|
311
320
|
const accounts = await provider.connect({ onlyIfTrusted: false });
|
|
312
321
|
if (accounts && accounts.length > 0) {
|
|
@@ -436,10 +445,32 @@ var ethereum = {
|
|
|
436
445
|
addEventListener,
|
|
437
446
|
removeEventListener
|
|
438
447
|
};
|
|
448
|
+
async function bindProviderEvents() {
|
|
449
|
+
try {
|
|
450
|
+
const strategy = await getProvider();
|
|
451
|
+
const provider = strategy.getProvider();
|
|
452
|
+
if (provider) {
|
|
453
|
+
provider.on("connect", () => {
|
|
454
|
+
provider.request({ method: "eth_accounts" }).then((accounts) => {
|
|
455
|
+
if (accounts?.length > 0)
|
|
456
|
+
triggerEvent("connect", accounts);
|
|
457
|
+
}).catch(() => {
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
provider.on("disconnect", () => triggerEvent("disconnect", []));
|
|
461
|
+
provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
|
|
462
|
+
provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
|
|
463
|
+
}
|
|
464
|
+
} catch (error) {
|
|
465
|
+
}
|
|
466
|
+
}
|
|
439
467
|
function createEthereumPlugin() {
|
|
440
468
|
return {
|
|
441
469
|
name: "ethereum",
|
|
442
|
-
create: () =>
|
|
470
|
+
create: () => {
|
|
471
|
+
bindProviderEvents();
|
|
472
|
+
return ethereum;
|
|
473
|
+
}
|
|
443
474
|
};
|
|
444
475
|
}
|
|
445
476
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createEthereumPlugin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MDTCVDFZ.mjs";
|
|
4
4
|
import "./chunk-WUKYLWAZ.mjs";
|
|
5
5
|
import "./chunk-GV6AIHPN.mjs";
|
|
6
6
|
|
|
7
7
|
// src/extension/isInstalled.ts
|
|
8
8
|
function isInstalled() {
|
|
9
9
|
try {
|
|
10
|
-
const phantom = window
|
|
10
|
+
const phantom = window?.phantom;
|
|
11
11
|
return !!phantom;
|
|
12
12
|
} catch (error) {
|
|
13
13
|
return false;
|
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { P as Plugin } from '../index-
|
|
2
|
-
import { VersionedTransaction, Transaction } from '@
|
|
1
|
+
import { P as Plugin } from '../index-3a750f13.js';
|
|
2
|
+
import { VersionedTransaction, Transaction } from '@phantom/sdk-types';
|
|
3
3
|
|
|
4
|
-
declare function connect(
|
|
4
|
+
declare function connect({ onlyIfTrusted }?: {
|
|
5
|
+
onlyIfTrusted?: boolean | undefined;
|
|
6
|
+
}): Promise<string | undefined>;
|
|
5
7
|
|
|
6
8
|
declare function disconnect(): Promise<void>;
|
|
7
9
|
|
|
@@ -54,6 +56,10 @@ interface PhantomSolanaProvider {
|
|
|
54
56
|
signature: string;
|
|
55
57
|
publicKey?: string;
|
|
56
58
|
}>;
|
|
59
|
+
signAndSendAllTransactions: (transactions: any[], options?: SendOptions) => Promise<{
|
|
60
|
+
signatures: string[];
|
|
61
|
+
publicKey?: string;
|
|
62
|
+
}>;
|
|
57
63
|
signAllTransactions: (transactions: any[]) => Promise<any[]>;
|
|
58
64
|
signTransaction: (transaction: any) => Promise<any>;
|
|
59
65
|
on: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
|
|
@@ -78,6 +84,33 @@ declare function signAndSendTransaction(transaction: VersionedTransaction | Tran
|
|
|
78
84
|
address?: string;
|
|
79
85
|
}>;
|
|
80
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
|
+
|
|
81
114
|
/**
|
|
82
115
|
* Signs in with Solana using the Phantom provider.
|
|
83
116
|
* @param signInData The sign-in data.
|
|
@@ -108,7 +141,10 @@ type Solana = {
|
|
|
108
141
|
getAccount: typeof getAccount;
|
|
109
142
|
signMessage: typeof signMessage;
|
|
110
143
|
signIn: typeof signIn;
|
|
144
|
+
signTransaction: typeof signTransaction;
|
|
145
|
+
signAllTransactions: typeof signAllTransactions;
|
|
111
146
|
signAndSendTransaction: typeof signAndSendTransaction;
|
|
147
|
+
signAndSendAllTransactions: typeof signAndSendAllTransactions;
|
|
112
148
|
addEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => () => void;
|
|
113
149
|
removeEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => void;
|
|
114
150
|
};
|
package/dist/solana/index.js
CHANGED
|
@@ -67,6 +67,9 @@ var InjectedSolanaStrategy = class {
|
|
|
67
67
|
scheduleRetry(() => resolve(this), reject);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
+
getProvider() {
|
|
71
|
+
return __privateMethod(this, _getProvider, getProvider_fn).call(this) || null;
|
|
72
|
+
}
|
|
70
73
|
get isConnected() {
|
|
71
74
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
72
75
|
return provider?.isConnected && provider.publicKey ? true : false;
|
|
@@ -140,6 +143,23 @@ var InjectedSolanaStrategy = class {
|
|
|
140
143
|
address: result.publicKey
|
|
141
144
|
};
|
|
142
145
|
}
|
|
146
|
+
async signAndSendAllTransactions(transactions) {
|
|
147
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
148
|
+
if (!provider) {
|
|
149
|
+
throw new Error("Provider not found.");
|
|
150
|
+
}
|
|
151
|
+
if (!provider.isConnected) {
|
|
152
|
+
throw new Error("Provider is not connected.");
|
|
153
|
+
}
|
|
154
|
+
if (!provider.signAndSendAllTransactions) {
|
|
155
|
+
throw new Error("Provider does not support signAndSendAllTransactions.");
|
|
156
|
+
}
|
|
157
|
+
const results = await provider.signAndSendAllTransactions(transactions);
|
|
158
|
+
return {
|
|
159
|
+
signatures: results.signatures,
|
|
160
|
+
address: results.publicKey
|
|
161
|
+
};
|
|
162
|
+
}
|
|
143
163
|
async signTransaction(transaction) {
|
|
144
164
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
145
165
|
if (!provider) {
|
|
@@ -165,94 +185,10 @@ var InjectedSolanaStrategy = class {
|
|
|
165
185
|
};
|
|
166
186
|
_getProvider = new WeakSet();
|
|
167
187
|
getProvider_fn = function() {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// src/solana/strategies/deeplinks.ts
|
|
172
|
-
var DeepLinkSolanaStrategy = class {
|
|
173
|
-
constructor() {
|
|
174
|
-
this.type = "deeplink" /* DEEPLINK */;
|
|
175
|
-
}
|
|
176
|
-
load() {
|
|
177
|
-
return Promise.resolve(this);
|
|
178
|
-
}
|
|
179
|
-
get isConnected() {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
async connect({ onlyIfTrusted }) {
|
|
183
|
-
const deeplink = `phantom://connect?onlyIfTrusted=${onlyIfTrusted}`;
|
|
184
|
-
window.location.href = deeplink;
|
|
185
|
-
return Promise.resolve(void 0);
|
|
186
|
-
}
|
|
187
|
-
async disconnect() {
|
|
188
|
-
const deeplink = `phantom://disconnect`;
|
|
189
|
-
window.location.href = deeplink;
|
|
190
|
-
return Promise.resolve();
|
|
191
|
-
}
|
|
192
|
-
async getAccount() {
|
|
193
|
-
const deeplink = `phantom://account`;
|
|
194
|
-
window.location.href = deeplink;
|
|
195
|
-
return Promise.resolve(void 0);
|
|
196
|
-
}
|
|
197
|
-
async signMessage(message, display) {
|
|
198
|
-
const messageEncoded = Buffer.from(message).toString("base64");
|
|
199
|
-
const deeplink = `phantom://sign-message?message=${messageEncoded}&display=${display}`;
|
|
200
|
-
window.location.href = deeplink;
|
|
201
|
-
return Promise.resolve({
|
|
202
|
-
signature: new Uint8Array(),
|
|
203
|
-
address: ""
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
async signIn(signInData) {
|
|
207
|
-
const deeplink = `phantom://sign-in?signInData=${encodeURIComponent(JSON.stringify(signInData))}`;
|
|
208
|
-
window.location.href = deeplink;
|
|
209
|
-
return Promise.resolve({
|
|
210
|
-
address: "",
|
|
211
|
-
signature: new Uint8Array(),
|
|
212
|
-
signedMessage: new Uint8Array()
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async signAndSendTransaction(transaction) {
|
|
216
|
-
let serialized;
|
|
217
|
-
if ("serialize" in transaction && typeof transaction.serialize === "function") {
|
|
218
|
-
serialized = transaction.serialize();
|
|
219
|
-
} else {
|
|
220
|
-
serialized = transaction.serializeMessage?.() || new Uint8Array();
|
|
221
|
-
}
|
|
222
|
-
const encoded = Buffer.from(serialized).toString("base64");
|
|
223
|
-
const deeplink = `phantom://sign-and-send-transaction?transaction=${encoded}`;
|
|
224
|
-
window.location.href = deeplink;
|
|
225
|
-
return Promise.resolve({
|
|
226
|
-
signature: "",
|
|
227
|
-
address: ""
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
async signTransaction(transaction) {
|
|
231
|
-
let serialized;
|
|
232
|
-
if ("serialize" in transaction && typeof transaction.serialize === "function") {
|
|
233
|
-
serialized = transaction.serialize();
|
|
234
|
-
} else {
|
|
235
|
-
serialized = transaction.serializeMessage?.() || new Uint8Array();
|
|
236
|
-
}
|
|
237
|
-
const encoded = Buffer.from(serialized).toString("base64");
|
|
238
|
-
const deeplink = `phantom://sign-transaction?transaction=${encoded}`;
|
|
239
|
-
window.location.href = deeplink;
|
|
240
|
-
return Promise.resolve(transaction);
|
|
241
|
-
}
|
|
242
|
-
async signAllTransactions(transactions) {
|
|
243
|
-
const serializedTxs = transactions.map((tx) => {
|
|
244
|
-
let serialized;
|
|
245
|
-
if ("serialize" in tx && typeof tx.serialize === "function") {
|
|
246
|
-
serialized = tx.serialize();
|
|
247
|
-
} else {
|
|
248
|
-
serialized = tx.serializeMessage?.() || new Uint8Array();
|
|
249
|
-
}
|
|
250
|
-
return Buffer.from(serialized).toString("base64");
|
|
251
|
-
});
|
|
252
|
-
const deeplink = `phantom://sign-all-transactions?transactions=${JSON.stringify(serializedTxs)}`;
|
|
253
|
-
window.location.href = deeplink;
|
|
254
|
-
return Promise.resolve(transactions);
|
|
188
|
+
if (typeof window === "undefined") {
|
|
189
|
+
return void 0;
|
|
255
190
|
}
|
|
191
|
+
return window?.phantom?.solana;
|
|
256
192
|
};
|
|
257
193
|
|
|
258
194
|
// src/solana/getProvider.ts
|
|
@@ -265,8 +201,6 @@ async function getProvider(strategy = "injected" /* INJECTED */) {
|
|
|
265
201
|
} catch (error) {
|
|
266
202
|
throw new Error("Provider not found.");
|
|
267
203
|
}
|
|
268
|
-
} else if (strategy === "deeplink") {
|
|
269
|
-
return new DeepLinkSolanaStrategy();
|
|
270
204
|
} else {
|
|
271
205
|
throw new Error("Invalid provider type.");
|
|
272
206
|
}
|
|
@@ -306,7 +240,7 @@ function triggerEvent(event, ...args) {
|
|
|
306
240
|
}
|
|
307
241
|
|
|
308
242
|
// src/solana/connect.ts
|
|
309
|
-
async function connect() {
|
|
243
|
+
async function connect({ onlyIfTrusted = false } = {}) {
|
|
310
244
|
const provider = await getProvider();
|
|
311
245
|
if (!provider) {
|
|
312
246
|
throw new Error("Provider not found.");
|
|
@@ -322,6 +256,9 @@ async function connect() {
|
|
|
322
256
|
}
|
|
323
257
|
} catch (error) {
|
|
324
258
|
}
|
|
259
|
+
if (onlyIfTrusted) {
|
|
260
|
+
throw new Error("No trusted connection available.");
|
|
261
|
+
}
|
|
325
262
|
try {
|
|
326
263
|
const address = await provider.connect({ onlyIfTrusted: false });
|
|
327
264
|
if (address) {
|
|
@@ -361,6 +298,42 @@ async function signAndSendTransaction(transaction) {
|
|
|
361
298
|
return provider.signAndSendTransaction(transaction);
|
|
362
299
|
}
|
|
363
300
|
|
|
301
|
+
// src/solana/signAndSendAllTransactions.ts
|
|
302
|
+
async function signAndSendAllTransactions(transactions) {
|
|
303
|
+
const provider = await getProvider();
|
|
304
|
+
if (!provider) {
|
|
305
|
+
throw new Error("Provider not found.");
|
|
306
|
+
}
|
|
307
|
+
if (!provider.isConnected) {
|
|
308
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
309
|
+
}
|
|
310
|
+
return provider.signAndSendAllTransactions(transactions);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/solana/signTransaction.ts
|
|
314
|
+
async function signTransaction(transaction) {
|
|
315
|
+
const provider = await getProvider();
|
|
316
|
+
if (!provider) {
|
|
317
|
+
throw new Error("Provider not found.");
|
|
318
|
+
}
|
|
319
|
+
if (!provider.isConnected) {
|
|
320
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
321
|
+
}
|
|
322
|
+
return provider.signTransaction(transaction);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/solana/signAllTransactions.ts
|
|
326
|
+
async function signAllTransactions(transactions) {
|
|
327
|
+
const provider = await getProvider();
|
|
328
|
+
if (!provider) {
|
|
329
|
+
throw new Error("Provider not found.");
|
|
330
|
+
}
|
|
331
|
+
if (!provider.isConnected) {
|
|
332
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
333
|
+
}
|
|
334
|
+
return provider.signAllTransactions(transactions);
|
|
335
|
+
}
|
|
336
|
+
|
|
364
337
|
// src/solana/signIn.ts
|
|
365
338
|
async function signIn(signInData) {
|
|
366
339
|
const provider = await getProvider();
|
|
@@ -393,14 +366,38 @@ var solana = {
|
|
|
393
366
|
getAccount,
|
|
394
367
|
signMessage,
|
|
395
368
|
signIn,
|
|
369
|
+
signTransaction,
|
|
370
|
+
signAllTransactions,
|
|
396
371
|
signAndSendTransaction,
|
|
372
|
+
signAndSendAllTransactions,
|
|
397
373
|
addEventListener,
|
|
398
374
|
removeEventListener
|
|
399
375
|
};
|
|
376
|
+
async function bindProviderEvents() {
|
|
377
|
+
try {
|
|
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
|
+
});
|
|
390
|
+
}
|
|
391
|
+
} catch (error) {
|
|
392
|
+
}
|
|
393
|
+
}
|
|
400
394
|
function createSolanaPlugin() {
|
|
401
395
|
return {
|
|
402
396
|
name: "solana",
|
|
403
|
-
create: () =>
|
|
397
|
+
create: () => {
|
|
398
|
+
bindProviderEvents();
|
|
399
|
+
return solana;
|
|
400
|
+
}
|
|
404
401
|
};
|
|
405
402
|
}
|
|
406
403
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/solana/index.mjs
CHANGED
|
@@ -34,6 +34,9 @@ var InjectedSolanaStrategy = class {
|
|
|
34
34
|
scheduleRetry(() => resolve(this), reject);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
getProvider() {
|
|
38
|
+
return __privateMethod(this, _getProvider, getProvider_fn).call(this) || null;
|
|
39
|
+
}
|
|
37
40
|
get isConnected() {
|
|
38
41
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
39
42
|
return provider?.isConnected && provider.publicKey ? true : false;
|
|
@@ -107,6 +110,23 @@ var InjectedSolanaStrategy = class {
|
|
|
107
110
|
address: result.publicKey
|
|
108
111
|
};
|
|
109
112
|
}
|
|
113
|
+
async signAndSendAllTransactions(transactions) {
|
|
114
|
+
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
115
|
+
if (!provider) {
|
|
116
|
+
throw new Error("Provider not found.");
|
|
117
|
+
}
|
|
118
|
+
if (!provider.isConnected) {
|
|
119
|
+
throw new Error("Provider is not connected.");
|
|
120
|
+
}
|
|
121
|
+
if (!provider.signAndSendAllTransactions) {
|
|
122
|
+
throw new Error("Provider does not support signAndSendAllTransactions.");
|
|
123
|
+
}
|
|
124
|
+
const results = await provider.signAndSendAllTransactions(transactions);
|
|
125
|
+
return {
|
|
126
|
+
signatures: results.signatures,
|
|
127
|
+
address: results.publicKey
|
|
128
|
+
};
|
|
129
|
+
}
|
|
110
130
|
async signTransaction(transaction) {
|
|
111
131
|
const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
|
|
112
132
|
if (!provider) {
|
|
@@ -132,94 +152,10 @@ var InjectedSolanaStrategy = class {
|
|
|
132
152
|
};
|
|
133
153
|
_getProvider = new WeakSet();
|
|
134
154
|
getProvider_fn = function() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// src/solana/strategies/deeplinks.ts
|
|
139
|
-
var DeepLinkSolanaStrategy = class {
|
|
140
|
-
constructor() {
|
|
141
|
-
this.type = "deeplink" /* DEEPLINK */;
|
|
142
|
-
}
|
|
143
|
-
load() {
|
|
144
|
-
return Promise.resolve(this);
|
|
145
|
-
}
|
|
146
|
-
get isConnected() {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
async connect({ onlyIfTrusted }) {
|
|
150
|
-
const deeplink = `phantom://connect?onlyIfTrusted=${onlyIfTrusted}`;
|
|
151
|
-
window.location.href = deeplink;
|
|
152
|
-
return Promise.resolve(void 0);
|
|
153
|
-
}
|
|
154
|
-
async disconnect() {
|
|
155
|
-
const deeplink = `phantom://disconnect`;
|
|
156
|
-
window.location.href = deeplink;
|
|
157
|
-
return Promise.resolve();
|
|
158
|
-
}
|
|
159
|
-
async getAccount() {
|
|
160
|
-
const deeplink = `phantom://account`;
|
|
161
|
-
window.location.href = deeplink;
|
|
162
|
-
return Promise.resolve(void 0);
|
|
163
|
-
}
|
|
164
|
-
async signMessage(message, display) {
|
|
165
|
-
const messageEncoded = Buffer.from(message).toString("base64");
|
|
166
|
-
const deeplink = `phantom://sign-message?message=${messageEncoded}&display=${display}`;
|
|
167
|
-
window.location.href = deeplink;
|
|
168
|
-
return Promise.resolve({
|
|
169
|
-
signature: new Uint8Array(),
|
|
170
|
-
address: ""
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
async signIn(signInData) {
|
|
174
|
-
const deeplink = `phantom://sign-in?signInData=${encodeURIComponent(JSON.stringify(signInData))}`;
|
|
175
|
-
window.location.href = deeplink;
|
|
176
|
-
return Promise.resolve({
|
|
177
|
-
address: "",
|
|
178
|
-
signature: new Uint8Array(),
|
|
179
|
-
signedMessage: new Uint8Array()
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
async signAndSendTransaction(transaction) {
|
|
183
|
-
let serialized;
|
|
184
|
-
if ("serialize" in transaction && typeof transaction.serialize === "function") {
|
|
185
|
-
serialized = transaction.serialize();
|
|
186
|
-
} else {
|
|
187
|
-
serialized = transaction.serializeMessage?.() || new Uint8Array();
|
|
188
|
-
}
|
|
189
|
-
const encoded = Buffer.from(serialized).toString("base64");
|
|
190
|
-
const deeplink = `phantom://sign-and-send-transaction?transaction=${encoded}`;
|
|
191
|
-
window.location.href = deeplink;
|
|
192
|
-
return Promise.resolve({
|
|
193
|
-
signature: "",
|
|
194
|
-
address: ""
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async signTransaction(transaction) {
|
|
198
|
-
let serialized;
|
|
199
|
-
if ("serialize" in transaction && typeof transaction.serialize === "function") {
|
|
200
|
-
serialized = transaction.serialize();
|
|
201
|
-
} else {
|
|
202
|
-
serialized = transaction.serializeMessage?.() || new Uint8Array();
|
|
203
|
-
}
|
|
204
|
-
const encoded = Buffer.from(serialized).toString("base64");
|
|
205
|
-
const deeplink = `phantom://sign-transaction?transaction=${encoded}`;
|
|
206
|
-
window.location.href = deeplink;
|
|
207
|
-
return Promise.resolve(transaction);
|
|
208
|
-
}
|
|
209
|
-
async signAllTransactions(transactions) {
|
|
210
|
-
const serializedTxs = transactions.map((tx) => {
|
|
211
|
-
let serialized;
|
|
212
|
-
if ("serialize" in tx && typeof tx.serialize === "function") {
|
|
213
|
-
serialized = tx.serialize();
|
|
214
|
-
} else {
|
|
215
|
-
serialized = tx.serializeMessage?.() || new Uint8Array();
|
|
216
|
-
}
|
|
217
|
-
return Buffer.from(serialized).toString("base64");
|
|
218
|
-
});
|
|
219
|
-
const deeplink = `phantom://sign-all-transactions?transactions=${JSON.stringify(serializedTxs)}`;
|
|
220
|
-
window.location.href = deeplink;
|
|
221
|
-
return Promise.resolve(transactions);
|
|
155
|
+
if (typeof window === "undefined") {
|
|
156
|
+
return void 0;
|
|
222
157
|
}
|
|
158
|
+
return window?.phantom?.solana;
|
|
223
159
|
};
|
|
224
160
|
|
|
225
161
|
// src/solana/getProvider.ts
|
|
@@ -232,8 +168,6 @@ async function getProvider(strategy = "injected" /* INJECTED */) {
|
|
|
232
168
|
} catch (error) {
|
|
233
169
|
throw new Error("Provider not found.");
|
|
234
170
|
}
|
|
235
|
-
} else if (strategy === "deeplink") {
|
|
236
|
-
return new DeepLinkSolanaStrategy();
|
|
237
171
|
} else {
|
|
238
172
|
throw new Error("Invalid provider type.");
|
|
239
173
|
}
|
|
@@ -273,7 +207,7 @@ function triggerEvent(event, ...args) {
|
|
|
273
207
|
}
|
|
274
208
|
|
|
275
209
|
// src/solana/connect.ts
|
|
276
|
-
async function connect() {
|
|
210
|
+
async function connect({ onlyIfTrusted = false } = {}) {
|
|
277
211
|
const provider = await getProvider();
|
|
278
212
|
if (!provider) {
|
|
279
213
|
throw new Error("Provider not found.");
|
|
@@ -289,6 +223,9 @@ async function connect() {
|
|
|
289
223
|
}
|
|
290
224
|
} catch (error) {
|
|
291
225
|
}
|
|
226
|
+
if (onlyIfTrusted) {
|
|
227
|
+
throw new Error("No trusted connection available.");
|
|
228
|
+
}
|
|
292
229
|
try {
|
|
293
230
|
const address = await provider.connect({ onlyIfTrusted: false });
|
|
294
231
|
if (address) {
|
|
@@ -328,6 +265,42 @@ async function signAndSendTransaction(transaction) {
|
|
|
328
265
|
return provider.signAndSendTransaction(transaction);
|
|
329
266
|
}
|
|
330
267
|
|
|
268
|
+
// src/solana/signAndSendAllTransactions.ts
|
|
269
|
+
async function signAndSendAllTransactions(transactions) {
|
|
270
|
+
const provider = await getProvider();
|
|
271
|
+
if (!provider) {
|
|
272
|
+
throw new Error("Provider not found.");
|
|
273
|
+
}
|
|
274
|
+
if (!provider.isConnected) {
|
|
275
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
276
|
+
}
|
|
277
|
+
return provider.signAndSendAllTransactions(transactions);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/solana/signTransaction.ts
|
|
281
|
+
async function signTransaction(transaction) {
|
|
282
|
+
const provider = await getProvider();
|
|
283
|
+
if (!provider) {
|
|
284
|
+
throw new Error("Provider not found.");
|
|
285
|
+
}
|
|
286
|
+
if (!provider.isConnected) {
|
|
287
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
288
|
+
}
|
|
289
|
+
return provider.signTransaction(transaction);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/solana/signAllTransactions.ts
|
|
293
|
+
async function signAllTransactions(transactions) {
|
|
294
|
+
const provider = await getProvider();
|
|
295
|
+
if (!provider) {
|
|
296
|
+
throw new Error("Provider not found.");
|
|
297
|
+
}
|
|
298
|
+
if (!provider.isConnected) {
|
|
299
|
+
await provider.connect({ onlyIfTrusted: false });
|
|
300
|
+
}
|
|
301
|
+
return provider.signAllTransactions(transactions);
|
|
302
|
+
}
|
|
303
|
+
|
|
331
304
|
// src/solana/signIn.ts
|
|
332
305
|
async function signIn(signInData) {
|
|
333
306
|
const provider = await getProvider();
|
|
@@ -360,14 +333,38 @@ var solana = {
|
|
|
360
333
|
getAccount,
|
|
361
334
|
signMessage,
|
|
362
335
|
signIn,
|
|
336
|
+
signTransaction,
|
|
337
|
+
signAllTransactions,
|
|
363
338
|
signAndSendTransaction,
|
|
339
|
+
signAndSendAllTransactions,
|
|
364
340
|
addEventListener,
|
|
365
341
|
removeEventListener
|
|
366
342
|
};
|
|
343
|
+
async function bindProviderEvents() {
|
|
344
|
+
try {
|
|
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
|
+
});
|
|
357
|
+
}
|
|
358
|
+
} catch (error) {
|
|
359
|
+
}
|
|
360
|
+
}
|
|
367
361
|
function createSolanaPlugin() {
|
|
368
362
|
return {
|
|
369
363
|
name: "solana",
|
|
370
|
-
create: () =>
|
|
364
|
+
create: () => {
|
|
365
|
+
bindProviderEvents();
|
|
366
|
+
return solana;
|
|
367
|
+
}
|
|
371
368
|
};
|
|
372
369
|
}
|
|
373
370
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/browser-injected-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/phantom/phantom-connect-sdk",
|
|
7
|
+
"directory": "packages/browser-injected-sdk"
|
|
8
|
+
},
|
|
4
9
|
"main": "dist/index.js",
|
|
5
10
|
"module": "dist/index.mjs",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
@@ -42,8 +47,8 @@
|
|
|
42
47
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
43
48
|
},
|
|
44
49
|
"dependencies": {
|
|
45
|
-
"@phantom/constants": "^1.0.0-beta.
|
|
46
|
-
"@
|
|
50
|
+
"@phantom/constants": "^1.0.0-beta.13",
|
|
51
|
+
"@phantom/sdk-types": "^1.0.0-beta.13"
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
54
|
"@types/jest": "^29.5.14",
|