@phantom/browser-injected-sdk 1.0.0-beta.4 → 1.0.0-beta.6

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.
@@ -1,4 +1,4 @@
1
- import { P as Plugin } from '../index-04827df9.js';
1
+ import { P as Plugin } from '../index-3a750f13.js';
2
2
  import { NetworkId } from '@phantom/constants';
3
3
 
4
4
  type AutoConfirmEnableParams = {
@@ -29,7 +29,7 @@ function getProvider() {
29
29
  if (typeof window === "undefined") {
30
30
  return null;
31
31
  }
32
- const provider = window.phantom?.app;
32
+ const provider = window?.phantom?.app;
33
33
  if (!provider) {
34
34
  return null;
35
35
  }
@@ -5,7 +5,7 @@ function getProvider() {
5
5
  if (typeof window === "undefined") {
6
6
  return null;
7
7
  }
8
- const provider = window.phantom?.app;
8
+ const provider = window?.phantom?.app;
9
9
  if (!provider) {
10
10
  return null;
11
11
  }
@@ -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,26 +387,30 @@ 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
412
  create: () => {
385
- try {
386
- const provider = window?.phantom?.ethereum;
387
- if (provider) {
388
- provider.on("connect", () => {
389
- provider.request({ method: "eth_accounts" }).then((accounts) => {
390
- if (accounts?.length > 0)
391
- triggerEvent("connect", accounts);
392
- }).catch(() => {
393
- });
394
- });
395
- provider.on("disconnect", () => triggerEvent("disconnect", []));
396
- provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
397
- provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
398
- }
399
- } catch (error) {
400
- }
413
+ bindProviderEvents();
401
414
  return ethereum;
402
415
  }
403
416
  };
@@ -1 +1 @@
1
- export { E as Ethereum, e as EthereumEventType, d as EthereumSignInData, b as EthereumTransaction, a as PhantomEthereumProvider, c as createEthereumPlugin } from '../index-04827df9.js';
1
+ export { E as Ethereum, e as EthereumEventType, d as EthereumSignInData, b as EthereumTransaction, a as PhantomEthereumProvider, c as createEthereumPlugin } from '../index-3a750f13.js';
@@ -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,26 +421,30 @@ 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
446
  create: () => {
419
- try {
420
- const provider = window?.phantom?.ethereum;
421
- if (provider) {
422
- provider.on("connect", () => {
423
- provider.request({ method: "eth_accounts" }).then((accounts) => {
424
- if (accounts?.length > 0)
425
- triggerEvent("connect", accounts);
426
- }).catch(() => {
427
- });
428
- });
429
- provider.on("disconnect", () => triggerEvent("disconnect", []));
430
- provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
431
- provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
432
- }
433
- } catch (error) {
434
- }
447
+ bindProviderEvents();
435
448
  return ethereum;
436
449
  }
437
450
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createEthereumPlugin
3
- } from "../chunk-CGMYPQYU.mjs";
3
+ } from "../chunk-MDTCVDFZ.mjs";
4
4
  import "../chunk-WUKYLWAZ.mjs";
5
5
  import "../chunk-GV6AIHPN.mjs";
6
6
  export {
@@ -11,7 +11,9 @@ declare module "../index" {
11
11
  }
12
12
  }
13
13
 
14
- declare function connect(): Promise<string[]>;
14
+ declare function connect({ onlyIfTrusted }?: {
15
+ onlyIfTrusted?: boolean | undefined;
16
+ }): Promise<string[]>;
15
17
 
16
18
  declare function disconnect(): Promise<void>;
17
19
 
