@wagmi/connectors 6.1.3 → 6.2.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.
@@ -1,2 +1,2 @@
1
- export const version = '6.1.3';
1
+ export const version = '6.2.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1,5 +1,40 @@
1
1
  import type { createBaseAccountSDK, ProviderInterface } from '@base-org/account';
2
2
  import type { Mutable, Omit } from '@wagmi/core/internal';
3
+ import { type Address, type Hex } from 'viem';
3
4
  export type BaseAccountParameters = Mutable<Omit<Parameters<typeof createBaseAccountSDK>[0], 'appChainIds'>>;
4
- export declare function baseAccount(parameters?: BaseAccountParameters): import("@wagmi/core").CreateConnectorFn<ProviderInterface, Record<string, unknown>, Record<string, unknown>>;
5
+ export declare function baseAccount(parameters?: BaseAccountParameters): import("@wagmi/core").CreateConnectorFn<ProviderInterface, {
6
+ connect<withCapabilities extends boolean = false>(parameters?: {
7
+ chainId?: number | undefined;
8
+ capabilities?: {
9
+ signInWithEthereum?: {
10
+ chainId?: string | undefined;
11
+ domain?: string | undefined;
12
+ expirationTime?: string | undefined;
13
+ issuedAt?: string | undefined;
14
+ nonce: string;
15
+ notBefore?: string | undefined;
16
+ requestId?: string | undefined;
17
+ resources?: string[] | undefined;
18
+ scheme?: string | undefined;
19
+ statement?: string | undefined;
20
+ uri?: string | undefined;
21
+ version?: string | undefined;
22
+ };
23
+ [capability: string]: any;
24
+ } | undefined;
25
+ withCapabilities?: withCapabilities | boolean | undefined;
26
+ }): Promise<{
27
+ accounts: withCapabilities extends true ? readonly {
28
+ address: Address;
29
+ capabilities: {
30
+ [capability: string]: any;
31
+ signInWithEthereum?: {
32
+ message: string;
33
+ signature: Hex;
34
+ } | undefined;
35
+ };
36
+ }[] : readonly Address[];
37
+ chainId: number;
38
+ }>;
39
+ }, Record<string, unknown>>;
5
40
  //# sourceMappingURL=baseAccount.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"baseAccount.d.ts","sourceRoot":"","sources":["../../src/baseAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAMhF,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAWzD,MAAM,MAAM,qBAAqB,GAAG,OAAO,CACzC,IAAI,CACF,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,EAC1C,aAAa,CACd,CACF,CAAA;AAED,wBAAgB,WAAW,CAAC,UAAU,GAAE,qBAA0B,gHAmNjE"}
