@phantom/browser-injected-sdk 0.0.9 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,7 +79,6 @@ Once the `phantom.solana` object is initialized, you can access the following me
79
79
  The SDK also allows you to listen for `connect`, `disconnect`, and `accountChanged` events:
80
80
 
81
81
  - `addEventListener(event: PhantomEventType, callback: PhantomEventCallback): () => void`
82
-
83
82
  - Registers a callback that will be invoked when the specified event occurs.
84
83
  - For the `connect` event, the callback receives the public key (as a string) of the connected account.
85
84
  - For the `disconnect` event, the callback receives no arguments.
@@ -110,7 +109,6 @@ The SDK also allows you to listen for `connect`, `disconnect`, and `accountChang
110
109
  ```
111
110
 
112
111
  - `removeEventListener(event: PhantomEventType, callback: PhantomEventCallback): void`
113
-
114
112
  - Unregisters a previously registered callback for the specified event.
115
113
 
116
114
  **Example:**
@@ -1,15 +1,15 @@
1
- import { P as Plugin } from '../index-2f448acb.js';
1
+ import { P as Plugin } from '../index-ecfd5526.js';
2
+ import { NetworkId } from '@phantom/constants';
2
3
 
3
- type NetworkID = "bip122:000000000019d6689c085ae165831e93" | "bip122:000000000933ea01ad0ee984209779ba" | "solana:101" | "solana:102" | "solana:103" | "solana:localnet" | "eip155:1" | "eip155:11155111" | "eip155:137" | "eip155:80002" | "eip155:8453" | "eip155:84532" | "eip155:143" | "eip155:10143" | "eip155:41454" | "eip155:42161" | "eip155:421614" | "hypercore:mainnet" | "hypercore:testnet" | "sui:mainnet" | "sui:testnet";
4
4
  type AutoConfirmEnableParams = {
5
- chains?: NetworkID[];
5
+ chains?: NetworkId[];
6
6
  };
7
7
  type AutoConfirmResult = {
8
8
  enabled: boolean;
9
- chains: NetworkID[];
9
+ chains: NetworkId[];
10
10
  };
11
11
  type AutoConfirmSupportedChainsResult = {
12
- chains: NetworkID[];
12
+ chains: NetworkId[];
13
13
  };
14
14
 
15
15
  declare function autoConfirmEnable(params?: AutoConfirmEnableParams): Promise<AutoConfirmResult>;
@@ -34,4 +34,4 @@ declare module "../index" {
34
34
  }
35
35
  }
36
36
 
37
- export { AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, NetworkID, createAutoConfirmPlugin };
37
+ export { AutoConfirmEnableParams, AutoConfirmPlugin, AutoConfirmResult, AutoConfirmSupportedChainsResult, createAutoConfirmPlugin };
@@ -37,19 +37,25 @@ function getProvider() {
37
37
  }
38
38
 
39
39
  // src/auto-confirm/autoConfirmEnable.ts
40
+ var import_constants = require("@phantom/constants");
40
41
  async function autoConfirmEnable(params) {
41
42
  const provider = await getProvider();
42
43
  if (!provider) {
43
44
  throw new Error("Provider not found.");
44
45
  }
46
+ const transformedParams = params?.chains ? { chains: params.chains.map(import_constants.networkIdToInternalCaip) } : {};
45
47
  const result = await provider.request({
46
48
  method: "phantom_auto_confirm_enable",
47
- params: params || {}
49
+ params: transformedParams
48
50
  });
49
- return result;
51
+ return {
52
+ ...result,
53
+ chains: result.chains.map(import_constants.internalCaipToNetworkId)
54
+ };
50
55
  }
51
56
 
52
57
  // src/auto-confirm/autoConfirmDisable.ts
58
+ var import_constants2 = require("@phantom/constants");
53
59
  async function autoConfirmDisable() {
54
60
  const provider = await getProvider();
55
61
  if (!provider) {
@@ -59,10 +65,14 @@ async function autoConfirmDisable() {
59
65
  method: "phantom_auto_confirm_disable",
60
66
  params: {}
61
67
  });
62
- return result;
68
+ return {
69
+ ...result,
70
+ chains: result.chains.map(import_constants2.internalCaipToNetworkId)
71
+ };
63
72
  }
