@etherplay/connect 0.0.34 → 0.0.36
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/dist/index.d.ts +102 -37
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +119 -70
- package/dist/index.js.map +1 -1
- package/package.json +32 -5
- package/src/index.ts +358 -157
- package/dist/provider.d.ts +0 -14
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -77
- package/dist/provider.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,13 +26,17 @@ export type BasicChainInfo = {
|
|
|
26
26
|
iconUrls?: readonly string[];
|
|
27
27
|
chainType?: string;
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
type ChainInfoWithRPCUrl = BasicChainInfo & {
|
|
30
30
|
readonly rpcUrls: {
|
|
31
31
|
readonly default: {
|
|
32
32
|
http: readonly string[];
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
+
type ChainInfoWithProvider<WalletProviderType> = BasicChainInfo & {
|
|
37
|
+
provider: WalletProviderType;
|
|
38
|
+
};
|
|
39
|
+
export type ChainInfo<WalletProviderType> = ChainInfoWithRPCUrl | ChainInfoWithProvider<WalletProviderType>;
|
|
36
40
|
export type PopupSettings = {
|
|
37
41
|
walletHost: string;
|
|
38
42
|
mechanism: AlchemyMechanism;
|
|
@@ -50,6 +54,7 @@ export type WalletMechanism<WalletName extends string | undefined, Address exten
|
|
|
50
54
|
});
|
|
51
55
|
export type Mechanism = AlchemyMechanism | WalletMechanism<string | undefined, `0x${string}` | undefined>;
|
|
52
56
|
export type FullfilledMechanism = AlchemyMechanism | WalletMechanism<string, `0x${string}`>;
|
|
57
|
+
export type TargetStep = 'WalletConnected' | 'SignedIn';
|
|
53
58
|
export type WalletState<WalletProviderType> = {
|
|
54
59
|
provider: WalletProvider<WalletProviderType>;
|
|
55
60
|
accounts: `0x${string}`[];
|
|
@@ -66,11 +71,16 @@ export type WalletState<WalletProviderType> = {
|
|
|
66
71
|
status: 'disconnected';
|
|
67
72
|
connecting: boolean;
|
|
68
73
|
});
|
|
69
|
-
type
|
|
74
|
+
type WaitingForSignature<WalletProviderType> = {
|
|
70
75
|
step: 'WaitingForSignature';
|
|
71
76
|
mechanism: WalletMechanism<string, `0x${string}`>;
|
|
72
77
|
wallet: WalletState<WalletProviderType>;
|
|
73
78
|
};
|
|
79
|
+
type WalletConnected<WalletProviderType> = {
|
|
80
|
+
step: 'WalletConnected';
|
|
81
|
+
mechanism: WalletMechanism<string, `0x${string}`>;
|
|
82
|
+
wallet: WalletState<WalletProviderType>;
|
|
83
|
+
};
|
|
74
84
|
type SignedIn<WalletProviderType> = {
|
|
75
85
|
step: 'SignedIn';
|
|
76
86
|
mechanism: AlchemyMechanism;
|
|
@@ -112,18 +122,27 @@ export type Connection<WalletProviderType> = {
|
|
|
112
122
|
step: 'ChooseWalletAccount';
|
|
113
123
|
mechanism: WalletMechanism<string, undefined>;
|
|
114
124
|
wallet: WalletState<WalletProviderType>;
|
|
115
|
-
} |
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
} | WalletConnected<WalletProviderType> | WaitingForSignature<WalletProviderType> | SignedIn<WalletProviderType>);
|
|
126
|
+
export type SignedInWithWallet<WalletProviderType> = Extract<Connection<WalletProviderType>, {
|
|
127
|
+
step: 'SignedIn';
|
|
118
128
|
wallet: WalletState<WalletProviderType>;
|
|
119
|
-
}
|
|
120
|
-
export type
|
|
129
|
+
}>;
|
|
130
|
+
export type WalletConnectedState<WalletProviderType> = Extract<Connection<WalletProviderType>, {
|
|
131
|
+
step: 'WalletConnected';
|
|
132
|
+
}>;
|
|
133
|
+
export type ConnectedWithWallet<WalletProviderType> = WalletConnectedState<WalletProviderType> | SignedInWithWallet<WalletProviderType>;
|
|
134
|
+
export type SignedInState<WalletProviderType> = Extract<Connection<WalletProviderType>, {
|
|
135
|
+
step: 'SignedIn';
|
|
136
|
+
}>;
|
|
137
|
+
export declare function isTargetStepReached<WalletProviderType, Target extends TargetStep, WalletOnly extends boolean = false>(connection: Connection<WalletProviderType>, targetStep: Target, walletOnly?: WalletOnly): connection is Target extends 'WalletConnected' ? ConnectedWithWallet<WalletProviderType> : WalletOnly extends true ? SignedInWithWallet<WalletProviderType> : SignedInState<WalletProviderType>;
|
|
138
|
+
export type ConnectionOptions = {
|
|
139
|
+
requireUserConfirmationBeforeSignatureRequest?: boolean;
|
|
140
|
+
doNotStoreLocally?: boolean;
|
|
141
|
+
requestSignatureRightAway?: boolean;
|
|
142
|
+
};
|
|
143
|
+
export type ConnectionStore<WalletProviderType, Target extends TargetStep = 'SignedIn', WalletOnly extends boolean = false> = {
|
|
121
144
|
subscribe: (run: (value: Connection<WalletProviderType>) => void) => () => void;
|
|
122
|
-
connect: (mechanism?: Mechanism, options?:
|
|
123
|
-
requireUserConfirmationBeforeSignatureRequest?: boolean;
|
|
124
|
-
doNotStoreLocally?: boolean;
|
|
125
|
-
requestSignatureRightAway?: boolean;
|
|
126
|
-
}) => Promise<void>;
|
|
145
|
+
connect: (mechanism?: Target extends 'WalletConnected' ? WalletMechanism<string | undefined, `0x${string}` | undefined> : WalletOnly extends true ? WalletMechanism<string | undefined, `0x${string}` | undefined> : Mechanism, options?: ConnectionOptions) => Promise<void>;
|
|
127
146
|
cancel: () => void;
|
|
128
147
|
back: (step: 'MechanismToChoose' | 'Idle' | 'WalletToChoose') => void;
|
|
129
148
|
requestSignature: () => Promise<void>;
|
|
@@ -134,49 +153,95 @@ export type ConnectionStore<WalletProviderType> = {
|
|
|
134
153
|
getSignatureForPublicKeyPublication: () => Promise<`0x${string}`>;
|
|
135
154
|
switchWalletChain: (chainInfo?: BasicChainInfo) => Promise<void>;
|
|
136
155
|
unlock: () => Promise<void>;
|
|
137
|
-
ensureConnected: {
|
|
138
|
-
(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}): Promise<WalletConnected<WalletProviderType>>;
|
|
143
|
-
(step: 'SignedIn', mechanism?:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
(mechanism?: Mechanism, options?: {
|
|
149
|
-
requireUserConfirmationBeforeSignatureRequest?: boolean;
|
|
150
|
-
doNotStoreLocally?: boolean;
|
|
151
|
-
requestSignatureRightAway?: boolean;
|
|
152
|
-
}): Promise<SignedIn<WalletProviderType>>;
|
|
156
|
+
ensureConnected: Target extends 'WalletConnected' ? {
|
|
157
|
+
(options?: ConnectionOptions): Promise<WalletConnected<WalletProviderType>>;
|
|
158
|
+
(step: 'WalletConnected', mechanism?: WalletMechanism<string | undefined, `0x${string}` | undefined>, options?: ConnectionOptions): Promise<WalletConnected<WalletProviderType>>;
|
|
159
|
+
} : WalletOnly extends true ? {
|
|
160
|
+
(options?: ConnectionOptions): Promise<SignedInWithWallet<WalletProviderType>>;
|
|
161
|
+
(step: 'WalletConnected', mechanism?: WalletMechanism<string | undefined, `0x${string}` | undefined>, options?: ConnectionOptions): Promise<WalletConnected<WalletProviderType>>;
|
|
162
|
+
(step: 'SignedIn', mechanism?: WalletMechanism<string | undefined, `0x${string}` | undefined>, options?: ConnectionOptions): Promise<SignedInWithWallet<WalletProviderType>>;
|
|
163
|
+
} : {
|
|
164
|
+
(options?: ConnectionOptions): Promise<SignedIn<WalletProviderType>>;
|
|
165
|
+
(step: 'WalletConnected', mechanism?: WalletMechanism<string | undefined, `0x${string}` | undefined>, options?: ConnectionOptions): Promise<WalletConnected<WalletProviderType>>;
|
|
166
|
+
(step: 'SignedIn', mechanism?: Mechanism, options?: ConnectionOptions): Promise<SignedIn<WalletProviderType>>;
|
|
153
167
|
};
|
|
168
|
+
isTargetStepReached: (connection: Connection<WalletProviderType>) => connection is Target extends 'WalletConnected' ? ConnectedWithWallet<WalletProviderType> : WalletOnly extends true ? SignedInWithWallet<WalletProviderType> : SignedInState<WalletProviderType>;
|
|
169
|
+
targetStep: Target;
|
|
170
|
+
walletOnly: WalletOnly;
|
|
154
171
|
provider: WalletProviderType;
|
|
155
172
|
chainId: string;
|
|
156
|
-
chainInfo: ChainInfo
|
|
173
|
+
chainInfo: ChainInfo<WalletProviderType>;
|
|
157
174
|
};
|
|
158
175
|
export declare function createConnection<WalletProviderType>(settings: {
|
|
159
|
-
|
|
160
|
-
walletHost
|
|
176
|
+
targetStep: 'WalletConnected';
|
|
177
|
+
walletHost?: string;
|
|
178
|
+
chainInfo: ChainInfo<WalletProviderType>;
|
|
179
|
+
walletConnector: WalletConnector<WalletProviderType>;
|
|
180
|
+
autoConnect?: boolean;
|
|
181
|
+
alwaysUseCurrentAccount?: boolean;
|
|
182
|
+
prioritizeWalletProvider?: boolean;
|
|
183
|
+
requestsPerSecond?: number;
|
|
184
|
+
}): ConnectionStore<WalletProviderType, 'WalletConnected'>;
|
|
185
|
+
export declare function createConnection(settings: {
|
|
186
|
+
targetStep: 'WalletConnected';
|
|
187
|
+
walletHost?: string;
|
|
188
|
+
chainInfo: ChainInfo<UnderlyingEthereumProvider>;
|
|
189
|
+
walletConnector?: undefined;
|
|
161
190
|
autoConnect?: boolean;
|
|
162
|
-
|
|
191
|
+
alwaysUseCurrentAccount?: boolean;
|
|
192
|
+
prioritizeWalletProvider?: boolean;
|
|
193
|
+
requestsPerSecond?: number;
|
|
194
|
+
}): ConnectionStore<UnderlyingEthereumProvider, 'WalletConnected', true>;
|
|
195
|
+
export declare function createConnection<WalletProviderType>(settings: {
|
|
196
|
+
targetStep?: 'SignedIn';
|
|
197
|
+
walletOnly: true;
|
|
198
|
+
walletHost?: string;
|
|
199
|
+
chainInfo: ChainInfo<WalletProviderType>;
|
|
163
200
|
walletConnector: WalletConnector<WalletProviderType>;
|
|
201
|
+
signingOrigin?: string;
|
|
202
|
+
autoConnect?: boolean;
|
|
164
203
|
requestSignatureAutomaticallyIfPossible?: boolean;
|
|
165
204
|
alwaysUseCurrentAccount?: boolean;
|
|
166
|
-
chainInfo: ChainInfo;
|
|
167
205
|
prioritizeWalletProvider?: boolean;
|
|
168
206
|
requestsPerSecond?: number;
|
|
169
|
-
}): ConnectionStore<WalletProviderType>;
|
|
207
|
+
}): ConnectionStore<WalletProviderType, 'SignedIn', true>;
|
|
170
208
|
export declare function createConnection(settings: {
|
|
209
|
+
targetStep?: 'SignedIn';
|
|
210
|
+
walletOnly: true;
|
|
211
|
+
walletHost?: string;
|
|
212
|
+
chainInfo: ChainInfo<UnderlyingEthereumProvider>;
|
|
213
|
+
walletConnector?: undefined;
|
|
171
214
|
signingOrigin?: string;
|
|
215
|
+
autoConnect?: boolean;
|
|
216
|
+
requestSignatureAutomaticallyIfPossible?: boolean;
|
|
217
|
+
alwaysUseCurrentAccount?: boolean;
|
|
218
|
+
prioritizeWalletProvider?: boolean;
|
|
219
|
+
requestsPerSecond?: number;
|
|
220
|
+
}): ConnectionStore<UnderlyingEthereumProvider, 'SignedIn', true>;
|
|
221
|
+
export declare function createConnection<WalletProviderType>(settings: {
|
|
222
|
+
targetStep?: 'SignedIn';
|
|
223
|
+
walletOnly?: false;
|
|
172
224
|
walletHost: string;
|
|
225
|
+
chainInfo: ChainInfo<WalletProviderType>;
|
|
226
|
+
walletConnector: WalletConnector<WalletProviderType>;
|
|
227
|
+
signingOrigin?: string;
|
|
173
228
|
autoConnect?: boolean;
|
|
174
|
-
|
|
229
|
+
requestSignatureAutomaticallyIfPossible?: boolean;
|
|
230
|
+
alwaysUseCurrentAccount?: boolean;
|
|
231
|
+
prioritizeWalletProvider?: boolean;
|
|
232
|
+
requestsPerSecond?: number;
|
|
233
|
+
}): ConnectionStore<WalletProviderType, 'SignedIn', false>;
|
|
234
|
+
export declare function createConnection(settings: {
|
|
235
|
+
targetStep?: 'SignedIn';
|
|
236
|
+
walletOnly?: false;
|
|
237
|
+
walletHost: string;
|
|
238
|
+
chainInfo: ChainInfo<UnderlyingEthereumProvider>;
|
|
175
239
|
walletConnector?: undefined;
|
|
240
|
+
signingOrigin?: string;
|
|
241
|
+
autoConnect?: boolean;
|
|
176
242
|
requestSignatureAutomaticallyIfPossible?: boolean;
|
|
177
243
|
alwaysUseCurrentAccount?: boolean;
|
|
178
|
-
chainInfo: ChainInfo;
|
|
179
244
|
prioritizeWalletProvider?: boolean;
|
|
180
245
|
requestsPerSecond?: number;
|
|
181
|
-
}): ConnectionStore<UnderlyingEthereumProvider>;
|
|
246
|
+
}): ConnectionStore<UnderlyingEthereumProvider, 'SignedIn', false>;
|
|
182
247
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAA0B,KAAK,0BAA0B,EAAC,MAAM,sCAAsC,CAAC;AAG9G,OAAO,EACN,wBAAwB,EAExB,gBAAgB,EAChB,iCAAiC,EACjC,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAC,wBAAwB,EAAE,iCAAiC,EAAE,gBAAgB,EAAC,CAAC;AACvF,YAAY,EAAC,aAAa,EAAC,CAAC;AAE5B,YAAY,EAAC,0BAA0B,EAAC,CAAC;AAEzC,MAAM,MAAM,cAAc,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,OAAO,CAAC,EAAE;QAClB,QAAQ,CAAC,OAAO,EAAE;YACjB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;SACxB,CAAC;KACF,CAAC;IACF,QAAQ,CAAC,cAAc,CAAC,EAAE;QACzB,QAAQ,CAAC,OAAO,EAAE;YACjB,GAAG,EAAE,MAAM,CAAC;SACZ,CAAC;KACF,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,cAAc,CAAC,EAAE;QACzB,QAAQ,EA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AAC;IACzC,eAAe,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uCAAuC,CAAC,EAAE,OAAO,CAAC;IAClD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,eAAe,CAAC,kBAAkB,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AAG3D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE;IAC1C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC,0BAA0B,CAAC,CAAC;IACjD,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uCAAuC,CAAC,EAAE,OAAO,CAAC;IAClD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,eAAe,CAAC,0BAA0B,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,24 @@ import { createPopupLauncher } from './popup.js';
|
|
|
4
4
|
import { fromEntropyKeyToMnemonic, fromSignatureToKey, originKeyMessage, originPublicKeyPublicationMessage, } from '@etherplay/alchemy';
|
|
5
5
|
import { withTimeout } from './utils.js';
|
|
6
6
|
export { fromEntropyKeyToMnemonic, originPublicKeyPublicationMessage, originKeyMessage };
|
|
7
|
+
// Type guard - narrows Connection based on targetStep and walletOnly
|
|
8
|
+
// For 'WalletConnected' target: narrows to ConnectedWithWallet (WalletConnected | SignedIn-with-wallet)
|
|
9
|
+
// For 'SignedIn' target with walletOnly: narrows to SignedInWithWallet
|
|
10
|
+
// For 'SignedIn' target (default): narrows to SignedIn
|
|
11
|
+
export function isTargetStepReached(connection, targetStep, walletOnly) {
|
|
12
|
+
if (targetStep === 'WalletConnected') {
|
|
13
|
+
// For WalletConnected target, accept WalletConnected OR SignedIn-with-wallet
|
|
14
|
+
return connection.step === 'WalletConnected' || (connection.step === 'SignedIn' && connection.wallet !== undefined);
|
|
15
|
+
}
|
|
16
|
+
// For SignedIn target (regardless of walletOnly), only accept SignedIn
|
|
17
|
+
// walletOnly affects the return type narrowing, not the step check
|
|
18
|
+
if (walletOnly) {
|
|
19
|
+
// For SignedIn + walletOnly, only accept SignedIn-with-wallet
|
|
20
|
+
return connection.step === 'SignedIn' && connection.wallet !== undefined;
|
|
21
|
+
}
|
|
22
|
+
// For SignedIn target, accept any SignedIn variant
|
|
23
|
+
return connection.step === 'SignedIn';
|
|
24
|
+
}
|
|
7
25
|
function viemChainInfoToSwitchChainInfo(chainInfo) {
|
|
8
26
|
return {
|
|
9
27
|
chainId: `0x${Number(chainInfo.id).toString(16)}`,
|
|
@@ -15,28 +33,28 @@ function viemChainInfoToSwitchChainInfo(chainInfo) {
|
|
|
15
33
|
}
|
|
16
34
|
const storageKeyAccount = '__origin_account';
|
|
17
35
|
const storageKeyLastWallet = '__last_wallet';
|
|
36
|
+
// Implementation signature
|
|
18
37
|
export function createConnection(settings) {
|
|
19
38
|
function originToSignWith() {
|
|
20
39
|
return settings.signingOrigin || origin;
|
|
21
40
|
}
|
|
22
|
-
const endpoint = settings.chainInfo.rpcUrls.default.http[0];
|
|
23
41
|
const walletConnector = settings.walletConnector || new EthereumWalletConnector();
|
|
24
42
|
const alwaysOnChainId = '' + settings.chainInfo.id;
|
|
25
43
|
const alwaysOnProviderWrapper = walletConnector.createAlwaysOnProvider({
|
|
26
|
-
endpoint,
|
|
44
|
+
endpoint: 'provider' in settings.chainInfo ? settings.chainInfo.provider : settings.chainInfo.rpcUrls.default.http[0],
|
|
27
45
|
chainId: '' + settings.chainInfo.id,
|
|
28
46
|
prioritizeWalletProvider: settings.prioritizeWalletProvider,
|
|
29
47
|
requestsPerSecond: settings.requestsPerSecond,
|
|
30
48
|
});
|
|
49
|
+
// Determine target step (defaults to 'SignedIn')
|
|
50
|
+
const targetStep = settings.targetStep || 'SignedIn';
|
|
31
51
|
let autoConnect = true;
|
|
32
52
|
if (typeof settings.autoConnect !== 'undefined') {
|
|
33
53
|
autoConnect = settings.autoConnect;
|
|
34
54
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
const requestSignatureAutomaticallyIfPossible = settings.requestSignatureAutomaticallyIfPossible || false;
|
|
55
|
+
// For SignedIn target, we can auto-request signature if configured
|
|
56
|
+
// For WalletConnected target, this is always false (we never auto-request signature)
|
|
57
|
+
const requestSignatureAutomaticallyIfPossible = targetStep === 'SignedIn' ? settings.requestSignatureAutomaticallyIfPossible || false : false;
|
|
40
58
|
let $connection = { step: 'Idle', loading: true, wallet: undefined, wallets: [] };
|
|
41
59
|
const _store = writable($connection);
|
|
42
60
|
function set(connection) {
|
|
@@ -83,13 +101,18 @@ export function createConnection(settings) {
|
|
|
83
101
|
}, 100);
|
|
84
102
|
});
|
|
85
103
|
}
|
|
104
|
+
// Auto-connect logic based on targetStep
|
|
105
|
+
// When targetStep: 'WalletConnected' - only check lastWallet
|
|
106
|
+
// When targetStep: 'SignedIn' - check originAccount first, then fallback to lastWallet
|
|
107
|
+
let autoConnectHandled = false;
|
|
86
108
|
if (autoConnect) {
|
|
87
109
|
if (typeof window !== 'undefined') {
|
|
88
|
-
// set({step: 'Idle', loading: true, wallets: $connection.wallets});
|
|
89
110
|
try {
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
111
|
+
// For SignedIn target, check for existing account first
|
|
112
|
+
if (targetStep === 'SignedIn') {
|
|
113
|
+
const existingAccount = getOriginAccount();
|
|
114
|
+
if (existingAccount && existingAccount.signer) {
|
|
115
|
+
autoConnectHandled = true;
|
|
93
116
|
const mechanismUsed = existingAccount.mechanismUsed;
|
|
94
117
|
if (mechanismUsed.type == 'wallet') {
|
|
95
118
|
const walletMechanism = mechanismUsed;
|
|
@@ -99,15 +122,11 @@ export function createConnection(settings) {
|
|
|
99
122
|
const chainIdAsHex = await withTimeout(walletProvider.getChainId());
|
|
100
123
|
const chainId = Number(chainIdAsHex).toString();
|
|
101
124
|
_wallet = { provider: walletProvider, chainId };
|
|
102
|
-
// TODO
|
|
103
125
|
alwaysOnProviderWrapper.setWalletProvider(walletProvider.underlyingProvider);
|
|
104
126
|
watchForChainIdChange(_wallet.provider);
|
|
105
127
|
let accounts = [];
|
|
106
|
-
// try {
|
|
107
128
|
accounts = await withTimeout(walletProvider.getAccounts());
|
|
108
129
|
accounts = accounts.map((v) => v.toLowerCase());
|
|
109
|
-
// } catch {}
|
|
110
|
-
// // TODO try catch ? and use logic of onAccountChanged
|
|
111
130
|
set({
|
|
112
131
|
step: 'SignedIn',
|
|
113
132
|
account: existingAccount,
|
|
@@ -124,7 +143,6 @@ export function createConnection(settings) {
|
|
|
124
143
|
},
|
|
125
144
|
});
|
|
126
145
|
alwaysOnProviderWrapper.setWalletStatus('connected');
|
|
127
|
-
// TODO use the same logic before hand
|
|
128
146
|
onAccountChanged(accounts);
|
|
129
147
|
watchForAccountChange(walletProvider);
|
|
130
148
|
})
|
|
@@ -142,55 +160,43 @@ export function createConnection(settings) {
|
|
|
142
160
|
});
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
|
-
else {
|
|
146
|
-
set({ step: 'Idle', loading: false, wallet: undefined, wallets: $connection.wallets });
|
|
147
|
-
}
|
|
148
163
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
chainId,
|
|
178
|
-
invalidChainId: alwaysOnChainId != chainId,
|
|
179
|
-
switchingChain: false,
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
alwaysOnProviderWrapper.setWalletStatus('connected');
|
|
183
|
-
// TODO use the same logic before hand
|
|
184
|
-
onAccountChanged(accounts);
|
|
185
|
-
watchForAccountChange(walletProvider);
|
|
186
|
-
})
|
|
187
|
-
.catch((err) => {
|
|
188
|
-
set({ step: 'Idle', loading: false, wallet: undefined, wallets: $connection.wallets });
|
|
164
|
+
// For both targets, fallback to lastWallet if no account found (or WalletConnected target)
|
|
165
|
+
if (!autoConnectHandled) {
|
|
166
|
+
const lastWallet = getLastWallet();
|
|
167
|
+
if (lastWallet) {
|
|
168
|
+
waitForWallet(lastWallet.name)
|
|
169
|
+
.then(async (walletDetails) => {
|
|
170
|
+
const walletProvider = walletDetails.walletProvider;
|
|
171
|
+
const chainIdAsHex = await withTimeout(walletProvider.getChainId());
|
|
172
|
+
const chainId = Number(chainIdAsHex).toString();
|
|
173
|
+
_wallet = { provider: walletProvider, chainId };
|
|
174
|
+
alwaysOnProviderWrapper.setWalletProvider(walletProvider.underlyingProvider);
|
|
175
|
+
watchForChainIdChange(_wallet.provider);
|
|
176
|
+
let accounts = [];
|
|
177
|
+
accounts = await withTimeout(walletProvider.getAccounts());
|
|
178
|
+
accounts = accounts.map((v) => v.toLowerCase());
|
|
179
|
+
set({
|
|
180
|
+
step: 'WalletConnected',
|
|
181
|
+
mechanism: lastWallet,
|
|
182
|
+
wallets: $connection.wallets,
|
|
183
|
+
wallet: {
|
|
184
|
+
provider: walletProvider,
|
|
185
|
+
accounts,
|
|
186
|
+
status: 'connected',
|
|
187
|
+
accountChanged: undefined,
|
|
188
|
+
chainId,
|
|
189
|
+
invalidChainId: alwaysOnChainId != chainId,
|
|
190
|
+
switchingChain: false,
|
|
191
|
+
},
|
|
189
192
|
});
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
alwaysOnProviderWrapper.setWalletStatus('connected');
|
|
194
|
+
onAccountChanged(accounts);
|
|
195
|
+
watchForAccountChange(walletProvider);
|
|
196
|
+
})
|
|
197
|
+
.catch((err) => {
|
|
192
198
|
set({ step: 'Idle', loading: false, wallet: undefined, wallets: $connection.wallets });
|
|
193
|
-
}
|
|
199
|
+
});
|
|
194
200
|
}
|
|
195
201
|
else {
|
|
196
202
|
set({ step: 'Idle', loading: false, wallet: undefined, wallets: $connection.wallets });
|
|
@@ -689,6 +695,10 @@ export function createConnection(settings) {
|
|
|
689
695
|
}
|
|
690
696
|
}
|
|
691
697
|
else {
|
|
698
|
+
// Popup-based auth requires walletHost
|
|
699
|
+
if (!settings.walletHost) {
|
|
700
|
+
throw new Error('walletHost is required for popup-based authentication (email, oauth, mnemonic)');
|
|
701
|
+
}
|
|
692
702
|
popup = connectViaPopup({
|
|
693
703
|
mechanism,
|
|
694
704
|
walletHost: settings.walletHost,
|
|
@@ -741,18 +751,37 @@ export function createConnection(settings) {
|
|
|
741
751
|
});
|
|
742
752
|
}
|
|
743
753
|
}
|
|
744
|
-
async function ensureConnected(
|
|
745
|
-
|
|
746
|
-
let
|
|
754
|
+
async function ensureConnected(stepOrMechanismOrOptions, mechanismOrOptions, options) {
|
|
755
|
+
// Determine if first arg is a step string, mechanism, or options
|
|
756
|
+
let step;
|
|
757
|
+
let mechanism;
|
|
758
|
+
let opts;
|
|
759
|
+
if (typeof stepOrMechanismOrOptions === 'string') {
|
|
760
|
+
// First arg is a step
|
|
761
|
+
step = stepOrMechanismOrOptions;
|
|
762
|
+
mechanism = mechanismOrOptions;
|
|
763
|
+
opts = options;
|
|
764
|
+
}
|
|
765
|
+
else if (stepOrMechanismOrOptions && 'type' in stepOrMechanismOrOptions) {
|
|
766
|
+
// First arg is a mechanism
|
|
767
|
+
step = targetStep; // Use configured target as default
|
|
768
|
+
mechanism = stepOrMechanismOrOptions;
|
|
769
|
+
opts = mechanismOrOptions;
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
// First arg is options or undefined
|
|
773
|
+
step = targetStep; // Use configured target as default
|
|
774
|
+
mechanism = undefined;
|
|
775
|
+
opts = stepOrMechanismOrOptions;
|
|
776
|
+
}
|
|
777
|
+
// For WalletConnected step, default to wallet mechanism
|
|
747
778
|
if (!mechanism && step === 'WalletConnected') {
|
|
748
779
|
mechanism = { type: 'wallet' };
|
|
749
780
|
}
|
|
750
|
-
options = typeof stepOrMechanism === 'string' ? options : mechanismOrOptions;
|
|
751
781
|
const promise = new Promise((resolve, reject) => {
|
|
752
782
|
let forceConnect = false;
|
|
753
783
|
if ($connection.step == 'WalletConnected' &&
|
|
754
784
|
($connection.wallet.status == 'locked' || $connection.wallet.status === 'disconnected')) {
|
|
755
|
-
// console.log(`locked / disconnected : we assume it needs reconnection`);
|
|
756
785
|
forceConnect = true;
|
|
757
786
|
mechanism = $connection.mechanism; // we reuse existing mechanism as we just want to reconnect
|
|
758
787
|
}
|
|
@@ -762,7 +791,7 @@ export function createConnection(settings) {
|
|
|
762
791
|
}
|
|
763
792
|
let idlePassed = $connection.step != 'Idle';
|
|
764
793
|
if (!idlePassed || forceConnect) {
|
|
765
|
-
connect(mechanism,
|
|
794
|
+
connect(mechanism, opts);
|
|
766
795
|
}
|
|
767
796
|
const unsubscribe = _store.subscribe((connection) => {
|
|
768
797
|
if (connection.step === 'Idle' && idlePassed) {
|
|
@@ -1064,7 +1093,23 @@ export function createConnection(settings) {
|
|
|
1064
1093
|
}
|
|
1065
1094
|
}
|
|
1066
1095
|
}
|
|
1067
|
-
|
|
1096
|
+
// Determine walletOnly (defaults to false, but true implies WalletConnected target behavior for mechanism)
|
|
1097
|
+
const walletOnly = settings.walletOnly || targetStep === 'WalletConnected';
|
|
1098
|
+
// Method on the store to check if target step is reached
|
|
1099
|
+
function storeIsTargetStepReached(connection) {
|
|
1100
|
+
if (targetStep === 'WalletConnected') {
|
|
1101
|
+
// For WalletConnected target, accept WalletConnected OR SignedIn-with-wallet
|
|
1102
|
+
return (connection.step === 'WalletConnected' || (connection.step === 'SignedIn' && connection.wallet !== undefined));
|
|
1103
|
+
}
|
|
1104
|
+
// For SignedIn target
|
|
1105
|
+
if (walletOnly) {
|
|
1106
|
+
// With walletOnly, only accept SignedIn-with-wallet
|
|
1107
|
+
return connection.step === 'SignedIn' && connection.wallet !== undefined;
|
|
1108
|
+
}
|
|
1109
|
+
// Accept any SignedIn variant
|
|
1110
|
+
return connection.step === 'SignedIn';
|
|
1111
|
+
}
|
|
1112
|
+
const store = {
|
|
1068
1113
|
subscribe: _store.subscribe,
|
|
1069
1114
|
connect,
|
|
1070
1115
|
cancel,
|
|
@@ -1075,10 +1120,14 @@ export function createConnection(settings) {
|
|
|
1075
1120
|
getSignatureForPublicKeyPublication,
|
|
1076
1121
|
switchWalletChain,
|
|
1077
1122
|
unlock,
|
|
1078
|
-
ensureConnected,
|
|
1123
|
+
ensureConnected: ensureConnected, // Cast to bypass complex conditional typing
|
|
1124
|
+
isTargetStepReached: storeIsTargetStepReached, // Cast for type guard
|
|
1125
|
+
targetStep,
|
|
1126
|
+
walletOnly,
|
|
1079
1127
|
provider: alwaysOnProviderWrapper.provider,
|
|
1080
1128
|
chainId: '' + settings.chainInfo.id,
|
|
1081
1129
|
chainInfo: settings.chainInfo,
|
|
1082
1130
|
};
|
|
1131
|
+
return store;
|
|
1083
1132
|
}
|
|
1084
1133
|
//# sourceMappingURL=index.js.map
|