@0xsequence/provider 0.39.0 → 0.39.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/dist/0xsequence-provider.cjs.dev.js +33 -16
- package/dist/0xsequence-provider.cjs.prod.js +33 -16
- package/dist/0xsequence-provider.esm.js +33 -16
- package/dist/declarations/src/transports/base-provider-transport.d.ts +4 -1
- package/dist/declarations/src/transports/base-wallet-transport.d.ts +1 -1
- package/dist/declarations/src/transports/extension-transport/base-injected-transport.d.ts +1 -2
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +2 -2
- package/dist/declarations/src/types.d.ts +2 -1
- package/dist/declarations/src/wallet.d.ts +1 -1
- package/package.json +8 -8
- package/src/transports/base-provider-transport.ts +8 -5
- package/src/transports/base-wallet-transport.ts +5 -4
- package/src/transports/extension-transport/base-injected-transport.ts +1 -1
- package/src/transports/wallet-request-handler.ts +4 -5
- package/src/types.ts +2 -1
- package/src/wallet.ts +13 -4
|
@@ -378,13 +378,18 @@ class BaseProviderTransport {
|
|
|
378
378
|
|
|
379
379
|
|
|
380
380
|
if (message.type === exports.EventType.ACCOUNTS_CHANGED) {
|
|
381
|
-
this.accountsChangedPayload =
|
|
381
|
+
this.accountsChangedPayload = {
|
|
382
|
+
accounts: []
|
|
383
|
+
};
|
|
382
384
|
|
|
383
385
|
if (message.data && message.data.length > 0) {
|
|
384
|
-
this.accountsChangedPayload =
|
|
385
|
-
|
|
386
|
+
this.accountsChangedPayload = {
|
|
387
|
+
accounts: [ethers.ethers.utils.getAddress(message.data[0])],
|
|
388
|
+
origin: message.origin
|
|
389
|
+
};
|
|
390
|
+
this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin);
|
|
386
391
|
} else {
|
|
387
|
-
this.events.emit('accountsChanged', []);
|
|
392
|
+
this.events.emit('accountsChanged', [], message.origin);
|
|
388
393
|
}
|
|
389
394
|
|
|
390
395
|
return;
|
|
@@ -1192,7 +1197,7 @@ class WalletRequestHandler {
|
|
|
1192
1197
|
};
|
|
1193
1198
|
}
|
|
1194
1199
|
|
|
1195
|
-
notifyConnect(connectDetails) {
|
|
1200
|
+
notifyConnect(connectDetails, origin) {
|
|
1196
1201
|
var _connectDetails$sessi;
|
|
1197
1202
|
|
|
1198
1203
|
this.events.emit('connect', connectDetails);
|
|
@@ -1200,13 +1205,12 @@ class WalletRequestHandler {
|
|
|
1200
1205
|
if ((_connectDetails$sessi = connectDetails.session) != null && _connectDetails$sessi.accountAddress) {
|
|
1201
1206
|
var _connectDetails$sessi2;
|
|
1202
1207
|
|
|
1203
|
-
this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress]);
|
|
1208
|
+
this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress], origin);
|
|
1204
1209
|
}
|
|
1205
1210
|
}
|
|
1206
1211
|
|
|
1207
|
-
notifyDisconnect() {
|
|
1208
|
-
this.events.emit('accountsChanged', []);
|
|
1209
|
-
this.events.emit('networks', []);
|
|
1212
|
+
notifyDisconnect(origin) {
|
|
1213
|
+
this.events.emit('accountsChanged', [], origin);
|
|
1210
1214
|
this.events.emit('disconnect');
|
|
1211
1215
|
}
|
|
1212
1216
|
|
|
@@ -2099,9 +2103,9 @@ class BaseWalletTransport {
|
|
|
2099
2103
|
|
|
2100
2104
|
this.notifyDisconnect(error);
|
|
2101
2105
|
});
|
|
2102
|
-
this.walletRequestHandler.on('accountsChanged', accounts => {
|
|
2106
|
+
this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
|
|
2103
2107
|
if (!this.registered) return;
|
|
2104
|
-
this.notifyAccountsChanged(accounts);
|
|
2108
|
+
this.notifyAccountsChanged(accounts, origin);
|
|
2105
2109
|
});
|
|
2106
2110
|
this.walletRequestHandler.on('networks', networks => {
|
|
2107
2111
|
if (!this.registered) return;
|
|
@@ -2186,11 +2190,12 @@ class BaseWalletTransport {
|
|
|
2186
2190
|
});
|
|
2187
2191
|
}
|
|
2188
2192
|
|
|
2189
|
-
notifyAccountsChanged(accounts) {
|
|
2193
|
+
notifyAccountsChanged(accounts, origin) {
|
|
2190
2194
|
this.sendMessage({
|
|
2191
2195
|
idx: -1,
|
|
2192
2196
|
type: exports.EventType.ACCOUNTS_CHANGED,
|
|
2193
|
-
data: accounts
|
|
2197
|
+
data: accounts,
|
|
2198
|
+
origin: origin
|
|
2194
2199
|
});
|
|
2195
2200
|
}
|
|
2196
2201
|
|
|
@@ -3323,9 +3328,21 @@ class Wallet {
|
|
|
3323
3328
|
} else {
|
|
3324
3329
|
this.useSession(session, true);
|
|
3325
3330
|
}
|
|
3326
|
-
}); // below will update the account upon wallet connect/disconnect
|
|
3331
|
+
}); // below will update the account upon wallet connect/disconnect - aka, login/logout.
|
|
3332
|
+
// if an origin is provided, this operation should be performed only on that origin
|
|
3333
|
+
// and shouldn't affect the session of the wallet.
|
|
3334
|
+
|
|
3335
|
+
this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
|
|
3336
|
+
if (origin) {
|
|
3337
|
+
if (accounts.length > 0) {
|
|
3338
|
+
this.useSession({
|
|
3339
|
+
accountAddress: accounts[0]
|
|
3340
|
+
}, true);
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3327
3345
|
|
|
3328
|
-
this.transport.messageProvider.on('accountsChanged', accounts => {
|
|
3329
3346
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
3330
3347
|
this.clearSession();
|
|
3331
3348
|
} else {
|
|
@@ -3359,7 +3376,7 @@ class Wallet {
|
|
|
3359
3376
|
_this.disconnect();
|
|
3360
3377
|
}
|
|
3361
3378
|
|
|
3362
|
-
if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3379
|
+
if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3363
3380
|
return {
|
|
3364
3381
|
connected: true,
|
|
3365
3382
|
session: _this.session,
|
|
@@ -378,13 +378,18 @@ class BaseProviderTransport {
|
|
|
378
378
|
|
|
379
379
|
|
|
380
380
|
if (message.type === exports.EventType.ACCOUNTS_CHANGED) {
|
|
381
|
-
this.accountsChangedPayload =
|
|
381
|
+
this.accountsChangedPayload = {
|
|
382
|
+
accounts: []
|
|
383
|
+
};
|
|
382
384
|
|
|
383
385
|
if (message.data && message.data.length > 0) {
|
|
384
|
-
this.accountsChangedPayload =
|
|
385
|
-
|
|
386
|
+
this.accountsChangedPayload = {
|
|
387
|
+
accounts: [ethers.ethers.utils.getAddress(message.data[0])],
|
|
388
|
+
origin: message.origin
|
|
389
|
+
};
|
|
390
|
+
this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin);
|
|
386
391
|
} else {
|
|
387
|
-
this.events.emit('accountsChanged', []);
|
|
392
|
+
this.events.emit('accountsChanged', [], message.origin);
|
|
388
393
|
}
|
|
389
394
|
|
|
390
395
|
return;
|
|
@@ -1192,7 +1197,7 @@ class WalletRequestHandler {
|
|
|
1192
1197
|
};
|
|
1193
1198
|
}
|
|
1194
1199
|
|
|
1195
|
-
notifyConnect(connectDetails) {
|
|
1200
|
+
notifyConnect(connectDetails, origin) {
|
|
1196
1201
|
var _connectDetails$sessi;
|
|
1197
1202
|
|
|
1198
1203
|
this.events.emit('connect', connectDetails);
|
|
@@ -1200,13 +1205,12 @@ class WalletRequestHandler {
|
|
|
1200
1205
|
if ((_connectDetails$sessi = connectDetails.session) != null && _connectDetails$sessi.accountAddress) {
|
|
1201
1206
|
var _connectDetails$sessi2;
|
|
1202
1207
|
|
|
1203
|
-
this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress]);
|
|
1208
|
+
this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress], origin);
|
|
1204
1209
|
}
|
|
1205
1210
|
}
|
|
1206
1211
|
|
|
1207
|
-
notifyDisconnect() {
|
|
1208
|
-
this.events.emit('accountsChanged', []);
|
|
1209
|
-
this.events.emit('networks', []);
|
|
1212
|
+
notifyDisconnect(origin) {
|
|
1213
|
+
this.events.emit('accountsChanged', [], origin);
|
|
1210
1214
|
this.events.emit('disconnect');
|
|
1211
1215
|
}
|
|
1212
1216
|
|
|
@@ -2099,9 +2103,9 @@ class BaseWalletTransport {
|
|
|
2099
2103
|
|
|
2100
2104
|
this.notifyDisconnect(error);
|
|
2101
2105
|
});
|
|
2102
|
-
this.walletRequestHandler.on('accountsChanged', accounts => {
|
|
2106
|
+
this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
|
|
2103
2107
|
if (!this.registered) return;
|
|
2104
|
-
this.notifyAccountsChanged(accounts);
|
|
2108
|
+
this.notifyAccountsChanged(accounts, origin);
|
|
2105
2109
|
});
|
|
2106
2110
|
this.walletRequestHandler.on('networks', networks => {
|
|
2107
2111
|
if (!this.registered) return;
|
|
@@ -2186,11 +2190,12 @@ class BaseWalletTransport {
|
|
|
2186
2190
|
});
|
|
2187
2191
|
}
|
|
2188
2192
|
|
|
2189
|
-
notifyAccountsChanged(accounts) {
|
|
2193
|
+
notifyAccountsChanged(accounts, origin) {
|
|
2190
2194
|
this.sendMessage({
|
|
2191
2195
|
idx: -1,
|
|
2192
2196
|
type: exports.EventType.ACCOUNTS_CHANGED,
|
|
2193
|
-
data: accounts
|
|
2197
|
+
data: accounts,
|
|
2198
|
+
origin: origin
|
|
2194
2199
|
});
|
|
2195
2200
|
}
|
|
2196
2201
|
|
|
@@ -3323,9 +3328,21 @@ class Wallet {
|
|
|
3323
3328
|
} else {
|
|
3324
3329
|
this.useSession(session, true);
|
|
3325
3330
|
}
|
|
3326
|
-
}); // below will update the account upon wallet connect/disconnect
|
|
3331
|
+
}); // below will update the account upon wallet connect/disconnect - aka, login/logout.
|
|
3332
|
+
// if an origin is provided, this operation should be performed only on that origin
|
|
3333
|
+
// and shouldn't affect the session of the wallet.
|
|
3334
|
+
|
|
3335
|
+
this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
|
|
3336
|
+
if (origin) {
|
|
3337
|
+
if (accounts.length > 0) {
|
|
3338
|
+
this.useSession({
|
|
3339
|
+
accountAddress: accounts[0]
|
|
3340
|
+
}, true);
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3327
3345
|
|
|
3328
|
-
this.transport.messageProvider.on('accountsChanged', accounts => {
|
|
3329
3346
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
3330
3347
|
this.clearSession();
|
|
3331
3348
|
} else {
|
|
@@ -3359,7 +3376,7 @@ class Wallet {
|
|
|
3359
3376
|
_this.disconnect();
|
|
3360
3377
|
}
|
|
3361
3378
|
|
|
3362
|
-
if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3379
|
+
if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3363
3380
|
return {
|
|
3364
3381
|
connected: true,
|
|
3365
3382
|
session: _this.session,
|
|
@@ -374,13 +374,18 @@ class BaseProviderTransport {
|
|
|
374
374
|
|
|
375
375
|
|
|
376
376
|
if (message.type === EventType.ACCOUNTS_CHANGED) {
|
|
377
|
-
this.accountsChangedPayload =
|
|
377
|
+
this.accountsChangedPayload = {
|
|
378
|
+
accounts: []
|
|
379
|
+
};
|
|
378
380
|
|
|
379
381
|
if (message.data && message.data.length > 0) {
|
|
380
|
-
this.accountsChangedPayload =
|
|
381
|
-
|
|
382
|
+
this.accountsChangedPayload = {
|
|
383
|
+
accounts: [ethers.utils.getAddress(message.data[0])],
|
|
384
|
+
origin: message.origin
|
|
385
|
+
};
|
|
386
|
+
this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin);
|
|
382
387
|
} else {
|
|
383
|
-
this.events.emit('accountsChanged', []);
|
|
388
|
+
this.events.emit('accountsChanged', [], message.origin);
|
|
384
389
|
}
|
|
385
390
|
|
|
386
391
|
return;
|
|
@@ -1188,7 +1193,7 @@ class WalletRequestHandler {
|
|
|
1188
1193
|
};
|
|
1189
1194
|
}
|
|
1190
1195
|
|
|
1191
|
-
notifyConnect(connectDetails) {
|
|
1196
|
+
notifyConnect(connectDetails, origin) {
|
|
1192
1197
|
var _connectDetails$sessi;
|
|
1193
1198
|
|
|
1194
1199
|
this.events.emit('connect', connectDetails);
|
|
@@ -1196,13 +1201,12 @@ class WalletRequestHandler {
|
|
|
1196
1201
|
if ((_connectDetails$sessi = connectDetails.session) != null && _connectDetails$sessi.accountAddress) {
|
|
1197
1202
|
var _connectDetails$sessi2;
|
|
1198
1203
|
|
|
1199
|
-
this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress]);
|
|
1204
|
+
this.events.emit('accountsChanged', [(_connectDetails$sessi2 = connectDetails.session) == null ? void 0 : _connectDetails$sessi2.accountAddress], origin);
|
|
1200
1205
|
}
|
|
1201
1206
|
}
|
|
1202
1207
|
|
|
1203
|
-
notifyDisconnect() {
|
|
1204
|
-
this.events.emit('accountsChanged', []);
|
|
1205
|
-
this.events.emit('networks', []);
|
|
1208
|
+
notifyDisconnect(origin) {
|
|
1209
|
+
this.events.emit('accountsChanged', [], origin);
|
|
1206
1210
|
this.events.emit('disconnect');
|
|
1207
1211
|
}
|
|
1208
1212
|
|
|
@@ -2095,9 +2099,9 @@ class BaseWalletTransport {
|
|
|
2095
2099
|
|
|
2096
2100
|
this.notifyDisconnect(error);
|
|
2097
2101
|
});
|
|
2098
|
-
this.walletRequestHandler.on('accountsChanged', accounts => {
|
|
2102
|
+
this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
|
|
2099
2103
|
if (!this.registered) return;
|
|
2100
|
-
this.notifyAccountsChanged(accounts);
|
|
2104
|
+
this.notifyAccountsChanged(accounts, origin);
|
|
2101
2105
|
});
|
|
2102
2106
|
this.walletRequestHandler.on('networks', networks => {
|
|
2103
2107
|
if (!this.registered) return;
|
|
@@ -2182,11 +2186,12 @@ class BaseWalletTransport {
|
|
|
2182
2186
|
});
|
|
2183
2187
|
}
|
|
2184
2188
|
|
|
2185
|
-
notifyAccountsChanged(accounts) {
|
|
2189
|
+
notifyAccountsChanged(accounts, origin) {
|
|
2186
2190
|
this.sendMessage({
|
|
2187
2191
|
idx: -1,
|
|
2188
2192
|
type: EventType.ACCOUNTS_CHANGED,
|
|
2189
|
-
data: accounts
|
|
2193
|
+
data: accounts,
|
|
2194
|
+
origin: origin
|
|
2190
2195
|
});
|
|
2191
2196
|
}
|
|
2192
2197
|
|
|
@@ -3319,9 +3324,21 @@ class Wallet {
|
|
|
3319
3324
|
} else {
|
|
3320
3325
|
this.useSession(session, true);
|
|
3321
3326
|
}
|
|
3322
|
-
}); // below will update the account upon wallet connect/disconnect
|
|
3327
|
+
}); // below will update the account upon wallet connect/disconnect - aka, login/logout.
|
|
3328
|
+
// if an origin is provided, this operation should be performed only on that origin
|
|
3329
|
+
// and shouldn't affect the session of the wallet.
|
|
3330
|
+
|
|
3331
|
+
this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
|
|
3332
|
+
if (origin) {
|
|
3333
|
+
if (accounts.length > 0) {
|
|
3334
|
+
this.useSession({
|
|
3335
|
+
accountAddress: accounts[0]
|
|
3336
|
+
}, true);
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
return;
|
|
3340
|
+
}
|
|
3323
3341
|
|
|
3324
|
-
this.transport.messageProvider.on('accountsChanged', accounts => {
|
|
3325
3342
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
3326
3343
|
this.clearSession();
|
|
3327
3344
|
} else {
|
|
@@ -3355,7 +3372,7 @@ class Wallet {
|
|
|
3355
3372
|
_this.disconnect();
|
|
3356
3373
|
}
|
|
3357
3374
|
|
|
3358
|
-
if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3375
|
+
if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3359
3376
|
return {
|
|
3360
3377
|
connected: true,
|
|
3361
3378
|
session: _this.session,
|
|
@@ -13,7 +13,10 @@ export declare abstract class BaseProviderTransport implements ProviderTransport
|
|
|
13
13
|
session?: WalletSession;
|
|
14
14
|
} | undefined;
|
|
15
15
|
protected connectPayload: ConnectDetails | undefined;
|
|
16
|
-
protected accountsChangedPayload:
|
|
16
|
+
protected accountsChangedPayload: {
|
|
17
|
+
accounts: string[];
|
|
18
|
+
origin?: string;
|
|
19
|
+
} | undefined;
|
|
17
20
|
protected networksPayload: NetworkConfig[] | undefined;
|
|
18
21
|
protected walletContextPayload: WalletContext | undefined;
|
|
19
22
|
protected _sessionId?: string;
|
|
@@ -26,7 +26,7 @@ export declare abstract class BaseWalletTransport implements WalletTransport {
|
|
|
26
26
|
notifyClose(error?: ProviderRpcError): void;
|
|
27
27
|
notifyConnect(connectDetails: ConnectDetails): void;
|
|
28
28
|
notifyDisconnect(error?: ProviderRpcError): void;
|
|
29
|
-
notifyAccountsChanged(accounts: string[]): void;
|
|
29
|
+
notifyAccountsChanged(accounts: string[], origin?: string): void;
|
|
30
30
|
notifyChainChanged(chainIdHex: string): void;
|
|
31
31
|
notifyNetworks(networks: NetworkConfig[]): void;
|
|
32
32
|
notifyWalletContext(walletContext: WalletContext): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter2 as EventEmitter } from 'eventemitter2';
|
|
2
2
|
import { ProviderMessageResponseCallback, ProviderMessageRequest, ProviderMessageResponse } from '../../types';
|
|
3
|
-
interface Stream {
|
|
3
|
+
export interface Stream {
|
|
4
4
|
on(ev: string | symbol, fn: (...args: any[]) => void): void;
|
|
5
5
|
writable: boolean;
|
|
6
6
|
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
|
@@ -15,4 +15,3 @@ export declare abstract class BaseInjectedTransport extends EventEmitter {
|
|
|
15
15
|
protected sendMessageRequest: (message: ProviderMessageRequest) => Promise<ProviderMessageResponse>;
|
|
16
16
|
private sendMessage;
|
|
17
17
|
}
|
|
18
|
-
export {};
|
|
@@ -41,8 +41,8 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
41
41
|
setDefaultNetwork(chainId: string | number, notifyNetworks?: boolean): Promise<number | undefined>;
|
|
42
42
|
getNetworks(jsonRpcResponse?: boolean): Promise<NetworkConfig[]>;
|
|
43
43
|
walletSession(): Promise<WalletSession | undefined>;
|
|
44
|
-
notifyConnect(connectDetails: ConnectDetails): void;
|
|
45
|
-
notifyDisconnect(): void;
|
|
44
|
+
notifyConnect(connectDetails: ConnectDetails, origin?: string): void;
|
|
45
|
+
notifyDisconnect(origin?: string): void;
|
|
46
46
|
notifyNetworks(networks?: NetworkConfig[]): Promise<void>;
|
|
47
47
|
notifyWalletContext(): Promise<void>;
|
|
48
48
|
notifyClose(error?: ProviderRpcError): void;
|
|
@@ -33,6 +33,7 @@ export interface ProviderMessage<T> {
|
|
|
33
33
|
type: string;
|
|
34
34
|
data: T;
|
|
35
35
|
chainId?: number;
|
|
36
|
+
origin?: string;
|
|
36
37
|
}
|
|
37
38
|
export declare type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>;
|
|
38
39
|
export declare type ProviderMessageResponse = ProviderMessage<JsonRpcResponse>;
|
|
@@ -87,7 +88,7 @@ export interface WalletEventTypes {
|
|
|
87
88
|
close: (error?: ProviderRpcError) => void;
|
|
88
89
|
connect: (connectDetails: ConnectDetails) => void;
|
|
89
90
|
disconnect: (error?: ProviderRpcError) => void;
|
|
90
|
-
accountsChanged: (accounts: string[]) => void;
|
|
91
|
+
accountsChanged: (accounts: string[], origin?: string) => void;
|
|
91
92
|
chainChanged: (chainIdHex: string) => void;
|
|
92
93
|
networks: (networks: NetworkConfig[]) => void;
|
|
93
94
|
walletContext: (walletContext: WalletContext) => void;
|
|
@@ -43,7 +43,7 @@ export declare class Wallet implements WalletProvider {
|
|
|
43
43
|
addConnectedSite(origin: string | undefined): Promise<void>;
|
|
44
44
|
removeConnectedSite(origin: string): Promise<void>;
|
|
45
45
|
getConnectedSites(): Promise<string[] | undefined>;
|
|
46
|
-
|
|
46
|
+
isSiteConnected(origin: string | undefined): Promise<boolean>;
|
|
47
47
|
authorize: (options?: ConnectOptions | undefined) => Promise<ConnectDetails>;
|
|
48
48
|
disconnect(): void;
|
|
49
49
|
getProviderConfig(): ProviderConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "provider sub-package for Sequence",
|
|
5
5
|
"repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@0xsequence/abi": "^0.39.
|
|
17
|
-
"@0xsequence/auth": "^0.39.
|
|
18
|
-
"@0xsequence/config": "^0.39.
|
|
19
|
-
"@0xsequence/network": "^0.39.
|
|
20
|
-
"@0xsequence/transactions": "^0.39.
|
|
21
|
-
"@0xsequence/utils": "^0.39.
|
|
22
|
-
"@0xsequence/wallet": "^0.39.
|
|
16
|
+
"@0xsequence/abi": "^0.39.1",
|
|
17
|
+
"@0xsequence/auth": "^0.39.1",
|
|
18
|
+
"@0xsequence/config": "^0.39.1",
|
|
19
|
+
"@0xsequence/network": "^0.39.1",
|
|
20
|
+
"@0xsequence/transactions": "^0.39.1",
|
|
21
|
+
"@0xsequence/utils": "^0.39.1",
|
|
22
|
+
"@0xsequence/wallet": "^0.39.1",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
|
@@ -37,7 +37,7 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
37
37
|
|
|
38
38
|
protected openPayload: { sessionId?: string; session?: WalletSession } | undefined
|
|
39
39
|
protected connectPayload: ConnectDetails | undefined
|
|
40
|
-
protected accountsChangedPayload: string | undefined
|
|
40
|
+
protected accountsChangedPayload: { accounts: string[]; origin?: string } | undefined
|
|
41
41
|
protected networksPayload: NetworkConfig[] | undefined
|
|
42
42
|
protected walletContextPayload: WalletContext | undefined
|
|
43
43
|
|
|
@@ -224,12 +224,15 @@ export abstract class BaseProviderTransport implements ProviderTransport {
|
|
|
224
224
|
|
|
225
225
|
// ACCOUNTS_CHANGED -- when a user logs in or out
|
|
226
226
|
if (message.type === EventType.ACCOUNTS_CHANGED) {
|
|
227
|
-
this.accountsChangedPayload =
|
|
227
|
+
this.accountsChangedPayload = { accounts: [] }
|
|
228
228
|
if (message.data && message.data.length > 0) {
|
|
229
|
-
this.accountsChangedPayload =
|
|
230
|
-
|
|
229
|
+
this.accountsChangedPayload = {
|
|
230
|
+
accounts: [ethers.utils.getAddress(message.data[0])],
|
|
231
|
+
origin: message.origin
|
|
232
|
+
}
|
|
233
|
+
this.events.emit('accountsChanged', this.accountsChangedPayload.accounts, this.accountsChangedPayload.origin)
|
|
231
234
|
} else {
|
|
232
|
-
this.events.emit('accountsChanged', [])
|
|
235
|
+
this.events.emit('accountsChanged', [], message.origin)
|
|
233
236
|
}
|
|
234
237
|
return
|
|
235
238
|
}
|
|
@@ -55,9 +55,9 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
55
55
|
this.notifyDisconnect(error)
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
this.walletRequestHandler.on('accountsChanged', (accounts: string[]) => {
|
|
58
|
+
this.walletRequestHandler.on('accountsChanged', (accounts: string[], origin?: string) => {
|
|
59
59
|
if (!this.registered) return
|
|
60
|
-
this.notifyAccountsChanged(accounts)
|
|
60
|
+
this.notifyAccountsChanged(accounts, origin)
|
|
61
61
|
})
|
|
62
62
|
|
|
63
63
|
this.walletRequestHandler.on('networks', (networks: NetworkConfig[]) => {
|
|
@@ -206,11 +206,12 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
206
206
|
})
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
notifyAccountsChanged(accounts: string[]) {
|
|
209
|
+
notifyAccountsChanged(accounts: string[], origin?: string) {
|
|
210
210
|
this.sendMessage({
|
|
211
211
|
idx: -1,
|
|
212
212
|
type: EventType.ACCOUNTS_CHANGED,
|
|
213
|
-
data: accounts
|
|
213
|
+
data: accounts,
|
|
214
|
+
origin: origin
|
|
214
215
|
})
|
|
215
216
|
}
|
|
216
217
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ProviderMessageResponse
|
|
10
10
|
} from '../../types'
|
|
11
11
|
|
|
12
|
-
interface Stream {
|
|
12
|
+
export interface Stream {
|
|
13
13
|
on(ev: string | symbol, fn: (...args: any[]) => void): void
|
|
14
14
|
writable: boolean
|
|
15
15
|
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean
|
|
@@ -702,16 +702,15 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
704
|
|
|
705
|
-
notifyConnect(connectDetails: ConnectDetails) {
|
|
705
|
+
notifyConnect(connectDetails: ConnectDetails, origin?: string) {
|
|
706
706
|
this.events.emit('connect', connectDetails)
|
|
707
707
|
if (connectDetails.session?.accountAddress) {
|
|
708
|
-
this.events.emit('accountsChanged', [connectDetails.session?.accountAddress])
|
|
708
|
+
this.events.emit('accountsChanged', [connectDetails.session?.accountAddress], origin)
|
|
709
709
|
}
|
|
710
710
|
}
|
|
711
711
|
|
|
712
|
-
notifyDisconnect() {
|
|
713
|
-
this.events.emit('accountsChanged', [])
|
|
714
|
-
this.events.emit('networks', [])
|
|
712
|
+
notifyDisconnect(origin?: string) {
|
|
713
|
+
this.events.emit('accountsChanged', [], origin)
|
|
715
714
|
this.events.emit('disconnect')
|
|
716
715
|
}
|
|
717
716
|
|
package/src/types.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface ProviderMessage<T> {
|
|
|
37
37
|
type: string // message type
|
|
38
38
|
data: T // the ethereum json-rpc payload
|
|
39
39
|
chainId?: number // chain id which the message is intended
|
|
40
|
+
origin?: string // origin of the message
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
export type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>
|
|
@@ -111,7 +112,7 @@ export interface WalletEventTypes {
|
|
|
111
112
|
connect: (connectDetails: ConnectDetails) => void
|
|
112
113
|
disconnect: (error?: ProviderRpcError) => void
|
|
113
114
|
|
|
114
|
-
accountsChanged: (accounts: string[]) => void
|
|
115
|
+
accountsChanged: (accounts: string[], origin?: string) => void
|
|
115
116
|
chainChanged: (chainIdHex: string) => void
|
|
116
117
|
|
|
117
118
|
networks: (networks: NetworkConfig[]) => void
|
package/src/wallet.ts
CHANGED
|
@@ -210,8 +210,17 @@ export class Wallet implements WalletProvider {
|
|
|
210
210
|
}
|
|
211
211
|
})
|
|
212
212
|
|
|
213
|
-
// below will update the account upon wallet connect/disconnect
|
|
214
|
-
|
|
213
|
+
// below will update the account upon wallet connect/disconnect - aka, login/logout.
|
|
214
|
+
// if an origin is provided, this operation should be performed only on that origin
|
|
215
|
+
// and shouldn't affect the session of the wallet.
|
|
216
|
+
this.transport.messageProvider.on('accountsChanged', (accounts: string[], origin?: string) => {
|
|
217
|
+
if (origin) {
|
|
218
|
+
if (accounts.length > 0) {
|
|
219
|
+
this.useSession({ accountAddress: accounts[0] }, true)
|
|
220
|
+
}
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
|
|
215
224
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
216
225
|
this.clearSession()
|
|
217
226
|
} else {
|
|
@@ -244,7 +253,7 @@ export class Wallet implements WalletProvider {
|
|
|
244
253
|
|
|
245
254
|
if (
|
|
246
255
|
this.isConnected() &&
|
|
247
|
-
this.isSiteConnected(options?.origin) &&
|
|
256
|
+
(await this.isSiteConnected(options?.origin)) &&
|
|
248
257
|
!!this.session &&
|
|
249
258
|
!options?.authorize &&
|
|
250
259
|
!options?.askForEmail
|
|
@@ -307,7 +316,7 @@ export class Wallet implements WalletProvider {
|
|
|
307
316
|
return this.connectedSites.get()
|
|
308
317
|
}
|
|
309
318
|
|
|
310
|
-
|
|
319
|
+
async isSiteConnected(origin: string | undefined): Promise<boolean> {
|
|
311
320
|
const authorized = await this.connectedSites.get()
|
|
312
321
|
|
|
313
322
|
return !!authorized && authorized.includes(origin || window.location.origin)
|