64
73
 
65
74
  // src/auto-confirm/autoConfirmStatus.ts
75
+ var import_constants3 = require("@phantom/constants");
66
76
  async function autoConfirmStatus() {
67
77
  const provider = await getProvider();
68
78
  if (!provider) {
@@ -72,12 +82,16 @@ async function autoConfirmStatus() {
72
82
  method: "phantom_auto_confirm_status",
73
83
  params: {}
74
84
  });
75
- return result;
85
+ return {
86
+ ...result,
87
+ chains: result.chains.map(import_constants3.internalCaipToNetworkId)
88
+ };
76
89
  }
77
90
 
78
91
  // src/auto-confirm/autoConfirmSupportedChains.ts
92
+ var import_constants4 = require("@phantom/constants");
79
93
  async function autoConfirmSupportedChains() {
80
- const provider = getProvider();
94
+ const provider = await getProvider();
81
95
  if (!provider) {
82
96
  throw new Error("Provider not found.");
83
97
  }
@@ -85,7 +99,9 @@ async function autoConfirmSupportedChains() {
85
99
  method: "phantom_auto_confirm_supported_chains",
86
100
  params: {}
87
101
  });
88
- return result;
102
+ return {
103
+ chains: result.chains.map(import_constants4.internalCaipToNetworkId)
104
+ };
89
105
  }
90
106
 
91
107
  // src/auto-confirm/plugin.ts
@@ -13,19 +13,25 @@ function getProvider() {
13
13
  }
14
14
 
15
15
  // src/auto-confirm/autoConfirmEnable.ts
16
+ import { networkIdToInternalCaip, internalCaipToNetworkId } from "@phantom/constants";
16
17
  async function autoConfirmEnable(params) {
17
18
  const provider = await getProvider();
18
19
  if (!provider) {
19
20
  throw new Error("Provider not found.");
20
21
  }
22
+ const transformedParams = params?.chains ? { chains: params.chains.map(networkIdToInternalCaip) } : {};
21
23
  const result = await provider.request({
22
24
  method: "phantom_auto_confirm_enable",
23
- params: params || {}
25
+ params: transformedParams
24
26
  });
25
- return result;
27
+ return {
28
+ ...result,
29
+ chains: result.chains.map(internalCaipToNetworkId)
30
+ };
26
31
  }
27
32
 
28
33
  // src/auto-confirm/autoConfirmDisable.ts
34
+ import { internalCaipToNetworkId as internalCaipToNetworkId2 } from "@phantom/constants";
29
35
  async function autoConfirmDisable() {
30
36
  const provider = await getProvider();
31
37
  if (!provider) {
@@ -35,10 +41,14 @@ async function autoConfirmDisable() {
35
41
  method: "phantom_auto_confirm_disable",
36
42
  params: {}
37
43
  });
38
- return result;
44
+ return {
45
+ ...result,
46
+ chains: result.chains.map(internalCaipToNetworkId2)
47
+ };
39
48
  }
40
49
 
41
50
  // src/auto-confirm/autoConfirmStatus.ts
51
+ import { internalCaipToNetworkId as internalCaipToNetworkId3 } from "@phantom/constants";
42
52
  async function autoConfirmStatus() {
43
53
  const provider = await getProvider();
44
54
  if (!provider) {
@@ -48,12 +58,16 @@ async function autoConfirmStatus() {
48
58
  method: "phantom_auto_confirm_status",
49
59
  params: {}
50
60
  });
51
- return result;
61
+ return {
62
+ ...result,
63
+ chains: result.chains.map(internalCaipToNetworkId3)
64
+ };
52
65
  }
53
66
 
54
67
  // src/auto-confirm/autoConfirmSupportedChains.ts
68
+ import { internalCaipToNetworkId as internalCaipToNetworkId4 } from "@phantom/constants";
55
69
  async function autoConfirmSupportedChains() {
56
- const provider = getProvider();
70
+ const provider = await getProvider();
57
71
  if (!provider) {
58
72
  throw new Error("Provider not found.");
59
73
  }
@@ -61,7 +75,9 @@ async function autoConfirmSupportedChains() {
61
75
  method: "phantom_auto_confirm_supported_chains",
62
76
  params: {}
63
77
  });
