@wagmi/connectors 3.1.1 → 4.0.0-alpha.1
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/README.md +6 -39
- package/dist/esm/coinbaseWallet.js +141 -0
- package/dist/esm/coinbaseWallet.js.map +1 -0
- package/dist/esm/exports/index.js +7 -0
- package/dist/esm/exports/index.js.map +1 -0
- package/dist/esm/exports/index.test-d.js +4 -0
- package/dist/esm/exports/index.test-d.js.map +1 -0
- package/dist/esm/injected.js +372 -0
- package/dist/esm/injected.js.map +1 -0
- package/dist/esm/ledger.js +162 -0
- package/dist/esm/ledger.js.map +1 -0
- package/dist/esm/safe.js +88 -0
- package/dist/esm/safe.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/walletConnect.js +280 -0
- package/dist/esm/walletConnect.js.map +1 -0
- package/dist/types/coinbaseWallet.d.ts +21 -0
- package/dist/types/coinbaseWallet.d.ts.map +1 -0
- package/dist/types/exports/index.d.ts +7 -0
- package/dist/types/exports/index.d.ts.map +1 -0
- package/dist/types/exports/index.test-d.d.ts +2 -0
- package/dist/types/exports/index.test-d.d.ts.map +1 -0
- package/dist/types/injected.d.ts +382 -0
- package/dist/types/injected.d.ts.map +1 -0
- package/dist/types/ledger.d.ts +18 -0
- package/dist/types/ledger.d.ts.map +1 -0
- package/dist/types/safe.d.ts +18 -0
- package/dist/types/safe.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/dist/types/walletConnect.d.ts +63 -0
- package/dist/types/walletConnect.d.ts.map +1 -0
- package/package.json +43 -82
- package/src/coinbaseWallet.ts +207 -0
- package/src/exports/index.ts +17 -0
- package/src/injected.ts +535 -0
- package/src/ledger.ts +210 -0
- package/src/safe.ts +114 -0
- package/src/version.ts +1 -0
- package/src/walletConnect.ts +394 -0
- package/coinbaseWallet/package.json +0 -4
- package/dist/base-70e3a8a9.d.ts +0 -142
- package/dist/chunk-2UFLHRLT.js +0 -391
- package/dist/chunk-OQILYQDO.js +0 -15
- package/dist/chunk-UGBGYVBH.js +0 -22
- package/dist/chunk-W65LBPLT.js +0 -58
- package/dist/coinbaseWallet.d.ts +0 -62
- package/dist/coinbaseWallet.js +0 -216
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -16
- package/dist/injected.d.ts +0 -64
- package/dist/injected.js +0 -9
- package/dist/ledger.d.ts +0 -69
- package/dist/ledger.js +0 -261
- package/dist/metaMask.d.ts +0 -33
- package/dist/metaMask.js +0 -144
- package/dist/mock/index.d.ts +0 -80
- package/dist/mock/index.js +0 -200
- package/dist/safe.d.ts +0 -53
- package/dist/safe.js +0 -129
- package/dist/walletConnect.d.ts +0 -109
- package/dist/walletConnect.js +0 -325
- package/dist/walletConnectLegacy.d.ts +0 -38
- package/dist/walletConnectLegacy.js +0 -179
- package/injected/package.json +0 -4
- package/ledger/package.json +0 -4
- package/metaMask/package.json +0 -4
- package/mock/package.json +0 -4
- package/safe/package.json +0 -4
- package/walletConnect/package.json +0 -4
- package/walletConnectLegacy/package.json +0 -4
package/dist/metaMask.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InjectedConnector
|
|
3
|
-
} from "./chunk-2UFLHRLT.js";
|
|
4
|
-
import {
|
|
5
|
-
ConnectorNotFoundError
|
|
6
|
-
} from "./chunk-UGBGYVBH.js";
|
|
7
|
-
import "./chunk-OQILYQDO.js";
|
|
8
|
-
import {
|
|
9
|
-
__privateAdd,
|
|
10
|
-
__privateGet,
|
|
11
|
-
__privateSet
|
|
12
|
-
} from "./chunk-W65LBPLT.js";
|
|
13
|
-
|
|
14
|
-
// src/metaMask.ts
|
|
15
|
-
import {
|
|
16
|
-
ResourceUnavailableRpcError,
|
|
17
|
-
UserRejectedRequestError,
|
|
18
|
-
getAddress
|
|
19
|
-
} from "viem";
|
|
20
|
-
var _UNSTABLE_shimOnConnectSelectAccount;
|
|
21
|
-
var MetaMaskConnector = class extends InjectedConnector {
|
|
22
|
-
constructor({
|
|
23
|
-
chains,
|
|
24
|
-
options: options_
|
|
25
|
-
} = {}) {
|
|
26
|
-
const options = {
|
|
27
|
-
name: "MetaMask",
|
|
28
|
-
shimDisconnect: true,
|
|
29
|
-
getProvider() {
|
|
30
|
-
function getReady(ethereum2) {
|
|
31
|
-
const isMetaMask = !!ethereum2?.isMetaMask;
|
|
32
|
-
if (!isMetaMask)
|
|
33
|
-
return;
|
|
34
|
-
if (ethereum2.isBraveWallet && !ethereum2._events && !ethereum2._state)
|
|
35
|
-
return;
|
|
36
|
-
if (ethereum2.isApexWallet)
|
|
37
|
-
return;
|
|
38
|
-
if (ethereum2.isAvalanche)
|
|
39
|
-
return;
|
|
40
|
-
if (ethereum2.isBitKeep)
|
|
41
|
-
return;
|
|
42
|
-
if (ethereum2.isBlockWallet)
|
|
43
|
-
return;
|
|
44
|
-
if (ethereum2.isCoin98)
|
|
45
|
-
return;
|
|
46
|
-
if (ethereum2.isFordefi)
|
|
47
|
-
return;
|
|
48
|
-
if (ethereum2.isMathWallet)
|
|
49
|
-
return;
|
|
50
|
-
if (ethereum2.isOkxWallet || ethereum2.isOKExWallet)
|
|
51
|
-
return;
|
|
52
|
-
if (ethereum2.isOneInchIOSWallet || ethereum2.isOneInchAndroidWallet)
|
|
53
|
-
return;
|
|
54
|
-
if (ethereum2.isOpera)
|
|
55
|
-
return;
|
|
56
|
-
if (ethereum2.isPortal)
|
|
57
|
-
return;
|
|
58
|
-
if (ethereum2.isRabby)
|
|
59
|
-
return;
|
|
60
|
-
if (ethereum2.isDefiant)
|
|
61
|
-
return;
|
|
62
|
-
if (ethereum2.isTokenPocket)
|
|
63
|
-
return;
|
|
64
|
-
if (ethereum2.isTokenary)
|
|
65
|
-
return;
|
|
66
|
-
if (ethereum2.isZeal)
|
|
67
|
-
return;
|
|
68
|
-
if (ethereum2.isZerion)
|
|
69
|
-
return;
|
|
70
|
-
return ethereum2;
|
|
71
|
-
}
|
|
72
|
-
if (typeof window === "undefined")
|
|
73
|
-
return;
|
|
74
|
-
const ethereum = window.ethereum;
|
|
75
|
-
if (ethereum?.providers)
|
|
76
|
-
return ethereum.providers.find(getReady);
|
|
77
|
-
return getReady(ethereum);
|
|
78
|
-
},
|
|
79
|
-
...options_
|
|
80
|
-
};
|
|
81
|
-
super({ chains, options });
|
|
82
|
-
this.id = "metaMask";
|
|
83
|
-
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
|
|
84
|
-
__privateAdd(this, _UNSTABLE_shimOnConnectSelectAccount, void 0);
|
|
85
|
-
__privateSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
86
|
-
}
|
|
87
|
-
async connect({ chainId } = {}) {
|
|
88
|
-
try {
|
|
89
|
-
const provider = await this.getProvider();
|
|
90
|
-
if (!provider)
|
|
91
|
-
throw new ConnectorNotFoundError();
|
|
92
|
-
if (provider.on) {
|
|
93
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
94
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
95
|
-
provider.on("disconnect", this.onDisconnect);
|
|
96
|
-
}
|
|
97
|
-
this.emit("message", { type: "connecting" });
|
|
98
|
-
let account = null;
|
|
99
|
-
if (__privateGet(this, _UNSTABLE_shimOnConnectSelectAccount) && this.options?.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey)) {
|
|
100
|
-
account = await this.getAccount().catch(() => null);
|
|
101
|
-
const isConnected = !!account;
|
|
102
|
-
if (isConnected)
|
|
103
|
-
try {
|
|
104
|
-
await provider.request({
|
|
105
|
-
method: "wallet_requestPermissions",
|
|
106
|
-
params: [{ eth_accounts: {} }]
|
|
107
|
-
});
|
|
108
|
-
account = await this.getAccount();
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (this.isUserRejectedRequestError(error))
|
|
111
|
-
throw new UserRejectedRequestError(error);
|
|
112
|
-
if (error.code === new ResourceUnavailableRpcError(error).code)
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (!account) {
|
|
117
|
-
const accounts = await provider.request({
|
|
118
|
-
method: "eth_requestAccounts"
|
|
119
|
-
});
|
|
120
|
-
account = getAddress(accounts[0]);
|
|
121
|
-
}
|
|
122
|
-
let id = await this.getChainId();
|
|
123
|
-
let unsupported = this.isChainUnsupported(id);
|
|
124
|
-
if (chainId && id !== chainId) {
|
|
125
|
-
const chain = await this.switchChain(chainId);
|
|
126
|
-
id = chain.id;
|
|
127
|
-
unsupported = this.isChainUnsupported(id);
|
|
128
|
-
}
|
|
129
|
-
if (this.options?.shimDisconnect)
|
|
130
|
-
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
131
|
-
return { account, chain: { id, unsupported }, provider };
|
|
132
|
-
} catch (error) {
|
|
133
|
-
if (this.isUserRejectedRequestError(error))
|
|
134
|
-
throw new UserRejectedRequestError(error);
|
|
135
|
-
if (error.code === -32002)
|
|
136
|
-
throw new ResourceUnavailableRpcError(error);
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
_UNSTABLE_shimOnConnectSelectAccount = new WeakMap();
|
|
142
|
-
export {
|
|
143
|
-
MetaMaskConnector
|
|
144
|
-
};
|
package/dist/mock/index.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Chain } from 'viem/chains';
|
|
2
|
-
import { c as WalletClient, C as Connector, a as ConnectorData } from '../base-70e3a8a9.js';
|
|
3
|
-
import EventEmitter from 'eventemitter3';
|
|
4
|
-
import 'viem';
|
|
5
|
-
|
|
6
|
-
type MockProviderOptions = {
|
|
7
|
-
chainId: number;
|
|
8
|
-
flags?: {
|
|
9
|
-
isAuthorized?: boolean;
|
|
10
|
-
failConnect?: boolean;
|
|
11
|
-
failSwitchChain?: boolean;
|
|
12
|
-
noSwitchChain?: boolean;
|
|
13
|
-
};
|
|
14
|
-
walletClient: WalletClient;
|
|
15
|
-
};
|
|
16
|
-
type Events = {
|
|
17
|
-
accountsChanged(accounts: string[]): void;
|
|
18
|
-
chainChanged(chainId: number | string): void;
|
|
19
|
-
disconnect(): void;
|
|
20
|
-
};
|
|
21
|
-
type Event = keyof Events;
|
|
22
|
-
declare class MockProvider {
|
|
23
|
-
#private;
|
|
24
|
-
events: EventEmitter<Events, any>;
|
|
25
|
-
chainId: number;
|
|
26
|
-
constructor(options: MockProviderOptions);
|
|
27
|
-
enable(): Promise<`0x${string}`[]>;
|
|
28
|
-
disconnect(): Promise<void>;
|
|
29
|
-
getAccounts(): Promise<`0x${string}`[]>;
|
|
30
|
-
getWalletClient(): WalletClient;
|
|
31
|
-
switchChain(chainId: number): Promise<void>;
|
|
32
|
-
switchWalletClient(walletClient: WalletClient): Promise<void>;
|
|
33
|
-
watchAsset(_asset: {
|
|
34
|
-
address: string;
|
|
35
|
-
decimals?: number;
|
|
36
|
-
image?: string;
|
|
37
|
-
symbol: string;
|
|
38
|
-
}): Promise<boolean>;
|
|
39
|
-
request({ method, params }: any): Promise<unknown>;
|
|
40
|
-
on(event: Event, listener: (...args: any[]) => void): this;
|
|
41
|
-
removeListener(event: Event, listener: (...args: any[]) => void): this;
|
|
42
|
-
toJSON(): string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type MockConnectorOptions = Omit<MockProviderOptions, 'chainId'> & {
|
|
46
|
-
chainId?: number;
|
|
47
|
-
};
|
|
48
|
-
declare class MockConnector extends Connector<MockProvider, MockConnectorOptions> {
|
|
49
|
-
#private;
|
|
50
|
-
readonly id = "mock";
|
|
51
|
-
readonly name = "Mock";
|
|
52
|
-
readonly ready = true;
|
|
53
|
-
constructor({ chains, options, }: {
|
|
54
|
-
chains?: Chain[];
|
|
55
|
-
options: MockConnectorOptions;
|
|
56
|
-
});
|
|
57
|
-
connect({ chainId }?: {
|
|
58
|
-
chainId?: number;
|
|
59
|
-
}): Promise<Required<ConnectorData>>;
|
|
60
|
-
disconnect(): Promise<void>;
|
|
61
|
-
getAccount(): Promise<`0x${string}`>;
|
|
62
|
-
getChainId(): Promise<number>;
|
|
63
|
-
getProvider({ chainId }?: {
|
|
64
|
-
chainId?: number;
|
|
65
|
-
}): Promise<MockProvider>;
|
|
66
|
-
getWalletClient(): Promise<WalletClient>;
|
|
67
|
-
isAuthorized(): Promise<boolean>;
|
|
68
|
-
watchAsset(asset: {
|
|
69
|
-
address: string;
|
|
70
|
-
decimals?: number;
|
|
71
|
-
image?: string;
|
|
72
|
-
symbol: string;
|
|
73
|
-
}): Promise<boolean>;
|
|
74
|
-
protected onAccountsChanged: (accounts: string[]) => void;
|
|
75
|
-
protected onChainChanged: (chainId: number | string) => void;
|
|
76
|
-
protected onDisconnect: () => void;
|
|
77
|
-
toJSON(): string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export { MockConnector, MockProvider, MockProviderOptions };
|
package/dist/mock/index.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalizeChainId
|
|
3
|
-
} from "../chunk-OQILYQDO.js";
|
|
4
|
-
import {
|
|
5
|
-
Connector,
|
|
6
|
-
__privateAdd,
|
|
7
|
-
__privateGet,
|
|
8
|
-
__privateMethod,
|
|
9
|
-
__privateSet
|
|
10
|
-
} from "../chunk-W65LBPLT.js";
|
|
11
|
-
|
|
12
|
-
// src/mock/connector.ts
|
|
13
|
-
import { getAddress as getAddress2 } from "viem";
|
|
14
|
-
|
|
15
|
-
// src/mock/provider.ts
|
|
16
|
-
import { default as EventEmitter } from "eventemitter3";
|
|
17
|
-
import { UserRejectedRequestError, getAddress } from "viem";
|
|
18
|
-
var _options, _walletClient;
|
|
19
|
-
var MockProvider = class {
|
|
20
|
-
constructor(options) {
|
|
21
|
-
this.events = new EventEmitter();
|
|
22
|
-
__privateAdd(this, _options, void 0);
|
|
23
|
-
__privateAdd(this, _walletClient, void 0);
|
|
24
|
-
this.chainId = options.chainId;
|
|
25
|
-
__privateSet(this, _options, options);
|
|
26
|
-
}
|
|
27
|
-
async enable() {
|
|
28
|
-
if (__privateGet(this, _options).flags?.failConnect)
|
|
29
|
-
throw new UserRejectedRequestError(new Error("Failed to connect."));
|
|
30
|
-
if (!__privateGet(this, _walletClient))
|
|
31
|
-
__privateSet(this, _walletClient, __privateGet(this, _options).walletClient);
|
|
32
|
-
const address = __privateGet(this, _walletClient).account.address;
|
|
33
|
-
this.events.emit("accountsChanged", [address]);
|
|
34
|
-
return [address];
|
|
35
|
-
}
|
|
36
|
-
async disconnect() {
|
|
37
|
-
this.events.emit("disconnect");
|
|
38
|
-
__privateSet(this, _walletClient, void 0);
|
|
39
|
-
}
|
|
40
|
-
async getAccounts() {
|
|
41
|
-
const address = __privateGet(this, _walletClient)?.account.address;
|
|
42
|
-
if (!address)
|
|
43
|
-
return [];
|
|
44
|
-
return [getAddress(address)];
|
|
45
|
-
}
|
|
46
|
-
getWalletClient() {
|
|
47
|
-
const walletClient = __privateGet(this, _walletClient);
|
|
48
|
-
if (!walletClient)
|
|
49
|
-
throw new Error("walletClient not found");
|
|
50
|
-
return walletClient;
|
|
51
|
-
}
|
|
52
|
-
async switchChain(chainId) {
|
|
53
|
-
if (__privateGet(this, _options).flags?.failSwitchChain)
|
|
54
|
-
throw new UserRejectedRequestError(new Error("Failed to switch chain."));
|
|
55
|
-
__privateGet(this, _options).chainId = chainId;
|
|
56
|
-
this.chainId = chainId;
|
|
57
|
-
this.events.emit("chainChanged", chainId);
|
|
58
|
-
}
|
|
59
|
-
async switchWalletClient(walletClient) {
|
|
60
|
-
const address = walletClient.account.address;
|
|
61
|
-
__privateSet(this, _walletClient, walletClient);
|
|
62
|
-
this.events.emit("accountsChanged", [address]);
|
|
63
|
-
}
|
|
64
|
-
async watchAsset(_asset) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
async request({ method, params }) {
|
|
68
|
-
return __privateGet(this, _walletClient)?.transport.request({ method, params });
|
|
69
|
-
}
|
|
70
|
-
on(event, listener) {
|
|
71
|
-
this.events.on(event, listener);
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
removeListener(event, listener) {
|
|
75
|
-
this.events.removeListener(event, listener);
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
toJSON() {
|
|
79
|
-
return "<MockProvider>";
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
_options = new WeakMap();
|
|
83
|
-
_walletClient = new WeakMap();
|
|
84
|
-
|
|
85
|
-
// src/mock/connector.ts
|
|
86
|
-
var _provider, _switchChain, switchChain_fn;
|
|
87
|
-
var MockConnector = class extends Connector {
|
|
88
|
-
constructor({
|
|
89
|
-
chains,
|
|
90
|
-
options
|
|
91
|
-
}) {
|
|
92
|
-
super({
|
|
93
|
-
chains,
|
|
94
|
-
options: {
|
|
95
|
-
...options,
|
|
96
|
-
chainId: options.chainId ?? chains?.[0]?.id
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
__privateAdd(this, _switchChain);
|
|
100
|
-
this.id = "mock";
|
|
101
|
-
this.name = "Mock";
|
|
102
|
-
this.ready = true;
|
|
103
|
-
__privateAdd(this, _provider, void 0);
|
|
104
|
-
this.onAccountsChanged = (accounts) => {
|
|
105
|
-
if (accounts.length === 0)
|
|
106
|
-
this.emit("disconnect");
|
|
107
|
-
else
|
|
108
|
-
this.emit("change", { account: getAddress2(accounts[0]) });
|
|
109
|
-
};
|
|
110
|
-
this.onChainChanged = (chainId) => {
|
|
111
|
-
const id = normalizeChainId(chainId);
|
|
112
|
-
const unsupported = this.isChainUnsupported(id);
|
|
113
|
-
this.emit("change", { chain: { id, unsupported } });
|
|
114
|
-
};
|
|
115
|
-
this.onDisconnect = () => {
|
|
116
|
-
this.emit("disconnect");
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async connect({ chainId } = {}) {
|
|
120
|
-
const provider = await this.getProvider({ chainId });
|
|
121
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
122
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
123
|
-
provider.on("disconnect", this.onDisconnect);
|
|
124
|
-
this.emit("message", { type: "connecting" });
|
|
125
|
-
const accounts = await provider.enable();
|
|
126
|
-
const account = getAddress2(accounts[0]);
|
|
127
|
-
const id = normalizeChainId(provider.chainId);
|
|
128
|
-
const unsupported = this.isChainUnsupported(id);
|
|
129
|
-
const data = { account, chain: { id, unsupported }, provider };
|
|
130
|
-
if (!this.options.flags?.noSwitchChain)
|
|
131
|
-
this.switchChain = __privateMethod(this, _switchChain, switchChain_fn);
|
|
132
|
-
return new Promise(
|
|
133
|
-
(res) => setTimeout(() => res(data), 100)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
async disconnect() {
|
|
137
|
-
const provider = await this.getProvider();
|
|
138
|
-
await provider.disconnect();
|
|
139
|
-
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
140
|
-
provider.removeListener("chainChanged", this.onChainChanged);
|
|
141
|
-
provider.removeListener("disconnect", this.onDisconnect);
|
|
142
|
-
}
|
|
143
|
-
async getAccount() {
|
|
144
|
-
const provider = await this.getProvider();
|
|
145
|
-
const accounts = await provider.getAccounts();
|
|
146
|
-
const account = accounts[0];
|
|
147
|
-
if (!account)
|
|
148
|
-
throw new Error("Failed to get account");
|
|
149
|
-
return getAddress2(account);
|
|
150
|
-
}
|
|
151
|
-
async getChainId() {
|
|
152
|
-
const provider = await this.getProvider();
|
|
153
|
-
return normalizeChainId(provider.chainId);
|
|
154
|
-
}
|
|
155
|
-
async getProvider({ chainId } = {}) {
|
|
156
|
-
if (!__privateGet(this, _provider) || chainId)
|
|
157
|
-
__privateSet(this, _provider, new MockProvider({
|
|
158
|
-
...this.options,
|
|
159
|
-
chainId: chainId ?? this.options.chainId ?? this.chains[0].id
|
|
160
|
-
}));
|
|
161
|
-
return __privateGet(this, _provider);
|
|
162
|
-
}
|
|
163
|
-
async getWalletClient() {
|
|
164
|
-
const provider = await this.getProvider();
|
|
165
|
-
return provider.getWalletClient();
|
|
166
|
-
}
|
|
167
|
-
async isAuthorized() {
|
|
168
|
-
try {
|
|
169
|
-
const provider = await this.getProvider();
|
|
170
|
-
const account = await provider.getAccounts();
|
|
171
|
-
return this.options.flags?.isAuthorized ?? !!account;
|
|
172
|
-
} catch {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
async watchAsset(asset) {
|
|
177
|
-
const provider = await this.getProvider();
|
|
178
|
-
return provider.watchAsset(asset);
|
|
179
|
-
}
|
|
180
|
-
toJSON() {
|
|
181
|
-
return "<MockConnector>";
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
_provider = new WeakMap();
|
|
185
|
-
_switchChain = new WeakSet();
|
|
186
|
-
switchChain_fn = async function(chainId) {
|
|
187
|
-
const provider = await this.getProvider();
|
|
188
|
-
await provider.switchChain(chainId);
|
|
189
|
-
return this.chains.find((x) => x.id === chainId) ?? {
|
|
190
|
-
id: chainId,
|
|
191
|
-
name: `Chain ${chainId}`,
|
|
192
|
-
network: `${chainId}`,
|
|
193
|
-
nativeCurrency: { name: "Ether", decimals: 18, symbol: "ETH" },
|
|
194
|
-
rpcUrls: { default: { http: [""] }, public: { http: [""] } }
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
export {
|
|
198
|
-
MockConnector,
|
|
199
|
-
MockProvider
|
|
200
|
-
};
|
package/dist/safe.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { SafeAppProvider } from '@safe-global/safe-apps-provider';
|
|
2
|
-
import { Opts } from '@safe-global/safe-apps-sdk';
|
|
3
|
-
import { Chain } from 'viem/chains';
|
|
4
|
-
import { C as Connector, c as WalletClient } from './base-70e3a8a9.js';
|
|
5
|
-
import 'eventemitter3';
|
|
6
|
-
import 'viem';
|
|
7
|
-
|
|
8
|
-
type SafeConnectorProvider = SafeAppProvider;
|
|
9
|
-
type SafeConnectorOptions = Opts & {
|
|
10
|
-
/**
|
|
11
|
-
* Connector automatically connects when used as Safe App.
|
|
12
|
-
*
|
|
13
|
-
* This flag simulates the disconnect behavior by keeping track of connection status in storage
|
|
14
|
-
* and only autoconnecting when previously connected by user action (e.g. explicitly choosing to connect).
|
|
15
|
-
*
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
shimDisconnect?: boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Connector for [Safe Wallet](https://safe.global)
|
|
22
|
-
*/
|
|
23
|
-
declare class SafeConnector extends Connector<SafeConnectorProvider, SafeConnectorOptions> {
|
|
24
|
-
#private;
|
|
25
|
-
readonly id = "safe";
|
|
26
|
-
readonly name = "Safe";
|
|
27
|
-
ready: boolean;
|
|
28
|
-
protected shimDisconnectKey: string;
|
|
29
|
-
constructor({ chains, options: options_, }: {
|
|
30
|
-
chains?: Chain[];
|
|
31
|
-
options?: SafeConnectorOptions;
|
|
32
|
-
});
|
|
33
|
-
connect(): Promise<{
|
|
34
|
-
account: `0x${string}`;
|
|
35
|
-
chain: {
|
|
36
|
-
id: number;
|
|
37
|
-
unsupported: boolean;
|
|
38
|
-
};
|
|
39
|
-
}>;
|
|
40
|
-
disconnect(): Promise<void>;
|
|
41
|
-
getAccount(): Promise<`0x${string}`>;
|
|
42
|
-
getChainId(): Promise<number>;
|
|
43
|
-
getProvider(): Promise<SafeAppProvider>;
|
|
44
|
-
getWalletClient({ chainId, }?: {
|
|
45
|
-
chainId?: number;
|
|
46
|
-
}): Promise<WalletClient>;
|
|
47
|
-
isAuthorized(): Promise<boolean>;
|
|
48
|
-
protected onAccountsChanged(_accounts: string[]): void;
|
|
49
|
-
protected onChainChanged(_chainId: string | number): void;
|
|
50
|
-
protected onDisconnect(): void;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { SafeConnector, SafeConnectorOptions, SafeConnectorProvider };
|
package/dist/safe.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConnectorNotFoundError
|
|
3
|
-
} from "./chunk-UGBGYVBH.js";
|
|
4
|
-
import {
|
|
5
|
-
normalizeChainId
|
|
6
|
-
} from "./chunk-OQILYQDO.js";
|
|
7
|
-
import {
|
|
8
|
-
Connector,
|
|
9
|
-
__privateAdd,
|
|
10
|
-
__privateGet,
|
|
11
|
-
__privateSet
|
|
12
|
-
} from "./chunk-W65LBPLT.js";
|
|
13
|
-
|
|
14
|
-
// src/safe.ts
|
|
15
|
-
import { SafeAppProvider } from "@safe-global/safe-apps-provider";
|
|
16
|
-
import { default as SafeAppsSDK } from "@safe-global/safe-apps-sdk";
|
|
17
|
-
import { createWalletClient, custom, getAddress } from "viem";
|
|
18
|
-
var _provider, _sdk;
|
|
19
|
-
var SafeConnector = class extends Connector {
|
|
20
|
-
constructor({
|
|
21
|
-
chains,
|
|
22
|
-
options: options_
|
|
23
|
-
}) {
|
|
24
|
-
const options = {
|
|
25
|
-
shimDisconnect: false,
|
|
26
|
-
...options_
|
|
27
|
-
};
|
|
28
|
-
super({ chains, options });
|
|
29
|
-
this.id = "safe";
|
|
30
|
-
this.name = "Safe";
|
|
31
|
-
this.ready = !(typeof window === "undefined") && window?.parent !== window;
|
|
32
|
-
__privateAdd(this, _provider, void 0);
|
|
33
|
-
__privateAdd(this, _sdk, void 0);
|
|
34
|
-
this.shimDisconnectKey = `${this.id}.shimDisconnect`;
|
|
35
|
-
let SDK = SafeAppsSDK;
|
|
36
|
-
if (typeof SafeAppsSDK !== "function" && typeof SafeAppsSDK.default === "function")
|
|
37
|
-
SDK = SafeAppsSDK.default;
|
|
38
|
-
__privateSet(this, _sdk, new SDK(options));
|
|
39
|
-
}
|
|
40
|
-
async connect() {
|
|
41
|
-
const provider = await this.getProvider();
|
|
42
|
-
if (!provider)
|
|
43
|
-
throw new ConnectorNotFoundError();
|
|
44
|
-
if (provider.on) {
|
|
45
|
-
provider.on("accountsChanged", this.onAccountsChanged);
|
|
46
|
-
provider.on("chainChanged", this.onChainChanged);
|
|
47
|
-
provider.on("disconnect", this.onDisconnect);
|
|
48
|
-
}
|
|
49
|
-
this.emit("message", { type: "connecting" });
|
|
50
|
-
const account = await this.getAccount();
|
|
51
|
-
const id = await this.getChainId();
|
|
52
|
-
if (this.options.shimDisconnect)
|
|
53
|
-
this.storage?.setItem(this.shimDisconnectKey, true);
|
|
54
|
-
return {
|
|
55
|
-
account,
|
|
56
|
-
chain: { id, unsupported: this.isChainUnsupported(id) }
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async disconnect() {
|
|
60
|
-
const provider = await this.getProvider();
|
|
61
|
-
if (!provider?.removeListener)
|
|
62
|
-
return;
|
|
63
|
-
provider.removeListener("accountsChanged", this.onAccountsChanged);
|
|
64
|
-
provider.removeListener("chainChanged", this.onChainChanged);
|
|
65
|
-
provider.removeListener("disconnect", this.onDisconnect);
|
|
66
|
-
if (this.options.shimDisconnect)
|
|
67
|
-
this.storage?.removeItem(this.shimDisconnectKey);
|
|
68
|
-
}
|
|
69
|
-
async getAccount() {
|
|
70
|
-
const provider = await this.getProvider();
|
|
71
|
-
if (!provider)
|
|
72
|
-
throw new ConnectorNotFoundError();
|
|
73
|
-
const accounts = await provider.request({
|
|
74
|
-
method: "eth_accounts"
|
|
75
|
-
});
|
|
76
|
-
return getAddress(accounts[0]);
|
|
77
|
-
}
|
|
78
|
-
async getChainId() {
|
|
79
|
-
const provider = await this.getProvider();
|
|
80
|
-
if (!provider)
|
|
81
|
-
throw new ConnectorNotFoundError();
|
|
82
|
-
return normalizeChainId(provider.chainId);
|
|
83
|
-
}
|
|
84
|
-
async getProvider() {
|
|
85
|
-
if (!__privateGet(this, _provider)) {
|
|
86
|
-
const safe = await __privateGet(this, _sdk).safe.getInfo();
|
|
87
|
-
if (!safe)
|
|
88
|
-
throw new Error("Could not load Safe information");
|
|
89
|
-
__privateSet(this, _provider, new SafeAppProvider(safe, __privateGet(this, _sdk)));
|
|
90
|
-
}
|
|
91
|
-
return __privateGet(this, _provider);
|
|
92
|
-
}
|
|
93
|
-
async getWalletClient({
|
|
94
|
-
chainId
|
|
95
|
-
} = {}) {
|
|
96
|
-
const provider = await this.getProvider();
|
|
97
|
-
const account = await this.getAccount();
|
|
98
|
-
const chain = this.chains.find((x) => x.id === chainId);
|
|
99
|
-
if (!provider)
|
|
100
|
-
throw new Error("provider is required.");
|
|
101
|
-
return createWalletClient({
|
|
102
|
-
account,
|
|
103
|
-
chain,
|
|
104
|
-
transport: custom(provider)
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
async isAuthorized() {
|
|
108
|
-
try {
|
|
109
|
-
if (this.options.shimDisconnect && !this.storage?.getItem(this.shimDisconnectKey))
|
|
110
|
-
return false;
|
|
111
|
-
const account = await this.getAccount();
|
|
112
|
-
return !!account;
|
|
113
|
-
} catch {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
onAccountsChanged(_accounts) {
|
|
118
|
-
}
|
|
119
|
-
onChainChanged(_chainId) {
|
|
120
|
-
}
|
|
121
|
-
onDisconnect() {
|
|
122
|
-
this.emit("disconnect");
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
_provider = new WeakMap();
|
|
126
|
-
_sdk = new WeakMap();
|
|
127
|
-
export {
|
|
128
|
-
SafeConnector
|
|
129
|
-
};
|