@@ -134,6 +136,7 @@ declare enum ProviderStrategy {
134
136
  interface EthereumStrategy {
135
137
  readonly type: ProviderStrategy;
136
138
  isConnected: boolean;
139
+ getProvider: () => PhantomEthereumProvider | null;
137
140
  connect: ({ onlyIfTrusted }: {
138
141
  onlyIfTrusted: boolean;
139
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-04827df9.js';
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.phantom;
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,26 +445,30 @@ 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
470
  create: () => {
443
- try {
444
- const provider = window?.phantom?.ethereum;
445
- if (provider) {
446
- provider.on("connect", () => {
447
- provider.request({ method: "eth_accounts" }).then((accounts) => {
448
- if (accounts?.length > 0)
449
- triggerEvent("connect", accounts);
450
- }).catch(() => {
451
- });
452
- });
453
- provider.on("disconnect", () => triggerEvent("disconnect", []));
454
- provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
455
- provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
456
- }
457
- } catch (error) {
458
- }
471
+ bindProviderEvents();
459
472
  return ethereum;
460
473
  }
461
474
  };
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  createEthereumPlugin
3
- } from "./chunk-CGMYPQYU.mjs";
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.phantom;
10
+ const phantom = window?.phantom;
11
11
  return !!phantom;
12
12
  } catch (error) {
13
13
  return false;
@@ -1,7 +1,9 @@
1
- import { P as Plugin } from '../index-04827df9.js';
1
+ import { P as Plugin } from '../index-3a750f13.js';
2
2
  import { VersionedTransaction, Transaction } from '@phantom/sdk-types';
3
3
 
4
- declare function connect(): Promise<string | undefined>;
4
+ declare function connect({ onlyIfTrusted }?: {
5
+ onlyIfTrusted?: boolean | undefined;
6
+ }): Promise<string | undefined>;
5
7
 
6
8
  declare function disconnect(): Promise<void>;
7
9
 
@@ -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;
@@ -182,6 +185,9 @@ var InjectedSolanaStrategy = class {
182
185
  };
183
186
  _getProvider = new WeakSet();
184
187
  getProvider_fn = function() {
188
+ if (typeof window === "undefined") {
189
+ return void 0;
190
+ }
185
191
  return window?.phantom?.solana;
186
192
  };
187
193
 
@@ -234,7 +240,7 @@ function triggerEvent(event, ...args) {
234
240
  }
235
241
 
236
242
  // src/solana/connect.ts
237
- async function connect() {
243
+ async function connect({ onlyIfTrusted = false } = {}) {
238
244
  const provider = await getProvider();
239
245
  if (!provider) {
240
246
  throw new Error("Provider not found.");
@@ -250,6 +256,9 @@ async function connect() {
250
256
  }
251
257
  } catch (error) {
252
258
  }
259
+ if (onlyIfTrusted) {
260
+ throw new Error("No trusted connection available.");
261
+ }
253
262
  try {
254
263
  const address = await provider.connect({ onlyIfTrusted: false });
255
264
  if (address) {
@@ -364,25 +373,29 @@ var solana = {
364
373
  addEventListener,
365
374
  removeEventListener
366
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
+ }
367
394
  function createSolanaPlugin() {
368
395
  return {
369
396
  name: "solana",
370
397
  create: () => {
371
- try {
372
- const provider = window?.phantom?.solana;
373
- if (provider) {
374
- provider.on("connect", (publicKey) => {
375
- if (publicKey)
376
- triggerEvent("connect", publicKey.toString());
377
- });
378
- provider.on("disconnect", () => triggerEvent("disconnect"));
379
- provider.on("accountChanged", (publicKey) => {
380
- if (publicKey)
381
- triggerEvent("accountChanged", publicKey.toString());
382
- });
383
- }
384
- } catch (error) {
385
- }
398
+ bindProviderEvents();
386
399
  return solana;
387
400
  }
388
401
  };
@@ -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;
@@ -149,6 +152,9 @@ var InjectedSolanaStrategy = class {
149
152
  };
150
153
  _getProvider = new WeakSet();
151
154
  getProvider_fn = function() {
155
+ if (typeof window === "undefined") {
156
+ return void 0;
157
+ }
152
158
  return window?.phantom?.solana;
153
159
  };
154
160
 
@@ -201,7 +207,7 @@ function triggerEvent(event, ...args) {
201
207
  }
202
208
 
203
209
  // src/solana/connect.ts
204
- async function connect() {
210
+ async function connect({ onlyIfTrusted = false } = {}) {
205
211
  const provider = await getProvider();
206
212
  if (!provider) {
207
213
  throw new Error("Provider not found.");
@@ -217,6 +223,9 @@ async function connect() {
217
223
  }
218
224
  } catch (error) {
219
225
  }
226
+ if (onlyIfTrusted) {
227
+ throw new Error("No trusted connection available.");
228
+ }
220
229
  try {
221
230
  const address = await provider.connect({ onlyIfTrusted: false });
222
231
  if (address) {
@@ -331,25 +340,29 @@ var solana = {
331
340
  addEventListener,
332
341
  removeEventListener
333
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
+ }
334
361
  function createSolanaPlugin() {
335
362
  return {
336
363
  name: "solana",
337
364
  create: () => {
338
- try {
339
- const provider = window?.phantom?.solana;
340
- if (provider) {
341
- provider.on("connect", (publicKey) => {
342
- if (publicKey)
343
- triggerEvent("connect", publicKey.toString());
344
- });
345
- provider.on("disconnect", () => triggerEvent("disconnect"));
346
- provider.on("accountChanged", (publicKey) => {
347
- if (publicKey)
348
- triggerEvent("accountChanged", publicKey.toString());
349
- });
350
- }
351
- } catch (error) {
352
- }
365
+ bindProviderEvents();
353
366
  return solana;
354
367
  }
355
368
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/browser-injected-sdk",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
43
43
  },
44
44
  "dependencies": {
45
- "@phantom/constants": "^1.0.0-beta.6",
46
- "@phantom/sdk-types": "^1.0.0-beta.6"
45
+ "@phantom/constants": "^1.0.0-beta.8",
46
+ "@phantom/sdk-types": "^1.0.0-beta.8"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/jest": "^29.5.14",