@phantom/browser-sdk 0.0.6 → 0.0.8
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/solana/index.d.ts +2 -1
- package/dist/solana/index.js +223 -9
- package/dist/solana/index.mjs +223 -9
- package/package.json +1 -1
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChainPlugin } from '../index.js';
|
|
2
2
|
import { Transaction as Transaction$1 } from '@solana/kit';
|
|
3
|
+
import { VersionedTransaction as VersionedTransaction$1 } from '@solana/web3.js';
|
|
3
4
|
|
|
4
5
|
declare function connect(): Promise<string | undefined>;
|
|
5
6
|
|
|
@@ -88,7 +89,7 @@ declare function getAccount(): Promise<string | undefined>;
|
|
|
88
89
|
* @returns A promise that resolves with the transaction signature and optionally the public key.
|
|
89
90
|
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
90
91
|
*/
|
|
91
|
-
declare function signAndSendTransaction(transaction: Transaction$1): Promise<{
|
|
92
|
+
declare function signAndSendTransaction(transaction: Transaction$1 | VersionedTransaction$1): Promise<{
|
|
92
93
|
signature: string;
|
|
93
94
|
address?: string;
|
|
94
95
|
}>;
|
package/dist/solana/index.js
CHANGED
|
@@ -187,14 +187,217 @@ getProvider_fn = function() {
|
|
|
187
187
|
return window?.phantom?.solana;
|
|
188
188
|
};
|
|
189
189
|
|
|
190
|
+
// src/solana/adapters/kms.ts
|
|
191
|
+
var API_URL = "https://api.phantom.app/v1/wallet";
|
|
192
|
+
var _getJwtToken, getJwtToken_fn;
|
|
193
|
+
var KmsSolanaAdapter = class {
|
|
194
|
+
constructor() {
|
|
195
|
+
__privateAdd(this, _getJwtToken);
|
|
196
|
+
}
|
|
197
|
+
load() {
|
|
198
|
+
return Promise.resolve(this);
|
|
199
|
+
}
|
|
200
|
+
get isConnected() {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
async connect({ onlyIfTrusted }) {
|
|
204
|
+
return fetch(`${API_URL}/connect`, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
"Content-Type": "application/json",
|
|
208
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
209
|
+
},
|
|
210
|
+
body: JSON.stringify({
|
|
211
|
+
onlyIfTrusted
|
|
212
|
+
})
|
|
213
|
+
}).then((res) => res.json()).then((data) => data.publicKey);
|
|
214
|
+
}
|
|
215
|
+
async disconnect() {
|
|
216
|
+
const response = await fetch(`${API_URL}/disconnect`, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
headers: {
|
|
219
|
+
"Content-Type": "application/json",
|
|
220
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
221
|
+
}
|
|
222
|
+
}).then((res) => res.json()).then((data) => data.disconnected);
|
|
223
|
+
if (!response) {
|
|
224
|
+
throw new Error("Failed to disconnect wallet.");
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
async getAccount() {
|
|
229
|
+
return fetch(`${API_URL}/account`, {
|
|
230
|
+
method: "GET",
|
|
231
|
+
headers: {
|
|
232
|
+
"Content-Type": "application/json",
|
|
233
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
234
|
+
}
|
|
235
|
+
}).then((res) => res.json()).then((data) => data.publicKey);
|
|
236
|
+
}
|
|
237
|
+
async signMessage(message, display) {
|
|
238
|
+
return fetch(`${API_URL}/sign-message`, {
|
|
239
|
+
method: "POST",
|
|
240
|
+
headers: {
|
|
241
|
+
"Content-Type": "application/json",
|
|
242
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
243
|
+
},
|
|
244
|
+
body: JSON.stringify({
|
|
245
|
+
message,
|
|
246
|
+
display
|
|
247
|
+
})
|
|
248
|
+
}).then((res) => res.json()).then((data) => {
|
|
249
|
+
return {
|
|
250
|
+
signature: new Uint8Array(Buffer.from(data.signature, "base64")),
|
|
251
|
+
address: data.publicKey
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
async signIn(signInData) {
|
|
256
|
+
return fetch(`${API_URL}/sign-in`, {
|
|
257
|
+
method: "POST",
|
|
258
|
+
headers: {
|
|
259
|
+
"Content-Type": "application/json",
|
|
260
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
261
|
+
},
|
|
262
|
+
body: JSON.stringify({
|
|
263
|
+
signInData
|
|
264
|
+
})
|
|
265
|
+
}).then((res) => res.json()).then((data) => {
|
|
266
|
+
return {
|
|
267
|
+
address: data.address,
|
|
268
|
+
signature: new Uint8Array(Buffer.from(data.signature, "base64")),
|
|
269
|
+
signedMessage: new Uint8Array(Buffer.from(data.signedMessage, "base64"))
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async signAndSendTransaction(transaction) {
|
|
274
|
+
return fetch(`${API_URL}/sign-and-send-transaction`, {
|
|
275
|
+
method: "POST",
|
|
276
|
+
headers: {
|
|
277
|
+
"Content-Type": "application/json",
|
|
278
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
279
|
+
},
|
|
280
|
+
body: JSON.stringify({
|
|
281
|
+
transaction
|
|
282
|
+
})
|
|
283
|
+
}).then((res) => res.json()).then((data) => {
|
|
284
|
+
return {
|
|
285
|
+
signature: data.signature,
|
|
286
|
+
address: data.publicKey
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
async signTransaction(transaction) {
|
|
291
|
+
return fetch(`${API_URL}/sign-transaction`, {
|
|
292
|
+
method: "POST",
|
|
293
|
+
headers: {
|
|
294
|
+
"Content-Type": "application/json",
|
|
295
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
296
|
+
},
|
|
297
|
+
body: JSON.stringify({
|
|
298
|
+
transaction
|
|
299
|
+
})
|
|
300
|
+
}).then((res) => res.json()).then((data) => {
|
|
301
|
+
return data;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
async signAllTransactions(transactions) {
|
|
305
|
+
return fetch(`${API_URL}/sign-all-transactions`, {
|
|
306
|
+
method: "POST",
|
|
307
|
+
headers: {
|
|
308
|
+
"Content-Type": "application/json",
|
|
309
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
310
|
+
},
|
|
311
|
+
body: JSON.stringify({
|
|
312
|
+
transactions
|
|
313
|
+
})
|
|
314
|
+
}).then((res) => res.json()).then((data) => {
|
|
315
|
+
return data;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
_getJwtToken = new WeakSet();
|
|
320
|
+
getJwtToken_fn = function() {
|
|
321
|
+
return localStorage.getItem("phantom-solana-kms-jwt");
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// src/solana/adapters/deeplinks.ts
|
|
325
|
+
var DeepLinkSolanaAdapter = class {
|
|
326
|
+
load() {
|
|
327
|
+
return Promise.resolve(this);
|
|
328
|
+
}
|
|
329
|
+
get isConnected() {
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
async connect({ onlyIfTrusted }) {
|
|
333
|
+
const deeplink = `phantom://connect?onlyIfTrusted=${onlyIfTrusted}`;
|
|
334
|
+
window.location.href = deeplink;
|
|
335
|
+
return Promise.resolve(void 0);
|
|
336
|
+
}
|
|
337
|
+
async disconnect() {
|
|
338
|
+
const deeplink = `phantom://disconnect`;
|
|
339
|
+
window.location.href = deeplink;
|
|
340
|
+
return Promise.resolve();
|
|
341
|
+
}
|
|
342
|
+
async getAccount() {
|
|
343
|
+
const deeplink = `phantom://account`;
|
|
344
|
+
window.location.href = deeplink;
|
|
345
|
+
return Promise.resolve(void 0);
|
|
346
|
+
}
|
|
347
|
+
async signMessage(message, display) {
|
|
348
|
+
const messageEncoded = Buffer.from(message).toString("base64");
|
|
349
|
+
const deeplink = `phantom://sign-message?message=${messageEncoded}&display=${display}`;
|
|
350
|
+
window.location.href = deeplink;
|
|
351
|
+
return Promise.resolve({
|
|
352
|
+
signature: new Uint8Array(),
|
|
353
|
+
address: ""
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
async signIn(signInData) {
|
|
357
|
+
const deeplink = `phantom://sign-in?signInData=${encodeURIComponent(JSON.stringify(signInData))}`;
|
|
358
|
+
window.location.href = deeplink;
|
|
359
|
+
return Promise.resolve({
|
|
360
|
+
address: "",
|
|
361
|
+
signature: new Uint8Array(),
|
|
362
|
+
signedMessage: new Uint8Array()
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
async signAndSendTransaction(transaction) {
|
|
366
|
+
const deeplink = `phantom://sign-and-send-transaction?transaction=${transaction}`;
|
|
367
|
+
window.location.href = deeplink;
|
|
368
|
+
return Promise.resolve({
|
|
369
|
+
signature: "",
|
|
370
|
+
address: ""
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async signTransaction(transaction) {
|
|
374
|
+
const deeplink = `phantom://sign-transaction?transaction=${transaction}`;
|
|
375
|
+
window.location.href = deeplink;
|
|
376
|
+
return Promise.resolve(transaction);
|
|
377
|
+
}
|
|
378
|
+
async signAllTransactions(transactions) {
|
|
379
|
+
const deeplink = `phantom://sign-all-transactions?transactions=${transactions}`;
|
|
380
|
+
window.location.href = deeplink;
|
|
381
|
+
return Promise.resolve(transactions);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
190
385
|
// src/solana/getAdapter.ts
|
|
191
|
-
async function getAdapter(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
386
|
+
async function getAdapter(type = "injected") {
|
|
387
|
+
if (type === "injected") {
|
|
388
|
+
const adapter = new InjectedSolanaAdapter();
|
|
389
|
+
try {
|
|
390
|
+
await adapter.load();
|
|
391
|
+
return adapter;
|
|
392
|
+
} catch (error) {
|
|
393
|
+
throw new Error("Phantom provider not found.");
|
|
394
|
+
}
|
|
395
|
+
} else if (type === "kms") {
|
|
396
|
+
return new KmsSolanaAdapter();
|
|
397
|
+
} else if (type === "deeplink") {
|
|
398
|
+
return new DeepLinkSolanaAdapter();
|
|
399
|
+
} else {
|
|
400
|
+
throw new Error("Invalid adapter type.");
|
|
198
401
|
}
|
|
199
402
|
}
|
|
200
403
|
|
|
@@ -276,6 +479,7 @@ async function getAccount() {
|
|
|
276
479
|
}
|
|
277
480
|
|
|
278
481
|
// src/solana/signAndSendTransaction.ts
|
|
482
|
+
var import_compat2 = require("@solana/compat");
|
|
279
483
|
async function signAndSendTransaction(transaction) {
|
|
280
484
|
const adapter = await getAdapter();
|
|
281
485
|
if (!adapter) {
|
|
@@ -284,7 +488,13 @@ async function signAndSendTransaction(transaction) {
|
|
|
284
488
|
if (!adapter.isConnected) {
|
|
285
489
|
await adapter.connect({ onlyIfTrusted: false });
|
|
286
490
|
}
|
|
287
|
-
|
|
491
|
+
let kitTransaction;
|
|
492
|
+
if (transaction?.messageBytes == null) {
|
|
493
|
+
kitTransaction = (0, import_compat2.fromVersionedTransaction)(transaction);
|
|
494
|
+
} else {
|
|
495
|
+
kitTransaction = transaction;
|
|
496
|
+
}
|
|
497
|
+
return adapter.signAndSendTransaction(kitTransaction);
|
|
288
498
|
}
|
|
289
499
|
|
|
290
500
|
// src/solana/signIn.ts
|
|
@@ -293,7 +503,11 @@ async function signIn(signInData) {
|
|
|
293
503
|
if (!adapter) {
|
|
294
504
|
throw new Error("Adapter not found.");
|
|
295
505
|
}
|
|
296
|
-
|
|
506
|
+
const result = await adapter.signIn(signInData);
|
|
507
|
+
if (result.address) {
|
|
508
|
+
triggerEvent("connect", result.address);
|
|
509
|
+
}
|
|
510
|
+
return result;
|
|
297
511
|
}
|
|
298
512
|
|
|
299
513
|
// src/solana/signMessage.ts
|
package/dist/solana/index.mjs
CHANGED
|
@@ -153,14 +153,217 @@ getProvider_fn = function() {
|
|
|
153
153
|
return window?.phantom?.solana;
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
+
// src/solana/adapters/kms.ts
|
|
157
|
+
var API_URL = "https://api.phantom.app/v1/wallet";
|
|
158
|
+
var _getJwtToken, getJwtToken_fn;
|
|
159
|
+
var KmsSolanaAdapter = class {
|
|
160
|
+
constructor() {
|
|
161
|
+
__privateAdd(this, _getJwtToken);
|
|
162
|
+
}
|
|
163
|
+
load() {
|
|
164
|
+
return Promise.resolve(this);
|
|
165
|
+
}
|
|
166
|
+
get isConnected() {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
async connect({ onlyIfTrusted }) {
|
|
170
|
+
return fetch(`${API_URL}/connect`, {
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers: {
|
|
173
|
+
"Content-Type": "application/json",
|
|
174
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
175
|
+
},
|
|
176
|
+
body: JSON.stringify({
|
|
177
|
+
onlyIfTrusted
|
|
178
|
+
})
|
|
179
|
+
}).then((res) => res.json()).then((data) => data.publicKey);
|
|
180
|
+
}
|
|
181
|
+
async disconnect() {
|
|
182
|
+
const response = await fetch(`${API_URL}/disconnect`, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: {
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
187
|
+
}
|
|
188
|
+
}).then((res) => res.json()).then((data) => data.disconnected);
|
|
189
|
+
if (!response) {
|
|
190
|
+
throw new Error("Failed to disconnect wallet.");
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
async getAccount() {
|
|
195
|
+
return fetch(`${API_URL}/account`, {
|
|
196
|
+
method: "GET",
|
|
197
|
+
headers: {
|
|
198
|
+
"Content-Type": "application/json",
|
|
199
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
200
|
+
}
|
|
201
|
+
}).then((res) => res.json()).then((data) => data.publicKey);
|
|
202
|
+
}
|
|
203
|
+
async signMessage(message, display) {
|
|
204
|
+
return fetch(`${API_URL}/sign-message`, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
"Content-Type": "application/json",
|
|
208
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
209
|
+
},
|
|
210
|
+
body: JSON.stringify({
|
|
211
|
+
message,
|
|
212
|
+
display
|
|
213
|
+
})
|
|
214
|
+
}).then((res) => res.json()).then((data) => {
|
|
215
|
+
return {
|
|
216
|
+
signature: new Uint8Array(Buffer.from(data.signature, "base64")),
|
|
217
|
+
address: data.publicKey
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async signIn(signInData) {
|
|
222
|
+
return fetch(`${API_URL}/sign-in`, {
|
|
223
|
+
method: "POST",
|
|
224
|
+
headers: {
|
|
225
|
+
"Content-Type": "application/json",
|
|
226
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
227
|
+
},
|
|
228
|
+
body: JSON.stringify({
|
|
229
|
+
signInData
|
|
230
|
+
})
|
|
231
|
+
}).then((res) => res.json()).then((data) => {
|
|
232
|
+
return {
|
|
233
|
+
address: data.address,
|
|
234
|
+
signature: new Uint8Array(Buffer.from(data.signature, "base64")),
|
|
235
|
+
signedMessage: new Uint8Array(Buffer.from(data.signedMessage, "base64"))
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
async signAndSendTransaction(transaction) {
|
|
240
|
+
return fetch(`${API_URL}/sign-and-send-transaction`, {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: {
|
|
243
|
+
"Content-Type": "application/json",
|
|
244
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
245
|
+
},
|
|
246
|
+
body: JSON.stringify({
|
|
247
|
+
transaction
|
|
248
|
+
})
|
|
249
|
+
}).then((res) => res.json()).then((data) => {
|
|
250
|
+
return {
|
|
251
|
+
signature: data.signature,
|
|
252
|
+
address: data.publicKey
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async signTransaction(transaction) {
|
|
257
|
+
return fetch(`${API_URL}/sign-transaction`, {
|
|
258
|
+
method: "POST",
|
|
259
|
+
headers: {
|
|
260
|
+
"Content-Type": "application/json",
|
|
261
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
262
|
+
},
|
|
263
|
+
body: JSON.stringify({
|
|
264
|
+
transaction
|
|
265
|
+
})
|
|
266
|
+
}).then((res) => res.json()).then((data) => {
|
|
267
|
+
return data;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
async signAllTransactions(transactions) {
|
|
271
|
+
return fetch(`${API_URL}/sign-all-transactions`, {
|
|
272
|
+
method: "POST",
|
|
273
|
+
headers: {
|
|
274
|
+
"Content-Type": "application/json",
|
|
275
|
+
Authorization: `Bearer ${__privateMethod(this, _getJwtToken, getJwtToken_fn).call(this)}`
|
|
276
|
+
},
|
|
277
|
+
body: JSON.stringify({
|
|
278
|
+
transactions
|
|
279
|
+
})
|
|
280
|
+
}).then((res) => res.json()).then((data) => {
|
|
281
|
+
return data;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
_getJwtToken = new WeakSet();
|
|
286
|
+
getJwtToken_fn = function() {
|
|
287
|
+
return localStorage.getItem("phantom-solana-kms-jwt");
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/solana/adapters/deeplinks.ts
|
|
291
|
+
var DeepLinkSolanaAdapter = class {
|
|
292
|
+
load() {
|
|
293
|
+
return Promise.resolve(this);
|
|
294
|
+
}
|
|
295
|
+
get isConnected() {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
async connect({ onlyIfTrusted }) {
|
|
299
|
+
const deeplink = `phantom://connect?onlyIfTrusted=${onlyIfTrusted}`;
|
|
300
|
+
window.location.href = deeplink;
|
|
301
|
+
return Promise.resolve(void 0);
|
|
302
|
+
}
|
|
303
|
+
async disconnect() {
|
|
304
|
+
const deeplink = `phantom://disconnect`;
|
|
305
|
+
window.location.href = deeplink;
|
|
306
|
+
return Promise.resolve();
|
|
307
|
+
}
|
|
308
|
+
async getAccount() {
|
|
309
|
+
const deeplink = `phantom://account`;
|
|
310
|
+
window.location.href = deeplink;
|
|
311
|
+
return Promise.resolve(void 0);
|
|
312
|
+
}
|
|
313
|
+
async signMessage(message, display) {
|
|
314
|
+
const messageEncoded = Buffer.from(message).toString("base64");
|
|
315
|
+
const deeplink = `phantom://sign-message?message=${messageEncoded}&display=${display}`;
|
|
316
|
+
window.location.href = deeplink;
|
|
317
|
+
return Promise.resolve({
|
|
318
|
+
signature: new Uint8Array(),
|
|
319
|
+
address: ""
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
async signIn(signInData) {
|
|
323
|
+
const deeplink = `phantom://sign-in?signInData=${encodeURIComponent(JSON.stringify(signInData))}`;
|
|
324
|
+
window.location.href = deeplink;
|
|
325
|
+
return Promise.resolve({
|
|
326
|
+
address: "",
|
|
327
|
+
signature: new Uint8Array(),
|
|
328
|
+
signedMessage: new Uint8Array()
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
async signAndSendTransaction(transaction) {
|
|
332
|
+
const deeplink = `phantom://sign-and-send-transaction?transaction=${transaction}`;
|
|
333
|
+
window.location.href = deeplink;
|
|
334
|
+
return Promise.resolve({
|
|
335
|
+
signature: "",
|
|
336
|
+
address: ""
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async signTransaction(transaction) {
|
|
340
|
+
const deeplink = `phantom://sign-transaction?transaction=${transaction}`;
|
|
341
|
+
window.location.href = deeplink;
|
|
342
|
+
return Promise.resolve(transaction);
|
|
343
|
+
}
|
|
344
|
+
async signAllTransactions(transactions) {
|
|
345
|
+
const deeplink = `phantom://sign-all-transactions?transactions=${transactions}`;
|
|
346
|
+
window.location.href = deeplink;
|
|
347
|
+
return Promise.resolve(transactions);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
156
351
|
// src/solana/getAdapter.ts
|
|
157
|
-
async function getAdapter(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
352
|
+
async function getAdapter(type = "injected") {
|
|
353
|
+
if (type === "injected") {
|
|
354
|
+
const adapter = new InjectedSolanaAdapter();
|
|
355
|
+
try {
|
|
356
|
+
await adapter.load();
|
|
357
|
+
return adapter;
|
|
358
|
+
} catch (error) {
|
|
359
|
+
throw new Error("Phantom provider not found.");
|
|
360
|
+
}
|
|
361
|
+
} else if (type === "kms") {
|
|
362
|
+
return new KmsSolanaAdapter();
|
|
363
|
+
} else if (type === "deeplink") {
|
|
364
|
+
return new DeepLinkSolanaAdapter();
|
|
365
|
+
} else {
|
|
366
|
+
throw new Error("Invalid adapter type.");
|
|
164
367
|
}
|
|
165
368
|
}
|
|
166
369
|
|
|
@@ -242,6 +445,7 @@ async function getAccount() {
|
|
|
242
445
|
}
|
|
243
446
|
|
|
244
447
|
// src/solana/signAndSendTransaction.ts
|
|
448
|
+
import { fromVersionedTransaction as fromVersionedTransaction2 } from "@solana/compat";
|
|
245
449
|
async function signAndSendTransaction(transaction) {
|
|
246
450
|
const adapter = await getAdapter();
|
|
247
451
|
if (!adapter) {
|
|
@@ -250,7 +454,13 @@ async function signAndSendTransaction(transaction) {
|
|
|
250
454
|
if (!adapter.isConnected) {
|
|
251
455
|
await adapter.connect({ onlyIfTrusted: false });
|
|
252
456
|
}
|
|
253
|
-
|
|
457
|
+
let kitTransaction;
|
|
458
|
+
if (transaction?.messageBytes == null) {
|
|
459
|
+
kitTransaction = fromVersionedTransaction2(transaction);
|
|
460
|
+
} else {
|
|
461
|
+
kitTransaction = transaction;
|
|
462
|
+
}
|
|
463
|
+
return adapter.signAndSendTransaction(kitTransaction);
|
|
254
464
|
}
|
|
255
465
|
|
|
256
466
|
// src/solana/signIn.ts
|
|
@@ -259,7 +469,11 @@ async function signIn(signInData) {
|
|
|
259
469
|
if (!adapter) {
|
|
260
470
|
throw new Error("Adapter not found.");
|
|
261
471
|
}
|
|
262
|
-
|
|
472
|
+
const result = await adapter.signIn(signInData);
|
|
473
|
+
if (result.address) {
|
|
474
|
+
triggerEvent("connect", result.address);
|
|
475
|
+
}
|
|
476
|
+
return result;
|
|
263
477
|
}
|
|
264
478
|
|
|
265
479
|
// src/solana/signMessage.ts
|