1
+ {"version":3,"file":"baseAccount.d.ts","sourceRoot":"","sources":["../../src/baseAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAMhF,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAEL,KAAK,OAAO,EAEZ,KAAK,GAAG,EAKT,MAAM,MAAM,CAAA;AAEb,MAAM,MAAM,qBAAqB,GAAG,OAAO,CACzC,IAAI,CACF,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,EAC1C,aAAa,CACd,CACF,CAAA;AAED,wBAAgB,WAAW,CAAC,UAAU,GAAE,qBAA0B;YAGtD,gBAAgB,SAAS,OAAO,uBAAuB;QAC7D,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC5B,YAAY,CAAC,EACT;YACE,kBAAkB,CAAC,EAAE;gBACnB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBACnC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC7B,KAAK,EAAE,MAAM,CAAA;gBACb,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC9B,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;gBAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBAC9B,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;gBACxB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;aAC7B,CAAA;YACD,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;SAC1B,GACD,SAAS,CAAA;QACb,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,OAAO,GAAG,SAAS,CAAA;KAC1D,GAAG,OAAO,CAAC;QACV,QAAQ,EAAE,gBAAgB,SAAS,IAAI,GACnC,SAAS;YACP,OAAO,EAAE,OAAO,CAAA;YAChB,YAAY;;qCAOC;oBAAE,OAAO,EAAE,MAAM,CAAC;oBAAC,SAAS,EAAE,GAAG,CAAA;iBAAE,GAAG,SAAS;cAPb;SAChD,EAAE,GACH,SAAS,OAAO,EAAE,CAAA;QACtB,OAAO,EAAE,MAAM,CAAA;KAChB,CAAC;4BAiPL"}
@@ -1,2 +1,2 @@
1
- export declare const version = "6.1.3";
1
+ export declare const version = "6.2.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wagmi/connectors",
3
3
  "description": "Collection of connectors for Wagmi",
4
- "version": "6.1.3",
4
+ "version": "6.2.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@base-org/account": "2.4.0",
42
42
  "@coinbase/wallet-sdk": "4.3.6",
43
- "@gemini-wallet/core": "0.3.1",
43
+ "@gemini-wallet/core": "0.3.2",
44
44
  "@metamask/sdk": "0.33.1",
45
45
  "@safe-global/safe-apps-provider": "0.18.6",
46
46
  "@safe-global/safe-apps-sdk": "9.1.0",
@@ -7,6 +7,7 @@ import {
7
7
  import type { Mutable, Omit } from '@wagmi/core/internal'
8
8
  import {
9
9
  type AddEthereumChainParameter,
10
+ type Address,
10
11
  getAddress,
11
12
  type Hex,
12
13
  numberToHex,
@@ -24,6 +25,43 @@ export type BaseAccountParameters = Mutable<
24
25
 
25
26
  export function baseAccount(parameters: BaseAccountParameters = {}) {
26
27
  type Provider = ProviderInterface
28
+ type Properties = {
29
+ connect<withCapabilities extends boolean = false>(parameters?: {
30
+ chainId?: number | undefined
31
+ capabilities?:
32
+ | {
33
+ signInWithEthereum?: {
34
+ chainId?: string | undefined
35
+ domain?: string | undefined
36
+ expirationTime?: string | undefined
37
+ issuedAt?: string | undefined
38
+ nonce: string
39
+ notBefore?: string | undefined
40
+ requestId?: string | undefined
41
+ resources?: string[] | undefined
42
+ scheme?: string | undefined
43
+ statement?: string | undefined
44
+ uri?: string | undefined
45
+ version?: string | undefined
46
+ }
47
+ [capability: string]: any
48
+ }
49
+ | undefined
50
+ withCapabilities?: withCapabilities | boolean | undefined
51
+ }): Promise<{
52
+ accounts: withCapabilities extends true
53
+ ? readonly {
54
+ address: Address
55
+ capabilities: WalletConnectResponseCapabilities
56
+ }[]
57
+ : readonly Address[]
58
+ chainId: number
59
+ }>
60
+ }
61
+ type WalletConnectResponseCapabilities = {
62
+ signInWithEthereum?: { message: string; signature: Hex } | undefined
63
+ [capability: string]: any
64
+ }
27
65
 
28
66
  let walletProvider: Provider | undefined
29
67
 
@@ -31,20 +69,47 @@ export function baseAccount(parameters: BaseAccountParameters = {}) {
31
69
  let chainChanged: Connector['onChainChanged'] | undefined
32
70
  let disconnect: Connector['onDisconnect'] | undefined
33
71
 
34
- return createConnector<Provider>((config) => ({
72
+ return createConnector<Provider, Properties>((config) => ({
35
73
  id: 'baseAccount',
36
74
  name: 'Base Account',
37
75
  rdns: 'app.base.account',
38
76
  type: 'baseAccount',
39
- async connect({ chainId, withCapabilities } = {}) {
77
+ async connect({ chainId, withCapabilities, ...rest } = {}) {
40
78
  try {
41
79
  const provider = await this.getProvider()
42
- const accounts = (
43
- (await provider.request({
44
- method: 'eth_requestAccounts',
45
- params: [],
46
- })) as string[]
47
- ).map((x) => getAddress(x))
80
+
81
+ const targetChainId = chainId ?? config.chains[0]?.id
82
+ if (!targetChainId) throw new ChainNotConfiguredError()
83
+
84
+ const response = (await provider.request({
85
+ method: 'wallet_connect',
86
+ params: [
87
+ {
88
+ capabilities:
89
+ 'capabilities' in rest && rest.capabilities
90
+ ? rest.capabilities
91
+ : {},
92
+ chainIds: [
93
+ numberToHex(targetChainId),
94
+ ...config.chains
95
+ .filter((x) => x.id !== targetChainId)
96
+ .map((x) => numberToHex(x.id)),
97
+ ],
98
+ },
99
+ ],
100
+ })) as {
101
+ accounts: {
102
+ address: Address
103
+ capabilities?: WalletConnectResponseCapabilities | undefined
104
+ }[]
105
+ chainIds: Hex[]
106
+ }
107
+
108
+ const accounts = response.accounts.map((account) => ({
109
+ address: getAddress(account.address),
110
+ capabilities: account.capabilities ?? {},
111
+ }))
112
+ let currentChainId = Number(response.chainIds[0])
48
113
 
49
114
  if (!accountsChanged) {
50
115
  accountsChanged = this.onAccountsChanged.bind(this)
@@ -60,7 +125,6 @@ export function baseAccount(parameters: BaseAccountParameters = {}) {
60
125
  }
61
126
 
62
127
  // Switch to chain if provided
63
- let currentChainId = await this.getChainId()
64
128
  if (chainId && currentChainId !== chainId) {
65
129
  const chain = await this.switchChain!({ chainId }).catch((error) => {
66
130
  if (error.code === UserRejectedRequestError.code) throw error
@@ -72,8 +136,8 @@ export function baseAccount(parameters: BaseAccountParameters = {}) {
72
136
  return {
73
137
  // TODO(v3): Make `withCapabilities: true` default behavior
74
138
  accounts: (withCapabilities
75
- ? accounts.map((address) => ({ address, capabilities: {} }))
76
- : accounts) as never,
139
+ ? accounts
140
+ : accounts.map((account) => account.address)) as never,
77
141
  chainId: currentChainId,
78
142
  }
79
143
  } catch (error) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '6.1.3'
1
+ export const version = '6.2.0'