64
- return result;
78
+ return {
79
+ chains: result.chains.map(internalCaipToNetworkId4)
80
+ };
65
81
  }
66
82
 
67
83
  // src/auto-confirm/plugin.ts
@@ -174,6 +174,13 @@ var InjectedEthereumStrategy = class {
174
174
  params: [{ chainId }]
175
175
  });
176
176
  }
177
+ async request(args) {
178
+ const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
179
+ if (!provider) {
180
+ throw new Error("Provider not found.");
181
+ }
182
+ return await provider.request(args);
183
+ }
177
184
  };
178
185
  _getProvider = new WeakSet();
179
186
  getProvider_fn = function() {
@@ -367,6 +374,7 @@ var ethereum = {
367
374
  signTransaction,
368
375
  getChainId,
369
376
  switchChain,
377
+ getProvider,
370
378
  addEventListener,
371
379
  removeEventListener
372
380
  };
@@ -1 +1 @@
1
- export { d as EthereumEventType, b as EthereumSignInData, E as EthereumTransaction, a as PhantomEthereumProvider, c as createEthereumPlugin } from '../index-2f448acb.js';
1
+ export { E as Ethereum, e as EthereumEventType, d as EthereumSignInData, b as EthereumTransaction, a as PhantomEthereumProvider, c as createEthereumPlugin } from '../index-ecfd5526.js';
@@ -208,6 +208,13 @@ var InjectedEthereumStrategy = class {
208
208
  params: [{ chainId }]
209
209
  });
210
210
  }
211
+ async request(args) {
212
+ const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
213
+ if (!provider) {
214
+ throw new Error("Provider not found.");
215
+ }
216
+ return await provider.request(args);
217
+ }
211
218
  };
212
219
  _getProvider = new WeakSet();
213
220
  getProvider_fn = function() {
@@ -401,6 +408,7 @@ var ethereum = {
401
408
  signTransaction,
402
409
  getChainId,
403
410
  switchChain,
411
+ getProvider,
404
412
  addEventListener,
405
413
  removeEventListener
406
414
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createEthereumPlugin
3
- } from "../chunk-QNVIOBKG.mjs";
3
+ } from "../chunk-IHSV7HFD.mjs";
4
4
  import "../chunk-WUKYLWAZ.mjs";
5
5
  import "../chunk-GV6AIHPN.mjs";
