@0xsequence/provider 0.39.0 → 0.39.3
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 +37 -16
- package/dist/0xsequence-provider.cjs.prod.js +37 -16
- package/dist/0xsequence-provider.esm.js +37 -16
- package/dist/declarations/src/provider.d.ts +5 -0
- 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/provider.ts +4 -0
- 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
|
|
|
@@ -1308,6 +1312,10 @@ class Web3Provider extends providers.Web3Provider {
|
|
|
1308
1312
|
return this._sender.send(method, params, chainId);
|
|
1309
1313
|
}
|
|
1310
1314
|
|
|
1315
|
+
request(request) {
|
|
1316
|
+
return this.send(request.method, request.params || [], request.chainId);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1311
1319
|
getSigner() {
|
|
1312
1320
|
return new Web3Signer(this, this._defaultChainId);
|
|
1313
1321
|
}
|
|
@@ -2099,9 +2107,9 @@ class BaseWalletTransport {
|
|
|
2099
2107
|
|
|
2100
2108
|
this.notifyDisconnect(error);
|
|
2101
2109
|
});
|
|
2102
|
-
this.walletRequestHandler.on('accountsChanged', accounts => {
|
|
2110
|
+
this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
|
|
2103
2111
|
if (!this.registered) return;
|
|
2104
|
-
this.notifyAccountsChanged(accounts);
|
|
2112
|
+
this.notifyAccountsChanged(accounts, origin);
|
|
2105
2113
|
});
|
|
2106
2114
|
this.walletRequestHandler.on('networks', networks => {
|
|
2107
2115
|
if (!this.registered) return;
|
|
@@ -2186,11 +2194,12 @@ class BaseWalletTransport {
|
|
|
2186
2194
|
});
|
|
2187
2195
|
}
|
|
2188
2196
|
|
|
2189
|
-
notifyAccountsChanged(accounts) {
|
|
2197
|
+
notifyAccountsChanged(accounts, origin) {
|
|
2190
2198
|
this.sendMessage({
|
|
2191
2199
|
idx: -1,
|
|
2192
2200
|
type: exports.EventType.ACCOUNTS_CHANGED,
|
|
2193
|
-
data: accounts
|
|
2201
|
+
data: accounts,
|
|
2202
|
+
origin: origin
|
|
2194
2203
|
});
|
|
2195
2204
|
}
|
|
2196
2205
|
|
|
@@ -3323,9 +3332,21 @@ class Wallet {
|
|
|
3323
3332
|
} else {
|
|
3324
3333
|
this.useSession(session, true);
|
|
3325
3334
|
}
|
|
3326
|
-
}); // below will update the account upon wallet connect/disconnect
|
|
3335
|
+
}); // below will update the account upon wallet connect/disconnect - aka, login/logout.
|
|
3336
|
+
// if an origin is provided, this operation should be performed only on that origin
|
|
3337
|
+
// and shouldn't affect the session of the wallet.
|
|
3338
|
+
|
|
3339
|
+
this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
|
|
3340
|
+
if (origin) {
|
|
3341
|
+
if (accounts.length > 0) {
|
|
3342
|
+
this.useSession({
|
|
3343
|
+
accountAddress: accounts[0]
|
|
3344
|
+
}, true);
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3327
3349
|
|
|
3328
|
-
this.transport.messageProvider.on('accountsChanged', accounts => {
|
|
3329
3350
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
3330
3351
|
this.clearSession();
|
|
3331
3352
|
} else {
|
|
@@ -3359,7 +3380,7 @@ class Wallet {
|
|
|
3359
3380
|
_this.disconnect();
|
|
3360
3381
|
}
|
|
3361
3382
|
|
|
3362
|
-
if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3383
|
+
if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3363
3384
|
return {
|
|
3364
3385
|
connected: true,
|
|
3365
3386
|
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
|
|
|
@@ -1308,6 +1312,10 @@ class Web3Provider extends providers.Web3Provider {
|
|
|
1308
1312
|
return this._sender.send(method, params, chainId);
|
|
1309
1313
|
}
|
|
1310
1314
|
|
|
1315
|
+
request(request) {
|
|
1316
|
+
return this.send(request.method, request.params || [], request.chainId);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1311
1319
|
getSigner() {
|
|
1312
1320
|
return new Web3Signer(this, this._defaultChainId);
|
|
1313
1321
|
}
|
|
@@ -2099,9 +2107,9 @@ class BaseWalletTransport {
|
|
|
2099
2107
|
|
|
2100
2108
|
this.notifyDisconnect(error);
|
|
2101
2109
|
});
|
|
2102
|
-
this.walletRequestHandler.on('accountsChanged', accounts => {
|
|
2110
|
+
this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
|
|
2103
2111
|
if (!this.registered) return;
|
|
2104
|
-
this.notifyAccountsChanged(accounts);
|
|
2112
|
+
this.notifyAccountsChanged(accounts, origin);
|
|
2105
2113
|
});
|
|
2106
2114
|
this.walletRequestHandler.on('networks', networks => {
|
|
2107
2115
|
if (!this.registered) return;
|
|
@@ -2186,11 +2194,12 @@ class BaseWalletTransport {
|
|
|
2186
2194
|
});
|
|
2187
2195
|
}
|
|
2188
2196
|
|
|
2189
|
-
notifyAccountsChanged(accounts) {
|
|
2197
|
+
notifyAccountsChanged(accounts, origin) {
|
|
2190
2198
|
this.sendMessage({
|
|
2191
2199
|
idx: -1,
|
|
2192
2200
|
type: exports.EventType.ACCOUNTS_CHANGED,
|
|
2193
|
-
data: accounts
|
|
2201
|
+
data: accounts,
|
|
2202
|
+
origin: origin
|
|
2194
2203
|
});
|
|
2195
2204
|
}
|
|
2196
2205
|
|
|
@@ -3323,9 +3332,21 @@ class Wallet {
|
|
|
3323
3332
|
} else {
|
|
3324
3333
|
this.useSession(session, true);
|
|
3325
3334
|
}
|
|
3326
|
-
}); // below will update the account upon wallet connect/disconnect
|
|
3335
|
+
}); // below will update the account upon wallet connect/disconnect - aka, login/logout.
|
|
3336
|
+
// if an origin is provided, this operation should be performed only on that origin
|
|
3337
|
+
// and shouldn't affect the session of the wallet.
|
|
3338
|
+
|
|
3339
|
+
this.transport.messageProvider.on('accountsChanged', (accounts, origin) => {
|
|
3340
|
+
if (origin) {
|
|
3341
|
+
if (accounts.length > 0) {
|
|
3342
|
+
this.useSession({
|
|
3343
|
+
accountAddress: accounts[0]
|
|
3344
|
+
}, true);
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3327
3349
|
|
|
3328
|
-
this.transport.messageProvider.on('accountsChanged', accounts => {
|
|
3329
3350
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
3330
3351
|
this.clearSession();
|
|
3331
3352
|
} else {
|
|
@@ -3359,7 +3380,7 @@ class Wallet {
|
|
|
3359
3380
|
_this.disconnect();
|
|
3360
3381
|
}
|
|
3361
3382
|
|
|
3362
|
-
if (_this.isConnected() && _this.isSiteConnected(options == null ? void 0 : options.origin) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3383
|
+
if (_this.isConnected() && (await _this.isSiteConnected(options == null ? void 0 : options.origin)) && !!_this.session && !(options != null && options.authorize) && !(options != null && options.askForEmail)) {
|
|
3363
3384
|
return {
|
|
3364
3385
|
connected: true,
|
|
3365
3386
|
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
|
|
|
@@ -1304,6 +1308,10 @@ class Web3Provider extends Web3Provider$1 {
|
|
|
1304
1308
|
return this._sender.send(method, params, chainId);
|
|
1305
1309
|
}
|
|
1306
1310
|
|
|
1311
|
+
request(request) {
|
|
1312
|
+
return this.send(request.method, request.params || [], request.chainId);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1307
1315
|
getSigner() {
|
|
1308
1316
|
return new Web3Signer(this, this._defaultChainId);
|
|
1309
1317
|
}
|
|
@@ -2095,9 +2103,9 @@ class BaseWalletTransport {
|
|
|
2095
2103
|
|
|
2096
2104
|
this.notifyDisconnect(error);
|
|
2097
2105
|
});
|
|
2098
|
-
this.walletRequestHandler.on('accountsChanged', accounts => {
|
|
2106
|
+
this.walletRequestHandler.on('accountsChanged', (accounts, origin) => {
|
|
2099
2107
|
if (!this.registered) return;
|
|
2100
|
-
this.notifyAccountsChanged(accounts);
|
|
2108
|
+
this.notifyAccountsChanged(accounts, origin);
|
|
2101
2109
|
});
|
|
2102
2110
|
this.walletRequestHandler.on('networks', networks => {
|
|
2103
2111
|
if (!this.registered) return;
|
|
@@ -2182,11 +2190,12 @@ class BaseWalletTransport {
|
|
|
2182
2190
|
});
|
|
2183
2191
|
}
|
|
2184
2192
|
|
|
2185
|
-
notifyAccountsChanged(accounts) {
|
|
2193
|
+
notifyAccountsChanged(accounts, origin) {
|
|
2186
2194
|
this.sendMessage({
|
|
2187
2195
|
idx: -1,
|
|
2188
2196
|
type: EventType.ACCOUNTS_CHANGED,
|
|
2189
|
-
data: accounts
|
|
2197
|
+
data: accounts,
|
|
2198
|
+
origin: origin
|
|
2190
2199
|
});
|
|
2191
2200
|
}
|
|
2192
2201
|
|
|
@@ -3319,9 +3328,21 @@ class Wallet {
|
|
|
3319
3328
|
} else {
|
|
3320
3329
|
this.useSession(session, true);
|
|
3321
3330
|
}
|
|
3322
|
-
}); // 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
|
+
}
|
|
3323
3345
|
|
|
3324
|
-
this.transport.messageProvider.on('accountsChanged', accounts => {
|
|
3325
3346
|
if (!accounts || accounts.length === 0 || accounts[0] === '') {
|
|
3326
3347
|
this.clearSession();
|
|
3327
3348
|
} else {
|
|
@@ -3355,7 +3376,7 @@ class Wallet {
|
|
|
3355
3376
|
_this.disconnect();
|
|
3356
3377
|
}
|
|
3357
3378
|
|
|
3358
|
-
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)) {
|
|
3359
3380
|
return {
|
|
3360
3381
|
connected: true,
|
|
3361
3382
|
session: _this.session,
|
|
@@ -16,6 +16,11 @@ export declare class Web3Provider extends EthersWeb3Provider implements JsonRpcH
|
|
|
16
16
|
constructor(provider: JsonRpcProvider | JsonRpcHandler | JsonRpcFetchFunc, defaultChainId?: ChainIdLike);
|
|
17
17
|
sendAsync(request: JsonRpcRequest, callback: JsonRpcResponseCallback | ((error: any, response: any) => void), chainId?: number): void;
|
|
18
18
|
send(method: string, params: Array<any>, chainId?: number): Promise<any>;
|
|
19
|
+
request(request: {
|
|
20
|
+
method: string;
|
|
21
|
+
params?: Array<any>;
|
|
22
|
+
chainId?: number;
|
|
23
|
+
}): Promise<any>;
|
|
19
24
|
getSigner(): Web3Signer;
|
|
20
25
|
getChainId(): Promise<number>;
|
|
21
26
|
}
|
|
@@ -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.3",
|
|
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.3",
|
|
17
|
+
"@0xsequence/auth": "^0.39.3",
|
|
18
|
+
"@0xsequence/config": "^0.39.3",
|
|
19
|
+
"@0xsequence/network": "^0.39.3",
|
|
20
|
+
"@0xsequence/transactions": "^0.39.3",
|
|
21
|
+
"@0xsequence/utils": "^0.39.3",
|
|
22
|
+
"@0xsequence/wallet": "^0.39.3",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
package/src/provider.ts
CHANGED
|
@@ -66,6 +66,10 @@ export class Web3Provider extends EthersWeb3Provider implements JsonRpcHandler {
|
|
|
66
66
|
return this._sender.send(method, params, chainId)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
request(request: { method: string; params?: Array<any>, chainId?: number }): Promise<any> {
|
|
70
|
+
return this.send(request.method, request.params || [], request.chainId)
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
getSigner(): Web3Signer {
|
|
70
74
|
return new Web3Signer(this, this._defaultChainId)
|
|
71
75
|
}
|
|
@@ -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)
|