@0xsequence/provider 0.35.6 → 0.35.10
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 +41 -34
- package/dist/0xsequence-provider.cjs.prod.js +41 -34
- package/dist/0xsequence-provider.esm.js +41 -34
- package/dist/declarations/src/transports/wallet-request-handler.d.ts +3 -3
- package/package.json +8 -8
- package/src/transports/base-wallet-transport.ts +9 -12
- package/src/transports/wallet-request-handler.ts +21 -14
- package/src/transports/window-transport/window-message-provider.ts +4 -1
|
@@ -597,14 +597,9 @@ class BaseWalletTransport {
|
|
|
597
597
|
};
|
|
598
598
|
|
|
599
599
|
this.handleMessage = async function (message) {
|
|
600
|
-
const request = message; // ensure
|
|
601
|
-
|
|
602
|
-
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
603
|
-
await _this.walletRequestHandler.signerReady();
|
|
604
|
-
} // ensure initial handshake is complete before accepting
|
|
600
|
+
const request = message; // ensure initial handshake is complete before accepting
|
|
605
601
|
// other kinds of messages.
|
|
606
602
|
|
|
607
|
-
|
|
608
603
|
if (_this._init !== exports.InitState.OK) {
|
|
609
604
|
if (request.type === exports.EventType.INIT) {
|
|
610
605
|
if (_this.isValidInitAck(message)) {
|
|
@@ -618,7 +613,11 @@ class BaseWalletTransport {
|
|
|
618
613
|
}
|
|
619
614
|
|
|
620
615
|
return;
|
|
621
|
-
} // handle
|
|
616
|
+
} // ensure signer is ready to handle requests
|
|
617
|
+
// if (this.walletRequestHandler.getSigner() === undefined) {
|
|
618
|
+
// await this.walletRequestHandler.signerReady()
|
|
619
|
+
// }
|
|
620
|
+
// handle request
|
|
622
621
|
|
|
623
622
|
|
|
624
623
|
switch (request.type) {
|
|
@@ -678,12 +677,7 @@ class BaseWalletTransport {
|
|
|
678
677
|
});
|
|
679
678
|
}
|
|
680
679
|
|
|
681
|
-
_this.walletRequestHandler.setOpenIntent(intent); //
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
685
|
-
await _this.walletRequestHandler.signerReady();
|
|
686
|
-
} // init handshake for certain transports, before we can open the communication.
|
|
680
|
+
_this.walletRequestHandler.setOpenIntent(intent); // init handshake for certain transports, before we can open the communication.
|
|
687
681
|
//
|
|
688
682
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
689
683
|
// origin host of the dapp.
|
|
@@ -725,10 +719,12 @@ class BaseWalletTransport {
|
|
|
725
719
|
}
|
|
726
720
|
} else {
|
|
727
721
|
_this.walletRequestHandler.setConnectOptions(undefined);
|
|
728
|
-
} //
|
|
722
|
+
} // ensure signer is ready
|
|
723
|
+
|
|
729
724
|
|
|
725
|
+
await _this.walletRequestHandler.getSigner(); // Notify open and proceed to prompt for connection if intended
|
|
730
726
|
|
|
731
|
-
if (!_this.walletRequestHandler.isSignedIn()) {
|
|
727
|
+
if (!(await _this.walletRequestHandler.isSignedIn())) {
|
|
732
728
|
// open wallet without a specific connected chainId, as the user is not signed in
|
|
733
729
|
_this.notifyOpen({
|
|
734
730
|
sessionId: _this._sessionId
|
|
@@ -1380,7 +1376,9 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1380
1376
|
|
|
1381
1377
|
this.register = () => {
|
|
1382
1378
|
if (registeredWindowMessageProvider) {
|
|
1383
|
-
|
|
1379
|
+
// overriding the registered message provider
|
|
1380
|
+
registeredWindowMessageProvider.unregister();
|
|
1381
|
+
registeredWindowMessageProvider = this;
|
|
1384
1382
|
} // listen for incoming messages from wallet
|
|
1385
1383
|
|
|
1386
1384
|
|
|
@@ -1705,6 +1703,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1705
1703
|
|
|
1706
1704
|
}
|
|
1707
1705
|
|
|
1706
|
+
const SIGNER_READY_TIMEOUT = 10000;
|
|
1708
1707
|
class WalletRequestHandler {
|
|
1709
1708
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1710
1709
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
@@ -1754,10 +1753,7 @@ class WalletRequestHandler {
|
|
|
1754
1753
|
id: request.id,
|
|
1755
1754
|
result: null
|
|
1756
1755
|
};
|
|
1757
|
-
|
|
1758
|
-
if (_this.signer === undefined) {
|
|
1759
|
-
await _this.signerReady();
|
|
1760
|
-
}
|
|
1756
|
+
await _this.getSigner();
|
|
1761
1757
|
|
|
1762
1758
|
try {
|
|
1763
1759
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -2150,6 +2146,21 @@ class WalletRequestHandler {
|
|
|
2150
2146
|
callback(undefined, response);
|
|
2151
2147
|
};
|
|
2152
2148
|
|
|
2149
|
+
this.isSignedIn = async function () {
|
|
2150
|
+
await _this.signerReady();
|
|
2151
|
+
return !!_this.signer;
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
this.getSigner = async function () {
|
|
2155
|
+
await _this.signerReady();
|
|
2156
|
+
|
|
2157
|
+
if (_this.signer === undefined) {
|
|
2158
|
+
throw new Error('signerReady failed resolve');
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
return _this.signer;
|
|
2162
|
+
};
|
|
2163
|
+
|
|
2153
2164
|
this.signer = _signer;
|
|
2154
2165
|
this.prompter = prompter;
|
|
2155
2166
|
this.mainnetNetworks = mainnetNetworks;
|
|
@@ -2206,7 +2217,7 @@ class WalletRequestHandler {
|
|
|
2206
2217
|
|
|
2207
2218
|
signOut() {
|
|
2208
2219
|
// signed out state
|
|
2209
|
-
this.
|
|
2220
|
+
this.setSigner(null);
|
|
2210
2221
|
}
|
|
2211
2222
|
|
|
2212
2223
|
signerReset() {
|
|
@@ -2215,14 +2226,18 @@ class WalletRequestHandler {
|
|
|
2215
2226
|
this.signer = undefined;
|
|
2216
2227
|
}
|
|
2217
2228
|
|
|
2218
|
-
signerReady() {
|
|
2229
|
+
signerReady(timeout = SIGNER_READY_TIMEOUT) {
|
|
2219
2230
|
return new Promise((resolve, reject) => {
|
|
2220
2231
|
if (this.signer !== undefined) {
|
|
2221
|
-
resolve(
|
|
2232
|
+
resolve();
|
|
2222
2233
|
} else {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2234
|
+
setTimeout(() => {
|
|
2235
|
+
if (this.signer === undefined) {
|
|
2236
|
+
this.signerReadyCallbacks = [];
|
|
2237
|
+
reject(`signerReady timed out`);
|
|
2238
|
+
}
|
|
2239
|
+
}, timeout);
|
|
2240
|
+
this.signerReadyCallbacks.push(resolve);
|
|
2226
2241
|
}
|
|
2227
2242
|
});
|
|
2228
2243
|
}
|
|
@@ -2426,14 +2441,6 @@ class WalletRequestHandler {
|
|
|
2426
2441
|
this.events.emit('close', error);
|
|
2427
2442
|
}
|
|
2428
2443
|
|
|
2429
|
-
isSignedIn() {
|
|
2430
|
-
return !!this.signer;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
getSigner() {
|
|
2434
|
-
return this.signer;
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
2444
|
setSigner(signer) {
|
|
2438
2445
|
this.signer = signer;
|
|
2439
2446
|
|
|
@@ -597,14 +597,9 @@ class BaseWalletTransport {
|
|
|
597
597
|
};
|
|
598
598
|
|
|
599
599
|
this.handleMessage = async function (message) {
|
|
600
|
-
const request = message; // ensure
|
|
601
|
-
|
|
602
|
-
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
603
|
-
await _this.walletRequestHandler.signerReady();
|
|
604
|
-
} // ensure initial handshake is complete before accepting
|
|
600
|
+
const request = message; // ensure initial handshake is complete before accepting
|
|
605
601
|
// other kinds of messages.
|
|
606
602
|
|
|
607
|
-
|
|
608
603
|
if (_this._init !== exports.InitState.OK) {
|
|
609
604
|
if (request.type === exports.EventType.INIT) {
|
|
610
605
|
if (_this.isValidInitAck(message)) {
|
|
@@ -618,7 +613,11 @@ class BaseWalletTransport {
|
|
|
618
613
|
}
|
|
619
614
|
|
|
620
615
|
return;
|
|
621
|
-
} // handle
|
|
616
|
+
} // ensure signer is ready to handle requests
|
|
617
|
+
// if (this.walletRequestHandler.getSigner() === undefined) {
|
|
618
|
+
// await this.walletRequestHandler.signerReady()
|
|
619
|
+
// }
|
|
620
|
+
// handle request
|
|
622
621
|
|
|
623
622
|
|
|
624
623
|
switch (request.type) {
|
|
@@ -678,12 +677,7 @@ class BaseWalletTransport {
|
|
|
678
677
|
});
|
|
679
678
|
}
|
|
680
679
|
|
|
681
|
-
_this.walletRequestHandler.setOpenIntent(intent); //
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
685
|
-
await _this.walletRequestHandler.signerReady();
|
|
686
|
-
} // init handshake for certain transports, before we can open the communication.
|
|
680
|
+
_this.walletRequestHandler.setOpenIntent(intent); // init handshake for certain transports, before we can open the communication.
|
|
687
681
|
//
|
|
688
682
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
689
683
|
// origin host of the dapp.
|
|
@@ -725,10 +719,12 @@ class BaseWalletTransport {
|
|
|
725
719
|
}
|
|
726
720
|
} else {
|
|
727
721
|
_this.walletRequestHandler.setConnectOptions(undefined);
|
|
728
|
-
} //
|
|
722
|
+
} // ensure signer is ready
|
|
723
|
+
|
|
729
724
|
|
|
725
|
+
await _this.walletRequestHandler.getSigner(); // Notify open and proceed to prompt for connection if intended
|
|
730
726
|
|
|
731
|
-
if (!_this.walletRequestHandler.isSignedIn()) {
|
|
727
|
+
if (!(await _this.walletRequestHandler.isSignedIn())) {
|
|
732
728
|
// open wallet without a specific connected chainId, as the user is not signed in
|
|
733
729
|
_this.notifyOpen({
|
|
734
730
|
sessionId: _this._sessionId
|
|
@@ -1380,7 +1376,9 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1380
1376
|
|
|
1381
1377
|
this.register = () => {
|
|
1382
1378
|
if (registeredWindowMessageProvider) {
|
|
1383
|
-
|
|
1379
|
+
// overriding the registered message provider
|
|
1380
|
+
registeredWindowMessageProvider.unregister();
|
|
1381
|
+
registeredWindowMessageProvider = this;
|
|
1384
1382
|
} // listen for incoming messages from wallet
|
|
1385
1383
|
|
|
1386
1384
|
|
|
@@ -1705,6 +1703,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1705
1703
|
|
|
1706
1704
|
}
|
|
1707
1705
|
|
|
1706
|
+
const SIGNER_READY_TIMEOUT = 10000;
|
|
1708
1707
|
class WalletRequestHandler {
|
|
1709
1708
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1710
1709
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
@@ -1754,10 +1753,7 @@ class WalletRequestHandler {
|
|
|
1754
1753
|
id: request.id,
|
|
1755
1754
|
result: null
|
|
1756
1755
|
};
|
|
1757
|
-
|
|
1758
|
-
if (_this.signer === undefined) {
|
|
1759
|
-
await _this.signerReady();
|
|
1760
|
-
}
|
|
1756
|
+
await _this.getSigner();
|
|
1761
1757
|
|
|
1762
1758
|
try {
|
|
1763
1759
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -2150,6 +2146,21 @@ class WalletRequestHandler {
|
|
|
2150
2146
|
callback(undefined, response);
|
|
2151
2147
|
};
|
|
2152
2148
|
|
|
2149
|
+
this.isSignedIn = async function () {
|
|
2150
|
+
await _this.signerReady();
|
|
2151
|
+
return !!_this.signer;
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
this.getSigner = async function () {
|
|
2155
|
+
await _this.signerReady();
|
|
2156
|
+
|
|
2157
|
+
if (_this.signer === undefined) {
|
|
2158
|
+
throw new Error('signerReady failed resolve');
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
return _this.signer;
|
|
2162
|
+
};
|
|
2163
|
+
|
|
2153
2164
|
this.signer = _signer;
|
|
2154
2165
|
this.prompter = prompter;
|
|
2155
2166
|
this.mainnetNetworks = mainnetNetworks;
|
|
@@ -2206,7 +2217,7 @@ class WalletRequestHandler {
|
|
|
2206
2217
|
|
|
2207
2218
|
signOut() {
|
|
2208
2219
|
// signed out state
|
|
2209
|
-
this.
|
|
2220
|
+
this.setSigner(null);
|
|
2210
2221
|
}
|
|
2211
2222
|
|
|
2212
2223
|
signerReset() {
|
|
@@ -2215,14 +2226,18 @@ class WalletRequestHandler {
|
|
|
2215
2226
|
this.signer = undefined;
|
|
2216
2227
|
}
|
|
2217
2228
|
|
|
2218
|
-
signerReady() {
|
|
2229
|
+
signerReady(timeout = SIGNER_READY_TIMEOUT) {
|
|
2219
2230
|
return new Promise((resolve, reject) => {
|
|
2220
2231
|
if (this.signer !== undefined) {
|
|
2221
|
-
resolve(
|
|
2232
|
+
resolve();
|
|
2222
2233
|
} else {
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2234
|
+
setTimeout(() => {
|
|
2235
|
+
if (this.signer === undefined) {
|
|
2236
|
+
this.signerReadyCallbacks = [];
|
|
2237
|
+
reject(`signerReady timed out`);
|
|
2238
|
+
}
|
|
2239
|
+
}, timeout);
|
|
2240
|
+
this.signerReadyCallbacks.push(resolve);
|
|
2226
2241
|
}
|
|
2227
2242
|
});
|
|
2228
2243
|
}
|
|
@@ -2426,14 +2441,6 @@ class WalletRequestHandler {
|
|
|
2426
2441
|
this.events.emit('close', error);
|
|
2427
2442
|
}
|
|
2428
2443
|
|
|
2429
|
-
isSignedIn() {
|
|
2430
|
-
return !!this.signer;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
getSigner() {
|
|
2434
|
-
return this.signer;
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
2444
|
setSigner(signer) {
|
|
2438
2445
|
this.signer = signer;
|
|
2439
2446
|
|
|
@@ -593,14 +593,9 @@ class BaseWalletTransport {
|
|
|
593
593
|
};
|
|
594
594
|
|
|
595
595
|
this.handleMessage = async function (message) {
|
|
596
|
-
const request = message; // ensure
|
|
597
|
-
|
|
598
|
-
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
599
|
-
await _this.walletRequestHandler.signerReady();
|
|
600
|
-
} // ensure initial handshake is complete before accepting
|
|
596
|
+
const request = message; // ensure initial handshake is complete before accepting
|
|
601
597
|
// other kinds of messages.
|
|
602
598
|
|
|
603
|
-
|
|
604
599
|
if (_this._init !== InitState.OK) {
|
|
605
600
|
if (request.type === EventType.INIT) {
|
|
606
601
|
if (_this.isValidInitAck(message)) {
|
|
@@ -614,7 +609,11 @@ class BaseWalletTransport {
|
|
|
614
609
|
}
|
|
615
610
|
|
|
616
611
|
return;
|
|
617
|
-
} // handle
|
|
612
|
+
} // ensure signer is ready to handle requests
|
|
613
|
+
// if (this.walletRequestHandler.getSigner() === undefined) {
|
|
614
|
+
// await this.walletRequestHandler.signerReady()
|
|
615
|
+
// }
|
|
616
|
+
// handle request
|
|
618
617
|
|
|
619
618
|
|
|
620
619
|
switch (request.type) {
|
|
@@ -674,12 +673,7 @@ class BaseWalletTransport {
|
|
|
674
673
|
});
|
|
675
674
|
}
|
|
676
675
|
|
|
677
|
-
_this.walletRequestHandler.setOpenIntent(intent); //
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
if (_this.walletRequestHandler.getSigner() === undefined) {
|
|
681
|
-
await _this.walletRequestHandler.signerReady();
|
|
682
|
-
} // init handshake for certain transports, before we can open the communication.
|
|
676
|
+
_this.walletRequestHandler.setOpenIntent(intent); // init handshake for certain transports, before we can open the communication.
|
|
683
677
|
//
|
|
684
678
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
685
679
|
// origin host of the dapp.
|
|
@@ -721,10 +715,12 @@ class BaseWalletTransport {
|
|
|
721
715
|
}
|
|
722
716
|
} else {
|
|
723
717
|
_this.walletRequestHandler.setConnectOptions(undefined);
|
|
724
|
-
} //
|
|
718
|
+
} // ensure signer is ready
|
|
719
|
+
|
|
725
720
|
|
|
721
|
+
await _this.walletRequestHandler.getSigner(); // Notify open and proceed to prompt for connection if intended
|
|
726
722
|
|
|
727
|
-
if (!_this.walletRequestHandler.isSignedIn()) {
|
|
723
|
+
if (!(await _this.walletRequestHandler.isSignedIn())) {
|
|
728
724
|
// open wallet without a specific connected chainId, as the user is not signed in
|
|
729
725
|
_this.notifyOpen({
|
|
730
726
|
sessionId: _this._sessionId
|
|
@@ -1376,7 +1372,9 @@ class WindowMessageProvider extends BaseProviderTransport {
|
|
|
1376
1372
|
|
|
1377
1373
|
this.register = () => {
|
|
1378
1374
|
if (registeredWindowMessageProvider) {
|
|
1379
|
-
|
|
1375
|
+
// overriding the registered message provider
|
|
1376
|
+
registeredWindowMessageProvider.unregister();
|
|
1377
|
+
registeredWindowMessageProvider = this;
|
|
1380
1378
|
} // listen for incoming messages from wallet
|
|
1381
1379
|
|
|
1382
1380
|
|
|
@@ -1701,6 +1699,7 @@ class WindowMessageHandler extends BaseWalletTransport {
|
|
|
1701
1699
|
|
|
1702
1700
|
}
|
|
1703
1701
|
|
|
1702
|
+
const SIGNER_READY_TIMEOUT = 10000;
|
|
1704
1703
|
class WalletRequestHandler {
|
|
1705
1704
|
// signer interface of the wallet. A null value means there is no signer (ie. user not signed in). An undefined
|
|
1706
1705
|
// value means the signer state is unknown, usually meaning the wallet app is booting up and initializing. Of course
|
|
@@ -1750,10 +1749,7 @@ class WalletRequestHandler {
|
|
|
1750
1749
|
id: request.id,
|
|
1751
1750
|
result: null
|
|
1752
1751
|
};
|
|
1753
|
-
|
|
1754
|
-
if (_this.signer === undefined) {
|
|
1755
|
-
await _this.signerReady();
|
|
1756
|
-
}
|
|
1752
|
+
await _this.getSigner();
|
|
1757
1753
|
|
|
1758
1754
|
try {
|
|
1759
1755
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -2146,6 +2142,21 @@ class WalletRequestHandler {
|
|
|
2146
2142
|
callback(undefined, response);
|
|
2147
2143
|
};
|
|
2148
2144
|
|
|
2145
|
+
this.isSignedIn = async function () {
|
|
2146
|
+
await _this.signerReady();
|
|
2147
|
+
return !!_this.signer;
|
|
2148
|
+
};
|
|
2149
|
+
|
|
2150
|
+
this.getSigner = async function () {
|
|
2151
|
+
await _this.signerReady();
|
|
2152
|
+
|
|
2153
|
+
if (_this.signer === undefined) {
|
|
2154
|
+
throw new Error('signerReady failed resolve');
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
return _this.signer;
|
|
2158
|
+
};
|
|
2159
|
+
|
|
2149
2160
|
this.signer = _signer;
|
|
2150
2161
|
this.prompter = prompter;
|
|
2151
2162
|
this.mainnetNetworks = mainnetNetworks;
|
|
@@ -2202,7 +2213,7 @@ class WalletRequestHandler {
|
|
|
2202
2213
|
|
|
2203
2214
|
signOut() {
|
|
2204
2215
|
// signed out state
|
|
2205
|
-
this.
|
|
2216
|
+
this.setSigner(null);
|
|
2206
2217
|
}
|
|
2207
2218
|
|
|
2208
2219
|
signerReset() {
|
|
@@ -2211,14 +2222,18 @@ class WalletRequestHandler {
|
|
|
2211
2222
|
this.signer = undefined;
|
|
2212
2223
|
}
|
|
2213
2224
|
|
|
2214
|
-
signerReady() {
|
|
2225
|
+
signerReady(timeout = SIGNER_READY_TIMEOUT) {
|
|
2215
2226
|
return new Promise((resolve, reject) => {
|
|
2216
2227
|
if (this.signer !== undefined) {
|
|
2217
|
-
resolve(
|
|
2228
|
+
resolve();
|
|
2218
2229
|
} else {
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2230
|
+
setTimeout(() => {
|
|
2231
|
+
if (this.signer === undefined) {
|
|
2232
|
+
this.signerReadyCallbacks = [];
|
|
2233
|
+
reject(`signerReady timed out`);
|
|
2234
|
+
}
|
|
2235
|
+
}, timeout);
|
|
2236
|
+
this.signerReadyCallbacks.push(resolve);
|
|
2222
2237
|
}
|
|
2223
2238
|
});
|
|
2224
2239
|
}
|
|
@@ -2422,14 +2437,6 @@ class WalletRequestHandler {
|
|
|
2422
2437
|
this.events.emit('close', error);
|
|
2423
2438
|
}
|
|
2424
2439
|
|
|
2425
|
-
isSignedIn() {
|
|
2426
|
-
return !!this.signer;
|
|
2427
|
-
}
|
|
2428
|
-
|
|
2429
|
-
getSigner() {
|
|
2430
|
-
return this.signer;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
2440
|
setSigner(signer) {
|
|
2434
2441
|
this.signer = signer;
|
|
2435
2442
|
|
|
@@ -24,7 +24,7 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
24
24
|
signIn(signer: Signer | null, options?: WalletSignInOptions): Promise<void>;
|
|
25
25
|
signOut(): void;
|
|
26
26
|
signerReset(): void;
|
|
27
|
-
signerReady(): Promise<
|
|
27
|
+
signerReady(timeout?: number): Promise<void>;
|
|
28
28
|
connect(options?: ConnectOptions): Promise<ConnectDetails>;
|
|
29
29
|
promptConnect: (options?: ConnectOptions | undefined) => Promise<ConnectDetails>;
|
|
30
30
|
sendMessageRequest(message: ProviderMessageRequest): Promise<ProviderMessageResponse>;
|
|
@@ -46,8 +46,8 @@ export declare class WalletRequestHandler implements ExternalProvider, JsonRpcHa
|
|
|
46
46
|
notifyNetworks(networks?: NetworkConfig[]): Promise<void>;
|
|
47
47
|
notifyWalletContext(): Promise<void>;
|
|
48
48
|
notifyClose(error?: ProviderRpcError): void;
|
|
49
|
-
isSignedIn()
|
|
50
|
-
getSigner()
|
|
49
|
+
isSignedIn: () => Promise<boolean>;
|
|
50
|
+
getSigner: () => Promise<Signer | null>;
|
|
51
51
|
setSigner(signer: Signer | null | undefined): void;
|
|
52
52
|
private handleConfirmWalletDeployPrompt;
|
|
53
53
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/provider",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.10",
|
|
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.35.
|
|
17
|
-
"@0xsequence/auth": "^0.35.
|
|
18
|
-
"@0xsequence/config": "^0.35.
|
|
19
|
-
"@0xsequence/network": "^0.35.
|
|
20
|
-
"@0xsequence/transactions": "^0.35.
|
|
21
|
-
"@0xsequence/utils": "^0.35.
|
|
22
|
-
"@0xsequence/wallet": "^0.35.
|
|
16
|
+
"@0xsequence/abi": "^0.35.10",
|
|
17
|
+
"@0xsequence/auth": "^0.35.10",
|
|
18
|
+
"@0xsequence/config": "^0.35.10",
|
|
19
|
+
"@0xsequence/network": "^0.35.10",
|
|
20
|
+
"@0xsequence/transactions": "^0.35.10",
|
|
21
|
+
"@0xsequence/utils": "^0.35.10",
|
|
22
|
+
"@0xsequence/wallet": "^0.35.10",
|
|
23
23
|
"@ethersproject/abstract-signer": "^5.5.0",
|
|
24
24
|
"@ethersproject/hash": "^5.5.0",
|
|
25
25
|
"@ethersproject/providers": "^5.5.1",
|
|
@@ -100,11 +100,6 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
100
100
|
handleMessage = async (message: ProviderMessage<any>) => {
|
|
101
101
|
const request = message
|
|
102
102
|
|
|
103
|
-
// ensure signer is ready to handle requests
|
|
104
|
-
if (this.walletRequestHandler.getSigner() === undefined) {
|
|
105
|
-
await this.walletRequestHandler.signerReady()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
103
|
// ensure initial handshake is complete before accepting
|
|
109
104
|
// other kinds of messages.
|
|
110
105
|
if (this._init !== InitState.OK) {
|
|
@@ -123,6 +118,11 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
123
118
|
return
|
|
124
119
|
}
|
|
125
120
|
|
|
121
|
+
// ensure signer is ready to handle requests
|
|
122
|
+
// if (this.walletRequestHandler.getSigner() === undefined) {
|
|
123
|
+
// await this.walletRequestHandler.signerReady()
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
126
|
// handle request
|
|
127
127
|
switch (request.type) {
|
|
128
128
|
case EventType.OPEN: {
|
|
@@ -321,18 +321,12 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
321
321
|
|
|
322
322
|
this.walletRequestHandler.setOpenIntent(intent)
|
|
323
323
|
|
|
324
|
-
// ensure signer is ready
|
|
325
|
-
if (this.walletRequestHandler.getSigner() === undefined) {
|
|
326
|
-
await this.walletRequestHandler.signerReady()
|
|
327
|
-
}
|
|
328
|
-
|
|
329
324
|
// init handshake for certain transports, before we can open the communication.
|
|
330
325
|
//
|
|
331
326
|
// for example, with the window-transport, we have to exchange messages to determine the
|
|
332
327
|
// origin host of the dapp.
|
|
333
328
|
await this.init()
|
|
334
329
|
|
|
335
|
-
|
|
336
330
|
// Prepare connect options from intent
|
|
337
331
|
if (intent && intent.type === 'connect' && intent.options) {
|
|
338
332
|
const connectOptions = intent.options
|
|
@@ -370,8 +364,11 @@ export abstract class BaseWalletTransport implements WalletTransport {
|
|
|
370
364
|
this.walletRequestHandler.setConnectOptions(undefined)
|
|
371
365
|
}
|
|
372
366
|
|
|
367
|
+
// ensure signer is ready
|
|
368
|
+
await this.walletRequestHandler.getSigner()
|
|
369
|
+
|
|
373
370
|
// Notify open and proceed to prompt for connection if intended
|
|
374
|
-
if (!this.walletRequestHandler.isSignedIn()) {
|
|
371
|
+
if (!(await this.walletRequestHandler.isSignedIn())) {
|
|
375
372
|
// open wallet without a specific connected chainId, as the user is not signed in
|
|
376
373
|
this.notifyOpen({
|
|
377
374
|
sessionId: this._sessionId
|
|
@@ -34,6 +34,8 @@ import { logger, TypedData } from '@0xsequence/utils'
|
|
|
34
34
|
|
|
35
35
|
import { isWalletUpToDate } from '../utils'
|
|
36
36
|
|
|
37
|
+
const SIGNER_READY_TIMEOUT = 10000
|
|
38
|
+
|
|
37
39
|
export interface WalletSignInOptions {
|
|
38
40
|
connect?: boolean
|
|
39
41
|
mainnetNetworks?: Networks
|
|
@@ -74,7 +76,6 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
74
76
|
async signIn(signer: Signer | null, options: WalletSignInOptions = {}) {
|
|
75
77
|
this.setSigner(signer)
|
|
76
78
|
|
|
77
|
-
|
|
78
79
|
const { connect, mainnetNetworks, testnetNetworks, defaultNetworkId } = options
|
|
79
80
|
|
|
80
81
|
if (mainnetNetworks && mainnetNetworks.length > 0) {
|
|
@@ -119,7 +120,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
119
120
|
|
|
120
121
|
signOut() {
|
|
121
122
|
// signed out state
|
|
122
|
-
this.
|
|
123
|
+
this.setSigner(null)
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
signerReset() {
|
|
@@ -128,14 +129,18 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
128
129
|
this.signer = undefined
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
signerReady() {
|
|
132
|
+
signerReady(timeout: number = SIGNER_READY_TIMEOUT): Promise<void> {
|
|
132
133
|
return new Promise((resolve, reject) => {
|
|
133
134
|
if (this.signer !== undefined) {
|
|
134
|
-
resolve(
|
|
135
|
+
resolve()
|
|
135
136
|
} else {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
if (this.signer === undefined) {
|
|
139
|
+
this.signerReadyCallbacks = []
|
|
140
|
+
reject(`signerReady timed out`)
|
|
141
|
+
}
|
|
142
|
+
}, timeout)
|
|
143
|
+
this.signerReadyCallbacks.push(resolve)
|
|
139
144
|
}
|
|
140
145
|
})
|
|
141
146
|
}
|
|
@@ -196,7 +201,6 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
const promptConnectDetails = await this.prompter.promptConnect(options || this._connectOptions).catch(_ => {
|
|
199
|
-
|
|
200
204
|
return { connected: false } as ConnectDetails
|
|
201
205
|
})
|
|
202
206
|
|
|
@@ -240,9 +244,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
240
244
|
result: null
|
|
241
245
|
}
|
|
242
246
|
|
|
243
|
-
|
|
244
|
-
await this.signerReady()
|
|
245
|
-
}
|
|
247
|
+
await this.getSigner()
|
|
246
248
|
|
|
247
249
|
try {
|
|
248
250
|
// only allow public json rpc method to the provider when user is not logged in, aka signer is not set
|
|
@@ -722,11 +724,16 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
722
724
|
this.events.emit('close', error)
|
|
723
725
|
}
|
|
724
726
|
|
|
725
|
-
isSignedIn(): boolean {
|
|
727
|
+
isSignedIn = async (): Promise<boolean> => {
|
|
728
|
+
await this.signerReady()
|
|
726
729
|
return !!this.signer
|
|
727
730
|
}
|
|
728
731
|
|
|
729
|
-
getSigner(): Signer | null
|
|
732
|
+
getSigner = async (): Promise<Signer | null> => {
|
|
733
|
+
await this.signerReady()
|
|
734
|
+
if (this.signer === undefined) {
|
|
735
|
+
throw new Error('signerReady failed resolve')
|
|
736
|
+
}
|
|
730
737
|
return this.signer
|
|
731
738
|
}
|
|
732
739
|
|
|
@@ -734,7 +741,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
|
|
|
734
741
|
this.signer = signer
|
|
735
742
|
|
|
736
743
|
if (signer !== undefined) {
|
|
737
|
-
for (let i=0; i < this.signerReadyCallbacks.length; i++) {
|
|
744
|
+
for (let i = 0; i < this.signerReadyCallbacks.length; i++) {
|
|
738
745
|
this.signerReadyCallbacks[i]()
|
|
739
746
|
}
|
|
740
747
|
this.signerReadyCallbacks = []
|
|
@@ -17,7 +17,9 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
17
17
|
|
|
18
18
|
register = () => {
|
|
19
19
|
if (registeredWindowMessageProvider) {
|
|
20
|
-
|
|
20
|
+
// overriding the registered message provider
|
|
21
|
+
registeredWindowMessageProvider.unregister()
|
|
22
|
+
registeredWindowMessageProvider = this
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// listen for incoming messages from wallet
|
|
@@ -80,6 +82,7 @@ export class WindowMessageProvider extends BaseProviderTransport {
|
|
|
80
82
|
this._init = InitState.NIL
|
|
81
83
|
this._sessionId = `${performance.now()}`
|
|
82
84
|
windowSessionParams.set('sid', this._sessionId)
|
|
85
|
+
|
|
83
86
|
if (intent) {
|
|
84
87
|
// for the window-transport, we eagerly/optimistically set the origin host
|
|
85
88
|
// when connecting to the wallet, however, this will be verified and enforced
|