6
6
  export {
@@ -127,6 +127,43 @@ declare function getChainId(): Promise<string>;
127
127
  */
128
128
  declare function switchChain(chainId: string): Promise<void>;
129
129
 
130
+ declare enum ProviderStrategy {
131
+ INJECTED = "injected",
132
+ DEEPLINK = "deeplink"
133
+ }
134
+
135
+ interface EthereumStrategy {
136
+ readonly type: ProviderStrategy;
137
+ isConnected: boolean;
138
+ connect: ({ onlyIfTrusted }: {
139
+ onlyIfTrusted: boolean;
140
+ }) => Promise<string[] | undefined>;
141
+ disconnect: () => Promise<void>;
142
+ getAccounts: () => Promise<string[]>;
143
+ signMessage: (message: string, address: string) => Promise<string>;
144
+ signPersonalMessage: (message: string, address: string) => Promise<string>;
145
+ signTypedData: (typedData: any, address: string) => Promise<string>;
146
+ signIn: (signInData: EthereumSignInData) => Promise<{
147
+ address: string;
148
+ signature: string;
149
+ signedMessage: string;
150
+ }>;
151
+ sendTransaction: (transaction: EthereumTransaction) => Promise<string>;
152
+ signTransaction: (transaction: EthereumTransaction) => Promise<string>;
153
+ getChainId: () => Promise<string>;
154
+ switchChain: (chainId: string) => Promise<void>;
155
+ request: <T = any>(args: {
156
+ method: string;
157
+ params?: unknown[];
158
+ }) => Promise<T>;
159
+ }
160
+
161
+ /**
162
+ * Retrieves Phantom Ethereum provider and returns it if it exists.
163
+ * @returns Phantom Ethereum provider or throws error if it doesn't exist.
164
+ */
165
+ declare function getProvider(strategy?: ProviderStrategy): Promise<EthereumStrategy>;
166
+
130
167
  type Ethereum = {
131
168
  connect: typeof connect;
132
169
  disconnect: typeof disconnect;
@@ -139,6 +176,7 @@ type Ethereum = {
139
176
  signTransaction: typeof signTransaction;
140
177
  getChainId: typeof getChainId;
141
178
  switchChain: typeof switchChain;
179
+ getProvider: typeof getProvider;
142
180
  addEventListener: (event: EthereumEventType, callback: PhantomEthereumEventCallback) => () => void;
143
181
  removeEventListener: (event: EthereumEventType, callback: PhantomEthereumEventCallback) => void;
144
182
  };
@@ -165,4 +203,4 @@ interface Phantom {
165
203
  */
166
204
  declare function createPhantom({ plugins }: CreatePhantomConfig): Phantom;
167
205
 
168
- export { CreatePhantomConfig as C, EthereumTransaction as E, Plugin as P, PhantomEthereumProvider as a, EthereumSignInData as b, createEthereumPlugin as c, EthereumEventType as d, Phantom as e, createPhantom as f, createExtensionPlugin as g, isInstalled as i };
206
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { C as CreatePhantomConfig, e as Phantom, P as Plugin, c as createEthereumPlugin, g as createExtensionPlugin, f as createPhantom, i as isPhantomExtensionInstalled } from './index-2f448acb.js';
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-ecfd5526.js';
package/dist/index.js CHANGED
@@ -232,6 +232,13 @@ var InjectedEthereumStrategy = class {
232
232
  params: [{ chainId }]
233
233
  });
234
234
  }
235
+ async request(args) {
236
+ const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
237
+ if (!provider) {
238
+ throw new Error("Provider not found.");
239
+ }
240
+ return await provider.request(args);
241
+ }
235
242
  };
236
243
  _getProvider = new WeakSet();
237
244
  getProvider_fn = function() {
@@ -425,6 +432,7 @@ var ethereum = {
425
432
  signTransaction,
426
433
  getChainId,
427
434
  switchChain,
435
+ getProvider,
428
436
  addEventListener,
429
437
  removeEventListener
430
438
  };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createEthereumPlugin
3
- } from "./chunk-QNVIOBKG.mjs";
3
+ } from "./chunk-IHSV7HFD.mjs";
4
4
  import "./chunk-WUKYLWAZ.mjs";
5
5
  import "./chunk-GV6AIHPN.mjs";
6
6
 
@@ -1,26 +1,10 @@
1
- import { P as Plugin } from '../index-2f448acb.js';
2
- import { Transaction as Transaction$1 } from '@solana/kit';
3
- import { VersionedTransaction as VersionedTransaction$1 } from '@solana/web3.js';
1
+ import { P as Plugin } from '../index-ecfd5526.js';
2
+ import { VersionedTransaction, Transaction } from '@solana/web3.js';
4
3
 
5
4
  declare function connect(): Promise<string | undefined>;
6
5
 
7
6
  declare function disconnect(): Promise<void>;
8
7
 
