@dynamic-labs/solana 0.17.0-RC.10
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 +793 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +30 -0
- package/_virtual/_tslib.js +26 -0
- package/package.json +36 -0
- package/src/CoinbaseSolana.cjs +53 -0
- package/src/CoinbaseSolana.d.ts +14 -0
- package/src/CoinbaseSolana.js +49 -0
- package/src/Glow.cjs +50 -0
- package/src/Glow.d.ts +13 -0
- package/src/Glow.js +46 -0
- package/src/Slope.cjs +98 -0
- package/src/Slope.d.ts +27 -0
- package/src/Slope.js +94 -0
- package/src/Solflare.cjs +66 -0
- package/src/Solflare.d.ts +11 -0
- package/src/Solflare.js +62 -0
- package/src/index.cjs +24 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +18 -0
- package/src/injected/BraveSol.cjs +21 -0
- package/src/injected/BraveSol.d.ts +5 -0
- package/src/injected/BraveSol.js +17 -0
- package/src/injected/ExodusSol.cjs +14 -0
- package/src/injected/ExodusSol.d.ts +4 -0
- package/src/injected/ExodusSol.js +10 -0
- package/src/injected/InjectedWalletBase.cjs +68 -0
- package/src/injected/InjectedWalletBase.d.ts +13 -0
- package/src/injected/InjectedWalletBase.js +64 -0
- package/src/injected/Phantom.cjs +14 -0
- package/src/injected/Phantom.d.ts +4 -0
- package/src/injected/Phantom.js +10 -0
- package/src/injected/PhantomLedger.cjs +70 -0
- package/src/injected/PhantomLedger.d.ts +14 -0
- package/src/injected/PhantomLedger.js +65 -0
- package/src/injected/index.cjs +12 -0
- package/src/injected/index.d.ts +2 -0
- package/src/injected/index.js +8 -0
- package/src/solProviderHelper.cjs +162 -0
- package/src/solProviderHelper.d.ts +29 -0
- package/src/solProviderHelper.js +158 -0
- package/src/solWalletConnector.cjs +75 -0
- package/src/solWalletConnector.d.ts +21 -0
- package/src/solWalletConnector.js +71 -0
- package/src/types.d.ts +42 -0
- package/src/utils/extractNonce.cjs +13 -0
- package/src/utils/extractNonce.d.ts +1 -0
- package/src/utils/extractNonce.js +9 -0
package/src/Solflare.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
import { bufferToBase64 } from '@dynamic-labs/utils';
|
|
3
|
+
import { SolWalletConnector } from './solWalletConnector.js';
|
|
4
|
+
import { SolProviderHelper } from './solProviderHelper.js';
|
|
5
|
+
|
|
6
|
+
class Solflare extends SolWalletConnector {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.name = 'Solflare';
|
|
10
|
+
}
|
|
11
|
+
isInstalledOnBrowser() {
|
|
12
|
+
return SolProviderHelper.isInstalledHelper(this.name);
|
|
13
|
+
}
|
|
14
|
+
fetchPublicAddress() {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return SolProviderHelper.fetchPublicAddressWithName(this.name);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
connect() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
yield SolProviderHelper.connectWithName(this.name);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
getSigner() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return SolProviderHelper.connectWithName(this.name);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
signMessage(messageToSign) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const walletAddress = yield this.fetchPublicAddress();
|
|
32
|
+
if (!walletAddress) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const provider = SolProviderHelper.findProvider(this.name);
|
|
36
|
+
if (!provider) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const encodedMessage = new TextEncoder().encode(messageToSign);
|
|
40
|
+
const isSignedMessage = (value) => value.signature !== undefined;
|
|
41
|
+
yield provider.connect();
|
|
42
|
+
/**
|
|
43
|
+
* TODO: Remove the sleep once problem is fixed on Solflare's extension.
|
|
44
|
+
* Tracked in DYN-442
|
|
45
|
+
*/
|
|
46
|
+
yield new Promise((resolve) => {
|
|
47
|
+
setTimeout(resolve, 100);
|
|
48
|
+
});
|
|
49
|
+
const rawMessage = yield provider.signMessage(encodedMessage, 'utf8');
|
|
50
|
+
return isSignedMessage(rawMessage)
|
|
51
|
+
? bufferToBase64(rawMessage.signature)
|
|
52
|
+
: undefined;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getConnectedAccounts() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
return SolProviderHelper.getConnectedAccountsWithName(this.name);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { Solflare };
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var CoinbaseSolana = require('./CoinbaseSolana.cjs');
|
|
6
|
+
var Glow = require('./Glow.cjs');
|
|
7
|
+
var Slope = require('./Slope.cjs');
|
|
8
|
+
var Solflare = require('./Solflare.cjs');
|
|
9
|
+
var index = require('./injected/index.cjs');
|
|
10
|
+
var solWalletConnector = require('./solWalletConnector.cjs');
|
|
11
|
+
var solProviderHelper = require('./solProviderHelper.cjs');
|
|
12
|
+
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14
|
+
const SolanaWalletConnectors = (props) => [
|
|
15
|
+
...index.injectedWallets,
|
|
16
|
+
CoinbaseSolana.CoinbaseSolana,
|
|
17
|
+
Glow.Glow,
|
|
18
|
+
Slope.Slope,
|
|
19
|
+
Solflare.Solflare,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
exports.SolWalletConnector = solWalletConnector.SolWalletConnector;
|
|
23
|
+
exports.SolProviderHelper = solProviderHelper.SolProviderHelper;
|
|
24
|
+
exports.SolanaWalletConnectors = SolanaWalletConnectors;
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CoinbaseSolana } from './CoinbaseSolana.js';
|
|
2
|
+
import { Glow } from './Glow.js';
|
|
3
|
+
import { Slope } from './Slope.js';
|
|
4
|
+
import { Solflare } from './Solflare.js';
|
|
5
|
+
import { injectedWallets } from './injected/index.js';
|
|
6
|
+
export { SolWalletConnector } from './solWalletConnector.js';
|
|
7
|
+
export { SolProviderHelper } from './solProviderHelper.js';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
10
|
+
const SolanaWalletConnectors = (props) => [
|
|
11
|
+
...injectedWallets,
|
|
12
|
+
CoinbaseSolana,
|
|
13
|
+
Glow,
|
|
14
|
+
Slope,
|
|
15
|
+
Solflare,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export { SolanaWalletConnectors };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
6
|
+
var solProviderHelper = require('../solProviderHelper.cjs');
|
|
7
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
8
|
+
|
|
9
|
+
class BraveSol extends InjectedWalletBase.InjectedWalletBase {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.name = 'BraveSol';
|
|
13
|
+
}
|
|
14
|
+
fetchPublicAddress() {
|
|
15
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
return solProviderHelper.SolProviderHelper.fetchPublicAddressWithName(this.name);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.BraveSol = BraveSol;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
|
+
import { SolProviderHelper } from '../solProviderHelper.js';
|
|
3
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
4
|
+
|
|
5
|
+
class BraveSol extends InjectedWalletBase {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.name = 'BraveSol';
|
|
9
|
+
}
|
|
10
|
+
fetchPublicAddress() {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
return SolProviderHelper.fetchPublicAddressWithName(this.name);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { BraveSol };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
6
|
+
|
|
7
|
+
class ExodusSol extends InjectedWalletBase.InjectedWalletBase {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = 'ExodusSol';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.ExodusSol = ExodusSol;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
var solWalletConnector = require('../solWalletConnector.cjs');
|
|
8
|
+
var solProviderHelper = require('../solProviderHelper.cjs');
|
|
9
|
+
|
|
10
|
+
class InjectedWalletBase extends solWalletConnector.SolWalletConnector {
|
|
11
|
+
setupEventListeners(listeners) {
|
|
12
|
+
solProviderHelper.SolProviderHelper._setupEventListeners(listeners, solProviderHelper.SolProviderHelper.findProvider(this.name));
|
|
13
|
+
}
|
|
14
|
+
teardownEventListeners() {
|
|
15
|
+
solProviderHelper.SolProviderHelper._teardownEventListeners(this.name);
|
|
16
|
+
}
|
|
17
|
+
connect() {
|
|
18
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
yield solProviderHelper.SolProviderHelper.connectWithName(this.name);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getSigner() {
|
|
23
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return solProviderHelper.SolProviderHelper.connectWithName(this.name);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
isInstalledOnBrowser() {
|
|
28
|
+
var _a;
|
|
29
|
+
/**
|
|
30
|
+
* When Glow wallet is installed and Phantom isn't, isPhantom will
|
|
31
|
+
* still be true. This added check is to return false in that scenario.
|
|
32
|
+
* It relies on the fact that if both Glow and Phantom are enabled,
|
|
33
|
+
* solana.isGlow will return false.
|
|
34
|
+
*/
|
|
35
|
+
return (solProviderHelper.SolProviderHelper.isInstalledHelper(this.name) && !((_a = window.solana) === null || _a === void 0 ? void 0 : _a.isGlow));
|
|
36
|
+
}
|
|
37
|
+
fetchPublicAddress() {
|
|
38
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (this.isInstalledOnBrowser()) {
|
|
40
|
+
return solProviderHelper.SolProviderHelper.fetchPublicAddressWithName(this.name);
|
|
41
|
+
}
|
|
42
|
+
const url = encodeURIComponent(window.location.toString());
|
|
43
|
+
const ref = encodeURIComponent(window.location.origin);
|
|
44
|
+
// samsung browser only supports native links, not universal links
|
|
45
|
+
if (utils.isMobile()) {
|
|
46
|
+
if (utils.isSamsungBrowser()) {
|
|
47
|
+
window.location.assign(`phantom://browse/${url}?ref=${ref}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
window.location.assign(`https://phantom.app/ul/browse/${url}?ref=${ref}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
signMessage(messageToSign) {
|
|
57
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return solProviderHelper.SolProviderHelper.signMessageWithName(messageToSign, this.name);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getConnectedAccounts() {
|
|
62
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return solProviderHelper.SolProviderHelper.getConnectedAccountsWithName(this.name);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.InjectedWalletBase = InjectedWalletBase;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { SolWalletConnector } from '../solWalletConnector';
|
|
3
|
+
import { ISolana } from '../types';
|
|
4
|
+
export declare abstract class InjectedWalletBase extends SolWalletConnector {
|
|
5
|
+
setupEventListeners(listeners: WalletEventListeners): void;
|
|
6
|
+
teardownEventListeners(): void;
|
|
7
|
+
connect(): Promise<void>;
|
|
8
|
+
getSigner(): Promise<ISolana | undefined>;
|
|
9
|
+
isInstalledOnBrowser(): boolean;
|
|
10
|
+
fetchPublicAddress(): Promise<string | undefined>;
|
|
11
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
12
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
|
+
import { isMobile, isSamsungBrowser } from '@dynamic-labs/utils';
|
|
3
|
+
import { SolWalletConnector } from '../solWalletConnector.js';
|
|
4
|
+
import { SolProviderHelper } from '../solProviderHelper.js';
|
|
5
|
+
|
|
6
|
+
class InjectedWalletBase extends SolWalletConnector {
|
|
7
|
+
setupEventListeners(listeners) {
|
|
8
|
+
SolProviderHelper._setupEventListeners(listeners, SolProviderHelper.findProvider(this.name));
|
|
9
|
+
}
|
|
10
|
+
teardownEventListeners() {
|
|
11
|
+
SolProviderHelper._teardownEventListeners(this.name);
|
|
12
|
+
}
|
|
13
|
+
connect() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
yield SolProviderHelper.connectWithName(this.name);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
getSigner() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return SolProviderHelper.connectWithName(this.name);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
isInstalledOnBrowser() {
|
|
24
|
+
var _a;
|
|
25
|
+
/**
|
|
26
|
+
* When Glow wallet is installed and Phantom isn't, isPhantom will
|
|
27
|
+
* still be true. This added check is to return false in that scenario.
|
|
28
|
+
* It relies on the fact that if both Glow and Phantom are enabled,
|
|
29
|
+
* solana.isGlow will return false.
|
|
30
|
+
*/
|
|
31
|
+
return (SolProviderHelper.isInstalledHelper(this.name) && !((_a = window.solana) === null || _a === void 0 ? void 0 : _a.isGlow));
|
|
32
|
+
}
|
|
33
|
+
fetchPublicAddress() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (this.isInstalledOnBrowser()) {
|
|
36
|
+
return SolProviderHelper.fetchPublicAddressWithName(this.name);
|
|
37
|
+
}
|
|
38
|
+
const url = encodeURIComponent(window.location.toString());
|
|
39
|
+
const ref = encodeURIComponent(window.location.origin);
|
|
40
|
+
// samsung browser only supports native links, not universal links
|
|
41
|
+
if (isMobile()) {
|
|
42
|
+
if (isSamsungBrowser()) {
|
|
43
|
+
window.location.assign(`phantom://browse/${url}?ref=${ref}`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
window.location.assign(`https://phantom.app/ul/browse/${url}?ref=${ref}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
signMessage(messageToSign) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return SolProviderHelper.signMessageWithName(messageToSign, this.name);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getConnectedAccounts() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return SolProviderHelper.getConnectedAccountsWithName(this.name);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { InjectedWalletBase };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
6
|
+
|
|
7
|
+
class Phantom extends InjectedWalletBase.InjectedWalletBase {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = 'Phantom';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.Phantom = Phantom;
|
|
@@ -0,0 +1,70 @@
|
|
|
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 extractNonce = require('../utils/extractNonce.cjs');
|
|
10
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
11
|
+
|
|
12
|
+
const MEMO_PROGRAM_ID = new web3_js.PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
13
|
+
class PhantomLedger extends InjectedWalletBase.InjectedWalletBase {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
/**
|
|
17
|
+
* I'm exporting the walletName to use it for DYN-1447. As we only need the wallet name,
|
|
18
|
+
* exporting it in this way, we avoid to instantiate the whole PhantomLedger class every time.
|
|
19
|
+
*/
|
|
20
|
+
this.name = walletConnectorCore.PhantomLedgerWalletName;
|
|
21
|
+
this.buildAuthTx = (message) => {
|
|
22
|
+
const transaction = new web3_js.Transaction();
|
|
23
|
+
transaction.add(new web3_js.TransactionInstruction({
|
|
24
|
+
data: Buffer.from(message, 'utf8'),
|
|
25
|
+
keys: [],
|
|
26
|
+
programId: MEMO_PROGRAM_ID,
|
|
27
|
+
}));
|
|
28
|
+
return transaction;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
signMessage() {
|
|
32
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
throw new utils.NotSupportedError(`Message signing is currently not supported on ${this.name}
|
|
34
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
35
|
+
by signing a transaction with a memo instruction.
|
|
36
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
proveOwnership(messageToSign) {
|
|
40
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const nonce = extractNonce.extractNonce(messageToSign);
|
|
42
|
+
if (!nonce) {
|
|
43
|
+
throw new utils.DynamicError('Nonce missing');
|
|
44
|
+
}
|
|
45
|
+
return this.signMessageViaTransaction(nonce);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
signMessageViaTransaction(messageToSign) {
|
|
49
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const address = yield this.fetchPublicAddress();
|
|
51
|
+
if (!address) {
|
|
52
|
+
throw new utils.DynamicError('Address missing');
|
|
53
|
+
}
|
|
54
|
+
const transaction = this.buildAuthTx(messageToSign);
|
|
55
|
+
transaction.feePayer = new web3_js.PublicKey(address);
|
|
56
|
+
transaction.recentBlockhash = (yield this.getWeb3Provider().getLatestBlockhash()).blockhash;
|
|
57
|
+
const signer = yield this.getSigner();
|
|
58
|
+
if (!signer) {
|
|
59
|
+
throw new utils.DynamicError('Signer not found');
|
|
60
|
+
}
|
|
61
|
+
const signedTransaction = yield signer.signTransaction(transaction);
|
|
62
|
+
return JSON.stringify({
|
|
63
|
+
signedTransaction: signedTransaction.serialize(),
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.MEMO_PROGRAM_ID = MEMO_PROGRAM_ID;
|
|
70
|
+
exports.PhantomLedger = PhantomLedger;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { InjectedWalletBase } from './InjectedWalletBase';
|
|
3
|
+
export declare const MEMO_PROGRAM_ID: PublicKey;
|
|
4
|
+
export declare class PhantomLedger extends InjectedWalletBase {
|
|
5
|
+
/**
|
|
6
|
+
* I'm exporting the walletName to use it for DYN-1447. As we only need the wallet name,
|
|
7
|
+
* exporting it in this way, we avoid to instantiate the whole PhantomLedger class every time.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
signMessage(): Promise<string | undefined>;
|
|
11
|
+
proveOwnership(messageToSign: string): Promise<string | undefined>;
|
|
12
|
+
signMessageViaTransaction(messageToSign: string): Promise<string>;
|
|
13
|
+
private buildAuthTx;
|
|
14
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { extractNonce } from '../utils/extractNonce.js';
|
|
6
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
7
|
+
|
|
8
|
+
const MEMO_PROGRAM_ID = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
|
|
9
|
+
class PhantomLedger extends InjectedWalletBase {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/**
|
|
13
|
+
* I'm exporting the walletName to use it for DYN-1447. As we only need the wallet name,
|
|
14
|
+
* exporting it in this way, we avoid to instantiate the whole PhantomLedger class every time.
|
|
15
|
+
*/
|
|
16
|
+
this.name = PhantomLedgerWalletName;
|
|
17
|
+
this.buildAuthTx = (message) => {
|
|
18
|
+
const transaction = new Transaction();
|
|
19
|
+
transaction.add(new TransactionInstruction({
|
|
20
|
+
data: Buffer.from(message, 'utf8'),
|
|
21
|
+
keys: [],
|
|
22
|
+
programId: MEMO_PROGRAM_ID,
|
|
23
|
+
}));
|
|
24
|
+
return transaction;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
signMessage() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
throw new NotSupportedError(`Message signing is currently not supported on ${this.name}
|
|
30
|
+
You can use signMessageViaTransaction instead to achieve similar functionality
|
|
31
|
+
by signing a transaction with a memo instruction.
|
|
32
|
+
You can read more about it here https://github.com/solana-labs/solana/issues/21366`);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
proveOwnership(messageToSign) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const nonce = extractNonce(messageToSign);
|
|
38
|
+
if (!nonce) {
|
|
39
|
+
throw new DynamicError('Nonce missing');
|
|
40
|
+
}
|
|
41
|
+
return this.signMessageViaTransaction(nonce);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
signMessageViaTransaction(messageToSign) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const address = yield this.fetchPublicAddress();
|
|
47
|
+
if (!address) {
|
|
48
|
+
throw new DynamicError('Address missing');
|
|
49
|
+
}
|
|
50
|
+
const transaction = this.buildAuthTx(messageToSign);
|
|
51
|
+
transaction.feePayer = new PublicKey(address);
|
|
52
|
+
transaction.recentBlockhash = (yield this.getWeb3Provider().getLatestBlockhash()).blockhash;
|
|
53
|
+
const signer = yield this.getSigner();
|
|
54
|
+
if (!signer) {
|
|
55
|
+
throw new DynamicError('Signer not found');
|
|
56
|
+
}
|
|
57
|
+
const signedTransaction = yield signer.signTransaction(transaction);
|
|
58
|
+
return JSON.stringify({
|
|
59
|
+
signedTransaction: signedTransaction.serialize(),
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { MEMO_PROGRAM_ID, PhantomLedger };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var BraveSol = require('./BraveSol.cjs');
|
|
6
|
+
var ExodusSol = require('./ExodusSol.cjs');
|
|
7
|
+
var PhantomLedger = require('./PhantomLedger.cjs');
|
|
8
|
+
var Phantom = require('./Phantom.cjs');
|
|
9
|
+
|
|
10
|
+
const injectedWallets = [BraveSol.BraveSol, ExodusSol.ExodusSol, PhantomLedger.PhantomLedger, Phantom.Phantom];
|
|
11
|
+
|
|
12
|
+
exports.injectedWallets = injectedWallets;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BraveSol } from './BraveSol.js';
|
|
2
|
+
import { ExodusSol } from './ExodusSol.js';
|
|
3
|
+
import { PhantomLedger } from './PhantomLedger.js';
|
|
4
|
+
import { Phantom } from './Phantom.js';
|
|
5
|
+
|
|
6
|
+
const injectedWallets = [BraveSol, ExodusSol, PhantomLedger, Phantom];
|
|
7
|
+
|
|
8
|
+
export { injectedWallets };
|