@vue-solana/core 0.5.1 → 0.7.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 +6 -3
- package/dist/address.cjs +9 -1
- package/dist/address.mjs +9 -1
- package/dist/errors.cjs +50 -0
- package/dist/errors.d.cts +17 -0
- package/dist/errors.d.mts +17 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.mjs +45 -0
- package/dist/index.cjs +13 -2
- package/dist/index.d.cts +4 -2
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +5 -3
- package/dist/ios-wallet.cjs +1 -1
- package/dist/ios-wallet.mjs +1 -1
- package/dist/shared/{core.DJZldB_x.cjs → core.BsekSwcZ.cjs} +87 -85
- package/dist/shared/{core.DSI7vIfT.mjs → core.Ch_Z7_17.mjs} +87 -85
- package/dist/shared/{core.D7olTUN_.mjs → core.DSMNiaHD.mjs} +23 -1
- package/dist/shared/{core.8V8PLE-S.cjs → core.DX2frf65.cjs} +22 -0
- package/dist/timeout.cjs +32 -0
- package/dist/timeout.d.cts +4 -0
- package/dist/timeout.d.mts +4 -0
- package/dist/timeout.d.ts +4 -0
- package/dist/timeout.mjs +29 -0
- package/dist/transaction.cjs +30 -30
- package/dist/transaction.mjs +30 -30
- package/dist/types.d.cts +8 -1
- package/dist/types.d.mts +8 -1
- package/dist/types.d.ts +8 -1
- package/dist/wallet-standard.cjs +1 -1
- package/dist/wallet-standard.mjs +1 -1
- package/dist/wallet.cjs +30 -2
- package/dist/wallet.d.cts +12 -1
- package/dist/wallet.d.mts +12 -1
- package/dist/wallet.d.ts +12 -1
- package/dist/wallet.mjs +28 -3
- package/package.json +11 -1
|
@@ -392,6 +392,92 @@ function deserializeTransaction(source, bytes) {
|
|
|
392
392
|
return VersionedTransaction.deserialize(bytes);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
function launchConnect(definition, options) {
|
|
396
|
+
const keyPair = nacl.box.keyPair();
|
|
397
|
+
const pending = createPendingRequest(definition.id, "connect", keyPair, options.redirectUrl);
|
|
398
|
+
const appIdentity = options.appIdentity ?? getDefaultIosWalletAppIdentity();
|
|
399
|
+
const url = new URL(definition.connectUrl);
|
|
400
|
+
url.searchParams.set("app_url", appIdentity.uri);
|
|
401
|
+
url.searchParams.set("dapp_encryption_public_key", pending.dappEncryptionPublicKey);
|
|
402
|
+
url.searchParams.set("redirect_link", pending.redirectUrl);
|
|
403
|
+
if (options.cluster && options.cluster !== "localnet") {
|
|
404
|
+
url.searchParams.set("cluster", options.cluster);
|
|
405
|
+
}
|
|
406
|
+
storePendingRequest(pending);
|
|
407
|
+
openIosWalletUrl(url.toString());
|
|
408
|
+
}
|
|
409
|
+
async function launchSignTransaction(definition, transaction, options) {
|
|
410
|
+
const response = await launchEncryptedWalletRequest(definition, "signTransaction", options, {
|
|
411
|
+
transaction: bs58.encode(serializeTransaction(transaction))
|
|
412
|
+
});
|
|
413
|
+
if (!response.transaction) {
|
|
414
|
+
throw new Error("iOS wallet did not return a signed transaction");
|
|
415
|
+
}
|
|
416
|
+
return response.transaction;
|
|
417
|
+
}
|
|
418
|
+
async function launchSignAllTransactions(definition, transactions, options) {
|
|
419
|
+
const response = await launchEncryptedWalletRequest(definition, "signAllTransactions", options, {
|
|
420
|
+
transactions: transactions.map((transaction) => bs58.encode(serializeTransaction(transaction)))
|
|
421
|
+
});
|
|
422
|
+
if (!response.transactions) {
|
|
423
|
+
throw new Error("iOS wallet did not return signed transactions");
|
|
424
|
+
}
|
|
425
|
+
return response.transactions;
|
|
426
|
+
}
|
|
427
|
+
async function launchSignAndSendTransaction(definition, transaction, sendOptions, options) {
|
|
428
|
+
const response = await launchEncryptedWalletRequest(
|
|
429
|
+
definition,
|
|
430
|
+
"signAndSendTransaction",
|
|
431
|
+
options,
|
|
432
|
+
{
|
|
433
|
+
transaction: bs58.encode(serializeTransaction(transaction)),
|
|
434
|
+
sendOptions
|
|
435
|
+
}
|
|
436
|
+
);
|
|
437
|
+
if (!response.signature) {
|
|
438
|
+
throw new Error("iOS wallet did not return a transaction signature");
|
|
439
|
+
}
|
|
440
|
+
return { signature: response.signature };
|
|
441
|
+
}
|
|
442
|
+
async function launchEncryptedWalletRequest(definition, method, options, payload) {
|
|
443
|
+
const session = getStoredSession(definition.id);
|
|
444
|
+
if (!session) {
|
|
445
|
+
throw new Error("Connect the iOS wallet before signing");
|
|
446
|
+
}
|
|
447
|
+
const methodUrl = getIosWalletMethodUrl(definition, method);
|
|
448
|
+
const pending = createPendingRequest(
|
|
449
|
+
definition.id,
|
|
450
|
+
method,
|
|
451
|
+
{
|
|
452
|
+
publicKey: bs58.decode(session.dappEncryptionPublicKey),
|
|
453
|
+
secretKey: bs58.decode(session.dappEncryptionSecretKey)
|
|
454
|
+
},
|
|
455
|
+
options.redirectUrl,
|
|
456
|
+
method === "signAllTransactions" && Array.isArray(payload.transactions) ? payload.transactions.length : void 0
|
|
457
|
+
);
|
|
458
|
+
const nonce = nacl.randomBytes(nacl.box.nonceLength);
|
|
459
|
+
const encryptedPayload = encryptPayload(
|
|
460
|
+
{ ...payload, session: session.session },
|
|
461
|
+
nonce,
|
|
462
|
+
bs58.decode(session.sharedSecret)
|
|
463
|
+
);
|
|
464
|
+
const url = new URL(methodUrl);
|
|
465
|
+
url.searchParams.set("dapp_encryption_public_key", session.dappEncryptionPublicKey);
|
|
466
|
+
url.searchParams.set("nonce", bs58.encode(nonce));
|
|
467
|
+
url.searchParams.set("redirect_link", pending.redirectUrl);
|
|
468
|
+
url.searchParams.set("payload", encryptedPayload);
|
|
469
|
+
storePendingRequest(pending);
|
|
470
|
+
openIosWalletUrl(url.toString());
|
|
471
|
+
return waitForRedirect();
|
|
472
|
+
}
|
|
473
|
+
function getIosWalletMethodUrl(definition, method) {
|
|
474
|
+
const url = definition[`${method}Url`];
|
|
475
|
+
if (!url) {
|
|
476
|
+
throw new Error(`${definition.name} does not support ${method} through iOS deeplinks`);
|
|
477
|
+
}
|
|
478
|
+
return url;
|
|
479
|
+
}
|
|
480
|
+
|
|
395
481
|
function getSolanaIosWallets(options = {}) {
|
|
396
482
|
if (!isSolanaIosBrowserWalletSupported()) {
|
|
397
483
|
return [];
|
|
@@ -409,6 +495,7 @@ function getSolanaIosWallets(options = {}) {
|
|
|
409
495
|
callbackUrl,
|
|
410
496
|
capabilities: {
|
|
411
497
|
connect: true,
|
|
498
|
+
disconnect: true,
|
|
412
499
|
signTransaction: Boolean(wallet.signTransactionUrl),
|
|
413
500
|
signAllTransactions: Boolean(wallet.signAllTransactionsUrl),
|
|
414
501
|
signAndSendTransaction: Boolean(wallet.signAndSendTransactionUrl)
|
|
@@ -491,91 +578,6 @@ function adaptSolanaIosWallet(walletInfo, options = {}) {
|
|
|
491
578
|
function isSolanaIosWalletInfo(walletInfo) {
|
|
492
579
|
return walletInfo.source === "deep-link" && isIosWalletDefinition(walletInfo.wallet);
|
|
493
580
|
}
|
|
494
|
-
function launchConnect(definition, options) {
|
|
495
|
-
const keyPair = nacl.box.keyPair();
|
|
496
|
-
const pending = createPendingRequest(definition.id, "connect", keyPair, options.redirectUrl);
|
|
497
|
-
const appIdentity = options.appIdentity ?? getDefaultIosWalletAppIdentity();
|
|
498
|
-
const url = new URL(definition.connectUrl);
|
|
499
|
-
url.searchParams.set("app_url", appIdentity.uri);
|
|
500
|
-
url.searchParams.set("dapp_encryption_public_key", pending.dappEncryptionPublicKey);
|
|
501
|
-
url.searchParams.set("redirect_link", pending.redirectUrl);
|
|
502
|
-
if (options.cluster && options.cluster !== "localnet") {
|
|
503
|
-
url.searchParams.set("cluster", options.cluster);
|
|
504
|
-
}
|
|
505
|
-
storePendingRequest(pending);
|
|
506
|
-
openIosWalletUrl(url.toString());
|
|
507
|
-
}
|
|
508
|
-
async function launchSignTransaction(definition, transaction, options) {
|
|
509
|
-
const response = await launchEncryptedWalletRequest(definition, "signTransaction", options, {
|
|
510
|
-
transaction: bs58.encode(serializeTransaction(transaction))
|
|
511
|
-
});
|
|
512
|
-
if (!response.transaction) {
|
|
513
|
-
throw new Error("iOS wallet did not return a signed transaction");
|
|
514
|
-
}
|
|
515
|
-
return response.transaction;
|
|
516
|
-
}
|
|
517
|
-
async function launchSignAllTransactions(definition, transactions, options) {
|
|
518
|
-
const response = await launchEncryptedWalletRequest(definition, "signAllTransactions", options, {
|
|
519
|
-
transactions: transactions.map((transaction) => bs58.encode(serializeTransaction(transaction)))
|
|
520
|
-
});
|
|
521
|
-
if (!response.transactions) {
|
|
522
|
-
throw new Error("iOS wallet did not return signed transactions");
|
|
523
|
-
}
|
|
524
|
-
return response.transactions;
|
|
525
|
-
}
|
|
526
|
-
async function launchSignAndSendTransaction(definition, transaction, sendOptions, options) {
|
|
527
|
-
const response = await launchEncryptedWalletRequest(
|
|
528
|
-
definition,
|
|
529
|
-
"signAndSendTransaction",
|
|
530
|
-
options,
|
|
531
|
-
{
|
|
532
|
-
transaction: bs58.encode(serializeTransaction(transaction)),
|
|
533
|
-
sendOptions
|
|
534
|
-
}
|
|
535
|
-
);
|
|
536
|
-
if (!response.signature) {
|
|
537
|
-
throw new Error("iOS wallet did not return a transaction signature");
|
|
538
|
-
}
|
|
539
|
-
return { signature: response.signature };
|
|
540
|
-
}
|
|
541
|
-
async function launchEncryptedWalletRequest(definition, method, options, payload) {
|
|
542
|
-
const session = getStoredSession(definition.id);
|
|
543
|
-
if (!session) {
|
|
544
|
-
throw new Error("Connect the iOS wallet before signing");
|
|
545
|
-
}
|
|
546
|
-
const methodUrl = getIosWalletMethodUrl(definition, method);
|
|
547
|
-
const pending = createPendingRequest(
|
|
548
|
-
definition.id,
|
|
549
|
-
method,
|
|
550
|
-
{
|
|
551
|
-
publicKey: bs58.decode(session.dappEncryptionPublicKey),
|
|
552
|
-
secretKey: bs58.decode(session.dappEncryptionSecretKey)
|
|
553
|
-
},
|
|
554
|
-
options.redirectUrl,
|
|
555
|
-
method === "signAllTransactions" && Array.isArray(payload.transactions) ? payload.transactions.length : void 0
|
|
556
|
-
);
|
|
557
|
-
const nonce = nacl.randomBytes(nacl.box.nonceLength);
|
|
558
|
-
const encryptedPayload = encryptPayload(
|
|
559
|
-
{ ...payload, session: session.session },
|
|
560
|
-
nonce,
|
|
561
|
-
bs58.decode(session.sharedSecret)
|
|
562
|
-
);
|
|
563
|
-
const url = new URL(methodUrl);
|
|
564
|
-
url.searchParams.set("dapp_encryption_public_key", session.dappEncryptionPublicKey);
|
|
565
|
-
url.searchParams.set("nonce", bs58.encode(nonce));
|
|
566
|
-
url.searchParams.set("redirect_link", pending.redirectUrl);
|
|
567
|
-
url.searchParams.set("payload", encryptedPayload);
|
|
568
|
-
storePendingRequest(pending);
|
|
569
|
-
openIosWalletUrl(url.toString());
|
|
570
|
-
return waitForRedirect();
|
|
571
|
-
}
|
|
572
|
-
function getIosWalletMethodUrl(definition, method) {
|
|
573
|
-
const url = definition[`${method}Url`];
|
|
574
|
-
if (!url) {
|
|
575
|
-
throw new Error(`${definition.name} does not support ${method} through iOS deeplinks`);
|
|
576
|
-
}
|
|
577
|
-
return url;
|
|
578
|
-
}
|
|
579
581
|
function getIosWalletDefinition(walletInfo) {
|
|
580
582
|
if (!isIosWalletDefinition(walletInfo.wallet)) {
|
|
581
583
|
throw new Error("Solana wallet info is not an iOS wallet");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StandardEvents, StandardDisconnect, StandardConnect } from '@wallet-standard/features';
|
|
2
|
-
import { SolanaSignAndSendTransaction, SolanaSignTransaction } from '@solana/wallet-standard-features';
|
|
2
|
+
import { SolanaSignAndSendTransaction, SolanaSignTransaction, SolanaSignMessage } from '@solana/wallet-standard-features';
|
|
3
3
|
import { Transaction, VersionedTransaction, PublicKey } from '@solana/web3-compat';
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import { getWallets } from '@wallet-standard/app';
|
|
@@ -23,6 +23,9 @@ function hasSignTransaction(wallet) {
|
|
|
23
23
|
function hasSignAndSendTransaction(wallet) {
|
|
24
24
|
return SolanaSignAndSendTransaction in wallet.features;
|
|
25
25
|
}
|
|
26
|
+
function hasSignMessage(wallet) {
|
|
27
|
+
return SolanaSignMessage in wallet.features;
|
|
28
|
+
}
|
|
26
29
|
|
|
27
30
|
function serializeTransaction(transaction) {
|
|
28
31
|
if (transaction instanceof Transaction) {
|
|
@@ -107,6 +110,17 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
107
110
|
options.onChange?.();
|
|
108
111
|
}
|
|
109
112
|
},
|
|
113
|
+
signMessage: hasSignMessage(wallet) ? async (message) => {
|
|
114
|
+
const activeAccount = getActiveAccount(account);
|
|
115
|
+
const [result] = await wallet.features[SolanaSignMessage].signMessage({
|
|
116
|
+
account: activeAccount,
|
|
117
|
+
message
|
|
118
|
+
});
|
|
119
|
+
if (!result) {
|
|
120
|
+
throw new Error("Solana wallet did not return a message signature");
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
} : void 0,
|
|
110
124
|
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
111
125
|
const activeAccount = getActiveAccount(account);
|
|
112
126
|
const [result] = await wallet.features[SolanaSignTransaction].signTransaction({
|
|
@@ -208,6 +222,14 @@ function createSolanaWalletInfo(wallet) {
|
|
|
208
222
|
platform: isMobileWallet ? "mobile" : "browser",
|
|
209
223
|
source: isMobileWallet ? "mobile-wallet-adapter" : "wallet-standard",
|
|
210
224
|
appUrl: getWalletUrl(wallet),
|
|
225
|
+
capabilities: {
|
|
226
|
+
connect: true,
|
|
227
|
+
disconnect: true,
|
|
228
|
+
signMessage: hasSignMessage(wallet),
|
|
229
|
+
signTransaction: hasSignTransaction(wallet),
|
|
230
|
+
signAllTransactions: hasSignTransaction(wallet),
|
|
231
|
+
signAndSendTransaction: hasSignAndSendTransaction(wallet)
|
|
232
|
+
},
|
|
211
233
|
accounts: wallet.accounts.map((account) => ({
|
|
212
234
|
address: account.address,
|
|
213
235
|
publicKey: Uint8Array.from(account.publicKey),
|
|
@@ -29,6 +29,9 @@ function hasSignTransaction(wallet) {
|
|
|
29
29
|
function hasSignAndSendTransaction(wallet) {
|
|
30
30
|
return walletStandardFeatures.SolanaSignAndSendTransaction in wallet.features;
|
|
31
31
|
}
|
|
32
|
+
function hasSignMessage(wallet) {
|
|
33
|
+
return walletStandardFeatures.SolanaSignMessage in wallet.features;
|
|
34
|
+
}
|
|
32
35
|
|
|
33
36
|
function serializeTransaction(transaction) {
|
|
34
37
|
if (transaction instanceof web3Compat.Transaction) {
|
|
@@ -113,6 +116,17 @@ function adaptSolanaStandardWallet(walletInfo, options = {}) {
|
|
|
113
116
|
options.onChange?.();
|
|
114
117
|
}
|
|
115
118
|
},
|
|
119
|
+
signMessage: hasSignMessage(wallet) ? async (message) => {
|
|
120
|
+
const activeAccount = getActiveAccount(account);
|
|
121
|
+
const [result] = await wallet.features[walletStandardFeatures.SolanaSignMessage].signMessage({
|
|
122
|
+
account: activeAccount,
|
|
123
|
+
message
|
|
124
|
+
});
|
|
125
|
+
if (!result) {
|
|
126
|
+
throw new Error("Solana wallet did not return a message signature");
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
} : void 0,
|
|
116
130
|
signTransaction: hasSignTransaction(wallet) ? async (transaction) => {
|
|
117
131
|
const activeAccount = getActiveAccount(account);
|
|
118
132
|
const [result] = await wallet.features[walletStandardFeatures.SolanaSignTransaction].signTransaction({
|
|
@@ -214,6 +228,14 @@ function createSolanaWalletInfo(wallet) {
|
|
|
214
228
|
platform: isMobileWallet ? "mobile" : "browser",
|
|
215
229
|
source: isMobileWallet ? "mobile-wallet-adapter" : "wallet-standard",
|
|
216
230
|
appUrl: getWalletUrl(wallet),
|
|
231
|
+
capabilities: {
|
|
232
|
+
connect: true,
|
|
233
|
+
disconnect: true,
|
|
234
|
+
signMessage: hasSignMessage(wallet),
|
|
235
|
+
signTransaction: hasSignTransaction(wallet),
|
|
236
|
+
signAllTransactions: hasSignTransaction(wallet),
|
|
237
|
+
signAndSendTransaction: hasSignAndSendTransaction(wallet)
|
|
238
|
+
},
|
|
217
239
|
accounts: wallet.accounts.map((account) => ({
|
|
218
240
|
address: account.address,
|
|
219
241
|
publicKey: Uint8Array.from(account.publicKey),
|
package/dist/timeout.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const errors = require('./errors.cjs');
|
|
4
|
+
|
|
5
|
+
function withTimeout(promise, timeoutMs, createError) {
|
|
6
|
+
if (timeoutMs === void 0) {
|
|
7
|
+
return promise;
|
|
8
|
+
}
|
|
9
|
+
let timeoutId;
|
|
10
|
+
return Promise.race([
|
|
11
|
+
promise,
|
|
12
|
+
new Promise((_, reject) => {
|
|
13
|
+
timeoutId = setTimeout(() => {
|
|
14
|
+
try {
|
|
15
|
+
reject(createError());
|
|
16
|
+
} catch (error) {
|
|
17
|
+
reject(error);
|
|
18
|
+
}
|
|
19
|
+
}, timeoutMs);
|
|
20
|
+
})
|
|
21
|
+
]).finally(() => {
|
|
22
|
+
if (timeoutId) {
|
|
23
|
+
clearTimeout(timeoutId);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function withSolanaTimeout(promise, timeoutMs, message) {
|
|
28
|
+
return withTimeout(promise, timeoutMs, () => errors.createSolanaError("TRANSACTION_TIMEOUT", message));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.withSolanaTimeout = withSolanaTimeout;
|
|
32
|
+
exports.withTimeout = withTimeout;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, createError: () => unknown): Promise<T>;
|
|
2
|
+
declare function withSolanaTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, message: string): Promise<T>;
|
|
3
|
+
|
|
4
|
+
export { withSolanaTimeout, withTimeout };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, createError: () => unknown): Promise<T>;
|
|
2
|
+
declare function withSolanaTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, message: string): Promise<T>;
|
|
3
|
+
|
|
4
|
+
export { withSolanaTimeout, withTimeout };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, createError: () => unknown): Promise<T>;
|
|
2
|
+
declare function withSolanaTimeout<T>(promise: Promise<T>, timeoutMs: number | undefined, message: string): Promise<T>;
|
|
3
|
+
|
|
4
|
+
export { withSolanaTimeout, withTimeout };
|
package/dist/timeout.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createSolanaError } from './errors.mjs';
|
|
2
|
+
|
|
3
|
+
function withTimeout(promise, timeoutMs, createError) {
|
|
4
|
+
if (timeoutMs === void 0) {
|
|
5
|
+
return promise;
|
|
6
|
+
}
|
|
7
|
+
let timeoutId;
|
|
8
|
+
return Promise.race([
|
|
9
|
+
promise,
|
|
10
|
+
new Promise((_, reject) => {
|
|
11
|
+
timeoutId = setTimeout(() => {
|
|
12
|
+
try {
|
|
13
|
+
reject(createError());
|
|
14
|
+
} catch (error) {
|
|
15
|
+
reject(error);
|
|
16
|
+
}
|
|
17
|
+
}, timeoutMs);
|
|
18
|
+
})
|
|
19
|
+
]).finally(() => {
|
|
20
|
+
if (timeoutId) {
|
|
21
|
+
clearTimeout(timeoutId);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function withSolanaTimeout(promise, timeoutMs, message) {
|
|
26
|
+
return withTimeout(promise, timeoutMs, () => createSolanaError("TRANSACTION_TIMEOUT", message));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { withSolanaTimeout, withTimeout };
|
package/dist/transaction.cjs
CHANGED
|
@@ -1,32 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const errors = require('./errors.cjs');
|
|
4
|
+
const timeout = require('./timeout.cjs');
|
|
3
5
|
const wallet = require('./wallet.cjs');
|
|
4
6
|
|
|
5
7
|
const DEFAULT_CONFIRMATION_COMMITMENT = "confirmed";
|
|
6
8
|
const DEFAULT_CONFIRMATION_TIMEOUT_MS = 6e4;
|
|
7
9
|
async function signAndSendTransaction(connection, wallet$1, transaction, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
try {
|
|
11
|
+
wallet.assertWalletConnected(wallet$1);
|
|
12
|
+
if (isMobileWalletAdapterWallet(wallet$1) && wallet$1.signTransaction) {
|
|
13
|
+
wallet.assertWalletCanSign(wallet$1);
|
|
14
|
+
return await signAndSendRawTransaction(connection, wallet$1, transaction, options);
|
|
15
|
+
}
|
|
16
|
+
if (wallet$1.signAndSendTransaction) {
|
|
17
|
+
const result = await wallet$1.signAndSendTransaction(transaction, options);
|
|
18
|
+
return result.signature;
|
|
19
|
+
}
|
|
10
20
|
wallet.assertWalletCanSign(wallet$1);
|
|
11
|
-
return signAndSendRawTransaction(connection, wallet$1, transaction, options);
|
|
21
|
+
return await signAndSendRawTransaction(connection, wallet$1, transaction, options);
|
|
22
|
+
} catch (cause) {
|
|
23
|
+
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
12
24
|
}
|
|
13
|
-
if (wallet$1.signAndSendTransaction) {
|
|
14
|
-
const result = await wallet$1.signAndSendTransaction(transaction, options);
|
|
15
|
-
return result.signature;
|
|
16
|
-
}
|
|
17
|
-
wallet.assertWalletCanSign(wallet$1);
|
|
18
|
-
return signAndSendRawTransaction(connection, wallet$1, transaction, options);
|
|
19
25
|
}
|
|
20
26
|
async function confirmTransactionSignature(connection, signature, options = {}) {
|
|
21
27
|
const commitment = options.commitment ?? DEFAULT_CONFIRMATION_COMMITMENT;
|
|
22
28
|
const confirmation = connection.confirmTransaction(signature, commitment);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
let result;
|
|
30
|
+
try {
|
|
31
|
+
result = await timeout.withSolanaTimeout(
|
|
32
|
+
confirmation,
|
|
33
|
+
options.timeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS,
|
|
34
|
+
`Timed out waiting for transaction ${signature} to reach ${commitment} commitment.`
|
|
35
|
+
);
|
|
36
|
+
} catch (cause) {
|
|
37
|
+
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
38
|
+
}
|
|
28
39
|
if (result.value.err) {
|
|
29
|
-
throw
|
|
40
|
+
throw errors.createSolanaError(
|
|
41
|
+
"RPC_FAILURE",
|
|
42
|
+
`Transaction ${signature} failed to reach ${commitment} commitment.`,
|
|
43
|
+
{ cause: result.value.err }
|
|
44
|
+
);
|
|
30
45
|
}
|
|
31
46
|
return {
|
|
32
47
|
signature,
|
|
@@ -42,21 +57,6 @@ async function signAndSendRawTransaction(connection, wallet, transaction, option
|
|
|
42
57
|
function isMobileWalletAdapterWallet(wallet) {
|
|
43
58
|
return wallet.source === "mobile-wallet-adapter";
|
|
44
59
|
}
|
|
45
|
-
async function withTransactionTimeout(promise, timeoutMs, message) {
|
|
46
|
-
let timeoutId;
|
|
47
|
-
try {
|
|
48
|
-
const timeout = new Promise((_, reject) => {
|
|
49
|
-
timeoutId = setTimeout(() => {
|
|
50
|
-
reject(new Error(message));
|
|
51
|
-
}, timeoutMs);
|
|
52
|
-
});
|
|
53
|
-
return await Promise.race([promise, timeout]);
|
|
54
|
-
} finally {
|
|
55
|
-
if (timeoutId) {
|
|
56
|
-
clearTimeout(timeoutId);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
60
|
|
|
61
61
|
exports.confirmTransactionSignature = confirmTransactionSignature;
|
|
62
62
|
exports.signAndSendTransaction = signAndSendTransaction;
|
package/dist/transaction.mjs
CHANGED
|
@@ -1,30 +1,45 @@
|
|
|
1
|
+
import { normalizeSolanaError, createSolanaError } from './errors.mjs';
|
|
2
|
+
import { withSolanaTimeout } from './timeout.mjs';
|
|
1
3
|
import { assertWalletConnected, assertWalletCanSign } from './wallet.mjs';
|
|
2
4
|
|
|
3
5
|
const DEFAULT_CONFIRMATION_COMMITMENT = "confirmed";
|
|
4
6
|
const DEFAULT_CONFIRMATION_TIMEOUT_MS = 6e4;
|
|
5
7
|
async function signAndSendTransaction(connection, wallet, transaction, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
try {
|
|
9
|
+
assertWalletConnected(wallet);
|
|
10
|
+
if (isMobileWalletAdapterWallet(wallet) && wallet.signTransaction) {
|
|
11
|
+
assertWalletCanSign(wallet);
|
|
12
|
+
return await signAndSendRawTransaction(connection, wallet, transaction, options);
|
|
13
|
+
}
|
|
14
|
+
if (wallet.signAndSendTransaction) {
|
|
15
|
+
const result = await wallet.signAndSendTransaction(transaction, options);
|
|
16
|
+
return result.signature;
|
|
17
|
+
}
|
|
8
18
|
assertWalletCanSign(wallet);
|
|
9
|
-
return signAndSendRawTransaction(connection, wallet, transaction, options);
|
|
19
|
+
return await signAndSendRawTransaction(connection, wallet, transaction, options);
|
|
20
|
+
} catch (cause) {
|
|
21
|
+
throw normalizeSolanaError(cause, "RPC_FAILURE");
|
|
10
22
|
}
|
|
11
|
-
if (wallet.signAndSendTransaction) {
|
|
12
|
-
const result = await wallet.signAndSendTransaction(transaction, options);
|
|
13
|
-
return result.signature;
|
|
14
|
-
}
|
|
15
|
-
assertWalletCanSign(wallet);
|
|
16
|
-
return signAndSendRawTransaction(connection, wallet, transaction, options);
|
|
17
23
|
}
|
|
18
24
|
async function confirmTransactionSignature(connection, signature, options = {}) {
|
|
19
25
|
const commitment = options.commitment ?? DEFAULT_CONFIRMATION_COMMITMENT;
|
|
20
26
|
const confirmation = connection.confirmTransaction(signature, commitment);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
let result;
|
|
28
|
+
try {
|
|
29
|
+
result = await withSolanaTimeout(
|
|
30
|
+
confirmation,
|
|
31
|
+
options.timeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS,
|
|
32
|
+
`Timed out waiting for transaction ${signature} to reach ${commitment} commitment.`
|
|
33
|
+
);
|
|
34
|
+
} catch (cause) {
|
|
35
|
+
throw normalizeSolanaError(cause, "RPC_FAILURE");
|
|
36
|
+
}
|
|
26
37
|
if (result.value.err) {
|
|
27
|
-
throw
|
|
38
|
+
throw createSolanaError(
|
|
39
|
+
"RPC_FAILURE",
|
|
40
|
+
`Transaction ${signature} failed to reach ${commitment} commitment.`,
|
|
41
|
+
{ cause: result.value.err }
|
|
42
|
+
);
|
|
28
43
|
}
|
|
29
44
|
return {
|
|
30
45
|
signature,
|
|
@@ -40,20 +55,5 @@ async function signAndSendRawTransaction(connection, wallet, transaction, option
|
|
|
40
55
|
function isMobileWalletAdapterWallet(wallet) {
|
|
41
56
|
return wallet.source === "mobile-wallet-adapter";
|
|
42
57
|
}
|
|
43
|
-
async function withTransactionTimeout(promise, timeoutMs, message) {
|
|
44
|
-
let timeoutId;
|
|
45
|
-
try {
|
|
46
|
-
const timeout = new Promise((_, reject) => {
|
|
47
|
-
timeoutId = setTimeout(() => {
|
|
48
|
-
reject(new Error(message));
|
|
49
|
-
}, timeoutMs);
|
|
50
|
-
});
|
|
51
|
-
return await Promise.race([promise, timeout]);
|
|
52
|
-
} finally {
|
|
53
|
-
if (timeoutId) {
|
|
54
|
-
clearTimeout(timeoutId);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
58
|
|
|
59
59
|
export { confirmTransactionSignature, signAndSendTransaction };
|
package/dist/types.d.cts
CHANGED
|
@@ -16,6 +16,10 @@ interface SolanaContext {
|
|
|
16
16
|
connection: Connection;
|
|
17
17
|
}
|
|
18
18
|
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
19
|
+
interface SolanaSignMessageResult {
|
|
20
|
+
signedMessage: Uint8Array;
|
|
21
|
+
signature: Uint8Array;
|
|
22
|
+
}
|
|
19
23
|
interface SolanaWallet {
|
|
20
24
|
publicKey: PublicKey | null;
|
|
21
25
|
connected: boolean;
|
|
@@ -25,6 +29,7 @@ interface SolanaWallet {
|
|
|
25
29
|
source?: SolanaWalletInfo["source"];
|
|
26
30
|
connect: () => Promise<void>;
|
|
27
31
|
disconnect: () => Promise<void>;
|
|
32
|
+
signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
|
|
28
33
|
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
29
34
|
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
30
35
|
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
@@ -42,6 +47,8 @@ interface SolanaWalletInfo {
|
|
|
42
47
|
callbackUrl?: string;
|
|
43
48
|
capabilities?: {
|
|
44
49
|
connect?: boolean;
|
|
50
|
+
disconnect?: boolean;
|
|
51
|
+
signMessage?: boolean;
|
|
45
52
|
signTransaction?: boolean;
|
|
46
53
|
signAllTransactions?: boolean;
|
|
47
54
|
signAndSendTransaction?: boolean;
|
|
@@ -68,4 +75,4 @@ interface TransactionConfirmation {
|
|
|
68
75
|
result: RpcResponseAndContext<SignatureResult>;
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
|
|
78
|
+
export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
|
package/dist/types.d.mts
CHANGED
|
@@ -16,6 +16,10 @@ interface SolanaContext {
|
|
|
16
16
|
connection: Connection;
|
|
17
17
|
}
|
|
18
18
|
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
19
|
+
interface SolanaSignMessageResult {
|
|
20
|
+
signedMessage: Uint8Array;
|
|
21
|
+
signature: Uint8Array;
|
|
22
|
+
}
|
|
19
23
|
interface SolanaWallet {
|
|
20
24
|
publicKey: PublicKey | null;
|
|
21
25
|
connected: boolean;
|
|
@@ -25,6 +29,7 @@ interface SolanaWallet {
|
|
|
25
29
|
source?: SolanaWalletInfo["source"];
|
|
26
30
|
connect: () => Promise<void>;
|
|
27
31
|
disconnect: () => Promise<void>;
|
|
32
|
+
signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
|
|
28
33
|
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
29
34
|
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
30
35
|
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
@@ -42,6 +47,8 @@ interface SolanaWalletInfo {
|
|
|
42
47
|
callbackUrl?: string;
|
|
43
48
|
capabilities?: {
|
|
44
49
|
connect?: boolean;
|
|
50
|
+
disconnect?: boolean;
|
|
51
|
+
signMessage?: boolean;
|
|
45
52
|
signTransaction?: boolean;
|
|
46
53
|
signAllTransactions?: boolean;
|
|
47
54
|
signAndSendTransaction?: boolean;
|
|
@@ -68,4 +75,4 @@ interface TransactionConfirmation {
|
|
|
68
75
|
result: RpcResponseAndContext<SignatureResult>;
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
|
|
78
|
+
export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
|
package/dist/types.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ interface SolanaContext {
|
|
|
16
16
|
connection: Connection;
|
|
17
17
|
}
|
|
18
18
|
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
19
|
+
interface SolanaSignMessageResult {
|
|
20
|
+
signedMessage: Uint8Array;
|
|
21
|
+
signature: Uint8Array;
|
|
22
|
+
}
|
|
19
23
|
interface SolanaWallet {
|
|
20
24
|
publicKey: PublicKey | null;
|
|
21
25
|
connected: boolean;
|
|
@@ -25,6 +29,7 @@ interface SolanaWallet {
|
|
|
25
29
|
source?: SolanaWalletInfo["source"];
|
|
26
30
|
connect: () => Promise<void>;
|
|
27
31
|
disconnect: () => Promise<void>;
|
|
32
|
+
signMessage?: (message: Uint8Array) => Promise<SolanaSignMessageResult>;
|
|
28
33
|
signTransaction?: <T extends SolanaTransaction>(transaction: T) => Promise<T>;
|
|
29
34
|
signAllTransactions?: <T extends SolanaTransaction>(transactions: T[]) => Promise<T[]>;
|
|
30
35
|
signAndSendTransaction?: (transaction: SolanaTransaction, options?: SendOptions) => Promise<{
|
|
@@ -42,6 +47,8 @@ interface SolanaWalletInfo {
|
|
|
42
47
|
callbackUrl?: string;
|
|
43
48
|
capabilities?: {
|
|
44
49
|
connect?: boolean;
|
|
50
|
+
disconnect?: boolean;
|
|
51
|
+
signMessage?: boolean;
|
|
45
52
|
signTransaction?: boolean;
|
|
46
53
|
signAllTransactions?: boolean;
|
|
47
54
|
signAndSendTransaction?: boolean;
|
|
@@ -68,4 +75,4 @@ interface TransactionConfirmation {
|
|
|
68
75
|
result: RpcResponseAndContext<SignatureResult>;
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
|
|
78
|
+
export type { ConfirmTransactionOptions, SendTransactionOptions, SolanaChain, SolanaCluster, SolanaConfig, SolanaContext, SolanaSignMessageResult, SolanaTransaction, SolanaWallet, SolanaWalletInfo, TransactionConfirmation };
|
package/dist/wallet-standard.cjs
CHANGED
package/dist/wallet-standard.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.
|
|
1
|
+
export { S as SOLANA_CHAINS, a as SOLANA_MOBILE_WALLET_ADAPTER_WALLET_NAME, b as adaptSolanaStandardWallet, g as getRegisteredSolanaWallets, c as getSolanaChain, i as isSolanaStandardWallet, s as subscribeSolanaWallets } from './shared/core.DSMNiaHD.mjs';
|
|
2
2
|
import '@wallet-standard/features';
|
|
3
3
|
import '@solana/wallet-standard-features';
|
|
4
4
|
import '@solana/web3-compat';
|