@dynamic-labs/solana 0.0.0-exp20240808.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/CHANGELOG.md +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.json +48 -0
- package/src/CoinbaseSolana.cjs +52 -0
- package/src/CoinbaseSolana.d.ts +9 -0
- package/src/CoinbaseSolana.js +48 -0
- package/src/Phantom.cjs +44 -0
- package/src/Phantom.d.ts +13 -0
- package/src/Phantom.js +40 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.cjs +100 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.d.ts +21 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.js +96 -0
- package/src/SolanaWalletStandardConnector/index.d.ts +1 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs +117 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +4 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js +113 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/index.d.ts +1 -0
- package/src/Solflare.cjs +63 -0
- package/src/Solflare.d.ts +9 -0
- package/src/Solflare.js +59 -0
- package/src/contants.cjs +8 -0
- package/src/contants.d.ts +1 -0
- package/src/contants.js +4 -0
- package/src/errors/SignMessageNotSupportedError.cjs +17 -0
- package/src/errors/SignMessageNotSupportedError.d.ts +4 -0
- package/src/errors/SignMessageNotSupportedError.js +13 -0
- package/src/index.cjs +30 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +22 -0
- package/src/injected/BackpackSol.cjs +46 -0
- package/src/injected/BackpackSol.d.ts +9 -0
- package/src/injected/BackpackSol.js +42 -0
- package/src/injected/FallbackSolanaConnector.cjs +22 -0
- package/src/injected/FallbackSolanaConnector.d.ts +9 -0
- package/src/injected/FallbackSolanaConnector.js +18 -0
- package/src/injected/InjectedWalletBase.cjs +118 -0
- package/src/injected/InjectedWalletBase.d.ts +21 -0
- package/src/injected/InjectedWalletBase.js +114 -0
- package/src/injected/PhantomInjected.cjs +37 -0
- package/src/injected/PhantomInjected.d.ts +8 -0
- package/src/injected/PhantomInjected.js +33 -0
- package/src/injected/UnknownInjected.cjs +21 -0
- package/src/injected/UnknownInjected.d.ts +8 -0
- package/src/injected/UnknownInjected.js +17 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +63 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
- package/src/injected/fetchInjectedWalletConnectors.js +58 -0
- package/src/injected/index.d.ts +3 -0
- package/src/phantomRedirect/PhantomRedirect.cjs +337 -0
- package/src/phantomRedirect/PhantomRedirect.d.ts +37 -0
- package/src/phantomRedirect/PhantomRedirect.js +328 -0
- package/src/phantomRedirect/storage.cjs +96 -0
- package/src/phantomRedirect/storage.d.ts +40 -0
- package/src/phantomRedirect/storage.js +91 -0
- package/src/phantomRedirect/types.d.ts +1 -0
- package/src/phantomRedirect/utils.cjs +56 -0
- package/src/phantomRedirect/utils.d.ts +4 -0
- package/src/phantomRedirect/utils.js +44 -0
- package/src/solProviderHelper.cjs +173 -0
- package/src/solProviderHelper.d.ts +36 -0
- package/src/solProviderHelper.js +169 -0
- package/src/solWalletConnector.cjs +174 -0
- package/src/solWalletConnector.d.ts +37 -0
- package/src/solWalletConnector.js +170 -0
- package/src/types.d.ts +68 -0
- package/src/utils/extractNonce.cjs +14 -0
- package/src/utils/extractNonce.d.ts +1 -0
- package/src/utils/extractNonce.js +10 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.cjs +29 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.d.ts +3 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.js +25 -0
- package/src/utils/findWalletProviderFromWalletStandard/index.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey.cjs +10 -0
- package/src/utils/getGenesisHashLSKey.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey.js +6 -0
- package/src/utils/isBackpackSolanaSigner.cjs +8 -0
- package/src/utils/isBackpackSolanaSigner.d.ts +2 -0
- package/src/utils/isBackpackSolanaSigner.js +4 -0
- package/src/utils/isSignedMessage.cjs +8 -0
- package/src/utils/isSignedMessage.d.ts +2 -0
- package/src/utils/isSignedMessage.js +4 -0
- package/src/wallet/SolanaWallet.cjs +33 -0
- package/src/wallet/SolanaWallet.d.ts +17 -0
- package/src/wallet/SolanaWallet.js +29 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isSolanaWallet.cjs +8 -0
- package/src/wallet/isSolanaWallet.d.ts +3 -0
- package/src/wallet/isSolanaWallet.js +4 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var web3_js = require('@solana/web3.js');
|
|
8
|
+
var utils = require('../../../phantomRedirect/utils.cjs');
|
|
9
|
+
|
|
10
|
+
const isVersionedTransaction = (transaction) => !('instructions' in transaction);
|
|
11
|
+
const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
|
|
12
|
+
const features = wallet.features;
|
|
13
|
+
const getCurrentAccount = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const address = yield walletConnector.getAddress();
|
|
15
|
+
const account = wallet.accounts.find((account) => account.address === address);
|
|
16
|
+
if (!account) {
|
|
17
|
+
throw new Error('Account not found');
|
|
18
|
+
}
|
|
19
|
+
return account;
|
|
20
|
+
});
|
|
21
|
+
const getChain = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const rpc = (_b = (_a = walletConnector.solNetworks[0].privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : walletConnector.solNetworks[0].rpcUrls[0];
|
|
24
|
+
const cluster = yield utils.fetchCluster(rpc);
|
|
25
|
+
return `solana:${cluster}`;
|
|
26
|
+
});
|
|
27
|
+
const signTransaction = (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const account = yield getCurrentAccount();
|
|
29
|
+
const signTransactionResult = yield features['solana:signTransaction'].signTransaction({
|
|
30
|
+
account,
|
|
31
|
+
chain: yield getChain(),
|
|
32
|
+
transaction: transaction.serialize({
|
|
33
|
+
requireAllSignatures: false,
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
if (isVersionedTransaction(transaction)) {
|
|
37
|
+
return web3_js.VersionedTransaction.deserialize(signTransactionResult[0].signedTransaction);
|
|
38
|
+
}
|
|
39
|
+
return web3_js.Transaction.from(signTransactionResult[0].signedTransaction);
|
|
40
|
+
});
|
|
41
|
+
const signAllTransactions = (transactions) => _tslib.__awaiter(void 0, void 0, void 0, function* () { return Promise.all(transactions.map(signTransaction)); });
|
|
42
|
+
const signAndSendTransaction = (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const account = yield getCurrentAccount();
|
|
44
|
+
const signedTransactions = yield features['solana:signAndSendTransaction'].signAndSendTransaction({
|
|
45
|
+
account,
|
|
46
|
+
chain: yield getChain(),
|
|
47
|
+
transaction: transaction.serialize(),
|
|
48
|
+
});
|
|
49
|
+
const [{ signature }] = signedTransactions;
|
|
50
|
+
return { signature: new TextDecoder().decode(signature) };
|
|
51
|
+
});
|
|
52
|
+
const signMessage = (message) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const account = yield getCurrentAccount();
|
|
54
|
+
const messages = yield features['solana:signMessage'].signMessage({
|
|
55
|
+
account,
|
|
56
|
+
message,
|
|
57
|
+
});
|
|
58
|
+
return messages[0].signature;
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
addListener: () => {
|
|
62
|
+
throw new Error('Not implemented');
|
|
63
|
+
},
|
|
64
|
+
connect: () => {
|
|
65
|
+
throw new Error('Not implemented');
|
|
66
|
+
},
|
|
67
|
+
disconnect: () => walletConnector.endSession(),
|
|
68
|
+
emit: () => {
|
|
69
|
+
throw new Error('Not implemented');
|
|
70
|
+
},
|
|
71
|
+
eventNames: () => {
|
|
72
|
+
throw new Error('Not implemented');
|
|
73
|
+
},
|
|
74
|
+
isBackpack: false,
|
|
75
|
+
isBraveWallet: false,
|
|
76
|
+
isConnected: true,
|
|
77
|
+
isExodus: false,
|
|
78
|
+
isGlow: false,
|
|
79
|
+
isMagicEden: false,
|
|
80
|
+
isPhantom: false,
|
|
81
|
+
isSolflare: false,
|
|
82
|
+
listenerCount: () => {
|
|
83
|
+
throw new Error('Not implemented');
|
|
84
|
+
},
|
|
85
|
+
listeners: () => {
|
|
86
|
+
throw new Error('Not implemented');
|
|
87
|
+
},
|
|
88
|
+
off: () => {
|
|
89
|
+
throw new Error('Not implemented');
|
|
90
|
+
},
|
|
91
|
+
on: () => {
|
|
92
|
+
throw new Error('Not implemented');
|
|
93
|
+
},
|
|
94
|
+
once: () => {
|
|
95
|
+
throw new Error('Not implemented');
|
|
96
|
+
},
|
|
97
|
+
providers: [],
|
|
98
|
+
get publicKey() {
|
|
99
|
+
return new web3_js.PublicKey(wallet.accounts[0].publicKey);
|
|
100
|
+
},
|
|
101
|
+
removeAllListeners: () => {
|
|
102
|
+
throw new Error('Not implemented');
|
|
103
|
+
},
|
|
104
|
+
removeListener: () => {
|
|
105
|
+
throw new Error('Not implemented');
|
|
106
|
+
},
|
|
107
|
+
send: () => {
|
|
108
|
+
throw new Error('Not implemented');
|
|
109
|
+
},
|
|
110
|
+
signAllTransactions,
|
|
111
|
+
signAndSendTransaction,
|
|
112
|
+
signMessage,
|
|
113
|
+
signTransaction,
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.createSolanaSignerFromWalletStandard = createSolanaSignerFromWalletStandard;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { ISolana } from '../../../types';
|
|
3
|
+
import { SolWalletConnector } from '../../../solWalletConnector';
|
|
4
|
+
export declare const createSolanaSignerFromWalletStandard: (wallet: Wallet, walletConnector: SolWalletConnector) => ISolana;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
+
import { PublicKey, VersionedTransaction, Transaction } from '@solana/web3.js';
|
|
4
|
+
import { fetchCluster } from '../../../phantomRedirect/utils.js';
|
|
5
|
+
|
|
6
|
+
const isVersionedTransaction = (transaction) => !('instructions' in transaction);
|
|
7
|
+
const createSolanaSignerFromWalletStandard = (wallet, walletConnector) => {
|
|
8
|
+
const features = wallet.features;
|
|
9
|
+
const getCurrentAccount = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
10
|
+
const address = yield walletConnector.getAddress();
|
|
11
|
+
const account = wallet.accounts.find((account) => account.address === address);
|
|
12
|
+
if (!account) {
|
|
13
|
+
throw new Error('Account not found');
|
|
14
|
+
}
|
|
15
|
+
return account;
|
|
16
|
+
});
|
|
17
|
+
const getChain = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const rpc = (_b = (_a = walletConnector.solNetworks[0].privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : walletConnector.solNetworks[0].rpcUrls[0];
|
|
20
|
+
const cluster = yield fetchCluster(rpc);
|
|
21
|
+
return `solana:${cluster}`;
|
|
22
|
+
});
|
|
23
|
+
const signTransaction = (transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const account = yield getCurrentAccount();
|
|
25
|
+
const signTransactionResult = yield features['solana:signTransaction'].signTransaction({
|
|
26
|
+
account,
|
|
27
|
+
chain: yield getChain(),
|
|
28
|
+
transaction: transaction.serialize({
|
|
29
|
+
requireAllSignatures: false,
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
if (isVersionedTransaction(transaction)) {
|
|
33
|
+
return VersionedTransaction.deserialize(signTransactionResult[0].signedTransaction);
|
|
34
|
+
}
|
|
35
|
+
return Transaction.from(signTransactionResult[0].signedTransaction);
|
|
36
|
+
});
|
|
37
|
+
const signAllTransactions = (transactions) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all(transactions.map(signTransaction)); });
|
|
38
|
+
const signAndSendTransaction = (transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const account = yield getCurrentAccount();
|
|
40
|
+
const signedTransactions = yield features['solana:signAndSendTransaction'].signAndSendTransaction({
|
|
41
|
+
account,
|
|
42
|
+
chain: yield getChain(),
|
|
43
|
+
transaction: transaction.serialize(),
|
|
44
|
+
});
|
|
45
|
+
const [{ signature }] = signedTransactions;
|
|
46
|
+
return { signature: new TextDecoder().decode(signature) };
|
|
47
|
+
});
|
|
48
|
+
const signMessage = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const account = yield getCurrentAccount();
|
|
50
|
+
const messages = yield features['solana:signMessage'].signMessage({
|
|
51
|
+
account,
|
|
52
|
+
message,
|
|
53
|
+
});
|
|
54
|
+
return messages[0].signature;
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
addListener: () => {
|
|
58
|
+
throw new Error('Not implemented');
|
|
59
|
+
},
|
|
60
|
+
connect: () => {
|
|
61
|
+
throw new Error('Not implemented');
|
|
62
|
+
},
|
|
63
|
+
disconnect: () => walletConnector.endSession(),
|
|
64
|
+
emit: () => {
|
|
65
|
+
throw new Error('Not implemented');
|
|
66
|
+
},
|
|
67
|
+
eventNames: () => {
|
|
68
|
+
throw new Error('Not implemented');
|
|
69
|
+
},
|
|
70
|
+
isBackpack: false,
|
|
71
|
+
isBraveWallet: false,
|
|
72
|
+
isConnected: true,
|
|
73
|
+
isExodus: false,
|
|
74
|
+
isGlow: false,
|
|
75
|
+
isMagicEden: false,
|
|
76
|
+
isPhantom: false,
|
|
77
|
+
isSolflare: false,
|
|
78
|
+
listenerCount: () => {
|
|
79
|
+
throw new Error('Not implemented');
|
|
80
|
+
},
|
|
81
|
+
listeners: () => {
|
|
82
|
+
throw new Error('Not implemented');
|
|
83
|
+
},
|
|
84
|
+
off: () => {
|
|
85
|
+
throw new Error('Not implemented');
|
|
86
|
+
},
|
|
87
|
+
on: () => {
|
|
88
|
+
throw new Error('Not implemented');
|
|
89
|
+
},
|
|
90
|
+
once: () => {
|
|
91
|
+
throw new Error('Not implemented');
|
|
92
|
+
},
|
|
93
|
+
providers: [],
|
|
94
|
+
get publicKey() {
|
|
95
|
+
return new PublicKey(wallet.accounts[0].publicKey);
|
|
96
|
+
},
|
|
97
|
+
removeAllListeners: () => {
|
|
98
|
+
throw new Error('Not implemented');
|
|
99
|
+
},
|
|
100
|
+
removeListener: () => {
|
|
101
|
+
throw new Error('Not implemented');
|
|
102
|
+
},
|
|
103
|
+
send: () => {
|
|
104
|
+
throw new Error('Not implemented');
|
|
105
|
+
},
|
|
106
|
+
signAllTransactions,
|
|
107
|
+
signAndSendTransaction,
|
|
108
|
+
signMessage,
|
|
109
|
+
signTransaction,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { createSolanaSignerFromWalletStandard };
|
package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSolanaSignerFromWalletStandard } from './createSolanaSignerFromWalletStandard';
|
package/src/Solflare.cjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
|
+
var InjectedWalletBase = require('./injected/InjectedWalletBase.cjs');
|
|
10
|
+
|
|
11
|
+
class Solflare extends InjectedWalletBase.InjectedWalletBase {
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
super(opts);
|
|
14
|
+
this.name = 'Solflare';
|
|
15
|
+
this.overrideKey = 'solflare';
|
|
16
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
17
|
+
}
|
|
18
|
+
getAddress() {
|
|
19
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
|
+
/**
|
|
22
|
+
* It should redirect to in-app browser if on mobile and if not in the in-app browser,
|
|
23
|
+
* this checks if it is not in the in-app browser by checking if the provider is not available.
|
|
24
|
+
*/
|
|
25
|
+
if (utils.isMobile() && !this.isInstalledOnBrowser()) {
|
|
26
|
+
utils.handleMobileWalletRedirect({
|
|
27
|
+
nativeLink: ((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.native) || 'solflare://ul/v1/browse',
|
|
28
|
+
universalLink: ((_d = (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.universal) || 'https://solflare.com/ul/v1/browse',
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
return (_e = this.getSolProviderHelper()) === null || _e === void 0 ? void 0 : _e.getAddress();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
signMessage(messageToSign) {
|
|
36
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const walletAddress = yield this.getAddress();
|
|
38
|
+
if (!walletAddress) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const provider = yield this.getSigner();
|
|
42
|
+
if (!provider) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const encodedMessage = new TextEncoder().encode(messageToSign);
|
|
46
|
+
const isSignedMessage = (value) => value.signature !== undefined;
|
|
47
|
+
yield provider.connect();
|
|
48
|
+
/**
|
|
49
|
+
* TODO: Remove the sleep once problem is fixed on Solflare's extension.
|
|
50
|
+
* Tracked in DYN-442
|
|
51
|
+
*/
|
|
52
|
+
yield new Promise((resolve) => {
|
|
53
|
+
setTimeout(resolve, 100);
|
|
54
|
+
});
|
|
55
|
+
const rawMessage = yield provider.signMessage(encodedMessage, 'utf8');
|
|
56
|
+
return isSignedMessage(rawMessage)
|
|
57
|
+
? utils.bufferToBase64(rawMessage.signature)
|
|
58
|
+
: undefined;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.Solflare = Solflare;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InjectedWalletBase } from './injected/InjectedWalletBase';
|
|
2
|
+
import { SolWalletConnectorOpts } from './solWalletConnector';
|
|
3
|
+
export declare class Solflare extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
constructor(opts: SolWalletConnectorOpts);
|
|
7
|
+
getAddress(): Promise<string | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
}
|
package/src/Solflare.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { isMobile, handleMobileWalletRedirect, bufferToBase64 } from '@dynamic-labs/utils';
|
|
4
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { InjectedWalletBase } from './injected/InjectedWalletBase.js';
|
|
6
|
+
|
|
7
|
+
class Solflare extends InjectedWalletBase {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super(opts);
|
|
10
|
+
this.name = 'Solflare';
|
|
11
|
+
this.overrideKey = 'solflare';
|
|
12
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
13
|
+
}
|
|
14
|
+
getAddress() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b, _c, _d, _e;
|
|
17
|
+
/**
|
|
18
|
+
* It should redirect to in-app browser if on mobile and if not in the in-app browser,
|
|
19
|
+
* this checks if it is not in the in-app browser by checking if the provider is not available.
|
|
20
|
+
*/
|
|
21
|
+
if (isMobile() && !this.isInstalledOnBrowser()) {
|
|
22
|
+
handleMobileWalletRedirect({
|
|
23
|
+
nativeLink: ((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.native) || 'solflare://ul/v1/browse',
|
|
24
|
+
universalLink: ((_d = (_c = this.wallet) === null || _c === void 0 ? void 0 : _c.mobile) === null || _d === void 0 ? void 0 : _d.universal) || 'https://solflare.com/ul/v1/browse',
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return (_e = this.getSolProviderHelper()) === null || _e === void 0 ? void 0 : _e.getAddress();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
signMessage(messageToSign) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const walletAddress = yield this.getAddress();
|
|
34
|
+
if (!walletAddress) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const provider = yield this.getSigner();
|
|
38
|
+
if (!provider) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const encodedMessage = new TextEncoder().encode(messageToSign);
|
|
42
|
+
const isSignedMessage = (value) => value.signature !== undefined;
|
|
43
|
+
yield provider.connect();
|
|
44
|
+
/**
|
|
45
|
+
* TODO: Remove the sleep once problem is fixed on Solflare's extension.
|
|
46
|
+
* Tracked in DYN-442
|
|
47
|
+
*/
|
|
48
|
+
yield new Promise((resolve) => {
|
|
49
|
+
setTimeout(resolve, 100);
|
|
50
|
+
});
|
|
51
|
+
const rawMessage = yield provider.signMessage(encodedMessage, 'utf8');
|
|
52
|
+
return isSignedMessage(rawMessage)
|
|
53
|
+
? bufferToBase64(rawMessage.signature)
|
|
54
|
+
: undefined;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Solflare };
|
package/src/contants.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SOLANA_GENESIS_HASH = "genesis-hash";
|
package/src/contants.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
|
|
8
|
+
class SignMessageNotSupportedError extends utils.NotSupportedError {
|
|
9
|
+
constructor(walletName) {
|
|
10
|
+
super(`Message signing is currently not supported on ${walletName} hardware wallet.
|
|
11
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
12
|
+
by signing a transaction with a memo instruction.
|
|
13
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.SignMessageNotSupportedError = SignMessageNotSupportedError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { NotSupportedError } from '@dynamic-labs/utils';
|
|
3
|
+
|
|
4
|
+
class SignMessageNotSupportedError extends NotSupportedError {
|
|
5
|
+
constructor(walletName) {
|
|
6
|
+
super(`Message signing is currently not supported on ${walletName} hardware wallet.
|
|
7
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
8
|
+
by signing a transaction with a memo instruction.
|
|
9
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { SignMessageNotSupportedError };
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var embeddedWalletSolana = require('@dynamic-labs/embedded-wallet-solana');
|
|
7
|
+
var Phantom = require('./Phantom.cjs');
|
|
8
|
+
var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
|
|
9
|
+
var UnknownInjected = require('./injected/UnknownInjected.cjs');
|
|
10
|
+
var FallbackSolanaConnector = require('./injected/FallbackSolanaConnector.cjs');
|
|
11
|
+
var isSignedMessage = require('./utils/isSignedMessage.cjs');
|
|
12
|
+
var isBackpackSolanaSigner = require('./utils/isBackpackSolanaSigner.cjs');
|
|
13
|
+
var SolanaWallet = require('./wallet/SolanaWallet.cjs');
|
|
14
|
+
var isSolanaWallet = require('./wallet/isSolanaWallet.cjs');
|
|
15
|
+
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
17
|
+
const SolanaWalletConnectors = (props) => [
|
|
18
|
+
...fetchInjectedWalletConnectors.injectedWalletOverrides,
|
|
19
|
+
...fetchInjectedWalletConnectors.fetchInjectedWalletConnectors(props),
|
|
20
|
+
...embeddedWalletSolana.TurnkeySolanaWalletConnectors(props),
|
|
21
|
+
Phantom.Phantom,
|
|
22
|
+
UnknownInjected.UnknownInjected,
|
|
23
|
+
FallbackSolanaConnector.FallbackSolanaConnector,
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
exports.isSignedMessage = isSignedMessage.isSignedMessage;
|
|
27
|
+
exports.isBackpackSolanaSigner = isBackpackSolanaSigner.isBackpackSolanaSigner;
|
|
28
|
+
exports.SolanaWallet = SolanaWallet.SolanaWallet;
|
|
29
|
+
exports.isSolanaWallet = isSolanaWallet.isSolanaWallet;
|
|
30
|
+
exports.SolanaWalletConnectors = SolanaWalletConnectors;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Phantom } from './Phantom';
|
|
2
|
+
export declare const SolanaWalletConnectors: (props: any) => (import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor | typeof Phantom)[];
|
|
3
|
+
export { isSignedMessage } from './utils/isSignedMessage';
|
|
4
|
+
export { isBackpackSolanaSigner } from './utils/isBackpackSolanaSigner';
|
|
5
|
+
export type { ISolana, IBackpackSolanaSigner, ICoinbaseSolanaSigner, SignedMessage, ISolanaSigner, } from './types';
|
|
6
|
+
export * from './wallet';
|
|
7
|
+
export type { IEmbeddedWalletSolanaSigner } from '@dynamic-labs/embedded-wallet-solana';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { TurnkeySolanaWalletConnectors } from '@dynamic-labs/embedded-wallet-solana';
|
|
3
|
+
import { Phantom } from './Phantom.js';
|
|
4
|
+
import { injectedWalletOverrides, fetchInjectedWalletConnectors } from './injected/fetchInjectedWalletConnectors.js';
|
|
5
|
+
import { UnknownInjected } from './injected/UnknownInjected.js';
|
|
6
|
+
import { FallbackSolanaConnector } from './injected/FallbackSolanaConnector.js';
|
|
7
|
+
export { isSignedMessage } from './utils/isSignedMessage.js';
|
|
8
|
+
export { isBackpackSolanaSigner } from './utils/isBackpackSolanaSigner.js';
|
|
9
|
+
export { SolanaWallet } from './wallet/SolanaWallet.js';
|
|
10
|
+
export { isSolanaWallet } from './wallet/isSolanaWallet.js';
|
|
11
|
+
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
+
const SolanaWalletConnectors = (props) => [
|
|
14
|
+
...injectedWalletOverrides,
|
|
15
|
+
...fetchInjectedWalletConnectors(props),
|
|
16
|
+
...TurnkeySolanaWalletConnectors(props),
|
|
17
|
+
Phantom,
|
|
18
|
+
UnknownInjected,
|
|
19
|
+
FallbackSolanaConnector,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export { SolanaWalletConnectors };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
10
|
+
|
|
11
|
+
class BackpackSol extends InjectedWalletBase.InjectedWalletBase {
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
super(opts);
|
|
14
|
+
this.name = 'Backpack';
|
|
15
|
+
this.overrideKey = 'backpacksol';
|
|
16
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
17
|
+
}
|
|
18
|
+
getSigner() {
|
|
19
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.connect();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
signMessage(messageToSign) {
|
|
25
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const publicAddress = yield this.getAddress();
|
|
27
|
+
if (!publicAddress) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const provider = yield this.getSigner();
|
|
31
|
+
if (!provider) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const signedMessage = yield provider.signMessage(Buffer.from(messageToSign, 'utf8'));
|
|
35
|
+
if (!signedMessage) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (typeof signedMessage === 'object' && 'signature' in signedMessage) {
|
|
39
|
+
return utils.bufferToBase64(signedMessage.signature);
|
|
40
|
+
}
|
|
41
|
+
return utils.bufferToBase64(signedMessage);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.BackpackSol = BackpackSol;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SolWalletConnectorOpts } from '../solWalletConnector';
|
|
2
|
+
import { InjectedWalletBase } from './InjectedWalletBase';
|
|
3
|
+
export declare class BackpackSol extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
constructor(opts: SolWalletConnectorOpts);
|
|
7
|
+
getSigner<IBackpackSolanaSigner>(): Promise<IBackpackSolanaSigner | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { bufferToBase64 } from '@dynamic-labs/utils';
|
|
4
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
6
|
+
|
|
7
|
+
class BackpackSol extends InjectedWalletBase {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super(opts);
|
|
10
|
+
this.name = 'Backpack';
|
|
11
|
+
this.overrideKey = 'backpacksol';
|
|
12
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
13
|
+
}
|
|
14
|
+
getSigner() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.connect();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
signMessage(messageToSign) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const publicAddress = yield this.getAddress();
|
|
23
|
+
if (!publicAddress) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const provider = yield this.getSigner();
|
|
27
|
+
if (!provider) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const signedMessage = yield provider.signMessage(Buffer.from(messageToSign, 'utf8'));
|
|
31
|
+
if (!signedMessage) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (typeof signedMessage === 'object' && 'signature' in signedMessage) {
|
|
35
|
+
return bufferToBase64(signedMessage.signature);
|
|
36
|
+
}
|
|
37
|
+
return bufferToBase64(signedMessage);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { BackpackSol };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
8
|
+
|
|
9
|
+
class FallbackSolanaConnector extends InjectedWalletBase.InjectedWalletBase {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts);
|
|
12
|
+
this.name = 'Fallback Connector';
|
|
13
|
+
this.overrideKey = 'fallbackconnector';
|
|
14
|
+
this.isAvailable = false;
|
|
15
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
16
|
+
}
|
|
17
|
+
isInstalledOnBrowser() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.FallbackSolanaConnector = FallbackSolanaConnector;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SolWalletConnectorOpts } from '../solWalletConnector';
|
|
2
|
+
import { InjectedWalletBase } from './InjectedWalletBase';
|
|
3
|
+
export declare class FallbackSolanaConnector extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
isAvailable: boolean;
|
|
7
|
+
constructor(opts: SolWalletConnectorOpts);
|
|
8
|
+
isInstalledOnBrowser(): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
4
|
+
|
|
5
|
+
class FallbackSolanaConnector extends InjectedWalletBase {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
super(opts);
|
|
8
|
+
this.name = 'Fallback Connector';
|
|
9
|
+
this.overrideKey = 'fallbackconnector';
|
|
10
|
+
this.isAvailable = false;
|
|
11
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
12
|
+
}
|
|
13
|
+
isInstalledOnBrowser() {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { FallbackSolanaConnector };
|