@phantom/browser-injected-sdk 0.0.9 → 0.0.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/README.md +0 -2
- package/dist/solana/index.d.ts +2 -18
- package/dist/solana/index.js +6 -33
- package/dist/solana/index.mjs +6 -33
- package/package.json +5 -7
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:**
|
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { P as Plugin } from '../index-2f448acb.js';
|
|
2
|
-
import { Transaction
|
|
3
|
-
import { VersionedTransaction as VersionedTransaction$1 } from '@solana/web3.js';
|
|
2
|
+
import { Transaction, VersionedTransaction } 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;
|
|
@@ -89,7 +73,7 @@ declare function getAccount(): Promise<string | undefined>;
|
|
|
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
|
|
76
|
+
declare function signAndSendTransaction(transaction: Transaction | VersionedTransaction): Promise<{
|
|
93
77
|
signature: string;
|
|
94
78
|
address?: string;
|
|
95
79
|
}>;
|
package/dist/solana/index.js
CHANGED
|
@@ -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
|
|
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
|
|
166
|
-
|
|
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
|
|
179
|
-
|
|
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();
|
|
@@ -347,7 +327,6 @@ async function getAccount() {
|
|
|
347
327
|
}
|
|
348
328
|
|
|
349
329
|
// src/solana/signAndSendTransaction.ts
|
|
350
|
-
var import_compat2 = require("@solana/compat");
|
|
351
330
|
async function signAndSendTransaction(transaction) {
|
|
352
331
|
const provider = await getProvider();
|
|
353
332
|
if (!provider) {
|
|
@@ -356,13 +335,7 @@ async function signAndSendTransaction(transaction) {
|
|
|
356
335
|
if (!provider.isConnected) {
|
|
357
336
|
await provider.connect({ onlyIfTrusted: false });
|
|
358
337
|
}
|
|
359
|
-
|
|
360
|
-
if (transaction?.messageBytes == null) {
|
|
361
|
-
kitTransaction = (0, import_compat2.fromVersionedTransaction)(transaction);
|
|
362
|
-
} else {
|
|
363
|
-
kitTransaction = transaction;
|
|
364
|
-
}
|
|
365
|
-
return provider.signAndSendTransaction(kitTransaction);
|
|
338
|
+
return provider.signAndSendTransaction(transaction);
|
|
366
339
|
}
|
|
367
340
|
|
|
368
341
|
// src/solana/signIn.ts
|
package/dist/solana/index.mjs
CHANGED
|
@@ -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
|
|
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
|
|
133
|
-
|
|
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
|
|
146
|
-
|
|
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();
|
|
@@ -314,7 +294,6 @@ async function getAccount() {
|
|
|
314
294
|
}
|
|
315
295
|
|
|
316
296
|
// src/solana/signAndSendTransaction.ts
|
|
317
|
-
import { fromVersionedTransaction as fromVersionedTransaction2 } from "@solana/compat";
|
|
318
297
|
async function signAndSendTransaction(transaction) {
|
|
319
298
|
const provider = await getProvider();
|
|
320
299
|
if (!provider) {
|
|
@@ -323,13 +302,7 @@ async function signAndSendTransaction(transaction) {
|
|
|
323
302
|
if (!provider.isConnected) {
|
|
324
303
|
await provider.connect({ onlyIfTrusted: false });
|
|
325
304
|
}
|
|
326
|
-
|
|
327
|
-
if (transaction?.messageBytes == null) {
|
|
328
|
-
kitTransaction = fromVersionedTransaction2(transaction);
|
|
329
|
-
} else {
|
|
330
|
-
kitTransaction = transaction;
|
|
331
|
-
}
|
|
332
|
-
return provider.signAndSendTransaction(kitTransaction);
|
|
305
|
+
return provider.signAndSendTransaction(transaction);
|
|
333
306
|
}
|
|
334
307
|
|
|
335
308
|
// 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.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,11 +37,14 @@
|
|
|
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
|
+
"@solana/web3.js": "^1.98.2"
|
|
46
|
+
},
|
|
43
47
|
"devDependencies": {
|
|
44
|
-
"@solana/web3.js": "^1.98.2",
|
|
45
48
|
"@types/jest": "^29.5.14",
|
|
46
49
|
"eslint": "8.53.0",
|
|
47
50
|
"jest": "^29.7.0",
|
|
@@ -50,11 +53,6 @@
|
|
|
50
53
|
"tsup": "^6.7.0",
|
|
51
54
|
"typescript": "^5.0.4"
|
|
52
55
|
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"@solana/compat": "2.1.1",
|
|
55
|
-
"@solana/kit": "^2.1.1",
|
|
56
|
-
"@solana/transactions": "^2.1.1"
|
|
57
|
-
},
|
|
58
56
|
"publishConfig": {
|
|
59
57
|
"directory": "_release/package"
|
|
60
58
|
}
|