@dynamic-labs/solana 0.0.0-exp20240808.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.json +48 -0
- package/src/CoinbaseSolana.cjs +52 -0
- package/src/CoinbaseSolana.d.ts +9 -0
- package/src/CoinbaseSolana.js +48 -0
- package/src/Phantom.cjs +44 -0
- package/src/Phantom.d.ts +13 -0
- package/src/Phantom.js +40 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.cjs +100 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.d.ts +21 -0
- package/src/SolanaWalletStandardConnector/SolanaWalletStandardConnector.js +96 -0
- package/src/SolanaWalletStandardConnector/index.d.ts +1 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs +117 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.d.ts +4 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js +113 -0
- package/src/SolanaWalletStandardConnector/utils/createSolanaSignerFromWalletStandard/index.d.ts +1 -0
- package/src/Solflare.cjs +63 -0
- package/src/Solflare.d.ts +9 -0
- package/src/Solflare.js +59 -0
- package/src/contants.cjs +8 -0
- package/src/contants.d.ts +1 -0
- package/src/contants.js +4 -0
- package/src/errors/SignMessageNotSupportedError.cjs +17 -0
- package/src/errors/SignMessageNotSupportedError.d.ts +4 -0
- package/src/errors/SignMessageNotSupportedError.js +13 -0
- package/src/index.cjs +30 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +22 -0
- package/src/injected/BackpackSol.cjs +46 -0
- package/src/injected/BackpackSol.d.ts +9 -0
- package/src/injected/BackpackSol.js +42 -0
- package/src/injected/FallbackSolanaConnector.cjs +22 -0
- package/src/injected/FallbackSolanaConnector.d.ts +9 -0
- package/src/injected/FallbackSolanaConnector.js +18 -0
- package/src/injected/InjectedWalletBase.cjs +118 -0
- package/src/injected/InjectedWalletBase.d.ts +21 -0
- package/src/injected/InjectedWalletBase.js +114 -0
- package/src/injected/PhantomInjected.cjs +37 -0
- package/src/injected/PhantomInjected.d.ts +8 -0
- package/src/injected/PhantomInjected.js +33 -0
- package/src/injected/UnknownInjected.cjs +21 -0
- package/src/injected/UnknownInjected.d.ts +8 -0
- package/src/injected/UnknownInjected.js +17 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +63 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
- package/src/injected/fetchInjectedWalletConnectors.js +58 -0
- package/src/injected/index.d.ts +3 -0
- package/src/phantomRedirect/PhantomRedirect.cjs +337 -0
- package/src/phantomRedirect/PhantomRedirect.d.ts +37 -0
- package/src/phantomRedirect/PhantomRedirect.js +328 -0
- package/src/phantomRedirect/storage.cjs +96 -0
- package/src/phantomRedirect/storage.d.ts +40 -0
- package/src/phantomRedirect/storage.js +91 -0
- package/src/phantomRedirect/types.d.ts +1 -0
- package/src/phantomRedirect/utils.cjs +56 -0
- package/src/phantomRedirect/utils.d.ts +4 -0
- package/src/phantomRedirect/utils.js +44 -0
- package/src/solProviderHelper.cjs +173 -0
- package/src/solProviderHelper.d.ts +36 -0
- package/src/solProviderHelper.js +169 -0
- package/src/solWalletConnector.cjs +174 -0
- package/src/solWalletConnector.d.ts +37 -0
- package/src/solWalletConnector.js +170 -0
- package/src/types.d.ts +68 -0
- package/src/utils/extractNonce.cjs +14 -0
- package/src/utils/extractNonce.d.ts +1 -0
- package/src/utils/extractNonce.js +10 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.cjs +29 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.d.ts +3 -0
- package/src/utils/findWalletProviderFromWalletStandard/findWalletProviderFromWalletStandard.js +25 -0
- package/src/utils/findWalletProviderFromWalletStandard/index.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey.cjs +10 -0
- package/src/utils/getGenesisHashLSKey.d.ts +1 -0
- package/src/utils/getGenesisHashLSKey.js +6 -0
- package/src/utils/isBackpackSolanaSigner.cjs +8 -0
- package/src/utils/isBackpackSolanaSigner.d.ts +2 -0
- package/src/utils/isBackpackSolanaSigner.js +4 -0
- package/src/utils/isSignedMessage.cjs +8 -0
- package/src/utils/isSignedMessage.d.ts +2 -0
- package/src/utils/isSignedMessage.js +4 -0
- package/src/wallet/SolanaWallet.cjs +33 -0
- package/src/wallet/SolanaWallet.d.ts +17 -0
- package/src/wallet/SolanaWallet.js +29 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isSolanaWallet.cjs +8 -0
- package/src/wallet/isSolanaWallet.d.ts +3 -0
- package/src/wallet/isSolanaWallet.js +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { __awaiter };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/solana",
|
|
3
|
+
"version": "0.0.0-exp20240808.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
7
|
+
"directory": "packages/solana"
|
|
8
|
+
},
|
|
9
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/dynamic-labs/DynamicAuth/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/dynamic-labs/DynamicAuth#readme",
|
|
14
|
+
"author": "Dynamic Labs, Inc.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "./src/index.cjs",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"import": "./src/index.js",
|
|
24
|
+
"require": "./src/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@solana/web3.js": "1.92.1",
|
|
30
|
+
"@dynamic-labs/sdk-api-core": "0.0.509",
|
|
31
|
+
"@wallet-standard/app": "1.0.1",
|
|
32
|
+
"@wallet-standard/base": "1.0.1",
|
|
33
|
+
"@wallet-standard/features": "1.0.3",
|
|
34
|
+
"@wallet-standard/experimental-features": "0.1.1",
|
|
35
|
+
"bs58": "5.0.0",
|
|
36
|
+
"tweetnacl": "1.0.3",
|
|
37
|
+
"@dynamic-labs/embedded-wallet-solana": "0.0.0-exp20240808.0",
|
|
38
|
+
"@dynamic-labs/rpc-provider-solana": "0.0.0-exp20240808.0",
|
|
39
|
+
"@dynamic-labs/rpc-providers": "0.0.0-exp20240808.0",
|
|
40
|
+
"@dynamic-labs/solana-utils": "0.0.0-exp20240808.0",
|
|
41
|
+
"@dynamic-labs/types": "0.0.0-exp20240808.0",
|
|
42
|
+
"@dynamic-labs/utils": "0.0.0-exp20240808.0",
|
|
43
|
+
"@dynamic-labs/wallet-book": "0.0.0-exp20240808.0",
|
|
44
|
+
"@dynamic-labs/wallet-connector-core": "0.0.0-exp20240808.0",
|
|
45
|
+
"eventemitter3": "5.0.1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {}
|
|
48
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
|
+
require('@dynamic-labs/embedded-wallet-solana');
|
|
10
|
+
require('./solWalletConnector.cjs');
|
|
11
|
+
require('tweetnacl');
|
|
12
|
+
require('bs58');
|
|
13
|
+
require('@solana/web3.js');
|
|
14
|
+
var InjectedWalletBase = require('./injected/InjectedWalletBase.cjs');
|
|
15
|
+
require('./SolanaWalletStandardConnector/SolanaWalletStandardConnector.cjs');
|
|
16
|
+
var isSignedMessage = require('./utils/isSignedMessage.cjs');
|
|
17
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
18
|
+
|
|
19
|
+
class CoinbaseSolana extends InjectedWalletBase.InjectedWalletBase {
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
super(opts);
|
|
22
|
+
this.name = 'CoinbaseSolana';
|
|
23
|
+
this.overrideKey = 'coinbasesolana';
|
|
24
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
25
|
+
}
|
|
26
|
+
getSigner() {
|
|
27
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.connect();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
signMessage(messageToSign) {
|
|
33
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const walletAddress = yield this.getAddress();
|
|
35
|
+
if (!walletAddress) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const provider = yield this.getSigner();
|
|
39
|
+
if (!provider) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const encodedMessage = new TextEncoder().encode(messageToSign);
|
|
43
|
+
const signedMessage = yield provider.signMessage(encodedMessage, walletAddress);
|
|
44
|
+
if (!signedMessage) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return utils.bufferToBase64(isSignedMessage.isSignedMessage(signedMessage) ? signedMessage.signature : signedMessage);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.CoinbaseSolana = CoinbaseSolana;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SolWalletConnectorOpts } from './solWalletConnector';
|
|
2
|
+
import { InjectedWalletBase } from './injected/InjectedWalletBase';
|
|
3
|
+
export declare class CoinbaseSolana extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
constructor(opts: SolWalletConnectorOpts);
|
|
7
|
+
getSigner<ICoinbaseSolanaSigner>(): Promise<ICoinbaseSolanaSigner | undefined>;
|
|
8
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { bufferToBase64 } from '@dynamic-labs/utils';
|
|
4
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import '@dynamic-labs/embedded-wallet-solana';
|
|
6
|
+
import './solWalletConnector.js';
|
|
7
|
+
import 'tweetnacl';
|
|
8
|
+
import 'bs58';
|
|
9
|
+
import '@solana/web3.js';
|
|
10
|
+
import { InjectedWalletBase } from './injected/InjectedWalletBase.js';
|
|
11
|
+
import './SolanaWalletStandardConnector/SolanaWalletStandardConnector.js';
|
|
12
|
+
import { isSignedMessage } from './utils/isSignedMessage.js';
|
|
13
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
14
|
+
|
|
15
|
+
class CoinbaseSolana extends InjectedWalletBase {
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
super(opts);
|
|
18
|
+
this.name = 'CoinbaseSolana';
|
|
19
|
+
this.overrideKey = 'coinbasesolana';
|
|
20
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
21
|
+
}
|
|
22
|
+
getSigner() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = this.getSolProviderHelper()) === null || _a === void 0 ? void 0 : _a.connect();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
signMessage(messageToSign) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const walletAddress = yield this.getAddress();
|
|
31
|
+
if (!walletAddress) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const provider = yield this.getSigner();
|
|
35
|
+
if (!provider) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const encodedMessage = new TextEncoder().encode(messageToSign);
|
|
39
|
+
const signedMessage = yield provider.signMessage(encodedMessage, walletAddress);
|
|
40
|
+
if (!signedMessage) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return bufferToBase64(isSignedMessage(signedMessage) ? signedMessage.signature : signedMessage);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { CoinbaseSolana };
|
package/src/Phantom.cjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var solWalletConnector = require('./solWalletConnector.cjs');
|
|
10
|
+
var PhantomRedirect = require('./phantomRedirect/PhantomRedirect.cjs');
|
|
11
|
+
var PhantomInjected = require('./injected/PhantomInjected.cjs');
|
|
12
|
+
|
|
13
|
+
class Phantom extends solWalletConnector.SolWalletConnector {
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
super(opts);
|
|
16
|
+
this.name = 'Phantom';
|
|
17
|
+
this.overrideKey = 'phantom';
|
|
18
|
+
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
19
|
+
}
|
|
20
|
+
connect() {
|
|
21
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
yield this.getMobileOrInstalledWallet().connect();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
getSigner() {
|
|
26
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return this.getMobileOrInstalledWallet().getSigner();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getMobileOrInstalledWallet() {
|
|
31
|
+
const phantomInjected = new PhantomInjected.PhantomInjected(this.constructorProps);
|
|
32
|
+
if (!utils.isMobile() || phantomInjected.isInstalledOnBrowser()) {
|
|
33
|
+
return phantomInjected;
|
|
34
|
+
}
|
|
35
|
+
if (this.mobileExperience === 'redirect') {
|
|
36
|
+
return new PhantomRedirect.PhantomRedirect(this.constructorProps);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return new PhantomInjected.PhantomInjected(this.constructorProps);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
exports.Phantom = Phantom;
|
package/src/Phantom.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
+
import { WalletConnectorCore } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { ISolana } from '..';
|
|
4
|
+
import { SolWalletConnector, SolWalletConnectorOpts } from './solWalletConnector';
|
|
5
|
+
export declare class Phantom extends SolWalletConnector {
|
|
6
|
+
name: string;
|
|
7
|
+
overrideKey: string;
|
|
8
|
+
wallet: WalletSchema | undefined;
|
|
9
|
+
constructor(opts: SolWalletConnectorOpts);
|
|
10
|
+
connect(): Promise<void>;
|
|
11
|
+
getSigner(): Promise<ISolana | undefined>;
|
|
12
|
+
getMobileOrInstalledWallet(): WalletConnectorCore.WalletConnector;
|
|
13
|
+
}
|
package/src/Phantom.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
|
+
import { isMobile } from '@dynamic-labs/utils';
|
|
5
|
+
import { SolWalletConnector } from './solWalletConnector.js';
|
|
6
|
+
import { PhantomRedirect } from './phantomRedirect/PhantomRedirect.js';
|
|
7
|
+
import { PhantomInjected } from './injected/PhantomInjected.js';
|
|
8
|
+
|
|
9
|
+
class Phantom extends SolWalletConnector {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts);
|
|
12
|
+
this.name = 'Phantom';
|
|
13
|
+
this.overrideKey = 'phantom';
|
|
14
|
+
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
15
|
+
}
|
|
16
|
+
connect() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
yield this.getMobileOrInstalledWallet().connect();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
getSigner() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return this.getMobileOrInstalledWallet().getSigner();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
getMobileOrInstalledWallet() {
|
|
27
|
+
const phantomInjected = new PhantomInjected(this.constructorProps);
|
|
28
|
+
if (!isMobile() || phantomInjected.isInstalledOnBrowser()) {
|
|
29
|
+
return phantomInjected;
|
|
30
|
+
}
|
|
31
|
+
if (this.mobileExperience === 'redirect') {
|
|
32
|
+
return new PhantomRedirect(this.constructorProps);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return new PhantomInjected(this.constructorProps);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { Phantom };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var app = require('@wallet-standard/app');
|
|
8
|
+
var solWalletConnector = require('../solWalletConnector.cjs');
|
|
9
|
+
var createSolanaSignerFromWalletStandard = require('./utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.cjs');
|
|
10
|
+
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
class SolanaWalletStandardConnector extends solWalletConnector.SolWalletConnector {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.connectedChain = 'SOL';
|
|
16
|
+
this.supportedChains = ['SOL'];
|
|
17
|
+
}
|
|
18
|
+
get wallet() {
|
|
19
|
+
const walletStandard = SolanaWalletStandardConnector.getWallet(this.walletBook, this.key);
|
|
20
|
+
if (!walletStandard) {
|
|
21
|
+
throw new Error('Wallet not found');
|
|
22
|
+
}
|
|
23
|
+
return walletStandard;
|
|
24
|
+
}
|
|
25
|
+
get walletFeatures() {
|
|
26
|
+
return this.wallet.features;
|
|
27
|
+
}
|
|
28
|
+
connect() {
|
|
29
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
yield this.walletFeatures['standard:connect'].connect();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
endSession() {
|
|
34
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.walletFeatures['standard:disconnect'].disconnect();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
isInstalledOnBrowser() {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
getAddress() {
|
|
42
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
yield this.connect();
|
|
44
|
+
const [address] = yield this.getConnectedAccounts();
|
|
45
|
+
return address;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
getConnectedAccounts() {
|
|
49
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const addresses = this.wallet.accounts.map((account) => account.address);
|
|
51
|
+
return addresses;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
signMessage(messageToSign) {
|
|
55
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const signer = yield this.getSigner();
|
|
57
|
+
if (!signer) {
|
|
58
|
+
throw new Error('Signer not found');
|
|
59
|
+
}
|
|
60
|
+
const message = encoder.encode(messageToSign);
|
|
61
|
+
const signature = yield signer.signMessage(message);
|
|
62
|
+
if (!(signature instanceof Uint8Array)) {
|
|
63
|
+
throw new Error('Signature not found');
|
|
64
|
+
}
|
|
65
|
+
return Buffer.from(signature).toString('base64');
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getSigner() {
|
|
69
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const { wallet } = this;
|
|
71
|
+
return createSolanaSignerFromWalletStandard.createSolanaSignerFromWalletStandard(wallet, this);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
static getWallet(walletBook, walletKey) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const wallets = app.getWallets().get();
|
|
77
|
+
const injectedConfig = (_a = walletBook.wallets[walletKey].injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sol');
|
|
78
|
+
if (!injectedConfig)
|
|
79
|
+
return;
|
|
80
|
+
const { features } = (_b = injectedConfig.walletStandard) !== null && _b !== void 0 ? _b : {};
|
|
81
|
+
if (!features)
|
|
82
|
+
return;
|
|
83
|
+
const wallet = wallets.find((wallet) => {
|
|
84
|
+
var _a;
|
|
85
|
+
const isNameMatch = wallet.name === ((_a = injectedConfig.walletStandard) === null || _a === void 0 ? void 0 : _a.name);
|
|
86
|
+
if (!isNameMatch)
|
|
87
|
+
return false;
|
|
88
|
+
const hasFeatures = features.reduce((hasAllFeatures, key) => {
|
|
89
|
+
const walletFeatures = Object.keys(wallet.features);
|
|
90
|
+
if (!hasAllFeatures)
|
|
91
|
+
return false;
|
|
92
|
+
return walletFeatures.includes(key);
|
|
93
|
+
}, true);
|
|
94
|
+
return hasFeatures;
|
|
95
|
+
});
|
|
96
|
+
return wallet;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.SolanaWalletStandardConnector = SolanaWalletStandardConnector;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Wallet } from '@wallet-standard/base';
|
|
2
|
+
import { StandardConnectFeature, StandardDisconnectFeature } from '@wallet-standard/features';
|
|
3
|
+
import { Chain } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { SolWalletConnector, SolWalletConnectorOpts } from './../solWalletConnector';
|
|
6
|
+
import { ISolana } from './../types';
|
|
7
|
+
export declare abstract class SolanaWalletStandardConnector extends SolWalletConnector {
|
|
8
|
+
connectedChain: Chain;
|
|
9
|
+
supportedChains: Chain[];
|
|
10
|
+
constructor(props: SolWalletConnectorOpts);
|
|
11
|
+
get wallet(): Wallet;
|
|
12
|
+
get walletFeatures(): StandardConnectFeature & StandardDisconnectFeature;
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
endSession(): Promise<void>;
|
|
15
|
+
isInstalledOnBrowser(): boolean;
|
|
16
|
+
getAddress(): Promise<string | undefined>;
|
|
17
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
18
|
+
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
19
|
+
getSigner(): Promise<ISolana | undefined>;
|
|
20
|
+
static getWallet(walletBook: WalletBookSchema, walletKey: string): Wallet | undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { getWallets } from '@wallet-standard/app';
|
|
4
|
+
import { SolWalletConnector } from '../solWalletConnector.js';
|
|
5
|
+
import { createSolanaSignerFromWalletStandard } from './utils/createSolanaSignerFromWalletStandard/createSolanaSignerFromWalletStandard.js';
|
|
6
|
+
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
class SolanaWalletStandardConnector extends SolWalletConnector {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.connectedChain = 'SOL';
|
|
12
|
+
this.supportedChains = ['SOL'];
|
|
13
|
+
}
|
|
14
|
+
get wallet() {
|
|
15
|
+
const walletStandard = SolanaWalletStandardConnector.getWallet(this.walletBook, this.key);
|
|
16
|
+
if (!walletStandard) {
|
|
17
|
+
throw new Error('Wallet not found');
|
|
18
|
+
}
|
|
19
|
+
return walletStandard;
|
|
20
|
+
}
|
|
21
|
+
get walletFeatures() {
|
|
22
|
+
return this.wallet.features;
|
|
23
|
+
}
|
|
24
|
+
connect() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield this.walletFeatures['standard:connect'].connect();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
endSession() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield this.walletFeatures['standard:disconnect'].disconnect();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
isInstalledOnBrowser() {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
getAddress() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
yield this.connect();
|
|
40
|
+
const [address] = yield this.getConnectedAccounts();
|
|
41
|
+
return address;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getConnectedAccounts() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const addresses = this.wallet.accounts.map((account) => account.address);
|
|
47
|
+
return addresses;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
signMessage(messageToSign) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const signer = yield this.getSigner();
|
|
53
|
+
if (!signer) {
|
|
54
|
+
throw new Error('Signer not found');
|
|
55
|
+
}
|
|
56
|
+
const message = encoder.encode(messageToSign);
|
|
57
|
+
const signature = yield signer.signMessage(message);
|
|
58
|
+
if (!(signature instanceof Uint8Array)) {
|
|
59
|
+
throw new Error('Signature not found');
|
|
60
|
+
}
|
|
61
|
+
return Buffer.from(signature).toString('base64');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
getSigner() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const { wallet } = this;
|
|
67
|
+
return createSolanaSignerFromWalletStandard(wallet, this);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
static getWallet(walletBook, walletKey) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const wallets = getWallets().get();
|
|
73
|
+
const injectedConfig = (_a = walletBook.wallets[walletKey].injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sol');
|
|
74
|
+
if (!injectedConfig)
|
|
75
|
+
return;
|
|
76
|
+
const { features } = (_b = injectedConfig.walletStandard) !== null && _b !== void 0 ? _b : {};
|
|
77
|
+
if (!features)
|
|
78
|
+
return;
|
|
79
|
+
const wallet = wallets.find((wallet) => {
|
|
80
|
+
var _a;
|
|
81
|
+
const isNameMatch = wallet.name === ((_a = injectedConfig.walletStandard) === null || _a === void 0 ? void 0 : _a.name);
|
|
82
|
+
if (!isNameMatch)
|
|
83
|
+
return false;
|
|
84
|
+
const hasFeatures = features.reduce((hasAllFeatures, key) => {
|
|
85
|
+
const walletFeatures = Object.keys(wallet.features);
|
|
86
|
+
if (!hasAllFeatures)
|
|
87
|
+
return false;
|
|
88
|
+
return walletFeatures.includes(key);
|
|
89
|
+
}, true);
|
|
90
|
+
return hasFeatures;
|
|
91
|
+
});
|
|
92
|
+
return wallet;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { SolanaWalletStandardConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SolanaWalletStandardConnector } from './SolanaWalletStandardConnector';
|