9
- type Transaction = {
10
- message: Uint8Array;
11
- recentBlockhash: string;
12
- feePayer: string;
13
- instructions: any[];
14
- signers: string[];
15
- version: number;
16
- };
17
- type VersionedTransaction = {
18
- signatures: Uint8Array[];
19
- message: {
20
- deserialize: (serializedTransaction: Uint8Array) => VersionedTransaction;
21
- serialize: (transaction: VersionedTransaction) => Uint8Array;
22
- };
23
- };
24
8
  type SendOptions = {
25
9
  skipPreflight?: boolean;
26
10
  preflightCommitment?: string;
@@ -66,12 +50,12 @@ interface PhantomSolanaProvider {
66
50
  signature: Uint8Array;
67
51
  signedMessage: Uint8Array;
68
52
  }>;
69
- signAndSendTransaction: (transaction: Transaction | VersionedTransaction, options?: SendOptions) => Promise<{
53
+ signAndSendTransaction: (transaction: any, options?: SendOptions) => Promise<{
70
54
  signature: string;
71
55
  publicKey?: string;
72
56
  }>;
73
- signAllTransactions: (transactions: (Transaction | VersionedTransaction)[]) => Promise<(Transaction | VersionedTransaction)[]>;
74
- signTransaction: (transaction: Transaction | VersionedTransaction) => Promise<Transaction | VersionedTransaction>;
57
+ signAllTransactions: (transactions: any[]) => Promise<any[]>;
58
+ signTransaction: (transaction: any) => Promise<any>;
75
59
  on: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
76
60
  off: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
77
61
  }
@@ -85,11 +69,11 @@ declare function getAccount(): Promise<string | undefined>;
85
69
 
86
70
  /**
87
71
  * Signs and sends a transaction using the Phantom provider.
88
- * @param transaction The transaction to sign and send.
72
+ * @param transaction The transaction to sign and send (Web3.js format).
89
73
  * @returns A promise that resolves with the transaction signature and optionally the public key.
90
74
  * @throws Error if Phantom provider is not found or if the operation fails.
91
75
  */
92
- declare function signAndSendTransaction(transaction: Transaction$1 | VersionedTransaction$1): Promise<{
76
+ declare function signAndSendTransaction(transaction: VersionedTransaction | Transaction): Promise<{
93
77
  signature: string;
94
78
  address?: string;
95
79
  }>;
@@ -136,4 +120,4 @@ declare module "../index" {
136
120
  }
137
121
  }
138
122
 
139
- export { PhantomSolanaProvider, SolanaSignInData, createSolanaPlugin };
123
+ export { PhantomSolanaProvider, Solana, SolanaSignInData, createSolanaPlugin };
@@ -37,20 +37,7 @@ __export(solana_exports, {
37
37
  });
38
38
  module.exports = __toCommonJS(solana_exports);
39
39
 
40
- // src/solana/utils/transactionToVersionedTransaction.ts
41
- var import_transactions = require("@solana/transactions");
42
- function transactionToVersionedTransaction(transaction) {
43
- const serialized = (0, import_transactions.getTransactionEncoder)().encode(transaction);
44
- const fakeVersioned = {
45
- serialize() {
46
- return new Uint8Array(serialized);
47
- }
48
- };
49
- return fakeVersioned;
50
- }
51
-
52
40
  // src/solana/strategies/injected.ts
53
- var import_compat = require("@solana/compat");
54
41
  var MAX_RETRIES = 4;
55
42
  var BASE_DELAY = 100;
56
43
  var _getProvider, getProvider_fn;
@@ -147,8 +134,7 @@ var InjectedSolanaStrategy = class {
147
134
  if (!provider.isConnected) {
148
135
  throw new Error("Provider is not connected.");
149
136
  }
150
- const versionedTransaction = transactionToVersionedTransaction(transaction);
151
- const result = await provider.signAndSendTransaction(versionedTransaction);
137
+ const result = await provider.signAndSendTransaction(transaction);
152
138
  return {
153
139
  signature: result.signature,
154
140
  address: result.publicKey
@@ -162,10 +148,8 @@ var InjectedSolanaStrategy = class {
162
148
  if (!provider.isConnected) {
163
149
  throw new Error("Provider is not connected.");
164
150
  }
165
- const versionedTransaction = transactionToVersionedTransaction(transaction);
166
- const result = await provider.signTransaction(versionedTransaction);
167
- const responseTransaction = (0, import_compat.fromVersionedTransaction)(result);
168
- return responseTransaction;
151
+ const result = await provider.signTransaction(transaction);
152
+ return result;
169
153
  }
170
154
  async signAllTransactions(transactions) {
171
155
  const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
@@ -175,12 +159,8 @@ var InjectedSolanaStrategy = class {
175
159
  if (!provider.isConnected) {
176
160
  throw new Error("Provider is not connected.");
177
161
  }
178
- const versionedTransactions = transactions.map(
179
- (transaction) => transactionToVersionedTransaction(transaction)
180
- );
181
- const result = await provider.signAllTransactions(versionedTransactions);
182
- const responseTransactions = result.map((transaction) => (0, import_compat.fromVersionedTransaction)(transaction));
183
- return responseTransactions;
162
+ const result = await provider.signAllTransactions(transactions);
163
+ return result;
184
164
  }
185
165
  };
186
166
  _getProvider = new WeakSet();
@@ -233,7 +213,14 @@ var DeepLinkSolanaStrategy = class {
233
213
  });
234
214
  }
235
215
  async signAndSendTransaction(transaction) {
236
- const deeplink = `phantom://sign-and-send-transaction?transaction=${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}`;
237
224
  window.location.href = deeplink;
238
225
  return Promise.resolve({
239
226
  signature: "",
@@ -241,12 +228,28 @@ var DeepLinkSolanaStrategy = class {
241
228
  });
242
229
  }
243
230
  async signTransaction(transaction) {
244
- const deeplink = `phantom://sign-transaction?transaction=${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}`;
245
239
  window.location.href = deeplink;
246
240
  return Promise.resolve(transaction);
247
241
  }
248
242
  async signAllTransactions(transactions) {
249
- const deeplink = `phantom://sign-all-transactions?transactions=${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)}`;
250
253
  window.location.href = deeplink;
251
254
  return Promise.resolve(transactions);
252
255
  }
@@ -347,7 +350,6 @@ async function getAccount() {
347
350
  }
348
351
 
349
352
  // src/solana/signAndSendTransaction.ts
350
- var import_compat2 = require("@solana/compat");
351
353
  async function signAndSendTransaction(transaction) {
352
354
  const provider = await getProvider();
353
355
  if (!provider) {
@@ -356,13 +358,7 @@ async function signAndSendTransaction(transaction) {
356
358
  if (!provider.isConnected) {
357
359
  await provider.connect({ onlyIfTrusted: false });
358
360
  }
359
- let kitTransaction;
360
- if (transaction?.messageBytes == null) {
361
- kitTransaction = (0, import_compat2.fromVersionedTransaction)(transaction);
362
- } else {
363
- kitTransaction = transaction;
364
- }
365
- return provider.signAndSendTransaction(kitTransaction);
361
+ return provider.signAndSendTransaction(transaction);
366
362
  }
367
363
 
368
364
  // src/solana/signIn.ts
@@ -4,20 +4,7 @@ import {
4
4
  __privateMethod
5
5
  } from "../chunk-GV6AIHPN.mjs";
6
6
 
7
- // src/solana/utils/transactionToVersionedTransaction.ts
8
- import { getTransactionEncoder } from "@solana/transactions";
9
- function transactionToVersionedTransaction(transaction) {
10
- const serialized = getTransactionEncoder().encode(transaction);
11
- const fakeVersioned = {
12
- serialize() {
13
- return new Uint8Array(serialized);
14
- }
15
- };
16
- return fakeVersioned;
17
- }
18
-
19
7
  // src/solana/strategies/injected.ts
20
- import { fromVersionedTransaction } from "@solana/compat";
21
8
  var MAX_RETRIES = 4;
22
9
  var BASE_DELAY = 100;
23
10
  var _getProvider, getProvider_fn;
@@ -114,8 +101,7 @@ var InjectedSolanaStrategy = class {
114
101
  if (!provider.isConnected) {
115
102
  throw new Error("Provider is not connected.");
116
103
  }
117
- const versionedTransaction = transactionToVersionedTransaction(transaction);
118
- const result = await provider.signAndSendTransaction(versionedTransaction);
104
+ const result = await provider.signAndSendTransaction(transaction);
119
105
  return {
120
106
  signature: result.signature,
121
107
  address: result.publicKey
@@ -129,10 +115,8 @@ var InjectedSolanaStrategy = class {
129
115
  if (!provider.isConnected) {
130
116
  throw new Error("Provider is not connected.");
131
117
  }
132
- const versionedTransaction = transactionToVersionedTransaction(transaction);
133
- const result = await provider.signTransaction(versionedTransaction);
134
- const responseTransaction = fromVersionedTransaction(result);
135
- return responseTransaction;
118
+ const result = await provider.signTransaction(transaction);
119
+ return result;
136
120
  }
137
121
  async signAllTransactions(transactions) {
138
122
  const provider = __privateMethod(this, _getProvider, getProvider_fn).call(this);
@@ -142,12 +126,8 @@ var InjectedSolanaStrategy = class {
142
126
  if (!provider.isConnected) {
143
127
  throw new Error("Provider is not connected.");
144
128
  }
145
- const versionedTransactions = transactions.map(
146
- (transaction) => transactionToVersionedTransaction(transaction)
147
- );
148
- const result = await provider.signAllTransactions(versionedTransactions);
149
- const responseTransactions = result.map((transaction) => fromVersionedTransaction(transaction));
150
- return responseTransactions;
129
+ const result = await provider.signAllTransactions(transactions);
130
+ return result;
151
131
  }
152
132
  };
153
133
  _getProvider = new WeakSet();
@@ -200,7 +180,14 @@ var DeepLinkSolanaStrategy = class {
200
180
  });
201
181
  }
202
182
  async signAndSendTransaction(transaction) {
203
- const deeplink = `phantom://sign-and-send-transaction?transaction=${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}`;
204
191
  window.location.href = deeplink;
205
192
  return Promise.resolve({
206
193
  signature: "",
@@ -208,12 +195,28 @@ var DeepLinkSolanaStrategy = class {
208
195
  });
209
196
  }
210
197
  async signTransaction(transaction) {
211
- const deeplink = `phantom://sign-transaction?transaction=${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}`;
212
206
  window.location.href = deeplink;
213
207
  return Promise.resolve(transaction);
214
208
  }
215
209
  async signAllTransactions(transactions) {
216
- const deeplink = `phantom://sign-all-transactions?transactions=${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)}`;
217
220
  window.location.href = deeplink;
218
221
  return Promise.resolve(transactions);
219
222
  }
@@ -314,7 +317,6 @@ async function getAccount() {
314
317
  }
315
318
 
316
319
  // src/solana/signAndSendTransaction.ts
317
- import { fromVersionedTransaction as fromVersionedTransaction2 } from "@solana/compat";
318
320
  async function signAndSendTransaction(transaction) {
319
321
  const provider = await getProvider();
320
322
  if (!provider) {
@@ -323,13 +325,7 @@ async function signAndSendTransaction(transaction) {
323
325
  if (!provider.isConnected) {
324
326
  await provider.connect({ onlyIfTrusted: false });
325
327
  }
326
- let kitTransaction;
327
- if (transaction?.messageBytes == null) {
328
- kitTransaction = fromVersionedTransaction2(transaction);
329
- } else {
330
- kitTransaction = transaction;
331
- }
332
- return provider.signAndSendTransaction(kitTransaction);
328
+ return provider.signAndSendTransaction(transaction);
333
329
  }
334
330
 
335
331
  // src/solana/signIn.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/browser-injected-sdk",
3
- "version": "0.0.9",
3
+ "version": "1.0.0-beta.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -37,11 +37,15 @@
37
37
  "build:watch": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/auto-confirm/index.ts src/ethereum/index.ts --format cjs,esm --dts --watch",
38
38
  "dev": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/auto-confirm/index.ts src/ethereum/index.ts --format cjs,esm --dts --watch",
39
39
  "lint": "tsc --noEmit && eslint --cache . --ext .ts,.tsx",
40
+ "check-types": "tsc --noEmit",
40
41
  "test": "jest",
41
42
  "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
42
43
  },
44
+ "dependencies": {
45
+ "@phantom/constants": "^1.0.0-beta.0",
46
+ "@solana/web3.js": "^1.98.2"
47
+ },
43
48
  "devDependencies": {
44
- "@solana/web3.js": "^1.98.2",
45
49
  "@types/jest": "^29.5.14",
46
50
  "eslint": "8.53.0",
47
51
  "jest": "^29.7.0",
@@ -50,11 +54,6 @@
50
54
  "tsup": "^6.7.0",
51
55
  "typescript": "^5.0.4"
52
56
  },
53
- "dependencies": {
54
- "@solana/compat": "2.1.1",
55
- "@solana/kit": "^2.1.1",
56
- "@solana/transactions": "^2.1.1"
57
- },
58
57
  "publishConfig": {
59
58
  "directory": "_release/package"
60
59
  }