@dynamic-labs/solana 1.1.0-alpha.12 → 1.1.0-alpha.13
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 +18 -0
- package/_virtual/_tslib.cjs +6 -1
- package/_virtual/_tslib.js +6 -1
- package/package.json +7 -6
- package/src/CoinbaseSolana.cjs +1 -2
- package/src/CoinbaseSolana.js +1 -2
- package/src/errors/SignMessageNotSupportedError.cjs +16 -0
- package/src/errors/SignMessageNotSupportedError.d.ts +4 -0
- package/src/errors/SignMessageNotSupportedError.js +12 -0
- package/src/injected/InjectedWalletBase.cjs +5 -0
- package/src/injected/InjectedWalletBase.js +5 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +0 -2
- package/src/injected/fetchInjectedWalletConnectors.js +0 -2
- package/src/solWalletConnector.cjs +86 -0
- package/src/solWalletConnector.d.ts +12 -2
- package/src/solWalletConnector.js +88 -2
- package/src/injected/PhantomLedger.cjs +0 -72
- package/src/injected/PhantomLedger.d.ts +0 -16
- package/src/injected/PhantomLedger.js +0 -67
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.1.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.12...v1.1.0-alpha.13) (2024-01-23)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add createWalletClientFromWallet helper function ([#4416](https://github.com/dynamic-labs/DynamicAuth/issues/4416)) ([b384898](https://github.com/dynamic-labs/DynamicAuth/commit/b384898061bb3f9b38b2ed670b6650cfc1d4b429))
|
|
8
|
+
* add hardware wallets to wallet book ([#4445](https://github.com/dynamic-labs/DynamicAuth/issues/4445)) ([66c0f5b](https://github.com/dynamic-labs/DynamicAuth/commit/66c0f5b29a6a700099bb95a6f7622f6178e0bccf))
|
|
9
|
+
* add support for Argent Web and Mobile ([#4328](https://github.com/dynamic-labs/DynamicAuth/issues/4328)) ([bce20b8](https://github.com/dynamic-labs/DynamicAuth/commit/bce20b8f35a8630f2621f53a541a1acb06a38fc0))
|
|
10
|
+
* enable ledger for glow, solflare and backpack ([#4392](https://github.com/dynamic-labs/DynamicAuth/issues/4392)) ([fa7b992](https://github.com/dynamic-labs/DynamicAuth/commit/fa7b992f87ebc43560f87b43ac56f2cd9909b306))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* breaking changes script ([#4440](https://github.com/dynamic-labs/DynamicAuth/issues/4440)) ([446173d](https://github.com/dynamic-labs/DynamicAuth/commit/446173d074d652d81856c6412e304b46b1565320))
|
|
16
|
+
* broken help icon in create passkey view ([#4428](https://github.com/dynamic-labs/DynamicAuth/issues/4428)) ([e0ffc02](https://github.com/dynamic-labs/DynamicAuth/commit/e0ffc02ffea34b7ac3198ff6e1baf7f9907acddd))
|
|
17
|
+
* infinite loop when connecting with trust wallet ([#4448](https://github.com/dynamic-labs/DynamicAuth/issues/4448)) ([4e20edf](https://github.com/dynamic-labs/DynamicAuth/commit/4e20edf9abaabf20e5e9f9167b44d7f691e844f1))
|
|
18
|
+
* render wagmi elements based on react version ([#4453](https://github.com/dynamic-labs/DynamicAuth/issues/4453)) ([43c624c](https://github.com/dynamic-labs/DynamicAuth/commit/43c624ca996b0c51de1454910f19fdf908149938))
|
|
19
|
+
|
|
2
20
|
## [1.1.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.11...v1.1.0-alpha.12) (2024-01-18)
|
|
3
21
|
|
|
4
22
|
|
package/_virtual/_tslib.cjs
CHANGED
|
@@ -25,6 +25,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
25
25
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
27
|
});
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
31
|
+
var e = new Error(message);
|
|
32
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
33
|
+
};
|
|
29
34
|
|
|
30
35
|
exports.__awaiter = __awaiter;
|
package/_virtual/_tslib.js
CHANGED
|
@@ -21,6 +21,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
21
21
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
22
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
23
|
});
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
27
|
+
var e = new Error(message);
|
|
28
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
29
|
+
};
|
|
25
30
|
|
|
26
31
|
export { __awaiter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/solana",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -27,11 +27,12 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@solana/web3.js": "1.70.1",
|
|
30
|
-
"@dynamic-labs/
|
|
31
|
-
"@dynamic-labs/
|
|
32
|
-
"@dynamic-labs/
|
|
33
|
-
"@dynamic-labs/
|
|
34
|
-
"@dynamic-labs/wallet-
|
|
30
|
+
"@dynamic-labs/sdk-api": "0.0.352",
|
|
31
|
+
"@dynamic-labs/rpc-providers": "1.1.0-alpha.13",
|
|
32
|
+
"@dynamic-labs/types": "1.1.0-alpha.13",
|
|
33
|
+
"@dynamic-labs/utils": "1.1.0-alpha.13",
|
|
34
|
+
"@dynamic-labs/wallet-book": "1.1.0-alpha.13",
|
|
35
|
+
"@dynamic-labs/wallet-connector-core": "1.1.0-alpha.13",
|
|
35
36
|
"eventemitter3": "5.0.1"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {}
|
package/src/CoinbaseSolana.cjs
CHANGED
|
@@ -8,8 +8,7 @@ var walletBook = require('@dynamic-labs/wallet-book');
|
|
|
8
8
|
var InjectedWalletBase = require('./injected/InjectedWalletBase.cjs');
|
|
9
9
|
require('@solana/web3.js');
|
|
10
10
|
require('@dynamic-labs/wallet-connector-core');
|
|
11
|
-
require('
|
|
12
|
-
require('./injected/PhantomLedger.cjs');
|
|
11
|
+
require('./solWalletConnector.cjs');
|
|
13
12
|
var isSignedMessage = require('./utils/isSignedMessage.cjs');
|
|
14
13
|
|
|
15
14
|
class CoinbaseSolana extends InjectedWalletBase.InjectedWalletBase {
|
package/src/CoinbaseSolana.js
CHANGED
|
@@ -4,8 +4,7 @@ import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
|
4
4
|
import { InjectedWalletBase } from './injected/InjectedWalletBase.js';
|
|
5
5
|
import '@solana/web3.js';
|
|
6
6
|
import '@dynamic-labs/wallet-connector-core';
|
|
7
|
-
import '
|
|
8
|
-
import './injected/PhantomLedger.js';
|
|
7
|
+
import './solWalletConnector.js';
|
|
9
8
|
import { isSignedMessage } from './utils/isSignedMessage.js';
|
|
10
9
|
|
|
11
10
|
class CoinbaseSolana extends InjectedWalletBase {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils = require('@dynamic-labs/utils');
|
|
6
|
+
|
|
7
|
+
class SignMessageNotSupportedError extends utils.NotSupportedError {
|
|
8
|
+
constructor(walletName) {
|
|
9
|
+
super(`Message signing is currently not supported on ${walletName} hardware wallet.
|
|
10
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
11
|
+
by signing a transaction with a memo instruction.
|
|
12
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.SignMessageNotSupportedError = SignMessageNotSupportedError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NotSupportedError } from '@dynamic-labs/utils';
|
|
2
|
+
|
|
3
|
+
class SignMessageNotSupportedError extends NotSupportedError {
|
|
4
|
+
constructor(walletName) {
|
|
5
|
+
super(`Message signing is currently not supported on ${walletName} hardware wallet.
|
|
6
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
7
|
+
by signing a transaction with a memo instruction.
|
|
8
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { SignMessageNotSupportedError };
|
|
@@ -6,6 +6,7 @@ var _tslib = require('../../_virtual/_tslib.cjs');
|
|
|
6
6
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
7
|
var solProviderHelper = require('../solProviderHelper.cjs');
|
|
8
8
|
var solWalletConnector = require('../solWalletConnector.cjs');
|
|
9
|
+
var SignMessageNotSupportedError = require('../errors/SignMessageNotSupportedError.cjs');
|
|
9
10
|
|
|
10
11
|
class InjectedWalletBase extends solWalletConnector.SolWalletConnector {
|
|
11
12
|
getSolProviderHelper() {
|
|
@@ -46,6 +47,10 @@ class InjectedWalletBase extends solWalletConnector.SolWalletConnector {
|
|
|
46
47
|
}
|
|
47
48
|
signMessage(messageToSign) {
|
|
48
49
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const walletAddress = yield this.getSolProviderHelper().fetchPublicAddress();
|
|
51
|
+
if (walletAddress && this.isLedgerAddress(walletAddress)) {
|
|
52
|
+
throw new SignMessageNotSupportedError.SignMessageNotSupportedError(this.name);
|
|
53
|
+
}
|
|
49
54
|
return this.getSolProviderHelper().signMessage(messageToSign);
|
|
50
55
|
});
|
|
51
56
|
}
|
|
@@ -2,6 +2,7 @@ import { __awaiter } from '../../_virtual/_tslib.js';
|
|
|
2
2
|
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
3
3
|
import { SolProviderHelper } from '../solProviderHelper.js';
|
|
4
4
|
import { SolWalletConnector } from '../solWalletConnector.js';
|
|
5
|
+
import { SignMessageNotSupportedError } from '../errors/SignMessageNotSupportedError.js';
|
|
5
6
|
|
|
6
7
|
class InjectedWalletBase extends SolWalletConnector {
|
|
7
8
|
getSolProviderHelper() {
|
|
@@ -42,6 +43,10 @@ class InjectedWalletBase extends SolWalletConnector {
|
|
|
42
43
|
}
|
|
43
44
|
signMessage(messageToSign) {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const walletAddress = yield this.getSolProviderHelper().fetchPublicAddress();
|
|
47
|
+
if (walletAddress && this.isLedgerAddress(walletAddress)) {
|
|
48
|
+
throw new SignMessageNotSupportedError(this.name);
|
|
49
|
+
}
|
|
45
50
|
return this.getSolProviderHelper().signMessage(messageToSign);
|
|
46
51
|
});
|
|
47
52
|
}
|
|
@@ -6,14 +6,12 @@ var CoinbaseSolana = require('../CoinbaseSolana.cjs');
|
|
|
6
6
|
var Slope = require('../Slope.cjs');
|
|
7
7
|
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
8
8
|
var Phantom = require('./Phantom.cjs');
|
|
9
|
-
var PhantomLedger = require('./PhantomLedger.cjs');
|
|
10
9
|
var BackpackSol = require('./BackpackSol.cjs');
|
|
11
10
|
|
|
12
11
|
const injectedWalletOverrides = [
|
|
13
12
|
CoinbaseSolana.CoinbaseSolana,
|
|
14
13
|
Slope.Slope,
|
|
15
14
|
Phantom.Phantom,
|
|
16
|
-
PhantomLedger.PhantomLedger,
|
|
17
15
|
BackpackSol.BackpackSol,
|
|
18
16
|
];
|
|
19
17
|
const filteredInjectedWalletKeysOverrides = [
|
|
@@ -2,14 +2,12 @@ import { CoinbaseSolana } from '../CoinbaseSolana.js';
|
|
|
2
2
|
import { Slope } from '../Slope.js';
|
|
3
3
|
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
4
4
|
import { Phantom } from './Phantom.js';
|
|
5
|
-
import { PhantomLedger } from './PhantomLedger.js';
|
|
6
5
|
import { BackpackSol } from './BackpackSol.js';
|
|
7
6
|
|
|
8
7
|
const injectedWalletOverrides = [
|
|
9
8
|
CoinbaseSolana,
|
|
10
9
|
Slope,
|
|
11
10
|
Phantom,
|
|
12
|
-
PhantomLedger,
|
|
13
11
|
BackpackSol,
|
|
14
12
|
];
|
|
15
13
|
const filteredInjectedWalletKeysOverrides = [
|
|
@@ -7,11 +7,16 @@ var web3_js = require('@solana/web3.js');
|
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
8
|
var rpcProviders = require('@dynamic-labs/rpc-providers');
|
|
9
9
|
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
11
|
+
var extractNonce = require('./utils/extractNonce.cjs');
|
|
10
12
|
|
|
13
|
+
const MEMO_PROGRAM_ID = new web3_js.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
11
14
|
class SolWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
12
15
|
constructor(opts) {
|
|
13
16
|
var _a;
|
|
14
17
|
super(opts);
|
|
18
|
+
this.isHardwareWalletEnabled = false;
|
|
19
|
+
this.verifiedCredentials = [];
|
|
15
20
|
this.supportedChains = ['SOL'];
|
|
16
21
|
this.connectedChain = 'SOL';
|
|
17
22
|
this.solNetworks = opts.solNetworks;
|
|
@@ -87,6 +92,87 @@ class SolWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
87
92
|
lamportsToSol(lamports) {
|
|
88
93
|
return lamports / 1000000000;
|
|
89
94
|
}
|
|
95
|
+
canConnectWithHardwareWallet() {
|
|
96
|
+
const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
97
|
+
if (!wallet || !wallet.hardwareWallets)
|
|
98
|
+
return false;
|
|
99
|
+
return wallet.hardwareWallets.includes('ledger');
|
|
100
|
+
}
|
|
101
|
+
signMessage(messageToSign) {
|
|
102
|
+
const _super = Object.create(null, {
|
|
103
|
+
signMessage: { get: () => super.signMessage }
|
|
104
|
+
});
|
|
105
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
if (this.isHardwareWalletEnabled) {
|
|
107
|
+
throw new utils.NotSupportedError(`Message signing is currently not supported on ${this.name} hardware wallet.
|
|
108
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
109
|
+
by signing a transaction with a memo instruction.
|
|
110
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
111
|
+
}
|
|
112
|
+
return _super.signMessage.call(this, messageToSign);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
proveOwnership(messageToSign) {
|
|
116
|
+
const _super = Object.create(null, {
|
|
117
|
+
proveOwnership: { get: () => super.proveOwnership }
|
|
118
|
+
});
|
|
119
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
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, messageToSign);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
signMessageViaTransaction(messageToSign) {
|
|
131
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const address = yield this.fetchPublicAddress();
|
|
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
|
+
const ledgerWallets = this.verifiedCredentials
|
|
172
|
+
.filter((v) => { var _a; return ((_a = v.walletProperties) === null || _a === void 0 ? void 0 : _a.hardwareWallet) === 'ledger'; })
|
|
173
|
+
.map((v) => v.address);
|
|
174
|
+
return ledgerWallets.includes(address);
|
|
175
|
+
}
|
|
90
176
|
}
|
|
91
177
|
|
|
92
178
|
exports.SolWalletConnector = SolWalletConnector;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { Chain, IHardwareWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { GenericNetwork } from '@dynamic-labs/types';
|
|
4
4
|
import { ChainRpcProviders } from '@dynamic-labs/rpc-providers';
|
|
5
5
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
6
|
+
import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api';
|
|
6
7
|
import { ISolana } from './types';
|
|
7
8
|
export type SolWalletConnectorOpts = {
|
|
8
9
|
chainRpcProviders: typeof ChainRpcProviders;
|
|
9
10
|
solNetworks: GenericNetwork[];
|
|
10
11
|
walletBook: WalletBookSchema;
|
|
11
12
|
};
|
|
12
|
-
export declare abstract class SolWalletConnector extends WalletConnectorBase {
|
|
13
|
+
export declare abstract class SolWalletConnector extends WalletConnectorBase implements IHardwareWalletConnector {
|
|
14
|
+
isHardwareWalletEnabled: boolean;
|
|
15
|
+
verifiedCredentials: JwtVerifiedCredential[];
|
|
13
16
|
solNetworks: GenericNetwork[];
|
|
14
17
|
supportedChains: Chain[];
|
|
15
18
|
connectedChain: Chain;
|
|
@@ -21,4 +24,11 @@ export declare abstract class SolWalletConnector extends WalletConnectorBase {
|
|
|
21
24
|
abstract connect(): Promise<void>;
|
|
22
25
|
getBalance(): Promise<string | undefined>;
|
|
23
26
|
lamportsToSol(lamports: number): number;
|
|
27
|
+
canConnectWithHardwareWallet(): boolean;
|
|
28
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
29
|
+
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
30
|
+
signMessageViaTransaction(messageToSign: string): Promise<string>;
|
|
31
|
+
private buildAuthTx;
|
|
32
|
+
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
33
|
+
isLedgerAddress(address: string): boolean;
|
|
24
34
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
-
import { Connection,
|
|
2
|
+
import { PublicKey, Connection, Transaction, TransactionInstruction } from '@solana/web3.js';
|
|
3
3
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { ProviderChain } from '@dynamic-labs/rpc-providers';
|
|
5
|
-
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
|
+
import { DynamicError, NotSupportedError } from '@dynamic-labs/utils';
|
|
6
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
7
|
+
import { extractNonce } from './utils/extractNonce.js';
|
|
6
8
|
|
|
9
|
+
const MEMO_PROGRAM_ID = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
7
10
|
class SolWalletConnector extends WalletConnectorBase {
|
|
8
11
|
constructor(opts) {
|
|
9
12
|
var _a;
|
|
10
13
|
super(opts);
|
|
14
|
+
this.isHardwareWalletEnabled = false;
|
|
15
|
+
this.verifiedCredentials = [];
|
|
11
16
|
this.supportedChains = ['SOL'];
|
|
12
17
|
this.connectedChain = 'SOL';
|
|
13
18
|
this.solNetworks = opts.solNetworks;
|
|
@@ -83,6 +88,87 @@ class SolWalletConnector extends WalletConnectorBase {
|
|
|
83
88
|
lamportsToSol(lamports) {
|
|
84
89
|
return lamports / 1000000000;
|
|
85
90
|
}
|
|
91
|
+
canConnectWithHardwareWallet() {
|
|
92
|
+
const wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
93
|
+
if (!wallet || !wallet.hardwareWallets)
|
|
94
|
+
return false;
|
|
95
|
+
return wallet.hardwareWallets.includes('ledger');
|
|
96
|
+
}
|
|
97
|
+
signMessage(messageToSign) {
|
|
98
|
+
const _super = Object.create(null, {
|
|
99
|
+
signMessage: { get: () => super.signMessage }
|
|
100
|
+
});
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
if (this.isHardwareWalletEnabled) {
|
|
103
|
+
throw new NotSupportedError(`Message signing is currently not supported on ${this.name} hardware wallet.
|
|
104
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
105
|
+
by signing a transaction with a memo instruction.
|
|
106
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
107
|
+
}
|
|
108
|
+
return _super.signMessage.call(this, messageToSign);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
proveOwnership(messageToSign) {
|
|
112
|
+
const _super = Object.create(null, {
|
|
113
|
+
proveOwnership: { get: () => super.proveOwnership }
|
|
114
|
+
});
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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, messageToSign);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
signMessageViaTransaction(messageToSign) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const address = yield this.fetchPublicAddress();
|
|
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
|
+
const ledgerWallets = this.verifiedCredentials
|
|
168
|
+
.filter((v) => { var _a; return ((_a = v.walletProperties) === null || _a === void 0 ? void 0 : _a.hardwareWallet) === 'ledger'; })
|
|
169
|
+
.map((v) => v.address);
|
|
170
|
+
return ledgerWallets.includes(address);
|
|
171
|
+
}
|
|
86
172
|
}
|
|
87
173
|
|
|
88
174
|
export { SolWalletConnector };
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
6
|
-
var web3_js = require('@solana/web3.js');
|
|
7
|
-
var utils = require('@dynamic-labs/utils');
|
|
8
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
10
|
-
var extractNonce = require('../utils/extractNonce.cjs');
|
|
11
|
-
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
12
|
-
|
|
13
|
-
const MEMO_PROGRAM_ID = new web3_js.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
14
|
-
class PhantomLedger extends InjectedWalletBase.InjectedWalletBase {
|
|
15
|
-
constructor(opts) {
|
|
16
|
-
super(opts);
|
|
17
|
-
/**
|
|
18
|
-
* I'm exporting the walletName to use it for DYN-1447. As we only need the wallet name,
|
|
19
|
-
* exporting it in this way, we avoid to instantiate the whole PhantomLedger class every time.
|
|
20
|
-
*/
|
|
21
|
-
this.name = walletConnectorCore.PhantomLedgerWalletName;
|
|
22
|
-
this.buildAuthTx = (message) => {
|
|
23
|
-
const transaction = new web3_js.Transaction();
|
|
24
|
-
transaction.add(new web3_js.TransactionInstruction({
|
|
25
|
-
data: Buffer.from(message, 'utf8'),
|
|
26
|
-
keys: [],
|
|
27
|
-
programId: MEMO_PROGRAM_ID,
|
|
28
|
-
}));
|
|
29
|
-
return transaction;
|
|
30
|
-
};
|
|
31
|
-
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
32
|
-
}
|
|
33
|
-
signMessage() {
|
|
34
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
throw new utils.NotSupportedError(`Message signing is currently not supported on ${this.name}
|
|
36
|
-
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
37
|
-
by signing a transaction with a memo instruction.
|
|
38
|
-
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
proveOwnership(messageToSign) {
|
|
42
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const nonce = extractNonce.extractNonce(messageToSign);
|
|
44
|
-
if (!nonce) {
|
|
45
|
-
throw new utils.DynamicError('Nonce missing');
|
|
46
|
-
}
|
|
47
|
-
return this.signMessageViaTransaction(nonce);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
signMessageViaTransaction(messageToSign) {
|
|
51
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const address = yield this.fetchPublicAddress();
|
|
53
|
-
if (!address) {
|
|
54
|
-
throw new utils.DynamicError('Address missing');
|
|
55
|
-
}
|
|
56
|
-
const transaction = this.buildAuthTx(messageToSign);
|
|
57
|
-
transaction.feePayer = new web3_js.PublicKey(address);
|
|
58
|
-
transaction.recentBlockhash = (yield this.getWalletClient().getLatestBlockhash()).blockhash;
|
|
59
|
-
const signer = yield this.getSigner();
|
|
60
|
-
if (!signer) {
|
|
61
|
-
throw new utils.DynamicError('Signer not found');
|
|
62
|
-
}
|
|
63
|
-
const signedTransaction = yield signer.signTransaction(transaction);
|
|
64
|
-
return JSON.stringify({
|
|
65
|
-
signedTransaction: signedTransaction.serialize(),
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
exports.MEMO_PROGRAM_ID = MEMO_PROGRAM_ID;
|
|
72
|
-
exports.PhantomLedger = PhantomLedger;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { SolWalletConnectorOpts } from '../solWalletConnector';
|
|
3
|
-
import { InjectedWalletBase } from './InjectedWalletBase';
|
|
4
|
-
export declare const MEMO_PROGRAM_ID: PublicKey;
|
|
5
|
-
export declare class PhantomLedger extends InjectedWalletBase {
|
|
6
|
-
/**
|
|
7
|
-
* I'm exporting the walletName to use it for DYN-1447. As we only need the wallet name,
|
|
8
|
-
* exporting it in this way, we avoid to instantiate the whole PhantomLedger class every time.
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
constructor(opts: SolWalletConnectorOpts);
|
|
12
|
-
signMessage(): Promise<string | undefined>;
|
|
13
|
-
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
14
|
-
signMessageViaTransaction(messageToSign: string): Promise<string>;
|
|
15
|
-
private buildAuthTx;
|
|
16
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
|
-
import { PublicKey, Transaction, TransactionInstruction } from '@solana/web3.js';
|
|
3
|
-
import { NotSupportedError, DynamicError } from '@dynamic-labs/utils';
|
|
4
|
-
import { PhantomLedgerWalletName } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
-
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
6
|
-
import { extractNonce } from '../utils/extractNonce.js';
|
|
7
|
-
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
8
|
-
|
|
9
|
-
const MEMO_PROGRAM_ID = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
10
|
-
class PhantomLedger extends InjectedWalletBase {
|
|
11
|
-
constructor(opts) {
|
|
12
|
-
super(opts);
|
|
13
|
-
/**
|
|
14
|
-
* I'm exporting the walletName to use it for DYN-1447. As we only need the wallet name,
|
|
15
|
-
* exporting it in this way, we avoid to instantiate the whole PhantomLedger class every time.
|
|
16
|
-
*/
|
|
17
|
-
this.name = PhantomLedgerWalletName;
|
|
18
|
-
this.buildAuthTx = (message) => {
|
|
19
|
-
const transaction = new Transaction();
|
|
20
|
-
transaction.add(new TransactionInstruction({
|
|
21
|
-
data: Buffer.from(message, 'utf8'),
|
|
22
|
-
keys: [],
|
|
23
|
-
programId: MEMO_PROGRAM_ID,
|
|
24
|
-
}));
|
|
25
|
-
return transaction;
|
|
26
|
-
};
|
|
27
|
-
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
28
|
-
}
|
|
29
|
-
signMessage() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
throw new NotSupportedError(`Message signing is currently not supported on ${this.name}
|
|
32
|
-
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
33
|
-
by signing a transaction with a memo instruction.
|
|
34
|
-
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
proveOwnership(messageToSign) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const nonce = extractNonce(messageToSign);
|
|
40
|
-
if (!nonce) {
|
|
41
|
-
throw new DynamicError('Nonce missing');
|
|
42
|
-
}
|
|
43
|
-
return this.signMessageViaTransaction(nonce);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
signMessageViaTransaction(messageToSign) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const address = yield this.fetchPublicAddress();
|
|
49
|
-
if (!address) {
|
|
50
|
-
throw new DynamicError('Address missing');
|
|
51
|
-
}
|
|
52
|
-
const transaction = this.buildAuthTx(messageToSign);
|
|
53
|
-
transaction.feePayer = new PublicKey(address);
|
|
54
|
-
transaction.recentBlockhash = (yield this.getWalletClient().getLatestBlockhash()).blockhash;
|
|
55
|
-
const signer = yield this.getSigner();
|
|
56
|
-
if (!signer) {
|
|
57
|
-
throw new DynamicError('Signer not found');
|
|
58
|
-
}
|
|
59
|
-
const signedTransaction = yield signer.signTransaction(transaction);
|
|
60
|
-
return JSON.stringify({
|
|
61
|
-
signedTransaction: signedTransaction.serialize(),
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export { MEMO_PROGRAM_ID, PhantomLedger };
|