@dynamic-labs/blocto-evm 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/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,36 @@
1
+ {
2
+ "name": "@dynamic-labs/blocto-evm",
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/blocto-evm"
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
+ "@blocto/sdk": "0.5.4",
30
+ "@dynamic-labs/ethereum": "0.0.0-exp20240808.0",
31
+ "@dynamic-labs/wallet-connector-core": "0.0.0-exp20240808.0"
32
+ },
33
+ "peerDependencies": {
34
+ "viem": "^2.7.6"
35
+ }
36
+ }
@@ -0,0 +1,87 @@
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
+ var BloctoEvm = require('./BloctoEvm.cjs');
9
+
10
+ class BloctoEmailConnector extends BloctoEvm.BloctoEvm {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.requiresNonDynamicEmailOtp = true;
14
+ }
15
+ get email() {
16
+ return this._email;
17
+ }
18
+ setEmail(email) {
19
+ this._email = email;
20
+ if (!email) {
21
+ localStorage.removeItem(BloctoEmailConnector.storageEmailKey);
22
+ }
23
+ else {
24
+ localStorage.setItem(BloctoEmailConnector.storageEmailKey, email);
25
+ }
26
+ }
27
+ getAddress() {
28
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
29
+ try {
30
+ const client = this.getClient();
31
+ if (!(client === null || client === void 0 ? void 0 : client.ethereum)) {
32
+ return undefined;
33
+ }
34
+ const addresses = yield client.ethereum.request({
35
+ method: 'eth_requestAccounts',
36
+ // When the email is provided, the login modal will prefill the email field.
37
+ params: this.email ? [this.email] : undefined,
38
+ });
39
+ if ((addresses === null || addresses === void 0 ? void 0 : addresses.length) > 0) {
40
+ return addresses[0];
41
+ }
42
+ return undefined;
43
+ }
44
+ catch (e) {
45
+ walletConnectorCore.logger.error(e);
46
+ return Promise.reject(e);
47
+ }
48
+ });
49
+ }
50
+ getConnectedAccounts() {
51
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
52
+ const client = this.getClient();
53
+ if (!client) {
54
+ return [];
55
+ }
56
+ if (client.ethereum) {
57
+ const accounts = yield client.ethereum.request({
58
+ method: 'eth_requestAccounts',
59
+ // When the email is provided, the login modal will prefill the email field.
60
+ params: this.email ? [this.email] : undefined,
61
+ });
62
+ return accounts || [];
63
+ }
64
+ return [];
65
+ });
66
+ }
67
+ clearEmail() {
68
+ this.setEmail(undefined);
69
+ }
70
+ endSession() {
71
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
72
+ const client = this.getClient();
73
+ localStorage.removeItem('sdk.session');
74
+ if (this.email && // cancel the session only if the email is set
75
+ client &&
76
+ client.ethereum &&
77
+ this.checkForSessionAccounts()) {
78
+ yield client.ethereum.request({ method: 'wallet_disconnect' });
79
+ this.removeClient();
80
+ }
81
+ this.clearEmail();
82
+ });
83
+ }
84
+ }
85
+ BloctoEmailConnector.storageEmailKey = 'blocto-email';
86
+
87
+ exports.BloctoEmailConnector = BloctoEmailConnector;
@@ -0,0 +1,13 @@
1
+ import { IEmailWalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ import { BloctoEvm } from './BloctoEvm';
3
+ export declare class BloctoEmailConnector extends BloctoEvm implements IEmailWalletConnector {
4
+ requiresNonDynamicEmailOtp: boolean;
5
+ protected _email: string | undefined | null;
6
+ get email(): string | null | undefined;
7
+ setEmail(email: BloctoEmailConnector['email']): void;
8
+ getAddress(): Promise<`0x${string}` | undefined>;
9
+ getConnectedAccounts(): Promise<string[]>;
10
+ clearEmail(): void;
11
+ endSession(): Promise<void>;
12
+ static storageEmailKey: string;
13
+ }
@@ -0,0 +1,83 @@
1
+ 'use client'
2
+ import { __awaiter } from '../_virtual/_tslib.js';
3
+ import { logger } from '@dynamic-labs/wallet-connector-core';
4
+ import { BloctoEvm } from './BloctoEvm.js';
5
+
6
+ class BloctoEmailConnector extends BloctoEvm {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.requiresNonDynamicEmailOtp = true;
10
+ }
11
+ get email() {
12
+ return this._email;
13
+ }
14
+ setEmail(email) {
15
+ this._email = email;
16
+ if (!email) {
17
+ localStorage.removeItem(BloctoEmailConnector.storageEmailKey);
18
+ }
19
+ else {
20
+ localStorage.setItem(BloctoEmailConnector.storageEmailKey, email);
21
+ }
22
+ }
23
+ getAddress() {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ try {
26
+ const client = this.getClient();
27
+ if (!(client === null || client === void 0 ? void 0 : client.ethereum)) {
28
+ return undefined;
29
+ }
30
+ const addresses = yield client.ethereum.request({
31
+ method: 'eth_requestAccounts',
32
+ // When the email is provided, the login modal will prefill the email field.
33
+ params: this.email ? [this.email] : undefined,
34
+ });
35
+ if ((addresses === null || addresses === void 0 ? void 0 : addresses.length) > 0) {
36
+ return addresses[0];
37
+ }
38
+ return undefined;
39
+ }
40
+ catch (e) {
41
+ logger.error(e);
42
+ return Promise.reject(e);
43
+ }
44
+ });
45
+ }
46
+ getConnectedAccounts() {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const client = this.getClient();
49
+ if (!client) {
50
+ return [];
51
+ }
52
+ if (client.ethereum) {
53
+ const accounts = yield client.ethereum.request({
54
+ method: 'eth_requestAccounts',
55
+ // When the email is provided, the login modal will prefill the email field.
56
+ params: this.email ? [this.email] : undefined,
57
+ });
58
+ return accounts || [];
59
+ }
60
+ return [];
61
+ });
62
+ }
63
+ clearEmail() {
64
+ this.setEmail(undefined);
65
+ }
66
+ endSession() {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const client = this.getClient();
69
+ localStorage.removeItem('sdk.session');
70
+ if (this.email && // cancel the session only if the email is set
71
+ client &&
72
+ client.ethereum &&
73
+ this.checkForSessionAccounts()) {
74
+ yield client.ethereum.request({ method: 'wallet_disconnect' });
75
+ this.removeClient();
76
+ }
77
+ this.clearEmail();
78
+ });
79
+ }
80
+ }
81
+ BloctoEmailConnector.storageEmailKey = 'blocto-email';
82
+
83
+ export { BloctoEmailConnector };
@@ -0,0 +1,144 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../_virtual/_tslib.cjs');
7
+ var BloctoSDK = require('@blocto/sdk');
8
+ var viem = require('viem');
9
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
10
+ var ethereum = require('@dynamic-labs/ethereum');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var BloctoSDK__default = /*#__PURE__*/_interopDefaultLegacy(BloctoSDK);
15
+
16
+ class BloctoEvm extends ethereum.EthWalletConnector {
17
+ constructor(props) {
18
+ var _a, _b;
19
+ super(props);
20
+ this.LOCAL_STORAGE_KEY = 'dynamic_blocto_evm_chain_id';
21
+ this.SESSION_STORAGE_BLOCTO_KEY = 'BLOCTO_SDK';
22
+ this.name = 'bloctoevm';
23
+ this.overrideKey = 'bloctoevm';
24
+ this.canConnectViaCustodialService = true;
25
+ this.connectedChain = 'EVM';
26
+ this.supportedChains = ['EVM', 'ETH'];
27
+ this.supportsNetworkSwitching = () => false;
28
+ // Taken from : https://docs.blocto.app/blocto-sdk/javascript-sdk/evm-sdk/provider
29
+ const BLOCTO_SUPPORTED_CHAIN_IDS = [1, 4, 56, 97, 137, 80001, 43114, 43113];
30
+ this.evmNetworks = this.evmNetworks.filter((n) => BLOCTO_SUPPORTED_CHAIN_IDS.includes(n.chainId));
31
+ this.chainId =
32
+ Number(localStorage.getItem(this.LOCAL_STORAGE_KEY)) ||
33
+ ((_a = this.evmNetworks.find((n) => n.chainId === 137)) === null || _a === void 0 ? void 0 : _a.chainId) ||
34
+ ((_b = this.evmNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId);
35
+ if (this.evmNetworks.length > 0) {
36
+ this.initClient();
37
+ }
38
+ }
39
+ // Check if there are already any accounts in the session
40
+ // Blocto in version > 0.5.0 started to store the accounts in the session storage
41
+ checkForSessionAccounts() {
42
+ var _a, _b;
43
+ try {
44
+ const sessionValue = sessionStorage.getItem(this.SESSION_STORAGE_BLOCTO_KEY);
45
+ const parsedSessionValue = JSON.parse(sessionValue);
46
+ return (((_a = parsedSessionValue === null || parsedSessionValue === void 0 ? void 0 : parsedSessionValue.data) === null || _a === void 0 ? void 0 : _a.accounts) &&
47
+ Object.keys((_b = parsedSessionValue === null || parsedSessionValue === void 0 ? void 0 : parsedSessionValue.data) === null || _b === void 0 ? void 0 : _b.accounts).length > 0);
48
+ }
49
+ catch (_c) {
50
+ return false;
51
+ }
52
+ }
53
+ initClient() {
54
+ if (!this.client) {
55
+ const network = this.evmNetworks.find((n) => n.chainId === this.chainId);
56
+ if (network) {
57
+ this.client = new BloctoSDK__default["default"]({
58
+ ethereum: {
59
+ chainId: `0x${this.chainId.toString(16)}`,
60
+ rpc: network.rpcUrls[0],
61
+ },
62
+ });
63
+ }
64
+ else {
65
+ walletConnectorCore.logger.error("Couldn't find a configured network for Blocto EVM");
66
+ }
67
+ }
68
+ }
69
+ getClient() {
70
+ return this.client;
71
+ }
72
+ removeClient() {
73
+ this.client = undefined;
74
+ }
75
+ getWalletClient() {
76
+ const client = this.getClient();
77
+ if ((client === null || client === void 0 ? void 0 : client.ethereum) && this.checkForSessionAccounts()) {
78
+ return viem.createWalletClient({ transport: viem.custom(client.ethereum) });
79
+ }
80
+ else {
81
+ return undefined;
82
+ }
83
+ }
84
+ // We are calling the client directly and not via Web3Provider because if we will wrap it in Ethers,
85
+ // Ethers will be making retries on failure. This becomes an issue on the connect step.
86
+ // When Blocto's modal closes prior to receiving a response with the address on the connect step,
87
+ // then ethers would retry and the modal will open again.
88
+ getAddress() {
89
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
90
+ try {
91
+ const client = this.getClient();
92
+ if (!(client === null || client === void 0 ? void 0 : client.ethereum)) {
93
+ return undefined;
94
+ }
95
+ const addresses = yield client.ethereum.request({
96
+ method: 'eth_requestAccounts',
97
+ });
98
+ if ((addresses === null || addresses === void 0 ? void 0 : addresses.length) > 0) {
99
+ return addresses[0];
100
+ }
101
+ return undefined;
102
+ }
103
+ catch (e) {
104
+ walletConnectorCore.logger.error(e);
105
+ return Promise.reject(e);
106
+ }
107
+ });
108
+ }
109
+ signMessage(messageToSign) {
110
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
111
+ var _a;
112
+ try {
113
+ const account = yield this.getAddress();
114
+ if (!account) {
115
+ return Promise.resolve(undefined);
116
+ }
117
+ return yield ((_a = this.getWalletClient()) === null || _a === void 0 ? void 0 : _a.signMessage({
118
+ account,
119
+ message: messageToSign,
120
+ }));
121
+ }
122
+ catch (e) {
123
+ if (e.message === 'User declined the signing request') {
124
+ return Promise.reject({ code: '4001' });
125
+ }
126
+ else {
127
+ return Promise.reject(e);
128
+ }
129
+ }
130
+ });
131
+ }
132
+ endSession() {
133
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
134
+ var _a;
135
+ localStorage.removeItem('sdk.session');
136
+ if (((_a = this.client) === null || _a === void 0 ? void 0 : _a.ethereum) && this.checkForSessionAccounts()) {
137
+ yield this.client.ethereum.request({ method: 'wallet_disconnect' });
138
+ this.removeClient();
139
+ }
140
+ });
141
+ }
142
+ }
143
+
144
+ exports.BloctoEvm = BloctoEvm;
@@ -0,0 +1,25 @@
1
+ import BloctoSDK from '@blocto/sdk';
2
+ import { Hex, WalletClient, Account, Transport, Chain as ViemChain } from 'viem';
3
+ import { Chain } from '@dynamic-labs/wallet-connector-core';
4
+ import { EthWalletConnector, EthWalletConnectorOpts } from '@dynamic-labs/ethereum';
5
+ export declare class BloctoEvm extends EthWalletConnector {
6
+ LOCAL_STORAGE_KEY: string;
7
+ SESSION_STORAGE_BLOCTO_KEY: string;
8
+ protected client?: BloctoSDK;
9
+ name: string;
10
+ overrideKey: string;
11
+ canConnectViaCustodialService: boolean;
12
+ connectedChain: Chain;
13
+ supportedChains: Chain[];
14
+ chainId: number;
15
+ supportsNetworkSwitching: () => boolean;
16
+ constructor(props: EthWalletConnectorOpts);
17
+ protected checkForSessionAccounts(): boolean;
18
+ protected initClient(): void;
19
+ protected getClient(): BloctoSDK | undefined;
20
+ protected removeClient(): void;
21
+ getWalletClient(): WalletClient<Transport, ViemChain, Account> | undefined;
22
+ getAddress(): Promise<Hex | undefined>;
23
+ signMessage(messageToSign: string): Promise<string | undefined>;
24
+ endSession(): Promise<void>;
25
+ }
@@ -0,0 +1,136 @@
1
+ 'use client'
2
+ import { __awaiter } from '../_virtual/_tslib.js';
3
+ import BloctoSDK from '@blocto/sdk';
4
+ import { createWalletClient, custom } from 'viem';
5
+ import { logger } from '@dynamic-labs/wallet-connector-core';
6
+ import { EthWalletConnector } from '@dynamic-labs/ethereum';
7
+
8
+ class BloctoEvm extends EthWalletConnector {
9
+ constructor(props) {
10
+ var _a, _b;
11
+ super(props);
12
+ this.LOCAL_STORAGE_KEY = 'dynamic_blocto_evm_chain_id';
13
+ this.SESSION_STORAGE_BLOCTO_KEY = 'BLOCTO_SDK';
14
+ this.name = 'bloctoevm';
15
+ this.overrideKey = 'bloctoevm';
16
+ this.canConnectViaCustodialService = true;
17
+ this.connectedChain = 'EVM';
18
+ this.supportedChains = ['EVM', 'ETH'];
19
+ this.supportsNetworkSwitching = () => false;
20
+ // Taken from : https://docs.blocto.app/blocto-sdk/javascript-sdk/evm-sdk/provider
21
+ const BLOCTO_SUPPORTED_CHAIN_IDS = [1, 4, 56, 97, 137, 80001, 43114, 43113];
22
+ this.evmNetworks = this.evmNetworks.filter((n) => BLOCTO_SUPPORTED_CHAIN_IDS.includes(n.chainId));
23
+ this.chainId =
24
+ Number(localStorage.getItem(this.LOCAL_STORAGE_KEY)) ||
25
+ ((_a = this.evmNetworks.find((n) => n.chainId === 137)) === null || _a === void 0 ? void 0 : _a.chainId) ||
26
+ ((_b = this.evmNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId);
27
+ if (this.evmNetworks.length > 0) {
28
+ this.initClient();
29
+ }
30
+ }
31
+ // Check if there are already any accounts in the session
32
+ // Blocto in version > 0.5.0 started to store the accounts in the session storage
33
+ checkForSessionAccounts() {
34
+ var _a, _b;
35
+ try {
36
+ const sessionValue = sessionStorage.getItem(this.SESSION_STORAGE_BLOCTO_KEY);
37
+ const parsedSessionValue = JSON.parse(sessionValue);
38
+ return (((_a = parsedSessionValue === null || parsedSessionValue === void 0 ? void 0 : parsedSessionValue.data) === null || _a === void 0 ? void 0 : _a.accounts) &&
39
+ Object.keys((_b = parsedSessionValue === null || parsedSessionValue === void 0 ? void 0 : parsedSessionValue.data) === null || _b === void 0 ? void 0 : _b.accounts).length > 0);
40
+ }
41
+ catch (_c) {
42
+ return false;
43
+ }
44
+ }
45
+ initClient() {
46
+ if (!this.client) {
47
+ const network = this.evmNetworks.find((n) => n.chainId === this.chainId);
48
+ if (network) {
49
+ this.client = new BloctoSDK({
50
+ ethereum: {
51
+ chainId: `0x${this.chainId.toString(16)}`,
52
+ rpc: network.rpcUrls[0],
53
+ },
54
+ });
55
+ }
56
+ else {
57
+ logger.error("Couldn't find a configured network for Blocto EVM");
58
+ }
59
+ }
60
+ }
61
+ getClient() {
62
+ return this.client;
63
+ }
64
+ removeClient() {
65
+ this.client = undefined;
66
+ }
67
+ getWalletClient() {
68
+ const client = this.getClient();
69
+ if ((client === null || client === void 0 ? void 0 : client.ethereum) && this.checkForSessionAccounts()) {
70
+ return createWalletClient({ transport: custom(client.ethereum) });
71
+ }
72
+ else {
73
+ return undefined;
74
+ }
75
+ }
76
+ // We are calling the client directly and not via Web3Provider because if we will wrap it in Ethers,
77
+ // Ethers will be making retries on failure. This becomes an issue on the connect step.
78
+ // When Blocto's modal closes prior to receiving a response with the address on the connect step,
79
+ // then ethers would retry and the modal will open again.
80
+ getAddress() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ try {
83
+ const client = this.getClient();
84
+ if (!(client === null || client === void 0 ? void 0 : client.ethereum)) {
85
+ return undefined;
86
+ }
87
+ const addresses = yield client.ethereum.request({
88
+ method: 'eth_requestAccounts',
89
+ });
90
+ if ((addresses === null || addresses === void 0 ? void 0 : addresses.length) > 0) {
91
+ return addresses[0];
92
+ }
93
+ return undefined;
94
+ }
95
+ catch (e) {
96
+ logger.error(e);
97
+ return Promise.reject(e);
98
+ }
99
+ });
100
+ }
101
+ signMessage(messageToSign) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ var _a;
104
+ try {
105
+ const account = yield this.getAddress();
106
+ if (!account) {
107
+ return Promise.resolve(undefined);
108
+ }
109
+ return yield ((_a = this.getWalletClient()) === null || _a === void 0 ? void 0 : _a.signMessage({
110
+ account,
111
+ message: messageToSign,
112
+ }));
113
+ }
114
+ catch (e) {
115
+ if (e.message === 'User declined the signing request') {
116
+ return Promise.reject({ code: '4001' });
117
+ }
118
+ else {
119
+ return Promise.reject(e);
120
+ }
121
+ }
122
+ });
123
+ }
124
+ endSession() {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ var _a;
127
+ localStorage.removeItem('sdk.session');
128
+ if (((_a = this.client) === null || _a === void 0 ? void 0 : _a.ethereum) && this.checkForSessionAccounts()) {
129
+ yield this.client.ethereum.request({ method: 'wallet_disconnect' });
130
+ this.removeClient();
131
+ }
132
+ });
133
+ }
134
+ }
135
+
136
+ export { BloctoEvm };
package/src/index.cjs ADDED
@@ -0,0 +1,18 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var BloctoEvm = require('./BloctoEvm.cjs');
7
+ var BloctoEmailConnector = require('./BloctoEmailConnector.cjs');
8
+
9
+ const BloctoEvmWalletConnectors = (
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ _props) => [
12
+ BloctoEvm.BloctoEvm,
13
+ ...(_props.apiProviders.blocto ? [BloctoEmailConnector.BloctoEmailConnector] : []),
14
+ ];
15
+
16
+ exports.BloctoEvm = BloctoEvm.BloctoEvm;
17
+ exports.BloctoEmailConnector = BloctoEmailConnector.BloctoEmailConnector;
18
+ exports.BloctoEvmWalletConnectors = BloctoEvmWalletConnectors;
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
2
+ export * from './BloctoEvm';
3
+ export * from './BloctoEmailConnector';
4
+ export declare const BloctoEvmWalletConnectors: (_props: any) => WalletConnectorConstructor[];
package/src/index.js ADDED
@@ -0,0 +1,14 @@
1
+ 'use client'
2
+ import { BloctoEvm } from './BloctoEvm.js';
3
+ export { BloctoEvm } from './BloctoEvm.js';
4
+ import { BloctoEmailConnector } from './BloctoEmailConnector.js';
5
+ export { BloctoEmailConnector } from './BloctoEmailConnector.js';
6
+
7
+ const BloctoEvmWalletConnectors = (
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ _props) => [
10
+ BloctoEvm,
11
+ ...(_props.apiProviders.blocto ? [BloctoEmailConnector] : []),
12
+ ];
13
+
14
+ export { BloctoEvmWalletConnectors };