@dynamic-labs/solana-core 3.0.0-alpha.52 → 3.0.0-alpha.54
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 +46 -0
- package/package.json +8 -5
- package/src/connector/SolWalletConnector.cjs +175 -0
- package/src/connector/SolWalletConnector.d.ts +37 -0
- package/src/connector/SolWalletConnector.js +171 -0
- package/src/connector/index.d.ts +1 -0
- package/src/constants.cjs +8 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +4 -0
- package/src/index.cjs +14 -4
- package/src/index.d.ts +4 -0
- package/src/index.js +5 -0
- package/src/types.d.ts +60 -0
- package/src/utils/extractNonce/extractNonce.cjs +14 -0
- package/src/utils/extractNonce/extractNonce.d.ts +1 -0
- package/src/utils/extractNonce/extractNonce.js +10 -0
- package/src/utils/extractNonce/index.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs +10 -0
- package/src/utils/getGenesisHashLSKey/getGenesisHashLSKey.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey/getGenesisHashLSKey.js +6 -0
- package/src/utils/getGenesisHashLSKey/index.d.ts +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/wallet/SolanaWallet.cjs +68 -0
- package/src/wallet/SolanaWallet.d.ts +17 -0
- package/src/wallet/SolanaWallet.js +64 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isSolanaWallet/index.d.ts +1 -0
- package/src/wallet/isSolanaWallet/isSolanaWallet.cjs +8 -0
- package/src/wallet/isSolanaWallet/isSolanaWallet.d.ts +3 -0
- package/src/wallet/isSolanaWallet/isSolanaWallet.js +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.54](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.53...v3.0.0-alpha.54) (2024-08-29)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* transaction hanging in confirmation modal ([#6740](https://github.com/dynamic-labs/DynamicAuth/issues/6740)) ([f03d286](https://github.com/dynamic-labs/DynamicAuth/commit/f03d286aaf471dbc7a6149acee10512be7b56b18))
|
|
8
|
+
|
|
9
|
+
## [3.0.0-alpha.53](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.52...v3.0.0-alpha.53) (2024-08-29)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### ⚠ BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* simplify solana wallet signer types (#6748)
|
|
15
|
+
* deprecate getEoaConnector (#6571)
|
|
16
|
+
* limit methods and props returned by wallet.connector (#6540)
|
|
17
|
+
* move generic solana code to solana-core package (#6701)
|
|
18
|
+
* revamp ether v6 interface (#6548)
|
|
19
|
+
* add ethereum wallet specific methods and intercept to sync when needed (#6662)
|
|
20
|
+
* add solana wallet specific methods and intercept to sync when needed (#6608)
|
|
21
|
+
* don't force primary wallet to be connected (#6128)
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* add bitcoin wallet specific methods and intercept to sync when needed ([#6663](https://github.com/dynamic-labs/DynamicAuth/issues/6663)) ([ed699b1](https://github.com/dynamic-labs/DynamicAuth/commit/ed699b1f8c264755779ec4840d105f89ade5500e))
|
|
26
|
+
* add ethereum wallet specific methods and intercept to sync when needed ([#6662](https://github.com/dynamic-labs/DynamicAuth/issues/6662)) ([372360e](https://github.com/dynamic-labs/DynamicAuth/commit/372360ed7ca395f88811fc62c94b2b494eb59971))
|
|
27
|
+
* add solana wallet specific methods and intercept to sync when needed ([#6608](https://github.com/dynamic-labs/DynamicAuth/issues/6608)) ([565f610](https://github.com/dynamic-labs/DynamicAuth/commit/565f6100340296c267e9706fd263e9bd3f7d3732))
|
|
28
|
+
* add useSmartWallets hook to manage aa wallets ([#6564](https://github.com/dynamic-labs/DynamicAuth/issues/6564)) ([a243d36](https://github.com/dynamic-labs/DynamicAuth/commit/a243d361ce7c368d0f1afda55f9c1fabefd75ba8))
|
|
29
|
+
* don't force primary wallet to be connected ([#6128](https://github.com/dynamic-labs/DynamicAuth/issues/6128)) ([018a6f6](https://github.com/dynamic-labs/DynamicAuth/commit/018a6f66f8725914ab97ea3e2e1c80626266e503))
|
|
30
|
+
* new prop to enable prompt for linking when account change is detected ([#6713](https://github.com/dynamic-labs/DynamicAuth/issues/6713)) ([b5a6321](https://github.com/dynamic-labs/DynamicAuth/commit/b5a63212ae33fae24401f141d5ca2356b446dcff))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* always sync wagmi client with primary wallet ([#6577](https://github.com/dynamic-labs/DynamicAuth/issues/6577)) ([be22fde](https://github.com/dynamic-labs/DynamicAuth/commit/be22fdea3bb61db79b06ba56cb32da6cd8141b66))
|
|
36
|
+
* cosmos wallet intercepts ([#6720](https://github.com/dynamic-labs/DynamicAuth/issues/6720)) ([cfc9df4](https://github.com/dynamic-labs/DynamicAuth/commit/cfc9df48a8032f7348fec14f77b9e378d2e26a22))
|
|
37
|
+
* magiceden wallet events not working correctly on page refresh ([#6735](https://github.com/dynamic-labs/DynamicAuth/issues/6735)) ([6ed5964](https://github.com/dynamic-labs/DynamicAuth/commit/6ed5964134a2cafd392c19f18eb71e6ca2ce238d))
|
|
38
|
+
* use proxy to intercept solana signer methods ([#6743](https://github.com/dynamic-labs/DynamicAuth/issues/6743)) ([ecbe5ea](https://github.com/dynamic-labs/DynamicAuth/commit/ecbe5ea772592d2c693d8222d85b7642acd151a8))
|
|
39
|
+
* wallet.chain references ([525c1ca](https://github.com/dynamic-labs/DynamicAuth/commit/525c1ca9a8fe6402c06eabe6aebc30e310411d9b))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
* deprecate getEoaConnector ([#6571](https://github.com/dynamic-labs/DynamicAuth/issues/6571)) ([0226ee5](https://github.com/dynamic-labs/DynamicAuth/commit/0226ee5a13f2418607076ee6f2ec0a579b06dd5d))
|
|
43
|
+
* limit methods and props returned by wallet.connector ([#6540](https://github.com/dynamic-labs/DynamicAuth/issues/6540)) ([9c86e35](https://github.com/dynamic-labs/DynamicAuth/commit/9c86e35c72cd40313bfd19254dd6171ee8f62213))
|
|
44
|
+
* move generic solana code to solana-core package ([#6701](https://github.com/dynamic-labs/DynamicAuth/issues/6701)) ([30815f5](https://github.com/dynamic-labs/DynamicAuth/commit/30815f5d46feeefb2413c1b7d30b43d5370ee032))
|
|
45
|
+
* revamp ether v6 interface ([#6548](https://github.com/dynamic-labs/DynamicAuth/issues/6548)) ([f3b2fb8](https://github.com/dynamic-labs/DynamicAuth/commit/f3b2fb8da7de21f9c58e67fa7f5580166195092a))
|
|
46
|
+
* simplify solana wallet signer types ([#6748](https://github.com/dynamic-labs/DynamicAuth/issues/6748)) ([01d1a42](https://github.com/dynamic-labs/DynamicAuth/commit/01d1a42bc916ab329580b741ba60d706bf6c5491))
|
|
47
|
+
|
|
2
48
|
## [3.0.0-alpha.52](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.51...v3.0.0-alpha.52) (2024-08-28)
|
|
3
49
|
|
|
4
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/solana-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.54",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -26,13 +26,16 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.519",
|
|
29
30
|
"@solana/web3.js": "1.92.1",
|
|
30
31
|
"@solana/spl-token": "0.4.6"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"@dynamic-labs/rpc-providers": "3.0.0-alpha.
|
|
34
|
-
"@dynamic-labs/
|
|
35
|
-
"@dynamic-labs/
|
|
36
|
-
"@dynamic-labs/
|
|
34
|
+
"@dynamic-labs/rpc-providers": "3.0.0-alpha.54",
|
|
35
|
+
"@dynamic-labs/types": "3.0.0-alpha.54",
|
|
36
|
+
"@dynamic-labs/utils": "3.0.0-alpha.54",
|
|
37
|
+
"@dynamic-labs/wallet-book": "3.0.0-alpha.54",
|
|
38
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.54",
|
|
39
|
+
"eventemitter3": "5.0.1"
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -0,0 +1,175 @@
|
|
|
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 walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
11
|
+
var SolanaWallet = require('../wallet/SolanaWallet.cjs');
|
|
12
|
+
var extractNonce = require('../utils/extractNonce/extractNonce.cjs');
|
|
13
|
+
var getGenesisHashLSKey = require('../utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
|
|
14
|
+
|
|
15
|
+
const MEMO_PROGRAM_ID = new web3_js.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
16
|
+
class SolWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
var _a;
|
|
19
|
+
super(opts);
|
|
20
|
+
this.isHardwareWalletEnabled = false;
|
|
21
|
+
this.verifiedCredentials = [];
|
|
22
|
+
this.ChainWallet = SolanaWallet.SolanaWallet;
|
|
23
|
+
this.supportedChains = ['SOL'];
|
|
24
|
+
this.connectedChain = 'SOL';
|
|
25
|
+
this.solNetworks = opts.solNetworks;
|
|
26
|
+
this.chainRpcProviders = opts.chainRpcProviders;
|
|
27
|
+
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders();
|
|
28
|
+
}
|
|
29
|
+
getNetwork() {
|
|
30
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const provider = this.getWalletClient();
|
|
32
|
+
let genesisHash = localStorage.getItem(getGenesisHashLSKey.getGenesisHashLSKey(provider.rpcEndpoint));
|
|
33
|
+
if (!genesisHash) {
|
|
34
|
+
genesisHash = yield provider.getGenesisHash();
|
|
35
|
+
localStorage.setItem(getGenesisHashLSKey.getGenesisHashLSKey(provider.rpcEndpoint), genesisHash);
|
|
36
|
+
}
|
|
37
|
+
genesisHash = genesisHash.substring(0, 32);
|
|
38
|
+
// see: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
|
|
39
|
+
let network;
|
|
40
|
+
if (genesisHash === '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') {
|
|
41
|
+
network = 'mainnet';
|
|
42
|
+
}
|
|
43
|
+
else if (genesisHash === 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1') {
|
|
44
|
+
network = 'devnet';
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
network = 'testnet';
|
|
48
|
+
}
|
|
49
|
+
return network;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
endSession() {
|
|
53
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
localStorage.removeItem(getGenesisHashLSKey.getGenesisHashLSKey(this.getWalletClient().rpcEndpoint));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getWalletClient() {
|
|
58
|
+
var _a;
|
|
59
|
+
const [network] = this.solNetworks;
|
|
60
|
+
if (!network) {
|
|
61
|
+
throw new utils.DynamicError('No enabled networks');
|
|
62
|
+
}
|
|
63
|
+
const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
|
|
64
|
+
return new web3_js.Connection(rpcUrl, 'confirmed');
|
|
65
|
+
}
|
|
66
|
+
getPublicClient() {
|
|
67
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
if (this.solNetworks.length === 0)
|
|
70
|
+
return;
|
|
71
|
+
const configurations = {
|
|
72
|
+
cosmos: [],
|
|
73
|
+
evm: undefined,
|
|
74
|
+
solana: this.solNetworks,
|
|
75
|
+
starknet: undefined,
|
|
76
|
+
};
|
|
77
|
+
if (!this.chainRpcProviders)
|
|
78
|
+
return undefined;
|
|
79
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
80
|
+
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers, '101')) === null || _a === void 0 ? void 0 : _a.provider;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getBalance(address) {
|
|
84
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const publicKey = new web3_js.PublicKey(address);
|
|
86
|
+
const balance = this.lamportsToSol(yield this.getWalletClient().getBalance(publicKey));
|
|
87
|
+
return balance.toString();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Solana uses lamports as the smallest unit of currency. This converts lamports to SOL.
|
|
91
|
+
lamportsToSol(lamports) {
|
|
92
|
+
return lamports / 1000000000;
|
|
93
|
+
}
|
|
94
|
+
canConnectWithHardwareWallet() {
|
|
95
|
+
const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
96
|
+
if (!wallet || !wallet.hardwareWallets)
|
|
97
|
+
return false;
|
|
98
|
+
return wallet.hardwareWallets.includes('ledger');
|
|
99
|
+
}
|
|
100
|
+
signMessage(messageToSign) {
|
|
101
|
+
const _super = Object.create(null, {
|
|
102
|
+
signMessage: { get: () => super.signMessage }
|
|
103
|
+
});
|
|
104
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (this.isHardwareWalletEnabled) {
|
|
106
|
+
throw new utils.NotSupportedError(`Message signing is currently not supported on ${this.name} hardware wallet.
|
|
107
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
108
|
+
by signing a transaction with a memo instruction.
|
|
109
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
110
|
+
}
|
|
111
|
+
return _super.signMessage.call(this, messageToSign);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
proveOwnership(address, messageToSign) {
|
|
115
|
+
const _super = Object.create(null, {
|
|
116
|
+
proveOwnership: { get: () => super.proveOwnership }
|
|
117
|
+
});
|
|
118
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
yield this.validateActiveWallet(address);
|
|
120
|
+
if (this.isHardwareWalletEnabled) {
|
|
121
|
+
const nonce = extractNonce.extractNonce(messageToSign);
|
|
122
|
+
if (!nonce) {
|
|
123
|
+
throw new utils.DynamicError('Nonce missing');
|
|
124
|
+
}
|
|
125
|
+
return this.signMessageViaTransaction(nonce);
|
|
126
|
+
}
|
|
127
|
+
return _super.proveOwnership.call(this, address, messageToSign);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
signMessageViaTransaction(messageToSign) {
|
|
131
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const address = yield this.getAddress();
|
|
133
|
+
if (!address) {
|
|
134
|
+
throw new utils.DynamicError('Address missing');
|
|
135
|
+
}
|
|
136
|
+
const transaction = this.buildAuthTx(messageToSign);
|
|
137
|
+
transaction.feePayer = new web3_js.PublicKey(address);
|
|
138
|
+
transaction.recentBlockhash = (yield this.getWalletClient().getLatestBlockhash()).blockhash;
|
|
139
|
+
const signer = yield this.getSigner();
|
|
140
|
+
if (!signer) {
|
|
141
|
+
throw new utils.DynamicError('Signer not found');
|
|
142
|
+
}
|
|
143
|
+
const signedTransaction = yield signer.signTransaction(transaction);
|
|
144
|
+
const serializedSignedTransaction = signedTransaction.serialize();
|
|
145
|
+
/**
|
|
146
|
+
* Serializing the transaction and adding the type 'Buffer' is required
|
|
147
|
+
* when connecting with backpack + Ledger, because the returned object is not correctly
|
|
148
|
+
* serialized
|
|
149
|
+
*/
|
|
150
|
+
return JSON.stringify({
|
|
151
|
+
signedTransaction: {
|
|
152
|
+
data: Array.from(serializedSignedTransaction),
|
|
153
|
+
type: 'Buffer',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
buildAuthTx(message) {
|
|
159
|
+
const transaction = new web3_js.Transaction();
|
|
160
|
+
transaction.add(new web3_js.TransactionInstruction({
|
|
161
|
+
data: Buffer.from(message, 'utf8'),
|
|
162
|
+
keys: [],
|
|
163
|
+
programId: MEMO_PROGRAM_ID,
|
|
164
|
+
}));
|
|
165
|
+
return transaction;
|
|
166
|
+
}
|
|
167
|
+
setVerifiedCredentials(verifiedCredentials) {
|
|
168
|
+
this.verifiedCredentials = verifiedCredentials;
|
|
169
|
+
}
|
|
170
|
+
isLedgerAddress(address) {
|
|
171
|
+
return utils.isLedgerAddressViaVerifiedCredentials(address, this.verifiedCredentials);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
exports.SolWalletConnector = SolWalletConnector;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3.js';
|
|
2
|
+
import { Chain, IHardwareWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
6
|
+
import { IChainRpcProviders } from '../rpc';
|
|
7
|
+
import { SolanaWallet } from '../wallet';
|
|
8
|
+
import { ISolana } from '../types';
|
|
9
|
+
export type SolWalletConnectorOpts = {
|
|
10
|
+
chainRpcProviders: IChainRpcProviders;
|
|
11
|
+
solNetworks: GenericNetwork[];
|
|
12
|
+
walletBook: WalletBookSchema;
|
|
13
|
+
};
|
|
14
|
+
export declare abstract class SolWalletConnector extends WalletConnectorBase<typeof SolanaWallet> implements IHardwareWalletConnector {
|
|
15
|
+
isHardwareWalletEnabled: boolean;
|
|
16
|
+
verifiedCredentials: JwtVerifiedCredential[];
|
|
17
|
+
solNetworks: GenericNetwork[];
|
|
18
|
+
ChainWallet: typeof SolanaWallet;
|
|
19
|
+
supportedChains: Chain[];
|
|
20
|
+
connectedChain: Chain;
|
|
21
|
+
constructor(opts: SolWalletConnectorOpts);
|
|
22
|
+
getNetwork(): Promise<string>;
|
|
23
|
+
endSession(): Promise<void>;
|
|
24
|
+
getWalletClient(): Connection;
|
|
25
|
+
getPublicClient(): Promise<Connection | undefined>;
|
|
26
|
+
abstract getSigner(): Promise<ISolana | undefined>;
|
|
27
|
+
abstract connect(): Promise<void>;
|
|
28
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
29
|
+
lamportsToSol(lamports: number): number;
|
|
30
|
+
canConnectWithHardwareWallet(): boolean;
|
|
31
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
32
|
+
proveOwnership(address: string, messageToSign: string): Promise<string | undefined>;
|
|
33
|
+
signMessageViaTransaction(messageToSign: string): Promise<string>;
|
|
34
|
+
private buildAuthTx;
|
|
35
|
+
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
36
|
+
isLedgerAddress(address: string): boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { PublicKey, Connection, Transaction, TransactionInstruction } from '@solana/web3.js';
|
|
4
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { DynamicError, isLedgerAddressViaVerifiedCredentials, NotSupportedError } from '@dynamic-labs/utils';
|
|
6
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
7
|
+
import { SolanaWallet } from '../wallet/SolanaWallet.js';
|
|
8
|
+
import { extractNonce } from '../utils/extractNonce/extractNonce.js';
|
|
9
|
+
import { getGenesisHashLSKey } from '../utils/getGenesisHashLSKey/getGenesisHashLSKey.js';
|
|
10
|
+
|
|
11
|
+
const MEMO_PROGRAM_ID = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
12
|
+
class SolWalletConnector extends WalletConnectorBase {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
var _a;
|
|
15
|
+
super(opts);
|
|
16
|
+
this.isHardwareWalletEnabled = false;
|
|
17
|
+
this.verifiedCredentials = [];
|
|
18
|
+
this.ChainWallet = SolanaWallet;
|
|
19
|
+
this.supportedChains = ['SOL'];
|
|
20
|
+
this.connectedChain = 'SOL';
|
|
21
|
+
this.solNetworks = opts.solNetworks;
|
|
22
|
+
this.chainRpcProviders = opts.chainRpcProviders;
|
|
23
|
+
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders();
|
|
24
|
+
}
|
|
25
|
+
getNetwork() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const provider = this.getWalletClient();
|
|
28
|
+
let genesisHash = localStorage.getItem(getGenesisHashLSKey(provider.rpcEndpoint));
|
|
29
|
+
if (!genesisHash) {
|
|
30
|
+
genesisHash = yield provider.getGenesisHash();
|
|
31
|
+
localStorage.setItem(getGenesisHashLSKey(provider.rpcEndpoint), genesisHash);
|
|
32
|
+
}
|
|
33
|
+
genesisHash = genesisHash.substring(0, 32);
|
|
34
|
+
// see: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
|
|
35
|
+
let network;
|
|
36
|
+
if (genesisHash === '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') {
|
|
37
|
+
network = 'mainnet';
|
|
38
|
+
}
|
|
39
|
+
else if (genesisHash === 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1') {
|
|
40
|
+
network = 'devnet';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
network = 'testnet';
|
|
44
|
+
}
|
|
45
|
+
return network;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
endSession() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
localStorage.removeItem(getGenesisHashLSKey(this.getWalletClient().rpcEndpoint));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
getWalletClient() {
|
|
54
|
+
var _a;
|
|
55
|
+
const [network] = this.solNetworks;
|
|
56
|
+
if (!network) {
|
|
57
|
+
throw new DynamicError('No enabled networks');
|
|
58
|
+
}
|
|
59
|
+
const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
|
|
60
|
+
return new Connection(rpcUrl, 'confirmed');
|
|
61
|
+
}
|
|
62
|
+
getPublicClient() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
|
+
if (this.solNetworks.length === 0)
|
|
66
|
+
return;
|
|
67
|
+
const configurations = {
|
|
68
|
+
cosmos: [],
|
|
69
|
+
evm: undefined,
|
|
70
|
+
solana: this.solNetworks,
|
|
71
|
+
starknet: undefined,
|
|
72
|
+
};
|
|
73
|
+
if (!this.chainRpcProviders)
|
|
74
|
+
return undefined;
|
|
75
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
76
|
+
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers, '101')) === null || _a === void 0 ? void 0 : _a.provider;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getBalance(address) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const publicKey = new PublicKey(address);
|
|
82
|
+
const balance = this.lamportsToSol(yield this.getWalletClient().getBalance(publicKey));
|
|
83
|
+
return balance.toString();
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Solana uses lamports as the smallest unit of currency. This converts lamports to SOL.
|
|
87
|
+
lamportsToSol(lamports) {
|
|
88
|
+
return lamports / 1000000000;
|
|
89
|
+
}
|
|
90
|
+
canConnectWithHardwareWallet() {
|
|
91
|
+
const wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
92
|
+
if (!wallet || !wallet.hardwareWallets)
|
|
93
|
+
return false;
|
|
94
|
+
return wallet.hardwareWallets.includes('ledger');
|
|
95
|
+
}
|
|
96
|
+
signMessage(messageToSign) {
|
|
97
|
+
const _super = Object.create(null, {
|
|
98
|
+
signMessage: { get: () => super.signMessage }
|
|
99
|
+
});
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
if (this.isHardwareWalletEnabled) {
|
|
102
|
+
throw new NotSupportedError(`Message signing is currently not supported on ${this.name} hardware wallet.
|
|
103
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
104
|
+
by signing a transaction with a memo instruction.
|
|
105
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
106
|
+
}
|
|
107
|
+
return _super.signMessage.call(this, messageToSign);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
proveOwnership(address, messageToSign) {
|
|
111
|
+
const _super = Object.create(null, {
|
|
112
|
+
proveOwnership: { get: () => super.proveOwnership }
|
|
113
|
+
});
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
yield this.validateActiveWallet(address);
|
|
116
|
+
if (this.isHardwareWalletEnabled) {
|
|
117
|
+
const nonce = extractNonce(messageToSign);
|
|
118
|
+
if (!nonce) {
|
|
119
|
+
throw new DynamicError('Nonce missing');
|
|
120
|
+
}
|
|
121
|
+
return this.signMessageViaTransaction(nonce);
|
|
122
|
+
}
|
|
123
|
+
return _super.proveOwnership.call(this, address, messageToSign);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
signMessageViaTransaction(messageToSign) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const address = yield this.getAddress();
|
|
129
|
+
if (!address) {
|
|
130
|
+
throw new DynamicError('Address missing');
|
|
131
|
+
}
|
|
132
|
+
const transaction = this.buildAuthTx(messageToSign);
|
|
133
|
+
transaction.feePayer = new PublicKey(address);
|
|
134
|
+
transaction.recentBlockhash = (yield this.getWalletClient().getLatestBlockhash()).blockhash;
|
|
135
|
+
const signer = yield this.getSigner();
|
|
136
|
+
if (!signer) {
|
|
137
|
+
throw new DynamicError('Signer not found');
|
|
138
|
+
}
|
|
139
|
+
const signedTransaction = yield signer.signTransaction(transaction);
|
|
140
|
+
const serializedSignedTransaction = signedTransaction.serialize();
|
|
141
|
+
/**
|
|
142
|
+
* Serializing the transaction and adding the type 'Buffer' is required
|
|
143
|
+
* when connecting with backpack + Ledger, because the returned object is not correctly
|
|
144
|
+
* serialized
|
|
145
|
+
*/
|
|
146
|
+
return JSON.stringify({
|
|
147
|
+
signedTransaction: {
|
|
148
|
+
data: Array.from(serializedSignedTransaction),
|
|
149
|
+
type: 'Buffer',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
buildAuthTx(message) {
|
|
155
|
+
const transaction = new Transaction();
|
|
156
|
+
transaction.add(new TransactionInstruction({
|
|
157
|
+
data: Buffer.from(message, 'utf8'),
|
|
158
|
+
keys: [],
|
|
159
|
+
programId: MEMO_PROGRAM_ID,
|
|
160
|
+
}));
|
|
161
|
+
return transaction;
|
|
162
|
+
}
|
|
163
|
+
setVerifiedCredentials(verifiedCredentials) {
|
|
164
|
+
this.verifiedCredentials = verifiedCredentials;
|
|
165
|
+
}
|
|
166
|
+
isLedgerAddress(address) {
|
|
167
|
+
return isLedgerAddressViaVerifiedCredentials(address, this.verifiedCredentials);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { SolWalletConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SolWalletConnector';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SOLANA_GENESIS_HASH = "genesis-hash";
|
package/src/constants.js
ADDED
package/src/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
+
var SolWalletConnector = require('./connector/SolWalletConnector.cjs');
|
|
6
7
|
require('./rpc/RpcProviderSolana/RpcProviderSolana.cjs');
|
|
7
8
|
var rpcProviders = require('@dynamic-labs/rpc-providers');
|
|
8
9
|
var solanaProvidersSelector = require('./rpc/solanaProvidersSelector/solanaProvidersSelector.cjs');
|
|
@@ -10,17 +11,26 @@ var SolanaUiTransaction = require('./utils/SolanaUiTransaction/SolanaUiTransacti
|
|
|
10
11
|
var decodeTransactionFromBase64 = require('./utils/decodeTransactionFromBase64/decodeTransactionFromBase64.cjs');
|
|
11
12
|
var isVersionedTransaction = require('./utils/isVersionedTransaction/isVersionedTransaction.cjs');
|
|
12
13
|
var encodeTransactionToBase64 = require('./utils/encodeTransactionToBase64/encodeTransactionToBase64.cjs');
|
|
14
|
+
var getGenesisHashLSKey = require('./utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
|
|
15
|
+
var SolanaWallet = require('./wallet/SolanaWallet.cjs');
|
|
16
|
+
var isSolanaWallet = require('./wallet/isSolanaWallet/isSolanaWallet.cjs');
|
|
17
|
+
var constants = require('./constants.cjs');
|
|
13
18
|
|
|
14
19
|
|
|
15
20
|
|
|
21
|
+
exports.SolWalletConnector = SolWalletConnector.SolWalletConnector;
|
|
16
22
|
exports.solanaProvidersSelector = solanaProvidersSelector.solanaProvidersSelector;
|
|
17
23
|
exports.SolanaUiTransaction = SolanaUiTransaction.SolanaUiTransaction;
|
|
18
24
|
exports.decodeTransactionFromBase64 = decodeTransactionFromBase64.decodeTransactionFromBase64;
|
|
19
25
|
exports.isVersionedTransaction = isVersionedTransaction.isVersionedTransaction;
|
|
20
26
|
exports.encodeTransactionToBase64 = encodeTransactionToBase64.encodeTransactionToBase64;
|
|
27
|
+
exports.getGenesisHashLSKey = getGenesisHashLSKey.getGenesisHashLSKey;
|
|
28
|
+
exports.SolanaWallet = SolanaWallet.SolanaWallet;
|
|
29
|
+
exports.isSolanaWallet = isSolanaWallet.isSolanaWallet;
|
|
30
|
+
exports.SOLANA_GENESIS_HASH = constants.SOLANA_GENESIS_HASH;
|
|
21
31
|
Object.keys(rpcProviders).forEach(function (k) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return rpcProviders[k]; }
|
|
35
|
+
});
|
|
26
36
|
});
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
export * from './connector';
|
|
1
2
|
export * from './rpc';
|
|
2
3
|
export * from './utils';
|
|
4
|
+
export * from './wallet';
|
|
5
|
+
export { SOLANA_GENESIS_HASH } from './constants';
|
|
6
|
+
export type { ConnectionResult, ExtensionLocator, ISolana, IBackpackSolanaSigner, SignedMessage, ISolanaSigner, } from './types';
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
export { SolWalletConnector } from './connector/SolWalletConnector.js';
|
|
2
3
|
import './rpc/RpcProviderSolana/RpcProviderSolana.js';
|
|
3
4
|
export * from '@dynamic-labs/rpc-providers';
|
|
4
5
|
export { solanaProvidersSelector } from './rpc/solanaProvidersSelector/solanaProvidersSelector.js';
|
|
@@ -6,3 +7,7 @@ export { SolanaUiTransaction } from './utils/SolanaUiTransaction/SolanaUiTransac
|
|
|
6
7
|
export { decodeTransactionFromBase64 } from './utils/decodeTransactionFromBase64/decodeTransactionFromBase64.js';
|
|
7
8
|
export { isVersionedTransaction } from './utils/isVersionedTransaction/isVersionedTransaction.js';
|
|
8
9
|
export { encodeTransactionToBase64 } from './utils/encodeTransactionToBase64/encodeTransactionToBase64.js';
|
|
10
|
+
export { getGenesisHashLSKey } from './utils/getGenesisHashLSKey/getGenesisHashLSKey.js';
|
|
11
|
+
export { SolanaWallet } from './wallet/SolanaWallet.js';
|
|
12
|
+
export { isSolanaWallet } from './wallet/isSolanaWallet/isSolanaWallet.js';
|
|
13
|
+
export { SOLANA_GENESIS_HASH } from './constants.js';
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Connection, SendOptions, Signer, Transaction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import EventEmitter from 'eventemitter3';
|
|
3
|
+
declare global {
|
|
4
|
+
interface IWindowPhantom {
|
|
5
|
+
solana: ISolana;
|
|
6
|
+
}
|
|
7
|
+
interface Window {
|
|
8
|
+
coinbaseSolana?: ISolana;
|
|
9
|
+
glowSolana?: ISolana;
|
|
10
|
+
phantom?: IWindowPhantom;
|
|
11
|
+
solana?: ISolana;
|
|
12
|
+
solflare?: ISolana;
|
|
13
|
+
backpack?: IBackpackSolanaSigner;
|
|
14
|
+
magicEden?: {
|
|
15
|
+
solana: ISolana;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
type PublicKey = {
|
|
20
|
+
toString: () => string;
|
|
21
|
+
};
|
|
22
|
+
export type ConnectionResult = {
|
|
23
|
+
address?: string;
|
|
24
|
+
publicKey?: PublicKey;
|
|
25
|
+
} | undefined;
|
|
26
|
+
interface ISolanaEvents {
|
|
27
|
+
connect(...args: unknown[]): unknown;
|
|
28
|
+
disconnect(...args: unknown[]): unknown;
|
|
29
|
+
accountChanged(publicKey: string): unknown;
|
|
30
|
+
activeWalletDidChange(publicKey: string): unknown;
|
|
31
|
+
}
|
|
32
|
+
export type SignedMessage = {
|
|
33
|
+
signature: Uint8Array;
|
|
34
|
+
};
|
|
35
|
+
type ExtensionLocators = {
|
|
36
|
+
[key in ExtensionLocator]: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type ISolanaSigner = ExtensionLocators & EventEmitter<ISolanaEvents> & {
|
|
39
|
+
publicKey?: {
|
|
40
|
+
toBytes(): Uint8Array;
|
|
41
|
+
};
|
|
42
|
+
isConnected: boolean;
|
|
43
|
+
providers: ISolanaSigner[];
|
|
44
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
45
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
|
|
46
|
+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<{
|
|
47
|
+
signature: TransactionSignature;
|
|
48
|
+
}>;
|
|
49
|
+
signMessage(message: Uint8Array, encoding?: string): Promise<SignedMessage>;
|
|
50
|
+
connect: (args?: {
|
|
51
|
+
onlyIfTrusted: boolean;
|
|
52
|
+
}) => Promise<ConnectionResult>;
|
|
53
|
+
disconnect(): Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
export type IBackpackSolanaSigner = ISolanaSigner & {
|
|
56
|
+
send: (transaction: Transaction, signers?: Signer[], options?: SendOptions, connection?: Connection, publicKey?: PublicKey) => Promise<TransactionSignature>;
|
|
57
|
+
};
|
|
58
|
+
export type ISolana = ISolanaSigner | IBackpackSolanaSigner;
|
|
59
|
+
export type ExtensionLocator = 'isBraveWallet' | 'isGlow' | 'isPhantom' | 'isSolflare' | 'isExodus' | 'isBackpack' | 'isMagicEden';
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const extractNonce = (messageToSign) => {
|
|
7
|
+
const regex = messageToSign.match(/Nonce: (.*)/);
|
|
8
|
+
if (regex && regex.length === 2) {
|
|
9
|
+
return regex[1];
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.extractNonce = extractNonce;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const extractNonce: (messageToSign: string) => string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { extractNonce } from './extractNonce';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var constants = require('../../constants.cjs');
|
|
7
|
+
|
|
8
|
+
const getGenesisHashLSKey = (rpcEndpoint) => `${rpcEndpoint}_${constants.SOLANA_GENESIS_HASH}`;
|
|
9
|
+
|
|
10
|
+
exports.getGenesisHashLSKey = getGenesisHashLSKey;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getGenesisHashLSKey: (rpcEndpoint: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getGenesisHashLSKey } from './getGenesisHashLSKey';
|
package/src/utils/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { SolanaUiTransaction } from './SolanaUiTransaction';
|
|
|
2
2
|
export { decodeTransactionFromBase64 } from './decodeTransactionFromBase64';
|
|
3
3
|
export { isVersionedTransaction } from './isVersionedTransaction';
|
|
4
4
|
export { encodeTransactionToBase64, type EncodedTransaction, } from './encodeTransactionToBase64';
|
|
5
|
+
export { getGenesisHashLSKey } from './getGenesisHashLSKey';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
|
|
9
|
+
class SolanaWallet extends walletConnectorCore.Wallet {
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves the RPC connection
|
|
12
|
+
* @returns A promise that resolves to the RPC connection
|
|
13
|
+
*/
|
|
14
|
+
getConnection() {
|
|
15
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return this._connector.getWalletClient();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the solana signer for the wallet.
|
|
21
|
+
* @returns A promise that resolves to the signer,
|
|
22
|
+
* or throws an error if the signer cannot be retrieved.
|
|
23
|
+
*/
|
|
24
|
+
getSigner() {
|
|
25
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const signer = yield this._connector.getSigner();
|
|
27
|
+
if (!signer) {
|
|
28
|
+
throw new Error('unable to retrieve Solana signer');
|
|
29
|
+
}
|
|
30
|
+
const proxiedSigner = new Proxy(signer, {
|
|
31
|
+
get: (target, prop) => {
|
|
32
|
+
switch (prop) {
|
|
33
|
+
case 'signTransaction': {
|
|
34
|
+
return (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.sync();
|
|
36
|
+
return target.signTransaction(transaction);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
case 'signAllTransactions': {
|
|
40
|
+
return (transactions) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield this.sync();
|
|
42
|
+
return target.signAllTransactions(transactions);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
case 'signAndSendTransaction': {
|
|
46
|
+
return (transaction, ...args) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield this.sync();
|
|
48
|
+
return target.signAndSendTransaction(transaction, ...args);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
case 'signMessage': {
|
|
52
|
+
return (message, ...args) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
yield this.sync();
|
|
54
|
+
return target.signMessage(message, ...args);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
default: {
|
|
58
|
+
return Reflect.get(target, prop);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return proxiedSigner;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.SolanaWallet = SolanaWallet;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3.js';
|
|
2
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { SolWalletConnector } from '../connector';
|
|
4
|
+
import { ISolana } from '../types';
|
|
5
|
+
export declare class SolanaWallet extends Wallet<SolWalletConnector> {
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves the RPC connection
|
|
8
|
+
* @returns A promise that resolves to the RPC connection
|
|
9
|
+
*/
|
|
10
|
+
getConnection(): Promise<Connection>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the solana signer for the wallet.
|
|
13
|
+
* @returns A promise that resolves to the signer,
|
|
14
|
+
* or throws an error if the signer cannot be retrieved.
|
|
15
|
+
*/
|
|
16
|
+
getSigner(): Promise<ISolana>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
|
|
5
|
+
class SolanaWallet extends Wallet {
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves the RPC connection
|
|
8
|
+
* @returns A promise that resolves to the RPC connection
|
|
9
|
+
*/
|
|
10
|
+
getConnection() {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
return this._connector.getWalletClient();
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the solana signer for the wallet.
|
|
17
|
+
* @returns A promise that resolves to the signer,
|
|
18
|
+
* or throws an error if the signer cannot be retrieved.
|
|
19
|
+
*/
|
|
20
|
+
getSigner() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const signer = yield this._connector.getSigner();
|
|
23
|
+
if (!signer) {
|
|
24
|
+
throw new Error('unable to retrieve Solana signer');
|
|
25
|
+
}
|
|
26
|
+
const proxiedSigner = new Proxy(signer, {
|
|
27
|
+
get: (target, prop) => {
|
|
28
|
+
switch (prop) {
|
|
29
|
+
case 'signTransaction': {
|
|
30
|
+
return (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield this.sync();
|
|
32
|
+
return target.signTransaction(transaction);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
case 'signAllTransactions': {
|
|
36
|
+
return (transactions) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
yield this.sync();
|
|
38
|
+
return target.signAllTransactions(transactions);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
case 'signAndSendTransaction': {
|
|
42
|
+
return (transaction, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
yield this.sync();
|
|
44
|
+
return target.signAndSendTransaction(transaction, ...args);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
case 'signMessage': {
|
|
48
|
+
return (message, ...args) => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
yield this.sync();
|
|
50
|
+
return target.signMessage(message, ...args);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
return Reflect.get(target, prop);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return proxiedSigner;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { SolanaWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isSolanaWallet';
|